crypto: driver for tegra AES hardware
PATCH 1/1 crypto: driver for tegra AES hardware
From: Varun Wadekar <[email protected]>
driver supports ecb/cbc/ofb/ansi_x9.31rng modes,
128, 192 and 256-bit key sizes.
--- drivers/crypto/Kconfig | 8 + drivers/crypto/Makefile | 2 + drivers/crypto/tegra-aes.c | 1120 ++++++++++++++++++++++++++++++++++++++++++++ drivers/crypto/tegra-aes.h | 114 +++++ 4 files changed, 1244 insertions(+), 0 deletions(-) create mode 100644 drivers/crypto/tegra-aes.c create mode 100644 drivers/crypto/tegra-aes.h
drivers/crypto/Kconfig +8 -0
@@ -293,4 +293,12 @@ config CRYPTO_DEV_S5P Select this to offload Samsung S5PV210 or S5PC110 from AES algorithms execution. +config CRYPTO_DEV_TEGRA_AES + tristate "Support for TEGRA AES hw engine" + depends on ARCH_TEGRA_2x_SOC + select CRYPTO_AES + help + TEGRA processors have AES module accelerator. Select this if you + want to use the TEGRA module for AES algorithms. + endif # CRYPTO_HW
drivers/crypto/Makefile +2 -0
@@ -13,3 +13,5 @@ obj-$(CONFIG_CRYPTO_DEV_OMAP_SHAM) += omap-sham.o obj-$(CONFIG_CRYPTO_DEV_OMAP_AES) += omap-aes.o obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o +obj-$(CONFIG_CRYPTO_DEV_TEGRA_AES) += tegra-aes.o +
drivers/crypto/tegra-aes.c new file +1120 -0
1,120 lines not on this page · raw message
drivers/crypto/tegra-aes.h new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): 1320405256-29374-1-git-send-email-vwadekar-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Hi Varun,
thanks that you come up with an "official" patch for the aes-stuff.
Against which tree you did test the patch?
I tested it against git://git.kernel.org/pub/scm/linux/kernel/git/olof/tegra.git for-next choose to build it as module and got the following errors:
drivers/crypto/tegra-aes.c: In function 'aes_start_crypt':drivers/crypto/tegra-aes.c:226:13: error: 'eng' undeclared (first use in this function) drivers/crypto/tegra-aes.c:226:13: note: each undeclared identifier is reported only once for each function it appears in drivers/crypto/tegra-aes.c: In function 'aes_irq':drivers/crypto/tegra-aes.c:614:18: error: 'intr_err_mask' undeclared (first use in this function) drivers/crypto/tegra-aes.c:620:1: warning: label 'done' defined but not used
Which are problems inside the driver it self, which can be easy fixed:
- aes_writel(eng, 0xFFFFFFFF, INTR_STATUS);
+ aes_writel(dd, 0xFFFFFFFF, INTR_STATUS);
- aes_writel(dd, intr_err_mask, INTR_STATUS);
+ aes_writel(dd, INT_ERROR_MASK, INTR_STATUS);
Second problem it don't build as modul
first:
typo inMODULE_LICENSE("GPLv2") it needs a space MODULE_LICENSE("GPL v2")
second:tegra_chip_uid function is not exported
I have attched patch which fixes all the stuff besides the not used variable. I did not runtime test it for 3.x kernels, but works backported to the 2.6.38-chromeos tree.
Bye Henning
Quoted 1 line
From
96d513a1688e4d1f53f79d099950cb0ad2899848Mon Sep 17 00:00:00 2001
From: Henning Heinold <[email protected]>
Date: Fri, 4 Nov 2011 14:52:58 +0100
Subject: [PATCH] arm:tegra:aes: fix building as module
--- arch/arm/mach-tegra/fuse.c | 2 ++ drivers/crypto/tegra-aes.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/mach-tegra/fuse.c +2 -0
@@ -19,6 +19,7 @@#include <linux/kernel.h> #include <linux/io.h> +#include <linux/module.h> #include <mach/iomap.h>
@@ -58,6 +59,7 @@ unsigned long long tegra_chip_uid(void) hi =fuse_readl (FUSE_UID_HIGH );return (hi <<32ull ) | lo; } +EXPORT_SYMBOL (tegra_chip_uid);int tegra_sku_id (void ) {
drivers/crypto/tegra-aes.c +3 -3
@@ -223,7 +223,7 @@ static int aes_start_crypt(struct tegra_aes_dev *dd, u32 in_addr, u32 out_addr,u32 value;/* reset all the interrupt bits */ -aes_writel (eng,0xFFFFFFFF ,INTR_STATUS ); +aes_writel (dd,0xFFFFFFFF ,INTR_STATUS );/* enable error, dma xfer complete interrupts */ aes_writel (dd,0x33 ,INT_ENB );
@@ -611,7 +611,7 @@ static irqreturn_t aes_irq(int irq, void *dev_id)dev_dbg (dd->dev,"irq_stat: 0x%x" , value);if (value &INT_ERROR_MASK ) -aes_writel (dd, intr_err_mask,INTR_STATUS ); +aes_writel (dd,INT_ERROR_MASK ,INTR_STATUS ); value =aes_readl (dd,INTR_STATUS );if (!(value &ENGINE_BUSY_FIELD ))
@@ -1117,4 +1117,4 @@ module_exit(tegra_aes_module_exit);MODULE_DESCRIPTION ("Tegra AES/OFB/CPRNG hw acceleration support." );MODULE_AUTHOR ("NVIDIA Corporation" ); -MODULE_LICENSE ("GPLv2" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
1.7.7.1
A message that is not in the archive (sent off-list or not yet received): 20111104135436.GA29112-/JE64I/[email protected]
Quoted 5 lines · Henning Heinold
Hi Varun,
thanks that you come up with an "official" patch for the aes-stuff.
Against which tree you did test the patch?
I tested it against Linus's master branch but unfortunately, some other changes crept inside this patch due to which you saw that compilation errors.
Quoted 18 lines
I tested it against
git://git.kernel.org/pub/scm/linux/kernel/git/olof/tegra.gitfor-next choose to build it as module and got the following errors:
drivers/crypto/tegra-aes.c: In function 'aes_start_crypt':drivers/crypto/tegra-aes.c:226:13: error: 'eng' undeclared (first use in this function)drivers/crypto/tegra-aes.c:226:13: note: each undeclared identifier is reported only once for each function it appears indrivers/crypto/tegra-aes.c: In function 'aes_irq':drivers/crypto/tegra-aes.c:614:18: error: 'intr_err_mask' undeclared (first use in this function)drivers/crypto/tegra-aes.c:620:1: warning: label 'done' defined but not usedWhich are problems inside the driver it self, which can be easy fixed:
drivers/crypto/tegra-aes.c +2
-2-aes_writel (eng,0xFFFFFFFF ,INTR_STATUS ); +aes_writel (dd,0xFFFFFFFF ,INTR_STATUS ); -aes_writel (dd, intr_err_mask,INTR_STATUS ); +aes_writel (dd,INT_ERROR_MASK ,INTR_STATUS );
Quoted 5 lines
Second problem it don't build as modul
first:
typo inMODULE_LICENSE("GPLv2")it needs a spaceMODULE_LICENSE("GPL v2")
All the above changes will be present in my next patch.
Quoted 2 lines
second:
tegra_chip_uidfunction is not exported
Will submit a different patch to Olof and Stephen to get this change in the mach-tegra tree. If you want to post the fuse changes to them yourself, please go ahead.
Quoted 3 lines
I have attched patch which fixes all the stuff besides the not used variable. I did not runtime test it for 3.x kernels, but works backported to the 2.6.38-chromeos tree.
Thanks for your help.
Quoted 1 line
Bye Henning
Varun Wadekar wrote at Friday, November 04, 2011 5:14 AM:
Quoted 1 line
From: Varun Wadekar <[email protected]>
If you teach git your full name, it'll omit this From: header from the email body, which will be a little more idiomatic:
git config --global sendemail.from "Varun Wadekar <[email protected]>"
Quoted 4 lines
driver supports ecb/cbc/ofb/ansi_x9.31rng modes,
128, 192 and 256-bit key sizes.Change-Id: Ic7d8d6d76b8ab6712f3bc9048e2dee7b5ebd13ff
Please remove the Change-Id lines from patches before posting them.
Quoted 1 line
Signed-off-by Varun Wadekar <[email protected]>
I ran this patch through checkpatch, and there's one error and some warnings to fix.
drivers/crypto/Kconfig config CRYPTO_DEV_S5P · line 298
Quoted 3 lines
drivers/crypto/Kconfig +3
-0+config CRYPTO_DEV_TEGRA_AES + tristate "Support for TEGRA AES hw engine" + depends on ARCH_TEGRA_2x_SOC
Is this HW specific to Tegra20 such that the driver won't be useful for Tegra30? In other words, should this depend on ARCH_TEGRA instead?
Quoted 1 line
drivers/crypto/Makefile +0
-0
...
drivers/crypto/Makefile obj-$(CONFIG_CRYPTO_DEV_OMAP_SHAM) += omap-sham.o · line 17
Quoted 3 lines
obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o
drivers/crypto/Makefile +2
-0+obj-$(CONFIG_CRYPTO_DEV_TEGRA_AES) += tegra-aes.o +
Can you please remove the extra blank line?
drivers/crypto/Makefile
Quoted 11 lines
drivers/crypto/Makefile +11
-0+static int tegra_aes_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct tegra_aes_dev *dd; + struct resource *res; + int err = -ENOMEM, i = 0, j; + + if (aes_dev) + return -EEXIST; + + dd = kzalloc(sizeof(struct tegra_aes_dev), GFP_KERNEL);
If you use devm_kzalloc here, and other devm_*() functions throughout, you'll need a bunch less cleanup code in the failure path in probe(), and the teardown path in remove().
drivers/crypto/Makefile
Quoted 1 line
drivers/crypto/Makefile +1
-0+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Don't you need to call request_mem_region() between get_resource() and ioremap()?
drivers/crypto/Makefile
Quoted 1 line
drivers/crypto/Makefile +1
-0+ dd->io_base = ioremap(dd->phys_base, resource_size(res));
There's a devm_ variant for this.
drivers/crypto/Makefile
Quoted 2 lines
drivers/crypto/Makefile +2
-0+ /* Initialize the vde clock */ + dd->aes_clk = clk_get(dev, "vde");
That clock doesn't exist in the mainline kernel; "bsev" exists for device "tegra-aes"...
drivers/crypto/Makefile
Quoted 1 line
drivers/crypto/Makefile +1
-0+ err = clk_set_rate(dd->aes_clk, ULONG_MAX);
That's a little fast... What rate should it be running at. Is this something the driver should be configuring, or should the board file or device-tree be configuring this?
drivers/crypto/Makefile
Quoted 2 lines
drivers/crypto/Makefile +2
-0+ err = request_irq(INT_VDE_BSE_V, aes_irq, IRQF_TRIGGER_HIGH, + "tegra-aes", dd);
Shouldn't the IRQ number come from a resource rather than being hard-coded?
drivers/crypto/Makefile
Quoted 8 lines
drivers/crypto/Makefile +8
-0+static struct platform_driver tegra_aes_driver = { + .probe = tegra_aes_probe, + .remove = __devexit_p(tegra_aes_remove), + .driver = { + .name = "tegra-aes", + .owner = THIS_MODULE, + }, +};
Can you please allow instantiation from device-tree too; see drivers/ gpio/gpio-tegra.c's tegra_gpio_of_match[] for an example.
drivers/crypto/tegra-aes.h
Quoted 3 lines
drivers/crypto/tegra-aes.h +1
-0+#define ICMDQUE_WR 0x1000
It'd be nice to prefix all the defines in this file with e.g. TEGRA_AES_ so that they're guaranteed not to conflict with any unrelated defines.
Signature · 1 line
nvpublic
A message that is not in the archive (sent off-list or not yet received): 74CDBE0F657A3D45AFBB94109FB122FF173F9A4E83-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org
Quoted 3 lines
drivers/crypto/tegra-aes.c line 932
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );Don't you need to call
request_mem_region()betweenget_resource()andioremap()?
I am remapping the module register space. Used IORESOURCE_IO instead.
Quoted 7 lines
drivers/crypto/tegra-aes.c line 948
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +2
-0+/* Initialize the vde clock */ + dd->aes_clk =clk_get (dev,"vde" );That clock doesn't exist in the mainline kernel; "bsev" exists for device "tegra-aes"...
We need to use the "vde" clock. I will submit a patch to add the "vde" clock. "bsev" might not be needed at the moment.
Quoted 5 lines
drivers/crypto/tegra-aes.c line 955
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+ err =clk_set_rate (dd->aes_clk,ULONG_MAX );That's a little fast... What rate should it be running at. Is this something the driver should be configuring, or should the board file or device-tree be configuring this?
We need to run the hardware at the highest speed. AFAIK, clk_set_rate(ULONG_MAX) will set the clock rate at the max clock specified for the clock. Need to get every bit of performance from that piece of hardware.
Quoted 10 lines
drivers/crypto/tegra-aes.c line 1101
Quoted 8 lines
drivers/crypto/tegra-aes.c new file +8
-0+static struct platform_driver tegra_aes_driver = { + .probe = tegra_aes_probe, + .remove =__devexit_p (tegra_aes_remove), + .driver = { + .name ="tegra-aes" , + .owner =THIS_MODULE , + }, +};Can you please allow instantiation from device-tree too; see
drivers/gpio/gpio-tegra.c's tegra_gpio_of_match[] for an example.
Actually, I am planning to add complete device tree support in the next patch. But if you insist, I can add partial support here and then complete it in the next patch.
Quoted 8 lines
Quoted 6 lines
drivers/crypto/tegra-aes.c line 948
Quoted 3 lines
drivers/crypto/tegra-aes.c new file +2
-0+/* Initialize the vde clock */ + dd->aes_clk =clk_get (dev,"vde" );That clock doesn't exist in the mainline kernel; "bsev" exists for device "tegra-aes"...
We need to use the "vde" clock. I will submit a patch to add the "vde" clock. "bsev" might not be needed at the moment.
Just checked and we have "vde" as a duplicate clock for "tegra-aes"
A message that is not in the archive (sent off-list or not yet received): [email protected]
Varun Wadekar wrote at Saturday, November 05, 2011 2:12 AM:
Quoted 5 lines
Quoted 3 lines
drivers/crypto/tegra-aes.c line 932
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );Don't you need to call
request_mem_region()betweenget_resource()andioremap()?I am remapping the module register space. Used
IORESOURCE_IOinstead.
But you should be using IORESOURCE_MEM; that's what it is, and that's what all the other entries in arch/arm/mach-tegra/devices.c use.
And I don't think simply changing the type of the resource would remove the need to request that region of MEM or IO space.
Quoted 10 lines
Quoted 4 lines
drivers/crypto/tegra-aes.c line 948
Quoted 2 lines
drivers/crypto/tegra-aes.c new file +2
-0+/* Initialize the vde clock */ + dd->aes_clk =clk_get (dev,"vde" );That clock doesn't exist in the mainline kernel; "bsev" exists for device "tegra-aes"...
We need to use the "vde" clock. I will submit a patch to add the "vde" clock. "bsev" might not be needed at the moment.
[from another email by Varun]
Just checked and we have "vde" as a duplicate clock for "tegra-aes"
Ah right, I do see the CLK_DUPLICATE line. So, this is probably fine.
Quoted 9 lines
Quoted 4 lines
drivers/crypto/tegra-aes.c line 955
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+ err =clk_set_rate (dd->aes_clk,ULONG_MAX );That's a little fast... What rate should it be running at. Is this something the driver should be configuring, or should the board file or device-tree be configuring this?
We need to run the hardware at the highest speed. AFAIK,
clk_set_rate(ULONG_MAX)will set the clock rate at the max clock specified for the clock. Need to get every bit of performance from that piece of hardware.
Hmmm. This still seems wrong. Hopefully somebody else more familiar with clocks will chime in either saying this is fine, or pointing out a better way to do this.
Quoted 12 lines
Quoted 11 lines
drivers/crypto/tegra-aes.c line 1101
Quoted 9 lines
drivers/crypto/tegra-aes.c new file +8
-0+static struct platform_driver tegra_aes_driver = { + .probe = tegra_aes_probe, + .remove =__devexit_p (tegra_aes_remove), + .driver = { + .name ="tegra-aes" , + .owner =THIS_MODULE , + }, +};Can you please allow instantiation from device-tree too; see
drivers/gpio/gpio-tegra.c's tegra_gpio_of_match[] for an example.
Quoted 3 lines
Actually, I am planning to add complete device tree support in the next patch. But if you insist, I can add partial support here and then complete it in the next patch.
Why not just add complete device-tree support from the start? Since this driver uses no platform data, isn't the of match table the /only/ device- tree support this driver needs?
Signature · 1 line
nvpublic
drivers/crypto/tegra-aes.c line 105
Quoted 4 lines · On Fri, 4 Nov 2011 16:44:16 +0530 <[email protected]> wrote:
drivers/crypto/tegra-aes.c new file +4
-0+/* Define sub-commands */ +enum { +SUBCMD_VRAM_SEL =0x1 , +SUBCMD_CRYPTO_TABLESEL =0x3 ,
SUBCMD_CRYPTO_TABLE_SEL, to match VRAM_SEL for a more consistent naming convention
drivers/crypto/tegra-aes.c line 106
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+ SUBCMD_KEYTABLESEL = 0x8,
SUBCMD_KEY_TABLE_SEL?
drivers/crypto/tegra-aes.c line 113
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +5
-0+/* memdma_vd command */ +#define MEMDMA_DIR_DTOVRAM 0/* sdram -> vram */ +#define MEMDMA_DIR_VTODRAM 1/* vram -> sdram */ +#define MEMDMABITSHIFT_DIR 25 +#define MEMDMABITSHIFT_NUM_WORDS 12
MEMDMA_DIR_SHIFT, MEMDMA_NUM_WORDS_SHIFT
drivers/crypto/tegra-aes.c line 121
Quoted 8 lines
drivers/crypto/tegra-aes.c new file +8
-0+ +/* command queue bit shifts */ +enum { +CMDQBITSHIFT_KEYTABLEADDR =0 , +CMDQBITSHIFT_KEYTABLEID =17 , +CMDQBITSHIFT_VRAMSEL =23 , +CMDQBITSHIFT_TABLESEL =24 , +CMDQBITSHIFT_OPCODE =26 ,
same here. Seems to better suit existing naming strategy in this driver.
drivers/crypto/tegra-aes.c line 230
Quoted 13 lines
drivers/crypto/tegra-aes.c new file +13
-0+static int aes_start_crypt (struct tegra_aes_dev *dd,u32 in_addr,u32 out_addr, +int nblocks,int mode,bool upd_iv) +{ +u32 cmdq[AES_HW_MAX_ICQ_LENGTH ]; +int qlen =0 , i, eng_busy, icq_empty, ret; +u32 value; + +/* reset all the interrupt bits */ +aes_writel (eng,0xFFFFFFFF ,INTR_STATUS ); + +/* enable error, dma xfer complete interrupts */ +aes_writel (dd,0x33 ,INT_ENB ); +enable_irq (INT_VDE_BSE_V );
is it really necessary to manually control the enabling and disabling of IRQs? If so, add a comment explaining why.
drivers/crypto/tegra-aes.c line 235
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+ cmdq[qlen++] =CMD_DMASETUP <<CMDQBITSHIFT_OPCODE ; + cmdq[qlen++] = in_addr; + cmdq[qlen++] =CMD_BLKSTARTENGINE <<CMDQBITSHIFT_OPCODE | (nblocks-1 ); + cmdq[qlen++] =CMD_DMACOMPLETE <<CMDQBITSHIFT_OPCODE ;
qlen appears to be AES_HW_MAX_ICQ_LENGTH -> would this be simpler?:
cmdq[0] = ..
cmdq[1] = ..
..and later qlen references be replaced with AES_HW_MAX_ICQ_LENGTH.
drivers/crypto/tegra-aes.c line 242
Quoted 6 lines
drivers/crypto/tegra-aes.c new file +6
-0+ value =aes_readl (dd,CMDQUE_CONTROL ); +/* access SDRAM through AHB */ + value &= ~CMDQ_CTRL_SRC_STM_SEL_FIELD ; + value &= ~CMDQ_CTRL_DST_STM_SEL_FIELD ; + value |= (CMDQ_CTRL_SRC_STM_SEL_FIELD |CMDQ_CTRL_DST_STM_SEL_FIELD | +CMDQ_CTRL_ICMDQEN_FIELD );
arm arch could really use some set/clr/clrsetbits helpers..
Quoted 7 lines
drivers/crypto/tegra-aes.c new file +7
-0+aes_writel (dd, value,CMDQUE_CONTROL ); +dev_dbg (dd->dev,"cmd_q_ctrl=0x%x" , value); + + value = (0x1 <<SECURE_INPUT_ALG_SEL_SHIFT ) | + ((dd->ctx->keylen *8 ) <<SECURE_INPUT_KEY_LEN_SHIFT ) | + ((u32 )upd_iv <<SECURE_IV_SELECT_SHIFT ); +
drivers/crypto/tegra-aes.c line 259
Quoted 10 lines
drivers/crypto/tegra-aes.c new file +10
-0+if (mode &FLAGS_CBC ) { + value |= ((((mode &FLAGS_ENCRYPT ) ?2 :3 ) + <<SECURE_XOR_POS_SHIFT ) | + (0 <<SECURE_INPUT_SEL_SHIFT ) | + (((mode &FLAGS_ENCRYPT ) ?2 :3 ) + <<SECURE_VCTRAM_SEL_SHIFT ) | + ((mode &FLAGS_ENCRYPT ) ?1 :0 ) + <<SECURE_CORE_SEL_SHIFT | + (0 <<SECURE_RNG_ENB_SHIFT ) | + (0 <<SECURE_HASH_ENB_SHIFT ));
simpler and easier to read if we don't assign 0 to context-irrelevant bitfields - I'm assuming such fields are non-overlapping and already guaranteed to be 0.
drivers/crypto/tegra-aes.c line 293
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +5
-0+for (i =0 ; i < qlen -1 ; i++) { + do { + value = aes_readl(dd, INTR_STATUS); + eng_busy = value & BIT(0); + icq_empty = value & BIT(3);
name BIT(0) and BIT(3)?
drivers/crypto/tegra-aes.c line 335
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +3
-0+static struct tegra_aes_slot *aes_find_key_slot (struct tegra_aes_dev *dd) + spin_unlock(&list_lock); +return found ? slot :NULL ;
leave blank lines before return statements
drivers/crypto/tegra-aes.c line 348
Quoted 11 lines
drivers/crypto/tegra-aes.c new file +11
-0+static int aes_set_key (struct tegra_aes_dev *dd) +{ +u32 value, cmdq[2 ]; +struct tegra_aes_ctx *ctx = dd->ctx; +int i, eng_busy, icq_empty, dma_busy; +bool use_ssk = false; + +if (!ctx) { +dev_err (dd->dev,"%s: context invalid\n" , __func__); +return -EINVAL ; + }
when would this condition be met?
drivers/crypto/tegra-aes.c line 369
Quoted 2 lines
drivers/crypto/tegra-aes.c new file +2
-0+if (use_ssk) + goto out;
return 0;
drivers/crypto/tegra-aes.c line 372
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +3
-0+ +/* copy the key table from sdram to vram */ + cmdq[0 ] =0 ;
not needed
drivers/crypto/tegra-aes.c line 376
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+ cmdq[0 ] =CMD_MEMDMAVD <<CMDQBITSHIFT_OPCODE | + (MEMDMA_DIR_DTOVRAM <<MEMDMABITSHIFT_DIR ) | + (AES_HW_KEY_TABLE_LENGTH_BYTES /sizeof (u32)) + <<MEMDMABITSHIFT_NUM_WORDS ;
alignment, unnecessary parens, operators at end of prior line:
cmdq[0] = CMD_MEMDMAVD << CMDQBITSHIFT_OPCODE |
MEMDMA_DIR_DTOVRAM << MEMDMABITSHIFT_DIR | AES_HW_KEY_TABLE_LENGTH_BYTES / sizeof(u32) << MEMDMABITSHIFT_NUM_WORDS;
drivers/crypto/tegra-aes.c line 380
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+ cmdq[1 ] = (u32 )dd->ivkey_phys_base; + +for (i =0 ; i <ARRAY_SIZE (cmdq); i++) +aes_writel (dd, cmdq[i],ICMDQUE_WR );
ARRAY_SIZE is 2 here - why not use a single temporary variable and two individual aes_writel()s?
drivers/crypto/tegra-aes.c line 386
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+ value =aes_readl (dd,INTR_STATUS ); + eng_busy = value &BIT (0 ); + icq_empty = value &BIT (3 ); + dma_busy = value &BIT (23 );
name bits 0, 3, and 23.
drivers/crypto/tegra-aes.c line 390
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +4
-0+ }while (eng_busy & (!icq_empty) & dma_busy); + +/* settable command to get key into internal registers */ + value =0 ;
not needed.
drivers/crypto/tegra-aes.c line 395
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +5
-0+ value =CMD_SETTABLE <<CMDQBITSHIFT_OPCODE | +SUBCMD_CRYPTO_TABLESEL <<CMDQBITSHIFT_TABLESEL | +SUBCMD_VRAM_SEL <<CMDQBITSHIFT_VRAMSEL | + (SUBCMD_KEYTABLESEL | ctx->slot->slot_num) + <<CMDQBITSHIFT_KEYTABLEID ;
alignment
drivers/crypto/tegra-aes.c line 465
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +3
-0+static int tegra_aes_handle_req (struct tegra_aes_dev *dd) + dd->iv = (u8 *)req->info; + dd->ivlen =AES_BLOCK_SIZE ;
fyi, getting the iv length from crypto_ablkcipher_ivsize() would be more futureproof.
drivers/crypto/tegra-aes.c line 474
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+if (ctx->flags &FLAGS_NEW_KEY ) { +/* copy the key */ +memset (dd->ivkey_base,0 ,AES_HW_KEY_TABLE_LENGTH_BYTES ); +memcpy (dd->ivkey_base, ctx->key, ctx->keylen);
do you really need the overlapping memset?
Review
Quoted 2 lines
(quoted diff) +2
-0+ ret = aes_start_crypt(dd, (u32)dd->dma_buf_in, + (u32)dd->dma_buf_out, 1, FLAGS_CBC, false);
alignment. Casts necessary?
drivers/crypto/tegra-aes.c line 518
Quoted 2 lines
drivers/crypto/tegra-aes.c new file +2
-0+ ret =aes_start_crypt (dd, addr_in, addr_out, nblocks, + dd->flags, true);
alignment
drivers/crypto/tegra-aes.c line 549
Quoted 2 lines
drivers/crypto/tegra-aes.c new file +2
-0+static int tegra_aes_setkey (struct crypto_ablkcipher *tfm,const u8 *key, +unsigned int keylen)
alignment:
static int tegra_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
unsigned int keylen)
drivers/crypto/tegra-aes.c line 555
Quoted 6 lines
drivers/crypto/tegra-aes.c new file +6
-0+{ +struct tegra_aes_ctx *ctx =crypto_ablkcipher_ctx (tfm); +struct tegra_aes_dev *dd = aes_dev; +struct tegra_aes_slot *key_slot; + +if (!ctx || !dd) {
when would this condition be met?
drivers/crypto/tegra-aes.c line 563
Quoted 8 lines
drivers/crypto/tegra-aes.c new file +8
-0+pr_err ("ctx=0x%x, dd=0x%x\n" , + (unsigned int )ctx, (unsigned int )dd); +return -EINVAL ; + } + +if ((keylen !=AES_KEYSIZE_128 ) && (keylen !=AES_KEYSIZE_192 ) && + (keylen !=AES_KEYSIZE_256 )) { +dev_err (dd->dev,"unsupported key size\n" );
crypto_ablkcipher_set_flags(.., CRYPTO_TFM_RES_BAD_KEY_LEN);
drivers/crypto/tegra-aes.c line 571
Quoted 8 lines
drivers/crypto/tegra-aes.c new file +8
-0+return -EINVAL ; + } + +dev_dbg (dd->dev,"keylen: %d\n" , keylen); + + ctx->dd = dd; + +if (key) {
when would this condition not be met?
Quoted 1 line
+#define
INT_ERROR_MASK0xFFF000
perhaps this belongs in the header file
drivers/crypto/tegra-aes.c line 616
Quoted 10 lines
drivers/crypto/tegra-aes.c new file +10
-0+static irqreturn_t aes_irq (int irq,void *dev_id) +{ +struct tegra_aes_dev *dd = (struct tegra_aes_dev *)dev_id; +u32 value =aes_readl (dd,INTR_STATUS ); + +dev_dbg (dd->dev,"irq_stat: 0x%x" , value); +if (value &INT_ERROR_MASK ) +aes_writel (dd, intr_err_mask,INTR_STATUS ); + + value =aes_readl (dd,INTR_STATUS );
why read the IRQ status twice?
drivers/crypto/tegra-aes.c line 620
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+if (!(value &ENGINE_BUSY_FIELD )) +complete (&dd->op_complete); + +done:
label not used
drivers/crypto/tegra-aes.c line 621
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+return IRQ_HANDLED ;
need to return IRQ_NONE if device reports no valid IRQ status.
drivers/crypto/tegra-aes.c line 667
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +4
-0+static int tegra_aes_cbc_decrypt (struct ablkcipher_request *req) +{ +return tegra_aes_crypt (req,FLAGS_CBC ); +}
insert blank line here
drivers/crypto/tegra-aes.c line 679
Quoted 4 lines
drivers/crypto/tegra-aes.c new file +3
-0+static int tegra_aes_ofb_encrypt(struct ablkcipher_request *req) +static int tegra_aes_get_random(struct crypto_rng *tfm, u8 *rdata, + unsigned int dlen)
alignment
drivers/crypto/tegra-aes.c line 696
Quoted 2 lines
drivers/crypto/tegra-aes.c new file +2
-0+memset (dd->buf_in,0 ,AES_BLOCK_SIZE ); +memcpy (dd->buf_in, dt,DEFAULT_RNG_BLK_SZ );
unnecessary memset
drivers/crypto/tegra-aes.c line 766
Quoted 3 lines
drivers/crypto/tegra-aes.c new file +3
-0+/* copy the key to the key slot */ +memset (dd->ivkey_base,0 ,AES_HW_KEY_TABLE_LENGTH_BYTES ); +memcpy (dd->ivkey_base, seed +DEFAULT_RNG_BLK_SZ ,AES_KEYSIZE_128 );
64 byte memset vs. 16 byte memcpy - is the memset still needed?
drivers/crypto/tegra-aes.c line 779
Quoted 3 lines
drivers/crypto/tegra-aes.c new file +3
-0+/* set seed to the aes hw slot */ +memset (dd->buf_in,0 ,AES_BLOCK_SIZE ); +memcpy (dd->buf_in, dd->iv,DEFAULT_RNG_BLK_SZ );
memset not necessary - both are 16 byte ops.
Review
Quoted 2 lines
(quoted diff) +2
-0+ ret = aes_start_crypt(dd, (u32)dd->dma_buf_in, + (u32)dd->dma_buf_out, 1, FLAGS_CBC, false);
fix alignment.
Quoted 9 lines
drivers/crypto/tegra-aes.c new file +9
-0+static struct crypto_alg algs[] = { + { + .cra_name ="ecb(aes)" , + .cra_driver_name ="ecb-aes-tegra" , + .cra_priority =300 , + .cra_flags =CRYPTO_ALG_TYPE_ABLKCIPHER |CRYPTO_ALG_ASYNC , + .cra_blocksize =AES_BLOCK_SIZE , + .cra_ctxsize =sizeof (struct tegra_aes_ctx ), + .cra_alignmask =3 ,
drivers/crypto/tegra-aes.c line 842
Quoted 10 lines
drivers/crypto/tegra-aes.c new file +10
-0+ .cra_type = &crypto_ablkcipher_type, + .cra_module = THIS_MODULE, + .cra_init = tegra_aes_cra_init, + .cra_exit = tegra_aes_cra_exit, + .cra_u.ablkcipher = { + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .setkey = tegra_aes_setkey, + .encrypt = tegra_aes_ecb_encrypt, + .decrypt = tegra_aes_ecb_decrypt,
cra_priority, cra_ctxsize, cra_module, cra_init, cra_exit are constant throughout the array, and can thus be assigned once prior to alg registration.
drivers/crypto/tegra-aes.c line 910
Quoted 9 lines
drivers/crypto/tegra-aes.c new file +9
-0+static int tegra_aes_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct tegra_aes_dev *dd; +struct resource *res; +int err = -ENOMEM , i =0 , j; + +if (aes_dev) +return -EEXIST ;
when would this condition be met?
drivers/crypto/tegra-aes.c line 915
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +5
-0+ + dd =kzalloc (sizeof (struct tegra_aes_dev ),GFP_KERNEL ); +if (dd ==NULL ) { +dev_err (dev,"unable to alloc data struct.\n" ); +return -ENOMEM ;;
return err;
drivers/crypto/tegra-aes.h line 47
Quoted 4 lines
drivers/crypto/tegra-aes.h +2
-0+/* interrupt status reg masks and shifts */ +#define DMA_BUSY_SHIFT (9)
single value expressions don't need parens; here and throughout the reset of the file.
Quoted 1 line
+#define
DMA_BUSY_FIELD(0x1<<DMA_BUSY_SHIFT)
alignment
drivers/crypto/tegra-aes.h line 50
Quoted 2 lines
drivers/crypto/tegra-aes.h +2
-0+#define ICQ_EMPTY_SHIFT (3) +#define ICQ_EMPTY_FIELD (0x1 << ICQ_EMPTY_SHIFT)
alignment
Kim
A message that is not in the archive (sent off-list or not yet received): 20111104202202.882b4d84473ba616cacda7d7-KZfg59tc24xl57MIdRCFDg@public.gmane.org
Quoted 7 lines
drivers/crypto/tegra-aes.c line 380
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +4
-0+ cmdq[1 ] = (u32 )dd->ivkey_phys_base; + +for (i =0 ; i <ARRAY_SIZE (cmdq); i++) +aes_writel (dd, cmdq[i],ICMDQUE_WR );
ARRAY_SIZEis 2 here - why not use a single temporary variable and two individual aes_writel()s?
Removed 'i' and kept cmdq as it is. Adding 2 more variables seems unnecessary.
Quoted 6 lines
drivers/crypto/tegra-aes.c line 474
Quoted 5 lines
drivers/crypto/tegra-aes.c new file +4
-0+if (ctx->flags &FLAGS_NEW_KEY ) { +/* copy the key */ +memset (dd->ivkey_base,0 ,AES_HW_KEY_TABLE_LENGTH_BYTES ); +memcpy (dd->ivkey_base, ctx->key, ctx->keylen);do you really need the overlapping memset?
keylen < AES_HW_KEY_TABLE_LENGTH_BYTES. A key slot contains key, iv and updated iv.
Quoted 2 lines
drivers/crypto/tegra-aes.c line 621
Quoted 1 line
drivers/crypto/tegra-aes.c new file +1
-0+return IRQ_HANDLED ;need to return
IRQ_NONEif device reports no valid IRQ status.
I could not find a scenario where IRQ_NONE can be returned.