Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Pull crypto updates from Herbert Xu:
"API:
- Add speed testing on 1420-byte blocks for networking

Algorithms:
- Improve performance of chacha on ARM for network packets
- Improve performance of aegis128 on ARM for network packets

Drivers:
- Add support for Keem Bay OCS AES/SM4
- Add support for QAT 4xxx devices
- Enable crypto-engine retry mechanism in caam
- Enable support for crypto engine on sdm845 in qce
- Add HiSilicon PRNG driver support"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (161 commits)
crypto: qat - add capability detection logic in qat_4xxx
crypto: qat - add AES-XTS support for QAT GEN4 devices
crypto: qat - add AES-CTR support for QAT GEN4 devices
crypto: atmel-i2c - select CONFIG_BITREVERSE
crypto: hisilicon/trng - replace atomic_add_return()
crypto: keembay - Add support for Keem Bay OCS AES/SM4
dt-bindings: Add Keem Bay OCS AES bindings
crypto: aegis128 - avoid spurious references crypto_aegis128_update_simd
crypto: seed - remove trailing semicolon in macro definition
crypto: x86/poly1305 - Use TEST %reg,%reg instead of CMP $0,%reg
crypto: x86/sha512 - Use TEST %reg,%reg instead of CMP $0,%reg
crypto: aesni - Use TEST %reg,%reg instead of CMP $0,%reg
crypto: cpt - Fix sparse warnings in cptpf
hwrng: ks-sa - Add dependency on IOMEM and OF
crypto: lib/blake2s - Move selftest prototype into header file
crypto: arm/aes-ce - work around Cortex-A57/A72 silion errata
crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()
crypto: ccree - rework cache parameters handling
crypto: cavium - Use dma_set_mask_and_coherent to simplify code
crypto: marvell/octeontx - Use dma_set_mask_and_coherent to simplify code
...

+8433 -1998
+45
Documentation/devicetree/bindings/crypto/intel,keembay-ocs-aes.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/crypto/intel,keembay-ocs-aes.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Intel Keem Bay OCS AES Device Tree Bindings 8 + 9 + maintainers: 10 + - Daniele Alessandrelli <daniele.alessandrelli@intel.com> 11 + 12 + description: 13 + The Intel Keem Bay Offload and Crypto Subsystem (OCS) AES engine provides 14 + hardware-accelerated AES/SM4 encryption/decryption. 15 + 16 + properties: 17 + compatible: 18 + const: intel,keembay-ocs-aes 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + interrupts: 24 + maxItems: 1 25 + 26 + clocks: 27 + maxItems: 1 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - interrupts 33 + - clocks 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/arm-gic.h> 40 + crypto@30008000 { 41 + compatible = "intel,keembay-ocs-aes"; 42 + reg = <0x30008000 0x1000>; 43 + interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>; 44 + clocks = <&scmi_clk 95>; 45 + };
+12 -2
MAINTAINERS
··· 8016 8016 HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT 8017 8017 M: Zaibo Xu <xuzaibo@huawei.com> 8018 8018 S: Maintained 8019 - F: drivers/char/hw_random/hisi-trng-v2.c 8019 + F: drivers/crypto/hisilicon/trng/trng.c 8020 8020 8021 8021 HISILICON V3XX SPI NOR FLASH Controller Driver 8022 8022 M: John Garry <john.garry@huawei.com> ··· 8975 8975 S: Maintained 8976 8976 F: drivers/char/hw_random/ixp4xx-rng.c 8977 8977 8978 - INTEL KEEMBAY DRM DRIVER 8978 + INTEL KEEM BAY DRM DRIVER 8979 8979 M: Anitha Chrisanthus <anitha.chrisanthus@intel.com> 8980 8980 M: Edmund Dea <edmund.j.dea@intel.com> 8981 8981 S: Maintained 8982 8982 F: Documentation/devicetree/bindings/display/intel,kmb_display.yaml 8983 8983 F: drivers/gpu/drm/kmb/ 8984 + 8985 + INTEL KEEM BAY OCS AES/SM4 CRYPTO DRIVER 8986 + M: Daniele Alessandrelli <daniele.alessandrelli@intel.com> 8987 + S: Maintained 8988 + F: Documentation/devicetree/bindings/crypto/intel,keembay-ocs-aes.yaml 8989 + F: drivers/crypto/keembay/Kconfig 8990 + F: drivers/crypto/keembay/Makefile 8991 + F: drivers/crypto/keembay/keembay-ocs-aes-core.c 8992 + F: drivers/crypto/keembay/ocs-aes.c 8993 + F: drivers/crypto/keembay/ocs-aes.h 8984 8994 8985 8995 INTEL MANAGEMENT ENGINE (mei) 8986 8996 M: Tomas Winkler <tomas.winkler@intel.com>
+22 -10
arch/arm/crypto/aes-ce-core.S
··· 386 386 .Lctrloop4x: 387 387 subs r4, r4, #4 388 388 bmi .Lctr1x 389 - add r6, r6, #1 389 + 390 + /* 391 + * NOTE: the sequence below has been carefully tweaked to avoid 392 + * a silicon erratum that exists in Cortex-A57 (#1742098) and 393 + * Cortex-A72 (#1655431) cores, where AESE/AESMC instruction pairs 394 + * may produce an incorrect result if they take their input from a 395 + * register of which a single 32-bit lane has been updated the last 396 + * time it was modified. To work around this, the lanes of registers 397 + * q0-q3 below are not manipulated individually, and the different 398 + * counter values are prepared by successive manipulations of q7. 399 + */ 400 + add ip, r6, #1 390 401 vmov q0, q7 402 + rev ip, ip 403 + add lr, r6, #2 404 + vmov s31, ip @ set lane 3 of q1 via q7 405 + add ip, r6, #3 406 + rev lr, lr 391 407 vmov q1, q7 392 - rev ip, r6 393 - add r6, r6, #1 408 + vmov s31, lr @ set lane 3 of q2 via q7 409 + rev ip, ip 394 410 vmov q2, q7 395 - vmov s7, ip 396 - rev ip, r6 397 - add r6, r6, #1 411 + vmov s31, ip @ set lane 3 of q3 via q7 412 + add r6, r6, #4 398 413 vmov q3, q7 399 - vmov s11, ip 400 - rev ip, r6 401 - add r6, r6, #1 402 - vmov s15, ip 414 + 403 415 vld1.8 {q4-q5}, [r1]! 404 416 vld1.8 {q6}, [r1]! 405 417 vld1.8 {q15}, [r1]!
+5 -3
arch/arm/crypto/aes-neonbs-glue.c
··· 19 19 MODULE_LICENSE("GPL v2"); 20 20 21 21 MODULE_ALIAS_CRYPTO("ecb(aes)"); 22 - MODULE_ALIAS_CRYPTO("cbc(aes)"); 22 + MODULE_ALIAS_CRYPTO("cbc(aes)-all"); 23 23 MODULE_ALIAS_CRYPTO("ctr(aes)"); 24 24 MODULE_ALIAS_CRYPTO("xts(aes)"); 25 25 ··· 191 191 struct aesbs_cbc_ctx *ctx = crypto_skcipher_ctx(tfm); 192 192 unsigned int reqsize; 193 193 194 - ctx->enc_tfm = crypto_alloc_skcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC); 194 + ctx->enc_tfm = crypto_alloc_skcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC | 195 + CRYPTO_ALG_NEED_FALLBACK); 195 196 if (IS_ERR(ctx->enc_tfm)) 196 197 return PTR_ERR(ctx->enc_tfm); 197 198 ··· 442 441 .base.cra_blocksize = AES_BLOCK_SIZE, 443 442 .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctx), 444 443 .base.cra_module = THIS_MODULE, 445 - .base.cra_flags = CRYPTO_ALG_INTERNAL, 444 + .base.cra_flags = CRYPTO_ALG_INTERNAL | 445 + CRYPTO_ALG_NEED_FALLBACK, 446 446 447 447 .min_keysize = AES_MIN_KEY_SIZE, 448 448 .max_keysize = AES_MAX_KEY_SIZE,
+17 -17
arch/arm/crypto/chacha-glue.c
··· 23 23 asmlinkage void chacha_block_xor_neon(const u32 *state, u8 *dst, const u8 *src, 24 24 int nrounds); 25 25 asmlinkage void chacha_4block_xor_neon(const u32 *state, u8 *dst, const u8 *src, 26 - int nrounds); 26 + int nrounds, unsigned int nbytes); 27 27 asmlinkage void hchacha_block_arm(const u32 *state, u32 *out, int nrounds); 28 28 asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds); 29 29 ··· 42 42 { 43 43 u8 buf[CHACHA_BLOCK_SIZE]; 44 44 45 - while (bytes >= CHACHA_BLOCK_SIZE * 4) { 46 - chacha_4block_xor_neon(state, dst, src, nrounds); 47 - bytes -= CHACHA_BLOCK_SIZE * 4; 48 - src += CHACHA_BLOCK_SIZE * 4; 49 - dst += CHACHA_BLOCK_SIZE * 4; 50 - state[12] += 4; 51 - } 52 - while (bytes >= CHACHA_BLOCK_SIZE) { 53 - chacha_block_xor_neon(state, dst, src, nrounds); 54 - bytes -= CHACHA_BLOCK_SIZE; 55 - src += CHACHA_BLOCK_SIZE; 56 - dst += CHACHA_BLOCK_SIZE; 57 - state[12]++; 45 + while (bytes > CHACHA_BLOCK_SIZE) { 46 + unsigned int l = min(bytes, CHACHA_BLOCK_SIZE * 4U); 47 + 48 + chacha_4block_xor_neon(state, dst, src, nrounds, l); 49 + bytes -= l; 50 + src += l; 51 + dst += l; 52 + state[12] += DIV_ROUND_UP(l, CHACHA_BLOCK_SIZE); 58 53 } 59 54 if (bytes) { 60 - memcpy(buf, src, bytes); 61 - chacha_block_xor_neon(state, buf, buf, nrounds); 62 - memcpy(dst, buf, bytes); 55 + const u8 *s = src; 56 + u8 *d = dst; 57 + 58 + if (bytes != CHACHA_BLOCK_SIZE) 59 + s = d = memcpy(buf, src, bytes); 60 + chacha_block_xor_neon(state, d, s, nrounds); 61 + if (d != dst) 62 + memcpy(dst, buf, bytes); 63 63 } 64 64 } 65 65
+90 -7
arch/arm/crypto/chacha-neon-core.S
··· 47 47 */ 48 48 49 49 #include <linux/linkage.h> 50 + #include <asm/cache.h> 50 51 51 52 .text 52 53 .fpu neon ··· 206 205 207 206 .align 5 208 207 ENTRY(chacha_4block_xor_neon) 209 - push {r4-r5} 208 + push {r4, lr} 210 209 mov r4, sp // preserve the stack pointer 211 210 sub ip, sp, #0x20 // allocate a 32 byte buffer 212 211 bic ip, ip, #0x1f // aligned to 32 bytes ··· 230 229 vld1.32 {q0-q1}, [r0] 231 230 vld1.32 {q2-q3}, [ip] 232 231 233 - adr r5, .Lctrinc 232 + adr lr, .Lctrinc 234 233 vdup.32 q15, d7[1] 235 234 vdup.32 q14, d7[0] 236 - vld1.32 {q4}, [r5, :128] 235 + vld1.32 {q4}, [lr, :128] 237 236 vdup.32 q13, d6[1] 238 237 vdup.32 q12, d6[0] 239 238 vdup.32 q11, d5[1] ··· 456 455 457 456 // Re-interleave the words in the first two rows of each block (x0..7). 458 457 // Also add the counter values 0-3 to x12[0-3]. 459 - vld1.32 {q8}, [r5, :128] // load counter values 0-3 458 + vld1.32 {q8}, [lr, :128] // load counter values 0-3 460 459 vzip.32 q0, q1 // => (0 1 0 1) (0 1 0 1) 461 460 vzip.32 q2, q3 // => (2 3 2 3) (2 3 2 3) 462 461 vzip.32 q4, q5 // => (4 5 4 5) (4 5 4 5) ··· 494 493 495 494 // Re-interleave the words in the last two rows of each block (x8..15). 496 495 vld1.32 {q8-q9}, [sp, :256] 496 + mov sp, r4 // restore original stack pointer 497 + ldr r4, [r4, #8] // load number of bytes 497 498 vzip.32 q12, q13 // => (12 13 12 13) (12 13 12 13) 498 499 vzip.32 q14, q15 // => (14 15 14 15) (14 15 14 15) 499 500 vzip.32 q8, q9 // => (8 9 8 9) (8 9 8 9) ··· 523 520 // XOR the rest of the data with the keystream 524 521 525 522 vld1.8 {q0-q1}, [r2]! 523 + subs r4, r4, #96 526 524 veor q0, q0, q8 527 525 veor q1, q1, q12 526 + ble .Lle96 528 527 vst1.8 {q0-q1}, [r1]! 529 528 530 529 vld1.8 {q0-q1}, [r2]! 530 + subs r4, r4, #32 531 531 veor q0, q0, q2 532 532 veor q1, q1, q6 533 + ble .Lle128 533 534 vst1.8 {q0-q1}, [r1]! 534 535 535 536 vld1.8 {q0-q1}, [r2]! 537 + subs r4, r4, #32 536 538 veor q0, q0, q10 537 539 veor q1, q1, q14 540 + ble .Lle160 538 541 vst1.8 {q0-q1}, [r1]! 539 542 540 543 vld1.8 {q0-q1}, [r2]! 544 + subs r4, r4, #32 541 545 veor q0, q0, q4 542 546 veor q1, q1, q5 547 + ble .Lle192 543 548 vst1.8 {q0-q1}, [r1]! 544 549 545 550 vld1.8 {q0-q1}, [r2]! 551 + subs r4, r4, #32 546 552 veor q0, q0, q9 547 553 veor q1, q1, q13 554 + ble .Lle224 548 555 vst1.8 {q0-q1}, [r1]! 549 556 550 557 vld1.8 {q0-q1}, [r2]! 558 + subs r4, r4, #32 551 559 veor q0, q0, q3 552 560 veor q1, q1, q7 561 + blt .Llt256 562 + .Lout: 553 563 vst1.8 {q0-q1}, [r1]! 554 564 555 565 vld1.8 {q0-q1}, [r2] 556 - mov sp, r4 // restore original stack pointer 557 566 veor q0, q0, q11 558 567 veor q1, q1, q15 559 568 vst1.8 {q0-q1}, [r1] 560 569 561 - pop {r4-r5} 562 - bx lr 570 + pop {r4, pc} 571 + 572 + .Lle192: 573 + vmov q4, q9 574 + vmov q5, q13 575 + 576 + .Lle160: 577 + // nothing to do 578 + 579 + .Lfinalblock: 580 + // Process the final block if processing less than 4 full blocks. 581 + // Entered with 32 bytes of ChaCha cipher stream in q4-q5, and the 582 + // previous 32 byte output block that still needs to be written at 583 + // [r1] in q0-q1. 584 + beq .Lfullblock 585 + 586 + .Lpartialblock: 587 + adr lr, .Lpermute + 32 588 + add r2, r2, r4 589 + add lr, lr, r4 590 + add r4, r4, r1 591 + 592 + vld1.8 {q2-q3}, [lr] 593 + vld1.8 {q6-q7}, [r2] 594 + 595 + add r4, r4, #32 596 + 597 + vtbl.8 d4, {q4-q5}, d4 598 + vtbl.8 d5, {q4-q5}, d5 599 + vtbl.8 d6, {q4-q5}, d6 600 + vtbl.8 d7, {q4-q5}, d7 601 + 602 + veor q6, q6, q2 603 + veor q7, q7, q3 604 + 605 + vst1.8 {q6-q7}, [r4] // overlapping stores 606 + vst1.8 {q0-q1}, [r1] 607 + pop {r4, pc} 608 + 609 + .Lfullblock: 610 + vmov q11, q4 611 + vmov q15, q5 612 + b .Lout 613 + .Lle96: 614 + vmov q4, q2 615 + vmov q5, q6 616 + b .Lfinalblock 617 + .Lle128: 618 + vmov q4, q10 619 + vmov q5, q14 620 + b .Lfinalblock 621 + .Lle224: 622 + vmov q4, q3 623 + vmov q5, q7 624 + b .Lfinalblock 625 + .Llt256: 626 + vmov q4, q11 627 + vmov q5, q15 628 + b .Lpartialblock 563 629 ENDPROC(chacha_4block_xor_neon) 630 + 631 + .align L1_CACHE_SHIFT 632 + .Lpermute: 633 + .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 634 + .byte 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 635 + .byte 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 636 + .byte 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f 637 + .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 638 + .byte 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 639 + .byte 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 640 + .byte 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
+1 -1
arch/arm/crypto/sha1-ce-glue.c
··· 7 7 8 8 #include <crypto/internal/hash.h> 9 9 #include <crypto/internal/simd.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha1.h> 11 11 #include <crypto/sha1_base.h> 12 12 #include <linux/cpufeature.h> 13 13 #include <linux/crypto.h>
+1 -1
arch/arm/crypto/sha1.h
··· 3 3 #define ASM_ARM_CRYPTO_SHA1_H 4 4 5 5 #include <linux/crypto.h> 6 - #include <crypto/sha.h> 6 + #include <crypto/sha1.h> 7 7 8 8 extern int sha1_update_arm(struct shash_desc *desc, const u8 *data, 9 9 unsigned int len);
+1 -1
arch/arm/crypto/sha1_glue.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/module.h> 17 17 #include <linux/types.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha1.h> 19 19 #include <crypto/sha1_base.h> 20 20 #include <asm/byteorder.h> 21 21
+1 -1
arch/arm/crypto/sha1_neon_glue.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/mm.h> 21 21 #include <linux/types.h> 22 - #include <crypto/sha.h> 22 + #include <crypto/sha1.h> 23 23 #include <crypto/sha1_base.h> 24 24 #include <asm/neon.h> 25 25 #include <asm/simd.h>
+1 -1
arch/arm/crypto/sha2-ce-glue.c
··· 7 7 8 8 #include <crypto/internal/hash.h> 9 9 #include <crypto/internal/simd.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha2.h> 11 11 #include <crypto/sha256_base.h> 12 12 #include <linux/cpufeature.h> 13 13 #include <linux/crypto.h>
+1 -1
arch/arm/crypto/sha256_glue.c
··· 17 17 #include <linux/mm.h> 18 18 #include <linux/types.h> 19 19 #include <linux/string.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha2.h> 21 21 #include <crypto/sha256_base.h> 22 22 #include <asm/simd.h> 23 23 #include <asm/neon.h>
+1 -1
arch/arm/crypto/sha256_neon_glue.c
··· 13 13 #include <crypto/internal/simd.h> 14 14 #include <linux/types.h> 15 15 #include <linux/string.h> 16 - #include <crypto/sha.h> 16 + #include <crypto/sha2.h> 17 17 #include <crypto/sha256_base.h> 18 18 #include <asm/byteorder.h> 19 19 #include <asm/simd.h>
+1 -1
arch/arm/crypto/sha512-glue.c
··· 6 6 */ 7 7 8 8 #include <crypto/internal/hash.h> 9 - #include <crypto/sha.h> 9 + #include <crypto/sha2.h> 10 10 #include <crypto/sha512_base.h> 11 11 #include <linux/crypto.h> 12 12 #include <linux/module.h>
+1 -1
arch/arm/crypto/sha512-neon-glue.c
··· 7 7 8 8 #include <crypto/internal/hash.h> 9 9 #include <crypto/internal/simd.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha2.h> 11 11 #include <crypto/sha512_base.h> 12 12 #include <linux/crypto.h> 13 13 #include <linux/module.h>
+1
arch/arm64/configs/defconfig
··· 1082 1082 CONFIG_CRYPTO_DEV_HISI_SEC2=m 1083 1083 CONFIG_CRYPTO_DEV_HISI_ZIP=m 1084 1084 CONFIG_CRYPTO_DEV_HISI_HPRE=m 1085 + CONFIG_CRYPTO_DEV_HISI_TRNG=m 1085 1086 CONFIG_CMA_SIZE_MBYTES=32 1086 1087 CONFIG_PRINTK_TIME=y 1087 1088 CONFIG_DEBUG_INFO=y
+1 -1
arch/arm64/crypto/aes-glue.c
··· 10 10 #include <asm/simd.h> 11 11 #include <crypto/aes.h> 12 12 #include <crypto/ctr.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 #include <crypto/internal/hash.h> 15 15 #include <crypto/internal/simd.h> 16 16 #include <crypto/internal/skcipher.h>
+72 -127
arch/arm64/crypto/chacha-neon-core.S
··· 195 195 adr_l x10, .Lpermute 196 196 and x5, x4, #63 197 197 add x10, x10, x5 198 - add x11, x10, #64 199 198 200 199 // 201 200 // This function encrypts four consecutive ChaCha blocks by loading ··· 644 645 zip2 v31.4s, v14.4s, v15.4s 645 646 eor a15, a15, w9 646 647 647 - mov x3, #64 648 + add x3, x2, x4 649 + sub x3, x3, #128 // start of last block 650 + 648 651 subs x5, x4, #128 649 - add x6, x5, x2 650 - csel x3, x3, xzr, ge 651 - csel x2, x2, x6, ge 652 + csel x2, x2, x3, ge 652 653 653 654 // interleave 64-bit words in state n, n+2 654 655 zip1 v0.2d, v16.2d, v18.2d ··· 657 658 zip1 v8.2d, v17.2d, v19.2d 658 659 zip2 v12.2d, v17.2d, v19.2d 659 660 stp a2, a3, [x1, #-56] 660 - ld1 {v16.16b-v19.16b}, [x2], x3 661 661 662 662 subs x6, x4, #192 663 - ccmp x3, xzr, #4, lt 664 - add x7, x6, x2 665 - csel x3, x3, xzr, eq 666 - csel x2, x2, x7, eq 663 + ld1 {v16.16b-v19.16b}, [x2], #64 664 + csel x2, x2, x3, ge 667 665 668 666 zip1 v1.2d, v20.2d, v22.2d 669 667 zip2 v5.2d, v20.2d, v22.2d ··· 668 672 zip1 v9.2d, v21.2d, v23.2d 669 673 zip2 v13.2d, v21.2d, v23.2d 670 674 stp a6, a7, [x1, #-40] 671 - ld1 {v20.16b-v23.16b}, [x2], x3 672 675 673 676 subs x7, x4, #256 674 - ccmp x3, xzr, #4, lt 675 - add x8, x7, x2 676 - csel x3, x3, xzr, eq 677 - csel x2, x2, x8, eq 677 + ld1 {v20.16b-v23.16b}, [x2], #64 678 + csel x2, x2, x3, ge 678 679 679 680 zip1 v2.2d, v24.2d, v26.2d 680 681 zip2 v6.2d, v24.2d, v26.2d ··· 679 686 zip1 v10.2d, v25.2d, v27.2d 680 687 zip2 v14.2d, v25.2d, v27.2d 681 688 stp a10, a11, [x1, #-24] 682 - ld1 {v24.16b-v27.16b}, [x2], x3 683 689 684 690 subs x8, x4, #320 685 - ccmp x3, xzr, #4, lt 686 - add x9, x8, x2 687 - csel x2, x2, x9, eq 691 + ld1 {v24.16b-v27.16b}, [x2], #64 692 + csel x2, x2, x3, ge 688 693 689 694 zip1 v3.2d, v28.2d, v30.2d 690 695 zip2 v7.2d, v28.2d, v30.2d ··· 690 699 zip1 v11.2d, v29.2d, v31.2d 691 700 zip2 v15.2d, v29.2d, v31.2d 692 701 stp a14, a15, [x1, #-8] 702 + 703 + tbnz x5, #63, .Lt128 693 704 ld1 {v28.16b-v31.16b}, [x2] 694 705 695 706 // xor with corresponding input, write to output 696 - tbnz x5, #63, 0f 697 707 eor v16.16b, v16.16b, v0.16b 698 708 eor v17.16b, v17.16b, v1.16b 699 709 eor v18.16b, v18.16b, v2.16b 700 710 eor v19.16b, v19.16b, v3.16b 701 - st1 {v16.16b-v19.16b}, [x1], #64 702 - cbz x5, .Lout 703 711 704 - tbnz x6, #63, 1f 712 + tbnz x6, #63, .Lt192 713 + 705 714 eor v20.16b, v20.16b, v4.16b 706 715 eor v21.16b, v21.16b, v5.16b 707 716 eor v22.16b, v22.16b, v6.16b 708 717 eor v23.16b, v23.16b, v7.16b 709 - st1 {v20.16b-v23.16b}, [x1], #64 710 - cbz x6, .Lout 711 718 712 - tbnz x7, #63, 2f 719 + st1 {v16.16b-v19.16b}, [x1], #64 720 + tbnz x7, #63, .Lt256 721 + 713 722 eor v24.16b, v24.16b, v8.16b 714 723 eor v25.16b, v25.16b, v9.16b 715 724 eor v26.16b, v26.16b, v10.16b 716 725 eor v27.16b, v27.16b, v11.16b 717 - st1 {v24.16b-v27.16b}, [x1], #64 718 - cbz x7, .Lout 719 726 720 - tbnz x8, #63, 3f 727 + st1 {v20.16b-v23.16b}, [x1], #64 728 + tbnz x8, #63, .Lt320 729 + 721 730 eor v28.16b, v28.16b, v12.16b 722 731 eor v29.16b, v29.16b, v13.16b 723 732 eor v30.16b, v30.16b, v14.16b 724 733 eor v31.16b, v31.16b, v15.16b 734 + 735 + st1 {v24.16b-v27.16b}, [x1], #64 725 736 st1 {v28.16b-v31.16b}, [x1] 726 737 727 738 .Lout: frame_pop 728 739 ret 729 740 730 - // fewer than 128 bytes of in/output 731 - 0: ld1 {v8.16b}, [x10] 732 - ld1 {v9.16b}, [x11] 733 - movi v10.16b, #16 734 - sub x2, x1, #64 735 - add x1, x1, x5 736 - ld1 {v16.16b-v19.16b}, [x2] 737 - tbl v4.16b, {v0.16b-v3.16b}, v8.16b 738 - tbx v20.16b, {v16.16b-v19.16b}, v9.16b 739 - add v8.16b, v8.16b, v10.16b 740 - add v9.16b, v9.16b, v10.16b 741 - tbl v5.16b, {v0.16b-v3.16b}, v8.16b 742 - tbx v21.16b, {v16.16b-v19.16b}, v9.16b 743 - add v8.16b, v8.16b, v10.16b 744 - add v9.16b, v9.16b, v10.16b 745 - tbl v6.16b, {v0.16b-v3.16b}, v8.16b 746 - tbx v22.16b, {v16.16b-v19.16b}, v9.16b 747 - add v8.16b, v8.16b, v10.16b 748 - add v9.16b, v9.16b, v10.16b 749 - tbl v7.16b, {v0.16b-v3.16b}, v8.16b 750 - tbx v23.16b, {v16.16b-v19.16b}, v9.16b 751 - 752 - eor v20.16b, v20.16b, v4.16b 753 - eor v21.16b, v21.16b, v5.16b 754 - eor v22.16b, v22.16b, v6.16b 755 - eor v23.16b, v23.16b, v7.16b 756 - st1 {v20.16b-v23.16b}, [x1] 757 - b .Lout 758 - 759 741 // fewer than 192 bytes of in/output 760 - 1: ld1 {v8.16b}, [x10] 761 - ld1 {v9.16b}, [x11] 762 - movi v10.16b, #16 763 - add x1, x1, x6 764 - tbl v0.16b, {v4.16b-v7.16b}, v8.16b 765 - tbx v20.16b, {v16.16b-v19.16b}, v9.16b 766 - add v8.16b, v8.16b, v10.16b 767 - add v9.16b, v9.16b, v10.16b 768 - tbl v1.16b, {v4.16b-v7.16b}, v8.16b 769 - tbx v21.16b, {v16.16b-v19.16b}, v9.16b 770 - add v8.16b, v8.16b, v10.16b 771 - add v9.16b, v9.16b, v10.16b 772 - tbl v2.16b, {v4.16b-v7.16b}, v8.16b 773 - tbx v22.16b, {v16.16b-v19.16b}, v9.16b 774 - add v8.16b, v8.16b, v10.16b 775 - add v9.16b, v9.16b, v10.16b 776 - tbl v3.16b, {v4.16b-v7.16b}, v8.16b 777 - tbx v23.16b, {v16.16b-v19.16b}, v9.16b 742 + .Lt192: cbz x5, 1f // exactly 128 bytes? 743 + ld1 {v28.16b-v31.16b}, [x10] 744 + add x5, x5, x1 745 + tbl v28.16b, {v4.16b-v7.16b}, v28.16b 746 + tbl v29.16b, {v4.16b-v7.16b}, v29.16b 747 + tbl v30.16b, {v4.16b-v7.16b}, v30.16b 748 + tbl v31.16b, {v4.16b-v7.16b}, v31.16b 778 749 779 - eor v20.16b, v20.16b, v0.16b 780 - eor v21.16b, v21.16b, v1.16b 781 - eor v22.16b, v22.16b, v2.16b 782 - eor v23.16b, v23.16b, v3.16b 783 - st1 {v20.16b-v23.16b}, [x1] 750 + 0: eor v20.16b, v20.16b, v28.16b 751 + eor v21.16b, v21.16b, v29.16b 752 + eor v22.16b, v22.16b, v30.16b 753 + eor v23.16b, v23.16b, v31.16b 754 + st1 {v20.16b-v23.16b}, [x5] // overlapping stores 755 + 1: st1 {v16.16b-v19.16b}, [x1] 784 756 b .Lout 757 + 758 + // fewer than 128 bytes of in/output 759 + .Lt128: ld1 {v28.16b-v31.16b}, [x10] 760 + add x5, x5, x1 761 + sub x1, x1, #64 762 + tbl v28.16b, {v0.16b-v3.16b}, v28.16b 763 + tbl v29.16b, {v0.16b-v3.16b}, v29.16b 764 + tbl v30.16b, {v0.16b-v3.16b}, v30.16b 765 + tbl v31.16b, {v0.16b-v3.16b}, v31.16b 766 + ld1 {v16.16b-v19.16b}, [x1] // reload first output block 767 + b 0b 785 768 786 769 // fewer than 256 bytes of in/output 787 - 2: ld1 {v4.16b}, [x10] 788 - ld1 {v5.16b}, [x11] 789 - movi v6.16b, #16 790 - add x1, x1, x7 770 + .Lt256: cbz x6, 2f // exactly 192 bytes? 771 + ld1 {v4.16b-v7.16b}, [x10] 772 + add x6, x6, x1 791 773 tbl v0.16b, {v8.16b-v11.16b}, v4.16b 792 - tbx v24.16b, {v20.16b-v23.16b}, v5.16b 793 - add v4.16b, v4.16b, v6.16b 794 - add v5.16b, v5.16b, v6.16b 795 - tbl v1.16b, {v8.16b-v11.16b}, v4.16b 796 - tbx v25.16b, {v20.16b-v23.16b}, v5.16b 797 - add v4.16b, v4.16b, v6.16b 798 - add v5.16b, v5.16b, v6.16b 799 - tbl v2.16b, {v8.16b-v11.16b}, v4.16b 800 - tbx v26.16b, {v20.16b-v23.16b}, v5.16b 801 - add v4.16b, v4.16b, v6.16b 802 - add v5.16b, v5.16b, v6.16b 803 - tbl v3.16b, {v8.16b-v11.16b}, v4.16b 804 - tbx v27.16b, {v20.16b-v23.16b}, v5.16b 805 - 806 - eor v24.16b, v24.16b, v0.16b 807 - eor v25.16b, v25.16b, v1.16b 808 - eor v26.16b, v26.16b, v2.16b 809 - eor v27.16b, v27.16b, v3.16b 810 - st1 {v24.16b-v27.16b}, [x1] 811 - b .Lout 812 - 813 - // fewer than 320 bytes of in/output 814 - 3: ld1 {v4.16b}, [x10] 815 - ld1 {v5.16b}, [x11] 816 - movi v6.16b, #16 817 - add x1, x1, x8 818 - tbl v0.16b, {v12.16b-v15.16b}, v4.16b 819 - tbx v28.16b, {v24.16b-v27.16b}, v5.16b 820 - add v4.16b, v4.16b, v6.16b 821 - add v5.16b, v5.16b, v6.16b 822 - tbl v1.16b, {v12.16b-v15.16b}, v4.16b 823 - tbx v29.16b, {v24.16b-v27.16b}, v5.16b 824 - add v4.16b, v4.16b, v6.16b 825 - add v5.16b, v5.16b, v6.16b 826 - tbl v2.16b, {v12.16b-v15.16b}, v4.16b 827 - tbx v30.16b, {v24.16b-v27.16b}, v5.16b 828 - add v4.16b, v4.16b, v6.16b 829 - add v5.16b, v5.16b, v6.16b 830 - tbl v3.16b, {v12.16b-v15.16b}, v4.16b 831 - tbx v31.16b, {v24.16b-v27.16b}, v5.16b 774 + tbl v1.16b, {v8.16b-v11.16b}, v5.16b 775 + tbl v2.16b, {v8.16b-v11.16b}, v6.16b 776 + tbl v3.16b, {v8.16b-v11.16b}, v7.16b 832 777 833 778 eor v28.16b, v28.16b, v0.16b 834 779 eor v29.16b, v29.16b, v1.16b 835 780 eor v30.16b, v30.16b, v2.16b 836 781 eor v31.16b, v31.16b, v3.16b 837 - st1 {v28.16b-v31.16b}, [x1] 782 + st1 {v28.16b-v31.16b}, [x6] // overlapping stores 783 + 2: st1 {v20.16b-v23.16b}, [x1] 784 + b .Lout 785 + 786 + // fewer than 320 bytes of in/output 787 + .Lt320: cbz x7, 3f // exactly 256 bytes? 788 + ld1 {v4.16b-v7.16b}, [x10] 789 + add x7, x7, x1 790 + tbl v0.16b, {v12.16b-v15.16b}, v4.16b 791 + tbl v1.16b, {v12.16b-v15.16b}, v5.16b 792 + tbl v2.16b, {v12.16b-v15.16b}, v6.16b 793 + tbl v3.16b, {v12.16b-v15.16b}, v7.16b 794 + 795 + eor v28.16b, v28.16b, v0.16b 796 + eor v29.16b, v29.16b, v1.16b 797 + eor v30.16b, v30.16b, v2.16b 798 + eor v31.16b, v31.16b, v3.16b 799 + st1 {v28.16b-v31.16b}, [x7] // overlapping stores 800 + 3: st1 {v24.16b-v27.16b}, [x1] 838 801 b .Lout 839 802 SYM_FUNC_END(chacha_4block_xor_neon) 840 803 ··· 796 851 .align L1_CACHE_SHIFT 797 852 .Lpermute: 798 853 .set .Li, 0 799 - .rept 192 854 + .rept 128 800 855 .byte (.Li - 64) 801 856 .set .Li, .Li + 1 802 857 .endr
+15
arch/arm64/crypto/ghash-ce-core.S
··· 544 544 ext XL.16b, XL.16b, XL.16b, #8 545 545 rev64 XL.16b, XL.16b 546 546 eor XL.16b, XL.16b, KS0.16b 547 + 548 + .if \enc == 1 547 549 st1 {XL.16b}, [x10] // store tag 550 + .else 551 + ldp x11, x12, [sp, #40] // load tag pointer and authsize 552 + adr_l x17, .Lpermute_table 553 + ld1 {KS0.16b}, [x11] // load supplied tag 554 + add x17, x17, x12 555 + ld1 {KS1.16b}, [x17] // load permute vector 556 + 557 + cmeq XL.16b, XL.16b, KS0.16b // compare tags 558 + mvn XL.16b, XL.16b // -1 for fail, 0 for pass 559 + tbl XL.16b, {XL.16b}, KS1.16b // keep authsize bytes only 560 + sminv b0, XL.16b // signed minimum across XL 561 + smov w0, v0.b[0] // return b0 562 + .endif 548 563 549 564 4: ldp x29, x30, [sp], #32 550 565 ret
+29 -19
arch/arm64/crypto/ghash-ce-glue.c
··· 55 55 asmlinkage void pmull_gcm_encrypt(int bytes, u8 dst[], const u8 src[], 56 56 u64 const h[][2], u64 dg[], u8 ctr[], 57 57 u32 const rk[], int rounds, u8 tag[]); 58 - 59 - asmlinkage void pmull_gcm_decrypt(int bytes, u8 dst[], const u8 src[], 60 - u64 const h[][2], u64 dg[], u8 ctr[], 61 - u32 const rk[], int rounds, u8 tag[]); 58 + asmlinkage int pmull_gcm_decrypt(int bytes, u8 dst[], const u8 src[], 59 + u64 const h[][2], u64 dg[], u8 ctr[], 60 + u32 const rk[], int rounds, const u8 l[], 61 + const u8 tag[], u64 authsize); 62 62 63 63 static int ghash_init(struct shash_desc *desc) 64 64 { ··· 168 168 put_unaligned_be64(ctx->digest[1], dst); 169 169 put_unaligned_be64(ctx->digest[0], dst + 8); 170 170 171 - *ctx = (struct ghash_desc_ctx){}; 171 + memzero_explicit(ctx, sizeof(*ctx)); 172 172 return 0; 173 173 } 174 174 ··· 458 458 unsigned int authsize = crypto_aead_authsize(aead); 459 459 int nrounds = num_rounds(&ctx->aes_key); 460 460 struct skcipher_walk walk; 461 + u8 otag[AES_BLOCK_SIZE]; 461 462 u8 buf[AES_BLOCK_SIZE]; 462 463 u8 iv[AES_BLOCK_SIZE]; 463 464 u64 dg[2] = {}; ··· 475 474 memcpy(iv, req->iv, GCM_IV_SIZE); 476 475 put_unaligned_be32(2, iv + GCM_IV_SIZE); 477 476 477 + scatterwalk_map_and_copy(otag, req->src, 478 + req->assoclen + req->cryptlen - authsize, 479 + authsize, 0); 480 + 478 481 err = skcipher_walk_aead_decrypt(&walk, req, false); 479 482 480 483 if (likely(crypto_simd_usable())) { 484 + int ret; 485 + 481 486 do { 482 487 const u8 *src = walk.src.virt.addr; 483 488 u8 *dst = walk.dst.virt.addr; ··· 500 493 } 501 494 502 495 kernel_neon_begin(); 503 - pmull_gcm_decrypt(nbytes, dst, src, ctx->ghash_key.h, 504 - dg, iv, ctx->aes_key.key_enc, nrounds, 505 - tag); 496 + ret = pmull_gcm_decrypt(nbytes, dst, src, 497 + ctx->ghash_key.h, 498 + dg, iv, ctx->aes_key.key_enc, 499 + nrounds, tag, otag, authsize); 506 500 kernel_neon_end(); 507 501 508 502 if (unlikely(!nbytes)) ··· 515 507 516 508 err = skcipher_walk_done(&walk, walk.nbytes - nbytes); 517 509 } while (walk.nbytes); 510 + 511 + if (err) 512 + return err; 513 + if (ret) 514 + return -EBADMSG; 518 515 } else { 519 516 while (walk.nbytes >= AES_BLOCK_SIZE) { 520 517 int blocks = walk.nbytes / AES_BLOCK_SIZE; ··· 561 548 err = skcipher_walk_done(&walk, 0); 562 549 } 563 550 551 + if (err) 552 + return err; 553 + 564 554 put_unaligned_be64(dg[1], tag); 565 555 put_unaligned_be64(dg[0], tag + 8); 566 556 put_unaligned_be32(1, iv + GCM_IV_SIZE); 567 557 aes_encrypt(&ctx->aes_key, iv, iv); 568 558 crypto_xor(tag, iv, AES_BLOCK_SIZE); 559 + 560 + if (crypto_memneq(tag, otag, authsize)) { 561 + memzero_explicit(tag, AES_BLOCK_SIZE); 562 + return -EBADMSG; 563 + } 569 564 } 570 - 571 - if (err) 572 - return err; 573 - 574 - /* compare calculated auth tag with the stored one */ 575 - scatterwalk_map_and_copy(buf, req->src, 576 - req->assoclen + req->cryptlen - authsize, 577 - authsize, 0); 578 - 579 - if (crypto_memneq(tag, buf, authsize)) 580 - return -EBADMSG; 581 565 return 0; 582 566 } 583 567
+1 -1
arch/arm64/crypto/poly1305-armv8.pl
··· 840 840 ldp d14,d15,[sp,#64] 841 841 addp $ACC2,$ACC2,$ACC2 842 842 ldr x30,[sp,#8] 843 - .inst 0xd50323bf // autiasp 844 843 845 844 //////////////////////////////////////////////////////////////// 846 845 // lazy reduction, but without narrowing ··· 881 882 str x4,[$ctx,#8] // set is_base2_26 882 883 883 884 ldr x29,[sp],#80 885 + .inst 0xd50323bf // autiasp 884 886 ret 885 887 .size poly1305_blocks_neon,.-poly1305_blocks_neon 886 888
+1 -1
arch/arm64/crypto/poly1305-core.S_shipped
··· 779 779 ldp d14,d15,[sp,#64] 780 780 addp v21.2d,v21.2d,v21.2d 781 781 ldr x30,[sp,#8] 782 - .inst 0xd50323bf // autiasp 783 782 784 783 //////////////////////////////////////////////////////////////// 785 784 // lazy reduction, but without narrowing ··· 820 821 str x4,[x0,#8] // set is_base2_26 821 822 822 823 ldr x29,[sp],#80 824 + .inst 0xd50323bf // autiasp 823 825 ret 824 826 .size poly1305_blocks_neon,.-poly1305_blocks_neon 825 827
+1 -1
arch/arm64/crypto/poly1305-glue.c
··· 177 177 } 178 178 179 179 poly1305_emit(&dctx->h, dst, dctx->s); 180 - *dctx = (struct poly1305_desc_ctx){}; 180 + memzero_explicit(dctx, sizeof(*dctx)); 181 181 } 182 182 EXPORT_SYMBOL(poly1305_final_arch); 183 183
+1 -1
arch/arm64/crypto/sha1-ce-glue.c
··· 10 10 #include <asm/unaligned.h> 11 11 #include <crypto/internal/hash.h> 12 12 #include <crypto/internal/simd.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha1.h> 14 14 #include <crypto/sha1_base.h> 15 15 #include <linux/cpufeature.h> 16 16 #include <linux/crypto.h>
+1 -1
arch/arm64/crypto/sha2-ce-glue.c
··· 10 10 #include <asm/unaligned.h> 11 11 #include <crypto/internal/hash.h> 12 12 #include <crypto/internal/simd.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 #include <crypto/sha256_base.h> 15 15 #include <linux/cpufeature.h> 16 16 #include <linux/crypto.h>
+1 -1
arch/arm64/crypto/sha256-glue.c
··· 10 10 #include <asm/simd.h> 11 11 #include <crypto/internal/hash.h> 12 12 #include <crypto/internal/simd.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 #include <crypto/sha256_base.h> 15 15 #include <linux/types.h> 16 16 #include <linux/string.h>
+1 -1
arch/arm64/crypto/sha3-ce-glue.c
··· 94 94 if (digest_size & 4) 95 95 put_unaligned_le32(sctx->st[i], (__le32 *)digest); 96 96 97 - *sctx = (struct sha3_state){}; 97 + memzero_explicit(sctx, sizeof(*sctx)); 98 98 return 0; 99 99 } 100 100
+1 -1
arch/arm64/crypto/sha512-ce-glue.c
··· 14 14 #include <asm/unaligned.h> 15 15 #include <crypto/internal/hash.h> 16 16 #include <crypto/internal/simd.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha2.h> 18 18 #include <crypto/sha512_base.h> 19 19 #include <linux/cpufeature.h> 20 20 #include <linux/crypto.h>
+1 -1
arch/arm64/crypto/sha512-glue.c
··· 8 8 #include <crypto/internal/hash.h> 9 9 #include <linux/types.h> 10 10 #include <linux/string.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha2.h> 12 12 #include <crypto/sha512_base.h> 13 13 #include <asm/neon.h> 14 14
+1 -1
arch/mips/cavium-octeon/crypto/octeon-crypto.h
··· 41 41 */ 42 42 #define read_octeon_64bit_hash_dword(index) \ 43 43 ({ \ 44 - u64 __value; \ 44 + __be64 __value; \ 45 45 \ 46 46 __asm__ __volatile__ ( \ 47 47 "dmfc2 %[rt],0x0048+" STR(index) \
+8 -6
arch/mips/cavium-octeon/crypto/octeon-md5.c
··· 68 68 { 69 69 struct md5_state *mctx = shash_desc_ctx(desc); 70 70 71 - mctx->hash[0] = cpu_to_le32(MD5_H0); 72 - mctx->hash[1] = cpu_to_le32(MD5_H1); 73 - mctx->hash[2] = cpu_to_le32(MD5_H2); 74 - mctx->hash[3] = cpu_to_le32(MD5_H3); 71 + mctx->hash[0] = MD5_H0; 72 + mctx->hash[1] = MD5_H1; 73 + mctx->hash[2] = MD5_H2; 74 + mctx->hash[3] = MD5_H3; 75 + cpu_to_le32_array(mctx->hash, 4); 75 76 mctx->byte_count = 0; 76 77 77 78 return 0; ··· 140 139 } 141 140 142 141 memset(p, 0, padding); 143 - mctx->block[14] = cpu_to_le32(mctx->byte_count << 3); 144 - mctx->block[15] = cpu_to_le32(mctx->byte_count >> 29); 142 + mctx->block[14] = mctx->byte_count << 3; 143 + mctx->block[15] = mctx->byte_count >> 29; 144 + cpu_to_le32_array(mctx->block + 14, 2); 145 145 octeon_md5_transform(mctx->block); 146 146 147 147 octeon_md5_read_hash(mctx);
+1 -1
arch/mips/cavium-octeon/crypto/octeon-sha1.c
··· 14 14 */ 15 15 16 16 #include <linux/mm.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha1.h> 18 18 #include <linux/init.h> 19 19 #include <linux/types.h> 20 20 #include <linux/module.h>
+1 -1
arch/mips/cavium-octeon/crypto/octeon-sha256.c
··· 15 15 */ 16 16 17 17 #include <linux/mm.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha2.h> 19 19 #include <linux/init.h> 20 20 #include <linux/types.h> 21 21 #include <linux/module.h>
+1 -1
arch/mips/cavium-octeon/crypto/octeon-sha512.c
··· 14 14 */ 15 15 16 16 #include <linux/mm.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha2.h> 18 18 #include <linux/init.h> 19 19 #include <linux/types.h> 20 20 #include <linux/module.h>
+1 -1
arch/powerpc/crypto/sha1-spe-glue.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/mm.h> 14 14 #include <linux/types.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha1.h> 16 16 #include <asm/byteorder.h> 17 17 #include <asm/switch_to.h> 18 18 #include <linux/hardirq.h>
+1 -1
arch/powerpc/crypto/sha1.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/mm.h> 19 19 #include <linux/types.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha1.h> 21 21 #include <asm/byteorder.h> 22 22 23 23 void powerpc_sha_transform(u32 *state, const u8 *src);
+2 -2
arch/powerpc/crypto/sha256-spe-glue.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/mm.h> 15 15 #include <linux/types.h> 16 - #include <crypto/sha.h> 16 + #include <crypto/sha2.h> 17 17 #include <asm/byteorder.h> 18 18 #include <asm/switch_to.h> 19 19 #include <linux/hardirq.h> ··· 177 177 178 178 static int ppc_spe_sha224_final(struct shash_desc *desc, u8 *out) 179 179 { 180 - u32 D[SHA256_DIGEST_SIZE >> 2]; 180 + __be32 D[SHA256_DIGEST_SIZE >> 2]; 181 181 __be32 *dst = (__be32 *)out; 182 182 183 183 ppc_spe_sha256_final(desc, (u8 *)D);
+2 -1
arch/s390/crypto/sha.h
··· 11 11 #define _CRYPTO_ARCH_S390_SHA_H 12 12 13 13 #include <linux/crypto.h> 14 - #include <crypto/sha.h> 14 + #include <crypto/sha1.h> 15 + #include <crypto/sha2.h> 15 16 #include <crypto/sha3.h> 16 17 17 18 /* must be big enough for the largest SHA variant */
+1 -1
arch/s390/crypto/sha1_s390.c
··· 22 22 #include <linux/init.h> 23 23 #include <linux/module.h> 24 24 #include <linux/cpufeature.h> 25 - #include <crypto/sha.h> 25 + #include <crypto/sha1.h> 26 26 #include <asm/cpacf.h> 27 27 28 28 #include "sha.h"
+1 -1
arch/s390/crypto/sha256_s390.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/module.h> 14 14 #include <linux/cpufeature.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha2.h> 16 16 #include <asm/cpacf.h> 17 17 18 18 #include "sha.h"
-1
arch/s390/crypto/sha3_256_s390.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/module.h> 14 14 #include <linux/cpufeature.h> 15 - #include <crypto/sha.h> 16 15 #include <crypto/sha3.h> 17 16 #include <asm/cpacf.h> 18 17
-1
arch/s390/crypto/sha3_512_s390.c
··· 11 11 #include <linux/init.h> 12 12 #include <linux/module.h> 13 13 #include <linux/cpufeature.h> 14 - #include <crypto/sha.h> 15 14 #include <crypto/sha3.h> 16 15 #include <asm/cpacf.h> 17 16
+1 -1
arch/s390/crypto/sha512_s390.c
··· 8 8 * Author(s): Jan Glauber (jang@de.ibm.com) 9 9 */ 10 10 #include <crypto/internal/hash.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha2.h> 12 12 #include <linux/errno.h> 13 13 #include <linux/init.h> 14 14 #include <linux/kernel.h>
+1 -1
arch/s390/purgatory/purgatory.c
··· 9 9 10 10 #include <linux/kexec.h> 11 11 #include <linux/string.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha2.h> 13 13 #include <asm/purgatory.h> 14 14 15 15 int verify_sha256_digest(void)
+1 -1
arch/sparc/crypto/crc32c_glue.c
··· 35 35 36 36 if (keylen != sizeof(u32)) 37 37 return -EINVAL; 38 - *(__le32 *)mctx = le32_to_cpup((__le32 *)key); 38 + *mctx = le32_to_cpup((__le32 *)key); 39 39 return 0; 40 40 } 41 41
+5 -4
arch/sparc/crypto/md5_glue.c
··· 33 33 { 34 34 struct md5_state *mctx = shash_desc_ctx(desc); 35 35 36 - mctx->hash[0] = cpu_to_le32(MD5_H0); 37 - mctx->hash[1] = cpu_to_le32(MD5_H1); 38 - mctx->hash[2] = cpu_to_le32(MD5_H2); 39 - mctx->hash[3] = cpu_to_le32(MD5_H3); 36 + mctx->hash[0] = MD5_H0; 37 + mctx->hash[1] = MD5_H1; 38 + mctx->hash[2] = MD5_H2; 39 + mctx->hash[3] = MD5_H3; 40 + le32_to_cpu_array(mctx->hash, 4); 40 41 mctx->byte_count = 0; 41 42 42 43 return 0;
+1 -1
arch/sparc/crypto/sha1_glue.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/mm.h> 18 18 #include <linux/types.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha1.h> 20 20 21 21 #include <asm/pstate.h> 22 22 #include <asm/elf.h>
+1 -1
arch/sparc/crypto/sha256_glue.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/mm.h> 18 18 #include <linux/types.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha2.h> 20 20 21 21 #include <asm/pstate.h> 22 22 #include <asm/elf.h>
+1 -1
arch/sparc/crypto/sha512_glue.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/mm.h> 17 17 #include <linux/types.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha2.h> 19 19 20 20 #include <asm/pstate.h> 21 21 #include <asm/elf.h>
-1
arch/x86/crypto/aes_glue.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only
+10 -10
arch/x86/crypto/aesni-intel_asm.S
··· 318 318 319 319 # Main loop - Encrypt/Decrypt remaining blocks 320 320 321 - cmp $0, %r13 321 + test %r13, %r13 322 322 je _zero_cipher_left_\@ 323 323 sub $64, %r13 324 324 je _four_cipher_left_\@ ··· 437 437 438 438 mov PBlockLen(%arg2), %r12 439 439 440 - cmp $0, %r12 440 + test %r12, %r12 441 441 je _partial_done\@ 442 442 443 443 GHASH_MUL %xmm8, %xmm13, %xmm9, %xmm10, %xmm11, %xmm5, %xmm6 ··· 474 474 add $8, %r10 475 475 sub $8, %r11 476 476 psrldq $8, %xmm0 477 - cmp $0, %r11 477 + test %r11, %r11 478 478 je _return_T_done_\@ 479 479 _T_4_\@: 480 480 movd %xmm0, %eax ··· 482 482 add $4, %r10 483 483 sub $4, %r11 484 484 psrldq $4, %xmm0 485 - cmp $0, %r11 485 + test %r11, %r11 486 486 je _return_T_done_\@ 487 487 _T_123_\@: 488 488 movd %xmm0, %eax ··· 619 619 620 620 /* read the last <16B of AAD */ 621 621 _get_AAD_rest\@: 622 - cmp $0, %r11 622 + test %r11, %r11 623 623 je _get_AAD_done\@ 624 624 625 625 READ_PARTIAL_BLOCK %r10, %r11, \TMP1, \TMP7 ··· 640 640 .macro PARTIAL_BLOCK CYPH_PLAIN_OUT PLAIN_CYPH_IN PLAIN_CYPH_LEN DATA_OFFSET \ 641 641 AAD_HASH operation 642 642 mov PBlockLen(%arg2), %r13 643 - cmp $0, %r13 643 + test %r13, %r13 644 644 je _partial_block_done_\@ # Leave Macro if no partial blocks 645 645 # Read in input data without over reading 646 646 cmp $16, \PLAIN_CYPH_LEN ··· 692 692 pshufb %xmm2, %xmm3 693 693 pxor %xmm3, \AAD_HASH 694 694 695 - cmp $0, %r10 695 + test %r10, %r10 696 696 jl _partial_incomplete_1_\@ 697 697 698 698 # GHASH computation for the last <16 Byte block ··· 727 727 pshufb %xmm2, %xmm9 728 728 pxor %xmm9, \AAD_HASH 729 729 730 - cmp $0, %r10 730 + test %r10, %r10 731 731 jl _partial_incomplete_2_\@ 732 732 733 733 # GHASH computation for the last <16 Byte block ··· 747 747 pshufb %xmm2, %xmm9 748 748 .endif 749 749 # output encrypted Bytes 750 - cmp $0, %r10 750 + test %r10, %r10 751 751 jl _partial_fill_\@ 752 752 mov %r13, %r12 753 753 mov $16, %r13 ··· 2720 2720 */ 2721 2721 SYM_FUNC_START(aesni_xts_crypt8) 2722 2722 FRAME_BEGIN 2723 - cmpb $0, %cl 2723 + testb %cl, %cl 2724 2724 movl $0, %ecx 2725 2725 movl $240, %r10d 2726 2726 leaq _aesni_enc4, %r11
+10 -10
arch/x86/crypto/aesni-intel_avx-x86_64.S
··· 369 369 370 370 371 371 _initial_blocks_encrypted\@: 372 - cmp $0, %r13 372 + test %r13, %r13 373 373 je _zero_cipher_left\@ 374 374 375 375 sub $128, %r13 ··· 528 528 vmovdqu HashKey(arg2), %xmm13 529 529 530 530 mov PBlockLen(arg2), %r12 531 - cmp $0, %r12 531 + test %r12, %r12 532 532 je _partial_done\@ 533 533 534 534 #GHASH computation for the last <16 Byte block ··· 573 573 add $8, %r10 574 574 sub $8, %r11 575 575 vpsrldq $8, %xmm9, %xmm9 576 - cmp $0, %r11 576 + test %r11, %r11 577 577 je _return_T_done\@ 578 578 _T_4\@: 579 579 vmovd %xmm9, %eax ··· 581 581 add $4, %r10 582 582 sub $4, %r11 583 583 vpsrldq $4, %xmm9, %xmm9 584 - cmp $0, %r11 584 + test %r11, %r11 585 585 je _return_T_done\@ 586 586 _T_123\@: 587 587 vmovd %xmm9, %eax ··· 625 625 cmp $16, %r11 626 626 jge _get_AAD_blocks\@ 627 627 vmovdqu \T8, \T7 628 - cmp $0, %r11 628 + test %r11, %r11 629 629 je _get_AAD_done\@ 630 630 631 631 vpxor \T7, \T7, \T7 ··· 644 644 vpxor \T1, \T7, \T7 645 645 jmp _get_AAD_rest8\@ 646 646 _get_AAD_rest4\@: 647 - cmp $0, %r11 647 + test %r11, %r11 648 648 jle _get_AAD_rest0\@ 649 649 mov (%r10), %eax 650 650 movq %rax, \T1 ··· 749 749 .macro PARTIAL_BLOCK GHASH_MUL CYPH_PLAIN_OUT PLAIN_CYPH_IN PLAIN_CYPH_LEN DATA_OFFSET \ 750 750 AAD_HASH ENC_DEC 751 751 mov PBlockLen(arg2), %r13 752 - cmp $0, %r13 752 + test %r13, %r13 753 753 je _partial_block_done_\@ # Leave Macro if no partial blocks 754 754 # Read in input data without over reading 755 755 cmp $16, \PLAIN_CYPH_LEN ··· 801 801 vpshufb %xmm2, %xmm3, %xmm3 802 802 vpxor %xmm3, \AAD_HASH, \AAD_HASH 803 803 804 - cmp $0, %r10 804 + test %r10, %r10 805 805 jl _partial_incomplete_1_\@ 806 806 807 807 # GHASH computation for the last <16 Byte block ··· 836 836 vpshufb %xmm2, %xmm9, %xmm9 837 837 vpxor %xmm9, \AAD_HASH, \AAD_HASH 838 838 839 - cmp $0, %r10 839 + test %r10, %r10 840 840 jl _partial_incomplete_2_\@ 841 841 842 842 # GHASH computation for the last <16 Byte block ··· 856 856 vpshufb %xmm2, %xmm9, %xmm9 857 857 .endif 858 858 # output encrypted Bytes 859 - cmp $0, %r10 859 + test %r10, %r10 860 860 jl _partial_fill_\@ 861 861 mov %r13, %r12 862 862 mov $16, %r13
+1 -1
arch/x86/crypto/poly1305-x86_64-cryptogams.pl
··· 251 251 mov %rax,8($ctx) 252 252 mov %rax,16($ctx) 253 253 254 - cmp \$0,$inp 254 + test $inp,$inp 255 255 je .Lno_key 256 256 ___ 257 257 $code.=<<___ if (!$kernel);
+1 -1
arch/x86/crypto/poly1305_glue.c
··· 210 210 } 211 211 212 212 poly1305_simd_emit(&dctx->h, dst, dctx->s); 213 - *dctx = (struct poly1305_desc_ctx){}; 213 + memzero_explicit(dctx, sizeof(*dctx)); 214 214 } 215 215 EXPORT_SYMBOL(poly1305_final_arch); 216 216
+1 -1
arch/x86/crypto/sha1_ssse3_glue.c
··· 22 22 #include <linux/module.h> 23 23 #include <linux/mm.h> 24 24 #include <linux/types.h> 25 - #include <crypto/sha.h> 25 + #include <crypto/sha1.h> 26 26 #include <crypto/sha1_base.h> 27 27 #include <asm/simd.h> 28 28
+1 -1
arch/x86/crypto/sha256_ssse3_glue.c
··· 35 35 #include <linux/module.h> 36 36 #include <linux/mm.h> 37 37 #include <linux/types.h> 38 - #include <crypto/sha.h> 38 + #include <crypto/sha2.h> 39 39 #include <crypto/sha256_base.h> 40 40 #include <linux/string.h> 41 41 #include <asm/simd.h>
+1 -1
arch/x86/crypto/sha512-avx-asm.S
··· 278 278 # "blocks" is the message length in SHA512 blocks 279 279 ######################################################################## 280 280 SYM_FUNC_START(sha512_transform_avx) 281 - cmp $0, msglen 281 + test msglen, msglen 282 282 je nowork 283 283 284 284 # Allocate Stack Space
+1 -1
arch/x86/crypto/sha512-ssse3-asm.S
··· 280 280 ######################################################################## 281 281 SYM_FUNC_START(sha512_transform_ssse3) 282 282 283 - cmp $0, msglen 283 + test msglen, msglen 284 284 je nowork 285 285 286 286 # Allocate Stack Space
+1 -1
arch/x86/crypto/sha512_ssse3_glue.c
··· 34 34 #include <linux/mm.h> 35 35 #include <linux/string.h> 36 36 #include <linux/types.h> 37 - #include <crypto/sha.h> 37 + #include <crypto/sha2.h> 38 38 #include <crypto/sha512_base.h> 39 39 #include <asm/simd.h> 40 40
+1 -1
arch/x86/purgatory/purgatory.c
··· 9 9 */ 10 10 11 11 #include <linux/bug.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha2.h> 13 13 #include <asm/purgatory.h> 14 14 15 15 #include "../boot/string.h"
+2 -2
crypto/Kconfig
··· 145 145 146 146 config CRYPTO_MANAGER_EXTRA_TESTS 147 147 bool "Enable extra run-time crypto self tests" 148 - depends on DEBUG_KERNEL && !CRYPTO_MANAGER_DISABLE_TESTS 148 + depends on DEBUG_KERNEL && !CRYPTO_MANAGER_DISABLE_TESTS && CRYPTO_MANAGER 149 149 help 150 150 Enable extra run-time self tests of registered crypto algorithms, 151 151 including randomized fuzz tests. ··· 201 201 202 202 config CRYPTO_TEST 203 203 tristate "Testing module" 204 - depends on m 204 + depends on m || EXPERT 205 205 select CRYPTO_MANAGER 206 206 help 207 207 Quick & dirty crypto test module.
+171 -76
crypto/aegis128-core.c
··· 67 67 const u8 *src, unsigned int size); 68 68 void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst, 69 69 const u8 *src, unsigned int size); 70 - void crypto_aegis128_final_simd(struct aegis_state *state, 71 - union aegis_block *tag_xor, 72 - u64 assoclen, u64 cryptlen); 70 + int crypto_aegis128_final_simd(struct aegis_state *state, 71 + union aegis_block *tag_xor, 72 + unsigned int assoclen, 73 + unsigned int cryptlen, 74 + unsigned int authsize); 73 75 74 76 static void crypto_aegis128_update(struct aegis_state *state) 75 77 { ··· 86 84 } 87 85 88 86 static void crypto_aegis128_update_a(struct aegis_state *state, 89 - const union aegis_block *msg) 87 + const union aegis_block *msg, 88 + bool do_simd) 90 89 { 91 - if (aegis128_do_simd()) { 90 + if (IS_ENABLED(CONFIG_CRYPTO_AEGIS128_SIMD) && do_simd) { 92 91 crypto_aegis128_update_simd(state, msg); 93 92 return; 94 93 } ··· 98 95 crypto_aegis_block_xor(&state->blocks[0], msg); 99 96 } 100 97 101 - static void crypto_aegis128_update_u(struct aegis_state *state, const void *msg) 98 + static void crypto_aegis128_update_u(struct aegis_state *state, const void *msg, 99 + bool do_simd) 102 100 { 103 - if (aegis128_do_simd()) { 101 + if (IS_ENABLED(CONFIG_CRYPTO_AEGIS128_SIMD) && do_simd) { 104 102 crypto_aegis128_update_simd(state, msg); 105 103 return; 106 104 } ··· 130 126 crypto_aegis_block_xor(&state->blocks[4], &crypto_aegis_const[1]); 131 127 132 128 for (i = 0; i < 5; i++) { 133 - crypto_aegis128_update_a(state, key); 134 - crypto_aegis128_update_a(state, &key_iv); 129 + crypto_aegis128_update_a(state, key, false); 130 + crypto_aegis128_update_a(state, &key_iv, false); 135 131 } 136 132 } 137 133 138 134 static void crypto_aegis128_ad(struct aegis_state *state, 139 - const u8 *src, unsigned int size) 135 + const u8 *src, unsigned int size, 136 + bool do_simd) 140 137 { 141 138 if (AEGIS_ALIGNED(src)) { 142 139 const union aegis_block *src_blk = 143 140 (const union aegis_block *)src; 144 141 145 142 while (size >= AEGIS_BLOCK_SIZE) { 146 - crypto_aegis128_update_a(state, src_blk); 143 + crypto_aegis128_update_a(state, src_blk, do_simd); 147 144 148 145 size -= AEGIS_BLOCK_SIZE; 149 146 src_blk++; 150 147 } 151 148 } else { 152 149 while (size >= AEGIS_BLOCK_SIZE) { 153 - crypto_aegis128_update_u(state, src); 150 + crypto_aegis128_update_u(state, src, do_simd); 154 151 155 152 size -= AEGIS_BLOCK_SIZE; 156 153 src += AEGIS_BLOCK_SIZE; 157 154 } 158 155 } 156 + } 157 + 158 + static void crypto_aegis128_wipe_chunk(struct aegis_state *state, u8 *dst, 159 + const u8 *src, unsigned int size) 160 + { 161 + memzero_explicit(dst, size); 159 162 } 160 163 161 164 static void crypto_aegis128_encrypt_chunk(struct aegis_state *state, u8 *dst, ··· 183 172 crypto_aegis_block_xor(&tmp, &state->blocks[1]); 184 173 crypto_aegis_block_xor(&tmp, src_blk); 185 174 186 - crypto_aegis128_update_a(state, src_blk); 175 + crypto_aegis128_update_a(state, src_blk, false); 187 176 188 177 *dst_blk = tmp; 189 178 ··· 199 188 crypto_aegis_block_xor(&tmp, &state->blocks[1]); 200 189 crypto_xor(tmp.bytes, src, AEGIS_BLOCK_SIZE); 201 190 202 - crypto_aegis128_update_u(state, src); 191 + crypto_aegis128_update_u(state, src, false); 203 192 204 193 memcpy(dst, tmp.bytes, AEGIS_BLOCK_SIZE); 205 194 ··· 218 207 crypto_aegis_block_xor(&tmp, &state->blocks[4]); 219 208 crypto_aegis_block_xor(&tmp, &state->blocks[1]); 220 209 221 - crypto_aegis128_update_a(state, &msg); 210 + crypto_aegis128_update_a(state, &msg, false); 222 211 223 212 crypto_aegis_block_xor(&msg, &tmp); 224 213 ··· 244 233 crypto_aegis_block_xor(&tmp, &state->blocks[1]); 245 234 crypto_aegis_block_xor(&tmp, src_blk); 246 235 247 - crypto_aegis128_update_a(state, &tmp); 236 + crypto_aegis128_update_a(state, &tmp, false); 248 237 249 238 *dst_blk = tmp; 250 239 ··· 260 249 crypto_aegis_block_xor(&tmp, &state->blocks[1]); 261 250 crypto_xor(tmp.bytes, src, AEGIS_BLOCK_SIZE); 262 251 263 - crypto_aegis128_update_a(state, &tmp); 252 + crypto_aegis128_update_a(state, &tmp, false); 264 253 265 254 memcpy(dst, tmp.bytes, AEGIS_BLOCK_SIZE); 266 255 ··· 282 271 283 272 memset(msg.bytes + size, 0, AEGIS_BLOCK_SIZE - size); 284 273 285 - crypto_aegis128_update_a(state, &msg); 274 + crypto_aegis128_update_a(state, &msg, false); 286 275 287 276 memcpy(dst, msg.bytes, size); 288 277 } ··· 290 279 291 280 static void crypto_aegis128_process_ad(struct aegis_state *state, 292 281 struct scatterlist *sg_src, 293 - unsigned int assoclen) 282 + unsigned int assoclen, 283 + bool do_simd) 294 284 { 295 285 struct scatter_walk walk; 296 286 union aegis_block buf; ··· 308 296 if (pos > 0) { 309 297 unsigned int fill = AEGIS_BLOCK_SIZE - pos; 310 298 memcpy(buf.bytes + pos, src, fill); 311 - crypto_aegis128_update_a(state, &buf); 299 + crypto_aegis128_update_a(state, &buf, do_simd); 312 300 pos = 0; 313 301 left -= fill; 314 302 src += fill; 315 303 } 316 304 317 - crypto_aegis128_ad(state, src, left); 305 + crypto_aegis128_ad(state, src, left, do_simd); 318 306 src += left & ~(AEGIS_BLOCK_SIZE - 1); 319 307 left &= AEGIS_BLOCK_SIZE - 1; 320 308 } ··· 330 318 331 319 if (pos > 0) { 332 320 memset(buf.bytes + pos, 0, AEGIS_BLOCK_SIZE - pos); 333 - crypto_aegis128_update_a(state, &buf); 321 + crypto_aegis128_update_a(state, &buf, do_simd); 334 322 } 335 323 } 336 324 337 325 static __always_inline 338 326 int crypto_aegis128_process_crypt(struct aegis_state *state, 339 - struct aead_request *req, 340 327 struct skcipher_walk *walk, 341 328 void (*crypt)(struct aegis_state *state, 342 329 u8 *dst, const u8 *src, ··· 372 361 crypto_aegis_block_xor(&tmp, &state->blocks[3]); 373 362 374 363 for (i = 0; i < 7; i++) 375 - crypto_aegis128_update_a(state, &tmp); 364 + crypto_aegis128_update_a(state, &tmp, false); 376 365 377 366 for (i = 0; i < AEGIS128_STATE_BLOCKS; i++) 378 367 crypto_aegis_block_xor(tag_xor, &state->blocks[i]); ··· 400 389 return 0; 401 390 } 402 391 403 - static int crypto_aegis128_encrypt(struct aead_request *req) 392 + static int crypto_aegis128_encrypt_generic(struct aead_request *req) 404 393 { 405 394 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 406 395 union aegis_block tag = {}; ··· 411 400 struct aegis_state state; 412 401 413 402 skcipher_walk_aead_encrypt(&walk, req, false); 414 - if (aegis128_do_simd()) { 415 - crypto_aegis128_init_simd(&state, &ctx->key, req->iv); 416 - crypto_aegis128_process_ad(&state, req->src, req->assoclen); 417 - crypto_aegis128_process_crypt(&state, req, &walk, 418 - crypto_aegis128_encrypt_chunk_simd); 419 - crypto_aegis128_final_simd(&state, &tag, req->assoclen, 420 - cryptlen); 421 - } else { 422 - crypto_aegis128_init(&state, &ctx->key, req->iv); 423 - crypto_aegis128_process_ad(&state, req->src, req->assoclen); 424 - crypto_aegis128_process_crypt(&state, req, &walk, 425 - crypto_aegis128_encrypt_chunk); 426 - crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); 427 - } 403 + crypto_aegis128_init(&state, &ctx->key, req->iv); 404 + crypto_aegis128_process_ad(&state, req->src, req->assoclen, false); 405 + crypto_aegis128_process_crypt(&state, &walk, 406 + crypto_aegis128_encrypt_chunk); 407 + crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); 428 408 429 409 scatterwalk_map_and_copy(tag.bytes, req->dst, req->assoclen + cryptlen, 430 410 authsize, 1); 431 411 return 0; 432 412 } 433 413 434 - static int crypto_aegis128_decrypt(struct aead_request *req) 414 + static int crypto_aegis128_decrypt_generic(struct aead_request *req) 435 415 { 436 416 static const u8 zeros[AEGIS128_MAX_AUTH_SIZE] = {}; 437 417 struct crypto_aead *tfm = crypto_aead_reqtfm(req); ··· 437 435 authsize, 0); 438 436 439 437 skcipher_walk_aead_decrypt(&walk, req, false); 440 - if (aegis128_do_simd()) { 441 - crypto_aegis128_init_simd(&state, &ctx->key, req->iv); 442 - crypto_aegis128_process_ad(&state, req->src, req->assoclen); 443 - crypto_aegis128_process_crypt(&state, req, &walk, 444 - crypto_aegis128_decrypt_chunk_simd); 445 - crypto_aegis128_final_simd(&state, &tag, req->assoclen, 446 - cryptlen); 447 - } else { 448 - crypto_aegis128_init(&state, &ctx->key, req->iv); 449 - crypto_aegis128_process_ad(&state, req->src, req->assoclen); 450 - crypto_aegis128_process_crypt(&state, req, &walk, 451 - crypto_aegis128_decrypt_chunk); 452 - crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); 453 - } 438 + crypto_aegis128_init(&state, &ctx->key, req->iv); 439 + crypto_aegis128_process_ad(&state, req->src, req->assoclen, false); 440 + crypto_aegis128_process_crypt(&state, &walk, 441 + crypto_aegis128_decrypt_chunk); 442 + crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); 454 443 455 - return crypto_memneq(tag.bytes, zeros, authsize) ? -EBADMSG : 0; 444 + if (unlikely(crypto_memneq(tag.bytes, zeros, authsize))) { 445 + /* 446 + * From Chapter 4. 'Security Analysis' of the AEGIS spec [0] 447 + * 448 + * "3. If verification fails, the decrypted plaintext and the 449 + * wrong authentication tag should not be given as output." 450 + * 451 + * [0] https://competitions.cr.yp.to/round3/aegisv11.pdf 452 + */ 453 + skcipher_walk_aead_decrypt(&walk, req, false); 454 + crypto_aegis128_process_crypt(NULL, &walk, 455 + crypto_aegis128_wipe_chunk); 456 + memzero_explicit(&tag, sizeof(tag)); 457 + return -EBADMSG; 458 + } 459 + return 0; 456 460 } 457 461 458 - static struct aead_alg crypto_aegis128_alg = { 459 - .setkey = crypto_aegis128_setkey, 460 - .setauthsize = crypto_aegis128_setauthsize, 461 - .encrypt = crypto_aegis128_encrypt, 462 - .decrypt = crypto_aegis128_decrypt, 462 + static int crypto_aegis128_encrypt_simd(struct aead_request *req) 463 + { 464 + struct crypto_aead *tfm = crypto_aead_reqtfm(req); 465 + union aegis_block tag = {}; 466 + unsigned int authsize = crypto_aead_authsize(tfm); 467 + struct aegis_ctx *ctx = crypto_aead_ctx(tfm); 468 + unsigned int cryptlen = req->cryptlen; 469 + struct skcipher_walk walk; 470 + struct aegis_state state; 463 471 464 - .ivsize = AEGIS128_NONCE_SIZE, 465 - .maxauthsize = AEGIS128_MAX_AUTH_SIZE, 466 - .chunksize = AEGIS_BLOCK_SIZE, 472 + if (!aegis128_do_simd()) 473 + return crypto_aegis128_encrypt_generic(req); 467 474 468 - .base = { 469 - .cra_blocksize = 1, 470 - .cra_ctxsize = sizeof(struct aegis_ctx), 471 - .cra_alignmask = 0, 475 + skcipher_walk_aead_encrypt(&walk, req, false); 476 + crypto_aegis128_init_simd(&state, &ctx->key, req->iv); 477 + crypto_aegis128_process_ad(&state, req->src, req->assoclen, true); 478 + crypto_aegis128_process_crypt(&state, &walk, 479 + crypto_aegis128_encrypt_chunk_simd); 480 + crypto_aegis128_final_simd(&state, &tag, req->assoclen, cryptlen, 0); 472 481 473 - .cra_priority = 100, 482 + scatterwalk_map_and_copy(tag.bytes, req->dst, req->assoclen + cryptlen, 483 + authsize, 1); 484 + return 0; 485 + } 474 486 475 - .cra_name = "aegis128", 476 - .cra_driver_name = "aegis128-generic", 487 + static int crypto_aegis128_decrypt_simd(struct aead_request *req) 488 + { 489 + struct crypto_aead *tfm = crypto_aead_reqtfm(req); 490 + union aegis_block tag; 491 + unsigned int authsize = crypto_aead_authsize(tfm); 492 + unsigned int cryptlen = req->cryptlen - authsize; 493 + struct aegis_ctx *ctx = crypto_aead_ctx(tfm); 494 + struct skcipher_walk walk; 495 + struct aegis_state state; 477 496 478 - .cra_module = THIS_MODULE, 497 + if (!aegis128_do_simd()) 498 + return crypto_aegis128_decrypt_generic(req); 499 + 500 + scatterwalk_map_and_copy(tag.bytes, req->src, req->assoclen + cryptlen, 501 + authsize, 0); 502 + 503 + skcipher_walk_aead_decrypt(&walk, req, false); 504 + crypto_aegis128_init_simd(&state, &ctx->key, req->iv); 505 + crypto_aegis128_process_ad(&state, req->src, req->assoclen, true); 506 + crypto_aegis128_process_crypt(&state, &walk, 507 + crypto_aegis128_decrypt_chunk_simd); 508 + 509 + if (unlikely(crypto_aegis128_final_simd(&state, &tag, req->assoclen, 510 + cryptlen, authsize))) { 511 + skcipher_walk_aead_decrypt(&walk, req, false); 512 + crypto_aegis128_process_crypt(NULL, &walk, 513 + crypto_aegis128_wipe_chunk); 514 + return -EBADMSG; 479 515 } 516 + return 0; 517 + } 518 + 519 + static struct aead_alg crypto_aegis128_alg_generic = { 520 + .setkey = crypto_aegis128_setkey, 521 + .setauthsize = crypto_aegis128_setauthsize, 522 + .encrypt = crypto_aegis128_encrypt_generic, 523 + .decrypt = crypto_aegis128_decrypt_generic, 524 + 525 + .ivsize = AEGIS128_NONCE_SIZE, 526 + .maxauthsize = AEGIS128_MAX_AUTH_SIZE, 527 + .chunksize = AEGIS_BLOCK_SIZE, 528 + 529 + .base.cra_blocksize = 1, 530 + .base.cra_ctxsize = sizeof(struct aegis_ctx), 531 + .base.cra_alignmask = 0, 532 + .base.cra_priority = 100, 533 + .base.cra_name = "aegis128", 534 + .base.cra_driver_name = "aegis128-generic", 535 + .base.cra_module = THIS_MODULE, 536 + }; 537 + 538 + static struct aead_alg crypto_aegis128_alg_simd = { 539 + .setkey = crypto_aegis128_setkey, 540 + .setauthsize = crypto_aegis128_setauthsize, 541 + .encrypt = crypto_aegis128_encrypt_simd, 542 + .decrypt = crypto_aegis128_decrypt_simd, 543 + 544 + .ivsize = AEGIS128_NONCE_SIZE, 545 + .maxauthsize = AEGIS128_MAX_AUTH_SIZE, 546 + .chunksize = AEGIS_BLOCK_SIZE, 547 + 548 + .base.cra_blocksize = 1, 549 + .base.cra_ctxsize = sizeof(struct aegis_ctx), 550 + .base.cra_alignmask = 0, 551 + .base.cra_priority = 200, 552 + .base.cra_name = "aegis128", 553 + .base.cra_driver_name = "aegis128-simd", 554 + .base.cra_module = THIS_MODULE, 480 555 }; 481 556 482 557 static int __init crypto_aegis128_module_init(void) 483 558 { 484 - if (IS_ENABLED(CONFIG_CRYPTO_AEGIS128_SIMD) && 485 - crypto_aegis128_have_simd()) 486 - static_branch_enable(&have_simd); 559 + int ret; 487 560 488 - return crypto_register_aead(&crypto_aegis128_alg); 561 + ret = crypto_register_aead(&crypto_aegis128_alg_generic); 562 + if (ret) 563 + return ret; 564 + 565 + if (IS_ENABLED(CONFIG_CRYPTO_AEGIS128_SIMD) && 566 + crypto_aegis128_have_simd()) { 567 + ret = crypto_register_aead(&crypto_aegis128_alg_simd); 568 + if (ret) { 569 + crypto_unregister_aead(&crypto_aegis128_alg_generic); 570 + return ret; 571 + } 572 + static_branch_enable(&have_simd); 573 + } 574 + return 0; 489 575 } 490 576 491 577 static void __exit crypto_aegis128_module_exit(void) 492 578 { 493 - crypto_unregister_aead(&crypto_aegis128_alg); 579 + if (IS_ENABLED(CONFIG_CRYPTO_AEGIS128_SIMD) && 580 + crypto_aegis128_have_simd()) 581 + crypto_unregister_aead(&crypto_aegis128_alg_simd); 582 + 583 + crypto_unregister_aead(&crypto_aegis128_alg_generic); 494 584 } 495 585 496 586 subsys_initcall(crypto_aegis128_module_init); ··· 593 499 MODULE_DESCRIPTION("AEGIS-128 AEAD algorithm"); 594 500 MODULE_ALIAS_CRYPTO("aegis128"); 595 501 MODULE_ALIAS_CRYPTO("aegis128-generic"); 502 + MODULE_ALIAS_CRYPTO("aegis128-simd");
+102 -20
crypto/aegis128-neon-inner.c
··· 20 20 extern int aegis128_have_aes_insn; 21 21 22 22 void *memcpy(void *dest, const void *src, size_t n); 23 - void *memset(void *s, int c, size_t n); 24 23 25 24 struct aegis128_state { 26 25 uint8x16_t v[5]; ··· 172 173 aegis128_save_state_neon(st, state); 173 174 } 174 175 176 + #ifdef CONFIG_ARM 177 + /* 178 + * AArch32 does not provide these intrinsics natively because it does not 179 + * implement the underlying instructions. AArch32 only provides 64-bit 180 + * wide vtbl.8/vtbx.8 instruction, so use those instead. 181 + */ 182 + static uint8x16_t vqtbl1q_u8(uint8x16_t a, uint8x16_t b) 183 + { 184 + union { 185 + uint8x16_t val; 186 + uint8x8x2_t pair; 187 + } __a = { a }; 188 + 189 + return vcombine_u8(vtbl2_u8(__a.pair, vget_low_u8(b)), 190 + vtbl2_u8(__a.pair, vget_high_u8(b))); 191 + } 192 + 193 + static uint8x16_t vqtbx1q_u8(uint8x16_t v, uint8x16_t a, uint8x16_t b) 194 + { 195 + union { 196 + uint8x16_t val; 197 + uint8x8x2_t pair; 198 + } __a = { a }; 199 + 200 + return vcombine_u8(vtbx2_u8(vget_low_u8(v), __a.pair, vget_low_u8(b)), 201 + vtbx2_u8(vget_high_u8(v), __a.pair, vget_high_u8(b))); 202 + } 203 + 204 + static int8_t vminvq_s8(int8x16_t v) 205 + { 206 + int8x8_t s = vpmin_s8(vget_low_s8(v), vget_high_s8(v)); 207 + 208 + s = vpmin_s8(s, s); 209 + s = vpmin_s8(s, s); 210 + s = vpmin_s8(s, s); 211 + 212 + return vget_lane_s8(s, 0); 213 + } 214 + #endif 215 + 216 + static const uint8_t permute[] __aligned(64) = { 217 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 218 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 219 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 220 + }; 221 + 175 222 void crypto_aegis128_encrypt_chunk_neon(void *state, void *dst, const void *src, 176 223 unsigned int size) 177 224 { 178 225 struct aegis128_state st = aegis128_load_state_neon(state); 226 + const int short_input = size < AEGIS_BLOCK_SIZE; 179 227 uint8x16_t msg; 180 228 181 229 preload_sbox(); ··· 232 186 233 187 msg = vld1q_u8(src); 234 188 st = aegis128_update_neon(st, msg); 235 - vst1q_u8(dst, msg ^ s); 189 + msg ^= s; 190 + vst1q_u8(dst, msg); 236 191 237 192 size -= AEGIS_BLOCK_SIZE; 238 193 src += AEGIS_BLOCK_SIZE; ··· 242 195 243 196 if (size > 0) { 244 197 uint8x16_t s = st.v[1] ^ (st.v[2] & st.v[3]) ^ st.v[4]; 245 - uint8_t buf[AEGIS_BLOCK_SIZE] = {}; 198 + uint8_t buf[AEGIS_BLOCK_SIZE]; 199 + const void *in = src; 200 + void *out = dst; 201 + uint8x16_t m; 246 202 247 - memcpy(buf, src, size); 248 - msg = vld1q_u8(buf); 249 - st = aegis128_update_neon(st, msg); 250 - vst1q_u8(buf, msg ^ s); 251 - memcpy(dst, buf, size); 203 + if (__builtin_expect(short_input, 0)) 204 + in = out = memcpy(buf + AEGIS_BLOCK_SIZE - size, src, size); 205 + 206 + m = vqtbl1q_u8(vld1q_u8(in + size - AEGIS_BLOCK_SIZE), 207 + vld1q_u8(permute + 32 - size)); 208 + 209 + st = aegis128_update_neon(st, m); 210 + 211 + vst1q_u8(out + size - AEGIS_BLOCK_SIZE, 212 + vqtbl1q_u8(m ^ s, vld1q_u8(permute + size))); 213 + 214 + if (__builtin_expect(short_input, 0)) 215 + memcpy(dst, out, size); 216 + else 217 + vst1q_u8(out - AEGIS_BLOCK_SIZE, msg); 252 218 } 253 219 254 220 aegis128_save_state_neon(st, state); ··· 271 211 unsigned int size) 272 212 { 273 213 struct aegis128_state st = aegis128_load_state_neon(state); 214 + const int short_input = size < AEGIS_BLOCK_SIZE; 274 215 uint8x16_t msg; 275 216 276 217 preload_sbox(); ··· 289 228 if (size > 0) { 290 229 uint8x16_t s = st.v[1] ^ (st.v[2] & st.v[3]) ^ st.v[4]; 291 230 uint8_t buf[AEGIS_BLOCK_SIZE]; 231 + const void *in = src; 232 + void *out = dst; 233 + uint8x16_t m; 292 234 293 - vst1q_u8(buf, s); 294 - memcpy(buf, src, size); 295 - msg = vld1q_u8(buf) ^ s; 296 - vst1q_u8(buf, msg); 297 - memcpy(dst, buf, size); 235 + if (__builtin_expect(short_input, 0)) 236 + in = out = memcpy(buf + AEGIS_BLOCK_SIZE - size, src, size); 298 237 299 - st = aegis128_update_neon(st, msg); 238 + m = s ^ vqtbx1q_u8(s, vld1q_u8(in + size - AEGIS_BLOCK_SIZE), 239 + vld1q_u8(permute + 32 - size)); 240 + 241 + st = aegis128_update_neon(st, m); 242 + 243 + vst1q_u8(out + size - AEGIS_BLOCK_SIZE, 244 + vqtbl1q_u8(m, vld1q_u8(permute + size))); 245 + 246 + if (__builtin_expect(short_input, 0)) 247 + memcpy(dst, out, size); 248 + else 249 + vst1q_u8(out - AEGIS_BLOCK_SIZE, msg); 300 250 } 301 251 302 252 aegis128_save_state_neon(st, state); 303 253 } 304 254 305 - void crypto_aegis128_final_neon(void *state, void *tag_xor, uint64_t assoclen, 306 - uint64_t cryptlen) 255 + int crypto_aegis128_final_neon(void *state, void *tag_xor, 256 + unsigned int assoclen, 257 + unsigned int cryptlen, 258 + unsigned int authsize) 307 259 { 308 260 struct aegis128_state st = aegis128_load_state_neon(state); 309 261 uint8x16_t v; ··· 324 250 325 251 preload_sbox(); 326 252 327 - v = st.v[3] ^ (uint8x16_t)vcombine_u64(vmov_n_u64(8 * assoclen), 328 - vmov_n_u64(8 * cryptlen)); 253 + v = st.v[3] ^ (uint8x16_t)vcombine_u64(vmov_n_u64(8ULL * assoclen), 254 + vmov_n_u64(8ULL * cryptlen)); 329 255 330 256 for (i = 0; i < 7; i++) 331 257 st = aegis128_update_neon(st, v); 332 258 333 - v = vld1q_u8(tag_xor); 334 - v ^= st.v[0] ^ st.v[1] ^ st.v[2] ^ st.v[3] ^ st.v[4]; 259 + v = st.v[0] ^ st.v[1] ^ st.v[2] ^ st.v[3] ^ st.v[4]; 260 + 261 + if (authsize > 0) { 262 + v = vqtbl1q_u8(~vceqq_u8(v, vld1q_u8(tag_xor)), 263 + vld1q_u8(permute + authsize)); 264 + 265 + return vminvq_s8((int8x16_t)v); 266 + } 267 + 335 268 vst1q_u8(tag_xor, v); 269 + return 0; 336 270 }
+15 -6
crypto/aegis128-neon.c
··· 14 14 unsigned int size); 15 15 void crypto_aegis128_decrypt_chunk_neon(void *state, void *dst, const void *src, 16 16 unsigned int size); 17 - void crypto_aegis128_final_neon(void *state, void *tag_xor, uint64_t assoclen, 18 - uint64_t cryptlen); 17 + int crypto_aegis128_final_neon(void *state, void *tag_xor, 18 + unsigned int assoclen, 19 + unsigned int cryptlen, 20 + unsigned int authsize); 19 21 20 22 int aegis128_have_aes_insn __ro_after_init; 21 23 ··· 62 60 kernel_neon_end(); 63 61 } 64 62 65 - void crypto_aegis128_final_simd(union aegis_block *state, 66 - union aegis_block *tag_xor, 67 - u64 assoclen, u64 cryptlen) 63 + int crypto_aegis128_final_simd(union aegis_block *state, 64 + union aegis_block *tag_xor, 65 + unsigned int assoclen, 66 + unsigned int cryptlen, 67 + unsigned int authsize) 68 68 { 69 + int ret; 70 + 69 71 kernel_neon_begin(); 70 - crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen); 72 + ret = crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen, 73 + authsize); 71 74 kernel_neon_end(); 75 + 76 + return ret; 72 77 }
+7 -3
crypto/af_alg.c
··· 147 147 const u32 allowed = CRYPTO_ALG_KERN_DRIVER_ONLY; 148 148 struct sock *sk = sock->sk; 149 149 struct alg_sock *ask = alg_sk(sk); 150 - struct sockaddr_alg *sa = (void *)uaddr; 150 + struct sockaddr_alg_new *sa = (void *)uaddr; 151 151 const struct af_alg_type *type; 152 152 void *private; 153 153 int err; ··· 155 155 if (sock->state == SS_CONNECTED) 156 156 return -EINVAL; 157 157 158 - if (addr_len < sizeof(*sa)) 158 + BUILD_BUG_ON(offsetof(struct sockaddr_alg_new, salg_name) != 159 + offsetof(struct sockaddr_alg, salg_name)); 160 + BUILD_BUG_ON(offsetof(struct sockaddr_alg, salg_name) != sizeof(*sa)); 161 + 162 + if (addr_len < sizeof(*sa) + 1) 159 163 return -EINVAL; 160 164 161 165 /* If caller uses non-allowed flag, return error. */ ··· 167 163 return -EINVAL; 168 164 169 165 sa->salg_type[sizeof(sa->salg_type) - 1] = 0; 170 - sa->salg_name[sizeof(sa->salg_name) + addr_len - sizeof(*sa) - 1] = 0; 166 + sa->salg_name[addr_len - sizeof(*sa) - 1] = 0; 171 167 172 168 type = alg_get_type(sa->salg_type); 173 169 if (PTR_ERR(type) == -ENOENT) {
+1 -1
crypto/asymmetric_keys/asym_tpm.c
··· 10 10 #include <linux/tpm_command.h> 11 11 #include <crypto/akcipher.h> 12 12 #include <crypto/hash.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha1.h> 14 14 #include <asm/unaligned.h> 15 15 #include <keys/asymmetric-subtype.h> 16 16 #include <keys/trusted_tpm.h>
+5 -4
crypto/ecdh.c
··· 53 53 return ecc_gen_privkey(ctx->curve_id, ctx->ndigits, 54 54 ctx->private_key); 55 55 56 - if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits, 57 - (const u64 *)params.key, params.key_size) < 0) 58 - return -EINVAL; 59 - 60 56 memcpy(ctx->private_key, params.key, params.key_size); 61 57 58 + if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits, 59 + ctx->private_key, params.key_size) < 0) { 60 + memzero_explicit(ctx->private_key, params.key_size); 61 + return -EINVAL; 62 + } 62 63 return 0; 63 64 } 64 65
+1 -1
crypto/seed.c
··· 322 322 SS2[byte(t1, 2)] ^ SS3[byte(t1, 3)]; \ 323 323 t0 += t1; \ 324 324 X1 ^= t0; \ 325 - X2 ^= t1; 325 + X2 ^= t1 326 326 327 327 static int seed_set_key(struct crypto_tfm *tfm, const u8 *in_key, 328 328 unsigned int key_len)
+1 -1
crypto/sha1_generic.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/mm.h> 18 18 #include <linux/types.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha1.h> 20 20 #include <crypto/sha1_base.h> 21 21 #include <asm/byteorder.h> 22 22
+1 -1
crypto/sha256_generic.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/mm.h> 14 14 #include <linux/types.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha2.h> 16 16 #include <crypto/sha256_base.h> 17 17 #include <asm/byteorder.h> 18 18 #include <asm/unaligned.h>
+1 -1
crypto/sha512_generic.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/crypto.h> 14 14 #include <linux/types.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha2.h> 16 16 #include <crypto/sha512_base.h> 17 17 #include <linux/percpu.h> 18 18 #include <asm/byteorder.h>
+29 -46
crypto/sm2.c
··· 119 119 memset(ec, 0, sizeof(*ec)); 120 120 } 121 121 122 - static int sm2_ec_ctx_reset(struct mpi_ec_ctx *ec) 123 - { 124 - sm2_ec_ctx_deinit(ec); 125 - return sm2_ec_ctx_init(ec); 126 - } 127 - 128 122 /* RESULT must have been initialized and is set on success to the 129 123 * point given by VALUE. 130 124 */ ··· 126 132 { 127 133 int rc; 128 134 size_t n; 129 - const unsigned char *buf; 130 - unsigned char *buf_memory; 135 + unsigned char *buf; 131 136 MPI x, y; 132 137 133 - n = (mpi_get_nbits(value)+7)/8; 134 - buf_memory = kmalloc(n, GFP_KERNEL); 135 - rc = mpi_print(GCRYMPI_FMT_USG, buf_memory, n, &n, value); 136 - if (rc) { 137 - kfree(buf_memory); 138 - return rc; 139 - } 140 - buf = buf_memory; 138 + n = MPI_NBYTES(value); 139 + buf = kmalloc(n, GFP_KERNEL); 140 + if (!buf) 141 + return -ENOMEM; 141 142 142 - if (n < 1) { 143 - kfree(buf_memory); 144 - return -EINVAL; 145 - } 146 - if (*buf != 4) { 147 - kfree(buf_memory); 148 - return -EINVAL; /* No support for point compression. */ 149 - } 150 - if (((n-1)%2)) { 151 - kfree(buf_memory); 152 - return -EINVAL; 153 - } 154 - n = (n-1)/2; 143 + rc = mpi_print(GCRYMPI_FMT_USG, buf, n, &n, value); 144 + if (rc) 145 + goto err_freebuf; 146 + 147 + rc = -EINVAL; 148 + if (n < 1 || ((n - 1) % 2)) 149 + goto err_freebuf; 150 + /* No support for point compression */ 151 + if (*buf != 0x4) 152 + goto err_freebuf; 153 + 154 + rc = -ENOMEM; 155 + n = (n - 1) / 2; 155 156 x = mpi_read_raw_data(buf + 1, n); 156 - if (!x) { 157 - kfree(buf_memory); 158 - return -ENOMEM; 159 - } 157 + if (!x) 158 + goto err_freebuf; 160 159 y = mpi_read_raw_data(buf + 1 + n, n); 161 - kfree(buf_memory); 162 - if (!y) { 163 - mpi_free(x); 164 - return -ENOMEM; 165 - } 160 + if (!y) 161 + goto err_freex; 166 162 167 163 mpi_normalize(x); 168 164 mpi_normalize(y); 169 - 170 165 mpi_set(result->x, x); 171 166 mpi_set(result->y, y); 172 167 mpi_set_ui(result->z, 1); 173 168 174 - mpi_free(x); 175 - mpi_free(y); 169 + rc = 0; 176 170 177 - return 0; 171 + mpi_free(y); 172 + err_freex: 173 + mpi_free(x); 174 + err_freebuf: 175 + kfree(buf); 176 + return rc; 178 177 } 179 178 180 179 struct sm2_signature_ctx { ··· 385 398 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); 386 399 MPI a; 387 400 int rc; 388 - 389 - rc = sm2_ec_ctx_reset(ec); 390 - if (rc) 391 - return rc; 392 401 393 402 ec->Q = mpi_point_new(0); 394 403 if (!ec->Q)
+45 -38
crypto/tcrypt.c
··· 77 77 NULL 78 78 }; 79 79 80 - static u32 block_sizes[] = { 16, 64, 256, 1024, 1472, 8192, 0 }; 81 - static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 }; 80 + static const int block_sizes[] = { 16, 64, 256, 1024, 1420, 4096, 0 }; 81 + static const int aead_sizes[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 }; 82 82 83 83 #define XBUFSIZE 8 84 84 #define MAX_IVLEN 32 ··· 256 256 struct test_mb_aead_data *data; 257 257 struct crypto_aead *tfm; 258 258 unsigned int i, j, iv_len; 259 + const int *b_size; 259 260 const char *key; 260 261 const char *e; 261 262 void *assoc; 262 - u32 *b_size; 263 263 char *iv; 264 264 int ret; 265 265 ··· 337 337 do { 338 338 b_size = aead_sizes; 339 339 do { 340 - if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) { 340 + int bs = round_up(*b_size, crypto_aead_blocksize(tfm)); 341 + 342 + if (bs + authsize > XBUFSIZE * PAGE_SIZE) { 341 343 pr_err("template (%u) too big for buffer (%lu)\n", 342 - authsize + *b_size, 344 + authsize + bs, 343 345 XBUFSIZE * PAGE_SIZE); 344 346 goto out; 345 347 } 346 348 347 349 pr_info("test %u (%d bit key, %d byte blocks): ", i, 348 - *keysize * 8, *b_size); 350 + *keysize * 8, bs); 349 351 350 352 /* Set up tfm global state, i.e. the key */ 351 353 ··· 382 380 memset(assoc, 0xff, aad_size); 383 381 384 382 sg_init_aead(cur->sg, cur->xbuf, 385 - *b_size + (enc ? 0 : authsize), 383 + bs + (enc ? 0 : authsize), 386 384 assoc, aad_size); 387 385 388 386 sg_init_aead(cur->sgout, cur->xoutbuf, 389 - *b_size + (enc ? authsize : 0), 387 + bs + (enc ? authsize : 0), 390 388 assoc, aad_size); 391 389 392 390 aead_request_set_ad(cur->req, aad_size); ··· 396 394 aead_request_set_crypt(cur->req, 397 395 cur->sgout, 398 396 cur->sg, 399 - *b_size, iv); 397 + bs, iv); 400 398 ret = crypto_aead_encrypt(cur->req); 401 399 ret = do_one_aead_op(cur->req, ret); 402 400 ··· 408 406 } 409 407 410 408 aead_request_set_crypt(cur->req, cur->sg, 411 - cur->sgout, *b_size + 409 + cur->sgout, bs + 412 410 (enc ? 0 : authsize), 413 411 iv); 414 412 415 413 } 416 414 417 415 if (secs) { 418 - ret = test_mb_aead_jiffies(data, enc, *b_size, 416 + ret = test_mb_aead_jiffies(data, enc, bs, 419 417 secs, num_mb); 420 418 cond_resched(); 421 419 } else { 422 - ret = test_mb_aead_cycles(data, enc, *b_size, 420 + ret = test_mb_aead_cycles(data, enc, bs, 423 421 num_mb); 424 422 } 425 423 ··· 536 534 char *xbuf[XBUFSIZE]; 537 535 char *xoutbuf[XBUFSIZE]; 538 536 char *axbuf[XBUFSIZE]; 539 - unsigned int *b_size; 537 + const int *b_size; 540 538 unsigned int iv_len; 541 539 struct crypto_wait wait; 542 540 ··· 592 590 do { 593 591 b_size = aead_sizes; 594 592 do { 593 + u32 bs = round_up(*b_size, crypto_aead_blocksize(tfm)); 594 + 595 595 assoc = axbuf[0]; 596 596 memset(assoc, 0xff, aad_size); 597 597 598 - if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { 598 + if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) { 599 599 pr_err("template (%u) too big for tvmem (%lu)\n", 600 - *keysize + *b_size, 600 + *keysize + bs, 601 601 TVMEMSIZE * PAGE_SIZE); 602 602 goto out; 603 603 } ··· 620 616 621 617 crypto_aead_clear_flags(tfm, ~0); 622 618 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", 623 - i, *keysize * 8, *b_size); 619 + i, *keysize * 8, bs); 624 620 625 621 626 622 memset(tvmem[0], 0xff, PAGE_SIZE); ··· 631 627 goto out; 632 628 } 633 629 634 - sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize), 630 + sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize), 635 631 assoc, aad_size); 636 632 637 633 sg_init_aead(sgout, xoutbuf, 638 - *b_size + (enc ? authsize : 0), assoc, 634 + bs + (enc ? authsize : 0), assoc, 639 635 aad_size); 640 636 641 637 aead_request_set_ad(req, aad_size); ··· 648 644 * reversed (input <-> output) to calculate it 649 645 */ 650 646 aead_request_set_crypt(req, sgout, sg, 651 - *b_size, iv); 647 + bs, iv); 652 648 ret = do_one_aead_op(req, 653 649 crypto_aead_encrypt(req)); 654 650 ··· 660 656 } 661 657 662 658 aead_request_set_crypt(req, sg, sgout, 663 - *b_size + (enc ? 0 : authsize), 659 + bs + (enc ? 0 : authsize), 664 660 iv); 665 661 666 662 if (secs) { 667 - ret = test_aead_jiffies(req, enc, *b_size, 663 + ret = test_aead_jiffies(req, enc, bs, 668 664 secs); 669 665 cond_resched(); 670 666 } else { 671 - ret = test_aead_cycles(req, enc, *b_size); 667 + ret = test_aead_cycles(req, enc, bs); 672 668 } 673 669 674 670 if (ret) { ··· 1257 1253 struct test_mb_skcipher_data *data; 1258 1254 struct crypto_skcipher *tfm; 1259 1255 unsigned int i, j, iv_len; 1256 + const int *b_size; 1260 1257 const char *key; 1261 1258 const char *e; 1262 - u32 *b_size; 1263 1259 char iv[128]; 1264 1260 int ret; 1265 1261 ··· 1320 1316 do { 1321 1317 b_size = block_sizes; 1322 1318 do { 1323 - if (*b_size > XBUFSIZE * PAGE_SIZE) { 1319 + u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm)); 1320 + 1321 + if (bs > XBUFSIZE * PAGE_SIZE) { 1324 1322 pr_err("template (%u) too big for buffer (%lu)\n", 1325 1323 *b_size, XBUFSIZE * PAGE_SIZE); 1326 1324 goto out; 1327 1325 } 1328 1326 1329 1327 pr_info("test %u (%d bit key, %d byte blocks): ", i, 1330 - *keysize * 8, *b_size); 1328 + *keysize * 8, bs); 1331 1329 1332 1330 /* Set up tfm global state, i.e. the key */ 1333 1331 ··· 1359 1353 1360 1354 for (j = 0; j < num_mb; ++j) { 1361 1355 struct test_mb_skcipher_data *cur = &data[j]; 1362 - unsigned int k = *b_size; 1356 + unsigned int k = bs; 1363 1357 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE); 1364 1358 unsigned int p = 0; 1365 1359 ··· 1383 1377 1384 1378 if (secs) { 1385 1379 ret = test_mb_acipher_jiffies(data, enc, 1386 - *b_size, secs, 1380 + bs, secs, 1387 1381 num_mb); 1388 1382 cond_resched(); 1389 1383 } else { 1390 1384 ret = test_mb_acipher_cycles(data, enc, 1391 - *b_size, num_mb); 1385 + bs, num_mb); 1392 1386 } 1393 1387 1394 1388 if (ret) { ··· 1503 1497 char iv[128]; 1504 1498 struct skcipher_request *req; 1505 1499 struct crypto_skcipher *tfm; 1500 + const int *b_size; 1506 1501 const char *e; 1507 - u32 *b_size; 1508 1502 1509 1503 if (enc == ENCRYPT) 1510 1504 e = "encryption"; ··· 1539 1533 b_size = block_sizes; 1540 1534 1541 1535 do { 1536 + u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm)); 1542 1537 struct scatterlist sg[TVMEMSIZE]; 1543 1538 1544 - if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { 1539 + if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) { 1545 1540 pr_err("template (%u) too big for " 1546 - "tvmem (%lu)\n", *keysize + *b_size, 1541 + "tvmem (%lu)\n", *keysize + bs, 1547 1542 TVMEMSIZE * PAGE_SIZE); 1548 1543 goto out_free_req; 1549 1544 } 1550 1545 1551 1546 pr_info("test %u (%d bit key, %d byte blocks): ", i, 1552 - *keysize * 8, *b_size); 1547 + *keysize * 8, bs); 1553 1548 1554 1549 memset(tvmem[0], 0xff, PAGE_SIZE); 1555 1550 ··· 1572 1565 goto out_free_req; 1573 1566 } 1574 1567 1575 - k = *keysize + *b_size; 1568 + k = *keysize + bs; 1576 1569 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE)); 1577 1570 1578 1571 if (k > PAGE_SIZE) { ··· 1589 1582 sg_set_buf(sg + j, tvmem[j], k); 1590 1583 memset(tvmem[j], 0xff, k); 1591 1584 } else { 1592 - sg_set_buf(sg, tvmem[0] + *keysize, *b_size); 1585 + sg_set_buf(sg, tvmem[0] + *keysize, bs); 1593 1586 } 1594 1587 1595 1588 iv_len = crypto_skcipher_ivsize(tfm); 1596 1589 if (iv_len) 1597 1590 memset(&iv, 0xff, iv_len); 1598 1591 1599 - skcipher_request_set_crypt(req, sg, sg, *b_size, iv); 1592 + skcipher_request_set_crypt(req, sg, sg, bs, iv); 1600 1593 1601 1594 if (secs) { 1602 1595 ret = test_acipher_jiffies(req, enc, 1603 - *b_size, secs); 1596 + bs, secs); 1604 1597 cond_resched(); 1605 1598 } else { 1606 1599 ret = test_acipher_cycles(req, enc, 1607 - *b_size); 1600 + bs); 1608 1601 } 1609 1602 1610 1603 if (ret) { ··· 3073 3066 */ 3074 3067 static void __exit tcrypt_mod_fini(void) { } 3075 3068 3076 - subsys_initcall(tcrypt_mod_init); 3069 + late_initcall(tcrypt_mod_init); 3077 3070 module_exit(tcrypt_mod_fini); 3078 3071 3079 3072 module_param(alg, charp, 0);
+67 -74
crypto/testmgr.c
··· 1171 1171 } 1172 1172 1173 1173 /* Test one hash test vector in one configuration, using the shash API */ 1174 - static int test_shash_vec_cfg(const char *driver, 1175 - const struct hash_testvec *vec, 1174 + static int test_shash_vec_cfg(const struct hash_testvec *vec, 1176 1175 const char *vec_name, 1177 1176 const struct testvec_config *cfg, 1178 1177 struct shash_desc *desc, ··· 1182 1183 const unsigned int alignmask = crypto_shash_alignmask(tfm); 1183 1184 const unsigned int digestsize = crypto_shash_digestsize(tfm); 1184 1185 const unsigned int statesize = crypto_shash_statesize(tfm); 1186 + const char *driver = crypto_shash_driver_name(tfm); 1185 1187 const struct test_sg_division *divs[XBUFSIZE]; 1186 1188 unsigned int i; 1187 1189 u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN]; ··· 1355 1355 } 1356 1356 1357 1357 /* Test one hash test vector in one configuration, using the ahash API */ 1358 - static int test_ahash_vec_cfg(const char *driver, 1359 - const struct hash_testvec *vec, 1358 + static int test_ahash_vec_cfg(const struct hash_testvec *vec, 1360 1359 const char *vec_name, 1361 1360 const struct testvec_config *cfg, 1362 1361 struct ahash_request *req, ··· 1366 1367 const unsigned int alignmask = crypto_ahash_alignmask(tfm); 1367 1368 const unsigned int digestsize = crypto_ahash_digestsize(tfm); 1368 1369 const unsigned int statesize = crypto_ahash_statesize(tfm); 1370 + const char *driver = crypto_ahash_driver_name(tfm); 1369 1371 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; 1370 1372 const struct test_sg_division *divs[XBUFSIZE]; 1371 1373 DECLARE_CRYPTO_WAIT(wait); ··· 1521 1521 driver, cfg); 1522 1522 } 1523 1523 1524 - static int test_hash_vec_cfg(const char *driver, 1525 - const struct hash_testvec *vec, 1524 + static int test_hash_vec_cfg(const struct hash_testvec *vec, 1526 1525 const char *vec_name, 1527 1526 const struct testvec_config *cfg, 1528 1527 struct ahash_request *req, ··· 1538 1539 */ 1539 1540 1540 1541 if (desc) { 1541 - err = test_shash_vec_cfg(driver, vec, vec_name, cfg, desc, tsgl, 1542 + err = test_shash_vec_cfg(vec, vec_name, cfg, desc, tsgl, 1542 1543 hashstate); 1543 1544 if (err) 1544 1545 return err; 1545 1546 } 1546 1547 1547 - return test_ahash_vec_cfg(driver, vec, vec_name, cfg, req, tsgl, 1548 - hashstate); 1548 + return test_ahash_vec_cfg(vec, vec_name, cfg, req, tsgl, hashstate); 1549 1549 } 1550 1550 1551 - static int test_hash_vec(const char *driver, const struct hash_testvec *vec, 1552 - unsigned int vec_num, struct ahash_request *req, 1553 - struct shash_desc *desc, struct test_sglist *tsgl, 1554 - u8 *hashstate) 1551 + static int test_hash_vec(const struct hash_testvec *vec, unsigned int vec_num, 1552 + struct ahash_request *req, struct shash_desc *desc, 1553 + struct test_sglist *tsgl, u8 *hashstate) 1555 1554 { 1556 1555 char vec_name[16]; 1557 1556 unsigned int i; ··· 1558 1561 sprintf(vec_name, "%u", vec_num); 1559 1562 1560 1563 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) { 1561 - err = test_hash_vec_cfg(driver, vec, vec_name, 1564 + err = test_hash_vec_cfg(vec, vec_name, 1562 1565 &default_hash_testvec_configs[i], 1563 1566 req, desc, tsgl, hashstate); 1564 1567 if (err) ··· 1573 1576 for (i = 0; i < fuzz_iterations; i++) { 1574 1577 generate_random_testvec_config(&cfg, cfgname, 1575 1578 sizeof(cfgname)); 1576 - err = test_hash_vec_cfg(driver, vec, vec_name, &cfg, 1579 + err = test_hash_vec_cfg(vec, vec_name, &cfg, 1577 1580 req, desc, tsgl, hashstate); 1578 1581 if (err) 1579 1582 return err; ··· 1630 1633 * Test the hash algorithm represented by @req against the corresponding generic 1631 1634 * implementation, if one is available. 1632 1635 */ 1633 - static int test_hash_vs_generic_impl(const char *driver, 1634 - const char *generic_driver, 1636 + static int test_hash_vs_generic_impl(const char *generic_driver, 1635 1637 unsigned int maxkeysize, 1636 1638 struct ahash_request *req, 1637 1639 struct shash_desc *desc, ··· 1642 1646 const unsigned int blocksize = crypto_ahash_blocksize(tfm); 1643 1647 const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; 1644 1648 const char *algname = crypto_hash_alg_common(tfm)->base.cra_name; 1649 + const char *driver = crypto_ahash_driver_name(tfm); 1645 1650 char _generic_driver[CRYPTO_MAX_ALG_NAME]; 1646 1651 struct crypto_shash *generic_tfm = NULL; 1647 1652 struct shash_desc *generic_desc = NULL; ··· 1729 1732 vec_name, sizeof(vec_name)); 1730 1733 generate_random_testvec_config(cfg, cfgname, sizeof(cfgname)); 1731 1734 1732 - err = test_hash_vec_cfg(driver, &vec, vec_name, cfg, 1735 + err = test_hash_vec_cfg(&vec, vec_name, cfg, 1733 1736 req, desc, tsgl, hashstate); 1734 1737 if (err) 1735 1738 goto out; ··· 1746 1749 return err; 1747 1750 } 1748 1751 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 1749 - static int test_hash_vs_generic_impl(const char *driver, 1750 - const char *generic_driver, 1752 + static int test_hash_vs_generic_impl(const char *generic_driver, 1751 1753 unsigned int maxkeysize, 1752 1754 struct ahash_request *req, 1753 1755 struct shash_desc *desc, ··· 1816 1820 driver, PTR_ERR(atfm)); 1817 1821 return PTR_ERR(atfm); 1818 1822 } 1823 + driver = crypto_ahash_driver_name(atfm); 1819 1824 1820 1825 req = ahash_request_alloc(atfm, GFP_KERNEL); 1821 1826 if (!req) { ··· 1856 1859 } 1857 1860 1858 1861 for (i = 0; i < num_vecs; i++) { 1859 - err = test_hash_vec(driver, &vecs[i], i, req, desc, tsgl, 1860 - hashstate); 1862 + err = test_hash_vec(&vecs[i], i, req, desc, tsgl, hashstate); 1861 1863 if (err) 1862 1864 goto out; 1863 1865 cond_resched(); 1864 1866 } 1865 - err = test_hash_vs_generic_impl(driver, generic_driver, maxkeysize, req, 1867 + err = test_hash_vs_generic_impl(generic_driver, maxkeysize, req, 1866 1868 desc, tsgl, hashstate); 1867 1869 out: 1868 1870 kfree(hashstate); ··· 1919 1923 return err; 1920 1924 } 1921 1925 1922 - static int test_aead_vec_cfg(const char *driver, int enc, 1923 - const struct aead_testvec *vec, 1926 + static int test_aead_vec_cfg(int enc, const struct aead_testvec *vec, 1924 1927 const char *vec_name, 1925 1928 const struct testvec_config *cfg, 1926 1929 struct aead_request *req, ··· 1929 1934 const unsigned int alignmask = crypto_aead_alignmask(tfm); 1930 1935 const unsigned int ivsize = crypto_aead_ivsize(tfm); 1931 1936 const unsigned int authsize = vec->clen - vec->plen; 1937 + const char *driver = crypto_aead_driver_name(tfm); 1932 1938 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; 1933 1939 const char *op = enc ? "encryption" : "decryption"; 1934 1940 DECLARE_CRYPTO_WAIT(wait); ··· 2102 2106 return 0; 2103 2107 } 2104 2108 2105 - static int test_aead_vec(const char *driver, int enc, 2106 - const struct aead_testvec *vec, unsigned int vec_num, 2107 - struct aead_request *req, 2109 + static int test_aead_vec(int enc, const struct aead_testvec *vec, 2110 + unsigned int vec_num, struct aead_request *req, 2108 2111 struct cipher_test_sglists *tsgls) 2109 2112 { 2110 2113 char vec_name[16]; ··· 2116 2121 sprintf(vec_name, "%u", vec_num); 2117 2122 2118 2123 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) { 2119 - err = test_aead_vec_cfg(driver, enc, vec, vec_name, 2124 + err = test_aead_vec_cfg(enc, vec, vec_name, 2120 2125 &default_cipher_testvec_configs[i], 2121 2126 req, tsgls); 2122 2127 if (err) ··· 2131 2136 for (i = 0; i < fuzz_iterations; i++) { 2132 2137 generate_random_testvec_config(&cfg, cfgname, 2133 2138 sizeof(cfgname)); 2134 - err = test_aead_vec_cfg(driver, enc, vec, vec_name, 2139 + err = test_aead_vec_cfg(enc, vec, vec_name, 2135 2140 &cfg, req, tsgls); 2136 2141 if (err) 2137 2142 return err; ··· 2147 2152 struct aead_extra_tests_ctx { 2148 2153 struct aead_request *req; 2149 2154 struct crypto_aead *tfm; 2150 - const char *driver; 2151 2155 const struct alg_test_desc *test_desc; 2152 2156 struct cipher_test_sglists *tsgls; 2153 2157 unsigned int maxdatasize; ··· 2352 2358 if (ctx->vec.novrfy) { 2353 2359 generate_random_testvec_config(&ctx->cfg, ctx->cfgname, 2354 2360 sizeof(ctx->cfgname)); 2355 - err = test_aead_vec_cfg(ctx->driver, DECRYPT, &ctx->vec, 2361 + err = test_aead_vec_cfg(DECRYPT, &ctx->vec, 2356 2362 ctx->vec_name, &ctx->cfg, 2357 2363 ctx->req, ctx->tsgls); 2358 2364 if (err) ··· 2371 2377 { 2372 2378 struct crypto_aead *tfm = ctx->tfm; 2373 2379 const char *algname = crypto_aead_alg(tfm)->base.cra_name; 2374 - const char *driver = ctx->driver; 2380 + const char *driver = crypto_aead_driver_name(tfm); 2375 2381 const char *generic_driver = ctx->test_desc->generic_driver; 2376 2382 char _generic_driver[CRYPTO_MAX_ALG_NAME]; 2377 2383 struct crypto_aead *generic_tfm = NULL; ··· 2448 2454 generate_random_testvec_config(&ctx->cfg, ctx->cfgname, 2449 2455 sizeof(ctx->cfgname)); 2450 2456 if (!ctx->vec.novrfy) { 2451 - err = test_aead_vec_cfg(driver, ENCRYPT, &ctx->vec, 2457 + err = test_aead_vec_cfg(ENCRYPT, &ctx->vec, 2452 2458 ctx->vec_name, &ctx->cfg, 2453 2459 ctx->req, ctx->tsgls); 2454 2460 if (err) 2455 2461 goto out; 2456 2462 } 2457 2463 if (ctx->vec.crypt_error == 0 || ctx->vec.novrfy) { 2458 - err = test_aead_vec_cfg(driver, DECRYPT, &ctx->vec, 2464 + err = test_aead_vec_cfg(DECRYPT, &ctx->vec, 2459 2465 ctx->vec_name, &ctx->cfg, 2460 2466 ctx->req, ctx->tsgls); 2461 2467 if (err) ··· 2470 2476 return err; 2471 2477 } 2472 2478 2473 - static int test_aead_extra(const char *driver, 2474 - const struct alg_test_desc *test_desc, 2479 + static int test_aead_extra(const struct alg_test_desc *test_desc, 2475 2480 struct aead_request *req, 2476 2481 struct cipher_test_sglists *tsgls) 2477 2482 { ··· 2486 2493 return -ENOMEM; 2487 2494 ctx->req = req; 2488 2495 ctx->tfm = crypto_aead_reqtfm(req); 2489 - ctx->driver = driver; 2490 2496 ctx->test_desc = test_desc; 2491 2497 ctx->tsgls = tsgls; 2492 2498 ctx->maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; ··· 2520 2528 return err; 2521 2529 } 2522 2530 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 2523 - static int test_aead_extra(const char *driver, 2524 - const struct alg_test_desc *test_desc, 2531 + static int test_aead_extra(const struct alg_test_desc *test_desc, 2525 2532 struct aead_request *req, 2526 2533 struct cipher_test_sglists *tsgls) 2527 2534 { ··· 2528 2537 } 2529 2538 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 2530 2539 2531 - static int test_aead(const char *driver, int enc, 2532 - const struct aead_test_suite *suite, 2540 + static int test_aead(int enc, const struct aead_test_suite *suite, 2533 2541 struct aead_request *req, 2534 2542 struct cipher_test_sglists *tsgls) 2535 2543 { ··· 2536 2546 int err; 2537 2547 2538 2548 for (i = 0; i < suite->count; i++) { 2539 - err = test_aead_vec(driver, enc, &suite->vecs[i], i, req, 2540 - tsgls); 2549 + err = test_aead_vec(enc, &suite->vecs[i], i, req, tsgls); 2541 2550 if (err) 2542 2551 return err; 2543 2552 cond_resched(); ··· 2564 2575 driver, PTR_ERR(tfm)); 2565 2576 return PTR_ERR(tfm); 2566 2577 } 2578 + driver = crypto_aead_driver_name(tfm); 2567 2579 2568 2580 req = aead_request_alloc(tfm, GFP_KERNEL); 2569 2581 if (!req) { ··· 2582 2592 goto out; 2583 2593 } 2584 2594 2585 - err = test_aead(driver, ENCRYPT, suite, req, tsgls); 2595 + err = test_aead(ENCRYPT, suite, req, tsgls); 2586 2596 if (err) 2587 2597 goto out; 2588 2598 2589 - err = test_aead(driver, DECRYPT, suite, req, tsgls); 2599 + err = test_aead(DECRYPT, suite, req, tsgls); 2590 2600 if (err) 2591 2601 goto out; 2592 2602 2593 - err = test_aead_extra(driver, desc, req, tsgls); 2603 + err = test_aead_extra(desc, req, tsgls); 2594 2604 out: 2595 2605 free_cipher_test_sglists(tsgls); 2596 2606 aead_request_free(req); ··· 2685 2695 return ret; 2686 2696 } 2687 2697 2688 - static int test_skcipher_vec_cfg(const char *driver, int enc, 2689 - const struct cipher_testvec *vec, 2698 + static int test_skcipher_vec_cfg(int enc, const struct cipher_testvec *vec, 2690 2699 const char *vec_name, 2691 2700 const struct testvec_config *cfg, 2692 2701 struct skcipher_request *req, ··· 2694 2705 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 2695 2706 const unsigned int alignmask = crypto_skcipher_alignmask(tfm); 2696 2707 const unsigned int ivsize = crypto_skcipher_ivsize(tfm); 2708 + const char *driver = crypto_skcipher_driver_name(tfm); 2697 2709 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; 2698 2710 const char *op = enc ? "encryption" : "decryption"; 2699 2711 DECLARE_CRYPTO_WAIT(wait); ··· 2849 2859 return 0; 2850 2860 } 2851 2861 2852 - static int test_skcipher_vec(const char *driver, int enc, 2853 - const struct cipher_testvec *vec, 2862 + static int test_skcipher_vec(int enc, const struct cipher_testvec *vec, 2854 2863 unsigned int vec_num, 2855 2864 struct skcipher_request *req, 2856 2865 struct cipher_test_sglists *tsgls) ··· 2864 2875 sprintf(vec_name, "%u", vec_num); 2865 2876 2866 2877 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) { 2867 - err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, 2878 + err = test_skcipher_vec_cfg(enc, vec, vec_name, 2868 2879 &default_cipher_testvec_configs[i], 2869 2880 req, tsgls); 2870 2881 if (err) ··· 2879 2890 for (i = 0; i < fuzz_iterations; i++) { 2880 2891 generate_random_testvec_config(&cfg, cfgname, 2881 2892 sizeof(cfgname)); 2882 - err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, 2893 + err = test_skcipher_vec_cfg(enc, vec, vec_name, 2883 2894 &cfg, req, tsgls); 2884 2895 if (err) 2885 2896 return err; ··· 2950 2961 * Test the skcipher algorithm represented by @req against the corresponding 2951 2962 * generic implementation, if one is available. 2952 2963 */ 2953 - static int test_skcipher_vs_generic_impl(const char *driver, 2954 - const char *generic_driver, 2964 + static int test_skcipher_vs_generic_impl(const char *generic_driver, 2955 2965 struct skcipher_request *req, 2956 2966 struct cipher_test_sglists *tsgls) 2957 2967 { ··· 2960 2972 const unsigned int blocksize = crypto_skcipher_blocksize(tfm); 2961 2973 const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; 2962 2974 const char *algname = crypto_skcipher_alg(tfm)->base.cra_name; 2975 + const char *driver = crypto_skcipher_driver_name(tfm); 2963 2976 char _generic_driver[CRYPTO_MAX_ALG_NAME]; 2964 2977 struct crypto_skcipher *generic_tfm = NULL; 2965 2978 struct skcipher_request *generic_req = NULL; ··· 3066 3077 vec_name, sizeof(vec_name)); 3067 3078 generate_random_testvec_config(cfg, cfgname, sizeof(cfgname)); 3068 3079 3069 - err = test_skcipher_vec_cfg(driver, ENCRYPT, &vec, vec_name, 3080 + err = test_skcipher_vec_cfg(ENCRYPT, &vec, vec_name, 3070 3081 cfg, req, tsgls); 3071 3082 if (err) 3072 3083 goto out; 3073 - err = test_skcipher_vec_cfg(driver, DECRYPT, &vec, vec_name, 3084 + err = test_skcipher_vec_cfg(DECRYPT, &vec, vec_name, 3074 3085 cfg, req, tsgls); 3075 3086 if (err) 3076 3087 goto out; ··· 3088 3099 return err; 3089 3100 } 3090 3101 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 3091 - static int test_skcipher_vs_generic_impl(const char *driver, 3092 - const char *generic_driver, 3102 + static int test_skcipher_vs_generic_impl(const char *generic_driver, 3093 3103 struct skcipher_request *req, 3094 3104 struct cipher_test_sglists *tsgls) 3095 3105 { ··· 3096 3108 } 3097 3109 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 3098 3110 3099 - static int test_skcipher(const char *driver, int enc, 3100 - const struct cipher_test_suite *suite, 3111 + static int test_skcipher(int enc, const struct cipher_test_suite *suite, 3101 3112 struct skcipher_request *req, 3102 3113 struct cipher_test_sglists *tsgls) 3103 3114 { ··· 3104 3117 int err; 3105 3118 3106 3119 for (i = 0; i < suite->count; i++) { 3107 - err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req, 3108 - tsgls); 3120 + err = test_skcipher_vec(enc, &suite->vecs[i], i, req, tsgls); 3109 3121 if (err) 3110 3122 return err; 3111 3123 cond_resched(); ··· 3132 3146 driver, PTR_ERR(tfm)); 3133 3147 return PTR_ERR(tfm); 3134 3148 } 3149 + driver = crypto_skcipher_driver_name(tfm); 3135 3150 3136 3151 req = skcipher_request_alloc(tfm, GFP_KERNEL); 3137 3152 if (!req) { ··· 3150 3163 goto out; 3151 3164 } 3152 3165 3153 - err = test_skcipher(driver, ENCRYPT, suite, req, tsgls); 3166 + err = test_skcipher(ENCRYPT, suite, req, tsgls); 3154 3167 if (err) 3155 3168 goto out; 3156 3169 3157 - err = test_skcipher(driver, DECRYPT, suite, req, tsgls); 3170 + err = test_skcipher(DECRYPT, suite, req, tsgls); 3158 3171 if (err) 3159 3172 goto out; 3160 3173 3161 - err = test_skcipher_vs_generic_impl(driver, desc->generic_driver, req, 3162 - tsgls); 3174 + err = test_skcipher_vs_generic_impl(desc->generic_driver, req, tsgls); 3163 3175 out: 3164 3176 free_cipher_test_sglists(tsgls); 3165 3177 skcipher_request_free(req); ··· 3588 3602 "%ld\n", driver, PTR_ERR(tfm)); 3589 3603 return PTR_ERR(tfm); 3590 3604 } 3605 + driver = crypto_shash_driver_name(tfm); 3591 3606 3592 3607 do { 3593 3608 SHASH_DESC_ON_STACK(shash, tfm); ··· 5664 5677 type, mask); 5665 5678 5666 5679 test_done: 5667 - if (rc && (fips_enabled || panic_on_fail)) { 5668 - fips_fail_notify(); 5669 - panic("alg: self-tests for %s (%s) failed in %s mode!\n", 5670 - driver, alg, fips_enabled ? "fips" : "panic_on_fail"); 5680 + if (rc) { 5681 + if (fips_enabled || panic_on_fail) { 5682 + fips_fail_notify(); 5683 + panic("alg: self-tests for %s (%s) failed in %s mode!\n", 5684 + driver, alg, 5685 + fips_enabled ? "fips" : "panic_on_fail"); 5686 + } 5687 + WARN(1, "alg: self-tests for %s (%s) failed (rc=%d)", 5688 + driver, alg, rc); 5689 + } else { 5690 + if (fips_enabled) 5691 + pr_info("alg: self-tests for %s (%s) passed\n", 5692 + driver, alg); 5671 5693 } 5672 - 5673 - if (fips_enabled && !rc) 5674 - pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); 5675 5694 5676 5695 return rc; 5677 5696
+1 -13
drivers/char/hw_random/Kconfig
··· 348 348 349 349 If unsure, say Y. 350 350 351 - config HW_RANDOM_HISI_V2 352 - tristate "HiSilicon True Random Number Generator V2 support" 353 - depends on HW_RANDOM && ARM64 && ACPI 354 - default HW_RANDOM 355 - help 356 - This driver provides kernel-side support for the True Random Number 357 - Generator V2 hardware found on HiSilicon Hi1620 SoC. 358 - 359 - To compile this driver as a module, choose M here: the 360 - module will be called hisi-trng-v2. 361 - 362 - If unsure, say Y. 363 - 364 351 config HW_RANDOM_ST 365 352 tristate "ST Microelectronics HW Random Number Generator support" 366 353 depends on HW_RANDOM && ARCH_STI ··· 495 508 496 509 config HW_RANDOM_KEYSTONE 497 510 depends on ARCH_KEYSTONE || COMPILE_TEST 511 + depends on HAS_IOMEM && OF 498 512 default HW_RANDOM 499 513 tristate "TI Keystone NETCP SA Hardware random number generator" 500 514 help
-1
drivers/char/hw_random/Makefile
··· 30 30 obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o 31 31 obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o 32 32 obj-$(CONFIG_HW_RANDOM_HISI) += hisi-rng.o 33 - obj-$(CONFIG_HW_RANDOM_HISI_V2) += hisi-trng-v2.o 34 33 obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o 35 34 obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o 36 35 obj-$(CONFIG_HW_RANDOM_ST) += st-rng.o
-99
drivers/char/hw_random/hisi-trng-v2.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* Copyright (c) 2019 HiSilicon Limited. */ 3 - 4 - #include <linux/acpi.h> 5 - #include <linux/err.h> 6 - #include <linux/hw_random.h> 7 - #include <linux/io.h> 8 - #include <linux/iopoll.h> 9 - #include <linux/kernel.h> 10 - #include <linux/module.h> 11 - #include <linux/platform_device.h> 12 - #include <linux/random.h> 13 - 14 - #define HISI_TRNG_REG 0x00F0 15 - #define HISI_TRNG_BYTES 4 16 - #define HISI_TRNG_QUALITY 512 17 - #define SLEEP_US 10 18 - #define TIMEOUT_US 10000 19 - 20 - struct hisi_trng { 21 - void __iomem *base; 22 - struct hwrng rng; 23 - }; 24 - 25 - static int hisi_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) 26 - { 27 - struct hisi_trng *trng; 28 - int currsize = 0; 29 - u32 val = 0; 30 - u32 ret; 31 - 32 - trng = container_of(rng, struct hisi_trng, rng); 33 - 34 - do { 35 - ret = readl_poll_timeout(trng->base + HISI_TRNG_REG, val, 36 - val, SLEEP_US, TIMEOUT_US); 37 - if (ret) 38 - return currsize; 39 - 40 - if (max - currsize >= HISI_TRNG_BYTES) { 41 - memcpy(buf + currsize, &val, HISI_TRNG_BYTES); 42 - currsize += HISI_TRNG_BYTES; 43 - if (currsize == max) 44 - return currsize; 45 - continue; 46 - } 47 - 48 - /* copy remaining bytes */ 49 - memcpy(buf + currsize, &val, max - currsize); 50 - currsize = max; 51 - } while (currsize < max); 52 - 53 - return currsize; 54 - } 55 - 56 - static int hisi_trng_probe(struct platform_device *pdev) 57 - { 58 - struct hisi_trng *trng; 59 - int ret; 60 - 61 - trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); 62 - if (!trng) 63 - return -ENOMEM; 64 - 65 - trng->base = devm_platform_ioremap_resource(pdev, 0); 66 - if (IS_ERR(trng->base)) 67 - return PTR_ERR(trng->base); 68 - 69 - trng->rng.name = pdev->name; 70 - trng->rng.read = hisi_trng_read; 71 - trng->rng.quality = HISI_TRNG_QUALITY; 72 - 73 - ret = devm_hwrng_register(&pdev->dev, &trng->rng); 74 - if (ret) 75 - dev_err(&pdev->dev, "failed to register hwrng!\n"); 76 - 77 - return ret; 78 - } 79 - 80 - static const struct acpi_device_id hisi_trng_acpi_match[] = { 81 - { "HISI02B3", 0 }, 82 - { } 83 - }; 84 - MODULE_DEVICE_TABLE(acpi, hisi_trng_acpi_match); 85 - 86 - static struct platform_driver hisi_trng_driver = { 87 - .probe = hisi_trng_probe, 88 - .driver = { 89 - .name = "hisi-trng-v2", 90 - .acpi_match_table = ACPI_PTR(hisi_trng_acpi_match), 91 - }, 92 - }; 93 - 94 - module_platform_driver(hisi_trng_driver); 95 - 96 - MODULE_LICENSE("GPL v2"); 97 - MODULE_AUTHOR("Weili Qian <qianweili@huawei.com>"); 98 - MODULE_AUTHOR("Zaibo Xu <xuzaibo@huawei.com>"); 99 - MODULE_DESCRIPTION("HiSilicon true random number generator V2 driver");
+1 -3
drivers/char/hw_random/imx-rngc.c
··· 252 252 } 253 253 254 254 irq = platform_get_irq(pdev, 0); 255 - if (irq <= 0) { 256 - dev_err(&pdev->dev, "Couldn't get irq %d\n", irq); 255 + if (irq < 0) 257 256 return irq; 258 - } 259 257 260 258 ret = clk_prepare_enable(rngc->clk); 261 259 if (ret)
+1 -1
drivers/char/random.c
··· 336 336 #include <linux/completion.h> 337 337 #include <linux/uuid.h> 338 338 #include <crypto/chacha.h> 339 - #include <crypto/sha.h> 339 + #include <crypto/sha1.h> 340 340 341 341 #include <asm/processor.h> 342 342 #include <linux/uaccess.h>
+4 -1
drivers/crypto/Kconfig
··· 548 548 549 549 config CRYPTO_DEV_ATMEL_I2C 550 550 tristate 551 + select BITREVERSE 551 552 552 553 config CRYPTO_DEV_ATMEL_ECC 553 554 tristate "Support for Microchip / Atmel ECC hw accelerator" ··· 649 648 default CRYPTO_DEV_QCE_ENABLE_ALL 650 649 depends on CRYPTO_DEV_QCE 651 650 help 652 - This option allows to choose whether to build support for all algorihtms 651 + This option allows to choose whether to build support for all algorithms 653 652 (default), hashes-only, or skciphers-only. 654 653 655 654 The QCE engine does not appear to scale as well as the CPU to handle ··· 900 899 K3 devices include a security accelerator engine that may be 901 900 used for crypto offload. Select this if you want to use hardware 902 901 acceleration for cryptographic algorithms on these devices. 902 + 903 + source "drivers/crypto/keembay/Kconfig" 903 904 904 905 endif # CRYPTO_HW
+1
drivers/crypto/Makefile
··· 51 51 obj-$(CONFIG_CRYPTO_DEV_ZYNQMP_AES) += xilinx/ 52 52 obj-y += hisilicon/ 53 53 obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/ 54 + obj-y += keembay/
+1 -1
drivers/crypto/allwinner/Kconfig
··· 43 43 depends on CRYPTO_DEV_ALLWINNER 44 44 depends on PM 45 45 help 46 - Select y here to have support for the crypto Engine availlable on 46 + Select y here to have support for the crypto Engine available on 47 47 Allwinner SoC H2+, H3, H5, H6, R40 and A64. 48 48 The Crypto Engine handle AES/3DES ciphers in ECB/CBC mode. 49 49
+1 -1
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
··· 25 25 #include <linux/pm_runtime.h> 26 26 #include <crypto/md5.h> 27 27 #include <crypto/skcipher.h> 28 - #include <crypto/sha.h> 28 + #include <crypto/sha1.h> 29 29 #include <crypto/hash.h> 30 30 #include <crypto/internal/hash.h> 31 31 #include <crypto/internal/skcipher.h>
+14 -9
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
··· 13 13 #include <linux/pm_runtime.h> 14 14 #include <linux/scatterlist.h> 15 15 #include <crypto/internal/hash.h> 16 - #include <crypto/sha.h> 16 + #include <crypto/sha1.h> 17 + #include <crypto/sha2.h> 17 18 #include <crypto/md5.h> 18 19 #include "sun8i-ce.h" 19 20 ··· 263 262 u32 common; 264 263 u64 byte_count; 265 264 __le32 *bf; 266 - void *buf; 265 + void *buf = NULL; 267 266 int j, i, todo; 268 267 int nbw = 0; 269 268 u64 fill, min_fill; 270 269 __be64 *bebits; 271 270 __le64 *lebits; 272 - void *result; 271 + void *result = NULL; 273 272 u64 bs; 274 273 int digestsize; 275 274 dma_addr_t addr_res, addr_pad; ··· 286 285 287 286 /* the padding could be up to two block. */ 288 287 buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA); 289 - if (!buf) 290 - return -ENOMEM; 288 + if (!buf) { 289 + err = -ENOMEM; 290 + goto theend; 291 + } 291 292 bf = (__le32 *)buf; 292 293 293 294 result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); 294 - if (!result) 295 - return -ENOMEM; 295 + if (!result) { 296 + err = -ENOMEM; 297 + goto theend; 298 + } 296 299 297 300 flow = rctx->flow; 298 301 chan = &ce->chanlist[flow]; ··· 408 403 dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 409 404 dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE); 410 405 411 - kfree(buf); 412 406 413 407 memcpy(areq->result, result, algt->alg.hash.halg.digestsize); 414 - kfree(result); 415 408 theend: 409 + kfree(buf); 410 + kfree(result); 416 411 crypto_finalize_hash_request(engine, breq, err); 417 412 return 0; 418 413 }
+2 -1
drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
··· 16 16 #include <crypto/internal/hash.h> 17 17 #include <crypto/md5.h> 18 18 #include <crypto/rng.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha1.h> 20 + #include <crypto/sha2.h> 20 21 21 22 /* CE Registers */ 22 23 #define CE_TDQ 0x00
+2 -1
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
··· 13 13 #include <linux/pm_runtime.h> 14 14 #include <linux/scatterlist.h> 15 15 #include <crypto/internal/hash.h> 16 - #include <crypto/sha.h> 16 + #include <crypto/sha1.h> 17 + #include <crypto/sha2.h> 17 18 #include <crypto/md5.h> 18 19 #include "sun8i-ss.h" 19 20
+2 -1
drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h
··· 15 15 #include <linux/crypto.h> 16 16 #include <crypto/internal/hash.h> 17 17 #include <crypto/md5.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha1.h> 19 + #include <crypto/sha2.h> 19 20 20 21 #define SS_START 1 21 22
+1 -1
drivers/crypto/amcc/crypto4xx_alg.c
··· 20 20 #include <crypto/aead.h> 21 21 #include <crypto/aes.h> 22 22 #include <crypto/gcm.h> 23 - #include <crypto/sha.h> 23 + #include <crypto/sha1.h> 24 24 #include <crypto/ctr.h> 25 25 #include <crypto/skcipher.h> 26 26 #include "crypto4xx_reg_def.h"
+2 -2
drivers/crypto/amcc/crypto4xx_core.c
··· 30 30 #include <crypto/aes.h> 31 31 #include <crypto/ctr.h> 32 32 #include <crypto/gcm.h> 33 - #include <crypto/sha.h> 33 + #include <crypto/sha1.h> 34 34 #include <crypto/rng.h> 35 35 #include <crypto/scatterwalk.h> 36 36 #include <crypto/skcipher.h> ··· 917 917 } 918 918 919 919 pd->pd_ctl.w = PD_CTL_HOST_READY | 920 - ((crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AHASH) | 920 + ((crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AHASH) || 921 921 (crypto_tfm_alg_type(req->tfm) == CRYPTO_ALG_TYPE_AEAD) ? 922 922 PD_CTL_HASH_FINAL : 0); 923 923 pd->pd_ctl_len.w = 0x00400000 | (assoclen + datalen);
+2 -1
drivers/crypto/atmel-authenc.h
··· 16 16 17 17 #include <crypto/authenc.h> 18 18 #include <crypto/hash.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha1.h> 20 + #include <crypto/sha2.h> 20 21 #include "atmel-sha-regs.h" 21 22 22 23 struct atmel_aes_dev;
+2 -2
drivers/crypto/atmel-sha.c
··· 33 33 #include <linux/crypto.h> 34 34 #include <crypto/scatterwalk.h> 35 35 #include <crypto/algapi.h> 36 - #include <crypto/sha.h> 36 + #include <crypto/sha1.h> 37 + #include <crypto/sha2.h> 37 38 #include <crypto/hash.h> 38 39 #include <crypto/internal/hash.h> 39 40 #include "atmel-sha-regs.h" ··· 460 459 break; 461 460 default: 462 461 return -EINVAL; 463 - break; 464 462 } 465 463 466 464 ctx->bufcnt = 0;
+2 -1
drivers/crypto/axis/artpec6_crypto.c
··· 28 28 #include <crypto/internal/hash.h> 29 29 #include <crypto/internal/skcipher.h> 30 30 #include <crypto/scatterwalk.h> 31 - #include <crypto/sha.h> 31 + #include <crypto/sha1.h> 32 + #include <crypto/sha2.h> 32 33 #include <crypto/xts.h> 33 34 34 35 /* Max length of a line in all cache levels for Artpec SoCs. */
+2 -1
drivers/crypto/bcm/cipher.c
··· 26 26 #include <crypto/aes.h> 27 27 #include <crypto/internal/des.h> 28 28 #include <crypto/hmac.h> 29 - #include <crypto/sha.h> 30 29 #include <crypto/md5.h> 31 30 #include <crypto/authenc.h> 32 31 #include <crypto/skcipher.h> 33 32 #include <crypto/hash.h> 33 + #include <crypto/sha1.h> 34 + #include <crypto/sha2.h> 34 35 #include <crypto/sha3.h> 35 36 36 37 #include "util.h"
+2 -1
drivers/crypto/bcm/cipher.h
··· 16 16 #include <crypto/aead.h> 17 17 #include <crypto/arc4.h> 18 18 #include <crypto/gcm.h> 19 - #include <crypto/sha.h> 19 + #include <crypto/sha1.h> 20 + #include <crypto/sha2.h> 20 21 #include <crypto/sha3.h> 21 22 22 23 #include "spu.h"
+2 -1
drivers/crypto/bcm/spu.h
··· 17 17 18 18 #include <linux/types.h> 19 19 #include <linux/scatterlist.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha1.h> 21 + #include <crypto/sha2.h> 21 22 22 23 enum spu_cipher_alg { 23 24 CIPHER_ALG_NONE = 0x0,
+2 -2
drivers/crypto/caam/caamalg.c
··· 3404 3404 fallback = crypto_alloc_skcipher(tfm_name, 0, 3405 3405 CRYPTO_ALG_NEED_FALLBACK); 3406 3406 if (IS_ERR(fallback)) { 3407 - dev_err(ctx->jrdev, "Failed to allocate %s fallback: %ld\n", 3408 - tfm_name, PTR_ERR(fallback)); 3407 + pr_err("Failed to allocate %s fallback: %ld\n", 3408 + tfm_name, PTR_ERR(fallback)); 3409 3409 return PTR_ERR(fallback); 3410 3410 } 3411 3411
+6 -6
drivers/crypto/caam/caamalg_qi.c
··· 852 852 853 853 cpu = smp_processor_id(); 854 854 drv_ctx = caam_drv_ctx_init(ctx->qidev, &cpu, desc); 855 - if (!IS_ERR_OR_NULL(drv_ctx)) 855 + if (!IS_ERR(drv_ctx)) 856 856 drv_ctx->op_type = type; 857 857 858 858 ctx->drv_ctx[type] = drv_ctx; ··· 955 955 struct caam_drv_ctx *drv_ctx; 956 956 957 957 drv_ctx = get_drv_ctx(ctx, encrypt ? ENCRYPT : DECRYPT); 958 - if (IS_ERR_OR_NULL(drv_ctx)) 958 + if (IS_ERR(drv_ctx)) 959 959 return (struct aead_edesc *)drv_ctx; 960 960 961 961 /* allocate space for base edesc and hw desc commands, link tables */ ··· 1165 1165 1166 1166 /* allocate extended descriptor */ 1167 1167 edesc = aead_edesc_alloc(req, encrypt); 1168 - if (IS_ERR_OR_NULL(edesc)) 1168 + if (IS_ERR(edesc)) 1169 1169 return PTR_ERR(edesc); 1170 1170 1171 1171 /* Create and submit job descriptor */ ··· 1259 1259 struct caam_drv_ctx *drv_ctx; 1260 1260 1261 1261 drv_ctx = get_drv_ctx(ctx, encrypt ? ENCRYPT : DECRYPT); 1262 - if (IS_ERR_OR_NULL(drv_ctx)) 1262 + if (IS_ERR(drv_ctx)) 1263 1263 return (struct skcipher_edesc *)drv_ctx; 1264 1264 1265 1265 src_nents = sg_nents_for_len(req->src, req->cryptlen); ··· 2502 2502 fallback = crypto_alloc_skcipher(tfm_name, 0, 2503 2503 CRYPTO_ALG_NEED_FALLBACK); 2504 2504 if (IS_ERR(fallback)) { 2505 - dev_err(ctx->jrdev, "Failed to allocate %s fallback: %ld\n", 2506 - tfm_name, PTR_ERR(fallback)); 2505 + pr_err("Failed to allocate %s fallback: %ld\n", 2506 + tfm_name, PTR_ERR(fallback)); 2507 2507 return PTR_ERR(fallback); 2508 2508 } 2509 2509
+2 -1
drivers/crypto/caam/caamalg_qi2.c
··· 1611 1611 fallback = crypto_alloc_skcipher(tfm_name, 0, 1612 1612 CRYPTO_ALG_NEED_FALLBACK); 1613 1613 if (IS_ERR(fallback)) { 1614 - dev_err(ctx->dev, "Failed to allocate %s fallback: %ld\n", 1614 + dev_err(caam_alg->caam.dev, 1615 + "Failed to allocate %s fallback: %ld\n", 1615 1616 tfm_name, PTR_ERR(fallback)); 1616 1617 return PTR_ERR(fallback); 1617 1618 }
+2 -1
drivers/crypto/caam/compat.h
··· 34 34 #include <crypto/ctr.h> 35 35 #include <crypto/internal/des.h> 36 36 #include <crypto/gcm.h> 37 - #include <crypto/sha.h> 37 + #include <crypto/sha1.h> 38 + #include <crypto/sha2.h> 38 39 #include <crypto/md5.h> 39 40 #include <crypto/chacha.h> 40 41 #include <crypto/poly1305.h>
+8
drivers/crypto/caam/intern.h
··· 16 16 /* Currently comes from Kconfig param as a ^2 (driver-required) */ 17 17 #define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE) 18 18 19 + /* 20 + * Maximum size for crypto-engine software queue based on Job Ring 21 + * size (JOBR_DEPTH) and a THRESHOLD (reserved for the non-crypto-API 22 + * requests that are not passed through crypto-engine) 23 + */ 24 + #define THRESHOLD 15 25 + #define CRYPTO_ENGINE_MAX_QLEN (JOBR_DEPTH - THRESHOLD) 26 + 19 27 /* Kconfig params for interrupt coalescing if selected (else zero) */ 20 28 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_INTC 21 29 #define JOBR_INTC JRCFG_ICEN
+3 -1
drivers/crypto/caam/jr.c
··· 550 550 } 551 551 552 552 /* Initialize crypto engine */ 553 - jrpriv->engine = crypto_engine_alloc_init(jrdev, false); 553 + jrpriv->engine = crypto_engine_alloc_init_and_set(jrdev, true, NULL, 554 + false, 555 + CRYPTO_ENGINE_MAX_QLEN); 554 556 if (!jrpriv->engine) { 555 557 dev_err(jrdev, "Could not init crypto-engine\n"); 556 558 return -ENOMEM;
+5 -11
drivers/crypto/cavium/cpt/cptpf_main.c
··· 244 244 245 245 struct ucode_header { 246 246 u8 version[CPT_UCODE_VERSION_SZ]; 247 - u32 code_length; 247 + __be32 code_length; 248 248 u32 data_length; 249 249 u64 sram_address; 250 250 }; ··· 288 288 289 289 /* Byte swap 64-bit */ 290 290 for (j = 0; j < (mcode->code_size / 8); j++) 291 - ((u64 *)mcode->code)[j] = cpu_to_be64(((u64 *)mcode->code)[j]); 291 + ((__be64 *)mcode->code)[j] = cpu_to_be64(((u64 *)mcode->code)[j]); 292 292 /* MC needs 16-bit swap */ 293 293 for (j = 0; j < (mcode->code_size / 2); j++) 294 - ((u16 *)mcode->code)[j] = cpu_to_be16(((u16 *)mcode->code)[j]); 294 + ((__be16 *)mcode->code)[j] = cpu_to_be16(((u16 *)mcode->code)[j]); 295 295 296 296 dev_dbg(dev, "mcode->code_size = %u\n", mcode->code_size); 297 297 dev_dbg(dev, "mcode->is_ae = %u\n", mcode->is_ae); ··· 569 569 goto cpt_err_disable_device; 570 570 } 571 571 572 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48)); 572 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); 573 573 if (err) { 574 - dev_err(dev, "Unable to get usable DMA configuration\n"); 575 - goto cpt_err_release_regions; 576 - } 577 - 578 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48)); 579 - if (err) { 580 - dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n"); 574 + dev_err(dev, "Unable to get usable 48-bit DMA configuration\n"); 581 575 goto cpt_err_release_regions; 582 576 } 583 577
+2 -8
drivers/crypto/cavium/cpt/cptvf_main.c
··· 687 687 } 688 688 /* Mark as VF driver */ 689 689 cptvf->flags |= CPT_FLAG_VF_DRIVER; 690 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48)); 690 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); 691 691 if (err) { 692 - dev_err(dev, "Unable to get usable DMA configuration\n"); 693 - goto cptvf_err_release_regions; 694 - } 695 - 696 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48)); 697 - if (err) { 698 - dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n"); 692 + dev_err(dev, "Unable to get usable 48-bit DMA configuration\n"); 699 693 goto cptvf_err_release_regions; 700 694 } 701 695
+5 -6
drivers/crypto/cavium/nitrox/nitrox_aead.c
··· 7 7 #include <crypto/aead.h> 8 8 #include <crypto/authenc.h> 9 9 #include <crypto/des.h> 10 - #include <crypto/sha.h> 11 10 #include <crypto/internal/aead.h> 12 11 #include <crypto/scatterwalk.h> 13 12 #include <crypto/gcm.h> ··· 44 45 45 46 /* fill crypto context */ 46 47 fctx = nctx->u.fctx; 47 - flags.f = be64_to_cpu(fctx->flags.f); 48 + flags.fu = be64_to_cpu(fctx->flags.f); 48 49 flags.w0.aes_keylen = aes_keylen; 49 - fctx->flags.f = cpu_to_be64(flags.f); 50 + fctx->flags.f = cpu_to_be64(flags.fu); 50 51 51 52 /* copy enc key to context */ 52 53 memset(&fctx->crypto, 0, sizeof(fctx->crypto)); ··· 62 63 struct flexi_crypto_context *fctx = nctx->u.fctx; 63 64 union fc_ctx_flags flags; 64 65 65 - flags.f = be64_to_cpu(fctx->flags.f); 66 + flags.fu = be64_to_cpu(fctx->flags.f); 66 67 flags.w0.mac_len = authsize; 67 - fctx->flags.f = cpu_to_be64(flags.f); 68 + fctx->flags.f = cpu_to_be64(flags.fu); 68 69 69 70 aead->authsize = authsize; 70 71 ··· 318 319 flags->w0.iv_source = IV_FROM_DPTR; 319 320 /* ask microcode to calculate ipad/opad */ 320 321 flags->w0.auth_input_type = 1; 321 - flags->f = be64_to_cpu(flags->f); 322 + flags->f = cpu_to_be64(flags->fu); 322 323 323 324 return 0; 324 325 }
+1
drivers/crypto/cavium/nitrox/nitrox_debugfs.c
··· 3 3 #include <linux/debugfs.h> 4 4 5 5 #include "nitrox_csr.h" 6 + #include "nitrox_debugfs.h" 6 7 #include "nitrox_dev.h" 7 8 8 9 static int firmware_show(struct seq_file *s, void *v)
+1
drivers/crypto/cavium/nitrox/nitrox_hal.c
··· 3 3 4 4 #include "nitrox_dev.h" 5 5 #include "nitrox_csr.h" 6 + #include "nitrox_hal.h" 6 7 7 8 #define PLL_REF_CLK 50 8 9 #define MAX_CSR_RETRIES 10
+1
drivers/crypto/cavium/nitrox/nitrox_isr.c
··· 7 7 #include "nitrox_csr.h" 8 8 #include "nitrox_common.h" 9 9 #include "nitrox_hal.h" 10 + #include "nitrox_isr.h" 10 11 #include "nitrox_mbx.h" 11 12 12 13 /**
+9
drivers/crypto/cavium/nitrox/nitrox_isr.h
··· 9 9 int nitrox_sriov_register_interupts(struct nitrox_device *ndev); 10 10 void nitrox_sriov_unregister_interrupts(struct nitrox_device *ndev); 11 11 12 + #ifdef CONFIG_PCI_IOV 13 + int nitrox_sriov_configure(struct pci_dev *pdev, int num_vfs); 14 + #else 15 + static inline int nitrox_sriov_configure(struct pci_dev *pdev, int num_vfs) 16 + { 17 + return 0; 18 + } 19 + #endif 20 + 12 21 #endif /* __NITROX_ISR_H */
-13
drivers/crypto/cavium/nitrox/nitrox_main.c
··· 49 49 module_param(qlen, uint, 0644); 50 50 MODULE_PARM_DESC(qlen, "Command queue length - default 2048"); 51 51 52 - #ifdef CONFIG_PCI_IOV 53 - int nitrox_sriov_configure(struct pci_dev *pdev, int num_vfs); 54 - #else 55 - int nitrox_sriov_configure(struct pci_dev *pdev, int num_vfs) 56 - { 57 - return 0; 58 - } 59 - #endif 60 - 61 52 /** 62 53 * struct ucode - Firmware Header 63 54 * @id: microcode ID ··· 546 555 547 556 nitrox_remove_from_devlist(ndev); 548 557 549 - #ifdef CONFIG_PCI_IOV 550 558 /* disable SR-IOV */ 551 559 nitrox_sriov_configure(pdev, 0); 552 - #endif 553 560 nitrox_crypto_unregister(); 554 561 nitrox_debugfs_exit(ndev); 555 562 nitrox_pf_sw_cleanup(ndev); ··· 573 584 .probe = nitrox_probe, 574 585 .remove = nitrox_remove, 575 586 .shutdown = nitrox_shutdown, 576 - #ifdef CONFIG_PCI_IOV 577 587 .sriov_configure = nitrox_sriov_configure, 578 - #endif 579 588 }; 580 589 581 590 module_pci_driver(nitrox_driver);
+2 -1
drivers/crypto/cavium/nitrox/nitrox_mbx.c
··· 4 4 #include "nitrox_csr.h" 5 5 #include "nitrox_hal.h" 6 6 #include "nitrox_dev.h" 7 + #include "nitrox_mbx.h" 7 8 8 9 #define RING_TO_VFNO(_x, _y) ((_x) / (_y)) 9 10 ··· 113 112 case MBX_MSG_TYPE_ACK: 114 113 case MBX_MSG_TYPE_NACK: 115 114 break; 116 - }; 115 + } 117 116 118 117 kfree(pf2vf_resp); 119 118 }
+4
drivers/crypto/cavium/nitrox/nitrox_req.h
··· 149 149 150 150 union fc_ctx_flags { 151 151 __be64 f; 152 + u64 fu; 152 153 struct { 153 154 #if defined(__BIG_ENDIAN_BITFIELD) 154 155 u64 cipher_type : 4; ··· 281 280 * - packet payload bytes 282 281 */ 283 282 union pkt_instr_hdr { 283 + __be64 bev; 284 284 u64 value; 285 285 struct { 286 286 #if defined(__BIG_ENDIAN_BITFIELD) ··· 326 324 * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases. 327 325 */ 328 326 union pkt_hdr { 327 + __be64 bev[2]; 329 328 u64 value[2]; 330 329 struct { 331 330 #if defined(__BIG_ENDIAN_BITFIELD) ··· 373 370 * sglist components at [RPTR] on the remote host. 374 371 */ 375 372 union slc_store_info { 373 + __be64 bev[2]; 376 374 u64 value[2]; 377 375 struct { 378 376 #if defined(__BIG_ENDIAN_BITFIELD)
+4 -3
drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
··· 3 3 #include <linux/workqueue.h> 4 4 #include <crypto/internal/skcipher.h> 5 5 6 + #include "nitrox_common.h" 6 7 #include "nitrox_dev.h" 7 8 #include "nitrox_req.h" 8 9 #include "nitrox_csr.h" ··· 449 448 sr->instr.ih.s.ssz = sr->out.sgmap_cnt; 450 449 sr->instr.ih.s.fsz = FDATA_SIZE + sizeof(struct gphdr); 451 450 sr->instr.ih.s.tlen = sr->instr.ih.s.fsz + sr->in.total_bytes; 452 - sr->instr.ih.value = cpu_to_be64(sr->instr.ih.value); 451 + sr->instr.ih.bev = cpu_to_be64(sr->instr.ih.value); 453 452 454 453 /* word 2 */ 455 454 sr->instr.irh.value[0] = 0; ··· 461 460 sr->instr.irh.s.ctxc = req->ctrl.s.ctxc; 462 461 sr->instr.irh.s.arg = req->ctrl.s.arg; 463 462 sr->instr.irh.s.opcode = req->opcode; 464 - sr->instr.irh.value[0] = cpu_to_be64(sr->instr.irh.value[0]); 463 + sr->instr.irh.bev[0] = cpu_to_be64(sr->instr.irh.value[0]); 465 464 466 465 /* word 3 */ 467 466 sr->instr.irh.s.ctxp = cpu_to_be64(ctx_handle); ··· 469 468 /* word 4 */ 470 469 sr->instr.slc.value[0] = 0; 471 470 sr->instr.slc.s.ssz = sr->out.sgmap_cnt; 472 - sr->instr.slc.value[0] = cpu_to_be64(sr->instr.slc.value[0]); 471 + sr->instr.slc.bev[0] = cpu_to_be64(sr->instr.slc.value[0]); 473 472 474 473 /* word 5 */ 475 474 sr->instr.slc.s.rptr = cpu_to_be64(sr->out.sgcomp_dma);
+2 -8
drivers/crypto/cavium/zip/zip_main.c
··· 263 263 goto err_disable_device; 264 264 } 265 265 266 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48)); 266 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); 267 267 if (err) { 268 - dev_err(dev, "Unable to get usable DMA configuration\n"); 269 - goto err_release_regions; 270 - } 271 - 272 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48)); 273 - if (err) { 274 - dev_err(dev, "Unable to get 48-bit DMA for allocations\n"); 268 + dev_err(dev, "Unable to get usable 48-bit DMA configuration\n"); 275 269 goto err_release_regions; 276 270 } 277 271
+2 -1
drivers/crypto/ccp/ccp-crypto-sha.c
··· 17 17 #include <crypto/hash.h> 18 18 #include <crypto/hmac.h> 19 19 #include <crypto/internal/hash.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha1.h> 21 + #include <crypto/sha2.h> 21 22 #include <crypto/scatterwalk.h> 22 23 #include <linux/string.h> 23 24
+2 -1
drivers/crypto/ccp/ccp-crypto.h
··· 19 19 #include <crypto/aead.h> 20 20 #include <crypto/ctr.h> 21 21 #include <crypto/hash.h> 22 - #include <crypto/sha.h> 22 + #include <crypto/sha1.h> 23 + #include <crypto/sha2.h> 23 24 #include <crypto/akcipher.h> 24 25 #include <crypto/skcipher.h> 25 26 #include <crypto/internal/rsa.h>
+3
drivers/crypto/ccree/cc_cipher.c
··· 97 97 case S_DIN_to_SM4: 98 98 if (size == SM4_KEY_SIZE) 99 99 return 0; 100 + break; 100 101 default: 101 102 break; 102 103 } ··· 140 139 case DRV_CIPHER_CBC: 141 140 if (IS_ALIGNED(size, SM4_BLOCK_SIZE)) 142 141 return 0; 142 + break; 143 143 default: 144 144 break; 145 145 } 146 + break; 146 147 default: 147 148 break; 148 149 }
+59 -16
drivers/crypto/ccree/cc_driver.c
··· 100 100 }; 101 101 MODULE_DEVICE_TABLE(of, arm_ccree_dev_of_match); 102 102 103 + static void init_cc_cache_params(struct cc_drvdata *drvdata) 104 + { 105 + struct device *dev = drvdata_to_dev(drvdata); 106 + u32 cache_params, ace_const, val, mask; 107 + 108 + /* compute CC_AXIM_CACHE_PARAMS */ 109 + cache_params = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); 110 + dev_dbg(dev, "Cache params previous: 0x%08X\n", cache_params); 111 + 112 + /* non cached or write-back, write allocate */ 113 + val = drvdata->coherent ? 0xb : 0x2; 114 + 115 + mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_AWCACHE); 116 + cache_params &= ~mask; 117 + cache_params |= FIELD_PREP(mask, val); 118 + 119 + mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_AWCACHE_LAST); 120 + cache_params &= ~mask; 121 + cache_params |= FIELD_PREP(mask, val); 122 + 123 + mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_ARCACHE); 124 + cache_params &= ~mask; 125 + cache_params |= FIELD_PREP(mask, val); 126 + 127 + drvdata->cache_params = cache_params; 128 + 129 + dev_dbg(dev, "Cache params current: 0x%08X\n", cache_params); 130 + 131 + if (drvdata->hw_rev <= CC_HW_REV_710) 132 + return; 133 + 134 + /* compute CC_AXIM_ACE_CONST */ 135 + ace_const = cc_ioread(drvdata, CC_REG(AXIM_ACE_CONST)); 136 + dev_dbg(dev, "ACE-const previous: 0x%08X\n", ace_const); 137 + 138 + /* system or outer-sharable */ 139 + val = drvdata->coherent ? 0x2 : 0x3; 140 + 141 + mask = CC_GENMASK(CC_AXIM_ACE_CONST_ARDOMAIN); 142 + ace_const &= ~mask; 143 + ace_const |= FIELD_PREP(mask, val); 144 + 145 + mask = CC_GENMASK(CC_AXIM_ACE_CONST_AWDOMAIN); 146 + ace_const &= ~mask; 147 + ace_const |= FIELD_PREP(mask, val); 148 + 149 + dev_dbg(dev, "ACE-const current: 0x%08X\n", ace_const); 150 + 151 + drvdata->ace_const = ace_const; 152 + } 153 + 103 154 static u32 cc_read_idr(struct cc_drvdata *drvdata, const u32 *idr_offsets) 104 155 { 105 156 int i; ··· 269 218 return false; 270 219 } 271 220 272 - int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe) 221 + int init_cc_regs(struct cc_drvdata *drvdata) 273 222 { 274 - unsigned int val, cache_params; 223 + unsigned int val; 275 224 struct device *dev = drvdata_to_dev(drvdata); 276 225 277 226 /* Unmask all AXI interrupt sources AXI_CFG1 register */ ··· 296 245 297 246 cc_iowrite(drvdata, CC_REG(HOST_IMR), ~val); 298 247 299 - cache_params = (drvdata->coherent ? CC_COHERENT_CACHE_PARAMS : 0x0); 300 - 301 - val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); 302 - 303 - if (is_probe) 304 - dev_dbg(dev, "Cache params previous: 0x%08X\n", val); 305 - 306 - cc_iowrite(drvdata, CC_REG(AXIM_CACHE_PARAMS), cache_params); 307 - val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); 308 - 309 - if (is_probe) 310 - dev_dbg(dev, "Cache params current: 0x%08X (expect: 0x%08X)\n", 311 - val, cache_params); 248 + cc_iowrite(drvdata, CC_REG(AXIM_CACHE_PARAMS), drvdata->cache_params); 249 + if (drvdata->hw_rev >= CC_HW_REV_712) 250 + cc_iowrite(drvdata, CC_REG(AXIM_ACE_CONST), drvdata->ace_const); 312 251 313 252 return 0; 314 253 } ··· 486 445 } 487 446 dev_dbg(dev, "Registered to IRQ: %d\n", irq); 488 447 489 - rc = init_cc_regs(new_drvdata, true); 448 + init_cc_cache_params(new_drvdata); 449 + 450 + rc = init_cc_regs(new_drvdata); 490 451 if (rc) { 491 452 dev_err(dev, "init_cc_regs failed\n"); 492 453 goto post_pm_err;
+5 -4
drivers/crypto/ccree/cc_driver.h
··· 17 17 #include <crypto/algapi.h> 18 18 #include <crypto/internal/skcipher.h> 19 19 #include <crypto/aes.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha1.h> 21 + #include <crypto/sha2.h> 21 22 #include <crypto/aead.h> 22 23 #include <crypto/authenc.h> 23 24 #include <crypto/hash.h> ··· 49 48 CC_STD_OSCCA = 0x2, 50 49 CC_STD_ALL = 0x3 51 50 }; 52 - 53 - #define CC_COHERENT_CACHE_PARAMS 0xEEE 54 51 55 52 #define CC_PINS_FULL 0x0 56 53 #define CC_PINS_SLIM 0x9F ··· 154 155 int std_bodies; 155 156 bool sec_disabled; 156 157 u32 comp_mask; 158 + u32 cache_params; 159 + u32 ace_const; 157 160 }; 158 161 159 162 struct cc_crypto_alg { ··· 206 205 } 207 206 208 207 bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata); 209 - int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe); 208 + int init_cc_regs(struct cc_drvdata *drvdata); 210 209 void fini_cc_regs(struct cc_drvdata *drvdata); 211 210 unsigned int cc_get_default_hash_len(struct cc_drvdata *drvdata); 212 211
+1 -1
drivers/crypto/ccree/cc_pm.c
··· 45 45 } 46 46 47 47 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); 48 - rc = init_cc_regs(drvdata, false); 48 + rc = init_cc_regs(drvdata); 49 49 if (rc) { 50 50 dev_err(dev, "init_cc_regs (%x)\n", rc); 51 51 return rc;
+2 -1
drivers/crypto/chelsio/chcr_algo.c
··· 53 53 #include <crypto/algapi.h> 54 54 #include <crypto/hash.h> 55 55 #include <crypto/gcm.h> 56 - #include <crypto/sha.h> 56 + #include <crypto/sha1.h> 57 + #include <crypto/sha2.h> 57 58 #include <crypto/authenc.h> 58 59 #include <crypto/ctr.h> 59 60 #include <crypto/gf128mul.h>
+8
drivers/crypto/hisilicon/Kconfig
··· 71 71 help 72 72 Support for HiSilicon HPRE(High Performance RSA Engine) 73 73 accelerator, which can accelerate RSA and DH algorithms. 74 + 75 + config CRYPTO_DEV_HISI_TRNG 76 + tristate "Support for HISI TRNG Driver" 77 + depends on ARM64 && ACPI 78 + select HW_RANDOM 79 + select CRYPTO_RNG 80 + help 81 + Support for HiSilicon TRNG Driver.
+1
drivers/crypto/hisilicon/Makefile
··· 5 5 obj-$(CONFIG_CRYPTO_DEV_HISI_QM) += hisi_qm.o 6 6 hisi_qm-objs = qm.o sgl.o 7 7 obj-$(CONFIG_CRYPTO_DEV_HISI_ZIP) += zip/ 8 + obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += trng/
+1 -3
drivers/crypto/hisilicon/hpre/hpre_main.c
··· 705 705 706 706 qm->debug.sqe_mask_offset = HPRE_SQE_MASK_OFFSET; 707 707 qm->debug.sqe_mask_len = HPRE_SQE_MASK_LEN; 708 - ret = hisi_qm_debug_init(qm); 709 - if (ret) 710 - goto failed_to_create; 708 + hisi_qm_debug_init(qm); 711 709 712 710 if (qm->pdev->device == HPRE_PCI_DEVICE_ID) { 713 711 ret = hpre_ctrl_debug_init(qm);
+143 -77
drivers/crypto/hisilicon/qm.c
··· 473 473 474 474 return readl_relaxed_poll_timeout(qm->io_base + QM_MB_CMD_SEND_BASE, 475 475 val, !((val >> QM_MB_BUSY_SHIFT) & 476 - 0x1), 10, 1000); 476 + 0x1), POLL_PERIOD, POLL_TIMEOUT); 477 477 } 478 478 479 479 /* 128 bit should be written to hardware at one time to trigger a mailbox */ ··· 583 583 584 584 writel(0x1, qm->io_base + QM_MEM_START_INIT); 585 585 return readl_relaxed_poll_timeout(qm->io_base + QM_MEM_INIT_DONE, val, 586 - val & BIT(0), 10, 1000); 586 + val & BIT(0), POLL_PERIOD, 587 + POLL_TIMEOUT); 587 588 } 588 589 589 590 static u32 qm_get_irq_num_v1(struct hisi_qm *qm) ··· 805 804 int ret; 806 805 807 806 ret = readl_relaxed_poll_timeout(qm->io_base + QM_VFT_CFG_RDY, val, 808 - val & BIT(0), 10, 1000); 807 + val & BIT(0), POLL_PERIOD, 808 + POLL_TIMEOUT); 809 809 if (ret) 810 810 return ret; 811 811 ··· 820 818 writel(0x1, qm->io_base + QM_VFT_CFG_OP_ENABLE); 821 819 822 820 return readl_relaxed_poll_timeout(qm->io_base + QM_VFT_CFG_RDY, val, 823 - val & BIT(0), 10, 1000); 821 + val & BIT(0), POLL_PERIOD, 822 + POLL_TIMEOUT); 824 823 } 825 824 826 825 /* The config should be conducted after qm_dev_mem_reset() */ ··· 932 929 return -EINVAL; 933 930 } 934 931 mutex_unlock(&file->lock); 935 - ret = sprintf(tbuf, "%u\n", val); 932 + 933 + ret = scnprintf(tbuf, QM_DBG_TMP_BUF_LEN, "%u\n", val); 936 934 return simple_read_from_buffer(buf, count, pos, tbuf, ret); 937 935 } 938 936 ··· 1521 1517 .write = qm_cmd_write, 1522 1518 }; 1523 1519 1524 - static int qm_create_debugfs_file(struct hisi_qm *qm, enum qm_debug_file index) 1520 + static void qm_create_debugfs_file(struct hisi_qm *qm, enum qm_debug_file index) 1525 1521 { 1526 1522 struct dentry *qm_d = qm->debug.qm_d; 1527 1523 struct debugfs_file *file = qm->debug.files + index; ··· 1532 1528 file->index = index; 1533 1529 mutex_init(&file->lock); 1534 1530 file->debug = &qm->debug; 1535 - 1536 - return 0; 1537 1531 } 1538 1532 1539 1533 static void qm_hw_error_init_v1(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe) ··· 1735 1733 } 1736 1734 EXPORT_SYMBOL_GPL(hisi_qm_release_qp); 1737 1735 1738 - static int qm_qp_ctx_cfg(struct hisi_qp *qp, int qp_id, u32 pasid) 1736 + static int qm_sq_ctx_cfg(struct hisi_qp *qp, int qp_id, u32 pasid) 1739 1737 { 1740 1738 struct hisi_qm *qm = qp->qm; 1741 1739 struct device *dev = &qm->pdev->dev; 1742 1740 enum qm_hw_ver ver = qm->ver; 1743 1741 struct qm_sqc *sqc; 1744 - struct qm_cqc *cqc; 1745 1742 dma_addr_t sqc_dma; 1746 - dma_addr_t cqc_dma; 1747 1743 int ret; 1748 - 1749 - qm_init_qp_status(qp); 1750 1744 1751 1745 sqc = kzalloc(sizeof(struct qm_sqc), GFP_KERNEL); 1752 1746 if (!sqc) ··· 1768 1770 ret = qm_mb(qm, QM_MB_CMD_SQC, sqc_dma, qp_id, 0); 1769 1771 dma_unmap_single(dev, sqc_dma, sizeof(struct qm_sqc), DMA_TO_DEVICE); 1770 1772 kfree(sqc); 1771 - if (ret) 1772 - return ret; 1773 + 1774 + return ret; 1775 + } 1776 + 1777 + static int qm_cq_ctx_cfg(struct hisi_qp *qp, int qp_id, u32 pasid) 1778 + { 1779 + struct hisi_qm *qm = qp->qm; 1780 + struct device *dev = &qm->pdev->dev; 1781 + enum qm_hw_ver ver = qm->ver; 1782 + struct qm_cqc *cqc; 1783 + dma_addr_t cqc_dma; 1784 + int ret; 1773 1785 1774 1786 cqc = kzalloc(sizeof(struct qm_cqc), GFP_KERNEL); 1775 1787 if (!cqc) ··· 1793 1785 1794 1786 INIT_QC_COMMON(cqc, qp->cqe_dma, pasid); 1795 1787 if (ver == QM_HW_V1) { 1796 - cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V1(0, 0, 0, 4)); 1788 + cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V1(0, 0, 0, 1789 + QM_QC_CQE_SIZE)); 1797 1790 cqc->w8 = cpu_to_le16(QM_Q_DEPTH - 1); 1798 1791 } else { 1799 - cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V2(4)); 1800 - cqc->w8 = 0; 1792 + cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V2(QM_QC_CQE_SIZE)); 1793 + cqc->w8 = 0; /* rand_qc */ 1801 1794 } 1802 1795 cqc->dw6 = cpu_to_le32(1 << QM_CQ_PHASE_SHIFT | 1 << QM_CQ_FLAG_SHIFT); 1803 1796 ··· 1807 1798 kfree(cqc); 1808 1799 1809 1800 return ret; 1801 + } 1802 + 1803 + static int qm_qp_ctx_cfg(struct hisi_qp *qp, int qp_id, u32 pasid) 1804 + { 1805 + int ret; 1806 + 1807 + qm_init_qp_status(qp); 1808 + 1809 + ret = qm_sq_ctx_cfg(qp, qp_id, pasid); 1810 + if (ret) 1811 + return ret; 1812 + 1813 + return qm_cq_ctx_cfg(qp, qp_id, pasid); 1810 1814 } 1811 1815 1812 1816 static int qm_start_qp_nolock(struct hisi_qp *qp, unsigned long arg) ··· 1865 1843 EXPORT_SYMBOL_GPL(hisi_qm_start_qp); 1866 1844 1867 1845 /** 1846 + * qm_drain_qp() - Drain a qp. 1847 + * @qp: The qp we want to drain. 1848 + * 1868 1849 * Determine whether the queue is cleared by judging the tail pointers of 1869 1850 * sq and cq. 1870 1851 */ ··· 2033 2008 2034 2009 writel(0x1, qm->io_base + QM_CACHE_WB_START); 2035 2010 if (readl_relaxed_poll_timeout(qm->io_base + QM_CACHE_WB_DONE, 2036 - val, val & BIT(0), 10, 1000)) 2011 + val, val & BIT(0), POLL_PERIOD, 2012 + POLL_TIMEOUT)) 2037 2013 dev_err(&qm->pdev->dev, "QM writeback sqc cache fail!\n"); 2038 2014 } 2039 2015 ··· 2138 2112 hisi_qm_stop_qp(q->priv); 2139 2113 } 2140 2114 2141 - static int qm_set_sqctype(struct uacce_queue *q, u16 type) 2115 + static void qm_set_sqctype(struct uacce_queue *q, u16 type) 2142 2116 { 2143 2117 struct hisi_qm *qm = q->uacce->priv; 2144 2118 struct hisi_qp *qp = q->priv; ··· 2146 2120 down_write(&qm->qps_lock); 2147 2121 qp->alg_type = type; 2148 2122 up_write(&qm->qps_lock); 2149 - 2150 - return 0; 2151 2123 } 2152 2124 2153 2125 static long hisi_qm_uacce_ioctl(struct uacce_queue *q, unsigned int cmd, ··· 2442 2418 qm->is_frozen = false; 2443 2419 } 2444 2420 2421 + static void hisi_qm_pci_uninit(struct hisi_qm *qm) 2422 + { 2423 + struct pci_dev *pdev = qm->pdev; 2424 + 2425 + pci_free_irq_vectors(pdev); 2426 + iounmap(qm->io_base); 2427 + pci_release_mem_regions(pdev); 2428 + pci_disable_device(pdev); 2429 + } 2430 + 2445 2431 /** 2446 2432 * hisi_qm_uninit() - Uninitialize qm. 2447 2433 * @qm: The qm needed uninit. ··· 2470 2436 return; 2471 2437 } 2472 2438 2473 - uacce_remove(qm->uacce); 2474 - qm->uacce = NULL; 2475 - 2476 2439 hisi_qp_memory_uninit(qm, qm->qp_num); 2477 2440 idr_destroy(&qm->qp_idr); 2478 2441 ··· 2481 2450 } 2482 2451 2483 2452 qm_irq_unregister(qm); 2484 - pci_free_irq_vectors(pdev); 2485 - iounmap(qm->io_base); 2486 - pci_release_mem_regions(pdev); 2487 - pci_disable_device(pdev); 2453 + hisi_qm_pci_uninit(qm); 2454 + uacce_remove(qm->uacce); 2455 + qm->uacce = NULL; 2488 2456 2489 2457 up_write(&qm->qps_lock); 2490 2458 } ··· 2516 2486 EXPORT_SYMBOL_GPL(hisi_qm_get_vft); 2517 2487 2518 2488 /** 2489 + * hisi_qm_set_vft() - Set vft to a qm. 2490 + * @qm: The qm we want to set its vft. 2491 + * @fun_num: The function number. 2492 + * @base: The base number of queue in vft. 2493 + * @number: The number of queues in vft. 2494 + * 2519 2495 * This function is alway called in PF driver, it is used to assign queues 2520 2496 * among PF and VFs. 2521 2497 * ··· 2555 2519 { 2556 2520 struct device *dev = &qm->pdev->dev; 2557 2521 struct qm_eqc *eqc; 2558 - struct qm_aeqc *aeqc; 2559 2522 dma_addr_t eqc_dma; 2560 - dma_addr_t aeqc_dma; 2561 2523 int ret; 2562 2524 2563 - qm_init_eq_aeq_status(qm); 2564 - 2565 - eqc = kzalloc(sizeof(struct qm_eqc), GFP_KERNEL); 2525 + eqc = kzalloc(sizeof(struct qm_eqc), GFP_KERNEL); //todo 2566 2526 if (!eqc) 2567 2527 return -ENOMEM; 2568 2528 eqc_dma = dma_map_single(dev, eqc, sizeof(struct qm_eqc), ··· 2573 2541 if (qm->ver == QM_HW_V1) 2574 2542 eqc->dw3 = cpu_to_le32(QM_EQE_AEQE_SIZE); 2575 2543 eqc->dw6 = cpu_to_le32((QM_EQ_DEPTH - 1) | (1 << QM_EQC_PHASE_SHIFT)); 2544 + 2576 2545 ret = qm_mb(qm, QM_MB_CMD_EQC, eqc_dma, 0, 0); 2577 2546 dma_unmap_single(dev, eqc_dma, sizeof(struct qm_eqc), DMA_TO_DEVICE); 2578 2547 kfree(eqc); 2579 - if (ret) 2580 - return ret; 2548 + 2549 + return ret; 2550 + } 2551 + 2552 + static int qm_aeq_ctx_cfg(struct hisi_qm *qm) 2553 + { 2554 + struct device *dev = &qm->pdev->dev; 2555 + struct qm_aeqc *aeqc; 2556 + dma_addr_t aeqc_dma; 2557 + int ret; 2581 2558 2582 2559 aeqc = kzalloc(sizeof(struct qm_aeqc), GFP_KERNEL); 2583 2560 if (!aeqc) ··· 2609 2568 return ret; 2610 2569 } 2611 2570 2571 + static int qm_eq_aeq_ctx_cfg(struct hisi_qm *qm) 2572 + { 2573 + struct device *dev = &qm->pdev->dev; 2574 + int ret; 2575 + 2576 + qm_init_eq_aeq_status(qm); 2577 + 2578 + ret = qm_eq_ctx_cfg(qm); 2579 + if (ret) { 2580 + dev_err(dev, "Set eqc failed!\n"); 2581 + return ret; 2582 + } 2583 + 2584 + return qm_aeq_ctx_cfg(qm); 2585 + } 2586 + 2612 2587 static int __hisi_qm_start(struct hisi_qm *qm) 2613 2588 { 2614 2589 int ret; ··· 2641 2584 return ret; 2642 2585 } 2643 2586 2644 - ret = qm_eq_ctx_cfg(qm); 2587 + ret = qm_eq_aeq_ctx_cfg(qm); 2645 2588 if (ret) 2646 2589 return ret; 2647 2590 ··· 2747 2690 return 0; 2748 2691 } 2749 2692 2693 + 2750 2694 /** 2695 + * qm_clear_queues() - Clear all queues memory in a qm. 2696 + * @qm: The qm in which the queues will be cleared. 2697 + * 2751 2698 * This function clears all queues memory in a qm. Reset of accelerator can 2752 2699 * use this to clear queues. 2753 2700 */ ··· 2867 2806 * 2868 2807 * Create qm related debugfs files. 2869 2808 */ 2870 - int hisi_qm_debug_init(struct hisi_qm *qm) 2809 + void hisi_qm_debug_init(struct hisi_qm *qm) 2871 2810 { 2872 2811 struct qm_dfx *dfx = &qm->debug.dfx; 2873 2812 struct dentry *qm_d; 2874 2813 void *data; 2875 - int i, ret; 2814 + int i; 2876 2815 2877 2816 qm_d = debugfs_create_dir("qm", qm->debug.debug_root); 2878 2817 qm->debug.qm_d = qm_d; ··· 2880 2819 /* only show this in PF */ 2881 2820 if (qm->fun_type == QM_HW_PF) 2882 2821 for (i = CURRENT_Q; i < DEBUG_FILE_NUM; i++) 2883 - if (qm_create_debugfs_file(qm, i)) { 2884 - ret = -ENOENT; 2885 - goto failed_to_create; 2886 - } 2822 + qm_create_debugfs_file(qm, i); 2887 2823 2888 2824 debugfs_create_file("regs", 0444, qm->debug.qm_d, qm, &qm_regs_fops); 2889 2825 ··· 2896 2838 data, 2897 2839 &qm_atomic64_ops); 2898 2840 } 2899 - 2900 - return 0; 2901 - 2902 - failed_to_create: 2903 - debugfs_remove_recursive(qm_d); 2904 - return ret; 2905 2841 } 2906 2842 EXPORT_SYMBOL_GPL(hisi_qm_debug_init); 2907 2843 ··· 3325 3273 } 3326 3274 EXPORT_SYMBOL_GPL(hisi_qm_dev_err_detected); 3327 3275 3328 - static int qm_get_hw_error_status(struct hisi_qm *qm) 3276 + static u32 qm_get_hw_error_status(struct hisi_qm *qm) 3329 3277 { 3330 3278 return readl(qm->io_base + QM_ABNORMAL_INT_STATUS); 3331 3279 } ··· 3624 3572 return ret; 3625 3573 } 3626 3574 3627 - static int qm_get_dev_err_status(struct hisi_qm *qm) 3575 + static u32 qm_get_dev_err_status(struct hisi_qm *qm) 3628 3576 { 3629 3577 return qm->err_ini->get_dev_hw_err_status(qm); 3630 3578 } ··· 4044 3992 } 4045 3993 EXPORT_SYMBOL_GPL(hisi_qm_alg_unregister); 4046 3994 4047 - /** 4048 - * hisi_qm_init() - Initialize configures about qm. 4049 - * @qm: The qm needing init. 4050 - * 4051 - * This function init qm, then we can call hisi_qm_start to put qm into work. 4052 - */ 4053 - int hisi_qm_init(struct hisi_qm *qm) 3995 + static int hisi_qm_pci_init(struct hisi_qm *qm) 4054 3996 { 4055 3997 struct pci_dev *pdev = qm->pdev; 4056 3998 struct device *dev = &pdev->dev; 4057 3999 unsigned int num_vec; 4058 4000 int ret; 4059 4001 4060 - hisi_qm_pre_init(qm); 4061 - 4062 - ret = qm_alloc_uacce(qm); 4063 - if (ret < 0) 4064 - dev_warn(&pdev->dev, "fail to alloc uacce (%d)\n", ret); 4065 - 4066 4002 ret = pci_enable_device_mem(pdev); 4067 4003 if (ret < 0) { 4068 - dev_err(&pdev->dev, "Failed to enable device mem!\n"); 4069 - goto err_remove_uacce; 4004 + dev_err(dev, "Failed to enable device mem!\n"); 4005 + return ret; 4070 4006 } 4071 4007 4072 4008 ret = pci_request_mem_regions(pdev, qm->dev_name); 4073 4009 if (ret < 0) { 4074 - dev_err(&pdev->dev, "Failed to request mem regions!\n"); 4010 + dev_err(dev, "Failed to request mem regions!\n"); 4075 4011 goto err_disable_pcidev; 4076 4012 } 4077 4013 ··· 4087 4047 goto err_iounmap; 4088 4048 } 4089 4049 4050 + return 0; 4051 + 4052 + err_iounmap: 4053 + iounmap(qm->io_base); 4054 + err_release_mem_regions: 4055 + pci_release_mem_regions(pdev); 4056 + err_disable_pcidev: 4057 + pci_disable_device(pdev); 4058 + return ret; 4059 + } 4060 + 4061 + /** 4062 + * hisi_qm_init() - Initialize configures about qm. 4063 + * @qm: The qm needing init. 4064 + * 4065 + * This function init qm, then we can call hisi_qm_start to put qm into work. 4066 + */ 4067 + int hisi_qm_init(struct hisi_qm *qm) 4068 + { 4069 + struct pci_dev *pdev = qm->pdev; 4070 + struct device *dev = &pdev->dev; 4071 + int ret; 4072 + 4073 + hisi_qm_pre_init(qm); 4074 + 4075 + ret = qm_alloc_uacce(qm); 4076 + if (ret < 0) 4077 + dev_warn(dev, "fail to alloc uacce (%d)\n", ret); 4078 + 4079 + ret = hisi_qm_pci_init(qm); 4080 + if (ret) 4081 + goto err_remove_uacce; 4082 + 4090 4083 ret = qm_irq_register(qm); 4091 4084 if (ret) 4092 - goto err_free_irq_vectors; 4085 + goto err_pci_uninit; 4093 4086 4094 4087 if (qm->fun_type == QM_HW_VF && qm->ver != QM_HW_V1) { 4095 4088 /* v2 starts to support get vft by mailbox */ ··· 4145 4072 4146 4073 err_irq_unregister: 4147 4074 qm_irq_unregister(qm); 4148 - err_free_irq_vectors: 4149 - pci_free_irq_vectors(pdev); 4150 - err_iounmap: 4151 - iounmap(qm->io_base); 4152 - err_release_mem_regions: 4153 - pci_release_mem_regions(pdev); 4154 - err_disable_pcidev: 4155 - pci_disable_device(pdev); 4075 + err_pci_uninit: 4076 + hisi_qm_pci_uninit(qm); 4156 4077 err_remove_uacce: 4157 4078 uacce_remove(qm->uacce); 4158 4079 qm->uacce = NULL; 4159 4080 return ret; 4160 4081 } 4161 4082 EXPORT_SYMBOL_GPL(hisi_qm_init); 4162 - 4163 4083 4164 4084 MODULE_LICENSE("GPL v2"); 4165 4085 MODULE_AUTHOR("Zhou Wang <wangzhou1@hisilicon.com>");
+1 -1
drivers/crypto/hisilicon/qm.h
··· 350 350 int hisi_qp_send(struct hisi_qp *qp, const void *msg); 351 351 int hisi_qm_get_free_qp_num(struct hisi_qm *qm); 352 352 int hisi_qm_get_vft(struct hisi_qm *qm, u32 *base, u32 *number); 353 - int hisi_qm_debug_init(struct hisi_qm *qm); 353 + void hisi_qm_debug_init(struct hisi_qm *qm); 354 354 enum qm_hw_ver hisi_qm_get_hw_version(struct pci_dev *pdev); 355 355 void hisi_qm_debug_regs_clear(struct hisi_qm *qm); 356 356 int hisi_qm_sriov_enable(struct pci_dev *pdev, int max_vfs);
-2
drivers/crypto/hisilicon/sec2/sec.h
··· 109 109 struct list_head backlog; 110 110 struct hisi_acc_sgl_pool *c_in_pool; 111 111 struct hisi_acc_sgl_pool *c_out_pool; 112 - atomic_t pending_reqs; 113 112 }; 114 113 115 114 enum sec_alg_type { ··· 179 180 struct sec_debug debug; 180 181 u32 ctx_q_num; 181 182 bool iommu_used; 182 - unsigned long status; 183 183 }; 184 184 185 185 void sec_destroy_qps(struct hisi_qp **qps, int qp_num);
+11 -14
drivers/crypto/hisilicon/sec2/sec_crypto.c
··· 7 7 #include <crypto/des.h> 8 8 #include <crypto/hash.h> 9 9 #include <crypto/internal/aead.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha1.h> 11 + #include <crypto/sha2.h> 11 12 #include <crypto/skcipher.h> 12 13 #include <crypto/xts.h> 13 14 #include <linux/crypto.h> ··· 102 101 103 102 req->qp_ctx = qp_ctx; 104 103 qp_ctx->req_list[req_id] = req; 104 + 105 105 return req_id; 106 106 } 107 107 ··· 319 317 j * SEC_PBUF_PKG + pbuf_page_offset; 320 318 } 321 319 } 320 + 322 321 return 0; 323 322 } 324 323 ··· 348 345 } 349 346 350 347 return 0; 348 + 351 349 alloc_pbuf_fail: 352 350 if (ctx->alg_type == SEC_AEAD) 353 351 sec_free_mac_resource(dev, qp_ctx->res); 354 352 alloc_fail: 355 353 sec_free_civ_resource(dev, res); 356 - 357 354 return ret; 358 355 } 359 356 ··· 422 419 hisi_acc_free_sgl_pool(dev, qp_ctx->c_in_pool); 423 420 err_destroy_idr: 424 421 idr_destroy(&qp_ctx->req_idr); 425 - 426 422 return ret; 427 423 } 428 424 ··· 559 557 goto err_cipher_init; 560 558 561 559 return 0; 560 + 562 561 err_cipher_init: 563 562 sec_ctx_base_uninit(ctx); 564 - 565 563 return ret; 566 564 } 567 565 ··· 742 740 743 741 if (unlikely(pbuf_length != copy_size)) 744 742 dev_err(dev, "copy pbuf data to dst error!\n"); 745 - 746 743 } 747 744 748 745 static int sec_cipher_map(struct sec_ctx *ctx, struct sec_req *req, ··· 858 857 struct crypto_authenc_keys *keys) 859 858 { 860 859 struct crypto_shash *hash_tfm = ctx->hash_tfm; 861 - int blocksize, ret; 860 + int blocksize, digestsize, ret; 862 861 863 862 if (!keys->authkeylen) { 864 863 pr_err("hisi_sec2: aead auth key error!\n"); ··· 866 865 } 867 866 868 867 blocksize = crypto_shash_blocksize(hash_tfm); 868 + digestsize = crypto_shash_digestsize(hash_tfm); 869 869 if (keys->authkeylen > blocksize) { 870 870 ret = crypto_shash_tfm_digest(hash_tfm, keys->authkey, 871 871 keys->authkeylen, ctx->a_key); ··· 874 872 pr_err("hisi_sec2: aead auth digest error!\n"); 875 873 return -EINVAL; 876 874 } 877 - ctx->a_key_len = blocksize; 875 + ctx->a_key_len = digestsize; 878 876 } else { 879 877 memcpy(ctx->a_key, keys->authkey, keys->authkeylen); 880 878 ctx->a_key_len = keys->authkeylen; ··· 915 913 } 916 914 917 915 return 0; 916 + 918 917 bad_key: 919 918 memzero_explicit(&keys, sizeof(struct crypto_authenc_keys)); 920 - 921 919 return -EINVAL; 922 920 } 923 921 ··· 968 966 969 967 unmap_req_buf: 970 968 ctx->req_op->buf_unmap(ctx, req); 971 - 972 969 return ret; 973 970 } 974 971 ··· 1107 1106 -EINPROGRESS); 1108 1107 atomic64_inc(&ctx->sec->debug.dfx.recv_busy_cnt); 1109 1108 } 1110 - 1111 1109 1112 1110 sk_req->base.complete(&sk_req->base, err); 1113 1111 } ··· 1279 1279 sec_request_untransfer(ctx, req); 1280 1280 err_uninit_req: 1281 1281 sec_request_uninit(ctx, req); 1282 - 1283 1282 return ret; 1284 1283 } 1285 1284 ··· 1348 1349 sec_auth_uninit(ctx); 1349 1350 err_auth_init: 1350 1351 sec_ctx_base_uninit(ctx); 1351 - 1352 1352 return ret; 1353 1353 } 1354 1354 ··· 1435 1437 } 1436 1438 return 0; 1437 1439 } 1438 - 1439 1440 dev_err(dev, "skcipher algorithm error!\n"); 1441 + 1440 1442 return -EINVAL; 1441 1443 } 1442 1444 ··· 1552 1554 if (unlikely(c_alg != SEC_CALG_AES)) { 1553 1555 dev_err(SEC_CTX_DEV(ctx), "aead crypto alg error!\n"); 1554 1556 return -EINVAL; 1555 - 1556 1557 } 1557 1558 if (sreq->c_req.encrypt) 1558 1559 sreq->c_req.c_len = req->cryptlen;
+13 -21
drivers/crypto/hisilicon/sec2/sec_main.c
··· 652 652 sec_debugfs_root); 653 653 qm->debug.sqe_mask_offset = SEC_SQE_MASK_OFFSET; 654 654 qm->debug.sqe_mask_len = SEC_SQE_MASK_LEN; 655 - ret = hisi_qm_debug_init(qm); 656 - if (ret) 657 - goto failed_to_create; 655 + hisi_qm_debug_init(qm); 658 656 659 657 ret = sec_debug_init(qm); 660 658 if (ret) 661 659 goto failed_to_create; 662 660 663 - 664 661 return 0; 665 662 666 663 failed_to_create: 667 664 debugfs_remove_recursive(sec_debugfs_root); 668 - 669 665 return ret; 670 666 } 671 667 ··· 679 683 while (errs->msg) { 680 684 if (errs->int_msk & err_sts) { 681 685 dev_err(dev, "%s [error status=0x%x] found\n", 682 - errs->msg, errs->int_msk); 686 + errs->msg, errs->int_msk); 683 687 684 688 if (SEC_CORE_INT_STATUS_M_ECC & errs->int_msk) { 685 689 err_val = readl(qm->io_base + 686 690 SEC_CORE_SRAM_ECC_ERR_INFO); 687 691 dev_err(dev, "multi ecc sram num=0x%x\n", 688 - SEC_ECC_NUM(err_val)); 692 + SEC_ECC_NUM(err_val)); 689 693 } 690 694 } 691 695 errs++; ··· 720 724 .log_dev_hw_err = sec_log_hw_error, 721 725 .open_axi_master_ooo = sec_open_axi_master_ooo, 722 726 .err_info = { 723 - .ce = QM_BASE_CE, 724 - .nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT | 725 - QM_ACC_WB_NOT_READY_TIMEOUT, 726 - .fe = 0, 727 - .ecc_2bits_mask = SEC_CORE_INT_STATUS_M_ECC, 728 - .msi_wr_port = BIT(0), 729 - .acpi_rst = "SRST", 727 + .ce = QM_BASE_CE, 728 + .nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT | 729 + QM_ACC_WB_NOT_READY_TIMEOUT, 730 + .fe = 0, 731 + .ecc_2bits_mask = SEC_CORE_INT_STATUS_M_ECC, 732 + .msi_wr_port = BIT(0), 733 + .acpi_rst = "SRST", 730 734 } 731 735 }; 732 736 ··· 895 899 896 900 err_alg_unregister: 897 901 hisi_qm_alg_unregister(qm, &sec_devices); 898 - 899 902 err_qm_stop: 900 903 sec_debugfs_exit(qm); 901 904 hisi_qm_stop(qm, QM_NORMAL); 902 - 903 905 err_probe_uninit: 904 906 sec_probe_uninit(qm); 905 - 906 907 err_qm_uninit: 907 908 sec_qm_uninit(qm); 908 - 909 909 return ret; 910 910 } 911 911 ··· 928 936 929 937 static const struct pci_error_handlers sec_err_handler = { 930 938 .error_detected = hisi_qm_dev_err_detected, 931 - .slot_reset = hisi_qm_dev_slot_reset, 932 - .reset_prepare = hisi_qm_reset_prepare, 933 - .reset_done = hisi_qm_reset_done, 939 + .slot_reset = hisi_qm_dev_slot_reset, 940 + .reset_prepare = hisi_qm_reset_prepare, 941 + .reset_done = hisi_qm_reset_done, 934 942 }; 935 943 936 944 static struct pci_driver sec_pci_driver = {
-2
drivers/crypto/hisilicon/sgl.c
··· 246 246 * @dev: The device which hw sgl belongs to. 247 247 * @sgl: Related scatterlist. 248 248 * @hw_sgl: Virtual address of hw sgl. 249 - * @hw_sgl_dma: DMA address of hw sgl. 250 - * @pool: Pool which hw sgl is allocated in. 251 249 * 252 250 * This function unmaps allocated hw sgl. 253 251 */
+2
drivers/crypto/hisilicon/trng/Makefile
··· 1 + obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += hisi-trng-v2.o 2 + hisi-trng-v2-objs = trng.o
+334
drivers/crypto/hisilicon/trng/trng.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright (c) 2019 HiSilicon Limited. */ 3 + 4 + #include <linux/acpi.h> 5 + #include <linux/crypto.h> 6 + #include <linux/err.h> 7 + #include <linux/hw_random.h> 8 + #include <linux/io.h> 9 + #include <linux/iopoll.h> 10 + #include <linux/kernel.h> 11 + #include <linux/list.h> 12 + #include <linux/module.h> 13 + #include <linux/mutex.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/random.h> 16 + #include <crypto/internal/rng.h> 17 + 18 + #define HISI_TRNG_REG 0x00F0 19 + #define HISI_TRNG_BYTES 4 20 + #define HISI_TRNG_QUALITY 512 21 + #define SLEEP_US 10 22 + #define TIMEOUT_US 10000 23 + #define SW_DRBG_NUM_SHIFT 2 24 + #define SW_DRBG_KEY_BASE 0x082C 25 + #define SW_DRBG_SEED(n) (SW_DRBG_KEY_BASE - ((n) << SW_DRBG_NUM_SHIFT)) 26 + #define SW_DRBG_SEED_REGS_NUM 12 27 + #define SW_DRBG_SEED_SIZE 48 28 + #define SW_DRBG_BLOCKS 0x0830 29 + #define SW_DRBG_INIT 0x0834 30 + #define SW_DRBG_GEN 0x083c 31 + #define SW_DRBG_STATUS 0x0840 32 + #define SW_DRBG_BLOCKS_NUM 4095 33 + #define SW_DRBG_DATA_BASE 0x0850 34 + #define SW_DRBG_DATA_NUM 4 35 + #define SW_DRBG_DATA(n) (SW_DRBG_DATA_BASE - ((n) << SW_DRBG_NUM_SHIFT)) 36 + #define SW_DRBG_BYTES 16 37 + #define SW_DRBG_ENABLE_SHIFT 12 38 + #define SEED_SHIFT_24 24 39 + #define SEED_SHIFT_16 16 40 + #define SEED_SHIFT_8 8 41 + 42 + struct hisi_trng_list { 43 + struct mutex lock; 44 + struct list_head list; 45 + bool is_init; 46 + }; 47 + 48 + struct hisi_trng { 49 + void __iomem *base; 50 + struct hisi_trng_list *trng_list; 51 + struct list_head list; 52 + struct hwrng rng; 53 + bool is_used; 54 + struct mutex mutex; 55 + }; 56 + 57 + struct hisi_trng_ctx { 58 + struct hisi_trng *trng; 59 + }; 60 + 61 + static atomic_t trng_active_devs; 62 + static struct hisi_trng_list trng_devices; 63 + 64 + static void hisi_trng_set_seed(struct hisi_trng *trng, const u8 *seed) 65 + { 66 + u32 val, seed_reg, i; 67 + 68 + for (i = 0; i < SW_DRBG_SEED_SIZE; 69 + i += SW_DRBG_SEED_SIZE / SW_DRBG_SEED_REGS_NUM) { 70 + val = seed[i] << SEED_SHIFT_24; 71 + val |= seed[i + 1UL] << SEED_SHIFT_16; 72 + val |= seed[i + 2UL] << SEED_SHIFT_8; 73 + val |= seed[i + 3UL]; 74 + 75 + seed_reg = (i >> SW_DRBG_NUM_SHIFT) % SW_DRBG_SEED_REGS_NUM; 76 + writel(val, trng->base + SW_DRBG_SEED(seed_reg)); 77 + } 78 + } 79 + 80 + static int hisi_trng_seed(struct crypto_rng *tfm, const u8 *seed, 81 + unsigned int slen) 82 + { 83 + struct hisi_trng_ctx *ctx = crypto_rng_ctx(tfm); 84 + struct hisi_trng *trng = ctx->trng; 85 + u32 val = 0; 86 + int ret = 0; 87 + 88 + if (slen < SW_DRBG_SEED_SIZE) { 89 + pr_err("slen(%u) is not matched with trng(%d)\n", slen, 90 + SW_DRBG_SEED_SIZE); 91 + return -EINVAL; 92 + } 93 + 94 + writel(0x0, trng->base + SW_DRBG_BLOCKS); 95 + hisi_trng_set_seed(trng, seed); 96 + 97 + writel(SW_DRBG_BLOCKS_NUM | (0x1 << SW_DRBG_ENABLE_SHIFT), 98 + trng->base + SW_DRBG_BLOCKS); 99 + writel(0x1, trng->base + SW_DRBG_INIT); 100 + 101 + ret = readl_relaxed_poll_timeout(trng->base + SW_DRBG_STATUS, 102 + val, val & BIT(0), SLEEP_US, TIMEOUT_US); 103 + if (ret) 104 + pr_err("fail to init trng(%d)\n", ret); 105 + 106 + return ret; 107 + } 108 + 109 + static int hisi_trng_generate(struct crypto_rng *tfm, const u8 *src, 110 + unsigned int slen, u8 *dstn, unsigned int dlen) 111 + { 112 + struct hisi_trng_ctx *ctx = crypto_rng_ctx(tfm); 113 + struct hisi_trng *trng = ctx->trng; 114 + u32 data[SW_DRBG_DATA_NUM]; 115 + u32 currsize = 0; 116 + u32 val = 0; 117 + int ret; 118 + u32 i; 119 + 120 + if (dlen > SW_DRBG_BLOCKS_NUM * SW_DRBG_BYTES || dlen == 0) { 121 + pr_err("dlen(%d) exceeds limit(%d)!\n", dlen, 122 + SW_DRBG_BLOCKS_NUM * SW_DRBG_BYTES); 123 + return -EINVAL; 124 + } 125 + 126 + do { 127 + ret = readl_relaxed_poll_timeout(trng->base + SW_DRBG_STATUS, 128 + val, val & BIT(1), SLEEP_US, TIMEOUT_US); 129 + if (ret) { 130 + pr_err("fail to generate random number(%d)!\n", ret); 131 + break; 132 + } 133 + 134 + for (i = 0; i < SW_DRBG_DATA_NUM; i++) 135 + data[i] = readl(trng->base + SW_DRBG_DATA(i)); 136 + 137 + if (dlen - currsize >= SW_DRBG_BYTES) { 138 + memcpy(dstn + currsize, data, SW_DRBG_BYTES); 139 + currsize += SW_DRBG_BYTES; 140 + } else { 141 + memcpy(dstn + currsize, data, dlen - currsize); 142 + currsize = dlen; 143 + } 144 + 145 + writel(0x1, trng->base + SW_DRBG_GEN); 146 + } while (currsize < dlen); 147 + 148 + return ret; 149 + } 150 + 151 + static int hisi_trng_init(struct crypto_tfm *tfm) 152 + { 153 + struct hisi_trng_ctx *ctx = crypto_tfm_ctx(tfm); 154 + struct hisi_trng *trng; 155 + int ret = -EBUSY; 156 + 157 + mutex_lock(&trng_devices.lock); 158 + list_for_each_entry(trng, &trng_devices.list, list) { 159 + if (!trng->is_used) { 160 + trng->is_used = true; 161 + ctx->trng = trng; 162 + ret = 0; 163 + break; 164 + } 165 + } 166 + mutex_unlock(&trng_devices.lock); 167 + 168 + return ret; 169 + } 170 + 171 + static void hisi_trng_exit(struct crypto_tfm *tfm) 172 + { 173 + struct hisi_trng_ctx *ctx = crypto_tfm_ctx(tfm); 174 + 175 + mutex_lock(&trng_devices.lock); 176 + ctx->trng->is_used = false; 177 + mutex_unlock(&trng_devices.lock); 178 + } 179 + 180 + static int hisi_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) 181 + { 182 + struct hisi_trng *trng; 183 + int currsize = 0; 184 + u32 val = 0; 185 + u32 ret; 186 + 187 + trng = container_of(rng, struct hisi_trng, rng); 188 + 189 + do { 190 + ret = readl_poll_timeout(trng->base + HISI_TRNG_REG, val, 191 + val, SLEEP_US, TIMEOUT_US); 192 + if (ret) 193 + return currsize; 194 + 195 + if (max - currsize >= HISI_TRNG_BYTES) { 196 + memcpy(buf + currsize, &val, HISI_TRNG_BYTES); 197 + currsize += HISI_TRNG_BYTES; 198 + if (currsize == max) 199 + return currsize; 200 + continue; 201 + } 202 + 203 + /* copy remaining bytes */ 204 + memcpy(buf + currsize, &val, max - currsize); 205 + currsize = max; 206 + } while (currsize < max); 207 + 208 + return currsize; 209 + } 210 + 211 + static struct rng_alg hisi_trng_alg = { 212 + .generate = hisi_trng_generate, 213 + .seed = hisi_trng_seed, 214 + .seedsize = SW_DRBG_SEED_SIZE, 215 + .base = { 216 + .cra_name = "stdrng", 217 + .cra_driver_name = "hisi_stdrng", 218 + .cra_priority = 300, 219 + .cra_ctxsize = sizeof(struct hisi_trng_ctx), 220 + .cra_module = THIS_MODULE, 221 + .cra_init = hisi_trng_init, 222 + .cra_exit = hisi_trng_exit, 223 + }, 224 + }; 225 + 226 + static void hisi_trng_add_to_list(struct hisi_trng *trng) 227 + { 228 + mutex_lock(&trng_devices.lock); 229 + list_add_tail(&trng->list, &trng_devices.list); 230 + mutex_unlock(&trng_devices.lock); 231 + } 232 + 233 + static int hisi_trng_del_from_list(struct hisi_trng *trng) 234 + { 235 + int ret = -EBUSY; 236 + 237 + mutex_lock(&trng_devices.lock); 238 + if (!trng->is_used) { 239 + list_del(&trng->list); 240 + ret = 0; 241 + } 242 + mutex_unlock(&trng_devices.lock); 243 + 244 + return ret; 245 + } 246 + 247 + static int hisi_trng_probe(struct platform_device *pdev) 248 + { 249 + struct hisi_trng *trng; 250 + int ret; 251 + 252 + trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); 253 + if (!trng) 254 + return -ENOMEM; 255 + 256 + platform_set_drvdata(pdev, trng); 257 + 258 + trng->base = devm_platform_ioremap_resource(pdev, 0); 259 + if (IS_ERR(trng->base)) 260 + return PTR_ERR(trng->base); 261 + 262 + trng->is_used = false; 263 + if (!trng_devices.is_init) { 264 + INIT_LIST_HEAD(&trng_devices.list); 265 + mutex_init(&trng_devices.lock); 266 + trng_devices.is_init = true; 267 + } 268 + 269 + hisi_trng_add_to_list(trng); 270 + if (atomic_inc_return(&trng_active_devs) == 1) { 271 + ret = crypto_register_rng(&hisi_trng_alg); 272 + if (ret) { 273 + dev_err(&pdev->dev, 274 + "failed to register crypto(%d)\n", ret); 275 + atomic_dec_return(&trng_active_devs); 276 + goto err_remove_from_list; 277 + } 278 + } 279 + 280 + trng->rng.name = pdev->name; 281 + trng->rng.read = hisi_trng_read; 282 + trng->rng.quality = HISI_TRNG_QUALITY; 283 + ret = devm_hwrng_register(&pdev->dev, &trng->rng); 284 + if (ret) { 285 + dev_err(&pdev->dev, "failed to register hwrng: %d!\n", ret); 286 + goto err_crypto_unregister; 287 + } 288 + 289 + return ret; 290 + 291 + err_crypto_unregister: 292 + if (atomic_dec_return(&trng_active_devs) == 0) 293 + crypto_unregister_rng(&hisi_trng_alg); 294 + 295 + err_remove_from_list: 296 + hisi_trng_del_from_list(trng); 297 + return ret; 298 + } 299 + 300 + static int hisi_trng_remove(struct platform_device *pdev) 301 + { 302 + struct hisi_trng *trng = platform_get_drvdata(pdev); 303 + 304 + /* Wait until the task is finished */ 305 + while (hisi_trng_del_from_list(trng)) 306 + ; 307 + 308 + if (atomic_dec_return(&trng_active_devs) == 0) 309 + crypto_unregister_rng(&hisi_trng_alg); 310 + 311 + return 0; 312 + } 313 + 314 + static const struct acpi_device_id hisi_trng_acpi_match[] = { 315 + { "HISI02B3", 0 }, 316 + { } 317 + }; 318 + MODULE_DEVICE_TABLE(acpi, hisi_trng_acpi_match); 319 + 320 + static struct platform_driver hisi_trng_driver = { 321 + .probe = hisi_trng_probe, 322 + .remove = hisi_trng_remove, 323 + .driver = { 324 + .name = "hisi-trng-v2", 325 + .acpi_match_table = ACPI_PTR(hisi_trng_acpi_match), 326 + }, 327 + }; 328 + 329 + module_platform_driver(hisi_trng_driver); 330 + 331 + MODULE_LICENSE("GPL v2"); 332 + MODULE_AUTHOR("Weili Qian <qianweili@huawei.com>"); 333 + MODULE_AUTHOR("Zaibo Xu <xuzaibo@huawei.com>"); 334 + MODULE_DESCRIPTION("HiSilicon true random number generator V2 driver");
+24 -6
drivers/crypto/hisilicon/zip/zip_main.c
··· 590 590 qm->debug.sqe_mask_offset = HZIP_SQE_MASK_OFFSET; 591 591 qm->debug.sqe_mask_len = HZIP_SQE_MASK_LEN; 592 592 qm->debug.debug_root = dev_d; 593 - ret = hisi_qm_debug_init(qm); 594 - if (ret) 595 - goto failed_to_create; 593 + hisi_qm_debug_init(qm); 596 594 597 595 if (qm->fun_type == QM_HW_PF) { 598 596 ret = hisi_zip_ctrl_debug_init(qm); ··· 747 749 748 750 static int hisi_zip_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) 749 751 { 752 + int ret; 753 + 750 754 qm->pdev = pdev; 751 755 qm->ver = pdev->revision; 752 756 qm->algs = "zlib\ngzip"; ··· 774 774 qm->qp_num = HZIP_QUEUE_NUM_V1 - HZIP_PF_DEF_Q_NUM; 775 775 } 776 776 777 - return hisi_qm_init(qm); 777 + qm->wq = alloc_workqueue("%s", WQ_HIGHPRI | WQ_MEM_RECLAIM | 778 + WQ_UNBOUND, num_online_cpus(), 779 + pci_name(qm->pdev)); 780 + if (!qm->wq) { 781 + pci_err(qm->pdev, "fail to alloc workqueue\n"); 782 + return -ENOMEM; 783 + } 784 + 785 + ret = hisi_qm_init(qm); 786 + if (ret) 787 + destroy_workqueue(qm->wq); 788 + 789 + return ret; 790 + } 791 + 792 + static void hisi_zip_qm_uninit(struct hisi_qm *qm) 793 + { 794 + hisi_qm_uninit(qm); 795 + destroy_workqueue(qm->wq); 778 796 } 779 797 780 798 static int hisi_zip_probe_init(struct hisi_zip *hisi_zip) ··· 874 856 hisi_qm_dev_err_uninit(qm); 875 857 876 858 err_qm_uninit: 877 - hisi_qm_uninit(qm); 859 + hisi_zip_qm_uninit(qm); 878 860 879 861 return ret; 880 862 } ··· 892 874 hisi_zip_debugfs_exit(qm); 893 875 hisi_qm_stop(qm, QM_NORMAL); 894 876 hisi_qm_dev_err_uninit(qm); 895 - hisi_qm_uninit(qm); 877 + hisi_zip_qm_uninit(qm); 896 878 } 897 879 898 880 static const struct pci_error_handlers hisi_zip_err_handler = {
+2 -1
drivers/crypto/img-hash.c
··· 19 19 20 20 #include <crypto/internal/hash.h> 21 21 #include <crypto/md5.h> 22 - #include <crypto/sha.h> 22 + #include <crypto/sha1.h> 23 + #include <crypto/sha2.h> 23 24 24 25 #define CR_RESET 0 25 26 #define CR_RESET_SET 1
+1 -1
drivers/crypto/inside-secure/safexcel.c
··· 1639 1639 1640 1640 priv->ring[i].rdr_req = devm_kcalloc(dev, 1641 1641 EIP197_DEFAULT_RING_SIZE, 1642 - sizeof(priv->ring[i].rdr_req), 1642 + sizeof(*priv->ring[i].rdr_req), 1643 1643 GFP_KERNEL); 1644 1644 if (!priv->ring[i].rdr_req) 1645 1645 return -ENOMEM;
+2 -1
drivers/crypto/inside-secure/safexcel.h
··· 11 11 #include <crypto/aead.h> 12 12 #include <crypto/algapi.h> 13 13 #include <crypto/internal/hash.h> 14 - #include <crypto/sha.h> 14 + #include <crypto/sha1.h> 15 + #include <crypto/sha2.h> 15 16 #include <crypto/sha3.h> 16 17 #include <crypto/skcipher.h> 17 18 #include <linux/types.h>
+2 -1
drivers/crypto/inside-secure/safexcel_cipher.c
··· 18 18 #include <crypto/gcm.h> 19 19 #include <crypto/ghash.h> 20 20 #include <crypto/poly1305.h> 21 - #include <crypto/sha.h> 21 + #include <crypto/sha1.h> 22 + #include <crypto/sha2.h> 22 23 #include <crypto/sm3.h> 23 24 #include <crypto/sm4.h> 24 25 #include <crypto/xts.h>
+2 -1
drivers/crypto/inside-secure/safexcel_hash.c
··· 8 8 #include <crypto/aes.h> 9 9 #include <crypto/hmac.h> 10 10 #include <crypto/md5.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha1.h> 12 + #include <crypto/sha2.h> 12 13 #include <crypto/sha3.h> 13 14 #include <crypto/skcipher.h> 14 15 #include <crypto/sm3.h>
+1 -1
drivers/crypto/ixp4xx_crypto.c
··· 20 20 #include <crypto/internal/des.h> 21 21 #include <crypto/aes.h> 22 22 #include <crypto/hmac.h> 23 - #include <crypto/sha.h> 23 + #include <crypto/sha1.h> 24 24 #include <crypto/algapi.h> 25 25 #include <crypto/internal/aead.h> 26 26 #include <crypto/internal/skcipher.h>
+39
drivers/crypto/keembay/Kconfig
··· 1 + config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4 2 + tristate "Support for Intel Keem Bay OCS AES/SM4 HW acceleration" 3 + depends on OF || COMPILE_TEST 4 + select CRYPTO_SKCIPHER 5 + select CRYPTO_AEAD 6 + select CRYPTO_ENGINE 7 + help 8 + Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) AES and 9 + SM4 cihper hardware acceleration for use with Crypto API. 10 + 11 + Provides HW acceleration for the following transformations: 12 + cbc(aes), ctr(aes), ccm(aes), gcm(aes), cbc(sm4), ctr(sm4), ccm(sm4) 13 + and gcm(sm4). 14 + 15 + Optionally, support for the following transformations can also be 16 + enabled: ecb(aes), cts(cbc(aes)), ecb(sm4) and cts(cbc(sm4)). 17 + 18 + config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 19 + bool "Support for Intel Keem Bay OCS AES/SM4 ECB HW acceleration" 20 + depends on CRYPTO_DEV_KEEMBAY_OCS_AES_SM4 21 + help 22 + Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) 23 + AES/SM4 ECB mode hardware acceleration for use with Crypto API. 24 + 25 + Provides OCS version of ecb(aes) and ecb(sm4) 26 + 27 + Intel does not recommend use of ECB mode with AES/SM4. 28 + 29 + config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 30 + bool "Support for Intel Keem Bay OCS AES/SM4 CTS HW acceleration" 31 + depends on CRYPTO_DEV_KEEMBAY_OCS_AES_SM4 32 + help 33 + Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) 34 + AES/SM4 CBC with CTS mode hardware acceleration for use with 35 + Crypto API. 36 + 37 + Provides OCS version of cts(cbc(aes)) and cts(cbc(sm4)). 38 + 39 + Intel does not recommend use of CTS mode with AES/SM4.
+5
drivers/crypto/keembay/Makefile
··· 1 + # 2 + # Makefile for Intel Keem Bay OCS Crypto API Linux drivers 3 + # 4 + obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4) += keembay-ocs-aes.o 5 + keembay-ocs-aes-objs := keembay-ocs-aes-core.o ocs-aes.o
+1713
drivers/crypto/keembay/keembay-ocs-aes-core.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Keem Bay OCS AES Crypto Driver. 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/completion.h> 10 + #include <linux/crypto.h> 11 + #include <linux/dma-mapping.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/io.h> 14 + #include <linux/module.h> 15 + #include <linux/of.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/types.h> 18 + 19 + #include <crypto/aes.h> 20 + #include <crypto/engine.h> 21 + #include <crypto/gcm.h> 22 + #include <crypto/scatterwalk.h> 23 + 24 + #include <crypto/internal/aead.h> 25 + #include <crypto/internal/skcipher.h> 26 + 27 + #include "ocs-aes.h" 28 + 29 + #define KMB_OCS_PRIORITY 350 30 + #define DRV_NAME "keembay-ocs-aes" 31 + 32 + #define OCS_AES_MIN_KEY_SIZE 16 33 + #define OCS_AES_MAX_KEY_SIZE 32 34 + #define OCS_AES_KEYSIZE_128 16 35 + #define OCS_AES_KEYSIZE_192 24 36 + #define OCS_AES_KEYSIZE_256 32 37 + #define OCS_SM4_KEY_SIZE 16 38 + 39 + /** 40 + * struct ocs_aes_tctx - OCS AES Transform context 41 + * @engine_ctx: Engine context. 42 + * @aes_dev: The OCS AES device. 43 + * @key: AES/SM4 key. 44 + * @key_len: The length (in bytes) of @key. 45 + * @cipher: OCS cipher to use (either AES or SM4). 46 + * @sw_cipher: The cipher to use as fallback. 47 + * @use_fallback: Whether or not fallback cipher should be used. 48 + */ 49 + struct ocs_aes_tctx { 50 + struct crypto_engine_ctx engine_ctx; 51 + struct ocs_aes_dev *aes_dev; 52 + u8 key[OCS_AES_KEYSIZE_256]; 53 + unsigned int key_len; 54 + enum ocs_cipher cipher; 55 + union { 56 + struct crypto_sync_skcipher *sk; 57 + struct crypto_aead *aead; 58 + } sw_cipher; 59 + bool use_fallback; 60 + }; 61 + 62 + /** 63 + * struct ocs_aes_rctx - OCS AES Request context. 64 + * @instruction: Instruction to be executed (encrypt / decrypt). 65 + * @mode: Mode to use (ECB, CBC, CTR, CCm, GCM, CTS) 66 + * @src_nents: Number of source SG entries. 67 + * @dst_nents: Number of destination SG entries. 68 + * @src_dma_count: The number of DMA-mapped entries of the source SG. 69 + * @dst_dma_count: The number of DMA-mapped entries of the destination SG. 70 + * @in_place: Whether or not this is an in place request, i.e., 71 + * src_sg == dst_sg. 72 + * @src_dll: OCS DMA linked list for input data. 73 + * @dst_dll: OCS DMA linked list for output data. 74 + * @last_ct_blk: Buffer to hold last cipher text block (only used in CBC 75 + * mode). 76 + * @cts_swap: Whether or not CTS swap must be performed. 77 + * @aad_src_dll: OCS DMA linked list for input AAD data. 78 + * @aad_dst_dll: OCS DMA linked list for output AAD data. 79 + * @in_tag: Buffer to hold input encrypted tag (only used for 80 + * CCM/GCM decrypt). 81 + * @out_tag: Buffer to hold output encrypted / decrypted tag (only 82 + * used for GCM encrypt / decrypt). 83 + */ 84 + struct ocs_aes_rctx { 85 + /* Fields common across all modes. */ 86 + enum ocs_instruction instruction; 87 + enum ocs_mode mode; 88 + int src_nents; 89 + int dst_nents; 90 + int src_dma_count; 91 + int dst_dma_count; 92 + bool in_place; 93 + struct ocs_dll_desc src_dll; 94 + struct ocs_dll_desc dst_dll; 95 + 96 + /* CBC specific */ 97 + u8 last_ct_blk[AES_BLOCK_SIZE]; 98 + 99 + /* CTS specific */ 100 + int cts_swap; 101 + 102 + /* CCM/GCM specific */ 103 + struct ocs_dll_desc aad_src_dll; 104 + struct ocs_dll_desc aad_dst_dll; 105 + u8 in_tag[AES_BLOCK_SIZE]; 106 + 107 + /* GCM specific */ 108 + u8 out_tag[AES_BLOCK_SIZE]; 109 + }; 110 + 111 + /* Driver data. */ 112 + struct ocs_aes_drv { 113 + struct list_head dev_list; 114 + spinlock_t lock; /* Protects dev_list. */ 115 + }; 116 + 117 + static struct ocs_aes_drv ocs_aes = { 118 + .dev_list = LIST_HEAD_INIT(ocs_aes.dev_list), 119 + .lock = __SPIN_LOCK_UNLOCKED(ocs_aes.lock), 120 + }; 121 + 122 + static struct ocs_aes_dev *kmb_ocs_aes_find_dev(struct ocs_aes_tctx *tctx) 123 + { 124 + struct ocs_aes_dev *aes_dev; 125 + 126 + spin_lock(&ocs_aes.lock); 127 + 128 + if (tctx->aes_dev) { 129 + aes_dev = tctx->aes_dev; 130 + goto exit; 131 + } 132 + 133 + /* Only a single OCS device available */ 134 + aes_dev = list_first_entry(&ocs_aes.dev_list, struct ocs_aes_dev, list); 135 + tctx->aes_dev = aes_dev; 136 + 137 + exit: 138 + spin_unlock(&ocs_aes.lock); 139 + 140 + return aes_dev; 141 + } 142 + 143 + /* 144 + * Ensure key is 128-bit or 256-bit for AES or 128-bit for SM4 and an actual 145 + * key is being passed in. 146 + * 147 + * Return: 0 if key is valid, -EINVAL otherwise. 148 + */ 149 + static int check_key(const u8 *in_key, size_t key_len, enum ocs_cipher cipher) 150 + { 151 + if (!in_key) 152 + return -EINVAL; 153 + 154 + /* For AES, only 128-byte or 256-byte keys are supported. */ 155 + if (cipher == OCS_AES && (key_len == OCS_AES_KEYSIZE_128 || 156 + key_len == OCS_AES_KEYSIZE_256)) 157 + return 0; 158 + 159 + /* For SM4, only 128-byte keys are supported. */ 160 + if (cipher == OCS_SM4 && key_len == OCS_AES_KEYSIZE_128) 161 + return 0; 162 + 163 + /* Everything else is unsupported. */ 164 + return -EINVAL; 165 + } 166 + 167 + /* Save key into transformation context. */ 168 + static int save_key(struct ocs_aes_tctx *tctx, const u8 *in_key, size_t key_len, 169 + enum ocs_cipher cipher) 170 + { 171 + int ret; 172 + 173 + ret = check_key(in_key, key_len, cipher); 174 + if (ret) 175 + return ret; 176 + 177 + memcpy(tctx->key, in_key, key_len); 178 + tctx->key_len = key_len; 179 + tctx->cipher = cipher; 180 + 181 + return 0; 182 + } 183 + 184 + /* Set key for symmetric cypher. */ 185 + static int kmb_ocs_sk_set_key(struct crypto_skcipher *tfm, const u8 *in_key, 186 + size_t key_len, enum ocs_cipher cipher) 187 + { 188 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 189 + 190 + /* Fallback is used for AES with 192-bit key. */ 191 + tctx->use_fallback = (cipher == OCS_AES && 192 + key_len == OCS_AES_KEYSIZE_192); 193 + 194 + if (!tctx->use_fallback) 195 + return save_key(tctx, in_key, key_len, cipher); 196 + 197 + crypto_sync_skcipher_clear_flags(tctx->sw_cipher.sk, 198 + CRYPTO_TFM_REQ_MASK); 199 + crypto_sync_skcipher_set_flags(tctx->sw_cipher.sk, 200 + tfm->base.crt_flags & 201 + CRYPTO_TFM_REQ_MASK); 202 + 203 + return crypto_sync_skcipher_setkey(tctx->sw_cipher.sk, in_key, key_len); 204 + } 205 + 206 + /* Set key for AEAD cipher. */ 207 + static int kmb_ocs_aead_set_key(struct crypto_aead *tfm, const u8 *in_key, 208 + size_t key_len, enum ocs_cipher cipher) 209 + { 210 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(tfm); 211 + 212 + /* Fallback is used for AES with 192-bit key. */ 213 + tctx->use_fallback = (cipher == OCS_AES && 214 + key_len == OCS_AES_KEYSIZE_192); 215 + 216 + if (!tctx->use_fallback) 217 + return save_key(tctx, in_key, key_len, cipher); 218 + 219 + crypto_aead_clear_flags(tctx->sw_cipher.aead, CRYPTO_TFM_REQ_MASK); 220 + crypto_aead_set_flags(tctx->sw_cipher.aead, 221 + crypto_aead_get_flags(tfm) & CRYPTO_TFM_REQ_MASK); 222 + 223 + return crypto_aead_setkey(tctx->sw_cipher.aead, in_key, key_len); 224 + } 225 + 226 + /* Swap two AES blocks in SG lists. */ 227 + static void sg_swap_blocks(struct scatterlist *sgl, unsigned int nents, 228 + off_t blk1_offset, off_t blk2_offset) 229 + { 230 + u8 tmp_buf1[AES_BLOCK_SIZE], tmp_buf2[AES_BLOCK_SIZE]; 231 + 232 + /* 233 + * No easy way to copy within sg list, so copy both blocks to temporary 234 + * buffers first. 235 + */ 236 + sg_pcopy_to_buffer(sgl, nents, tmp_buf1, AES_BLOCK_SIZE, blk1_offset); 237 + sg_pcopy_to_buffer(sgl, nents, tmp_buf2, AES_BLOCK_SIZE, blk2_offset); 238 + sg_pcopy_from_buffer(sgl, nents, tmp_buf1, AES_BLOCK_SIZE, blk2_offset); 239 + sg_pcopy_from_buffer(sgl, nents, tmp_buf2, AES_BLOCK_SIZE, blk1_offset); 240 + } 241 + 242 + /* Initialize request context to default values. */ 243 + static void ocs_aes_init_rctx(struct ocs_aes_rctx *rctx) 244 + { 245 + /* Zero everything. */ 246 + memset(rctx, 0, sizeof(*rctx)); 247 + 248 + /* Set initial value for DMA addresses. */ 249 + rctx->src_dll.dma_addr = DMA_MAPPING_ERROR; 250 + rctx->dst_dll.dma_addr = DMA_MAPPING_ERROR; 251 + rctx->aad_src_dll.dma_addr = DMA_MAPPING_ERROR; 252 + rctx->aad_dst_dll.dma_addr = DMA_MAPPING_ERROR; 253 + } 254 + 255 + static int kmb_ocs_sk_validate_input(struct skcipher_request *req, 256 + enum ocs_mode mode) 257 + { 258 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 259 + int iv_size = crypto_skcipher_ivsize(tfm); 260 + 261 + switch (mode) { 262 + case OCS_MODE_ECB: 263 + /* Ensure input length is multiple of block size */ 264 + if (req->cryptlen % AES_BLOCK_SIZE != 0) 265 + return -EINVAL; 266 + 267 + return 0; 268 + 269 + case OCS_MODE_CBC: 270 + /* Ensure input length is multiple of block size */ 271 + if (req->cryptlen % AES_BLOCK_SIZE != 0) 272 + return -EINVAL; 273 + 274 + /* Ensure IV is present and block size in length */ 275 + if (!req->iv || iv_size != AES_BLOCK_SIZE) 276 + return -EINVAL; 277 + /* 278 + * NOTE: Since req->cryptlen == 0 case was already handled in 279 + * kmb_ocs_sk_common(), the above two conditions also guarantee 280 + * that: cryptlen >= iv_size 281 + */ 282 + return 0; 283 + 284 + case OCS_MODE_CTR: 285 + /* Ensure IV is present and block size in length */ 286 + if (!req->iv || iv_size != AES_BLOCK_SIZE) 287 + return -EINVAL; 288 + return 0; 289 + 290 + case OCS_MODE_CTS: 291 + /* Ensure input length >= block size */ 292 + if (req->cryptlen < AES_BLOCK_SIZE) 293 + return -EINVAL; 294 + 295 + /* Ensure IV is present and block size in length */ 296 + if (!req->iv || iv_size != AES_BLOCK_SIZE) 297 + return -EINVAL; 298 + 299 + return 0; 300 + default: 301 + return -EINVAL; 302 + } 303 + } 304 + 305 + /* 306 + * Called by encrypt() / decrypt() skcipher functions. 307 + * 308 + * Use fallback if needed, otherwise initialize context and enqueue request 309 + * into engine. 310 + */ 311 + static int kmb_ocs_sk_common(struct skcipher_request *req, 312 + enum ocs_cipher cipher, 313 + enum ocs_instruction instruction, 314 + enum ocs_mode mode) 315 + { 316 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 317 + struct ocs_aes_rctx *rctx = skcipher_request_ctx(req); 318 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 319 + struct ocs_aes_dev *aes_dev; 320 + int rc; 321 + 322 + if (tctx->use_fallback) { 323 + SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, tctx->sw_cipher.sk); 324 + 325 + skcipher_request_set_sync_tfm(subreq, tctx->sw_cipher.sk); 326 + skcipher_request_set_callback(subreq, req->base.flags, NULL, 327 + NULL); 328 + skcipher_request_set_crypt(subreq, req->src, req->dst, 329 + req->cryptlen, req->iv); 330 + 331 + if (instruction == OCS_ENCRYPT) 332 + rc = crypto_skcipher_encrypt(subreq); 333 + else 334 + rc = crypto_skcipher_decrypt(subreq); 335 + 336 + skcipher_request_zero(subreq); 337 + 338 + return rc; 339 + } 340 + 341 + /* 342 + * If cryptlen == 0, no processing needed for ECB, CBC and CTR. 343 + * 344 + * For CTS continue: kmb_ocs_sk_validate_input() will return -EINVAL. 345 + */ 346 + if (!req->cryptlen && mode != OCS_MODE_CTS) 347 + return 0; 348 + 349 + rc = kmb_ocs_sk_validate_input(req, mode); 350 + if (rc) 351 + return rc; 352 + 353 + aes_dev = kmb_ocs_aes_find_dev(tctx); 354 + if (!aes_dev) 355 + return -ENODEV; 356 + 357 + if (cipher != tctx->cipher) 358 + return -EINVAL; 359 + 360 + ocs_aes_init_rctx(rctx); 361 + rctx->instruction = instruction; 362 + rctx->mode = mode; 363 + 364 + return crypto_transfer_skcipher_request_to_engine(aes_dev->engine, req); 365 + } 366 + 367 + static void cleanup_ocs_dma_linked_list(struct device *dev, 368 + struct ocs_dll_desc *dll) 369 + { 370 + if (dll->vaddr) 371 + dma_free_coherent(dev, dll->size, dll->vaddr, dll->dma_addr); 372 + dll->vaddr = NULL; 373 + dll->size = 0; 374 + dll->dma_addr = DMA_MAPPING_ERROR; 375 + } 376 + 377 + static void kmb_ocs_sk_dma_cleanup(struct skcipher_request *req) 378 + { 379 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 380 + struct ocs_aes_rctx *rctx = skcipher_request_ctx(req); 381 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 382 + struct device *dev = tctx->aes_dev->dev; 383 + 384 + if (rctx->src_dma_count) { 385 + dma_unmap_sg(dev, req->src, rctx->src_nents, DMA_TO_DEVICE); 386 + rctx->src_dma_count = 0; 387 + } 388 + 389 + if (rctx->dst_dma_count) { 390 + dma_unmap_sg(dev, req->dst, rctx->dst_nents, rctx->in_place ? 391 + DMA_BIDIRECTIONAL : 392 + DMA_FROM_DEVICE); 393 + rctx->dst_dma_count = 0; 394 + } 395 + 396 + /* Clean up OCS DMA linked lists */ 397 + cleanup_ocs_dma_linked_list(dev, &rctx->src_dll); 398 + cleanup_ocs_dma_linked_list(dev, &rctx->dst_dll); 399 + } 400 + 401 + static int kmb_ocs_sk_prepare_inplace(struct skcipher_request *req) 402 + { 403 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 404 + struct ocs_aes_rctx *rctx = skcipher_request_ctx(req); 405 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 406 + int iv_size = crypto_skcipher_ivsize(tfm); 407 + int rc; 408 + 409 + /* 410 + * For CBC decrypt, save last block (iv) to last_ct_blk buffer. 411 + * 412 + * Note: if we are here, we already checked that cryptlen >= iv_size 413 + * and iv_size == AES_BLOCK_SIZE (i.e., the size of last_ct_blk); see 414 + * kmb_ocs_sk_validate_input(). 415 + */ 416 + if (rctx->mode == OCS_MODE_CBC && rctx->instruction == OCS_DECRYPT) 417 + scatterwalk_map_and_copy(rctx->last_ct_blk, req->src, 418 + req->cryptlen - iv_size, iv_size, 0); 419 + 420 + /* For CTS decrypt, swap last two blocks, if needed. */ 421 + if (rctx->cts_swap && rctx->instruction == OCS_DECRYPT) 422 + sg_swap_blocks(req->dst, rctx->dst_nents, 423 + req->cryptlen - AES_BLOCK_SIZE, 424 + req->cryptlen - (2 * AES_BLOCK_SIZE)); 425 + 426 + /* src and dst buffers are the same, use bidirectional DMA mapping. */ 427 + rctx->dst_dma_count = dma_map_sg(tctx->aes_dev->dev, req->dst, 428 + rctx->dst_nents, DMA_BIDIRECTIONAL); 429 + if (rctx->dst_dma_count == 0) { 430 + dev_err(tctx->aes_dev->dev, "Failed to map destination sg\n"); 431 + return -ENOMEM; 432 + } 433 + 434 + /* Create DST linked list */ 435 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 436 + rctx->dst_dma_count, &rctx->dst_dll, 437 + req->cryptlen, 0); 438 + if (rc) 439 + return rc; 440 + /* 441 + * If descriptor creation was successful, set the src_dll.dma_addr to 442 + * the value of dst_dll.dma_addr, as we do in-place AES operation on 443 + * the src. 444 + */ 445 + rctx->src_dll.dma_addr = rctx->dst_dll.dma_addr; 446 + 447 + return 0; 448 + } 449 + 450 + static int kmb_ocs_sk_prepare_notinplace(struct skcipher_request *req) 451 + { 452 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 453 + struct ocs_aes_rctx *rctx = skcipher_request_ctx(req); 454 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 455 + int rc; 456 + 457 + rctx->src_nents = sg_nents_for_len(req->src, req->cryptlen); 458 + if (rctx->src_nents < 0) 459 + return -EBADMSG; 460 + 461 + /* Map SRC SG. */ 462 + rctx->src_dma_count = dma_map_sg(tctx->aes_dev->dev, req->src, 463 + rctx->src_nents, DMA_TO_DEVICE); 464 + if (rctx->src_dma_count == 0) { 465 + dev_err(tctx->aes_dev->dev, "Failed to map source sg\n"); 466 + return -ENOMEM; 467 + } 468 + 469 + /* Create SRC linked list */ 470 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->src, 471 + rctx->src_dma_count, &rctx->src_dll, 472 + req->cryptlen, 0); 473 + if (rc) 474 + return rc; 475 + 476 + /* Map DST SG. */ 477 + rctx->dst_dma_count = dma_map_sg(tctx->aes_dev->dev, req->dst, 478 + rctx->dst_nents, DMA_FROM_DEVICE); 479 + if (rctx->dst_dma_count == 0) { 480 + dev_err(tctx->aes_dev->dev, "Failed to map destination sg\n"); 481 + return -ENOMEM; 482 + } 483 + 484 + /* Create DST linked list */ 485 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 486 + rctx->dst_dma_count, &rctx->dst_dll, 487 + req->cryptlen, 0); 488 + if (rc) 489 + return rc; 490 + 491 + /* If this is not a CTS decrypt operation with swapping, we are done. */ 492 + if (!(rctx->cts_swap && rctx->instruction == OCS_DECRYPT)) 493 + return 0; 494 + 495 + /* 496 + * Otherwise, we have to copy src to dst (as we cannot modify src). 497 + * Use OCS AES bypass mode to copy src to dst via DMA. 498 + * 499 + * NOTE: for anything other than small data sizes this is rather 500 + * inefficient. 501 + */ 502 + rc = ocs_aes_bypass_op(tctx->aes_dev, rctx->dst_dll.dma_addr, 503 + rctx->src_dll.dma_addr, req->cryptlen); 504 + if (rc) 505 + return rc; 506 + 507 + /* 508 + * Now dst == src, so clean up what we did so far and use in_place 509 + * logic. 510 + */ 511 + kmb_ocs_sk_dma_cleanup(req); 512 + rctx->in_place = true; 513 + 514 + return kmb_ocs_sk_prepare_inplace(req); 515 + } 516 + 517 + static int kmb_ocs_sk_run(struct skcipher_request *req) 518 + { 519 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 520 + struct ocs_aes_rctx *rctx = skcipher_request_ctx(req); 521 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 522 + struct ocs_aes_dev *aes_dev = tctx->aes_dev; 523 + int iv_size = crypto_skcipher_ivsize(tfm); 524 + int rc; 525 + 526 + rctx->dst_nents = sg_nents_for_len(req->dst, req->cryptlen); 527 + if (rctx->dst_nents < 0) 528 + return -EBADMSG; 529 + 530 + /* 531 + * If 2 blocks or greater, and multiple of block size swap last two 532 + * blocks to be compatible with other crypto API CTS implementations: 533 + * OCS mode uses CBC-CS2, whereas other crypto API implementations use 534 + * CBC-CS3. 535 + * CBC-CS2 and CBC-CS3 defined by: 536 + * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a-add.pdf 537 + */ 538 + rctx->cts_swap = (rctx->mode == OCS_MODE_CTS && 539 + req->cryptlen > AES_BLOCK_SIZE && 540 + req->cryptlen % AES_BLOCK_SIZE == 0); 541 + 542 + rctx->in_place = (req->src == req->dst); 543 + 544 + if (rctx->in_place) 545 + rc = kmb_ocs_sk_prepare_inplace(req); 546 + else 547 + rc = kmb_ocs_sk_prepare_notinplace(req); 548 + 549 + if (rc) 550 + goto error; 551 + 552 + rc = ocs_aes_op(aes_dev, rctx->mode, tctx->cipher, rctx->instruction, 553 + rctx->dst_dll.dma_addr, rctx->src_dll.dma_addr, 554 + req->cryptlen, req->iv, iv_size); 555 + if (rc) 556 + goto error; 557 + 558 + /* Clean-up DMA before further processing output. */ 559 + kmb_ocs_sk_dma_cleanup(req); 560 + 561 + /* For CTS Encrypt, swap last 2 blocks, if needed. */ 562 + if (rctx->cts_swap && rctx->instruction == OCS_ENCRYPT) { 563 + sg_swap_blocks(req->dst, rctx->dst_nents, 564 + req->cryptlen - AES_BLOCK_SIZE, 565 + req->cryptlen - (2 * AES_BLOCK_SIZE)); 566 + return 0; 567 + } 568 + 569 + /* For CBC copy IV to req->IV. */ 570 + if (rctx->mode == OCS_MODE_CBC) { 571 + /* CBC encrypt case. */ 572 + if (rctx->instruction == OCS_ENCRYPT) { 573 + scatterwalk_map_and_copy(req->iv, req->dst, 574 + req->cryptlen - iv_size, 575 + iv_size, 0); 576 + return 0; 577 + } 578 + /* CBC decrypt case. */ 579 + if (rctx->in_place) 580 + memcpy(req->iv, rctx->last_ct_blk, iv_size); 581 + else 582 + scatterwalk_map_and_copy(req->iv, req->src, 583 + req->cryptlen - iv_size, 584 + iv_size, 0); 585 + return 0; 586 + } 587 + /* For all other modes there's nothing to do. */ 588 + 589 + return 0; 590 + 591 + error: 592 + kmb_ocs_sk_dma_cleanup(req); 593 + 594 + return rc; 595 + } 596 + 597 + static int kmb_ocs_aead_validate_input(struct aead_request *req, 598 + enum ocs_instruction instruction, 599 + enum ocs_mode mode) 600 + { 601 + struct crypto_aead *tfm = crypto_aead_reqtfm(req); 602 + int tag_size = crypto_aead_authsize(tfm); 603 + int iv_size = crypto_aead_ivsize(tfm); 604 + 605 + /* For decrypt crytplen == len(PT) + len(tag). */ 606 + if (instruction == OCS_DECRYPT && req->cryptlen < tag_size) 607 + return -EINVAL; 608 + 609 + /* IV is mandatory. */ 610 + if (!req->iv) 611 + return -EINVAL; 612 + 613 + switch (mode) { 614 + case OCS_MODE_GCM: 615 + if (iv_size != GCM_AES_IV_SIZE) 616 + return -EINVAL; 617 + 618 + return 0; 619 + 620 + case OCS_MODE_CCM: 621 + /* Ensure IV is present and block size in length */ 622 + if (iv_size != AES_BLOCK_SIZE) 623 + return -EINVAL; 624 + 625 + return 0; 626 + 627 + default: 628 + return -EINVAL; 629 + } 630 + } 631 + 632 + /* 633 + * Called by encrypt() / decrypt() aead functions. 634 + * 635 + * Use fallback if needed, otherwise initialize context and enqueue request 636 + * into engine. 637 + */ 638 + static int kmb_ocs_aead_common(struct aead_request *req, 639 + enum ocs_cipher cipher, 640 + enum ocs_instruction instruction, 641 + enum ocs_mode mode) 642 + { 643 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); 644 + struct ocs_aes_rctx *rctx = aead_request_ctx(req); 645 + struct ocs_aes_dev *dd; 646 + int rc; 647 + 648 + if (tctx->use_fallback) { 649 + struct aead_request *subreq = aead_request_ctx(req); 650 + 651 + aead_request_set_tfm(subreq, tctx->sw_cipher.aead); 652 + aead_request_set_callback(subreq, req->base.flags, 653 + req->base.complete, req->base.data); 654 + aead_request_set_crypt(subreq, req->src, req->dst, 655 + req->cryptlen, req->iv); 656 + aead_request_set_ad(subreq, req->assoclen); 657 + rc = crypto_aead_setauthsize(tctx->sw_cipher.aead, 658 + crypto_aead_authsize(crypto_aead_reqtfm(req))); 659 + if (rc) 660 + return rc; 661 + 662 + return (instruction == OCS_ENCRYPT) ? 663 + crypto_aead_encrypt(subreq) : 664 + crypto_aead_decrypt(subreq); 665 + } 666 + 667 + rc = kmb_ocs_aead_validate_input(req, instruction, mode); 668 + if (rc) 669 + return rc; 670 + 671 + dd = kmb_ocs_aes_find_dev(tctx); 672 + if (!dd) 673 + return -ENODEV; 674 + 675 + if (cipher != tctx->cipher) 676 + return -EINVAL; 677 + 678 + ocs_aes_init_rctx(rctx); 679 + rctx->instruction = instruction; 680 + rctx->mode = mode; 681 + 682 + return crypto_transfer_aead_request_to_engine(dd->engine, req); 683 + } 684 + 685 + static void kmb_ocs_aead_dma_cleanup(struct aead_request *req) 686 + { 687 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); 688 + struct ocs_aes_rctx *rctx = aead_request_ctx(req); 689 + struct device *dev = tctx->aes_dev->dev; 690 + 691 + if (rctx->src_dma_count) { 692 + dma_unmap_sg(dev, req->src, rctx->src_nents, DMA_TO_DEVICE); 693 + rctx->src_dma_count = 0; 694 + } 695 + 696 + if (rctx->dst_dma_count) { 697 + dma_unmap_sg(dev, req->dst, rctx->dst_nents, rctx->in_place ? 698 + DMA_BIDIRECTIONAL : 699 + DMA_FROM_DEVICE); 700 + rctx->dst_dma_count = 0; 701 + } 702 + /* Clean up OCS DMA linked lists */ 703 + cleanup_ocs_dma_linked_list(dev, &rctx->src_dll); 704 + cleanup_ocs_dma_linked_list(dev, &rctx->dst_dll); 705 + cleanup_ocs_dma_linked_list(dev, &rctx->aad_src_dll); 706 + cleanup_ocs_dma_linked_list(dev, &rctx->aad_dst_dll); 707 + } 708 + 709 + /** 710 + * kmb_ocs_aead_dma_prepare() - Do DMA mapping for AEAD processing. 711 + * @req: The AEAD request being processed. 712 + * @src_dll_size: Where to store the length of the data mapped into the 713 + * src_dll OCS DMA list. 714 + * 715 + * Do the following: 716 + * - DMA map req->src and req->dst 717 + * - Initialize the following OCS DMA linked lists: rctx->src_dll, 718 + * rctx->dst_dll, rctx->aad_src_dll and rxtc->aad_dst_dll. 719 + * 720 + * Return: 0 on success, negative error code otherwise. 721 + */ 722 + static int kmb_ocs_aead_dma_prepare(struct aead_request *req, u32 *src_dll_size) 723 + { 724 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); 725 + const int tag_size = crypto_aead_authsize(crypto_aead_reqtfm(req)); 726 + struct ocs_aes_rctx *rctx = aead_request_ctx(req); 727 + u32 in_size; /* The length of the data to be mapped by src_dll. */ 728 + u32 out_size; /* The length of the data to be mapped by dst_dll. */ 729 + u32 dst_size; /* The length of the data in dst_sg. */ 730 + int rc; 731 + 732 + /* Get number of entries in input data SG list. */ 733 + rctx->src_nents = sg_nents_for_len(req->src, 734 + req->assoclen + req->cryptlen); 735 + if (rctx->src_nents < 0) 736 + return -EBADMSG; 737 + 738 + if (rctx->instruction == OCS_DECRYPT) { 739 + /* 740 + * For decrypt: 741 + * - src sg list is: AAD|CT|tag 742 + * - dst sg list expects: AAD|PT 743 + * 744 + * in_size == len(CT); out_size == len(PT) 745 + */ 746 + 747 + /* req->cryptlen includes both CT and tag. */ 748 + in_size = req->cryptlen - tag_size; 749 + 750 + /* out_size = PT size == CT size */ 751 + out_size = in_size; 752 + 753 + /* len(dst_sg) == len(AAD) + len(PT) */ 754 + dst_size = req->assoclen + out_size; 755 + 756 + /* 757 + * Copy tag from source SG list to 'in_tag' buffer. 758 + * 759 + * Note: this needs to be done here, before DMA mapping src_sg. 760 + */ 761 + sg_pcopy_to_buffer(req->src, rctx->src_nents, rctx->in_tag, 762 + tag_size, req->assoclen + in_size); 763 + 764 + } else { /* OCS_ENCRYPT */ 765 + /* 766 + * For encrypt: 767 + * src sg list is: AAD|PT 768 + * dst sg list expects: AAD|CT|tag 769 + */ 770 + /* in_size == len(PT) */ 771 + in_size = req->cryptlen; 772 + 773 + /* 774 + * In CCM mode the OCS engine appends the tag to the ciphertext, 775 + * but in GCM mode the tag must be read from the tag registers 776 + * and appended manually below 777 + */ 778 + out_size = (rctx->mode == OCS_MODE_CCM) ? in_size + tag_size : 779 + in_size; 780 + /* len(dst_sg) == len(AAD) + len(CT) + len(tag) */ 781 + dst_size = req->assoclen + in_size + tag_size; 782 + } 783 + *src_dll_size = in_size; 784 + 785 + /* Get number of entries in output data SG list. */ 786 + rctx->dst_nents = sg_nents_for_len(req->dst, dst_size); 787 + if (rctx->dst_nents < 0) 788 + return -EBADMSG; 789 + 790 + rctx->in_place = (req->src == req->dst) ? 1 : 0; 791 + 792 + /* Map destination; use bidirectional mapping for in-place case. */ 793 + rctx->dst_dma_count = dma_map_sg(tctx->aes_dev->dev, req->dst, 794 + rctx->dst_nents, 795 + rctx->in_place ? DMA_BIDIRECTIONAL : 796 + DMA_FROM_DEVICE); 797 + if (rctx->dst_dma_count == 0 && rctx->dst_nents != 0) { 798 + dev_err(tctx->aes_dev->dev, "Failed to map destination sg\n"); 799 + return -ENOMEM; 800 + } 801 + 802 + /* Create AAD DST list: maps dst[0:AAD_SIZE-1]. */ 803 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 804 + rctx->dst_dma_count, 805 + &rctx->aad_dst_dll, req->assoclen, 806 + 0); 807 + if (rc) 808 + return rc; 809 + 810 + /* Create DST list: maps dst[AAD_SIZE:out_size] */ 811 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 812 + rctx->dst_dma_count, &rctx->dst_dll, 813 + out_size, req->assoclen); 814 + if (rc) 815 + return rc; 816 + 817 + if (rctx->in_place) { 818 + /* If this is not CCM encrypt, we are done. */ 819 + if (!(rctx->mode == OCS_MODE_CCM && 820 + rctx->instruction == OCS_ENCRYPT)) { 821 + /* 822 + * SRC and DST are the same, so re-use the same DMA 823 + * addresses (to avoid allocating new DMA lists 824 + * identical to the dst ones). 825 + */ 826 + rctx->src_dll.dma_addr = rctx->dst_dll.dma_addr; 827 + rctx->aad_src_dll.dma_addr = rctx->aad_dst_dll.dma_addr; 828 + 829 + return 0; 830 + } 831 + /* 832 + * For CCM encrypt the input and output linked lists contain 833 + * different amounts of data, so, we need to create different 834 + * SRC and AAD SRC lists, even for the in-place case. 835 + */ 836 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 837 + rctx->dst_dma_count, 838 + &rctx->aad_src_dll, 839 + req->assoclen, 0); 840 + if (rc) 841 + return rc; 842 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->dst, 843 + rctx->dst_dma_count, 844 + &rctx->src_dll, in_size, 845 + req->assoclen); 846 + if (rc) 847 + return rc; 848 + 849 + return 0; 850 + } 851 + /* Not in-place case. */ 852 + 853 + /* Map source SG. */ 854 + rctx->src_dma_count = dma_map_sg(tctx->aes_dev->dev, req->src, 855 + rctx->src_nents, DMA_TO_DEVICE); 856 + if (rctx->src_dma_count == 0 && rctx->src_nents != 0) { 857 + dev_err(tctx->aes_dev->dev, "Failed to map source sg\n"); 858 + return -ENOMEM; 859 + } 860 + 861 + /* Create AAD SRC list. */ 862 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->src, 863 + rctx->src_dma_count, 864 + &rctx->aad_src_dll, 865 + req->assoclen, 0); 866 + if (rc) 867 + return rc; 868 + 869 + /* Create SRC list. */ 870 + rc = ocs_create_linked_list_from_sg(tctx->aes_dev, req->src, 871 + rctx->src_dma_count, 872 + &rctx->src_dll, in_size, 873 + req->assoclen); 874 + if (rc) 875 + return rc; 876 + 877 + if (req->assoclen == 0) 878 + return 0; 879 + 880 + /* Copy AAD from src sg to dst sg using OCS DMA. */ 881 + rc = ocs_aes_bypass_op(tctx->aes_dev, rctx->aad_dst_dll.dma_addr, 882 + rctx->aad_src_dll.dma_addr, req->cryptlen); 883 + if (rc) 884 + dev_err(tctx->aes_dev->dev, 885 + "Failed to copy source AAD to destination AAD\n"); 886 + 887 + return rc; 888 + } 889 + 890 + static int kmb_ocs_aead_run(struct aead_request *req) 891 + { 892 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); 893 + const int tag_size = crypto_aead_authsize(crypto_aead_reqtfm(req)); 894 + struct ocs_aes_rctx *rctx = aead_request_ctx(req); 895 + u32 in_size; /* The length of the data mapped by src_dll. */ 896 + int rc; 897 + 898 + rc = kmb_ocs_aead_dma_prepare(req, &in_size); 899 + if (rc) 900 + goto exit; 901 + 902 + /* For CCM, we just call the OCS processing and we are done. */ 903 + if (rctx->mode == OCS_MODE_CCM) { 904 + rc = ocs_aes_ccm_op(tctx->aes_dev, tctx->cipher, 905 + rctx->instruction, rctx->dst_dll.dma_addr, 906 + rctx->src_dll.dma_addr, in_size, 907 + req->iv, 908 + rctx->aad_src_dll.dma_addr, req->assoclen, 909 + rctx->in_tag, tag_size); 910 + goto exit; 911 + } 912 + /* GCM case; invoke OCS processing. */ 913 + rc = ocs_aes_gcm_op(tctx->aes_dev, tctx->cipher, 914 + rctx->instruction, 915 + rctx->dst_dll.dma_addr, 916 + rctx->src_dll.dma_addr, in_size, 917 + req->iv, 918 + rctx->aad_src_dll.dma_addr, req->assoclen, 919 + rctx->out_tag, tag_size); 920 + if (rc) 921 + goto exit; 922 + 923 + /* For GCM decrypt, we have to compare in_tag with out_tag. */ 924 + if (rctx->instruction == OCS_DECRYPT) { 925 + rc = memcmp(rctx->in_tag, rctx->out_tag, tag_size) ? 926 + -EBADMSG : 0; 927 + goto exit; 928 + } 929 + 930 + /* For GCM encrypt, we must manually copy out_tag to DST sg. */ 931 + 932 + /* Clean-up must be called before the sg_pcopy_from_buffer() below. */ 933 + kmb_ocs_aead_dma_cleanup(req); 934 + 935 + /* Copy tag to destination sg after AAD and CT. */ 936 + sg_pcopy_from_buffer(req->dst, rctx->dst_nents, rctx->out_tag, 937 + tag_size, req->assoclen + req->cryptlen); 938 + 939 + /* Return directly as DMA cleanup already done. */ 940 + return 0; 941 + 942 + exit: 943 + kmb_ocs_aead_dma_cleanup(req); 944 + 945 + return rc; 946 + } 947 + 948 + static int kmb_ocs_aes_sk_do_one_request(struct crypto_engine *engine, 949 + void *areq) 950 + { 951 + struct skcipher_request *req = 952 + container_of(areq, struct skcipher_request, base); 953 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 954 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 955 + int err; 956 + 957 + if (!tctx->aes_dev) { 958 + err = -ENODEV; 959 + goto exit; 960 + } 961 + 962 + err = ocs_aes_set_key(tctx->aes_dev, tctx->key_len, tctx->key, 963 + tctx->cipher); 964 + if (err) 965 + goto exit; 966 + 967 + err = kmb_ocs_sk_run(req); 968 + 969 + exit: 970 + crypto_finalize_skcipher_request(engine, req, err); 971 + 972 + return 0; 973 + } 974 + 975 + static int kmb_ocs_aes_aead_do_one_request(struct crypto_engine *engine, 976 + void *areq) 977 + { 978 + struct aead_request *req = container_of(areq, 979 + struct aead_request, base); 980 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); 981 + int err; 982 + 983 + if (!tctx->aes_dev) 984 + return -ENODEV; 985 + 986 + err = ocs_aes_set_key(tctx->aes_dev, tctx->key_len, tctx->key, 987 + tctx->cipher); 988 + if (err) 989 + goto exit; 990 + 991 + err = kmb_ocs_aead_run(req); 992 + 993 + exit: 994 + crypto_finalize_aead_request(tctx->aes_dev->engine, req, err); 995 + 996 + return 0; 997 + } 998 + 999 + static int kmb_ocs_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key, 1000 + unsigned int key_len) 1001 + { 1002 + return kmb_ocs_sk_set_key(tfm, in_key, key_len, OCS_AES); 1003 + } 1004 + 1005 + static int kmb_ocs_aes_aead_set_key(struct crypto_aead *tfm, const u8 *in_key, 1006 + unsigned int key_len) 1007 + { 1008 + return kmb_ocs_aead_set_key(tfm, in_key, key_len, OCS_AES); 1009 + } 1010 + 1011 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 1012 + static int kmb_ocs_aes_ecb_encrypt(struct skcipher_request *req) 1013 + { 1014 + return kmb_ocs_sk_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_ECB); 1015 + } 1016 + 1017 + static int kmb_ocs_aes_ecb_decrypt(struct skcipher_request *req) 1018 + { 1019 + return kmb_ocs_sk_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_ECB); 1020 + } 1021 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */ 1022 + 1023 + static int kmb_ocs_aes_cbc_encrypt(struct skcipher_request *req) 1024 + { 1025 + return kmb_ocs_sk_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_CBC); 1026 + } 1027 + 1028 + static int kmb_ocs_aes_cbc_decrypt(struct skcipher_request *req) 1029 + { 1030 + return kmb_ocs_sk_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_CBC); 1031 + } 1032 + 1033 + static int kmb_ocs_aes_ctr_encrypt(struct skcipher_request *req) 1034 + { 1035 + return kmb_ocs_sk_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_CTR); 1036 + } 1037 + 1038 + static int kmb_ocs_aes_ctr_decrypt(struct skcipher_request *req) 1039 + { 1040 + return kmb_ocs_sk_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_CTR); 1041 + } 1042 + 1043 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 1044 + static int kmb_ocs_aes_cts_encrypt(struct skcipher_request *req) 1045 + { 1046 + return kmb_ocs_sk_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_CTS); 1047 + } 1048 + 1049 + static int kmb_ocs_aes_cts_decrypt(struct skcipher_request *req) 1050 + { 1051 + return kmb_ocs_sk_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_CTS); 1052 + } 1053 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */ 1054 + 1055 + static int kmb_ocs_aes_gcm_encrypt(struct aead_request *req) 1056 + { 1057 + return kmb_ocs_aead_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_GCM); 1058 + } 1059 + 1060 + static int kmb_ocs_aes_gcm_decrypt(struct aead_request *req) 1061 + { 1062 + return kmb_ocs_aead_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_GCM); 1063 + } 1064 + 1065 + static int kmb_ocs_aes_ccm_encrypt(struct aead_request *req) 1066 + { 1067 + return kmb_ocs_aead_common(req, OCS_AES, OCS_ENCRYPT, OCS_MODE_CCM); 1068 + } 1069 + 1070 + static int kmb_ocs_aes_ccm_decrypt(struct aead_request *req) 1071 + { 1072 + return kmb_ocs_aead_common(req, OCS_AES, OCS_DECRYPT, OCS_MODE_CCM); 1073 + } 1074 + 1075 + static int kmb_ocs_sm4_set_key(struct crypto_skcipher *tfm, const u8 *in_key, 1076 + unsigned int key_len) 1077 + { 1078 + return kmb_ocs_sk_set_key(tfm, in_key, key_len, OCS_SM4); 1079 + } 1080 + 1081 + static int kmb_ocs_sm4_aead_set_key(struct crypto_aead *tfm, const u8 *in_key, 1082 + unsigned int key_len) 1083 + { 1084 + return kmb_ocs_aead_set_key(tfm, in_key, key_len, OCS_SM4); 1085 + } 1086 + 1087 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 1088 + static int kmb_ocs_sm4_ecb_encrypt(struct skcipher_request *req) 1089 + { 1090 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_ECB); 1091 + } 1092 + 1093 + static int kmb_ocs_sm4_ecb_decrypt(struct skcipher_request *req) 1094 + { 1095 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_ECB); 1096 + } 1097 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */ 1098 + 1099 + static int kmb_ocs_sm4_cbc_encrypt(struct skcipher_request *req) 1100 + { 1101 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_CBC); 1102 + } 1103 + 1104 + static int kmb_ocs_sm4_cbc_decrypt(struct skcipher_request *req) 1105 + { 1106 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_CBC); 1107 + } 1108 + 1109 + static int kmb_ocs_sm4_ctr_encrypt(struct skcipher_request *req) 1110 + { 1111 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_CTR); 1112 + } 1113 + 1114 + static int kmb_ocs_sm4_ctr_decrypt(struct skcipher_request *req) 1115 + { 1116 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_CTR); 1117 + } 1118 + 1119 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 1120 + static int kmb_ocs_sm4_cts_encrypt(struct skcipher_request *req) 1121 + { 1122 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_CTS); 1123 + } 1124 + 1125 + static int kmb_ocs_sm4_cts_decrypt(struct skcipher_request *req) 1126 + { 1127 + return kmb_ocs_sk_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_CTS); 1128 + } 1129 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */ 1130 + 1131 + static int kmb_ocs_sm4_gcm_encrypt(struct aead_request *req) 1132 + { 1133 + return kmb_ocs_aead_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_GCM); 1134 + } 1135 + 1136 + static int kmb_ocs_sm4_gcm_decrypt(struct aead_request *req) 1137 + { 1138 + return kmb_ocs_aead_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_GCM); 1139 + } 1140 + 1141 + static int kmb_ocs_sm4_ccm_encrypt(struct aead_request *req) 1142 + { 1143 + return kmb_ocs_aead_common(req, OCS_SM4, OCS_ENCRYPT, OCS_MODE_CCM); 1144 + } 1145 + 1146 + static int kmb_ocs_sm4_ccm_decrypt(struct aead_request *req) 1147 + { 1148 + return kmb_ocs_aead_common(req, OCS_SM4, OCS_DECRYPT, OCS_MODE_CCM); 1149 + } 1150 + 1151 + static inline int ocs_common_init(struct ocs_aes_tctx *tctx) 1152 + { 1153 + tctx->engine_ctx.op.prepare_request = NULL; 1154 + tctx->engine_ctx.op.do_one_request = kmb_ocs_aes_sk_do_one_request; 1155 + tctx->engine_ctx.op.unprepare_request = NULL; 1156 + 1157 + return 0; 1158 + } 1159 + 1160 + static int ocs_aes_init_tfm(struct crypto_skcipher *tfm) 1161 + { 1162 + const char *alg_name = crypto_tfm_alg_name(&tfm->base); 1163 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 1164 + struct crypto_sync_skcipher *blk; 1165 + 1166 + /* set fallback cipher in case it will be needed */ 1167 + blk = crypto_alloc_sync_skcipher(alg_name, 0, CRYPTO_ALG_NEED_FALLBACK); 1168 + if (IS_ERR(blk)) 1169 + return PTR_ERR(blk); 1170 + 1171 + tctx->sw_cipher.sk = blk; 1172 + 1173 + crypto_skcipher_set_reqsize(tfm, sizeof(struct ocs_aes_rctx)); 1174 + 1175 + return ocs_common_init(tctx); 1176 + } 1177 + 1178 + static int ocs_sm4_init_tfm(struct crypto_skcipher *tfm) 1179 + { 1180 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 1181 + 1182 + crypto_skcipher_set_reqsize(tfm, sizeof(struct ocs_aes_rctx)); 1183 + 1184 + return ocs_common_init(tctx); 1185 + } 1186 + 1187 + static inline void clear_key(struct ocs_aes_tctx *tctx) 1188 + { 1189 + memzero_explicit(tctx->key, OCS_AES_KEYSIZE_256); 1190 + 1191 + /* Zero key registers if set */ 1192 + if (tctx->aes_dev) 1193 + ocs_aes_set_key(tctx->aes_dev, OCS_AES_KEYSIZE_256, 1194 + tctx->key, OCS_AES); 1195 + } 1196 + 1197 + static void ocs_exit_tfm(struct crypto_skcipher *tfm) 1198 + { 1199 + struct ocs_aes_tctx *tctx = crypto_skcipher_ctx(tfm); 1200 + 1201 + clear_key(tctx); 1202 + 1203 + if (tctx->sw_cipher.sk) { 1204 + crypto_free_sync_skcipher(tctx->sw_cipher.sk); 1205 + tctx->sw_cipher.sk = NULL; 1206 + } 1207 + } 1208 + 1209 + static inline int ocs_common_aead_init(struct ocs_aes_tctx *tctx) 1210 + { 1211 + tctx->engine_ctx.op.prepare_request = NULL; 1212 + tctx->engine_ctx.op.do_one_request = kmb_ocs_aes_aead_do_one_request; 1213 + tctx->engine_ctx.op.unprepare_request = NULL; 1214 + 1215 + return 0; 1216 + } 1217 + 1218 + static int ocs_aes_aead_cra_init(struct crypto_aead *tfm) 1219 + { 1220 + const char *alg_name = crypto_tfm_alg_name(&tfm->base); 1221 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(tfm); 1222 + struct crypto_aead *blk; 1223 + 1224 + /* Set fallback cipher in case it will be needed */ 1225 + blk = crypto_alloc_aead(alg_name, 0, CRYPTO_ALG_NEED_FALLBACK); 1226 + if (IS_ERR(blk)) 1227 + return PTR_ERR(blk); 1228 + 1229 + tctx->sw_cipher.aead = blk; 1230 + 1231 + crypto_aead_set_reqsize(tfm, 1232 + max(sizeof(struct ocs_aes_rctx), 1233 + (sizeof(struct aead_request) + 1234 + crypto_aead_reqsize(tctx->sw_cipher.aead)))); 1235 + 1236 + return ocs_common_aead_init(tctx); 1237 + } 1238 + 1239 + static int kmb_ocs_aead_ccm_setauthsize(struct crypto_aead *tfm, 1240 + unsigned int authsize) 1241 + { 1242 + switch (authsize) { 1243 + case 4: 1244 + case 6: 1245 + case 8: 1246 + case 10: 1247 + case 12: 1248 + case 14: 1249 + case 16: 1250 + return 0; 1251 + default: 1252 + return -EINVAL; 1253 + } 1254 + } 1255 + 1256 + static int kmb_ocs_aead_gcm_setauthsize(struct crypto_aead *tfm, 1257 + unsigned int authsize) 1258 + { 1259 + return crypto_gcm_check_authsize(authsize); 1260 + } 1261 + 1262 + static int ocs_sm4_aead_cra_init(struct crypto_aead *tfm) 1263 + { 1264 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(tfm); 1265 + 1266 + crypto_aead_set_reqsize(tfm, sizeof(struct ocs_aes_rctx)); 1267 + 1268 + return ocs_common_aead_init(tctx); 1269 + } 1270 + 1271 + static void ocs_aead_cra_exit(struct crypto_aead *tfm) 1272 + { 1273 + struct ocs_aes_tctx *tctx = crypto_aead_ctx(tfm); 1274 + 1275 + clear_key(tctx); 1276 + 1277 + if (tctx->sw_cipher.aead) { 1278 + crypto_free_aead(tctx->sw_cipher.aead); 1279 + tctx->sw_cipher.aead = NULL; 1280 + } 1281 + } 1282 + 1283 + static struct skcipher_alg algs[] = { 1284 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 1285 + { 1286 + .base.cra_name = "ecb(aes)", 1287 + .base.cra_driver_name = "ecb-aes-keembay-ocs", 1288 + .base.cra_priority = KMB_OCS_PRIORITY, 1289 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1290 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1291 + CRYPTO_ALG_NEED_FALLBACK, 1292 + .base.cra_blocksize = AES_BLOCK_SIZE, 1293 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1294 + .base.cra_module = THIS_MODULE, 1295 + .base.cra_alignmask = 0, 1296 + 1297 + .min_keysize = OCS_AES_MIN_KEY_SIZE, 1298 + .max_keysize = OCS_AES_MAX_KEY_SIZE, 1299 + .setkey = kmb_ocs_aes_set_key, 1300 + .encrypt = kmb_ocs_aes_ecb_encrypt, 1301 + .decrypt = kmb_ocs_aes_ecb_decrypt, 1302 + .init = ocs_aes_init_tfm, 1303 + .exit = ocs_exit_tfm, 1304 + }, 1305 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */ 1306 + { 1307 + .base.cra_name = "cbc(aes)", 1308 + .base.cra_driver_name = "cbc-aes-keembay-ocs", 1309 + .base.cra_priority = KMB_OCS_PRIORITY, 1310 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1311 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1312 + CRYPTO_ALG_NEED_FALLBACK, 1313 + .base.cra_blocksize = AES_BLOCK_SIZE, 1314 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1315 + .base.cra_module = THIS_MODULE, 1316 + .base.cra_alignmask = 0, 1317 + 1318 + .min_keysize = OCS_AES_MIN_KEY_SIZE, 1319 + .max_keysize = OCS_AES_MAX_KEY_SIZE, 1320 + .ivsize = AES_BLOCK_SIZE, 1321 + .setkey = kmb_ocs_aes_set_key, 1322 + .encrypt = kmb_ocs_aes_cbc_encrypt, 1323 + .decrypt = kmb_ocs_aes_cbc_decrypt, 1324 + .init = ocs_aes_init_tfm, 1325 + .exit = ocs_exit_tfm, 1326 + }, 1327 + { 1328 + .base.cra_name = "ctr(aes)", 1329 + .base.cra_driver_name = "ctr-aes-keembay-ocs", 1330 + .base.cra_priority = KMB_OCS_PRIORITY, 1331 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1332 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1333 + CRYPTO_ALG_NEED_FALLBACK, 1334 + .base.cra_blocksize = 1, 1335 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1336 + .base.cra_module = THIS_MODULE, 1337 + .base.cra_alignmask = 0, 1338 + 1339 + .min_keysize = OCS_AES_MIN_KEY_SIZE, 1340 + .max_keysize = OCS_AES_MAX_KEY_SIZE, 1341 + .ivsize = AES_BLOCK_SIZE, 1342 + .setkey = kmb_ocs_aes_set_key, 1343 + .encrypt = kmb_ocs_aes_ctr_encrypt, 1344 + .decrypt = kmb_ocs_aes_ctr_decrypt, 1345 + .init = ocs_aes_init_tfm, 1346 + .exit = ocs_exit_tfm, 1347 + }, 1348 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 1349 + { 1350 + .base.cra_name = "cts(cbc(aes))", 1351 + .base.cra_driver_name = "cts-aes-keembay-ocs", 1352 + .base.cra_priority = KMB_OCS_PRIORITY, 1353 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1354 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1355 + CRYPTO_ALG_NEED_FALLBACK, 1356 + .base.cra_blocksize = AES_BLOCK_SIZE, 1357 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1358 + .base.cra_module = THIS_MODULE, 1359 + .base.cra_alignmask = 0, 1360 + 1361 + .min_keysize = OCS_AES_MIN_KEY_SIZE, 1362 + .max_keysize = OCS_AES_MAX_KEY_SIZE, 1363 + .ivsize = AES_BLOCK_SIZE, 1364 + .setkey = kmb_ocs_aes_set_key, 1365 + .encrypt = kmb_ocs_aes_cts_encrypt, 1366 + .decrypt = kmb_ocs_aes_cts_decrypt, 1367 + .init = ocs_aes_init_tfm, 1368 + .exit = ocs_exit_tfm, 1369 + }, 1370 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */ 1371 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 1372 + { 1373 + .base.cra_name = "ecb(sm4)", 1374 + .base.cra_driver_name = "ecb-sm4-keembay-ocs", 1375 + .base.cra_priority = KMB_OCS_PRIORITY, 1376 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1377 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1378 + .base.cra_blocksize = AES_BLOCK_SIZE, 1379 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1380 + .base.cra_module = THIS_MODULE, 1381 + .base.cra_alignmask = 0, 1382 + 1383 + .min_keysize = OCS_SM4_KEY_SIZE, 1384 + .max_keysize = OCS_SM4_KEY_SIZE, 1385 + .setkey = kmb_ocs_sm4_set_key, 1386 + .encrypt = kmb_ocs_sm4_ecb_encrypt, 1387 + .decrypt = kmb_ocs_sm4_ecb_decrypt, 1388 + .init = ocs_sm4_init_tfm, 1389 + .exit = ocs_exit_tfm, 1390 + }, 1391 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */ 1392 + { 1393 + .base.cra_name = "cbc(sm4)", 1394 + .base.cra_driver_name = "cbc-sm4-keembay-ocs", 1395 + .base.cra_priority = KMB_OCS_PRIORITY, 1396 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1397 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1398 + .base.cra_blocksize = AES_BLOCK_SIZE, 1399 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1400 + .base.cra_module = THIS_MODULE, 1401 + .base.cra_alignmask = 0, 1402 + 1403 + .min_keysize = OCS_SM4_KEY_SIZE, 1404 + .max_keysize = OCS_SM4_KEY_SIZE, 1405 + .ivsize = AES_BLOCK_SIZE, 1406 + .setkey = kmb_ocs_sm4_set_key, 1407 + .encrypt = kmb_ocs_sm4_cbc_encrypt, 1408 + .decrypt = kmb_ocs_sm4_cbc_decrypt, 1409 + .init = ocs_sm4_init_tfm, 1410 + .exit = ocs_exit_tfm, 1411 + }, 1412 + { 1413 + .base.cra_name = "ctr(sm4)", 1414 + .base.cra_driver_name = "ctr-sm4-keembay-ocs", 1415 + .base.cra_priority = KMB_OCS_PRIORITY, 1416 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1417 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1418 + .base.cra_blocksize = 1, 1419 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1420 + .base.cra_module = THIS_MODULE, 1421 + .base.cra_alignmask = 0, 1422 + 1423 + .min_keysize = OCS_SM4_KEY_SIZE, 1424 + .max_keysize = OCS_SM4_KEY_SIZE, 1425 + .ivsize = AES_BLOCK_SIZE, 1426 + .setkey = kmb_ocs_sm4_set_key, 1427 + .encrypt = kmb_ocs_sm4_ctr_encrypt, 1428 + .decrypt = kmb_ocs_sm4_ctr_decrypt, 1429 + .init = ocs_sm4_init_tfm, 1430 + .exit = ocs_exit_tfm, 1431 + }, 1432 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 1433 + { 1434 + .base.cra_name = "cts(cbc(sm4))", 1435 + .base.cra_driver_name = "cts-sm4-keembay-ocs", 1436 + .base.cra_priority = KMB_OCS_PRIORITY, 1437 + .base.cra_flags = CRYPTO_ALG_ASYNC | 1438 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1439 + .base.cra_blocksize = AES_BLOCK_SIZE, 1440 + .base.cra_ctxsize = sizeof(struct ocs_aes_tctx), 1441 + .base.cra_module = THIS_MODULE, 1442 + .base.cra_alignmask = 0, 1443 + 1444 + .min_keysize = OCS_SM4_KEY_SIZE, 1445 + .max_keysize = OCS_SM4_KEY_SIZE, 1446 + .ivsize = AES_BLOCK_SIZE, 1447 + .setkey = kmb_ocs_sm4_set_key, 1448 + .encrypt = kmb_ocs_sm4_cts_encrypt, 1449 + .decrypt = kmb_ocs_sm4_cts_decrypt, 1450 + .init = ocs_sm4_init_tfm, 1451 + .exit = ocs_exit_tfm, 1452 + } 1453 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */ 1454 + }; 1455 + 1456 + static struct aead_alg algs_aead[] = { 1457 + { 1458 + .base = { 1459 + .cra_name = "gcm(aes)", 1460 + .cra_driver_name = "gcm-aes-keembay-ocs", 1461 + .cra_priority = KMB_OCS_PRIORITY, 1462 + .cra_flags = CRYPTO_ALG_ASYNC | 1463 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1464 + CRYPTO_ALG_NEED_FALLBACK, 1465 + .cra_blocksize = 1, 1466 + .cra_ctxsize = sizeof(struct ocs_aes_tctx), 1467 + .cra_alignmask = 0, 1468 + .cra_module = THIS_MODULE, 1469 + }, 1470 + .init = ocs_aes_aead_cra_init, 1471 + .exit = ocs_aead_cra_exit, 1472 + .ivsize = GCM_AES_IV_SIZE, 1473 + .maxauthsize = AES_BLOCK_SIZE, 1474 + .setauthsize = kmb_ocs_aead_gcm_setauthsize, 1475 + .setkey = kmb_ocs_aes_aead_set_key, 1476 + .encrypt = kmb_ocs_aes_gcm_encrypt, 1477 + .decrypt = kmb_ocs_aes_gcm_decrypt, 1478 + }, 1479 + { 1480 + .base = { 1481 + .cra_name = "ccm(aes)", 1482 + .cra_driver_name = "ccm-aes-keembay-ocs", 1483 + .cra_priority = KMB_OCS_PRIORITY, 1484 + .cra_flags = CRYPTO_ALG_ASYNC | 1485 + CRYPTO_ALG_KERN_DRIVER_ONLY | 1486 + CRYPTO_ALG_NEED_FALLBACK, 1487 + .cra_blocksize = 1, 1488 + .cra_ctxsize = sizeof(struct ocs_aes_tctx), 1489 + .cra_alignmask = 0, 1490 + .cra_module = THIS_MODULE, 1491 + }, 1492 + .init = ocs_aes_aead_cra_init, 1493 + .exit = ocs_aead_cra_exit, 1494 + .ivsize = AES_BLOCK_SIZE, 1495 + .maxauthsize = AES_BLOCK_SIZE, 1496 + .setauthsize = kmb_ocs_aead_ccm_setauthsize, 1497 + .setkey = kmb_ocs_aes_aead_set_key, 1498 + .encrypt = kmb_ocs_aes_ccm_encrypt, 1499 + .decrypt = kmb_ocs_aes_ccm_decrypt, 1500 + }, 1501 + { 1502 + .base = { 1503 + .cra_name = "gcm(sm4)", 1504 + .cra_driver_name = "gcm-sm4-keembay-ocs", 1505 + .cra_priority = KMB_OCS_PRIORITY, 1506 + .cra_flags = CRYPTO_ALG_ASYNC | 1507 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1508 + .cra_blocksize = 1, 1509 + .cra_ctxsize = sizeof(struct ocs_aes_tctx), 1510 + .cra_alignmask = 0, 1511 + .cra_module = THIS_MODULE, 1512 + }, 1513 + .init = ocs_sm4_aead_cra_init, 1514 + .exit = ocs_aead_cra_exit, 1515 + .ivsize = GCM_AES_IV_SIZE, 1516 + .maxauthsize = AES_BLOCK_SIZE, 1517 + .setauthsize = kmb_ocs_aead_gcm_setauthsize, 1518 + .setkey = kmb_ocs_sm4_aead_set_key, 1519 + .encrypt = kmb_ocs_sm4_gcm_encrypt, 1520 + .decrypt = kmb_ocs_sm4_gcm_decrypt, 1521 + }, 1522 + { 1523 + .base = { 1524 + .cra_name = "ccm(sm4)", 1525 + .cra_driver_name = "ccm-sm4-keembay-ocs", 1526 + .cra_priority = KMB_OCS_PRIORITY, 1527 + .cra_flags = CRYPTO_ALG_ASYNC | 1528 + CRYPTO_ALG_KERN_DRIVER_ONLY, 1529 + .cra_blocksize = 1, 1530 + .cra_ctxsize = sizeof(struct ocs_aes_tctx), 1531 + .cra_alignmask = 0, 1532 + .cra_module = THIS_MODULE, 1533 + }, 1534 + .init = ocs_sm4_aead_cra_init, 1535 + .exit = ocs_aead_cra_exit, 1536 + .ivsize = AES_BLOCK_SIZE, 1537 + .maxauthsize = AES_BLOCK_SIZE, 1538 + .setauthsize = kmb_ocs_aead_ccm_setauthsize, 1539 + .setkey = kmb_ocs_sm4_aead_set_key, 1540 + .encrypt = kmb_ocs_sm4_ccm_encrypt, 1541 + .decrypt = kmb_ocs_sm4_ccm_decrypt, 1542 + } 1543 + }; 1544 + 1545 + static void unregister_aes_algs(struct ocs_aes_dev *aes_dev) 1546 + { 1547 + crypto_unregister_aeads(algs_aead, ARRAY_SIZE(algs_aead)); 1548 + crypto_unregister_skciphers(algs, ARRAY_SIZE(algs)); 1549 + } 1550 + 1551 + static int register_aes_algs(struct ocs_aes_dev *aes_dev) 1552 + { 1553 + int ret; 1554 + 1555 + /* 1556 + * If any algorithm fails to register, all preceding algorithms that 1557 + * were successfully registered will be automatically unregistered. 1558 + */ 1559 + ret = crypto_register_aeads(algs_aead, ARRAY_SIZE(algs_aead)); 1560 + if (ret) 1561 + return ret; 1562 + 1563 + ret = crypto_register_skciphers(algs, ARRAY_SIZE(algs)); 1564 + if (ret) 1565 + crypto_unregister_aeads(algs_aead, ARRAY_SIZE(algs)); 1566 + 1567 + return ret; 1568 + } 1569 + 1570 + /* Device tree driver match. */ 1571 + static const struct of_device_id kmb_ocs_aes_of_match[] = { 1572 + { 1573 + .compatible = "intel,keembay-ocs-aes", 1574 + }, 1575 + {} 1576 + }; 1577 + 1578 + static int kmb_ocs_aes_remove(struct platform_device *pdev) 1579 + { 1580 + struct ocs_aes_dev *aes_dev; 1581 + 1582 + aes_dev = platform_get_drvdata(pdev); 1583 + if (!aes_dev) 1584 + return -ENODEV; 1585 + 1586 + unregister_aes_algs(aes_dev); 1587 + 1588 + spin_lock(&ocs_aes.lock); 1589 + list_del(&aes_dev->list); 1590 + spin_unlock(&ocs_aes.lock); 1591 + 1592 + crypto_engine_exit(aes_dev->engine); 1593 + 1594 + return 0; 1595 + } 1596 + 1597 + static int kmb_ocs_aes_probe(struct platform_device *pdev) 1598 + { 1599 + struct device *dev = &pdev->dev; 1600 + struct ocs_aes_dev *aes_dev; 1601 + struct resource *aes_mem; 1602 + int rc; 1603 + 1604 + aes_dev = devm_kzalloc(dev, sizeof(*aes_dev), GFP_KERNEL); 1605 + if (!aes_dev) 1606 + return -ENOMEM; 1607 + 1608 + aes_dev->dev = dev; 1609 + 1610 + platform_set_drvdata(pdev, aes_dev); 1611 + 1612 + rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 1613 + if (rc) { 1614 + dev_err(dev, "Failed to set 32 bit dma mask %d\n", rc); 1615 + return rc; 1616 + } 1617 + 1618 + /* Get base register address. */ 1619 + aes_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1620 + if (!aes_mem) { 1621 + dev_err(dev, "Could not retrieve io mem resource\n"); 1622 + return -ENODEV; 1623 + } 1624 + 1625 + aes_dev->base_reg = devm_ioremap_resource(&pdev->dev, aes_mem); 1626 + if (IS_ERR(aes_dev->base_reg)) { 1627 + dev_err(dev, "Failed to get base address\n"); 1628 + return PTR_ERR(aes_dev->base_reg); 1629 + } 1630 + 1631 + /* Get and request IRQ */ 1632 + aes_dev->irq = platform_get_irq(pdev, 0); 1633 + if (aes_dev->irq < 0) 1634 + return aes_dev->irq; 1635 + 1636 + rc = devm_request_threaded_irq(dev, aes_dev->irq, ocs_aes_irq_handler, 1637 + NULL, 0, "keembay-ocs-aes", aes_dev); 1638 + if (rc < 0) { 1639 + dev_err(dev, "Could not request IRQ\n"); 1640 + return rc; 1641 + } 1642 + 1643 + INIT_LIST_HEAD(&aes_dev->list); 1644 + spin_lock(&ocs_aes.lock); 1645 + list_add_tail(&aes_dev->list, &ocs_aes.dev_list); 1646 + spin_unlock(&ocs_aes.lock); 1647 + 1648 + init_completion(&aes_dev->irq_completion); 1649 + 1650 + /* Initialize crypto engine */ 1651 + aes_dev->engine = crypto_engine_alloc_init(dev, true); 1652 + if (!aes_dev->engine) 1653 + goto list_del; 1654 + 1655 + rc = crypto_engine_start(aes_dev->engine); 1656 + if (rc) { 1657 + dev_err(dev, "Could not start crypto engine\n"); 1658 + goto cleanup; 1659 + } 1660 + 1661 + rc = register_aes_algs(aes_dev); 1662 + if (rc) { 1663 + dev_err(dev, 1664 + "Could not register OCS algorithms with Crypto API\n"); 1665 + goto cleanup; 1666 + } 1667 + 1668 + return 0; 1669 + 1670 + cleanup: 1671 + crypto_engine_exit(aes_dev->engine); 1672 + list_del: 1673 + spin_lock(&ocs_aes.lock); 1674 + list_del(&aes_dev->list); 1675 + spin_unlock(&ocs_aes.lock); 1676 + 1677 + return rc; 1678 + } 1679 + 1680 + /* The OCS driver is a platform device. */ 1681 + static struct platform_driver kmb_ocs_aes_driver = { 1682 + .probe = kmb_ocs_aes_probe, 1683 + .remove = kmb_ocs_aes_remove, 1684 + .driver = { 1685 + .name = DRV_NAME, 1686 + .of_match_table = kmb_ocs_aes_of_match, 1687 + }, 1688 + }; 1689 + 1690 + module_platform_driver(kmb_ocs_aes_driver); 1691 + 1692 + MODULE_DESCRIPTION("Intel Keem Bay Offload and Crypto Subsystem (OCS) AES/SM4 Driver"); 1693 + MODULE_LICENSE("GPL"); 1694 + 1695 + MODULE_ALIAS_CRYPTO("cbc-aes-keembay-ocs"); 1696 + MODULE_ALIAS_CRYPTO("ctr-aes-keembay-ocs"); 1697 + MODULE_ALIAS_CRYPTO("gcm-aes-keembay-ocs"); 1698 + MODULE_ALIAS_CRYPTO("ccm-aes-keembay-ocs"); 1699 + 1700 + MODULE_ALIAS_CRYPTO("cbc-sm4-keembay-ocs"); 1701 + MODULE_ALIAS_CRYPTO("ctr-sm4-keembay-ocs"); 1702 + MODULE_ALIAS_CRYPTO("gcm-sm4-keembay-ocs"); 1703 + MODULE_ALIAS_CRYPTO("ccm-sm4-keembay-ocs"); 1704 + 1705 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB 1706 + MODULE_ALIAS_CRYPTO("ecb-aes-keembay-ocs"); 1707 + MODULE_ALIAS_CRYPTO("ecb-sm4-keembay-ocs"); 1708 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */ 1709 + 1710 + #ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS 1711 + MODULE_ALIAS_CRYPTO("cts-aes-keembay-ocs"); 1712 + MODULE_ALIAS_CRYPTO("cts-sm4-keembay-ocs"); 1713 + #endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */
+1489
drivers/crypto/keembay/ocs-aes.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Keem Bay OCS AES Crypto Driver. 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation 6 + */ 7 + 8 + #include <linux/dma-mapping.h> 9 + #include <linux/interrupt.h> 10 + #include <linux/platform_device.h> 11 + #include <linux/slab.h> 12 + #include <linux/swab.h> 13 + 14 + #include <asm/byteorder.h> 15 + #include <asm/errno.h> 16 + 17 + #include <crypto/aes.h> 18 + #include <crypto/gcm.h> 19 + 20 + #include "ocs-aes.h" 21 + 22 + #define AES_COMMAND_OFFSET 0x0000 23 + #define AES_KEY_0_OFFSET 0x0004 24 + #define AES_KEY_1_OFFSET 0x0008 25 + #define AES_KEY_2_OFFSET 0x000C 26 + #define AES_KEY_3_OFFSET 0x0010 27 + #define AES_KEY_4_OFFSET 0x0014 28 + #define AES_KEY_5_OFFSET 0x0018 29 + #define AES_KEY_6_OFFSET 0x001C 30 + #define AES_KEY_7_OFFSET 0x0020 31 + #define AES_IV_0_OFFSET 0x0024 32 + #define AES_IV_1_OFFSET 0x0028 33 + #define AES_IV_2_OFFSET 0x002C 34 + #define AES_IV_3_OFFSET 0x0030 35 + #define AES_ACTIVE_OFFSET 0x0034 36 + #define AES_STATUS_OFFSET 0x0038 37 + #define AES_KEY_SIZE_OFFSET 0x0044 38 + #define AES_IER_OFFSET 0x0048 39 + #define AES_ISR_OFFSET 0x005C 40 + #define AES_MULTIPURPOSE1_0_OFFSET 0x0200 41 + #define AES_MULTIPURPOSE1_1_OFFSET 0x0204 42 + #define AES_MULTIPURPOSE1_2_OFFSET 0x0208 43 + #define AES_MULTIPURPOSE1_3_OFFSET 0x020C 44 + #define AES_MULTIPURPOSE2_0_OFFSET 0x0220 45 + #define AES_MULTIPURPOSE2_1_OFFSET 0x0224 46 + #define AES_MULTIPURPOSE2_2_OFFSET 0x0228 47 + #define AES_MULTIPURPOSE2_3_OFFSET 0x022C 48 + #define AES_BYTE_ORDER_CFG_OFFSET 0x02C0 49 + #define AES_TLEN_OFFSET 0x0300 50 + #define AES_T_MAC_0_OFFSET 0x0304 51 + #define AES_T_MAC_1_OFFSET 0x0308 52 + #define AES_T_MAC_2_OFFSET 0x030C 53 + #define AES_T_MAC_3_OFFSET 0x0310 54 + #define AES_PLEN_OFFSET 0x0314 55 + #define AES_A_DMA_SRC_ADDR_OFFSET 0x0400 56 + #define AES_A_DMA_DST_ADDR_OFFSET 0x0404 57 + #define AES_A_DMA_SRC_SIZE_OFFSET 0x0408 58 + #define AES_A_DMA_DST_SIZE_OFFSET 0x040C 59 + #define AES_A_DMA_DMA_MODE_OFFSET 0x0410 60 + #define AES_A_DMA_NEXT_SRC_DESCR_OFFSET 0x0418 61 + #define AES_A_DMA_NEXT_DST_DESCR_OFFSET 0x041C 62 + #define AES_A_DMA_WHILE_ACTIVE_MODE_OFFSET 0x0420 63 + #define AES_A_DMA_LOG_OFFSET 0x0424 64 + #define AES_A_DMA_STATUS_OFFSET 0x0428 65 + #define AES_A_DMA_PERF_CNTR_OFFSET 0x042C 66 + #define AES_A_DMA_MSI_ISR_OFFSET 0x0480 67 + #define AES_A_DMA_MSI_IER_OFFSET 0x0484 68 + #define AES_A_DMA_MSI_MASK_OFFSET 0x0488 69 + #define AES_A_DMA_INBUFFER_WRITE_FIFO_OFFSET 0x0600 70 + #define AES_A_DMA_OUTBUFFER_READ_FIFO_OFFSET 0x0700 71 + 72 + /* 73 + * AES_A_DMA_DMA_MODE register. 74 + * Default: 0x00000000. 75 + * bit[31] ACTIVE 76 + * This bit activates the DMA. When the DMA finishes, it resets 77 + * this bit to zero. 78 + * bit[30:26] Unused by this driver. 79 + * bit[25] SRC_LINK_LIST_EN 80 + * Source link list enable bit. When the linked list is terminated 81 + * this bit is reset by the DMA. 82 + * bit[24] DST_LINK_LIST_EN 83 + * Destination link list enable bit. When the linked list is 84 + * terminated this bit is reset by the DMA. 85 + * bit[23:0] Unused by this driver. 86 + */ 87 + #define AES_A_DMA_DMA_MODE_ACTIVE BIT(31) 88 + #define AES_A_DMA_DMA_MODE_SRC_LINK_LIST_EN BIT(25) 89 + #define AES_A_DMA_DMA_MODE_DST_LINK_LIST_EN BIT(24) 90 + 91 + /* 92 + * AES_ACTIVE register 93 + * default 0x00000000 94 + * bit[31:10] Reserved 95 + * bit[9] LAST_ADATA 96 + * bit[8] LAST_GCX 97 + * bit[7:2] Reserved 98 + * bit[1] TERMINATION 99 + * bit[0] TRIGGER 100 + */ 101 + #define AES_ACTIVE_LAST_ADATA BIT(9) 102 + #define AES_ACTIVE_LAST_CCM_GCM BIT(8) 103 + #define AES_ACTIVE_TERMINATION BIT(1) 104 + #define AES_ACTIVE_TRIGGER BIT(0) 105 + 106 + #define AES_DISABLE_INT 0x00000000 107 + #define AES_DMA_CPD_ERR_INT BIT(8) 108 + #define AES_DMA_OUTBUF_RD_ERR_INT BIT(7) 109 + #define AES_DMA_OUTBUF_WR_ERR_INT BIT(6) 110 + #define AES_DMA_INBUF_RD_ERR_INT BIT(5) 111 + #define AES_DMA_INBUF_WR_ERR_INT BIT(4) 112 + #define AES_DMA_BAD_COMP_INT BIT(3) 113 + #define AES_DMA_SAI_INT BIT(2) 114 + #define AES_DMA_SRC_DONE_INT BIT(0) 115 + #define AES_COMPLETE_INT BIT(1) 116 + 117 + #define AES_DMA_MSI_MASK_CLEAR BIT(0) 118 + 119 + #define AES_128_BIT_KEY 0x00000000 120 + #define AES_256_BIT_KEY BIT(0) 121 + 122 + #define AES_DEACTIVATE_PERF_CNTR 0x00000000 123 + #define AES_ACTIVATE_PERF_CNTR BIT(0) 124 + 125 + #define AES_MAX_TAG_SIZE_U32 4 126 + 127 + #define OCS_LL_DMA_FLAG_TERMINATE BIT(31) 128 + 129 + /* 130 + * There is an inconsistency in the documentation. This is documented as a 131 + * 11-bit value, but it is actually 10-bits. 132 + */ 133 + #define AES_DMA_STATUS_INPUT_BUFFER_OCCUPANCY_MASK 0x3FF 134 + 135 + /* 136 + * During CCM decrypt, the OCS block needs to finish processing the ciphertext 137 + * before the tag is written. For 128-bit mode this required delay is 28 OCS 138 + * clock cycles. For 256-bit mode it is 36 OCS clock cycles. 139 + */ 140 + #define CCM_DECRYPT_DELAY_TAG_CLK_COUNT 36UL 141 + 142 + /* 143 + * During CCM decrypt there must be a delay of at least 42 OCS clock cycles 144 + * between setting the TRIGGER bit in AES_ACTIVE and setting the LAST_CCM_GCM 145 + * bit in the same register (as stated in the OCS databook) 146 + */ 147 + #define CCM_DECRYPT_DELAY_LAST_GCX_CLK_COUNT 42UL 148 + 149 + /* See RFC3610 section 2.2 */ 150 + #define L_PRIME_MIN (1) 151 + #define L_PRIME_MAX (7) 152 + /* 153 + * CCM IV format from RFC 3610 section 2.3 154 + * 155 + * Octet Number Contents 156 + * ------------ --------- 157 + * 0 Flags 158 + * 1 ... 15-L Nonce N 159 + * 16-L ... 15 Counter i 160 + * 161 + * Flags = L' = L - 1 162 + */ 163 + #define L_PRIME_IDX 0 164 + #define COUNTER_START(lprime) (16 - ((lprime) + 1)) 165 + #define COUNTER_LEN(lprime) ((lprime) + 1) 166 + 167 + enum aes_counter_mode { 168 + AES_CTR_M_NO_INC = 0, 169 + AES_CTR_M_32_INC = 1, 170 + AES_CTR_M_64_INC = 2, 171 + AES_CTR_M_128_INC = 3, 172 + }; 173 + 174 + /** 175 + * struct ocs_dma_linked_list - OCS DMA linked list entry. 176 + * @src_addr: Source address of the data. 177 + * @src_len: Length of data to be fetched. 178 + * @next: Next dma_list to fetch. 179 + * @ll_flags: Flags (Freeze @ terminate) for the DMA engine. 180 + */ 181 + struct ocs_dma_linked_list { 182 + u32 src_addr; 183 + u32 src_len; 184 + u32 next; 185 + u32 ll_flags; 186 + } __packed; 187 + 188 + /* 189 + * Set endianness of inputs and outputs 190 + * AES_BYTE_ORDER_CFG 191 + * default 0x00000000 192 + * bit [10] - KEY_HI_LO_SWAP 193 + * bit [9] - KEY_HI_SWAP_DWORDS_IN_OCTWORD 194 + * bit [8] - KEY_HI_SWAP_BYTES_IN_DWORD 195 + * bit [7] - KEY_LO_SWAP_DWORDS_IN_OCTWORD 196 + * bit [6] - KEY_LO_SWAP_BYTES_IN_DWORD 197 + * bit [5] - IV_SWAP_DWORDS_IN_OCTWORD 198 + * bit [4] - IV_SWAP_BYTES_IN_DWORD 199 + * bit [3] - DOUT_SWAP_DWORDS_IN_OCTWORD 200 + * bit [2] - DOUT_SWAP_BYTES_IN_DWORD 201 + * bit [1] - DOUT_SWAP_DWORDS_IN_OCTWORD 202 + * bit [0] - DOUT_SWAP_BYTES_IN_DWORD 203 + */ 204 + static inline void aes_a_set_endianness(const struct ocs_aes_dev *aes_dev) 205 + { 206 + iowrite32(0x7FF, aes_dev->base_reg + AES_BYTE_ORDER_CFG_OFFSET); 207 + } 208 + 209 + /* Trigger AES process start. */ 210 + static inline void aes_a_op_trigger(const struct ocs_aes_dev *aes_dev) 211 + { 212 + iowrite32(AES_ACTIVE_TRIGGER, aes_dev->base_reg + AES_ACTIVE_OFFSET); 213 + } 214 + 215 + /* Indicate last bulk of data. */ 216 + static inline void aes_a_op_termination(const struct ocs_aes_dev *aes_dev) 217 + { 218 + iowrite32(AES_ACTIVE_TERMINATION, 219 + aes_dev->base_reg + AES_ACTIVE_OFFSET); 220 + } 221 + 222 + /* 223 + * Set LAST_CCM_GCM in AES_ACTIVE register and clear all other bits. 224 + * 225 + * Called when DMA is programmed to fetch the last batch of data. 226 + * - For AES-CCM it is called for the last batch of Payload data and Ciphertext 227 + * data. 228 + * - For AES-GCM, it is called for the last batch of Plaintext data and 229 + * Ciphertext data. 230 + */ 231 + static inline void aes_a_set_last_gcx(const struct ocs_aes_dev *aes_dev) 232 + { 233 + iowrite32(AES_ACTIVE_LAST_CCM_GCM, 234 + aes_dev->base_reg + AES_ACTIVE_OFFSET); 235 + } 236 + 237 + /* Wait for LAST_CCM_GCM bit to be unset. */ 238 + static inline void aes_a_wait_last_gcx(const struct ocs_aes_dev *aes_dev) 239 + { 240 + u32 aes_active_reg; 241 + 242 + do { 243 + aes_active_reg = ioread32(aes_dev->base_reg + 244 + AES_ACTIVE_OFFSET); 245 + } while (aes_active_reg & AES_ACTIVE_LAST_CCM_GCM); 246 + } 247 + 248 + /* Wait for 10 bits of input occupancy. */ 249 + static void aes_a_dma_wait_input_buffer_occupancy(const struct ocs_aes_dev *aes_dev) 250 + { 251 + u32 reg; 252 + 253 + do { 254 + reg = ioread32(aes_dev->base_reg + AES_A_DMA_STATUS_OFFSET); 255 + } while (reg & AES_DMA_STATUS_INPUT_BUFFER_OCCUPANCY_MASK); 256 + } 257 + 258 + /* 259 + * Set LAST_CCM_GCM and LAST_ADATA bits in AES_ACTIVE register (and clear all 260 + * other bits). 261 + * 262 + * Called when DMA is programmed to fetch the last batch of Associated Data 263 + * (CCM case) or Additional Authenticated Data (GCM case). 264 + */ 265 + static inline void aes_a_set_last_gcx_and_adata(const struct ocs_aes_dev *aes_dev) 266 + { 267 + iowrite32(AES_ACTIVE_LAST_ADATA | AES_ACTIVE_LAST_CCM_GCM, 268 + aes_dev->base_reg + AES_ACTIVE_OFFSET); 269 + } 270 + 271 + /* Set DMA src and dst transfer size to 0 */ 272 + static inline void aes_a_dma_set_xfer_size_zero(const struct ocs_aes_dev *aes_dev) 273 + { 274 + iowrite32(0, aes_dev->base_reg + AES_A_DMA_SRC_SIZE_OFFSET); 275 + iowrite32(0, aes_dev->base_reg + AES_A_DMA_DST_SIZE_OFFSET); 276 + } 277 + 278 + /* Activate DMA for zero-byte transfer case. */ 279 + static inline void aes_a_dma_active(const struct ocs_aes_dev *aes_dev) 280 + { 281 + iowrite32(AES_A_DMA_DMA_MODE_ACTIVE, 282 + aes_dev->base_reg + AES_A_DMA_DMA_MODE_OFFSET); 283 + } 284 + 285 + /* Activate DMA and enable src linked list */ 286 + static inline void aes_a_dma_active_src_ll_en(const struct ocs_aes_dev *aes_dev) 287 + { 288 + iowrite32(AES_A_DMA_DMA_MODE_ACTIVE | 289 + AES_A_DMA_DMA_MODE_SRC_LINK_LIST_EN, 290 + aes_dev->base_reg + AES_A_DMA_DMA_MODE_OFFSET); 291 + } 292 + 293 + /* Activate DMA and enable dst linked list */ 294 + static inline void aes_a_dma_active_dst_ll_en(const struct ocs_aes_dev *aes_dev) 295 + { 296 + iowrite32(AES_A_DMA_DMA_MODE_ACTIVE | 297 + AES_A_DMA_DMA_MODE_DST_LINK_LIST_EN, 298 + aes_dev->base_reg + AES_A_DMA_DMA_MODE_OFFSET); 299 + } 300 + 301 + /* Activate DMA and enable src and dst linked lists */ 302 + static inline void aes_a_dma_active_src_dst_ll_en(const struct ocs_aes_dev *aes_dev) 303 + { 304 + iowrite32(AES_A_DMA_DMA_MODE_ACTIVE | 305 + AES_A_DMA_DMA_MODE_SRC_LINK_LIST_EN | 306 + AES_A_DMA_DMA_MODE_DST_LINK_LIST_EN, 307 + aes_dev->base_reg + AES_A_DMA_DMA_MODE_OFFSET); 308 + } 309 + 310 + /* Reset PERF_CNTR to 0 and activate it */ 311 + static inline void aes_a_dma_reset_and_activate_perf_cntr(const struct ocs_aes_dev *aes_dev) 312 + { 313 + iowrite32(0x00000000, aes_dev->base_reg + AES_A_DMA_PERF_CNTR_OFFSET); 314 + iowrite32(AES_ACTIVATE_PERF_CNTR, 315 + aes_dev->base_reg + AES_A_DMA_WHILE_ACTIVE_MODE_OFFSET); 316 + } 317 + 318 + /* Wait until PERF_CNTR is > delay, then deactivate it */ 319 + static inline void aes_a_dma_wait_and_deactivate_perf_cntr(const struct ocs_aes_dev *aes_dev, 320 + int delay) 321 + { 322 + while (ioread32(aes_dev->base_reg + AES_A_DMA_PERF_CNTR_OFFSET) < delay) 323 + ; 324 + iowrite32(AES_DEACTIVATE_PERF_CNTR, 325 + aes_dev->base_reg + AES_A_DMA_WHILE_ACTIVE_MODE_OFFSET); 326 + } 327 + 328 + /* Disable AES and DMA IRQ. */ 329 + static void aes_irq_disable(struct ocs_aes_dev *aes_dev) 330 + { 331 + u32 isr_val = 0; 332 + 333 + /* Disable interrupts */ 334 + iowrite32(AES_DISABLE_INT, 335 + aes_dev->base_reg + AES_A_DMA_MSI_IER_OFFSET); 336 + iowrite32(AES_DISABLE_INT, aes_dev->base_reg + AES_IER_OFFSET); 337 + 338 + /* Clear any pending interrupt */ 339 + isr_val = ioread32(aes_dev->base_reg + AES_A_DMA_MSI_ISR_OFFSET); 340 + if (isr_val) 341 + iowrite32(isr_val, 342 + aes_dev->base_reg + AES_A_DMA_MSI_ISR_OFFSET); 343 + 344 + isr_val = ioread32(aes_dev->base_reg + AES_A_DMA_MSI_MASK_OFFSET); 345 + if (isr_val) 346 + iowrite32(isr_val, 347 + aes_dev->base_reg + AES_A_DMA_MSI_MASK_OFFSET); 348 + 349 + isr_val = ioread32(aes_dev->base_reg + AES_ISR_OFFSET); 350 + if (isr_val) 351 + iowrite32(isr_val, aes_dev->base_reg + AES_ISR_OFFSET); 352 + } 353 + 354 + /* Enable AES or DMA IRQ. IRQ is disabled once fired. */ 355 + static void aes_irq_enable(struct ocs_aes_dev *aes_dev, u8 irq) 356 + { 357 + if (irq == AES_COMPLETE_INT) { 358 + /* Ensure DMA error interrupts are enabled */ 359 + iowrite32(AES_DMA_CPD_ERR_INT | 360 + AES_DMA_OUTBUF_RD_ERR_INT | 361 + AES_DMA_OUTBUF_WR_ERR_INT | 362 + AES_DMA_INBUF_RD_ERR_INT | 363 + AES_DMA_INBUF_WR_ERR_INT | 364 + AES_DMA_BAD_COMP_INT | 365 + AES_DMA_SAI_INT, 366 + aes_dev->base_reg + AES_A_DMA_MSI_IER_OFFSET); 367 + /* 368 + * AES_IER 369 + * default 0x00000000 370 + * bits [31:3] - reserved 371 + * bit [2] - EN_SKS_ERR 372 + * bit [1] - EN_AES_COMPLETE 373 + * bit [0] - reserved 374 + */ 375 + iowrite32(AES_COMPLETE_INT, aes_dev->base_reg + AES_IER_OFFSET); 376 + return; 377 + } 378 + if (irq == AES_DMA_SRC_DONE_INT) { 379 + /* Ensure AES interrupts are disabled */ 380 + iowrite32(AES_DISABLE_INT, aes_dev->base_reg + AES_IER_OFFSET); 381 + /* 382 + * DMA_MSI_IER 383 + * default 0x00000000 384 + * bits [31:9] - reserved 385 + * bit [8] - CPD_ERR_INT_EN 386 + * bit [7] - OUTBUF_RD_ERR_INT_EN 387 + * bit [6] - OUTBUF_WR_ERR_INT_EN 388 + * bit [5] - INBUF_RD_ERR_INT_EN 389 + * bit [4] - INBUF_WR_ERR_INT_EN 390 + * bit [3] - BAD_COMP_INT_EN 391 + * bit [2] - SAI_INT_EN 392 + * bit [1] - DST_DONE_INT_EN 393 + * bit [0] - SRC_DONE_INT_EN 394 + */ 395 + iowrite32(AES_DMA_CPD_ERR_INT | 396 + AES_DMA_OUTBUF_RD_ERR_INT | 397 + AES_DMA_OUTBUF_WR_ERR_INT | 398 + AES_DMA_INBUF_RD_ERR_INT | 399 + AES_DMA_INBUF_WR_ERR_INT | 400 + AES_DMA_BAD_COMP_INT | 401 + AES_DMA_SAI_INT | 402 + AES_DMA_SRC_DONE_INT, 403 + aes_dev->base_reg + AES_A_DMA_MSI_IER_OFFSET); 404 + } 405 + } 406 + 407 + /* Enable and wait for IRQ (either from OCS AES engine or DMA) */ 408 + static int ocs_aes_irq_enable_and_wait(struct ocs_aes_dev *aes_dev, u8 irq) 409 + { 410 + int rc; 411 + 412 + reinit_completion(&aes_dev->irq_completion); 413 + aes_irq_enable(aes_dev, irq); 414 + rc = wait_for_completion_interruptible(&aes_dev->irq_completion); 415 + if (rc) 416 + return rc; 417 + 418 + return aes_dev->dma_err_mask ? -EIO : 0; 419 + } 420 + 421 + /* Configure DMA to OCS, linked list mode */ 422 + static inline void dma_to_ocs_aes_ll(struct ocs_aes_dev *aes_dev, 423 + dma_addr_t dma_list) 424 + { 425 + iowrite32(0, aes_dev->base_reg + AES_A_DMA_SRC_SIZE_OFFSET); 426 + iowrite32(dma_list, 427 + aes_dev->base_reg + AES_A_DMA_NEXT_SRC_DESCR_OFFSET); 428 + } 429 + 430 + /* Configure DMA from OCS, linked list mode */ 431 + static inline void dma_from_ocs_aes_ll(struct ocs_aes_dev *aes_dev, 432 + dma_addr_t dma_list) 433 + { 434 + iowrite32(0, aes_dev->base_reg + AES_A_DMA_DST_SIZE_OFFSET); 435 + iowrite32(dma_list, 436 + aes_dev->base_reg + AES_A_DMA_NEXT_DST_DESCR_OFFSET); 437 + } 438 + 439 + irqreturn_t ocs_aes_irq_handler(int irq, void *dev_id) 440 + { 441 + struct ocs_aes_dev *aes_dev = dev_id; 442 + u32 aes_dma_isr; 443 + 444 + /* Read DMA ISR status. */ 445 + aes_dma_isr = ioread32(aes_dev->base_reg + AES_A_DMA_MSI_ISR_OFFSET); 446 + 447 + /* Disable and clear interrupts. */ 448 + aes_irq_disable(aes_dev); 449 + 450 + /* Save DMA error status. */ 451 + aes_dev->dma_err_mask = aes_dma_isr & 452 + (AES_DMA_CPD_ERR_INT | 453 + AES_DMA_OUTBUF_RD_ERR_INT | 454 + AES_DMA_OUTBUF_WR_ERR_INT | 455 + AES_DMA_INBUF_RD_ERR_INT | 456 + AES_DMA_INBUF_WR_ERR_INT | 457 + AES_DMA_BAD_COMP_INT | 458 + AES_DMA_SAI_INT); 459 + 460 + /* Signal IRQ completion. */ 461 + complete(&aes_dev->irq_completion); 462 + 463 + return IRQ_HANDLED; 464 + } 465 + 466 + /** 467 + * ocs_aes_set_key() - Write key into OCS AES hardware. 468 + * @aes_dev: The OCS AES device to write the key to. 469 + * @key_size: The size of the key (in bytes). 470 + * @key: The key to write. 471 + * @cipher: The cipher the key is for. 472 + * 473 + * For AES @key_size must be either 16 or 32. For SM4 @key_size must be 16. 474 + * 475 + * Return: 0 on success, negative error code otherwise. 476 + */ 477 + int ocs_aes_set_key(struct ocs_aes_dev *aes_dev, u32 key_size, const u8 *key, 478 + enum ocs_cipher cipher) 479 + { 480 + const u32 *key_u32; 481 + u32 val; 482 + int i; 483 + 484 + /* OCS AES supports 128-bit and 256-bit keys only. */ 485 + if (cipher == OCS_AES && !(key_size == 32 || key_size == 16)) { 486 + dev_err(aes_dev->dev, 487 + "%d-bit keys not supported by AES cipher\n", 488 + key_size * 8); 489 + return -EINVAL; 490 + } 491 + /* OCS SM4 supports 128-bit keys only. */ 492 + if (cipher == OCS_SM4 && key_size != 16) { 493 + dev_err(aes_dev->dev, 494 + "%d-bit keys not supported for SM4 cipher\n", 495 + key_size * 8); 496 + return -EINVAL; 497 + } 498 + 499 + if (!key) 500 + return -EINVAL; 501 + 502 + key_u32 = (const u32 *)key; 503 + 504 + /* Write key to AES_KEY[0-7] registers */ 505 + for (i = 0; i < (key_size / sizeof(u32)); i++) { 506 + iowrite32(key_u32[i], 507 + aes_dev->base_reg + AES_KEY_0_OFFSET + 508 + (i * sizeof(u32))); 509 + } 510 + /* 511 + * Write key size 512 + * bits [31:1] - reserved 513 + * bit [0] - AES_KEY_SIZE 514 + * 0 - 128 bit key 515 + * 1 - 256 bit key 516 + */ 517 + val = (key_size == 16) ? AES_128_BIT_KEY : AES_256_BIT_KEY; 518 + iowrite32(val, aes_dev->base_reg + AES_KEY_SIZE_OFFSET); 519 + 520 + return 0; 521 + } 522 + 523 + /* Write AES_COMMAND */ 524 + static inline void set_ocs_aes_command(struct ocs_aes_dev *aes_dev, 525 + enum ocs_cipher cipher, 526 + enum ocs_mode mode, 527 + enum ocs_instruction instruction) 528 + { 529 + u32 val; 530 + 531 + /* AES_COMMAND 532 + * default 0x000000CC 533 + * bit [14] - CIPHER_SELECT 534 + * 0 - AES 535 + * 1 - SM4 536 + * bits [11:8] - OCS_AES_MODE 537 + * 0000 - ECB 538 + * 0001 - CBC 539 + * 0010 - CTR 540 + * 0110 - CCM 541 + * 0111 - GCM 542 + * 1001 - CTS 543 + * bits [7:6] - AES_INSTRUCTION 544 + * 00 - ENCRYPT 545 + * 01 - DECRYPT 546 + * 10 - EXPAND 547 + * 11 - BYPASS 548 + * bits [3:2] - CTR_M_BITS 549 + * 00 - No increment 550 + * 01 - Least significant 32 bits are incremented 551 + * 10 - Least significant 64 bits are incremented 552 + * 11 - Full 128 bits are incremented 553 + */ 554 + val = (cipher << 14) | (mode << 8) | (instruction << 6) | 555 + (AES_CTR_M_128_INC << 2); 556 + iowrite32(val, aes_dev->base_reg + AES_COMMAND_OFFSET); 557 + } 558 + 559 + static void ocs_aes_init(struct ocs_aes_dev *aes_dev, 560 + enum ocs_mode mode, 561 + enum ocs_cipher cipher, 562 + enum ocs_instruction instruction) 563 + { 564 + /* Ensure interrupts are disabled and pending interrupts cleared. */ 565 + aes_irq_disable(aes_dev); 566 + 567 + /* Set endianness recommended by data-sheet. */ 568 + aes_a_set_endianness(aes_dev); 569 + 570 + /* Set AES_COMMAND register. */ 571 + set_ocs_aes_command(aes_dev, cipher, mode, instruction); 572 + } 573 + 574 + /* 575 + * Write the byte length of the last AES/SM4 block of Payload data (without 576 + * zero padding and without the length of the MAC) in register AES_PLEN. 577 + */ 578 + static inline void ocs_aes_write_last_data_blk_len(struct ocs_aes_dev *aes_dev, 579 + u32 size) 580 + { 581 + u32 val; 582 + 583 + if (size == 0) { 584 + val = 0; 585 + goto exit; 586 + } 587 + 588 + val = size % AES_BLOCK_SIZE; 589 + if (val == 0) 590 + val = AES_BLOCK_SIZE; 591 + 592 + exit: 593 + iowrite32(val, aes_dev->base_reg + AES_PLEN_OFFSET); 594 + } 595 + 596 + /* 597 + * Validate inputs according to mode. 598 + * If OK return 0; else return -EINVAL. 599 + */ 600 + static int ocs_aes_validate_inputs(dma_addr_t src_dma_list, u32 src_size, 601 + const u8 *iv, u32 iv_size, 602 + dma_addr_t aad_dma_list, u32 aad_size, 603 + const u8 *tag, u32 tag_size, 604 + enum ocs_cipher cipher, enum ocs_mode mode, 605 + enum ocs_instruction instruction, 606 + dma_addr_t dst_dma_list) 607 + { 608 + /* Ensure cipher, mode and instruction are valid. */ 609 + if (!(cipher == OCS_AES || cipher == OCS_SM4)) 610 + return -EINVAL; 611 + 612 + if (mode != OCS_MODE_ECB && mode != OCS_MODE_CBC && 613 + mode != OCS_MODE_CTR && mode != OCS_MODE_CCM && 614 + mode != OCS_MODE_GCM && mode != OCS_MODE_CTS) 615 + return -EINVAL; 616 + 617 + if (instruction != OCS_ENCRYPT && instruction != OCS_DECRYPT && 618 + instruction != OCS_EXPAND && instruction != OCS_BYPASS) 619 + return -EINVAL; 620 + 621 + /* 622 + * When instruction is OCS_BYPASS, OCS simply copies data from source 623 + * to destination using DMA. 624 + * 625 + * AES mode is irrelevant, but both source and destination DMA 626 + * linked-list must be defined. 627 + */ 628 + if (instruction == OCS_BYPASS) { 629 + if (src_dma_list == DMA_MAPPING_ERROR || 630 + dst_dma_list == DMA_MAPPING_ERROR) 631 + return -EINVAL; 632 + 633 + return 0; 634 + } 635 + 636 + /* 637 + * For performance reasons switch based on mode to limit unnecessary 638 + * conditionals for each mode 639 + */ 640 + switch (mode) { 641 + case OCS_MODE_ECB: 642 + /* Ensure input length is multiple of block size */ 643 + if (src_size % AES_BLOCK_SIZE != 0) 644 + return -EINVAL; 645 + 646 + /* Ensure source and destination linked lists are created */ 647 + if (src_dma_list == DMA_MAPPING_ERROR || 648 + dst_dma_list == DMA_MAPPING_ERROR) 649 + return -EINVAL; 650 + 651 + return 0; 652 + 653 + case OCS_MODE_CBC: 654 + /* Ensure input length is multiple of block size */ 655 + if (src_size % AES_BLOCK_SIZE != 0) 656 + return -EINVAL; 657 + 658 + /* Ensure source and destination linked lists are created */ 659 + if (src_dma_list == DMA_MAPPING_ERROR || 660 + dst_dma_list == DMA_MAPPING_ERROR) 661 + return -EINVAL; 662 + 663 + /* Ensure IV is present and block size in length */ 664 + if (!iv || iv_size != AES_BLOCK_SIZE) 665 + return -EINVAL; 666 + 667 + return 0; 668 + 669 + case OCS_MODE_CTR: 670 + /* Ensure input length of 1 byte or greater */ 671 + if (src_size == 0) 672 + return -EINVAL; 673 + 674 + /* Ensure source and destination linked lists are created */ 675 + if (src_dma_list == DMA_MAPPING_ERROR || 676 + dst_dma_list == DMA_MAPPING_ERROR) 677 + return -EINVAL; 678 + 679 + /* Ensure IV is present and block size in length */ 680 + if (!iv || iv_size != AES_BLOCK_SIZE) 681 + return -EINVAL; 682 + 683 + return 0; 684 + 685 + case OCS_MODE_CTS: 686 + /* Ensure input length >= block size */ 687 + if (src_size < AES_BLOCK_SIZE) 688 + return -EINVAL; 689 + 690 + /* Ensure source and destination linked lists are created */ 691 + if (src_dma_list == DMA_MAPPING_ERROR || 692 + dst_dma_list == DMA_MAPPING_ERROR) 693 + return -EINVAL; 694 + 695 + /* Ensure IV is present and block size in length */ 696 + if (!iv || iv_size != AES_BLOCK_SIZE) 697 + return -EINVAL; 698 + 699 + return 0; 700 + 701 + case OCS_MODE_GCM: 702 + /* Ensure IV is present and GCM_AES_IV_SIZE in length */ 703 + if (!iv || iv_size != GCM_AES_IV_SIZE) 704 + return -EINVAL; 705 + 706 + /* 707 + * If input data present ensure source and destination linked 708 + * lists are created 709 + */ 710 + if (src_size && (src_dma_list == DMA_MAPPING_ERROR || 711 + dst_dma_list == DMA_MAPPING_ERROR)) 712 + return -EINVAL; 713 + 714 + /* If aad present ensure aad linked list is created */ 715 + if (aad_size && aad_dma_list == DMA_MAPPING_ERROR) 716 + return -EINVAL; 717 + 718 + /* Ensure tag destination is set */ 719 + if (!tag) 720 + return -EINVAL; 721 + 722 + /* Just ensure that tag_size doesn't cause overflows. */ 723 + if (tag_size > (AES_MAX_TAG_SIZE_U32 * sizeof(u32))) 724 + return -EINVAL; 725 + 726 + return 0; 727 + 728 + case OCS_MODE_CCM: 729 + /* Ensure IV is present and block size in length */ 730 + if (!iv || iv_size != AES_BLOCK_SIZE) 731 + return -EINVAL; 732 + 733 + /* 2 <= L <= 8, so 1 <= L' <= 7 */ 734 + if (iv[L_PRIME_IDX] < L_PRIME_MIN || 735 + iv[L_PRIME_IDX] > L_PRIME_MAX) 736 + return -EINVAL; 737 + 738 + /* If aad present ensure aad linked list is created */ 739 + if (aad_size && aad_dma_list == DMA_MAPPING_ERROR) 740 + return -EINVAL; 741 + 742 + /* Just ensure that tag_size doesn't cause overflows. */ 743 + if (tag_size > (AES_MAX_TAG_SIZE_U32 * sizeof(u32))) 744 + return -EINVAL; 745 + 746 + if (instruction == OCS_DECRYPT) { 747 + /* 748 + * If input data present ensure source and destination 749 + * linked lists are created 750 + */ 751 + if (src_size && (src_dma_list == DMA_MAPPING_ERROR || 752 + dst_dma_list == DMA_MAPPING_ERROR)) 753 + return -EINVAL; 754 + 755 + /* Ensure input tag is present */ 756 + if (!tag) 757 + return -EINVAL; 758 + 759 + return 0; 760 + } 761 + 762 + /* Instruction == OCS_ENCRYPT */ 763 + 764 + /* 765 + * Destination linked list always required (for tag even if no 766 + * input data) 767 + */ 768 + if (dst_dma_list == DMA_MAPPING_ERROR) 769 + return -EINVAL; 770 + 771 + /* If input data present ensure src linked list is created */ 772 + if (src_size && src_dma_list == DMA_MAPPING_ERROR) 773 + return -EINVAL; 774 + 775 + return 0; 776 + 777 + default: 778 + return -EINVAL; 779 + } 780 + } 781 + 782 + /** 783 + * ocs_aes_op() - Perform AES/SM4 operation. 784 + * @aes_dev: The OCS AES device to use. 785 + * @mode: The mode to use (ECB, CBC, CTR, or CTS). 786 + * @cipher: The cipher to use (AES or SM4). 787 + * @instruction: The instruction to perform (encrypt or decrypt). 788 + * @dst_dma_list: The OCS DMA list mapping output memory. 789 + * @src_dma_list: The OCS DMA list mapping input payload data. 790 + * @src_size: The amount of data mapped by @src_dma_list. 791 + * @iv: The IV vector. 792 + * @iv_size: The size (in bytes) of @iv. 793 + * 794 + * Return: 0 on success, negative error code otherwise. 795 + */ 796 + int ocs_aes_op(struct ocs_aes_dev *aes_dev, 797 + enum ocs_mode mode, 798 + enum ocs_cipher cipher, 799 + enum ocs_instruction instruction, 800 + dma_addr_t dst_dma_list, 801 + dma_addr_t src_dma_list, 802 + u32 src_size, 803 + u8 *iv, 804 + u32 iv_size) 805 + { 806 + u32 *iv32; 807 + int rc; 808 + 809 + rc = ocs_aes_validate_inputs(src_dma_list, src_size, iv, iv_size, 0, 0, 810 + NULL, 0, cipher, mode, instruction, 811 + dst_dma_list); 812 + if (rc) 813 + return rc; 814 + /* 815 + * ocs_aes_validate_inputs() is a generic check, now ensure mode is not 816 + * GCM or CCM. 817 + */ 818 + if (mode == OCS_MODE_GCM || mode == OCS_MODE_CCM) 819 + return -EINVAL; 820 + 821 + /* Cast IV to u32 array. */ 822 + iv32 = (u32 *)iv; 823 + 824 + ocs_aes_init(aes_dev, mode, cipher, instruction); 825 + 826 + if (mode == OCS_MODE_CTS) { 827 + /* Write the byte length of the last data block to engine. */ 828 + ocs_aes_write_last_data_blk_len(aes_dev, src_size); 829 + } 830 + 831 + /* ECB is the only mode that doesn't use IV. */ 832 + if (mode != OCS_MODE_ECB) { 833 + iowrite32(iv32[0], aes_dev->base_reg + AES_IV_0_OFFSET); 834 + iowrite32(iv32[1], aes_dev->base_reg + AES_IV_1_OFFSET); 835 + iowrite32(iv32[2], aes_dev->base_reg + AES_IV_2_OFFSET); 836 + iowrite32(iv32[3], aes_dev->base_reg + AES_IV_3_OFFSET); 837 + } 838 + 839 + /* Set AES_ACTIVE.TRIGGER to start the operation. */ 840 + aes_a_op_trigger(aes_dev); 841 + 842 + /* Configure and activate input / output DMA. */ 843 + dma_to_ocs_aes_ll(aes_dev, src_dma_list); 844 + dma_from_ocs_aes_ll(aes_dev, dst_dma_list); 845 + aes_a_dma_active_src_dst_ll_en(aes_dev); 846 + 847 + if (mode == OCS_MODE_CTS) { 848 + /* 849 + * For CTS mode, instruct engine to activate ciphertext 850 + * stealing if last block of data is incomplete. 851 + */ 852 + aes_a_set_last_gcx(aes_dev); 853 + } else { 854 + /* For all other modes, just write the 'termination' bit. */ 855 + aes_a_op_termination(aes_dev); 856 + } 857 + 858 + /* Wait for engine to complete processing. */ 859 + rc = ocs_aes_irq_enable_and_wait(aes_dev, AES_COMPLETE_INT); 860 + if (rc) 861 + return rc; 862 + 863 + if (mode == OCS_MODE_CTR) { 864 + /* Read back IV for streaming mode */ 865 + iv32[0] = ioread32(aes_dev->base_reg + AES_IV_0_OFFSET); 866 + iv32[1] = ioread32(aes_dev->base_reg + AES_IV_1_OFFSET); 867 + iv32[2] = ioread32(aes_dev->base_reg + AES_IV_2_OFFSET); 868 + iv32[3] = ioread32(aes_dev->base_reg + AES_IV_3_OFFSET); 869 + } 870 + 871 + return 0; 872 + } 873 + 874 + /* Compute and write J0 to engine registers. */ 875 + static void ocs_aes_gcm_write_j0(const struct ocs_aes_dev *aes_dev, 876 + const u8 *iv) 877 + { 878 + const u32 *j0 = (u32 *)iv; 879 + 880 + /* 881 + * IV must be 12 bytes; Other sizes not supported as Linux crypto API 882 + * does only expects/allows 12 byte IV for GCM 883 + */ 884 + iowrite32(0x00000001, aes_dev->base_reg + AES_IV_0_OFFSET); 885 + iowrite32(__swab32(j0[2]), aes_dev->base_reg + AES_IV_1_OFFSET); 886 + iowrite32(__swab32(j0[1]), aes_dev->base_reg + AES_IV_2_OFFSET); 887 + iowrite32(__swab32(j0[0]), aes_dev->base_reg + AES_IV_3_OFFSET); 888 + } 889 + 890 + /* Read GCM tag from engine registers. */ 891 + static inline void ocs_aes_gcm_read_tag(struct ocs_aes_dev *aes_dev, 892 + u8 *tag, u32 tag_size) 893 + { 894 + u32 tag_u32[AES_MAX_TAG_SIZE_U32]; 895 + 896 + /* 897 + * The Authentication Tag T is stored in Little Endian order in the 898 + * registers with the most significant bytes stored from AES_T_MAC[3] 899 + * downward. 900 + */ 901 + tag_u32[0] = __swab32(ioread32(aes_dev->base_reg + AES_T_MAC_3_OFFSET)); 902 + tag_u32[1] = __swab32(ioread32(aes_dev->base_reg + AES_T_MAC_2_OFFSET)); 903 + tag_u32[2] = __swab32(ioread32(aes_dev->base_reg + AES_T_MAC_1_OFFSET)); 904 + tag_u32[3] = __swab32(ioread32(aes_dev->base_reg + AES_T_MAC_0_OFFSET)); 905 + 906 + memcpy(tag, tag_u32, tag_size); 907 + } 908 + 909 + /** 910 + * ocs_aes_gcm_op() - Perform GCM operation. 911 + * @aes_dev: The OCS AES device to use. 912 + * @cipher: The Cipher to use (AES or SM4). 913 + * @instruction: The instruction to perform (encrypt or decrypt). 914 + * @dst_dma_list: The OCS DMA list mapping output memory. 915 + * @src_dma_list: The OCS DMA list mapping input payload data. 916 + * @src_size: The amount of data mapped by @src_dma_list. 917 + * @iv: The input IV vector. 918 + * @aad_dma_list: The OCS DMA list mapping input AAD data. 919 + * @aad_size: The amount of data mapped by @aad_dma_list. 920 + * @out_tag: Where to store computed tag. 921 + * @tag_size: The size (in bytes) of @out_tag. 922 + * 923 + * Return: 0 on success, negative error code otherwise. 924 + */ 925 + int ocs_aes_gcm_op(struct ocs_aes_dev *aes_dev, 926 + enum ocs_cipher cipher, 927 + enum ocs_instruction instruction, 928 + dma_addr_t dst_dma_list, 929 + dma_addr_t src_dma_list, 930 + u32 src_size, 931 + const u8 *iv, 932 + dma_addr_t aad_dma_list, 933 + u32 aad_size, 934 + u8 *out_tag, 935 + u32 tag_size) 936 + { 937 + u64 bit_len; 938 + u32 val; 939 + int rc; 940 + 941 + rc = ocs_aes_validate_inputs(src_dma_list, src_size, iv, 942 + GCM_AES_IV_SIZE, aad_dma_list, 943 + aad_size, out_tag, tag_size, cipher, 944 + OCS_MODE_GCM, instruction, 945 + dst_dma_list); 946 + if (rc) 947 + return rc; 948 + 949 + ocs_aes_init(aes_dev, OCS_MODE_GCM, cipher, instruction); 950 + 951 + /* Compute and write J0 to OCS HW. */ 952 + ocs_aes_gcm_write_j0(aes_dev, iv); 953 + 954 + /* Write out_tag byte length */ 955 + iowrite32(tag_size, aes_dev->base_reg + AES_TLEN_OFFSET); 956 + 957 + /* Write the byte length of the last plaintext / ciphertext block. */ 958 + ocs_aes_write_last_data_blk_len(aes_dev, src_size); 959 + 960 + /* Write ciphertext bit length */ 961 + bit_len = src_size * 8; 962 + val = bit_len & 0xFFFFFFFF; 963 + iowrite32(val, aes_dev->base_reg + AES_MULTIPURPOSE2_0_OFFSET); 964 + val = bit_len >> 32; 965 + iowrite32(val, aes_dev->base_reg + AES_MULTIPURPOSE2_1_OFFSET); 966 + 967 + /* Write aad bit length */ 968 + bit_len = aad_size * 8; 969 + val = bit_len & 0xFFFFFFFF; 970 + iowrite32(val, aes_dev->base_reg + AES_MULTIPURPOSE2_2_OFFSET); 971 + val = bit_len >> 32; 972 + iowrite32(val, aes_dev->base_reg + AES_MULTIPURPOSE2_3_OFFSET); 973 + 974 + /* Set AES_ACTIVE.TRIGGER to start the operation. */ 975 + aes_a_op_trigger(aes_dev); 976 + 977 + /* Process AAD. */ 978 + if (aad_size) { 979 + /* If aad present, configure DMA to feed it to the engine. */ 980 + dma_to_ocs_aes_ll(aes_dev, aad_dma_list); 981 + aes_a_dma_active_src_ll_en(aes_dev); 982 + 983 + /* Instructs engine to pad last block of aad, if needed. */ 984 + aes_a_set_last_gcx_and_adata(aes_dev); 985 + 986 + /* Wait for DMA transfer to complete. */ 987 + rc = ocs_aes_irq_enable_and_wait(aes_dev, AES_DMA_SRC_DONE_INT); 988 + if (rc) 989 + return rc; 990 + } else { 991 + aes_a_set_last_gcx_and_adata(aes_dev); 992 + } 993 + 994 + /* Wait until adata (if present) has been processed. */ 995 + aes_a_wait_last_gcx(aes_dev); 996 + aes_a_dma_wait_input_buffer_occupancy(aes_dev); 997 + 998 + /* Now process payload. */ 999 + if (src_size) { 1000 + /* Configure and activate DMA for both input and output data. */ 1001 + dma_to_ocs_aes_ll(aes_dev, src_dma_list); 1002 + dma_from_ocs_aes_ll(aes_dev, dst_dma_list); 1003 + aes_a_dma_active_src_dst_ll_en(aes_dev); 1004 + } else { 1005 + aes_a_dma_set_xfer_size_zero(aes_dev); 1006 + aes_a_dma_active(aes_dev); 1007 + } 1008 + 1009 + /* Instruct AES/SMA4 engine payload processing is over. */ 1010 + aes_a_set_last_gcx(aes_dev); 1011 + 1012 + /* Wait for OCS AES engine to complete processing. */ 1013 + rc = ocs_aes_irq_enable_and_wait(aes_dev, AES_COMPLETE_INT); 1014 + if (rc) 1015 + return rc; 1016 + 1017 + ocs_aes_gcm_read_tag(aes_dev, out_tag, tag_size); 1018 + 1019 + return 0; 1020 + } 1021 + 1022 + /* Write encrypted tag to AES/SM4 engine. */ 1023 + static void ocs_aes_ccm_write_encrypted_tag(struct ocs_aes_dev *aes_dev, 1024 + const u8 *in_tag, u32 tag_size) 1025 + { 1026 + int i; 1027 + 1028 + /* Ensure DMA input buffer is empty */ 1029 + aes_a_dma_wait_input_buffer_occupancy(aes_dev); 1030 + 1031 + /* 1032 + * During CCM decrypt, the OCS block needs to finish processing the 1033 + * ciphertext before the tag is written. So delay needed after DMA has 1034 + * completed writing the ciphertext 1035 + */ 1036 + aes_a_dma_reset_and_activate_perf_cntr(aes_dev); 1037 + aes_a_dma_wait_and_deactivate_perf_cntr(aes_dev, 1038 + CCM_DECRYPT_DELAY_TAG_CLK_COUNT); 1039 + 1040 + /* Write encrypted tag to AES/SM4 engine. */ 1041 + for (i = 0; i < tag_size; i++) { 1042 + iowrite8(in_tag[i], aes_dev->base_reg + 1043 + AES_A_DMA_INBUFFER_WRITE_FIFO_OFFSET); 1044 + } 1045 + } 1046 + 1047 + /* 1048 + * Write B0 CCM block to OCS AES HW. 1049 + * 1050 + * Note: B0 format is documented in NIST Special Publication 800-38C 1051 + * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf 1052 + * (see Section A.2.1) 1053 + */ 1054 + static int ocs_aes_ccm_write_b0(const struct ocs_aes_dev *aes_dev, 1055 + const u8 *iv, u32 adata_size, u32 tag_size, 1056 + u32 cryptlen) 1057 + { 1058 + u8 b0[16]; /* CCM B0 block is 16 bytes long. */ 1059 + int i, q; 1060 + 1061 + /* Initialize B0 to 0. */ 1062 + memset(b0, 0, sizeof(b0)); 1063 + 1064 + /* 1065 + * B0[0] is the 'Flags Octet' and has the following structure: 1066 + * bit 7: Reserved 1067 + * bit 6: Adata flag 1068 + * bit 5-3: t value encoded as (t-2)/2 1069 + * bit 2-0: q value encoded as q - 1 1070 + */ 1071 + /* If there is AAD data, set the Adata flag. */ 1072 + if (adata_size) 1073 + b0[0] |= BIT(6); 1074 + /* 1075 + * t denotes the octet length of T. 1076 + * t can only be an element of { 4, 6, 8, 10, 12, 14, 16} and is 1077 + * encoded as (t - 2) / 2 1078 + */ 1079 + b0[0] |= (((tag_size - 2) / 2) & 0x7) << 3; 1080 + /* 1081 + * q is the octet length of Q. 1082 + * q can only be an element of {2, 3, 4, 5, 6, 7, 8} and is encoded as 1083 + * q - 1 == iv[0] 1084 + */ 1085 + b0[0] |= iv[0] & 0x7; 1086 + /* 1087 + * Copy the Nonce N from IV to B0; N is located in iv[1]..iv[15 - q] 1088 + * and must be copied to b0[1]..b0[15-q]. 1089 + * q == iv[0] + 1 1090 + */ 1091 + q = iv[0] + 1; 1092 + for (i = 1; i <= 15 - q; i++) 1093 + b0[i] = iv[i]; 1094 + /* 1095 + * The rest of B0 must contain Q, i.e., the message length. 1096 + * Q is encoded in q octets, in big-endian order, so to write it, we 1097 + * start from the end of B0 and we move backward. 1098 + */ 1099 + i = sizeof(b0) - 1; 1100 + while (q) { 1101 + b0[i] = cryptlen & 0xff; 1102 + cryptlen >>= 8; 1103 + i--; 1104 + q--; 1105 + } 1106 + /* 1107 + * If cryptlen is not zero at this point, it means that its original 1108 + * value was too big. 1109 + */ 1110 + if (cryptlen) 1111 + return -EOVERFLOW; 1112 + /* Now write B0 to OCS AES input buffer. */ 1113 + for (i = 0; i < sizeof(b0); i++) 1114 + iowrite8(b0[i], aes_dev->base_reg + 1115 + AES_A_DMA_INBUFFER_WRITE_FIFO_OFFSET); 1116 + return 0; 1117 + } 1118 + 1119 + /* 1120 + * Write adata length to OCS AES HW. 1121 + * 1122 + * Note: adata len encoding is documented in NIST Special Publication 800-38C 1123 + * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf 1124 + * (see Section A.2.2) 1125 + */ 1126 + static void ocs_aes_ccm_write_adata_len(const struct ocs_aes_dev *aes_dev, 1127 + u64 adata_len) 1128 + { 1129 + u8 enc_a[10]; /* Maximum encoded size: 10 octets. */ 1130 + int i, len; 1131 + 1132 + /* 1133 + * adata_len ('a') is encoded as follows: 1134 + * If 0 < a < 2^16 - 2^8 ==> 'a' encoded as [a]16, i.e., two octets 1135 + * (big endian). 1136 + * If 2^16 - 2^8 ≤ a < 2^32 ==> 'a' encoded as 0xff || 0xfe || [a]32, 1137 + * i.e., six octets (big endian). 1138 + * If 2^32 ≤ a < 2^64 ==> 'a' encoded as 0xff || 0xff || [a]64, 1139 + * i.e., ten octets (big endian). 1140 + */ 1141 + if (adata_len < 65280) { 1142 + len = 2; 1143 + *(__be16 *)enc_a = cpu_to_be16(adata_len); 1144 + } else if (adata_len <= 0xFFFFFFFF) { 1145 + len = 6; 1146 + *(__be16 *)enc_a = cpu_to_be16(0xfffe); 1147 + *(__be32 *)&enc_a[2] = cpu_to_be32(adata_len); 1148 + } else { /* adata_len >= 2^32 */ 1149 + len = 10; 1150 + *(__be16 *)enc_a = cpu_to_be16(0xffff); 1151 + *(__be64 *)&enc_a[2] = cpu_to_be64(adata_len); 1152 + } 1153 + for (i = 0; i < len; i++) 1154 + iowrite8(enc_a[i], 1155 + aes_dev->base_reg + 1156 + AES_A_DMA_INBUFFER_WRITE_FIFO_OFFSET); 1157 + } 1158 + 1159 + static int ocs_aes_ccm_do_adata(struct ocs_aes_dev *aes_dev, 1160 + dma_addr_t adata_dma_list, u32 adata_size) 1161 + { 1162 + int rc; 1163 + 1164 + if (!adata_size) { 1165 + /* Since no aad the LAST_GCX bit can be set now */ 1166 + aes_a_set_last_gcx_and_adata(aes_dev); 1167 + goto exit; 1168 + } 1169 + 1170 + /* Adata case. */ 1171 + 1172 + /* 1173 + * Form the encoding of the Associated data length and write it 1174 + * to the AES/SM4 input buffer. 1175 + */ 1176 + ocs_aes_ccm_write_adata_len(aes_dev, adata_size); 1177 + 1178 + /* Configure the AES/SM4 DMA to fetch the Associated Data */ 1179 + dma_to_ocs_aes_ll(aes_dev, adata_dma_list); 1180 + 1181 + /* Activate DMA to fetch Associated data. */ 1182 + aes_a_dma_active_src_ll_en(aes_dev); 1183 + 1184 + /* Set LAST_GCX and LAST_ADATA in AES ACTIVE register. */ 1185 + aes_a_set_last_gcx_and_adata(aes_dev); 1186 + 1187 + /* Wait for DMA transfer to complete. */ 1188 + rc = ocs_aes_irq_enable_and_wait(aes_dev, AES_DMA_SRC_DONE_INT); 1189 + if (rc) 1190 + return rc; 1191 + 1192 + exit: 1193 + /* Wait until adata (if present) has been processed. */ 1194 + aes_a_wait_last_gcx(aes_dev); 1195 + aes_a_dma_wait_input_buffer_occupancy(aes_dev); 1196 + 1197 + return 0; 1198 + } 1199 + 1200 + static int ocs_aes_ccm_encrypt_do_payload(struct ocs_aes_dev *aes_dev, 1201 + dma_addr_t dst_dma_list, 1202 + dma_addr_t src_dma_list, 1203 + u32 src_size) 1204 + { 1205 + if (src_size) { 1206 + /* 1207 + * Configure and activate DMA for both input and output 1208 + * data. 1209 + */ 1210 + dma_to_ocs_aes_ll(aes_dev, src_dma_list); 1211 + dma_from_ocs_aes_ll(aes_dev, dst_dma_list); 1212 + aes_a_dma_active_src_dst_ll_en(aes_dev); 1213 + } else { 1214 + /* Configure and activate DMA for output data only. */ 1215 + dma_from_ocs_aes_ll(aes_dev, dst_dma_list); 1216 + aes_a_dma_active_dst_ll_en(aes_dev); 1217 + } 1218 + 1219 + /* 1220 + * Set the LAST GCX bit in AES_ACTIVE Register to instruct 1221 + * AES/SM4 engine to pad the last block of data. 1222 + */ 1223 + aes_a_set_last_gcx(aes_dev); 1224 + 1225 + /* We are done, wait for IRQ and return. */ 1226 + return ocs_aes_irq_enable_and_wait(aes_dev, AES_COMPLETE_INT); 1227 + } 1228 + 1229 + static int ocs_aes_ccm_decrypt_do_payload(struct ocs_aes_dev *aes_dev, 1230 + dma_addr_t dst_dma_list, 1231 + dma_addr_t src_dma_list, 1232 + u32 src_size) 1233 + { 1234 + if (!src_size) { 1235 + /* Let engine process 0-length input. */ 1236 + aes_a_dma_set_xfer_size_zero(aes_dev); 1237 + aes_a_dma_active(aes_dev); 1238 + aes_a_set_last_gcx(aes_dev); 1239 + 1240 + return 0; 1241 + } 1242 + 1243 + /* 1244 + * Configure and activate DMA for both input and output 1245 + * data. 1246 + */ 1247 + dma_to_ocs_aes_ll(aes_dev, src_dma_list); 1248 + dma_from_ocs_aes_ll(aes_dev, dst_dma_list); 1249 + aes_a_dma_active_src_dst_ll_en(aes_dev); 1250 + /* 1251 + * Set the LAST GCX bit in AES_ACTIVE Register; this allows the 1252 + * AES/SM4 engine to differentiate between encrypted data and 1253 + * encrypted MAC. 1254 + */ 1255 + aes_a_set_last_gcx(aes_dev); 1256 + /* 1257 + * Enable DMA DONE interrupt; once DMA transfer is over, 1258 + * interrupt handler will process the MAC/tag. 1259 + */ 1260 + return ocs_aes_irq_enable_and_wait(aes_dev, AES_DMA_SRC_DONE_INT); 1261 + } 1262 + 1263 + /* 1264 + * Compare Tag to Yr. 1265 + * 1266 + * Only used at the end of CCM decrypt. If tag == yr, message authentication 1267 + * has succeeded. 1268 + */ 1269 + static inline int ccm_compare_tag_to_yr(struct ocs_aes_dev *aes_dev, 1270 + u8 tag_size_bytes) 1271 + { 1272 + u32 tag[AES_MAX_TAG_SIZE_U32]; 1273 + u32 yr[AES_MAX_TAG_SIZE_U32]; 1274 + u8 i; 1275 + 1276 + /* Read Tag and Yr from AES registers. */ 1277 + for (i = 0; i < AES_MAX_TAG_SIZE_U32; i++) { 1278 + tag[i] = ioread32(aes_dev->base_reg + 1279 + AES_T_MAC_0_OFFSET + (i * sizeof(u32))); 1280 + yr[i] = ioread32(aes_dev->base_reg + 1281 + AES_MULTIPURPOSE2_0_OFFSET + 1282 + (i * sizeof(u32))); 1283 + } 1284 + 1285 + return memcmp(tag, yr, tag_size_bytes) ? -EBADMSG : 0; 1286 + } 1287 + 1288 + /** 1289 + * ocs_aes_ccm_op() - Perform CCM operation. 1290 + * @aes_dev: The OCS AES device to use. 1291 + * @cipher: The Cipher to use (AES or SM4). 1292 + * @instruction: The instruction to perform (encrypt or decrypt). 1293 + * @dst_dma_list: The OCS DMA list mapping output memory. 1294 + * @src_dma_list: The OCS DMA list mapping input payload data. 1295 + * @src_size: The amount of data mapped by @src_dma_list. 1296 + * @iv: The input IV vector. 1297 + * @adata_dma_list: The OCS DMA list mapping input A-data. 1298 + * @adata_size: The amount of data mapped by @adata_dma_list. 1299 + * @in_tag: Input tag. 1300 + * @tag_size: The size (in bytes) of @in_tag. 1301 + * 1302 + * Note: for encrypt the tag is appended to the ciphertext (in the memory 1303 + * mapped by @dst_dma_list). 1304 + * 1305 + * Return: 0 on success, negative error code otherwise. 1306 + */ 1307 + int ocs_aes_ccm_op(struct ocs_aes_dev *aes_dev, 1308 + enum ocs_cipher cipher, 1309 + enum ocs_instruction instruction, 1310 + dma_addr_t dst_dma_list, 1311 + dma_addr_t src_dma_list, 1312 + u32 src_size, 1313 + u8 *iv, 1314 + dma_addr_t adata_dma_list, 1315 + u32 adata_size, 1316 + u8 *in_tag, 1317 + u32 tag_size) 1318 + { 1319 + u32 *iv_32; 1320 + u8 lprime; 1321 + int rc; 1322 + 1323 + rc = ocs_aes_validate_inputs(src_dma_list, src_size, iv, 1324 + AES_BLOCK_SIZE, adata_dma_list, adata_size, 1325 + in_tag, tag_size, cipher, OCS_MODE_CCM, 1326 + instruction, dst_dma_list); 1327 + if (rc) 1328 + return rc; 1329 + 1330 + ocs_aes_init(aes_dev, OCS_MODE_CCM, cipher, instruction); 1331 + 1332 + /* 1333 + * Note: rfc 3610 and NIST 800-38C require counter of zero to encrypt 1334 + * auth tag so ensure this is the case 1335 + */ 1336 + lprime = iv[L_PRIME_IDX]; 1337 + memset(&iv[COUNTER_START(lprime)], 0, COUNTER_LEN(lprime)); 1338 + 1339 + /* 1340 + * Nonce is already converted to ctr0 before being passed into this 1341 + * function as iv. 1342 + */ 1343 + iv_32 = (u32 *)iv; 1344 + iowrite32(__swab32(iv_32[0]), 1345 + aes_dev->base_reg + AES_MULTIPURPOSE1_3_OFFSET); 1346 + iowrite32(__swab32(iv_32[1]), 1347 + aes_dev->base_reg + AES_MULTIPURPOSE1_2_OFFSET); 1348 + iowrite32(__swab32(iv_32[2]), 1349 + aes_dev->base_reg + AES_MULTIPURPOSE1_1_OFFSET); 1350 + iowrite32(__swab32(iv_32[3]), 1351 + aes_dev->base_reg + AES_MULTIPURPOSE1_0_OFFSET); 1352 + 1353 + /* Write MAC/tag length in register AES_TLEN */ 1354 + iowrite32(tag_size, aes_dev->base_reg + AES_TLEN_OFFSET); 1355 + /* 1356 + * Write the byte length of the last AES/SM4 block of Payload data 1357 + * (without zero padding and without the length of the MAC) in register 1358 + * AES_PLEN. 1359 + */ 1360 + ocs_aes_write_last_data_blk_len(aes_dev, src_size); 1361 + 1362 + /* Set AES_ACTIVE.TRIGGER to start the operation. */ 1363 + aes_a_op_trigger(aes_dev); 1364 + 1365 + aes_a_dma_reset_and_activate_perf_cntr(aes_dev); 1366 + 1367 + /* Form block B0 and write it to the AES/SM4 input buffer. */ 1368 + rc = ocs_aes_ccm_write_b0(aes_dev, iv, adata_size, tag_size, src_size); 1369 + if (rc) 1370 + return rc; 1371 + /* 1372 + * Ensure there has been at least CCM_DECRYPT_DELAY_LAST_GCX_CLK_COUNT 1373 + * clock cycles since TRIGGER bit was set 1374 + */ 1375 + aes_a_dma_wait_and_deactivate_perf_cntr(aes_dev, 1376 + CCM_DECRYPT_DELAY_LAST_GCX_CLK_COUNT); 1377 + 1378 + /* Process Adata. */ 1379 + ocs_aes_ccm_do_adata(aes_dev, adata_dma_list, adata_size); 1380 + 1381 + /* For Encrypt case we just process the payload and return. */ 1382 + if (instruction == OCS_ENCRYPT) { 1383 + return ocs_aes_ccm_encrypt_do_payload(aes_dev, dst_dma_list, 1384 + src_dma_list, src_size); 1385 + } 1386 + /* For Decypt we need to process the payload and then the tag. */ 1387 + rc = ocs_aes_ccm_decrypt_do_payload(aes_dev, dst_dma_list, 1388 + src_dma_list, src_size); 1389 + if (rc) 1390 + return rc; 1391 + 1392 + /* Process MAC/tag directly: feed tag to engine and wait for IRQ. */ 1393 + ocs_aes_ccm_write_encrypted_tag(aes_dev, in_tag, tag_size); 1394 + rc = ocs_aes_irq_enable_and_wait(aes_dev, AES_COMPLETE_INT); 1395 + if (rc) 1396 + return rc; 1397 + 1398 + return ccm_compare_tag_to_yr(aes_dev, tag_size); 1399 + } 1400 + 1401 + /** 1402 + * ocs_create_linked_list_from_sg() - Create OCS DMA linked list from SG list. 1403 + * @aes_dev: The OCS AES device the list will be created for. 1404 + * @sg: The SG list OCS DMA linked list will be created from. When 1405 + * passed to this function, @sg must have been already mapped 1406 + * with dma_map_sg(). 1407 + * @sg_dma_count: The number of DMA-mapped entries in @sg. This must be the 1408 + * value returned by dma_map_sg() when @sg was mapped. 1409 + * @dll_desc: The OCS DMA dma_list to use to store information about the 1410 + * created linked list. 1411 + * @data_size: The size of the data (from the SG list) to be mapped into the 1412 + * OCS DMA linked list. 1413 + * @data_offset: The offset (within the SG list) of the data to be mapped. 1414 + * 1415 + * Return: 0 on success, negative error code otherwise. 1416 + */ 1417 + int ocs_create_linked_list_from_sg(const struct ocs_aes_dev *aes_dev, 1418 + struct scatterlist *sg, 1419 + int sg_dma_count, 1420 + struct ocs_dll_desc *dll_desc, 1421 + size_t data_size, size_t data_offset) 1422 + { 1423 + struct ocs_dma_linked_list *ll = NULL; 1424 + struct scatterlist *sg_tmp; 1425 + unsigned int tmp; 1426 + int dma_nents; 1427 + int i; 1428 + 1429 + if (!dll_desc || !sg || !aes_dev) 1430 + return -EINVAL; 1431 + 1432 + /* Default values for when no ddl_desc is created. */ 1433 + dll_desc->vaddr = NULL; 1434 + dll_desc->dma_addr = DMA_MAPPING_ERROR; 1435 + dll_desc->size = 0; 1436 + 1437 + if (data_size == 0) 1438 + return 0; 1439 + 1440 + /* Loop over sg_list until we reach entry at specified offset. */ 1441 + while (data_offset >= sg_dma_len(sg)) { 1442 + data_offset -= sg_dma_len(sg); 1443 + sg_dma_count--; 1444 + sg = sg_next(sg); 1445 + /* If we reach the end of the list, offset was invalid. */ 1446 + if (!sg || sg_dma_count == 0) 1447 + return -EINVAL; 1448 + } 1449 + 1450 + /* Compute number of DMA-mapped SG entries to add into OCS DMA list. */ 1451 + dma_nents = 0; 1452 + tmp = 0; 1453 + sg_tmp = sg; 1454 + while (tmp < data_offset + data_size) { 1455 + /* If we reach the end of the list, data_size was invalid. */ 1456 + if (!sg_tmp) 1457 + return -EINVAL; 1458 + tmp += sg_dma_len(sg_tmp); 1459 + dma_nents++; 1460 + sg_tmp = sg_next(sg_tmp); 1461 + } 1462 + if (dma_nents > sg_dma_count) 1463 + return -EINVAL; 1464 + 1465 + /* Allocate the DMA list, one entry for each SG entry. */ 1466 + dll_desc->size = sizeof(struct ocs_dma_linked_list) * dma_nents; 1467 + dll_desc->vaddr = dma_alloc_coherent(aes_dev->dev, dll_desc->size, 1468 + &dll_desc->dma_addr, GFP_KERNEL); 1469 + if (!dll_desc->vaddr) 1470 + return -ENOMEM; 1471 + 1472 + /* Populate DMA linked list entries. */ 1473 + ll = dll_desc->vaddr; 1474 + for (i = 0; i < dma_nents; i++, sg = sg_next(sg)) { 1475 + ll[i].src_addr = sg_dma_address(sg) + data_offset; 1476 + ll[i].src_len = (sg_dma_len(sg) - data_offset) < data_size ? 1477 + (sg_dma_len(sg) - data_offset) : data_size; 1478 + data_offset = 0; 1479 + data_size -= ll[i].src_len; 1480 + /* Current element points to the DMA address of the next one. */ 1481 + ll[i].next = dll_desc->dma_addr + (sizeof(*ll) * (i + 1)); 1482 + ll[i].ll_flags = 0; 1483 + } 1484 + /* Terminate last element. */ 1485 + ll[i - 1].next = 0; 1486 + ll[i - 1].ll_flags = OCS_LL_DMA_FLAG_TERMINATE; 1487 + 1488 + return 0; 1489 + }
+129
drivers/crypto/keembay/ocs-aes.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Intel Keem Bay OCS AES Crypto Driver. 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation 6 + */ 7 + 8 + #ifndef _CRYPTO_OCS_AES_H 9 + #define _CRYPTO_OCS_AES_H 10 + 11 + #include <linux/dma-mapping.h> 12 + 13 + enum ocs_cipher { 14 + OCS_AES = 0, 15 + OCS_SM4 = 1, 16 + }; 17 + 18 + enum ocs_mode { 19 + OCS_MODE_ECB = 0, 20 + OCS_MODE_CBC = 1, 21 + OCS_MODE_CTR = 2, 22 + OCS_MODE_CCM = 6, 23 + OCS_MODE_GCM = 7, 24 + OCS_MODE_CTS = 9, 25 + }; 26 + 27 + enum ocs_instruction { 28 + OCS_ENCRYPT = 0, 29 + OCS_DECRYPT = 1, 30 + OCS_EXPAND = 2, 31 + OCS_BYPASS = 3, 32 + }; 33 + 34 + /** 35 + * struct ocs_aes_dev - AES device context. 36 + * @list: List head for insertion into device list hold 37 + * by driver. 38 + * @dev: OCS AES device. 39 + * @irq: IRQ number. 40 + * @base_reg: IO base address of OCS AES. 41 + * @irq_copy_completion: Completion to indicate IRQ has been triggered. 42 + * @dma_err_mask: Error reported by OCS DMA interrupts. 43 + * @engine: Crypto engine for the device. 44 + */ 45 + struct ocs_aes_dev { 46 + struct list_head list; 47 + struct device *dev; 48 + int irq; 49 + void __iomem *base_reg; 50 + struct completion irq_completion; 51 + u32 dma_err_mask; 52 + struct crypto_engine *engine; 53 + }; 54 + 55 + /** 56 + * struct ocs_dll_desc - Descriptor of an OCS DMA Linked List. 57 + * @vaddr: Virtual address of the linked list head. 58 + * @dma_addr: DMA address of the linked list head. 59 + * @size: Size (in bytes) of the linked list. 60 + */ 61 + struct ocs_dll_desc { 62 + void *vaddr; 63 + dma_addr_t dma_addr; 64 + size_t size; 65 + }; 66 + 67 + int ocs_aes_set_key(struct ocs_aes_dev *aes_dev, const u32 key_size, 68 + const u8 *key, const enum ocs_cipher cipher); 69 + 70 + int ocs_aes_op(struct ocs_aes_dev *aes_dev, 71 + enum ocs_mode mode, 72 + enum ocs_cipher cipher, 73 + enum ocs_instruction instruction, 74 + dma_addr_t dst_dma_list, 75 + dma_addr_t src_dma_list, 76 + u32 src_size, 77 + u8 *iv, 78 + u32 iv_size); 79 + 80 + /** 81 + * ocs_aes_bypass_op() - Use OCS DMA to copy data. 82 + * @aes_dev: The OCS AES device to use. 83 + * @dst_dma_list: The OCS DMA list mapping the memory where input data 84 + * will be copied to. 85 + * @src_dma_list: The OCS DMA list mapping input data. 86 + * @src_size: The amount of data to copy. 87 + */ 88 + static inline int ocs_aes_bypass_op(struct ocs_aes_dev *aes_dev, 89 + dma_addr_t dst_dma_list, 90 + dma_addr_t src_dma_list, u32 src_size) 91 + { 92 + return ocs_aes_op(aes_dev, OCS_MODE_ECB, OCS_AES, OCS_BYPASS, 93 + dst_dma_list, src_dma_list, src_size, NULL, 0); 94 + } 95 + 96 + int ocs_aes_gcm_op(struct ocs_aes_dev *aes_dev, 97 + enum ocs_cipher cipher, 98 + enum ocs_instruction instruction, 99 + dma_addr_t dst_dma_list, 100 + dma_addr_t src_dma_list, 101 + u32 src_size, 102 + const u8 *iv, 103 + dma_addr_t aad_dma_list, 104 + u32 aad_size, 105 + u8 *out_tag, 106 + u32 tag_size); 107 + 108 + int ocs_aes_ccm_op(struct ocs_aes_dev *aes_dev, 109 + enum ocs_cipher cipher, 110 + enum ocs_instruction instruction, 111 + dma_addr_t dst_dma_list, 112 + dma_addr_t src_dma_list, 113 + u32 src_size, 114 + u8 *iv, 115 + dma_addr_t adata_dma_list, 116 + u32 adata_size, 117 + u8 *in_tag, 118 + u32 tag_size); 119 + 120 + int ocs_create_linked_list_from_sg(const struct ocs_aes_dev *aes_dev, 121 + struct scatterlist *sg, 122 + int sg_dma_count, 123 + struct ocs_dll_desc *dll_desc, 124 + size_t data_size, 125 + size_t data_offset); 126 + 127 + irqreturn_t ocs_aes_irq_handler(int irq, void *dev_id); 128 + 129 + #endif
+2 -1
drivers/crypto/marvell/cesa/hash.c
··· 11 11 12 12 #include <crypto/hmac.h> 13 13 #include <crypto/md5.h> 14 - #include <crypto/sha.h> 14 + #include <crypto/sha1.h> 15 + #include <crypto/sha2.h> 15 16 #include <linux/device.h> 16 17 #include <linux/dma-mapping.h> 17 18
+2 -8
drivers/crypto/marvell/octeontx/otx_cptpf_main.c
··· 212 212 goto err_disable_device; 213 213 } 214 214 215 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48)); 215 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); 216 216 if (err) { 217 - dev_err(dev, "Unable to get usable DMA configuration\n"); 218 - goto err_release_regions; 219 - } 220 - 221 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48)); 222 - if (err) { 223 - dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n"); 217 + dev_err(dev, "Unable to get usable 48-bit DMA configuration\n"); 224 218 goto err_release_regions; 225 219 } 226 220
+2 -1
drivers/crypto/marvell/octeontx/otx_cptvf_algs.c
··· 13 13 #include <crypto/cryptd.h> 14 14 #include <crypto/des.h> 15 15 #include <crypto/internal/aead.h> 16 - #include <crypto/sha.h> 16 + #include <crypto/sha1.h> 17 + #include <crypto/sha2.h> 17 18 #include <crypto/xts.h> 18 19 #include <crypto/scatterwalk.h> 19 20 #include <linux/rtnetlink.h>
+2 -8
drivers/crypto/marvell/octeontx/otx_cptvf_main.c
··· 804 804 dev_err(dev, "PCI request regions failed 0x%x\n", err); 805 805 goto disable_device; 806 806 } 807 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48)); 807 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)); 808 808 if (err) { 809 - dev_err(dev, "Unable to get usable DMA configuration\n"); 810 - goto release_regions; 811 - } 812 - 813 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48)); 814 - if (err) { 815 - dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n"); 809 + dev_err(dev, "Unable to get usable 48-bit DMA configuration\n"); 816 810 goto release_regions; 817 811 } 818 812
+2 -1
drivers/crypto/mediatek/mtk-sha.c
··· 10 10 */ 11 11 12 12 #include <crypto/hmac.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha1.h> 14 + #include <crypto/sha2.h> 14 15 #include "mtk-platform.h" 15 16 16 17 #define SHA_ALIGN_MSK (sizeof(u32) - 1)
+2 -1
drivers/crypto/mxs-dcp.c
··· 17 17 #include <linux/clk.h> 18 18 19 19 #include <crypto/aes.h> 20 - #include <crypto/sha.h> 20 + #include <crypto/sha1.h> 21 + #include <crypto/sha2.h> 21 22 #include <crypto/internal/hash.h> 22 23 #include <crypto/internal/skcipher.h> 23 24 #include <crypto/scatterwalk.h>
+2 -1
drivers/crypto/n2_core.c
··· 15 15 #include <linux/interrupt.h> 16 16 #include <linux/crypto.h> 17 17 #include <crypto/md5.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha1.h> 19 + #include <crypto/sha2.h> 19 20 #include <crypto/aes.h> 20 21 #include <crypto/internal/des.h> 21 22 #include <linux/mutex.h>
+1 -1
drivers/crypto/nx/nx-sha256.c
··· 8 8 */ 9 9 10 10 #include <crypto/internal/hash.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha2.h> 12 12 #include <linux/module.h> 13 13 #include <asm/vio.h> 14 14 #include <asm/byteorder.h>
+1 -1
drivers/crypto/nx/nx-sha512.c
··· 8 8 */ 9 9 10 10 #include <crypto/internal/hash.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha2.h> 12 12 #include <linux/module.h> 13 13 #include <asm/vio.h> 14 14
+1 -1
drivers/crypto/nx/nx.c
··· 10 10 #include <crypto/internal/aead.h> 11 11 #include <crypto/internal/hash.h> 12 12 #include <crypto/aes.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 #include <crypto/algapi.h> 15 15 #include <crypto/scatterwalk.h> 16 16 #include <linux/module.h>
+3 -1
drivers/crypto/omap-aes.c
··· 105 105 106 106 err = pm_runtime_get_sync(dd->dev); 107 107 if (err < 0) { 108 + pm_runtime_put_noidle(dd->dev); 108 109 dev_err(dd->dev, "failed to get sync: %d\n", err); 109 110 return err; 110 111 } ··· 1138 1137 if (err < 0) { 1139 1138 dev_err(dev, "%s: failed to get_sync(%d)\n", 1140 1139 __func__, err); 1141 - goto err_res; 1140 + goto err_pm_disable; 1142 1141 } 1143 1142 1144 1143 omap_aes_dma_stop(dd); ··· 1247 1246 omap_aes_dma_cleanup(dd); 1248 1247 err_irq: 1249 1248 tasklet_kill(&dd->done_task); 1249 + err_pm_disable: 1250 1250 pm_runtime_disable(dev); 1251 1251 err_res: 1252 1252 dd = NULL;
+2 -1
drivers/crypto/omap-sham.c
··· 35 35 #include <linux/crypto.h> 36 36 #include <crypto/scatterwalk.h> 37 37 #include <crypto/algapi.h> 38 - #include <crypto/sha.h> 38 + #include <crypto/sha1.h> 39 + #include <crypto/sha2.h> 39 40 #include <crypto/hash.h> 40 41 #include <crypto/hmac.h> 41 42 #include <crypto/internal/hash.h>
+2 -1
drivers/crypto/padlock-sha.c
··· 9 9 10 10 #include <crypto/internal/hash.h> 11 11 #include <crypto/padlock.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha1.h> 13 + #include <crypto/sha2.h> 13 14 #include <linux/err.h> 14 15 #include <linux/module.h> 15 16 #include <linux/init.h>
+2 -1
drivers/crypto/picoxcell_crypto.c
··· 8 8 #include <crypto/authenc.h> 9 9 #include <crypto/internal/des.h> 10 10 #include <crypto/md5.h> 11 - #include <crypto/sha.h> 11 + #include <crypto/sha1.h> 12 + #include <crypto/sha2.h> 12 13 #include <crypto/internal/skcipher.h> 13 14 #include <linux/clk.h> 14 15 #include <linux/crypto.h>
+11
drivers/crypto/qat/Kconfig
··· 46 46 To compile this as a module, choose M here: the module 47 47 will be called qat_c62x. 48 48 49 + config CRYPTO_DEV_QAT_4XXX 50 + tristate "Support for Intel(R) QAT_4XXX" 51 + depends on X86 && PCI 52 + select CRYPTO_DEV_QAT 53 + help 54 + Support for Intel(R) QuickAssist Technology QAT_4xxx 55 + for accelerating crypto and compression workloads. 56 + 57 + To compile this as a module, choose M here: the module 58 + will be called qat_4xxx. 59 + 49 60 config CRYPTO_DEV_QAT_DH895xCCVF 50 61 tristate "Support for Intel(R) DH895xCC Virtual Function" 51 62 depends on X86 && PCI
+1
drivers/crypto/qat/Makefile
··· 3 3 obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCC) += qat_dh895xcc/ 4 4 obj-$(CONFIG_CRYPTO_DEV_QAT_C3XXX) += qat_c3xxx/ 5 5 obj-$(CONFIG_CRYPTO_DEV_QAT_C62X) += qat_c62x/ 6 + obj-$(CONFIG_CRYPTO_DEV_QAT_4XXX) += qat_4xxx/ 6 7 obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCCVF) += qat_dh895xccvf/ 7 8 obj-$(CONFIG_CRYPTO_DEV_QAT_C3XXXVF) += qat_c3xxxvf/ 8 9 obj-$(CONFIG_CRYPTO_DEV_QAT_C62XVF) += qat_c62xvf/
+4
drivers/crypto/qat/qat_4xxx/Makefile
··· 1 + # SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 + ccflags-y := -I $(srctree)/$(src)/../qat_common 3 + obj-$(CONFIG_CRYPTO_DEV_QAT_4XXX) += qat_4xxx.o 4 + qat_4xxx-objs := adf_drv.o adf_4xxx_hw_data.o
+242
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.c
··· 1 + // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #include <adf_accel_devices.h> 4 + #include <adf_common_drv.h> 5 + #include <adf_pf2vf_msg.h> 6 + #include <adf_gen4_hw_data.h> 7 + #include "adf_4xxx_hw_data.h" 8 + #include "icp_qat_hw.h" 9 + 10 + struct adf_fw_config { 11 + u32 ae_mask; 12 + char *obj_name; 13 + }; 14 + 15 + static struct adf_fw_config adf_4xxx_fw_config[] = { 16 + {0xF0, ADF_4XXX_SYM_OBJ}, 17 + {0xF, ADF_4XXX_ASYM_OBJ}, 18 + {0x100, ADF_4XXX_ADMIN_OBJ}, 19 + }; 20 + 21 + /* Worker thread to service arbiter mappings */ 22 + static u32 thrd_to_arb_map[] = { 23 + 0x5555555, 0x5555555, 0x5555555, 0x5555555, 24 + 0xAAAAAAA, 0xAAAAAAA, 0xAAAAAAA, 0xAAAAAAA, 25 + 0x0 26 + }; 27 + 28 + static struct adf_hw_device_class adf_4xxx_class = { 29 + .name = ADF_4XXX_DEVICE_NAME, 30 + .type = DEV_4XXX, 31 + .instances = 0, 32 + }; 33 + 34 + static u32 get_accel_mask(struct adf_hw_device_data *self) 35 + { 36 + return ADF_4XXX_ACCELERATORS_MASK; 37 + } 38 + 39 + static u32 get_ae_mask(struct adf_hw_device_data *self) 40 + { 41 + u32 me_disable = self->fuses; 42 + 43 + return ~me_disable & ADF_4XXX_ACCELENGINES_MASK; 44 + } 45 + 46 + static u32 get_num_accels(struct adf_hw_device_data *self) 47 + { 48 + return ADF_4XXX_MAX_ACCELERATORS; 49 + } 50 + 51 + static u32 get_num_aes(struct adf_hw_device_data *self) 52 + { 53 + if (!self || !self->ae_mask) 54 + return 0; 55 + 56 + return hweight32(self->ae_mask); 57 + } 58 + 59 + static u32 get_misc_bar_id(struct adf_hw_device_data *self) 60 + { 61 + return ADF_4XXX_PMISC_BAR; 62 + } 63 + 64 + static u32 get_etr_bar_id(struct adf_hw_device_data *self) 65 + { 66 + return ADF_4XXX_ETR_BAR; 67 + } 68 + 69 + static u32 get_sram_bar_id(struct adf_hw_device_data *self) 70 + { 71 + return ADF_4XXX_SRAM_BAR; 72 + } 73 + 74 + /* 75 + * The vector routing table is used to select the MSI-X entry to use for each 76 + * interrupt source. 77 + * The first ADF_4XXX_ETR_MAX_BANKS entries correspond to ring interrupts. 78 + * The final entry corresponds to VF2PF or error interrupts. 79 + * This vector table could be used to configure one MSI-X entry to be shared 80 + * between multiple interrupt sources. 81 + * 82 + * The default routing is set to have a one to one correspondence between the 83 + * interrupt source and the MSI-X entry used. 84 + */ 85 + static void set_msix_default_rttable(struct adf_accel_dev *accel_dev) 86 + { 87 + void __iomem *csr; 88 + int i; 89 + 90 + csr = (&GET_BARS(accel_dev)[ADF_4XXX_PMISC_BAR])->virt_addr; 91 + for (i = 0; i <= ADF_4XXX_ETR_MAX_BANKS; i++) 92 + ADF_CSR_WR(csr, ADF_4XXX_MSIX_RTTABLE_OFFSET(i), i); 93 + } 94 + 95 + static u32 get_accel_cap(struct adf_accel_dev *accel_dev) 96 + { 97 + struct pci_dev *pdev = accel_dev->accel_pci_dev.pci_dev; 98 + u32 fusectl1; 99 + u32 capabilities = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | 100 + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | 101 + ICP_ACCEL_CAPABILITIES_AUTHENTICATION | 102 + ICP_ACCEL_CAPABILITIES_AES_V2; 103 + 104 + /* Read accelerator capabilities mask */ 105 + pci_read_config_dword(pdev, ADF_4XXX_FUSECTL1_OFFSET, &fusectl1); 106 + 107 + if (fusectl1 & ICP_ACCEL_4XXX_MASK_CIPHER_SLICE) 108 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; 109 + if (fusectl1 & ICP_ACCEL_4XXX_MASK_AUTH_SLICE) 110 + capabilities &= ~ICP_ACCEL_CAPABILITIES_AUTHENTICATION; 111 + if (fusectl1 & ICP_ACCEL_4XXX_MASK_PKE_SLICE) 112 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; 113 + 114 + return capabilities; 115 + } 116 + 117 + static enum dev_sku_info get_sku(struct adf_hw_device_data *self) 118 + { 119 + return DEV_SKU_1; 120 + } 121 + 122 + static void adf_get_arbiter_mapping(struct adf_accel_dev *accel_dev, 123 + u32 const **arb_map_config) 124 + { 125 + struct adf_hw_device_data *hw_device = accel_dev->hw_device; 126 + unsigned long ae_mask = hw_device->ae_mask; 127 + int i; 128 + 129 + for_each_clear_bit(i, &ae_mask, ADF_4XXX_MAX_ACCELENGINES) 130 + thrd_to_arb_map[i] = 0; 131 + 132 + *arb_map_config = thrd_to_arb_map; 133 + } 134 + 135 + static void get_arb_info(struct arb_info *arb_info) 136 + { 137 + arb_info->arb_cfg = ADF_4XXX_ARB_CONFIG; 138 + arb_info->arb_offset = ADF_4XXX_ARB_OFFSET; 139 + arb_info->wt2sam_offset = ADF_4XXX_ARB_WRK_2_SER_MAP_OFFSET; 140 + } 141 + 142 + static void get_admin_info(struct admin_info *admin_csrs_info) 143 + { 144 + admin_csrs_info->mailbox_offset = ADF_4XXX_MAILBOX_BASE_OFFSET; 145 + admin_csrs_info->admin_msg_ur = ADF_4XXX_ADMINMSGUR_OFFSET; 146 + admin_csrs_info->admin_msg_lr = ADF_4XXX_ADMINMSGLR_OFFSET; 147 + } 148 + 149 + static void adf_enable_error_correction(struct adf_accel_dev *accel_dev) 150 + { 151 + struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_4XXX_PMISC_BAR]; 152 + void __iomem *csr = misc_bar->virt_addr; 153 + 154 + /* Enable all in errsou3 except VFLR notification on host */ 155 + ADF_CSR_WR(csr, ADF_4XXX_ERRMSK3, ADF_4XXX_VFLNOTIFY); 156 + } 157 + 158 + static void adf_enable_ints(struct adf_accel_dev *accel_dev) 159 + { 160 + void __iomem *addr; 161 + 162 + addr = (&GET_BARS(accel_dev)[ADF_4XXX_PMISC_BAR])->virt_addr; 163 + 164 + /* Enable bundle interrupts */ 165 + ADF_CSR_WR(addr, ADF_4XXX_SMIAPF_RP_X0_MASK_OFFSET, 0); 166 + ADF_CSR_WR(addr, ADF_4XXX_SMIAPF_RP_X1_MASK_OFFSET, 0); 167 + 168 + /* Enable misc interrupts */ 169 + ADF_CSR_WR(addr, ADF_4XXX_SMIAPF_MASK_OFFSET, 0); 170 + } 171 + 172 + static int adf_pf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev) 173 + { 174 + return 0; 175 + } 176 + 177 + static u32 uof_get_num_objs(void) 178 + { 179 + return ARRAY_SIZE(adf_4xxx_fw_config); 180 + } 181 + 182 + static char *uof_get_name(u32 obj_num) 183 + { 184 + return adf_4xxx_fw_config[obj_num].obj_name; 185 + } 186 + 187 + static u32 uof_get_ae_mask(u32 obj_num) 188 + { 189 + return adf_4xxx_fw_config[obj_num].ae_mask; 190 + } 191 + 192 + void adf_init_hw_data_4xxx(struct adf_hw_device_data *hw_data) 193 + { 194 + hw_data->dev_class = &adf_4xxx_class; 195 + hw_data->instance_id = adf_4xxx_class.instances++; 196 + hw_data->num_banks = ADF_4XXX_ETR_MAX_BANKS; 197 + hw_data->num_rings_per_bank = ADF_4XXX_NUM_RINGS_PER_BANK; 198 + hw_data->num_accel = ADF_4XXX_MAX_ACCELERATORS; 199 + hw_data->num_engines = ADF_4XXX_MAX_ACCELENGINES; 200 + hw_data->num_logical_accel = 1; 201 + hw_data->tx_rx_gap = ADF_4XXX_RX_RINGS_OFFSET; 202 + hw_data->tx_rings_mask = ADF_4XXX_TX_RINGS_MASK; 203 + hw_data->alloc_irq = adf_isr_resource_alloc; 204 + hw_data->free_irq = adf_isr_resource_free; 205 + hw_data->enable_error_correction = adf_enable_error_correction; 206 + hw_data->get_accel_mask = get_accel_mask; 207 + hw_data->get_ae_mask = get_ae_mask; 208 + hw_data->get_num_accels = get_num_accels; 209 + hw_data->get_num_aes = get_num_aes; 210 + hw_data->get_sram_bar_id = get_sram_bar_id; 211 + hw_data->get_etr_bar_id = get_etr_bar_id; 212 + hw_data->get_misc_bar_id = get_misc_bar_id; 213 + hw_data->get_arb_info = get_arb_info; 214 + hw_data->get_admin_info = get_admin_info; 215 + hw_data->get_accel_cap = get_accel_cap; 216 + hw_data->get_sku = get_sku; 217 + hw_data->fw_name = ADF_4XXX_FW; 218 + hw_data->fw_mmp_name = ADF_4XXX_MMP; 219 + hw_data->init_admin_comms = adf_init_admin_comms; 220 + hw_data->exit_admin_comms = adf_exit_admin_comms; 221 + hw_data->disable_iov = adf_disable_sriov; 222 + hw_data->send_admin_init = adf_send_admin_init; 223 + hw_data->init_arb = adf_init_arb; 224 + hw_data->exit_arb = adf_exit_arb; 225 + hw_data->get_arb_mapping = adf_get_arbiter_mapping; 226 + hw_data->enable_ints = adf_enable_ints; 227 + hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 228 + hw_data->reset_device = adf_reset_flr; 229 + hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 230 + hw_data->admin_ae_mask = ADF_4XXX_ADMIN_AE_MASK; 231 + hw_data->uof_get_num_objs = uof_get_num_objs; 232 + hw_data->uof_get_name = uof_get_name; 233 + hw_data->uof_get_ae_mask = uof_get_ae_mask; 234 + hw_data->set_msix_rttable = set_msix_default_rttable; 235 + 236 + adf_gen4_init_hw_csr_ops(&hw_data->csr_ops); 237 + } 238 + 239 + void adf_clean_hw_data_4xxx(struct adf_hw_device_data *hw_data) 240 + { 241 + hw_data->dev_class->instances--; 242 + }
+86
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.h
··· 1 + /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */ 2 + /* Copyright(c) 2014 - 2020 Intel Corporation */ 3 + #ifndef ADF_4XXX_HW_DATA_H_ 4 + #define ADF_4XXX_HW_DATA_H_ 5 + 6 + #include <adf_accel_devices.h> 7 + 8 + /* PCIe configuration space */ 9 + #define ADF_4XXX_SRAM_BAR 0 10 + #define ADF_4XXX_PMISC_BAR 1 11 + #define ADF_4XXX_ETR_BAR 2 12 + #define ADF_4XXX_RX_RINGS_OFFSET 1 13 + #define ADF_4XXX_TX_RINGS_MASK 0x1 14 + #define ADF_4XXX_MAX_ACCELERATORS 1 15 + #define ADF_4XXX_MAX_ACCELENGINES 9 16 + #define ADF_4XXX_BAR_MASK (BIT(0) | BIT(2) | BIT(4)) 17 + 18 + /* Physical function fuses */ 19 + #define ADF_4XXX_FUSECTL0_OFFSET (0x2C8) 20 + #define ADF_4XXX_FUSECTL1_OFFSET (0x2CC) 21 + #define ADF_4XXX_FUSECTL2_OFFSET (0x2D0) 22 + #define ADF_4XXX_FUSECTL3_OFFSET (0x2D4) 23 + #define ADF_4XXX_FUSECTL4_OFFSET (0x2D8) 24 + #define ADF_4XXX_FUSECTL5_OFFSET (0x2DC) 25 + 26 + #define ADF_4XXX_ACCELERATORS_MASK (0x1) 27 + #define ADF_4XXX_ACCELENGINES_MASK (0x1FF) 28 + #define ADF_4XXX_ADMIN_AE_MASK (0x100) 29 + 30 + #define ADF_4XXX_ETR_MAX_BANKS 64 31 + 32 + /* MSIX interrupt */ 33 + #define ADF_4XXX_SMIAPF_RP_X0_MASK_OFFSET (0x41A040) 34 + #define ADF_4XXX_SMIAPF_RP_X1_MASK_OFFSET (0x41A044) 35 + #define ADF_4XXX_SMIAPF_MASK_OFFSET (0x41A084) 36 + #define ADF_4XXX_MSIX_RTTABLE_OFFSET(i) (0x409000 + ((i) * 0x04)) 37 + 38 + /* Bank and ring configuration */ 39 + #define ADF_4XXX_NUM_RINGS_PER_BANK 2 40 + 41 + /* Error source registers */ 42 + #define ADF_4XXX_ERRSOU0 (0x41A200) 43 + #define ADF_4XXX_ERRSOU1 (0x41A204) 44 + #define ADF_4XXX_ERRSOU2 (0x41A208) 45 + #define ADF_4XXX_ERRSOU3 (0x41A20C) 46 + 47 + /* Error source mask registers */ 48 + #define ADF_4XXX_ERRMSK0 (0x41A210) 49 + #define ADF_4XXX_ERRMSK1 (0x41A214) 50 + #define ADF_4XXX_ERRMSK2 (0x41A218) 51 + #define ADF_4XXX_ERRMSK3 (0x41A21C) 52 + 53 + #define ADF_4XXX_VFLNOTIFY BIT(7) 54 + 55 + /* Arbiter configuration */ 56 + #define ADF_4XXX_ARB_CONFIG (BIT(31) | BIT(6) | BIT(0)) 57 + #define ADF_4XXX_ARB_OFFSET (0x0) 58 + #define ADF_4XXX_ARB_WRK_2_SER_MAP_OFFSET (0x400) 59 + 60 + /* Admin Interface Reg Offset */ 61 + #define ADF_4XXX_ADMINMSGUR_OFFSET (0x500574) 62 + #define ADF_4XXX_ADMINMSGLR_OFFSET (0x500578) 63 + #define ADF_4XXX_MAILBOX_BASE_OFFSET (0x600970) 64 + 65 + /* Firmware Binaries */ 66 + #define ADF_4XXX_FW "qat_4xxx.bin" 67 + #define ADF_4XXX_MMP "qat_4xxx_mmp.bin" 68 + #define ADF_4XXX_SYM_OBJ "qat_4xxx_sym.bin" 69 + #define ADF_4XXX_ASYM_OBJ "qat_4xxx_asym.bin" 70 + #define ADF_4XXX_ADMIN_OBJ "qat_4xxx_admin.bin" 71 + 72 + /* qat_4xxx fuse bits are different from old GENs, redefine them */ 73 + enum icp_qat_4xxx_slice_mask { 74 + ICP_ACCEL_4XXX_MASK_CIPHER_SLICE = BIT(0), 75 + ICP_ACCEL_4XXX_MASK_AUTH_SLICE = BIT(1), 76 + ICP_ACCEL_4XXX_MASK_PKE_SLICE = BIT(2), 77 + ICP_ACCEL_4XXX_MASK_COMPRESS_SLICE = BIT(3), 78 + ICP_ACCEL_4XXX_MASK_UCS_SLICE = BIT(4), 79 + ICP_ACCEL_4XXX_MASK_EIA3_SLICE = BIT(5), 80 + ICP_ACCEL_4XXX_MASK_SMX_SLICE = BIT(6), 81 + }; 82 + 83 + void adf_init_hw_data_4xxx(struct adf_hw_device_data *hw_data); 84 + void adf_clean_hw_data_4xxx(struct adf_hw_device_data *hw_data); 85 + 86 + #endif
+323
drivers/crypto/qat/qat_4xxx/adf_drv.c
··· 1 + // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #include <linux/device.h> 4 + #include <linux/module.h> 5 + #include <linux/pci.h> 6 + 7 + #include <adf_accel_devices.h> 8 + #include <adf_cfg.h> 9 + #include <adf_common_drv.h> 10 + 11 + #include "adf_4xxx_hw_data.h" 12 + #include "qat_crypto.h" 13 + #include "adf_transport_access_macros.h" 14 + 15 + static const struct pci_device_id adf_pci_tbl[] = { 16 + { PCI_VDEVICE(INTEL, ADF_4XXX_PCI_DEVICE_ID), }, 17 + { } 18 + }; 19 + MODULE_DEVICE_TABLE(pci, adf_pci_tbl); 20 + 21 + static void adf_cleanup_accel(struct adf_accel_dev *accel_dev) 22 + { 23 + if (accel_dev->hw_device) { 24 + adf_clean_hw_data_4xxx(accel_dev->hw_device); 25 + accel_dev->hw_device = NULL; 26 + } 27 + adf_cfg_dev_remove(accel_dev); 28 + debugfs_remove(accel_dev->debugfs_dir); 29 + adf_devmgr_rm_dev(accel_dev, NULL); 30 + } 31 + 32 + static int adf_crypto_dev_config(struct adf_accel_dev *accel_dev) 33 + { 34 + char key[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; 35 + int banks = GET_MAX_BANKS(accel_dev); 36 + int cpus = num_online_cpus(); 37 + unsigned long bank, val; 38 + int instances; 39 + int ret; 40 + int i; 41 + 42 + if (adf_hw_dev_has_crypto(accel_dev)) 43 + instances = min(cpus, banks / 2); 44 + else 45 + instances = 0; 46 + 47 + ret = adf_cfg_section_add(accel_dev, ADF_KERNEL_SEC); 48 + if (ret) 49 + goto err; 50 + 51 + ret = adf_cfg_section_add(accel_dev, "Accelerator0"); 52 + if (ret) 53 + goto err; 54 + 55 + for (i = 0; i < instances; i++) { 56 + val = i; 57 + bank = i * 2; 58 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_BANK_NUM, i); 59 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 60 + key, &bank, ADF_DEC); 61 + if (ret) 62 + goto err; 63 + 64 + bank += 1; 65 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_BANK_NUM, i); 66 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 67 + key, &bank, ADF_DEC); 68 + if (ret) 69 + goto err; 70 + 71 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_ETRMGR_CORE_AFFINITY, 72 + i); 73 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 74 + key, &val, ADF_DEC); 75 + if (ret) 76 + goto err; 77 + 78 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_SIZE, i); 79 + val = 128; 80 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 81 + key, &val, ADF_DEC); 82 + if (ret) 83 + goto err; 84 + 85 + val = 512; 86 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_SIZE, i); 87 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 88 + key, &val, ADF_DEC); 89 + if (ret) 90 + goto err; 91 + 92 + val = 0; 93 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_TX, i); 94 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 95 + key, &val, ADF_DEC); 96 + if (ret) 97 + goto err; 98 + 99 + val = 0; 100 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_TX, i); 101 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 102 + key, &val, ADF_DEC); 103 + if (ret) 104 + goto err; 105 + 106 + val = 1; 107 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_RX, i); 108 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 109 + key, &val, ADF_DEC); 110 + if (ret) 111 + goto err; 112 + 113 + val = 1; 114 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_RX, i); 115 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 116 + key, &val, ADF_DEC); 117 + if (ret) 118 + goto err; 119 + 120 + val = ADF_COALESCING_DEF_TIME; 121 + snprintf(key, sizeof(key), ADF_ETRMGR_COALESCE_TIMER_FORMAT, i); 122 + ret = adf_cfg_add_key_value_param(accel_dev, "Accelerator0", 123 + key, &val, ADF_DEC); 124 + if (ret) 125 + goto err; 126 + } 127 + 128 + val = i; 129 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, ADF_NUM_CY, 130 + &val, ADF_DEC); 131 + if (ret) 132 + goto err; 133 + 134 + set_bit(ADF_STATUS_CONFIGURED, &accel_dev->status); 135 + return 0; 136 + err: 137 + dev_err(&GET_DEV(accel_dev), "Failed to start QAT accel dev\n"); 138 + return ret; 139 + } 140 + 141 + static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 142 + { 143 + struct adf_accel_dev *accel_dev; 144 + struct adf_accel_pci *accel_pci_dev; 145 + struct adf_hw_device_data *hw_data; 146 + char name[ADF_DEVICE_NAME_LENGTH]; 147 + unsigned int i, bar_nr; 148 + unsigned long bar_mask; 149 + struct adf_bar *bar; 150 + int ret; 151 + 152 + if (num_possible_nodes() > 1 && dev_to_node(&pdev->dev) < 0) { 153 + /* 154 + * If the accelerator is connected to a node with no memory 155 + * there is no point in using the accelerator since the remote 156 + * memory transaction will be very slow. 157 + */ 158 + dev_err(&pdev->dev, "Invalid NUMA configuration.\n"); 159 + return -EINVAL; 160 + } 161 + 162 + accel_dev = devm_kzalloc(&pdev->dev, sizeof(*accel_dev), GFP_KERNEL); 163 + if (!accel_dev) 164 + return -ENOMEM; 165 + 166 + INIT_LIST_HEAD(&accel_dev->crypto_list); 167 + accel_pci_dev = &accel_dev->accel_pci_dev; 168 + accel_pci_dev->pci_dev = pdev; 169 + 170 + /* 171 + * Add accel device to accel table 172 + * This should be called before adf_cleanup_accel is called 173 + */ 174 + if (adf_devmgr_add_dev(accel_dev, NULL)) { 175 + dev_err(&pdev->dev, "Failed to add new accelerator device.\n"); 176 + return -EFAULT; 177 + } 178 + 179 + accel_dev->owner = THIS_MODULE; 180 + /* Allocate and initialise device hardware meta-data structure */ 181 + hw_data = devm_kzalloc(&pdev->dev, sizeof(*hw_data), GFP_KERNEL); 182 + if (!hw_data) { 183 + ret = -ENOMEM; 184 + goto out_err; 185 + } 186 + 187 + accel_dev->hw_device = hw_data; 188 + adf_init_hw_data_4xxx(accel_dev->hw_device); 189 + 190 + pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid); 191 + pci_read_config_dword(pdev, ADF_4XXX_FUSECTL4_OFFSET, &hw_data->fuses); 192 + 193 + /* Get Accelerators and Accelerators Engines masks */ 194 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 195 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 196 + accel_pci_dev->sku = hw_data->get_sku(hw_data); 197 + /* If the device has no acceleration engines then ignore it */ 198 + if (!hw_data->accel_mask || !hw_data->ae_mask || 199 + (~hw_data->ae_mask & 0x01)) { 200 + dev_err(&pdev->dev, "No acceleration units found.\n"); 201 + ret = -EFAULT; 202 + goto out_err; 203 + } 204 + 205 + /* Create dev top level debugfs entry */ 206 + snprintf(name, sizeof(name), "%s%s_%s", ADF_DEVICE_NAME_PREFIX, 207 + hw_data->dev_class->name, pci_name(pdev)); 208 + 209 + accel_dev->debugfs_dir = debugfs_create_dir(name, NULL); 210 + 211 + /* Create device configuration table */ 212 + ret = adf_cfg_dev_add(accel_dev); 213 + if (ret) 214 + goto out_err; 215 + 216 + /* Enable PCI device */ 217 + ret = pcim_enable_device(pdev); 218 + if (ret) { 219 + dev_err(&pdev->dev, "Can't enable PCI device.\n"); 220 + goto out_err; 221 + } 222 + 223 + /* Set DMA identifier */ 224 + if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { 225 + if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) { 226 + dev_err(&pdev->dev, "No usable DMA configuration.\n"); 227 + ret = -EFAULT; 228 + goto out_err; 229 + } else { 230 + pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 231 + } 232 + } else { 233 + pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 234 + } 235 + 236 + /* Get accelerator capabilities mask */ 237 + hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev); 238 + 239 + /* Find and map all the device's BARS */ 240 + bar_mask = pci_select_bars(pdev, IORESOURCE_MEM) & ADF_4XXX_BAR_MASK; 241 + 242 + ret = pcim_iomap_regions_request_all(pdev, bar_mask, pci_name(pdev)); 243 + if (ret) { 244 + dev_err(&pdev->dev, "Failed to map pci regions.\n"); 245 + goto out_err; 246 + } 247 + 248 + i = 0; 249 + for_each_set_bit(bar_nr, &bar_mask, PCI_STD_NUM_BARS) { 250 + bar = &accel_pci_dev->pci_bars[i++]; 251 + bar->virt_addr = pcim_iomap_table(pdev)[bar_nr]; 252 + } 253 + 254 + pci_set_master(pdev); 255 + 256 + if (adf_enable_aer(accel_dev)) { 257 + dev_err(&pdev->dev, "Failed to enable aer.\n"); 258 + ret = -EFAULT; 259 + goto out_err; 260 + } 261 + 262 + if (pci_save_state(pdev)) { 263 + dev_err(&pdev->dev, "Failed to save pci state.\n"); 264 + ret = -ENOMEM; 265 + goto out_err_disable_aer; 266 + } 267 + 268 + ret = adf_crypto_dev_config(accel_dev); 269 + if (ret) 270 + goto out_err_disable_aer; 271 + 272 + ret = adf_dev_init(accel_dev); 273 + if (ret) 274 + goto out_err_dev_shutdown; 275 + 276 + ret = adf_dev_start(accel_dev); 277 + if (ret) 278 + goto out_err_dev_stop; 279 + 280 + return ret; 281 + 282 + out_err_dev_stop: 283 + adf_dev_stop(accel_dev); 284 + out_err_dev_shutdown: 285 + adf_dev_shutdown(accel_dev); 286 + out_err_disable_aer: 287 + adf_disable_aer(accel_dev); 288 + out_err: 289 + adf_cleanup_accel(accel_dev); 290 + return ret; 291 + } 292 + 293 + static void adf_remove(struct pci_dev *pdev) 294 + { 295 + struct adf_accel_dev *accel_dev = adf_devmgr_pci_to_accel_dev(pdev); 296 + 297 + if (!accel_dev) { 298 + pr_err("QAT: Driver removal failed\n"); 299 + return; 300 + } 301 + adf_dev_stop(accel_dev); 302 + adf_dev_shutdown(accel_dev); 303 + adf_disable_aer(accel_dev); 304 + adf_cleanup_accel(accel_dev); 305 + } 306 + 307 + static struct pci_driver adf_driver = { 308 + .id_table = adf_pci_tbl, 309 + .name = ADF_4XXX_DEVICE_NAME, 310 + .probe = adf_probe, 311 + .remove = adf_remove, 312 + .sriov_configure = adf_sriov_configure, 313 + }; 314 + 315 + module_pci_driver(adf_driver); 316 + 317 + MODULE_LICENSE("Dual BSD/GPL"); 318 + MODULE_AUTHOR("Intel"); 319 + MODULE_FIRMWARE(ADF_4XXX_FW); 320 + MODULE_FIRMWARE(ADF_4XXX_MMP); 321 + MODULE_DESCRIPTION("Intel(R) QuickAssist Technology"); 322 + MODULE_VERSION(ADF_DRV_VERSION); 323 + MODULE_SOFTDEP("pre: crypto-intel_qat");
+42 -7
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_common_drv.h> 5 5 #include <adf_pf2vf_msg.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_c3xxx_hw_data.h" 8 + #include "icp_qat_hw.h" 7 9 8 10 /* Worker thread to service arbiter mappings based on dev SKUs */ 9 11 static const u32 thrd_to_arb_map_6_me_sku[] = { ··· 19 17 .instances = 0 20 18 }; 21 19 22 - static u32 get_accel_mask(u32 fuse) 20 + static u32 get_accel_mask(struct adf_hw_device_data *self) 23 21 { 24 - return (~fuse) >> ADF_C3XXX_ACCELERATORS_REG_OFFSET & 25 - ADF_C3XXX_ACCELERATORS_MASK; 22 + u32 straps = self->straps; 23 + u32 fuses = self->fuses; 24 + u32 accel; 25 + 26 + accel = ~(fuses | straps) >> ADF_C3XXX_ACCELERATORS_REG_OFFSET; 27 + accel &= ADF_C3XXX_ACCELERATORS_MASK; 28 + 29 + return accel; 26 30 } 27 31 28 - static u32 get_ae_mask(u32 fuse) 32 + static u32 get_ae_mask(struct adf_hw_device_data *self) 29 33 { 30 - return (~fuse) & ADF_C3XXX_ACCELENGINES_MASK; 34 + u32 straps = self->straps; 35 + u32 fuses = self->fuses; 36 + unsigned long disabled; 37 + u32 ae_disable; 38 + int accel; 39 + 40 + /* If an accel is disabled, then disable the corresponding two AEs */ 41 + disabled = ~get_accel_mask(self) & ADF_C3XXX_ACCELERATORS_MASK; 42 + ae_disable = BIT(1) | BIT(0); 43 + for_each_set_bit(accel, &disabled, ADF_C3XXX_MAX_ACCELERATORS) 44 + straps |= ae_disable << (accel << 1); 45 + 46 + return ~(fuses | straps) & ADF_C3XXX_ACCELENGINES_MASK; 31 47 } 32 48 33 49 static u32 get_num_accels(struct adf_hw_device_data *self) ··· 129 109 { 130 110 struct adf_hw_device_data *hw_device = accel_dev->hw_device; 131 111 struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C3XXX_PMISC_BAR]; 112 + unsigned long accel_mask = hw_device->accel_mask; 113 + unsigned long ae_mask = hw_device->ae_mask; 132 114 void __iomem *csr = misc_bar->virt_addr; 133 115 unsigned int val, i; 134 116 135 117 /* Enable Accel Engine error detection & correction */ 136 - for (i = 0; i < hw_device->get_num_aes(hw_device); i++) { 118 + for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 137 119 val = ADF_CSR_RD(csr, ADF_C3XXX_AE_CTX_ENABLES(i)); 138 120 val |= ADF_C3XXX_ENABLE_AE_ECC_ERR; 139 121 ADF_CSR_WR(csr, ADF_C3XXX_AE_CTX_ENABLES(i), val); ··· 145 123 } 146 124 147 125 /* Enable shared memory error detection & correction */ 148 - for (i = 0; i < hw_device->get_num_accels(hw_device); i++) { 126 + for_each_set_bit(i, &accel_mask, ADF_C3XXX_MAX_ACCELERATORS) { 149 127 val = ADF_CSR_RD(csr, ADF_C3XXX_UERRSSMSH(i)); 150 128 val |= ADF_C3XXX_ERRSSMSH_EN; 151 129 ADF_CSR_WR(csr, ADF_C3XXX_UERRSSMSH(i), val); ··· 173 151 return 0; 174 152 } 175 153 154 + static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) 155 + { 156 + adf_gen2_cfg_iov_thds(accel_dev, enable, 157 + ADF_C3XXX_AE2FUNC_MAP_GRP_A_NUM_REGS, 158 + ADF_C3XXX_AE2FUNC_MAP_GRP_B_NUM_REGS); 159 + } 160 + 176 161 void adf_init_hw_data_c3xxx(struct adf_hw_device_data *hw_data) 177 162 { 178 163 hw_data->dev_class = &c3xxx_class; 179 164 hw_data->instance_id = c3xxx_class.instances++; 180 165 hw_data->num_banks = ADF_C3XXX_ETR_MAX_BANKS; 166 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 181 167 hw_data->num_accel = ADF_C3XXX_MAX_ACCELERATORS; 182 168 hw_data->num_logical_accel = 1; 183 169 hw_data->num_engines = ADF_C3XXX_MAX_ACCELENGINES; ··· 196 166 hw_data->enable_error_correction = adf_enable_error_correction; 197 167 hw_data->get_accel_mask = get_accel_mask; 198 168 hw_data->get_ae_mask = get_ae_mask; 169 + hw_data->get_accel_cap = adf_gen2_get_accel_cap; 199 170 hw_data->get_num_accels = get_num_accels; 200 171 hw_data->get_num_aes = get_num_aes; 201 172 hw_data->get_sram_bar_id = get_sram_bar_id; ··· 204 173 hw_data->get_misc_bar_id = get_misc_bar_id; 205 174 hw_data->get_pf2vf_offset = get_pf2vf_offset; 206 175 hw_data->get_vintmsk_offset = get_vintmsk_offset; 176 + hw_data->get_admin_info = adf_gen2_get_admin_info; 177 + hw_data->get_arb_info = adf_gen2_get_arb_info; 207 178 hw_data->get_sku = get_sku; 208 179 hw_data->fw_name = ADF_C3XXX_FW; 209 180 hw_data->fw_mmp_name = ADF_C3XXX_MMP; 210 181 hw_data->init_admin_comms = adf_init_admin_comms; 211 182 hw_data->exit_admin_comms = adf_exit_admin_comms; 183 + hw_data->configure_iov_threads = configure_iov_threads; 212 184 hw_data->disable_iov = adf_disable_sriov; 213 185 hw_data->send_admin_init = adf_send_admin_init; 214 186 hw_data->init_arb = adf_init_arb; ··· 221 187 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 222 188 hw_data->reset_device = adf_reset_flr; 223 189 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 190 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 224 191 } 225 192 226 193 void adf_clean_hw_data_c3xxx(struct adf_hw_device_data *hw_data)
+5
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.h
··· 18 18 #define ADF_C3XXX_SMIAPF1_MASK_OFFSET (0x3A000 + 0x30) 19 19 #define ADF_C3XXX_SMIA0_MASK 0xFFFF 20 20 #define ADF_C3XXX_SMIA1_MASK 0x1 21 + #define ADF_C3XXX_SOFTSTRAP_CSR_OFFSET 0x2EC 21 22 /* Error detection and correction */ 22 23 #define ADF_C3XXX_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818) 23 24 #define ADF_C3XXX_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960) ··· 30 29 31 30 #define ADF_C3XXX_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 32 31 #define ADF_C3XXX_VINTMSK_OFFSET(i) (0x3A000 + 0x200 + ((i) * 0x04)) 32 + 33 + /* AE to function mapping */ 34 + #define ADF_C3XXX_AE2FUNC_MAP_GRP_A_NUM_REGS 48 35 + #define ADF_C3XXX_AE2FUNC_MAP_GRP_B_NUM_REGS 6 33 36 34 37 /* Firmware Binary */ 35 38 #define ADF_C3XXX_FW "qat_c3xxx.bin"
+6 -5
drivers/crypto/qat/qat_c3xxx/adf_drv.c
··· 126 126 pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid); 127 127 pci_read_config_dword(pdev, ADF_DEVICE_FUSECTL_OFFSET, 128 128 &hw_data->fuses); 129 + pci_read_config_dword(pdev, ADF_C3XXX_SOFTSTRAP_CSR_OFFSET, 130 + &hw_data->straps); 129 131 130 132 /* Get Accelerators and Accelerators Engines masks */ 131 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 132 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 133 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 134 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 133 135 accel_pci_dev->sku = hw_data->get_sku(hw_data); 134 136 /* If the device has no acceleration engines then ignore it. */ 135 137 if (!hw_data->accel_mask || !hw_data->ae_mask || ··· 177 175 goto out_err_disable; 178 176 } 179 177 180 - /* Read accelerator capabilities mask */ 181 - pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET, 182 - &hw_data->accel_capabilities_mask); 178 + /* Get accelerator capabilities mask */ 179 + hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev); 183 180 184 181 /* Find and map all the device's BARS */ 185 182 i = 0;
+5 -2
drivers/crypto/qat/qat_c3xxxvf/adf_c3xxxvf_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_pf2vf_msg.h> 5 5 #include <adf_common_drv.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_c3xxxvf_hw_data.h" 7 8 8 9 static struct adf_hw_device_class c3xxxiov_class = { ··· 12 11 .instances = 0 13 12 }; 14 13 15 - static u32 get_accel_mask(u32 fuse) 14 + static u32 get_accel_mask(struct adf_hw_device_data *self) 16 15 { 17 16 return ADF_C3XXXIOV_ACCELERATORS_MASK; 18 17 } 19 18 20 - static u32 get_ae_mask(u32 fuse) 19 + static u32 get_ae_mask(struct adf_hw_device_data *self) 21 20 { 22 21 return ADF_C3XXXIOV_ACCELENGINES_MASK; 23 22 } ··· 70 69 { 71 70 hw_data->dev_class = &c3xxxiov_class; 72 71 hw_data->num_banks = ADF_C3XXXIOV_ETR_MAX_BANKS; 72 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 73 73 hw_data->num_accel = ADF_C3XXXIOV_MAX_ACCELERATORS; 74 74 hw_data->num_logical_accel = 1; 75 75 hw_data->num_engines = ADF_C3XXXIOV_MAX_ACCELENGINES; ··· 99 97 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 100 98 hw_data->dev_class->instances++; 101 99 adf_devmgr_update_class_index(hw_data); 100 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 102 101 } 103 102 104 103 void adf_clean_hw_data_c3xxxiov(struct adf_hw_device_data *hw_data)
+2 -2
drivers/crypto/qat/qat_c3xxxvf/adf_drv.c
··· 119 119 adf_init_hw_data_c3xxxiov(accel_dev->hw_device); 120 120 121 121 /* Get Accelerators and Accelerators Engines masks */ 122 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 123 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 122 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 123 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 124 124 accel_pci_dev->sku = hw_data->get_sku(hw_data); 125 125 126 126 /* Create dev top level debugfs entry */
+42 -7
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_common_drv.h> 5 5 #include <adf_pf2vf_msg.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_c62x_hw_data.h" 8 + #include "icp_qat_hw.h" 7 9 8 10 /* Worker thread to service arbiter mappings based on dev SKUs */ 9 11 static const u32 thrd_to_arb_map_8_me_sku[] = { ··· 24 22 .instances = 0 25 23 }; 26 24 27 - static u32 get_accel_mask(u32 fuse) 25 + static u32 get_accel_mask(struct adf_hw_device_data *self) 28 26 { 29 - return (~fuse) >> ADF_C62X_ACCELERATORS_REG_OFFSET & 30 - ADF_C62X_ACCELERATORS_MASK; 27 + u32 straps = self->straps; 28 + u32 fuses = self->fuses; 29 + u32 accel; 30 + 31 + accel = ~(fuses | straps) >> ADF_C62X_ACCELERATORS_REG_OFFSET; 32 + accel &= ADF_C62X_ACCELERATORS_MASK; 33 + 34 + return accel; 31 35 } 32 36 33 - static u32 get_ae_mask(u32 fuse) 37 + static u32 get_ae_mask(struct adf_hw_device_data *self) 34 38 { 35 - return (~fuse) & ADF_C62X_ACCELENGINES_MASK; 39 + u32 straps = self->straps; 40 + u32 fuses = self->fuses; 41 + unsigned long disabled; 42 + u32 ae_disable; 43 + int accel; 44 + 45 + /* If an accel is disabled, then disable the corresponding two AEs */ 46 + disabled = ~get_accel_mask(self) & ADF_C62X_ACCELERATORS_MASK; 47 + ae_disable = BIT(1) | BIT(0); 48 + for_each_set_bit(accel, &disabled, ADF_C62X_MAX_ACCELERATORS) 49 + straps |= ae_disable << (accel << 1); 50 + 51 + return ~(fuses | straps) & ADF_C62X_ACCELENGINES_MASK; 36 52 } 37 53 38 54 static u32 get_num_accels(struct adf_hw_device_data *self) ··· 139 119 { 140 120 struct adf_hw_device_data *hw_device = accel_dev->hw_device; 141 121 struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR]; 122 + unsigned long accel_mask = hw_device->accel_mask; 123 + unsigned long ae_mask = hw_device->ae_mask; 142 124 void __iomem *csr = misc_bar->virt_addr; 143 125 unsigned int val, i; 144 126 145 127 /* Enable Accel Engine error detection & correction */ 146 - for (i = 0; i < hw_device->get_num_aes(hw_device); i++) { 128 + for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 147 129 val = ADF_CSR_RD(csr, ADF_C62X_AE_CTX_ENABLES(i)); 148 130 val |= ADF_C62X_ENABLE_AE_ECC_ERR; 149 131 ADF_CSR_WR(csr, ADF_C62X_AE_CTX_ENABLES(i), val); ··· 155 133 } 156 134 157 135 /* Enable shared memory error detection & correction */ 158 - for (i = 0; i < hw_device->get_num_accels(hw_device); i++) { 136 + for_each_set_bit(i, &accel_mask, ADF_C62X_MAX_ACCELERATORS) { 159 137 val = ADF_CSR_RD(csr, ADF_C62X_UERRSSMSH(i)); 160 138 val |= ADF_C62X_ERRSSMSH_EN; 161 139 ADF_CSR_WR(csr, ADF_C62X_UERRSSMSH(i), val); ··· 183 161 return 0; 184 162 } 185 163 164 + static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) 165 + { 166 + adf_gen2_cfg_iov_thds(accel_dev, enable, 167 + ADF_C62X_AE2FUNC_MAP_GRP_A_NUM_REGS, 168 + ADF_C62X_AE2FUNC_MAP_GRP_B_NUM_REGS); 169 + } 170 + 186 171 void adf_init_hw_data_c62x(struct adf_hw_device_data *hw_data) 187 172 { 188 173 hw_data->dev_class = &c62x_class; 189 174 hw_data->instance_id = c62x_class.instances++; 190 175 hw_data->num_banks = ADF_C62X_ETR_MAX_BANKS; 176 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 191 177 hw_data->num_accel = ADF_C62X_MAX_ACCELERATORS; 192 178 hw_data->num_logical_accel = 1; 193 179 hw_data->num_engines = ADF_C62X_MAX_ACCELENGINES; ··· 206 176 hw_data->enable_error_correction = adf_enable_error_correction; 207 177 hw_data->get_accel_mask = get_accel_mask; 208 178 hw_data->get_ae_mask = get_ae_mask; 179 + hw_data->get_accel_cap = adf_gen2_get_accel_cap; 209 180 hw_data->get_num_accels = get_num_accels; 210 181 hw_data->get_num_aes = get_num_aes; 211 182 hw_data->get_sram_bar_id = get_sram_bar_id; ··· 214 183 hw_data->get_misc_bar_id = get_misc_bar_id; 215 184 hw_data->get_pf2vf_offset = get_pf2vf_offset; 216 185 hw_data->get_vintmsk_offset = get_vintmsk_offset; 186 + hw_data->get_admin_info = adf_gen2_get_admin_info; 187 + hw_data->get_arb_info = adf_gen2_get_arb_info; 217 188 hw_data->get_sku = get_sku; 218 189 hw_data->fw_name = ADF_C62X_FW; 219 190 hw_data->fw_mmp_name = ADF_C62X_MMP; 220 191 hw_data->init_admin_comms = adf_init_admin_comms; 221 192 hw_data->exit_admin_comms = adf_exit_admin_comms; 193 + hw_data->configure_iov_threads = configure_iov_threads; 222 194 hw_data->disable_iov = adf_disable_sriov; 223 195 hw_data->send_admin_init = adf_send_admin_init; 224 196 hw_data->init_arb = adf_init_arb; ··· 231 197 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 232 198 hw_data->reset_device = adf_reset_flr; 233 199 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 200 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 234 201 } 235 202 236 203 void adf_clean_hw_data_c62x(struct adf_hw_device_data *hw_data)
+5
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h
··· 19 19 #define ADF_C62X_SMIAPF1_MASK_OFFSET (0x3A000 + 0x30) 20 20 #define ADF_C62X_SMIA0_MASK 0xFFFF 21 21 #define ADF_C62X_SMIA1_MASK 0x1 22 + #define ADF_C62X_SOFTSTRAP_CSR_OFFSET 0x2EC 22 23 /* Error detection and correction */ 23 24 #define ADF_C62X_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818) 24 25 #define ADF_C62X_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960) ··· 31 30 32 31 #define ADF_C62X_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 33 32 #define ADF_C62X_VINTMSK_OFFSET(i) (0x3A000 + 0x200 + ((i) * 0x04)) 33 + 34 + /* AE to function mapping */ 35 + #define ADF_C62X_AE2FUNC_MAP_GRP_A_NUM_REGS 80 36 + #define ADF_C62X_AE2FUNC_MAP_GRP_B_NUM_REGS 10 34 37 35 38 /* Firmware Binary */ 36 39 #define ADF_C62X_FW "qat_c62x.bin"
+6 -5
drivers/crypto/qat/qat_c62x/adf_drv.c
··· 126 126 pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid); 127 127 pci_read_config_dword(pdev, ADF_DEVICE_FUSECTL_OFFSET, 128 128 &hw_data->fuses); 129 + pci_read_config_dword(pdev, ADF_C62X_SOFTSTRAP_CSR_OFFSET, 130 + &hw_data->straps); 129 131 130 132 /* Get Accelerators and Accelerators Engines masks */ 131 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 132 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 133 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 134 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 133 135 accel_pci_dev->sku = hw_data->get_sku(hw_data); 134 136 /* If the device has no acceleration engines then ignore it. */ 135 137 if (!hw_data->accel_mask || !hw_data->ae_mask || ··· 177 175 goto out_err_disable; 178 176 } 179 177 180 - /* Read accelerator capabilities mask */ 181 - pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET, 182 - &hw_data->accel_capabilities_mask); 178 + /* Get accelerator capabilities mask */ 179 + hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev); 183 180 184 181 /* Find and map all the device's BARS */ 185 182 i = (hw_data->fuses & ADF_DEVICE_FUSECTL_MASK) ? 1 : 0;
+5 -2
drivers/crypto/qat/qat_c62xvf/adf_c62xvf_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_pf2vf_msg.h> 5 5 #include <adf_common_drv.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_c62xvf_hw_data.h" 7 8 8 9 static struct adf_hw_device_class c62xiov_class = { ··· 12 11 .instances = 0 13 12 }; 14 13 15 - static u32 get_accel_mask(u32 fuse) 14 + static u32 get_accel_mask(struct adf_hw_device_data *self) 16 15 { 17 16 return ADF_C62XIOV_ACCELERATORS_MASK; 18 17 } 19 18 20 - static u32 get_ae_mask(u32 fuse) 19 + static u32 get_ae_mask(struct adf_hw_device_data *self) 21 20 { 22 21 return ADF_C62XIOV_ACCELENGINES_MASK; 23 22 } ··· 70 69 { 71 70 hw_data->dev_class = &c62xiov_class; 72 71 hw_data->num_banks = ADF_C62XIOV_ETR_MAX_BANKS; 72 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 73 73 hw_data->num_accel = ADF_C62XIOV_MAX_ACCELERATORS; 74 74 hw_data->num_logical_accel = 1; 75 75 hw_data->num_engines = ADF_C62XIOV_MAX_ACCELENGINES; ··· 99 97 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 100 98 hw_data->dev_class->instances++; 101 99 adf_devmgr_update_class_index(hw_data); 100 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 102 101 } 103 102 104 103 void adf_clean_hw_data_c62xiov(struct adf_hw_device_data *hw_data)
+2 -2
drivers/crypto/qat/qat_c62xvf/adf_drv.c
··· 119 119 adf_init_hw_data_c62xiov(accel_dev->hw_device); 120 120 121 121 /* Get Accelerators and Accelerators Engines masks */ 122 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 123 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 122 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 123 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 124 124 accel_pci_dev->sku = hw_data->get_sku(hw_data); 125 125 126 126 /* Create dev top level debugfs entry */
+2
drivers/crypto/qat/qat_common/Makefile
··· 10 10 adf_transport.o \ 11 11 adf_admin.o \ 12 12 adf_hw_arbiter.o \ 13 + adf_gen2_hw_data.o \ 14 + adf_gen4_hw_data.o \ 13 15 qat_crypto.o \ 14 16 qat_algs.o \ 15 17 qat_asym_algs.o \
+62 -3
drivers/crypto/qat/qat_common/adf_accel_devices.h
··· 15 15 #define ADF_C62XVF_DEVICE_NAME "c6xxvf" 16 16 #define ADF_C3XXX_DEVICE_NAME "c3xxx" 17 17 #define ADF_C3XXXVF_DEVICE_NAME "c3xxxvf" 18 + #define ADF_4XXX_DEVICE_NAME "4xxx" 19 + #define ADF_4XXX_PCI_DEVICE_ID 0x4940 20 + #define ADF_4XXXIOV_PCI_DEVICE_ID 0x4941 18 21 #define ADF_ERRSOU3 (0x3A000 + 0x0C) 19 22 #define ADF_ERRSOU5 (0x3A000 + 0xD8) 20 23 #define ADF_DEVICE_FUSECTL_OFFSET 0x40 ··· 100 97 u32 instances; 101 98 } __packed; 102 99 100 + struct arb_info { 101 + u32 arb_cfg; 102 + u32 arb_offset; 103 + u32 wt2sam_offset; 104 + }; 105 + 106 + struct admin_info { 107 + u32 admin_msg_ur; 108 + u32 admin_msg_lr; 109 + u32 mailbox_offset; 110 + }; 111 + 112 + struct adf_hw_csr_ops { 113 + u64 (*build_csr_ring_base_addr)(dma_addr_t addr, u32 size); 114 + u32 (*read_csr_ring_head)(void __iomem *csr_base_addr, u32 bank, 115 + u32 ring); 116 + void (*write_csr_ring_head)(void __iomem *csr_base_addr, u32 bank, 117 + u32 ring, u32 value); 118 + u32 (*read_csr_ring_tail)(void __iomem *csr_base_addr, u32 bank, 119 + u32 ring); 120 + void (*write_csr_ring_tail)(void __iomem *csr_base_addr, u32 bank, 121 + u32 ring, u32 value); 122 + u32 (*read_csr_e_stat)(void __iomem *csr_base_addr, u32 bank); 123 + void (*write_csr_ring_config)(void __iomem *csr_base_addr, u32 bank, 124 + u32 ring, u32 value); 125 + void (*write_csr_ring_base)(void __iomem *csr_base_addr, u32 bank, 126 + u32 ring, dma_addr_t addr); 127 + void (*write_csr_int_flag)(void __iomem *csr_base_addr, u32 bank, 128 + u32 value); 129 + void (*write_csr_int_srcsel)(void __iomem *csr_base_addr, u32 bank); 130 + void (*write_csr_int_col_en)(void __iomem *csr_base_addr, u32 bank, 131 + u32 value); 132 + void (*write_csr_int_col_ctl)(void __iomem *csr_base_addr, u32 bank, 133 + u32 value); 134 + void (*write_csr_int_flag_and_col)(void __iomem *csr_base_addr, 135 + u32 bank, u32 value); 136 + void (*write_csr_ring_srv_arb_en)(void __iomem *csr_base_addr, u32 bank, 137 + u32 value); 138 + }; 139 + 103 140 struct adf_cfg_device_data; 104 141 struct adf_accel_dev; 105 142 struct adf_etr_data; ··· 147 104 148 105 struct adf_hw_device_data { 149 106 struct adf_hw_device_class *dev_class; 150 - u32 (*get_accel_mask)(u32 fuse); 151 - u32 (*get_ae_mask)(u32 fuse); 107 + u32 (*get_accel_mask)(struct adf_hw_device_data *self); 108 + u32 (*get_ae_mask)(struct adf_hw_device_data *self); 109 + u32 (*get_accel_cap)(struct adf_accel_dev *accel_dev); 152 110 u32 (*get_sram_bar_id)(struct adf_hw_device_data *self); 153 111 u32 (*get_misc_bar_id)(struct adf_hw_device_data *self); 154 112 u32 (*get_etr_bar_id)(struct adf_hw_device_data *self); ··· 157 113 u32 (*get_num_accels)(struct adf_hw_device_data *self); 158 114 u32 (*get_pf2vf_offset)(u32 i); 159 115 u32 (*get_vintmsk_offset)(u32 i); 116 + void (*get_arb_info)(struct arb_info *arb_csrs_info); 117 + void (*get_admin_info)(struct admin_info *admin_csrs_info); 160 118 enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self); 161 119 int (*alloc_irq)(struct adf_accel_dev *accel_dev); 162 120 void (*free_irq)(struct adf_accel_dev *accel_dev); ··· 171 125 void (*get_arb_mapping)(struct adf_accel_dev *accel_dev, 172 126 const u32 **cfg); 173 127 void (*disable_iov)(struct adf_accel_dev *accel_dev); 128 + void (*configure_iov_threads)(struct adf_accel_dev *accel_dev, 129 + bool enable); 174 130 void (*enable_ints)(struct adf_accel_dev *accel_dev); 175 131 int (*enable_vf2pf_comms)(struct adf_accel_dev *accel_dev); 176 132 void (*reset_device)(struct adf_accel_dev *accel_dev); 133 + void (*set_msix_rttable)(struct adf_accel_dev *accel_dev); 134 + char *(*uof_get_name)(u32 obj_num); 135 + u32 (*uof_get_num_objs)(void); 136 + u32 (*uof_get_ae_mask)(u32 obj_num); 137 + struct adf_hw_csr_ops csr_ops; 177 138 const char *fw_name; 178 139 const char *fw_mmp_name; 179 140 u32 fuses; 141 + u32 straps; 180 142 u32 accel_capabilities_mask; 181 143 u32 instance_id; 182 144 u16 accel_mask; 183 - u16 ae_mask; 145 + u32 ae_mask; 146 + u32 admin_ae_mask; 184 147 u16 tx_rings_mask; 185 148 u8 tx_rx_gap; 186 149 u8 num_banks; 150 + u8 num_rings_per_bank; 187 151 u8 num_accel; 188 152 u8 num_logical_accel; 189 153 u8 num_engines; ··· 211 155 #define GET_BARS(accel_dev) ((accel_dev)->accel_pci_dev.pci_bars) 212 156 #define GET_HW_DATA(accel_dev) (accel_dev->hw_device) 213 157 #define GET_MAX_BANKS(accel_dev) (GET_HW_DATA(accel_dev)->num_banks) 158 + #define GET_NUM_RINGS_PER_BANK(accel_dev) \ 159 + GET_HW_DATA(accel_dev)->num_rings_per_bank 214 160 #define GET_MAX_ACCELENGINES(accel_dev) (GET_HW_DATA(accel_dev)->num_engines) 161 + #define GET_CSR_OPS(accel_dev) (&(accel_dev)->hw_device->csr_ops) 215 162 #define accel_to_pci_dev(accel_ptr) accel_ptr->accel_pci_dev.pci_dev 216 163 217 164 struct adf_admin_comms;
+56 -13
drivers/crypto/qat/qat_common/adf_accel_engine.c
··· 7 7 #include "adf_common_drv.h" 8 8 #include "icp_qat_uclo.h" 9 9 10 + static int adf_ae_fw_load_images(struct adf_accel_dev *accel_dev, void *fw_addr, 11 + u32 fw_size) 12 + { 13 + struct adf_fw_loader_data *loader_data = accel_dev->fw_loader; 14 + struct adf_hw_device_data *hw_device = accel_dev->hw_device; 15 + struct icp_qat_fw_loader_handle *loader; 16 + char *obj_name; 17 + u32 num_objs; 18 + u32 ae_mask; 19 + int i; 20 + 21 + loader = loader_data->fw_loader; 22 + num_objs = hw_device->uof_get_num_objs(); 23 + 24 + for (i = 0; i < num_objs; i++) { 25 + obj_name = hw_device->uof_get_name(i); 26 + ae_mask = hw_device->uof_get_ae_mask(i); 27 + 28 + if (qat_uclo_set_cfg_ae_mask(loader, ae_mask)) { 29 + dev_err(&GET_DEV(accel_dev), 30 + "Invalid mask for UOF image\n"); 31 + goto out_err; 32 + } 33 + if (qat_uclo_map_obj(loader, fw_addr, fw_size, obj_name)) { 34 + dev_err(&GET_DEV(accel_dev), 35 + "Failed to map UOF firmware\n"); 36 + goto out_err; 37 + } 38 + if (qat_uclo_wr_all_uimage(loader)) { 39 + dev_err(&GET_DEV(accel_dev), 40 + "Failed to load UOF firmware\n"); 41 + goto out_err; 42 + } 43 + qat_uclo_del_obj(loader); 44 + } 45 + 46 + return 0; 47 + 48 + out_err: 49 + adf_ae_fw_release(accel_dev); 50 + return -EFAULT; 51 + } 52 + 10 53 int adf_ae_fw_load(struct adf_accel_dev *accel_dev) 11 54 { 12 55 struct adf_fw_loader_data *loader_data = accel_dev->fw_loader; 13 56 struct adf_hw_device_data *hw_device = accel_dev->hw_device; 14 - void *uof_addr, *mmp_addr; 15 - u32 uof_size, mmp_size; 57 + void *fw_addr, *mmp_addr; 58 + u32 fw_size, mmp_size; 16 59 17 60 if (!hw_device->fw_name) 18 61 return 0; ··· 73 30 goto out_err; 74 31 } 75 32 76 - uof_size = loader_data->uof_fw->size; 77 - uof_addr = (void *)loader_data->uof_fw->data; 33 + fw_size = loader_data->uof_fw->size; 34 + fw_addr = (void *)loader_data->uof_fw->data; 78 35 mmp_size = loader_data->mmp_fw->size; 79 36 mmp_addr = (void *)loader_data->mmp_fw->data; 37 + 80 38 if (qat_uclo_wr_mimage(loader_data->fw_loader, mmp_addr, mmp_size)) { 81 39 dev_err(&GET_DEV(accel_dev), "Failed to load MMP\n"); 82 40 goto out_err; 83 41 } 84 - if (qat_uclo_map_obj(loader_data->fw_loader, uof_addr, uof_size)) { 42 + 43 + if (hw_device->uof_get_num_objs) 44 + return adf_ae_fw_load_images(accel_dev, fw_addr, fw_size); 45 + 46 + if (qat_uclo_map_obj(loader_data->fw_loader, fw_addr, fw_size, NULL)) { 85 47 dev_err(&GET_DEV(accel_dev), "Failed to map FW\n"); 86 48 goto out_err; 87 49 } ··· 109 61 if (!hw_device->fw_name) 110 62 return; 111 63 112 - qat_uclo_del_uof_obj(loader_data->fw_loader); 64 + qat_uclo_del_obj(loader_data->fw_loader); 113 65 qat_hal_deinit(loader_data->fw_loader); 114 66 release_firmware(loader_data->uof_fw); 115 67 release_firmware(loader_data->mmp_fw); ··· 122 74 { 123 75 struct adf_fw_loader_data *loader_data = accel_dev->fw_loader; 124 76 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 125 - u32 ae_ctr, ae, max_aes = GET_MAX_ACCELENGINES(accel_dev); 77 + u32 ae_ctr; 126 78 127 79 if (!hw_data->fw_name) 128 80 return 0; 129 81 130 - for (ae = 0, ae_ctr = 0; ae < max_aes; ae++) { 131 - if (hw_data->ae_mask & (1 << ae)) { 132 - qat_hal_start(loader_data->fw_loader, ae, 0xFF); 133 - ae_ctr++; 134 - } 135 - } 82 + ae_ctr = qat_hal_start(loader_data->fw_loader); 136 83 dev_info(&GET_DEV(accel_dev), 137 84 "qat_dev%d started %d acceleration engines\n", 138 85 accel_dev->accel_id, ae_ctr);
+41 -36
drivers/crypto/qat/qat_common/adf_admin.c
··· 10 10 #include "adf_common_drv.h" 11 11 #include "icp_qat_fw_init_admin.h" 12 12 13 - /* Admin Messages Registers */ 14 - #define ADF_DH895XCC_ADMINMSGUR_OFFSET (0x3A000 + 0x574) 15 - #define ADF_DH895XCC_ADMINMSGLR_OFFSET (0x3A000 + 0x578) 16 - #define ADF_DH895XCC_MAILBOX_BASE_OFFSET 0x20970 17 - #define ADF_DH895XCC_MAILBOX_STRIDE 0x1000 13 + #define ADF_ADMIN_MAILBOX_STRIDE 0x1000 18 14 #define ADF_ADMINMSG_LEN 32 19 15 #define ADF_CONST_TABLE_SIZE 1024 20 16 #define ADF_ADMIN_POLL_DELAY_US 20 ··· 66 70 0xf8, 0x2b, 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1, 0x51, 0x0e, 0x52, 67 71 0x7f, 0xad, 0xe6, 0x82, 0xd1, 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f, 68 72 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b, 0x5b, 0xe0, 0xcd, 0x19, 0x13, 69 - 0x7e, 0x21, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 73 + 0x7e, 0x21, 0x79, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 74 + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 + 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 76 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x18, 70 77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 72 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 73 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 74 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 77 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 78 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 78 + 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 79 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80 + 0x15, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x00, 81 + 0x00, 0x00, 0x00, 0x14, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x02, 82 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 83 + 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 84 + 0x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 85 + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 86 + 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 87 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88 + 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 89 + 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x01, 90 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 91 + 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 92 + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 94 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 91 95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ··· 114 118 struct adf_admin_comms *admin = accel_dev->admin; 115 119 int offset = ae * ADF_ADMINMSG_LEN * 2; 116 120 void __iomem *mailbox = admin->mailbox_addr; 117 - int mb_offset = ae * ADF_DH895XCC_MAILBOX_STRIDE; 121 + int mb_offset = ae * ADF_ADMIN_MAILBOX_STRIDE; 118 122 struct icp_qat_fw_init_admin_req *request = in; 119 123 120 124 mutex_lock(&admin->lock); ··· 163 167 return 0; 164 168 } 165 169 166 - static int adf_init_me(struct adf_accel_dev *accel_dev) 170 + static int adf_init_ae(struct adf_accel_dev *accel_dev) 167 171 { 168 172 struct icp_qat_fw_init_admin_req req; 169 173 struct icp_qat_fw_init_admin_resp resp; ··· 172 176 173 177 memset(&req, 0, sizeof(req)); 174 178 memset(&resp, 0, sizeof(resp)); 175 - req.cmd_id = ICP_QAT_FW_INIT_ME; 179 + req.cmd_id = ICP_QAT_FW_INIT_AE; 176 180 177 181 return adf_send_admin(accel_dev, &req, &resp, ae_mask); 178 182 } ··· 182 186 struct icp_qat_fw_init_admin_req req; 183 187 struct icp_qat_fw_init_admin_resp resp; 184 188 struct adf_hw_device_data *hw_device = accel_dev->hw_device; 185 - u32 ae_mask = hw_device->ae_mask; 189 + u32 ae_mask = hw_device->admin_ae_mask ?: hw_device->ae_mask; 186 190 187 191 memset(&req, 0, sizeof(req)); 188 192 memset(&resp, 0, sizeof(resp)); ··· 206 210 { 207 211 int ret; 208 212 209 - ret = adf_init_me(accel_dev); 213 + ret = adf_set_fw_constants(accel_dev); 210 214 if (ret) 211 215 return ret; 212 216 213 - return adf_set_fw_constants(accel_dev); 217 + return adf_init_ae(accel_dev); 214 218 } 215 219 EXPORT_SYMBOL_GPL(adf_send_admin_init); 216 220 ··· 221 225 struct adf_bar *pmisc = 222 226 &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 223 227 void __iomem *csr = pmisc->virt_addr; 224 - void __iomem *mailbox = (void __iomem *)((uintptr_t)csr + 225 - ADF_DH895XCC_MAILBOX_BASE_OFFSET); 228 + struct admin_info admin_csrs_info; 229 + u32 mailbox_offset, adminmsg_u, adminmsg_l; 230 + void __iomem *mailbox; 226 231 u64 reg_val; 227 232 228 233 admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL, ··· 251 254 } 252 255 253 256 memcpy(admin->virt_tbl_addr, const_tab, sizeof(const_tab)); 257 + hw_data->get_admin_info(&admin_csrs_info); 258 + 259 + mailbox_offset = admin_csrs_info.mailbox_offset; 260 + mailbox = csr + mailbox_offset; 261 + adminmsg_u = admin_csrs_info.admin_msg_ur; 262 + adminmsg_l = admin_csrs_info.admin_msg_lr; 263 + 254 264 reg_val = (u64)admin->phy_addr; 255 - ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGUR_OFFSET, reg_val >> 32); 256 - ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGLR_OFFSET, reg_val); 265 + ADF_CSR_WR(csr, adminmsg_u, upper_32_bits(reg_val)); 266 + ADF_CSR_WR(csr, adminmsg_l, lower_32_bits(reg_val)); 267 + 257 268 mutex_init(&admin->lock); 258 269 admin->mailbox_addr = mailbox; 259 270 accel_dev->admin = admin;
+2 -2
drivers/crypto/qat/qat_common/adf_cfg.c
··· 196 196 memcpy(val, keyval->val, ADF_CFG_MAX_VAL_LEN_IN_BYTES); 197 197 return 0; 198 198 } 199 - return -1; 199 + return -ENODATA; 200 200 } 201 201 202 202 /** ··· 243 243 } else { 244 244 dev_err(&GET_DEV(accel_dev), "Unknown type given.\n"); 245 245 kfree(key_val); 246 - return -1; 246 + return -EINVAL; 247 247 } 248 248 key_val->type = type; 249 249 down_write(&cfg->lock);
+2 -1
drivers/crypto/qat/qat_common/adf_cfg_common.h
··· 32 32 DEV_C62X, 33 33 DEV_C62XVF, 34 34 DEV_C3XXX, 35 - DEV_C3XXXVF 35 + DEV_C3XXXVF, 36 + DEV_4XXX, 36 37 }; 37 38 38 39 struct adf_dev_status_info {
+2 -1
drivers/crypto/qat/qat_common/adf_cfg_strings.h
··· 18 18 #define ADF_RING_DC_TX "RingTx" 19 19 #define ADF_RING_DC_RX "RingRx" 20 20 #define ADF_ETRMGR_BANK "Bank" 21 - #define ADF_RING_BANK_NUM "BankNumber" 21 + #define ADF_RING_SYM_BANK_NUM "BankSymNumber" 22 + #define ADF_RING_ASYM_BANK_NUM "BankAsymNumber" 22 23 #define ADF_CY "Cy" 23 24 #define ADF_DC "Dc" 24 25 #define ADF_ETRMGR_COALESCING_ENABLED "InterruptCoalescingEnabled"
+11 -8
drivers/crypto/qat/qat_common/adf_common_drv.h
··· 133 133 134 134 int qat_hal_init(struct adf_accel_dev *accel_dev); 135 135 void qat_hal_deinit(struct icp_qat_fw_loader_handle *handle); 136 - void qat_hal_start(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 137 - unsigned int ctx_mask); 136 + int qat_hal_start(struct icp_qat_fw_loader_handle *handle); 138 137 void qat_hal_stop(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 139 138 unsigned int ctx_mask); 140 139 void qat_hal_reset(struct icp_qat_fw_loader_handle *handle); ··· 162 163 unsigned char ae, 163 164 struct icp_qat_uof_batch_init *lm_init_header); 164 165 int qat_hal_init_gpr(struct icp_qat_fw_loader_handle *handle, 165 - unsigned char ae, unsigned char ctx_mask, 166 + unsigned char ae, unsigned long ctx_mask, 166 167 enum icp_qat_uof_regtype reg_type, 167 168 unsigned short reg_num, unsigned int regdata); 168 169 int qat_hal_init_wr_xfer(struct icp_qat_fw_loader_handle *handle, 169 - unsigned char ae, unsigned char ctx_mask, 170 + unsigned char ae, unsigned long ctx_mask, 170 171 enum icp_qat_uof_regtype reg_type, 171 172 unsigned short reg_num, unsigned int regdata); 172 173 int qat_hal_init_rd_xfer(struct icp_qat_fw_loader_handle *handle, 173 - unsigned char ae, unsigned char ctx_mask, 174 + unsigned char ae, unsigned long ctx_mask, 174 175 enum icp_qat_uof_regtype reg_type, 175 176 unsigned short reg_num, unsigned int regdata); 176 177 int qat_hal_init_nn(struct icp_qat_fw_loader_handle *handle, 177 - unsigned char ae, unsigned char ctx_mask, 178 + unsigned char ae, unsigned long ctx_mask, 178 179 unsigned short reg_num, unsigned int regdata); 179 180 int qat_hal_wr_lm(struct icp_qat_fw_loader_handle *handle, 180 181 unsigned char ae, unsigned short lm_addr, unsigned int value); 182 + void qat_hal_set_ae_tindex_mode(struct icp_qat_fw_loader_handle *handle, 183 + unsigned char ae, unsigned char mode); 181 184 int qat_uclo_wr_all_uimage(struct icp_qat_fw_loader_handle *handle); 182 - void qat_uclo_del_uof_obj(struct icp_qat_fw_loader_handle *handle); 185 + void qat_uclo_del_obj(struct icp_qat_fw_loader_handle *handle); 183 186 int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle, void *addr_ptr, 184 187 int mem_size); 185 188 int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle, 186 - void *addr_ptr, int mem_size); 189 + void *addr_ptr, u32 mem_size, char *obj_name); 190 + int qat_uclo_set_cfg_ae_mask(struct icp_qat_fw_loader_handle *handle, 191 + unsigned int cfg_ae_mask); 187 192 #if defined(CONFIG_PCI_IOV) 188 193 int adf_sriov_configure(struct pci_dev *pdev, int numvfs); 189 194 void adf_disable_sriov(struct adf_accel_dev *accel_dev);
+6 -5
drivers/crypto/qat/qat_common/adf_dev_mgr.c
··· 151 151 mutex_lock(&table_lock); 152 152 atomic_set(&accel_dev->ref_count, 0); 153 153 154 - /* PF on host or VF on guest */ 155 - if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) { 154 + /* PF on host or VF on guest - optimized to remove redundant is_vf */ 155 + if (!accel_dev->is_vf || !pf) { 156 156 struct vf_id_map *map; 157 157 158 158 list_for_each(itr, &accel_table) { ··· 248 248 struct adf_accel_dev *pf) 249 249 { 250 250 mutex_lock(&table_lock); 251 - if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) { 251 + /* PF on host or VF on guest - optimized to remove redundant is_vf */ 252 + if (!accel_dev->is_vf || !pf) { 252 253 id_map[accel_dev->accel_id] = 0; 253 254 num_devices--; 254 255 } else if (accel_dev->is_vf && pf) { ··· 286 285 287 286 /** 288 287 * adf_devmgr_pci_to_accel_dev() - Get accel_dev associated with the pci_dev. 289 - * @pci_dev: Pointer to pci device. 288 + * @pci_dev: Pointer to PCI device. 290 289 * 291 - * Function returns acceleration device associated with the given pci device. 290 + * Function returns acceleration device associated with the given PCI device. 292 291 * To be used by QAT device specific drivers. 293 292 * 294 293 * Return: pointer to accel_dev or NULL if not found.
+181
drivers/crypto/qat/qat_common/adf_gen2_hw_data.c
··· 1 + // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #include "adf_gen2_hw_data.h" 4 + #include "icp_qat_hw.h" 5 + #include <linux/pci.h> 6 + 7 + void adf_gen2_cfg_iov_thds(struct adf_accel_dev *accel_dev, bool enable, 8 + int num_a_regs, int num_b_regs) 9 + { 10 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 11 + void __iomem *pmisc_addr; 12 + struct adf_bar *pmisc; 13 + int pmisc_id, i; 14 + u32 reg; 15 + 16 + pmisc_id = hw_data->get_misc_bar_id(hw_data); 17 + pmisc = &GET_BARS(accel_dev)[pmisc_id]; 18 + pmisc_addr = pmisc->virt_addr; 19 + 20 + /* Set/Unset Valid bit in AE Thread to PCIe Function Mapping Group A */ 21 + for (i = 0; i < num_a_regs; i++) { 22 + reg = READ_CSR_AE2FUNCTION_MAP_A(pmisc_addr, i); 23 + if (enable) 24 + reg |= AE2FUNCTION_MAP_VALID; 25 + else 26 + reg &= ~AE2FUNCTION_MAP_VALID; 27 + WRITE_CSR_AE2FUNCTION_MAP_A(pmisc_addr, i, reg); 28 + } 29 + 30 + /* Set/Unset Valid bit in AE Thread to PCIe Function Mapping Group B */ 31 + for (i = 0; i < num_b_regs; i++) { 32 + reg = READ_CSR_AE2FUNCTION_MAP_B(pmisc_addr, i); 33 + if (enable) 34 + reg |= AE2FUNCTION_MAP_VALID; 35 + else 36 + reg &= ~AE2FUNCTION_MAP_VALID; 37 + WRITE_CSR_AE2FUNCTION_MAP_B(pmisc_addr, i, reg); 38 + } 39 + } 40 + EXPORT_SYMBOL_GPL(adf_gen2_cfg_iov_thds); 41 + 42 + void adf_gen2_get_admin_info(struct admin_info *admin_csrs_info) 43 + { 44 + admin_csrs_info->mailbox_offset = ADF_MAILBOX_BASE_OFFSET; 45 + admin_csrs_info->admin_msg_ur = ADF_ADMINMSGUR_OFFSET; 46 + admin_csrs_info->admin_msg_lr = ADF_ADMINMSGLR_OFFSET; 47 + } 48 + EXPORT_SYMBOL_GPL(adf_gen2_get_admin_info); 49 + 50 + void adf_gen2_get_arb_info(struct arb_info *arb_info) 51 + { 52 + arb_info->arb_cfg = ADF_ARB_CONFIG; 53 + arb_info->arb_offset = ADF_ARB_OFFSET; 54 + arb_info->wt2sam_offset = ADF_ARB_WRK_2_SER_MAP_OFFSET; 55 + } 56 + EXPORT_SYMBOL_GPL(adf_gen2_get_arb_info); 57 + 58 + static u64 build_csr_ring_base_addr(dma_addr_t addr, u32 size) 59 + { 60 + return BUILD_RING_BASE_ADDR(addr, size); 61 + } 62 + 63 + static u32 read_csr_ring_head(void __iomem *csr_base_addr, u32 bank, u32 ring) 64 + { 65 + return READ_CSR_RING_HEAD(csr_base_addr, bank, ring); 66 + } 67 + 68 + static void write_csr_ring_head(void __iomem *csr_base_addr, u32 bank, u32 ring, 69 + u32 value) 70 + { 71 + WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value); 72 + } 73 + 74 + static u32 read_csr_ring_tail(void __iomem *csr_base_addr, u32 bank, u32 ring) 75 + { 76 + return READ_CSR_RING_TAIL(csr_base_addr, bank, ring); 77 + } 78 + 79 + static void write_csr_ring_tail(void __iomem *csr_base_addr, u32 bank, u32 ring, 80 + u32 value) 81 + { 82 + WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value); 83 + } 84 + 85 + static u32 read_csr_e_stat(void __iomem *csr_base_addr, u32 bank) 86 + { 87 + return READ_CSR_E_STAT(csr_base_addr, bank); 88 + } 89 + 90 + static void write_csr_ring_config(void __iomem *csr_base_addr, u32 bank, 91 + u32 ring, u32 value) 92 + { 93 + WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value); 94 + } 95 + 96 + static void write_csr_ring_base(void __iomem *csr_base_addr, u32 bank, u32 ring, 97 + dma_addr_t addr) 98 + { 99 + WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, addr); 100 + } 101 + 102 + static void write_csr_int_flag(void __iomem *csr_base_addr, u32 bank, u32 value) 103 + { 104 + WRITE_CSR_INT_FLAG(csr_base_addr, bank, value); 105 + } 106 + 107 + static void write_csr_int_srcsel(void __iomem *csr_base_addr, u32 bank) 108 + { 109 + WRITE_CSR_INT_SRCSEL(csr_base_addr, bank); 110 + } 111 + 112 + static void write_csr_int_col_en(void __iomem *csr_base_addr, u32 bank, 113 + u32 value) 114 + { 115 + WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value); 116 + } 117 + 118 + static void write_csr_int_col_ctl(void __iomem *csr_base_addr, u32 bank, 119 + u32 value) 120 + { 121 + WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value); 122 + } 123 + 124 + static void write_csr_int_flag_and_col(void __iomem *csr_base_addr, u32 bank, 125 + u32 value) 126 + { 127 + WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value); 128 + } 129 + 130 + static void write_csr_ring_srv_arb_en(void __iomem *csr_base_addr, u32 bank, 131 + u32 value) 132 + { 133 + WRITE_CSR_RING_SRV_ARB_EN(csr_base_addr, bank, value); 134 + } 135 + 136 + void adf_gen2_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops) 137 + { 138 + csr_ops->build_csr_ring_base_addr = build_csr_ring_base_addr; 139 + csr_ops->read_csr_ring_head = read_csr_ring_head; 140 + csr_ops->write_csr_ring_head = write_csr_ring_head; 141 + csr_ops->read_csr_ring_tail = read_csr_ring_tail; 142 + csr_ops->write_csr_ring_tail = write_csr_ring_tail; 143 + csr_ops->read_csr_e_stat = read_csr_e_stat; 144 + csr_ops->write_csr_ring_config = write_csr_ring_config; 145 + csr_ops->write_csr_ring_base = write_csr_ring_base; 146 + csr_ops->write_csr_int_flag = write_csr_int_flag; 147 + csr_ops->write_csr_int_srcsel = write_csr_int_srcsel; 148 + csr_ops->write_csr_int_col_en = write_csr_int_col_en; 149 + csr_ops->write_csr_int_col_ctl = write_csr_int_col_ctl; 150 + csr_ops->write_csr_int_flag_and_col = write_csr_int_flag_and_col; 151 + csr_ops->write_csr_ring_srv_arb_en = write_csr_ring_srv_arb_en; 152 + } 153 + EXPORT_SYMBOL_GPL(adf_gen2_init_hw_csr_ops); 154 + 155 + u32 adf_gen2_get_accel_cap(struct adf_accel_dev *accel_dev) 156 + { 157 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 158 + struct pci_dev *pdev = accel_dev->accel_pci_dev.pci_dev; 159 + u32 straps = hw_data->straps; 160 + u32 fuses = hw_data->fuses; 161 + u32 legfuses; 162 + u32 capabilities = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | 163 + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | 164 + ICP_ACCEL_CAPABILITIES_AUTHENTICATION; 165 + 166 + /* Read accelerator capabilities mask */ 167 + pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET, &legfuses); 168 + 169 + if (legfuses & ICP_ACCEL_MASK_CIPHER_SLICE) 170 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; 171 + if (legfuses & ICP_ACCEL_MASK_PKE_SLICE) 172 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; 173 + if (legfuses & ICP_ACCEL_MASK_AUTH_SLICE) 174 + capabilities &= ~ICP_ACCEL_CAPABILITIES_AUTHENTICATION; 175 + 176 + if ((straps | fuses) & ADF_POWERGATE_PKE) 177 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; 178 + 179 + return capabilities; 180 + } 181 + EXPORT_SYMBOL_GPL(adf_gen2_get_accel_cap);
+123
drivers/crypto/qat/qat_common/adf_gen2_hw_data.h
··· 1 + /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */ 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #ifndef ADF_GEN2_HW_DATA_H_ 4 + #define ADF_GEN2_HW_DATA_H_ 5 + 6 + #include "adf_accel_devices.h" 7 + 8 + /* Transport access */ 9 + #define ADF_BANK_INT_SRC_SEL_MASK_0 0x4444444CUL 10 + #define ADF_BANK_INT_SRC_SEL_MASK_X 0x44444444UL 11 + #define ADF_RING_CSR_RING_CONFIG 0x000 12 + #define ADF_RING_CSR_RING_LBASE 0x040 13 + #define ADF_RING_CSR_RING_UBASE 0x080 14 + #define ADF_RING_CSR_RING_HEAD 0x0C0 15 + #define ADF_RING_CSR_RING_TAIL 0x100 16 + #define ADF_RING_CSR_E_STAT 0x14C 17 + #define ADF_RING_CSR_INT_FLAG 0x170 18 + #define ADF_RING_CSR_INT_SRCSEL 0x174 19 + #define ADF_RING_CSR_INT_SRCSEL_2 0x178 20 + #define ADF_RING_CSR_INT_COL_EN 0x17C 21 + #define ADF_RING_CSR_INT_COL_CTL 0x180 22 + #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184 23 + #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000 24 + #define ADF_RING_BUNDLE_SIZE 0x1000 25 + 26 + #define BUILD_RING_BASE_ADDR(addr, size) \ 27 + (((addr) >> 6) & (GENMASK_ULL(63, 0) << (size))) 28 + #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring) \ 29 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 30 + ADF_RING_CSR_RING_HEAD + ((ring) << 2)) 31 + #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring) \ 32 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 33 + ADF_RING_CSR_RING_TAIL + ((ring) << 2)) 34 + #define READ_CSR_E_STAT(csr_base_addr, bank) \ 35 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 36 + ADF_RING_CSR_E_STAT) 37 + #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value) \ 38 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 39 + ADF_RING_CSR_RING_CONFIG + ((ring) << 2), value) 40 + #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value) \ 41 + do { \ 42 + u32 l_base = 0, u_base = 0; \ 43 + l_base = (u32)((value) & 0xFFFFFFFF); \ 44 + u_base = (u32)(((value) & 0xFFFFFFFF00000000ULL) >> 32); \ 45 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 46 + ADF_RING_CSR_RING_LBASE + ((ring) << 2), l_base); \ 47 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 48 + ADF_RING_CSR_RING_UBASE + ((ring) << 2), u_base); \ 49 + } while (0) 50 + 51 + #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value) \ 52 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 53 + ADF_RING_CSR_RING_HEAD + ((ring) << 2), value) 54 + #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value) \ 55 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 56 + ADF_RING_CSR_RING_TAIL + ((ring) << 2), value) 57 + #define WRITE_CSR_INT_FLAG(csr_base_addr, bank, value) \ 58 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 59 + ADF_RING_CSR_INT_FLAG, value) 60 + #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank) \ 61 + do { \ 62 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 63 + ADF_RING_CSR_INT_SRCSEL, ADF_BANK_INT_SRC_SEL_MASK_0); \ 64 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 65 + ADF_RING_CSR_INT_SRCSEL_2, ADF_BANK_INT_SRC_SEL_MASK_X); \ 66 + } while (0) 67 + #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value) \ 68 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 69 + ADF_RING_CSR_INT_COL_EN, value) 70 + #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value) \ 71 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 72 + ADF_RING_CSR_INT_COL_CTL, \ 73 + ADF_RING_CSR_INT_COL_CTL_ENABLE | (value)) 74 + #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value) \ 75 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 76 + ADF_RING_CSR_INT_FLAG_AND_COL, value) 77 + 78 + /* AE to function map */ 79 + #define AE2FUNCTION_MAP_A_OFFSET (0x3A400 + 0x190) 80 + #define AE2FUNCTION_MAP_B_OFFSET (0x3A400 + 0x310) 81 + #define AE2FUNCTION_MAP_REG_SIZE 4 82 + #define AE2FUNCTION_MAP_VALID BIT(7) 83 + 84 + #define READ_CSR_AE2FUNCTION_MAP_A(pmisc_bar_addr, index) \ 85 + ADF_CSR_RD(pmisc_bar_addr, AE2FUNCTION_MAP_A_OFFSET + \ 86 + AE2FUNCTION_MAP_REG_SIZE * (index)) 87 + #define WRITE_CSR_AE2FUNCTION_MAP_A(pmisc_bar_addr, index, value) \ 88 + ADF_CSR_WR(pmisc_bar_addr, AE2FUNCTION_MAP_A_OFFSET + \ 89 + AE2FUNCTION_MAP_REG_SIZE * (index), value) 90 + #define READ_CSR_AE2FUNCTION_MAP_B(pmisc_bar_addr, index) \ 91 + ADF_CSR_RD(pmisc_bar_addr, AE2FUNCTION_MAP_B_OFFSET + \ 92 + AE2FUNCTION_MAP_REG_SIZE * (index)) 93 + #define WRITE_CSR_AE2FUNCTION_MAP_B(pmisc_bar_addr, index, value) \ 94 + ADF_CSR_WR(pmisc_bar_addr, AE2FUNCTION_MAP_B_OFFSET + \ 95 + AE2FUNCTION_MAP_REG_SIZE * (index), value) 96 + 97 + /* Admin Interface Offsets */ 98 + #define ADF_ADMINMSGUR_OFFSET (0x3A000 + 0x574) 99 + #define ADF_ADMINMSGLR_OFFSET (0x3A000 + 0x578) 100 + #define ADF_MAILBOX_BASE_OFFSET 0x20970 101 + 102 + /* Arbiter configuration */ 103 + #define ADF_ARB_OFFSET 0x30000 104 + #define ADF_ARB_WRK_2_SER_MAP_OFFSET 0x180 105 + #define ADF_ARB_CONFIG (BIT(31) | BIT(6) | BIT(0)) 106 + #define ADF_ARB_REG_SLOT 0x1000 107 + #define ADF_ARB_RINGSRVARBEN_OFFSET 0x19C 108 + 109 + #define WRITE_CSR_RING_SRV_ARB_EN(csr_addr, index, value) \ 110 + ADF_CSR_WR(csr_addr, ADF_ARB_RINGSRVARBEN_OFFSET + \ 111 + (ADF_ARB_REG_SLOT * (index)), value) 112 + 113 + /* Power gating */ 114 + #define ADF_POWERGATE_PKE BIT(24) 115 + 116 + void adf_gen2_cfg_iov_thds(struct adf_accel_dev *accel_dev, bool enable, 117 + int num_a_regs, int num_b_regs); 118 + void adf_gen2_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops); 119 + void adf_gen2_get_admin_info(struct admin_info *admin_csrs_info); 120 + void adf_gen2_get_arb_info(struct arb_info *arb_info); 121 + u32 adf_gen2_get_accel_cap(struct adf_accel_dev *accel_dev); 122 + 123 + #endif
+101
drivers/crypto/qat/qat_common/adf_gen4_hw_data.c
··· 1 + // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #include "adf_accel_devices.h" 4 + #include "adf_gen4_hw_data.h" 5 + 6 + static u64 build_csr_ring_base_addr(dma_addr_t addr, u32 size) 7 + { 8 + return BUILD_RING_BASE_ADDR(addr, size); 9 + } 10 + 11 + static u32 read_csr_ring_head(void __iomem *csr_base_addr, u32 bank, u32 ring) 12 + { 13 + return READ_CSR_RING_HEAD(csr_base_addr, bank, ring); 14 + } 15 + 16 + static void write_csr_ring_head(void __iomem *csr_base_addr, u32 bank, u32 ring, 17 + u32 value) 18 + { 19 + WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value); 20 + } 21 + 22 + static u32 read_csr_ring_tail(void __iomem *csr_base_addr, u32 bank, u32 ring) 23 + { 24 + return READ_CSR_RING_TAIL(csr_base_addr, bank, ring); 25 + } 26 + 27 + static void write_csr_ring_tail(void __iomem *csr_base_addr, u32 bank, u32 ring, 28 + u32 value) 29 + { 30 + WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value); 31 + } 32 + 33 + static u32 read_csr_e_stat(void __iomem *csr_base_addr, u32 bank) 34 + { 35 + return READ_CSR_E_STAT(csr_base_addr, bank); 36 + } 37 + 38 + static void write_csr_ring_config(void __iomem *csr_base_addr, u32 bank, u32 ring, 39 + u32 value) 40 + { 41 + WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value); 42 + } 43 + 44 + static void write_csr_ring_base(void __iomem *csr_base_addr, u32 bank, u32 ring, 45 + dma_addr_t addr) 46 + { 47 + WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, addr); 48 + } 49 + 50 + static void write_csr_int_flag(void __iomem *csr_base_addr, u32 bank, 51 + u32 value) 52 + { 53 + WRITE_CSR_INT_FLAG(csr_base_addr, bank, value); 54 + } 55 + 56 + static void write_csr_int_srcsel(void __iomem *csr_base_addr, u32 bank) 57 + { 58 + WRITE_CSR_INT_SRCSEL(csr_base_addr, bank); 59 + } 60 + 61 + static void write_csr_int_col_en(void __iomem *csr_base_addr, u32 bank, u32 value) 62 + { 63 + WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value); 64 + } 65 + 66 + static void write_csr_int_col_ctl(void __iomem *csr_base_addr, u32 bank, 67 + u32 value) 68 + { 69 + WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value); 70 + } 71 + 72 + static void write_csr_int_flag_and_col(void __iomem *csr_base_addr, u32 bank, 73 + u32 value) 74 + { 75 + WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value); 76 + } 77 + 78 + static void write_csr_ring_srv_arb_en(void __iomem *csr_base_addr, u32 bank, 79 + u32 value) 80 + { 81 + WRITE_CSR_RING_SRV_ARB_EN(csr_base_addr, bank, value); 82 + } 83 + 84 + void adf_gen4_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops) 85 + { 86 + csr_ops->build_csr_ring_base_addr = build_csr_ring_base_addr; 87 + csr_ops->read_csr_ring_head = read_csr_ring_head; 88 + csr_ops->write_csr_ring_head = write_csr_ring_head; 89 + csr_ops->read_csr_ring_tail = read_csr_ring_tail; 90 + csr_ops->write_csr_ring_tail = write_csr_ring_tail; 91 + csr_ops->read_csr_e_stat = read_csr_e_stat; 92 + csr_ops->write_csr_ring_config = write_csr_ring_config; 93 + csr_ops->write_csr_ring_base = write_csr_ring_base; 94 + csr_ops->write_csr_int_flag = write_csr_int_flag; 95 + csr_ops->write_csr_int_srcsel = write_csr_int_srcsel; 96 + csr_ops->write_csr_int_col_en = write_csr_int_col_en; 97 + csr_ops->write_csr_int_col_ctl = write_csr_int_col_ctl; 98 + csr_ops->write_csr_int_flag_and_col = write_csr_int_flag_and_col; 99 + csr_ops->write_csr_ring_srv_arb_en = write_csr_ring_srv_arb_en; 100 + } 101 + EXPORT_SYMBOL_GPL(adf_gen4_init_hw_csr_ops);
+99
drivers/crypto/qat/qat_common/adf_gen4_hw_data.h
··· 1 + /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */ 2 + /* Copyright(c) 2020 Intel Corporation */ 3 + #ifndef ADF_GEN4_HW_CSR_DATA_H_ 4 + #define ADF_GEN4_HW_CSR_DATA_H_ 5 + 6 + #include "adf_accel_devices.h" 7 + 8 + /* Transport access */ 9 + #define ADF_BANK_INT_SRC_SEL_MASK 0x44UL 10 + #define ADF_RING_CSR_RING_CONFIG 0x1000 11 + #define ADF_RING_CSR_RING_LBASE 0x1040 12 + #define ADF_RING_CSR_RING_UBASE 0x1080 13 + #define ADF_RING_CSR_RING_HEAD 0x0C0 14 + #define ADF_RING_CSR_RING_TAIL 0x100 15 + #define ADF_RING_CSR_E_STAT 0x14C 16 + #define ADF_RING_CSR_INT_FLAG 0x170 17 + #define ADF_RING_CSR_INT_SRCSEL 0x174 18 + #define ADF_RING_CSR_INT_COL_CTL 0x180 19 + #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184 20 + #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000 21 + #define ADF_RING_CSR_INT_COL_EN 0x17C 22 + #define ADF_RING_CSR_ADDR_OFFSET 0x100000 23 + #define ADF_RING_BUNDLE_SIZE 0x2000 24 + 25 + #define BUILD_RING_BASE_ADDR(addr, size) \ 26 + ((((addr) >> 6) & (GENMASK_ULL(63, 0) << (size))) << 6) 27 + #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring) \ 28 + ADF_CSR_RD((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 29 + ADF_RING_BUNDLE_SIZE * (bank) + \ 30 + ADF_RING_CSR_RING_HEAD + ((ring) << 2)) 31 + #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring) \ 32 + ADF_CSR_RD((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 33 + ADF_RING_BUNDLE_SIZE * (bank) + \ 34 + ADF_RING_CSR_RING_TAIL + ((ring) << 2)) 35 + #define READ_CSR_E_STAT(csr_base_addr, bank) \ 36 + ADF_CSR_RD((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 37 + ADF_RING_BUNDLE_SIZE * (bank) + ADF_RING_CSR_E_STAT) 38 + #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value) \ 39 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 40 + ADF_RING_BUNDLE_SIZE * (bank) + \ 41 + ADF_RING_CSR_RING_CONFIG + ((ring) << 2), value) 42 + #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value) \ 43 + do { \ 44 + void __iomem *_csr_base_addr = csr_base_addr; \ 45 + u32 _bank = bank; \ 46 + u32 _ring = ring; \ 47 + dma_addr_t _value = value; \ 48 + u32 l_base = 0, u_base = 0; \ 49 + l_base = lower_32_bits(_value); \ 50 + u_base = upper_32_bits(_value); \ 51 + ADF_CSR_WR((_csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 52 + ADF_RING_BUNDLE_SIZE * (_bank) + \ 53 + ADF_RING_CSR_RING_LBASE + ((_ring) << 2), l_base); \ 54 + ADF_CSR_WR((_csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 55 + ADF_RING_BUNDLE_SIZE * (_bank) + \ 56 + ADF_RING_CSR_RING_UBASE + ((_ring) << 2), u_base); \ 57 + } while (0) 58 + 59 + #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value) \ 60 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 61 + ADF_RING_BUNDLE_SIZE * (bank) + \ 62 + ADF_RING_CSR_RING_HEAD + ((ring) << 2), value) 63 + #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value) \ 64 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 65 + ADF_RING_BUNDLE_SIZE * (bank) + \ 66 + ADF_RING_CSR_RING_TAIL + ((ring) << 2), value) 67 + #define WRITE_CSR_INT_FLAG(csr_base_addr, bank, value) \ 68 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 69 + ADF_RING_BUNDLE_SIZE * (bank) + \ 70 + ADF_RING_CSR_INT_FLAG, (value)) 71 + #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank) \ 72 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 73 + ADF_RING_BUNDLE_SIZE * (bank) + \ 74 + ADF_RING_CSR_INT_SRCSEL, ADF_BANK_INT_SRC_SEL_MASK) 75 + #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value) \ 76 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 77 + ADF_RING_BUNDLE_SIZE * (bank) + \ 78 + ADF_RING_CSR_INT_COL_EN, (value)) 79 + #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value) \ 80 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 81 + ADF_RING_BUNDLE_SIZE * (bank) + \ 82 + ADF_RING_CSR_INT_COL_CTL, \ 83 + ADF_RING_CSR_INT_COL_CTL_ENABLE | (value)) 84 + #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value) \ 85 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 86 + ADF_RING_BUNDLE_SIZE * (bank) + \ 87 + ADF_RING_CSR_INT_FLAG_AND_COL, (value)) 88 + 89 + /* Arbiter configuration */ 90 + #define ADF_RING_CSR_RING_SRV_ARB_EN 0x19C 91 + 92 + #define WRITE_CSR_RING_SRV_ARB_EN(csr_base_addr, bank, value) \ 93 + ADF_CSR_WR((csr_base_addr) + ADF_RING_CSR_ADDR_OFFSET, \ 94 + ADF_RING_BUNDLE_SIZE * (bank) + \ 95 + ADF_RING_CSR_RING_SRV_ARB_EN, (value)) 96 + 97 + void adf_gen4_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops); 98 + 99 + #endif
+49 -41
drivers/crypto/qat/qat_common/adf_hw_arbiter.c
··· 6 6 7 7 #define ADF_ARB_NUM 4 8 8 #define ADF_ARB_REG_SIZE 0x4 9 - #define ADF_ARB_WTR_SIZE 0x20 10 - #define ADF_ARB_OFFSET 0x30000 11 - #define ADF_ARB_REG_SLOT 0x1000 12 - #define ADF_ARB_WTR_OFFSET 0x010 13 - #define ADF_ARB_RO_EN_OFFSET 0x090 14 - #define ADF_ARB_WQCFG_OFFSET 0x100 15 - #define ADF_ARB_WRK_2_SER_MAP_OFFSET 0x180 16 - #define ADF_ARB_RINGSRVARBEN_OFFSET 0x19C 17 9 18 - #define WRITE_CSR_ARB_RINGSRVARBEN(csr_addr, index, value) \ 19 - ADF_CSR_WR(csr_addr, ADF_ARB_RINGSRVARBEN_OFFSET + \ 20 - (ADF_ARB_REG_SLOT * index), value) 10 + #define WRITE_CSR_ARB_SARCONFIG(csr_addr, arb_offset, index, value) \ 11 + ADF_CSR_WR(csr_addr, (arb_offset) + \ 12 + (ADF_ARB_REG_SIZE * (index)), value) 21 13 22 - #define WRITE_CSR_ARB_SARCONFIG(csr_addr, index, value) \ 23 - ADF_CSR_WR(csr_addr, ADF_ARB_OFFSET + \ 24 - (ADF_ARB_REG_SIZE * index), value) 25 - 26 - #define WRITE_CSR_ARB_WRK_2_SER_MAP(csr_addr, index, value) \ 27 - ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \ 28 - ADF_ARB_WRK_2_SER_MAP_OFFSET) + \ 29 - (ADF_ARB_REG_SIZE * index), value) 30 - 31 - #define WRITE_CSR_ARB_WQCFG(csr_addr, index, value) \ 32 - ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \ 33 - ADF_ARB_WQCFG_OFFSET) + (ADF_ARB_REG_SIZE * index), value) 14 + #define WRITE_CSR_ARB_WT2SAM(csr_addr, arb_offset, wt_offset, index, value) \ 15 + ADF_CSR_WR(csr_addr, ((arb_offset) + (wt_offset)) + \ 16 + (ADF_ARB_REG_SIZE * (index)), value) 34 17 35 18 int adf_init_arb(struct adf_accel_dev *accel_dev) 36 19 { 37 20 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 38 21 void __iomem *csr = accel_dev->transport->banks[0].csr_addr; 39 - u32 arb_cfg = 0x1 << 31 | 0x4 << 4 | 0x1; 40 - u32 arb, i; 22 + u32 arb_off, wt_off, arb_cfg; 41 23 const u32 *thd_2_arb_cfg; 24 + struct arb_info info; 25 + int arb, i; 26 + 27 + hw_data->get_arb_info(&info); 28 + arb_cfg = info.arb_cfg; 29 + arb_off = info.arb_offset; 30 + wt_off = info.wt2sam_offset; 42 31 43 32 /* Service arb configured for 32 bytes responses and 44 33 * ring flow control check enabled. */ 45 34 for (arb = 0; arb < ADF_ARB_NUM; arb++) 46 - WRITE_CSR_ARB_SARCONFIG(csr, arb, arb_cfg); 47 - 48 - /* Setup worker queue registers */ 49 - for (i = 0; i < hw_data->num_engines; i++) 50 - WRITE_CSR_ARB_WQCFG(csr, i, i); 35 + WRITE_CSR_ARB_SARCONFIG(csr, arb_off, arb, arb_cfg); 51 36 52 37 /* Map worker threads to service arbiters */ 53 38 hw_data->get_arb_mapping(accel_dev, &thd_2_arb_cfg); ··· 41 56 return -EFAULT; 42 57 43 58 for (i = 0; i < hw_data->num_engines; i++) 44 - WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, *(thd_2_arb_cfg + i)); 59 + WRITE_CSR_ARB_WT2SAM(csr, arb_off, wt_off, i, thd_2_arb_cfg[i]); 45 60 46 61 return 0; 47 62 } ··· 49 64 50 65 void adf_update_ring_arb(struct adf_etr_ring_data *ring) 51 66 { 52 - WRITE_CSR_ARB_RINGSRVARBEN(ring->bank->csr_addr, 53 - ring->bank->bank_number, 54 - ring->bank->ring_mask & 0xFF); 67 + struct adf_accel_dev *accel_dev = ring->bank->accel_dev; 68 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 69 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(accel_dev); 70 + u32 tx_ring_mask = hw_data->tx_rings_mask; 71 + u32 shift = hw_data->tx_rx_gap; 72 + u32 arben, arben_tx, arben_rx; 73 + u32 rx_ring_mask; 74 + 75 + /* 76 + * Enable arbitration on a ring only if the TX half of the ring mask 77 + * matches the RX part. This results in writes to CSR on both TX and 78 + * RX update - only one is necessary, but both are done for 79 + * simplicity. 80 + */ 81 + rx_ring_mask = tx_ring_mask << shift; 82 + arben_tx = (ring->bank->ring_mask & tx_ring_mask) >> 0; 83 + arben_rx = (ring->bank->ring_mask & rx_ring_mask) >> shift; 84 + arben = arben_tx & arben_rx; 85 + 86 + csr_ops->write_csr_ring_srv_arb_en(ring->bank->csr_addr, 87 + ring->bank->bank_number, arben); 55 88 } 56 89 57 90 void adf_exit_arb(struct adf_accel_dev *accel_dev) 58 91 { 59 92 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 93 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(accel_dev); 94 + u32 arb_off, wt_off; 95 + struct arb_info info; 60 96 void __iomem *csr; 61 97 unsigned int i; 98 + 99 + hw_data->get_arb_info(&info); 100 + arb_off = info.arb_offset; 101 + wt_off = info.wt2sam_offset; 62 102 63 103 if (!accel_dev->transport) 64 104 return; 65 105 66 106 csr = accel_dev->transport->banks[0].csr_addr; 67 107 108 + hw_data->get_arb_info(&info); 109 + 68 110 /* Reset arbiter configuration */ 69 111 for (i = 0; i < ADF_ARB_NUM; i++) 70 - WRITE_CSR_ARB_SARCONFIG(csr, i, 0); 71 - 72 - /* Shutdown work queue */ 73 - for (i = 0; i < hw_data->num_engines; i++) 74 - WRITE_CSR_ARB_WQCFG(csr, i, 0); 112 + WRITE_CSR_ARB_SARCONFIG(csr, arb_off, i, 0); 75 113 76 114 /* Unmap worker threads to service arbiters */ 77 115 for (i = 0; i < hw_data->num_engines; i++) 78 - WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, 0); 116 + WRITE_CSR_ARB_WT2SAM(csr, arb_off, wt_off, i, 0); 79 117 80 118 /* Disable arbitration on all rings */ 81 119 for (i = 0; i < GET_MAX_BANKS(accel_dev); i++) 82 - WRITE_CSR_ARB_RINGSRVARBEN(csr, i, 0); 120 + csr_ops->write_csr_ring_srv_arb_en(csr, i, 0); 83 121 } 84 122 EXPORT_SYMBOL_GPL(adf_exit_arb);
+6 -1
drivers/crypto/qat/qat_common/adf_isr.c
··· 21 21 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 22 22 u32 msix_num_entries = 1; 23 23 24 + if (hw_data->set_msix_rttable) 25 + hw_data->set_msix_rttable(accel_dev); 26 + 24 27 /* If SR-IOV is disabled, add entries for each bank */ 25 28 if (!accel_dev->pf.vf_info) { 26 29 int i; ··· 53 50 static irqreturn_t adf_msix_isr_bundle(int irq, void *bank_ptr) 54 51 { 55 52 struct adf_etr_bank_data *bank = bank_ptr; 53 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 56 54 57 - WRITE_CSR_INT_FLAG_AND_COL(bank->csr_addr, bank->bank_number, 0); 55 + csr_ops->write_csr_int_flag_and_col(bank->csr_addr, bank->bank_number, 56 + 0); 58 57 tasklet_hi_schedule(&bank->resp_handler); 59 58 return IRQ_HANDLED; 60 59 }
+14 -64
drivers/crypto/qat/qat_common/adf_sriov.c
··· 10 10 11 11 static struct workqueue_struct *pf2vf_resp_wq; 12 12 13 - #define ME2FUNCTION_MAP_A_OFFSET (0x3A400 + 0x190) 14 - #define ME2FUNCTION_MAP_A_NUM_REGS 96 15 - 16 - #define ME2FUNCTION_MAP_B_OFFSET (0x3A400 + 0x310) 17 - #define ME2FUNCTION_MAP_B_NUM_REGS 12 18 - 19 - #define ME2FUNCTION_MAP_REG_SIZE 4 20 - #define ME2FUNCTION_MAP_VALID BIT(7) 21 - 22 - #define READ_CSR_ME2FUNCTION_MAP_A(pmisc_bar_addr, index) \ 23 - ADF_CSR_RD(pmisc_bar_addr, ME2FUNCTION_MAP_A_OFFSET + \ 24 - ME2FUNCTION_MAP_REG_SIZE * index) 25 - 26 - #define WRITE_CSR_ME2FUNCTION_MAP_A(pmisc_bar_addr, index, value) \ 27 - ADF_CSR_WR(pmisc_bar_addr, ME2FUNCTION_MAP_A_OFFSET + \ 28 - ME2FUNCTION_MAP_REG_SIZE * index, value) 29 - 30 - #define READ_CSR_ME2FUNCTION_MAP_B(pmisc_bar_addr, index) \ 31 - ADF_CSR_RD(pmisc_bar_addr, ME2FUNCTION_MAP_B_OFFSET + \ 32 - ME2FUNCTION_MAP_REG_SIZE * index) 33 - 34 - #define WRITE_CSR_ME2FUNCTION_MAP_B(pmisc_bar_addr, index, value) \ 35 - ADF_CSR_WR(pmisc_bar_addr, ME2FUNCTION_MAP_B_OFFSET + \ 36 - ME2FUNCTION_MAP_REG_SIZE * index, value) 37 - 38 13 struct adf_pf2vf_resp { 39 14 struct work_struct pf2vf_resp_work; 40 15 struct adf_accel_vf_info *vf_info; ··· 43 68 struct pci_dev *pdev = accel_to_pci_dev(accel_dev); 44 69 int totalvfs = pci_sriov_get_totalvfs(pdev); 45 70 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 46 - struct adf_bar *pmisc = 47 - &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 48 - void __iomem *pmisc_addr = pmisc->virt_addr; 49 71 struct adf_accel_vf_info *vf_info; 50 72 int i; 51 - u32 reg; 52 73 53 74 for (i = 0, vf_info = accel_dev->pf.vf_info; i < totalvfs; 54 75 i++, vf_info++) { ··· 61 90 DEFAULT_RATELIMIT_BURST); 62 91 } 63 92 64 - /* Set Valid bits in ME Thread to PCIe Function Mapping Group A */ 65 - for (i = 0; i < ME2FUNCTION_MAP_A_NUM_REGS; i++) { 66 - reg = READ_CSR_ME2FUNCTION_MAP_A(pmisc_addr, i); 67 - reg |= ME2FUNCTION_MAP_VALID; 68 - WRITE_CSR_ME2FUNCTION_MAP_A(pmisc_addr, i, reg); 69 - } 70 - 71 - /* Set Valid bits in ME Thread to PCIe Function Mapping Group B */ 72 - for (i = 0; i < ME2FUNCTION_MAP_B_NUM_REGS; i++) { 73 - reg = READ_CSR_ME2FUNCTION_MAP_B(pmisc_addr, i); 74 - reg |= ME2FUNCTION_MAP_VALID; 75 - WRITE_CSR_ME2FUNCTION_MAP_B(pmisc_addr, i, reg); 76 - } 93 + /* Set Valid bits in AE Thread to PCIe Function Mapping */ 94 + if (hw_data->configure_iov_threads) 95 + hw_data->configure_iov_threads(accel_dev, true); 77 96 78 97 /* Enable VF to PF interrupts for all VFs */ 79 - adf_enable_vf2pf_interrupts(accel_dev, GENMASK_ULL(totalvfs - 1, 0)); 98 + if (hw_data->get_pf2vf_offset) 99 + adf_enable_vf2pf_interrupts(accel_dev, BIT_ULL(totalvfs) - 1); 80 100 81 101 /* 82 102 * Due to the hardware design, when SR-IOV and the ring arbiter ··· 89 127 void adf_disable_sriov(struct adf_accel_dev *accel_dev) 90 128 { 91 129 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 92 - struct adf_bar *pmisc = 93 - &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 94 - void __iomem *pmisc_addr = pmisc->virt_addr; 95 130 int totalvfs = pci_sriov_get_totalvfs(accel_to_pci_dev(accel_dev)); 96 131 struct adf_accel_vf_info *vf; 97 - u32 reg; 98 132 int i; 99 133 100 134 if (!accel_dev->pf.vf_info) 101 135 return; 102 136 103 - adf_pf2vf_notify_restarting(accel_dev); 137 + if (hw_data->get_pf2vf_offset) 138 + adf_pf2vf_notify_restarting(accel_dev); 104 139 105 140 pci_disable_sriov(accel_to_pci_dev(accel_dev)); 106 141 107 142 /* Disable VF to PF interrupts */ 108 - adf_disable_vf2pf_interrupts(accel_dev, 0xFFFFFFFF); 143 + if (hw_data->get_pf2vf_offset) 144 + adf_disable_vf2pf_interrupts(accel_dev, GENMASK(31, 0)); 109 145 110 - /* Clear Valid bits in ME Thread to PCIe Function Mapping Group A */ 111 - for (i = 0; i < ME2FUNCTION_MAP_A_NUM_REGS; i++) { 112 - reg = READ_CSR_ME2FUNCTION_MAP_A(pmisc_addr, i); 113 - reg &= ~ME2FUNCTION_MAP_VALID; 114 - WRITE_CSR_ME2FUNCTION_MAP_A(pmisc_addr, i, reg); 115 - } 116 - 117 - /* Clear Valid bits in ME Thread to PCIe Function Mapping Group B */ 118 - for (i = 0; i < ME2FUNCTION_MAP_B_NUM_REGS; i++) { 119 - reg = READ_CSR_ME2FUNCTION_MAP_B(pmisc_addr, i); 120 - reg &= ~ME2FUNCTION_MAP_VALID; 121 - WRITE_CSR_ME2FUNCTION_MAP_B(pmisc_addr, i, reg); 122 - } 146 + /* Clear Valid bits in AE Thread to PCIe Function Mapping */ 147 + if (hw_data->configure_iov_threads) 148 + hw_data->configure_iov_threads(accel_dev, false); 123 149 124 150 for (i = 0, vf = accel_dev->pf.vf_info; i < totalvfs; i++, vf++) { 125 151 tasklet_disable(&vf->vf2pf_bh_tasklet); ··· 122 172 123 173 /** 124 174 * adf_sriov_configure() - Enable SRIOV for the device 125 - * @pdev: Pointer to pci device. 175 + * @pdev: Pointer to PCI device. 126 176 * @numvfs: Number of virtual functions (VFs) to enable. 127 177 * 128 178 * Note that the @numvfs parameter is ignored and all VFs supported by the 129 179 * device are enabled due to the design of the hardware. 130 180 * 131 - * Function enables SRIOV for the pci device. 181 + * Function enables SRIOV for the PCI device. 132 182 * 133 183 * Return: number of VFs enabled on success, error code otherwise. 134 184 */
+89 -41
drivers/crypto/qat/qat_common/adf_transport.c
··· 54 54 55 55 static void adf_enable_ring_irq(struct adf_etr_bank_data *bank, u32 ring) 56 56 { 57 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 58 + 57 59 spin_lock_bh(&bank->lock); 58 60 bank->irq_mask |= (1 << ring); 59 61 spin_unlock_bh(&bank->lock); 60 - WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask); 61 - WRITE_CSR_INT_COL_CTL(bank->csr_addr, bank->bank_number, 62 - bank->irq_coalesc_timer); 62 + csr_ops->write_csr_int_col_en(bank->csr_addr, bank->bank_number, 63 + bank->irq_mask); 64 + csr_ops->write_csr_int_col_ctl(bank->csr_addr, bank->bank_number, 65 + bank->irq_coalesc_timer); 63 66 } 64 67 65 68 static void adf_disable_ring_irq(struct adf_etr_bank_data *bank, u32 ring) 66 69 { 70 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 71 + 67 72 spin_lock_bh(&bank->lock); 68 73 bank->irq_mask &= ~(1 << ring); 69 74 spin_unlock_bh(&bank->lock); 70 - WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask); 75 + csr_ops->write_csr_int_col_en(bank->csr_addr, bank->bank_number, 76 + bank->irq_mask); 71 77 } 72 78 73 79 int adf_send_message(struct adf_etr_ring_data *ring, u32 *msg) 74 80 { 81 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(ring->bank->accel_dev); 82 + 75 83 if (atomic_add_return(1, ring->inflights) > 76 84 ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size)) { 77 85 atomic_dec(ring->inflights); ··· 92 84 ring->tail = adf_modulo(ring->tail + 93 85 ADF_MSG_SIZE_TO_BYTES(ring->msg_size), 94 86 ADF_RING_SIZE_MODULO(ring->ring_size)); 95 - WRITE_CSR_RING_TAIL(ring->bank->csr_addr, ring->bank->bank_number, 96 - ring->ring_number, ring->tail); 87 + csr_ops->write_csr_ring_tail(ring->bank->csr_addr, 88 + ring->bank->bank_number, ring->ring_number, 89 + ring->tail); 97 90 spin_unlock_bh(&ring->lock); 91 + 98 92 return 0; 99 93 } 100 94 101 95 static int adf_handle_response(struct adf_etr_ring_data *ring) 102 96 { 97 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(ring->bank->accel_dev); 103 98 u32 msg_counter = 0; 104 99 u32 *msg = (u32 *)((uintptr_t)ring->base_addr + ring->head); 105 100 ··· 116 105 msg_counter++; 117 106 msg = (u32 *)((uintptr_t)ring->base_addr + ring->head); 118 107 } 119 - if (msg_counter > 0) 120 - WRITE_CSR_RING_HEAD(ring->bank->csr_addr, 121 - ring->bank->bank_number, 122 - ring->ring_number, ring->head); 108 + if (msg_counter > 0) { 109 + csr_ops->write_csr_ring_head(ring->bank->csr_addr, 110 + ring->bank->bank_number, 111 + ring->ring_number, ring->head); 112 + } 123 113 return 0; 124 114 } 125 115 126 116 static void adf_configure_tx_ring(struct adf_etr_ring_data *ring) 127 117 { 118 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(ring->bank->accel_dev); 128 119 u32 ring_config = BUILD_RING_CONFIG(ring->ring_size); 129 120 130 - WRITE_CSR_RING_CONFIG(ring->bank->csr_addr, ring->bank->bank_number, 131 - ring->ring_number, ring_config); 121 + csr_ops->write_csr_ring_config(ring->bank->csr_addr, 122 + ring->bank->bank_number, 123 + ring->ring_number, ring_config); 124 + 132 125 } 133 126 134 127 static void adf_configure_rx_ring(struct adf_etr_ring_data *ring) 135 128 { 129 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(ring->bank->accel_dev); 136 130 u32 ring_config = 137 131 BUILD_RESP_RING_CONFIG(ring->ring_size, 138 132 ADF_RING_NEAR_WATERMARK_512, 139 133 ADF_RING_NEAR_WATERMARK_0); 140 134 141 - WRITE_CSR_RING_CONFIG(ring->bank->csr_addr, ring->bank->bank_number, 142 - ring->ring_number, ring_config); 135 + csr_ops->write_csr_ring_config(ring->bank->csr_addr, 136 + ring->bank->bank_number, 137 + ring->ring_number, ring_config); 143 138 } 144 139 145 140 static int adf_init_ring(struct adf_etr_ring_data *ring) ··· 153 136 struct adf_etr_bank_data *bank = ring->bank; 154 137 struct adf_accel_dev *accel_dev = bank->accel_dev; 155 138 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 139 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(accel_dev); 156 140 u64 ring_base; 157 141 u32 ring_size_bytes = 158 142 ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size); ··· 180 162 else 181 163 adf_configure_rx_ring(ring); 182 164 183 - ring_base = BUILD_RING_BASE_ADDR(ring->dma_addr, ring->ring_size); 184 - WRITE_CSR_RING_BASE(ring->bank->csr_addr, ring->bank->bank_number, 185 - ring->ring_number, ring_base); 165 + ring_base = csr_ops->build_csr_ring_base_addr(ring->dma_addr, 166 + ring->ring_size); 167 + 168 + csr_ops->write_csr_ring_base(ring->bank->csr_addr, 169 + ring->bank->bank_number, ring->ring_number, 170 + ring_base); 186 171 spin_lock_init(&ring->lock); 187 172 return 0; 188 173 } ··· 211 190 struct adf_etr_ring_data **ring_ptr) 212 191 { 213 192 struct adf_etr_data *transport_data = accel_dev->transport; 193 + u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(accel_dev); 214 194 struct adf_etr_bank_data *bank; 215 195 struct adf_etr_ring_data *ring; 216 196 char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; ··· 241 219 dev_err(&GET_DEV(accel_dev), "Can't get ring number\n"); 242 220 return -EFAULT; 243 221 } 244 - if (ring_num >= ADF_ETR_MAX_RINGS_PER_BANK) { 222 + if (ring_num >= num_rings_per_bank) { 245 223 dev_err(&GET_DEV(accel_dev), "Invalid ring number\n"); 246 224 return -EFAULT; 247 225 } ··· 290 268 void adf_remove_ring(struct adf_etr_ring_data *ring) 291 269 { 292 270 struct adf_etr_bank_data *bank = ring->bank; 271 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 293 272 294 273 /* Disable interrupts for the given ring */ 295 274 adf_disable_ring_irq(bank, ring->ring_number); 296 275 297 276 /* Clear PCI config space */ 298 - WRITE_CSR_RING_CONFIG(bank->csr_addr, bank->bank_number, 299 - ring->ring_number, 0); 300 - WRITE_CSR_RING_BASE(bank->csr_addr, bank->bank_number, 301 - ring->ring_number, 0); 277 + 278 + csr_ops->write_csr_ring_config(bank->csr_addr, bank->bank_number, 279 + ring->ring_number, 0); 280 + csr_ops->write_csr_ring_base(bank->csr_addr, bank->bank_number, 281 + ring->ring_number, 0); 302 282 adf_ring_debugfs_rm(ring); 303 283 adf_unreserve_ring(bank, ring->ring_number); 304 284 /* Disable HW arbitration for the given ring */ ··· 310 286 311 287 static void adf_ring_response_handler(struct adf_etr_bank_data *bank) 312 288 { 313 - u32 empty_rings, i; 289 + struct adf_accel_dev *accel_dev = bank->accel_dev; 290 + u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(accel_dev); 291 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(accel_dev); 292 + unsigned long empty_rings; 293 + int i; 314 294 315 - empty_rings = READ_CSR_E_STAT(bank->csr_addr, bank->bank_number); 295 + empty_rings = csr_ops->read_csr_e_stat(bank->csr_addr, 296 + bank->bank_number); 316 297 empty_rings = ~empty_rings & bank->irq_mask; 317 298 318 - for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; ++i) { 319 - if (empty_rings & (1 << i)) 320 - adf_handle_response(&bank->rings[i]); 321 - } 299 + for_each_set_bit(i, &empty_rings, num_rings_per_bank) 300 + adf_handle_response(&bank->rings[i]); 322 301 } 323 302 324 303 void adf_response_handler(uintptr_t bank_addr) 325 304 { 326 305 struct adf_etr_bank_data *bank = (void *)bank_addr; 306 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 327 307 328 308 /* Handle all the responses and reenable IRQs */ 329 309 adf_ring_response_handler(bank); 330 - WRITE_CSR_INT_FLAG_AND_COL(bank->csr_addr, bank->bank_number, 331 - bank->irq_mask); 310 + 311 + csr_ops->write_csr_int_flag_and_col(bank->csr_addr, bank->bank_number, 312 + bank->irq_mask); 332 313 } 333 314 334 315 static inline int adf_get_cfg_int(struct adf_accel_dev *accel_dev, ··· 372 343 u32 bank_num, void __iomem *csr_addr) 373 344 { 374 345 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 346 + u8 num_rings_per_bank = hw_data->num_rings_per_bank; 347 + struct adf_hw_csr_ops *csr_ops = &hw_data->csr_ops; 348 + u32 irq_mask = BIT(num_rings_per_bank) - 1; 375 349 struct adf_etr_ring_data *ring; 376 350 struct adf_etr_ring_data *tx_ring; 377 351 u32 i, coalesc_enabled = 0; 352 + unsigned long ring_mask; 353 + int size; 378 354 379 355 memset(bank, 0, sizeof(*bank)); 380 356 bank->bank_number = bank_num; 381 357 bank->csr_addr = csr_addr; 382 358 bank->accel_dev = accel_dev; 383 359 spin_lock_init(&bank->lock); 360 + 361 + /* Allocate the rings in the bank */ 362 + size = num_rings_per_bank * sizeof(struct adf_etr_ring_data); 363 + bank->rings = kzalloc_node(size, GFP_KERNEL, 364 + dev_to_node(&GET_DEV(accel_dev))); 365 + if (!bank->rings) 366 + return -ENOMEM; 384 367 385 368 /* Enable IRQ coalescing always. This will allow to use 386 369 * the optimised flag and coalesc register. ··· 404 363 else 405 364 bank->irq_coalesc_timer = ADF_COALESCING_MIN_TIME; 406 365 407 - for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 408 - WRITE_CSR_RING_CONFIG(csr_addr, bank_num, i, 0); 409 - WRITE_CSR_RING_BASE(csr_addr, bank_num, i, 0); 366 + for (i = 0; i < num_rings_per_bank; i++) { 367 + csr_ops->write_csr_ring_config(csr_addr, bank_num, i, 0); 368 + csr_ops->write_csr_ring_base(csr_addr, bank_num, i, 0); 369 + 410 370 ring = &bank->rings[i]; 411 371 if (hw_data->tx_rings_mask & (1 << i)) { 412 372 ring->inflights = ··· 432 390 goto err; 433 391 } 434 392 435 - WRITE_CSR_INT_FLAG(csr_addr, bank_num, ADF_BANK_INT_FLAG_CLEAR_MASK); 436 - WRITE_CSR_INT_SRCSEL(csr_addr, bank_num); 393 + csr_ops->write_csr_int_flag(csr_addr, bank_num, irq_mask); 394 + csr_ops->write_csr_int_srcsel(csr_addr, bank_num); 395 + 437 396 return 0; 438 397 err: 439 - for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 398 + ring_mask = hw_data->tx_rings_mask; 399 + for_each_set_bit(i, &ring_mask, num_rings_per_bank) { 440 400 ring = &bank->rings[i]; 441 - if (hw_data->tx_rings_mask & (1 << i)) 442 - kfree(ring->inflights); 401 + kfree(ring->inflights); 402 + ring->inflights = NULL; 443 403 } 404 + kfree(bank->rings); 444 405 return -ENOMEM; 445 406 } 446 407 ··· 509 464 510 465 static void cleanup_bank(struct adf_etr_bank_data *bank) 511 466 { 467 + struct adf_accel_dev *accel_dev = bank->accel_dev; 468 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 469 + u8 num_rings_per_bank = hw_data->num_rings_per_bank; 512 470 u32 i; 513 471 514 - for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 515 - struct adf_accel_dev *accel_dev = bank->accel_dev; 516 - struct adf_hw_device_data *hw_data = accel_dev->hw_device; 472 + for (i = 0; i < num_rings_per_bank; i++) { 517 473 struct adf_etr_ring_data *ring = &bank->rings[i]; 518 474 519 475 if (bank->ring_mask & (1 << i)) ··· 523 477 if (hw_data->tx_rings_mask & (1 << i)) 524 478 kfree(ring->inflights); 525 479 } 480 + kfree(bank->rings); 526 481 adf_bank_debugfs_rm(bank); 527 482 memset(bank, 0, sizeof(*bank)); 528 483 } ··· 554 507 if (etr_data) { 555 508 adf_cleanup_etr_handles(accel_dev); 556 509 debugfs_remove(etr_data->debug); 510 + kfree(etr_data->banks->rings); 557 511 kfree(etr_data->banks); 558 512 kfree(etr_data); 559 513 accel_dev->transport = NULL;
-67
drivers/crypto/qat/qat_common/adf_transport_access_macros.h
··· 4 4 #define ADF_TRANSPORT_ACCESS_MACROS_H 5 5 6 6 #include "adf_accel_devices.h" 7 - #define ADF_BANK_INT_SRC_SEL_MASK_0 0x4444444CUL 8 - #define ADF_BANK_INT_SRC_SEL_MASK_X 0x44444444UL 9 - #define ADF_BANK_INT_FLAG_CLEAR_MASK 0xFFFF 10 - #define ADF_RING_CSR_RING_CONFIG 0x000 11 - #define ADF_RING_CSR_RING_LBASE 0x040 12 - #define ADF_RING_CSR_RING_UBASE 0x080 13 - #define ADF_RING_CSR_RING_HEAD 0x0C0 14 - #define ADF_RING_CSR_RING_TAIL 0x100 15 - #define ADF_RING_CSR_E_STAT 0x14C 16 - #define ADF_RING_CSR_INT_FLAG 0x170 17 - #define ADF_RING_CSR_INT_SRCSEL 0x174 18 - #define ADF_RING_CSR_INT_SRCSEL_2 0x178 19 - #define ADF_RING_CSR_INT_COL_EN 0x17C 20 - #define ADF_RING_CSR_INT_COL_CTL 0x180 21 - #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184 22 - #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000 23 - #define ADF_RING_BUNDLE_SIZE 0x1000 24 7 #define ADF_RING_CONFIG_NEAR_FULL_WM 0x0A 25 8 #define ADF_RING_CONFIG_NEAR_EMPTY_WM 0x05 26 9 #define ADF_COALESCING_MIN_TIME 0x1FF ··· 55 72 ((watermark_nf << ADF_RING_CONFIG_NEAR_FULL_WM) \ 56 73 | (watermark_ne << ADF_RING_CONFIG_NEAR_EMPTY_WM) \ 57 74 | size) 58 - #define BUILD_RING_BASE_ADDR(addr, size) \ 59 - ((addr >> 6) & (0xFFFFFFFFFFFFFFFFULL << size)) 60 - #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring) \ 61 - ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 62 - ADF_RING_CSR_RING_HEAD + (ring << 2)) 63 - #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring) \ 64 - ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 65 - ADF_RING_CSR_RING_TAIL + (ring << 2)) 66 - #define READ_CSR_E_STAT(csr_base_addr, bank) \ 67 - ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 68 - ADF_RING_CSR_E_STAT) 69 - #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value) \ 70 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 71 - ADF_RING_CSR_RING_CONFIG + (ring << 2), value) 72 - #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value) \ 73 - do { \ 74 - u32 l_base = 0, u_base = 0; \ 75 - l_base = (u32)(value & 0xFFFFFFFF); \ 76 - u_base = (u32)((value & 0xFFFFFFFF00000000ULL) >> 32); \ 77 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 78 - ADF_RING_CSR_RING_LBASE + (ring << 2), l_base); \ 79 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 80 - ADF_RING_CSR_RING_UBASE + (ring << 2), u_base); \ 81 - } while (0) 82 - #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value) \ 83 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 84 - ADF_RING_CSR_RING_HEAD + (ring << 2), value) 85 - #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value) \ 86 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 87 - ADF_RING_CSR_RING_TAIL + (ring << 2), value) 88 - #define WRITE_CSR_INT_FLAG(csr_base_addr, bank, value) \ 89 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * (bank)) + \ 90 - ADF_RING_CSR_INT_FLAG, value) 91 - #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank) \ 92 - do { \ 93 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 94 - ADF_RING_CSR_INT_SRCSEL, ADF_BANK_INT_SRC_SEL_MASK_0); \ 95 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 96 - ADF_RING_CSR_INT_SRCSEL_2, ADF_BANK_INT_SRC_SEL_MASK_X); \ 97 - } while (0) 98 - #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value) \ 99 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 100 - ADF_RING_CSR_INT_COL_EN, value) 101 - #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value) \ 102 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 103 - ADF_RING_CSR_INT_COL_CTL, \ 104 - ADF_RING_CSR_INT_COL_CTL_ENABLE | value) 105 - #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value) \ 106 - ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 107 - ADF_RING_CSR_INT_FLAG_AND_COL, value) 108 75 #endif
+20 -12
drivers/crypto/qat/qat_common/adf_transport_debug.c
··· 42 42 { 43 43 struct adf_etr_ring_data *ring = sfile->private; 44 44 struct adf_etr_bank_data *bank = ring->bank; 45 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 45 46 void __iomem *csr = ring->bank->csr_addr; 46 47 47 48 if (v == SEQ_START_TOKEN) { 48 49 int head, tail, empty; 49 50 50 - head = READ_CSR_RING_HEAD(csr, bank->bank_number, 51 - ring->ring_number); 52 - tail = READ_CSR_RING_TAIL(csr, bank->bank_number, 53 - ring->ring_number); 54 - empty = READ_CSR_E_STAT(csr, bank->bank_number); 51 + head = csr_ops->read_csr_ring_head(csr, bank->bank_number, 52 + ring->ring_number); 53 + tail = csr_ops->read_csr_ring_tail(csr, bank->bank_number, 54 + ring->ring_number); 55 + empty = csr_ops->read_csr_e_stat(csr, bank->bank_number); 55 56 56 57 seq_puts(sfile, "------- Ring configuration -------\n"); 57 58 seq_printf(sfile, "ring name: %s\n", ··· 118 117 119 118 static void *adf_bank_start(struct seq_file *sfile, loff_t *pos) 120 119 { 120 + struct adf_etr_bank_data *bank = sfile->private; 121 + u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(bank->accel_dev); 122 + 121 123 mutex_lock(&bank_read_lock); 122 124 if (*pos == 0) 123 125 return SEQ_START_TOKEN; 124 126 125 - if (*pos >= ADF_ETR_MAX_RINGS_PER_BANK) 127 + if (*pos >= num_rings_per_bank) 126 128 return NULL; 127 129 128 130 return pos; ··· 133 129 134 130 static void *adf_bank_next(struct seq_file *sfile, void *v, loff_t *pos) 135 131 { 136 - if (++(*pos) >= ADF_ETR_MAX_RINGS_PER_BANK) 132 + struct adf_etr_bank_data *bank = sfile->private; 133 + u8 num_rings_per_bank = GET_NUM_RINGS_PER_BANK(bank->accel_dev); 134 + 135 + if (++(*pos) >= num_rings_per_bank) 137 136 return NULL; 138 137 139 138 return pos; ··· 145 138 static int adf_bank_show(struct seq_file *sfile, void *v) 146 139 { 147 140 struct adf_etr_bank_data *bank = sfile->private; 141 + struct adf_hw_csr_ops *csr_ops = GET_CSR_OPS(bank->accel_dev); 148 142 149 143 if (v == SEQ_START_TOKEN) { 150 144 seq_printf(sfile, "------- Bank %d configuration -------\n", ··· 159 151 if (!(bank->ring_mask & 1 << ring_id)) 160 152 return 0; 161 153 162 - head = READ_CSR_RING_HEAD(csr, bank->bank_number, 163 - ring->ring_number); 164 - tail = READ_CSR_RING_TAIL(csr, bank->bank_number, 165 - ring->ring_number); 166 - empty = READ_CSR_E_STAT(csr, bank->bank_number); 154 + head = csr_ops->read_csr_ring_head(csr, bank->bank_number, 155 + ring->ring_number); 156 + tail = csr_ops->read_csr_ring_tail(csr, bank->bank_number, 157 + ring->ring_number); 158 + empty = csr_ops->read_csr_e_stat(csr, bank->bank_number); 167 159 168 160 seq_printf(sfile, 169 161 "ring num %02d, head %04x, tail %04x, empty: %d\n",
+1 -1
drivers/crypto/qat/qat_common/adf_transport_internal.h
··· 28 28 }; 29 29 30 30 struct adf_etr_bank_data { 31 - struct adf_etr_ring_data rings[ADF_ETR_MAX_RINGS_PER_BANK]; 31 + struct adf_etr_ring_data *rings; 32 32 struct tasklet_struct resp_handler; 33 33 void __iomem *csr_addr; 34 34 u32 irq_coalesc_timer;
+3 -2
drivers/crypto/qat/qat_common/adf_vf_isr.c
··· 156 156 { 157 157 struct adf_accel_dev *accel_dev = privdata; 158 158 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 159 + struct adf_hw_csr_ops *csr_ops = &hw_data->csr_ops; 159 160 struct adf_bar *pmisc = 160 161 &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 161 162 void __iomem *pmisc_bar_addr = pmisc->virt_addr; ··· 181 180 struct adf_etr_bank_data *bank = &etr_data->banks[0]; 182 181 183 182 /* Disable Flag and Coalesce Ring Interrupts */ 184 - WRITE_CSR_INT_FLAG_AND_COL(bank->csr_addr, bank->bank_number, 185 - 0); 183 + csr_ops->write_csr_int_flag_and_col(bank->csr_addr, 184 + bank->bank_number, 0); 186 185 tasklet_hi_schedule(&bank->resp_handler); 187 186 return IRQ_HANDLED; 188 187 }
+3 -3
drivers/crypto/qat/qat_common/icp_qat_fw_init_admin.h
··· 6 6 #include "icp_qat_fw.h" 7 7 8 8 enum icp_qat_fw_init_admin_cmd_id { 9 - ICP_QAT_FW_INIT_ME = 0, 9 + ICP_QAT_FW_INIT_AE = 0, 10 10 ICP_QAT_FW_TRNG_ENABLE = 1, 11 11 ICP_QAT_FW_TRNG_DISABLE = 2, 12 12 ICP_QAT_FW_CONSTANTS_CFG = 3, ··· 39 39 }; 40 40 41 41 __u32 resrvd4; 42 - }; 42 + } __packed; 43 43 44 44 struct icp_qat_fw_init_admin_resp { 45 45 __u8 flags; ··· 92 92 __u64 resrvd8; 93 93 }; 94 94 }; 95 - }; 95 + } __packed; 96 96 97 97 #define ICP_QAT_FW_COMN_HEARTBEAT_OK 0 98 98 #define ICP_QAT_FW_COMN_HEARTBEAT_BLOCKED 1
+7
drivers/crypto/qat/qat_common/icp_qat_fw_la.h
··· 33 33 struct icp_qat_fw_comn_req_cd_ctrl cd_ctrl; 34 34 }; 35 35 36 + #define ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE 1 37 + #define QAT_LA_SLICE_TYPE_BITPOS 14 38 + #define QAT_LA_SLICE_TYPE_MASK 0x3 36 39 #define ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS 1 37 40 #define ICP_QAT_FW_LA_GCM_IV_LEN_NOT_12_OCTETS 0 38 41 #define QAT_FW_LA_ZUC_3G_PROTO_FLAG_BITPOS 12 ··· 181 178 #define ICP_QAT_FW_LA_PARTIAL_SET(flags, val) \ 182 179 QAT_FIELD_SET(flags, val, QAT_LA_PARTIAL_BITPOS, \ 183 180 QAT_LA_PARTIAL_MASK) 181 + 182 + #define ICP_QAT_FW_LA_SLICE_TYPE_SET(flags, val) \ 183 + QAT_FIELD_SET(flags, val, QAT_LA_SLICE_TYPE_BITPOS, \ 184 + QAT_LA_SLICE_TYPE_MASK) 184 185 185 186 struct icp_qat_fw_cipher_req_hdr_cd_pars { 186 187 union {
+25 -1
drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h
··· 15 15 struct icp_qat_fw_loader_hal_handle { 16 16 struct icp_qat_fw_loader_ae_data aes[ICP_QAT_UCLO_MAX_AE]; 17 17 unsigned int ae_mask; 18 + unsigned int admin_ae_mask; 18 19 unsigned int slice_mask; 19 20 unsigned int revision_id; 20 21 unsigned int ae_max_num; ··· 23 22 unsigned int max_ustore; 24 23 }; 25 24 25 + struct icp_qat_fw_loader_chip_info { 26 + bool sram_visible; 27 + bool nn; 28 + bool lm2lm3; 29 + u32 lm_size; 30 + u32 icp_rst_csr; 31 + u32 icp_rst_mask; 32 + u32 glb_clk_enable_csr; 33 + u32 misc_ctl_csr; 34 + u32 wakeup_event_val; 35 + bool fw_auth; 36 + bool css_3k; 37 + bool tgroup_share_ustore; 38 + u32 fcu_ctl_csr; 39 + u32 fcu_sts_csr; 40 + u32 fcu_dram_addr_hi; 41 + u32 fcu_dram_addr_lo; 42 + u32 fcu_loaded_ae_csr; 43 + u8 fcu_loaded_ae_pos; 44 + }; 45 + 26 46 struct icp_qat_fw_loader_handle { 27 47 struct icp_qat_fw_loader_hal_handle *hal_handle; 48 + struct icp_qat_fw_loader_chip_info *chip_info; 28 49 struct pci_dev *pci_dev; 29 50 void *obj_handle; 30 51 void *sobj_handle; 31 - bool fw_auth; 52 + void *mobj_handle; 53 + unsigned int cfg_ae_mask; 32 54 void __iomem *hal_sram_addr_v; 33 55 void __iomem *hal_cap_g_ctl_csr_addr_v; 34 56 void __iomem *hal_cap_ae_xfer_csr_addr_v;
+47 -16
drivers/crypto/qat/qat_common/icp_qat_hal.h
··· 5 5 #include "icp_qat_fw_loader_handle.h" 6 6 7 7 enum hal_global_csr { 8 - MISC_CONTROL = 0x04, 9 - ICP_RESET = 0x0c, 10 - ICP_GLOBAL_CLK_ENABLE = 0x50 8 + MISC_CONTROL = 0xA04, 9 + ICP_RESET = 0xA0c, 10 + ICP_GLOBAL_CLK_ENABLE = 0xA50 11 + }; 12 + 13 + enum { 14 + MISC_CONTROL_C4XXX = 0xAA0, 15 + ICP_RESET_CPP0 = 0x938, 16 + ICP_RESET_CPP1 = 0x93c, 17 + ICP_GLOBAL_CLK_ENABLE_CPP0 = 0x964, 18 + ICP_GLOBAL_CLK_ENABLE_CPP1 = 0x968 11 19 }; 12 20 13 21 enum hal_ae_csr { ··· 34 26 CTX_WAKEUP_EVENTS_INDIRECT = 0x050, 35 27 LM_ADDR_0_INDIRECT = 0x060, 36 28 LM_ADDR_1_INDIRECT = 0x068, 29 + LM_ADDR_2_INDIRECT = 0x0cc, 30 + LM_ADDR_3_INDIRECT = 0x0d4, 37 31 INDIRECT_LM_ADDR_0_BYTE_INDEX = 0x0e0, 38 32 INDIRECT_LM_ADDR_1_BYTE_INDEX = 0x0e8, 33 + INDIRECT_LM_ADDR_2_BYTE_INDEX = 0x10c, 34 + INDIRECT_LM_ADDR_3_BYTE_INDEX = 0x114, 35 + INDIRECT_T_INDEX = 0x0f8, 36 + INDIRECT_T_INDEX_BYTE_INDEX = 0x0fc, 39 37 FUTURE_COUNT_SIGNAL_INDIRECT = 0x078, 40 38 TIMESTAMP_LOW = 0x0c0, 41 39 TIMESTAMP_HIGH = 0x0c4, ··· 61 47 FCU_RAMBASE_ADDR_LO = 0x8d8 62 48 }; 63 49 50 + enum fcu_csr_4xxx { 51 + FCU_CONTROL_4XXX = 0x1000, 52 + FCU_STATUS_4XXX = 0x1004, 53 + FCU_ME_BROADCAST_MASK_TYPE = 0x1008, 54 + FCU_AE_LOADED_4XXX = 0x1010, 55 + FCU_DRAM_ADDR_LO_4XXX = 0x1014, 56 + FCU_DRAM_ADDR_HI_4XXX = 0x1018, 57 + }; 58 + 64 59 enum fcu_cmd { 65 60 FCU_CTRL_CMD_NOOP = 0, 66 61 FCU_CTRL_CMD_AUTH = 1, ··· 85 62 FCU_STS_LOAD_FAIL = 4, 86 63 FCU_STS_BUSY = 5 87 64 }; 65 + 66 + #define ALL_AE_MASK 0xFFFFFFFF 88 67 #define UA_ECS (0x1 << 31) 89 68 #define ACS_ABO_BITPOS 31 90 69 #define ACS_ACNO 0x7 91 70 #define CE_ENABLE_BITPOS 0x8 92 71 #define CE_LMADDR_0_GLOBAL_BITPOS 16 93 72 #define CE_LMADDR_1_GLOBAL_BITPOS 17 73 + #define CE_LMADDR_2_GLOBAL_BITPOS 22 74 + #define CE_LMADDR_3_GLOBAL_BITPOS 23 75 + #define CE_T_INDEX_GLOBAL_BITPOS 21 94 76 #define CE_NN_MODE_BITPOS 20 95 77 #define CE_REG_PAR_ERR_BITPOS 25 96 78 #define CE_BREAKPOINT_BITPOS 27 ··· 106 78 #define XCWE_VOLUNTARY (0x1) 107 79 #define LCS_STATUS (0x1) 108 80 #define MMC_SHARE_CS_BITPOS 2 109 - #define GLOBAL_CSR 0xA00 81 + #define WAKEUP_EVENT 0x10000 82 + #define FCU_CTRL_BROADCAST_POS 0x4 110 83 #define FCU_CTRL_AE_POS 0x8 111 84 #define FCU_AUTH_STS_MASK 0x7 112 85 #define FCU_STS_DONE_POS 0x9 ··· 115 86 #define FCU_LOADED_AE_POS 0x16 116 87 #define FW_AUTH_WAIT_PERIOD 10 117 88 #define FW_AUTH_MAX_RETRY 300 118 - 89 + #define ICP_QAT_AE_OFFSET 0x20000 90 + #define ICP_QAT_CAP_OFFSET (ICP_QAT_AE_OFFSET + 0x10000) 91 + #define LOCAL_TO_XFER_REG_OFFSET 0x800 92 + #define ICP_QAT_EP_OFFSET 0x3a000 93 + #define ICP_QAT_EP_OFFSET_4XXX 0x200000 /* HI MMIO CSRs */ 94 + #define ICP_QAT_AE_OFFSET_4XXX 0x600000 95 + #define ICP_QAT_CAP_OFFSET_4XXX 0x640000 119 96 #define SET_CAP_CSR(handle, csr, val) \ 120 - ADF_CSR_WR(handle->hal_cap_g_ctl_csr_addr_v, csr, val) 97 + ADF_CSR_WR((handle)->hal_cap_g_ctl_csr_addr_v, csr, val) 121 98 #define GET_CAP_CSR(handle, csr) \ 122 - ADF_CSR_RD(handle->hal_cap_g_ctl_csr_addr_v, csr) 123 - #define SET_GLB_CSR(handle, csr, val) SET_CAP_CSR(handle, csr + GLOBAL_CSR, val) 124 - #define GET_GLB_CSR(handle, csr) GET_CAP_CSR(handle, GLOBAL_CSR + csr) 99 + ADF_CSR_RD((handle)->hal_cap_g_ctl_csr_addr_v, csr) 125 100 #define AE_CSR(handle, ae) \ 126 - ((char __iomem *)handle->hal_cap_ae_local_csr_addr_v + \ 127 - ((ae & handle->hal_handle->ae_mask) << 12)) 128 - #define AE_CSR_ADDR(handle, ae, csr) (AE_CSR(handle, ae) + (0x3ff & csr)) 101 + ((char __iomem *)(handle)->hal_cap_ae_local_csr_addr_v + ((ae) << 12)) 102 + #define AE_CSR_ADDR(handle, ae, csr) (AE_CSR(handle, ae) + (0x3ff & (csr))) 129 103 #define SET_AE_CSR(handle, ae, csr, val) \ 130 104 ADF_CSR_WR(AE_CSR_ADDR(handle, ae, csr), 0, val) 131 105 #define GET_AE_CSR(handle, ae, csr) ADF_CSR_RD(AE_CSR_ADDR(handle, ae, csr), 0) 132 106 #define AE_XFER(handle, ae) \ 133 - ((char __iomem *)handle->hal_cap_ae_xfer_csr_addr_v + \ 134 - ((ae & handle->hal_handle->ae_mask) << 12)) 107 + ((char __iomem *)(handle)->hal_cap_ae_xfer_csr_addr_v + ((ae) << 12)) 135 108 #define AE_XFER_ADDR(handle, ae, reg) (AE_XFER(handle, ae) + \ 136 - ((reg & 0xff) << 2)) 109 + (((reg) & 0xff) << 2)) 137 110 #define SET_AE_XFER(handle, ae, reg, val) \ 138 111 ADF_CSR_WR(AE_XFER_ADDR(handle, ae, reg), 0, val) 139 112 #define SRAM_WRITE(handle, addr, val) \ 140 - ADF_CSR_WR(handle->hal_sram_addr_v, addr, val) 113 + ADF_CSR_WR((handle)->hal_sram_addr_v, addr, val) 141 114 #endif
+39 -1
drivers/crypto/qat/qat_common/icp_qat_hw.h
··· 65 65 __u32 reserved; 66 66 }; 67 67 68 + struct icp_qat_hw_ucs_cipher_config { 69 + __u32 val; 70 + __u32 reserved[3]; 71 + }; 72 + 73 + enum icp_qat_slice_mask { 74 + ICP_ACCEL_MASK_CIPHER_SLICE = BIT(0), 75 + ICP_ACCEL_MASK_AUTH_SLICE = BIT(1), 76 + ICP_ACCEL_MASK_PKE_SLICE = BIT(2), 77 + ICP_ACCEL_MASK_COMPRESS_SLICE = BIT(3), 78 + ICP_ACCEL_MASK_LZS_SLICE = BIT(4), 79 + ICP_ACCEL_MASK_EIA3_SLICE = BIT(5), 80 + ICP_ACCEL_MASK_SHA3_SLICE = BIT(6), 81 + }; 82 + 83 + enum icp_qat_capabilities_mask { 84 + ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC = BIT(0), 85 + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC = BIT(1), 86 + ICP_ACCEL_CAPABILITIES_CIPHER = BIT(2), 87 + ICP_ACCEL_CAPABILITIES_AUTHENTICATION = BIT(3), 88 + ICP_ACCEL_CAPABILITIES_RESERVED_1 = BIT(4), 89 + ICP_ACCEL_CAPABILITIES_COMPRESSION = BIT(5), 90 + ICP_ACCEL_CAPABILITIES_LZS_COMPRESSION = BIT(6), 91 + ICP_ACCEL_CAPABILITIES_RAND = BIT(7), 92 + ICP_ACCEL_CAPABILITIES_ZUC = BIT(8), 93 + ICP_ACCEL_CAPABILITIES_SHA3 = BIT(9), 94 + /* Bits 10-25 are currently reserved */ 95 + ICP_ACCEL_CAPABILITIES_AES_V2 = BIT(26) 96 + }; 97 + 68 98 #define QAT_AUTH_MODE_BITPOS 4 69 99 #define QAT_AUTH_MODE_MASK 0xF 70 100 #define QAT_AUTH_ALGO_BITPOS 0 ··· 285 255 __u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ]; 286 256 }; 287 257 258 + struct icp_qat_hw_ucs_cipher_aes256_f8 { 259 + struct icp_qat_hw_ucs_cipher_config cipher_config; 260 + __u8 key[ICP_QAT_HW_AES_256_F8_KEY_SZ]; 261 + }; 262 + 288 263 struct icp_qat_hw_cipher_algo_blk { 289 - struct icp_qat_hw_cipher_aes256_f8 aes; 264 + union { 265 + struct icp_qat_hw_cipher_aes256_f8 aes; 266 + struct icp_qat_hw_ucs_cipher_aes256_f8 ucs_aes; 267 + }; 290 268 } __aligned(64); 291 269 #endif
+116 -16
drivers/crypto/qat/qat_common/icp_qat_uclo.h
··· 6 6 #define ICP_QAT_AC_895XCC_DEV_TYPE 0x00400000 7 7 #define ICP_QAT_AC_C62X_DEV_TYPE 0x01000000 8 8 #define ICP_QAT_AC_C3XXX_DEV_TYPE 0x02000000 9 + #define ICP_QAT_AC_4XXX_A_DEV_TYPE 0x08000000 9 10 #define ICP_QAT_UCLO_MAX_AE 12 10 11 #define ICP_QAT_UCLO_MAX_CTX 8 11 12 #define ICP_QAT_UCLO_MAX_UIMAGE (ICP_QAT_UCLO_MAX_AE * ICP_QAT_UCLO_MAX_CTX) ··· 14 13 #define ICP_QAT_UCLO_MAX_XFER_REG 128 15 14 #define ICP_QAT_UCLO_MAX_GPR_REG 128 16 15 #define ICP_QAT_UCLO_MAX_LMEM_REG 1024 16 + #define ICP_QAT_UCLO_MAX_LMEM_REG_2X 1280 17 17 #define ICP_QAT_UCLO_AE_ALL_CTX 0xff 18 18 #define ICP_QAT_UOF_OBJID_LEN 8 19 19 #define ICP_QAT_UOF_FID 0xc6c2 ··· 33 31 #define ICP_QAT_SUOF_FID 0x53554f46 34 32 #define ICP_QAT_SUOF_MAJVER 0x0 35 33 #define ICP_QAT_SUOF_MINVER 0x1 34 + #define ICP_QAT_SUOF_OBJ_NAME_LEN 128 35 + #define ICP_QAT_MOF_OBJ_ID_LEN 8 36 + #define ICP_QAT_MOF_OBJ_CHUNKID_LEN 8 37 + #define ICP_QAT_MOF_FID 0x00666f6d 38 + #define ICP_QAT_MOF_MAJVER 0x0 39 + #define ICP_QAT_MOF_MINVER 0x1 40 + #define ICP_QAT_MOF_SYM_OBJS "SYM_OBJS" 41 + #define ICP_QAT_SUOF_OBJS "SUF_OBJS" 42 + #define ICP_QAT_SUOF_IMAG "SUF_IMAG" 36 43 #define ICP_QAT_SIMG_AE_INIT_SEQ_LEN (50 * sizeof(unsigned long long)) 37 44 #define ICP_QAT_SIMG_AE_INSTS_LEN (0x4000 * sizeof(unsigned long long)) 38 - #define ICP_QAT_CSS_FWSK_MODULUS_LEN 256 39 - #define ICP_QAT_CSS_FWSK_EXPONENT_LEN 4 40 - #define ICP_QAT_CSS_FWSK_PAD_LEN 252 41 - #define ICP_QAT_CSS_FWSK_PUB_LEN (ICP_QAT_CSS_FWSK_MODULUS_LEN + \ 42 - ICP_QAT_CSS_FWSK_EXPONENT_LEN + \ 43 - ICP_QAT_CSS_FWSK_PAD_LEN) 44 - #define ICP_QAT_CSS_SIGNATURE_LEN 256 45 + 46 + #define DSS_FWSK_MODULUS_LEN 384 /* RSA3K */ 47 + #define DSS_FWSK_EXPONENT_LEN 4 48 + #define DSS_FWSK_PADDING_LEN 380 49 + #define DSS_SIGNATURE_LEN 384 /* RSA3K */ 50 + 51 + #define CSS_FWSK_MODULUS_LEN 256 /* RSA2K */ 52 + #define CSS_FWSK_EXPONENT_LEN 4 53 + #define CSS_FWSK_PADDING_LEN 252 54 + #define CSS_SIGNATURE_LEN 256 /* RSA2K */ 55 + 56 + #define ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) ((handle)->chip_info->css_3k ? \ 57 + DSS_FWSK_MODULUS_LEN : \ 58 + CSS_FWSK_MODULUS_LEN) 59 + 60 + #define ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle) ((handle)->chip_info->css_3k ? \ 61 + DSS_FWSK_EXPONENT_LEN : \ 62 + CSS_FWSK_EXPONENT_LEN) 63 + 64 + #define ICP_QAT_CSS_FWSK_PAD_LEN(handle) ((handle)->chip_info->css_3k ? \ 65 + DSS_FWSK_PADDING_LEN : \ 66 + CSS_FWSK_PADDING_LEN) 67 + 68 + #define ICP_QAT_CSS_FWSK_PUB_LEN(handle) (ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + \ 69 + ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle) + \ 70 + ICP_QAT_CSS_FWSK_PAD_LEN(handle)) 71 + 72 + #define ICP_QAT_CSS_SIGNATURE_LEN(handle) ((handle)->chip_info->css_3k ? \ 73 + DSS_SIGNATURE_LEN : \ 74 + CSS_SIGNATURE_LEN) 75 + 45 76 #define ICP_QAT_CSS_AE_IMG_LEN (sizeof(struct icp_qat_simg_ae_mode) + \ 46 77 ICP_QAT_SIMG_AE_INIT_SEQ_LEN + \ 47 78 ICP_QAT_SIMG_AE_INSTS_LEN) 48 - #define ICP_QAT_CSS_AE_SIMG_LEN (sizeof(struct icp_qat_css_hdr) + \ 49 - ICP_QAT_CSS_FWSK_PUB_LEN + \ 50 - ICP_QAT_CSS_SIGNATURE_LEN + \ 51 - ICP_QAT_CSS_AE_IMG_LEN) 52 - #define ICP_QAT_AE_IMG_OFFSET (sizeof(struct icp_qat_css_hdr) + \ 53 - ICP_QAT_CSS_FWSK_MODULUS_LEN + \ 54 - ICP_QAT_CSS_FWSK_EXPONENT_LEN + \ 55 - ICP_QAT_CSS_SIGNATURE_LEN) 79 + #define ICP_QAT_CSS_AE_SIMG_LEN(handle) (sizeof(struct icp_qat_css_hdr) + \ 80 + ICP_QAT_CSS_FWSK_PUB_LEN(handle) + \ 81 + ICP_QAT_CSS_SIGNATURE_LEN(handle) + \ 82 + ICP_QAT_CSS_AE_IMG_LEN) 83 + #define ICP_QAT_AE_IMG_OFFSET(handle) (sizeof(struct icp_qat_css_hdr) + \ 84 + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + \ 85 + ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle) + \ 86 + ICP_QAT_CSS_SIGNATURE_LEN(handle)) 56 87 #define ICP_QAT_CSS_MAX_IMAGE_LEN 0x40000 57 88 58 89 #define ICP_QAT_CTX_MODE(ae_mode) ((ae_mode) & 0xf) ··· 95 60 96 61 #define ICP_QAT_LOC_MEM0_MODE(ae_mode) (((ae_mode) >> 0x8) & 0x1) 97 62 #define ICP_QAT_LOC_MEM1_MODE(ae_mode) (((ae_mode) >> 0x9) & 0x1) 63 + #define ICP_QAT_LOC_MEM2_MODE(ae_mode) (((ae_mode) >> 0x6) & 0x1) 64 + #define ICP_QAT_LOC_MEM3_MODE(ae_mode) (((ae_mode) >> 0x7) & 0x1) 65 + #define ICP_QAT_LOC_TINDEX_MODE(ae_mode) (((ae_mode) >> 0xe) & 0x1) 98 66 99 67 enum icp_qat_uof_mem_region { 100 68 ICP_QAT_UOF_SRAM_REGION = 0x0, ··· 127 89 ICP_LMEM0 = 27, 128 90 ICP_LMEM1 = 28, 129 91 ICP_NEIGH_REL = 31, 92 + ICP_LMEM2 = 61, 93 + ICP_LMEM3 = 62, 130 94 }; 131 95 132 96 enum icp_qat_css_fwtype { ··· 434 394 435 395 struct icp_qat_fw_auth_desc { 436 396 unsigned int img_len; 437 - unsigned int reserved; 397 + unsigned int ae_mask; 438 398 unsigned int css_hdr_high; 439 399 unsigned int css_hdr_low; 440 400 unsigned int img_high; ··· 520 480 struct icp_qat_suof_objhdr { 521 481 unsigned int img_length; 522 482 unsigned int reserved; 483 + }; 484 + 485 + struct icp_qat_mof_file_hdr { 486 + unsigned int file_id; 487 + unsigned int checksum; 488 + char min_ver; 489 + char maj_ver; 490 + unsigned short reserved; 491 + unsigned short max_chunks; 492 + unsigned short num_chunks; 493 + }; 494 + 495 + struct icp_qat_mof_chunkhdr { 496 + char chunk_id[ICP_QAT_MOF_OBJ_ID_LEN]; 497 + u64 offset; 498 + u64 size; 499 + }; 500 + 501 + struct icp_qat_mof_str_table { 502 + unsigned int tab_len; 503 + unsigned int strings; 504 + }; 505 + 506 + struct icp_qat_mof_obj_hdr { 507 + unsigned short max_chunks; 508 + unsigned short num_chunks; 509 + unsigned int reserved; 510 + }; 511 + 512 + struct icp_qat_mof_obj_chunkhdr { 513 + char chunk_id[ICP_QAT_MOF_OBJ_CHUNKID_LEN]; 514 + u64 offset; 515 + u64 size; 516 + unsigned int name; 517 + unsigned int reserved; 518 + }; 519 + 520 + struct icp_qat_mof_objhdr { 521 + char *obj_name; 522 + char *obj_buf; 523 + unsigned int obj_size; 524 + }; 525 + 526 + struct icp_qat_mof_table { 527 + unsigned int num_objs; 528 + struct icp_qat_mof_objhdr *obj_hdr; 529 + }; 530 + 531 + struct icp_qat_mof_handle { 532 + unsigned int file_id; 533 + unsigned int checksum; 534 + char min_ver; 535 + char maj_ver; 536 + char *mof_buf; 537 + u32 mof_size; 538 + char *sym_str; 539 + unsigned int sym_size; 540 + char *uobjs_hdr; 541 + char *sobjs_hdr; 542 + struct icp_qat_mof_table obj_table; 523 543 }; 524 544 #endif
+185 -63
drivers/crypto/qat/qat_common/qat_algs.c
··· 6 6 #include <crypto/internal/aead.h> 7 7 #include <crypto/internal/skcipher.h> 8 8 #include <crypto/aes.h> 9 - #include <crypto/sha.h> 9 + #include <crypto/sha1.h> 10 + #include <crypto/sha2.h> 10 11 #include <crypto/hash.h> 11 12 #include <crypto/hmac.h> 12 13 #include <crypto/algapi.h> 13 14 #include <crypto/authenc.h> 15 + #include <crypto/scatterwalk.h> 14 16 #include <crypto/xts.h> 15 17 #include <linux/dma-mapping.h> 16 18 #include "adf_accel_devices.h" ··· 32 30 ICP_QAT_HW_CIPHER_CONFIG_BUILD(mode, alg, \ 33 31 ICP_QAT_HW_CIPHER_KEY_CONVERT, \ 34 32 ICP_QAT_HW_CIPHER_DECRYPT) 33 + 34 + #define QAT_AES_HW_CONFIG_DEC_NO_CONV(alg, mode) \ 35 + ICP_QAT_HW_CIPHER_CONFIG_BUILD(mode, alg, \ 36 + ICP_QAT_HW_CIPHER_NO_CONVERT, \ 37 + ICP_QAT_HW_CIPHER_DECRYPT) 38 + 39 + #define HW_CAP_AES_V2(accel_dev) \ 40 + (GET_HW_DATA(accel_dev)->accel_capabilities_mask & \ 41 + ICP_ACCEL_CAPABILITIES_AES_V2) 35 42 36 43 static DEFINE_MUTEX(algs_lock); 37 44 static unsigned int active_devs; ··· 100 89 struct icp_qat_fw_la_bulk_req dec_fw_req; 101 90 struct qat_crypto_instance *inst; 102 91 struct crypto_skcipher *ftfm; 92 + struct crypto_cipher *tweak; 103 93 bool fallback; 94 + int mode; 104 95 }; 105 96 106 97 static int qat_get_inter_state_size(enum icp_qat_hw_auth_algo qat_hash_alg) ··· 116 103 return ICP_QAT_HW_SHA512_STATE1_SZ; 117 104 default: 118 105 return -EFAULT; 119 - }; 106 + } 120 107 return -EFAULT; 121 108 } 122 109 ··· 227 214 return 0; 228 215 } 229 216 230 - static void qat_alg_init_hdr_iv_updt(struct icp_qat_fw_comn_req_hdr *header) 231 - { 232 - ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(header->serv_specif_flags, 233 - ICP_QAT_FW_CIPH_IV_64BIT_PTR); 234 - ICP_QAT_FW_LA_UPDATE_STATE_SET(header->serv_specif_flags, 235 - ICP_QAT_FW_LA_UPDATE_STATE); 236 - } 237 - 238 - static void qat_alg_init_hdr_no_iv_updt(struct icp_qat_fw_comn_req_hdr *header) 239 - { 240 - ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(header->serv_specif_flags, 241 - ICP_QAT_FW_CIPH_IV_16BYTE_DATA); 242 - ICP_QAT_FW_LA_UPDATE_STATE_SET(header->serv_specif_flags, 243 - ICP_QAT_FW_LA_NO_UPDATE_STATE); 244 - } 245 - 246 - static void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header, 247 - int aead) 217 + static void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header) 248 218 { 249 219 header->hdr_flags = 250 220 ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET); ··· 237 241 QAT_COMN_PTR_TYPE_SGL); 238 242 ICP_QAT_FW_LA_PARTIAL_SET(header->serv_specif_flags, 239 243 ICP_QAT_FW_LA_PARTIAL_NONE); 240 - if (aead) 241 - qat_alg_init_hdr_no_iv_updt(header); 242 - else 243 - qat_alg_init_hdr_iv_updt(header); 244 + ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(header->serv_specif_flags, 245 + ICP_QAT_FW_CIPH_IV_16BYTE_DATA); 244 246 ICP_QAT_FW_LA_PROTO_SET(header->serv_specif_flags, 245 247 ICP_QAT_FW_LA_NO_PROTO); 248 + ICP_QAT_FW_LA_UPDATE_STATE_SET(header->serv_specif_flags, 249 + ICP_QAT_FW_LA_NO_UPDATE_STATE); 246 250 } 247 251 248 252 static int qat_alg_aead_init_enc_session(struct crypto_aead *aead_tfm, ··· 277 281 return -EFAULT; 278 282 279 283 /* Request setup */ 280 - qat_alg_init_common_hdr(header, 1); 284 + qat_alg_init_common_hdr(header); 281 285 header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER_HASH; 282 286 ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags, 283 287 ICP_QAT_FW_LA_DIGEST_IN_BUFFER); ··· 364 368 return -EFAULT; 365 369 366 370 /* Request setup */ 367 - qat_alg_init_common_hdr(header, 1); 371 + qat_alg_init_common_hdr(header); 368 372 header->service_cmd_id = ICP_QAT_FW_LA_CMD_HASH_CIPHER; 369 373 ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags, 370 374 ICP_QAT_FW_LA_DIGEST_IN_BUFFER); ··· 426 430 struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; 427 431 struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr; 428 432 struct icp_qat_fw_cipher_cd_ctrl_hdr *cd_ctrl = (void *)&req->cd_ctrl; 433 + bool aes_v2_capable = HW_CAP_AES_V2(ctx->inst->accel_dev); 434 + int mode = ctx->mode; 429 435 430 - memcpy(cd->aes.key, key, keylen); 431 - qat_alg_init_common_hdr(header, 0); 436 + qat_alg_init_common_hdr(header); 432 437 header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER; 433 438 cd_pars->u.s.content_desc_params_sz = 434 439 sizeof(struct icp_qat_hw_cipher_algo_blk) >> 3; 440 + 441 + if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_XTS_MODE) { 442 + ICP_QAT_FW_LA_SLICE_TYPE_SET(header->serv_specif_flags, 443 + ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE); 444 + 445 + /* Store both XTS keys in CD, only the first key is sent 446 + * to the HW, the second key is used for tweak calculation 447 + */ 448 + memcpy(cd->ucs_aes.key, key, keylen); 449 + keylen = keylen / 2; 450 + } else if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_CTR_MODE) { 451 + ICP_QAT_FW_LA_SLICE_TYPE_SET(header->serv_specif_flags, 452 + ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE); 453 + keylen = round_up(keylen, 16); 454 + memcpy(cd->ucs_aes.key, key, keylen); 455 + } else { 456 + memcpy(cd->aes.key, key, keylen); 457 + } 458 + 435 459 /* Cipher CD config setup */ 436 460 cd_ctrl->cipher_key_sz = keylen >> 3; 437 461 cd_ctrl->cipher_state_sz = AES_BLOCK_SIZE >> 3; ··· 473 457 enc_cd->aes.cipher_config.val = QAT_AES_HW_CONFIG_ENC(alg, mode); 474 458 } 475 459 460 + static void qat_alg_xts_reverse_key(const u8 *key_forward, unsigned int keylen, 461 + u8 *key_reverse) 462 + { 463 + struct crypto_aes_ctx aes_expanded; 464 + int nrounds; 465 + u8 *key; 466 + 467 + aes_expandkey(&aes_expanded, key_forward, keylen); 468 + if (keylen == AES_KEYSIZE_128) { 469 + nrounds = 10; 470 + key = (u8 *)aes_expanded.key_enc + (AES_BLOCK_SIZE * nrounds); 471 + memcpy(key_reverse, key, AES_BLOCK_SIZE); 472 + } else { 473 + /* AES_KEYSIZE_256 */ 474 + nrounds = 14; 475 + key = (u8 *)aes_expanded.key_enc + (AES_BLOCK_SIZE * nrounds); 476 + memcpy(key_reverse, key, AES_BLOCK_SIZE); 477 + memcpy(key_reverse + AES_BLOCK_SIZE, key - AES_BLOCK_SIZE, 478 + AES_BLOCK_SIZE); 479 + } 480 + } 481 + 476 482 static void qat_alg_skcipher_init_dec(struct qat_alg_skcipher_ctx *ctx, 477 483 int alg, const u8 *key, 478 484 unsigned int keylen, int mode) ··· 502 464 struct icp_qat_hw_cipher_algo_blk *dec_cd = ctx->dec_cd; 503 465 struct icp_qat_fw_la_bulk_req *req = &ctx->dec_fw_req; 504 466 struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars; 467 + bool aes_v2_capable = HW_CAP_AES_V2(ctx->inst->accel_dev); 505 468 506 469 qat_alg_skcipher_init_com(ctx, req, dec_cd, key, keylen); 507 470 cd_pars->u.s.content_desc_addr = ctx->dec_cd_paddr; 508 471 509 - if (mode != ICP_QAT_HW_CIPHER_CTR_MODE) 472 + if (aes_v2_capable && mode == ICP_QAT_HW_CIPHER_XTS_MODE) { 473 + /* Key reversing not supported, set no convert */ 474 + dec_cd->aes.cipher_config.val = 475 + QAT_AES_HW_CONFIG_DEC_NO_CONV(alg, mode); 476 + 477 + /* In-place key reversal */ 478 + qat_alg_xts_reverse_key(dec_cd->ucs_aes.key, keylen / 2, 479 + dec_cd->ucs_aes.key); 480 + } else if (mode != ICP_QAT_HW_CIPHER_CTR_MODE) { 510 481 dec_cd->aes.cipher_config.val = 511 482 QAT_AES_HW_CONFIG_DEC(alg, mode); 512 - else 483 + } else { 513 484 dec_cd->aes.cipher_config.val = 514 485 QAT_AES_HW_CONFIG_ENC(alg, mode); 486 + } 515 487 } 516 488 517 489 static int qat_alg_validate_key(int key_len, int *alg, int mode) ··· 835 787 areq->base.complete(&areq->base, res); 836 788 } 837 789 790 + static void qat_alg_update_iv_ctr_mode(struct qat_crypto_request *qat_req) 791 + { 792 + struct skcipher_request *sreq = qat_req->skcipher_req; 793 + u64 iv_lo_prev; 794 + u64 iv_lo; 795 + u64 iv_hi; 796 + 797 + memcpy(qat_req->iv, sreq->iv, AES_BLOCK_SIZE); 798 + 799 + iv_lo = be64_to_cpu(qat_req->iv_lo); 800 + iv_hi = be64_to_cpu(qat_req->iv_hi); 801 + 802 + iv_lo_prev = iv_lo; 803 + iv_lo += DIV_ROUND_UP(sreq->cryptlen, AES_BLOCK_SIZE); 804 + if (iv_lo < iv_lo_prev) 805 + iv_hi++; 806 + 807 + qat_req->iv_lo = cpu_to_be64(iv_lo); 808 + qat_req->iv_hi = cpu_to_be64(iv_hi); 809 + } 810 + 811 + static void qat_alg_update_iv_cbc_mode(struct qat_crypto_request *qat_req) 812 + { 813 + struct skcipher_request *sreq = qat_req->skcipher_req; 814 + int offset = sreq->cryptlen - AES_BLOCK_SIZE; 815 + struct scatterlist *sgl; 816 + 817 + if (qat_req->encryption) 818 + sgl = sreq->dst; 819 + else 820 + sgl = sreq->src; 821 + 822 + scatterwalk_map_and_copy(qat_req->iv, sgl, offset, AES_BLOCK_SIZE, 0); 823 + } 824 + 825 + static void qat_alg_update_iv(struct qat_crypto_request *qat_req) 826 + { 827 + struct qat_alg_skcipher_ctx *ctx = qat_req->skcipher_ctx; 828 + struct device *dev = &GET_DEV(ctx->inst->accel_dev); 829 + 830 + switch (ctx->mode) { 831 + case ICP_QAT_HW_CIPHER_CTR_MODE: 832 + qat_alg_update_iv_ctr_mode(qat_req); 833 + break; 834 + case ICP_QAT_HW_CIPHER_CBC_MODE: 835 + qat_alg_update_iv_cbc_mode(qat_req); 836 + break; 837 + case ICP_QAT_HW_CIPHER_XTS_MODE: 838 + break; 839 + default: 840 + dev_warn(dev, "Unsupported IV update for cipher mode %d\n", 841 + ctx->mode); 842 + } 843 + } 844 + 838 845 static void qat_skcipher_alg_callback(struct icp_qat_fw_la_resp *qat_resp, 839 846 struct qat_crypto_request *qat_req) 840 847 { ··· 897 794 struct qat_crypto_instance *inst = ctx->inst; 898 795 struct skcipher_request *sreq = qat_req->skcipher_req; 899 796 u8 stat_filed = qat_resp->comn_resp.comn_status; 900 - struct device *dev = &GET_DEV(ctx->inst->accel_dev); 901 797 int res = 0, qat_res = ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(stat_filed); 902 798 903 799 qat_alg_free_bufl(inst, qat_req); 904 800 if (unlikely(qat_res != ICP_QAT_FW_COMN_STATUS_FLAG_OK)) 905 801 res = -EINVAL; 906 802 803 + if (qat_req->encryption) 804 + qat_alg_update_iv(qat_req); 805 + 907 806 memcpy(sreq->iv, qat_req->iv, AES_BLOCK_SIZE); 908 - dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv, 909 - qat_req->iv_paddr); 910 807 911 808 sreq->base.complete(&sreq->base, res); 912 809 } ··· 1084 981 { 1085 982 struct qat_alg_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm); 1086 983 984 + ctx->mode = mode; 985 + 1087 986 if (ctx->enc_cd) 1088 987 return qat_alg_skcipher_rekey(ctx, key, keylen, mode); 1089 988 else ··· 1128 1023 1129 1024 ctx->fallback = false; 1130 1025 1131 - return qat_alg_skcipher_setkey(tfm, key, keylen, 1132 - ICP_QAT_HW_CIPHER_XTS_MODE); 1026 + ret = qat_alg_skcipher_setkey(tfm, key, keylen, 1027 + ICP_QAT_HW_CIPHER_XTS_MODE); 1028 + if (ret) 1029 + return ret; 1030 + 1031 + if (HW_CAP_AES_V2(ctx->inst->accel_dev)) 1032 + ret = crypto_cipher_setkey(ctx->tweak, key + (keylen / 2), 1033 + keylen / 2); 1034 + 1035 + return ret; 1036 + } 1037 + 1038 + static void qat_alg_set_req_iv(struct qat_crypto_request *qat_req) 1039 + { 1040 + struct icp_qat_fw_la_cipher_req_params *cipher_param; 1041 + struct qat_alg_skcipher_ctx *ctx = qat_req->skcipher_ctx; 1042 + bool aes_v2_capable = HW_CAP_AES_V2(ctx->inst->accel_dev); 1043 + u8 *iv = qat_req->skcipher_req->iv; 1044 + 1045 + cipher_param = (void *)&qat_req->req.serv_specif_rqpars; 1046 + 1047 + if (aes_v2_capable && ctx->mode == ICP_QAT_HW_CIPHER_XTS_MODE) 1048 + crypto_cipher_encrypt_one(ctx->tweak, 1049 + (u8 *)cipher_param->u.cipher_IV_array, 1050 + iv); 1051 + else 1052 + memcpy(cipher_param->u.cipher_IV_array, iv, AES_BLOCK_SIZE); 1133 1053 } 1134 1054 1135 1055 static int qat_alg_skcipher_encrypt(struct skcipher_request *req) ··· 1165 1035 struct qat_crypto_request *qat_req = skcipher_request_ctx(req); 1166 1036 struct icp_qat_fw_la_cipher_req_params *cipher_param; 1167 1037 struct icp_qat_fw_la_bulk_req *msg; 1168 - struct device *dev = &GET_DEV(ctx->inst->accel_dev); 1169 1038 int ret, ctr = 0; 1170 1039 1171 1040 if (req->cryptlen == 0) 1172 1041 return 0; 1173 1042 1174 - qat_req->iv = dma_alloc_coherent(dev, AES_BLOCK_SIZE, 1175 - &qat_req->iv_paddr, GFP_ATOMIC); 1176 - if (!qat_req->iv) 1177 - return -ENOMEM; 1178 - 1179 1043 ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req); 1180 - if (unlikely(ret)) { 1181 - dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv, 1182 - qat_req->iv_paddr); 1044 + if (unlikely(ret)) 1183 1045 return ret; 1184 - } 1185 1046 1186 1047 msg = &qat_req->req; 1187 1048 *msg = ctx->enc_fw_req; ··· 1182 1061 qat_req->req.comn_mid.opaque_data = (u64)(__force long)qat_req; 1183 1062 qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; 1184 1063 qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; 1064 + qat_req->encryption = true; 1185 1065 cipher_param = (void *)&qat_req->req.serv_specif_rqpars; 1186 1066 cipher_param->cipher_length = req->cryptlen; 1187 1067 cipher_param->cipher_offset = 0; 1188 - cipher_param->u.s.cipher_IV_ptr = qat_req->iv_paddr; 1189 - memcpy(qat_req->iv, req->iv, AES_BLOCK_SIZE); 1068 + 1069 + qat_alg_set_req_iv(qat_req); 1070 + 1190 1071 do { 1191 1072 ret = adf_send_message(ctx->inst->sym_tx, (u32 *)msg); 1192 1073 } while (ret == -EAGAIN && ctr++ < 10); 1193 1074 1194 1075 if (ret == -EAGAIN) { 1195 1076 qat_alg_free_bufl(ctx->inst, qat_req); 1196 - dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv, 1197 - qat_req->iv_paddr); 1198 1077 return -EBUSY; 1199 1078 } 1200 1079 return -EINPROGRESS; ··· 1234 1113 struct qat_crypto_request *qat_req = skcipher_request_ctx(req); 1235 1114 struct icp_qat_fw_la_cipher_req_params *cipher_param; 1236 1115 struct icp_qat_fw_la_bulk_req *msg; 1237 - struct device *dev = &GET_DEV(ctx->inst->accel_dev); 1238 1116 int ret, ctr = 0; 1239 1117 1240 1118 if (req->cryptlen == 0) 1241 1119 return 0; 1242 1120 1243 - qat_req->iv = dma_alloc_coherent(dev, AES_BLOCK_SIZE, 1244 - &qat_req->iv_paddr, GFP_ATOMIC); 1245 - if (!qat_req->iv) 1246 - return -ENOMEM; 1247 - 1248 1121 ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req); 1249 - if (unlikely(ret)) { 1250 - dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv, 1251 - qat_req->iv_paddr); 1122 + if (unlikely(ret)) 1252 1123 return ret; 1253 - } 1254 1124 1255 1125 msg = &qat_req->req; 1256 1126 *msg = ctx->dec_fw_req; ··· 1251 1139 qat_req->req.comn_mid.opaque_data = (u64)(__force long)qat_req; 1252 1140 qat_req->req.comn_mid.src_data_addr = qat_req->buf.blp; 1253 1141 qat_req->req.comn_mid.dest_data_addr = qat_req->buf.bloutp; 1142 + qat_req->encryption = false; 1254 1143 cipher_param = (void *)&qat_req->req.serv_specif_rqpars; 1255 1144 cipher_param->cipher_length = req->cryptlen; 1256 1145 cipher_param->cipher_offset = 0; 1257 - cipher_param->u.s.cipher_IV_ptr = qat_req->iv_paddr; 1258 - memcpy(qat_req->iv, req->iv, AES_BLOCK_SIZE); 1146 + 1147 + qat_alg_set_req_iv(qat_req); 1148 + qat_alg_update_iv(qat_req); 1149 + 1259 1150 do { 1260 1151 ret = adf_send_message(ctx->inst->sym_tx, (u32 *)msg); 1261 1152 } while (ret == -EAGAIN && ctr++ < 10); 1262 1153 1263 1154 if (ret == -EAGAIN) { 1264 1155 qat_alg_free_bufl(ctx->inst, qat_req); 1265 - dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv, 1266 - qat_req->iv_paddr); 1267 1156 return -EBUSY; 1268 1157 } 1269 1158 return -EINPROGRESS; ··· 1366 1253 if (IS_ERR(ctx->ftfm)) 1367 1254 return PTR_ERR(ctx->ftfm); 1368 1255 1256 + ctx->tweak = crypto_alloc_cipher("aes", 0, 0); 1257 + if (IS_ERR(ctx->tweak)) { 1258 + crypto_free_skcipher(ctx->ftfm); 1259 + return PTR_ERR(ctx->tweak); 1260 + } 1261 + 1369 1262 reqsize = max(sizeof(struct qat_crypto_request), 1370 1263 sizeof(struct skcipher_request) + 1371 1264 crypto_skcipher_reqsize(ctx->ftfm)); ··· 1413 1294 1414 1295 if (ctx->ftfm) 1415 1296 crypto_free_skcipher(ctx->ftfm); 1297 + 1298 + if (ctx->tweak) 1299 + crypto_free_cipher(ctx->tweak); 1416 1300 1417 1301 qat_alg_skcipher_exit_tfm(tfm); 1418 1302 }
+4 -9
drivers/crypto/qat/qat_common/qat_asym_algs.c
··· 201 201 return g2 ? PKE_DH_G2_4096 : PKE_DH_4096; 202 202 default: 203 203 return 0; 204 - }; 205 - } 206 - 207 - static inline struct qat_dh_ctx *qat_dh_get_params(struct crypto_kpp *tfm) 208 - { 209 - return kpp_tfm_ctx(tfm); 204 + } 210 205 } 211 206 212 207 static int qat_dh_compute_value(struct kpp_request *req) ··· 572 577 return PKE_RSA_EP_4096; 573 578 default: 574 579 return 0; 575 - }; 580 + } 576 581 } 577 582 578 583 #define PKE_RSA_DP1_512 0x1c161b3c ··· 601 606 return PKE_RSA_DP1_4096; 602 607 default: 603 608 return 0; 604 - }; 609 + } 605 610 } 606 611 607 612 #define PKE_RSA_DP2_512 0x1c131b57 ··· 630 635 return PKE_RSA_DP2_4096; 631 636 default: 632 637 return 0; 633 - }; 638 + } 634 639 } 635 640 636 641 static int qat_rsa_enc(struct akcipher_request *req)
+107 -55
drivers/crypto/qat/qat_common/qat_crypto.c
··· 115 115 */ 116 116 int qat_crypto_dev_config(struct adf_accel_dev *accel_dev) 117 117 { 118 - int cpus = num_online_cpus(); 119 - int banks = GET_MAX_BANKS(accel_dev); 120 - int instances = min(cpus, banks); 121 118 char key[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; 122 - int i; 119 + int banks = GET_MAX_BANKS(accel_dev); 120 + int cpus = num_online_cpus(); 123 121 unsigned long val; 122 + int instances; 123 + int ret; 124 + int i; 124 125 125 - if (adf_cfg_section_add(accel_dev, ADF_KERNEL_SEC)) 126 + if (adf_hw_dev_has_crypto(accel_dev)) 127 + instances = min(cpus, banks); 128 + else 129 + instances = 0; 130 + 131 + ret = adf_cfg_section_add(accel_dev, ADF_KERNEL_SEC); 132 + if (ret) 126 133 goto err; 127 - if (adf_cfg_section_add(accel_dev, "Accelerator0")) 134 + 135 + ret = adf_cfg_section_add(accel_dev, "Accelerator0"); 136 + if (ret) 128 137 goto err; 138 + 129 139 for (i = 0; i < instances; i++) { 130 140 val = i; 131 - snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_BANK_NUM, i); 132 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 133 - key, (void *)&val, ADF_DEC)) 141 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_BANK_NUM, i); 142 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 143 + key, &val, ADF_DEC); 144 + if (ret) 145 + goto err; 146 + 147 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_BANK_NUM, i); 148 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 149 + key, &val, ADF_DEC); 150 + if (ret) 134 151 goto err; 135 152 136 153 snprintf(key, sizeof(key), ADF_CY "%d" ADF_ETRMGR_CORE_AFFINITY, 137 154 i); 138 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 139 - key, (void *)&val, ADF_DEC)) 155 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 156 + key, &val, ADF_DEC); 157 + if (ret) 140 158 goto err; 141 159 142 160 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_SIZE, i); 143 161 val = 128; 144 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 145 - key, (void *)&val, ADF_DEC)) 162 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 163 + key, &val, ADF_DEC); 164 + if (ret) 146 165 goto err; 147 166 148 167 val = 512; 149 168 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_SIZE, i); 150 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 151 - key, (void *)&val, ADF_DEC)) 169 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 170 + key, &val, ADF_DEC); 171 + if (ret) 152 172 goto err; 153 173 154 174 val = 0; 155 175 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_TX, i); 156 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 157 - key, (void *)&val, ADF_DEC)) 176 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 177 + key, &val, ADF_DEC); 178 + if (ret) 158 179 goto err; 159 180 160 181 val = 2; 161 182 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_TX, i); 162 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 163 - key, (void *)&val, ADF_DEC)) 183 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 184 + key, &val, ADF_DEC); 185 + if (ret) 164 186 goto err; 165 187 166 188 val = 8; 167 189 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_RX, i); 168 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 169 - key, (void *)&val, ADF_DEC)) 190 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 191 + key, &val, ADF_DEC); 192 + if (ret) 170 193 goto err; 171 194 172 195 val = 10; 173 196 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_RX, i); 174 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 175 - key, (void *)&val, ADF_DEC)) 197 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 198 + key, &val, ADF_DEC); 199 + if (ret) 176 200 goto err; 177 201 178 202 val = ADF_COALESCING_DEF_TIME; 179 203 snprintf(key, sizeof(key), ADF_ETRMGR_COALESCE_TIMER_FORMAT, i); 180 - if (adf_cfg_add_key_value_param(accel_dev, "Accelerator0", 181 - key, (void *)&val, ADF_DEC)) 204 + ret = adf_cfg_add_key_value_param(accel_dev, "Accelerator0", 205 + key, &val, ADF_DEC); 206 + if (ret) 182 207 goto err; 183 208 } 184 209 185 210 val = i; 186 - if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, 187 - ADF_NUM_CY, (void *)&val, ADF_DEC)) 211 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, ADF_NUM_CY, 212 + &val, ADF_DEC); 213 + if (ret) 188 214 goto err; 189 215 190 216 set_bit(ADF_STATUS_CONFIGURED, &accel_dev->status); 191 217 return 0; 192 218 err: 193 219 dev_err(&GET_DEV(accel_dev), "Failed to start QAT accel dev\n"); 194 - return -EINVAL; 220 + return ret; 195 221 } 196 222 EXPORT_SYMBOL_GPL(qat_crypto_dev_config); 197 223 198 224 static int qat_crypto_create_instances(struct adf_accel_dev *accel_dev) 199 225 { 200 - int i; 201 - unsigned long bank; 202 226 unsigned long num_inst, num_msg_sym, num_msg_asym; 203 - int msg_size; 204 - struct qat_crypto_instance *inst; 205 227 char key[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; 206 228 char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; 229 + unsigned long sym_bank, asym_bank; 230 + struct qat_crypto_instance *inst; 231 + int msg_size; 232 + int ret; 233 + int i; 207 234 208 235 INIT_LIST_HEAD(&accel_dev->crypto_list); 209 - if (adf_cfg_get_param_value(accel_dev, SEC, ADF_NUM_CY, val)) 210 - return -EFAULT; 236 + ret = adf_cfg_get_param_value(accel_dev, SEC, ADF_NUM_CY, val); 237 + if (ret) 238 + return ret; 211 239 212 - if (kstrtoul(val, 0, &num_inst)) 213 - return -EFAULT; 240 + ret = kstrtoul(val, 0, &num_inst); 241 + if (ret) 242 + return ret; 214 243 215 244 for (i = 0; i < num_inst; i++) { 216 245 inst = kzalloc_node(sizeof(*inst), GFP_KERNEL, 217 246 dev_to_node(&GET_DEV(accel_dev))); 218 - if (!inst) 247 + if (!inst) { 248 + ret = -ENOMEM; 219 249 goto err; 250 + } 220 251 221 252 list_add_tail(&inst->list, &accel_dev->crypto_list); 222 253 inst->id = i; 223 254 atomic_set(&inst->refctr, 0); 224 255 inst->accel_dev = accel_dev; 225 - snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_BANK_NUM, i); 226 - if (adf_cfg_get_param_value(accel_dev, SEC, key, val)) 256 + 257 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_BANK_NUM, i); 258 + ret = adf_cfg_get_param_value(accel_dev, SEC, key, val); 259 + if (ret) 227 260 goto err; 228 261 229 - if (kstrtoul(val, 10, &bank)) 262 + ret = kstrtoul(val, 10, &sym_bank); 263 + if (ret) 230 264 goto err; 265 + 266 + snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_BANK_NUM, i); 267 + ret = adf_cfg_get_param_value(accel_dev, SEC, key, val); 268 + if (ret) 269 + goto err; 270 + 271 + ret = kstrtoul(val, 10, &asym_bank); 272 + if (ret) 273 + goto err; 274 + 231 275 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_SIZE, i); 232 - if (adf_cfg_get_param_value(accel_dev, SEC, key, val)) 276 + ret = adf_cfg_get_param_value(accel_dev, SEC, key, val); 277 + if (ret) 233 278 goto err; 234 279 235 - if (kstrtoul(val, 10, &num_msg_sym)) 280 + ret = kstrtoul(val, 10, &num_msg_sym); 281 + if (ret) 236 282 goto err; 237 283 238 284 num_msg_sym = num_msg_sym >> 1; 239 285 240 286 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_SIZE, i); 241 - if (adf_cfg_get_param_value(accel_dev, SEC, key, val)) 287 + ret = adf_cfg_get_param_value(accel_dev, SEC, key, val); 288 + if (ret) 242 289 goto err; 243 290 244 - if (kstrtoul(val, 10, &num_msg_asym)) 291 + ret = kstrtoul(val, 10, &num_msg_asym); 292 + if (ret) 245 293 goto err; 246 294 num_msg_asym = num_msg_asym >> 1; 247 295 248 296 msg_size = ICP_QAT_FW_REQ_DEFAULT_SZ; 249 297 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_TX, i); 250 - if (adf_create_ring(accel_dev, SEC, bank, num_msg_sym, 251 - msg_size, key, NULL, 0, &inst->sym_tx)) 298 + ret = adf_create_ring(accel_dev, SEC, sym_bank, num_msg_sym, 299 + msg_size, key, NULL, 0, &inst->sym_tx); 300 + if (ret) 252 301 goto err; 253 302 254 303 msg_size = msg_size >> 1; 255 304 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_TX, i); 256 - if (adf_create_ring(accel_dev, SEC, bank, num_msg_asym, 257 - msg_size, key, NULL, 0, &inst->pke_tx)) 305 + ret = adf_create_ring(accel_dev, SEC, asym_bank, num_msg_asym, 306 + msg_size, key, NULL, 0, &inst->pke_tx); 307 + if (ret) 258 308 goto err; 259 309 260 310 msg_size = ICP_QAT_FW_RESP_DEFAULT_SZ; 261 311 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_SYM_RX, i); 262 - if (adf_create_ring(accel_dev, SEC, bank, num_msg_sym, 263 - msg_size, key, qat_alg_callback, 0, 264 - &inst->sym_rx)) 312 + ret = adf_create_ring(accel_dev, SEC, sym_bank, num_msg_sym, 313 + msg_size, key, qat_alg_callback, 0, 314 + &inst->sym_rx); 315 + if (ret) 265 316 goto err; 266 317 267 318 snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_RX, i); 268 - if (adf_create_ring(accel_dev, SEC, bank, num_msg_asym, 269 - msg_size, key, qat_alg_asym_callback, 0, 270 - &inst->pke_rx)) 319 + ret = adf_create_ring(accel_dev, SEC, asym_bank, num_msg_asym, 320 + msg_size, key, qat_alg_asym_callback, 0, 321 + &inst->pke_rx); 322 + if (ret) 271 323 goto err; 272 324 } 273 325 return 0; 274 326 err: 275 327 qat_crypto_free_instances(accel_dev); 276 - return -ENOMEM; 328 + return ret; 277 329 } 278 330 279 331 static int qat_crypto_init(struct adf_accel_dev *accel_dev)
+24 -2
drivers/crypto/qat/qat_common/qat_crypto.h
··· 3 3 #ifndef _QAT_CRYPTO_INSTANCE_H_ 4 4 #define _QAT_CRYPTO_INSTANCE_H_ 5 5 6 + #include <crypto/aes.h> 6 7 #include <linux/list.h> 7 8 #include <linux/slab.h> 8 9 #include "adf_accel_devices.h" ··· 45 44 struct qat_crypto_request_buffs buf; 46 45 void (*cb)(struct icp_qat_fw_la_resp *resp, 47 46 struct qat_crypto_request *req); 48 - void *iv; 49 - dma_addr_t iv_paddr; 47 + union { 48 + struct { 49 + __be64 iv_hi; 50 + __be64 iv_lo; 51 + }; 52 + u8 iv[AES_BLOCK_SIZE]; 53 + }; 54 + bool encryption; 50 55 }; 56 + 57 + static inline bool adf_hw_dev_has_crypto(struct adf_accel_dev *accel_dev) 58 + { 59 + struct adf_hw_device_data *hw_device = accel_dev->hw_device; 60 + u32 mask = ~hw_device->accel_capabilities_mask; 61 + 62 + if (mask & ADF_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC) 63 + return false; 64 + if (mask & ADF_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) 65 + return false; 66 + if (mask & ADF_ACCEL_CAPABILITIES_AUTHENTICATION) 67 + return false; 68 + 69 + return true; 70 + } 51 71 52 72 #endif
+317 -108
drivers/crypto/qat/qat_common/qat_hal.c
··· 33 33 ((((const_val) << 12) & 0x0FF00000ull) | \ 34 34 (((const_val) << 0) & 0x000000FFull)))) 35 35 36 - #define AE(handle, ae) handle->hal_handle->aes[ae] 36 + #define AE(handle, ae) ((handle)->hal_handle->aes[ae]) 37 37 38 38 static const u64 inst_4b[] = { 39 39 0x0F0400C0000ull, 0x0F4400C0000ull, 0x0F040000300ull, 0x0F440000300ull, ··· 150 150 return 0; 151 151 } 152 152 153 - #define CLR_BIT(wrd, bit) (wrd & ~(1 << bit)) 154 - #define SET_BIT(wrd, bit) (wrd | 1 << bit) 153 + #define CLR_BIT(wrd, bit) ((wrd) & ~(1 << (bit))) 154 + #define SET_BIT(wrd, bit) ((wrd) | 1 << (bit)) 155 155 156 156 int qat_hal_set_ae_ctx_mode(struct icp_qat_fw_loader_handle *handle, 157 157 unsigned char ae, unsigned char mode) 158 158 { 159 159 unsigned int csr, new_csr; 160 160 161 - if ((mode != 4) && (mode != 8)) { 161 + if (mode != 4 && mode != 8) { 162 162 pr_err("QAT: bad ctx mode=%d\n", mode); 163 163 return -EINVAL; 164 164 } ··· 210 210 SET_BIT(csr, CE_LMADDR_1_GLOBAL_BITPOS) : 211 211 CLR_BIT(csr, CE_LMADDR_1_GLOBAL_BITPOS); 212 212 break; 213 + case ICP_LMEM2: 214 + new_csr = (mode) ? 215 + SET_BIT(csr, CE_LMADDR_2_GLOBAL_BITPOS) : 216 + CLR_BIT(csr, CE_LMADDR_2_GLOBAL_BITPOS); 217 + break; 218 + case ICP_LMEM3: 219 + new_csr = (mode) ? 220 + SET_BIT(csr, CE_LMADDR_3_GLOBAL_BITPOS) : 221 + CLR_BIT(csr, CE_LMADDR_3_GLOBAL_BITPOS); 222 + break; 213 223 default: 214 224 pr_err("QAT: lmType = 0x%x\n", lm_type); 215 225 return -EINVAL; ··· 228 218 if (new_csr != csr) 229 219 qat_hal_wr_ae_csr(handle, ae, CTX_ENABLES, new_csr); 230 220 return 0; 221 + } 222 + 223 + void qat_hal_set_ae_tindex_mode(struct icp_qat_fw_loader_handle *handle, 224 + unsigned char ae, unsigned char mode) 225 + { 226 + unsigned int csr, new_csr; 227 + 228 + csr = qat_hal_rd_ae_csr(handle, ae, CTX_ENABLES); 229 + csr &= IGNORE_W1C_MASK; 230 + new_csr = (mode) ? 231 + SET_BIT(csr, CE_T_INDEX_GLOBAL_BITPOS) : 232 + CLR_BIT(csr, CE_T_INDEX_GLOBAL_BITPOS); 233 + if (new_csr != csr) 234 + qat_hal_wr_ae_csr(handle, ae, CTX_ENABLES, new_csr); 231 235 } 232 236 233 237 static unsigned short qat_hal_get_reg_addr(unsigned int type, ··· 283 259 case ICP_LMEM1: 284 260 reg_addr = 0x220; 285 261 break; 262 + case ICP_LMEM2: 263 + reg_addr = 0x2c0; 264 + break; 265 + case ICP_LMEM3: 266 + reg_addr = 0x2e0; 267 + break; 286 268 case ICP_NO_DEST: 287 269 reg_addr = 0x300 | (reg_num & 0xff); 288 270 break; ··· 301 271 302 272 void qat_hal_reset(struct icp_qat_fw_loader_handle *handle) 303 273 { 304 - unsigned int ae_reset_csr; 274 + unsigned int reset_mask = handle->chip_info->icp_rst_mask; 275 + unsigned int reset_csr = handle->chip_info->icp_rst_csr; 276 + unsigned int csr_val; 305 277 306 - ae_reset_csr = GET_GLB_CSR(handle, ICP_RESET); 307 - ae_reset_csr |= handle->hal_handle->ae_mask << RST_CSR_AE_LSB; 308 - ae_reset_csr |= handle->hal_handle->slice_mask << RST_CSR_QAT_LSB; 309 - SET_GLB_CSR(handle, ICP_RESET, ae_reset_csr); 278 + csr_val = GET_CAP_CSR(handle, reset_csr); 279 + csr_val |= reset_mask; 280 + SET_CAP_CSR(handle, reset_csr, csr_val); 310 281 } 311 282 312 283 static void qat_hal_wr_indr_csr(struct icp_qat_fw_loader_handle *handle, ··· 377 346 378 347 static int qat_hal_check_ae_alive(struct icp_qat_fw_loader_handle *handle) 379 348 { 349 + unsigned long ae_mask = handle->hal_handle->ae_mask; 380 350 unsigned int base_cnt, cur_cnt; 381 351 unsigned char ae; 382 352 int times = MAX_RETRY_TIMES; 383 353 384 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 354 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 385 355 base_cnt = qat_hal_rd_ae_csr(handle, ae, PROFILE_COUNT); 386 356 base_cnt &= 0xffff; 387 357 ··· 416 384 417 385 static void qat_hal_reset_timestamp(struct icp_qat_fw_loader_handle *handle) 418 386 { 419 - unsigned int misc_ctl; 387 + unsigned long ae_mask = handle->hal_handle->ae_mask; 388 + unsigned int misc_ctl_csr, misc_ctl; 420 389 unsigned char ae; 421 390 391 + misc_ctl_csr = handle->chip_info->misc_ctl_csr; 422 392 /* stop the timestamp timers */ 423 - misc_ctl = GET_GLB_CSR(handle, MISC_CONTROL); 393 + misc_ctl = GET_CAP_CSR(handle, misc_ctl_csr); 424 394 if (misc_ctl & MC_TIMESTAMP_ENABLE) 425 - SET_GLB_CSR(handle, MISC_CONTROL, misc_ctl & 395 + SET_CAP_CSR(handle, misc_ctl_csr, misc_ctl & 426 396 (~MC_TIMESTAMP_ENABLE)); 427 397 428 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 398 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 429 399 qat_hal_wr_ae_csr(handle, ae, TIMESTAMP_LOW, 0); 430 400 qat_hal_wr_ae_csr(handle, ae, TIMESTAMP_HIGH, 0); 431 401 } 432 402 /* start timestamp timers */ 433 - SET_GLB_CSR(handle, MISC_CONTROL, misc_ctl | MC_TIMESTAMP_ENABLE); 403 + SET_CAP_CSR(handle, misc_ctl_csr, misc_ctl | MC_TIMESTAMP_ENABLE); 434 404 } 435 405 436 406 #define ESRAM_AUTO_TINIT BIT(2) ··· 462 428 qat_hal_wait_cycles(handle, 0, ESRAM_AUTO_INIT_USED_CYCLES, 0); 463 429 csr_val = ADF_CSR_RD(csr_addr, 0); 464 430 } while (!(csr_val & ESRAM_AUTO_TINIT_DONE) && times--); 465 - if ((times < 0)) { 431 + if (times < 0) { 466 432 pr_err("QAT: Fail to init eSram!\n"); 467 433 return -EFAULT; 468 434 } ··· 472 438 #define SHRAM_INIT_CYCLES 2060 473 439 int qat_hal_clr_reset(struct icp_qat_fw_loader_handle *handle) 474 440 { 475 - unsigned int ae_reset_csr; 476 - unsigned char ae; 477 - unsigned int clk_csr; 441 + unsigned int clk_csr = handle->chip_info->glb_clk_enable_csr; 442 + unsigned int reset_mask = handle->chip_info->icp_rst_mask; 443 + unsigned int reset_csr = handle->chip_info->icp_rst_csr; 444 + unsigned long ae_mask = handle->hal_handle->ae_mask; 445 + unsigned char ae = 0; 478 446 unsigned int times = 100; 479 - unsigned int csr; 447 + unsigned int csr_val; 480 448 481 449 /* write to the reset csr */ 482 - ae_reset_csr = GET_GLB_CSR(handle, ICP_RESET); 483 - ae_reset_csr &= ~(handle->hal_handle->ae_mask << RST_CSR_AE_LSB); 484 - ae_reset_csr &= ~(handle->hal_handle->slice_mask << RST_CSR_QAT_LSB); 450 + csr_val = GET_CAP_CSR(handle, reset_csr); 451 + csr_val &= ~reset_mask; 485 452 do { 486 - SET_GLB_CSR(handle, ICP_RESET, ae_reset_csr); 453 + SET_CAP_CSR(handle, reset_csr, csr_val); 487 454 if (!(times--)) 488 455 goto out_err; 489 - csr = GET_GLB_CSR(handle, ICP_RESET); 490 - } while ((handle->hal_handle->ae_mask | 491 - (handle->hal_handle->slice_mask << RST_CSR_QAT_LSB)) & csr); 456 + csr_val = GET_CAP_CSR(handle, reset_csr); 457 + csr_val &= reset_mask; 458 + } while (csr_val); 492 459 /* enable clock */ 493 - clk_csr = GET_GLB_CSR(handle, ICP_GLOBAL_CLK_ENABLE); 494 - clk_csr |= handle->hal_handle->ae_mask << 0; 495 - clk_csr |= handle->hal_handle->slice_mask << 20; 496 - SET_GLB_CSR(handle, ICP_GLOBAL_CLK_ENABLE, clk_csr); 460 + csr_val = GET_CAP_CSR(handle, clk_csr); 461 + csr_val |= reset_mask; 462 + SET_CAP_CSR(handle, clk_csr, csr_val); 497 463 if (qat_hal_check_ae_alive(handle)) 498 464 goto out_err; 499 465 500 466 /* Set undefined power-up/reset states to reasonable default values */ 501 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 467 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 502 468 qat_hal_wr_ae_csr(handle, ae, CTX_ENABLES, 503 469 INIT_CTX_ENABLE_VALUE); 504 470 qat_hal_wr_indr_csr(handle, ae, ICP_QAT_UCLO_AE_ALL_CTX, ··· 604 570 605 571 static void qat_hal_clear_xfer(struct icp_qat_fw_loader_handle *handle) 606 572 { 573 + unsigned long ae_mask = handle->hal_handle->ae_mask; 607 574 unsigned char ae; 608 575 unsigned short reg; 609 576 610 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 577 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 611 578 for (reg = 0; reg < ICP_QAT_UCLO_MAX_GPR_REG; reg++) { 612 579 qat_hal_init_rd_xfer(handle, ae, 0, ICP_SR_RD_ABS, 613 580 reg, 0); ··· 620 585 621 586 static int qat_hal_clear_gpr(struct icp_qat_fw_loader_handle *handle) 622 587 { 588 + unsigned long ae_mask = handle->hal_handle->ae_mask; 623 589 unsigned char ae; 624 590 unsigned int ctx_mask = ICP_QAT_UCLO_AE_ALL_CTX; 625 591 int times = MAX_RETRY_TIMES; ··· 628 592 unsigned int savctx = 0; 629 593 int ret = 0; 630 594 631 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 595 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 632 596 csr_val = qat_hal_rd_ae_csr(handle, ae, AE_MISC_CONTROL); 633 597 csr_val &= ~(1 << MMC_SHARE_CS_BITPOS); 634 598 qat_hal_wr_ae_csr(handle, ae, AE_MISC_CONTROL, csr_val); 635 599 csr_val = qat_hal_rd_ae_csr(handle, ae, CTX_ENABLES); 636 600 csr_val &= IGNORE_W1C_MASK; 637 - csr_val |= CE_NN_MODE; 601 + if (handle->chip_info->nn) 602 + csr_val |= CE_NN_MODE; 603 + 638 604 qat_hal_wr_ae_csr(handle, ae, CTX_ENABLES, csr_val); 639 605 qat_hal_wr_uwords(handle, ae, 0, ARRAY_SIZE(inst), 640 606 (u64 *)inst); ··· 651 613 qat_hal_wr_ae_csr(handle, ae, CTX_SIG_EVENTS_ACTIVE, 0); 652 614 qat_hal_enable_ctx(handle, ae, ctx_mask); 653 615 } 654 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 616 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 655 617 /* wait for AE to finish */ 656 618 do { 657 619 ret = qat_hal_wait_cycles(handle, ae, 20, 1); ··· 679 641 return 0; 680 642 } 681 643 682 - #define ICP_QAT_AE_OFFSET 0x20000 683 - #define ICP_QAT_CAP_OFFSET (ICP_QAT_AE_OFFSET + 0x10000) 684 - #define LOCAL_TO_XFER_REG_OFFSET 0x800 685 - #define ICP_QAT_EP_OFFSET 0x3a000 686 - int qat_hal_init(struct adf_accel_dev *accel_dev) 644 + static int qat_hal_chip_init(struct icp_qat_fw_loader_handle *handle, 645 + struct adf_accel_dev *accel_dev) 687 646 { 688 - unsigned char ae; 689 - unsigned int max_en_ae_id = 0; 690 - struct icp_qat_fw_loader_handle *handle; 691 647 struct adf_accel_pci *pci_info = &accel_dev->accel_pci_dev; 692 648 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 693 649 struct adf_bar *misc_bar = 694 650 &pci_info->pci_bars[hw_data->get_misc_bar_id(hw_data)]; 651 + unsigned int max_en_ae_id = 0; 695 652 struct adf_bar *sram_bar; 653 + unsigned int csr_val = 0; 654 + unsigned long ae_mask; 655 + unsigned char ae = 0; 656 + int ret = 0; 696 657 697 - handle = kzalloc(sizeof(*handle), GFP_KERNEL); 698 - if (!handle) 699 - return -ENOMEM; 700 - 701 - handle->hal_cap_g_ctl_csr_addr_v = 702 - (void __iomem *)((uintptr_t)misc_bar->virt_addr + 703 - ICP_QAT_CAP_OFFSET); 704 - handle->hal_cap_ae_xfer_csr_addr_v = 705 - (void __iomem *)((uintptr_t)misc_bar->virt_addr + 706 - ICP_QAT_AE_OFFSET); 707 - handle->hal_ep_csr_addr_v = 708 - (void __iomem *)((uintptr_t)misc_bar->virt_addr + 709 - ICP_QAT_EP_OFFSET); 710 - handle->hal_cap_ae_local_csr_addr_v = 711 - (void __iomem *)((uintptr_t)handle->hal_cap_ae_xfer_csr_addr_v + 712 - LOCAL_TO_XFER_REG_OFFSET); 713 658 handle->pci_dev = pci_info->pci_dev; 714 - if (handle->pci_dev->device == PCI_DEVICE_ID_INTEL_QAT_DH895XCC) { 659 + switch (handle->pci_dev->device) { 660 + case ADF_4XXX_PCI_DEVICE_ID: 661 + handle->chip_info->sram_visible = false; 662 + handle->chip_info->nn = false; 663 + handle->chip_info->lm2lm3 = true; 664 + handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG_2X; 665 + handle->chip_info->icp_rst_csr = ICP_RESET_CPP0; 666 + handle->chip_info->icp_rst_mask = 0x100015; 667 + handle->chip_info->glb_clk_enable_csr = ICP_GLOBAL_CLK_ENABLE_CPP0; 668 + handle->chip_info->misc_ctl_csr = MISC_CONTROL_C4XXX; 669 + handle->chip_info->wakeup_event_val = 0x80000000; 670 + handle->chip_info->fw_auth = true; 671 + handle->chip_info->css_3k = true; 672 + handle->chip_info->tgroup_share_ustore = true; 673 + handle->chip_info->fcu_ctl_csr = FCU_CONTROL_4XXX; 674 + handle->chip_info->fcu_sts_csr = FCU_STATUS_4XXX; 675 + handle->chip_info->fcu_dram_addr_hi = FCU_DRAM_ADDR_HI_4XXX; 676 + handle->chip_info->fcu_dram_addr_lo = FCU_DRAM_ADDR_LO_4XXX; 677 + handle->chip_info->fcu_loaded_ae_csr = FCU_AE_LOADED_4XXX; 678 + handle->chip_info->fcu_loaded_ae_pos = 0; 679 + 680 + handle->hal_cap_g_ctl_csr_addr_v = 681 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 682 + ICP_QAT_CAP_OFFSET_4XXX); 683 + handle->hal_cap_ae_xfer_csr_addr_v = 684 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 685 + ICP_QAT_AE_OFFSET_4XXX); 686 + handle->hal_ep_csr_addr_v = 687 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 688 + ICP_QAT_EP_OFFSET_4XXX); 689 + handle->hal_cap_ae_local_csr_addr_v = 690 + (void __iomem *)((uintptr_t)handle->hal_cap_ae_xfer_csr_addr_v 691 + + LOCAL_TO_XFER_REG_OFFSET); 692 + break; 693 + case PCI_DEVICE_ID_INTEL_QAT_C62X: 694 + case PCI_DEVICE_ID_INTEL_QAT_C3XXX: 695 + handle->chip_info->sram_visible = false; 696 + handle->chip_info->nn = true; 697 + handle->chip_info->lm2lm3 = false; 698 + handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG; 699 + handle->chip_info->icp_rst_csr = ICP_RESET; 700 + handle->chip_info->icp_rst_mask = (hw_data->ae_mask << RST_CSR_AE_LSB) | 701 + (hw_data->accel_mask << RST_CSR_QAT_LSB); 702 + handle->chip_info->glb_clk_enable_csr = ICP_GLOBAL_CLK_ENABLE; 703 + handle->chip_info->misc_ctl_csr = MISC_CONTROL; 704 + handle->chip_info->wakeup_event_val = WAKEUP_EVENT; 705 + handle->chip_info->fw_auth = true; 706 + handle->chip_info->css_3k = false; 707 + handle->chip_info->tgroup_share_ustore = false; 708 + handle->chip_info->fcu_ctl_csr = FCU_CONTROL; 709 + handle->chip_info->fcu_sts_csr = FCU_STATUS; 710 + handle->chip_info->fcu_dram_addr_hi = FCU_DRAM_ADDR_HI; 711 + handle->chip_info->fcu_dram_addr_lo = FCU_DRAM_ADDR_LO; 712 + handle->chip_info->fcu_loaded_ae_csr = FCU_STATUS; 713 + handle->chip_info->fcu_loaded_ae_pos = FCU_LOADED_AE_POS; 714 + handle->hal_cap_g_ctl_csr_addr_v = 715 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 716 + ICP_QAT_CAP_OFFSET); 717 + handle->hal_cap_ae_xfer_csr_addr_v = 718 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 719 + ICP_QAT_AE_OFFSET); 720 + handle->hal_ep_csr_addr_v = 721 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 722 + ICP_QAT_EP_OFFSET); 723 + handle->hal_cap_ae_local_csr_addr_v = 724 + (void __iomem *)((uintptr_t)handle->hal_cap_ae_xfer_csr_addr_v 725 + + LOCAL_TO_XFER_REG_OFFSET); 726 + break; 727 + case PCI_DEVICE_ID_INTEL_QAT_DH895XCC: 728 + handle->chip_info->sram_visible = true; 729 + handle->chip_info->nn = true; 730 + handle->chip_info->lm2lm3 = false; 731 + handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG; 732 + handle->chip_info->icp_rst_csr = ICP_RESET; 733 + handle->chip_info->icp_rst_mask = (hw_data->ae_mask << RST_CSR_AE_LSB) | 734 + (hw_data->accel_mask << RST_CSR_QAT_LSB); 735 + handle->chip_info->glb_clk_enable_csr = ICP_GLOBAL_CLK_ENABLE; 736 + handle->chip_info->misc_ctl_csr = MISC_CONTROL; 737 + handle->chip_info->wakeup_event_val = WAKEUP_EVENT; 738 + handle->chip_info->fw_auth = false; 739 + handle->chip_info->css_3k = false; 740 + handle->chip_info->tgroup_share_ustore = false; 741 + handle->chip_info->fcu_ctl_csr = 0; 742 + handle->chip_info->fcu_sts_csr = 0; 743 + handle->chip_info->fcu_dram_addr_hi = 0; 744 + handle->chip_info->fcu_dram_addr_lo = 0; 745 + handle->chip_info->fcu_loaded_ae_csr = 0; 746 + handle->chip_info->fcu_loaded_ae_pos = 0; 747 + handle->hal_cap_g_ctl_csr_addr_v = 748 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 749 + ICP_QAT_CAP_OFFSET); 750 + handle->hal_cap_ae_xfer_csr_addr_v = 751 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 752 + ICP_QAT_AE_OFFSET); 753 + handle->hal_ep_csr_addr_v = 754 + (void __iomem *)((uintptr_t)misc_bar->virt_addr + 755 + ICP_QAT_EP_OFFSET); 756 + handle->hal_cap_ae_local_csr_addr_v = 757 + (void __iomem *)((uintptr_t)handle->hal_cap_ae_xfer_csr_addr_v 758 + + LOCAL_TO_XFER_REG_OFFSET); 759 + break; 760 + default: 761 + ret = -EINVAL; 762 + goto out_err; 763 + } 764 + 765 + if (handle->chip_info->sram_visible) { 715 766 sram_bar = 716 767 &pci_info->pci_bars[hw_data->get_sram_bar_id(hw_data)]; 717 768 handle->hal_sram_addr_v = sram_bar->virt_addr; 718 769 } 719 - handle->fw_auth = (handle->pci_dev->device == 720 - PCI_DEVICE_ID_INTEL_QAT_DH895XCC) ? false : true; 721 - handle->hal_handle = kzalloc(sizeof(*handle->hal_handle), GFP_KERNEL); 722 - if (!handle->hal_handle) 723 - goto out_hal_handle; 724 770 handle->hal_handle->revision_id = accel_dev->accel_pci_dev.revid; 725 771 handle->hal_handle->ae_mask = hw_data->ae_mask; 772 + handle->hal_handle->admin_ae_mask = hw_data->admin_ae_mask; 726 773 handle->hal_handle->slice_mask = hw_data->accel_mask; 774 + handle->cfg_ae_mask = ALL_AE_MASK; 727 775 /* create AE objects */ 728 776 handle->hal_handle->upc_mask = 0x1ffff; 729 777 handle->hal_handle->max_ustore = 0x4000; 730 - for (ae = 0; ae < ICP_QAT_UCLO_MAX_AE; ae++) { 731 - if (!(hw_data->ae_mask & (1 << ae))) 732 - continue; 778 + 779 + ae_mask = handle->hal_handle->ae_mask; 780 + for_each_set_bit(ae, &ae_mask, ICP_QAT_UCLO_MAX_AE) { 733 781 handle->hal_handle->aes[ae].free_addr = 0; 734 782 handle->hal_handle->aes[ae].free_size = 735 783 handle->hal_handle->max_ustore; ··· 826 702 max_en_ae_id = ae; 827 703 } 828 704 handle->hal_handle->ae_max_num = max_en_ae_id + 1; 829 - /* take all AEs out of reset */ 830 - if (qat_hal_clr_reset(handle)) { 831 - dev_err(&GET_DEV(accel_dev), "qat_hal_clr_reset error\n"); 832 - goto out_err; 833 - } 834 - qat_hal_clear_xfer(handle); 835 - if (!handle->fw_auth) { 836 - if (qat_hal_clear_gpr(handle)) 837 - goto out_err; 838 - } 839 705 840 706 /* Set SIGNATURE_ENABLE[0] to 0x1 in order to enable ALU_OUT csr */ 841 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 842 - unsigned int csr_val = 0; 843 - 707 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 844 708 csr_val = qat_hal_rd_ae_csr(handle, ae, SIGNATURE_ENABLE); 845 709 csr_val |= 0x1; 846 710 qat_hal_wr_ae_csr(handle, ae, SIGNATURE_ENABLE, csr_val); 847 711 } 712 + out_err: 713 + return ret; 714 + } 715 + 716 + int qat_hal_init(struct adf_accel_dev *accel_dev) 717 + { 718 + struct icp_qat_fw_loader_handle *handle; 719 + int ret = 0; 720 + 721 + handle = kzalloc(sizeof(*handle), GFP_KERNEL); 722 + if (!handle) 723 + return -ENOMEM; 724 + 725 + handle->hal_handle = kzalloc(sizeof(*handle->hal_handle), GFP_KERNEL); 726 + if (!handle->hal_handle) { 727 + ret = -ENOMEM; 728 + goto out_hal_handle; 729 + } 730 + 731 + handle->chip_info = kzalloc(sizeof(*handle->chip_info), GFP_KERNEL); 732 + if (!handle->chip_info) { 733 + ret = -ENOMEM; 734 + goto out_chip_info; 735 + } 736 + 737 + ret = qat_hal_chip_init(handle, accel_dev); 738 + if (ret) { 739 + dev_err(&GET_DEV(accel_dev), "qat_hal_chip_init error\n"); 740 + goto out_err; 741 + } 742 + 743 + /* take all AEs out of reset */ 744 + ret = qat_hal_clr_reset(handle); 745 + if (ret) { 746 + dev_err(&GET_DEV(accel_dev), "qat_hal_clr_reset error\n"); 747 + goto out_err; 748 + } 749 + 750 + qat_hal_clear_xfer(handle); 751 + if (!handle->chip_info->fw_auth) { 752 + ret = qat_hal_clear_gpr(handle); 753 + if (ret) 754 + goto out_err; 755 + } 756 + 848 757 accel_dev->fw_loader->fw_loader = handle; 849 758 return 0; 850 759 851 760 out_err: 761 + kfree(handle->chip_info); 762 + out_chip_info: 852 763 kfree(handle->hal_handle); 853 764 out_hal_handle: 854 765 kfree(handle); 855 - return -EFAULT; 766 + return ret; 856 767 } 857 768 858 769 void qat_hal_deinit(struct icp_qat_fw_loader_handle *handle) 859 770 { 860 771 if (!handle) 861 772 return; 773 + kfree(handle->chip_info); 862 774 kfree(handle->hal_handle); 863 775 kfree(handle); 864 776 } 865 777 866 - void qat_hal_start(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 867 - unsigned int ctx_mask) 778 + int qat_hal_start(struct icp_qat_fw_loader_handle *handle) 868 779 { 780 + unsigned long ae_mask = handle->hal_handle->ae_mask; 781 + u32 wakeup_val = handle->chip_info->wakeup_event_val; 782 + u32 fcu_ctl_csr, fcu_sts_csr; 783 + unsigned int fcu_sts; 784 + unsigned char ae; 785 + u32 ae_ctr = 0; 869 786 int retry = 0; 870 - unsigned int fcu_sts = 0; 871 787 872 - if (handle->fw_auth) { 873 - SET_CAP_CSR(handle, FCU_CONTROL, FCU_CTRL_CMD_START); 788 + if (handle->chip_info->fw_auth) { 789 + fcu_ctl_csr = handle->chip_info->fcu_ctl_csr; 790 + fcu_sts_csr = handle->chip_info->fcu_sts_csr; 791 + ae_ctr = hweight32(ae_mask); 792 + SET_CAP_CSR(handle, fcu_ctl_csr, FCU_CTRL_CMD_START); 874 793 do { 875 794 msleep(FW_AUTH_WAIT_PERIOD); 876 - fcu_sts = GET_CAP_CSR(handle, FCU_STATUS); 795 + fcu_sts = GET_CAP_CSR(handle, fcu_sts_csr); 877 796 if (((fcu_sts >> FCU_STS_DONE_POS) & 0x1)) 878 - return; 797 + return ae_ctr; 879 798 } while (retry++ < FW_AUTH_MAX_RETRY); 880 - pr_err("QAT: start error (AE 0x%x FCU_STS = 0x%x)\n", ae, 881 - fcu_sts); 799 + pr_err("QAT: start error (FCU_STS = 0x%x)\n", fcu_sts); 800 + return 0; 882 801 } else { 883 - qat_hal_put_wakeup_event(handle, ae, (~ctx_mask) & 884 - ICP_QAT_UCLO_AE_ALL_CTX, 0x10000); 885 - qat_hal_enable_ctx(handle, ae, ctx_mask); 802 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 803 + qat_hal_put_wakeup_event(handle, ae, 0, wakeup_val); 804 + qat_hal_enable_ctx(handle, ae, ICP_QAT_UCLO_AE_ALL_CTX); 805 + ae_ctr++; 806 + } 807 + return ae_ctr; 886 808 } 887 809 } 888 810 889 811 void qat_hal_stop(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 890 812 unsigned int ctx_mask) 891 813 { 892 - if (!handle->fw_auth) 814 + if (!handle->chip_info->fw_auth) 893 815 qat_hal_disable_ctx(handle, ae, ctx_mask); 894 816 } 895 817 ··· 1002 832 int code_off, unsigned int max_cycle, 1003 833 unsigned int *endpc) 1004 834 { 835 + unsigned int ind_lm_addr_byte0 = 0, ind_lm_addr_byte1 = 0; 836 + unsigned int ind_lm_addr_byte2 = 0, ind_lm_addr_byte3 = 0; 837 + unsigned int ind_t_index = 0, ind_t_index_byte = 0; 838 + unsigned int ind_lm_addr0 = 0, ind_lm_addr1 = 0; 839 + unsigned int ind_lm_addr2 = 0, ind_lm_addr3 = 0; 1005 840 u64 savuwords[MAX_EXEC_INST]; 1006 - unsigned int ind_lm_addr0, ind_lm_addr1; 1007 - unsigned int ind_lm_addr_byte0, ind_lm_addr_byte1; 1008 841 unsigned int ind_cnt_sig; 1009 842 unsigned int ind_sig, act_sig; 1010 843 unsigned int csr_val = 0, newcsr_val; ··· 1026 853 INDIRECT_LM_ADDR_0_BYTE_INDEX); 1027 854 ind_lm_addr_byte1 = qat_hal_rd_indr_csr(handle, ae, ctx, 1028 855 INDIRECT_LM_ADDR_1_BYTE_INDEX); 856 + if (handle->chip_info->lm2lm3) { 857 + ind_lm_addr2 = qat_hal_rd_indr_csr(handle, ae, ctx, 858 + LM_ADDR_2_INDIRECT); 859 + ind_lm_addr3 = qat_hal_rd_indr_csr(handle, ae, ctx, 860 + LM_ADDR_3_INDIRECT); 861 + ind_lm_addr_byte2 = qat_hal_rd_indr_csr(handle, ae, ctx, 862 + INDIRECT_LM_ADDR_2_BYTE_INDEX); 863 + ind_lm_addr_byte3 = qat_hal_rd_indr_csr(handle, ae, ctx, 864 + INDIRECT_LM_ADDR_3_BYTE_INDEX); 865 + ind_t_index = qat_hal_rd_indr_csr(handle, ae, ctx, 866 + INDIRECT_T_INDEX); 867 + ind_t_index_byte = qat_hal_rd_indr_csr(handle, ae, ctx, 868 + INDIRECT_T_INDEX_BYTE_INDEX); 869 + } 1029 870 if (inst_num <= MAX_EXEC_INST) 1030 871 qat_hal_get_uwords(handle, ae, 0, inst_num, savuwords); 1031 872 qat_hal_get_wakeup_event(handle, ae, ctx, &wakeup_events); ··· 1097 910 INDIRECT_LM_ADDR_0_BYTE_INDEX, ind_lm_addr_byte0); 1098 911 qat_hal_wr_indr_csr(handle, ae, (1 << ctx), 1099 912 INDIRECT_LM_ADDR_1_BYTE_INDEX, ind_lm_addr_byte1); 913 + if (handle->chip_info->lm2lm3) { 914 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), LM_ADDR_2_INDIRECT, 915 + ind_lm_addr2); 916 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), LM_ADDR_3_INDIRECT, 917 + ind_lm_addr3); 918 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), 919 + INDIRECT_LM_ADDR_2_BYTE_INDEX, 920 + ind_lm_addr_byte2); 921 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), 922 + INDIRECT_LM_ADDR_3_BYTE_INDEX, 923 + ind_lm_addr_byte3); 924 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), 925 + INDIRECT_T_INDEX, ind_t_index); 926 + qat_hal_wr_indr_csr(handle, ae, BIT(ctx), 927 + INDIRECT_T_INDEX_BYTE_INDEX, 928 + ind_t_index_byte); 929 + } 1100 930 qat_hal_wr_indr_csr(handle, ae, (1 << ctx), 1101 931 FUTURE_COUNT_SIGNAL_INDIRECT, ind_cnt_sig); 1102 932 qat_hal_wr_indr_csr(handle, ae, (1 << ctx), ··· 1329 1125 plm_init = plm_init->next; 1330 1126 } 1331 1127 /* exec micro codes */ 1332 - if (micro_inst_arry && (micro_inst_num > 0)) { 1128 + if (micro_inst_arry && micro_inst_num > 0) { 1333 1129 micro_inst_arry[micro_inst_num++] = 0x0E000010000ull; 1334 1130 stat = qat_hal_exec_micro_init_lm(handle, ae, 0, &first_exec, 1335 1131 micro_inst_arry, ··· 1350 1146 unsigned short mask; 1351 1147 unsigned short dr_offset = 0x10; 1352 1148 1353 - status = ctx_enables = qat_hal_rd_ae_csr(handle, ae, CTX_ENABLES); 1149 + ctx_enables = qat_hal_rd_ae_csr(handle, ae, CTX_ENABLES); 1354 1150 if (CE_INUSE_CONTEXTS & ctx_enables) { 1355 1151 if (ctx & 0x1) { 1356 1152 pr_err("QAT: bad 4-ctx mode,ctx=0x%x\n", ctx); ··· 1475 1271 } 1476 1272 1477 1273 int qat_hal_init_gpr(struct icp_qat_fw_loader_handle *handle, 1478 - unsigned char ae, unsigned char ctx_mask, 1274 + unsigned char ae, unsigned long ctx_mask, 1479 1275 enum icp_qat_uof_regtype reg_type, 1480 1276 unsigned short reg_num, unsigned int regdata) 1481 1277 { ··· 1495 1291 } else { 1496 1292 reg = reg_num; 1497 1293 type = reg_type; 1498 - if (!test_bit(ctx, (unsigned long *)&ctx_mask)) 1294 + if (!test_bit(ctx, &ctx_mask)) 1499 1295 continue; 1500 1296 } 1501 1297 stat = qat_hal_wr_rel_reg(handle, ae, ctx, type, reg, regdata); ··· 1509 1305 } 1510 1306 1511 1307 int qat_hal_init_wr_xfer(struct icp_qat_fw_loader_handle *handle, 1512 - unsigned char ae, unsigned char ctx_mask, 1308 + unsigned char ae, unsigned long ctx_mask, 1513 1309 enum icp_qat_uof_regtype reg_type, 1514 1310 unsigned short reg_num, unsigned int regdata) 1515 1311 { ··· 1529 1325 } else { 1530 1326 reg = reg_num; 1531 1327 type = reg_type; 1532 - if (!test_bit(ctx, (unsigned long *)&ctx_mask)) 1328 + if (!test_bit(ctx, &ctx_mask)) 1533 1329 continue; 1534 1330 } 1535 1331 stat = qat_hal_put_rel_wr_xfer(handle, ae, ctx, type, reg, ··· 1544 1340 } 1545 1341 1546 1342 int qat_hal_init_rd_xfer(struct icp_qat_fw_loader_handle *handle, 1547 - unsigned char ae, unsigned char ctx_mask, 1343 + unsigned char ae, unsigned long ctx_mask, 1548 1344 enum icp_qat_uof_regtype reg_type, 1549 1345 unsigned short reg_num, unsigned int regdata) 1550 1346 { ··· 1564 1360 } else { 1565 1361 reg = reg_num; 1566 1362 type = reg_type; 1567 - if (!test_bit(ctx, (unsigned long *)&ctx_mask)) 1363 + if (!test_bit(ctx, &ctx_mask)) 1568 1364 continue; 1569 1365 } 1570 1366 stat = qat_hal_put_rel_rd_xfer(handle, ae, ctx, type, reg, ··· 1579 1375 } 1580 1376 1581 1377 int qat_hal_init_nn(struct icp_qat_fw_loader_handle *handle, 1582 - unsigned char ae, unsigned char ctx_mask, 1378 + unsigned char ae, unsigned long ctx_mask, 1583 1379 unsigned short reg_num, unsigned int regdata) 1584 1380 { 1585 1381 int stat = 0; 1586 1382 unsigned char ctx; 1383 + if (!handle->chip_info->nn) { 1384 + dev_err(&handle->pci_dev->dev, "QAT: No next neigh in 0x%x\n", 1385 + handle->pci_dev->device); 1386 + return -EINVAL; 1387 + } 1587 1388 1588 1389 if (ctx_mask == 0) 1589 1390 return -EINVAL; 1590 1391 1591 1392 for (ctx = 0; ctx < ICP_QAT_UCLO_MAX_CTX; ctx++) { 1592 - if (!test_bit(ctx, (unsigned long *)&ctx_mask)) 1393 + if (!test_bit(ctx, &ctx_mask)) 1593 1394 continue; 1594 1395 stat = qat_hal_put_rel_nn(handle, ae, ctx, reg_num, regdata); 1595 1396 if (stat) {
+589 -148
drivers/crypto/qat/qat_common/qat_uclo.c
··· 74 74 static char *qat_uclo_get_string(struct icp_qat_uof_strtable *str_table, 75 75 unsigned int str_offset) 76 76 { 77 - if ((!str_table->table_len) || (str_offset > str_table->table_len)) 77 + if (!str_table->table_len || str_offset > str_table->table_len) 78 78 return NULL; 79 79 return (char *)(((uintptr_t)(str_table->strings)) + str_offset); 80 80 } ··· 311 311 unsigned int ae; 312 312 313 313 if (qat_uclo_fetch_initmem_ae(handle, init_mem, 314 - ICP_QAT_UCLO_MAX_LMEM_REG, &ae)) 314 + handle->chip_info->lm_size, &ae)) 315 315 return -EINVAL; 316 316 if (qat_uclo_create_batch_init_list(handle, init_mem, ae, 317 317 &obj_handle->lm_init_tab[ae])) ··· 324 324 { 325 325 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 326 326 unsigned int ae, ustore_size, uaddr, i; 327 + struct icp_qat_uclo_aedata *aed; 327 328 328 329 ustore_size = obj_handle->ustore_phy_size; 329 330 if (qat_uclo_fetch_initmem_ae(handle, init_mem, ustore_size, &ae)) ··· 334 333 return -EINVAL; 335 334 /* set the highest ustore address referenced */ 336 335 uaddr = (init_mem->addr + init_mem->num_in_bytes) >> 0x2; 337 - for (i = 0; i < obj_handle->ae_data[ae].slice_num; i++) { 338 - if (obj_handle->ae_data[ae].ae_slices[i]. 339 - encap_image->uwords_num < uaddr) 340 - obj_handle->ae_data[ae].ae_slices[i]. 341 - encap_image->uwords_num = uaddr; 336 + aed = &obj_handle->ae_data[ae]; 337 + for (i = 0; i < aed->slice_num; i++) { 338 + if (aed->ae_slices[i].encap_image->uwords_num < uaddr) 339 + aed->ae_slices[i].encap_image->uwords_num = uaddr; 342 340 } 343 341 return 0; 344 342 } ··· 373 373 unsigned int ustore_size; 374 374 unsigned int patt_pos; 375 375 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 376 + unsigned long ae_mask = handle->hal_handle->ae_mask; 377 + unsigned long cfg_ae_mask = handle->cfg_ae_mask; 376 378 u64 *fill_data; 377 379 378 380 uof_image = image->img_ptr; ··· 387 385 sizeof(u64)); 388 386 page = image->page; 389 387 390 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 388 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 391 389 if (!test_bit(ae, (unsigned long *)&uof_image->ae_assigned)) 392 390 continue; 391 + 392 + if (!test_bit(ae, &cfg_ae_mask)) 393 + continue; 394 + 393 395 ustore_size = obj_handle->ae_data[ae].eff_ustore_size; 394 396 patt_pos = page->beg_addr_p + page->micro_words_num; 395 397 ··· 412 406 int i, ae; 413 407 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 414 408 struct icp_qat_uof_initmem *initmem = obj_handle->init_mem_tab.init_mem; 409 + unsigned long ae_mask = handle->hal_handle->ae_mask; 415 410 416 411 for (i = 0; i < obj_handle->init_mem_tab.entry_num; i++) { 417 412 if (initmem->num_in_bytes) { ··· 425 418 (sizeof(struct icp_qat_uof_memvar_attr) * 426 419 initmem->val_attr_num)); 427 420 } 428 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 421 + 422 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 429 423 if (qat_hal_batch_wr_lm(handle, ae, 430 424 obj_handle->lm_init_tab[ae])) { 431 425 pr_err("QAT: fail to batch init lmem for AE %d\n", ae); ··· 544 536 (encap_uof_obj->beg_uof + 545 537 code_page->neigh_reg_tab_offset); 546 538 if (neigh_reg_tab->entry_num) { 547 - pr_err("QAT: UOF can't contain shared control store feature\n"); 539 + pr_err("QAT: UOF can't contain neighbor register table\n"); 548 540 return -EINVAL; 549 541 } 550 542 if (image->numpages > 1) { ··· 657 649 int i, ae; 658 650 int mflag = 0; 659 651 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 652 + unsigned long ae_mask = handle->hal_handle->ae_mask; 653 + unsigned long cfg_ae_mask = handle->cfg_ae_mask; 660 654 661 - for (ae = 0; ae < max_ae; ae++) { 662 - if (!test_bit(ae, 663 - (unsigned long *)&handle->hal_handle->ae_mask)) 655 + for_each_set_bit(ae, &ae_mask, max_ae) { 656 + if (!test_bit(ae, &cfg_ae_mask)) 664 657 continue; 658 + 665 659 for (i = 0; i < obj_handle->uimage_num; i++) { 666 660 if (!test_bit(ae, (unsigned long *) 667 661 &obj_handle->ae_uimage[i].img_ptr->ae_assigned)) ··· 728 718 return ICP_QAT_AC_C62X_DEV_TYPE; 729 719 case PCI_DEVICE_ID_INTEL_QAT_C3XXX: 730 720 return ICP_QAT_AC_C3XXX_DEV_TYPE; 721 + case ADF_4XXX_PCI_DEVICE_ID: 722 + return ICP_QAT_AC_4XXX_A_DEV_TYPE; 731 723 default: 732 724 pr_err("QAT: unsupported device 0x%x\n", 733 725 handle->pci_dev->device); ··· 748 736 return -EINVAL; 749 737 } 750 738 maj_ver = obj_handle->prod_rev & 0xff; 751 - if ((obj_handle->encap_uof_obj.obj_hdr->max_cpu_ver < maj_ver) || 752 - (obj_handle->encap_uof_obj.obj_hdr->min_cpu_ver > maj_ver)) { 739 + if (obj_handle->encap_uof_obj.obj_hdr->max_cpu_ver < maj_ver || 740 + obj_handle->encap_uof_obj.obj_hdr->min_cpu_ver > maj_ver) { 753 741 pr_err("QAT: UOF majVer 0x%x out of range\n", maj_ver); 754 742 return -EINVAL; 755 743 } ··· 857 845 static int qat_uclo_init_globals(struct icp_qat_fw_loader_handle *handle) 858 846 { 859 847 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 848 + unsigned long ae_mask = handle->hal_handle->ae_mask; 849 + struct icp_qat_uclo_aedata *aed; 860 850 unsigned int s, ae; 861 851 862 852 if (obj_handle->global_inited) ··· 869 855 return -EINVAL; 870 856 } 871 857 } 872 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 873 - for (s = 0; s < obj_handle->ae_data[ae].slice_num; s++) { 874 - if (!obj_handle->ae_data[ae].ae_slices[s].encap_image) 858 + 859 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 860 + aed = &obj_handle->ae_data[ae]; 861 + for (s = 0; s < aed->slice_num; s++) { 862 + if (!aed->ae_slices[s].encap_image) 875 863 continue; 876 - if (qat_uclo_init_reg_sym(handle, ae, 877 - obj_handle->ae_data[ae]. 878 - ae_slices[s].encap_image)) 864 + if (qat_uclo_init_reg_sym(handle, ae, aed->ae_slices[s].encap_image)) 879 865 return -EINVAL; 880 866 } 881 867 } ··· 883 869 return 0; 884 870 } 885 871 872 + static int qat_hal_set_modes(struct icp_qat_fw_loader_handle *handle, 873 + struct icp_qat_uclo_objhandle *obj_handle, 874 + unsigned char ae, 875 + struct icp_qat_uof_image *uof_image) 876 + { 877 + unsigned char mode; 878 + int ret; 879 + 880 + mode = ICP_QAT_CTX_MODE(uof_image->ae_mode); 881 + ret = qat_hal_set_ae_ctx_mode(handle, ae, mode); 882 + if (ret) { 883 + pr_err("QAT: qat_hal_set_ae_ctx_mode error\n"); 884 + return ret; 885 + } 886 + if (handle->chip_info->nn) { 887 + mode = ICP_QAT_NN_MODE(uof_image->ae_mode); 888 + ret = qat_hal_set_ae_nn_mode(handle, ae, mode); 889 + if (ret) { 890 + pr_err("QAT: qat_hal_set_ae_nn_mode error\n"); 891 + return ret; 892 + } 893 + } 894 + mode = ICP_QAT_LOC_MEM0_MODE(uof_image->ae_mode); 895 + ret = qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM0, mode); 896 + if (ret) { 897 + pr_err("QAT: qat_hal_set_ae_lm_mode LMEM0 error\n"); 898 + return ret; 899 + } 900 + mode = ICP_QAT_LOC_MEM1_MODE(uof_image->ae_mode); 901 + ret = qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM1, mode); 902 + if (ret) { 903 + pr_err("QAT: qat_hal_set_ae_lm_mode LMEM1 error\n"); 904 + return ret; 905 + } 906 + if (handle->chip_info->lm2lm3) { 907 + mode = ICP_QAT_LOC_MEM2_MODE(uof_image->ae_mode); 908 + ret = qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM2, mode); 909 + if (ret) { 910 + pr_err("QAT: qat_hal_set_ae_lm_mode LMEM2 error\n"); 911 + return ret; 912 + } 913 + mode = ICP_QAT_LOC_MEM3_MODE(uof_image->ae_mode); 914 + ret = qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM3, mode); 915 + if (ret) { 916 + pr_err("QAT: qat_hal_set_ae_lm_mode LMEM3 error\n"); 917 + return ret; 918 + } 919 + mode = ICP_QAT_LOC_TINDEX_MODE(uof_image->ae_mode); 920 + qat_hal_set_ae_tindex_mode(handle, ae, mode); 921 + } 922 + return 0; 923 + } 924 + 886 925 static int qat_uclo_set_ae_mode(struct icp_qat_fw_loader_handle *handle) 887 926 { 888 - unsigned char ae, nn_mode, s; 889 927 struct icp_qat_uof_image *uof_image; 890 928 struct icp_qat_uclo_aedata *ae_data; 891 929 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 930 + unsigned long ae_mask = handle->hal_handle->ae_mask; 931 + unsigned long cfg_ae_mask = handle->cfg_ae_mask; 932 + unsigned char ae, s; 933 + int error; 892 934 893 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 894 - if (!test_bit(ae, 895 - (unsigned long *)&handle->hal_handle->ae_mask)) 935 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 936 + if (!test_bit(ae, &cfg_ae_mask)) 896 937 continue; 938 + 897 939 ae_data = &obj_handle->ae_data[ae]; 898 940 for (s = 0; s < min_t(unsigned int, ae_data->slice_num, 899 941 ICP_QAT_UCLO_MAX_CTX); s++) { 900 942 if (!obj_handle->ae_data[ae].ae_slices[s].encap_image) 901 943 continue; 902 944 uof_image = ae_data->ae_slices[s].encap_image->img_ptr; 903 - if (qat_hal_set_ae_ctx_mode(handle, ae, 904 - (char)ICP_QAT_CTX_MODE 905 - (uof_image->ae_mode))) { 906 - pr_err("QAT: qat_hal_set_ae_ctx_mode error\n"); 907 - return -EFAULT; 908 - } 909 - nn_mode = ICP_QAT_NN_MODE(uof_image->ae_mode); 910 - if (qat_hal_set_ae_nn_mode(handle, ae, nn_mode)) { 911 - pr_err("QAT: qat_hal_set_ae_nn_mode error\n"); 912 - return -EFAULT; 913 - } 914 - if (qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM0, 915 - (char)ICP_QAT_LOC_MEM0_MODE 916 - (uof_image->ae_mode))) { 917 - pr_err("QAT: qat_hal_set_ae_lm_mode LMEM0 error\n"); 918 - return -EFAULT; 919 - } 920 - if (qat_hal_set_ae_lm_mode(handle, ae, ICP_LMEM1, 921 - (char)ICP_QAT_LOC_MEM1_MODE 922 - (uof_image->ae_mode))) { 923 - pr_err("QAT: qat_hal_set_ae_lm_mode LMEM1 error\n"); 924 - return -EFAULT; 925 - } 945 + error = qat_hal_set_modes(handle, obj_handle, ae, 946 + uof_image); 947 + if (error) 948 + return error; 926 949 } 927 950 } 928 951 return 0; ··· 1054 1003 return 0; 1055 1004 } 1056 1005 1057 - static void qat_uclo_map_simg(struct icp_qat_suof_handle *suof_handle, 1006 + static void qat_uclo_map_simg(struct icp_qat_fw_loader_handle *handle, 1058 1007 struct icp_qat_suof_img_hdr *suof_img_hdr, 1059 1008 struct icp_qat_suof_chunk_hdr *suof_chunk_hdr) 1060 1009 { 1010 + struct icp_qat_suof_handle *suof_handle = handle->sobj_handle; 1061 1011 struct icp_qat_simg_ae_mode *ae_mode; 1062 1012 struct icp_qat_suof_objhdr *suof_objhdr; 1063 1013 ··· 1073 1021 suof_img_hdr->css_key = (suof_img_hdr->css_header + 1074 1022 sizeof(struct icp_qat_css_hdr)); 1075 1023 suof_img_hdr->css_signature = suof_img_hdr->css_key + 1076 - ICP_QAT_CSS_FWSK_MODULUS_LEN + 1077 - ICP_QAT_CSS_FWSK_EXPONENT_LEN; 1024 + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + 1025 + ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle); 1078 1026 suof_img_hdr->css_simg = suof_img_hdr->css_signature + 1079 - ICP_QAT_CSS_SIGNATURE_LEN; 1027 + ICP_QAT_CSS_SIGNATURE_LEN(handle); 1080 1028 1081 1029 ae_mode = (struct icp_qat_simg_ae_mode *)(suof_img_hdr->css_simg); 1082 1030 suof_img_hdr->ae_mask = ae_mode->ae_mask; ··· 1116 1064 return -EINVAL; 1117 1065 } 1118 1066 maj_ver = prod_rev & 0xff; 1119 - if ((maj_ver > img_ae_mode->devmax_ver) || 1120 - (maj_ver < img_ae_mode->devmin_ver)) { 1067 + if (maj_ver > img_ae_mode->devmax_ver || 1068 + maj_ver < img_ae_mode->devmin_ver) { 1121 1069 pr_err("QAT: incompatible device majver 0x%x\n", maj_ver); 1122 1070 return -EINVAL; 1123 1071 } ··· 1160 1108 unsigned int i = 0; 1161 1109 struct icp_qat_suof_img_hdr img_header; 1162 1110 1163 - if (!suof_ptr || (suof_size == 0)) { 1111 + if (!suof_ptr || suof_size == 0) { 1164 1112 pr_err("QAT: input parameter SUOF pointer/size is NULL\n"); 1165 1113 return -EINVAL; 1166 1114 } ··· 1182 1130 if (!suof_img_hdr) 1183 1131 return -ENOMEM; 1184 1132 suof_handle->img_table.simg_hdr = suof_img_hdr; 1185 - } 1186 1133 1187 - for (i = 0; i < suof_handle->img_table.num_simgs; i++) { 1188 - qat_uclo_map_simg(handle->sobj_handle, &suof_img_hdr[i], 1189 - &suof_chunk_hdr[1 + i]); 1190 - ret = qat_uclo_check_simg_compat(handle, 1191 - &suof_img_hdr[i]); 1192 - if (ret) 1193 - return ret; 1194 - if ((suof_img_hdr[i].ae_mask & 0x1) != 0) 1195 - ae0_img = i; 1134 + for (i = 0; i < suof_handle->img_table.num_simgs; i++) { 1135 + qat_uclo_map_simg(handle, &suof_img_hdr[i], 1136 + &suof_chunk_hdr[1 + i]); 1137 + ret = qat_uclo_check_simg_compat(handle, 1138 + &suof_img_hdr[i]); 1139 + if (ret) 1140 + return ret; 1141 + suof_img_hdr[i].ae_mask &= handle->cfg_ae_mask; 1142 + if ((suof_img_hdr[i].ae_mask & 0x1) != 0) 1143 + ae0_img = i; 1144 + } 1145 + 1146 + if (!handle->chip_info->tgroup_share_ustore) { 1147 + qat_uclo_tail_img(suof_img_hdr, ae0_img, 1148 + suof_handle->img_table.num_simgs); 1149 + } 1196 1150 } 1197 - qat_uclo_tail_img(suof_img_hdr, ae0_img, 1198 - suof_handle->img_table.num_simgs); 1199 1151 return 0; 1200 1152 } 1201 1153 ··· 1209 1153 static int qat_uclo_auth_fw(struct icp_qat_fw_loader_handle *handle, 1210 1154 struct icp_qat_fw_auth_desc *desc) 1211 1155 { 1212 - unsigned int fcu_sts, retry = 0; 1156 + u32 fcu_sts, retry = 0; 1157 + u32 fcu_ctl_csr, fcu_sts_csr; 1158 + u32 fcu_dram_hi_csr, fcu_dram_lo_csr; 1213 1159 u64 bus_addr; 1214 1160 1215 1161 bus_addr = ADD_ADDR(desc->css_hdr_high, desc->css_hdr_low) 1216 1162 - sizeof(struct icp_qat_auth_chunk); 1217 - SET_CAP_CSR(handle, FCU_DRAM_ADDR_HI, (bus_addr >> BITS_IN_DWORD)); 1218 - SET_CAP_CSR(handle, FCU_DRAM_ADDR_LO, bus_addr); 1219 - SET_CAP_CSR(handle, FCU_CONTROL, FCU_CTRL_CMD_AUTH); 1163 + 1164 + fcu_ctl_csr = handle->chip_info->fcu_ctl_csr; 1165 + fcu_sts_csr = handle->chip_info->fcu_sts_csr; 1166 + fcu_dram_hi_csr = handle->chip_info->fcu_dram_addr_hi; 1167 + fcu_dram_lo_csr = handle->chip_info->fcu_dram_addr_lo; 1168 + 1169 + SET_CAP_CSR(handle, fcu_dram_hi_csr, (bus_addr >> BITS_IN_DWORD)); 1170 + SET_CAP_CSR(handle, fcu_dram_lo_csr, bus_addr); 1171 + SET_CAP_CSR(handle, fcu_ctl_csr, FCU_CTRL_CMD_AUTH); 1220 1172 1221 1173 do { 1222 1174 msleep(FW_AUTH_WAIT_PERIOD); 1223 - fcu_sts = GET_CAP_CSR(handle, FCU_STATUS); 1175 + fcu_sts = GET_CAP_CSR(handle, fcu_sts_csr); 1224 1176 if ((fcu_sts & FCU_AUTH_STS_MASK) == FCU_STS_VERI_FAIL) 1225 1177 goto auth_fail; 1226 1178 if (((fcu_sts >> FCU_STS_AUTHFWLD_POS) & 0x1)) ··· 1239 1175 pr_err("QAT: authentication error (FCU_STATUS = 0x%x),retry = %d\n", 1240 1176 fcu_sts & FCU_AUTH_STS_MASK, retry); 1241 1177 return -EINVAL; 1178 + } 1179 + 1180 + static bool qat_uclo_is_broadcast(struct icp_qat_fw_loader_handle *handle, 1181 + int imgid) 1182 + { 1183 + struct icp_qat_suof_handle *sobj_handle; 1184 + 1185 + if (!handle->chip_info->tgroup_share_ustore) 1186 + return false; 1187 + 1188 + sobj_handle = (struct icp_qat_suof_handle *)handle->sobj_handle; 1189 + if (handle->hal_handle->admin_ae_mask & 1190 + sobj_handle->img_table.simg_hdr[imgid].ae_mask) 1191 + return false; 1192 + 1193 + return true; 1194 + } 1195 + 1196 + static int qat_uclo_broadcast_load_fw(struct icp_qat_fw_loader_handle *handle, 1197 + struct icp_qat_fw_auth_desc *desc) 1198 + { 1199 + unsigned long ae_mask = handle->hal_handle->ae_mask; 1200 + unsigned long desc_ae_mask = desc->ae_mask; 1201 + u32 fcu_sts, ae_broadcast_mask = 0; 1202 + u32 fcu_loaded_csr, ae_loaded; 1203 + u32 fcu_sts_csr, fcu_ctl_csr; 1204 + unsigned int ae, retry = 0; 1205 + 1206 + if (handle->chip_info->tgroup_share_ustore) { 1207 + fcu_ctl_csr = handle->chip_info->fcu_ctl_csr; 1208 + fcu_sts_csr = handle->chip_info->fcu_sts_csr; 1209 + fcu_loaded_csr = handle->chip_info->fcu_loaded_ae_csr; 1210 + } else { 1211 + pr_err("Chip 0x%x doesn't support broadcast load\n", 1212 + handle->pci_dev->device); 1213 + return -EINVAL; 1214 + } 1215 + 1216 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 1217 + if (qat_hal_check_ae_active(handle, (unsigned char)ae)) { 1218 + pr_err("QAT: Broadcast load failed. AE is not enabled or active.\n"); 1219 + return -EINVAL; 1220 + } 1221 + 1222 + if (test_bit(ae, &desc_ae_mask)) 1223 + ae_broadcast_mask |= 1 << ae; 1224 + } 1225 + 1226 + if (ae_broadcast_mask) { 1227 + SET_CAP_CSR(handle, FCU_ME_BROADCAST_MASK_TYPE, 1228 + ae_broadcast_mask); 1229 + 1230 + SET_CAP_CSR(handle, fcu_ctl_csr, FCU_CTRL_CMD_LOAD); 1231 + 1232 + do { 1233 + msleep(FW_AUTH_WAIT_PERIOD); 1234 + fcu_sts = GET_CAP_CSR(handle, fcu_sts_csr); 1235 + fcu_sts &= FCU_AUTH_STS_MASK; 1236 + 1237 + if (fcu_sts == FCU_STS_LOAD_FAIL) { 1238 + pr_err("Broadcast load failed: 0x%x)\n", fcu_sts); 1239 + return -EINVAL; 1240 + } else if (fcu_sts == FCU_STS_LOAD_DONE) { 1241 + ae_loaded = GET_CAP_CSR(handle, fcu_loaded_csr); 1242 + ae_loaded >>= handle->chip_info->fcu_loaded_ae_pos; 1243 + 1244 + if ((ae_loaded & ae_broadcast_mask) == ae_broadcast_mask) 1245 + break; 1246 + } 1247 + } while (retry++ < FW_AUTH_MAX_RETRY); 1248 + 1249 + if (retry > FW_AUTH_MAX_RETRY) { 1250 + pr_err("QAT: broadcast load failed timeout %d\n", retry); 1251 + return -EINVAL; 1252 + } 1253 + } 1254 + return 0; 1242 1255 } 1243 1256 1244 1257 static int qat_uclo_simg_alloc(struct icp_qat_fw_loader_handle *handle, ··· 1338 1197 static void qat_uclo_simg_free(struct icp_qat_fw_loader_handle *handle, 1339 1198 struct icp_firml_dram_desc *dram_desc) 1340 1199 { 1341 - dma_free_coherent(&handle->pci_dev->dev, 1342 - (size_t)(dram_desc->dram_size), 1343 - (dram_desc->dram_base_addr_v), 1344 - dram_desc->dram_bus_addr); 1345 - memset(dram_desc, 0, sizeof(*dram_desc)); 1200 + if (handle && dram_desc && dram_desc->dram_base_addr_v) { 1201 + dma_free_coherent(&handle->pci_dev->dev, 1202 + (size_t)(dram_desc->dram_size), 1203 + dram_desc->dram_base_addr_v, 1204 + dram_desc->dram_bus_addr); 1205 + } 1206 + 1207 + if (dram_desc) 1208 + memset(dram_desc, 0, sizeof(*dram_desc)); 1346 1209 } 1347 1210 1348 1211 static void qat_uclo_ummap_auth_fw(struct icp_qat_fw_loader_handle *handle, ··· 1354 1209 { 1355 1210 struct icp_firml_dram_desc dram_desc; 1356 1211 1357 - dram_desc.dram_base_addr_v = *desc; 1358 - dram_desc.dram_bus_addr = ((struct icp_qat_auth_chunk *) 1359 - (*desc))->chunk_bus_addr; 1360 - dram_desc.dram_size = ((struct icp_qat_auth_chunk *) 1361 - (*desc))->chunk_size; 1362 - qat_uclo_simg_free(handle, &dram_desc); 1212 + if (*desc) { 1213 + dram_desc.dram_base_addr_v = *desc; 1214 + dram_desc.dram_bus_addr = ((struct icp_qat_auth_chunk *) 1215 + (*desc))->chunk_bus_addr; 1216 + dram_desc.dram_size = ((struct icp_qat_auth_chunk *) 1217 + (*desc))->chunk_size; 1218 + qat_uclo_simg_free(handle, &dram_desc); 1219 + } 1363 1220 } 1364 1221 1365 1222 static int qat_uclo_map_auth_fw(struct icp_qat_fw_loader_handle *handle, ··· 1373 1226 struct icp_qat_auth_chunk *auth_chunk; 1374 1227 u64 virt_addr, bus_addr, virt_base; 1375 1228 unsigned int length, simg_offset = sizeof(*auth_chunk); 1229 + struct icp_qat_simg_ae_mode *simg_ae_mode; 1376 1230 struct icp_firml_dram_desc img_desc; 1377 1231 1378 - if (size > (ICP_QAT_AE_IMG_OFFSET + ICP_QAT_CSS_MAX_IMAGE_LEN)) { 1232 + if (size > (ICP_QAT_AE_IMG_OFFSET(handle) + ICP_QAT_CSS_MAX_IMAGE_LEN)) { 1379 1233 pr_err("QAT: error, input image size overflow %d\n", size); 1380 1234 return -EINVAL; 1381 1235 } 1382 1236 length = (css_hdr->fw_type == CSS_AE_FIRMWARE) ? 1383 - ICP_QAT_CSS_AE_SIMG_LEN + simg_offset : 1384 - size + ICP_QAT_CSS_FWSK_PAD_LEN + simg_offset; 1237 + ICP_QAT_CSS_AE_SIMG_LEN(handle) + simg_offset : 1238 + size + ICP_QAT_CSS_FWSK_PAD_LEN(handle) + simg_offset; 1385 1239 if (qat_uclo_simg_alloc(handle, &img_desc, length)) { 1386 1240 pr_err("QAT: error, allocate continuous dram fail\n"); 1387 1241 return -ENOMEM; ··· 1409 1261 1410 1262 memcpy((void *)(uintptr_t)virt_addr, 1411 1263 (void *)(image + sizeof(*css_hdr)), 1412 - ICP_QAT_CSS_FWSK_MODULUS_LEN); 1264 + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle)); 1413 1265 /* padding */ 1414 - memset((void *)(uintptr_t)(virt_addr + ICP_QAT_CSS_FWSK_MODULUS_LEN), 1415 - 0, ICP_QAT_CSS_FWSK_PAD_LEN); 1266 + memset((void *)(uintptr_t)(virt_addr + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle)), 1267 + 0, ICP_QAT_CSS_FWSK_PAD_LEN(handle)); 1416 1268 1417 1269 /* exponent */ 1418 - memcpy((void *)(uintptr_t)(virt_addr + ICP_QAT_CSS_FWSK_MODULUS_LEN + 1419 - ICP_QAT_CSS_FWSK_PAD_LEN), 1270 + memcpy((void *)(uintptr_t)(virt_addr + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + 1271 + ICP_QAT_CSS_FWSK_PAD_LEN(handle)), 1420 1272 (void *)(image + sizeof(*css_hdr) + 1421 - ICP_QAT_CSS_FWSK_MODULUS_LEN), 1273 + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle)), 1422 1274 sizeof(unsigned int)); 1423 1275 1424 1276 /* signature */ 1425 1277 bus_addr = ADD_ADDR(auth_desc->fwsk_pub_high, 1426 1278 auth_desc->fwsk_pub_low) + 1427 - ICP_QAT_CSS_FWSK_PUB_LEN; 1428 - virt_addr = virt_addr + ICP_QAT_CSS_FWSK_PUB_LEN; 1279 + ICP_QAT_CSS_FWSK_PUB_LEN(handle); 1280 + virt_addr = virt_addr + ICP_QAT_CSS_FWSK_PUB_LEN(handle); 1429 1281 auth_desc->signature_high = (unsigned int)(bus_addr >> BITS_IN_DWORD); 1430 1282 auth_desc->signature_low = (unsigned int)bus_addr; 1431 1283 1432 1284 memcpy((void *)(uintptr_t)virt_addr, 1433 1285 (void *)(image + sizeof(*css_hdr) + 1434 - ICP_QAT_CSS_FWSK_MODULUS_LEN + 1435 - ICP_QAT_CSS_FWSK_EXPONENT_LEN), 1436 - ICP_QAT_CSS_SIGNATURE_LEN); 1286 + ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + 1287 + ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle)), 1288 + ICP_QAT_CSS_SIGNATURE_LEN(handle)); 1437 1289 1438 1290 bus_addr = ADD_ADDR(auth_desc->signature_high, 1439 1291 auth_desc->signature_low) + 1440 - ICP_QAT_CSS_SIGNATURE_LEN; 1441 - virt_addr += ICP_QAT_CSS_SIGNATURE_LEN; 1292 + ICP_QAT_CSS_SIGNATURE_LEN(handle); 1293 + virt_addr += ICP_QAT_CSS_SIGNATURE_LEN(handle); 1442 1294 1443 1295 auth_desc->img_high = (unsigned int)(bus_addr >> BITS_IN_DWORD); 1444 1296 auth_desc->img_low = (unsigned int)bus_addr; 1445 - auth_desc->img_len = size - ICP_QAT_AE_IMG_OFFSET; 1297 + auth_desc->img_len = size - ICP_QAT_AE_IMG_OFFSET(handle); 1446 1298 memcpy((void *)(uintptr_t)virt_addr, 1447 - (void *)(image + ICP_QAT_AE_IMG_OFFSET), 1299 + (void *)(image + ICP_QAT_AE_IMG_OFFSET(handle)), 1448 1300 auth_desc->img_len); 1449 1301 virt_addr = virt_base; 1450 1302 /* AE firmware */ ··· 1463 1315 auth_desc->img_ae_insts_high = (unsigned int) 1464 1316 (bus_addr >> BITS_IN_DWORD); 1465 1317 auth_desc->img_ae_insts_low = (unsigned int)bus_addr; 1318 + virt_addr += sizeof(struct icp_qat_css_hdr); 1319 + virt_addr += ICP_QAT_CSS_FWSK_PUB_LEN(handle); 1320 + virt_addr += ICP_QAT_CSS_SIGNATURE_LEN(handle); 1321 + simg_ae_mode = (struct icp_qat_simg_ae_mode *)(uintptr_t)virt_addr; 1322 + auth_desc->ae_mask = simg_ae_mode->ae_mask & handle->cfg_ae_mask; 1466 1323 } else { 1467 1324 auth_desc->img_ae_insts_high = auth_desc->img_high; 1468 1325 auth_desc->img_ae_insts_low = auth_desc->img_low; ··· 1479 1326 static int qat_uclo_load_fw(struct icp_qat_fw_loader_handle *handle, 1480 1327 struct icp_qat_fw_auth_desc *desc) 1481 1328 { 1329 + unsigned long ae_mask = handle->hal_handle->ae_mask; 1330 + u32 fcu_sts_csr, fcu_ctl_csr; 1331 + u32 loaded_aes, loaded_csr; 1482 1332 unsigned int i; 1483 - unsigned int fcu_sts; 1484 - struct icp_qat_simg_ae_mode *virt_addr; 1485 - unsigned int fcu_loaded_ae_pos = FCU_LOADED_AE_POS; 1333 + u32 fcu_sts; 1486 1334 1487 - virt_addr = (void *)((uintptr_t)desc + 1488 - sizeof(struct icp_qat_auth_chunk) + 1489 - sizeof(struct icp_qat_css_hdr) + 1490 - ICP_QAT_CSS_FWSK_PUB_LEN + 1491 - ICP_QAT_CSS_SIGNATURE_LEN); 1492 - for (i = 0; i < handle->hal_handle->ae_max_num; i++) { 1335 + fcu_ctl_csr = handle->chip_info->fcu_ctl_csr; 1336 + fcu_sts_csr = handle->chip_info->fcu_sts_csr; 1337 + loaded_csr = handle->chip_info->fcu_loaded_ae_csr; 1338 + 1339 + for_each_set_bit(i, &ae_mask, handle->hal_handle->ae_max_num) { 1493 1340 int retry = 0; 1494 1341 1495 - if (!((virt_addr->ae_mask >> i) & 0x1)) 1342 + if (!((desc->ae_mask >> i) & 0x1)) 1496 1343 continue; 1497 1344 if (qat_hal_check_ae_active(handle, i)) { 1498 1345 pr_err("QAT: AE %d is active\n", i); 1499 1346 return -EINVAL; 1500 1347 } 1501 - SET_CAP_CSR(handle, FCU_CONTROL, 1502 - (FCU_CTRL_CMD_LOAD | (i << FCU_CTRL_AE_POS))); 1348 + SET_CAP_CSR(handle, fcu_ctl_csr, 1349 + (FCU_CTRL_CMD_LOAD | 1350 + (1 << FCU_CTRL_BROADCAST_POS) | 1351 + (i << FCU_CTRL_AE_POS))); 1503 1352 1504 1353 do { 1505 1354 msleep(FW_AUTH_WAIT_PERIOD); 1506 - fcu_sts = GET_CAP_CSR(handle, FCU_STATUS); 1507 - if (((fcu_sts & FCU_AUTH_STS_MASK) == 1508 - FCU_STS_LOAD_DONE) && 1509 - ((fcu_sts >> fcu_loaded_ae_pos) & (1 << i))) 1510 - break; 1355 + fcu_sts = GET_CAP_CSR(handle, fcu_sts_csr); 1356 + if ((fcu_sts & FCU_AUTH_STS_MASK) == 1357 + FCU_STS_LOAD_DONE) { 1358 + loaded_aes = GET_CAP_CSR(handle, loaded_csr); 1359 + loaded_aes >>= handle->chip_info->fcu_loaded_ae_pos; 1360 + if (loaded_aes & (1 << i)) 1361 + break; 1362 + } 1511 1363 } while (retry++ < FW_AUTH_MAX_RETRY); 1512 1364 if (retry > FW_AUTH_MAX_RETRY) { 1513 1365 pr_err("QAT: firmware load failed timeout %x\n", retry); ··· 1545 1387 struct icp_qat_fw_auth_desc *desc = NULL; 1546 1388 int status = 0; 1547 1389 1548 - if (handle->fw_auth) { 1390 + if (handle->chip_info->fw_auth) { 1549 1391 if (!qat_uclo_map_auth_fw(handle, addr_ptr, mem_size, &desc)) 1550 1392 status = qat_uclo_auth_fw(handle, desc); 1551 1393 qat_uclo_ummap_auth_fw(handle, &desc); 1552 1394 } else { 1553 - if (handle->pci_dev->device == PCI_DEVICE_ID_INTEL_QAT_C3XXX) { 1554 - pr_err("QAT: C3XXX doesn't support unsigned MMP\n"); 1555 - return -EINVAL; 1395 + if (!handle->chip_info->sram_visible) { 1396 + dev_dbg(&handle->pci_dev->dev, 1397 + "QAT MMP fw not loaded for device 0x%x", 1398 + handle->pci_dev->device); 1399 + return status; 1556 1400 } 1557 1401 qat_uclo_wr_sram_by_words(handle, 0, addr_ptr, mem_size); 1558 1402 } ··· 1597 1437 return -ENOMEM; 1598 1438 } 1599 1439 1600 - int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle, 1601 - void *addr_ptr, int mem_size) 1440 + static int qat_uclo_map_mof_file_hdr(struct icp_qat_fw_loader_handle *handle, 1441 + struct icp_qat_mof_file_hdr *mof_ptr, 1442 + u32 mof_size) 1602 1443 { 1444 + struct icp_qat_mof_handle *mobj_handle = handle->mobj_handle; 1445 + unsigned int min_ver_offset; 1446 + unsigned int checksum; 1447 + 1448 + mobj_handle->file_id = ICP_QAT_MOF_FID; 1449 + mobj_handle->mof_buf = (char *)mof_ptr; 1450 + mobj_handle->mof_size = mof_size; 1451 + 1452 + min_ver_offset = mof_size - offsetof(struct icp_qat_mof_file_hdr, 1453 + min_ver); 1454 + checksum = qat_uclo_calc_str_checksum(&mof_ptr->min_ver, 1455 + min_ver_offset); 1456 + if (checksum != mof_ptr->checksum) { 1457 + pr_err("QAT: incorrect MOF checksum\n"); 1458 + return -EINVAL; 1459 + } 1460 + 1461 + mobj_handle->checksum = mof_ptr->checksum; 1462 + mobj_handle->min_ver = mof_ptr->min_ver; 1463 + mobj_handle->maj_ver = mof_ptr->maj_ver; 1464 + return 0; 1465 + } 1466 + 1467 + static void qat_uclo_del_mof(struct icp_qat_fw_loader_handle *handle) 1468 + { 1469 + struct icp_qat_mof_handle *mobj_handle = handle->mobj_handle; 1470 + 1471 + kfree(mobj_handle->obj_table.obj_hdr); 1472 + mobj_handle->obj_table.obj_hdr = NULL; 1473 + kfree(handle->mobj_handle); 1474 + handle->mobj_handle = NULL; 1475 + } 1476 + 1477 + static int qat_uclo_seek_obj_inside_mof(struct icp_qat_mof_handle *mobj_handle, 1478 + char *obj_name, char **obj_ptr, 1479 + unsigned int *obj_size) 1480 + { 1481 + struct icp_qat_mof_objhdr *obj_hdr = mobj_handle->obj_table.obj_hdr; 1482 + unsigned int i; 1483 + 1484 + for (i = 0; i < mobj_handle->obj_table.num_objs; i++) { 1485 + if (!strncmp(obj_hdr[i].obj_name, obj_name, 1486 + ICP_QAT_SUOF_OBJ_NAME_LEN)) { 1487 + *obj_ptr = obj_hdr[i].obj_buf; 1488 + *obj_size = obj_hdr[i].obj_size; 1489 + return 0; 1490 + } 1491 + } 1492 + 1493 + pr_err("QAT: object %s is not found inside MOF\n", obj_name); 1494 + return -EINVAL; 1495 + } 1496 + 1497 + static int qat_uclo_map_obj_from_mof(struct icp_qat_mof_handle *mobj_handle, 1498 + struct icp_qat_mof_objhdr *mobj_hdr, 1499 + struct icp_qat_mof_obj_chunkhdr *obj_chunkhdr) 1500 + { 1501 + u8 *obj; 1502 + 1503 + if (!strncmp(obj_chunkhdr->chunk_id, ICP_QAT_UOF_IMAG, 1504 + ICP_QAT_MOF_OBJ_CHUNKID_LEN)) { 1505 + obj = mobj_handle->uobjs_hdr + obj_chunkhdr->offset; 1506 + } else if (!strncmp(obj_chunkhdr->chunk_id, ICP_QAT_SUOF_IMAG, 1507 + ICP_QAT_MOF_OBJ_CHUNKID_LEN)) { 1508 + obj = mobj_handle->sobjs_hdr + obj_chunkhdr->offset; 1509 + } else { 1510 + pr_err("QAT: unsupported chunk id\n"); 1511 + return -EINVAL; 1512 + } 1513 + mobj_hdr->obj_buf = obj; 1514 + mobj_hdr->obj_size = (unsigned int)obj_chunkhdr->size; 1515 + mobj_hdr->obj_name = obj_chunkhdr->name + mobj_handle->sym_str; 1516 + return 0; 1517 + } 1518 + 1519 + static int qat_uclo_map_objs_from_mof(struct icp_qat_mof_handle *mobj_handle) 1520 + { 1521 + struct icp_qat_mof_obj_chunkhdr *uobj_chunkhdr; 1522 + struct icp_qat_mof_obj_chunkhdr *sobj_chunkhdr; 1523 + struct icp_qat_mof_obj_hdr *uobj_hdr; 1524 + struct icp_qat_mof_obj_hdr *sobj_hdr; 1525 + struct icp_qat_mof_objhdr *mobj_hdr; 1526 + unsigned int uobj_chunk_num = 0; 1527 + unsigned int sobj_chunk_num = 0; 1528 + unsigned int *valid_chunk; 1529 + int ret, i; 1530 + 1531 + uobj_hdr = (struct icp_qat_mof_obj_hdr *)mobj_handle->uobjs_hdr; 1532 + sobj_hdr = (struct icp_qat_mof_obj_hdr *)mobj_handle->sobjs_hdr; 1533 + if (uobj_hdr) 1534 + uobj_chunk_num = uobj_hdr->num_chunks; 1535 + if (sobj_hdr) 1536 + sobj_chunk_num = sobj_hdr->num_chunks; 1537 + 1538 + mobj_hdr = kzalloc((uobj_chunk_num + sobj_chunk_num) * 1539 + sizeof(*mobj_hdr), GFP_KERNEL); 1540 + if (!mobj_hdr) 1541 + return -ENOMEM; 1542 + 1543 + mobj_handle->obj_table.obj_hdr = mobj_hdr; 1544 + valid_chunk = &mobj_handle->obj_table.num_objs; 1545 + uobj_chunkhdr = (struct icp_qat_mof_obj_chunkhdr *) 1546 + ((uintptr_t)uobj_hdr + sizeof(*uobj_hdr)); 1547 + sobj_chunkhdr = (struct icp_qat_mof_obj_chunkhdr *) 1548 + ((uintptr_t)sobj_hdr + sizeof(*sobj_hdr)); 1549 + 1550 + /* map uof objects */ 1551 + for (i = 0; i < uobj_chunk_num; i++) { 1552 + ret = qat_uclo_map_obj_from_mof(mobj_handle, 1553 + &mobj_hdr[*valid_chunk], 1554 + &uobj_chunkhdr[i]); 1555 + if (ret) 1556 + return ret; 1557 + (*valid_chunk)++; 1558 + } 1559 + 1560 + /* map suof objects */ 1561 + for (i = 0; i < sobj_chunk_num; i++) { 1562 + ret = qat_uclo_map_obj_from_mof(mobj_handle, 1563 + &mobj_hdr[*valid_chunk], 1564 + &sobj_chunkhdr[i]); 1565 + if (ret) 1566 + return ret; 1567 + (*valid_chunk)++; 1568 + } 1569 + 1570 + if ((uobj_chunk_num + sobj_chunk_num) != *valid_chunk) { 1571 + pr_err("QAT: inconsistent UOF/SUOF chunk amount\n"); 1572 + return -EINVAL; 1573 + } 1574 + return 0; 1575 + } 1576 + 1577 + static void qat_uclo_map_mof_symobjs(struct icp_qat_mof_handle *mobj_handle, 1578 + struct icp_qat_mof_chunkhdr *mof_chunkhdr) 1579 + { 1580 + char **sym_str = (char **)&mobj_handle->sym_str; 1581 + unsigned int *sym_size = &mobj_handle->sym_size; 1582 + struct icp_qat_mof_str_table *str_table_obj; 1583 + 1584 + *sym_size = *(unsigned int *)(uintptr_t) 1585 + (mof_chunkhdr->offset + mobj_handle->mof_buf); 1586 + *sym_str = (char *)(uintptr_t) 1587 + (mobj_handle->mof_buf + mof_chunkhdr->offset + 1588 + sizeof(str_table_obj->tab_len)); 1589 + } 1590 + 1591 + static void qat_uclo_map_mof_chunk(struct icp_qat_mof_handle *mobj_handle, 1592 + struct icp_qat_mof_chunkhdr *mof_chunkhdr) 1593 + { 1594 + char *chunk_id = mof_chunkhdr->chunk_id; 1595 + 1596 + if (!strncmp(chunk_id, ICP_QAT_MOF_SYM_OBJS, ICP_QAT_MOF_OBJ_ID_LEN)) 1597 + qat_uclo_map_mof_symobjs(mobj_handle, mof_chunkhdr); 1598 + else if (!strncmp(chunk_id, ICP_QAT_UOF_OBJS, ICP_QAT_MOF_OBJ_ID_LEN)) 1599 + mobj_handle->uobjs_hdr = mobj_handle->mof_buf + 1600 + mof_chunkhdr->offset; 1601 + else if (!strncmp(chunk_id, ICP_QAT_SUOF_OBJS, ICP_QAT_MOF_OBJ_ID_LEN)) 1602 + mobj_handle->sobjs_hdr = mobj_handle->mof_buf + 1603 + mof_chunkhdr->offset; 1604 + } 1605 + 1606 + static int qat_uclo_check_mof_format(struct icp_qat_mof_file_hdr *mof_hdr) 1607 + { 1608 + int maj = mof_hdr->maj_ver & 0xff; 1609 + int min = mof_hdr->min_ver & 0xff; 1610 + 1611 + if (mof_hdr->file_id != ICP_QAT_MOF_FID) { 1612 + pr_err("QAT: invalid header 0x%x\n", mof_hdr->file_id); 1613 + return -EINVAL; 1614 + } 1615 + 1616 + if (mof_hdr->num_chunks <= 0x1) { 1617 + pr_err("QAT: MOF chunk amount is incorrect\n"); 1618 + return -EINVAL; 1619 + } 1620 + if (maj != ICP_QAT_MOF_MAJVER || min != ICP_QAT_MOF_MINVER) { 1621 + pr_err("QAT: bad MOF version, major 0x%x, minor 0x%x\n", 1622 + maj, min); 1623 + return -EINVAL; 1624 + } 1625 + return 0; 1626 + } 1627 + 1628 + static int qat_uclo_map_mof_obj(struct icp_qat_fw_loader_handle *handle, 1629 + struct icp_qat_mof_file_hdr *mof_ptr, 1630 + u32 mof_size, char *obj_name, char **obj_ptr, 1631 + unsigned int *obj_size) 1632 + { 1633 + struct icp_qat_mof_chunkhdr *mof_chunkhdr; 1634 + unsigned int file_id = mof_ptr->file_id; 1635 + struct icp_qat_mof_handle *mobj_handle; 1636 + unsigned short chunks_num; 1637 + unsigned int i; 1638 + int ret; 1639 + 1640 + if (file_id == ICP_QAT_UOF_FID || file_id == ICP_QAT_SUOF_FID) { 1641 + if (obj_ptr) 1642 + *obj_ptr = (char *)mof_ptr; 1643 + if (obj_size) 1644 + *obj_size = mof_size; 1645 + return 0; 1646 + } 1647 + if (qat_uclo_check_mof_format(mof_ptr)) 1648 + return -EINVAL; 1649 + 1650 + mobj_handle = kzalloc(sizeof(*mobj_handle), GFP_KERNEL); 1651 + if (!mobj_handle) 1652 + return -ENOMEM; 1653 + 1654 + handle->mobj_handle = mobj_handle; 1655 + ret = qat_uclo_map_mof_file_hdr(handle, mof_ptr, mof_size); 1656 + if (ret) 1657 + return ret; 1658 + 1659 + mof_chunkhdr = (void *)mof_ptr + sizeof(*mof_ptr); 1660 + chunks_num = mof_ptr->num_chunks; 1661 + 1662 + /* Parse MOF file chunks */ 1663 + for (i = 0; i < chunks_num; i++) 1664 + qat_uclo_map_mof_chunk(mobj_handle, &mof_chunkhdr[i]); 1665 + 1666 + /* All sym_objs uobjs and sobjs should be available */ 1667 + if (!mobj_handle->sym_str || 1668 + (!mobj_handle->uobjs_hdr && !mobj_handle->sobjs_hdr)) 1669 + return -EINVAL; 1670 + 1671 + ret = qat_uclo_map_objs_from_mof(mobj_handle); 1672 + if (ret) 1673 + return ret; 1674 + 1675 + /* Seek specified uof object in MOF */ 1676 + return qat_uclo_seek_obj_inside_mof(mobj_handle, obj_name, 1677 + obj_ptr, obj_size); 1678 + } 1679 + 1680 + int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle, 1681 + void *addr_ptr, u32 mem_size, char *obj_name) 1682 + { 1683 + char *obj_addr; 1684 + u32 obj_size; 1685 + int ret; 1686 + 1603 1687 BUILD_BUG_ON(ICP_QAT_UCLO_MAX_AE >= 1604 1688 (sizeof(handle->hal_handle->ae_mask) * 8)); 1605 1689 1606 1690 if (!handle || !addr_ptr || mem_size < 24) 1607 1691 return -EINVAL; 1608 1692 1609 - return (handle->fw_auth) ? 1610 - qat_uclo_map_suof_obj(handle, addr_ptr, mem_size) : 1611 - qat_uclo_map_uof_obj(handle, addr_ptr, mem_size); 1693 + if (obj_name) { 1694 + ret = qat_uclo_map_mof_obj(handle, addr_ptr, mem_size, obj_name, 1695 + &obj_addr, &obj_size); 1696 + if (ret) 1697 + return ret; 1698 + } else { 1699 + obj_addr = addr_ptr; 1700 + obj_size = mem_size; 1701 + } 1702 + 1703 + return (handle->chip_info->fw_auth) ? 1704 + qat_uclo_map_suof_obj(handle, obj_addr, obj_size) : 1705 + qat_uclo_map_uof_obj(handle, obj_addr, obj_size); 1612 1706 } 1613 1707 1614 - void qat_uclo_del_uof_obj(struct icp_qat_fw_loader_handle *handle) 1708 + void qat_uclo_del_obj(struct icp_qat_fw_loader_handle *handle) 1615 1709 { 1616 1710 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 1617 1711 unsigned int a; 1618 1712 1713 + if (handle->mobj_handle) 1714 + qat_uclo_del_mof(handle); 1619 1715 if (handle->sobj_handle) 1620 1716 qat_uclo_del_suof(handle); 1621 1717 if (!obj_handle) ··· 1895 1479 u64 *uword, unsigned int addr_p, 1896 1480 unsigned int raddr, u64 fill) 1897 1481 { 1482 + unsigned int i, addr; 1898 1483 u64 uwrd = 0; 1899 - unsigned int i; 1900 1484 1901 1485 if (!encap_page) { 1902 1486 *uword = fill; 1903 1487 return; 1904 1488 } 1489 + addr = (encap_page->page_region) ? raddr : addr_p; 1905 1490 for (i = 0; i < encap_page->uwblock_num; i++) { 1906 - if (raddr >= encap_page->uwblock[i].start_addr && 1907 - raddr <= encap_page->uwblock[i].start_addr + 1491 + if (addr >= encap_page->uwblock[i].start_addr && 1492 + addr <= encap_page->uwblock[i].start_addr + 1908 1493 encap_page->uwblock[i].words_num - 1) { 1909 - raddr -= encap_page->uwblock[i].start_addr; 1910 - raddr *= obj_handle->uword_in_bytes; 1494 + addr -= encap_page->uwblock[i].start_addr; 1495 + addr *= obj_handle->uword_in_bytes; 1911 1496 memcpy(&uwrd, (void *)(((uintptr_t) 1912 - encap_page->uwblock[i].micro_words) + raddr), 1497 + encap_page->uwblock[i].micro_words) + addr), 1913 1498 obj_handle->uword_in_bytes); 1914 - uwrd = uwrd & 0xbffffffffffull; 1499 + uwrd = uwrd & GENMASK_ULL(43, 0); 1915 1500 } 1916 1501 } 1917 1502 *uword = uwrd; ··· 1963 1546 struct icp_qat_uof_image *image) 1964 1547 { 1965 1548 struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; 1549 + unsigned long ae_mask = handle->hal_handle->ae_mask; 1550 + unsigned long cfg_ae_mask = handle->cfg_ae_mask; 1551 + unsigned long ae_assigned = image->ae_assigned; 1552 + struct icp_qat_uclo_aedata *aed; 1966 1553 unsigned int ctx_mask, s; 1967 1554 struct icp_qat_uclo_page *page; 1968 1555 unsigned char ae; ··· 1978 1557 ctx_mask = 0x55; 1979 1558 /* load the default page and set assigned CTX PC 1980 1559 * to the entrypoint address */ 1981 - for (ae = 0; ae < handle->hal_handle->ae_max_num; ae++) { 1982 - if (!test_bit(ae, (unsigned long *)&image->ae_assigned)) 1560 + for_each_set_bit(ae, &ae_mask, handle->hal_handle->ae_max_num) { 1561 + if (!test_bit(ae, &cfg_ae_mask)) 1983 1562 continue; 1563 + 1564 + if (!test_bit(ae, &ae_assigned)) 1565 + continue; 1566 + 1567 + aed = &obj_handle->ae_data[ae]; 1984 1568 /* find the slice to which this image is assigned */ 1985 - for (s = 0; s < obj_handle->ae_data[ae].slice_num; s++) { 1986 - if (image->ctx_assigned & obj_handle->ae_data[ae]. 1987 - ae_slices[s].ctx_mask_assigned) 1569 + for (s = 0; s < aed->slice_num; s++) { 1570 + if (image->ctx_assigned & 1571 + aed->ae_slices[s].ctx_mask_assigned) 1988 1572 break; 1989 1573 } 1990 - if (s >= obj_handle->ae_data[ae].slice_num) 1574 + if (s >= aed->slice_num) 1991 1575 continue; 1992 - page = obj_handle->ae_data[ae].ae_slices[s].page; 1576 + page = aed->ae_slices[s].page; 1993 1577 if (!page->encap_page->def_page) 1994 1578 continue; 1995 1579 qat_uclo_wr_uimage_raw_page(handle, page->encap_page, ae); 1996 1580 1997 - page = obj_handle->ae_data[ae].ae_slices[s].page; 1581 + page = aed->ae_slices[s].page; 1998 1582 for (ctx = 0; ctx < ICP_QAT_UCLO_MAX_CTX; ctx++) 1999 - obj_handle->ae_data[ae].ae_slices[s].cur_page[ctx] = 1583 + aed->ae_slices[s].cur_page[ctx] = 2000 1584 (ctx_mask & (1 << ctx)) ? page : NULL; 2001 1585 qat_hal_set_live_ctx(handle, (unsigned char)ae, 2002 1586 image->ctx_assigned); ··· 2021 1595 if (qat_uclo_map_auth_fw(handle, 2022 1596 (char *)simg_hdr[i].simg_buf, 2023 1597 (unsigned int) 2024 - (simg_hdr[i].simg_len), 1598 + simg_hdr[i].simg_len, 2025 1599 &desc)) 2026 1600 goto wr_err; 2027 1601 if (qat_uclo_auth_fw(handle, desc)) 2028 1602 goto wr_err; 2029 - if (qat_uclo_load_fw(handle, desc)) 2030 - goto wr_err; 1603 + if (qat_uclo_is_broadcast(handle, i)) { 1604 + if (qat_uclo_broadcast_load_fw(handle, desc)) 1605 + goto wr_err; 1606 + } else { 1607 + if (qat_uclo_load_fw(handle, desc)) 1608 + goto wr_err; 1609 + } 2031 1610 qat_uclo_ummap_auth_fw(handle, &desc); 2032 1611 } 2033 1612 return 0; ··· 2061 1630 2062 1631 int qat_uclo_wr_all_uimage(struct icp_qat_fw_loader_handle *handle) 2063 1632 { 2064 - return (handle->fw_auth) ? qat_uclo_wr_suof_img(handle) : 1633 + return (handle->chip_info->fw_auth) ? qat_uclo_wr_suof_img(handle) : 2065 1634 qat_uclo_wr_uof_img(handle); 1635 + } 1636 + 1637 + int qat_uclo_set_cfg_ae_mask(struct icp_qat_fw_loader_handle *handle, 1638 + unsigned int cfg_ae_mask) 1639 + { 1640 + if (!cfg_ae_mask) 1641 + return -EINVAL; 1642 + 1643 + handle->cfg_ae_mask = cfg_ae_mask; 1644 + return 0; 2066 1645 }
+52 -8
drivers/crypto/qat/qat_dh895xcc/adf_dh895xcc_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_pf2vf_msg.h> 5 5 #include <adf_common_drv.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_dh895xcc_hw_data.h" 8 + #include "icp_qat_hw.h" 7 9 8 10 /* Worker thread to service arbiter mappings based on dev SKUs */ 9 11 static const u32 thrd_to_arb_map_sku4[] = { ··· 26 24 .instances = 0 27 25 }; 28 26 29 - static u32 get_accel_mask(u32 fuse) 27 + static u32 get_accel_mask(struct adf_hw_device_data *self) 30 28 { 31 - return (~fuse) >> ADF_DH895XCC_ACCELERATORS_REG_OFFSET & 32 - ADF_DH895XCC_ACCELERATORS_MASK; 29 + u32 fuses = self->fuses; 30 + 31 + return ~fuses >> ADF_DH895XCC_ACCELERATORS_REG_OFFSET & 32 + ADF_DH895XCC_ACCELERATORS_MASK; 33 33 } 34 34 35 - static u32 get_ae_mask(u32 fuse) 35 + static u32 get_ae_mask(struct adf_hw_device_data *self) 36 36 { 37 - return (~fuse) & ADF_DH895XCC_ACCELENGINES_MASK; 37 + u32 fuses = self->fuses; 38 + 39 + return ~fuses & ADF_DH895XCC_ACCELENGINES_MASK; 38 40 } 39 41 40 42 static u32 get_num_accels(struct adf_hw_device_data *self) ··· 82 76 static u32 get_sram_bar_id(struct adf_hw_device_data *self) 83 77 { 84 78 return ADF_DH895XCC_SRAM_BAR; 79 + } 80 + 81 + static u32 get_accel_cap(struct adf_accel_dev *accel_dev) 82 + { 83 + struct pci_dev *pdev = accel_dev->accel_pci_dev.pci_dev; 84 + u32 capabilities; 85 + u32 legfuses; 86 + 87 + capabilities = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | 88 + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | 89 + ICP_ACCEL_CAPABILITIES_AUTHENTICATION; 90 + 91 + /* Read accelerator capabilities mask */ 92 + pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET, &legfuses); 93 + 94 + if (legfuses & ICP_ACCEL_MASK_CIPHER_SLICE) 95 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; 96 + if (legfuses & ICP_ACCEL_MASK_PKE_SLICE) 97 + capabilities &= ~ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; 98 + if (legfuses & ICP_ACCEL_MASK_AUTH_SLICE) 99 + capabilities &= ~ICP_ACCEL_CAPABILITIES_AUTHENTICATION; 100 + 101 + return capabilities; 85 102 } 86 103 87 104 static enum dev_sku_info get_sku(struct adf_hw_device_data *self) ··· 160 131 { 161 132 struct adf_hw_device_data *hw_device = accel_dev->hw_device; 162 133 struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_DH895XCC_PMISC_BAR]; 134 + unsigned long accel_mask = hw_device->accel_mask; 135 + unsigned long ae_mask = hw_device->ae_mask; 163 136 void __iomem *csr = misc_bar->virt_addr; 164 137 unsigned int val, i; 165 138 166 139 /* Enable Accel Engine error detection & correction */ 167 - for (i = 0; i < hw_device->get_num_aes(hw_device); i++) { 140 + for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 168 141 val = ADF_CSR_RD(csr, ADF_DH895XCC_AE_CTX_ENABLES(i)); 169 142 val |= ADF_DH895XCC_ENABLE_AE_ECC_ERR; 170 143 ADF_CSR_WR(csr, ADF_DH895XCC_AE_CTX_ENABLES(i), val); ··· 176 145 } 177 146 178 147 /* Enable shared memory error detection & correction */ 179 - for (i = 0; i < hw_device->get_num_accels(hw_device); i++) { 148 + for_each_set_bit(i, &accel_mask, ADF_DH895XCC_MAX_ACCELERATORS) { 180 149 val = ADF_CSR_RD(csr, ADF_DH895XCC_UERRSSMSH(i)); 181 150 val |= ADF_DH895XCC_ERRSSMSH_EN; 182 151 ADF_CSR_WR(csr, ADF_DH895XCC_UERRSSMSH(i), val); ··· 195 164 /* Enable bundle and misc interrupts */ 196 165 ADF_CSR_WR(addr, ADF_DH895XCC_SMIAPF0_MASK_OFFSET, 197 166 accel_dev->pf.vf_info ? 0 : 198 - GENMASK_ULL(GET_MAX_BANKS(accel_dev) - 1, 0)); 167 + BIT_ULL(GET_MAX_BANKS(accel_dev)) - 1); 199 168 ADF_CSR_WR(addr, ADF_DH895XCC_SMIAPF1_MASK_OFFSET, 200 169 ADF_DH895XCC_SMIA1_MASK); 201 170 } ··· 205 174 return 0; 206 175 } 207 176 177 + static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) 178 + { 179 + adf_gen2_cfg_iov_thds(accel_dev, enable, 180 + ADF_DH895XCC_AE2FUNC_MAP_GRP_A_NUM_REGS, 181 + ADF_DH895XCC_AE2FUNC_MAP_GRP_B_NUM_REGS); 182 + } 183 + 208 184 void adf_init_hw_data_dh895xcc(struct adf_hw_device_data *hw_data) 209 185 { 210 186 hw_data->dev_class = &dh895xcc_class; 211 187 hw_data->instance_id = dh895xcc_class.instances++; 212 188 hw_data->num_banks = ADF_DH895XCC_ETR_MAX_BANKS; 189 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 213 190 hw_data->num_accel = ADF_DH895XCC_MAX_ACCELERATORS; 214 191 hw_data->num_logical_accel = 1; 215 192 hw_data->num_engines = ADF_DH895XCC_MAX_ACCELENGINES; ··· 228 189 hw_data->enable_error_correction = adf_enable_error_correction; 229 190 hw_data->get_accel_mask = get_accel_mask; 230 191 hw_data->get_ae_mask = get_ae_mask; 192 + hw_data->get_accel_cap = get_accel_cap; 231 193 hw_data->get_num_accels = get_num_accels; 232 194 hw_data->get_num_aes = get_num_aes; 233 195 hw_data->get_etr_bar_id = get_etr_bar_id; 234 196 hw_data->get_misc_bar_id = get_misc_bar_id; 235 197 hw_data->get_pf2vf_offset = get_pf2vf_offset; 236 198 hw_data->get_vintmsk_offset = get_vintmsk_offset; 199 + hw_data->get_admin_info = adf_gen2_get_admin_info; 200 + hw_data->get_arb_info = adf_gen2_get_arb_info; 237 201 hw_data->get_sram_bar_id = get_sram_bar_id; 238 202 hw_data->get_sku = get_sku; 239 203 hw_data->fw_name = ADF_DH895XCC_FW; 240 204 hw_data->fw_mmp_name = ADF_DH895XCC_MMP; 241 205 hw_data->init_admin_comms = adf_init_admin_comms; 242 206 hw_data->exit_admin_comms = adf_exit_admin_comms; 207 + hw_data->configure_iov_threads = configure_iov_threads; 243 208 hw_data->disable_iov = adf_disable_sriov; 244 209 hw_data->send_admin_init = adf_send_admin_init; 245 210 hw_data->init_arb = adf_init_arb; ··· 253 210 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 254 211 hw_data->reset_device = adf_reset_sbr; 255 212 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 213 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 256 214 } 257 215 258 216 void adf_clean_hw_data_dh895xcc(struct adf_hw_device_data *hw_data)
+5
drivers/crypto/qat/qat_dh895xcc/adf_dh895xcc_hw_data.h
··· 36 36 37 37 #define ADF_DH895XCC_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 38 38 #define ADF_DH895XCC_VINTMSK_OFFSET(i) (0x3A000 + 0x200 + ((i) * 0x04)) 39 + 40 + /* AE to function mapping */ 41 + #define ADF_DH895XCC_AE2FUNC_MAP_GRP_A_NUM_REGS 96 42 + #define ADF_DH895XCC_AE2FUNC_MAP_GRP_B_NUM_REGS 12 43 + 39 44 /* FW names */ 40 45 #define ADF_DH895XCC_FW "qat_895xcc.bin" 41 46 #define ADF_DH895XCC_MMP "qat_895xcc_mmp.bin"
+4 -5
drivers/crypto/qat/qat_dh895xcc/adf_drv.c
··· 128 128 &hw_data->fuses); 129 129 130 130 /* Get Accelerators and Accelerators Engines masks */ 131 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 132 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 131 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 132 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 133 133 accel_pci_dev->sku = hw_data->get_sku(hw_data); 134 134 /* If the device has no acceleration engines then ignore it. */ 135 135 if (!hw_data->accel_mask || !hw_data->ae_mask || ··· 177 177 goto out_err_disable; 178 178 } 179 179 180 - /* Read accelerator capabilities mask */ 181 - pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET, 182 - &hw_data->accel_capabilities_mask); 180 + /* Get accelerator capabilities mask */ 181 + hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev); 183 182 184 183 /* Find and map all the device's BARS */ 185 184 i = 0;
+5 -2
drivers/crypto/qat/qat_dh895xccvf/adf_dh895xccvf_hw_data.c
··· 3 3 #include <adf_accel_devices.h> 4 4 #include <adf_pf2vf_msg.h> 5 5 #include <adf_common_drv.h> 6 + #include <adf_gen2_hw_data.h> 6 7 #include "adf_dh895xccvf_hw_data.h" 7 8 8 9 static struct adf_hw_device_class dh895xcciov_class = { ··· 12 11 .instances = 0 13 12 }; 14 13 15 - static u32 get_accel_mask(u32 fuse) 14 + static u32 get_accel_mask(struct adf_hw_device_data *self) 16 15 { 17 16 return ADF_DH895XCCIOV_ACCELERATORS_MASK; 18 17 } 19 18 20 - static u32 get_ae_mask(u32 fuse) 19 + static u32 get_ae_mask(struct adf_hw_device_data *self) 21 20 { 22 21 return ADF_DH895XCCIOV_ACCELENGINES_MASK; 23 22 } ··· 70 69 { 71 70 hw_data->dev_class = &dh895xcciov_class; 72 71 hw_data->num_banks = ADF_DH895XCCIOV_ETR_MAX_BANKS; 72 + hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK; 73 73 hw_data->num_accel = ADF_DH895XCCIOV_MAX_ACCELERATORS; 74 74 hw_data->num_logical_accel = 1; 75 75 hw_data->num_engines = ADF_DH895XCCIOV_MAX_ACCELENGINES; ··· 99 97 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 100 98 hw_data->dev_class->instances++; 101 99 adf_devmgr_update_class_index(hw_data); 100 + adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 102 101 } 103 102 104 103 void adf_clean_hw_data_dh895xcciov(struct adf_hw_device_data *hw_data)
+2 -2
drivers/crypto/qat/qat_dh895xccvf/adf_drv.c
··· 119 119 adf_init_hw_data_dh895xcciov(accel_dev->hw_device); 120 120 121 121 /* Get Accelerators and Accelerators Engines masks */ 122 - hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); 123 - hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); 122 + hw_data->accel_mask = hw_data->get_accel_mask(hw_data); 123 + hw_data->ae_mask = hw_data->get_ae_mask(hw_data); 124 124 accel_pci_dev->sku = hw_data->get_sku(hw_data); 125 125 126 126 /* Create dev top level debugfs entry */
+2 -1
drivers/crypto/qce/common.c
··· 7 7 #include <linux/interrupt.h> 8 8 #include <linux/types.h> 9 9 #include <crypto/scatterwalk.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha1.h> 11 + #include <crypto/sha2.h> 11 12 12 13 #include "cipher.h" 13 14 #include "common.h"
+16 -2
drivers/crypto/qce/core.c
··· 13 13 #include <linux/types.h> 14 14 #include <crypto/algapi.h> 15 15 #include <crypto/internal/hash.h> 16 - #include <crypto/sha.h> 17 16 18 17 #include "core.h" 19 18 #include "cipher.h" ··· 159 160 return -ENODEV; 160 161 161 162 qce->burst_size = QCE_BAM_BURST_SIZE; 162 - qce->pipe_pair_id = 1; 163 + 164 + /* 165 + * Rx and tx pipes are treated as a pair inside CE. 166 + * Pipe pair number depends on the actual BAM dma pipe 167 + * that is used for transfers. The BAM dma pipes are passed 168 + * from the device tree and used to derive the pipe pair 169 + * id in the CE driver as follows. 170 + * BAM dma pipes(rx, tx) CE pipe pair id 171 + * 0,1 0 172 + * 2,3 1 173 + * 4,5 2 174 + * 6,7 3 175 + * ... 176 + */ 177 + qce->pipe_pair_id = qce->dma.rxchan->chan_id >> 1; 163 178 164 179 dev_dbg(qce->dev, "Crypto device found, version %d.%d.%d\n", 165 180 major, minor, step); ··· 274 261 275 262 static const struct of_device_id qce_crypto_of_match[] = { 276 263 { .compatible = "qcom,crypto-v5.1", }, 264 + { .compatible = "qcom,crypto-v5.4", }, 277 265 {} 278 266 }; 279 267 MODULE_DEVICE_TABLE(of, qce_crypto_of_match);
+1 -1
drivers/crypto/qce/sha.c
··· 48 48 dma_unmap_sg(qce->dev, &rctx->result_sg, 1, DMA_FROM_DEVICE); 49 49 50 50 memcpy(rctx->digest, result->auth_iv, digestsize); 51 - if (req->result) 51 + if (req->result && rctx->last_blk) 52 52 memcpy(req->result, result->auth_iv, digestsize); 53 53 54 54 rctx->byte_count[0] = cpu_to_be32(result->auth_byte_count[0]);
+2 -1
drivers/crypto/qce/sha.h
··· 7 7 #define _SHA_H_ 8 8 9 9 #include <crypto/scatterwalk.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha1.h> 11 + #include <crypto/sha2.h> 11 12 12 13 #include "common.h" 13 14 #include "core.h"
+2 -1
drivers/crypto/rockchip/rk3288_crypto.h
··· 12 12 #include <crypto/internal/skcipher.h> 13 13 14 14 #include <crypto/md5.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha1.h> 16 + #include <crypto/sha2.h> 16 17 17 18 #define _SBF(v, f) ((v) << (f)) 18 19
+2 -1
drivers/crypto/s5p-sss.c
··· 30 30 31 31 #include <crypto/hash.h> 32 32 #include <crypto/md5.h> 33 - #include <crypto/sha.h> 33 + #include <crypto/sha1.h> 34 + #include <crypto/sha2.h> 34 35 #include <crypto/internal/hash.h> 35 36 36 37 #define _SBF(s, v) ((v) << (s))
+64 -59
drivers/crypto/sa2ul.c
··· 9 9 * Tero Kristo 10 10 */ 11 11 #include <linux/clk.h> 12 + #include <linux/dma-mapping.h> 12 13 #include <linux/dmaengine.h> 13 14 #include <linux/dmapool.h> 15 + #include <linux/kernel.h> 14 16 #include <linux/module.h> 15 17 #include <linux/of_device.h> 16 18 #include <linux/platform_device.h> ··· 25 23 #include <crypto/internal/hash.h> 26 24 #include <crypto/internal/skcipher.h> 27 25 #include <crypto/scatterwalk.h> 28 - #include <crypto/sha.h> 26 + #include <crypto/sha1.h> 27 + #include <crypto/sha2.h> 29 28 30 29 #include "sa2ul.h" 31 30 ··· 364 361 } 365 362 366 363 /* Prepare the ipad and opad from key as per SHA algorithm step 1*/ 367 - static void prepare_kiopad(u8 *k_ipad, u8 *k_opad, const u8 *key, u16 key_sz) 364 + static void prepare_kipad(u8 *k_ipad, const u8 *key, u16 key_sz) 368 365 { 369 366 int i; 370 367 371 - for (i = 0; i < key_sz; i++) { 368 + for (i = 0; i < key_sz; i++) 372 369 k_ipad[i] = key[i] ^ 0x36; 373 - k_opad[i] = key[i] ^ 0x5c; 374 - } 375 370 376 371 /* Instead of XOR with 0 */ 377 - for (; i < SHA1_BLOCK_SIZE; i++) { 372 + for (; i < SHA1_BLOCK_SIZE; i++) 378 373 k_ipad[i] = 0x36; 379 - k_opad[i] = 0x5c; 380 - } 381 374 } 382 375 383 - static void sa_export_shash(struct shash_desc *hash, int block_size, 376 + static void prepare_kopad(u8 *k_opad, const u8 *key, u16 key_sz) 377 + { 378 + int i; 379 + 380 + for (i = 0; i < key_sz; i++) 381 + k_opad[i] = key[i] ^ 0x5c; 382 + 383 + /* Instead of XOR with 0 */ 384 + for (; i < SHA1_BLOCK_SIZE; i++) 385 + k_opad[i] = 0x5c; 386 + } 387 + 388 + static void sa_export_shash(void *state, struct shash_desc *hash, 384 389 int digest_size, __be32 *out) 385 390 { 386 - union { 387 - struct sha1_state sha1; 388 - struct sha256_state sha256; 389 - struct sha512_state sha512; 390 - } sha; 391 - void *state; 391 + struct sha1_state *sha1; 392 + struct sha256_state *sha256; 392 393 u32 *result; 393 - int i; 394 394 395 395 switch (digest_size) { 396 396 case SHA1_DIGEST_SIZE: 397 - state = &sha.sha1; 398 - result = sha.sha1.state; 397 + sha1 = state; 398 + result = sha1->state; 399 399 break; 400 400 case SHA256_DIGEST_SIZE: 401 - state = &sha.sha256; 402 - result = sha.sha256.state; 401 + sha256 = state; 402 + result = sha256->state; 403 403 break; 404 404 default: 405 405 dev_err(sa_k3_dev, "%s: bad digest_size=%d\n", __func__, ··· 412 406 413 407 crypto_shash_export(hash, state); 414 408 415 - for (i = 0; i < digest_size >> 2; i++) 416 - out[i] = cpu_to_be32(result[i]); 409 + cpu_to_be32_array(out, result, digest_size / 4); 417 410 } 418 411 419 412 static void sa_prepare_iopads(struct algo_data *data, const u8 *key, ··· 421 416 SHASH_DESC_ON_STACK(shash, data->ctx->shash); 422 417 int block_size = crypto_shash_blocksize(data->ctx->shash); 423 418 int digest_size = crypto_shash_digestsize(data->ctx->shash); 424 - u8 k_ipad[SHA1_BLOCK_SIZE]; 425 - u8 k_opad[SHA1_BLOCK_SIZE]; 419 + union { 420 + struct sha1_state sha1; 421 + struct sha256_state sha256; 422 + u8 k_pad[SHA1_BLOCK_SIZE]; 423 + } sha; 426 424 427 425 shash->tfm = data->ctx->shash; 428 426 429 - prepare_kiopad(k_ipad, k_opad, key, key_sz); 430 - 431 - memzero_explicit(ipad, block_size); 432 - memzero_explicit(opad, block_size); 427 + prepare_kipad(sha.k_pad, key, key_sz); 433 428 434 429 crypto_shash_init(shash); 435 - crypto_shash_update(shash, k_ipad, block_size); 436 - sa_export_shash(shash, block_size, digest_size, ipad); 430 + crypto_shash_update(shash, sha.k_pad, block_size); 431 + sa_export_shash(&sha, shash, digest_size, ipad); 432 + 433 + prepare_kopad(sha.k_pad, key, key_sz); 437 434 438 435 crypto_shash_init(shash); 439 - crypto_shash_update(shash, k_opad, block_size); 436 + crypto_shash_update(shash, sha.k_pad, block_size); 440 437 441 - sa_export_shash(shash, block_size, digest_size, opad); 438 + sa_export_shash(&sha, shash, digest_size, opad); 439 + 440 + memzero_explicit(&sha, sizeof(sha)); 442 441 } 443 442 444 443 /* Derive the inverse key used in AES-CBC decryption operation */ ··· 515 506 static void sa_set_sc_auth(struct algo_data *ad, const u8 *key, u16 key_sz, 516 507 u8 *sc_buf) 517 508 { 518 - __be32 ipad[64], opad[64]; 509 + __be32 *ipad = (void *)(sc_buf + 32); 510 + __be32 *opad = (void *)(sc_buf + 64); 519 511 520 512 /* Set Authentication mode selector to hash processing */ 521 513 sc_buf[0] = SA_HASH_PROCESSING; ··· 525 515 sc_buf[1] |= ad->auth_ctrl; 526 516 527 517 /* Copy the keys or ipad/opad */ 528 - if (ad->keyed_mac) { 518 + if (ad->keyed_mac) 529 519 ad->prep_iopad(ad, key, key_sz, ipad, opad); 530 - 531 - /* Copy ipad to AuthKey */ 532 - memcpy(&sc_buf[32], ipad, ad->hash_size); 533 - /* Copy opad to Aux-1 */ 534 - memcpy(&sc_buf[64], opad, ad->hash_size); 535 - } else { 520 + else { 536 521 /* basic hash */ 537 522 sc_buf[1] |= SA_BASIC_HASH; 538 523 } ··· 824 819 sa_free_ctx_info(&ctx->enc, data); 825 820 sa_free_ctx_info(&ctx->dec, data); 826 821 827 - crypto_free_sync_skcipher(ctx->fallback.skcipher); 822 + crypto_free_skcipher(ctx->fallback.skcipher); 828 823 } 829 824 830 825 static int sa_cipher_cra_init(struct crypto_skcipher *tfm) ··· 832 827 struct sa_tfm_ctx *ctx = crypto_skcipher_ctx(tfm); 833 828 struct sa_crypto_data *data = dev_get_drvdata(sa_k3_dev); 834 829 const char *name = crypto_tfm_alg_name(&tfm->base); 830 + struct crypto_skcipher *child; 835 831 int ret; 836 832 837 833 memzero_explicit(ctx, sizeof(*ctx)); ··· 847 841 return ret; 848 842 } 849 843 850 - ctx->fallback.skcipher = 851 - crypto_alloc_sync_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK); 844 + child = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK); 852 845 853 - if (IS_ERR(ctx->fallback.skcipher)) { 846 + if (IS_ERR(child)) { 854 847 dev_err(sa_k3_dev, "Error allocating fallback algo %s\n", name); 855 - return PTR_ERR(ctx->fallback.skcipher); 848 + return PTR_ERR(child); 856 849 } 850 + 851 + ctx->fallback.skcipher = child; 852 + crypto_skcipher_set_reqsize(tfm, crypto_skcipher_reqsize(child) + 853 + sizeof(struct skcipher_request)); 857 854 858 855 dev_dbg(sa_k3_dev, "%s(0x%p) sc-ids(0x%x(0x%pad), 0x%x(0x%pad))\n", 859 856 __func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys, ··· 868 859 unsigned int keylen, struct algo_data *ad) 869 860 { 870 861 struct sa_tfm_ctx *ctx = crypto_skcipher_ctx(tfm); 862 + struct crypto_skcipher *child = ctx->fallback.skcipher; 871 863 int cmdl_len; 872 864 struct sa_cmdl_cfg cfg; 873 865 int ret; ··· 884 874 cfg.enc_eng_id = ad->enc_eng.eng_id; 885 875 cfg.iv_size = crypto_skcipher_ivsize(tfm); 886 876 887 - crypto_sync_skcipher_clear_flags(ctx->fallback.skcipher, 877 + crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); 878 + crypto_skcipher_set_flags(child, tfm->base.crt_flags & 888 879 CRYPTO_TFM_REQ_MASK); 889 - crypto_sync_skcipher_set_flags(ctx->fallback.skcipher, 890 - tfm->base.crt_flags & 891 - CRYPTO_TFM_REQ_MASK); 892 - ret = crypto_sync_skcipher_setkey(ctx->fallback.skcipher, key, keylen); 880 + ret = crypto_skcipher_setkey(child, key, keylen); 893 881 if (ret) 894 882 return ret; 895 883 ··· 1278 1270 crypto_skcipher_ctx(crypto_skcipher_reqtfm(req)); 1279 1271 struct crypto_alg *alg = req->base.tfm->__crt_alg; 1280 1272 struct sa_req sa_req = { 0 }; 1281 - int ret; 1282 1273 1283 1274 if (!req->cryptlen) 1284 1275 return 0; ··· 1289 1282 if (req->cryptlen > SA_MAX_DATA_SZ || 1290 1283 (req->cryptlen >= SA_UNSAFE_DATA_SZ_MIN && 1291 1284 req->cryptlen <= SA_UNSAFE_DATA_SZ_MAX)) { 1292 - SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback.skcipher); 1285 + struct skcipher_request *subreq = skcipher_request_ctx(req); 1293 1286 1294 - skcipher_request_set_sync_tfm(subreq, ctx->fallback.skcipher); 1287 + skcipher_request_set_tfm(subreq, ctx->fallback.skcipher); 1295 1288 skcipher_request_set_callback(subreq, req->base.flags, 1296 - NULL, NULL); 1289 + req->base.complete, 1290 + req->base.data); 1297 1291 skcipher_request_set_crypt(subreq, req->src, req->dst, 1298 1292 req->cryptlen, req->iv); 1299 1293 if (enc) 1300 - ret = crypto_skcipher_encrypt(subreq); 1294 + return crypto_skcipher_encrypt(subreq); 1301 1295 else 1302 - ret = crypto_skcipher_decrypt(subreq); 1303 - 1304 - skcipher_request_zero(subreq); 1305 - return ret; 1296 + return crypto_skcipher_decrypt(subreq); 1306 1297 } 1307 1298 1308 1299 sa_req.size = req->cryptlen;
+3 -4
drivers/crypto/sa2ul.h
··· 12 12 #ifndef _K3_SA2UL_ 13 13 #define _K3_SA2UL_ 14 14 15 - #include <linux/interrupt.h> 16 - #include <linux/skbuff.h> 17 - #include <linux/hw_random.h> 18 15 #include <crypto/aes.h> 16 + #include <crypto/sha1.h> 17 + #include <crypto/sha2.h> 19 18 20 19 #define SA_ENGINE_ENABLE_CONTROL 0x1000 21 20 ··· 310 311 struct crypto_shash *shash; 311 312 /* for fallback */ 312 313 union { 313 - struct crypto_sync_skcipher *skcipher; 314 + struct crypto_skcipher *skcipher; 314 315 struct crypto_ahash *ahash; 315 316 struct crypto_aead *aead; 316 317 } fallback;
+2 -1
drivers/crypto/sahara.c
··· 15 15 #include <crypto/internal/hash.h> 16 16 #include <crypto/internal/skcipher.h> 17 17 #include <crypto/scatterwalk.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha1.h> 19 + #include <crypto/sha2.h> 19 20 20 21 #include <linux/clk.h> 21 22 #include <linux/dma-mapping.h>
+2 -1
drivers/crypto/stm32/stm32-hash.c
··· 25 25 #include <crypto/hash.h> 26 26 #include <crypto/md5.h> 27 27 #include <crypto/scatterwalk.h> 28 - #include <crypto/sha.h> 28 + #include <crypto/sha1.h> 29 + #include <crypto/sha2.h> 29 30 #include <crypto/internal/hash.h> 30 31 31 32 #define HASH_CR 0x00
+7 -6
drivers/crypto/talitos.c
··· 31 31 #include <crypto/algapi.h> 32 32 #include <crypto/aes.h> 33 33 #include <crypto/internal/des.h> 34 - #include <crypto/sha.h> 34 + #include <crypto/sha1.h> 35 + #include <crypto/sha2.h> 35 36 #include <crypto/md5.h> 36 37 #include <crypto/internal/aead.h> 37 38 #include <crypto/authenc.h> ··· 461 460 /* 462 461 * locate current (offending) descriptor 463 462 */ 464 - static u32 current_desc_hdr(struct device *dev, int ch) 463 + static __be32 current_desc_hdr(struct device *dev, int ch) 465 464 { 466 465 struct talitos_private *priv = dev_get_drvdata(dev); 467 466 int tail, iter; ··· 479 478 480 479 iter = tail; 481 480 while (priv->chan[ch].fifo[iter].dma_desc != cur_desc && 482 - priv->chan[ch].fifo[iter].desc->next_desc != cur_desc) { 481 + priv->chan[ch].fifo[iter].desc->next_desc != cpu_to_be32(cur_desc)) { 483 482 iter = (iter + 1) & (priv->fifo_len - 1); 484 483 if (iter == tail) { 485 484 dev_err(dev, "couldn't locate current descriptor\n"); ··· 487 486 } 488 487 } 489 488 490 - if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc) { 489 + if (priv->chan[ch].fifo[iter].desc->next_desc == cpu_to_be32(cur_desc)) { 491 490 struct talitos_edesc *edesc; 492 491 493 492 edesc = container_of(priv->chan[ch].fifo[iter].desc, ··· 502 501 /* 503 502 * user diagnostics; report root cause of error based on execution unit status 504 503 */ 505 - static void report_eu_error(struct device *dev, int ch, u32 desc_hdr) 504 + static void report_eu_error(struct device *dev, int ch, __be32 desc_hdr) 506 505 { 507 506 struct talitos_private *priv = dev_get_drvdata(dev); 508 507 int i; 509 508 510 509 if (!desc_hdr) 511 - desc_hdr = in_be32(priv->chan[ch].reg + TALITOS_DESCBUF); 510 + desc_hdr = cpu_to_be32(in_be32(priv->chan[ch].reg + TALITOS_DESCBUF)); 512 511 513 512 switch (desc_hdr & DESC_HDR_SEL0_MASK) { 514 513 case DESC_HDR_SEL0_AFEU:
+2 -1
drivers/crypto/ux500/hash/hash_core.c
··· 31 31 #include <linux/bitops.h> 32 32 33 33 #include <crypto/internal/hash.h> 34 - #include <crypto/sha.h> 34 + #include <crypto/sha1.h> 35 + #include <crypto/sha2.h> 35 36 #include <crypto/scatterwalk.h> 36 37 #include <crypto/algapi.h> 37 38
+1 -1
drivers/firmware/efi/embedded-firmware.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/types.h> 14 14 #include <linux/vmalloc.h> 15 - #include <crypto/sha.h> 15 + #include <crypto/sha2.h> 16 16 17 17 /* Exported for use by lib/test_firmware.c only */ 18 18 LIST_HEAD(efi_embedded_fw_list);
+2 -1
drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c
··· 51 51 #include <crypto/aes.h> 52 52 #include <crypto/algapi.h> 53 53 #include <crypto/hash.h> 54 - #include <crypto/sha.h> 54 + #include <crypto/sha1.h> 55 + #include <crypto/sha2.h> 55 56 #include <crypto/authenc.h> 56 57 #include <crypto/internal/aead.h> 57 58 #include <crypto/null.h>
+2 -1
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls.h
··· 9 9 #include <crypto/aes.h> 10 10 #include <crypto/algapi.h> 11 11 #include <crypto/hash.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha1.h> 13 + #include <crypto/sha2.h> 13 14 #include <crypto/authenc.h> 14 15 #include <crypto/ctr.h> 15 16 #include <crypto/gf128mul.h>
+1 -1
drivers/nfc/s3fwrn5/firmware.c
··· 9 9 #include <linux/completion.h> 10 10 #include <linux/firmware.h> 11 11 #include <crypto/hash.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha1.h> 13 13 14 14 #include "s3fwrn5.h" 15 15 #include "firmware.h"
+1 -1
drivers/tee/tee_core.c
··· 14 14 #include <linux/tee_drv.h> 15 15 #include <linux/uaccess.h> 16 16 #include <crypto/hash.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha1.h> 18 18 #include "tee_private.h" 19 19 20 20 #define TEE_NUM_DEVICES 32
+1 -1
fs/crypto/fname.c
··· 14 14 #include <linux/namei.h> 15 15 #include <linux/scatterlist.h> 16 16 #include <crypto/hash.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha2.h> 18 18 #include <crypto/skcipher.h> 19 19 #include "fscrypt_private.h" 20 20
+1 -1
fs/crypto/hkdf.c
··· 10 10 */ 11 11 12 12 #include <crypto/hash.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 15 15 #include "fscrypt_private.h" 16 16
-1
fs/ubifs/auth.c
··· 12 12 #include <linux/crypto.h> 13 13 #include <linux/verification.h> 14 14 #include <crypto/hash.h> 15 - #include <crypto/sha.h> 16 15 #include <crypto/algapi.h> 17 16 #include <keys/user-type.h> 18 17 #include <keys/asymmetric-type.h>
+1 -1
fs/verity/fsverity_private.h
··· 14 14 15 15 #define pr_fmt(fmt) "fs-verity: " fmt 16 16 17 - #include <crypto/sha.h> 17 + #include <crypto/sha2.h> 18 18 #include <linux/fsverity.h> 19 19 #include <linux/mempool.h> 20 20
+5
include/crypto/aead.h
··· 191 191 crypto_destroy_tfm(tfm, crypto_aead_tfm(tfm)); 192 192 } 193 193 194 + static inline const char *crypto_aead_driver_name(struct crypto_aead *tfm) 195 + { 196 + return crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 197 + } 198 + 194 199 static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm) 195 200 { 196 201 return container_of(crypto_aead_tfm(tfm)->__crt_alg,
+2
include/crypto/curve25519.h
··· 28 28 void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE], 29 29 const u8 secret[CURVE25519_KEY_SIZE]); 30 30 31 + bool curve25519_selftest(void); 32 + 31 33 static inline 32 34 bool __must_check curve25519(u8 mypublic[CURVE25519_KEY_SIZE], 33 35 const u8 secret[CURVE25519_KEY_SIZE],
+2 -1
include/crypto/hash_info.h
··· 8 8 #ifndef _CRYPTO_HASH_INFO_H 9 9 #define _CRYPTO_HASH_INFO_H 10 10 11 - #include <crypto/sha.h> 11 + #include <crypto/sha1.h> 12 + #include <crypto/sha2.h> 12 13 #include <crypto/md5.h> 13 14 #include <crypto/streebog.h> 14 15
+2
include/crypto/internal/blake2s.h
··· 16 16 void blake2s_compress_arch(struct blake2s_state *state,const u8 *block, 17 17 size_t nblocks, const u32 inc); 18 18 19 + bool blake2s_selftest(void); 20 + 19 21 static inline void blake2s_set_lastblock(struct blake2s_state *state) 20 22 { 21 23 state->f[0] = -1;
+4 -37
include/crypto/sha.h include/crypto/sha2.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 - * Common values for SHA algorithms 3 + * Common values for SHA-2 algorithms 4 4 */ 5 5 6 - #ifndef _CRYPTO_SHA_H 7 - #define _CRYPTO_SHA_H 6 + #ifndef _CRYPTO_SHA2_H 7 + #define _CRYPTO_SHA2_H 8 8 9 9 #include <linux/types.h> 10 - 11 - #define SHA1_DIGEST_SIZE 20 12 - #define SHA1_BLOCK_SIZE 64 13 10 14 11 #define SHA224_DIGEST_SIZE 28 15 12 #define SHA224_BLOCK_SIZE 64 ··· 19 22 20 23 #define SHA512_DIGEST_SIZE 64 21 24 #define SHA512_BLOCK_SIZE 128 22 - 23 - #define SHA1_H0 0x67452301UL 24 - #define SHA1_H1 0xefcdab89UL 25 - #define SHA1_H2 0x98badcfeUL 26 - #define SHA1_H3 0x10325476UL 27 - #define SHA1_H4 0xc3d2e1f0UL 28 25 29 26 #define SHA224_H0 0xc1059ed8UL 30 27 #define SHA224_H1 0x367cd507UL ··· 56 65 #define SHA512_H6 0x1f83d9abfb41bd6bULL 57 66 #define SHA512_H7 0x5be0cd19137e2179ULL 58 67 59 - extern const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE]; 60 - 61 68 extern const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE]; 62 69 63 70 extern const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE]; ··· 63 74 extern const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE]; 64 75 65 76 extern const u8 sha512_zero_message_hash[SHA512_DIGEST_SIZE]; 66 - 67 - struct sha1_state { 68 - u32 state[SHA1_DIGEST_SIZE / 4]; 69 - u64 count; 70 - u8 buffer[SHA1_BLOCK_SIZE]; 71 - }; 72 77 73 78 struct sha256_state { 74 79 u32 state[SHA256_DIGEST_SIZE / 4]; ··· 78 95 79 96 struct shash_desc; 80 97 81 - extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data, 82 - unsigned int len); 83 - 84 - extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data, 85 - unsigned int len, u8 *hash); 86 - 87 98 extern int crypto_sha256_update(struct shash_desc *desc, const u8 *data, 88 99 unsigned int len); 89 100 ··· 89 112 90 113 extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, 91 114 unsigned int len, u8 *hash); 92 - 93 - /* 94 - * An implementation of SHA-1's compression function. Don't use in new code! 95 - * You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this isn't 96 - * the correct way to hash something with SHA-1 (use crypto_shash instead). 97 - */ 98 - #define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4) 99 - #define SHA1_WORKSPACE_WORDS 16 100 - void sha1_init(__u32 *buf); 101 - void sha1_transform(__u32 *digest, const char *data, __u32 *W); 102 115 103 116 /* 104 117 * Stand-alone implementation of the SHA256 algorithm. It is designed to ··· 131 164 void sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len); 132 165 void sha224_final(struct sha256_state *sctx, u8 *out); 133 166 134 - #endif 167 + #endif /* _CRYPTO_SHA2_H */
+46
include/crypto/sha1.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Common values for SHA-1 algorithms 4 + */ 5 + 6 + #ifndef _CRYPTO_SHA1_H 7 + #define _CRYPTO_SHA1_H 8 + 9 + #include <linux/types.h> 10 + 11 + #define SHA1_DIGEST_SIZE 20 12 + #define SHA1_BLOCK_SIZE 64 13 + 14 + #define SHA1_H0 0x67452301UL 15 + #define SHA1_H1 0xefcdab89UL 16 + #define SHA1_H2 0x98badcfeUL 17 + #define SHA1_H3 0x10325476UL 18 + #define SHA1_H4 0xc3d2e1f0UL 19 + 20 + extern const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE]; 21 + 22 + struct sha1_state { 23 + u32 state[SHA1_DIGEST_SIZE / 4]; 24 + u64 count; 25 + u8 buffer[SHA1_BLOCK_SIZE]; 26 + }; 27 + 28 + struct shash_desc; 29 + 30 + extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data, 31 + unsigned int len); 32 + 33 + extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data, 34 + unsigned int len, u8 *hash); 35 + 36 + /* 37 + * An implementation of SHA-1's compression function. Don't use in new code! 38 + * You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this isn't 39 + * the correct way to hash something with SHA-1 (use crypto_shash instead). 40 + */ 41 + #define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4) 42 + #define SHA1_WORKSPACE_WORDS 16 43 + void sha1_init(__u32 *buf); 44 + void sha1_transform(__u32 *digest, const char *data, __u32 *W); 45 + 46 + #endif /* _CRYPTO_SHA1_H */
+3 -2
include/crypto/sha1_base.h
··· 9 9 #define _CRYPTO_SHA1_BASE_H 10 10 11 11 #include <crypto/internal/hash.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha1.h> 13 13 #include <linux/crypto.h> 14 14 #include <linux/module.h> 15 + #include <linux/string.h> 15 16 16 17 #include <asm/unaligned.h> 17 18 ··· 102 101 for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++) 103 102 put_unaligned_be32(sctx->state[i], digest++); 104 103 105 - *sctx = (struct sha1_state){}; 104 + memzero_explicit(sctx, sizeof(*sctx)); 106 105 return 0; 107 106 } 108 107
+3 -2
include/crypto/sha256_base.h
··· 9 9 #define _CRYPTO_SHA256_BASE_H 10 10 11 11 #include <crypto/internal/hash.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha2.h> 13 13 #include <linux/crypto.h> 14 14 #include <linux/module.h> 15 + #include <linux/string.h> 15 16 16 17 #include <asm/unaligned.h> 17 18 ··· 106 105 for (i = 0; digest_size > 0; i++, digest_size -= sizeof(__be32)) 107 106 put_unaligned_be32(sctx->state[i], digest++); 108 107 109 - *sctx = (struct sha256_state){}; 108 + memzero_explicit(sctx, sizeof(*sctx)); 110 109 return 0; 111 110 } 112 111
+3 -2
include/crypto/sha512_base.h
··· 9 9 #define _CRYPTO_SHA512_BASE_H 10 10 11 11 #include <crypto/internal/hash.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha2.h> 13 13 #include <linux/crypto.h> 14 14 #include <linux/module.h> 15 + #include <linux/string.h> 15 16 16 17 #include <asm/unaligned.h> 17 18 ··· 127 126 for (i = 0; digest_size > 0; i++, digest_size -= sizeof(__be64)) 128 127 put_unaligned_be64(sctx->state[i], digest++); 129 128 130 - *sctx = (struct sha512_state){}; 129 + memzero_explicit(sctx, sizeof(*sctx)); 131 130 return 0; 132 131 } 133 132
+2 -1
include/crypto/sm3_base.h
··· 13 13 #include <crypto/sm3.h> 14 14 #include <linux/crypto.h> 15 15 #include <linux/module.h> 16 + #include <linux/string.h> 16 17 #include <asm/unaligned.h> 17 18 18 19 typedef void (sm3_block_fn)(struct sm3_state *sst, u8 const *src, int blocks); ··· 105 104 for (i = 0; i < SM3_DIGEST_SIZE / sizeof(__be32); i++) 106 105 put_unaligned_be32(sctx->state[i], digest++); 107 106 108 - *sctx = (struct sm3_state){}; 107 + memzero_explicit(sctx, sizeof(*sctx)); 109 108 return 0; 110 109 } 111 110
+2 -1
include/linux/ccp.h
··· 15 15 #include <linux/workqueue.h> 16 16 #include <linux/list.h> 17 17 #include <crypto/aes.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha1.h> 19 + #include <crypto/sha2.h> 19 20 20 21 struct ccp_device; 21 22 struct ccp_cmd;
+1 -1
include/linux/filter.h
··· 21 21 #include <linux/if_vlan.h> 22 22 #include <linux/vmalloc.h> 23 23 #include <linux/sockptr.h> 24 - #include <crypto/sha.h> 24 + #include <crypto/sha1.h> 25 25 26 26 #include <net/sch_generic.h> 27 27
+1 -1
include/linux/purgatory.h
··· 3 3 #define _LINUX_PURGATORY_H 4 4 5 5 #include <linux/types.h> 6 - #include <crypto/sha.h> 6 + #include <crypto/sha2.h> 7 7 #include <uapi/linux/kexec.h> 8 8 9 9 struct kexec_sha_region {
+16
include/uapi/linux/if_alg.h
··· 24 24 __u8 salg_name[64]; 25 25 }; 26 26 27 + /* 28 + * Linux v4.12 and later removed the 64-byte limit on salg_name[]; it's now an 29 + * arbitrary-length field. We had to keep the original struct above for source 30 + * compatibility with existing userspace programs, though. Use the new struct 31 + * below if support for very long algorithm names is needed. To do this, 32 + * allocate 'sizeof(struct sockaddr_alg_new) + strlen(algname) + 1' bytes, and 33 + * copy algname (including the null terminator) into salg_name. 34 + */ 35 + struct sockaddr_alg_new { 36 + __u16 salg_family; 37 + __u8 salg_type[14]; 38 + __u32 salg_feat; 39 + __u32 salg_mask; 40 + __u8 salg_name[]; 41 + }; 42 + 27 43 struct af_alg_iv { 28 44 __u32 ivlen; 29 45 __u8 iv[0];
+1 -1
kernel/crash_core.c
··· 11 11 #include <asm/page.h> 12 12 #include <asm/sections.h> 13 13 14 - #include <crypto/sha.h> 14 + #include <crypto/sha1.h> 15 15 16 16 /* vmcoreinfo stuff */ 17 17 unsigned char *vmcoreinfo_data;
-1
kernel/kexec_core.c
··· 42 42 #include <asm/sections.h> 43 43 44 44 #include <crypto/hash.h> 45 - #include <crypto/sha.h> 46 45 #include "kexec_internal.h" 47 46 48 47 DEFINE_MUTEX(kexec_mutex);
+1 -1
kernel/kexec_file.c
··· 20 20 #include <linux/fs.h> 21 21 #include <linux/ima.h> 22 22 #include <crypto/hash.h> 23 - #include <crypto/sha.h> 23 + #include <crypto/sha2.h> 24 24 #include <linux/elf.h> 25 25 #include <linux/elfcore.h> 26 26 #include <linux/kernel.h>
+1 -1
lib/crypto/blake2s-selftest.c
··· 3 3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 4 4 */ 5 5 6 - #include <crypto/blake2s.h> 6 + #include <crypto/internal/blake2s.h> 7 7 #include <linux/string.h> 8 8 9 9 /*
-2
lib/crypto/blake2s.c
··· 17 17 #include <linux/bug.h> 18 18 #include <asm/unaligned.h> 19 19 20 - bool blake2s_selftest(void); 21 - 22 20 void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen) 23 21 { 24 22 const size_t fill = BLAKE2S_BLOCK_SIZE - state->buflen;
-2
lib/crypto/curve25519.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/init.h> 15 15 16 - bool curve25519_selftest(void); 17 - 18 16 static int __init mod_init(void) 19 17 { 20 18 if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) &&
+65 -149
lib/crypto/sha256.c
··· 15 15 #include <linux/export.h> 16 16 #include <linux/module.h> 17 17 #include <linux/string.h> 18 - #include <crypto/sha.h> 18 + #include <crypto/sha2.h> 19 19 #include <asm/unaligned.h> 20 + 21 + static const u32 SHA256_K[] = { 22 + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 23 + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 24 + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 25 + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 26 + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 27 + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 28 + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 29 + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 30 + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 31 + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 32 + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 33 + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 34 + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 35 + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 36 + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 37 + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, 38 + }; 20 39 21 40 static inline u32 Ch(u32 x, u32 y, u32 z) 22 41 { ··· 62 43 W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16]; 63 44 } 64 45 65 - static void sha256_transform(u32 *state, const u8 *input) 46 + #define SHA256_ROUND(i, a, b, c, d, e, f, g, h) do { \ 47 + u32 t1, t2; \ 48 + t1 = h + e1(e) + Ch(e, f, g) + SHA256_K[i] + W[i]; \ 49 + t2 = e0(a) + Maj(a, b, c); \ 50 + d += t1; \ 51 + h = t1 + t2; \ 52 + } while (0) 53 + 54 + static void sha256_transform(u32 *state, const u8 *input, u32 *W) 66 55 { 67 - u32 a, b, c, d, e, f, g, h, t1, t2; 68 - u32 W[64]; 56 + u32 a, b, c, d, e, f, g, h; 69 57 int i; 70 58 71 59 /* load the input */ 72 - for (i = 0; i < 16; i++) 73 - LOAD_OP(i, W, input); 60 + for (i = 0; i < 16; i += 8) { 61 + LOAD_OP(i + 0, W, input); 62 + LOAD_OP(i + 1, W, input); 63 + LOAD_OP(i + 2, W, input); 64 + LOAD_OP(i + 3, W, input); 65 + LOAD_OP(i + 4, W, input); 66 + LOAD_OP(i + 5, W, input); 67 + LOAD_OP(i + 6, W, input); 68 + LOAD_OP(i + 7, W, input); 69 + } 74 70 75 71 /* now blend */ 76 - for (i = 16; i < 64; i++) 77 - BLEND_OP(i, W); 72 + for (i = 16; i < 64; i += 8) { 73 + BLEND_OP(i + 0, W); 74 + BLEND_OP(i + 1, W); 75 + BLEND_OP(i + 2, W); 76 + BLEND_OP(i + 3, W); 77 + BLEND_OP(i + 4, W); 78 + BLEND_OP(i + 5, W); 79 + BLEND_OP(i + 6, W); 80 + BLEND_OP(i + 7, W); 81 + } 78 82 79 83 /* load the state into our registers */ 80 84 a = state[0]; b = state[1]; c = state[2]; d = state[3]; 81 85 e = state[4]; f = state[5]; g = state[6]; h = state[7]; 82 86 83 87 /* now iterate */ 84 - t1 = h + e1(e) + Ch(e, f, g) + 0x428a2f98 + W[0]; 85 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 86 - t1 = g + e1(d) + Ch(d, e, f) + 0x71374491 + W[1]; 87 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 88 - t1 = f + e1(c) + Ch(c, d, e) + 0xb5c0fbcf + W[2]; 89 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 90 - t1 = e + e1(b) + Ch(b, c, d) + 0xe9b5dba5 + W[3]; 91 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 92 - t1 = d + e1(a) + Ch(a, b, c) + 0x3956c25b + W[4]; 93 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 94 - t1 = c + e1(h) + Ch(h, a, b) + 0x59f111f1 + W[5]; 95 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 96 - t1 = b + e1(g) + Ch(g, h, a) + 0x923f82a4 + W[6]; 97 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 98 - t1 = a + e1(f) + Ch(f, g, h) + 0xab1c5ed5 + W[7]; 99 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 100 - 101 - t1 = h + e1(e) + Ch(e, f, g) + 0xd807aa98 + W[8]; 102 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 103 - t1 = g + e1(d) + Ch(d, e, f) + 0x12835b01 + W[9]; 104 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 105 - t1 = f + e1(c) + Ch(c, d, e) + 0x243185be + W[10]; 106 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 107 - t1 = e + e1(b) + Ch(b, c, d) + 0x550c7dc3 + W[11]; 108 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 109 - t1 = d + e1(a) + Ch(a, b, c) + 0x72be5d74 + W[12]; 110 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 111 - t1 = c + e1(h) + Ch(h, a, b) + 0x80deb1fe + W[13]; 112 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 113 - t1 = b + e1(g) + Ch(g, h, a) + 0x9bdc06a7 + W[14]; 114 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 115 - t1 = a + e1(f) + Ch(f, g, h) + 0xc19bf174 + W[15]; 116 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 117 - 118 - t1 = h + e1(e) + Ch(e, f, g) + 0xe49b69c1 + W[16]; 119 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 120 - t1 = g + e1(d) + Ch(d, e, f) + 0xefbe4786 + W[17]; 121 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 122 - t1 = f + e1(c) + Ch(c, d, e) + 0x0fc19dc6 + W[18]; 123 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 124 - t1 = e + e1(b) + Ch(b, c, d) + 0x240ca1cc + W[19]; 125 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 126 - t1 = d + e1(a) + Ch(a, b, c) + 0x2de92c6f + W[20]; 127 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 128 - t1 = c + e1(h) + Ch(h, a, b) + 0x4a7484aa + W[21]; 129 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 130 - t1 = b + e1(g) + Ch(g, h, a) + 0x5cb0a9dc + W[22]; 131 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 132 - t1 = a + e1(f) + Ch(f, g, h) + 0x76f988da + W[23]; 133 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 134 - 135 - t1 = h + e1(e) + Ch(e, f, g) + 0x983e5152 + W[24]; 136 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 137 - t1 = g + e1(d) + Ch(d, e, f) + 0xa831c66d + W[25]; 138 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 139 - t1 = f + e1(c) + Ch(c, d, e) + 0xb00327c8 + W[26]; 140 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 141 - t1 = e + e1(b) + Ch(b, c, d) + 0xbf597fc7 + W[27]; 142 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 143 - t1 = d + e1(a) + Ch(a, b, c) + 0xc6e00bf3 + W[28]; 144 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 145 - t1 = c + e1(h) + Ch(h, a, b) + 0xd5a79147 + W[29]; 146 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 147 - t1 = b + e1(g) + Ch(g, h, a) + 0x06ca6351 + W[30]; 148 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 149 - t1 = a + e1(f) + Ch(f, g, h) + 0x14292967 + W[31]; 150 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 151 - 152 - t1 = h + e1(e) + Ch(e, f, g) + 0x27b70a85 + W[32]; 153 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 154 - t1 = g + e1(d) + Ch(d, e, f) + 0x2e1b2138 + W[33]; 155 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 156 - t1 = f + e1(c) + Ch(c, d, e) + 0x4d2c6dfc + W[34]; 157 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 158 - t1 = e + e1(b) + Ch(b, c, d) + 0x53380d13 + W[35]; 159 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 160 - t1 = d + e1(a) + Ch(a, b, c) + 0x650a7354 + W[36]; 161 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 162 - t1 = c + e1(h) + Ch(h, a, b) + 0x766a0abb + W[37]; 163 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 164 - t1 = b + e1(g) + Ch(g, h, a) + 0x81c2c92e + W[38]; 165 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 166 - t1 = a + e1(f) + Ch(f, g, h) + 0x92722c85 + W[39]; 167 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 168 - 169 - t1 = h + e1(e) + Ch(e, f, g) + 0xa2bfe8a1 + W[40]; 170 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 171 - t1 = g + e1(d) + Ch(d, e, f) + 0xa81a664b + W[41]; 172 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 173 - t1 = f + e1(c) + Ch(c, d, e) + 0xc24b8b70 + W[42]; 174 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 175 - t1 = e + e1(b) + Ch(b, c, d) + 0xc76c51a3 + W[43]; 176 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 177 - t1 = d + e1(a) + Ch(a, b, c) + 0xd192e819 + W[44]; 178 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 179 - t1 = c + e1(h) + Ch(h, a, b) + 0xd6990624 + W[45]; 180 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 181 - t1 = b + e1(g) + Ch(g, h, a) + 0xf40e3585 + W[46]; 182 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 183 - t1 = a + e1(f) + Ch(f, g, h) + 0x106aa070 + W[47]; 184 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 185 - 186 - t1 = h + e1(e) + Ch(e, f, g) + 0x19a4c116 + W[48]; 187 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 188 - t1 = g + e1(d) + Ch(d, e, f) + 0x1e376c08 + W[49]; 189 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 190 - t1 = f + e1(c) + Ch(c, d, e) + 0x2748774c + W[50]; 191 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 192 - t1 = e + e1(b) + Ch(b, c, d) + 0x34b0bcb5 + W[51]; 193 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 194 - t1 = d + e1(a) + Ch(a, b, c) + 0x391c0cb3 + W[52]; 195 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 196 - t1 = c + e1(h) + Ch(h, a, b) + 0x4ed8aa4a + W[53]; 197 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 198 - t1 = b + e1(g) + Ch(g, h, a) + 0x5b9cca4f + W[54]; 199 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 200 - t1 = a + e1(f) + Ch(f, g, h) + 0x682e6ff3 + W[55]; 201 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 202 - 203 - t1 = h + e1(e) + Ch(e, f, g) + 0x748f82ee + W[56]; 204 - t2 = e0(a) + Maj(a, b, c); d += t1; h = t1 + t2; 205 - t1 = g + e1(d) + Ch(d, e, f) + 0x78a5636f + W[57]; 206 - t2 = e0(h) + Maj(h, a, b); c += t1; g = t1 + t2; 207 - t1 = f + e1(c) + Ch(c, d, e) + 0x84c87814 + W[58]; 208 - t2 = e0(g) + Maj(g, h, a); b += t1; f = t1 + t2; 209 - t1 = e + e1(b) + Ch(b, c, d) + 0x8cc70208 + W[59]; 210 - t2 = e0(f) + Maj(f, g, h); a += t1; e = t1 + t2; 211 - t1 = d + e1(a) + Ch(a, b, c) + 0x90befffa + W[60]; 212 - t2 = e0(e) + Maj(e, f, g); h += t1; d = t1 + t2; 213 - t1 = c + e1(h) + Ch(h, a, b) + 0xa4506ceb + W[61]; 214 - t2 = e0(d) + Maj(d, e, f); g += t1; c = t1 + t2; 215 - t1 = b + e1(g) + Ch(g, h, a) + 0xbef9a3f7 + W[62]; 216 - t2 = e0(c) + Maj(c, d, e); f += t1; b = t1 + t2; 217 - t1 = a + e1(f) + Ch(f, g, h) + 0xc67178f2 + W[63]; 218 - t2 = e0(b) + Maj(b, c, d); e += t1; a = t1 + t2; 88 + for (i = 0; i < 64; i += 8) { 89 + SHA256_ROUND(i + 0, a, b, c, d, e, f, g, h); 90 + SHA256_ROUND(i + 1, h, a, b, c, d, e, f, g); 91 + SHA256_ROUND(i + 2, g, h, a, b, c, d, e, f); 92 + SHA256_ROUND(i + 3, f, g, h, a, b, c, d, e); 93 + SHA256_ROUND(i + 4, e, f, g, h, a, b, c, d); 94 + SHA256_ROUND(i + 5, d, e, f, g, h, a, b, c); 95 + SHA256_ROUND(i + 6, c, d, e, f, g, h, a, b); 96 + SHA256_ROUND(i + 7, b, c, d, e, f, g, h, a); 97 + } 219 98 220 99 state[0] += a; state[1] += b; state[2] += c; state[3] += d; 221 100 state[4] += e; state[5] += f; state[6] += g; state[7] += h; 222 - 223 - /* clear any sensitive info... */ 224 - a = b = c = d = e = f = g = h = t1 = t2 = 0; 225 - memzero_explicit(W, 64 * sizeof(u32)); 226 101 } 227 102 228 103 void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len) 229 104 { 230 105 unsigned int partial, done; 231 106 const u8 *src; 107 + u32 W[64]; 232 108 233 109 partial = sctx->count & 0x3f; 234 110 sctx->count += len; ··· 138 224 } 139 225 140 226 do { 141 - sha256_transform(sctx->state, src); 227 + sha256_transform(sctx->state, src, W); 142 228 done += 64; 143 229 src = data + done; 144 230 } while (done + 63 < len); 231 + 232 + memzero_explicit(W, sizeof(W)); 145 233 146 234 partial = 0; 147 235 } ··· 181 265 put_unaligned_be32(sctx->state[i], &dst[i]); 182 266 183 267 /* Zeroize sensitive information. */ 184 - memset(sctx, 0, sizeof(*sctx)); 268 + memzero_explicit(sctx, sizeof(*sctx)); 185 269 } 186 270 187 271 void sha256_final(struct sha256_state *sctx, u8 *out)
+1 -1
lib/digsig.c
··· 20 20 #include <linux/key.h> 21 21 #include <linux/crypto.h> 22 22 #include <crypto/hash.h> 23 - #include <crypto/sha.h> 23 + #include <crypto/sha1.h> 24 24 #include <keys/user-type.h> 25 25 #include <linux/mpi.h> 26 26 #include <linux/digsig.h>
-3
lib/mpi/ec.c
··· 1252 1252 MPI_POINT q1, q2, prd, sum; 1253 1253 unsigned long sw; 1254 1254 mpi_size_t rsize; 1255 - int scalar_copied = 0; 1256 1255 1257 1256 /* Compute scalar point multiplication with Montgomery Ladder. 1258 1257 * Note that we don't use Y-coordinate in the points at all. ··· 1313 1314 point_free(&p2); 1314 1315 point_free(&p1_); 1315 1316 point_free(&p2_); 1316 - if (scalar_copied) 1317 - mpi_free(scalar); 1318 1317 return; 1319 1318 } 1320 1319
+1 -1
lib/sha1.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/export.h> 11 11 #include <linux/bitops.h> 12 - #include <crypto/sha.h> 12 + #include <crypto/sha1.h> 13 13 #include <asm/unaligned.h> 14 14 15 15 /*
-1
net/ipv6/seg6_hmac.c
··· 35 35 #include <net/xfrm.h> 36 36 37 37 #include <crypto/hash.h> 38 - #include <crypto/sha.h> 39 38 #include <net/seg6.h> 40 39 #include <net/genetlink.h> 41 40 #include <net/seg6_hmac.h>
+1 -1
net/mptcp/crypto.c
··· 21 21 */ 22 22 23 23 #include <linux/kernel.h> 24 - #include <crypto/sha.h> 24 + #include <crypto/sha2.h> 25 25 #include <asm/unaligned.h> 26 26 27 27 #include "protocol.h"
+1 -1
net/mptcp/options.c
··· 7 7 #define pr_fmt(fmt) "MPTCP: " fmt 8 8 9 9 #include <linux/kernel.h> 10 - #include <crypto/sha.h> 10 + #include <crypto/sha2.h> 11 11 #include <net/tcp.h> 12 12 #include <net/mptcp.h> 13 13 #include "protocol.h"
+1 -1
net/mptcp/subflow.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/netdevice.h> 12 12 #include <crypto/algapi.h> 13 - #include <crypto/sha.h> 13 + #include <crypto/sha2.h> 14 14 #include <net/sock.h> 15 15 #include <net/inet_common.h> 16 16 #include <net/inet_hashtables.h>
+1 -1
security/integrity/integrity.h
··· 14 14 15 15 #include <linux/types.h> 16 16 #include <linux/integrity.h> 17 - #include <crypto/sha.h> 17 + #include <crypto/sha1.h> 18 18 #include <linux/key.h> 19 19 #include <linux/audit.h> 20 20
+1 -1
security/keys/encrypted-keys/encrypted.c
··· 29 29 #include <crypto/aes.h> 30 30 #include <crypto/algapi.h> 31 31 #include <crypto/hash.h> 32 - #include <crypto/sha.h> 32 + #include <crypto/sha2.h> 33 33 #include <crypto/skcipher.h> 34 34 35 35 #include "encrypted.h"
+1 -1
security/keys/trusted-keys/trusted_tpm1.c
··· 22 22 #include <linux/rcupdate.h> 23 23 #include <linux/crypto.h> 24 24 #include <crypto/hash.h> 25 - #include <crypto/sha.h> 25 + #include <crypto/sha1.h> 26 26 #include <linux/capability.h> 27 27 #include <linux/tpm.h> 28 28 #include <linux/tpm_command.h>
+1 -1
sound/soc/codecs/cros_ec_codec.c
··· 8 8 * EC for audio function. 9 9 */ 10 10 11 - #include <crypto/sha.h> 11 + #include <crypto/sha2.h> 12 12 #include <linux/acpi.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/device.h>