2012-11-19 19:03:57

by Mark Greer

[permalink] [raw]
Subject: [PATCH 0/7] crypto: omap-aes updates

From: "Mark A. Greer" <[email protected]>

This series updates the crypto omap-aes driver and supporting
infrastructure.

Notes:

a) Based on omap-sham patches recently submitted, XXX

b) Since these patches will likely go though the OMAP tree (and not
through the crypto tree), it would be nice if the crypto guy(s)
would ACK or NACK patches 4-7 which modify the
drivers/crypto/omap-sham.c driver.

c) These have only been tested on an omap2420 h4 and an am37x evm.

d) Many thanks to Jon Hunter for testing on his omap2420 h4.

Mark A. Greer (7):
ARM: OMAP2xxx: hwmod: Convert AES crypto devcie data to hwmod
ARM: OMAP3xxx: hwmod: Convert AES crypto device data to hwmod
ARM: OMAP2+: Remove unnecessary message when no AES IP is present
crypto: omap-aes: Remove cpu_is/omap_type check from driver
crypto: omap-aes: Convert to use pm_runtime API
crypto: omap-aes: Add code to use dmaengine API
crypto: omap-aes: Remove usage of private DMA API

arch/arm/mach-omap2/clock2430_data.c | 1 +
arch/arm/mach-omap2/clock3xxx_data.c | 1 +
arch/arm/mach-omap2/devices.c | 75 +-------
arch/arm/mach-omap2/omap_hwmod_2420_data.c | 1 +
arch/arm/mach-omap2/omap_hwmod_2430_data.c | 1 +
.../mach-omap2/omap_hwmod_2xxx_interconnect_data.c | 18 ++
arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c | 38 ++++
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 62 +++++++
arch/arm/mach-omap2/omap_hwmod_common_data.h | 2 +
drivers/crypto/omap-aes.c | 202 ++++++++++++---------
10 files changed, 251 insertions(+), 150 deletions(-)

--
1.7.12


2012-11-19 19:03:57

by Mark Greer

[permalink] [raw]
Subject: [PATCH 3/7] ARM: OMAP2+: Remove unnecessary message when no AES IP is present

From: "Mark A. Greer" <[email protected]>

Remove the error message that prints when there is no AES IP
present to make it consistent with all the other IPs.

CC: Paul Walmsley <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
arch/arm/mach-omap2/devices.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 6a9152a..03c1b3a 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -470,20 +470,15 @@ static void __init omap_init_sham(void)

static void __init omap_init_aes(void)
{
- if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
- struct omap_hwmod *oh;
- struct platform_device *pdev;
-
- oh = omap_hwmod_lookup("aes");
- if (!oh)
- return;
-
- pdev = omap_device_build("omap-aes", -1, oh, NULL, 0, NULL,
- 0, 0);
- WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
- } else {
- pr_err("%s: platform not supported\n", __func__);
- }
+ struct omap_hwmod *oh;
+ struct platform_device *pdev;
+
+ oh = omap_hwmod_lookup("aes");
+ if (!oh)
+ return;
+
+ pdev = omap_device_build("omap-aes", -1, oh, NULL, 0, NULL, 0, 0);
+ WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
}

/*-------------------------------------------------------------------------*/
--
1.7.12

2012-11-19 19:03:58

by Mark Greer

[permalink] [raw]
Subject: [PATCH 2/7] ARM: OMAP3xxx: hwmod: Convert AES crypto device data to hwmod

From: "Mark A. Greer" <[email protected]>

Convert the device data for the OMAP3 AES crypto IP
from explicit platform_data to hwmod.

CC: Paul Walmsley <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
arch/arm/mach-omap2/clock3xxx_data.c | 1 +
arch/arm/mach-omap2/devices.c | 42 +-------------------
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 62 ++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 40 deletions(-)

diff --git a/arch/arm/mach-omap2/clock3xxx_data.c b/arch/arm/mach-omap2/clock3xxx_data.c
index 6f14d9b..ceb4153 100644
--- a/arch/arm/mach-omap2/clock3xxx_data.c
+++ b/arch/arm/mach-omap2/clock3xxx_data.c
@@ -3341,6 +3341,7 @@ static struct omap_clk omap3xxx_clks[] = {
CLK(NULL, "mmchs3_ick", &mmchs3_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX),
CLK(NULL, "icr_ick", &icr_ick, CK_34XX | CK_36XX),
CLK("omap-aes", "ick", &aes2_ick, CK_34XX | CK_36XX),
+ CLK(NULL, "aes2_ick", &aes2_ick, CK_34XX | CK_36XX),
CLK("omap-sham", "ick", &sha12_ick, CK_34XX | CK_36XX),
CLK(NULL, "sha12_ick", &sha12_ick, CK_34XX | CK_36XX),
CLK(NULL, "des2_ick", &des2_ick, CK_34XX | CK_36XX),
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 58831e5..6a9152a 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -468,38 +468,9 @@ static void __init omap_init_sham(void)
WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
}

-#if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)
-
-#ifdef CONFIG_ARCH_OMAP3
-static struct resource omap3_aes_resources[] = {
- {
- .start = OMAP34XX_SEC_AES_BASE,
- .end = OMAP34XX_SEC_AES_BASE + 0x4C,
- .flags = IORESOURCE_MEM,
- },
- {
- .start = OMAP34XX_DMA_AES2_TX,
- .flags = IORESOURCE_DMA,
- },
- {
- .start = OMAP34XX_DMA_AES2_RX,
- .flags = IORESOURCE_DMA,
- }
-};
-static int omap3_aes_resources_sz = ARRAY_SIZE(omap3_aes_resources);
-#else
-#define omap3_aes_resources NULL
-#define omap3_aes_resources_sz 0
-#endif
-
-static struct platform_device aes_device = {
- .name = "omap-aes",
- .id = -1,
-};
-
-static void omap_init_aes(void)
+static void __init omap_init_aes(void)
{
- if (cpu_is_omap24xx()) {
+ if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
struct omap_hwmod *oh;
struct platform_device *pdev;

@@ -510,20 +481,11 @@ static void omap_init_aes(void)
pdev = omap_device_build("omap-aes", -1, oh, NULL, 0, NULL,
0, 0);
WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
- } else if (cpu_is_omap34xx()) {
- aes_device.resource = omap3_aes_resources;
- aes_device.num_resources = omap3_aes_resources_sz;
- platform_device_register(&aes_device);
} else {
pr_err("%s: platform not supported\n", __func__);
- return;
}
}

-#else
-static inline void omap_init_aes(void) { }
-#endif
-
/*-------------------------------------------------------------------------*/

#if defined(CONFIG_VIDEO_OMAP2_VOUT) || \
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index a65972b..3b82304 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -3608,6 +3608,67 @@ static struct omap_hwmod_ocp_if omap3xxx_l4_core__sham = {
.user = OCP_USER_MPU | OCP_USER_SDMA,
};

+/* l4_core -> AES */
+static struct omap_hwmod_sysc_fields omap3xxx_aes_sysc_fields = {
+ .sidle_shift = 6,
+ .srst_shift = 1,
+ .autoidle_shift = 0,
+};
+
+static struct omap_hwmod_class_sysconfig omap3_aes_sysc = {
+ .rev_offs = 0x44,
+ .sysc_offs = 0x48,
+ .syss_offs = 0x4c,
+ .sysc_flags = (SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET |
+ SYSC_HAS_AUTOIDLE | SYSS_HAS_RESET_STATUS),
+ .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART),
+ .sysc_fields = &omap3xxx_aes_sysc_fields,
+};
+
+static struct omap_hwmod_class omap3xxx_aes_class = {
+ .name = "aes",
+ .sysc = &omap3_aes_sysc,
+};
+
+struct omap_hwmod_dma_info omap3_aes_sdma_reqs[] = {
+ { .name = "tx", .dma_req = OMAP34XX_DMA_AES2_TX, },
+ { .name = "rx", .dma_req = OMAP34XX_DMA_AES2_RX, },
+ { .dma_req = -1 }
+};
+
+struct omap_hwmod omap3xxx_aes_hwmod = {
+ .name = "aes",
+ .sdma_reqs = omap3_aes_sdma_reqs,
+ .main_clk = "aes2_ick",
+ .prcm = {
+ .omap2 = {
+ .module_offs = CORE_MOD,
+ .prcm_reg_id = 1,
+ .module_bit = OMAP3430_EN_AES2_SHIFT,
+ .idlest_reg_id = 1,
+ .idlest_idle_bit = OMAP3430_ST_AES2_SHIFT,
+ },
+ },
+ .class = &omap3xxx_aes_class,
+};
+
+static struct omap_hwmod_addr_space omap3xxx_aes_addrs[] = {
+ {
+ .pa_start = 0x480c5000,
+ .pa_end = 0x480c5000 + 0x50 - 1,
+ .flags = ADDR_TYPE_RT
+ },
+ { }
+};
+
+static struct omap_hwmod_ocp_if omap3xxx_l4_core__aes = {
+ .master = &omap3xxx_l4_core_hwmod,
+ .slave = &omap3xxx_aes_hwmod,
+ .clk = "aes2_ick",
+ .addr = omap3xxx_aes_addrs,
+ .user = OCP_USER_MPU | OCP_USER_SDMA,
+};
+
static struct omap_hwmod_ocp_if *omap3xxx_hwmod_ocp_ifs[] __initdata = {
&omap3xxx_l3_main__l4_core,
&omap3xxx_l3_main__l4_per,
@@ -3662,6 +3723,7 @@ static struct omap_hwmod_ocp_if *omap3xxx_hwmod_ocp_ifs[] __initdata = {
static struct omap_hwmod_ocp_if *omap3xxx_gp_hwmod_ocp_ifs[] __initdata = {
&omap3xxx_l4_sec__timer12,
&omap3xxx_l4_core__sham,
+ &omap3xxx_l4_core__aes,
NULL
};

--
1.7.12

2012-11-19 19:03:58

by Mark Greer

[permalink] [raw]
Subject: [PATCH 4/7] crypto: omap-aes: Remove cpu_is/omap_type check from driver

From: "Mark A. Greer" <[email protected]>

The omap-aes driver should not check the CPU class or the
type of OMAP device its on. The platform code should do
that instead.

Signed-off-by: Mark A. Greer <[email protected]>
---
drivers/crypto/omap-aes.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 093a8af..628c3cc 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -941,11 +941,6 @@ static int __init omap_aes_mod_init(void)
{
pr_info("loading %s driver\n", "omap-aes");

- if (!cpu_class_is_omap2() || omap_type() != OMAP2_DEVICE_TYPE_SEC) {
- pr_err("Unsupported cpu\n");
- return -ENODEV;
- }
-
return platform_driver_register(&omap_aes_driver);
}

--
1.7.12

2012-11-19 19:03:46

by Mark Greer

[permalink] [raw]
Subject: [PATCH 1/7] ARM: OMAP2xxx: hwmod: Convert AES crypto devcie data to hwmod

From: "Mark A. Greer" <[email protected]>

Convert the device data for the OMAP2 AES crypto IP from
explicit platform_data to hwmod.

CC: Paul Walmsley <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
arch/arm/mach-omap2/clock2430_data.c | 1 +
arch/arm/mach-omap2/devices.c | 36 +++++++-------------
arch/arm/mach-omap2/omap_hwmod_2420_data.c | 1 +
arch/arm/mach-omap2/omap_hwmod_2430_data.c | 1 +
.../mach-omap2/omap_hwmod_2xxx_interconnect_data.c | 18 ++++++++++
arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c | 38 ++++++++++++++++++++++
arch/arm/mach-omap2/omap_hwmod_common_data.h | 2 ++
7 files changed, 72 insertions(+), 25 deletions(-)

diff --git a/arch/arm/mach-omap2/clock2430_data.c b/arch/arm/mach-omap2/clock2430_data.c
index 4d52ec6..2259356 100644
--- a/arch/arm/mach-omap2/clock2430_data.c
+++ b/arch/arm/mach-omap2/clock2430_data.c
@@ -1997,6 +1997,7 @@ static struct omap_clk omap2430_clks[] = {
CLK("omap_rng", "ick", &rng_ick, CK_243X),
CLK(NULL, "rng_ick", &rng_ick, CK_243X),
CLK("omap-aes", "ick", &aes_ick, CK_243X),
+ CLK(NULL, "aes_ick", &aes_ick, CK_243X),
CLK(NULL, "pka_ick", &pka_ick, CK_243X),
CLK(NULL, "usb_fck", &usb_fck, CK_243X),
CLK("musb-omap2430", "ick", &usbhs_ick, CK_243X),
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 7ecce5e..58831e5 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -470,28 +470,6 @@ static void __init omap_init_sham(void)

#if defined(CONFIG_CRYPTO_DEV_OMAP_AES) || defined(CONFIG_CRYPTO_DEV_OMAP_AES_MODULE)

-#ifdef CONFIG_ARCH_OMAP2
-static struct resource omap2_aes_resources[] = {
- {
- .start = OMAP24XX_SEC_AES_BASE,
- .end = OMAP24XX_SEC_AES_BASE + 0x4C,
- .flags = IORESOURCE_MEM,
- },
- {
- .start = OMAP24XX_DMA_AES_TX,
- .flags = IORESOURCE_DMA,
- },
- {
- .start = OMAP24XX_DMA_AES_RX,
- .flags = IORESOURCE_DMA,
- }
-};
-static int omap2_aes_resources_sz = ARRAY_SIZE(omap2_aes_resources);
-#else
-#define omap2_aes_resources NULL
-#define omap2_aes_resources_sz 0
-#endif
-
#ifdef CONFIG_ARCH_OMAP3
static struct resource omap3_aes_resources[] = {
{
@@ -522,16 +500,24 @@ static struct platform_device aes_device = {
static void omap_init_aes(void)
{
if (cpu_is_omap24xx()) {
- aes_device.resource = omap2_aes_resources;
- aes_device.num_resources = omap2_aes_resources_sz;
+ struct omap_hwmod *oh;
+ struct platform_device *pdev;
+
+ oh = omap_hwmod_lookup("aes");
+ if (!oh)
+ return;
+
+ pdev = omap_device_build("omap-aes", -1, oh, NULL, 0, NULL,
+ 0, 0);
+ WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
} else if (cpu_is_omap34xx()) {
aes_device.resource = omap3_aes_resources;
aes_device.num_resources = omap3_aes_resources_sz;
+ platform_device_register(&aes_device);
} else {
pr_err("%s: platform not supported\n", __func__);
return;
}
- platform_device_register(&aes_device);
}

#else
diff --git a/arch/arm/mach-omap2/omap_hwmod_2420_data.c b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
index b102a53..613f862 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2420_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
@@ -604,6 +604,7 @@ static struct omap_hwmod_ocp_if *omap2420_hwmod_ocp_ifs[] __initdata = {
&omap2420_l4_core__msdi1,
&omap2xxx_l4_core__rng,
&omap2xxx_l4_core__sham,
+ &omap2xxx_l4_core__aes,
&omap2420_l4_core__hdq1w,
&omap2420_l4_wkup__counter_32k,
&omap2420_l3__gpmc,
diff --git a/arch/arm/mach-omap2/omap_hwmod_2430_data.c b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
index b1ce7b0..0db06a5 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2430_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
@@ -964,6 +964,7 @@ static struct omap_hwmod_ocp_if *omap2430_hwmod_ocp_ifs[] __initdata = {
&omap2430_l4_core__hdq1w,
&omap2xxx_l4_core__rng,
&omap2xxx_l4_core__sham,
+ &omap2xxx_l4_core__aes,
&omap2430_l4_wkup__counter_32k,
&omap2430_l3__gpmc,
NULL,
diff --git a/arch/arm/mach-omap2/omap_hwmod_2xxx_interconnect_data.c b/arch/arm/mach-omap2/omap_hwmod_2xxx_interconnect_data.c
index 4b4fd5f..96ba272 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2xxx_interconnect_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2xxx_interconnect_data.c
@@ -147,6 +147,15 @@ struct omap_hwmod_addr_space omap2xxx_sham_addrs[] = {
{ }
};

+struct omap_hwmod_addr_space omap2xxx_aes_addrs[] = {
+ {
+ .pa_start = 0x480a6000,
+ .pa_end = 0x480a6000 + 0x50 - 1,
+ .flags = ADDR_TYPE_RT
+ },
+ { }
+};
+
/*
* Common interconnect data
*/
@@ -407,3 +416,12 @@ struct omap_hwmod_ocp_if omap2xxx_l4_core__sham = {
.addr = omap2xxx_sham_addrs,
.user = OCP_USER_MPU | OCP_USER_SDMA,
};
+
+/* l4 core -> aes interface */
+struct omap_hwmod_ocp_if omap2xxx_l4_core__aes = {
+ .master = &omap2xxx_l4_core_hwmod,
+ .slave = &omap2xxx_aes_hwmod,
+ .clk = "aes_ick",
+ .addr = omap2xxx_aes_addrs,
+ .user = OCP_USER_MPU | OCP_USER_SDMA,
+};
diff --git a/arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c b/arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c
index 703b269..2f7583a 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c
@@ -894,3 +894,41 @@ struct omap_hwmod omap2xxx_sham_hwmod = {
},
.class = &omap2xxx_sham_class,
};
+
+/* AES */
+
+static struct omap_hwmod_class_sysconfig omap2_aes_sysc = {
+ .rev_offs = 0x44,
+ .sysc_offs = 0x48,
+ .syss_offs = 0x4c,
+ .sysc_flags = (SYSC_HAS_SOFTRESET | SYSC_HAS_AUTOIDLE |
+ SYSS_HAS_RESET_STATUS),
+ .sysc_fields = &omap_hwmod_sysc_type1,
+};
+
+static struct omap_hwmod_class omap2xxx_aes_class = {
+ .name = "aes",
+ .sysc = &omap2_aes_sysc,
+};
+
+struct omap_hwmod_dma_info omap2_aes_sdma_chs[] = {
+ { .name = "tx", .dma_req = OMAP24XX_DMA_AES_TX },
+ { .name = "rx", .dma_req = OMAP24XX_DMA_AES_RX },
+ { .dma_req = -1 }
+};
+
+struct omap_hwmod omap2xxx_aes_hwmod = {
+ .name = "aes",
+ .sdma_reqs = omap2_aes_sdma_chs,
+ .main_clk = "l4_ck",
+ .prcm = {
+ .omap2 = {
+ .module_offs = CORE_MOD,
+ .prcm_reg_id = 4,
+ .module_bit = OMAP24XX_EN_AES_SHIFT,
+ .idlest_reg_id = 4,
+ .idlest_idle_bit = OMAP24XX_ST_AES_SHIFT,
+ },
+ },
+ .class = &omap2xxx_aes_class,
+};
diff --git a/arch/arm/mach-omap2/omap_hwmod_common_data.h b/arch/arm/mach-omap2/omap_hwmod_common_data.h
index 74a7b7a..83f95b4 100644
--- a/arch/arm/mach-omap2/omap_hwmod_common_data.h
+++ b/arch/arm/mach-omap2/omap_hwmod_common_data.h
@@ -79,6 +79,7 @@ extern struct omap_hwmod omap2xxx_counter_32k_hwmod;
extern struct omap_hwmod omap2xxx_gpmc_hwmod;
extern struct omap_hwmod omap2xxx_rng_hwmod;
extern struct omap_hwmod omap2xxx_sham_hwmod;
+extern struct omap_hwmod omap2xxx_aes_hwmod;

/* Common interface data across OMAP2xxx */
extern struct omap_hwmod_ocp_if omap2xxx_l3_main__l4_core;
@@ -107,6 +108,7 @@ extern struct omap_hwmod_ocp_if omap2xxx_l4_core__dss_rfbi;
extern struct omap_hwmod_ocp_if omap2xxx_l4_core__dss_venc;
extern struct omap_hwmod_ocp_if omap2xxx_l4_core__rng;
extern struct omap_hwmod_ocp_if omap2xxx_l4_core__sham;
+extern struct omap_hwmod_ocp_if omap2xxx_l4_core__aes;

/* Common IP block data */
extern struct omap_hwmod_dma_info omap2_uart1_sdma_reqs[];
--
1.7.12


2012-11-19 19:03:50

by Mark Greer

[permalink] [raw]
Subject: [PATCH 5/7] crypto: omap-aes: Convert to use pm_runtime API

From: "Mark A. Greer" <[email protected]>

Convert the omap-aes crypto driver to use the
pm_runtime API instead of the clk API.

CC: Kevin Hilman <[email protected]>
CC: Paul Walmsley <[email protected]>
CC: Dmitry Kasatkin <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
drivers/crypto/omap-aes.c | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 628c3cc..75b842d 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -19,10 +19,10 @@
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/kernel.h>
-#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
+#include <linux/pm_runtime.h>
#include <linux/io.h>
#include <linux/crypto.h>
#include <linux/interrupt.h>
@@ -97,7 +97,6 @@ struct omap_aes_dev {
struct list_head list;
unsigned long phys_base;
void __iomem *io_base;
- struct clk *iclk;
struct omap_aes_ctx *ctx;
struct device *dev;
unsigned long flags;
@@ -181,7 +180,7 @@ static int omap_aes_hw_init(struct omap_aes_dev *dd)
* It may be long delays between requests.
* Device might go to off mode to save power.
*/
- clk_enable(dd->iclk);
+ pm_runtime_get_sync(dd->dev);

if (!(dd->flags & FLAGS_INIT)) {
/* is it necessary to reset before every operation? */
@@ -546,7 +545,7 @@ static void omap_aes_finish_req(struct omap_aes_dev *dd, int err)

pr_debug("err: %d\n", err);

- clk_disable(dd->iclk);
+ pm_runtime_put_sync(dd->dev);
dd->flags &= ~FLAGS_BUSY;

req->base.complete(&req->base, err);
@@ -841,26 +840,21 @@ static int omap_aes_probe(struct platform_device *pdev)
else
dd->dma_in = res->start;

- /* Initializing the clock */
- dd->iclk = clk_get(dev, "ick");
- if (IS_ERR(dd->iclk)) {
- dev_err(dev, "clock intialization failed.\n");
- err = PTR_ERR(dd->iclk);
- goto err_res;
- }
-
dd->io_base = ioremap(dd->phys_base, SZ_4K);
if (!dd->io_base) {
dev_err(dev, "can't ioremap\n");
err = -ENOMEM;
- goto err_io;
+ goto err_res;
}

- clk_enable(dd->iclk);
+ pm_runtime_enable(dev);
+ pm_runtime_get_sync(dev);
+
reg = omap_aes_read(dd, AES_REG_REV);
dev_info(dev, "OMAP AES hw accel rev: %u.%u\n",
(reg & AES_REG_REV_MAJOR) >> 4, reg & AES_REG_REV_MINOR);
- clk_disable(dd->iclk);
+
+ pm_runtime_put_sync(dev);

tasklet_init(&dd->done_task, omap_aes_done_task, (unsigned long)dd);
tasklet_init(&dd->queue_task, omap_aes_queue_task, (unsigned long)dd);
@@ -892,8 +886,7 @@ err_dma:
tasklet_kill(&dd->done_task);
tasklet_kill(&dd->queue_task);
iounmap(dd->io_base);
-err_io:
- clk_put(dd->iclk);
+ pm_runtime_disable(dev);
err_res:
kfree(dd);
dd = NULL;
@@ -921,7 +914,7 @@ static int omap_aes_remove(struct platform_device *pdev)
tasklet_kill(&dd->queue_task);
omap_aes_dma_cleanup(dd);
iounmap(dd->io_base);
- clk_put(dd->iclk);
+ pm_runtime_disable(dd->dev);
kfree(dd);
dd = NULL;

--
1.7.12


2012-11-19 19:03:52

by Mark Greer

[permalink] [raw]
Subject: [PATCH 7/7] crypto: omap-aes: Remove usage of private DMA API

From: "Mark A. Greer" <[email protected]>

Remove usage of the private OMAP DMA API.
The dmaengine API will be used instead.

CC: Russell King <[email protected]>
CC: Dmitry Kasatkin <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
drivers/crypto/omap-aes.c | 140 ----------------------------------------------
1 file changed, 140 deletions(-)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index c0a84b2..1fbfd2e 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -12,8 +12,6 @@
*
*/

-#define OMAP_AES_DMA_PRIVATE
-
#define pr_fmt(fmt) "%s: " fmt, __func__

#include <linux/err.h>
@@ -24,10 +22,8 @@
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
-#ifndef OMAP_AES_DMA_PRIVATE
#include <linux/dmaengine.h>
#include <linux/omap-dma.h>
-#endif
#include <linux/pm_runtime.h>
#include <linux/io.h>
#include <linux/crypto.h>
@@ -35,11 +31,6 @@
#include <crypto/scatterwalk.h>
#include <crypto/aes.h>

-#ifdef OMAP_AES_DMA_PRIVATE
-#include <plat/cpu.h>
-#include <plat/dma.h>
-#endif
-
#define DST_MAXBURST 4 /* Really element number (en) */

/* OMAP TRM gives bitfields as start:end, where start is the higher bit
@@ -121,33 +112,21 @@ struct omap_aes_dev {
struct ablkcipher_request *req;
size_t total;
struct scatterlist *in_sg;
-#ifndef OMAP_AES_DMA_PRIVATE
struct scatterlist in_sgl;
-#endif
size_t in_offset;
struct scatterlist *out_sg;
-#ifndef OMAP_AES_DMA_PRIVATE
struct scatterlist out_sgl;
-#endif
size_t out_offset;

size_t buflen;
void *buf_in;
size_t dma_size;
int dma_in;
-#ifdef OMAP_AES_DMA_PRIVATE
- int dma_lch_in;
-#else
struct dma_chan *dma_lch_in;
-#endif
dma_addr_t dma_addr_in;
void *buf_out;
int dma_out;
-#ifdef OMAP_AES_DMA_PRIVATE
- int dma_lch_out;
-#else
struct dma_chan *dma_lch_out;
-#endif
dma_addr_t dma_addr_out;
};

@@ -239,17 +218,10 @@ static int omap_aes_write_ctrl(struct omap_aes_dev *dd)
return err;

val = 0;
-#ifdef OMAP_AES_DMA_PRIVATE
- if (dd->dma_lch_out >= 0)
- val |= AES_REG_MASK_DMA_OUT_EN;
- if (dd->dma_lch_in >= 0)
- val |= AES_REG_MASK_DMA_IN_EN;
-#else
if (dd->dma_lch_out != NULL)
val |= AES_REG_MASK_DMA_OUT_EN;
if (dd->dma_lch_in != NULL)
val |= AES_REG_MASK_DMA_IN_EN;
-#endif

mask = AES_REG_MASK_DMA_IN_EN | AES_REG_MASK_DMA_OUT_EN;

@@ -277,22 +249,6 @@ static int omap_aes_write_ctrl(struct omap_aes_dev *dd)

omap_aes_write_mask(dd, AES_REG_CTRL, val, mask);

-#ifdef OMAP_AES_DMA_PRIVATE
- /* IN */
- omap_set_dma_dest_params(dd->dma_lch_in, 0, OMAP_DMA_AMODE_CONSTANT,
- dd->phys_base + AES_REG_DATA, 0, 4);
-
- omap_set_dma_dest_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
- omap_set_dma_src_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
-
- /* OUT */
- omap_set_dma_src_params(dd->dma_lch_out, 0, OMAP_DMA_AMODE_CONSTANT,
- dd->phys_base + AES_REG_DATA, 0, 4);
-
- omap_set_dma_src_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
- omap_set_dma_dest_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
-#endif
-
return 0;
}

@@ -317,23 +273,6 @@ static struct omap_aes_dev *omap_aes_find_dev(struct omap_aes_ctx *ctx)
return dd;
}

-#ifdef OMAP_AES_DMA_PRIVATE
-static void omap_aes_dma_callback(int lch, u16 ch_status, void *data)
-{
- struct omap_aes_dev *dd = data;
-
- if (ch_status != OMAP_DMA_BLOCK_IRQ) {
- pr_err("omap-aes DMA error status: 0x%hx\n", ch_status);
- dd->err = -EIO;
- dd->flags &= ~FLAGS_INIT; /* request to re-initialize */
- } else if (lch == dd->dma_lch_in) {
- return;
- }
-
- /* dma_lch_out - completed */
- tasklet_schedule(&dd->done_task);
-}
-#else
static void omap_aes_dma_out_callback(void *data)
{
struct omap_aes_dev *dd = data;
@@ -341,22 +280,14 @@ static void omap_aes_dma_out_callback(void *data)
/* dma_lch_out - completed */
tasklet_schedule(&dd->done_task);
}
-#endif

static int omap_aes_dma_init(struct omap_aes_dev *dd)
{
int err = -ENOMEM;
-#ifndef OMAP_AES_DMA_PRIVATE
dma_cap_mask_t mask;
-#endif

-#ifdef OMAP_AES_DMA_PRIVATE
- dd->dma_lch_out = -1;
- dd->dma_lch_in = -1;
-#else
dd->dma_lch_out = NULL;
dd->dma_lch_in = NULL;
-#endif

dd->buf_in = (void *)__get_free_pages(GFP_KERNEL, OMAP_AES_CACHE_SIZE);
dd->buf_out = (void *)__get_free_pages(GFP_KERNEL, OMAP_AES_CACHE_SIZE);
@@ -385,20 +316,6 @@ static int omap_aes_dma_init(struct omap_aes_dev *dd)
goto err_map_out;
}

-#ifdef OMAP_AES_DMA_PRIVATE
- err = omap_request_dma(dd->dma_in, "omap-aes-rx",
- omap_aes_dma_callback, dd, &dd->dma_lch_in);
- if (err) {
- dev_err(dd->dev, "Unable to request DMA channel\n");
- goto err_dma_in;
- }
- err = omap_request_dma(dd->dma_out, "omap-aes-tx",
- omap_aes_dma_callback, dd, &dd->dma_lch_out);
- if (err) {
- dev_err(dd->dev, "Unable to request DMA channel\n");
- goto err_dma_out;
- }
-#else
dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask);

@@ -415,16 +332,11 @@ static int omap_aes_dma_init(struct omap_aes_dev *dd)
dev_err(dd->dev, "Unable to request out DMA channel\n");
goto err_dma_out;
}
-#endif

return 0;

err_dma_out:
-#ifdef OMAP_AES_DMA_PRIVATE
- omap_free_dma(dd->dma_lch_in);
-#else
dma_release_channel(dd->dma_lch_in);
-#endif
err_dma_in:
dma_unmap_single(dd->dev, dd->dma_addr_out, dd->buflen,
DMA_FROM_DEVICE);
@@ -441,13 +353,8 @@ err_alloc:

static void omap_aes_dma_cleanup(struct omap_aes_dev *dd)
{
-#ifdef OMAP_AES_DMA_PRIVATE
- omap_free_dma(dd->dma_lch_out);
- omap_free_dma(dd->dma_lch_in);
-#else
dma_release_channel(dd->dma_lch_out);
dma_release_channel(dd->dma_lch_in);
-#endif
dma_unmap_single(dd->dev, dd->dma_addr_out, dd->buflen,
DMA_FROM_DEVICE);
dma_unmap_single(dd->dev, dd->dma_addr_in, dd->buflen, DMA_TO_DEVICE);
@@ -505,24 +412,15 @@ static int sg_copy(struct scatterlist **sg, size_t *offset, void *buf,
return off;
}

-#ifdef OMAP_AES_DMA_PRIVATE
-static int omap_aes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in,
- dma_addr_t dma_addr_out, int length)
-#else
static int omap_aes_crypt_dma(struct crypto_tfm *tfm,
struct scatterlist *in_sg, struct scatterlist *out_sg)
-#endif
{
struct omap_aes_ctx *ctx = crypto_tfm_ctx(tfm);
struct omap_aes_dev *dd = ctx->dd;
-#ifdef OMAP_AES_DMA_PRIVATE
- int len32;
-#else
struct dma_async_tx_descriptor *tx_in, *tx_out;
struct dma_slave_config cfg;
dma_addr_t dma_addr_in = sg_dma_address(in_sg);
int ret, length = sg_dma_len(in_sg);
-#endif

pr_debug("len: %d\n", length);

@@ -532,28 +430,6 @@ static int omap_aes_crypt_dma(struct crypto_tfm *tfm,
dma_sync_single_for_device(dd->dev, dma_addr_in, length,
DMA_TO_DEVICE);

-#ifdef OMAP_AES_DMA_PRIVATE
- len32 = DIV_ROUND_UP(length, sizeof(u32));
-
- /* IN */
- omap_set_dma_transfer_params(dd->dma_lch_in, OMAP_DMA_DATA_TYPE_S32,
- len32, 1, OMAP_DMA_SYNC_PACKET, dd->dma_in,
- OMAP_DMA_DST_SYNC);
-
- omap_set_dma_src_params(dd->dma_lch_in, 0, OMAP_DMA_AMODE_POST_INC,
- dma_addr_in, 0, 0);
-
- /* OUT */
- omap_set_dma_transfer_params(dd->dma_lch_out, OMAP_DMA_DATA_TYPE_S32,
- len32, 1, OMAP_DMA_SYNC_PACKET,
- dd->dma_out, OMAP_DMA_SRC_SYNC);
-
- omap_set_dma_dest_params(dd->dma_lch_out, 0, OMAP_DMA_AMODE_POST_INC,
- dma_addr_out, 0, 0);
-
- omap_start_dma(dd->dma_lch_in);
- omap_start_dma(dd->dma_lch_out);
-#else
memset(&cfg, 0, sizeof(cfg));

cfg.src_addr = dd->phys_base + AES_REG_DATA;
@@ -608,7 +484,6 @@ static int omap_aes_crypt_dma(struct crypto_tfm *tfm,

dma_async_issue_pending(dd->dma_lch_in);
dma_async_issue_pending(dd->dma_lch_out);
-#endif

/* start DMA or disable idle mode */
omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_START,
@@ -624,9 +499,7 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
int err, fast = 0, in, out;
size_t count;
dma_addr_t addr_in, addr_out;
-#ifndef OMAP_AES_DMA_PRIVATE
struct scatterlist *in_sg, *out_sg;
-#endif

pr_debug("total: %d\n", dd->total);

@@ -665,10 +538,8 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
addr_in = sg_dma_address(dd->in_sg);
addr_out = sg_dma_address(dd->out_sg);

-#ifndef OMAP_AES_DMA_PRIVATE
in_sg = dd->in_sg;
out_sg = dd->out_sg;
-#endif

dd->flags |= FLAGS_FAST;

@@ -677,7 +548,6 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
count = sg_copy(&dd->in_sg, &dd->in_offset, dd->buf_in,
dd->buflen, dd->total, 0);

-#ifndef OMAP_AES_DMA_PRIVATE
/*
* The data going into the AES module has been copied
* to a local buffer and the data coming out will go
@@ -696,7 +566,6 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)

in_sg = &dd->in_sgl;
out_sg = &dd->out_sgl;
-#endif

addr_in = dd->dma_addr_in;
addr_out = dd->dma_addr_out;
@@ -707,11 +576,7 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)

dd->total -= count;

-#ifdef OMAP_AES_DMA_PRIVATE
- err = omap_aes_crypt_dma(tfm, addr_in, addr_out, count);
-#else
err = omap_aes_crypt_dma(tfm, in_sg, out_sg);
-#endif
if (err) {
dma_unmap_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_TO_DEVICE);
@@ -741,13 +606,8 @@ static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)

omap_aes_write_mask(dd, AES_REG_MASK, 0, AES_REG_MASK_START);

-#ifdef OMAP_AES_DMA_PRIVATE
- omap_stop_dma(dd->dma_lch_in);
- omap_stop_dma(dd->dma_lch_out);
-#else
dmaengine_terminate_all(dd->dma_lch_in);
dmaengine_terminate_all(dd->dma_lch_out);
-#endif

if (dd->flags & FLAGS_FAST) {
dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_FROM_DEVICE);
--
1.7.12


2012-11-19 19:04:02

by Mark Greer

[permalink] [raw]
Subject: [PATCH 6/7] crypto: omap-aes: Add code to use dmaengine API

From: "Mark A. Greer" <[email protected]>

Add code to use the new dmaengine API alongside
the existing DMA code that uses the private
OMAP DMA API. The API to use is chosen by
defining or undefining 'OMAP_AES_DMA_PRIVATE'.

CC: Russell King <[email protected]>
CC: Dmitry Kasatkin <[email protected]>
Signed-off-by: Mark A. Greer <[email protected]>
---
drivers/crypto/omap-aes.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 186 insertions(+)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 75b842d..c0a84b2 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -12,6 +12,8 @@
*
*/

+#define OMAP_AES_DMA_PRIVATE
+
#define pr_fmt(fmt) "%s: " fmt, __func__

#include <linux/err.h>
@@ -22,6 +24,10 @@
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
+#ifndef OMAP_AES_DMA_PRIVATE
+#include <linux/dmaengine.h>
+#include <linux/omap-dma.h>
+#endif
#include <linux/pm_runtime.h>
#include <linux/io.h>
#include <linux/crypto.h>
@@ -29,8 +35,12 @@
#include <crypto/scatterwalk.h>
#include <crypto/aes.h>

+#ifdef OMAP_AES_DMA_PRIVATE
#include <plat/cpu.h>
#include <plat/dma.h>
+#endif
+
+#define DST_MAXBURST 4 /* Really element number (en) */

/* OMAP TRM gives bitfields as start:end, where start is the higher bit
number. For example 7:0 */
@@ -111,19 +121,33 @@ struct omap_aes_dev {
struct ablkcipher_request *req;
size_t total;
struct scatterlist *in_sg;
+#ifndef OMAP_AES_DMA_PRIVATE
+ struct scatterlist in_sgl;
+#endif
size_t in_offset;
struct scatterlist *out_sg;
+#ifndef OMAP_AES_DMA_PRIVATE
+ struct scatterlist out_sgl;
+#endif
size_t out_offset;

size_t buflen;
void *buf_in;
size_t dma_size;
int dma_in;
+#ifdef OMAP_AES_DMA_PRIVATE
int dma_lch_in;
+#else
+ struct dma_chan *dma_lch_in;
+#endif
dma_addr_t dma_addr_in;
void *buf_out;
int dma_out;
+#ifdef OMAP_AES_DMA_PRIVATE
int dma_lch_out;
+#else
+ struct dma_chan *dma_lch_out;
+#endif
dma_addr_t dma_addr_out;
};

@@ -215,10 +239,17 @@ static int omap_aes_write_ctrl(struct omap_aes_dev *dd)
return err;

val = 0;
+#ifdef OMAP_AES_DMA_PRIVATE
if (dd->dma_lch_out >= 0)
val |= AES_REG_MASK_DMA_OUT_EN;
if (dd->dma_lch_in >= 0)
val |= AES_REG_MASK_DMA_IN_EN;
+#else
+ if (dd->dma_lch_out != NULL)
+ val |= AES_REG_MASK_DMA_OUT_EN;
+ if (dd->dma_lch_in != NULL)
+ val |= AES_REG_MASK_DMA_IN_EN;
+#endif

mask = AES_REG_MASK_DMA_IN_EN | AES_REG_MASK_DMA_OUT_EN;

@@ -246,6 +277,7 @@ static int omap_aes_write_ctrl(struct omap_aes_dev *dd)

omap_aes_write_mask(dd, AES_REG_CTRL, val, mask);

+#ifdef OMAP_AES_DMA_PRIVATE
/* IN */
omap_set_dma_dest_params(dd->dma_lch_in, 0, OMAP_DMA_AMODE_CONSTANT,
dd->phys_base + AES_REG_DATA, 0, 4);
@@ -259,6 +291,7 @@ static int omap_aes_write_ctrl(struct omap_aes_dev *dd)

omap_set_dma_src_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
omap_set_dma_dest_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
+#endif

return 0;
}
@@ -284,6 +317,7 @@ static struct omap_aes_dev *omap_aes_find_dev(struct omap_aes_ctx *ctx)
return dd;
}

+#ifdef OMAP_AES_DMA_PRIVATE
static void omap_aes_dma_callback(int lch, u16 ch_status, void *data)
{
struct omap_aes_dev *dd = data;
@@ -299,13 +333,30 @@ static void omap_aes_dma_callback(int lch, u16 ch_status, void *data)
/* dma_lch_out - completed */
tasklet_schedule(&dd->done_task);
}
+#else
+static void omap_aes_dma_out_callback(void *data)
+{
+ struct omap_aes_dev *dd = data;
+
+ /* dma_lch_out - completed */
+ tasklet_schedule(&dd->done_task);
+}
+#endif

static int omap_aes_dma_init(struct omap_aes_dev *dd)
{
int err = -ENOMEM;
+#ifndef OMAP_AES_DMA_PRIVATE
+ dma_cap_mask_t mask;
+#endif

+#ifdef OMAP_AES_DMA_PRIVATE
dd->dma_lch_out = -1;
dd->dma_lch_in = -1;
+#else
+ dd->dma_lch_out = NULL;
+ dd->dma_lch_in = NULL;
+#endif

dd->buf_in = (void *)__get_free_pages(GFP_KERNEL, OMAP_AES_CACHE_SIZE);
dd->buf_out = (void *)__get_free_pages(GFP_KERNEL, OMAP_AES_CACHE_SIZE);
@@ -334,6 +385,7 @@ static int omap_aes_dma_init(struct omap_aes_dev *dd)
goto err_map_out;
}

+#ifdef OMAP_AES_DMA_PRIVATE
err = omap_request_dma(dd->dma_in, "omap-aes-rx",
omap_aes_dma_callback, dd, &dd->dma_lch_in);
if (err) {
@@ -346,11 +398,33 @@ static int omap_aes_dma_init(struct omap_aes_dev *dd)
dev_err(dd->dev, "Unable to request DMA channel\n");
goto err_dma_out;
}
+#else
+ dma_cap_zero(mask);
+ dma_cap_set(DMA_SLAVE, mask);
+
+ dd->dma_lch_in = dma_request_channel(mask, omap_dma_filter_fn,
+ &dd->dma_in);
+ if (!dd->dma_lch_in) {
+ dev_err(dd->dev, "Unable to request in DMA channel\n");
+ goto err_dma_in;
+ }
+
+ dd->dma_lch_out = dma_request_channel(mask, omap_dma_filter_fn,
+ &dd->dma_out);
+ if (!dd->dma_lch_out) {
+ dev_err(dd->dev, "Unable to request out DMA channel\n");
+ goto err_dma_out;
+ }
+#endif

return 0;

err_dma_out:
+#ifdef OMAP_AES_DMA_PRIVATE
omap_free_dma(dd->dma_lch_in);
+#else
+ dma_release_channel(dd->dma_lch_in);
+#endif
err_dma_in:
dma_unmap_single(dd->dev, dd->dma_addr_out, dd->buflen,
DMA_FROM_DEVICE);
@@ -367,8 +441,13 @@ err_alloc:

static void omap_aes_dma_cleanup(struct omap_aes_dev *dd)
{
+#ifdef OMAP_AES_DMA_PRIVATE
omap_free_dma(dd->dma_lch_out);
omap_free_dma(dd->dma_lch_in);
+#else
+ dma_release_channel(dd->dma_lch_out);
+ dma_release_channel(dd->dma_lch_in);
+#endif
dma_unmap_single(dd->dev, dd->dma_addr_out, dd->buflen,
DMA_FROM_DEVICE);
dma_unmap_single(dd->dev, dd->dma_addr_in, dd->buflen, DMA_TO_DEVICE);
@@ -426,12 +505,24 @@ static int sg_copy(struct scatterlist **sg, size_t *offset, void *buf,
return off;
}

+#ifdef OMAP_AES_DMA_PRIVATE
static int omap_aes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in,
dma_addr_t dma_addr_out, int length)
+#else
+static int omap_aes_crypt_dma(struct crypto_tfm *tfm,
+ struct scatterlist *in_sg, struct scatterlist *out_sg)
+#endif
{
struct omap_aes_ctx *ctx = crypto_tfm_ctx(tfm);
struct omap_aes_dev *dd = ctx->dd;
+#ifdef OMAP_AES_DMA_PRIVATE
int len32;
+#else
+ struct dma_async_tx_descriptor *tx_in, *tx_out;
+ struct dma_slave_config cfg;
+ dma_addr_t dma_addr_in = sg_dma_address(in_sg);
+ int ret, length = sg_dma_len(in_sg);
+#endif

pr_debug("len: %d\n", length);

@@ -441,6 +532,7 @@ static int omap_aes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in,
dma_sync_single_for_device(dd->dev, dma_addr_in, length,
DMA_TO_DEVICE);

+#ifdef OMAP_AES_DMA_PRIVATE
len32 = DIV_ROUND_UP(length, sizeof(u32));

/* IN */
@@ -461,6 +553,62 @@ static int omap_aes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in,

omap_start_dma(dd->dma_lch_in);
omap_start_dma(dd->dma_lch_out);
+#else
+ memset(&cfg, 0, sizeof(cfg));
+
+ cfg.src_addr = dd->phys_base + AES_REG_DATA;
+ cfg.dst_addr = dd->phys_base + AES_REG_DATA;
+ cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+ cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+ cfg.src_maxburst = DST_MAXBURST;
+ cfg.dst_maxburst = DST_MAXBURST;
+
+ /* IN */
+ ret = dmaengine_slave_config(dd->dma_lch_in, &cfg);
+ if (ret) {
+ dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
+ ret);
+ return ret;
+ }
+
+ tx_in = dmaengine_prep_slave_sg(dd->dma_lch_in, in_sg, 1,
+ DMA_MEM_TO_DEV,
+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+
+ if (!tx_in) {
+ dev_err(dd->dev, "IN prep_slave_sg() failed\n");
+ return -EINVAL;
+ }
+
+ /* No callback necessary */
+ tx_in->callback_param = dd;
+
+ /* OUT */
+ ret = dmaengine_slave_config(dd->dma_lch_out, &cfg);
+ if (ret) {
+ dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
+ ret);
+ return ret;
+ }
+
+ tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, 1,
+ DMA_DEV_TO_MEM,
+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+
+ if (!tx_out) {
+ dev_err(dd->dev, "OUT prep_slave_sg() failed\n");
+ return -EINVAL;
+ }
+
+ tx_out->callback = omap_aes_dma_out_callback;
+ tx_out->callback_param = dd;
+
+ dmaengine_submit(tx_in);
+ dmaengine_submit(tx_out);
+
+ dma_async_issue_pending(dd->dma_lch_in);
+ dma_async_issue_pending(dd->dma_lch_out);
+#endif

/* start DMA or disable idle mode */
omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_START,
@@ -476,6 +624,9 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
int err, fast = 0, in, out;
size_t count;
dma_addr_t addr_in, addr_out;
+#ifndef OMAP_AES_DMA_PRIVATE
+ struct scatterlist *in_sg, *out_sg;
+#endif

pr_debug("total: %d\n", dd->total);

@@ -514,6 +665,11 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
addr_in = sg_dma_address(dd->in_sg);
addr_out = sg_dma_address(dd->out_sg);

+#ifndef OMAP_AES_DMA_PRIVATE
+ in_sg = dd->in_sg;
+ out_sg = dd->out_sg;
+#endif
+
dd->flags |= FLAGS_FAST;

} else {
@@ -521,6 +677,27 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
count = sg_copy(&dd->in_sg, &dd->in_offset, dd->buf_in,
dd->buflen, dd->total, 0);

+#ifndef OMAP_AES_DMA_PRIVATE
+ /*
+ * The data going into the AES module has been copied
+ * to a local buffer and the data coming out will go
+ * into a local buffer so set up local SG entries for
+ * both.
+ */
+ sg_init_table(&dd->in_sgl, 1);
+ dd->in_sgl.offset = dd->in_offset;
+ sg_dma_len(&dd->in_sgl) = count;
+ sg_dma_address(&dd->in_sgl) = dd->dma_addr_in;
+
+ sg_init_table(&dd->out_sgl, 1);
+ dd->out_sgl.offset = dd->out_offset;
+ sg_dma_len(&dd->out_sgl) = count;
+ sg_dma_address(&dd->out_sgl) = dd->dma_addr_out;
+
+ in_sg = &dd->in_sgl;
+ out_sg = &dd->out_sgl;
+#endif
+
addr_in = dd->dma_addr_in;
addr_out = dd->dma_addr_out;

@@ -530,7 +707,11 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)

dd->total -= count;

+#ifdef OMAP_AES_DMA_PRIVATE
err = omap_aes_crypt_dma(tfm, addr_in, addr_out, count);
+#else
+ err = omap_aes_crypt_dma(tfm, in_sg, out_sg);
+#endif
if (err) {
dma_unmap_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_TO_DEVICE);
@@ -560,8 +741,13 @@ static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)

omap_aes_write_mask(dd, AES_REG_MASK, 0, AES_REG_MASK_START);

+#ifdef OMAP_AES_DMA_PRIVATE
omap_stop_dma(dd->dma_lch_in);
omap_stop_dma(dd->dma_lch_out);
+#else
+ dmaengine_terminate_all(dd->dma_lch_in);
+ dmaengine_terminate_all(dd->dma_lch_out);
+#endif

if (dd->flags & FLAGS_FAST) {
dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_FROM_DEVICE);
--
1.7.12

2012-11-19 22:45:20

by Mark Greer

[permalink] [raw]
Subject: Re: [PATCH 0/7] crypto: omap-aes updates

On Mon, Nov 19, 2012 at 12:03:45PM -0700, Mark A. Greer wrote:
> From: "Mark A. Greer" <[email protected]>
>
> This series updates the crypto omap-aes driver and supporting
> infrastructure.
>
> Notes:
>
> a) Based on omap-sham patches recently submitted, XXX
^^^
That was supposed to say that the series is based on the recently
submitted omap-sham updates:

http://permalink.gmane.org/gmane.linux.ports.arm.omap/89689

2012-11-20 12:08:26

by Kasatkin, Dmitry

[permalink] [raw]
Subject: Re: [PATCH 0/7] crypto: omap-aes updates

Great. You also worked on AES...
Will take a loos asap.

On Mon, Nov 19, 2012 at 9:03 PM, Mark A. Greer <[email protected]> wrote:
> From: "Mark A. Greer" <[email protected]>
>
> This series updates the crypto omap-aes driver and supporting
> infrastructure.
>
> Notes:
>
> a) Based on omap-sham patches recently submitted, XXX
>
> b) Since these patches will likely go though the OMAP tree (and not
> through the crypto tree), it would be nice if the crypto guy(s)
> would ACK or NACK patches 4-7 which modify the
> drivers/crypto/omap-sham.c driver.
>
> c) These have only been tested on an omap2420 h4 and an am37x evm.
>
> d) Many thanks to Jon Hunter for testing on his omap2420 h4.
>
> Mark A. Greer (7):
> ARM: OMAP2xxx: hwmod: Convert AES crypto devcie data to hwmod
> ARM: OMAP3xxx: hwmod: Convert AES crypto device data to hwmod
> ARM: OMAP2+: Remove unnecessary message when no AES IP is present
> crypto: omap-aes: Remove cpu_is/omap_type check from driver
> crypto: omap-aes: Convert to use pm_runtime API
> crypto: omap-aes: Add code to use dmaengine API
> crypto: omap-aes: Remove usage of private DMA API
>
> arch/arm/mach-omap2/clock2430_data.c | 1 +
> arch/arm/mach-omap2/clock3xxx_data.c | 1 +
> arch/arm/mach-omap2/devices.c | 75 +-------
> arch/arm/mach-omap2/omap_hwmod_2420_data.c | 1 +
> arch/arm/mach-omap2/omap_hwmod_2430_data.c | 1 +
> .../mach-omap2/omap_hwmod_2xxx_interconnect_data.c | 18 ++
> arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c | 38 ++++
> arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 62 +++++++
> arch/arm/mach-omap2/omap_hwmod_common_data.h | 2 +
> drivers/crypto/omap-aes.c | 202 ++++++++++++---------
> 10 files changed, 251 insertions(+), 150 deletions(-)
>
> --
> 1.7.12
>

2012-11-21 01:03:50

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH 4/7] crypto: omap-aes: Remove cpu_is/omap_type check from driver

* Mark A. Greer <[email protected]> [121119 11:06]:
> From: "Mark A. Greer" <[email protected]>
>
> The omap-aes driver should not check the CPU class or the
> type of OMAP device its on. The platform code should do
> that instead.

Similar patch for this one too should be queued already.

Regards,

Tony

> Signed-off-by: Mark A. Greer <[email protected]>
> ---
> drivers/crypto/omap-aes.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
> index 093a8af..628c3cc 100644
> --- a/drivers/crypto/omap-aes.c
> +++ b/drivers/crypto/omap-aes.c
> @@ -941,11 +941,6 @@ static int __init omap_aes_mod_init(void)
> {
> pr_info("loading %s driver\n", "omap-aes");
>
> - if (!cpu_class_is_omap2() || omap_type() != OMAP2_DEVICE_TYPE_SEC) {
> - pr_err("Unsupported cpu\n");
> - return -ENODEV;
> - }
> -
> return platform_driver_register(&omap_aes_driver);
> }
>
> --
> 1.7.12
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2012-12-05 10:28:48

by Kasatkin, Dmitry

[permalink] [raw]
Subject: Re: [PATCH 0/7] crypto: omap-aes updates

Hello,

I am not working on OMAP anymore and not able to test anything.
But in general changes are OK for me.

- Dmitry


On Tue, Nov 20, 2012 at 2:08 PM, Kasatkin, Dmitry
<[email protected]> wrote:
> Great. You also worked on AES...
> Will take a loos asap.
>
> On Mon, Nov 19, 2012 at 9:03 PM, Mark A. Greer <[email protected]> wrote:
>> From: "Mark A. Greer" <[email protected]>
>>
>> This series updates the crypto omap-aes driver and supporting
>> infrastructure.
>>
>> Notes:
>>
>> a) Based on omap-sham patches recently submitted, XXX
>>
>> b) Since these patches will likely go though the OMAP tree (and not
>> through the crypto tree), it would be nice if the crypto guy(s)
>> would ACK or NACK patches 4-7 which modify the
>> drivers/crypto/omap-sham.c driver.
>>
>> c) These have only been tested on an omap2420 h4 and an am37x evm.
>>
>> d) Many thanks to Jon Hunter for testing on his omap2420 h4.
>>
>> Mark A. Greer (7):
>> ARM: OMAP2xxx: hwmod: Convert AES crypto devcie data to hwmod
>> ARM: OMAP3xxx: hwmod: Convert AES crypto device data to hwmod
>> ARM: OMAP2+: Remove unnecessary message when no AES IP is present
>> crypto: omap-aes: Remove cpu_is/omap_type check from driver
>> crypto: omap-aes: Convert to use pm_runtime API
>> crypto: omap-aes: Add code to use dmaengine API
>> crypto: omap-aes: Remove usage of private DMA API
>>
>> arch/arm/mach-omap2/clock2430_data.c | 1 +
>> arch/arm/mach-omap2/clock3xxx_data.c | 1 +
>> arch/arm/mach-omap2/devices.c | 75 +-------
>> arch/arm/mach-omap2/omap_hwmod_2420_data.c | 1 +
>> arch/arm/mach-omap2/omap_hwmod_2430_data.c | 1 +
>> .../mach-omap2/omap_hwmod_2xxx_interconnect_data.c | 18 ++
>> arch/arm/mach-omap2/omap_hwmod_2xxx_ipblock_data.c | 38 ++++
>> arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 62 +++++++
>> arch/arm/mach-omap2/omap_hwmod_common_data.h | 2 +
>> drivers/crypto/omap-aes.c | 202 ++++++++++++---------
>> 10 files changed, 251 insertions(+), 150 deletions(-)
>>
>> --
>> 1.7.12
>>