Lines Matching +full:zynqmp +full:- +full:firmware
1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx ZynqMP AES Driver.
13 #include <linux/dma-mapping.h>
18 #include <linux/firmware/xlnx-zynqmp.h>
82 struct device *dev = tfm_ctx->dev; in zynqmp_aes_aead_cipher()
92 if (tfm_ctx->keysrc == ZYNQMP_AES_KUP_KEY) in zynqmp_aes_aead_cipher()
93 dma_size = req->cryptlen + ZYNQMP_AES_KEY_SIZE in zynqmp_aes_aead_cipher()
96 dma_size = req->cryptlen + GCM_AES_IV_SIZE; in zynqmp_aes_aead_cipher()
100 return -ENOMEM; in zynqmp_aes_aead_cipher()
106 return -ENOMEM; in zynqmp_aes_aead_cipher()
109 data_size = req->cryptlen; in zynqmp_aes_aead_cipher()
110 scatterwalk_map_and_copy(kbuf, req->src, 0, req->cryptlen, 0); in zynqmp_aes_aead_cipher()
111 memcpy(kbuf + data_size, req->iv, GCM_AES_IV_SIZE); in zynqmp_aes_aead_cipher()
113 hwreq->src = dma_addr_data; in zynqmp_aes_aead_cipher()
114 hwreq->dst = dma_addr_data; in zynqmp_aes_aead_cipher()
115 hwreq->iv = hwreq->src + data_size; in zynqmp_aes_aead_cipher()
116 hwreq->keysrc = tfm_ctx->keysrc; in zynqmp_aes_aead_cipher()
117 hwreq->op = rq_ctx->op; in zynqmp_aes_aead_cipher()
119 if (hwreq->op == ZYNQMP_AES_ENCRYPT) in zynqmp_aes_aead_cipher()
120 hwreq->size = data_size; in zynqmp_aes_aead_cipher()
122 hwreq->size = data_size - ZYNQMP_AES_AUTH_SIZE; in zynqmp_aes_aead_cipher()
124 if (hwreq->keysrc == ZYNQMP_AES_KUP_KEY) { in zynqmp_aes_aead_cipher()
126 tfm_ctx->key, ZYNQMP_AES_KEY_SIZE); in zynqmp_aes_aead_cipher()
128 hwreq->key = hwreq->src + data_size + GCM_AES_IV_SIZE; in zynqmp_aes_aead_cipher()
130 hwreq->key = 0; in zynqmp_aes_aead_cipher()
153 err = -status; in zynqmp_aes_aead_cipher()
155 if (hwreq->op == ZYNQMP_AES_ENCRYPT) in zynqmp_aes_aead_cipher()
158 data_size = data_size - ZYNQMP_AES_AUTH_SIZE; in zynqmp_aes_aead_cipher()
160 sg_copy_from_buffer(req->dst, sg_nents(req->dst), in zynqmp_aes_aead_cipher()
183 if (tfm_ctx->authsize != ZYNQMP_AES_AUTH_SIZE) in zynqmp_fallback_check()
186 if (tfm_ctx->keysrc == ZYNQMP_AES_KUP_KEY && in zynqmp_fallback_check()
187 tfm_ctx->keylen != ZYNQMP_AES_KEY_SIZE) { in zynqmp_fallback_check()
190 if (req->assoclen != 0 || in zynqmp_fallback_check()
191 req->cryptlen < ZYNQMP_AES_MIN_INPUT_BLK_SIZE) { in zynqmp_fallback_check()
194 if ((req->cryptlen % ZYNQMP_AES_WORD_LEN) != 0) in zynqmp_fallback_check()
197 if (rq_ctx->op == ZYNQMP_AES_DECRYPT && in zynqmp_fallback_check()
198 req->cryptlen <= ZYNQMP_AES_AUTH_SIZE) { in zynqmp_fallback_check()
219 aead_request_set_tfm(subreq, tfm_ctx->fbk_cipher); in zynqmp_handle_aes_req()
221 aead_request_set_callback(subreq, areq->base.flags, in zynqmp_handle_aes_req()
223 aead_request_set_crypt(subreq, areq->src, areq->dst, in zynqmp_handle_aes_req()
224 areq->cryptlen, areq->iv); in zynqmp_handle_aes_req()
225 aead_request_set_ad(subreq, areq->assoclen); in zynqmp_handle_aes_req()
226 if (rq_ctx->op == ZYNQMP_AES_ENCRYPT) in zynqmp_handle_aes_req()
251 tfm_ctx->keysrc = (enum zynqmp_aead_keysrc)keysrc; in zynqmp_aes_aead_setkey()
253 tfm_ctx->keylen = keylen; in zynqmp_aes_aead_setkey()
256 tfm_ctx->keylen = keylen; in zynqmp_aes_aead_setkey()
258 tfm_ctx->keysrc = ZYNQMP_AES_KUP_KEY; in zynqmp_aes_aead_setkey()
259 memcpy(tfm_ctx->key, key, keylen); in zynqmp_aes_aead_setkey()
263 tfm_ctx->fbk_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; in zynqmp_aes_aead_setkey()
264 tfm_ctx->fbk_cipher->base.crt_flags |= (aead->base.crt_flags & in zynqmp_aes_aead_setkey()
267 return crypto_aead_setkey(tfm_ctx->fbk_cipher, key, keylen); in zynqmp_aes_aead_setkey()
277 tfm_ctx->authsize = authsize; in zynqmp_aes_aead_setauthsize()
278 return crypto_aead_setauthsize(tfm_ctx->fbk_cipher, authsize); in zynqmp_aes_aead_setauthsize()
288 rq_ctx->op = ZYNQMP_AES_ENCRYPT; in zynqmp_aes_aead_encrypt()
291 return crypto_transfer_aead_request_to_engine(drv_ctx->engine, req); in zynqmp_aes_aead_encrypt()
301 rq_ctx->op = ZYNQMP_AES_DECRYPT; in zynqmp_aes_aead_decrypt()
304 return crypto_transfer_aead_request_to_engine(drv_ctx->engine, req); in zynqmp_aes_aead_decrypt()
316 tfm_ctx->dev = drv_ctx->dev; in zynqmp_aes_aead_init()
318 tfm_ctx->engine_ctx.op.do_one_request = zynqmp_handle_aes_req; in zynqmp_aes_aead_init()
319 tfm_ctx->engine_ctx.op.prepare_request = NULL; in zynqmp_aes_aead_init()
320 tfm_ctx->engine_ctx.op.unprepare_request = NULL; in zynqmp_aes_aead_init()
322 tfm_ctx->fbk_cipher = crypto_alloc_aead(drv_ctx->alg.aead.base.cra_name, in zynqmp_aes_aead_init()
326 if (IS_ERR(tfm_ctx->fbk_cipher)) { in zynqmp_aes_aead_init()
328 __func__, drv_ctx->alg.aead.base.cra_name); in zynqmp_aes_aead_init()
329 return PTR_ERR(tfm_ctx->fbk_cipher); in zynqmp_aes_aead_init()
335 crypto_aead_reqsize(tfm_ctx->fbk_cipher))); in zynqmp_aes_aead_init()
345 if (tfm_ctx->fbk_cipher) { in zynqmp_aes_aead_exit()
346 crypto_free_aead(tfm_ctx->fbk_cipher); in zynqmp_aes_aead_exit()
347 tfm_ctx->fbk_cipher = NULL; in zynqmp_aes_aead_exit()
364 .cra_driver_name = "xilinx-zynqmp-aes-gcm",
380 struct device *dev = &pdev->dev; in zynqmp_aes_aead_probe()
383 /* ZynqMP AES driver supports only one instance */ in zynqmp_aes_aead_probe()
387 return -ENODEV; in zynqmp_aes_aead_probe()
398 err = -ENOMEM; in zynqmp_aes_aead_probe()
434 { .compatible = "xlnx,zynqmp-aes" },
443 .name = "zynqmp-aes",