crypto: start to fix ixp4xx
cover crypto: start to fix ixp4xx
Hello
Loading the ixp4xx crypto driver exhibits lots of error. All algorithm fail selftests with different reasons. This series start to fixes some of thoses problem.
Corentin Labbe (11):
crypto: ixp4xx: dma_unmap the correct address
crypto: ixp4xx: update IV after requests
crypto: ixp4xx: fallback when having more than one SG
crypto: ixp4xx: convert unsigned to unsigned int
crypto: ixp4xx: convert all printk to dev_xxx
crypto: ixp4xx: whitespace fixes
crypto: ixp4xx: Do not initialize static to NULL
crypto: ixp4xx: remove brackets from single statement
crypto: ixp4xx: Correct functions alignment
MAINTAINERS: add ixp4xx_crypto to the right arch list
MAINTAINERS: add myself as maintainer of ixp4xx_crypto
MAINTAINERS | 7 + drivers/crypto/Kconfig | 5 + drivers/crypto/ixp4xx_crypto.c | 277 +++++++++++++++++++++------------ 3 files changed, 188 insertions(+), 101 deletions(-)
Signature · 1 line
2.26.3
PATCH 1/11 crypto: ixp4xx: dma_unmap the correct address
Testing ixp4xx_crypto with CONFIG_DMA_API_DEBUG lead to the following error:
DMA-API: platform ixp4xx_crypto.0: device driver tries to free DMA memory it has not allocated [device address=0x0000000000000000] [size=24 bytes]
This is due to dma_unmap using the wrong address.
--- drivers/crypto/ixp4xx_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ixp4xx_crypto.c +1 -1
@@ -330,7 +330,7 @@ static void free_buf_chain(struct device *dev, struct buffer_desc *buf, buf1 = buf->next; phys1 = buf->phys_next; -dma_unmap_single (dev, buf->phys_next, buf->buf_len, buf->dir); +dma_unmap_single (dev, buf->phys_addr, buf->buf_len, buf->dir);dma_pool_free (buffer_pool, buf, phys); buf = buf1; phys = phys1;
Signature · 1 line
2.26.3
PATCH 2/11 crypto: ixp4xx: update IV after requests
In reply to Corentin LabbeCrypto selftests fail on ixp4xx since it do not update IV after skcipher requests.
--- drivers/crypto/ixp4xx_crypto.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/crypto/ixp4xx_crypto.c +22 -0
@@ -149,6 +149,8 @@ struct crypt_ctl {struct ablk_ctx {struct buffer_desc *src;struct buffer_desc *dst; +u8 iv[MAX_IVLEN ]; +bool encrypt; };struct aead_ctx {
@@ -381,6 +383,20 @@ static void one_packet(dma_addr_t phys)case CTL_FLAG_PERFORM_ABLK : {struct skcipher_request *req = crypt->data.ablk_req;struct ablk_ctx *req_ctx =skcipher_request_ctx (req); +struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req); +unsigned int ivsize =crypto_skcipher_ivsize (tfm); +unsigned int offset; + +if (ivsize >0 ) { + offset = req->cryptlen - ivsize; +if (req_ctx->encrypt) { +scatterwalk_map_and_copy (req->iv, req->dst, + offset, ivsize,0 ); + }else { +memcpy (req->iv, req_ctx->iv, ivsize); +memzero_explicit (req_ctx->iv, ivsize); + } + }if (req_ctx->dst) {free_buf_chain (dev, req_ctx->dst, crypt->dst_buf);
@@ -876,6 +892,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)struct ablk_ctx *req_ctx =skcipher_request_ctx (req);struct buffer_desc src_hook;struct device *dev = &pdev->dev; +unsigned int offset;gfp_t flags = req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ?GFP_KERNEL :GFP_ATOMIC ;
@@ -885,6 +902,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)return -EAGAIN ; dir = encrypt ? &ctx->encrypt : &ctx->decrypt; + req_ctx->encrypt = encrypt; crypt =get_crypt_desc ();if (!crypt)
@@ -900,6 +918,10 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)BUG_ON (ivsize && !req->iv);memcpy (crypt->iv, req->iv, ivsize); +if (ivsize >0 && !encrypt) { + offset = req->cryptlen - ivsize; +scatterwalk_map_and_copy (req_ctx->iv, req->src, offset, ivsize,0 ); + }if (req->src != req->dst) {struct buffer_desc dst_hook; crypt->mode |=NPE_OP_NOT_IN_PLACE ;
Signature · 1 line
2.26.3
PATCH 3/11 crypto: ixp4xx: fallback when having more than one SG
In reply to Corentin LabbeTesting ixp4xx_crypto lead to:
alg: skcipher: ecb(des)-ixp4xx encryption overran dst buffer on test vector 0, cfg="two even aligned splits"
The HW overwrites destination always when sg_nents() > 1.
The problem seems that the HW always write areq->cryptlen bytes on the last SG.
A comment in driver's code seems to give a clue that multiple SG was not planned "This was never tested by Intel for more than one dst buffer, I think". So let's add a fallback for this situation.
--- drivers/crypto/Kconfig | 5 +++ drivers/crypto/ixp4xx_crypto.c | 56 ++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-)
drivers/crypto/Kconfig +5 -0
@@ -344,6 +344,11 @@ config CRYPTO_DEV_TALITOS2 config CRYPTO_DEV_IXP4XX tristate "Driver for IXP4xx crypto hardware acceleration" depends on ARCH_IXP4XX && IXP4XX_QMGR && IXP4XX_NPE + select CRYPTO_AES + select CRYPTO_DES + select CRYPTO_ECB + select CRYPTO_CBC + select CRYPTO_CTR select CRYPTO_LIB_DES select CRYPTO_AEAD select CRYPTO_AUTHENC
drivers/crypto/ixp4xx_crypto.c +53 -3
104 lines not on this page · raw message
Signature · 1 line
2.26.3
PATCH 4/11 crypto: ixp4xx: convert unsigned to unsigned int
In reply to Corentin LabbeFixes all issues reported by checkpatch about "unsigned", lets convert them to unsigned int.
--- drivers/crypto/ixp4xx_crypto.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/crypto/ixp4xx_crypto.c +10 -10
@@ -136,7 +136,7 @@ struct crypt_ctl {u32 crypto_ctx;/* NPE Crypto Param structure address */ /* Used by Host: 4*4 bytes*/ -unsigned ctl_flags; +unsigned int ctl_flags;union {struct skcipher_request *ablk_req;struct aead_request *aead_req;
@@ -184,7 +184,7 @@ struct ixp_ctx {u8 enckey[MAX_KEYLEN ];u8 salt[MAX_IVLEN ];u8 nonce[CTR_RFC3686_NONCE_SIZE ]; -unsigned salted; +unsigned int salted;atomic_t configuring;struct completion completion;struct crypto_skcipher *fallback_tfm;
@@ -695,8 +695,8 @@ static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,return 0 ; } -static int setup_auth (struct crypto_tfm *tfm,int encrypt,unsigned authsize, -const u8 *key,int key_len,unsigned digest_len) +static int setup_auth (struct crypto_tfm *tfm,int encrypt,unsigned int authsize, +const u8 *key,int key_len,unsigned int digest_len) {u32 itarget, otarget, npe_ctx_addr;unsigned char *cinfo;
@@ -823,12 +823,12 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt, }static struct buffer_desc *chainup_buffers (struct device *dev, -struct scatterlist *sg,unsigned nbytes, +struct scatterlist *sg,unsigned int nbytes,struct buffer_desc *buf,gfp_t flags,enum dma_data_direction dir) {for (; nbytes >0 ; sg =sg_next (sg)) { -unsigned len =min (nbytes, sg->length); +unsigned int len =min (nbytes, sg->length);struct buffer_desc *next_buf;dma_addr_t next_buf_phys;void *ptr;
@@ -930,7 +930,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt) {struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct ixp_ctx *ctx =crypto_skcipher_ctx (tfm); -unsigned ivsize =crypto_skcipher_ivsize (tfm); +unsigned int ivsize =crypto_skcipher_ivsize (tfm);struct ix_sa_dir *dir;struct crypt_ctl *crypt;unsigned int nbytes = req->cryptlen;
@@ -1045,8 +1045,8 @@ static int aead_perform(struct aead_request *req, int encrypt, {struct crypto_aead *tfm =crypto_aead_reqtfm (req);struct ixp_ctx *ctx =crypto_aead_ctx (tfm); -unsigned ivsize =crypto_aead_ivsize (tfm); -unsigned authsize =crypto_aead_authsize (tfm); +unsigned int ivsize =crypto_aead_ivsize (tfm); +unsigned int authsize =crypto_aead_authsize (tfm);struct ix_sa_dir *dir;struct crypt_ctl *crypt;unsigned int cryptlen;
@@ -1157,7 +1157,7 @@ static int aead_perform(struct aead_request *req, int encrypt,static int aead_setup (struct crypto_aead *tfm,unsigned int authsize) {struct ixp_ctx *ctx =crypto_aead_ctx (tfm); -unsigned digest_len =crypto_aead_maxauthsize (tfm); +unsigned int digest_len =crypto_aead_maxauthsize (tfm);int ret;if (!ctx->enckey_len && !ctx->authkey_len)
Signature · 1 line
2.26.3
PATCH 5/11 crypto: ixp4xx: convert all printk to dev_xxx
In reply to Corentin LabbeConvert all old printk to dev_xxx.
--- drivers/crypto/ixp4xx_crypto.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/crypto/ixp4xx_crypto.c +6 -8
@@ -452,7 +452,7 @@ static int init_ixp_crypto(struct device *dev)if (! ( ~(*IXP4XX_EXP_CFG2 ) & (IXP4XX_FEATURE_HASH |IXP4XX_FEATURE_AES |IXP4XX_FEATURE_DES ))) { -printk (KERN_ERR "ixp_crypto: No HW crypto available\n" ); +dev_err (dev,"ixp_crypto: No HW crypto available\n" );return ret; } npe_c =npe_request (NPE_ID );
@@ -475,8 +475,7 @@ static int init_ixp_crypto(struct device *dev)switch ((msg[1 ]>>16 ) &0xff ) {case 3 : -printk (KERN_WARNING "Firmware of %s lacks AES support\n" , -npe_name (npe_c)); +dev_warn (dev,"Firmware of %s lacks AES support\n" ,npe_name (npe_c)); support_aes =0 ;break ;case 4 :
@@ -484,8 +483,7 @@ static int init_ixp_crypto(struct device *dev) support_aes =1 ;break ;default : -printk (KERN_ERR "Firmware of %s lacks crypto support\n" , -npe_name (npe_c)); +dev_err (dev,"Firmware of %s lacks crypto support\n" ,npe_name (npe_c)); ret = -ENODEV ; goto npe_release; }
@@ -521,7 +519,7 @@ static int init_ixp_crypto(struct device *dev)return 0 ; npe_error: -printk (KERN_ERR "%s not responding\n" ,npe_name (npe_c)); +dev_err (dev,"%s not responding\n" ,npe_name (npe_c)); ret = -EIO ; err:dma_pool_destroy (ctx_pool);
@@ -1487,7 +1485,7 @@ static int __init ixp_module_init(void) cra->base.cra_alignmask =3 ; cra->base.cra_priority =300 ;if (crypto_register_skcipher (cra)) -printk (KERN_ERR "Failed to register '%s'\n" , +dev_err (&pdev->dev,"Failed to register '%s'\n" , cra->base.cra_name);else ixp4xx_algos[i].registered =1 ;
@@ -1520,7 +1518,7 @@ static int __init ixp_module_init(void) cra->base.cra_priority =300 ;if (crypto_register_aead (cra)) -printk (KERN_ERR "Failed to register '%s'\n" , +dev_err (&pdev->dev,"Failed to register '%s'\n" , cra->base.cra_driver_name);else ixp4xx_aeads[i].registered =1 ;
Signature · 1 line
2.26.3
PATCH 6/11 crypto: ixp4xx: whitespace fixes
In reply to Corentin LabbeFixes all whitespace issues reported by checkpatch
--- drivers/crypto/ixp4xx_crypto.c | 43 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-)
drivers/crypto/ixp4xx_crypto.c +24 -19
@@ -213,6 +213,7 @@ static const struct ix_hash_algo hash_alg_md5 = { .icv = "\x01\x23\x45\x67\x89\xAB\xCD\xEF" "\xFE\xDC\xBA\x98\x76\x54\x32\x10", }; +static const struct ix_hash_algo hash_alg_sha1 = { .cfgword =0x00000005 , .icv ="\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA"
@@ -244,12 +245,12 @@ static inline struct crypt_ctl *crypt_phys2virt(dma_addr_t phys)static inline u32 cipher_cfg_enc (struct crypto_tfm *tfm) { - return container_of(tfm->__crt_alg, struct ixp_alg,crypto.base)->cfg_enc; + return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_enc; }static inline u32 cipher_cfg_dec (struct crypto_tfm *tfm) { - return container_of(tfm->__crt_alg, struct ixp_alg,crypto.base)->cfg_dec; + return container_of(tfm->__crt_alg, struct ixp_alg, crypto.base)->cfg_dec; }static inline const struct ix_hash_algo *ix_hash (struct crypto_tfm *tfm)
@@ -260,6 +261,7 @@ static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm)static int setup_crypt_desc (void ) {struct device *dev = &pdev->dev; +BUILD_BUG_ON (sizeof (struct crypt_ctl ) !=64 ); crypt_virt = dma_alloc_coherent(dev, NPE_QLEN * sizeof(struct crypt_ctl),
@@ -290,7 +292,7 @@ static struct crypt_ctl *get_crypt_desc(void) idx =0 ; crypt_virt[i].ctl_flags =CTL_FLAG_USED ;spin_unlock_irqrestore (&desc_lock, flags); -return crypt_virt +i; +return crypt_virt + i; }else {spin_unlock_irqrestore (&desc_lock, flags);return NULL ;
@@ -318,7 +320,7 @@ static struct crypt_ctl *get_crypt_desc_emerg(void) idx =NPE_QLEN ; crypt_virt[i].ctl_flags =CTL_FLAG_USED ;spin_unlock_irqrestore (&emerg_lock, flags); -return crypt_virt +i; +return crypt_virt + i; }else {spin_unlock_irqrestore (&emerg_lock, flags);return NULL ;
@@ -417,7 +419,7 @@ static void one_packet(dma_addr_t phys)break ;case CTL_FLAG_GEN_REVAES : ctx =crypto_tfm_ctx (crypt->data.tfm); - *(u32 *)ctx->decrypt.npe_ctx &=cpu_to_be32 (~CIPH_ENCR ); + *(u32 *)ctx->decrypt.npe_ctx &=cpu_to_be32 (~CIPH_ENCR );if (atomic_dec_and_test (&ctx->configuring))complete (&ctx->completion);break ;
@@ -436,8 +438,9 @@ static void crypto_done_action(unsigned long arg) {int i; -for (i=0 ; i<4 ; i++) { +for (i =0 ; i <4 ; i++) {dma_addr_t phys =qmgr_get_entry (RECV_QID ); +if (!phys)return ;one_packet (phys);
@@ -473,7 +476,7 @@ static int init_ixp_crypto(struct device *dev) goto npe_error; } -switch ((msg[1 ]>>16 ) &0xff ) { +switch ((msg[1 ] >>16 ) &0xff ) {case 3 :dev_warn (dev,"Firmware of %s lacks AES support\n" ,npe_name (npe_c)); support_aes =0 ;
@@ -619,6 +622,7 @@ static int init_tfm_aead(struct crypto_aead *tfm)static void exit_tfm (struct crypto_tfm *tfm) {struct ixp_ctx *ctx =crypto_tfm_ctx (tfm); +free_sa_dir (&ctx->encrypt);free_sa_dir (&ctx->decrypt); }
@@ -709,11 +713,11 @@ static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned int authsize algo =ix_hash (tfm);/* write cfg word to cryptinfo */ - cfgword = algo->cfgword | ( authsize <<6 );/* (authsize/4) << 8 */ + cfgword = algo->cfgword | (authsize <<6 );/* (authsize/4) << 8 */ #ifndef __ARMEB__ cfgword ^=0xAA000000 ;/* change the "byte swap" flags */ #endif - *(u32 *)cinfo =cpu_to_be32 (cfgword); + *(u32 *)cinfo =cpu_to_be32 (cfgword); cinfo +=sizeof (cfgword);/* write ICV to cryptinfo */
@@ -750,7 +754,7 @@ static int gen_rev_aes_key(struct crypto_tfm *tfm)if (!crypt) {return -EAGAIN ; } - *(u32 *)dir->npe_ctx |=cpu_to_be32 (CIPH_ENCR ); + *(u32 *)dir->npe_ctx |=cpu_to_be32 (CIPH_ENCR ); crypt->data.tfm = tfm; crypt->crypt_offs =0 ;
@@ -802,21 +806,21 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt,return err; }/* write cfg word to cryptinfo */ - *(u32 *)cinfo =cpu_to_be32 (cipher_cfg); + *(u32 *)cinfo =cpu_to_be32 (cipher_cfg); cinfo +=sizeof (cipher_cfg);/* write cipher key to cryptinfo */ memcpy (cinfo, key, key_len);/* NPE wants keylen set to DES3_EDE_KEY_SIZE even for single DES */ if (key_len <DES3_EDE_KEY_SIZE && !(cipher_cfg &MOD_AES )) { -memset (cinfo + key_len,0 ,DES3_EDE_KEY_SIZE -key_len); +memset (cinfo + key_len,0 ,DES3_EDE_KEY_SIZE - key_len); key_len =DES3_EDE_KEY_SIZE ; } dir->npe_ctx_idx =sizeof (cipher_cfg) + key_len; dir->npe_mode |=NPE_OP_CRYPT_ENABLE ; -if ((cipher_cfg &MOD_AES ) && !encrypt) { +if ((cipher_cfg &MOD_AES ) && !encrypt)return gen_rev_aes_key (tfm); - } +return 0 ; }
@@ -971,6 +975,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt) }if (req->src != req->dst) {struct buffer_desc dst_hook; + crypt->mode |=NPE_OP_NOT_IN_PLACE ;/* This was never tested by Intel * for more than one dst buffer, I think. */
@@ -1025,7 +1030,7 @@ static int ablk_rfc3686_crypt(struct skcipher_request *req)int ret;/* set up counter block */ -memcpy (iv, ctx->nonce,CTR_RFC3686_NONCE_SIZE ); +memcpy (iv, ctx->nonce,CTR_RFC3686_NONCE_SIZE );memcpy (iv +CTR_RFC3686_NONCE_SIZE , info,CTR_RFC3686_IV_SIZE );/* initialize counter portion of counter block */
@@ -1067,7 +1072,7 @@ static int aead_perform(struct aead_request *req, int encrypt, }else { dir = &ctx->decrypt;/* req->cryptlen includes the authsize when decrypting */ - cryptlen = req->cryptlen -authsize; + cryptlen = req->cryptlen - authsize; eff_cryptlen -= authsize; } crypt =get_crypt_desc ();
@@ -1188,7 +1193,7 @@ static int aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) {int max =crypto_aead_maxauthsize (tfm) >>2 ; -if ((authsize>>2 ) <1 || (authsize>>2 ) > max || (authsize &3 )) +if ((authsize >>2 ) <1 || (authsize >>2 ) > max || (authsize &3 ))return -EINVAL ;return aead_setup (tfm, authsize); }
@@ -1453,7 +1458,7 @@ static int __init ixp_module_init(void)platform_device_unregister (pdev);return err; } -for (i=0 ; i< num; i++) { +for (i =0 ; i < num; i++) {struct skcipher_alg *cra = &ixp4xx_algos[i].crypto; if (snprintf(cra->base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
@@ -1536,7 +1541,7 @@ static void __exit ixp_module_exit(void)crypto_unregister_aead (&ixp4xx_aeads[i].crypto); } -for (i=0 ; i< num; i++) { +for (i =0 ; i < num; i++) {if (ixp4xx_algos[i].registered)crypto_unregister_skcipher (&ixp4xx_algos[i].crypto); }
Signature · 1 line
2.26.3
PATCH 7/11 crypto: ixp4xx: Do not initialize static to NULL
In reply to Corentin LabbeThis patch fixes all checkpatch report about static init.
--- drivers/crypto/ixp4xx_crypto.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/ixp4xx_crypto.c +4 -4
@@ -221,10 +221,10 @@ static const struct ix_hash_algo hash_alg_sha1 = { };static struct npe *npe_c; -static struct dma_pool *buffer_pool =NULL ; -static struct dma_pool *ctx_pool =NULL ; +static struct dma_pool *buffer_pool; +static struct dma_pool *ctx_pool; -static struct crypt_ctl *crypt_virt =NULL ; +static struct crypt_ctl *crypt_virt;static dma_addr_t crypt_phys;static int support_aes =1 ;
@@ -275,7 +275,7 @@ static DEFINE_SPINLOCK(desc_lock);static struct crypt_ctl *get_crypt_desc (void ) {int i; -static int idx =0 ; +static int idx;unsigned long flags;spin_lock_irqsave (&desc_lock, flags);
Signature · 1 line
2.26.3
PATCH 8/11 crypto: ixp4xx: remove brackets from single statement
In reply to Corentin Labbefixes all single statement issues reported by checkpatch
--- drivers/crypto/ixp4xx_crypto.c | 47 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-)
drivers/crypto/ixp4xx_crypto.c +21 -26
@@ -378,9 +378,9 @@ static void one_packet(dma_addr_t phys)free_buf_chain (dev, req_ctx->src, crypt->src_buf);free_buf_chain (dev, req_ctx->dst, crypt->dst_buf); -if (req_ctx->hmac_virt) { +if (req_ctx->hmac_virt)finish_scattered_hmac (crypt); - } + req->base.complete (&req->base, failed);break ; }
@@ -402,9 +402,9 @@ static void one_packet(dma_addr_t phys) } } -if (req_ctx->dst) { +if (req_ctx->dst)free_buf_chain (dev, req_ctx->dst, crypt->dst_buf); - } +free_buf_chain (dev, req_ctx->src, crypt->src_buf); req->base.complete (&req->base, failed);break ;
@@ -497,14 +497,14 @@ static int init_ixp_crypto(struct device *dev) buffer_pool =dma_pool_create ("buffer" , dev,sizeof (struct buffer_desc ),32 ,0 ); ret = -ENOMEM ; -if (!buffer_pool) { +if (!buffer_pool) goto err; - } + ctx_pool =dma_pool_create ("context" , dev,NPE_CTX_LEN ,16 ,0 ); -if (!ctx_pool) { +if (!ctx_pool) goto err; - } + ret =qmgr_request_queue (SEND_QID ,NPE_QLEN_TOTAL ,0 ,0 ,"ixp_crypto:out" ,NULL );if (ret)
@@ -545,11 +545,10 @@ static void release_ixp_crypto(struct device *dev)npe_release (npe_c); -if (crypt_virt) { +if (crypt_virt)dma_free_coherent (dev,NPE_QLEN *sizeof (struct crypt_ctl ), crypt_virt, crypt_phys); - } }static void reset_sa_dir (struct ix_sa_dir *dir)
@@ -562,9 +561,9 @@ static void reset_sa_dir(struct ix_sa_dir *dir)static int init_sa_dir (struct ix_sa_dir *dir) { dir->npe_ctx =dma_pool_alloc (ctx_pool,GFP_KERNEL , &dir->npe_ctx_phys); -if (!dir->npe_ctx) { +if (!dir->npe_ctx)return -ENOMEM ; - } +reset_sa_dir (dir);return 0 ; }
@@ -585,9 +584,9 @@ static int init_tfm(struct crypto_tfm *tfm)if (ret)return ret; ret =init_sa_dir (&ctx->decrypt); -if (ret) { +if (ret)free_sa_dir (&ctx->encrypt); - } +return ret; }
@@ -669,9 +668,8 @@ static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,memcpy (pad, key, key_len);memset (pad + key_len,0 ,HMAC_PAD_BLOCKLEN - key_len); -for (i =0 ; i <HMAC_PAD_BLOCKLEN ; i++) { +for (i =0 ; i <HMAC_PAD_BLOCKLEN ; i++) pad[i] ^= xpad; - } crypt->data.tfm = tfm; crypt->regist_ptr = pad;
@@ -751,9 +749,9 @@ static int gen_rev_aes_key(struct crypto_tfm *tfm)struct ix_sa_dir *dir = &ctx->decrypt; crypt =get_crypt_desc_emerg (); -if (!crypt) { +if (!crypt)return -EAGAIN ; - } + *(u32 *)dir->npe_ctx |=cpu_to_be32 (CIPH_ENCR ); crypt->data.tfm = tfm;
@@ -1004,9 +1002,9 @@ static int ablk_perform(struct skcipher_request *req, int encrypt) free_buf_src:free_buf_chain (dev, req_ctx->src, crypt->src_buf); free_buf_dest: -if (req->src != req->dst) { +if (req->src != req->dst)free_buf_chain (dev, req_ctx->dst, crypt->dst_buf); - } + crypt->ctl_flags =CTL_FLAG_UNUSED ;return -ENOMEM ; }
@@ -1462,14 +1460,11 @@ static int __init ixp_module_init(void)struct skcipher_alg *cra = &ixp4xx_algos[i].crypto;if (snprintf (cra->base.cra_driver_name,CRYPTO_MAX_ALG_NAME , -"%s" IXP_POSTFIX , cra->base.cra_name) >= -CRYPTO_MAX_ALG_NAME ) - { +"%s" IXP_POSTFIX , cra->base.cra_name) >= +CRYPTO_MAX_ALG_NAME )continue ; - } -if (!support_aes && (ixp4xx_algos[i].cfg_enc &MOD_AES )) { +if (!support_aes && (ixp4xx_algos[i].cfg_enc &MOD_AES ))continue ; - }/* block ciphers */ cra->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
Signature · 1 line
2.26.3
PATCH 9/11 crypto: ixp4xx: Correct functions alignment
In reply to Corentin LabbeThis patch fixes all alignment issues reported by checkpatch.
--- drivers/crypto/ixp4xx_crypto.c | 65 ++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 30 deletions(-)
drivers/crypto/ixp4xx_crypto.c +35 -30
@@ -354,8 +354,8 @@ static void finish_scattered_hmac(struct crypt_ctl *crypt)int decryptlen = req->assoclen + req->cryptlen - authsize;if (req_ctx->encrypt) { -scatterwalk_map_and_copy (req_ctx->hmac_virt, - req->dst, decryptlen, authsize,1 ); +scatterwalk_map_and_copy (req_ctx->hmac_virt, req->dst, + decryptlen, authsize,1 ); }dma_pool_free (buffer_pool, req_ctx->hmac_virt, crypt->icv_rev_aes); }
@@ -412,7 +412,7 @@ static void one_packet(dma_addr_t phys)case CTL_FLAG_GEN_ICV : ctx =crypto_tfm_ctx (crypt->data.tfm);dma_pool_free (ctx_pool, crypt->regist_ptr, - crypt->regist_buf->phys_addr); + crypt->regist_buf->phys_addr);dma_pool_free (buffer_pool, crypt->regist_buf, crypt->src_buf);if (atomic_dec_and_test (&ctx->configuring))complete (&ctx->completion);
@@ -494,14 +494,13 @@ static int init_ixp_crypto(struct device *dev)* so assure it is large enough */ BUILD_BUG_ON (SHA1_DIGEST_SIZE >sizeof (struct buffer_desc )); - buffer_pool =dma_pool_create ("buffer" , dev, -sizeof (struct buffer_desc ),32 ,0 ); + buffer_pool =dma_pool_create ("buffer" , dev,sizeof (struct buffer_desc ), +32 ,0 ); ret = -ENOMEM ;if (!buffer_pool) goto err; - ctx_pool =dma_pool_create ("context" , dev, -NPE_CTX_LEN ,16 ,0 ); + ctx_pool =dma_pool_create ("context" , dev,NPE_CTX_LEN ,16 ,0 );if (!ctx_pool) goto err;
@@ -546,9 +545,8 @@ static void release_ixp_crypto(struct device *dev)npe_release (npe_c);if (crypt_virt) -dma_free_coherent (dev, -NPE_QLEN *sizeof (struct crypt_ctl ), - crypt_virt, crypt_phys); +dma_free_coherent (dev,NPE_QLEN *sizeof (struct crypt_ctl ), + crypt_virt, crypt_phys); }static void reset_sa_dir (struct ix_sa_dir *dir)
@@ -641,7 +639,8 @@ static void exit_tfm_aead(struct crypto_aead *tfm) }static int register_chain_var (struct crypto_tfm *tfm,u8 xpad,u32 target, -int init_len,u32 ctx_addr,const u8 *key,int key_len) +int init_len,u32 ctx_addr,const u8 *key, +int key_len) {struct ixp_ctx *ctx =crypto_tfm_ctx (tfm);struct crypt_ctl *crypt;
@@ -735,11 +734,11 @@ static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned int authsize dir->npe_mode |=NPE_OP_HASH_VERIFY ; ret =register_chain_var (tfm,HMAC_OPAD_VALUE , otarget, - init_len, npe_ctx_addr, key, key_len); + init_len, npe_ctx_addr, key, key_len);if (ret)return ret;return register_chain_var (tfm,HMAC_IPAD_VALUE , itarget, - init_len, npe_ctx_addr, key, key_len); + init_len, npe_ctx_addr, key, key_len); }static int gen_rev_aes_key (struct crypto_tfm *tfm)
@@ -770,8 +769,8 @@ static int gen_rev_aes_key(struct crypto_tfm *tfm)return 0 ; } -static int setup_cipher (struct crypto_tfm *tfm,int encrypt, -const u8 *key,int key_len) +static int setup_cipher (struct crypto_tfm *tfm,int encrypt,const u8 *key, +int key_len) {u8 *cinfo;u32 cipher_cfg;
@@ -791,9 +790,15 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt, }if (cipher_cfg &MOD_AES ) {switch (key_len) { -case 16 : keylen_cfg =MOD_AES128 ;break ; -case 24 : keylen_cfg =MOD_AES192 ;break ; -case 32 : keylen_cfg =MOD_AES256 ;break ; +case 16 : + keylen_cfg =MOD_AES128 ; +break ; +case 24 : + keylen_cfg =MOD_AES192 ; +break ; +case 32 : + keylen_cfg =MOD_AES256 ; +break ;default :return -EINVAL ; }
@@ -855,7 +860,7 @@ static struct buffer_desc *chainup_buffers(struct device *dev, }static int ablk_setkey (struct crypto_skcipher *tfm,const u8 *key, -unsigned int key_len) +unsigned int key_len) {struct ixp_ctx *ctx =crypto_skcipher_ctx (tfm);int ret;
@@ -892,7 +897,7 @@ static int ablk_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, }static int ablk_rfc3686_setkey (struct crypto_skcipher *tfm,const u8 *key, -unsigned int key_len) +unsigned int key_len) {struct ixp_ctx *ctx =crypto_skcipher_ctx (tfm);
@@ -901,7 +906,7 @@ static int ablk_rfc3686_setkey(struct crypto_skcipher *tfm, const u8 *key,return -EINVAL ;memcpy (ctx->nonce, key + (key_len -CTR_RFC3686_NONCE_SIZE ), -CTR_RFC3686_NONCE_SIZE ); +CTR_RFC3686_NONCE_SIZE ); key_len -=CTR_RFC3686_NONCE_SIZE ;return ablk_setkey (tfm, key, key_len);
@@ -979,7 +984,7 @@ static int ablk_perform(struct skcipher_request *req, int encrypt)* for more than one dst buffer, I think. */ req_ctx->dst =NULL ;if (!chainup_buffers (dev, req->dst, nbytes, &dst_hook, - flags,DMA_FROM_DEVICE )) + flags,DMA_FROM_DEVICE )) goto free_buf_dest; src_direction =DMA_TO_DEVICE ; req_ctx->dst = dst_hook.next;
@@ -988,8 +993,8 @@ static int ablk_perform(struct skcipher_request *req, int encrypt) req_ctx->dst =NULL ; } req_ctx->src =NULL ; -if (!chainup_buffers (dev, req->src, nbytes, &src_hook, - flags, src_direction)) +if (!chainup_buffers (dev, req->src, nbytes, &src_hook, flags, + src_direction)) goto free_buf_src; req_ctx->src = src_hook.next;
@@ -1042,7 +1047,7 @@ static int ablk_rfc3686_crypt(struct skcipher_request *req) }static int aead_perform (struct aead_request *req,int encrypt, -int cryptoffset,int eff_cryptlen,u8 *iv) +int cryptoffset,int eff_cryptlen,u8 *iv) {struct crypto_aead *tfm =crypto_aead_reqtfm (req);struct ixp_ctx *ctx =crypto_aead_ctx (tfm);
@@ -1130,12 +1135,12 @@ static int aead_perform(struct aead_request *req, int encrypt,/* The 12 hmac bytes are scattered, * we need to copy them into a safe buffer */ req_ctx->hmac_virt =dma_pool_alloc (buffer_pool, flags, - &crypt->icv_rev_aes); + &crypt->icv_rev_aes);if (unlikely (!req_ctx->hmac_virt)) goto free_buf_dst;if (!encrypt) {scatterwalk_map_and_copy (req_ctx->hmac_virt, - req->src, cryptlen, authsize,0 ); + req->src, cryptlen, authsize,0 ); } req_ctx->encrypt = encrypt; }else {
@@ -1176,11 +1181,11 @@ static int aead_setup(struct crypto_aead *tfm, unsigned int authsize)if (ret) goto out; ret =setup_auth (&tfm->base,0 , authsize, ctx->authkey, - ctx->authkey_len, digest_len); + ctx->authkey_len, digest_len);if (ret) goto out; ret =setup_auth (&tfm->base,1 , authsize, ctx->authkey, - ctx->authkey_len, digest_len); + ctx->authkey_len, digest_len); out:if (!atomic_dec_and_test (&ctx->configuring))wait_for_completion (&ctx->completion);
@@ -1197,7 +1202,7 @@ static int aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) }static int aead_setkey (struct crypto_aead *tfm,const u8 *key, -unsigned int keylen) +unsigned int keylen) {struct ixp_ctx *ctx =crypto_aead_ctx (tfm);struct crypto_authenc_keys keys;
Signature · 1 line
2.26.3
PATCH 10/11 MAINTAINERS: add ixp4xx_crypto to the right arch list
In reply to Corentin Labbedrivers/crypto/ixp4xx_crypto.c is missing in the IXP4XX arch file list.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1974,6 +1974,7 @@ F: Documentation/devicetree/bindings/interrupt-controller/intel,ixp4xx-interrupt F: Documentation/devicetree/bindings/timer/intel,ixp4xx-timer.yaml F: arch/arm/mach-ixp4xx/ F: drivers/clocksource/timer-ixp4xx.c +F: drivers/crypto/ixp4xx_crypto.c F: drivers/gpio/gpio-ixp4xx.c F: drivers/irqchip/irq-ixp4xx.c F: include/linux/irqchip/irq-ixp4xx.h
Signature · 1 line
2.26.3
PATCH 11/11 MAINTAINERS: add myself as maintainer of ixp4xx_crypto
In reply to Corentin LabbeNo maintainer exists for ixp4xx_crypto, since I have access to a board with it, I propose to maintain it.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -9254,6 +9254,12 @@ F: Documentation/admin-guide/media/ipu3_rcb.svg F: Documentation/userspace-api/media/v4l/pixfmt-meta-intel-ipu3.rst F: drivers/staging/media/ipu3/ +INTEL IXP4XX CRYPTO SUPPORT +M: Corentin Labbe <[email protected]> +L: [email protected] +S: Maintained +F: drivers/crypto/ixp4xx_crypto.c + INTEL IXP4XX QMGR, NPE, ETHERNET and HSS SUPPORT M: Krzysztof Halasa <[email protected]> S: Maintained
Signature · 1 line
2.26.3
Herbert Xu
maintainerQuoted 19 lines · Corentin Labbe
Hello
Loading the ixp4xx crypto driver exhibits lots of error. All algorithm fail selftests with different reasons. This series start to fixes some of thoses problem.
Corentin Labbe (11):
crypto: ixp4xx:dma_unmapthe correct address
crypto: ixp4xx: update IV after requests
crypto: ixp4xx: fallback when having more than one SG
crypto: ixp4xx: convert unsigned to unsigned int
crypto: ixp4xx: convert all printk todev_xxx
crypto: ixp4xx: whitespace fixes
crypto: ixp4xx: Do not initialize static to NULL
crypto: ixp4xx: remove brackets from single statement
crypto: ixp4xx: Correct functions alignment
MAINTAINERS: addixp4xx_cryptoto the right arch list
MAINTAINERS: add myself as maintainer ofixp4xx_crypto
Quoted 4 lines
MAINTAINERS | 7 + drivers/crypto/Kconfig | 5 + drivers/crypto/ixp4xx_crypto.c | 277 +++++++++++++++++++++------------ 3 files changed, 188 insertions(+), 101 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 3 lines · Corentin Labbe
Loading the ixp4xx crypto driver exhibits lots of error. All algorithm fail selftests with different reasons. This series start to fixes some of thoses problem.
Excellent! Thanks for taking over this Corentin!!
FWIW:
If I merge my 3 additional patches through ARM SoC will it work out or do I need to think about some clever merging strategy?
Yours,
Linus Walleij
Herbert Xu
maintainerQuoted 6 lines · Linus Walleij
Quoted 3 lines · Corentin Labbe
Loading the ixp4xx crypto driver exhibits lots of error. All algorithm fail selftests with different reasons. This series start to fixes some of thoses problem.
Quoted 7 lines
Excellent! Thanks for taking over this Corentin!!
FWIW:Acked-by Linus Walleij <[email protected]>If I merge my 3 additional patches through ARM SoC will it work out or do I need to think about some clever merging strategy?
Well if your patches don't touch the drivers/crypto then there shouldn't be any conflicts.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 11 lines · Herbert Xu
Quoted 10 lines · Linus Walleij
Quoted 3 lines · Corentin Labbe
Loading the ixp4xx crypto driver exhibits lots of error. All algorithm fail selftests with different reasons. This series start to fixes some of thoses problem.
Excellent! Thanks for taking over this Corentin!!
FWIW:Acked-by Linus Walleij <[email protected]>
Quoted 6 lines
Quoted 3 lines
If I merge my 3 additional patches through ARM SoC will it work out or do I need to think about some clever merging strategy?
Well if your patches don't touch the
drivers/cryptothen there shouldn't be any conflicts.
Sadly they do, it's these:
https://lore.kernel.org/linux-crypto/[email protected]/
https://lore.kernel.org/linux-crypto/[email protected]/
https://lore.kernel.org/linux-crypto/[email protected]/
I guess we could turn it around: I see if I can apply these two on top of the crypto tree and resend then we hope there is no collision in the ARM SoC tree instead.
I need to respin the series anyway so shall we try this?
Yours,
Linus Walleij
Herbert Xu
maintainerQuoted 11 lines · Linus Walleij
Sadly they do, it's these:
https://lore.kernel.org/linux-crypto/[email protected]/
https://lore.kernel.org/linux-crypto/[email protected]/
https://lore.kernel.org/linux-crypto/[email protected]/I guess we could turn it around: I see if I can apply these two on top of the crypto tree and resend then we hope there is no collision in the ARM SoC tree instead.
I need to respin the series anyway so shall we try this?
Yes I think those changes are probably best routed through crypto as the code changes are quite extensive so the potential for non- trivial conflicts is high.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt