Re: [PATCH] ixp4xx_crypto: fix possible sleep while atomic

2010-01-12 Thread Christian Hohnstaedt
Hi Karl,

initially I designed the driver to use as less memory as possible if
it is only loaded but not used.
Since during module load some testciphers are run with the driver,
this approach became senseless.

I would rather move the call to setup_crypt_desc() into the module-load
function for 2 reasons:
 1) keep GFP_KERNEL
 2) remove some if (!crypt_virt) on the fast-path

I will create a patch and sync it with the patches from Krzysztof Halasa.

Christian

On Tue, Jan 12, 2010 at 04:06:05PM +0100, Karl Hiramoto wrote:
 use GFP_ATOMIC to allocate crypt_virt
 
 BUG: sleeping function called from invalid context at mm/page_alloc.c:1470
 in_atomic(): 0, irqs_disabled(): 128, pid: 1376, name: cryptomgr_test
 1 lock held by cryptomgr_test/1376:
  #0:  (desc_lock){}, at: [bf147050] get_crypt_desc+0x14/0xe8 
 [ixp4xx_crypto]
 [c0028954] (dump_stack+0x0/0x14) from [c0030f2c] (__might_sleep+0xcc/0xe8)
 [c0030e60] (__might_sleep+0x0/0xe8) from [c00676e4] 
 (__alloc_pages_internal+0xa4/0x430)
  r4:00d0
 [c0067640] (__alloc_pages_internal+0x0/0x430) from [c0029ea8] 
 (__dma_alloc+0x180/0x3e8)
 [c0029d28] (__dma_alloc+0x0/0x3e8) from [c002a198] 
 (dma_alloc_coherent+0x58/0x64)
 [c002a140] (dma_alloc_coherent+0x0/0x64) from [bf147078] 
 (get_crypt_desc+0x3c/0xe8 [ixp4xx_crypto])
  r7:c3bc3ce8 r6:c3bc3cc0 r5:2013 r4:bf14a81c
 [bf14703c] (get_crypt_desc+0x0/0xe8 [ixp4xx_crypto]) from [bf147788] 
 (ablk_perform+0x68/0x248 [ixp4xx_crypto])
  r7:c3bc3ce8 r6:c3bc3cc0 r5:c2cefc2c r4:
 [bf147720] (ablk_perform+0x0/0x248 [ixp4xx_crypto]) from [bf1479f0] 
 (ablk_encrypt+0x14/0x18 [ixp4xx_crypto])
 [bf1479dc] (ablk_encrypt+0x0/0x18 [ixp4xx_crypto]) from [c012bf4c] 
 (test_skcipher+0x1bc/0x668)
 [c012bd90] (test_skcipher+0x0/0x668) from [c012d428] 
 (alg_test_skcipher+0x60/0xa0)
 [c012d3c8] (alg_test_skcipher+0x0/0xa0) from [c012ce84] 
 (alg_test+0x128/0x160)
  r7: r6:0286 r5:c39ddd80 r4:c39dddc0
 [c012cd5c] (alg_test+0x0/0x160) from [c012bb0c] (cryptomgr_test+0x38/0x58)
 [c012bad4] (cryptomgr_test+0x0/0x58) from [c004bc7c] (kthread+0x58/0x90)
  r4:c2e38000
 [c004bc24] (kthread+0x0/0x90) from [c0039ed4] (do_exit+0x0/0x6d0)
  r6: r5: r4:
 
 Note this is somewhat hard to reproduce, but can be reproduced under memory 
 pressure when you first initialize ixp4xx_crypto.
 
 Signed-off-by: Karl Hiramoto k...@hiramoto.org
 ---
  drivers/crypto/ixp4xx_crypto.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
 index 6c6656d..564d68f 100644
 --- a/drivers/crypto/ixp4xx_crypto.c
 +++ b/drivers/crypto/ixp4xx_crypto.c
 @@ -246,7 +246,7 @@ static int setup_crypt_desc(void)
   BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);
   crypt_virt = dma_alloc_coherent(dev,
   NPE_QLEN * sizeof(struct crypt_ctl),
 - crypt_phys, GFP_KERNEL);
 + crypt_phys, GFP_ATOMIC);
   if (!crypt_virt)
   return -ENOMEM;
   memset(crypt_virt, 0, NPE_QLEN * sizeof(struct crypt_ctl));
 -- 
 1.6.4.4
 
Christian Hohnstaedt

-- 
Christian Hohnstaedt / Project Manager Hardware and Manufacturing

Innominate Security Technologies AG / protecting industrial networks
tel: +49.30.921028.208 / fax: +49.30.921028.020
Rudower Chaussee 13, D-12489 Berlin / http://www.innominate.com

Register Court: AG Charlottenburg, HR B 81603
Management Board: Dirk Seewald
Chairman of the Supervisory Board: Volker Bibelhausen
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: IXP4xx: Fix whitespace problems in ixp4xx_crypto.

2010-01-12 Thread Christian Hohnstaedt
On Sun, Jan 10, 2010 at 06:33:37PM +0100, Krzysztof Halasa wrote:
 Signed-off-by: Krzysztof Hałasa k...@pm.waw.pl
 
 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
 index 0c7e4f5..f8f6515 100644
 --- a/drivers/crypto/ixp4xx_crypto.c
 +++ b/drivers/crypto/ixp4xx_crypto.c
 @@ -64,7 +64,7 @@
  
  #define MOD_DES 0x
  #define MOD_TDEA2   0x0100
 -#define MOD_3DES   0x0200
 +#define MOD_3DES0x0200
  #define MOD_AES 0x0800
  #define MOD_AES128  (0x0800 | KEYLEN_128)
  #define MOD_AES192  (0x0900 | KEYLEN_192)
 @@ -137,7 +137,7 @@ struct crypt_ctl {
   u32 aadAddr;/* Additional Auth Data Addr for CCM mode */
   u32 crypto_ctx; /* NPE Crypto Param structure address */
  
 - /* Used by Host: 4*4 bytes*/
 + /* Used only by host: 4 * 4 bytes */
   unsigned ctl_flags;
   union {
   struct ablkcipher_request *ablk_req;
 @@ -208,10 +208,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;

This is not a whitespace-fix.
The error-path in init_ixp_crypto() depends on them being either NULL
or correctly allocated.

Or is it guaranteed that static variables are always initially zero ?

  static dma_addr_t crypt_phys;
  
  static int support_aes = 1;

But this initialization is superflous, since it will be initialized before use.

 @@ -246,12 +246,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)-cfg_enc;
 + return container_of(tfm-__crt_alg, struct ixp_alg, crypto)-cfg_enc;
  }
  
  static inline u32 cipher_cfg_dec(struct crypto_tfm *tfm)
  {
 - return container_of(tfm-__crt_alg, struct ixp_alg,crypto)-cfg_dec;
 + return container_of(tfm-__crt_alg, struct ixp_alg, crypto)-cfg_dec;
  }
  
  static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm)
 @@ -275,7 +275,7 @@ static spinlock_t desc_lock;
  static struct crypt_ctl *get_crypt_desc(void)
  {
   int i;
 - static int idx = 0;
 + static int idx;

This static index must be initialized with 0.

   unsigned long flags;
   struct crypt_ctl *desc = NULL;
  
 @@ -318,13 +318,13 @@ static struct crypt_ctl *get_crypt_desc_emerg(void)
   if (++idx = NPE_QLEN_TOTAL)
   idx = NPE_QLEN;
   crypt_virt[i].ctl_flags = CTL_FLAG_USED;
 - desc = crypt_virt +i;
 + desc = crypt_virt + i;
   }
   spin_unlock_irqrestore(emerg_lock, flags);
   return desc;
  }
  
 -static void free_buf_chain(struct device *dev, struct buffer_desc *buf,u32 
 phys)
 +static void free_buf_chain(struct device *dev, struct buffer_desc *buf, u32 
 phys)

Introduces a line-length  80.

  {
   while (buf) {
   struct buffer_desc *buf1;
 @@ -349,10 +349,9 @@ static void finish_scattered_hmac(struct crypt_ctl 
 *crypt)
   int authsize = crypto_aead_authsize(tfm);

[ snip ]

 @@ -1416,7 +1393,7 @@ static struct ixp_alg ixp4xx_algos[] = {
  static int __init ixp_module_init(void)
  {
   int num = ARRAY_SIZE(ixp4xx_algos);
 - int i,err ;
 + int i, err ;

Missed one before the ;

  
   if (platform_device_register(pseudo_dev))
   return -ENODEV;
 @@ -1429,18 +1406,14 @@ static int __init ixp_module_init(void)
   platform_device_unregister(pseudo_dev);
   return err;
   }
 - for (i=0; i num; i++) {
 + for (i = 0; i  num; i++) {
   struct crypto_alg *cra = ixp4xx_algos[i].crypto;
  
   if (snprintf(cra-cra_driver_name, CRYPTO_MAX_ALG_NAME,
 - %sIXP_POSTFIX, cra-cra_name) =
 - CRYPTO_MAX_ALG_NAME)
 - {
 + %sIXP_POSTFIX, cra-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;
 - }
   if (!ixp4xx_algos[i].hash) {
   /* block ciphers */
   cra-cra_type = crypto_ablkcipher_type;
 @@ -1484,7 +1457,7 @@ static void __exit ixp_module_exit(void)
   int num = ARRAY_SIZE(ixp4xx_algos);
   int i;
  
 - for (i=0; i num; i++) {
 + for (i = 0; i  num; i++) {
   if (ixp4xx_algos[i].registered)
   crypto_unregister_alg(ixp4xx_algos[i].crypto);
   }

Christian Hohnstaedt

-- 
Christian Hohnstaedt / Project Manager Hardware and Manufacturing

Innominate Security Technologies AG / protecting

Re: [6 PATCHes] IXP4xx crypto driver fixes.

2010-01-11 Thread Christian Hohnstaedt
On Sun, Jan 10, 2010 at 06:30:53PM +0100, Krzysztof Halasa wrote:
 IXP4xx: Fix ixp4xx_crypto little-endian operation.
 
 Signed-off-by: Krzysztof Hałasa k...@pm.waw.pl
Acked-by: Christian Hohnstaedt chohnsta...@innominate.com

 
 Fixes the following on IXP425 little-endian:
 
 NPE-C: firmware functionality 0x5, revision 0x2:1
 alg: skcipher: Test 1 failed on encryption for ecb(des)-ixp4xx
 : 01 23 45 67 89 ab cd e7
 alg: skcipher: Test 1 failed on encryption for ecb(des3_ede)-ixp4xx
 : 73 6f 6d 65 64 61 74 61
 alg: skcipher: Test 1 failed on encryption for ecb(aes)-ixp4xx
 : 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
 
 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
 index 6c6656d..cac026a 100644
 --- a/drivers/crypto/ixp4xx_crypto.c
 +++ b/drivers/crypto/ixp4xx_crypto.c
 @@ -96,8 +96,13 @@
  
  struct buffer_desc {
   u32 phys_next;
 +#ifdef __ARMEB__
   u16 buf_len;
   u16 pkt_len;
 +#else
 + u16 pkt_len;
 + u16 buf_len;
 +#endif
   u32 phys_addr;
   u32 __reserved[4];
   struct buffer_desc *next;
 @@ -105,17 +110,30 @@ struct buffer_desc {
  };
  
  struct crypt_ctl {
 +#ifdef __ARMEB__
   u8 mode;/* NPE_OP_*  operation mode */
   u8 init_len;
   u16 reserved;
 +#else
 + u16 reserved;
 + u8 init_len;
 + u8 mode;/* NPE_OP_*  operation mode */
 +#endif
   u8 iv[MAX_IVLEN];   /* IV for CBC mode or CTR IV for CTR mode */
   u32 icv_rev_aes;/* icv or rev aes */
   u32 src_buf;
   u32 dst_buf;
 +#ifdef __ARMEB__
   u16 auth_offs;  /* Authentication start offset */
   u16 auth_len;   /* Authentication data length */
   u16 crypt_offs; /* Cryption start offset */
   u16 crypt_len;  /* Cryption data length */
 +#else
 + u16 auth_len;   /* Authentication data length */
 + u16 auth_offs;  /* Authentication start offset */
 + u16 crypt_len;  /* Cryption data length */
 + u16 crypt_offs; /* Cryption start offset */
 +#endif
   u32 aadAddr;/* Additional Auth Data Addr for CCM mode */
   u32 crypto_ctx; /* NPE Crypto Param structure address */
  
 @@ -651,6 +669,9 @@ static int setup_auth(struct crypto_tfm *tfm, int 
 encrypt, unsigned authsize,
  
   /* write cfg word to cryptinfo */
   cfgword = algo-cfgword | ( authsize  6); /* (authsize/4)  8 */
 +#ifndef __ARMEB__
 + cfgword ^= 0xAA00; /* change the byte swap flags */
 +#endif
   *(u32*)cinfo = cpu_to_be32(cfgword);
   cinfo += sizeof(cfgword);
  
Christian Hohnstaedt

-- 
Christian Hohnstaedt / Project Manager Hardware and Manufacturing

Innominate Security Technologies AG / protecting industrial networks
tel: +49.30.921028.208 / fax: +49.30.921028.020
Rudower Chaussee 13, D-12489 Berlin / http://www.innominate.com

Register Court: AG Charlottenburg, HR B 81603
Management Board: Dirk Seewald
Chairman of the Supervisory Board: Volker Bibelhausen
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: ixp4xx_crypto: Fix possible NULL ptr dereference.

2010-01-11 Thread Christian Hohnstaedt
On Sun, Jan 10, 2010 at 06:37:25PM +0100, Krzysztof Halasa wrote:
 Signed-off-by: Krzysztof Hałasa k...@pm.waw.pl
 
 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
 index f8f6515..2ae7148 100644
 --- a/drivers/crypto/ixp4xx_crypto.c
 +++ b/drivers/crypto/ixp4xx_crypto.c
 @@ -786,10 +786,8 @@ static struct buffer_desc *chainup_buffers(struct device 
 *dev,
   nbytes -= len;
   ptr = page_address(sg_page(sg)) + sg-offset;
   next_buf = dma_pool_alloc(buffer_pool, flags, next_buf_phys);
 - if (!next_buf) {
 - buf = NULL;
 - break;
 - }
 + if (!next_buf)
 + return NULL;

This leaves buf-next uninitialized, but
free_buf_chain() iterates over buf-next.

We need:

if (!next_buf) {
buf-next = NULL;
return NULL;
}

Or get rid of next_buf and next_buf_phys:

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index b8cc714..c961b0f 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -794,21 +794,15 @@ static struct buffer_desc *chainup_buffers(struct device 
*dev,
 {
for (;nbytes  0; sg = scatterwalk_sg_next(sg)) {
unsigned len = min(nbytes, sg-length);
-   struct buffer_desc *next_buf;
-   u32 next_buf_phys;
void *ptr;
 
nbytes -= len;
ptr = page_address(sg_page(sg)) + sg-offset;
-   next_buf = dma_pool_alloc(buffer_pool, flags, next_buf_phys);
-   if (!next_buf) {
-   buf = NULL;
-   break;
-   }
+   buf-next = dma_pool_alloc(buffer_pool, flags, buf-phys_next);
+   if (!buf-next)
+   return NULL;
sg_dma_address(sg) = dma_map_single(dev, ptr, len, dir);
-   buf-next = next_buf;
-   buf-phys_next = next_buf_phys;
-   buf = next_buf;
+   buf = buf-next;
 
buf-phys_addr = sg_dma_address(sg);
buf-buf_len = len;


Christian Hohnstaedt

-- 
Christian Hohnstaedt / Project Manager Hardware and Manufacturing

Innominate Security Technologies AG / protecting industrial networks
tel: +49.30.921028.208 / fax: +49.30.921028.020
Rudower Chaussee 13, D-12489 Berlin / http://www.innominate.com

Register Court: AG Charlottenburg, HR B 81603
Management Board: Dirk Seewald
Chairman of the Supervisory Board: Volker Bibelhausen
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] ixp4xx_crypto: check firmware for crypto support

2009-04-09 Thread Christian Hohnstaedt
 - the loaded firmware may not support crypto at all or
   only support DES and 3DES but not AES or
   support DES, 3DES and AES.

 - in case of no crypto support of the firmware, the module load will fail.
 - in case of missing AES support, the AES algorithms are not registered
   and a warning is printed during module load.

Signed-off-by: Christian Hohnstaedt chohnsta...@innominate.com
---
 drivers/crypto/ixp4xx_crypto.c |   33 -
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index fdcd0ab..f72f414 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -415,6 +415,7 @@ static void crypto_done_action(unsigned long arg)
 static int init_ixp_crypto(void)
 {
int ret = -ENODEV;
+   u32 msg[2] = { 0, 0 };
 
if (! ( ~(*IXP4XX_EXP_CFG2)  (IXP4XX_FEATURE_HASH |
IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) {
@@ -426,9 +427,35 @@ static int init_ixp_crypto(void)
return ret;
 
if (!npe_running(npe_c)) {
-   npe_load_firmware(npe_c, npe_name(npe_c), dev);
+   ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
+   if (ret) {
+   return ret;
+   }
+   if (npe_recv_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+   } else {
+   if (npe_send_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+
+   if (npe_recv_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
}
 
+   switch ((msg[1]16)  0xff) {
+   case 3:
+   printk(KERN_WARNING Firmware of %s lacks AES support\n,
+   npe_name(npe_c));
+   support_aes = 0;
+   break;
+   case 4:
+   case 5:
+   support_aes = 1;
+   break;
+   default:
+   printk(KERN_ERR Firmware of %s lacks crypto support\n,
+   npe_name(npe_c));
+   return -ENODEV;
+   }
/* buffer_pool will also be used to sometimes store the hmac,
 * so assure it is large enough
 */
@@ -457,6 +484,10 @@ static int init_ixp_crypto(void)
 
qmgr_enable_irq(RECV_QID);
return 0;
+
+npe_error:
+   printk(KERN_ERR %s not responding\n, npe_name(npe_c));
+   ret = -EIO;
 err:
if (ctx_pool)
dma_pool_destroy(ctx_pool);
-- 
1.6.0.3

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: fix handling of sg buffers in ixp4xx driver

2009-03-02 Thread Christian Hohnstaedt

 - keep dma functions away from chained scatterlists.
   Use the existing scatterlist iteration inside the driver
   to call dma_map_single() for each chunk and avoid dma_map_sg().

Signed-off-by: Christian Hohnstaedt chohnsta...@innominate.com
Tested-By:  Karl Hiramoto k...@hiramoto.org

---
 drivers/crypto/ixp4xx_crypto.c |  182 ++--
 1 files changed, 63 insertions(+), 119 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 2d637e0..fdcd0ab 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -101,6 +101,7 @@ struct buffer_desc {
u32 phys_addr;
u32 __reserved[4];
struct buffer_desc *next;
+   enum dma_data_direction dir;
 };
 
 struct crypt_ctl {
@@ -132,14 +133,10 @@ struct crypt_ctl {
 struct ablk_ctx {
struct buffer_desc *src;
struct buffer_desc *dst;
-   unsigned src_nents;
-   unsigned dst_nents;
 };
 
 struct aead_ctx {
struct buffer_desc *buffer;
-   unsigned short assoc_nents;
-   unsigned short src_nents;
struct scatterlist ivlist;
/* used when the hmac is not on one sg entry */
u8 *hmac_virt;
@@ -312,7 +309,7 @@ static struct crypt_ctl *get_crypt_desc_emerg(void)
}
 }
 
-static void free_buf_chain(struct buffer_desc *buf, u32 phys)
+static void free_buf_chain(struct device *dev, struct buffer_desc *buf,u32 
phys)
 {
while (buf) {
struct buffer_desc *buf1;
@@ -320,6 +317,7 @@ static void free_buf_chain(struct buffer_desc *buf, u32 
phys)
 
buf1 = buf-next;
phys1 = buf-phys_next;
+   dma_unmap_single(dev, buf-phys_next, buf-buf_len, buf-dir);
dma_pool_free(buffer_pool, buf, phys);
buf = buf1;
phys = phys1;
@@ -348,7 +346,6 @@ static void one_packet(dma_addr_t phys)
struct crypt_ctl *crypt;
struct ixp_ctx *ctx;
int failed;
-   enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
 
failed = phys  0x1 ? -EBADMSG : 0;
phys = ~0x3;
@@ -358,13 +355,8 @@ static void one_packet(dma_addr_t phys)
case CTL_FLAG_PERFORM_AEAD: {
struct aead_request *req = crypt-data.aead_req;
struct aead_ctx *req_ctx = aead_request_ctx(req);
-   dma_unmap_sg(dev, req-assoc, req_ctx-assoc_nents,
-   DMA_TO_DEVICE);
-   dma_unmap_sg(dev, req_ctx-ivlist, 1, DMA_BIDIRECTIONAL);
-   dma_unmap_sg(dev, req-src, req_ctx-src_nents,
-   DMA_BIDIRECTIONAL);
 
-   free_buf_chain(req_ctx-buffer, crypt-src_buf);
+   free_buf_chain(dev, req_ctx-buffer, crypt-src_buf);
if (req_ctx-hmac_virt) {
finish_scattered_hmac(crypt);
}
@@ -374,16 +366,11 @@ static void one_packet(dma_addr_t phys)
case CTL_FLAG_PERFORM_ABLK: {
struct ablkcipher_request *req = crypt-data.ablk_req;
struct ablk_ctx *req_ctx = ablkcipher_request_ctx(req);
-   int nents;
+
if (req_ctx-dst) {
-   nents = req_ctx-dst_nents;
-   dma_unmap_sg(dev, req-dst, nents, DMA_FROM_DEVICE);
-   free_buf_chain(req_ctx-dst, crypt-dst_buf);
-   src_direction = DMA_TO_DEVICE;
+   free_buf_chain(dev, req_ctx-dst, crypt-dst_buf);
}
-   nents = req_ctx-src_nents;
-   dma_unmap_sg(dev, req-src, nents, src_direction);
-   free_buf_chain(req_ctx-src, crypt-src_buf);
+   free_buf_chain(dev, req_ctx-src, crypt-src_buf);
req-base.complete(req-base, failed);
break;
}
@@ -748,56 +735,35 @@ static int setup_cipher(struct crypto_tfm *tfm, int 
encrypt,
return 0;
 }
 
-static int count_sg(struct scatterlist *sg, int nbytes)
+static struct buffer_desc *chainup_buffers(struct device *dev,
+   struct scatterlist *sg, unsigned nbytes,
+   struct buffer_desc *buf, gfp_t flags,
+   enum dma_data_direction dir)
 {
-   int i;
-   for (i = 0; nbytes  0; i++, sg = sg_next(sg))
-   nbytes -= sg-length;
-   return i;
-}
-
-static struct buffer_desc *chainup_buffers(struct scatterlist *sg,
-   unsigned nbytes, struct buffer_desc *buf, gfp_t flags)
-{
-   int nents = 0;
-
-   while (nbytes  0) {
+   for (;nbytes  0; sg = scatterwalk_sg_next(sg)) {
+   unsigned len = min(nbytes, sg-length);
struct buffer_desc *next_buf;
u32 next_buf_phys;
-   unsigned len = min(nbytes, sg_dma_len(sg));
+   void *ptr;
 
-   nents++;
nbytes -= len;
-   if (!buf-phys_addr

Re: [PATCH] ixp4xx_crypto panic with fragmented packets in scatterlist

2009-02-27 Thread Christian Hohnstaedt
On Thu, Feb 26, 2009 at 09:27:09PM +0100, Karl Hiramoto wrote:
 Herbert Xu wrote:
 Russell King - ARM Linux li...@arm.linux.org.uk wrote:
   
 We can't merge this until _all_ of ARM has been fixed for walking
 scatterlist chains.
 

 Right, this is definitely not the way to fix this bug.  Because
 even if ARM completely supported chaining, you still have to fix
 all the other architectures as well.

 So please just fix the driver to remove the chaining before doing
 DMA.

   
 Is there an example of how to do this somewhere? 


Not needed.

Now that I know the details about the different ways of chaining
and their scope, I know how to fix my driver properly.

Patch follows, soon...

best regards
Christian

-- 
The iMac is just evidence of how dangerous vi is. Obviously Steve came up with
the name by accident after forgetting he was *already* in insert mode.
 — dagbrown on #emacs
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: ixp4xx_crypto panic with fragmented packets in scatterlist

2009-02-25 Thread Christian Hohnstaedt
On Tue, Feb 24, 2009 at 02:19:54PM +0100, Karl Hiramoto wrote:
 The latest thing i found is  kernel BUG at lib/scatterlist.c:26!
 
 ping -s 1800  host in a IPSec tunnel.  Setup is   802.1Q VLAN  -- 
 ixp4xx_eth  -- IPSec Tunnel
 
 trace with   some   debug printk's  i added.printk(%s:%d  
 values,__func__, __LINE__);
 
 
 [42949542.17] esp_output:142 skb-len=1828 data_len=328 clen=1832 alen=0 
 blksize=8  skb=c7a5cb40 data=c79ba054
 [42949542.18] esp_output:168 skb=c7a5cb40 data=c79ba054 clone=0
 [42949542.18] __skb_to_sgvec:2430 skb=c7a5cb40 data=c79ba030 sg=c78a0324 
 off=36 len=1832
 [42949542.19] __skb_to_sgvec:2477 list=c795a0c0 start=1536  end=1868 
 list-len=332 offset=1536
 [42949542.20] __skb_to_sgvec:2430 skb=c795a0c0 data=c6d8f048 sg=c78a0338 
 off=0 len=332
 [42949542.21] __skb_to_sgvec:2484 len==0 elt=2
 [42949542.21] esp_output:218 skb=c7a5cb40 data=c79ba030
 [42949542.22] esp_output:228 skb=c7a5cb40 data=c79ba030
 [42949542.23] ablk_perform:897 ivsize=8 nbytes=1840
 [42949542.23] ablk_perform:919 dst=NULL src=c78a0278
 [42949542.24] count_sg:757 i=0 nbytes=1840 sg=c78a0278  
 sg_next(sg)=c78a028c
 [42949542.24] count_sg:758 len=1508 sg_is_last(sg)=0
 [42949542.25] count_sg:757 i=1 nbytes=332 sg=c78a028c  
 sg_next(sg)=c78a02a0
 [42949542.25] count_sg:758 len=0 sg_is_last(sg)=0
 [42949542.26] kernel BUG at lib/scatterlist.c:26!
 [42949542.26] Unable to handle kernel NULL pointer dereference at virtual 
 address 

This differs from the issue you mentioned first.
The first one was in dma_cache_maint.

Are you sure, your printk()s don't have any side effect ?

Christian

-- 
The decline of the Roman Empire can be traced to the fact that, lacking
zero, they were unable to return from their C programs.
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: ixp4xx_crypto panic with fragmented packets in scatterlist

2009-02-25 Thread Christian Hohnstaedt
On Wed, Feb 25, 2009 at 10:36:11AM +0100, Karl Hiramoto wrote:
 Christian Hohnstaedt wrote:
  On Tue, Feb 24, 2009 at 02:19:54PM +0100, Karl Hiramoto wrote:

  [42949542.25] count_sg:758 len=0 sg_is_last(sg)=0
  [42949542.26] kernel BUG at lib/scatterlist.c:26!
  [42949542.26] Unable to handle kernel NULL pointer dereference at 
  virtual address 
  
 
  This differs from the issue you mentioned first.
  The first one was in dma_cache_maint.
 

 When i turned on CONFIG_DEBUG_SGi hit the BUG()  call in the
 scatterlist, instead of the dma_cache_maint..
 
 

looks like there are different, incompatible sg chaining implementations:

include/crypto/scatterwalk.h:scatterwalk_sg_chain()  uses
sg-lenght == 0 as indicator for a chained sg

include/linux/scatterlist.h:sg_chain() uses
bit 0 of sg-page_link to indicate chaining

Maybe the matters for b2ab4a57b018aafbba35bff088218f5cc3d2142e
are obsolete now...

However the scatterlist iteration in the arm implementation of
dma_map_sg() uses neither of them, but simply sg++

Please try the attached compile-tested patch.


Christian

-- 
Hardware
n, The parts of a computer system that can be kicked.
 — Henri Karrenbeld
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index aecc6c3..4948a3a 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -30,6 +30,7 @@
 #include linux/dmapool.h
 #include linux/list.h
 #include linux/scatterlist.h
+#include crypto/scatterwalk.h
 
 #include asm/cacheflush.h
 
@@ -442,7 +443,7 @@ dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 
 	BUG_ON(dir == DMA_NONE);
 
-	for (i = 0; i  nents; i++, sg++) {
+	for (i = 0; i  nents; i++, sg = scatterwalk_sg_next(sg)) {
 		struct page *page = sg_page(sg);
 		unsigned int offset = sg-offset;
 		unsigned int length = sg-length;
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 2d637e0..57c1c03 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -751,7 +751,7 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt,
 static int count_sg(struct scatterlist *sg, int nbytes)
 {
 	int i;
-	for (i = 0; nbytes  0; i++, sg = sg_next(sg))
+	for (i = 0; nbytes  0; i++, sg = scatterwalk_sg_next(sg))
 		nbytes -= sg-length;
 	return i;
 }
@@ -795,7 +795,7 @@ static struct buffer_desc *chainup_buffers(struct scatterlist *sg,
 		buf-buf_len = len;
 next:
 		if (nbytes  0) {
-			sg = sg_next(sg);
+			sg = scatterwalk_sg_next(sg);
 		}
 	}
 	return buf;
@@ -983,7 +983,7 @@ static int hmac_inconsistent(struct scatterlist *sg, unsigned start,
 			break;
 
 		offset += sg-length;
-		sg = sg_next(sg);
+		sg = scatterwalk_sg_next(sg);
 	}
 	return (start + nbytes  offset + sg-length);
 }


Re: [PATCH] ixp4xx_crypto: avoid firmware loading during module initialisation

2008-10-23 Thread Christian Hohnstaedt
On Tue, Aug 19, 2008 at 02:55:10PM +1000, Herbert Xu wrote:
 Christian Hohnstaedt [EMAIL PROTECTED] wrote:
  By moving the firmware-loading to the transform initialisation,
  the driver may be compiled in.
  
  Notify the user if the firmware does not support AES, or even
  no crypto at all.
 
 What happens when two tfms are constructed at the same time?
 

Subject: [PATCH] ixp4xx_crypto: avoid firmware loading during module 
initialisation

 By moving the firmware-loading to the transform initialisation,
 the driver may be compiled in.

 Notify the user if the firmware does not support AES, or even
 no crypto at all.

 Protect firmware loading and memory allocation by a mutex.

Signed-off-by: Christian Hohnstaedt [EMAIL PROTECTED]
---
 drivers/crypto/ixp4xx_crypto.c |  101 ++-
 1 files changed, 67 insertions(+), 34 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 2d637e0..440d672 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -17,6 +17,7 @@
 #include linux/rtnetlink.h
 #include linux/interrupt.h
 #include linux/spinlock.h
+#include linux/semaphore.h
 
 #include crypto/ctr.h
 #include crypto/des.h
@@ -244,44 +245,25 @@ static inline const struct ix_hash_algo *ix_hash(struct 
crypto_tfm *tfm)
return container_of(tfm-__crt_alg, struct ixp_alg, crypto)-hash;
 }
 
-static int setup_crypt_desc(void)
-{
-   BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);
-   crypt_virt = dma_alloc_coherent(dev,
-   NPE_QLEN * sizeof(struct crypt_ctl),
-   crypt_phys, GFP_KERNEL);
-   if (!crypt_virt)
-   return -ENOMEM;
-   memset(crypt_virt, 0, NPE_QLEN * sizeof(struct crypt_ctl));
-   return 0;
-}
-
 static spinlock_t desc_lock;
 static struct crypt_ctl *get_crypt_desc(void)
 {
int i;
static int idx = 0;
unsigned long flags;
+   struct crypt_ctl *ret = NULL;
 
spin_lock_irqsave(desc_lock, flags);
 
-   if (unlikely(!crypt_virt))
-   setup_crypt_desc();
-   if (unlikely(!crypt_virt)) {
-   spin_unlock_irqrestore(desc_lock, flags);
-   return NULL;
-   }
i = idx;
if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) {
if (++idx = NPE_QLEN)
idx = 0;
crypt_virt[i].ctl_flags = CTL_FLAG_USED;
-   spin_unlock_irqrestore(desc_lock, flags);
-   return crypt_virt +i;
-   } else {
-   spin_unlock_irqrestore(desc_lock, flags);
-   return NULL;
+   ret = crypt_virt +i;
}
+   spin_unlock_irqrestore(desc_lock, flags);
+   return ret;
 }
 
 static spinlock_t emerg_lock;
@@ -291,12 +273,11 @@ static struct crypt_ctl *get_crypt_desc_emerg(void)
static int idx = NPE_QLEN;
struct crypt_ctl *desc;
unsigned long flags;
+   struct crypt_ctl *ret = NULL;
 
desc = get_crypt_desc();
if (desc)
return desc;
-   if (unlikely(!crypt_virt))
-   return NULL;
 
spin_lock_irqsave(emerg_lock, flags);
i = idx;
@@ -304,12 +285,10 @@ static struct crypt_ctl *get_crypt_desc_emerg(void)
if (++idx = NPE_QLEN_TOTAL)
idx = NPE_QLEN;
crypt_virt[i].ctl_flags = CTL_FLAG_USED;
-   spin_unlock_irqrestore(emerg_lock, flags);
-   return crypt_virt +i;
-   } else {
-   spin_unlock_irqrestore(emerg_lock, flags);
-   return NULL;
+   ret = crypt_virt +i;
}
+   spin_unlock_irqrestore(emerg_lock, flags);
+   return ret;
 }
 
 static void free_buf_chain(struct buffer_desc *buf, u32 phys)
@@ -438,10 +417,6 @@ static int init_ixp_crypto(void)
if (!npe_c)
return ret;
 
-   if (!npe_running(npe_c)) {
-   npe_load_firmware(npe_c, npe_name(npe_c), dev);
-   }
-
/* buffer_pool will also be used to sometimes store the hmac,
 * so assure it is large enough
 */
@@ -526,9 +501,62 @@ static void free_sa_dir(struct ix_sa_dir *dir)
 static int init_tfm(struct crypto_tfm *tfm)
 {
struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+   u32 msg[2] = { 0, 0 };
+   static u32 image_id = 0;
+   static DECLARE_MUTEX(firmware);
int ret;
 
+   ret = down_interruptible(firmware);
+   if (ret != 0)
+   return ret;
+
+   if (!npe_running(npe_c)) {
+   ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
+   if (ret) {
+   up(firmware);
+   return ret;
+   }
+   if (npe_recv_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+
+   image_id = msg[1];
+   }
+   if (!image_id) {
+   if (npe_send_message(npe_c, msg

[PATCH] ixp4xx_crypto: avoid firmware loading during module initialisation

2008-08-18 Thread Christian Hohnstaedt
 By moving the firmware-loading to the transform initialisation,
 the driver may be compiled in.

 Notify the user if the firmware does not support AES, or even
 no crypto at all.

Signed-off-by: Christian Hohnstaedt [EMAIL PROTECTED]
---
 drivers/crypto/ixp4xx_crypto.c |   44 ---
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 42a107f..c3aa5a4 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -438,10 +438,6 @@ static int init_ixp_crypto(void)
if (!npe_c)
return ret;
 
-   if (!npe_running(npe_c)) {
-   npe_load_firmware(npe_c, npe_name(npe_c), dev);
-   }
-
/* buffer_pool will also be used to sometimes store the hmac,
 * so assure it is large enough
 */
@@ -526,9 +522,45 @@ static void free_sa_dir(struct ix_sa_dir *dir)
 static int init_tfm(struct crypto_tfm *tfm)
 {
struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+   u32 msg[2] = { 0, 0 };
+   static u32 image_id = 0;
int ret;
 
atomic_set(ctx-configuring, 0);
+
+   if (!npe_running(npe_c)) {
+   ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
+   if (ret)
+   return ret;
+   if (npe_recv_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+
+   image_id = msg[1];
+   }
+   if (!image_id) {
+   if (npe_send_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+
+   if (npe_recv_message(npe_c, msg, STATUS_MSG))
+   goto npe_error;
+
+   image_id = msg[1];
+   }
+   switch ((image_id16)  0xff) {
+   case 3:
+   if (cipher_cfg_enc(tfm)  MOD_AES) {
+   printk(KERN_ERR Firmware of %s lacks AES 
+   support\n, npe_name(npe_c));
+   return -ENODEV;
+   }
+   case 4:
+   case 5:
+   break;
+   default:
+   printk(KERN_ERR Firmware of %s lacks crypto support\n,
+   npe_name(npe_c));
+   return -ENODEV;
+   }
ret = init_sa_dir(ctx-encrypt);
if (ret)
return ret;
@@ -537,6 +569,10 @@ static int init_tfm(struct crypto_tfm *tfm)
free_sa_dir(ctx-encrypt);
}
return ret;
+
+npe_error:
+   printk(KERN_ERR %s not responding\n, npe_name(npe_c));
+   return -EIO;
 }
 
 static int init_tfm_ablk(struct crypto_tfm *tfm)
-- 
1.5.6.3

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: fix larval lookup

2008-08-18 Thread Christian Hohnstaedt

crypto_alg_mod_lookup() runs in a timeout (60s) for unknown algos.

crypto_larval_error() doesn't find the larval and thus doesn't
finish crypto_larval_wait, because
the larval-mask has the CRYPTO_ALG_TESTED bit set, while
crypto_alg_lookup() is called without that bit in the mask
and the mask comparison in __crypto_alg_lookup fails.

Since larvals itself never get tested, it seems ok to 
reset that bit.

Signed-off-by: Christian Hohnstaedt [EMAIL PROTECTED]
---
 crypto/api.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/crypto/api.c b/crypto/api.c
index cd232d4..0a4012e 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -118,7 +118,7 @@ struct crypto_larval *crypto_larval_alloc(const char *name, 
u32 type, u32 mask)
if (!larval)
return ERR_PTR(-ENOMEM);
 
-   larval-mask = mask;
+   larval-mask = mask  ~CRYPTO_ALG_TESTED;
larval-alg.cra_flags = CRYPTO_ALG_LARVAL | type;
larval-alg.cra_priority = -1;
larval-alg.cra_destroy = crypto_larval_destroy;
-- 
1.5.6.3

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] ixp4xx: Hardware crypto support for IXP4xx CPUs

2008-06-15 Thread Christian Hohnstaedt
Add support for the hardware crypto engine provided by the NPE C
of the Intel IXP4xx networking processor series.

Supported ciphers: des, des3, aes
and a combination of them with md5 and sha1 hmac

Signed-off-by: Christian Hohnstaedt [EMAIL PROTECTED]
---
 drivers/crypto/Kconfig |9 +
 drivers/crypto/Makefile|1 +
 drivers/crypto/ixp4xx_crypto.c | 1506 
 3 files changed, 1516 insertions(+), 0 deletions(-)
 create mode 100644 drivers/crypto/ixp4xx_crypto.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 98d96df..b51b3f9 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -189,4 +189,13 @@ config CRYPTO_DEV_TALITOS
  To compile this driver as a module, choose M here: the module
  will be called talitos.
 
+config CRYPTO_DEV_IXP4XX
+   tristate Driver for IXP4xx crypto hardware acceleration
+   depends on ARCH_IXP4XX
+   select CRYPTO_DES
+   select CRYPTO_ALGAPI
+   select CRYPTO_BLKCIPHER
+   help
+ Driver for the IXP4xx NPE crypto engine.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index d29d2cd..73557b2 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o
 obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
 obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
 obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o
+obj-$(CONFIG_CRYPTO_DEV_IXP4XX) += ixp4xx_crypto.o
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
new file mode 100644
index 000..42a107f
--- /dev/null
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -0,0 +1,1506 @@
+/*
+ * Intel IXP4xx NPE-C crypto driver
+ *
+ * Copyright (C) 2008 Christian Hohnstaedt [EMAIL PROTECTED]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ */
+
+#include linux/platform_device.h
+#include linux/dma-mapping.h
+#include linux/dmapool.h
+#include linux/crypto.h
+#include linux/kernel.h
+#include linux/rtnetlink.h
+#include linux/interrupt.h
+#include linux/spinlock.h
+
+#include crypto/ctr.h
+#include crypto/des.h
+#include crypto/aes.h
+#include crypto/sha.h
+#include crypto/algapi.h
+#include crypto/aead.h
+#include crypto/authenc.h
+#include crypto/scatterwalk.h
+
+#include asm/arch/npe.h
+#include asm/arch/qmgr.h
+
+#define MAX_KEYLEN 32
+
+/* hash: cfgword + 2 * digestlen; crypt: keylen + cfgword */
+#define NPE_CTX_LEN 80
+#define AES_BLOCK128 16
+
+#define NPE_OP_HASH_VERIFY   0x01
+#define NPE_OP_CCM_ENABLE0x04
+#define NPE_OP_CRYPT_ENABLE  0x08
+#define NPE_OP_HASH_ENABLE   0x10
+#define NPE_OP_NOT_IN_PLACE  0x20
+#define NPE_OP_HMAC_DISABLE  0x40
+#define NPE_OP_CRYPT_ENCRYPT 0x80
+
+#define NPE_OP_CCM_GEN_MIC   0xcc
+#define NPE_OP_HASH_GEN_ICV  0x50
+#define NPE_OP_ENC_GEN_KEY   0xc9
+
+#define MOD_ECB 0x
+#define MOD_CTR 0x1000
+#define MOD_CBC_ENC 0x2000
+#define MOD_CBC_DEC 0x3000
+#define MOD_CCM_ENC 0x4000
+#define MOD_CCM_DEC 0x5000
+
+#define KEYLEN_128  4
+#define KEYLEN_192  6
+#define KEYLEN_256  8
+
+#define CIPH_DECR   0x
+#define CIPH_ENCR   0x0400
+
+#define MOD_DES 0x
+#define MOD_TDEA2   0x0100
+#define MOD_3DES   0x0200
+#define MOD_AES 0x0800
+#define MOD_AES128  (0x0800 | KEYLEN_128)
+#define MOD_AES192  (0x0900 | KEYLEN_192)
+#define MOD_AES256  (0x0a00 | KEYLEN_256)
+
+#define MAX_IVLEN   16
+#define NPE_ID  2  /* NPE C */
+#define NPE_QLEN16
+/* Space for registering when the first
+ * NPE_QLEN crypt_ctl are busy */
+#define NPE_QLEN_TOTAL 64
+
+#define SEND_QID29
+#define RECV_QID30
+
+#define CTL_FLAG_UNUSED0x
+#define CTL_FLAG_USED  0x1000
+#define CTL_FLAG_PERFORM_ABLK  0x0001
+#define CTL_FLAG_GEN_ICV   0x0002
+#define CTL_FLAG_GEN_REVAES0x0004
+#define CTL_FLAG_PERFORM_AEAD  0x0008
+#define CTL_FLAG_MASK  0x000f
+
+#define HMAC_IPAD_VALUE   0x36
+#define HMAC_OPAD_VALUE   0x5C
+#define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE
+
+#define MD5_DIGEST_SIZE   16
+
+struct buffer_desc {
+   u32 phys_next;
+   u16 buf_len;
+   u16 pkt_len;
+   u32 phys_addr;
+   u32 __reserved[4];
+   struct buffer_desc *next;
+};
+
+struct crypt_ctl {
+   u8 mode;/* NPE_OP_*  operation mode */
+   u8 init_len;
+   u16 reserved;
+   u8 iv[MAX_IVLEN];   /* IV for CBC mode or CTR IV for CTR mode */
+   u32 icv_rev_aes;/* icv or rev aes */
+   u32 src_buf;
+   u32 dst_buf;
+   u16 auth_offs;  /* Authentication start offset */
+   u16 auth_len;   /* Authentication data length */
+   u16 crypt_offs; /* Cryption start offset */
+   u16 crypt_len;  /* Cryption data length */
+   u32 aadAddr;/* Additional Auth