Lines Matching refs:rctx
115 static inline unsigned int kmb_get_total_data(struct ocs_hcu_rctx *rctx) in kmb_get_total_data() argument
117 return rctx->sg_data_total + rctx->buf_cnt; in kmb_get_total_data()
121 static int flush_sg_to_ocs_buffer(struct ocs_hcu_rctx *rctx) in flush_sg_to_ocs_buffer() argument
125 if (rctx->sg_data_total > (sizeof(rctx->buffer) - rctx->buf_cnt)) { in flush_sg_to_ocs_buffer()
130 while (rctx->sg_data_total) { in flush_sg_to_ocs_buffer()
131 if (!rctx->sg) { in flush_sg_to_ocs_buffer()
139 if (rctx->sg_data_offset == rctx->sg->length) { in flush_sg_to_ocs_buffer()
140 rctx->sg = sg_next(rctx->sg); in flush_sg_to_ocs_buffer()
141 rctx->sg_data_offset = 0; in flush_sg_to_ocs_buffer()
149 count = min(rctx->sg->length - rctx->sg_data_offset, in flush_sg_to_ocs_buffer()
150 rctx->sg_data_total); in flush_sg_to_ocs_buffer()
152 scatterwalk_map_and_copy(&rctx->buffer[rctx->buf_cnt], in flush_sg_to_ocs_buffer()
153 rctx->sg, rctx->sg_data_offset, in flush_sg_to_ocs_buffer()
156 rctx->sg_data_offset += count; in flush_sg_to_ocs_buffer()
157 rctx->sg_data_total -= count; in flush_sg_to_ocs_buffer()
158 rctx->buf_cnt += count; in flush_sg_to_ocs_buffer()
188 struct ocs_hcu_rctx *rctx) in kmb_ocs_hcu_dma_cleanup() argument
190 struct ocs_hcu_dev *hcu_dev = rctx->hcu_dev; in kmb_ocs_hcu_dma_cleanup()
194 if (rctx->buf_dma_count) { in kmb_ocs_hcu_dma_cleanup()
195 dma_unmap_single(dev, rctx->buf_dma_addr, rctx->buf_dma_count, in kmb_ocs_hcu_dma_cleanup()
197 rctx->buf_dma_count = 0; in kmb_ocs_hcu_dma_cleanup()
201 if (rctx->sg_dma_nents) { in kmb_ocs_hcu_dma_cleanup()
202 dma_unmap_sg(dev, req->src, rctx->sg_dma_nents, DMA_TO_DEVICE); in kmb_ocs_hcu_dma_cleanup()
203 rctx->sg_dma_nents = 0; in kmb_ocs_hcu_dma_cleanup()
207 if (rctx->dma_list) { in kmb_ocs_hcu_dma_cleanup()
208 ocs_hcu_dma_list_free(hcu_dev, rctx->dma_list); in kmb_ocs_hcu_dma_cleanup()
209 rctx->dma_list = NULL; in kmb_ocs_hcu_dma_cleanup()
229 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_dma_prepare() local
230 struct device *dev = rctx->hcu_dev->dev; in kmb_ocs_dma_prepare()
239 total = kmb_get_total_data(rctx); in kmb_ocs_dma_prepare()
248 if (!(rctx->flags & REQ_FINAL)) in kmb_ocs_dma_prepare()
249 remainder = total % rctx->blk_sz; in kmb_ocs_dma_prepare()
252 nents = sg_nents_for_len(req->src, rctx->sg_data_total - remainder); in kmb_ocs_dma_prepare()
256 rctx->sg_dma_nents = dma_map_sg(dev, req->src, nents, in kmb_ocs_dma_prepare()
258 if (!rctx->sg_dma_nents) { in kmb_ocs_dma_prepare()
267 nents = rctx->sg_dma_nents; in kmb_ocs_dma_prepare()
274 if (rctx->buf_cnt) { in kmb_ocs_dma_prepare()
275 rctx->buf_dma_addr = dma_map_single(dev, rctx->buffer, in kmb_ocs_dma_prepare()
276 rctx->buf_cnt, in kmb_ocs_dma_prepare()
278 if (dma_mapping_error(dev, rctx->buf_dma_addr)) { in kmb_ocs_dma_prepare()
283 rctx->buf_dma_count = rctx->buf_cnt; in kmb_ocs_dma_prepare()
289 rctx->dma_list = ocs_hcu_dma_list_alloc(rctx->hcu_dev, nents); in kmb_ocs_dma_prepare()
290 if (!rctx->dma_list) { in kmb_ocs_dma_prepare()
296 if (rctx->buf_dma_count) { in kmb_ocs_dma_prepare()
297 rc = ocs_hcu_dma_list_add_tail(rctx->hcu_dev, rctx->dma_list, in kmb_ocs_dma_prepare()
298 rctx->buf_dma_addr, in kmb_ocs_dma_prepare()
299 rctx->buf_dma_count); in kmb_ocs_dma_prepare()
305 for_each_sg(req->src, rctx->sg, rctx->sg_dma_nents, i) { in kmb_ocs_dma_prepare()
312 count = min(rctx->sg_data_total - remainder, in kmb_ocs_dma_prepare()
313 sg_dma_len(rctx->sg) - rctx->sg_data_offset); in kmb_ocs_dma_prepare()
321 rc = ocs_hcu_dma_list_add_tail(rctx->hcu_dev, in kmb_ocs_dma_prepare()
322 rctx->dma_list, in kmb_ocs_dma_prepare()
323 rctx->sg->dma_address, in kmb_ocs_dma_prepare()
329 rctx->sg_data_total -= count; in kmb_ocs_dma_prepare()
336 if (rctx->sg_data_total <= remainder) { in kmb_ocs_dma_prepare()
337 WARN_ON(rctx->sg_data_total < remainder); in kmb_ocs_dma_prepare()
338 rctx->sg_data_offset += count; in kmb_ocs_dma_prepare()
346 rctx->sg_data_offset = 0; in kmb_ocs_dma_prepare()
352 kmb_ocs_hcu_dma_cleanup(req, rctx); in kmb_ocs_dma_prepare()
359 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_secure_cleanup() local
362 memzero_explicit(rctx->buffer, sizeof(rctx->buffer)); in kmb_ocs_hcu_secure_cleanup()
377 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in prepare_ipad() local
382 WARN(rctx->buf_cnt, "%s: Context buffer is not empty\n", __func__); in prepare_ipad()
383 WARN(!(rctx->flags & REQ_FLAGS_HMAC_SW), in prepare_ipad()
390 if (ctx->key_len > rctx->blk_sz) { in prepare_ipad()
395 rctx->blk_sz - ctx->key_len); in prepare_ipad()
396 ctx->key_len = rctx->blk_sz; in prepare_ipad()
404 for (i = 0; i < rctx->blk_sz; i++) in prepare_ipad()
405 rctx->buffer[i] = ctx->key[i] ^ HMAC_IPAD_VALUE; in prepare_ipad()
406 rctx->buf_cnt = rctx->blk_sz; in prepare_ipad()
417 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_do_one_request() local
432 if (rctx->flags & REQ_FLAGS_HMAC_HW) { in kmb_ocs_hcu_do_one_request()
438 rc = ocs_hcu_hmac(hcu_dev, rctx->algo, tctx->key, tctx->key_len, in kmb_ocs_hcu_do_one_request()
439 rctx->dma_list, req->result, rctx->dig_sz); in kmb_ocs_hcu_do_one_request()
442 kmb_ocs_hcu_dma_cleanup(req, rctx); in kmb_ocs_hcu_do_one_request()
452 if (!(rctx->flags & REQ_FINAL)) { in kmb_ocs_hcu_do_one_request()
454 if (!kmb_get_total_data(rctx)) in kmb_ocs_hcu_do_one_request()
463 rc = ocs_hcu_hash_update(hcu_dev, &rctx->hash_ctx, in kmb_ocs_hcu_do_one_request()
464 rctx->dma_list); in kmb_ocs_hcu_do_one_request()
467 kmb_ocs_hcu_dma_cleanup(req, rctx); in kmb_ocs_hcu_do_one_request()
477 rctx->buf_cnt = 0; in kmb_ocs_hcu_do_one_request()
485 rc = flush_sg_to_ocs_buffer(rctx); in kmb_ocs_hcu_do_one_request()
495 if (kmb_get_total_data(rctx)) { in kmb_ocs_hcu_do_one_request()
502 rc = ocs_hcu_hash_finup(hcu_dev, &rctx->hash_ctx, in kmb_ocs_hcu_do_one_request()
503 rctx->dma_list, in kmb_ocs_hcu_do_one_request()
504 req->result, rctx->dig_sz); in kmb_ocs_hcu_do_one_request()
506 kmb_ocs_hcu_dma_cleanup(req, rctx); in kmb_ocs_hcu_do_one_request()
513 rc = ocs_hcu_hash_final(hcu_dev, &rctx->hash_ctx, req->result, in kmb_ocs_hcu_do_one_request()
514 rctx->dig_sz); in kmb_ocs_hcu_do_one_request()
527 if (rctx->flags & REQ_FLAGS_HMAC_SW) { in kmb_ocs_hcu_do_one_request()
534 WARN_ON(tctx->key_len != rctx->blk_sz); in kmb_ocs_hcu_do_one_request()
535 for (i = 0; i < rctx->blk_sz; i++) in kmb_ocs_hcu_do_one_request()
536 rctx->buffer[i] = tctx->key[i] ^ HMAC_OPAD_VALUE; in kmb_ocs_hcu_do_one_request()
538 for (i = 0; (i < rctx->dig_sz); i++) in kmb_ocs_hcu_do_one_request()
539 rctx->buffer[rctx->blk_sz + i] = req->result[i]; in kmb_ocs_hcu_do_one_request()
542 rc = ocs_hcu_digest(hcu_dev, rctx->algo, rctx->buffer, in kmb_ocs_hcu_do_one_request()
543 rctx->blk_sz + rctx->dig_sz, req->result, in kmb_ocs_hcu_do_one_request()
544 rctx->dig_sz); in kmb_ocs_hcu_do_one_request()
564 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_init() local
572 memset(rctx, 0, sizeof(*rctx)); in kmb_ocs_hcu_init()
574 rctx->hcu_dev = hcu_dev; in kmb_ocs_hcu_init()
575 rctx->dig_sz = crypto_ahash_digestsize(tfm); in kmb_ocs_hcu_init()
577 switch (rctx->dig_sz) { in kmb_ocs_hcu_init()
580 rctx->blk_sz = SHA224_BLOCK_SIZE; in kmb_ocs_hcu_init()
581 rctx->algo = OCS_HCU_ALGO_SHA224; in kmb_ocs_hcu_init()
585 rctx->blk_sz = SHA256_BLOCK_SIZE; in kmb_ocs_hcu_init()
590 rctx->algo = ctx->is_sm3_tfm ? OCS_HCU_ALGO_SM3 : in kmb_ocs_hcu_init()
594 rctx->blk_sz = SHA384_BLOCK_SIZE; in kmb_ocs_hcu_init()
595 rctx->algo = OCS_HCU_ALGO_SHA384; in kmb_ocs_hcu_init()
598 rctx->blk_sz = SHA512_BLOCK_SIZE; in kmb_ocs_hcu_init()
599 rctx->algo = OCS_HCU_ALGO_SHA512; in kmb_ocs_hcu_init()
606 ocs_hcu_hash_init(&rctx->hash_ctx, rctx->algo); in kmb_ocs_hcu_init()
610 rctx->flags |= REQ_FLAGS_HMAC; in kmb_ocs_hcu_init()
617 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_update() local
623 rctx->sg_data_total = req->nbytes; in kmb_ocs_hcu_update()
624 rctx->sg_data_offset = 0; in kmb_ocs_hcu_update()
625 rctx->sg = req->src; in kmb_ocs_hcu_update()
632 if (rctx->flags & REQ_FLAGS_HMAC && in kmb_ocs_hcu_update()
633 !(rctx->flags & REQ_FLAGS_HMAC_SW)) { in kmb_ocs_hcu_update()
634 rctx->flags |= REQ_FLAGS_HMAC_SW; in kmb_ocs_hcu_update()
644 if (rctx->sg_data_total <= (sizeof(rctx->buffer) - rctx->buf_cnt)) in kmb_ocs_hcu_update()
645 return flush_sg_to_ocs_buffer(rctx); in kmb_ocs_hcu_update()
653 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_fin_common() local
658 rctx->flags |= REQ_FINAL; in kmb_ocs_hcu_fin_common()
664 if (rctx->flags & REQ_FLAGS_HMAC && in kmb_ocs_hcu_fin_common()
665 !(rctx->flags & REQ_FLAGS_HMAC_SW)) { in kmb_ocs_hcu_fin_common()
674 if (kmb_get_total_data(rctx) && in kmb_ocs_hcu_fin_common()
676 rctx->flags |= REQ_FLAGS_HMAC_HW; in kmb_ocs_hcu_fin_common()
678 rctx->flags |= REQ_FLAGS_HMAC_SW; in kmb_ocs_hcu_fin_common()
690 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_final() local
692 rctx->sg_data_total = 0; in kmb_ocs_hcu_final()
693 rctx->sg_data_offset = 0; in kmb_ocs_hcu_final()
694 rctx->sg = NULL; in kmb_ocs_hcu_final()
701 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_finup() local
703 rctx->sg_data_total = req->nbytes; in kmb_ocs_hcu_finup()
704 rctx->sg_data_offset = 0; in kmb_ocs_hcu_finup()
705 rctx->sg = req->src; in kmb_ocs_hcu_finup()
729 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_export() local
732 memcpy(out, rctx, sizeof(*rctx)); in kmb_ocs_hcu_export()
739 struct ocs_hcu_rctx *rctx = ahash_request_ctx_dma(req); in kmb_ocs_hcu_import() local
742 memcpy(rctx, in, sizeof(*rctx)); in kmb_ocs_hcu_import()