summaryrefslogtreecommitdiff
path: root/drivers/crypto/caam
AgeCommit message (Collapse)Author
2012-09-03ENGR00215875-2: caam: fix descriptor buffer overrun in hash_digest_key()Steve Cornelius
HMAC keys often need to be reduced to under the size of a digest to be used. The driver does this psuedo-synchronously through the use of hash_digest_key(), which builds a sequence pointered job descriptor to perform this function. When this function built the job descriptor, it correctly accounted for the number of instructions and number of pointers that would go into its construction. However, it failed to account for the fact that both the sequence in and out pointers used extended lengths, adding 8 more bytes to the required job descriptor. This caused the descriptor to overrun the allocated buffer by that amount, resulting in memory corruptions. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-09-03ENGR00215875-1: caam: improve initalization for context state savesSteve Cornelius
Multiple function in asynchronous hashing use a saved-state block, a.k.a. struct caam_hash_state, which holds a stash of information between requests (init/update/final). Certain values in this state block are loaded for processing using an inline-if, and when this is done, the potential for uninitialized data can pose conflicts. Therefore, this patch improves initialization of state data to prevent false assignments using uninitialized data in the state block. This patch addresses the following traceback, originating in ahash_final_ctx(), although a problem like this could certainly exhibit other symptoms: kernel BUG at arch/arm/mm/dma-mapping.c:465! Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = 80004000 [00000000] *pgd=00000000 Internal error: Oops: 805 [#1] PREEMPT SMP Modules linked in: CPU: 0 Not tainted (3.0.15-01752-gdd441b9-dirty #40) PC is at __bug+0x1c/0x28 LR is at __bug+0x18/0x28 pc : [<80043240>] lr : [<8004323c>] psr: 60000013 sp : e423fd98 ip : 60000013 fp : 0000001c r10: e4191b84 r9 : 00000020 r8 : 00000009 r7 : 88005038 r6 : 00000001 r5 : 2d676572 r4 : e4191a60 r3 : 00000000 r2 : 00000001 r1 : 60000093 r0 : 00000033 Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel Control: 10c53c7d Table: 1000404a DAC: 00000015 Process cryptomgr_test (pid: 1306, stack limit = 0xe423e2f0) Stack: (0xe423fd98 to 0xe4240000) fd80: 11807fd1 80048544 fda0: 88005000 e4191a00 e5178040 8039dda0 00000000 00000014 2d676572 e4191008 fdc0: 88005018 e4191a60 00100100 e4191a00 00000000 8039ce0c e423fea8 00000007 fde0: e4191a00 e4227000 e5178000 8039ce18 e419183c 80203808 80a94a44 00000006 fe00: 00000000 80207180 00000000 00000006 e423ff08 00000000 00000007 e5178000 fe20: e41918a4 80a949b4 8c4844e2 00000000 00000049 74227000 8c4844e2 00000e90 fe40: 0000000e 74227e90 ffff8c58 80ac29e0 e423fed4 8006a350 8c81625c e423ff5c fe60: 00008576 e4002500 00000003 00030010 e4002500 00000003 e5180000 e4002500 fe80: e5178000 800e6d24 007fffff 00000000 00000010 e4001280 e4002500 60000013 fea0: 000000d0 804df078 00000000 00000000 00000000 00000000 00000000 00000000 fec0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 fee0: 00000000 00000000 e4227000 e4226000 e4753000 e4752000 e40a5000 e40a4000 ff00: e41e7000 e41e6000 00000000 00000000 00000000 e423ff14 e423ff14 00000000 ff20: 00000400 804f9080 e5178000 e4db0b40 00000000 e4db0b80 0000047c 00000400 ff40: 00000000 8020758c 00000400 ffffffff 0000008a 00000000 e4db0b40 80206e00 ff60: e4049dbc 00000000 00000000 00000003 e423ffa4 80062978 e41a8bfc 00000000 ff80: 00000000 e4049db4 00000013 e4049db0 00000013 00000000 00000000 00000000 ffa0: e4db0b40 e4db0b40 80204cbc 00000013 00000000 00000000 00000000 80204cfc ffc0: e4049da0 80089544 80040a40 00000000 e4db0b40 00000000 00000000 00000000 ffe0: e423ffe0 e423ffe0 e4049da0 800894c4 80040a40 80040a40 00000000 00000000 [<80043240>] (__bug+0x1c/0x28) from [<80048544>] (___dma_single_dev_to_cpu+0x84) [<80048544>] (___dma_single_dev_to_cpu+0x84/0x94) from [<8039dda0>] (ahash_fina) [<8039dda0>] (ahash_final_ctx+0x180/0x428) from [<8039ce18>] (ahash_final+0xc/0) [<8039ce18>] (ahash_final+0xc/0x10) from [<80203808>] (crypto_ahash_op+0x28/0xc) [<80203808>] (crypto_ahash_op+0x28/0xc0) from [<80207180>] (test_hash+0x214/0x5) [<80207180>] (test_hash+0x214/0x5b8) from [<8020758c>] (alg_test_hash+0x68/0x8c) [<8020758c>] (alg_test_hash+0x68/0x8c) from [<80206e00>] (alg_test+0x7c/0x1b8) [<80206e00>] (alg_test+0x7c/0x1b8) from [<80204cfc>] (cryptomgr_test+0x40/0x48) [<80204cfc>] (cryptomgr_test+0x40/0x48) from [<80089544>] (kthread+0x80/0x88) [<80089544>] (kthread+0x80/0x88) from [<80040a40>] (kernel_thread_exit+0x0/0x8) Code: e59f0010 e1a01003 eb126a8d e3a03000 (e5833000) ---[ end trace d52a403a1d1eaa86 ]--- Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-08-12ENGR00216259 caam: improve RNG4 initialization processSteve Cornelius
Early versions of this driver used a set of entropy generation parameters inherited from QorIQ devices. Those parameters were a hardcoded set based upon internally-suggested values, and worked well on QorIQ. However, for certain mx6 devices, oscillator values were found to be exceeding the upper limit, and so RNG instantiation was failing in those cases. This code improves initialization by (a) making sure the oscillator divider is set to a known value, and (b) converting the parameter selection to a symbolic compiler-generated form, instead of using embedded magic number constants. The calculation is now based on the definition of RNG4_ENT_CLOCKS_SAMPLE, which defaults to 1600 unless overridden by something. The lower limit is then set as /4, and the upper limit set to *8. Tested-by: Minnick Michael-B21710 <b21710@freescale.com> Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Jason Liu <r64343@freescale.com>
2012-08-06ENGR00219164: caam: limit AXI pipeline depth = 1 on mx6 for errataSteve Cornelius
This patch limits AXI pipeline depth to 1 as a workaround for errta TKT134813, the write concurrency problem on mx6. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-25ENGR00215945-3: caam: Improve error recovery on failed RNG4 kickstartSteve Cornelius
RNG4 requires a kickstart process to transition into running mode. In the case that this kickstart process errors, the driver is shut back down (under the assumption that internal random padding of keys or data cannot occur). In an isolated case, the kickstart failed to start the RNG, an error was returned, and the driver attempted to de-register an RNG function that never completed, causing a crash. (This is difficult to test for without manual intervention). Therefore, amended the driver shutdown process to only de-register the hardware RNG when an instance kickstarted without error. This does NOT correct the kickstart problem, only the consequences. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-25ENGR00215945-2: Fix directions in cache coherence functionsSteve Cornelius
During a bug search, a review turned up two places where the wrong direction was used in dma_sync function calls. In practice. these compiled away to be inconsequential on the platform in question, but this may not be true on all platforms. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-25ENGR00215945-1: Rework scatterlist handling for bi-endian platformsSteve Cornelius
Former versions of this (ARM) branch of this driver reworked the hardware- readable scatter/gather list to operate as a set of 32-bit integers, rather than a packed structure of smaller sizes, which cannot burst-read correctly on a little-endian platform. Integration of caamhash.c revealed subtle ways in which the ordering of items written to a hardware s/g list could create bugs, such as the "final" bit being written to an entry that would later be updated with a size, inadvertently erasing the bit (e.g. such as sg_to_sec4_sg_last() before sg_to_sec4_sg()). Since fields must be ORed in to operate correctly using any order of operations, changed allocations of the combination of extended descriptor structs + hardware scatterlists to use kzalloc() instead of kmalloc(), so as to ensure that residue data would not be ORed in with the correct data. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215492-3: Detect HW features during alg registrationSteve Cornelius
i.MX6 instantiates a CAAM with a low-power MDHA block, which does not compute digests larger than 256 bits. Since the driver installs handlers for hashes longer than 256 bits in several places, added the ability to read and interpret the CHA version and instantiations registers, and then only register handlers that it can support. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215492-2: Add SGT error to formerly reserved entrySteve Cornelius
Add SGT error to formerly reserved entry. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215492-1: Fix DMA size in extended descriptor for ahash_digest()Steve Cornelius
Save of DMA size in extended descriptor was missing, thus crashes could occur during post-request unmapping. Also, removed lingering DEBUG def that shouldn't have been there. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215228-16: Add API module for asynchronous hashingSteve Cornelius
Add API module for asynchronous hashing Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215228-15: Add API module for /dev/hw_randomSteve Cornelius
Add API module for /dev/hw_random Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215228-14: Add in RNG4 kickstart functionSteve Cornelius
Add in RNG4 kickstart function Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-13: Add cache coherence to externalized key generationSteve Cornelius
Add cache coherence to externalized key generation Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-12: Move scatter/gather cache coherence into chained function.Steve Cornelius
Last driver revisions began to incorporate optimized mapping functions for scatter/gather list management, and then centralized them as inlinable functions usable from multiple modules. Since these became more globally useful, moved the coupled cache-coherence functions out of the mainline code and into the inlined ones for simplification. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-11: Enable ahash and rng configurationsSteve Cornelius
Add in ahash and rng options for build. Note that because of the way platform devices detect (as opposed to of-based detection), modularization of API interfaces is suppressed. Once CONFIG_OF is possible, this can go away. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-10: Descriptor optimizations, misc whitespace fixes.Steve Cornelius
Descriptor optimizations, misc whitespace fixes. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215228-9: Add hash and RNG initializers for non-OF buildsSteve Cornelius
Inserted explicit initializers for split-out startup and shutdown functions needed for kernels using platform devices in place of OF-device-tree initialization and detection. Also added necessary ahash algorithm list head to driver private storage block. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-8: Add pointer length extensions, non-error-propgation definition.Steve Cornelius
Add pointer length extensions, non-error-propgation definition. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-7: Externalize SG lists plus split-key generationSteve Cornelius
Split out inline scatter-gather list handlers into an external header, and moved key generation into standalone source. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00215228-6: Externalize scatter-gather handling for multiple API modules.Steve Cornelius
Moved scatter-gather list management outside of single API module in anticipation of multiple API modules which may be switch selectable. This includes a number of list management optimizations, as well as some aead descriptor optimizations. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-5: Add <md5.h> inclusion for expanded aead processing.Steve Cornelius
Add <md5.h> inclusion for expanded aead processing. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-4: Synchronize scatter/gather table definitions with QorIQ defsSteve Cornelius
Update scatter/gather definitions to more closely correspond with those in the QorIQ 1.2 release tree. Note that the definition of the CAAM-local scatter-gather table for QorIQ/Power-based devices assumed big-endian, and therefore does not burst-read properly into an ARM-based little-endian instantiation. Therefore, applied close-as-practical definitions to at least get close until a merge can be accomplished. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-3: Merge in RNGB changesSteve Cornelius
Added in register changes to enable RNGB initialization when it is present. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-2: Add era4 amendments and whitespace fixesSteve Cornelius
Added in era4 additions, and merged in whitespace fixes so as to be closed to QorIQ 1.2 staged-for-release code base. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00215228-1: Remove unused DECO base pointerSteve Cornelius
Remove unused DECO base pointer to be consistent with staged-for-1.2 QorIQ release. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00212512: Fix caam build error when being built as moduleTerry Lv
Fix caam build error when being built as module. Signed-off-by: Terry Lv <r65388@freescale.com>
2012-07-20ENGR00180943-14: Update internal definition of hardware link table listSteve Cornelius
Update internal definition of hardware link table list such that it can work properly on both big and little endian 32-bit configurations. This required pointer resizing, reserved-field initialization, and the combination of both buffer-pool ID and offset fields into a common 32-bit value that can burst-read correctly. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-13: Extend for ARM/iMX6 compatibilitySteve Cornelius
Extend for ARM/iMX6 compatibility, including: - Cache coherence for all streaming buffer mappings - Initialization from non-OF-dependent lower-level drivers Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-12: Extend to include support for ARM targets on iMX6 platformsSteve Cornelius
Extend to include support for ARM targets on iMX6 platforms, including: - platform property detection when OF device properties unavailable - ring entry direction clarification for DMA API access - cache coherence for rings Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-11: Add non-device-tree platform property detectionSteve Cornelius
Add non-device-tree platform property detection for driver startup and initialization for iMX6 family, including clock control, job ring detection and initialization, and interrupt mapping. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-10: Add register I/O primitives for ARM compatibilitySteve Cornelius
Add register I/O primitives for ARM compatibility. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-9: Include referenced for clock controlSteve Cornelius
Include referenced for clock control, and define "empty" IRQ function that's not provided on ARM platforms. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-8: Differentiate inclusions for OF versus non-OF platformsSteve Cornelius
Differentiate inclusions for OF versus non-OF platforms, and include clock control subsystems for ARM targets. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-2: Enable MXC devices to select CAAM driver in KconfigSteve Cornelius
Enable MXC devices to select CAAM driver in Kconfig. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
2012-07-20ENGR00180943-1: Backport in current 3.2 code tested on Power for ARMSteve Cornelius
Backport in current 3.2 code tested on Power for ARM redevelopment. Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com> Signed-off-by: Terry Lv <r65388@freescale.com>
2011-06-30crypto: caam - fix operator precedence in shared descriptor allocationKim Phillips
setkey allocates 16 bytes (CAAM_CMD_SZ * DESC_AEAD_SHARED_TEXT_LEN) shy of what is needed to store the shared descriptor, resulting in memory corruption. Fix this. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-19crypto: caam - add support for sha512 variants of existing AEAD algorithmsKim Phillips
In doing so, sha512 sized keys would not fit with the current descriptor inlining mechanism, so we now calculate whether keys should be referenced instead by pointers in the shared descriptor. also, use symbols for descriptor text lengths, and, ahem, unmap and free key i/o memory in cra_exit. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-19crypto: caam - remove unused authkeylen from caam_ctxKim Phillips
Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-19crypto: caam - fix decryption shared vs. non-shared key settingKim Phillips
Key sharing is enabled by default in the shared descriptor. Using CBC decrypt, AES has to alter the key in order to decrypt. During high traffic decryption rates, i.e, when sharing starts to take place, we need to use a different OPERATION option to tell AES that the key was already altered by the PRIOR descriptor - we need the following kind of logic: if ( shared ) operation where AES uses decryption key (DK=1) else operation where AES uses encryption key (DK=0) this patch implements this logic using a conditional and a non-conditional local jump within the decryption job descriptor. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-19crypto: caam - platform_bus_type migrationKim Phillips
this fixes a build error since cryptodev-2.6 got rebased to include commit d714d1979d7b4df7e2c127407f4014ce71f73cd0 "dt: eliminate of_platform_driver shim code". Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-04crypto: caam - fix printk recursion for long error textsKim Phillips
during recent descriptor development, an Invalid Sequence Command error triggered a: BUG: recent printk recursion! due to insufficient memory allocated for the error text. The Invalid Sequence Command error text is the longest. The length of the maximum error string is computed as the sum of: "DECO: ": 6 "jump tgt desc idx 255: ": 23 Invalid Sequence Command text: 272 zero termination character: 1 i.e, 302 characters. Define this maximum error string length in error.h and fix caam_jr_strstatus callsites. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-04crypto: caam - remove unused keylen from session contextKim Phillips
Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-03crypto: caam - remove duplicate dev_errKim Phillips
keep the hex error value reporting version (a) to be consistent with decrypt_done(), and (b) to keep our hardware guys happy. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-03crypto: caam - remove WAIT-FOR-COMPLETIONs from givencrypt descriptorKim Phillips
remains from descriptor debugging - not required for normal operation. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-03crypto: caam - fix queue interface detectionKim Phillips
The presence of a h/w Queue Interface would fail due to this cut-n-paste snafu. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-05-03crypto: caam - handle interrupt lines shared across ringsKim Phillips
- add IRQF_SHARED to request_irq flags to support parts such as the p1023 that has one IRQ line per couple of rings. - resetting a job ring triggers an interrupt, so move request_irq prior to jr_reset to avoid 'got IRQ but nobody cared' messages. - disable IRQs in h/w to avoid contention between reset and interrupt status - delete invalid comment - if there were incomplete jobs, module would be in use, preventing an unload. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-04-08crypto: caam - introduce missing kfreeJulia Lawall
Error handling code following a kmalloc should free the allocated data. The semantic match that finds the problem is as follows: (http://www.emn.fr/x-info/coccinelle/) // <smpl> @r exists@ local idexpression x; statement S; expression E; identifier f,f1,l; position p1,p2; expression *ptr != NULL; @@ x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...); ... if (x == NULL) S <... when != x when != if (...) { <+...x...+> } ( x->f1 = E | (x->f1 == NULL || ...) | f(...,x->f1,...) ) ...> ( return \(0\|<+...x...+>\|ptr\); | return@p2 ...; ) @script:python@ p1 << r.p1; p2 << r.p2; @@ print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line) // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Acked-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-03-27crypto: caam - ARRAY_SIZE() vs sizeof()Dan Carpenter
ARRAY_SIZE() was intended here instead of sizeof(). sizeof() is four times larger than ARRAY_SIZE(). outstr is normally 256 chars so printing garbage to it could overfill the buffer and corrupt memory. Signed-off-by: Dan Carpenter <error27@gmail.com> Acked-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2011-03-27crypto: caam - dereferencing ERR_PTR on allocation failureDan Carpenter
t_alg is an ERR_PTR here so we can't dereference it. Signed-off-by: Dan Carpenter <error27@gmail.com> Acked-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>