crypto: talitos - Implementation of SEC1
PATCH v2 15/17 crypto: talitos - Implementation of SEC1
This patch adds talitos1.c and talitos1.h with all specificities needed to handle the SEC1 security engine found in MPC885 and MPC8272.
The SEC1 has several differences with its younger brother SEC2:
* Several bits in registers have different locations
* Many bits are missing
* Some bits are in addition
* SEC1 doesn't support scatter/gather
* SEC1 has a different descriptor structure
We add a helper function for clearing the desc field in the descriptor as that field needs to be cleared on SEC1 and doesn't exist on SEC2.
--- drivers/crypto/Kconfig | 6 +- drivers/crypto/Makefile | 1 + drivers/crypto/talitos.c | 4 + drivers/crypto/talitos.h | 5 + drivers/crypto/talitos1.c | 176 ++++++++++++++++++++++++ drivers/crypto/talitos1.h | 339 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/crypto/talitos2.h | 4 + 7 files changed, 534 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/talitos1.c create mode 100644 drivers/crypto/talitos1.h
drivers/crypto/Kconfig +5 -1
@@ -211,7 +211,8 @@ config CRYPTO_DEV_TALITOS select CRYPTO_ALGAPI select CRYPTO_AUTHENC select HW_RANDOM - select CRYPTO_DEV_TALITOS2 + select CRYPTO_DEV_TALITOS1 if PPC_8xx || PPC_82xx + select CRYPTO_DEV_TALITOS2 if !CRYPTO_DEV_TALITOS1 depends on FSL_SOC help Say 'Y' here to use the Freescale Security Engine (SEC)
@@ -223,6 +224,9 @@ config CRYPTO_DEV_TALITOS To compile this driver as a module, choose M here: the module will be called talitos. +config CRYPTO_DEV_TALITOS1 + bool + config CRYPTO_DEV_TALITOS2 bool
drivers/crypto/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += amcc/ obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o +obj-$(CONFIG_CRYPTO_DEV_TALITOS1) += talitos1.o obj-$(CONFIG_CRYPTO_DEV_TALITOS2) += talitos2.o obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
drivers/crypto/talitos.c +4 -0
@@ -653,6 +653,8 @@ static int common_nonsnoop(struct talitos_edesc *edesc,/* last DWORD empty */ desc->ptr[6 ] = zero_entry; +to_talitos_next_desc_clear (desc); + ret =talitos_submit (dev, ctx->ch, desc, callback, areq);if (ret != -EINPROGRESS ) {common_nonsnoop_unmap (dev, edesc, areq);
@@ -811,6 +813,8 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,/* last DWORD empty */ desc->ptr[6 ] = zero_entry; +to_talitos_next_desc_clear (desc); + ret =talitos_submit (dev, ctx->ch, desc, callback, areq);if (ret != -EINPROGRESS ) {common_nonsnoop_hash_unmap (dev, edesc, areq);
drivers/crypto/talitos.h +5 -0
@@ -370,4 +370,9 @@ static inline int sg_count(struct scatterlist *sg_list, int nbytes,#define DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU cpu_to_be32(2 << 3)#define DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU cpu_to_be32(4 << 3) +#ifdef CONFIG_CRYPTO_DEV_TALITOS1 +#include "talitos1.h" +#endif +#ifdef CONFIG_CRYPTO_DEV_TALITOS2 #include "talitos2.h" +#endif
drivers/crypto/talitos1.c new file +176 -0
176 lines not on this page · raw message
drivers/crypto/talitos1.h new file +339 -0
339 lines not on this page · raw message
drivers/crypto/talitos2.h +4 -0
@@ -95,6 +95,10 @@ static inline void to_talitos_ptr_extent_clear(struct talitos_ptr *ptr) ptr->j_extent =0 ; } +static inline void to_talitos_next_desc_clear (struct talitos_desc *desc) +{ +} +/* * map virtual single (contiguous) pointer to h/w descriptor pointer */
Signature · 1 line
2.1.0
Quoted 10 lines · On Fri, 6 Mar 2015 17:42:26 +0100 Christophe Leroy <[email protected]>…
This patch adds
talitos1.candtalitos1.hwith all specificities needed to handle the SEC1 security engine found in MPC885 and MPC8272.The SEC1 has several differences with its younger brother SEC2:
* Several bits in registers have different locations
* Many bits are missing
* Some bits are in addition
* SEC1 doesn't support scatter/gather
* SEC1 has a different descriptor structure
Quoted 3 lines
We add a helper function for clearing the desc field in the descriptor as that field needs to be cleared on SEC1 and doesn't exist on SEC2.
Signed-off-by Christophe Leroy <[email protected]>
Hi Christophe,
Thanks for rebasing on cryptodev-2.6, now I can easily see the differences for review.
drivers/crypto/Kconfig config CRYPTO_DEV_TALITOS · line 215
Quoted 8 lines
+++ b/drivers/crypto/Kconfig
drivers/crypto/Kconfig +2
-1@@ -211,7 +211,8 @@ config CRYPTO_DEV_TALITOS select CRYPTO_ALGAPI select CRYPTO_AUTHENC select HW_RANDOM - select CRYPTO_DEV_TALITOS2 + select CRYPTO_DEV_TALITOS1 if PPC_8xx || PPC_82xx + select CRYPTO_DEV_TALITOS2 if !CRYPTO_DEV_TALITOS1
This will set CONFIG_CRYPTO_DEV_TALITOS1=y on a kernel with both PPC_82xx and PPC_83xx set, and will therefore break talitos when run on an 83xx part.
The driver needs to work on both v1 and v2/3 SECs dynamically, and behave accordingly depending on what version h/w is described in the device tree ("fsl,secX").
So, barring making a completely new driver, a couple of points:
- A h/w version 1 vs 2 compatible priv variable can be allocated for parts of the driver that need quicker access than calling of_device_is_compatible(). Other parts that do better as complete function rewrites (the scatter-gather mapping fns?) can be abstracted away using pointers to the v1 vs. v2+ base functions. The pointers would live in the device's priv struct, and be assigned at module initialization time.
- instead of rewriting the structs talitos_ptr, talitos_desc, either use the v2-named member as-is, or make unions.
E.g., instead of having a new struct talitos_ptr, either use the v2 h/w version as-is and shift the length into place, or, add a v1 len via a union, and make to_talitos_ptr a pointer to a function, with the v1 version of the function updating only the v1 len.
For struct talitos_desc, how about:
struct talitos_desc {
__be32 hdr;
struct talitos_ptr[8];
}and have the desc->ptr[X] assigning code add 1 via a new macro iff on a SEC2 compatible (the hdr_lo code would have to be hardcoded to refer to ptr[0] instead of hdr_lo directly, and next_desc would be ptr[7]).
talitos_edesc shouldn't need the extra ptr_{in,out}, rather allocate the extra space when they're needed, and refer to them via aliases to defines that cast and use link_tbl[0] as a base reference.
For IO register accesses, either a lookup table can be used, or, since they're not frequent, define v1-specific defines in addition to the v2 ones, and reference using the compatible variable.
Other than that, please make sure to use checkpatch.pl --strict, sparse -D__CHECK_ENDIAN__, and that building as a module doesn't break.
Thanks,
Kim