diff options
author | Gilad Ben-Yossef <gilad@benyossef.com> | 2017-10-03 11:42:16 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-03 18:28:17 +0200 |
commit | bdd0873dc28d57651ae2ed4e42bb79526ed684ac (patch) | |
tree | 18a023ad9aadf47e4e414e0ac8edbbf4cf6af4e6 /drivers/staging | |
parent | a55ef6f52fdd5a4538dc140903416361d156c548 (diff) |
staging: ccree: move to generic device log infra
Move over from using macro wrappers around to printk to
dev_err, dev_dbg and friends and clean up resulting fallout.
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/ccree/ssi_aead.c | 226 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_buffer_mgr.c | 394 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_buffer_mgr.h | 5 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_cipher.c | 138 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_driver.c | 142 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_driver.h | 13 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_fips.c | 12 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_hash.c | 297 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_ivgen.c | 13 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_pm.c | 15 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_request_mgr.c | 87 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_sram_mgr.c | 16 | ||||
-rw-r--r-- | drivers/staging/ccree/ssi_sysfs.c | 3 |
13 files changed, 688 insertions, 673 deletions
diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c index a51ad553ef73..ba0954e4d2e5 100644 --- a/drivers/staging/ccree/ssi_aead.c +++ b/drivers/staging/ccree/ssi_aead.c @@ -95,14 +95,14 @@ static void ssi_aead_exit(struct crypto_aead *tfm) struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); struct device *dev = drvdata_to_dev(ctx->drvdata); - SSI_LOG_DEBUG("Clearing context @%p for %s\n", - crypto_aead_ctx(tfm), crypto_tfm_alg_name(&tfm->base)); + dev_dbg(dev, "Clearing context @%p for %s\n", crypto_aead_ctx(tfm), + crypto_tfm_alg_name(&tfm->base)); /* Unmap enckey buffer */ if (ctx->enckey) { dma_free_coherent(dev, AES_MAX_KEY_SIZE, ctx->enckey, ctx->enckey_dma_addr); - SSI_LOG_DEBUG("Freed enckey DMA buffer enckey_dma_addr=%pad\n", - ctx->enckey_dma_addr); + dev_dbg(dev, "Freed enckey DMA buffer enckey_dma_addr=%pad\n", + &ctx->enckey_dma_addr); ctx->enckey_dma_addr = 0; ctx->enckey = NULL; } @@ -115,8 +115,8 @@ static void ssi_aead_exit(struct crypto_aead *tfm) xcbc->xcbc_keys, xcbc->xcbc_keys_dma_addr); } - SSI_LOG_DEBUG("Freed xcbc_keys DMA buffer xcbc_keys_dma_addr=%pad\n", - xcbc->xcbc_keys_dma_addr); + dev_dbg(dev, "Freed xcbc_keys DMA buffer xcbc_keys_dma_addr=%pad\n", + &xcbc->xcbc_keys_dma_addr); xcbc->xcbc_keys_dma_addr = 0; xcbc->xcbc_keys = NULL; } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC auth. */ @@ -126,8 +126,8 @@ static void ssi_aead_exit(struct crypto_aead *tfm) dma_free_coherent(dev, 2 * MAX_HMAC_DIGEST_SIZE, hmac->ipad_opad, hmac->ipad_opad_dma_addr); - SSI_LOG_DEBUG("Freed ipad_opad DMA buffer ipad_opad_dma_addr=%pad\n", - hmac->ipad_opad_dma_addr); + dev_dbg(dev, "Freed ipad_opad DMA buffer ipad_opad_dma_addr=%pad\n", + &hmac->ipad_opad_dma_addr); hmac->ipad_opad_dma_addr = 0; hmac->ipad_opad = NULL; } @@ -135,8 +135,8 @@ static void ssi_aead_exit(struct crypto_aead *tfm) dma_free_coherent(dev, MAX_HMAC_BLOCK_SIZE, hmac->padded_authkey, hmac->padded_authkey_dma_addr); - SSI_LOG_DEBUG("Freed padded_authkey DMA buffer padded_authkey_dma_addr=%pad\n", - hmac->padded_authkey_dma_addr); + dev_dbg(dev, "Freed padded_authkey DMA buffer padded_authkey_dma_addr=%pad\n", + &hmac->padded_authkey_dma_addr); hmac->padded_authkey_dma_addr = 0; hmac->padded_authkey = NULL; } @@ -151,7 +151,8 @@ static int ssi_aead_init(struct crypto_aead *tfm) container_of(alg, struct ssi_crypto_alg, aead_alg); struct device *dev = drvdata_to_dev(ssi_alg->drvdata); - SSI_LOG_DEBUG("Initializing context @%p for %s\n", ctx, crypto_tfm_alg_name(&tfm->base)); + dev_dbg(dev, "Initializing context @%p for %s\n", ctx, + crypto_tfm_alg_name(&tfm->base)); /* Initialize modes in instance */ ctx->cipher_mode = ssi_alg->cipher_mode; @@ -164,10 +165,11 @@ static int ssi_aead_init(struct crypto_aead *tfm) ctx->enckey = dma_alloc_coherent(dev, AES_MAX_KEY_SIZE, &ctx->enckey_dma_addr, GFP_KERNEL); if (!ctx->enckey) { - SSI_LOG_ERR("Failed allocating key buffer\n"); + dev_err(dev, "Failed allocating key buffer\n"); goto init_failed; } - SSI_LOG_DEBUG("Allocated enckey buffer in context ctx->enckey=@%p\n", ctx->enckey); + dev_dbg(dev, "Allocated enckey buffer in context ctx->enckey=@%p\n", + ctx->enckey); /* Set default authlen value */ @@ -181,7 +183,7 @@ static int ssi_aead_init(struct crypto_aead *tfm) &xcbc->xcbc_keys_dma_addr, GFP_KERNEL); if (!xcbc->xcbc_keys) { - SSI_LOG_ERR("Failed allocating buffer for XCBC keys\n"); + dev_err(dev, "Failed allocating buffer for XCBC keys\n"); goto init_failed; } } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC authentication */ @@ -195,12 +197,12 @@ static int ssi_aead_init(struct crypto_aead *tfm) GFP_KERNEL); if (!hmac->ipad_opad) { - SSI_LOG_ERR("Failed allocating IPAD/OPAD buffer\n"); + dev_err(dev, "Failed allocating IPAD/OPAD buffer\n"); goto init_failed; } - SSI_LOG_DEBUG("Allocated authkey buffer in context ctx->authkey=@%p\n", - hmac->ipad_opad); + dev_dbg(dev, "Allocated authkey buffer in context ctx->authkey=@%p\n", + hmac->ipad_opad); hmac->padded_authkey = dma_alloc_coherent(dev, MAX_HMAC_BLOCK_SIZE, @@ -208,7 +210,7 @@ static int ssi_aead_init(struct crypto_aead *tfm) GFP_KERNEL); if (!hmac->padded_authkey) { - SSI_LOG_ERR("failed to allocate padded_authkey\n"); + dev_err(dev, "failed to allocate padded_authkey\n"); goto init_failed; } } else { @@ -239,8 +241,7 @@ static void ssi_aead_complete(struct device *dev, void *ssi_req, void __iomem *c if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) { if (memcmp(areq_ctx->mac_buf, areq_ctx->icv_virt_addr, ctx->authsize) != 0) { - SSI_LOG_DEBUG("Payload authentication failure, " - "(auth-size=%d, cipher=%d).\n", + dev_dbg(dev, "Payload authentication failure, (auth-size=%d, cipher=%d)\n", ctx->authsize, ctx->cipher_mode); /* In case of payload authentication failure, MUST NOT * revealed the decrypted message --> zero its memory. @@ -251,8 +252,11 @@ static void ssi_aead_complete(struct device *dev, void *ssi_req, void __iomem *c } else { /*ENCRYPT*/ if (unlikely(areq_ctx->is_icv_fragmented)) ssi_buffer_mgr_copy_scatterlist_portion( - areq_ctx->mac_buf, areq_ctx->dst_sgl, areq->cryptlen + areq_ctx->dst_offset, - areq->cryptlen + areq_ctx->dst_offset + ctx->authsize, SSI_SG_FROM_BUF); + dev, areq_ctx->mac_buf, areq_ctx->dst_sgl, + areq->cryptlen + areq_ctx->dst_offset, + (areq->cryptlen + areq_ctx->dst_offset + + ctx->authsize), + SSI_SG_FROM_BUF); /* If an IV was generated, copy it back to the user provided buffer. */ if (areq_ctx->backup_giv) { @@ -376,8 +380,10 @@ static int hmac_setkey(struct cc_hw_desc *desc, struct ssi_aead_ctx *ctx) static int validate_keys_sizes(struct ssi_aead_ctx *ctx) { - SSI_LOG_DEBUG("enc_keylen=%u authkeylen=%u\n", - ctx->enc_keylen, ctx->auth_keylen); + struct device *dev = drvdata_to_dev(ctx->drvdata); + + dev_dbg(dev, "enc_keylen=%u authkeylen=%u\n", + ctx->enc_keylen, ctx->auth_keylen); switch (ctx->auth_mode) { case DRV_HASH_SHA1: @@ -394,22 +400,22 @@ static int validate_keys_sizes(struct ssi_aead_ctx *ctx) return -EINVAL; break; default: - SSI_LOG_ERR("Invalid auth_mode=%d\n", ctx->auth_mode); + dev_err(dev, "Invalid auth_mode=%d\n", ctx->auth_mode); return -EINVAL; } /* Check cipher key size */ if (unlikely(ctx->flow_mode == S_DIN_to_DES)) { if (ctx->enc_keylen != DES3_EDE_KEY_SIZE) { - SSI_LOG_ERR("Invalid cipher(3DES) key size: %u\n", - ctx->enc_keylen); + dev_err(dev, "Invalid cipher(3DES) key size: %u\n", + ctx->enc_keylen); return -EINVAL; } } else { /* Default assumed to be AES ciphers */ if ((ctx->enc_keylen != AES_KEYSIZE_128) && (ctx->enc_keylen != AES_KEYSIZE_192) && (ctx->enc_keylen != AES_KEYSIZE_256)) { - SSI_LOG_ERR("Invalid cipher(AES) key size: %u\n", - ctx->enc_keylen); + dev_err(dev, "Invalid cipher(AES) key size: %u\n", + ctx->enc_keylen); return -EINVAL; } } @@ -454,8 +460,8 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl if (likely(keylen != 0)) { key_dma_addr = dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev, key_dma_addr))) { - SSI_LOG_ERR("Mapping key va=0x%p len=%u for" - " DMA failed\n", key, keylen); + dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", + key, keylen); return -ENOMEM; } if (keylen > blocksize) { @@ -533,7 +539,7 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0); if (unlikely(rc != 0)) - SSI_LOG_ERR("send_request() failed (rc=%d)\n", rc); + dev_err(dev, "send_request() failed (rc=%d)\n", rc); if (likely(key_dma_addr != 0)) dma_unmap_single(dev, key_dma_addr, keylen, DMA_TO_DEVICE); @@ -550,10 +556,10 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) struct crypto_authenc_key_param *param; struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ]; int seq_len = 0, rc = -EINVAL; + struct device *dev = drvdata_to_dev(ctx->drvdata); - SSI_LOG_DEBUG("Setting key in context @%p for %s. key=%p keylen=%u\n", - ctx, crypto_tfm_alg_name(crypto_aead_tfm(tfm)), - key, keylen); + dev_dbg(dev, "Setting key in context @%p for %s. key=%p keylen=%u\n", + ctx, crypto_tfm_alg_name(crypto_aead_tfm(tfm)), key, keylen); /* STAT_PHASE_0: Init and sanity checks */ @@ -621,7 +627,7 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) case DRV_HASH_NULL: /* non-authenc modes, e.g., CCM */ break; /* No auth. key setup */ default: - SSI_LOG_ERR("Unsupported authenc (%d)\n", ctx->auth_mode); + dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode); rc = -ENOTSUPP; goto badkey; } @@ -631,7 +637,7 @@ ssi_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) if (seq_len > 0) { /* For CCM there is no sequence to setup the key */ rc = send_request(ctx->drvdata, &ssi_req, desc, seq_len, 0); if (unlikely(rc != 0)) { - SSI_LOG_ERR("send_request() failed (rc=%d)\n", rc); + dev_err(dev, "send_request() failed (rc=%d)\n", rc); goto setkey_error; } } @@ -666,6 +672,7 @@ static int ssi_aead_setauthsize( unsigned int authsize) { struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); + struct device *dev = drvdata_to_dev(ctx->drvdata); /* Unsupported auth. sizes */ if ((authsize == 0) || @@ -674,7 +681,7 @@ static int ssi_aead_setauthsize( } ctx->authsize = authsize; - SSI_LOG_DEBUG("authlen=%d\n", ctx->authsize); + dev_dbg(dev, "authlen=%d\n", ctx->authsize); return 0; } @@ -727,10 +734,11 @@ ssi_aead_create_assoc_desc( struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); enum ssi_req_dma_buf_type assoc_dma_type = areq_ctx->assoc_buff_type; unsigned int idx = *seq_size; + struct device *dev = drvdata_to_dev(ctx->drvdata); switch (assoc_dma_type) { case SSI_DMA_BUF_DLLI: - SSI_LOG_DEBUG("ASSOC buffer type DLLI\n"); + dev_dbg(dev, "ASSOC buffer type DLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_DLLI, sg_dma_address(areq->src), areq->assoclen, NS_BIT); set_flow_mode(&desc[idx], @@ -740,7 +748,7 @@ ssi_aead_create_assoc_desc( set_din_not_last_indication(&desc[idx]); break; case SSI_DMA_BUF_MLLI: - SSI_LOG_DEBUG("ASSOC buffer type MLLI\n"); + dev_dbg(dev, "ASSOC buffer type MLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_MLLI, areq_ctx->assoc.sram_addr, areq_ctx->assoc.mlli_nents, NS_BIT); @@ -751,7 +759,7 @@ ssi_aead_create_assoc_desc( break; case SSI_DMA_BUF_NULL: default: - SSI_LOG_ERR("Invalid ASSOC buffer type\n"); + dev_err(dev, "Invalid ASSOC buffer type\n"); } *seq_size = (++idx); @@ -768,6 +776,9 @@ ssi_aead_process_authenc_data_desc( struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); enum ssi_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type; unsigned int idx = *seq_size; + struct crypto_aead *tfm = crypto_aead_reqtfm(areq); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); switch (data_dma_type) { case SSI_DMA_BUF_DLLI: @@ -779,7 +790,7 @@ ssi_aead_process_authenc_data_desc( unsigned int offset = (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? areq_ctx->dst_offset : areq_ctx->src_offset; - SSI_LOG_DEBUG("AUTHENC: SRC/DST buffer type DLLI\n"); + dev_dbg(dev, "AUTHENC: SRC/DST buffer type DLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_DLLI, (sg_dma_address(cipher) + offset), @@ -806,7 +817,7 @@ ssi_aead_process_authenc_data_desc( } } - SSI_LOG_DEBUG("AUTHENC: SRC/DST buffer type MLLI\n"); + dev_dbg(dev, "AUTHENC: SRC/DST buffer type MLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_MLLI, mlli_addr, mlli_nents, NS_BIT); @@ -815,7 +826,7 @@ ssi_aead_process_authenc_data_desc( } case SSI_DMA_BUF_NULL: default: - SSI_LOG_ERR("AUTHENC: Invalid SRC/DST buffer type\n"); + dev_err(dev, "AUTHENC: Invalid SRC/DST buffer type\n"); } *seq_size = (++idx); @@ -831,13 +842,16 @@ ssi_aead_process_cipher_data_desc( unsigned int idx = *seq_size; struct aead_req_ctx *areq_ctx = aead_request_ctx(areq); enum ssi_req_dma_buf_type data_dma_type = areq_ctx->data_buff_type; + struct crypto_aead *tfm = crypto_aead_reqtfm(areq); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); if (areq_ctx->cryptlen == 0) return; /*null processing*/ switch (data_dma_type) { case SSI_DMA_BUF_DLLI: - SSI_LOG_DEBUG("CIPHER: SRC/DST buffer type DLLI\n"); + dev_dbg(dev, "CIPHER: SRC/DST buffer type DLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_DLLI, (sg_dma_address(areq_ctx->src_sgl) + @@ -849,7 +863,7 @@ ssi_aead_process_cipher_data_desc( set_flow_mode(&desc[idx], flow_mode); break; case SSI_DMA_BUF_MLLI: - SSI_LOG_DEBUG("CIPHER: SRC/DST buffer type MLLI\n"); + dev_dbg(dev, "CIPHER: SRC/DST buffer type MLLI\n"); hw_desc_init(&desc[idx]); set_din_type(&desc[idx], DMA_MLLI, areq_ctx->src.sram_addr, areq_ctx->src.mlli_nents, NS_BIT); @@ -859,7 +873,7 @@ ssi_aead_process_cipher_data_desc( break; case SSI_DMA_BUF_NULL: default: - SSI_LOG_ERR("CIPHER: Invalid SRC/DST buffer type\n"); + dev_err(dev, "CIPHER: Invalid SRC/DST buffer type\n"); } *seq_size = (++idx); @@ -1174,14 +1188,15 @@ static inline void ssi_aead_load_mlli_to_sram( struct aead_req_ctx *req_ctx = aead_request_ctx(req); struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); if (unlikely( (req_ctx->assoc_buff_type == SSI_DMA_BUF_MLLI) || (req_ctx->data_buff_type == SSI_DMA_BUF_MLLI) || !req_ctx->is_single_pass)) { - SSI_LOG_DEBUG("Copy-to-sram: mlli_dma=%08x, mlli_size=%u\n", - (unsigned int)ctx->drvdata->mlli_sram_addr, - req_ctx->mlli_params.mlli_len); + dev_dbg(dev, "Copy-to-sram: mlli_dma=%08x, mlli_size=%u\n", + (unsigned int)ctx->drvdata->mlli_sram_addr, + req_ctx->mlli_params.mlli_len); /* Copy MLLI table host-to-sram */ hw_desc_init(&desc[*seq_size]); set_din_type(&desc[*seq_size], DMA_DLLI, @@ -1329,6 +1344,7 @@ static int validate_data_size(struct ssi_aead_ctx *ctx, struct aead_request *req) { struct aead_req_ctx *areq_ctx = aead_request_ctx(req); + struct device *dev = drvdata_to_dev(ctx->drvdata); unsigned int assoclen = req->assoclen; unsigned int cipherlen = (direct == DRV_CRYPTO_DIRECTION_DECRYPT) ? (req->cryptlen - ctx->authsize) : req->cryptlen; @@ -1367,7 +1383,7 @@ static int validate_data_size(struct ssi_aead_ctx *ctx, areq_ctx->is_single_pass = false; break; default: - SSI_LOG_ERR("Unexpected flow mode (%d)\n", ctx->flow_mode); + dev_err(dev, "Unexpected flow mode (%d)\n", ctx->flow_mode); goto data_size_err; } @@ -1550,6 +1566,7 @@ static int config_ccm_adata(struct aead_request *req) { struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); struct aead_req_ctx *req_ctx = aead_request_ctx(req); //unsigned int size_of_a = 0, rem_a_size = 0; unsigned int lp = req->iv[0]; @@ -1571,7 +1588,7 @@ static int config_ccm_adata(struct aead_request *req) /* taken from crypto/ccm.c */ /* 2 <= L <= 8, so 1 <= L' <= 7. */ if (l < 2 || l > 8) { - SSI_LOG_ERR("illegal iv value %X\n", req->iv[0]); + dev_err(dev, "illegal iv value %X\n", req->iv[0]); return -EINVAL; } memcpy(b0, req->iv, AES_BLOCK_SIZE); @@ -1584,8 +1601,10 @@ static int config_ccm_adata(struct aead_request *req) *b0 |= 64; /* Enable bit 6 if Adata exists. */ rc = set_msg_len(b0 + 16 - l, cryptlen, l); /* Write L'. */ - if (rc != 0) + if (rc != 0) { + dev_err(dev, "message len overflow detected"); return rc; + } /* END of "taken from crypto/ccm.c" */ /* l(a) - size of associated data. */ @@ -1854,13 +1873,13 @@ static inline void ssi_aead_dump_gcm( return; if (title) { - SSI_LOG_DEBUG("----------------------------------------------------------------------------------"); - SSI_LOG_DEBUG("%s\n", title); + dev_dbg(dev, "----------------------------------------------------------------------------------"); + dev_dbg(dev, "%s\n", title); } - SSI_LOG_DEBUG("cipher_mode %d, authsize %d, enc_keylen %d, assoclen %d, cryptlen %d\n", - ctx->cipher_mode, ctx->authsize, ctx->enc_keylen, - req->assoclen, req_ctx->cryptlen); + dev_dbg(dev, "cipher_mode %d, authsize %d, enc_keylen %d, assoclen %d, cryptlen %d\n", + ctx->cipher_mode, ctx->authsize, ctx->enc_keylen, + req->assoclen, req_ctx->cryptlen); if (ctx->enckey) dump_byte_array("mac key", ctx->enckey, 16); @@ -1890,6 +1909,7 @@ static int config_gcm_context(struct aead_request *req) struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); struct aead_req_ctx *req_ctx = aead_request_ctx(req); + struct device *dev = drvdata_to_dev(ctx->drvdata); unsigned int cryptlen = (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_ENCRYPT) ? @@ -1897,7 +1917,8 @@ static int config_gcm_context(struct aead_request *req) (req->cryptlen - ctx->authsize); __be32 counter = cpu_to_be32(2); - SSI_LOG_DEBUG("%s() cryptlen = %d, req->assoclen = %d ctx->authsize = %d\n", __func__, cryptlen, req->assoclen, ctx->authsize); + dev_dbg(dev, "%s() cryptlen = %d, req->assoclen = %d ctx->authsize = %d\n", + __func__, cryptlen, req->assoclen, ctx->authsize); memset(req_ctx->hkey, 0, AES_BLOCK_SIZE); @@ -1954,17 +1975,17 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction struct device *dev = drvdata_to_dev(ctx->drvdata); struct ssi_crypto_req ssi_req = {}; - SSI_LOG_DEBUG("%s context=%p req=%p iv=%p src=%p src_ofs=%d dst=%p dst_ofs=%d cryptolen=%d\n", - ((direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? "Encrypt" : "Decrypt"), - ctx, req, req->iv, sg_virt(req->src), req->src->offset, - sg_virt(req->dst), req->dst->offset, req->cryptlen); + dev_dbg(dev, "%s context=%p req=%p iv=%p src=%p src_ofs=%d dst=%p dst_ofs=%d cryptolen=%d\n", + ((direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? "Enc" : "Dec"), + ctx, req, req->iv, sg_virt(req->src), req->src->offset, + sg_virt(req->dst), req->dst->offset, req->cryptlen); /* STAT_PHASE_0: Init and sanity checks */ /* Check data length according to mode */ if (unlikely(validate_data_size(ctx, direct, req) != 0)) { - SSI_LOG_ERR("Unsupported crypt/assoc len %d/%d.\n", - req->cryptlen, req->assoclen); + dev_err(dev, "Unsupported crypt/assoc len %d/%d.\n", + req->cryptlen, req->assoclen); crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN); return -EINVAL; } @@ -2010,7 +2031,8 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction if (ctx->cipher_mode == DRV_CIPHER_CCM) { rc = config_ccm_adata(req); if (unlikely(rc != 0)) { - SSI_LOG_ERR("config_ccm_adata() returned with a failure %d!", rc); + dev_dbg(dev, "config_ccm_adata() returned with a failure %d!", + rc); goto exit; } } else { @@ -2024,7 +2046,8 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction if (ctx->cipher_mode == DRV_CIPHER_GCTR) { rc = config_gcm_context(req); if (unlikely(rc != 0)) { - SSI_LOG_ERR("config_gcm_context() returned with a failure %d!", rc); + dev_dbg(dev, "config_gcm_context() returned with a failure %d!", + rc); goto exit; } } @@ -2032,7 +2055,7 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction rc = ssi_buffer_mgr_map_aead_request(ctx->drvdata, req); if (unlikely(rc != 0)) { - SSI_LOG_ERR("map_request() failed\n"); + dev_err(dev, "map_request() failed\n"); goto exit; } @@ -2088,7 +2111,7 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction break; #endif default: - SSI_LOG_ERR("Unsupported authenc (%d)\n", ctx->auth_mode); + dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode); ssi_buffer_mgr_unmap_aead_request(dev, req); rc = -ENOTSUPP; goto exit; @@ -2099,7 +2122,7 @@ static int ssi_aead_process(struct aead_request *req, enum drv_crypto_direction rc = send_request(ctx->drvdata, &ssi_req, desc, seq_len, 1); if (unlikely(rc != -EINPROGRESS)) { - SSI_LOG_ERR("send_request() failed (rc=%d)\n", rc); + dev_err(dev, "send_request() failed (rc=%d)\n", rc); ssi_buffer_mgr_unmap_aead_request(dev, req); } @@ -2132,10 +2155,13 @@ static int ssi_rfc4309_ccm_encrypt(struct aead_request *req) /* Very similar to ssi_aead_encrypt() above. */ struct aead_req_ctx *areq_ctx = aead_request_ctx(req); + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); int rc = -EINVAL; if (!valid_assoclen(req)) { - SSI_LOG_ERR("invalid Assoclen:%u\n", req->assoclen); + dev_err(dev, "invalid Assoclen:%u\n", req->assoclen); goto out; } @@ -2176,13 +2202,14 @@ static int ssi_aead_decrypt(struct aead_request *req) #if SSI_CC_HAS_AES_CCM static int ssi_rfc4309_ccm_decrypt(struct aead_request *req) { - /* Very similar to ssi_aead_decrypt() above. */ - + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); struct aead_req_ctx *areq_ctx = aead_request_ctx(req); int rc = -EINVAL; if (!valid_assoclen(req)) { - SSI_LOG_ERR("invalid Assoclen:%u\n", req->assoclen); + dev_err(dev, "invalid Assoclen:%u\n", req->assoclen); goto out; } @@ -2207,8 +2234,9 @@ out: static int ssi_rfc4106_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); - SSI_LOG_DEBUG("%s() keylen %d, key %p\n", __func__, keylen, key); + dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key); if (keylen < 4) return -EINVAL; @@ -2222,8 +2250,9 @@ static int ssi_rfc4106_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsign static int ssi_rfc4543_gcm_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); - SSI_LOG_DEBUG("%s() keylen %d, key %p\n", __func__, keylen, key); + dev_dbg(dev, "%s() keylen %d, key %p\n", __func__, keylen, key); if (keylen < 4) return -EINVAL; @@ -2256,7 +2285,10 @@ static int ssi_gcm_setauthsize(struct crypto_aead *authenc, static int ssi_rfc4106_gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - SSI_LOG_DEBUG("authsize %d\n", authsize); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); + struct device *dev = drvdata_to_dev(ctx->drvdata); + + dev_dbg(dev, "authsize %d\n", authsize); switch (authsize) { case 8: @@ -2273,7 +2305,10 @@ static int ssi_rfc4106_gcm_setauthsize(struct crypto_aead *authenc, static int ssi_rfc4543_gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - SSI_LOG_DEBUG("authsize %d\n", authsize); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(authenc); + struct device *dev = drvdata_to_dev(ctx->drvdata); + + dev_dbg(dev, "authsize %d\n", authsize); if (authsize != 16) return -EINVAL; @@ -2285,11 +2320,14 @@ static int ssi_rfc4106_gcm_encrypt(struct aead_request *req) { /* Very similar to ssi_aead_encrypt() above. */ + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); struct aead_req_ctx *areq_ctx = aead_request_ctx(req); int rc = -EINVAL; if (!valid_assoclen(req)) { - SSI_LOG_ERR("invalid Assoclen:%u\n", req->assoclen); + dev_err(dev, "invalid Assoclen:%u\n", req->assoclen); goto out; } @@ -2337,11 +2375,14 @@ static int ssi_rfc4106_gcm_decrypt(struct aead_request *req) { /* Very similar to ssi_aead_decrypt() above. */ + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + struct ssi_aead_ctx *ctx = crypto_aead_ctx(tfm); + struct device *dev = drvdata_to_dev(ctx->drvdata); struct aead_req_ctx *areq_ctx = aead_request_ctx(req); int rc = -EINVAL; if (!valid_assoclen(req)) { - SSI_LOG_ERR("invalid Assoclen:%u\n", req->assoclen); + dev_err(dev, "invalid Assoclen:%u\n", req->assoclen); goto out; } @@ -2641,16 +2682,17 @@ static struct ssi_alg_template aead_algs[] = { #endif /*SSI_CC_HAS_AES_GCM*/ }; -static struct ssi_crypto_alg *ssi_aead_create_alg(struct ssi_alg_template *template) +static struct ssi_crypto_alg *ssi_aead_create_alg( + struct ssi_alg_template *template, + struct device *dev) { struct ssi_crypto_alg *t_alg; struct aead_alg *alg; t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); - if (!t_alg) { - SSI_LOG_ERR("failed to allocate t_alg\n"); + if (!t_alg) return ERR_PTR(-ENOMEM); - } + alg = &template->template_aead; snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name); @@ -2700,6 +2742,7 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata) struct ssi_crypto_alg *t_alg; int rc = -ENOMEM; int alg; + struct device *dev = drvdata_to_dev(drvdata); aead_handle = kmalloc(sizeof(*aead_handle), GFP_KERNEL); if (!aead_handle) { @@ -2713,29 +2756,30 @@ int ssi_aead_alloc(struct ssi_drvdata *drvdata) aead_handle->sram_workspace_addr = ssi_sram_mgr_alloc( drvdata, MAX_HMAC_DIGEST_SIZE); if (aead_handle->sram_workspace_addr == NULL_SRAM_ADDR) { - SSI_LOG_ERR("SRAM pool exhausted\n"); + dev_err(dev, "SRAM pool exhausted\n"); rc = -ENOMEM; goto fail1; } /* Linux crypto */ for (alg = 0; alg < ARRAY_SIZE(aead_algs); alg++) { - t_alg = ssi_aead_create_alg(&aead_algs[alg]); + t_alg = ssi_aead_create_alg(&aead_algs[alg], dev); if (IS_ERR(t_alg)) { rc = PTR_ERR(t_alg); - SSI_LOG_ERR("%s alg allocation failed\n", - aead_algs[alg].driver_name); + dev_err(dev, "%s alg allocation failed\n", + aead_algs[alg].driver_name); goto fail1; } t_alg->drvdata = drvdata; rc = crypto_register_aead(&t_alg->aead_alg); if (unlikely(rc != 0)) { - SSI_LOG_ERR("%s alg registration failed\n", - t_alg->aead_alg.base.cra_driver_name); + dev_err(dev, "%s alg registration failed\n", + t_alg->aead_alg.base.cra_driver_name); goto fail2; } else { list_add_tail(&t_alg->entry, &aead_handle->aead_list); - SSI_LOG_DEBUG("Registered %s\n", t_alg->aead_alg.base.cra_driver_name); + dev_dbg(dev, "Registered %s\n", + t_alg->aead_alg.base.cra_driver_name); } } diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c index 8fd588d090fa..dca3ce84d043 100644 --- a/drivers/staging/ccree/ssi_buffer_mgr.c +++ b/drivers/staging/ccree/ssi_buffer_mgr.c @@ -33,14 +33,10 @@ #include "ssi_hash.h" #include "ssi_aead.h" -#ifdef CC_DEBUG #define GET_DMA_BUFFER_TYPE(buff_type) ( \ ((buff_type) == SSI_DMA_BUF_NULL) ? "BUF_NULL" : \ ((buff_type) == SSI_DMA_BUF_DLLI) ? "BUF_DLLI" : \ ((buff_type) == SSI_DMA_BUF_MLLI) ? "BUF_MLLI" : "BUF_INVALID") -#else -#define GET_DMA_BUFFER_TYPE(buff_type) -#endif enum dma_buffer_type { DMA_NULL_TYPE = -1, @@ -76,7 +72,8 @@ struct buffer_array { * @lbytes: [OUT] Returns the amount of bytes at the last entry */ static unsigned int ssi_buffer_mgr_get_sgl_nents( - struct scatterlist *sg_list, unsigned int nbytes, u32 *lbytes, bool *is_chained) + struct device *dev, struct scatterlist *sg_list, + unsigned int nbytes, u32 *lbytes, bool *is_chained) { unsigned int nents = 0; @@ -93,7 +90,7 @@ static unsigned int ssi_buffer_mgr_get_sgl_nents( *is_chained = true; } } - SSI_LOG_DEBUG("nents %d last bytes %d\n", nents, *lbytes); + dev_dbg(dev, "nents %d last bytes %d\n", nents, *lbytes); return nents; } @@ -129,20 +126,20 @@ void ssi_buffer_mgr_zero_sgl(struct scatterlist *sgl, u32 data_len) * @direct: */ void ssi_buffer_mgr_copy_scatterlist_portion( - u8 *dest, struct scatterlist *sg, - u32 to_skip, u32 end, - enum ssi_sg_cpy_direct direct) + struct device *dev, u8 *dest, + struct scatterlist *sg, u32 to_skip, + u32 end, enum ssi_sg_cpy_direct direct) { u32 nents, lbytes; - nents = ssi_buffer_mgr_get_sgl_nents(sg, end, &lbytes, NULL); + nents = ssi_buffer_mgr_get_sgl_nents(dev, sg, end, &lbytes, NULL); sg_copy_buffer(sg, nents, (void *)dest, (end - to_skip + 1), to_skip, (direct == SSI_SG_TO_BUF)); } static inline int ssi_buffer_mgr_render_buff_to_mlli( - dma_addr_t buff_dma, u32 buff_size, u32 *curr_nents, - u32 **mlli_entry_pp) + struct device *dev, dma_addr_t buff_dma, u32 buff_size, + u32 *curr_nents, u32 **mlli_entry_pp) { u32 *mlli_entry_p = *mlli_entry_pp; u32 new_nents; @@ -156,9 +153,9 @@ static inline int ssi_buffer_mgr_render_buff_to_mlli( while (buff_size > CC_MAX_MLLI_ENTRY_SIZE) { cc_lli_set_addr(mlli_entry_p, buff_dma); cc_lli_set_size(mlli_entry_p, CC_MAX_MLLI_ENTRY_SIZE); - SSI_LOG_DEBUG("entry[%d]: single_buff=0x%08X size=%08X\n", *curr_nents, - mlli_entry_p[LLI_WORD0_OFFSET], - mlli_entry_p[LLI_WORD1_OFFSET]); + dev_dbg(dev, "entry[%d]: single_buff=0x%08X size=%08X\n", + *curr_nents, mlli_entry_p[LLI_WORD0_OFFSET], + mlli_entry_p[LLI_WORD1_OFFSET]); buff_dma += CC_MAX_MLLI_ENTRY_SIZE; buff_size -= CC_MAX_MLLI_ENTRY_SIZE; mlli_entry_p = mlli_entry_p + 2; @@ -167,9 +164,9 @@ static inline int ssi_buffer_mgr_render_buff_to_mlli( /*Last entry */ cc_lli_set_addr(mlli_entry_p, buff_dma); cc_lli_set_size(mlli_entry_p, buff_size); - SSI_LOG_DEBUG("entry[%d]: single_buff=0x%08X size=%08X\n", *curr_nents, - mlli_entry_p[LLI_WORD0_OFFSET], - mlli_entry_p[LLI_WORD1_OFFSET]); + dev_dbg(dev, "entry[%d]: single_buff=0x%08X size=%08X\n", + *curr_nents, mlli_entry_p[LLI_WORD0_OFFSET], + mlli_entry_p[LLI_WORD1_OFFSET]); mlli_entry_p = mlli_entry_p + 2; *mlli_entry_pp = mlli_entry_p; (*curr_nents)++; @@ -177,8 +174,9 @@ static inline int ssi_buffer_mgr_render_buff_to_mlli( } static inline int ssi_buffer_mgr_render_scatterlist_to_mlli( - struct scatterlist *sgl, u32 sgl_data_len, u32 sgl_offset, - u32 *curr_nents, u32 **mlli_entry_pp) + struct device *dev, struct scatterlist *sgl, + u32 sgl_data_len, u32 sgl_offset, u32 *curr_nents, + u32 **mlli_entry_pp) { struct scatterlist *curr_sgl = sgl; u32 *mlli_entry_p = *mlli_entry_pp; @@ -192,8 +190,8 @@ static inline int ssi_buffer_mgr_render_scatterlist_to_mlli( sgl_data_len; sgl_data_len -= entry_data_len; rc = ssi_buffer_mgr_render_buff_to_mlli( - sg_dma_address(curr_sgl) + sgl_offset, entry_data_len, - curr_nents, &mlli_entry_p); + dev, sg_dma_address(curr_sgl) + sgl_offset, + entry_data_len, curr_nents, &mlli_entry_p); if (rc != 0) return rc; @@ -212,14 +210,14 @@ static int ssi_buffer_mgr_generate_mlli( u32 total_nents = 0, prev_total_nents = 0; int rc = 0, i; - SSI_LOG_DEBUG("NUM of SG's = %d\n", sg_data->num_of_buffers); + dev_dbg(dev, "NUM of SG's = %d\n", sg_data->num_of_buffers); /* Allocate memory from the pointed pool */ mlli_params->mlli_virt_addr = dma_pool_alloc( mlli_params->curr_pool, GFP_KERNEL, &mlli_params->mlli_dma_addr); if (unlikely(!mlli_params->mlli_virt_addr)) { - SSI_LOG_ERR("dma_pool_alloc() failed\n"); + dev_err(dev, "dma_pool_alloc() failed\n"); rc = -ENOMEM; goto build_mlli_exit; } @@ -229,12 +227,12 @@ static int ssi_buffer_mgr_generate_mlli( for (i = 0; i < sg_data->num_of_buffers; i++) { if (sg_data->type[i] == DMA_SGL_TYPE) rc = ssi_buffer_mgr_render_scatterlist_to_mlli( - sg_data->entry[i].sgl, - sg_data->total_data_len[i], sg_data->offset[i], &total_nents, - &mlli_p); + dev, sg_data->entry[i].sgl, + sg_data->total_data_len[i], sg_data->offset[i], + &total_nents, &mlli_p); else /*DMA_BUFF_TYPE*/ rc = ssi_buffer_mgr_render_buff_to_mlli( - sg_data->entry[i].buffer_dma, + dev, sg_data->entry[i].buffer_dma, sg_data->total_data_len[i], &total_nents, &mlli_p); if (rc != 0) @@ -254,26 +252,23 @@ static int ssi_buffer_mgr_generate_mlli( /* Set MLLI size for the bypass operation */ mlli_params->mlli_len = (total_nents * LLI_ENTRY_BYTE_SIZE); - SSI_LOG_DEBUG("MLLI params: " - "virt_addr=%pK dma_addr=%pad mlli_len=0x%X\n", - mlli_params->mlli_virt_addr, - mlli_params->mlli_dma_addr, - mlli_params->mlli_len); + dev_dbg(dev, "MLLI params: virt_addr=%pK dma_addr=%pad mlli_len=0x%X\n", + mlli_params->mlli_virt_addr, &mlli_params->mlli_dma_addr, + mlli_params->mlli_len); build_mlli_exit: |