Skip to contentSkip to conversation

crypto: Fully restore ahash request before completing

PATCH New Marek Vasut 7 participants 25 messages Sep 26, 2013 – Dec 1, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 crypto: Fully restore ahash request before completing

When finishing the ahash request, the ahash_op_unaligned_done() will call complete() on the request. Yet, this will not call the correct complete callback. The correct complete callback was previously stored in the requests' private data, as seen in ahash_op_unaligned(). This patch restores the correct complete callback and .data field of the request before calling complete() on it.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
---
 crypto/ahash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
crypto/ahash.c +4 -1
index 793a27f..a92dc38 100644
@@ -213,7 +213,10 @@ static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
 
 	ahash_op_unaligned_finish(areq, err);
 
-	complete(data, err);
+	areq->base.complete = complete;
+	areq->base.data = data;
+
+	complete(&areq->base, err);
 }
 
 static int ahash_op_unaligned(struct ahash_request *req,
Signature · 1 line
1.8.4.rc3
#1 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Add support for the MXS DCP block. The driver currently supports SHA-1/SHA-256 hashing and AES-128 CBC/ECB modes. The non-standard CRC32 is not yet supported.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/crypto/Kconfig   |   17 +
 drivers/crypto/Makefile  |    1 +
 drivers/crypto/mxs-dcp.c | 1082 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1100 insertions(+)
 create mode 100644 drivers/crypto/mxs-dcp.c
drivers/crypto/Kconfig +17 -0
index f4fd837..4aa6686 100644
@@ -399,4 +399,21 @@ config CRYPTO_DEV_ATMEL_SHA
 	  To compile this driver as a module, choose M here: the module
 	  will be called atmel-sha.
 
+config CRYPTO_DEV_MXS_DCP
+	tristate "Support for Freescale MXS DCP"
+	depends on ARCH_MXS
+	select CRYPTO_SHA1
+	select CRYPTO_SHA256
+	select CRYPTO_CBC
+	select CRYPTO_ECB
+	select CRYPTO_AES
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_ALGAPI
+	help
+	  The Freescale i.MX23/i.MX28 has SHA1/SHA256 and AES128 CBC/ECB
+	  co-processor on the die.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called atmel-sha.
+
 endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
index b4946dd..56cce04 100644
@@ -22,3 +22,4 @@ obj-$(CONFIG_CRYPTO_DEV_NX) += nx/
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_AES) += atmel-aes.o
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_TDES) += atmel-tdes.o
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_SHA) += atmel-sha.o
+obj-$(CONFIG_CRYPTO_DEV_MXS_DCP) += mxs-dcp.o
drivers/crypto/mxs-dcp.c new file +1082 -0

1,082 lines not on this page · raw message

Signature · 1 line
1.8.4.rc3
reviewer
#2 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi Marek,

Quoted 11 lines · Marek Vasut

Add support for the MXS DCP block. The driver currently supports SHA-1/SHA-256 hashing and AES-128 CBC/ECB modes. The non-standard CRC32 is not yet supported.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/crypto/Kconfig   |   17 +
 drivers/crypto/Makefile  |    1 +
 drivers/crypto/mxs-dcp.c | 1082 ++++++++++++++++++++++++++++++++++++++++++++++

What about the existing DCP driver at drivers/crypto/dcp.c ?

Why do we need to have two drivers for the same IP block? It looks confusing to have both.

Regards,

Fabio Estevam

#3 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Dear Fabio Estevam,

Quoted 12 lines

Hi Marek,

Quoted 9 lines · Marek Vasut

Add support for the MXS DCP block. The driver currently supports SHA-1/SHA-256 hashing and AES-128 CBC/ECB modes. The non-standard CRC32 is not yet supported.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>

---

Quoted 6 lines
Quoted 4 lines
 drivers/crypto/Kconfig   |   17 +
 drivers/crypto/Makefile  |    1 +
 drivers/crypto/mxs-dcp.c | 1082

++++++++++++++++++++++++++++++++++++++++++++++

What about the existing DCP driver at drivers/crypto/dcp.c ?

I was not aware of that one.

Quoted 2 lines

Why do we need to have two drivers for the same IP block? It looks confusing to have both.

Sure, I agree. I reviewed the one in mainline just now and I see some deficiencies of the dcp.c driver:

1) It only supports AES_CBC (mine does support AES_ECB, AES_CBC, SHA1 and SH256)
2) The driver was apparently never ran behind anyone working with MXS. ie.:
-> Restarting the DCP block is not done via mxs_reset_block()
-> The DT name is not "fsl,dcp" or "fsl,mxs-dcp" as other MXS drivers
3) What are those ugly new IOCTLs in the dcp.c driver?
4) The VMI IRQ is never used, yet it even calls the IRQ handler, this is bogus -> The DCP always triggers the dcp_irq upon DMA completion
-> VMI IRQ is not handled in the handler at all as I see it
5) The IRQ handler can't use usual completion() in the driver because that'd trigger "scheduling while atomic" oops, yes?

Finally, because the dcp.c driver only supports AES128 CBC, it depends on kernel _always_ passing the DCP scatterlist such that each of it's elements is 16-bytes long. If each of the elements is 16 bytes, there is no problem and the DCP will operate correctly. That is because the DCP has the following limitations:

-> For AES128, each buffer in the DMA chain must be multiple of 16 bytes. -> For SHA1/SHA256, each buffer in the DMA chain must by multiple of 64 bytes BUT only the last buffer in the DMA chain can be shorter.

So, in the AES128 case, if the hardware is passed two (4 bytes + 12 bytes for example) DMA descriptors instead of single 16 bytes descriptor, the DCP will simply stall or produce incorrect result. This can happen if the user of the async crypto API passes such a scatterlist.

It is true this is not caught by the in-kernel crypto tests, because they mostly trigger the software fallback in this driver, since this driver only supports 16 byte key (klen == 16 , see crypto/testmgr.h). It can be triggered by modifying the crypto tests so that they pass two buffers, multiple of 16 bytes in total, but each of them not multiple of 16 bytes.

I ran into many such problems when I was developing this driver I submitted here, I managed to trigger those by running the Cryptodev [1] tests [2] against this driver as well as testing the performance of this driver via Cryptodev/OpenSSL combination:

$ openssl speed sha1
$ openssl speed sha256
$ openssl speed aes-128-cbc

I also measured the performance via OpenSSL encryption/decryption. On larger files, the performance of encryption/decryption via DCP, even with fixups for unaligned buffers and the overhead of userspace-kernel-userspace switches due to cryptodev is still higher than software implementation:

$ time openssl enc -aes-128-ecb -in $IFILE -out $OFILE -k "test" -nosalt
$ time openssl enc -d -aes-128-ecb -in $OFILE -out $DFILE -k "test" -nosalt

Also, since OpenSSH uses OpenSSL, this helped my testing too.

[1] http://cryptodev-linux.org/
[2] https://github.com/nmav/cryptodev-linux/tree/master/tests

Best regards,
Marek Vasut

#4 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi,

Here are some thoughts of the design decisions I made when I wrote the dcp.c driver. Maybe it helps.

Quoted 11 lines · Marek Vasut

Dear Fabio Estevam,

Quoted 4 lines

Hi Marek,

Why do we need to have two drivers for the same IP block? It looks confusing to have both.

Sure, I agree. I reviewed the one in mainline just now and I see some deficiencies of the dcp.c driver:

1) It only supports AES_CBC (mine does support AES_ECB, AES_CBC, SHA1 and SH256)

Right, but for ECP only the interface is missing (and it is no real mode of operation) and hashes should be generally faster in SW.

Quoted 1 line

2) The driver was apparently never ran behind anyone working with MXS.

That is probably right.

Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API).
Therefore I added this miscdevice and adopted Freescale's interface.

Quoted 1 line

4) The VMI IRQ is never used, yet it even calls the IRQ handler, this is bogus

That's absolutely right.

Quoted 1 line
    -> The DCP always triggers the dcp_irq upon DMA completion

The IRQ is triggered after every packet, to enable simultaneous work for CPU/DCP: While the DCP is computing, the CPU is able to fill more packets. I don't know how far this is useful, because the 20 Packets which are enabled by default can address up to 80kB of plain-/ciphertext. However, I think it is better to do the work simultaneously to safe time (actual real world time, not CPU time).

Quoted 2 lines

5) The IRQ handler can't use usual completion() in the driver because that'd trigger "scheduling while atomic" oops, yes?

I decided to use the tasklets because of performance reasons. I don't remember numbers but a workqueue was significantly slower. The use of a kernel thread may reduce the overhead compared to the wq. I was not sure if it is appropriate to create an extra thread for a crypto-driver, without real reason (IMHO).

Quoted 7 lines

Finally, because the dcp.c driver only supports AES128 CBC, it depends on kernel _always_ passing the DCP scatterlist such that each of it's elements is 16-bytes long. [...]
So, in the AES128 case, if the hardware is passed two (4 bytes + 12 bytes for example) DMA descriptors instead of single 16 bytes descriptor, the DCP will simply stall or produce incorrect result. This can happen if the user of the async crypto API passes such a scatterlist.

The scatterlist alignment and bounce-buffering to get full 16 Byte blocks is done by the ablkcipher_walk API (with the error parameter) when needed. As far as I see, you are copying the whole buffer to your coherent block and back. Wouldn't it be better to do that just for unaligned blocks?

kind regards,
tr

#5 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi Tobias,

Quoted 4 lines

Hi,

Here are some thoughts of the design decisions I made when I wrote the dcp.c driver. Maybe it helps.

Was the driver not rather forward-ported from some old FSL BSP kernel?

Quoted 8 lines · Marek Vasut
Quoted 7 lines

Dear Fabio Estevam,

Quoted 4 lines

Hi Marek,

Why do we need to have two drivers for the same IP block? It looks confusing to have both.

Quoted 8 lines
Quoted 5 lines

Sure, I agree. I reviewed the one in mainline just now and I see some deficiencies of the dcp.c driver:

1) It only supports AES_CBC (mine does support AES_ECB, AES_CBC, SHA1 and SH256)

Right, but for ECP only the interface is missing (and it is no real mode of operation) and hashes should be generally faster in SW.

The ECB is slightly different from CBC, for example the IV handling differs. As for the performance, the SHA* hashing was more performant in hardware starting with ~8MB chunks. I checked this via the "openssl -speed" test via the linux cryptodev patch.

Quoted 6 lines
Quoted 1 line

2) The driver was apparently never ran behind anyone working with MXS.

That is probably right.

Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

Quoted 7 lines

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API).
Therefore I added this miscdevice and adopted Freescale's interface.

The keys are programmed into the OTP registers, correct? There is OCOTP driver for the MX23/MX28 OTP hardware. This is what should have been used then.

NOTE: This IOCTL interface seems like quite an abusive way to allow userland to access the crypto API in kernel. I understand this is used by some Freescale tool, but won't it be better to fix the Freescale tool instead ?

Quoted 5 lines
Quoted 2 lines

4) The VMI IRQ is never used, yet it even calls the IRQ handler, this is bogus

That's absolutely right.

Quoted 8 lines
Quoted 1 line
    -> The DCP always triggers the dcp_irq upon DMA completion

The IRQ is triggered after every packet, to enable simultaneous work for CPU/DCP: While the DCP is computing, the CPU is able to fill more packets. I don't know how far this is useful, because the 20 Packets which are enabled by default can address up to 80kB of plain-/ciphertext. However, I think it is better to do the work simultaneously to safe time (actual real world time, not CPU time).

This really depends on how you program the DCP's own DMA controller, or more precisely what you write into the DMA descriptors. Each descriptor has a bit that signalizes whether the DCP should generate an IRQ upon it's completion. You can thus program it to generate IRQ upon competing each descriptor only for the last descriptor in a chain or what fits you.

NOTE that chaining multiple DMA descriptors of small size is less performant than filling up a large buffer and then running it through the DCP in one longer DMA descriptor. This is actually why I have such a large bounce-buffer and not only a small one.

Quoted 8 lines
Quoted 2 lines

5) The IRQ handler can't use usual completion() in the driver because that'd trigger "scheduling while atomic" oops, yes?

I decided to use the tasklets because of performance reasons. I don't remember numbers but a workqueue was significantly slower. The use of a kernel thread may reduce the overhead compared to the wq. I was not sure if it is appropriate to create an extra thread for a crypto-driver, without real reason (IMHO).

Certainly, my remark was that the FSL driver had this issue and the code here didn't change much from the FSL driver. I was thus curious why you don't use completion in the driver as usual and whether this was to work around the issue the FSL driver had.

Quoted 8 lines
Quoted 7 lines

Finally, because the dcp.c driver only supports AES128 CBC, it depends on kernel _always_ passing the DCP scatterlist such that each of it's elements is 16-bytes long. [...]
So, in the AES128 case, if the hardware is passed two (4 bytes + 12 bytes for example) DMA descriptors instead of single 16 bytes descriptor, the DCP will simply stall or produce incorrect result. This can happen if the user of the async crypto API passes such a scatterlist.

Quoted 5 lines

The scatterlist alignment and bounce-buffering to get full 16 Byte blocks is done by the ablkcipher_walk API (with the error parameter) when needed. As far as I see, you are copying the whole buffer to your coherent block and back. Wouldn't it be better to do that just for unaligned blocks?

I tried writing a proper driver for this DCP piece of crap hardware about 7 times. I tried to squeeze as much power from it as possible, among others tried to avoid the copying, but there was always some hidden problem somewhere. The DCP is really _horribly_ designed hardware. But to answer your question, the copying of stuff back and forth is actually not a problem here.

The real question here is, how do we handle the current situation? I think this might be a question for Dave or Herbert to answer though.

Best regards,
Marek Vasut

#6 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hello Marek,

Quoted 10 lines

?Marek?Vasut?<[email protected]>?hat?am?28.?September?2013?um?05:35?geschrieben:
[...] ?>?>?3)?What?are?those?ugly?new?IOCTLs?in?the?dcp.c?driver?
?>? ?>?When?I?firstly?posted?the?driver?in?the?mailinglist,?there?where?one ?>?person?who?actually?used?this?interface?(it?was?introduced?in ?>?Freescale's?SDK)?to?use?the?OTP?keys?for?crypto.?As?far?as?I?have ?>?seen,?the?crypto?API?does?not?support?such?keys?(i.e.?there?seems?to ?>?be?no?way?to?tell?a?driver?to?use?some?kind?of?special?keys?-?which ?>?are?not?delivered?by?the?user?-?via?the?API).

Quoted 8 lines

?>?Therefore?I?added?this?miscdevice?and?adopted?Freescale's?interface. ? ?The?keys?are?programmed?into?the?OTP?registers,?correct??There?is?OCOTP?driver? ?for?the?MX23/MX28?OTP?hardware.?This?is?what?should?have?been?used?then. ? ?NOTE:?This?IOCTL?interface?seems?like?quite?an?abusive?way?to?allow?userland?to? ?access?the?crypto?API?in?kernel.?I?understand?this?is?used?by?some?Freescale? ?tool,?but?won't?it?be?better?to?fix?the?Freescale?tool?instead??

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Regards,
Christoph

#7 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hello Christoph,

Quoted 23 lines

Hello Marek,

Quoted 13 lines

Marek Vasut <[email protected]> hat am 28. September 2013 um 05:35 geschrieben:
[...]

Quoted 9 lines
Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API).
Therefore I added this miscdevice and adopted Freescale's interface.

Quoted 7 lines

The keys are programmed into the OTP registers, correct? There is OCOTP d river
for the MX23/MX28 OTP hardware. This is what should have been used then.
NOTE: This IOCTL interface seems like quite an abusive way to allow userl and to
access the crypto API in kernel. I understand this is used by some Freesc ale tool, but won't it be better to fix the Freescale tool instead ?

Quoted 6 lines

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Ah right. I suspect the crypto API services shall not be exported into userland at all, yes ? So there has to be some kind of workaround here for this freescale tool, which is rather unfortunate.

Thanks for clearing this up.

Best regards,
Marek Vasut

maintainer
#8 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Quoted 32 lines · Marek Vasut

Hello Christoph,

Quoted 23 lines

Hello Marek,

Quoted 13 lines

Marek Vasut <[email protected]> hat am 28. September 2013 um 05:35 geschrieben:
[...]

Quoted 9 lines
Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API).
Therefore I added this miscdevice and adopted Freescale's interface.

Quoted 7 lines

The keys are programmed into the OTP registers, correct? There is OCOTP d river
for the MX23/MX28 OTP hardware. This is what should have been used then.
NOTE: This IOCTL interface seems like quite an abusive way to allow userl and to
access the crypto API in kernel. I understand this is used by some Freesc ale tool, but won't it be better to fix the Freescale tool instead ?

Quoted 6 lines

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Quoted 3 lines

Ah right. I suspect the crypto API services shall not be exported into userland at all, yes ? So there has to be some kind of workaround here for this freescale tool, which is rather unfortunate.

These ioctls have to go. I should have never let them through in the first place. Can someone cook up a patch to kill them please?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#9 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hello Herbert,

Quoted 41 lines · Marek Vasut
Quoted 40 lines

Hello Christoph,

Quoted 37 lines

Hello Marek,

Quoted 21 lines

Marek Vasut <[email protected]> hat am 28. September 2013 um 05:35
geschrieben: [...]

Quoted 10 lines
Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API). Therefore I added this miscdevice and adopted Freescale's interface.

The keys are programmed into the OTP registers, correct? There is OCOTP d

river
for the MX23/MX28 OTP hardware. This is what should have been used then.

Quoted 7 lines

NOTE: This IOCTL interface seems like quite an abusive way to allow userl

and to
access the crypto API in kernel. I understand this is used by some Freesc ale tool, but won't it be better to fix the Freescale tool instead ?

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Quoted 6 lines
Quoted 3 lines

Ah right. I suspect the crypto API services shall not be exported into userland at all, yes ? So there has to be some kind of workaround here for this freescale tool, which is rather unfortunate.

These ioctls have to go. I should have never let them through in the first place. Can someone cook up a patch to kill them please?

I can do that. I wonder if we can't agree to nuke the in-tree driver altogether instead and replace it by this one though. Does it not sound more reasonable?

Best regards,
Marek Vasut

#10 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi,

Quoted 47 lines

Hello Herbert,

Quoted 45 lines · Marek Vasut
Quoted 43 lines

Hello Christoph,

Quoted 31 lines

Hello Marek,

Quoted 21 lines

Marek Vasut <[email protected]> hat am 28. September 2013 um 05:35
geschrieben: [...]

Quoted 10 lines
Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API). Therefore I added this miscdevice and adopted Freescale's interface.

The keys are programmed into the OTP registers, correct? There is OCOTP d

river
for the MX23/MX28 OTP hardware. This is what should have been used then.

Quoted 7 lines

NOTE: This IOCTL interface seems like quite an abusive way to allow userl

and to
access the crypto API in kernel. I understand this is used by some Freesc ale tool, but won't it be better to fix the Freescale tool instead ?

Quoted 6 lines

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Ah right. I suspect the crypto API services shall not be exported into userland at all, yes ? So there has to be some kind of workaround here for this freescale tool, which is rather unfortunate.

Quoted 6 lines
Quoted 2 lines

These ioctls have to go. I should have never let them through in the first place. Can someone cook up a patch to kill them please?

I can do that. I wonder if we can't agree to nuke the in-tree driver altogether instead and replace it by this one though. Does it not sound more reasonable?

Bump?

Best regards,
Marek Vasut

maintainer
#11 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Quoted 49 lines · Marek Vasut

Hi,

Quoted 47 lines

Hello Herbert,

Quoted 45 lines · Marek Vasut
Quoted 43 lines

Hello Christoph,

Quoted 31 lines

Hello Marek,

Quoted 21 lines

Marek Vasut <[email protected]> hat am 28. September 2013 um 05:35
geschrieben: [...]

Quoted 10 lines
Quoted 1 line

3) What are those ugly new IOCTLs in the dcp.c driver?

When I firstly posted the driver in the mailinglist, there where one person who actually used this interface (it was introduced in Freescale's SDK) to use the OTP keys for crypto. As far as I have seen, the crypto API does not support such keys (i.e. there seems to be no way to tell a driver to use some kind of special keys - which are not delivered by the user - via the API). Therefore I added this miscdevice and adopted Freescale's interface.

The keys are programmed into the OTP registers, correct? There is OCOTP d

river
for the MX23/MX28 OTP hardware. This is what should have been used then.

Quoted 7 lines

NOTE: This IOCTL interface seems like quite an abusive way to allow userl

and to
access the crypto API in kernel. I understand this is used by some Freesc ale tool, but won't it be better to fix the Freescale tool instead ?

Quoted 6 lines

the IOCTL interface is used to AES encrypt a bootstream with the AES key in OCOTP.
The idea is that only the DCP can read/access the key once it has been programmed
into the OCOTP. If the crypto API has means to tell the DCP to use the key from OCOTP, the tool from Freescale is a minor problem.

Ah right. I suspect the crypto API services shall not be exported into userland at all, yes ? So there has to be some kind of workaround here for this freescale tool, which is rather unfortunate.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

These ioctls have to go. I should have never let them through in the first place. Can someone cook up a patch to kill them please?

I can do that. I wonder if we can't agree to nuke the in-tree driver altogether instead and replace it by this one though. Does it not sound more reasonable?

Bump?

Well as it's been months and nobody has stepped up to maintain the in-tree driver then yes we can get rid of it.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#12 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi Herbert,

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I can do that. I wonder if we can't agree to nuke the in-tree driver altogether instead and replace it by this one though. Does it not sound more reasonable?

Bump?

Well as it's been months and nobody has stepped up to maintain the in-tree driver then yes we can get rid of it.

OK, I updated the DCP patches and re-posted them. Thanks!

Best regards,
Marek Vasut

#13 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

In reply to Marek Vasut

Hi Marek,

some small comments below.

Quoted 5 lines · Marek Vasut
drivers/crypto/mxs-dcp.c new file +0 -0
new file mode 100644
index 0000000..c2b35c7

[...]

Quoted 14 lines
drivers/crypto/mxs-dcp.c new file +14 -0
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+	[0] = {
+		.cra_name		= "ecb(aes)",
+		.cra_driver_name	= "ecb-aes-dcp",
+		.cra_priority		= 400,
+		.cra_alignmask		= 15,
+		.cra_flags		= CRYPTO_ALG_TYPE_ABLKCIPHER |
+					  CRYPTO_ALG_ASYNC |
+					  CRYPTO_ALG_NEED_FALLBACK,
+		.cra_init		= mxs_dcp_aes_fallback_init,
+		.cra_exit		= mxs_dcp_aes_fallback_exit,
+		.cra_blocksize		= AES_BLOCK_SIZE,
+		.cra_ctxsize		= sizeof(struct dcp_async_ctx),

drivers/crypto/mxs-dcp.c line 761

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+		.cra_type		= &crypto_ablkcipher_type,
+		.cra_module		= THIS_MODULE,
+		.cra_u	= {
+			.ablkcipher = {
+				.min_keysize	= AES_MIN_KEY_SIZE,
+				.max_keysize	= AES_MAX_KEY_SIZE,
+				.setkey		= mxs_dcp_aes_setkey,
+				.encrypt	= mxs_dcp_aes_ecb_encrypt,
+				.decrypt	= mxs_dcp_aes_ecb_decrypt
+			}

missing ',' after '}'

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+		}

dto.

Quoted 14 lines
drivers/crypto/mxs-dcp.c new file +14 -0
+	},
+	[1] = {
+		.cra_name		= "cbc(aes)",
+		.cra_driver_name	= "cbc-aes-dcp",
+		.cra_priority		= 400,
+		.cra_alignmask		= 15,
+		.cra_flags		= CRYPTO_ALG_TYPE_ABLKCIPHER |
+					  CRYPTO_ALG_ASYNC |
+					  CRYPTO_ALG_NEED_FALLBACK,
+		.cra_init		= mxs_dcp_aes_fallback_init,
+		.cra_exit		= mxs_dcp_aes_fallback_exit,
+		.cra_blocksize		= AES_BLOCK_SIZE,
+		.cra_ctxsize		= sizeof(struct dcp_async_ctx),
+		.cra_type		= &crypto_ablkcipher_type,

drivers/crypto/mxs-dcp.c line 786

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+		.cra_module		= THIS_MODULE,
+		.cra_u = {
+			.ablkcipher = {
+				.min_keysize	= AES_MIN_KEY_SIZE,
+				.max_keysize	= AES_MAX_KEY_SIZE,
+				.setkey		= mxs_dcp_aes_setkey,
+				.encrypt	= mxs_dcp_aes_cbc_encrypt,
+				.decrypt	= mxs_dcp_aes_cbc_decrypt,
+				.ivsize		= AES_BLOCK_SIZE,
+			}

dto.

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+		}

dto.

Quoted 14 lines
drivers/crypto/mxs-dcp.c new file +14 -0
+	},
+};
+
+/* SHA1 */
+static struct ahash_alg dcp_sha1_alg = {
+	.init	= dcp_sha_init,
+	.update	= dcp_sha_update,
+	.final	= dcp_sha_final,
+	.finup	= dcp_sha_finup,
+	.digest	= dcp_sha_digest,
+	.halg	= {
+		.digestsize	= SHA1_DIGEST_SIZE,
+		.base		= {
+			.cra_name		= "sha1",

drivers/crypto/mxs-dcp.c line 811

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+			.cra_driver_name	= "sha1-dcp",
+			.cra_priority		= 400,
+			.cra_alignmask		= 63,
+			.cra_flags		= CRYPTO_ALG_ASYNC,
+			.cra_blocksize		= SHA1_BLOCK_SIZE,
+			.cra_ctxsize		= sizeof(struct dcp_async_ctx),
+			.cra_module		= THIS_MODULE,
+			.cra_init		= dcp_sha_cra_init,
+			.cra_exit		= dcp_sha_cra_exit,
+		}

dto.

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+	}

dto.

Quoted 13 lines
drivers/crypto/mxs-dcp.c new file +13 -0
+};
+
+/* SHA256 */
+static struct ahash_alg dcp_sha256_alg = {
+	.init	= dcp_sha_init,
+	.update	= dcp_sha_update,
+	.final	= dcp_sha_final,
+	.finup	= dcp_sha_finup,
+	.digest	= dcp_sha_digest,
+	.halg	= {
+		.digestsize	= SHA256_DIGEST_SIZE,
+		.base		= {
+			.cra_name		= "sha256",

drivers/crypto/mxs-dcp.c line 835

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+			.cra_driver_name	= "sha256-dcp",
+			.cra_priority		= 400,
+			.cra_alignmask		= 63,
+			.cra_flags		= CRYPTO_ALG_ASYNC,
+			.cra_blocksize		= SHA256_BLOCK_SIZE,
+			.cra_ctxsize		= sizeof(struct dcp_async_ctx),
+			.cra_module		= THIS_MODULE,
+			.cra_init		= dcp_sha_cra_init,
+			.cra_exit		= dcp_sha_cra_exit,
+		}

dto.

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+	}

dto.

drivers/crypto/mxs-dcp.c line 1062

Quoted 3 lines
drivers/crypto/mxs-dcp.c new file +2 -0
+static const struct of_device_id mxs_dcp_dt_ids[] = {
+	{.compatible = "fsl,mxs-dcp", .data = NULL,},

missing spaces after '{' and before '}'

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#14 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Dear Lothar Wa?mann,

Quoted 31 lines

Hi Marek,

some small comments below.

Quoted 5 lines · Marek Vasut
drivers/crypto/mxs-dcp.c new file +0 -0
new file mode 100644
index 0000000..c2b35c7

[...]

Quoted 18 lines
drivers/crypto/mxs-dcp.c new file +18 -0
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+	[0] = {
+		.cra_name		= "ecb(aes)",
+		.cra_driver_name	= "ecb-aes-dcp",
+		.cra_priority		= 400,
+		.cra_alignmask		= 15,
+		.cra_flags		= CRYPTO_ALG_TYPE_ABLKCIPHER |
+					  CRYPTO_ALG_ASYNC |
+					  CRYPTO_ALG_NEED_FALLBACK,
+		.cra_init		= mxs_dcp_aes_fallback_init,
+		.cra_exit		= mxs_dcp_aes_fallback_exit,
+		.cra_blocksize		= AES_BLOCK_SIZE,
+		.cra_ctxsize		= sizeof(struct dcp_async_ctx),
+		.cra_type		= &crypto_ablkcipher_type,
+		.cra_module		= THIS_MODULE,
+		.cra_u	= {
+			.ablkcipher = {
Quoted 8 lines

drivers/crypto/mxs-dcp.c line 761

Quoted 6 lines
drivers/crypto/mxs-dcp.c new file +6 -0
+				.min_keysize	= AES_MIN_KEY_SIZE,
+				.max_keysize	= AES_MAX_KEY_SIZE,
+				.setkey		= mxs_dcp_aes_setkey,
+				.encrypt	= mxs_dcp_aes_ecb_encrypt,
+				.decrypt	= mxs_dcp_aes_ecb_decrypt
+			}

missing ',' after '}'

Is this a problem? The last ',' is not needed by the C standard.

[...]

Quoted 5 lines

drivers/crypto/mxs-dcp.c line 1062

Quoted 3 lines
drivers/crypto/mxs-dcp.c new file +2 -0
+static const struct of_device_id mxs_dcp_dt_ids[] = {
+	{.compatible = "fsl,mxs-dcp", .data = NULL,},

missing spaces after '{' and before '}'

Thanks!

Best regards,
Marek Vasut

#15 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Hi,

Quoted 42 lines · Marek Vasut

Dear Lothar Wa?mann,

Quoted 31 lines

Hi Marek,

some small comments below.

Quoted 5 lines · Marek Vasut
drivers/crypto/mxs-dcp.c new file +0 -0
new file mode 100644
index 0000000..c2b35c7

[...]

Quoted 18 lines
drivers/crypto/mxs-dcp.c new file +18 -0
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+	[0] = {
+		.cra_name		= "ecb(aes)",
+		.cra_driver_name	= "ecb-aes-dcp",
+		.cra_priority		= 400,
+		.cra_alignmask		= 15,
+		.cra_flags		= CRYPTO_ALG_TYPE_ABLKCIPHER |
+					  CRYPTO_ALG_ASYNC |
+					  CRYPTO_ALG_NEED_FALLBACK,
+		.cra_init		= mxs_dcp_aes_fallback_init,
+		.cra_exit		= mxs_dcp_aes_fallback_exit,
+		.cra_blocksize		= AES_BLOCK_SIZE,
+		.cra_ctxsize		= sizeof(struct dcp_async_ctx),
+		.cra_type		= &crypto_ablkcipher_type,
+		.cra_module		= THIS_MODULE,
+		.cra_u	= {
+			.ablkcipher = {
Quoted 8 lines

drivers/crypto/mxs-dcp.c line 761

Quoted 6 lines
drivers/crypto/mxs-dcp.c new file +6 -0
+				.min_keysize	= AES_MIN_KEY_SIZE,
+				.max_keysize	= AES_MAX_KEY_SIZE,
+				.setkey		= mxs_dcp_aes_setkey,
+				.encrypt	= mxs_dcp_aes_ecb_encrypt,
+				.decrypt	= mxs_dcp_aes_ecb_decrypt
+			}

missing ',' after '}'

Quoted 2 lines

Is this a problem? The last ',' is not needed by the C standard.

The problem arises when someone wants to append another item to the list. Without the comma he has to change two lines which may cause merge conflicts if two people add different items to the same struct.

That's why we usually have (unnecessary) commas on the last element of a struct initializer (except when they are meant to be the last element of course).

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#16 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Dear Lothar Wa?mann,

Quoted 32 lines

Hi,

Quoted 29 lines · Marek Vasut

Dear Lothar Wa?mann,

Quoted 27 lines

Hi Marek,

some small comments below.

Quoted 5 lines · Marek Vasut
drivers/crypto/mxs-dcp.c new file +0 -0
new file mode 100644
index 0000000..c2b35c7

[...]

Quoted 14 lines
drivers/crypto/mxs-dcp.c new file +14 -0
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+	[0] = {
+		.cra_name		= "ecb(aes)",
+		.cra_driver_name	= "ecb-aes-dcp",
+		.cra_priority		= 400,
+		.cra_alignmask		= 15,
+		.cra_flags		= CRYPTO_ALG_TYPE_ABLKCIPHER |
+					  CRYPTO_ALG_ASYNC |
+					  CRYPTO_ALG_NEED_FALLBACK,
+		.cra_init		= mxs_dcp_aes_fallback_init,
+		.cra_exit		= mxs_dcp_aes_fallback_exit,
+		.cra_blocksize		= AES_BLOCK_SIZE,
+		.cra_ctxsize		= sizeof(struct dcp_async_ctx),
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/crypto/mxs-dcp.c

Quoted 8 lines
drivers/crypto/mxs-dcp.c new file +8 -0
+		.cra_type		= &crypto_ablkcipher_type,
+		.cra_module		= THIS_MODULE,
+		.cra_u	= {
+			.ablkcipher = {
+				.min_keysize	= AES_MIN_KEY_SIZE,
+				.max_keysize	= AES_MAX_KEY_SIZE,
+				.setkey		= mxs_dcp_aes_setkey,
+				.encrypt	= 

mxs_dcp_aes_ecb_encrypt,

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+				.decrypt	= 

mxs_dcp_aes_ecb_decrypt

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

drivers/crypto/mxs-dcp.c

Quoted 1 line
drivers/crypto/mxs-dcp.c new file +1 -0
+			}

missing ',' after '}'

Is this a problem? The last ',' is not needed by the C standard.

Quoted 7 lines

The problem arises when someone wants to append another item to the list. Without the comma he has to change two lines which may cause merge conflicts if two people add different items to the same struct.

That's why we usually have (unnecessary) commas on the last element of a struct initializer (except when they are meant to be the last element of course).

Good point.

Best regards,
Marek Vasut

#17 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

In reply to Marek Vasut

Hi Marek,

drivers/crypto/Kconfig config CRYPTO_DEV_ATMEL_SHA · line 417

Quoted 2 lines
drivers/crypto/Kconfig +2 -0
+         To compile this driver as a module, choose M here: the module
+         will be called atmel-sha.

This is probably wrong?

--
Veli-Pekka Peltola

#18 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Dear Veli-Pekka Peltola,

Quoted 6 lines

Hi Marek,

drivers/crypto/Kconfig config CRYPTO_DEV_ATMEL_SHA · line 417

Quoted 2 lines
drivers/crypto/Kconfig +2 -0
+         To compile this driver as a module, choose M here: the module
+         will be called atmel-sha.

This is probably wrong?

Certainly. Nice to have you back btw. ;-)

Best regards,
Marek Vasut

reviewer
#19 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

In reply to Marek Vasut
Quoted 6 lines · Marek Vasut
drivers/crypto/Kconfig +6 -0
+config CRYPTO_DEV_MXS_DCP
+       tristate "Support for Freescale MXS DCP"
+       depends on ARCH_MXS
+       select CRYPTO_SHA1
+       select CRYPTO_SHA256
+       select CRYPTO_CBC

drivers/crypto/Kconfig config CRYPTO_DEV_ATMEL_SHA · line 417

Quoted 10 lines
drivers/crypto/Kconfig +10 -0
+       select CRYPTO_ECB
+       select CRYPTO_AES
+       select CRYPTO_BLKCIPHER
+       select CRYPTO_ALGAPI
+       help
+         The Freescale i.MX23/i.MX28 has SHA1/SHA256 and AES128 CBC/ECB
+         co-processor on the die.
+
+         To compile this driver as a module, choose M here: the module
+         will be called atmel-sha.

Actually it will be called 'mxs-dcp'.

Quoted 2 lines

+ * There can even be only one instance of the MXS DCP due to the
+ * design of Linux Crypto API.

Is this true? Usually we don't want to create a global struct.

drivers/crypto/mxs-dcp.c line 740

Quoted 4 lines
drivers/crypto/mxs-dcp.c new file +4 -0
+
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+       [0] = {

No need for explicitely add this [0]

Quoted 14 lines
drivers/crypto/mxs-dcp.c new file +14 -0
+               .cra_name               = "ecb(aes)",
+               .cra_driver_name        = "ecb-aes-dcp",
+               .cra_priority           = 400,
+               .cra_alignmask          = 15,
+               .cra_flags              = CRYPTO_ALG_TYPE_ABLKCIPHER |
+                                         CRYPTO_ALG_ASYNC |
+                                         CRYPTO_ALG_NEED_FALLBACK,
+               .cra_init               = mxs_dcp_aes_fallback_init,
+               .cra_exit               = mxs_dcp_aes_fallback_exit,
+               .cra_blocksize          = AES_BLOCK_SIZE,
+               .cra_ctxsize            = sizeof(struct dcp_async_ctx),
+               .cra_type               = &crypto_ablkcipher_type,
+               .cra_module             = THIS_MODULE,
+               .cra_u  = {

drivers/crypto/mxs-dcp.c line 764

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+                       .ablkcipher = {
+                               .min_keysize    = AES_MIN_KEY_SIZE,
+                               .max_keysize    = AES_MAX_KEY_SIZE,
+                               .setkey         = mxs_dcp_aes_setkey,
+                               .encrypt        = mxs_dcp_aes_ecb_encrypt,
+                               .decrypt        = mxs_dcp_aes_ecb_decrypt
+                       }
+               }
+       },
+       [1] = {

Same here.

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+static int mxs_dcp_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct dcp *sdcp = NULL;
+       int i, ret;
+
+       struct resource *iores;
+       int dcp_vmi_irq, dcp_irq;
+
+       mutex_lock(&global_mutex);

drivers/crypto/mxs-dcp.c line 880

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+       if (global_sdcp) {
+               dev_err(dev, "Only one DCP instance allowed!\n");
+               ret = -ENODEV;
+               goto err_mutex;
+       }
+
+       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       dcp_vmi_irq = platform_get_irq(pdev, 0);
+       dcp_irq = platform_get_irq(pdev, 1);
+       if (!iores || dcp_vmi_irq < 0 || dcp_irq < 0) {

No need to check for !iores here.

You use it inside devm_ioremap_resource, which already does this checking.

drivers/crypto/mxs-dcp.c line 940

Quoted 8 lines
drivers/crypto/mxs-dcp.c new file +8 -0
+       /*
+        * We do not enable context switching. Give the context buffer a
+        * pointer to an illegal address so if context switching is
+        * inadvertantly enabled, the DCP will return an error instead of
+        * trashing good memory. The DCP DMA cannot access ROM, so any ROM
+        * address will do.
+        */
+       writel(0xffff0000, sdcp->base + MXS_DCP_CONTEXT);

Can you use a define instead of this hardcoded number?

Quoted 19 lines
drivers/crypto/mxs-dcp.c new file +19 -0
+static int mxs_dcp_remove(struct platform_device *pdev)
+{
+       struct dcp *sdcp;
+       int i;
+
+       sdcp = platform_get_drvdata(pdev);
+
+       kthread_stop(sdcp->thread[DCP_CHAN_HASH_SHA]);
+       kthread_stop(sdcp->thread[DCP_CHAN_CRYPTO]);
+
+       platform_set_drvdata(pdev, NULL);
+
+       dma_free_coherent(sdcp->dev, sizeof(struct dcp_coherent_block),
+                         sdcp->coh, sdcp->coh_phys);
+
+       if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA256)
+               crypto_unregister_ahash(&dcp_sha256_alg);
+
+       if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA1)

drivers/crypto/mxs-dcp.c line 1056

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+               crypto_unregister_ahash(&dcp_sha1_alg);
+
+       if (sdcp->caps & MXS_DCP_CAPABILITY1_AES128) {
+               for (i = ARRAY_SIZE(dcp_aes_algs); i >= 0; i--)
+                       crypto_unregister_alg(&dcp_aes_algs[i]);
+       }
+
+       mutex_lock(&global_mutex);
+       global_sdcp = NULL;
+       mutex_unlock(&global_mutex);

The order of the resources removal does not look correct here.

It should match the order of the error path in probe.

drivers/crypto/mxs-dcp.c line 1062

Quoted 6 lines
drivers/crypto/mxs-dcp.c new file +6 -0
+
+       return 0;
+}
+
+static const struct of_device_id mxs_dcp_dt_ids[] = {
+       {.compatible = "fsl,mxs-dcp", .data = NULL,},

In the other mxs/imx drivers we use:

.compatible = "fsl,<soc>-dcp"

You also need to provide a devicetree documentation for this binding.

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+       { /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, mxs_dcp_dt_ids);
+
+static struct platform_driver mxs_dcp_driver = {
+       .probe  = mxs_dcp_probe,
+       .remove = mxs_dcp_remove,
+       .driver = {
+               .name           = "mxs-dcp",

drivers/crypto/mxs-dcp.c line 1082

Quoted 10 lines
drivers/crypto/mxs-dcp.c new file +10 -0
+               .owner          = THIS_MODULE,
+               .of_match_table = mxs_dcp_dt_ids,
+       },
+};
+
+module_platform_driver(mxs_dcp_driver);
+
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale MXS DCP Driver");
+MODULE_LICENSE("GPL");

Could also add MODULE_ALIAS.

#20 lore raw

PATCH 2/3 ARM: mxs: crypto: Add Freescale MXS DCP driver

Dear Fabio Estevam,

[...]

Quoted 4 lines
Quoted 2 lines

+ * There can even be only one instance of the MXS DCP due to the
+ * design of Linux Crypto API.

Is this true? Usually we don't want to create a global struct.

Yeah, unfortunatelly :-(

Quoted 7 lines

drivers/crypto/mxs-dcp.c line 740

Quoted 5 lines
drivers/crypto/mxs-dcp.c new file +4 -0
+
+/* AES 128 ECB and AES 128 CBC */
+static struct crypto_alg dcp_aes_algs[] = {
+       [0] = {

No need for explicitely add this [0]

I wanted to be explicit here, but OK.

[...]

Rest is fixed, thanks!

Best regards,
Marek Vasut

#21 lore raw

PATCH 3/3 ARM: mxs: dts: Enable DCP for MXS

In reply to Marek Vasut

Enable the DCP by default on both i.MX23 and i.MX28.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Shawn Guo <[email protected]>

To: linux-crypto at vger.kernel.org

---
 arch/arm/boot/dts/imx23.dtsi | 4 +++-
 arch/arm/boot/dts/imx28.dtsi | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/boot/dts/imx23.dtsi +3 -1
index 87faa6e..0630a9a 100644
@@ -337,8 +337,10 @@
 			};
 
 			dcp at 80028000 {
+				compatible = "fsl,mxs-dcp";
 				reg = <0x80028000 0x2000>;
-				status = "disabled";
+				interrupts = <53 54>;
+				status = "okay";
 			};
 
 			pxp at 8002a000 {
arch/arm/boot/dts/imx28.dtsi +3 -2
index 918d419..8b5ad60 100644
@@ -782,9 +782,10 @@
 			};
 
 			dcp: dcp at 80028000 {
+				compatible = "fsl,mxs-dcp";
 				reg = <0x80028000 0x2000>;
-				interrupts = <52 53 54>;
-				compatible = "fsl-dcp";
+				interrupts = <53 54>;
+				status = "okay";
 			};
 
 			pxp: pxp at 8002a000 {
Signature · 1 line
1.8.4.rc3
#22 lore raw

PATCH 3/3 ARM: mxs: dts: Enable DCP for MXS

Hi,

Quoted 18 lines · Marek Vasut

Enable the DCP by default on both i.MX23 and i.MX28.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Shawn Guo <[email protected]>

To: linux-crypto at vger.kernel.org

---
 arch/arm/boot/dts/imx23.dtsi | 4 +++-
 arch/arm/boot/dts/imx28.dtsi | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/boot/dts/imx23.dtsi +0 -0
index 87faa6e..0630a9a 100644

arch/arm/boot/dts/imx23.dtsi line 344

Quoted 9 lines
arch/arm/boot/dts/imx23.dtsi +3 -1
@@ -337,8 +337,10 @@
 			};
 
 			dcp at 80028000 {
+				compatible = "fsl,mxs-dcp";
 				reg = <0x80028000 0x2000>;
-				status = "disabled";
+				interrupts = <53 54>;
+				status = "okay";
 			};

AFAICT the policy seems to be that nodes, that are always enabled don't get a 'status' property at all.

Quoted 6 lines
arch/arm/boot/dts/imx23.dtsi +0 -0
 			pxp at 8002a000 {
arch/arm/boot/dts/imx28.dtsi +0 -0
index 918d419..8b5ad60 100644

arch/arm/boot/dts/imx28.dtsi line 787

Quoted 8 lines
arch/arm/boot/dts/imx28.dtsi +1 -2
@@ -782,9 +782,10 @@
 			};
 
 			dcp: dcp at 80028000 {
+				compatible = "fsl,mxs-dcp";
 				reg = <0x80028000 0x2000>;
-				interrupts = <52 53 54>;
-				compatible = "fsl-dcp";
 

What about drivers/crypto/dcp.c that is currently using this property?

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#23 lore raw

PATCH 3/3 ARM: mxs: dts: Enable DCP for MXS

Dear Lothar Wa?mann,

Quoted 31 lines

Hi,

Quoted 28 lines · Marek Vasut

Enable the DCP by default on both i.MX23 and i.MX28.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Shawn Guo <[email protected]>

To: linux-crypto at vger.kernel.org
---

 arch/arm/boot/dts/imx23.dtsi | 4 +++-
 arch/arm/boot/dts/imx28.dtsi | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/boot/dts/imx23.dtsi +1 -0
index 87faa6e..0630a9a 100644
@@ -337,8 +337,10 @@
 
 			};
 
 			dcp at 80028000 {
 
+				compatible = "fsl,mxs-dcp";
 
 				reg = <0x80028000 0x2000>;
 
Quoted 8 lines

arch/arm/boot/dts/imx23.dtsi

Quoted 5 lines
arch/arm/boot/dts/imx23.dtsi +2 -1
-				status = "disabled";
+				interrupts = <53 54>;
+				status = "okay";
 
 			};

AFAICT the policy seems to be that nodes, that are always enabled don't get a 'status' property at all.

This is new to me, thanks for letting me know!

As for the current DCP, please see my reply to Fabio in this thread.

Best regards,
Marek Vasut

#24 lore raw

PATCH 3/3 ARM: mxs: dts: Enable DCP for MXS

In reply to Lothar Waßmann

Dear Lothar Wa?mann,

Quoted 31 lines

Hi,

Quoted 28 lines · Marek Vasut

Enable the DCP by default on both i.MX23 and i.MX28.

Cc Herbert Xu <[email protected]>
Cc David S. Miller <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Shawn Guo <[email protected]>

To: linux-crypto at vger.kernel.org
---

 arch/arm/boot/dts/imx23.dtsi | 4 +++-
 arch/arm/boot/dts/imx28.dtsi | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/boot/dts/imx23.dtsi +1 -0
index 87faa6e..0630a9a 100644
@@ -337,8 +337,10 @@
 
 			};
 
 			dcp at 80028000 {
 
+				compatible = "fsl,mxs-dcp";
 
 				reg = <0x80028000 0x2000>;
 
Quoted 8 lines

arch/arm/boot/dts/imx23.dtsi

Quoted 5 lines
arch/arm/boot/dts/imx23.dtsi +2 -1
-				status = "disabled";
+				interrupts = <53 54>;
+				status = "okay";
 
 			};

AFAICT the policy seems to be that nodes, that are always enabled don't get a 'status' property at all.

Is this documented somewhere ?

Best regards,
Marek Vasut