Re: [PATCH 1/3] crypto: omap-des: Add omap-des driver for OMAP4/AM43xx

2013-09-10 Thread Joel Fernandes
On 08/30/2013 04:19 AM, Rajendra Nayak wrote:
> []..
> 
>> +
>> +#define pr_fmt(fmt) "%s: " fmt, __func__
>> +
>> +#ifdef DEBUG
>> +#define prn(num) printk(#num "=%d\n", num)
>> +#define prx(num) printk(#num "=%x\n", num)
>> +#else
>> +#define prn(num) do { } while (0)
>> +#define prx(num)  do { } while (0)
>> +#endif
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define DST_MAXBURST2
>> +
>> +#define DES_BLOCK_WORDS (DES_BLOCK_SIZE >> 2)
>> +
>> +#define _calc_walked(inout) (dd->inout##_walk.offset - 
>> dd->inout##_sg->offset)
>> +
>> +#define DES_REG_KEY(dd, x)  ((dd)->pdata->key_ofs - \
>> +((x ^ 0x01) * 0x04))
>> +
>> +#define DES_REG_IV(dd, x)   ((dd)->pdata->iv_ofs + ((x) * 0x04))
>> +
>> +#define DES_REG_CTRL(dd)((dd)->pdata->ctrl_ofs)
>> +#define DES_REG_CTRL_CBC(1 << 4)
>> +#define DES_REG_CTRL_TDES   (1 << 3)
>> +#define DES_REG_CTRL_DIRECTION  (1 << 2)
>> +#define DES_REG_CTRL_INPUT_READY(1 << 1)
>> +#define DES_REG_CTRL_OUTPUT_READY   (1 << 0)
> 
> Why not use bitops like you have done below.

Ok, will do that.

> 
>> +
>> +#define DES_REG_DATA_N(dd, x)   ((dd)->pdata->data_ofs + ((x) * 
>> 0x04))
>> +
>> +#define DES_REG_REV(dd) ((dd)->pdata->rev_ofs)
>> +
>> +#define DES_REG_MASK(dd)((dd)->pdata->mask_ofs)
>> +
>> +#define DES_REG_LENGTH_N(x) (0x24 + ((x) * 0x04))
>> +
>> +#define DES_REG_IRQ_STATUS(dd) ((dd)->pdata->irq_status_ofs)
>> +#define DES_REG_IRQ_ENABLE(dd) ((dd)->pdata->irq_enable_ofs)
>> +#define DES_REG_IRQ_DATA_INBIT(1)
>> +#define DES_REG_IRQ_DATA_OUT   BIT(2)
>> +
>> +#define FLAGS_MODE_MASK 0x000f
>> +#define FLAGS_ENCRYPT   BIT(0)
>> +#define FLAGS_CBC   BIT(1)
>> +#define FLAGS_INIT  BIT(4)
>> +#define FLAGS_BUSY  BIT(6)
>> +
> 
> []..
> 
>> +struct omap_des_pdata {
>> +struct omap_des_algs_info   *algs_info;
>> +unsigned intalgs_info_size;
>> +
>> +void(*trigger)(struct omap_des_dev *dd, int length);
> 
> Is this really used? How does a DT platform pass function pointers?

This is hard coded in the pdata structures for each platform and provided once
the DT matches. Different platforms may have different pdata.

>> +
>> +u32 key_ofs;
>> +u32 iv_ofs;
>> +u32 ctrl_ofs;
>> +u32 data_ofs;
>> +u32 rev_ofs;
>> +u32 mask_ofs;
>> +u32 irq_enable_ofs;
>> +u32 irq_status_ofs;
>> +
>> +u32 dma_enable_in;
>> +u32 dma_enable_out;
>> +u32 dma_start;
>> +
>> +u32 major_mask;
>> +u32 major_shift;
>> +u32 minor_mask;
>> +u32 minor_shift;
>> +};
>> +
>> +struct omap_des_dev {
>> +struct list_headlist;
>> +unsigned long   phys_base;
>> +void __iomem*io_base;
>> +struct omap_des_ctx *ctx;
>> +struct device   *dev;
>> +unsigned long   flags;
>> +int err;
>> +
>> +/* spinlock used for queues */
>> +spinlock_t  lock;
>> +struct crypto_queue queue;
>> +
>> +struct tasklet_struct   done_task;
>> +struct tasklet_struct   queue_task;
>> +
>> +struct ablkcipher_request   *req;
>> +/*
>> + * total is used by PIO mode for book keeping so introduce
>> + * variable total_save as need it to calc page_order
>> + */
>> +size_t  total;
>> +size_t  total_save;
>> +
>> +struct scatterlist  *in_sg;
>> +struct scatterlist  *out_sg;
>> +
>> +/* Buffers for copying for unaligned cases */
>> +struct scatterlist  in_sgl;
>> +struct scatterlist  out_sgl;
>> +struct scatterlist  *orig_out;
>> +int sgs_copied;
>> +
>> +struct scatter_walk in_walk;
>> +struct scatter_walk out_walk;
>> +int dma_in;
>> +struct dma_chan *dma_lch_in;
>> +int dma_out;
>> +struct dma_chan *dma_lch_out;
>> +int in_sg_len;
>> +int out_sg_len;
>> +int pio_only;
>> +const struct omap_des_pdata *pdata;
>> +};
>> +
>> +/* keep registered devices data here */
>> +static LIST_HEAD(dev_list);
>> +static DEFINE_SPINLOCK(list_lock);
>> +
> 
> []..
> 
>> +
>> +static int omap_des_

Re: [PATCH 1/3] crypto: omap-des: Add omap-des driver for OMAP4/AM43xx

2013-08-30 Thread Rajendra Nayak
[]..

> +
> +#define pr_fmt(fmt) "%s: " fmt, __func__
> +
> +#ifdef DEBUG
> +#define prn(num) printk(#num "=%d\n", num)
> +#define prx(num) printk(#num "=%x\n", num)
> +#else
> +#define prn(num) do { } while (0)
> +#define prx(num)  do { } while (0)
> +#endif
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DST_MAXBURST 2
> +
> +#define DES_BLOCK_WORDS  (DES_BLOCK_SIZE >> 2)
> +
> +#define _calc_walked(inout) (dd->inout##_walk.offset - 
> dd->inout##_sg->offset)
> +
> +#define DES_REG_KEY(dd, x)   ((dd)->pdata->key_ofs - \
> + ((x ^ 0x01) * 0x04))
> +
> +#define DES_REG_IV(dd, x)((dd)->pdata->iv_ofs + ((x) * 0x04))
> +
> +#define DES_REG_CTRL(dd) ((dd)->pdata->ctrl_ofs)
> +#define DES_REG_CTRL_CBC (1 << 4)
> +#define DES_REG_CTRL_TDES(1 << 3)
> +#define DES_REG_CTRL_DIRECTION   (1 << 2)
> +#define DES_REG_CTRL_INPUT_READY (1 << 1)
> +#define DES_REG_CTRL_OUTPUT_READY(1 << 0)

Why not use bitops like you have done below.

> +
> +#define DES_REG_DATA_N(dd, x)((dd)->pdata->data_ofs + ((x) * 
> 0x04))
> +
> +#define DES_REG_REV(dd)  ((dd)->pdata->rev_ofs)
> +
> +#define DES_REG_MASK(dd) ((dd)->pdata->mask_ofs)
> +
> +#define DES_REG_LENGTH_N(x)  (0x24 + ((x) * 0x04))
> +
> +#define DES_REG_IRQ_STATUS(dd) ((dd)->pdata->irq_status_ofs)
> +#define DES_REG_IRQ_ENABLE(dd) ((dd)->pdata->irq_enable_ofs)
> +#define DES_REG_IRQ_DATA_INBIT(1)
> +#define DES_REG_IRQ_DATA_OUT   BIT(2)
> +
> +#define FLAGS_MODE_MASK  0x000f
> +#define FLAGS_ENCRYPTBIT(0)
> +#define FLAGS_CBCBIT(1)
> +#define FLAGS_INIT   BIT(4)
> +#define FLAGS_BUSY   BIT(6)
> +

[]..

> +struct omap_des_pdata {
> + struct omap_des_algs_info   *algs_info;
> + unsigned intalgs_info_size;
> +
> + void(*trigger)(struct omap_des_dev *dd, int length);

Is this really used? How does a DT platform pass function pointers?

> +
> + u32 key_ofs;
> + u32 iv_ofs;
> + u32 ctrl_ofs;
> + u32 data_ofs;
> + u32 rev_ofs;
> + u32 mask_ofs;
> + u32 irq_enable_ofs;
> + u32 irq_status_ofs;
> +
> + u32 dma_enable_in;
> + u32 dma_enable_out;
> + u32 dma_start;
> +
> + u32 major_mask;
> + u32 major_shift;
> + u32 minor_mask;
> + u32 minor_shift;
> +};
> +
> +struct omap_des_dev {
> + struct list_headlist;
> + unsigned long   phys_base;
> + void __iomem*io_base;
> + struct omap_des_ctx *ctx;
> + struct device   *dev;
> + unsigned long   flags;
> + int err;
> +
> + /* spinlock used for queues */
> + spinlock_t  lock;
> + struct crypto_queue queue;
> +
> + struct tasklet_struct   done_task;
> + struct tasklet_struct   queue_task;
> +
> + struct ablkcipher_request   *req;
> + /*
> +  * total is used by PIO mode for book keeping so introduce
> +  * variable total_save as need it to calc page_order
> +  */
> + size_t  total;
> + size_t  total_save;
> +
> + struct scatterlist  *in_sg;
> + struct scatterlist  *out_sg;
> +
> + /* Buffers for copying for unaligned cases */
> + struct scatterlist  in_sgl;
> + struct scatterlist  out_sgl;
> + struct scatterlist  *orig_out;
> + int sgs_copied;
> +
> + struct scatter_walk in_walk;
> + struct scatter_walk out_walk;
> + int dma_in;
> + struct dma_chan *dma_lch_in;
> + int dma_out;
> + struct dma_chan *dma_lch_out;
> + int in_sg_len;
> + int out_sg_len;
> + int pio_only;
> + const struct omap_des_pdata *pdata;
> +};
> +
> +/* keep registered devices data here */
> +static LIST_HEAD(dev_list);
> +static DEFINE_SPINLOCK(list_lock);
> +

[]..

> +
> +static int omap_des_crypt_dma_start(struct omap_des_dev *dd)
> +{
> + struct crypto_tfm *tfm = crypto_ablkcipher_tfm(
> + crypto_ablkcipher_reqtfm(dd->req));
> + int err;
> +
> + pr_debug("total: %d\n", dd->total);
> +
> + if (!dd->pio_only) {
> + err = dma_map_sg(dd->d

Re: [PATCH 1/3] crypto: omap-des: Add omap-des driver for OMAP4/AM43xx

2013-08-29 Thread Joel Fernandes
On 08/29/2013 06:27 PM, Joel Fernandes wrote:
> Add omap-des driver with platform data for OMAP4. Support added for DES
> ECB and CBC modes.
> 
> Where possible, code is reused from omap-aes driver with changes made for
> adjusting key size, block size, removing non-existent encryption modes
> and adding support for OMAP4 platform data and offsets.
> 
> Tests have been conducted with the CRYPTO test manager, and functionality
> is verified at different page length alignments.
> 
> Signed-off-by: Joel Fernandes 
> ---
>  drivers/crypto/omap-des.c | 1192 
> +
>  1 file changed, 1192 insertions(+)
>  create mode 100644 drivers/crypto/omap-des.c
> 
> diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
> new file mode 100644
> index 000..6a9a25f
> --- /dev/null
> +++ b/drivers/crypto/omap-des.c
> @@ -0,0 +1,1192 @@
> +/*
> + * Cryptographic API.
> + *
> + * Support for OMAP DES and Triple DES HW acceleration.
> + *
> + * Copyright (c) 2012 Texas Instruments Incorporated
> + * Author: Joel Fernandes 

Have to change this to 2013. Will do so if there are no other comments.

Regards,

-Joel

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


[PATCH 1/3] crypto: omap-des: Add omap-des driver for OMAP4/AM43xx

2013-08-29 Thread Joel Fernandes
Add omap-des driver with platform data for OMAP4. Support added for DES
ECB and CBC modes.

Where possible, code is reused from omap-aes driver with changes made for
adjusting key size, block size, removing non-existent encryption modes
and adding support for OMAP4 platform data and offsets.

Tests have been conducted with the CRYPTO test manager, and functionality
is verified at different page length alignments.

Signed-off-by: Joel Fernandes 
---
 drivers/crypto/omap-des.c | 1192 +
 1 file changed, 1192 insertions(+)
 create mode 100644 drivers/crypto/omap-des.c

diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
new file mode 100644
index 000..6a9a25f
--- /dev/null
+++ b/drivers/crypto/omap-des.c
@@ -0,0 +1,1192 @@
+/*
+ * Cryptographic API.
+ *
+ * Support for OMAP DES and Triple DES HW acceleration.
+ *
+ * Copyright (c) 2012 Texas Instruments Incorporated
+ * Author: Joel Fernandes 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ */
+
+#define pr_fmt(fmt) "%s: " fmt, __func__
+
+#ifdef DEBUG
+#define prn(num) printk(#num "=%d\n", num)
+#define prx(num) printk(#num "=%x\n", num)
+#else
+#define prn(num) do { } while (0)
+#define prx(num)  do { } while (0)
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DST_MAXBURST   2
+
+#define DES_BLOCK_WORDS(DES_BLOCK_SIZE >> 2)
+
+#define _calc_walked(inout) (dd->inout##_walk.offset - dd->inout##_sg->offset)
+
+#define DES_REG_KEY(dd, x) ((dd)->pdata->key_ofs - \
+   ((x ^ 0x01) * 0x04))
+
+#define DES_REG_IV(dd, x)  ((dd)->pdata->iv_ofs + ((x) * 0x04))
+
+#define DES_REG_CTRL(dd)   ((dd)->pdata->ctrl_ofs)
+#define DES_REG_CTRL_CBC   (1 << 4)
+#define DES_REG_CTRL_TDES  (1 << 3)
+#define DES_REG_CTRL_DIRECTION (1 << 2)
+#define DES_REG_CTRL_INPUT_READY   (1 << 1)
+#define DES_REG_CTRL_OUTPUT_READY  (1 << 0)
+
+#define DES_REG_DATA_N(dd, x)  ((dd)->pdata->data_ofs + ((x) * 0x04))
+
+#define DES_REG_REV(dd)((dd)->pdata->rev_ofs)
+
+#define DES_REG_MASK(dd)   ((dd)->pdata->mask_ofs)
+
+#define DES_REG_LENGTH_N(x)(0x24 + ((x) * 0x04))
+
+#define DES_REG_IRQ_STATUS(dd) ((dd)->pdata->irq_status_ofs)
+#define DES_REG_IRQ_ENABLE(dd) ((dd)->pdata->irq_enable_ofs)
+#define DES_REG_IRQ_DATA_INBIT(1)
+#define DES_REG_IRQ_DATA_OUT   BIT(2)
+
+#define FLAGS_MODE_MASK0x000f
+#define FLAGS_ENCRYPT  BIT(0)
+#define FLAGS_CBC  BIT(1)
+#define FLAGS_INIT BIT(4)
+#define FLAGS_BUSY BIT(6)
+
+struct omap_des_ctx {
+   struct omap_des_dev *dd;
+
+   int keylen;
+   u32 key[DES_KEY_SIZE / sizeof(u32)];
+   unsigned long   flags;
+};
+
+struct omap_des_reqctx {
+   unsigned long mode;
+};
+
+#define OMAP_DES_QUEUE_LENGTH  1
+#define OMAP_DES_CACHE_SIZE0
+
+struct omap_des_algs_info {
+   struct crypto_alg   *algs_list;
+   unsigned intsize;
+   unsigned intregistered;
+};
+
+struct omap_des_pdata {
+   struct omap_des_algs_info   *algs_info;
+   unsigned intalgs_info_size;
+
+   void(*trigger)(struct omap_des_dev *dd, int length);
+
+   u32 key_ofs;
+   u32 iv_ofs;
+   u32 ctrl_ofs;
+   u32 data_ofs;
+   u32 rev_ofs;
+   u32 mask_ofs;
+   u32 irq_enable_ofs;
+   u32 irq_status_ofs;
+
+   u32 dma_enable_in;
+   u32 dma_enable_out;
+   u32 dma_start;
+
+   u32 major_mask;
+   u32 major_shift;
+   u32 minor_mask;
+   u32 minor_shift;
+};
+
+struct omap_des_dev {
+   struct list_headlist;
+   unsigned long   phys_base;
+   void __iomem*io_base;
+   struct omap_des_ctx *ctx;
+   struct device   *dev;
+   unsigned long   flags;
+   int err;
+
+   /* spinlock used for queues */
+   spinlock_t  lock;
+   struct crypto_queue queue;
+
+   struct tasklet_struct   done_task;
+   struct tasklet_struct   queue_task;
+
+   struct ablkcipher_request   *req;
+   /*
+* total is used by PIO mode for book keeping so introduce
+* variable total_save as need it to calc page_order
+*/
+   size_t