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:

- Delay boot-up self-test for built-in algorithms

Algorithms:

- Remove fallback path on arm64 as SIMD now runs with softirq off

Drivers:

- Add Keem Bay OCS ECC Driver"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (61 commits)
crypto: testmgr - fix wrong key length for pkcs1pad
crypto: pcrypt - Delay write to padata->info
crypto: ccp - Make use of the helper macro kthread_run()
crypto: sa2ul - Use the defined variable to clean code
crypto: s5p-sss - Add error handling in s5p_aes_probe()
crypto: keembay-ocs-ecc - Add Keem Bay OCS ECC Driver
dt-bindings: crypto: Add Keem Bay ECC bindings
crypto: ecc - Export additional helper functions
crypto: ecc - Move ecc.h to include/crypto/internal
crypto: engine - Add KPP Support to Crypto Engine
crypto: api - Do not create test larvals if manager is disabled
crypto: tcrypt - fix skcipher multi-buffer tests for 1420B blocks
hwrng: s390 - replace snprintf in show functions with sysfs_emit
crypto: octeontx2 - set assoclen in aead_do_fallback()
crypto: ccp - Fix whitespace in sev_cmd_buffer_len()
hwrng: mtk - Force runtime pm ops for sleep ops
crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
crypto: qat - share adf_enable_pf2vf_comms() from adf_pf2vf_msg.c
crypto: qat - extract send and wait from adf_vf2pf_request_version()
crypto: qat - add VF and PF wrappers to common send function
...

+2145 -1173
+4
Documentation/crypto/crypto_engine.rst
··· 69 69 70 70 * crypto_transfer_hash_request_to_engine() 71 71 72 + * crypto_transfer_kpp_request_to_engine() 73 + 72 74 * crypto_transfer_skcipher_request_to_engine() 73 75 74 76 At the end of the request process, a call to one of the following functions is needed: ··· 80 78 * crypto_finalize_akcipher_request() 81 79 82 80 * crypto_finalize_hash_request() 81 + 82 + * crypto_finalize_kpp_request() 83 83 84 84 * crypto_finalize_skcipher_request()
+47
Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.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-ecc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Intel Keem Bay OCS ECC Device Tree Bindings 8 + 9 + maintainers: 10 + - Daniele Alessandrelli <daniele.alessandrelli@intel.com> 11 + - Prabhjot Khurana <prabhjot.khurana@intel.com> 12 + 13 + description: 14 + The Intel Keem Bay Offload and Crypto Subsystem (OCS) Elliptic Curve 15 + Cryptography (ECC) device provides hardware acceleration for elliptic curve 16 + cryptography using the NIST P-256 and NIST P-384 elliptic curves. 17 + 18 + properties: 19 + compatible: 20 + const: intel,keembay-ocs-ecc 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + maxItems: 1 27 + 28 + clocks: 29 + maxItems: 1 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - interrupts 35 + - clocks 36 + 37 + additionalProperties: false 38 + 39 + examples: 40 + - | 41 + #include <dt-bindings/interrupt-controller/arm-gic.h> 42 + crypto@30001000 { 43 + compatible = "intel,keembay-ocs-ecc"; 44 + reg = <0x30001000 0x1000>; 45 + interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>; 46 + clocks = <&scmi_clk 95>; 47 + };
+11
MAINTAINERS
··· 9556 9556 F: drivers/crypto/keembay/ocs-aes.c 9557 9557 F: drivers/crypto/keembay/ocs-aes.h 9558 9558 9559 + INTEL KEEM BAY OCS ECC CRYPTO DRIVER 9560 + M: Daniele Alessandrelli <daniele.alessandrelli@intel.com> 9561 + M: Prabhjot Khurana <prabhjot.khurana@intel.com> 9562 + M: Mark Gross <mgross@linux.intel.com> 9563 + S: Maintained 9564 + F: Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml 9565 + F: drivers/crypto/keembay/Kconfig 9566 + F: drivers/crypto/keembay/Makefile 9567 + F: drivers/crypto/keembay/keembay-ocs-ecc.c 9568 + F: drivers/crypto/keembay/ocs-ecc-curve-defs.h 9569 + 9559 9570 INTEL KEEM BAY OCS HCU CRYPTO DRIVER 9560 9571 M: Daniele Alessandrelli <daniele.alessandrelli@intel.com> 9561 9572 M: Declan Murphy <declan.murphy@intel.com>
-6
arch/arm64/crypto/Kconfig
··· 88 88 depends on KERNEL_MODE_NEON 89 89 select CRYPTO_SKCIPHER 90 90 select CRYPTO_AES_ARM64_CE 91 - select CRYPTO_AES_ARM64 92 - select CRYPTO_SIMD 93 91 94 92 config CRYPTO_AES_ARM64_NEON_BLK 95 93 tristate "AES in ECB/CBC/CTR/XTS modes using NEON instructions" 96 94 depends on KERNEL_MODE_NEON 97 95 select CRYPTO_SKCIPHER 98 - select CRYPTO_AES_ARM64 99 96 select CRYPTO_LIB_AES 100 - select CRYPTO_SIMD 101 97 102 98 config CRYPTO_CHACHA20_NEON 103 99 tristate "ChaCha20, XChaCha20, and XChaCha12 stream ciphers using NEON instructions" ··· 118 122 depends on KERNEL_MODE_NEON 119 123 select CRYPTO_SKCIPHER 120 124 select CRYPTO_AES_ARM64_NEON_BLK 121 - select CRYPTO_AES_ARM64 122 125 select CRYPTO_LIB_AES 123 - select CRYPTO_SIMD 124 126 125 127 endif
+12 -12
arch/arm64/crypto/aes-ce-ccm-core.S
··· 12 12 .arch armv8-a+crypto 13 13 14 14 /* 15 - * void ce_aes_ccm_auth_data(u8 mac[], u8 const in[], u32 abytes, 16 - * u32 *macp, u8 const rk[], u32 rounds); 15 + * u32 ce_aes_ccm_auth_data(u8 mac[], u8 const in[], u32 abytes, 16 + * u32 macp, u8 const rk[], u32 rounds); 17 17 */ 18 18 SYM_FUNC_START(ce_aes_ccm_auth_data) 19 - ldr w8, [x3] /* leftover from prev round? */ 20 19 ld1 {v0.16b}, [x0] /* load mac */ 21 - cbz w8, 1f 22 - sub w8, w8, #16 20 + cbz w3, 1f 21 + sub w3, w3, #16 23 22 eor v1.16b, v1.16b, v1.16b 24 23 0: ldrb w7, [x1], #1 /* get 1 byte of input */ 25 24 subs w2, w2, #1 26 - add w8, w8, #1 25 + add w3, w3, #1 27 26 ins v1.b[0], w7 28 27 ext v1.16b, v1.16b, v1.16b, #1 /* rotate in the input bytes */ 29 28 beq 8f /* out of input? */ 30 - cbnz w8, 0b 29 + cbnz w3, 0b 31 30 eor v0.16b, v0.16b, v1.16b 32 31 1: ld1 {v3.4s}, [x4] /* load first round key */ 33 32 prfm pldl1strm, [x1] ··· 61 62 beq 10f 62 63 adds w2, w2, #16 63 64 beq 10f 64 - mov w8, w2 65 + mov w3, w2 65 66 7: ldrb w7, [x1], #1 66 67 umov w6, v0.b[0] 67 68 eor w6, w6, w7 ··· 70 71 beq 10f 71 72 ext v0.16b, v0.16b, v0.16b, #1 /* rotate out the mac bytes */ 72 73 b 7b 73 - 8: cbz w8, 91f 74 - mov w7, w8 75 - add w8, w8, #16 74 + 8: cbz w3, 91f 75 + mov w7, w3 76 + add w3, w3, #16 76 77 9: ext v1.16b, v1.16b, v1.16b, #1 77 78 adds w7, w7, #1 78 79 bne 9b 79 80 91: eor v0.16b, v0.16b, v1.16b 80 81 st1 {v0.16b}, [x0] 81 - 10: str w8, [x3] 82 + 10: mov w0, w3 82 83 ret 83 84 SYM_FUNC_END(ce_aes_ccm_auth_data) 84 85 ··· 123 124 SYM_FUNC_END(ce_aes_ccm_final) 124 125 125 126 .macro aes_ccm_do_crypt,enc 127 + cbz x2, 5f 126 128 ldr x8, [x6, #8] /* load lower ctr */ 127 129 ld1 {v0.16b}, [x5] /* load mac */ 128 130 CPU_LE( rev x8, x8 ) /* keep swabbed ctr in reg */
+73 -150
arch/arm64/crypto/aes-ce-ccm-glue.c
··· 6 6 */ 7 7 8 8 #include <asm/neon.h> 9 - #include <asm/simd.h> 10 9 #include <asm/unaligned.h> 11 10 #include <crypto/aes.h> 12 11 #include <crypto/scatterwalk.h> 13 12 #include <crypto/internal/aead.h> 14 - #include <crypto/internal/simd.h> 15 13 #include <crypto/internal/skcipher.h> 16 14 #include <linux/module.h> 17 15 ··· 27 29 return 6 + ctx->key_length / 4; 28 30 } 29 31 30 - asmlinkage void ce_aes_ccm_auth_data(u8 mac[], u8 const in[], u32 abytes, 31 - u32 *macp, u32 const rk[], u32 rounds); 32 + asmlinkage u32 ce_aes_ccm_auth_data(u8 mac[], u8 const in[], u32 abytes, 33 + u32 macp, u32 const rk[], u32 rounds); 32 34 33 35 asmlinkage void ce_aes_ccm_encrypt(u8 out[], u8 const in[], u32 cbytes, 34 36 u32 const rk[], u32 rounds, u8 mac[], ··· 94 96 return 0; 95 97 } 96 98 97 - static void ccm_update_mac(struct crypto_aes_ctx *key, u8 mac[], u8 const in[], 98 - u32 abytes, u32 *macp) 99 - { 100 - if (crypto_simd_usable()) { 101 - kernel_neon_begin(); 102 - ce_aes_ccm_auth_data(mac, in, abytes, macp, key->key_enc, 103 - num_rounds(key)); 104 - kernel_neon_end(); 105 - } else { 106 - if (*macp > 0 && *macp < AES_BLOCK_SIZE) { 107 - int added = min(abytes, AES_BLOCK_SIZE - *macp); 108 - 109 - crypto_xor(&mac[*macp], in, added); 110 - 111 - *macp += added; 112 - in += added; 113 - abytes -= added; 114 - } 115 - 116 - while (abytes >= AES_BLOCK_SIZE) { 117 - aes_encrypt(key, mac, mac); 118 - crypto_xor(mac, in, AES_BLOCK_SIZE); 119 - 120 - in += AES_BLOCK_SIZE; 121 - abytes -= AES_BLOCK_SIZE; 122 - } 123 - 124 - if (abytes > 0) { 125 - aes_encrypt(key, mac, mac); 126 - crypto_xor(mac, in, abytes); 127 - *macp = abytes; 128 - } 129 - } 130 - } 131 - 132 99 static void ccm_calculate_auth_mac(struct aead_request *req, u8 mac[]) 133 100 { 134 101 struct crypto_aead *aead = crypto_aead_reqtfm(req); ··· 113 150 ltag.len = 6; 114 151 } 115 152 116 - ccm_update_mac(ctx, mac, (u8 *)&ltag, ltag.len, &macp); 153 + macp = ce_aes_ccm_auth_data(mac, (u8 *)&ltag, ltag.len, macp, 154 + ctx->key_enc, num_rounds(ctx)); 117 155 scatterwalk_start(&walk, req->src); 118 156 119 157 do { ··· 125 161 scatterwalk_start(&walk, sg_next(walk.sg)); 126 162 n = scatterwalk_clamp(&walk, len); 127 163 } 164 + n = min_t(u32, n, SZ_4K); /* yield NEON at least every 4k */ 128 165 p = scatterwalk_map(&walk); 129 - ccm_update_mac(ctx, mac, p, n, &macp); 166 + 167 + macp = ce_aes_ccm_auth_data(mac, p, n, macp, ctx->key_enc, 168 + num_rounds(ctx)); 169 + 170 + if (len / SZ_4K > (len - n) / SZ_4K) { 171 + kernel_neon_end(); 172 + kernel_neon_begin(); 173 + } 130 174 len -= n; 131 175 132 176 scatterwalk_unmap(p); 133 177 scatterwalk_advance(&walk, n); 134 178 scatterwalk_done(&walk, 0, len); 135 179 } while (len); 136 - } 137 - 138 - static int ccm_crypt_fallback(struct skcipher_walk *walk, u8 mac[], u8 iv0[], 139 - struct crypto_aes_ctx *ctx, bool enc) 140 - { 141 - u8 buf[AES_BLOCK_SIZE]; 142 - int err = 0; 143 - 144 - while (walk->nbytes) { 145 - int blocks = walk->nbytes / AES_BLOCK_SIZE; 146 - u32 tail = walk->nbytes % AES_BLOCK_SIZE; 147 - u8 *dst = walk->dst.virt.addr; 148 - u8 *src = walk->src.virt.addr; 149 - u32 nbytes = walk->nbytes; 150 - 151 - if (nbytes == walk->total && tail > 0) { 152 - blocks++; 153 - tail = 0; 154 - } 155 - 156 - do { 157 - u32 bsize = AES_BLOCK_SIZE; 158 - 159 - if (nbytes < AES_BLOCK_SIZE) 160 - bsize = nbytes; 161 - 162 - crypto_inc(walk->iv, AES_BLOCK_SIZE); 163 - aes_encrypt(ctx, buf, walk->iv); 164 - aes_encrypt(ctx, mac, mac); 165 - if (enc) 166 - crypto_xor(mac, src, bsize); 167 - crypto_xor_cpy(dst, src, buf, bsize); 168 - if (!enc) 169 - crypto_xor(mac, dst, bsize); 170 - dst += bsize; 171 - src += bsize; 172 - nbytes -= bsize; 173 - } while (--blocks); 174 - 175 - err = skcipher_walk_done(walk, tail); 176 - } 177 - 178 - if (!err) { 179 - aes_encrypt(ctx, buf, iv0); 180 - aes_encrypt(ctx, mac, mac); 181 - crypto_xor(mac, buf, AES_BLOCK_SIZE); 182 - } 183 - return err; 184 180 } 185 181 186 182 static int ccm_encrypt(struct aead_request *req) ··· 157 233 if (err) 158 234 return err; 159 235 160 - if (req->assoclen) 161 - ccm_calculate_auth_mac(req, mac); 162 - 163 236 /* preserve the original iv for the final round */ 164 237 memcpy(buf, req->iv, AES_BLOCK_SIZE); 165 238 166 239 err = skcipher_walk_aead_encrypt(&walk, req, false); 167 - 168 - if (crypto_simd_usable()) { 169 - while (walk.nbytes) { 170 - u32 tail = walk.nbytes % AES_BLOCK_SIZE; 171 - 172 - if (walk.nbytes == walk.total) 173 - tail = 0; 174 - 175 - kernel_neon_begin(); 176 - ce_aes_ccm_encrypt(walk.dst.virt.addr, 177 - walk.src.virt.addr, 178 - walk.nbytes - tail, ctx->key_enc, 179 - num_rounds(ctx), mac, walk.iv); 180 - kernel_neon_end(); 181 - 182 - err = skcipher_walk_done(&walk, tail); 183 - } 184 - if (!err) { 185 - kernel_neon_begin(); 186 - ce_aes_ccm_final(mac, buf, ctx->key_enc, 187 - num_rounds(ctx)); 188 - kernel_neon_end(); 189 - } 190 - } else { 191 - err = ccm_crypt_fallback(&walk, mac, buf, ctx, true); 192 - } 193 - if (err) 240 + if (unlikely(err)) 194 241 return err; 242 + 243 + kernel_neon_begin(); 244 + 245 + if (req->assoclen) 246 + ccm_calculate_auth_mac(req, mac); 247 + 248 + do { 249 + u32 tail = walk.nbytes % AES_BLOCK_SIZE; 250 + 251 + if (walk.nbytes == walk.total) 252 + tail = 0; 253 + 254 + ce_aes_ccm_encrypt(walk.dst.virt.addr, walk.src.virt.addr, 255 + walk.nbytes - tail, ctx->key_enc, 256 + num_rounds(ctx), mac, walk.iv); 257 + 258 + if (walk.nbytes == walk.total) 259 + ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx)); 260 + 261 + kernel_neon_end(); 262 + 263 + if (walk.nbytes) { 264 + err = skcipher_walk_done(&walk, tail); 265 + if (unlikely(err)) 266 + return err; 267 + if (unlikely(walk.nbytes)) 268 + kernel_neon_begin(); 269 + } 270 + } while (walk.nbytes); 195 271 196 272 /* copy authtag to end of dst */ 197 273 scatterwalk_map_and_copy(mac, req->dst, req->assoclen + req->cryptlen, ··· 215 291 if (err) 216 292 return err; 217 293 218 - if (req->assoclen) 219 - ccm_calculate_auth_mac(req, mac); 220 - 221 294 /* preserve the original iv for the final round */ 222 295 memcpy(buf, req->iv, AES_BLOCK_SIZE); 223 296 224 297 err = skcipher_walk_aead_decrypt(&walk, req, false); 225 - 226 - if (crypto_simd_usable()) { 227 - while (walk.nbytes) { 228 - u32 tail = walk.nbytes % AES_BLOCK_SIZE; 229 - 230 - if (walk.nbytes == walk.total) 231 - tail = 0; 232 - 233 - kernel_neon_begin(); 234 - ce_aes_ccm_decrypt(walk.dst.virt.addr, 235 - walk.src.virt.addr, 236 - walk.nbytes - tail, ctx->key_enc, 237 - num_rounds(ctx), mac, walk.iv); 238 - kernel_neon_end(); 239 - 240 - err = skcipher_walk_done(&walk, tail); 241 - } 242 - if (!err) { 243 - kernel_neon_begin(); 244 - ce_aes_ccm_final(mac, buf, ctx->key_enc, 245 - num_rounds(ctx)); 246 - kernel_neon_end(); 247 - } 248 - } else { 249 - err = ccm_crypt_fallback(&walk, mac, buf, ctx, false); 250 - } 251 - 252 - if (err) 298 + if (unlikely(err)) 253 299 return err; 300 + 301 + kernel_neon_begin(); 302 + 303 + if (req->assoclen) 304 + ccm_calculate_auth_mac(req, mac); 305 + 306 + do { 307 + u32 tail = walk.nbytes % AES_BLOCK_SIZE; 308 + 309 + if (walk.nbytes == walk.total) 310 + tail = 0; 311 + 312 + ce_aes_ccm_decrypt(walk.dst.virt.addr, walk.src.virt.addr, 313 + walk.nbytes - tail, ctx->key_enc, 314 + num_rounds(ctx), mac, walk.iv); 315 + 316 + if (walk.nbytes == walk.total) 317 + ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx)); 318 + 319 + kernel_neon_end(); 320 + 321 + if (walk.nbytes) { 322 + err = skcipher_walk_done(&walk, tail); 323 + if (unlikely(err)) 324 + return err; 325 + if (unlikely(walk.nbytes)) 326 + kernel_neon_begin(); 327 + } 328 + } while (walk.nbytes); 254 329 255 330 /* compare calculated auth tag with the stored one */ 256 331 scatterwalk_map_and_copy(buf, req->src,
+13 -89
arch/arm64/crypto/aes-glue.c
··· 444 444 return err ?: cbc_decrypt_walk(req, &walk); 445 445 } 446 446 447 - static int ctr_encrypt(struct skcipher_request *req) 447 + static int __maybe_unused ctr_encrypt(struct skcipher_request *req) 448 448 { 449 449 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 450 450 struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); ··· 483 483 } 484 484 485 485 return err; 486 - } 487 - 488 - static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) 489 - { 490 - const struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); 491 - unsigned long flags; 492 - 493 - /* 494 - * Temporarily disable interrupts to avoid races where 495 - * cachelines are evicted when the CPU is interrupted 496 - * to do something else. 497 - */ 498 - local_irq_save(flags); 499 - aes_encrypt(ctx, dst, src); 500 - local_irq_restore(flags); 501 - } 502 - 503 - static int __maybe_unused ctr_encrypt_sync(struct skcipher_request *req) 504 - { 505 - if (!crypto_simd_usable()) 506 - return crypto_ctr_encrypt_walk(req, ctr_encrypt_one); 507 - 508 - return ctr_encrypt(req); 509 486 } 510 487 511 488 static int __maybe_unused xts_encrypt(struct skcipher_request *req) ··· 633 656 static struct skcipher_alg aes_algs[] = { { 634 657 #if defined(USE_V8_CRYPTO_EXTENSIONS) || !IS_ENABLED(CONFIG_CRYPTO_AES_ARM64_BS) 635 658 .base = { 636 - .cra_name = "__ecb(aes)", 637 - .cra_driver_name = "__ecb-aes-" MODE, 659 + .cra_name = "ecb(aes)", 660 + .cra_driver_name = "ecb-aes-" MODE, 638 661 .cra_priority = PRIO, 639 - .cra_flags = CRYPTO_ALG_INTERNAL, 640 662 .cra_blocksize = AES_BLOCK_SIZE, 641 663 .cra_ctxsize = sizeof(struct crypto_aes_ctx), 642 664 .cra_module = THIS_MODULE, ··· 647 671 .decrypt = ecb_decrypt, 648 672 }, { 649 673 .base = { 650 - .cra_name = "__cbc(aes)", 651 - .cra_driver_name = "__cbc-aes-" MODE, 674 + .cra_name = "cbc(aes)", 675 + .cra_driver_name = "cbc-aes-" MODE, 652 676 .cra_priority = PRIO, 653 - .cra_flags = CRYPTO_ALG_INTERNAL, 654 677 .cra_blocksize = AES_BLOCK_SIZE, 655 678 .cra_ctxsize = sizeof(struct crypto_aes_ctx), 656 679 .cra_module = THIS_MODULE, ··· 662 687 .decrypt = cbc_decrypt, 663 688 }, { 664 689 .base = { 665 - .cra_name = "__ctr(aes)", 666 - .cra_driver_name = "__ctr-aes-" MODE, 690 + .cra_name = "ctr(aes)", 691 + .cra_driver_name = "ctr-aes-" MODE, 667 692 .cra_priority = PRIO, 668 - .cra_flags = CRYPTO_ALG_INTERNAL, 669 693 .cra_blocksize = 1, 670 694 .cra_ctxsize = sizeof(struct crypto_aes_ctx), 671 695 .cra_module = THIS_MODULE, ··· 678 704 .decrypt = ctr_encrypt, 679 705 }, { 680 706 .base = { 681 - .cra_name = "ctr(aes)", 682 - .cra_driver_name = "ctr-aes-" MODE, 683 - .cra_priority = PRIO - 1, 684 - .cra_blocksize = 1, 685 - .cra_ctxsize = sizeof(struct crypto_aes_ctx), 686 - .cra_module = THIS_MODULE, 687 - }, 688 - .min_keysize = AES_MIN_KEY_SIZE, 689 - .max_keysize = AES_MAX_KEY_SIZE, 690 - .ivsize = AES_BLOCK_SIZE, 691 - .chunksize = AES_BLOCK_SIZE, 692 - .setkey = skcipher_aes_setkey, 693 - .encrypt = ctr_encrypt_sync, 694 - .decrypt = ctr_encrypt_sync, 695 - }, { 696 - .base = { 697 - .cra_name = "__xts(aes)", 698 - .cra_driver_name = "__xts-aes-" MODE, 707 + .cra_name = "xts(aes)", 708 + .cra_driver_name = "xts-aes-" MODE, 699 709 .cra_priority = PRIO, 700 - .cra_flags = CRYPTO_ALG_INTERNAL, 701 710 .cra_blocksize = AES_BLOCK_SIZE, 702 711 .cra_ctxsize = sizeof(struct crypto_aes_xts_ctx), 703 712 .cra_module = THIS_MODULE, ··· 695 738 }, { 696 739 #endif 697 740 .base = { 698 - .cra_name = "__cts(cbc(aes))", 699 - .cra_driver_name = "__cts-cbc-aes-" MODE, 741 + .cra_name = "cts(cbc(aes))", 742 + .cra_driver_name = "cts-cbc-aes-" MODE, 700 743 .cra_priority = PRIO, 701 - .cra_flags = CRYPTO_ALG_INTERNAL, 702 744 .cra_blocksize = AES_BLOCK_SIZE, 703 745 .cra_ctxsize = sizeof(struct crypto_aes_ctx), 704 746 .cra_module = THIS_MODULE, ··· 711 755 .decrypt = cts_cbc_decrypt, 712 756 }, { 713 757 .base = { 714 - .cra_name = "__essiv(cbc(aes),sha256)", 715 - .cra_driver_name = "__essiv-cbc-aes-sha256-" MODE, 758 + .cra_name = "essiv(cbc(aes),sha256)", 759 + .cra_driver_name = "essiv-cbc-aes-sha256-" MODE, 716 760 .cra_priority = PRIO + 1, 717 - .cra_flags = CRYPTO_ALG_INTERNAL, 718 761 .cra_blocksize = AES_BLOCK_SIZE, 719 762 .cra_ctxsize = sizeof(struct crypto_aes_essiv_cbc_ctx), 720 763 .cra_module = THIS_MODULE, ··· 952 997 .descsize = sizeof(struct mac_desc_ctx), 953 998 } }; 954 999 955 - static struct simd_skcipher_alg *aes_simd_algs[ARRAY_SIZE(aes_algs)]; 956 - 957 1000 static void aes_exit(void) 958 1001 { 959 - int i; 960 - 961 - for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++) 962 - if (aes_simd_algs[i]) 963 - simd_skcipher_free(aes_simd_algs[i]); 964 - 965 1002 crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs)); 966 1003 crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 967 1004 } 968 1005 969 1006 static int __init aes_init(void) 970 1007 { 971 - struct simd_skcipher_alg *simd; 972 - const char *basename; 973 - const char *algname; 974 - const char *drvname; 975 1008 int err; 976 - int i; 977 1009 978 1010 err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 979 1011 if (err) ··· 970 1028 if (err) 971 1029 goto unregister_ciphers; 972 1030 973 - for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { 974 - if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL)) 975 - continue; 976 - 977 - algname = aes_algs[i].base.cra_name + 2; 978 - drvname = aes_algs[i].base.cra_driver_name + 2; 979 - basename = aes_algs[i].base.cra_driver_name; 980 - simd = simd_skcipher_create_compat(algname, drvname, basename); 981 - err = PTR_ERR(simd); 982 - if (IS_ERR(simd)) 983 - goto unregister_simds; 984 - 985 - aes_simd_algs[i] = simd; 986 - } 987 - 988 1031 return 0; 989 1032 990 - unregister_simds: 991 - aes_exit(); 992 - return err; 993 1033 unregister_ciphers: 994 1034 crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 995 1035 return err;
+9 -113
arch/arm64/crypto/aes-neonbs-glue.c
··· 63 63 u32 enc[AES_MAX_KEYLENGTH_U32]; 64 64 }; 65 65 66 - struct aesbs_ctr_ctx { 67 - struct aesbs_ctx key; /* must be first member */ 68 - struct crypto_aes_ctx fallback; 69 - }; 70 - 71 66 struct aesbs_xts_ctx { 72 67 struct aesbs_ctx key; 73 68 u32 twkey[AES_MAX_KEYLENGTH_U32]; ··· 202 207 return err; 203 208 } 204 209 205 - static int aesbs_ctr_setkey_sync(struct crypto_skcipher *tfm, const u8 *in_key, 206 - unsigned int key_len) 207 - { 208 - struct aesbs_ctr_ctx *ctx = crypto_skcipher_ctx(tfm); 209 - int err; 210 - 211 - err = aes_expandkey(&ctx->fallback, in_key, key_len); 212 - if (err) 213 - return err; 214 - 215 - ctx->key.rounds = 6 + key_len / 4; 216 - 217 - kernel_neon_begin(); 218 - aesbs_convert_key(ctx->key.rk, ctx->fallback.key_enc, ctx->key.rounds); 219 - kernel_neon_end(); 220 - 221 - return 0; 222 - } 223 - 224 210 static int ctr_encrypt(struct skcipher_request *req) 225 211 { 226 212 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); ··· 266 290 memcpy(ctx->twkey, rk.key_enc, sizeof(ctx->twkey)); 267 291 268 292 return aesbs_setkey(tfm, in_key, key_len); 269 - } 270 - 271 - static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst) 272 - { 273 - struct aesbs_ctr_ctx *ctx = crypto_skcipher_ctx(tfm); 274 - unsigned long flags; 275 - 276 - /* 277 - * Temporarily disable interrupts to avoid races where 278 - * cachelines are evicted when the CPU is interrupted 279 - * to do something else. 280 - */ 281 - local_irq_save(flags); 282 - aes_encrypt(&ctx->fallback, dst, src); 283 - local_irq_restore(flags); 284 - } 285 - 286 - static int ctr_encrypt_sync(struct skcipher_request *req) 287 - { 288 - if (!crypto_simd_usable()) 289 - return crypto_ctr_encrypt_walk(req, ctr_encrypt_one); 290 - 291 - return ctr_encrypt(req); 292 293 } 293 294 294 295 static int __xts_crypt(struct skcipher_request *req, bool encrypt, ··· 384 431 } 385 432 386 433 static struct skcipher_alg aes_algs[] = { { 387 - .base.cra_name = "__ecb(aes)", 388 - .base.cra_driver_name = "__ecb-aes-neonbs", 434 + .base.cra_name = "ecb(aes)", 435 + .base.cra_driver_name = "ecb-aes-neonbs", 389 436 .base.cra_priority = 250, 390 437 .base.cra_blocksize = AES_BLOCK_SIZE, 391 438 .base.cra_ctxsize = sizeof(struct aesbs_ctx), 392 439 .base.cra_module = THIS_MODULE, 393 - .base.cra_flags = CRYPTO_ALG_INTERNAL, 394 440 395 441 .min_keysize = AES_MIN_KEY_SIZE, 396 442 .max_keysize = AES_MAX_KEY_SIZE, ··· 398 446 .encrypt = ecb_encrypt, 399 447 .decrypt = ecb_decrypt, 400 448 }, { 401 - .base.cra_name = "__cbc(aes)", 402 - .base.cra_driver_name = "__cbc-aes-neonbs", 449 + .base.cra_name = "cbc(aes)", 450 + .base.cra_driver_name = "cbc-aes-neonbs", 403 451 .base.cra_priority = 250, 404 452 .base.cra_blocksize = AES_BLOCK_SIZE, 405 453 .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctx), 406 454 .base.cra_module = THIS_MODULE, 407 - .base.cra_flags = CRYPTO_ALG_INTERNAL, 408 455 409 456 .min_keysize = AES_MIN_KEY_SIZE, 410 457 .max_keysize = AES_MAX_KEY_SIZE, ··· 413 462 .encrypt = cbc_encrypt, 414 463 .decrypt = cbc_decrypt, 415 464 }, { 416 - .base.cra_name = "__ctr(aes)", 417 - .base.cra_driver_name = "__ctr-aes-neonbs", 465 + .base.cra_name = "ctr(aes)", 466 + .base.cra_driver_name = "ctr-aes-neonbs", 418 467 .base.cra_priority = 250, 419 468 .base.cra_blocksize = 1, 420 469 .base.cra_ctxsize = sizeof(struct aesbs_ctx), 421 470 .base.cra_module = THIS_MODULE, 422 - .base.cra_flags = CRYPTO_ALG_INTERNAL, 423 471 424 472 .min_keysize = AES_MIN_KEY_SIZE, 425 473 .max_keysize = AES_MAX_KEY_SIZE, ··· 429 479 .encrypt = ctr_encrypt, 430 480 .decrypt = ctr_encrypt, 431 481 }, { 432 - .base.cra_name = "ctr(aes)", 433 - .base.cra_driver_name = "ctr-aes-neonbs", 434 - .base.cra_priority = 250 - 1, 435 - .base.cra_blocksize = 1, 436 - .base.cra_ctxsize = sizeof(struct aesbs_ctr_ctx), 437 - .base.cra_module = THIS_MODULE, 438 - 439 - .min_keysize = AES_MIN_KEY_SIZE, 440 - .max_keysize = AES_MAX_KEY_SIZE, 441 - .chunksize = AES_BLOCK_SIZE, 442 - .walksize = 8 * AES_BLOCK_SIZE, 443 - .ivsize = AES_BLOCK_SIZE, 444 - .setkey = aesbs_ctr_setkey_sync, 445 - .encrypt = ctr_encrypt_sync, 446 - .decrypt = ctr_encrypt_sync, 447 - }, { 448 - .base.cra_name = "__xts(aes)", 449 - .base.cra_driver_name = "__xts-aes-neonbs", 482 + .base.cra_name = "xts(aes)", 483 + .base.cra_driver_name = "xts-aes-neonbs", 450 484 .base.cra_priority = 250, 451 485 .base.cra_blocksize = AES_BLOCK_SIZE, 452 486 .base.cra_ctxsize = sizeof(struct aesbs_xts_ctx), 453 487 .base.cra_module = THIS_MODULE, 454 - .base.cra_flags = CRYPTO_ALG_INTERNAL, 455 488 456 489 .min_keysize = 2 * AES_MIN_KEY_SIZE, 457 490 .max_keysize = 2 * AES_MAX_KEY_SIZE, ··· 445 512 .decrypt = xts_decrypt, 446 513 } }; 447 514 448 - static struct simd_skcipher_alg *aes_simd_algs[ARRAY_SIZE(aes_algs)]; 449 - 450 515 static void aes_exit(void) 451 516 { 452 - int i; 453 - 454 - for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++) 455 - if (aes_simd_algs[i]) 456 - simd_skcipher_free(aes_simd_algs[i]); 457 - 458 517 crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 459 518 } 460 519 461 520 static int __init aes_init(void) 462 521 { 463 - struct simd_skcipher_alg *simd; 464 - const char *basename; 465 - const char *algname; 466 - const char *drvname; 467 - int err; 468 - int i; 469 - 470 522 if (!cpu_have_named_feature(ASIMD)) 471 523 return -ENODEV; 472 524 473 - err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 474 - if (err) 475 - return err; 476 - 477 - for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { 478 - if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL)) 479 - continue; 480 - 481 - algname = aes_algs[i].base.cra_name + 2; 482 - drvname = aes_algs[i].base.cra_driver_name + 2; 483 - basename = aes_algs[i].base.cra_driver_name; 484 - simd = simd_skcipher_create_compat(algname, drvname, basename); 485 - err = PTR_ERR(simd); 486 - if (IS_ERR(simd)) 487 - goto unregister_simds; 488 - 489 - aes_simd_algs[i] = simd; 490 - } 491 - return 0; 492 - 493 - unregister_simds: 494 - aes_exit(); 495 - return err; 525 + return crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 496 526 } 497 527 498 528 module_init(aes_init);
+55 -162
arch/arm64/crypto/ghash-ce-glue.c
··· 362 362 363 363 err = skcipher_walk_aead_encrypt(&walk, req, false); 364 364 365 - if (likely(crypto_simd_usable())) { 366 - do { 367 - const u8 *src = walk.src.virt.addr; 368 - u8 *dst = walk.dst.virt.addr; 369 - int nbytes = walk.nbytes; 370 - 371 - tag = (u8 *)&lengths; 372 - 373 - if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) { 374 - src = dst = memcpy(buf + sizeof(buf) - nbytes, 375 - src, nbytes); 376 - } else if (nbytes < walk.total) { 377 - nbytes &= ~(AES_BLOCK_SIZE - 1); 378 - tag = NULL; 379 - } 380 - 381 - kernel_neon_begin(); 382 - pmull_gcm_encrypt(nbytes, dst, src, ctx->ghash_key.h, 383 - dg, iv, ctx->aes_key.key_enc, nrounds, 384 - tag); 385 - kernel_neon_end(); 386 - 387 - if (unlikely(!nbytes)) 388 - break; 389 - 390 - if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) 391 - memcpy(walk.dst.virt.addr, 392 - buf + sizeof(buf) - nbytes, nbytes); 393 - 394 - err = skcipher_walk_done(&walk, walk.nbytes - nbytes); 395 - } while (walk.nbytes); 396 - } else { 397 - while (walk.nbytes >= AES_BLOCK_SIZE) { 398 - int blocks = walk.nbytes / AES_BLOCK_SIZE; 399 - const u8 *src = walk.src.virt.addr; 400 - u8 *dst = walk.dst.virt.addr; 401 - int remaining = blocks; 402 - 403 - do { 404 - aes_encrypt(&ctx->aes_key, buf, iv); 405 - crypto_xor_cpy(dst, src, buf, AES_BLOCK_SIZE); 406 - crypto_inc(iv, AES_BLOCK_SIZE); 407 - 408 - dst += AES_BLOCK_SIZE; 409 - src += AES_BLOCK_SIZE; 410 - } while (--remaining > 0); 411 - 412 - ghash_do_update(blocks, dg, walk.dst.virt.addr, 413 - &ctx->ghash_key, NULL); 414 - 415 - err = skcipher_walk_done(&walk, 416 - walk.nbytes % AES_BLOCK_SIZE); 417 - } 418 - 419 - /* handle the tail */ 420 - if (walk.nbytes) { 421 - aes_encrypt(&ctx->aes_key, buf, iv); 422 - 423 - crypto_xor_cpy(walk.dst.virt.addr, walk.src.virt.addr, 424 - buf, walk.nbytes); 425 - 426 - memcpy(buf, walk.dst.virt.addr, walk.nbytes); 427 - memset(buf + walk.nbytes, 0, sizeof(buf) - walk.nbytes); 428 - } 365 + do { 366 + const u8 *src = walk.src.virt.addr; 367 + u8 *dst = walk.dst.virt.addr; 368 + int nbytes = walk.nbytes; 429 369 430 370 tag = (u8 *)&lengths; 431 - ghash_do_update(1, dg, tag, &ctx->ghash_key, 432 - walk.nbytes ? buf : NULL); 433 371 434 - if (walk.nbytes) 435 - err = skcipher_walk_done(&walk, 0); 372 + if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) { 373 + src = dst = memcpy(buf + sizeof(buf) - nbytes, 374 + src, nbytes); 375 + } else if (nbytes < walk.total) { 376 + nbytes &= ~(AES_BLOCK_SIZE - 1); 377 + tag = NULL; 378 + } 436 379 437 - put_unaligned_be64(dg[1], tag); 438 - put_unaligned_be64(dg[0], tag + 8); 439 - put_unaligned_be32(1, iv + GCM_IV_SIZE); 440 - aes_encrypt(&ctx->aes_key, iv, iv); 441 - crypto_xor(tag, iv, AES_BLOCK_SIZE); 442 - } 380 + kernel_neon_begin(); 381 + pmull_gcm_encrypt(nbytes, dst, src, ctx->ghash_key.h, 382 + dg, iv, ctx->aes_key.key_enc, nrounds, 383 + tag); 384 + kernel_neon_end(); 385 + 386 + if (unlikely(!nbytes)) 387 + break; 388 + 389 + if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) 390 + memcpy(walk.dst.virt.addr, 391 + buf + sizeof(buf) - nbytes, nbytes); 392 + 393 + err = skcipher_walk_done(&walk, walk.nbytes - nbytes); 394 + } while (walk.nbytes); 443 395 444 396 if (err) 445 397 return err; ··· 416 464 u64 dg[2] = {}; 417 465 be128 lengths; 418 466 u8 *tag; 467 + int ret; 419 468 int err; 420 469 421 470 lengths.a = cpu_to_be64(req->assoclen * 8); ··· 434 481 435 482 err = skcipher_walk_aead_decrypt(&walk, req, false); 436 483 437 - if (likely(crypto_simd_usable())) { 438 - int ret; 439 - 440 - do { 441 - const u8 *src = walk.src.virt.addr; 442 - u8 *dst = walk.dst.virt.addr; 443 - int nbytes = walk.nbytes; 444 - 445 - tag = (u8 *)&lengths; 446 - 447 - if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) { 448 - src = dst = memcpy(buf + sizeof(buf) - nbytes, 449 - src, nbytes); 450 - } else if (nbytes < walk.total) { 451 - nbytes &= ~(AES_BLOCK_SIZE - 1); 452 - tag = NULL; 453 - } 454 - 455 - kernel_neon_begin(); 456 - ret = pmull_gcm_decrypt(nbytes, dst, src, 457 - ctx->ghash_key.h, 458 - dg, iv, ctx->aes_key.key_enc, 459 - nrounds, tag, otag, authsize); 460 - kernel_neon_end(); 461 - 462 - if (unlikely(!nbytes)) 463 - break; 464 - 465 - if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) 466 - memcpy(walk.dst.virt.addr, 467 - buf + sizeof(buf) - nbytes, nbytes); 468 - 469 - err = skcipher_walk_done(&walk, walk.nbytes - nbytes); 470 - } while (walk.nbytes); 471 - 472 - if (err) 473 - return err; 474 - if (ret) 475 - return -EBADMSG; 476 - } else { 477 - while (walk.nbytes >= AES_BLOCK_SIZE) { 478 - int blocks = walk.nbytes / AES_BLOCK_SIZE; 479 - const u8 *src = walk.src.virt.addr; 480 - u8 *dst = walk.dst.virt.addr; 481 - 482 - ghash_do_update(blocks, dg, walk.src.virt.addr, 483 - &ctx->ghash_key, NULL); 484 - 485 - do { 486 - aes_encrypt(&ctx->aes_key, buf, iv); 487 - crypto_xor_cpy(dst, src, buf, AES_BLOCK_SIZE); 488 - crypto_inc(iv, AES_BLOCK_SIZE); 489 - 490 - dst += AES_BLOCK_SIZE; 491 - src += AES_BLOCK_SIZE; 492 - } while (--blocks > 0); 493 - 494 - err = skcipher_walk_done(&walk, 495 - walk.nbytes % AES_BLOCK_SIZE); 496 - } 497 - 498 - /* handle the tail */ 499 - if (walk.nbytes) { 500 - memcpy(buf, walk.src.virt.addr, walk.nbytes); 501 - memset(buf + walk.nbytes, 0, sizeof(buf) - walk.nbytes); 502 - } 484 + do { 485 + const u8 *src = walk.src.virt.addr; 486 + u8 *dst = walk.dst.virt.addr; 487 + int nbytes = walk.nbytes; 503 488 504 489 tag = (u8 *)&lengths; 505 - ghash_do_update(1, dg, tag, &ctx->ghash_key, 506 - walk.nbytes ? buf : NULL); 507 490 508 - if (walk.nbytes) { 509 - aes_encrypt(&ctx->aes_key, buf, iv); 510 - 511 - crypto_xor_cpy(walk.dst.virt.addr, walk.src.virt.addr, 512 - buf, walk.nbytes); 513 - 514 - err = skcipher_walk_done(&walk, 0); 491 + if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) { 492 + src = dst = memcpy(buf + sizeof(buf) - nbytes, 493 + src, nbytes); 494 + } else if (nbytes < walk.total) { 495 + nbytes &= ~(AES_BLOCK_SIZE - 1); 496 + tag = NULL; 515 497 } 516 498 517 - if (err) 518 - return err; 499 + kernel_neon_begin(); 500 + ret = pmull_gcm_decrypt(nbytes, dst, src, ctx->ghash_key.h, 501 + dg, iv, ctx->aes_key.key_enc, 502 + nrounds, tag, otag, authsize); 503 + kernel_neon_end(); 519 504 520 - put_unaligned_be64(dg[1], tag); 521 - put_unaligned_be64(dg[0], tag + 8); 522 - put_unaligned_be32(1, iv + GCM_IV_SIZE); 523 - aes_encrypt(&ctx->aes_key, iv, iv); 524 - crypto_xor(tag, iv, AES_BLOCK_SIZE); 505 + if (unlikely(!nbytes)) 506 + break; 525 507 526 - if (crypto_memneq(tag, otag, authsize)) { 527 - memzero_explicit(tag, AES_BLOCK_SIZE); 528 - return -EBADMSG; 529 - } 530 - } 531 - return 0; 508 + if (unlikely(nbytes > 0 && nbytes < AES_BLOCK_SIZE)) 509 + memcpy(walk.dst.virt.addr, 510 + buf + sizeof(buf) - nbytes, nbytes); 511 + 512 + err = skcipher_walk_done(&walk, walk.nbytes - nbytes); 513 + } while (walk.nbytes); 514 + 515 + if (err) 516 + return err; 517 + 518 + return ret ? -EBADMSG : 0; 532 519 } 533 520 534 521 static struct aead_alg gcm_aes_alg = {
+1 -1
arch/x86/crypto/aesni-intel_glue.c
··· 866 866 req = &subreq; 867 867 868 868 err = skcipher_walk_virt(&walk, req, false); 869 - if (err) 869 + if (!walk.nbytes) 870 870 return err; 871 871 } else { 872 872 tail = 0;
+1 -1
crypto/Kconfig
··· 233 233 234 234 config CRYPTO_ECC 235 235 tristate 236 + select CRYPTO_RNG_DEFAULT 236 237 237 238 config CRYPTO_ECDH 238 239 tristate "ECDH algorithm" 239 240 select CRYPTO_ECC 240 241 select CRYPTO_KPP 241 - select CRYPTO_RNG_DEFAULT 242 242 help 243 243 Generic implementation of the ECDH algorithm 244 244
+84 -39
crypto/algapi.c
··· 216 216 } 217 217 EXPORT_SYMBOL_GPL(crypto_remove_spawns); 218 218 219 + static struct crypto_larval *crypto_alloc_test_larval(struct crypto_alg *alg) 220 + { 221 + struct crypto_larval *larval; 222 + 223 + if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER)) 224 + return NULL; 225 + 226 + larval = crypto_larval_alloc(alg->cra_name, 227 + alg->cra_flags | CRYPTO_ALG_TESTED, 0); 228 + if (IS_ERR(larval)) 229 + return larval; 230 + 231 + larval->adult = crypto_mod_get(alg); 232 + if (!larval->adult) { 233 + kfree(larval); 234 + return ERR_PTR(-ENOENT); 235 + } 236 + 237 + refcount_set(&larval->alg.cra_refcnt, 1); 238 + memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, 239 + CRYPTO_MAX_ALG_NAME); 240 + larval->alg.cra_priority = alg->cra_priority; 241 + 242 + return larval; 243 + } 244 + 219 245 static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) 220 246 { 221 247 struct crypto_alg *q; ··· 276 250 goto err; 277 251 } 278 252 279 - larval = crypto_larval_alloc(alg->cra_name, 280 - alg->cra_flags | CRYPTO_ALG_TESTED, 0); 253 + larval = crypto_alloc_test_larval(alg); 281 254 if (IS_ERR(larval)) 282 255 goto out; 283 256 284 - ret = -ENOENT; 285 - larval->adult = crypto_mod_get(alg); 286 - if (!larval->adult) 287 - goto free_larval; 288 - 289 - refcount_set(&larval->alg.cra_refcnt, 1); 290 - memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, 291 - CRYPTO_MAX_ALG_NAME); 292 - larval->alg.cra_priority = alg->cra_priority; 293 - 294 257 list_add(&alg->cra_list, &crypto_alg_list); 295 - list_add(&larval->alg.cra_list, &crypto_alg_list); 258 + 259 + if (larval) 260 + list_add(&larval->alg.cra_list, &crypto_alg_list); 296 261 297 262 crypto_stats_init(alg); 298 263 299 264 out: 300 265 return larval; 301 266 302 - free_larval: 303 - kfree(larval); 304 267 err: 305 268 larval = ERR_PTR(ret); 306 269 goto out; ··· 404 389 } 405 390 EXPORT_SYMBOL_GPL(crypto_remove_final); 406 391 407 - static void crypto_wait_for_test(struct crypto_larval *larval) 408 - { 409 - int err; 410 - 411 - err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult); 412 - if (err != NOTIFY_STOP) { 413 - if (WARN_ON(err != NOTIFY_DONE)) 414 - goto out; 415 - crypto_alg_tested(larval->alg.cra_driver_name, 0); 416 - } 417 - 418 - err = wait_for_completion_killable(&larval->completion); 419 - WARN_ON(err); 420 - if (!err) 421 - crypto_notify(CRYPTO_MSG_ALG_LOADED, larval); 422 - 423 - out: 424 - crypto_larval_kill(&larval->alg); 425 - } 426 - 427 392 int crypto_register_alg(struct crypto_alg *alg) 428 393 { 429 394 struct crypto_larval *larval; 395 + bool test_started; 430 396 int err; 431 397 432 398 alg->cra_flags &= ~CRYPTO_ALG_DEAD; ··· 417 421 418 422 down_write(&crypto_alg_sem); 419 423 larval = __crypto_register_alg(alg); 424 + test_started = static_key_enabled(&crypto_boot_test_finished); 425 + if (!IS_ERR_OR_NULL(larval)) 426 + larval->test_started = test_started; 420 427 up_write(&crypto_alg_sem); 421 428 422 - if (IS_ERR(larval)) 429 + if (IS_ERR_OR_NULL(larval)) 423 430 return PTR_ERR(larval); 424 431 425 - crypto_wait_for_test(larval); 432 + if (test_started) 433 + crypto_wait_for_test(larval); 426 434 return 0; 427 435 } 428 436 EXPORT_SYMBOL_GPL(crypto_register_alg); ··· 632 632 larval = __crypto_register_alg(&inst->alg); 633 633 if (IS_ERR(larval)) 634 634 goto unlock; 635 + else if (larval) 636 + larval->test_started = true; 635 637 636 638 hlist_add_head(&inst->list, &tmpl->instances); 637 639 inst->tmpl = tmpl; ··· 642 640 up_write(&crypto_alg_sem); 643 641 644 642 err = PTR_ERR(larval); 645 - if (IS_ERR(larval)) 643 + if (IS_ERR_OR_NULL(larval)) 646 644 goto err; 647 645 648 646 crypto_wait_for_test(larval); ··· 1263 1261 EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt); 1264 1262 #endif 1265 1263 1264 + static void __init crypto_start_tests(void) 1265 + { 1266 + for (;;) { 1267 + struct crypto_larval *larval = NULL; 1268 + struct crypto_alg *q; 1269 + 1270 + down_write(&crypto_alg_sem); 1271 + 1272 + list_for_each_entry(q, &crypto_alg_list, cra_list) { 1273 + struct crypto_larval *l; 1274 + 1275 + if (!crypto_is_larval(q)) 1276 + continue; 1277 + 1278 + l = (void *)q; 1279 + 1280 + if (!crypto_is_test_larval(l)) 1281 + continue; 1282 + 1283 + if (l->test_started) 1284 + continue; 1285 + 1286 + l->test_started = true; 1287 + larval = l; 1288 + break; 1289 + } 1290 + 1291 + up_write(&crypto_alg_sem); 1292 + 1293 + if (!larval) 1294 + break; 1295 + 1296 + crypto_wait_for_test(larval); 1297 + } 1298 + 1299 + static_branch_enable(&crypto_boot_test_finished); 1300 + } 1301 + 1266 1302 static int __init crypto_algapi_init(void) 1267 1303 { 1268 1304 crypto_init_proc(); 1305 + crypto_start_tests(); 1269 1306 return 0; 1270 1307 } 1271 1308 ··· 1313 1272 crypto_exit_proc(); 1314 1273 } 1315 1274 1316 - module_init(crypto_algapi_init); 1275 + /* 1276 + * We run this at late_initcall so that all the built-in algorithms 1277 + * have had a chance to register themselves first. 1278 + */ 1279 + late_initcall(crypto_algapi_init); 1317 1280 module_exit(crypto_algapi_exit); 1318 1281 1319 1282 MODULE_LICENSE("GPL");
+45 -5
crypto/api.c
··· 12 12 13 13 #include <linux/err.h> 14 14 #include <linux/errno.h> 15 + #include <linux/jump_label.h> 15 16 #include <linux/kernel.h> 16 17 #include <linux/kmod.h> 17 18 #include <linux/module.h> ··· 31 30 BLOCKING_NOTIFIER_HEAD(crypto_chain); 32 31 EXPORT_SYMBOL_GPL(crypto_chain); 33 32 33 + DEFINE_STATIC_KEY_FALSE(crypto_boot_test_finished); 34 + EXPORT_SYMBOL_GPL(crypto_boot_test_finished); 35 + 34 36 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg); 35 37 36 38 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) ··· 50 46 module_put(module); 51 47 } 52 48 EXPORT_SYMBOL_GPL(crypto_mod_put); 53 - 54 - static inline int crypto_is_test_larval(struct crypto_larval *larval) 55 - { 56 - return larval->alg.cra_driver_name[0]; 57 - } 58 49 59 50 static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, 60 51 u32 mask) ··· 162 163 } 163 164 EXPORT_SYMBOL_GPL(crypto_larval_kill); 164 165 166 + void crypto_wait_for_test(struct crypto_larval *larval) 167 + { 168 + int err; 169 + 170 + err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult); 171 + if (WARN_ON_ONCE(err != NOTIFY_STOP)) 172 + goto out; 173 + 174 + err = wait_for_completion_killable(&larval->completion); 175 + WARN_ON(err); 176 + if (!err) 177 + crypto_notify(CRYPTO_MSG_ALG_LOADED, larval); 178 + 179 + out: 180 + crypto_larval_kill(&larval->alg); 181 + } 182 + EXPORT_SYMBOL_GPL(crypto_wait_for_test); 183 + 184 + static void crypto_start_test(struct crypto_larval *larval) 185 + { 186 + if (!crypto_is_test_larval(larval)) 187 + return; 188 + 189 + if (larval->test_started) 190 + return; 191 + 192 + down_write(&crypto_alg_sem); 193 + if (larval->test_started) { 194 + up_write(&crypto_alg_sem); 195 + return; 196 + } 197 + 198 + larval->test_started = true; 199 + up_write(&crypto_alg_sem); 200 + 201 + crypto_wait_for_test(larval); 202 + } 203 + 165 204 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) 166 205 { 167 206 struct crypto_larval *larval = (void *)alg; 168 207 long timeout; 208 + 209 + if (!static_branch_likely(&crypto_boot_test_finished)) 210 + crypto_start_test(larval); 169 211 170 212 timeout = wait_for_completion_killable_timeout( 171 213 &larval->completion, 60 * HZ);
+26
crypto/crypto_engine.c
··· 328 328 EXPORT_SYMBOL_GPL(crypto_transfer_hash_request_to_engine); 329 329 330 330 /** 331 + * crypto_transfer_kpp_request_to_engine - transfer one kpp_request to list 332 + * into the engine queue 333 + * @engine: the hardware engine 334 + * @req: the request need to be listed into the engine queue 335 + */ 336 + int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine, 337 + struct kpp_request *req) 338 + { 339 + return crypto_transfer_request_to_engine(engine, &req->base); 340 + } 341 + EXPORT_SYMBOL_GPL(crypto_transfer_kpp_request_to_engine); 342 + 343 + /** 331 344 * crypto_transfer_skcipher_request_to_engine - transfer one skcipher_request 332 345 * to list into the engine queue 333 346 * @engine: the hardware engine ··· 394 381 return crypto_finalize_request(engine, &req->base, err); 395 382 } 396 383 EXPORT_SYMBOL_GPL(crypto_finalize_hash_request); 384 + 385 + /** 386 + * crypto_finalize_kpp_request - finalize one kpp_request if the request is done 387 + * @engine: the hardware engine 388 + * @req: the request need to be finalized 389 + * @err: error number 390 + */ 391 + void crypto_finalize_kpp_request(struct crypto_engine *engine, 392 + struct kpp_request *req, int err) 393 + { 394 + return crypto_finalize_request(engine, &req->base, err); 395 + } 396 + EXPORT_SYMBOL_GPL(crypto_finalize_kpp_request); 397 397 398 398 /** 399 399 * crypto_finalize_skcipher_request - finalize one skcipher_request if
+1 -1
crypto/drbg.c
··· 2003 2003 #define OUTBUFLEN 16 2004 2004 unsigned char buf[OUTBUFLEN]; 2005 2005 struct drbg_state *drbg = NULL; 2006 - int ret = -EFAULT; 2006 + int ret; 2007 2007 int rc = -EFAULT; 2008 2008 bool pr = false; 2009 2009 int coreref = 0;
+9 -5
crypto/ecc.c
··· 32 32 #include <linux/fips.h> 33 33 #include <crypto/ecdh.h> 34 34 #include <crypto/rng.h> 35 + #include <crypto/internal/ecc.h> 35 36 #include <asm/unaligned.h> 36 37 #include <linux/ratelimit.h> 37 38 38 - #include "ecc.h" 39 39 #include "ecc_curve_defs.h" 40 40 41 41 typedef struct { ··· 81 81 kfree_sensitive(space); 82 82 } 83 83 84 - static struct ecc_point *ecc_alloc_point(unsigned int ndigits) 84 + struct ecc_point *ecc_alloc_point(unsigned int ndigits) 85 85 { 86 86 struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL); 87 87 ··· 106 106 kfree(p); 107 107 return NULL; 108 108 } 109 + EXPORT_SYMBOL(ecc_alloc_point); 109 110 110 - static void ecc_free_point(struct ecc_point *p) 111 + void ecc_free_point(struct ecc_point *p) 111 112 { 112 113 if (!p) 113 114 return; ··· 117 116 kfree_sensitive(p->y); 118 117 kfree_sensitive(p); 119 118 } 119 + EXPORT_SYMBOL(ecc_free_point); 120 120 121 121 static void vli_clear(u64 *vli, unsigned int ndigits) 122 122 { ··· 167 165 } 168 166 169 167 /* Counts the number of bits required for vli. */ 170 - static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits) 168 + unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits) 171 169 { 172 170 unsigned int i, num_digits; 173 171 u64 digit; ··· 182 180 183 181 return ((num_digits - 1) * 64 + i); 184 182 } 183 + EXPORT_SYMBOL(vli_num_bits); 185 184 186 185 /* Set dest from unaligned bit string src. */ 187 186 void vli_from_be64(u64 *dest, const void *src, unsigned int ndigits) ··· 1065 1062 /* ------ Point operations ------ */ 1066 1063 1067 1064 /* Returns true if p_point is the point at infinity, false otherwise. */ 1068 - static bool ecc_point_is_zero(const struct ecc_point *point) 1065 + bool ecc_point_is_zero(const struct ecc_point *point) 1069 1066 { 1070 1067 return (vli_is_zero(point->x, point->ndigits) && 1071 1068 vli_is_zero(point->y, point->ndigits)); 1072 1069 } 1070 + EXPORT_SYMBOL(ecc_point_is_zero); 1073 1071 1074 1072 /* Point multiplication algorithm using Montgomery's ladder with co-Z 1075 1073 * coordinates. From https://eprint.iacr.org/2011/338.pdf
+36
crypto/ecc.h include/crypto/internal/ecc.h
··· 226 226 const u64 *mod, unsigned int ndigits); 227 227 228 228 /** 229 + * vli_num_bits() - Counts the number of bits required for vli. 230 + * 231 + * @vli: vli to check. 232 + * @ndigits: Length of the @vli 233 + * 234 + * Return: The number of bits required to represent @vli. 235 + */ 236 + unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits); 237 + 238 + /** 239 + * ecc_aloc_point() - Allocate ECC point. 240 + * 241 + * @ndigits: Length of vlis in u64 qwords. 242 + * 243 + * Return: Pointer to the allocated point or NULL if allocation failed. 244 + */ 245 + struct ecc_point *ecc_alloc_point(unsigned int ndigits); 246 + 247 + /** 248 + * ecc_free_point() - Free ECC point. 249 + * 250 + * @p: The point to free. 251 + */ 252 + void ecc_free_point(struct ecc_point *p); 253 + 254 + /** 255 + * ecc_point_is_zero() - Check if point is zero. 256 + * 257 + * @p: Point to check for zero. 258 + * 259 + * Return: true if point is the point at infinity, false otherwise. 260 + */ 261 + bool ecc_point_is_zero(const struct ecc_point *point); 262 + 263 + /** 229 264 * ecc_point_mult_shamir() - Add two points multiplied by scalars 230 265 * 231 266 * @result: resulting point ··· 277 242 const u64 *x, const struct ecc_point *p, 278 243 const u64 *y, const struct ecc_point *q, 279 244 const struct ecc_curve *curve); 245 + 280 246 #endif
+1 -1
crypto/ecdh.c
··· 6 6 */ 7 7 8 8 #include <linux/module.h> 9 + #include <crypto/internal/ecc.h> 9 10 #include <crypto/internal/kpp.h> 10 11 #include <crypto/kpp.h> 11 12 #include <crypto/ecdh.h> 12 13 #include <linux/scatterlist.h> 13 - #include "ecc.h" 14 14 15 15 struct ecdh_ctx { 16 16 unsigned int curve_id;
+1 -1
crypto/ecdsa.c
··· 5 5 6 6 #include <linux/module.h> 7 7 #include <crypto/internal/akcipher.h> 8 + #include <crypto/internal/ecc.h> 8 9 #include <crypto/akcipher.h> 9 10 #include <crypto/ecdh.h> 10 11 #include <linux/asn1_decoder.h> 11 12 #include <linux/scatterlist.h> 12 13 13 - #include "ecc.h" 14 14 #include "ecdsasignature.asn1.h" 15 15 16 16 struct ecc_ctx {
+1 -1
crypto/ecrdsa.c
··· 20 20 #include <linux/crypto.h> 21 21 #include <crypto/streebog.h> 22 22 #include <crypto/internal/akcipher.h> 23 + #include <crypto/internal/ecc.h> 23 24 #include <crypto/akcipher.h> 24 25 #include <linux/oid_registry.h> 25 26 #include <linux/scatterlist.h> 26 27 #include "ecrdsa_params.asn1.h" 27 28 #include "ecrdsa_pub_key.asn1.h" 28 - #include "ecc.h" 29 29 #include "ecrdsa_defs.h" 30 30 31 31 #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)
+1 -1
crypto/ecrdsa_defs.h
··· 13 13 #ifndef _CRYTO_ECRDSA_DEFS_H 14 14 #define _CRYTO_ECRDSA_DEFS_H 15 15 16 - #include "ecc.h" 16 + #include <crypto/internal/ecc.h> 17 17 18 18 #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8) 19 19 #define ECRDSA_MAX_DIGITS (512 / 64)
+10
crypto/internal.h
··· 10 10 11 11 #include <crypto/algapi.h> 12 12 #include <linux/completion.h> 13 + #include <linux/jump_label.h> 13 14 #include <linux/list.h> 14 15 #include <linux/module.h> 15 16 #include <linux/notifier.h> ··· 28 27 struct crypto_alg *adult; 29 28 struct completion completion; 30 29 u32 mask; 30 + bool test_started; 31 31 }; 32 32 33 33 enum { ··· 46 44 extern struct list_head crypto_alg_list; 47 45 extern struct rw_semaphore crypto_alg_sem; 48 46 extern struct blocking_notifier_head crypto_chain; 47 + 48 + DECLARE_STATIC_KEY_FALSE(crypto_boot_test_finished); 49 49 50 50 #ifdef CONFIG_PROC_FS 51 51 void __init crypto_init_proc(void); ··· 74 70 75 71 struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask); 76 72 void crypto_larval_kill(struct crypto_alg *alg); 73 + void crypto_wait_for_test(struct crypto_larval *larval); 77 74 void crypto_alg_tested(const char *name, int err); 78 75 79 76 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, ··· 159 154 { 160 155 if (flags & CRYPTO_TFM_REQ_MAY_SLEEP) 161 156 cond_resched(); 157 + } 158 + 159 + static inline int crypto_is_test_larval(struct crypto_larval *larval) 160 + { 161 + return larval->alg.cra_driver_name[0]; 162 162 } 163 163 164 164 #endif /* _CRYPTO_INTERNAL_H */
+12 -12
crypto/jitterentropy.c
··· 125 125 * This test complies with SP800-90B section 4.4.2. 126 126 ***************************************************************************/ 127 127 128 - /** 128 + /* 129 129 * Reset the APT counter 130 130 * 131 131 * @ec [in] Reference to entropy collector ··· 138 138 ec->apt_observations = 0; 139 139 } 140 140 141 - /** 141 + /* 142 142 * Insert a new entropy event into APT 143 143 * 144 144 * @ec [in] Reference to entropy collector ··· 182 182 * the end. The caller of the Jitter RNG is informed with an error code. 183 183 ***************************************************************************/ 184 184 185 - /** 185 + /* 186 186 * Repetition Count Test as defined in SP800-90B section 4.4.1 187 187 * 188 188 * @ec [in] Reference to entropy collector ··· 223 223 } 224 224 } 225 225 226 - /** 226 + /* 227 227 * Is there an RCT health test failure? 228 228 * 229 229 * @ec [in] Reference to entropy collector ··· 246 246 (JENT_UINT64_MAX - prev + 1 + next); 247 247 } 248 248 249 - /** 249 + /* 250 250 * Stuck test by checking the: 251 251 * 1st derivative of the jitter measurement (time delta) 252 252 * 2nd derivative of the jitter measurement (delta of time deltas) ··· 288 288 return 0; 289 289 } 290 290 291 - /** 291 + /* 292 292 * Report any health test failures 293 293 * 294 294 * @ec [in] Reference to entropy collector ··· 310 310 * Noise sources 311 311 ***************************************************************************/ 312 312 313 - /** 313 + /* 314 314 * Update of the loop count used for the next round of 315 315 * an entropy collection. 316 316 * ··· 353 353 return (shuffle + (1<<min)); 354 354 } 355 355 356 - /** 356 + /* 357 357 * CPU Jitter noise source -- this is the noise source based on the CPU 358 358 * execution time jitter 359 359 * ··· 435 435 ec->data = new; 436 436 } 437 437 438 - /** 438 + /* 439 439 * Memory Access noise source -- this is a noise source based on variations in 440 440 * memory access times 441 441 * ··· 500 500 /*************************************************************************** 501 501 * Start of entropy processing logic 502 502 ***************************************************************************/ 503 - /** 503 + /* 504 504 * This is the heart of the entropy generation: calculate time deltas and 505 505 * use the CPU jitter in the time deltas. The jitter is injected into the 506 506 * entropy pool. ··· 539 539 return stuck; 540 540 } 541 541 542 - /** 542 + /* 543 543 * Generator of one 64 bit random number 544 544 * Function fills rand_data->data 545 545 * ··· 566 566 } 567 567 } 568 568 569 - /** 569 + /* 570 570 * Entry function: Obtain entropy for the caller. 571 571 * 572 572 * This function invokes the entropy gathering logic as often to generate
+8 -4
crypto/pcrypt.c
··· 78 78 { 79 79 struct pcrypt_request *preq = pcrypt_padata_request(padata); 80 80 struct aead_request *req = pcrypt_request_ctx(preq); 81 + int ret; 81 82 82 - padata->info = crypto_aead_encrypt(req); 83 + ret = crypto_aead_encrypt(req); 83 84 84 - if (padata->info == -EINPROGRESS) 85 + if (ret == -EINPROGRESS) 85 86 return; 86 87 88 + padata->info = ret; 87 89 padata_do_serial(padata); 88 90 } 89 91 ··· 125 123 { 126 124 struct pcrypt_request *preq = pcrypt_padata_request(padata); 127 125 struct aead_request *req = pcrypt_request_ctx(preq); 126 + int ret; 128 127 129 - padata->info = crypto_aead_decrypt(req); 128 + ret = crypto_aead_decrypt(req); 130 129 131 - if (padata->info == -EINPROGRESS) 130 + if (ret == -EINPROGRESS) 132 131 return; 133 132 133 + padata->info = ret; 134 134 padata_do_serial(padata); 135 135 } 136 136
+2 -3
crypto/tcrypt.c
··· 1333 1333 1334 1334 if (bs > XBUFSIZE * PAGE_SIZE) { 1335 1335 pr_err("template (%u) too big for buffer (%lu)\n", 1336 - *b_size, XBUFSIZE * PAGE_SIZE); 1336 + bs, XBUFSIZE * PAGE_SIZE); 1337 1337 goto out; 1338 1338 } 1339 1339 ··· 1386 1386 memset(cur->xbuf[p], 0xff, k); 1387 1387 1388 1388 skcipher_request_set_crypt(cur->req, cur->sg, 1389 - cur->sg, *b_size, 1390 - iv); 1389 + cur->sg, bs, iv); 1391 1390 } 1392 1391 1393 1392 if (secs) {
+2 -2
crypto/testmgr.c
··· 1061 1061 1062 1062 static void crypto_disable_simd_for_test(void) 1063 1063 { 1064 - preempt_disable(); 1064 + migrate_disable(); 1065 1065 __this_cpu_write(crypto_simd_disabled_for_test, true); 1066 1066 } 1067 1067 1068 1068 static void crypto_reenable_simd_for_test(void) 1069 1069 { 1070 1070 __this_cpu_write(crypto_simd_disabled_for_test, false); 1071 - preempt_enable(); 1071 + migrate_enable(); 1072 1072 } 1073 1073 1074 1074 /*
+1 -1
crypto/testmgr.h
··· 1201 1201 "\xd1\x86\x48\x55\xce\x83\xee\x8e\x51\xc7\xde\x32\x12\x47\x7d\x46" 1202 1202 "\xb8\x35\xdf\x41\x02\x01\x00\x02\x01\x00\x02\x01\x00\x02\x01\x00" 1203 1203 "\x02\x01\x00", 1204 - .key_len = 804, 1204 + .key_len = 803, 1205 1205 /* 1206 1206 * m is SHA256 hash of following message: 1207 1207 * "\x49\x41\xbe\x0a\x0c\xc9\xf6\x35\x51\xe4\x27\x56\x13\x71\x4b\xd0"
+6 -6
drivers/char/hw_random/Kconfig
··· 63 63 64 64 config HW_RANDOM_ATMEL 65 65 tristate "Atmel Random Number Generator support" 66 - depends on ARCH_AT91 && HAVE_CLK && OF 66 + depends on (ARCH_AT91 || COMPILE_TEST) && HAVE_CLK && OF 67 67 default HW_RANDOM 68 68 help 69 69 This driver provides kernel-side support for the Random Number ··· 87 87 config HW_RANDOM_BCM2835 88 88 tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" 89 89 depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ 90 - ARCH_BCM_63XX || BCM63XX || BMIPS_GENERIC 90 + ARCH_BCM_63XX || BCM63XX || BMIPS_GENERIC || COMPILE_TEST 91 91 default HW_RANDOM 92 92 help 93 93 This driver provides kernel-side support for the Random Number ··· 100 100 101 101 config HW_RANDOM_IPROC_RNG200 102 102 tristate "Broadcom iProc/STB RNG200 support" 103 - depends on ARCH_BCM_IPROC || ARCH_BCM2835 || ARCH_BRCMSTB 103 + depends on ARCH_BCM_IPROC || ARCH_BCM2835 || ARCH_BRCMSTB || COMPILE_TEST 104 104 default HW_RANDOM 105 105 help 106 106 This driver provides kernel-side support for the RNG200 ··· 165 165 166 166 config HW_RANDOM_OMAP 167 167 tristate "OMAP Random Number Generator support" 168 - depends on ARCH_OMAP16XX || ARCH_OMAP2PLUS || ARCH_MVEBU || ARCH_K3 168 + depends on ARCH_OMAP16XX || ARCH_OMAP2PLUS || ARCH_MVEBU || ARCH_K3 || COMPILE_TEST 169 169 default HW_RANDOM 170 170 help 171 171 This driver provides kernel-side support for the Random Number ··· 179 179 180 180 config HW_RANDOM_OMAP3_ROM 181 181 tristate "OMAP3 ROM Random Number Generator support" 182 - depends on ARCH_OMAP3 182 + depends on ARCH_OMAP3 || COMPILE_TEST 183 183 default HW_RANDOM 184 184 help 185 185 This driver provides kernel-side support for the Random Number ··· 298 298 299 299 config HW_RANDOM_NOMADIK 300 300 tristate "ST-Ericsson Nomadik Random Number Generator support" 301 - depends on ARCH_NOMADIK 301 + depends on ARCH_NOMADIK || COMPILE_TEST 302 302 default HW_RANDOM 303 303 help 304 304 This driver provides kernel-side support for the Random Number
+1 -3
drivers/char/hw_random/ixp4xx-rng.c
··· 42 42 { 43 43 void __iomem * rng_base; 44 44 struct device *dev = &pdev->dev; 45 - struct resource *res; 46 45 47 46 if (!cpu_is_ixp46x()) /* includes IXP455 */ 48 47 return -ENOSYS; 49 48 50 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 51 - rng_base = devm_ioremap_resource(dev, res); 49 + rng_base = devm_platform_ioremap_resource(pdev, 0); 52 50 if (IS_ERR(rng_base)) 53 51 return PTR_ERR(rng_base); 54 52
+3 -2
drivers/char/hw_random/meson-rng.c
··· 54 54 if (IS_ERR(data->base)) 55 55 return PTR_ERR(data->base); 56 56 57 - data->core_clk = devm_clk_get(dev, "core"); 57 + data->core_clk = devm_clk_get_optional(dev, "core"); 58 58 if (IS_ERR(data->core_clk)) 59 - data->core_clk = NULL; 59 + return dev_err_probe(dev, PTR_ERR(data->core_clk), 60 + "Failed to get core clock\n"); 60 61 61 62 if (data->core_clk) { 62 63 ret = clk_prepare_enable(data->core_clk);
+7 -2
drivers/char/hw_random/mtk-rng.c
··· 166 166 return mtk_rng_init(&priv->rng); 167 167 } 168 168 169 - static UNIVERSAL_DEV_PM_OPS(mtk_rng_pm_ops, mtk_rng_runtime_suspend, 170 - mtk_rng_runtime_resume, NULL); 169 + static const struct dev_pm_ops mtk_rng_pm_ops = { 170 + SET_RUNTIME_PM_OPS(mtk_rng_runtime_suspend, 171 + mtk_rng_runtime_resume, NULL) 172 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 173 + pm_runtime_force_resume) 174 + }; 175 + 171 176 #define MTK_RNG_PM_OPS (&mtk_rng_pm_ops) 172 177 #else /* CONFIG_PM */ 173 178 #define MTK_RNG_PM_OPS NULL
+2 -2
drivers/char/hw_random/s390-trng.c
··· 111 111 #if IS_ENABLED(CONFIG_ARCH_RANDOM) 112 112 u64 arch_counter = atomic64_read(&s390_arch_random_counter); 113 113 114 - return snprintf(buf, PAGE_SIZE, 114 + return sysfs_emit(buf, 115 115 "trng: %llu\n" 116 116 "hwrng: %llu\n" 117 117 "arch: %llu\n" ··· 119 119 dev_counter, hwrng_counter, arch_counter, 120 120 dev_counter + hwrng_counter + arch_counter); 121 121 #else 122 - return snprintf(buf, PAGE_SIZE, 122 + return sysfs_emit(buf, 123 123 "trng: %llu\n" 124 124 "hwrng: %llu\n" 125 125 "total: %llu\n",
+15 -4
drivers/crypto/caam/caampkc.c
··· 1153 1153 int caam_pkc_init(struct device *ctrldev) 1154 1154 { 1155 1155 struct caam_drv_private *priv = dev_get_drvdata(ctrldev); 1156 - u32 pk_inst; 1156 + u32 pk_inst, pkha; 1157 1157 int err; 1158 1158 init_done = false; 1159 1159 1160 1160 /* Determine public key hardware accelerator presence. */ 1161 - if (priv->era < 10) 1161 + if (priv->era < 10) { 1162 1162 pk_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & 1163 1163 CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT; 1164 - else 1165 - pk_inst = rd_reg32(&priv->ctrl->vreg.pkha) & CHA_VER_NUM_MASK; 1164 + } else { 1165 + pkha = rd_reg32(&priv->ctrl->vreg.pkha); 1166 + pk_inst = pkha & CHA_VER_NUM_MASK; 1167 + 1168 + /* 1169 + * Newer CAAMs support partially disabled functionality. If this is the 1170 + * case, the number is non-zero, but this bit is set to indicate that 1171 + * no encryption or decryption is supported. Only signing and verifying 1172 + * is supported. 1173 + */ 1174 + if (pkha & CHA_VER_MISC_PKHA_NO_CRYPT) 1175 + pk_inst = 0; 1176 + } 1166 1177 1167 1178 /* Do not register algorithms if PKHA is not present. */ 1168 1179 if (!pk_inst)
+3
drivers/crypto/caam/regs.h
··· 322 322 /* CHA Miscellaneous Information - AESA_MISC specific */ 323 323 #define CHA_VER_MISC_AES_GCM BIT(1 + CHA_VER_MISC_SHIFT) 324 324 325 + /* CHA Miscellaneous Information - PKHA_MISC specific */ 326 + #define CHA_VER_MISC_PKHA_NO_CRYPT BIT(7 + CHA_VER_MISC_SHIFT) 327 + 325 328 /* 326 329 * caam_perfmon - Performance Monitor/Secure Memory Status/ 327 330 * CAAM Global Status/Component Version IDs
+2 -3
drivers/crypto/ccp/ccp-dev-v3.c
··· 467 467 468 468 cmd_q = &ccp->cmd_q[i]; 469 469 470 - kthread = kthread_create(ccp_cmd_queue_thread, cmd_q, 471 - "%s-q%u", ccp->name, cmd_q->id); 470 + kthread = kthread_run(ccp_cmd_queue_thread, cmd_q, 471 + "%s-q%u", ccp->name, cmd_q->id); 472 472 if (IS_ERR(kthread)) { 473 473 dev_err(dev, "error creating queue thread (%ld)\n", 474 474 PTR_ERR(kthread)); ··· 477 477 } 478 478 479 479 cmd_q->kthread = kthread; 480 - wake_up_process(kthread); 481 480 } 482 481 483 482 dev_dbg(dev, "Enabling interrupts...\n");
+2 -3
drivers/crypto/ccp/ccp-dev-v5.c
··· 950 950 951 951 cmd_q = &ccp->cmd_q[i]; 952 952 953 - kthread = kthread_create(ccp_cmd_queue_thread, cmd_q, 954 - "%s-q%u", ccp->name, cmd_q->id); 953 + kthread = kthread_run(ccp_cmd_queue_thread, cmd_q, 954 + "%s-q%u", ccp->name, cmd_q->id); 955 955 if (IS_ERR(kthread)) { 956 956 dev_err(dev, "error creating queue thread (%ld)\n", 957 957 PTR_ERR(kthread)); ··· 960 960 } 961 961 962 962 cmd_q->kthread = kthread; 963 - wake_up_process(kthread); 964 963 } 965 964 966 965 dev_dbg(dev, "Enabling interrupts...\n");
+1 -1
drivers/crypto/ccp/sev-dev.c
··· 134 134 case SEV_CMD_DOWNLOAD_FIRMWARE: return sizeof(struct sev_data_download_firmware); 135 135 case SEV_CMD_GET_ID: return sizeof(struct sev_data_get_id); 136 136 case SEV_CMD_ATTESTATION_REPORT: return sizeof(struct sev_data_attestation_report); 137 - case SEV_CMD_SEND_CANCEL: return sizeof(struct sev_data_send_cancel); 137 + case SEV_CMD_SEND_CANCEL: return sizeof(struct sev_data_send_cancel); 138 138 default: return 0; 139 139 } 140 140
+2 -1
drivers/crypto/ccree/cc_driver.c
··· 103 103 static void init_cc_cache_params(struct cc_drvdata *drvdata) 104 104 { 105 105 struct device *dev = drvdata_to_dev(drvdata); 106 - u32 cache_params, ace_const, val, mask; 106 + u32 cache_params, ace_const, val; 107 + u64 mask; 107 108 108 109 /* compute CC_AXIM_CACHE_PARAMS */ 109 110 cache_params = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS));
+63 -11
drivers/crypto/hisilicon/qm.c
··· 233 233 #define QM_DBG_WRITE_LEN 1024 234 234 #define QM_DBG_TMP_BUF_LEN 22 235 235 #define QM_PCI_COMMAND_INVALID ~0 236 + #define QM_RESET_STOP_TX_OFFSET 1 237 + #define QM_RESET_STOP_RX_OFFSET 2 236 238 237 239 #define WAIT_PERIOD 20 238 240 #define REMOVE_WAIT_DELAY 10 ··· 883 881 schedule_work(&qm->cmd_process); 884 882 885 883 return IRQ_HANDLED; 884 + } 885 + 886 + static void qm_set_qp_disable(struct hisi_qp *qp, int offset) 887 + { 888 + u32 *addr; 889 + 890 + if (qp->is_in_kernel) 891 + return; 892 + 893 + addr = (u32 *)(qp->qdma.va + qp->qdma.size) - offset; 894 + *addr = 1; 895 + 896 + /* make sure setup is completed */ 897 + mb(); 886 898 } 887 899 888 900 static irqreturn_t qm_aeq_irq(int irq, void *data) ··· 2483 2467 return qp->sqe + sq_tail * qp->qm->sqe_size; 2484 2468 } 2485 2469 2470 + static void hisi_qm_unset_hw_reset(struct hisi_qp *qp) 2471 + { 2472 + u64 *addr; 2473 + 2474 + /* Use last 64 bits of DUS to reset status. */ 2475 + addr = (u64 *)(qp->qdma.va + qp->qdma.size) - QM_RESET_STOP_TX_OFFSET; 2476 + *addr = 0; 2477 + } 2478 + 2486 2479 static struct hisi_qp *qm_create_qp_nolock(struct hisi_qm *qm, u8 alg_type) 2487 2480 { 2488 2481 struct device *dev = &qm->pdev->dev; ··· 2517 2492 } 2518 2493 2519 2494 qp = &qm->qp_array[qp_id]; 2520 - 2495 + hisi_qm_unset_hw_reset(qp); 2521 2496 memset(qp->cqe, 0, sizeof(struct qm_cqe) * QM_Q_DEPTH); 2522 2497 2523 2498 qp->event_cb = NULL; ··· 2937 2912 return hisi_qm_get_free_qp_num(uacce->priv); 2938 2913 } 2939 2914 2915 + static void hisi_qm_set_hw_reset(struct hisi_qm *qm, int offset) 2916 + { 2917 + int i; 2918 + 2919 + for (i = 0; i < qm->qp_num; i++) 2920 + qm_set_qp_disable(&qm->qp_array[i], offset); 2921 + } 2922 + 2940 2923 static int hisi_qm_uacce_get_queue(struct uacce_device *uacce, 2941 2924 unsigned long arg, 2942 2925 struct uacce_queue *q) ··· 3127 3094 if (IS_ERR(uacce)) 3128 3095 return PTR_ERR(uacce); 3129 3096 3130 - if (uacce->flags & UACCE_DEV_SVA && qm->mode == UACCE_MODE_SVA) { 3097 + if (uacce->flags & UACCE_DEV_SVA) { 3131 3098 qm->use_sva = true; 3132 3099 } else { 3133 3100 /* only consider sva case */ ··· 3155 3122 else 3156 3123 mmio_page_nr = qm->db_interval / PAGE_SIZE; 3157 3124 3125 + /* Add one more page for device or qp status */ 3158 3126 dus_page_nr = (PAGE_SIZE - 1 + qm->sqe_size * QM_Q_DEPTH + 3159 - sizeof(struct qm_cqe) * QM_Q_DEPTH) >> PAGE_SHIFT; 3127 + sizeof(struct qm_cqe) * QM_Q_DEPTH + PAGE_SIZE) >> 3128 + PAGE_SHIFT; 3160 3129 3161 3130 uacce->qf_pg_num[UACCE_QFRT_MMIO] = mmio_page_nr; 3162 3131 uacce->qf_pg_num[UACCE_QFRT_DUS] = dus_page_nr; ··· 3402 3367 3403 3368 qm_irq_unregister(qm); 3404 3369 hisi_qm_pci_uninit(qm); 3405 - uacce_remove(qm->uacce); 3406 - qm->uacce = NULL; 3370 + if (qm->use_sva) { 3371 + uacce_remove(qm->uacce); 3372 + qm->uacce = NULL; 3373 + } 3407 3374 3408 3375 up_write(&qm->qps_lock); 3409 3376 } ··· 3719 3682 3720 3683 if (qm->status.stop_reason == QM_SOFT_RESET || 3721 3684 qm->status.stop_reason == QM_FLR) { 3685 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); 3722 3686 ret = qm_stop_started_qp(qm); 3723 3687 if (ret < 0) { 3724 3688 dev_err(dev, "Failed to stop started qp!\n"); 3725 3689 goto err_unlock; 3726 3690 } 3691 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_RX_OFFSET); 3727 3692 } 3728 3693 3729 3694 /* Mask eq and aeq irq */ ··· 4224 4185 return -EINVAL; 4225 4186 } 4226 4187 4227 - ret = sscanf(buf, "%ld", val); 4188 + ret = sscanf(buf, "%lu", val); 4228 4189 if (ret != QM_QOS_VAL_NUM) 4229 4190 return -EINVAL; 4230 4191 ··· 5084 5045 5085 5046 ret = qm_controller_reset_prepare(qm); 5086 5047 if (ret) { 5048 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); 5049 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_RX_OFFSET); 5087 5050 clear_bit(QM_RST_SCHED, &qm->misc_ctl); 5088 5051 return ret; 5089 5052 } ··· 5172 5131 ret = hisi_qm_stop(qm, QM_FLR); 5173 5132 if (ret) { 5174 5133 pci_err(pdev, "Failed to stop QM, ret = %d.\n", ret); 5134 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); 5135 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_RX_OFFSET); 5175 5136 return; 5176 5137 } 5177 5138 ··· 5357 5314 atomic_set(&qm->status.flags, QM_STOP); 5358 5315 cmd = QM_VF_PREPARE_FAIL; 5359 5316 goto err_prepare; 5317 + } else { 5318 + goto out; 5360 5319 } 5361 5320 5362 5321 err_prepare: 5322 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); 5323 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_RX_OFFSET); 5324 + out: 5363 5325 pci_save_state(pdev); 5364 5326 ret = qm->ops->ping_pf(qm, cmd); 5365 5327 if (ret) ··· 5825 5777 goto err_irq_register; 5826 5778 } 5827 5779 5828 - ret = qm_alloc_uacce(qm); 5829 - if (ret < 0) 5830 - dev_warn(dev, "fail to alloc uacce (%d)\n", ret); 5780 + if (qm->mode == UACCE_MODE_SVA) { 5781 + ret = qm_alloc_uacce(qm); 5782 + if (ret < 0) 5783 + dev_warn(dev, "fail to alloc uacce (%d)\n", ret); 5784 + } 5831 5785 5832 5786 ret = hisi_qm_memory_init(qm); 5833 5787 if (ret) ··· 5842 5792 return 0; 5843 5793 5844 5794 err_alloc_uacce: 5845 - uacce_remove(qm->uacce); 5846 - qm->uacce = NULL; 5795 + if (qm->use_sva) { 5796 + uacce_remove(qm->uacce); 5797 + qm->uacce = NULL; 5798 + } 5847 5799 err_irq_register: 5848 5800 qm_irq_unregister(qm); 5849 5801 err_pci_init:
+1 -1
drivers/crypto/hisilicon/zip/zip_main.c
··· 218 218 {"HZIP_AVG_DELAY ", 0x28ull}, 219 219 {"HZIP_MEM_VISIBLE_DATA ", 0x30ull}, 220 220 {"HZIP_MEM_VISIBLE_ADDR ", 0x34ull}, 221 - {"HZIP_COMSUMED_BYTE ", 0x38ull}, 221 + {"HZIP_CONSUMED_BYTE ", 0x38ull}, 222 222 {"HZIP_PRODUCED_BYTE ", 0x40ull}, 223 223 {"HZIP_COMP_INF ", 0x70ull}, 224 224 {"HZIP_PRE_OUT ", 0x78ull},
+1 -6
drivers/crypto/img-hash.c
··· 674 674 static int img_hash_cra_init(struct crypto_tfm *tfm, const char *alg_name) 675 675 { 676 676 struct img_hash_ctx *ctx = crypto_tfm_ctx(tfm); 677 - int err = -ENOMEM; 678 677 679 678 ctx->fallback = crypto_alloc_ahash(alg_name, 0, 680 679 CRYPTO_ALG_NEED_FALLBACK); 681 680 if (IS_ERR(ctx->fallback)) { 682 681 pr_err("img_hash: Could not load fallback driver.\n"); 683 - err = PTR_ERR(ctx->fallback); 684 - goto err; 682 + return PTR_ERR(ctx->fallback); 685 683 } 686 684 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), 687 685 sizeof(struct img_hash_request_ctx) + ··· 687 689 IMG_HASH_DMA_THRESHOLD); 688 690 689 691 return 0; 690 - 691 - err: 692 - return err; 693 692 } 694 693 695 694 static int img_hash_cra_md5_init(struct crypto_tfm *tfm)
+19
drivers/crypto/keembay/Kconfig
··· 39 39 40 40 Intel does not recommend use of CTS mode with AES/SM4. 41 41 42 + config CRYPTO_DEV_KEEMBAY_OCS_ECC 43 + tristate "Support for Intel Keem Bay OCS ECC HW acceleration" 44 + depends on ARCH_KEEMBAY || COMPILE_TEST 45 + depends on OF || COMPILE_TEST 46 + depends on HAS_IOMEM 47 + select CRYPTO_ECDH 48 + select CRYPTO_ENGINE 49 + help 50 + Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) 51 + Elliptic Curve Cryptography (ECC) hardware acceleration for use with 52 + Crypto API. 53 + 54 + Provides OCS acceleration for ECDH-256 and ECDH-384. 55 + 56 + Say Y or M if you are compiling for the Intel Keem Bay SoC. The 57 + module will be called keembay-ocs-ecc. 58 + 59 + If unsure, say N. 60 + 42 61 config CRYPTO_DEV_KEEMBAY_OCS_HCU 43 62 tristate "Support for Intel Keem Bay OCS HCU HW acceleration" 44 63 select CRYPTO_HASH
+2
drivers/crypto/keembay/Makefile
··· 4 4 obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4) += keembay-ocs-aes.o 5 5 keembay-ocs-aes-objs := keembay-ocs-aes-core.o ocs-aes.o 6 6 7 + obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_ECC) += keembay-ocs-ecc.o 8 + 7 9 obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_HCU) += keembay-ocs-hcu.o 8 10 keembay-ocs-hcu-objs := keembay-ocs-hcu-core.o ocs-hcu.o
+1017
drivers/crypto/keembay/keembay-ocs-ecc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Keem Bay OCS ECC Crypto Driver. 4 + * 5 + * Copyright (C) 2019-2021 Intel Corporation 6 + */ 7 + 8 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 + 10 + #include <linux/clk.h> 11 + #include <linux/completion.h> 12 + #include <linux/crypto.h> 13 + #include <linux/delay.h> 14 + #include <linux/fips.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/io.h> 17 + #include <linux/iopoll.h> 18 + #include <linux/irq.h> 19 + #include <linux/module.h> 20 + #include <linux/of.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/scatterlist.h> 23 + #include <linux/slab.h> 24 + #include <linux/types.h> 25 + 26 + #include <crypto/ecc_curve.h> 27 + #include <crypto/ecdh.h> 28 + #include <crypto/engine.h> 29 + #include <crypto/kpp.h> 30 + #include <crypto/rng.h> 31 + 32 + #include <crypto/internal/ecc.h> 33 + #include <crypto/internal/kpp.h> 34 + 35 + #define DRV_NAME "keembay-ocs-ecc" 36 + 37 + #define KMB_OCS_ECC_PRIORITY 350 38 + 39 + #define HW_OFFS_OCS_ECC_COMMAND 0x00000000 40 + #define HW_OFFS_OCS_ECC_STATUS 0x00000004 41 + #define HW_OFFS_OCS_ECC_DATA_IN 0x00000080 42 + #define HW_OFFS_OCS_ECC_CX_DATA_OUT 0x00000100 43 + #define HW_OFFS_OCS_ECC_CY_DATA_OUT 0x00000180 44 + #define HW_OFFS_OCS_ECC_ISR 0x00000400 45 + #define HW_OFFS_OCS_ECC_IER 0x00000404 46 + 47 + #define HW_OCS_ECC_ISR_INT_STATUS_DONE BIT(0) 48 + #define HW_OCS_ECC_COMMAND_INS_BP BIT(0) 49 + 50 + #define HW_OCS_ECC_COMMAND_START_VAL BIT(0) 51 + 52 + #define OCS_ECC_OP_SIZE_384 BIT(8) 53 + #define OCS_ECC_OP_SIZE_256 0 54 + 55 + /* ECC Instruction : for ECC_COMMAND */ 56 + #define OCS_ECC_INST_WRITE_AX (0x1 << HW_OCS_ECC_COMMAND_INS_BP) 57 + #define OCS_ECC_INST_WRITE_AY (0x2 << HW_OCS_ECC_COMMAND_INS_BP) 58 + #define OCS_ECC_INST_WRITE_BX_D (0x3 << HW_OCS_ECC_COMMAND_INS_BP) 59 + #define OCS_ECC_INST_WRITE_BY_L (0x4 << HW_OCS_ECC_COMMAND_INS_BP) 60 + #define OCS_ECC_INST_WRITE_P (0x5 << HW_OCS_ECC_COMMAND_INS_BP) 61 + #define OCS_ECC_INST_WRITE_A (0x6 << HW_OCS_ECC_COMMAND_INS_BP) 62 + #define OCS_ECC_INST_CALC_D_IDX_A (0x8 << HW_OCS_ECC_COMMAND_INS_BP) 63 + #define OCS_ECC_INST_CALC_A_POW_B_MODP (0xB << HW_OCS_ECC_COMMAND_INS_BP) 64 + #define OCS_ECC_INST_CALC_A_MUL_B_MODP (0xC << HW_OCS_ECC_COMMAND_INS_BP) 65 + #define OCS_ECC_INST_CALC_A_ADD_B_MODP (0xD << HW_OCS_ECC_COMMAND_INS_BP) 66 + 67 + #define ECC_ENABLE_INTR 1 68 + 69 + #define POLL_USEC 100 70 + #define TIMEOUT_USEC 10000 71 + 72 + #define KMB_ECC_VLI_MAX_DIGITS ECC_CURVE_NIST_P384_DIGITS 73 + #define KMB_ECC_VLI_MAX_BYTES (KMB_ECC_VLI_MAX_DIGITS \ 74 + << ECC_DIGITS_TO_BYTES_SHIFT) 75 + 76 + #define POW_CUBE 3 77 + 78 + /** 79 + * struct ocs_ecc_dev - ECC device context 80 + * @list: List of device contexts 81 + * @dev: OCS ECC device 82 + * @base_reg: IO base address of OCS ECC 83 + * @engine: Crypto engine for the device 84 + * @irq_done: IRQ done completion. 85 + * @irq: IRQ number 86 + */ 87 + struct ocs_ecc_dev { 88 + struct list_head list; 89 + struct device *dev; 90 + void __iomem *base_reg; 91 + struct crypto_engine *engine; 92 + struct completion irq_done; 93 + int irq; 94 + }; 95 + 96 + /** 97 + * struct ocs_ecc_ctx - Transformation context. 98 + * @engine_ctx: Crypto engine ctx. 99 + * @ecc_dev: The ECC driver associated with this context. 100 + * @curve: The elliptic curve used by this transformation. 101 + * @private_key: The private key. 102 + */ 103 + struct ocs_ecc_ctx { 104 + struct crypto_engine_ctx engine_ctx; 105 + struct ocs_ecc_dev *ecc_dev; 106 + const struct ecc_curve *curve; 107 + u64 private_key[KMB_ECC_VLI_MAX_DIGITS]; 108 + }; 109 + 110 + /* Driver data. */ 111 + struct ocs_ecc_drv { 112 + struct list_head dev_list; 113 + spinlock_t lock; /* Protects dev_list. */ 114 + }; 115 + 116 + /* Global variable holding the list of OCS ECC devices (only one expected). */ 117 + static struct ocs_ecc_drv ocs_ecc = { 118 + .dev_list = LIST_HEAD_INIT(ocs_ecc.dev_list), 119 + .lock = __SPIN_LOCK_UNLOCKED(ocs_ecc.lock), 120 + }; 121 + 122 + /* Get OCS ECC tfm context from kpp_request. */ 123 + static inline struct ocs_ecc_ctx *kmb_ocs_ecc_tctx(struct kpp_request *req) 124 + { 125 + return kpp_tfm_ctx(crypto_kpp_reqtfm(req)); 126 + } 127 + 128 + /* Converts number of digits to number of bytes. */ 129 + static inline unsigned int digits_to_bytes(unsigned int n) 130 + { 131 + return n << ECC_DIGITS_TO_BYTES_SHIFT; 132 + } 133 + 134 + /* 135 + * Wait for ECC idle i.e when an operation (other than write operations) 136 + * is done. 137 + */ 138 + static inline int ocs_ecc_wait_idle(struct ocs_ecc_dev *dev) 139 + { 140 + u32 value; 141 + 142 + return readl_poll_timeout((dev->base_reg + HW_OFFS_OCS_ECC_STATUS), 143 + value, 144 + !(value & HW_OCS_ECC_ISR_INT_STATUS_DONE), 145 + POLL_USEC, TIMEOUT_USEC); 146 + } 147 + 148 + static void ocs_ecc_cmd_start(struct ocs_ecc_dev *ecc_dev, u32 op_size) 149 + { 150 + iowrite32(op_size | HW_OCS_ECC_COMMAND_START_VAL, 151 + ecc_dev->base_reg + HW_OFFS_OCS_ECC_COMMAND); 152 + } 153 + 154 + /* Direct write of u32 buffer to ECC engine with associated instruction. */ 155 + static void ocs_ecc_write_cmd_and_data(struct ocs_ecc_dev *dev, 156 + u32 op_size, 157 + u32 inst, 158 + const void *data_in, 159 + size_t data_size) 160 + { 161 + iowrite32(op_size | inst, dev->base_reg + HW_OFFS_OCS_ECC_COMMAND); 162 + 163 + /* MMIO Write src uint32 to dst. */ 164 + memcpy_toio(dev->base_reg + HW_OFFS_OCS_ECC_DATA_IN, data_in, 165 + data_size); 166 + } 167 + 168 + /* Start OCS ECC operation and wait for its completion. */ 169 + static int ocs_ecc_trigger_op(struct ocs_ecc_dev *ecc_dev, u32 op_size, 170 + u32 inst) 171 + { 172 + reinit_completion(&ecc_dev->irq_done); 173 + 174 + iowrite32(ECC_ENABLE_INTR, ecc_dev->base_reg + HW_OFFS_OCS_ECC_IER); 175 + iowrite32(op_size | inst, ecc_dev->base_reg + HW_OFFS_OCS_ECC_COMMAND); 176 + 177 + return wait_for_completion_interruptible(&ecc_dev->irq_done); 178 + } 179 + 180 + /** 181 + * ocs_ecc_read_cx_out() - Read the CX data output buffer. 182 + * @dev: The OCS ECC device to read from. 183 + * @cx_out: The buffer where to store the CX value. Must be at least 184 + * @byte_count byte long. 185 + * @byte_count: The amount of data to read. 186 + */ 187 + static inline void ocs_ecc_read_cx_out(struct ocs_ecc_dev *dev, void *cx_out, 188 + size_t byte_count) 189 + { 190 + memcpy_fromio(cx_out, dev->base_reg + HW_OFFS_OCS_ECC_CX_DATA_OUT, 191 + byte_count); 192 + } 193 + 194 + /** 195 + * ocs_ecc_read_cy_out() - Read the CX data output buffer. 196 + * @dev: The OCS ECC device to read from. 197 + * @cy_out: The buffer where to store the CY value. Must be at least 198 + * @byte_count byte long. 199 + * @byte_count: The amount of data to read. 200 + */ 201 + static inline void ocs_ecc_read_cy_out(struct ocs_ecc_dev *dev, void *cy_out, 202 + size_t byte_count) 203 + { 204 + memcpy_fromio(cy_out, dev->base_reg + HW_OFFS_OCS_ECC_CY_DATA_OUT, 205 + byte_count); 206 + } 207 + 208 + static struct ocs_ecc_dev *kmb_ocs_ecc_find_dev(struct ocs_ecc_ctx *tctx) 209 + { 210 + if (tctx->ecc_dev) 211 + return tctx->ecc_dev; 212 + 213 + spin_lock(&ocs_ecc.lock); 214 + 215 + /* Only a single OCS device available. */ 216 + tctx->ecc_dev = list_first_entry(&ocs_ecc.dev_list, struct ocs_ecc_dev, 217 + list); 218 + 219 + spin_unlock(&ocs_ecc.lock); 220 + 221 + return tctx->ecc_dev; 222 + } 223 + 224 + /* Do point multiplication using OCS ECC HW. */ 225 + static int kmb_ecc_point_mult(struct ocs_ecc_dev *ecc_dev, 226 + struct ecc_point *result, 227 + const struct ecc_point *point, 228 + u64 *scalar, 229 + const struct ecc_curve *curve) 230 + { 231 + u8 sca[KMB_ECC_VLI_MAX_BYTES]; /* Use the maximum data size. */ 232 + u32 op_size = (curve->g.ndigits > ECC_CURVE_NIST_P256_DIGITS) ? 233 + OCS_ECC_OP_SIZE_384 : OCS_ECC_OP_SIZE_256; 234 + size_t nbytes = digits_to_bytes(curve->g.ndigits); 235 + int rc = 0; 236 + 237 + /* Generate random nbytes for Simple and Differential SCA protection. */ 238 + rc = crypto_get_default_rng(); 239 + if (rc) 240 + return rc; 241 + 242 + rc = crypto_rng_get_bytes(crypto_default_rng, sca, nbytes); 243 + crypto_put_default_rng(); 244 + if (rc) 245 + return rc; 246 + 247 + /* Wait engine to be idle before starting new operation. */ 248 + rc = ocs_ecc_wait_idle(ecc_dev); 249 + if (rc) 250 + return rc; 251 + 252 + /* Send ecc_start pulse as well as indicating operation size. */ 253 + ocs_ecc_cmd_start(ecc_dev, op_size); 254 + 255 + /* Write ax param; Base point (Gx). */ 256 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_AX, 257 + point->x, nbytes); 258 + 259 + /* Write ay param; Base point (Gy). */ 260 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_AY, 261 + point->y, nbytes); 262 + 263 + /* 264 + * Write the private key into DATA_IN reg. 265 + * 266 + * Since DATA_IN register is used to write different values during the 267 + * computation private Key value is overwritten with 268 + * side-channel-resistance value. 269 + */ 270 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_BX_D, 271 + scalar, nbytes); 272 + 273 + /* Write operand by/l. */ 274 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_BY_L, 275 + sca, nbytes); 276 + memzero_explicit(sca, sizeof(sca)); 277 + 278 + /* Write p = curve prime(GF modulus). */ 279 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_P, 280 + curve->p, nbytes); 281 + 282 + /* Write a = curve coefficient. */ 283 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_A, 284 + curve->a, nbytes); 285 + 286 + /* Make hardware perform the multiplication. */ 287 + rc = ocs_ecc_trigger_op(ecc_dev, op_size, OCS_ECC_INST_CALC_D_IDX_A); 288 + if (rc) 289 + return rc; 290 + 291 + /* Read result. */ 292 + ocs_ecc_read_cx_out(ecc_dev, result->x, nbytes); 293 + ocs_ecc_read_cy_out(ecc_dev, result->y, nbytes); 294 + 295 + return 0; 296 + } 297 + 298 + /** 299 + * kmb_ecc_do_scalar_op() - Perform Scalar operation using OCS ECC HW. 300 + * @ecc_dev: The OCS ECC device to use. 301 + * @scalar_out: Where to store the output scalar. 302 + * @scalar_a: Input scalar operand 'a'. 303 + * @scalar_b: Input scalar operand 'b' 304 + * @curve: The curve on which the operation is performed. 305 + * @ndigits: The size of the operands (in digits). 306 + * @inst: The operation to perform (as an OCS ECC instruction). 307 + * 308 + * Return: 0 on success, negative error code otherwise. 309 + */ 310 + static int kmb_ecc_do_scalar_op(struct ocs_ecc_dev *ecc_dev, u64 *scalar_out, 311 + const u64 *scalar_a, const u64 *scalar_b, 312 + const struct ecc_curve *curve, 313 + unsigned int ndigits, const u32 inst) 314 + { 315 + u32 op_size = (ndigits > ECC_CURVE_NIST_P256_DIGITS) ? 316 + OCS_ECC_OP_SIZE_384 : OCS_ECC_OP_SIZE_256; 317 + size_t nbytes = digits_to_bytes(ndigits); 318 + int rc; 319 + 320 + /* Wait engine to be idle before starting new operation. */ 321 + rc = ocs_ecc_wait_idle(ecc_dev); 322 + if (rc) 323 + return rc; 324 + 325 + /* Send ecc_start pulse as well as indicating operation size. */ 326 + ocs_ecc_cmd_start(ecc_dev, op_size); 327 + 328 + /* Write ax param (Base point (Gx).*/ 329 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_AX, 330 + scalar_a, nbytes); 331 + 332 + /* Write ay param Base point (Gy).*/ 333 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_AY, 334 + scalar_b, nbytes); 335 + 336 + /* Write p = curve prime(GF modulus).*/ 337 + ocs_ecc_write_cmd_and_data(ecc_dev, op_size, OCS_ECC_INST_WRITE_P, 338 + curve->p, nbytes); 339 + 340 + /* Give instruction A.B or A+B to ECC engine. */ 341 + rc = ocs_ecc_trigger_op(ecc_dev, op_size, inst); 342 + if (rc) 343 + return rc; 344 + 345 + ocs_ecc_read_cx_out(ecc_dev, scalar_out, nbytes); 346 + 347 + if (vli_is_zero(scalar_out, ndigits)) 348 + return -EINVAL; 349 + 350 + return 0; 351 + } 352 + 353 + /* SP800-56A section 5.6.2.3.4 partial verification: ephemeral keys only */ 354 + static int kmb_ocs_ecc_is_pubkey_valid_partial(struct ocs_ecc_dev *ecc_dev, 355 + const struct ecc_curve *curve, 356 + struct ecc_point *pk) 357 + { 358 + u64 xxx[KMB_ECC_VLI_MAX_DIGITS] = { 0 }; 359 + u64 yy[KMB_ECC_VLI_MAX_DIGITS] = { 0 }; 360 + u64 w[KMB_ECC_VLI_MAX_DIGITS] = { 0 }; 361 + int rc; 362 + 363 + if (WARN_ON(pk->ndigits != curve->g.ndigits)) 364 + return -EINVAL; 365 + 366 + /* Check 1: Verify key is not the zero point. */ 367 + if (ecc_point_is_zero(pk)) 368 + return -EINVAL; 369 + 370 + /* Check 2: Verify key is in the range [0, p-1]. */ 371 + if (vli_cmp(curve->p, pk->x, pk->ndigits) != 1) 372 + return -EINVAL; 373 + 374 + if (vli_cmp(curve->p, pk->y, pk->ndigits) != 1) 375 + return -EINVAL; 376 + 377 + /* Check 3: Verify that y^2 == (x^3 + a·x + b) mod p */ 378 + 379 + /* y^2 */ 380 + /* Compute y^2 -> store in yy */ 381 + rc = kmb_ecc_do_scalar_op(ecc_dev, yy, pk->y, pk->y, curve, pk->ndigits, 382 + OCS_ECC_INST_CALC_A_MUL_B_MODP); 383 + if (rc) 384 + goto exit; 385 + 386 + /* x^3 */ 387 + /* Assigning w = 3, used for calculating x^3. */ 388 + w[0] = POW_CUBE; 389 + /* Load the next stage.*/ 390 + rc = kmb_ecc_do_scalar_op(ecc_dev, xxx, pk->x, w, curve, pk->ndigits, 391 + OCS_ECC_INST_CALC_A_POW_B_MODP); 392 + if (rc) 393 + goto exit; 394 + 395 + /* Do a*x -> store in w. */ 396 + rc = kmb_ecc_do_scalar_op(ecc_dev, w, curve->a, pk->x, curve, 397 + pk->ndigits, 398 + OCS_ECC_INST_CALC_A_MUL_B_MODP); 399 + if (rc) 400 + goto exit; 401 + 402 + /* Do ax + b == w + b; store in w. */ 403 + rc = kmb_ecc_do_scalar_op(ecc_dev, w, w, curve->b, curve, 404 + pk->ndigits, 405 + OCS_ECC_INST_CALC_A_ADD_B_MODP); 406 + if (rc) 407 + goto exit; 408 + 409 + /* x^3 + ax + b == x^3 + w -> store in w. */ 410 + rc = kmb_ecc_do_scalar_op(ecc_dev, w, xxx, w, curve, pk->ndigits, 411 + OCS_ECC_INST_CALC_A_ADD_B_MODP); 412 + if (rc) 413 + goto exit; 414 + 415 + /* Compare y^2 == x^3 + a·x + b. */ 416 + rc = vli_cmp(yy, w, pk->ndigits); 417 + if (rc) 418 + rc = -EINVAL; 419 + 420 + exit: 421 + memzero_explicit(xxx, sizeof(xxx)); 422 + memzero_explicit(yy, sizeof(yy)); 423 + memzero_explicit(w, sizeof(w)); 424 + 425 + return rc; 426 + } 427 + 428 + /* SP800-56A section 5.6.2.3.3 full verification */ 429 + static int kmb_ocs_ecc_is_pubkey_valid_full(struct ocs_ecc_dev *ecc_dev, 430 + const struct ecc_curve *curve, 431 + struct ecc_point *pk) 432 + { 433 + struct ecc_point *nQ; 434 + int rc; 435 + 436 + /* Checks 1 through 3 */ 437 + rc = kmb_ocs_ecc_is_pubkey_valid_partial(ecc_dev, curve, pk); 438 + if (rc) 439 + return rc; 440 + 441 + /* Check 4: Verify that nQ is the zero point. */ 442 + nQ = ecc_alloc_point(pk->ndigits); 443 + if (!nQ) 444 + return -ENOMEM; 445 + 446 + rc = kmb_ecc_point_mult(ecc_dev, nQ, pk, curve->n, curve); 447 + if (rc) 448 + goto exit; 449 + 450 + if (!ecc_point_is_zero(nQ)) 451 + rc = -EINVAL; 452 + 453 + exit: 454 + ecc_free_point(nQ); 455 + 456 + return rc; 457 + } 458 + 459 + static int kmb_ecc_is_key_valid(const struct ecc_curve *curve, 460 + const u64 *private_key, size_t private_key_len) 461 + { 462 + size_t ndigits = curve->g.ndigits; 463 + u64 one[KMB_ECC_VLI_MAX_DIGITS] = {1}; 464 + u64 res[KMB_ECC_VLI_MAX_DIGITS]; 465 + 466 + if (private_key_len != digits_to_bytes(ndigits)) 467 + return -EINVAL; 468 + 469 + if (!private_key) 470 + return -EINVAL; 471 + 472 + /* Make sure the private key is in the range [2, n-3]. */ 473 + if (vli_cmp(one, private_key, ndigits) != -1) 474 + return -EINVAL; 475 + 476 + vli_sub(res, curve->n, one, ndigits); 477 + vli_sub(res, res, one, ndigits); 478 + if (vli_cmp(res, private_key, ndigits) != 1) 479 + return -EINVAL; 480 + 481 + return 0; 482 + } 483 + 484 + /* 485 + * ECC private keys are generated using the method of extra random bits, 486 + * equivalent to that described in FIPS 186-4, Appendix B.4.1. 487 + * 488 + * d = (c mod(n–1)) + 1 where c is a string of random bits, 64 bits longer 489 + * than requested 490 + * 0 <= c mod(n-1) <= n-2 and implies that 491 + * 1 <= d <= n-1 492 + * 493 + * This method generates a private key uniformly distributed in the range 494 + * [1, n-1]. 495 + */ 496 + static int kmb_ecc_gen_privkey(const struct ecc_curve *curve, u64 *privkey) 497 + { 498 + size_t nbytes = digits_to_bytes(curve->g.ndigits); 499 + u64 priv[KMB_ECC_VLI_MAX_DIGITS]; 500 + size_t nbits; 501 + int rc; 502 + 503 + nbits = vli_num_bits(curve->n, curve->g.ndigits); 504 + 505 + /* Check that N is included in Table 1 of FIPS 186-4, section 6.1.1 */ 506 + if (nbits < 160 || curve->g.ndigits > ARRAY_SIZE(priv)) 507 + return -EINVAL; 508 + 509 + /* 510 + * FIPS 186-4 recommends that the private key should be obtained from a 511 + * RBG with a security strength equal to or greater than the security 512 + * strength associated with N. 513 + * 514 + * The maximum security strength identified by NIST SP800-57pt1r4 for 515 + * ECC is 256 (N >= 512). 516 + * 517 + * This condition is met by the default RNG because it selects a favored 518 + * DRBG with a security strength of 256. 519 + */ 520 + if (crypto_get_default_rng()) 521 + return -EFAULT; 522 + 523 + rc = crypto_rng_get_bytes(crypto_default_rng, (u8 *)priv, nbytes); 524 + crypto_put_default_rng(); 525 + if (rc) 526 + goto cleanup; 527 + 528 + rc = kmb_ecc_is_key_valid(curve, priv, nbytes); 529 + if (rc) 530 + goto cleanup; 531 + 532 + ecc_swap_digits(priv, privkey, curve->g.ndigits); 533 + 534 + cleanup: 535 + memzero_explicit(&priv, sizeof(priv)); 536 + 537 + return rc; 538 + } 539 + 540 + static int kmb_ocs_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, 541 + unsigned int len) 542 + { 543 + struct ocs_ecc_ctx *tctx = kpp_tfm_ctx(tfm); 544 + struct ecdh params; 545 + int rc = 0; 546 + 547 + rc = crypto_ecdh_decode_key(buf, len, &params); 548 + if (rc) 549 + goto cleanup; 550 + 551 + /* Ensure key size is not bigger then expected. */ 552 + if (params.key_size > digits_to_bytes(tctx->curve->g.ndigits)) { 553 + rc = -EINVAL; 554 + goto cleanup; 555 + } 556 + 557 + /* Auto-generate private key is not provided. */ 558 + if (!params.key || !params.key_size) { 559 + rc = kmb_ecc_gen_privkey(tctx->curve, tctx->private_key); 560 + goto cleanup; 561 + } 562 + 563 + rc = kmb_ecc_is_key_valid(tctx->curve, (const u64 *)params.key, 564 + params.key_size); 565 + if (rc) 566 + goto cleanup; 567 + 568 + ecc_swap_digits((const u64 *)params.key, tctx->private_key, 569 + tctx->curve->g.ndigits); 570 + cleanup: 571 + memzero_explicit(&params, sizeof(params)); 572 + 573 + if (rc) 574 + tctx->curve = NULL; 575 + 576 + return rc; 577 + } 578 + 579 + /* Compute shared secret. */ 580 + static int kmb_ecc_do_shared_secret(struct ocs_ecc_ctx *tctx, 581 + struct kpp_request *req) 582 + { 583 + struct ocs_ecc_dev *ecc_dev = tctx->ecc_dev; 584 + const struct ecc_curve *curve = tctx->curve; 585 + u64 shared_secret[KMB_ECC_VLI_MAX_DIGITS]; 586 + u64 pubk_buf[KMB_ECC_VLI_MAX_DIGITS * 2]; 587 + size_t copied, nbytes, pubk_len; 588 + struct ecc_point *pk, *result; 589 + int rc; 590 + 591 + nbytes = digits_to_bytes(curve->g.ndigits); 592 + 593 + /* Public key is a point, thus it has two coordinates */ 594 + pubk_len = 2 * nbytes; 595 + 596 + /* Copy public key from SG list to pubk_buf. */ 597 + copied = sg_copy_to_buffer(req->src, 598 + sg_nents_for_len(req->src, pubk_len), 599 + pubk_buf, pubk_len); 600 + if (copied != pubk_len) 601 + return -EINVAL; 602 + 603 + /* Allocate and initialize public key point. */ 604 + pk = ecc_alloc_point(curve->g.ndigits); 605 + if (!pk) 606 + return -ENOMEM; 607 + 608 + ecc_swap_digits(pubk_buf, pk->x, curve->g.ndigits); 609 + ecc_swap_digits(&pubk_buf[curve->g.ndigits], pk->y, curve->g.ndigits); 610 + 611 + /* 612 + * Check the public key for following 613 + * Check 1: Verify key is not the zero point. 614 + * Check 2: Verify key is in the range [1, p-1]. 615 + * Check 3: Verify that y^2 == (x^3 + a·x + b) mod p 616 + */ 617 + rc = kmb_ocs_ecc_is_pubkey_valid_partial(ecc_dev, curve, pk); 618 + if (rc) 619 + goto exit_free_pk; 620 + 621 + /* Allocate point for storing computed shared secret. */ 622 + result = ecc_alloc_point(pk->ndigits); 623 + if (!result) { 624 + rc = -ENOMEM; 625 + goto exit_free_pk; 626 + } 627 + 628 + /* Calculate the shared secret.*/ 629 + rc = kmb_ecc_point_mult(ecc_dev, result, pk, tctx->private_key, curve); 630 + if (rc) 631 + goto exit_free_result; 632 + 633 + if (ecc_point_is_zero(result)) { 634 + rc = -EFAULT; 635 + goto exit_free_result; 636 + } 637 + 638 + /* Copy shared secret from point to buffer. */ 639 + ecc_swap_digits(result->x, shared_secret, result->ndigits); 640 + 641 + /* Request might ask for less bytes than what we have. */ 642 + nbytes = min_t(size_t, nbytes, req->dst_len); 643 + 644 + copied = sg_copy_from_buffer(req->dst, 645 + sg_nents_for_len(req->dst, nbytes), 646 + shared_secret, nbytes); 647 + 648 + if (copied != nbytes) 649 + rc = -EINVAL; 650 + 651 + memzero_explicit(shared_secret, sizeof(shared_secret)); 652 + 653 + exit_free_result: 654 + ecc_free_point(result); 655 + 656 + exit_free_pk: 657 + ecc_free_point(pk); 658 + 659 + return rc; 660 + } 661 + 662 + /* Compute public key. */ 663 + static int kmb_ecc_do_public_key(struct ocs_ecc_ctx *tctx, 664 + struct kpp_request *req) 665 + { 666 + const struct ecc_curve *curve = tctx->curve; 667 + u64 pubk_buf[KMB_ECC_VLI_MAX_DIGITS * 2]; 668 + struct ecc_point *pk; 669 + size_t pubk_len; 670 + size_t copied; 671 + int rc; 672 + 673 + /* Public key is a point, so it has double the digits. */ 674 + pubk_len = 2 * digits_to_bytes(curve->g.ndigits); 675 + 676 + pk = ecc_alloc_point(curve->g.ndigits); 677 + if (!pk) 678 + return -ENOMEM; 679 + 680 + /* Public Key(pk) = priv * G. */ 681 + rc = kmb_ecc_point_mult(tctx->ecc_dev, pk, &curve->g, tctx->private_key, 682 + curve); 683 + if (rc) 684 + goto exit; 685 + 686 + /* SP800-56A rev 3 5.6.2.1.3 key check */ 687 + if (kmb_ocs_ecc_is_pubkey_valid_full(tctx->ecc_dev, curve, pk)) { 688 + rc = -EAGAIN; 689 + goto exit; 690 + } 691 + 692 + /* Copy public key from point to buffer. */ 693 + ecc_swap_digits(pk->x, pubk_buf, pk->ndigits); 694 + ecc_swap_digits(pk->y, &pubk_buf[pk->ndigits], pk->ndigits); 695 + 696 + /* Copy public key to req->dst. */ 697 + copied = sg_copy_from_buffer(req->dst, 698 + sg_nents_for_len(req->dst, pubk_len), 699 + pubk_buf, pubk_len); 700 + 701 + if (copied != pubk_len) 702 + rc = -EINVAL; 703 + 704 + exit: 705 + ecc_free_point(pk); 706 + 707 + return rc; 708 + } 709 + 710 + static int kmb_ocs_ecc_do_one_request(struct crypto_engine *engine, 711 + void *areq) 712 + { 713 + struct kpp_request *req = container_of(areq, struct kpp_request, base); 714 + struct ocs_ecc_ctx *tctx = kmb_ocs_ecc_tctx(req); 715 + struct ocs_ecc_dev *ecc_dev = tctx->ecc_dev; 716 + int rc; 717 + 718 + if (req->src) 719 + rc = kmb_ecc_do_shared_secret(tctx, req); 720 + else 721 + rc = kmb_ecc_do_public_key(tctx, req); 722 + 723 + crypto_finalize_kpp_request(ecc_dev->engine, req, rc); 724 + 725 + return 0; 726 + } 727 + 728 + static int kmb_ocs_ecdh_generate_public_key(struct kpp_request *req) 729 + { 730 + struct ocs_ecc_ctx *tctx = kmb_ocs_ecc_tctx(req); 731 + const struct ecc_curve *curve = tctx->curve; 732 + 733 + /* Ensure kmb_ocs_ecdh_set_secret() has been successfully called. */ 734 + if (!tctx->curve) 735 + return -EINVAL; 736 + 737 + /* Ensure dst is present. */ 738 + if (!req->dst) 739 + return -EINVAL; 740 + 741 + /* Check the request dst is big enough to hold the public key. */ 742 + if (req->dst_len < (2 * digits_to_bytes(curve->g.ndigits))) 743 + return -EINVAL; 744 + 745 + /* 'src' is not supposed to be present when generate pubk is called. */ 746 + if (req->src) 747 + return -EINVAL; 748 + 749 + return crypto_transfer_kpp_request_to_engine(tctx->ecc_dev->engine, 750 + req); 751 + } 752 + 753 + static int kmb_ocs_ecdh_compute_shared_secret(struct kpp_request *req) 754 + { 755 + struct ocs_ecc_ctx *tctx = kmb_ocs_ecc_tctx(req); 756 + const struct ecc_curve *curve = tctx->curve; 757 + 758 + /* Ensure kmb_ocs_ecdh_set_secret() has been successfully called. */ 759 + if (!tctx->curve) 760 + return -EINVAL; 761 + 762 + /* Ensure dst is present. */ 763 + if (!req->dst) 764 + return -EINVAL; 765 + 766 + /* Ensure src is present. */ 767 + if (!req->src) 768 + return -EINVAL; 769 + 770 + /* 771 + * req->src is expected to the (other-side) public key, so its length 772 + * must be 2 * coordinate size (in bytes). 773 + */ 774 + if (req->src_len != 2 * digits_to_bytes(curve->g.ndigits)) 775 + return -EINVAL; 776 + 777 + return crypto_transfer_kpp_request_to_engine(tctx->ecc_dev->engine, 778 + req); 779 + } 780 + 781 + static int kmb_ecc_tctx_init(struct ocs_ecc_ctx *tctx, unsigned int curve_id) 782 + { 783 + memset(tctx, 0, sizeof(*tctx)); 784 + 785 + tctx->ecc_dev = kmb_ocs_ecc_find_dev(tctx); 786 + 787 + if (IS_ERR(tctx->ecc_dev)) { 788 + pr_err("Failed to find the device : %ld\n", 789 + PTR_ERR(tctx->ecc_dev)); 790 + return PTR_ERR(tctx->ecc_dev); 791 + } 792 + 793 + tctx->curve = ecc_get_curve(curve_id); 794 + if (!tctx->curve) 795 + return -EOPNOTSUPP; 796 + 797 + tctx->engine_ctx.op.prepare_request = NULL; 798 + tctx->engine_ctx.op.do_one_request = kmb_ocs_ecc_do_one_request; 799 + tctx->engine_ctx.op.unprepare_request = NULL; 800 + 801 + return 0; 802 + } 803 + 804 + static int kmb_ocs_ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm) 805 + { 806 + struct ocs_ecc_ctx *tctx = kpp_tfm_ctx(tfm); 807 + 808 + return kmb_ecc_tctx_init(tctx, ECC_CURVE_NIST_P256); 809 + } 810 + 811 + static int kmb_ocs_ecdh_nist_p384_init_tfm(struct crypto_kpp *tfm) 812 + { 813 + struct ocs_ecc_ctx *tctx = kpp_tfm_ctx(tfm); 814 + 815 + return kmb_ecc_tctx_init(tctx, ECC_CURVE_NIST_P384); 816 + } 817 + 818 + static void kmb_ocs_ecdh_exit_tfm(struct crypto_kpp *tfm) 819 + { 820 + struct ocs_ecc_ctx *tctx = kpp_tfm_ctx(tfm); 821 + 822 + memzero_explicit(tctx->private_key, sizeof(*tctx->private_key)); 823 + } 824 + 825 + static unsigned int kmb_ocs_ecdh_max_size(struct crypto_kpp *tfm) 826 + { 827 + struct ocs_ecc_ctx *tctx = kpp_tfm_ctx(tfm); 828 + 829 + /* Public key is made of two coordinates, so double the digits. */ 830 + return digits_to_bytes(tctx->curve->g.ndigits) * 2; 831 + } 832 + 833 + static struct kpp_alg ocs_ecdh_p256 = { 834 + .set_secret = kmb_ocs_ecdh_set_secret, 835 + .generate_public_key = kmb_ocs_ecdh_generate_public_key, 836 + .compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret, 837 + .init = kmb_ocs_ecdh_nist_p256_init_tfm, 838 + .exit = kmb_ocs_ecdh_exit_tfm, 839 + .max_size = kmb_ocs_ecdh_max_size, 840 + .base = { 841 + .cra_name = "ecdh-nist-p256", 842 + .cra_driver_name = "ecdh-nist-p256-keembay-ocs", 843 + .cra_priority = KMB_OCS_ECC_PRIORITY, 844 + .cra_module = THIS_MODULE, 845 + .cra_ctxsize = sizeof(struct ocs_ecc_ctx), 846 + }, 847 + }; 848 + 849 + static struct kpp_alg ocs_ecdh_p384 = { 850 + .set_secret = kmb_ocs_ecdh_set_secret, 851 + .generate_public_key = kmb_ocs_ecdh_generate_public_key, 852 + .compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret, 853 + .init = kmb_ocs_ecdh_nist_p384_init_tfm, 854 + .exit = kmb_ocs_ecdh_exit_tfm, 855 + .max_size = kmb_ocs_ecdh_max_size, 856 + .base = { 857 + .cra_name = "ecdh-nist-p384", 858 + .cra_driver_name = "ecdh-nist-p384-keembay-ocs", 859 + .cra_priority = KMB_OCS_ECC_PRIORITY, 860 + .cra_module = THIS_MODULE, 861 + .cra_ctxsize = sizeof(struct ocs_ecc_ctx), 862 + }, 863 + }; 864 + 865 + static irqreturn_t ocs_ecc_irq_handler(int irq, void *dev_id) 866 + { 867 + struct ocs_ecc_dev *ecc_dev = dev_id; 868 + u32 status; 869 + 870 + /* 871 + * Read the status register and write it back to clear the 872 + * DONE_INT_STATUS bit. 873 + */ 874 + status = ioread32(ecc_dev->base_reg + HW_OFFS_OCS_ECC_ISR); 875 + iowrite32(status, ecc_dev->base_reg + HW_OFFS_OCS_ECC_ISR); 876 + 877 + if (!(status & HW_OCS_ECC_ISR_INT_STATUS_DONE)) 878 + return IRQ_NONE; 879 + 880 + complete(&ecc_dev->irq_done); 881 + 882 + return IRQ_HANDLED; 883 + } 884 + 885 + static int kmb_ocs_ecc_probe(struct platform_device *pdev) 886 + { 887 + struct device *dev = &pdev->dev; 888 + struct ocs_ecc_dev *ecc_dev; 889 + int rc; 890 + 891 + ecc_dev = devm_kzalloc(dev, sizeof(*ecc_dev), GFP_KERNEL); 892 + if (!ecc_dev) 893 + return -ENOMEM; 894 + 895 + ecc_dev->dev = dev; 896 + 897 + platform_set_drvdata(pdev, ecc_dev); 898 + 899 + INIT_LIST_HEAD(&ecc_dev->list); 900 + init_completion(&ecc_dev->irq_done); 901 + 902 + /* Get base register address. */ 903 + ecc_dev->base_reg = devm_platform_ioremap_resource(pdev, 0); 904 + if (IS_ERR(ecc_dev->base_reg)) { 905 + dev_err(dev, "Failed to get base address\n"); 906 + rc = PTR_ERR(ecc_dev->base_reg); 907 + goto list_del; 908 + } 909 + 910 + /* Get and request IRQ */ 911 + ecc_dev->irq = platform_get_irq(pdev, 0); 912 + if (ecc_dev->irq < 0) { 913 + rc = ecc_dev->irq; 914 + goto list_del; 915 + } 916 + 917 + rc = devm_request_threaded_irq(dev, ecc_dev->irq, ocs_ecc_irq_handler, 918 + NULL, 0, "keembay-ocs-ecc", ecc_dev); 919 + if (rc < 0) { 920 + dev_err(dev, "Could not request IRQ\n"); 921 + goto list_del; 922 + } 923 + 924 + /* Add device to the list of OCS ECC devices. */ 925 + spin_lock(&ocs_ecc.lock); 926 + list_add_tail(&ecc_dev->list, &ocs_ecc.dev_list); 927 + spin_unlock(&ocs_ecc.lock); 928 + 929 + /* Initialize crypto engine. */ 930 + ecc_dev->engine = crypto_engine_alloc_init(dev, 1); 931 + if (!ecc_dev->engine) { 932 + dev_err(dev, "Could not allocate crypto engine\n"); 933 + goto list_del; 934 + } 935 + 936 + rc = crypto_engine_start(ecc_dev->engine); 937 + if (rc) { 938 + dev_err(dev, "Could not start crypto engine\n"); 939 + goto cleanup; 940 + } 941 + 942 + /* Register the KPP algo. */ 943 + rc = crypto_register_kpp(&ocs_ecdh_p256); 944 + if (rc) { 945 + dev_err(dev, 946 + "Could not register OCS algorithms with Crypto API\n"); 947 + goto cleanup; 948 + } 949 + 950 + rc = crypto_register_kpp(&ocs_ecdh_p384); 951 + if (rc) { 952 + dev_err(dev, 953 + "Could not register OCS algorithms with Crypto API\n"); 954 + goto ocs_ecdh_p384_error; 955 + } 956 + 957 + return 0; 958 + 959 + ocs_ecdh_p384_error: 960 + crypto_unregister_kpp(&ocs_ecdh_p256); 961 + 962 + cleanup: 963 + crypto_engine_exit(ecc_dev->engine); 964 + 965 + list_del: 966 + spin_lock(&ocs_ecc.lock); 967 + list_del(&ecc_dev->list); 968 + spin_unlock(&ocs_ecc.lock); 969 + 970 + return rc; 971 + } 972 + 973 + static int kmb_ocs_ecc_remove(struct platform_device *pdev) 974 + { 975 + struct ocs_ecc_dev *ecc_dev; 976 + 977 + ecc_dev = platform_get_drvdata(pdev); 978 + if (!ecc_dev) 979 + return -ENODEV; 980 + 981 + crypto_unregister_kpp(&ocs_ecdh_p384); 982 + crypto_unregister_kpp(&ocs_ecdh_p256); 983 + 984 + spin_lock(&ocs_ecc.lock); 985 + list_del(&ecc_dev->list); 986 + spin_unlock(&ocs_ecc.lock); 987 + 988 + crypto_engine_exit(ecc_dev->engine); 989 + 990 + return 0; 991 + } 992 + 993 + /* Device tree driver match. */ 994 + static const struct of_device_id kmb_ocs_ecc_of_match[] = { 995 + { 996 + .compatible = "intel,keembay-ocs-ecc", 997 + }, 998 + {} 999 + }; 1000 + 1001 + /* The OCS driver is a platform device. */ 1002 + static struct platform_driver kmb_ocs_ecc_driver = { 1003 + .probe = kmb_ocs_ecc_probe, 1004 + .remove = kmb_ocs_ecc_remove, 1005 + .driver = { 1006 + .name = DRV_NAME, 1007 + .of_match_table = kmb_ocs_ecc_of_match, 1008 + }, 1009 + }; 1010 + module_platform_driver(kmb_ocs_ecc_driver); 1011 + 1012 + MODULE_LICENSE("GPL"); 1013 + MODULE_DESCRIPTION("Intel Keem Bay OCS ECC Driver"); 1014 + MODULE_ALIAS_CRYPTO("ecdh-nist-p256"); 1015 + MODULE_ALIAS_CRYPTO("ecdh-nist-p384"); 1016 + MODULE_ALIAS_CRYPTO("ecdh-nist-p256-keembay-ocs"); 1017 + MODULE_ALIAS_CRYPTO("ecdh-nist-p384-keembay-ocs");
-1
drivers/crypto/marvell/cesa/cesa.c
··· 615 615 }; 616 616 module_platform_driver(marvell_cesa); 617 617 618 - MODULE_ALIAS("platform:mv_crypto"); 619 618 MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>"); 620 619 MODULE_AUTHOR("Arnaud Ebalard <arno@natisbad.org>"); 621 620 MODULE_DESCRIPTION("Support for Marvell's cryptographic engine");
+1
drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c
··· 1274 1274 req->base.complete, req->base.data); 1275 1275 aead_request_set_crypt(&rctx->fbk_req, req->src, 1276 1276 req->dst, req->cryptlen, req->iv); 1277 + aead_request_set_ad(&rctx->fbk_req, req->assoclen); 1277 1278 ret = is_enc ? crypto_aead_encrypt(&rctx->fbk_req) : 1278 1279 crypto_aead_decrypt(&rctx->fbk_req); 1279 1280 } else {
+33 -2
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.c
··· 1 1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 2 /* Copyright(c) 2020 Intel Corporation */ 3 + #include <linux/iopoll.h> 3 4 #include <adf_accel_devices.h> 4 5 #include <adf_common_drv.h> 5 6 #include <adf_pf2vf_msg.h> ··· 162 161 ADF_CSR_WR(addr, ADF_4XXX_SMIAPF_MASK_OFFSET, 0); 163 162 } 164 163 165 - static int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 164 + static int adf_init_device(struct adf_accel_dev *accel_dev) 165 + { 166 + void __iomem *addr; 167 + u32 status; 168 + u32 csr; 169 + int ret; 170 + 171 + addr = (&GET_BARS(accel_dev)[ADF_4XXX_PMISC_BAR])->virt_addr; 172 + 173 + /* Temporarily mask PM interrupt */ 174 + csr = ADF_CSR_RD(addr, ADF_4XXX_ERRMSK2); 175 + csr |= ADF_4XXX_PM_SOU; 176 + ADF_CSR_WR(addr, ADF_4XXX_ERRMSK2, csr); 177 + 178 + /* Set DRV_ACTIVE bit to power up the device */ 179 + ADF_CSR_WR(addr, ADF_4XXX_PM_INTERRUPT, ADF_4XXX_PM_DRV_ACTIVE); 180 + 181 + /* Poll status register to make sure the device is powered up */ 182 + ret = read_poll_timeout(ADF_CSR_RD, status, 183 + status & ADF_4XXX_PM_INIT_STATE, 184 + ADF_4XXX_PM_POLL_DELAY_US, 185 + ADF_4XXX_PM_POLL_TIMEOUT_US, true, addr, 186 + ADF_4XXX_PM_STATUS); 187 + if (ret) 188 + dev_err(&GET_DEV(accel_dev), "Failed to power up the device\n"); 189 + 190 + return ret; 191 + } 192 + 193 + static int pfvf_comms_disabled(struct adf_accel_dev *accel_dev) 166 194 { 167 195 return 0; 168 196 } ··· 245 215 hw_data->exit_arb = adf_exit_arb; 246 216 hw_data->get_arb_mapping = adf_get_arbiter_mapping; 247 217 hw_data->enable_ints = adf_enable_ints; 218 + hw_data->init_device = adf_init_device; 248 219 hw_data->reset_device = adf_reset_flr; 249 220 hw_data->admin_ae_mask = ADF_4XXX_ADMIN_AE_MASK; 250 221 hw_data->uof_get_num_objs = uof_get_num_objs; ··· 253 222 hw_data->uof_get_ae_mask = uof_get_ae_mask; 254 223 hw_data->set_msix_rttable = set_msix_default_rttable; 255 224 hw_data->set_ssm_wdtimer = adf_gen4_set_ssm_wdtimer; 256 - hw_data->enable_pfvf_comms = adf_enable_pf2vf_comms; 225 + hw_data->enable_pfvf_comms = pfvf_comms_disabled; 257 226 hw_data->disable_iov = adf_disable_sriov; 258 227 hw_data->min_iov_compat_ver = ADF_PFVF_COMPAT_THIS_VERSION; 259 228
+10
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.h
··· 62 62 #define ADF_4XXX_ADMINMSGLR_OFFSET (0x500578) 63 63 #define ADF_4XXX_MAILBOX_BASE_OFFSET (0x600970) 64 64 65 + /* Power management */ 66 + #define ADF_4XXX_PM_POLL_DELAY_US 20 67 + #define ADF_4XXX_PM_POLL_TIMEOUT_US USEC_PER_SEC 68 + #define ADF_4XXX_PM_STATUS (0x50A00C) 69 + #define ADF_4XXX_PM_INTERRUPT (0x50A028) 70 + #define ADF_4XXX_PM_DRV_ACTIVE BIT(20) 71 + #define ADF_4XXX_PM_INIT_STATE BIT(21) 72 + /* Power management source in ERRSOU2 and ERRMSK2 */ 73 + #define ADF_4XXX_PM_SOU BIT(18) 74 + 65 75 /* Firmware Binaries */ 66 76 #define ADF_4XXX_FW "qat_4xxx.bin" 67 77 #define ADF_4XXX_MMP "qat_4xxx_mmp.bin"
+11 -78
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.c
··· 48 48 return ~(fuses | straps) & ADF_C3XXX_ACCELENGINES_MASK; 49 49 } 50 50 51 - static u32 get_num_accels(struct adf_hw_device_data *self) 52 - { 53 - u32 i, ctr = 0; 54 - 55 - if (!self || !self->accel_mask) 56 - return 0; 57 - 58 - for (i = 0; i < ADF_C3XXX_MAX_ACCELERATORS; i++) { 59 - if (self->accel_mask & (1 << i)) 60 - ctr++; 61 - } 62 - return ctr; 63 - } 64 - 65 - static u32 get_num_aes(struct adf_hw_device_data *self) 66 - { 67 - u32 i, ctr = 0; 68 - 69 - if (!self || !self->ae_mask) 70 - return 0; 71 - 72 - for (i = 0; i < ADF_C3XXX_MAX_ACCELENGINES; i++) { 73 - if (self->ae_mask & (1 << i)) 74 - ctr++; 75 - } 76 - return ctr; 77 - } 78 - 79 51 static u32 get_misc_bar_id(struct adf_hw_device_data *self) 80 52 { 81 53 return ADF_C3XXX_PMISC_BAR; ··· 60 88 61 89 static u32 get_sram_bar_id(struct adf_hw_device_data *self) 62 90 { 63 - return 0; 91 + return ADF_C3XXX_SRAM_BAR; 64 92 } 65 93 66 94 static enum dev_sku_info get_sku(struct adf_hw_device_data *self) 67 95 { 68 - int aes = get_num_aes(self); 96 + int aes = self->get_num_aes(self); 69 97 70 98 if (aes == 6) 71 99 return DEV_SKU_4; ··· 76 104 static const u32 *adf_get_arbiter_mapping(void) 77 105 { 78 106 return thrd_to_arb_map; 79 - } 80 - 81 - static u32 get_pf2vf_offset(u32 i) 82 - { 83 - return ADF_C3XXX_PF2VF_OFFSET(i); 84 - } 85 - 86 - static void adf_enable_error_correction(struct adf_accel_dev *accel_dev) 87 - { 88 - struct adf_hw_device_data *hw_device = accel_dev->hw_device; 89 - struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C3XXX_PMISC_BAR]; 90 - unsigned long accel_mask = hw_device->accel_mask; 91 - unsigned long ae_mask = hw_device->ae_mask; 92 - void __iomem *csr = misc_bar->virt_addr; 93 - unsigned int val, i; 94 - 95 - /* Enable Accel Engine error detection & correction */ 96 - for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 97 - val = ADF_CSR_RD(csr, ADF_C3XXX_AE_CTX_ENABLES(i)); 98 - val |= ADF_C3XXX_ENABLE_AE_ECC_ERR; 99 - ADF_CSR_WR(csr, ADF_C3XXX_AE_CTX_ENABLES(i), val); 100 - val = ADF_CSR_RD(csr, ADF_C3XXX_AE_MISC_CONTROL(i)); 101 - val |= ADF_C3XXX_ENABLE_AE_ECC_PARITY_CORR; 102 - ADF_CSR_WR(csr, ADF_C3XXX_AE_MISC_CONTROL(i), val); 103 - } 104 - 105 - /* Enable shared memory error detection & correction */ 106 - for_each_set_bit(i, &accel_mask, ADF_C3XXX_MAX_ACCELERATORS) { 107 - val = ADF_CSR_RD(csr, ADF_C3XXX_UERRSSMSH(i)); 108 - val |= ADF_C3XXX_ERRSSMSH_EN; 109 - ADF_CSR_WR(csr, ADF_C3XXX_UERRSSMSH(i), val); 110 - val = ADF_CSR_RD(csr, ADF_C3XXX_CERRSSMSH(i)); 111 - val |= ADF_C3XXX_ERRSSMSH_EN; 112 - ADF_CSR_WR(csr, ADF_C3XXX_CERRSSMSH(i), val); 113 - } 114 107 } 115 108 116 109 static void adf_enable_ints(struct adf_accel_dev *accel_dev) ··· 89 152 ADF_C3XXX_SMIA0_MASK); 90 153 ADF_CSR_WR(addr, ADF_C3XXX_SMIAPF1_MASK_OFFSET, 91 154 ADF_C3XXX_SMIA1_MASK); 92 - } 93 - 94 - static int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 95 - { 96 - spin_lock_init(&accel_dev->pf.vf2pf_ints_lock); 97 - 98 - return 0; 99 155 } 100 156 101 157 static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) ··· 107 177 hw_data->num_accel = ADF_C3XXX_MAX_ACCELERATORS; 108 178 hw_data->num_logical_accel = 1; 109 179 hw_data->num_engines = ADF_C3XXX_MAX_ACCELENGINES; 110 - hw_data->tx_rx_gap = ADF_C3XXX_RX_RINGS_OFFSET; 111 - hw_data->tx_rings_mask = ADF_C3XXX_TX_RINGS_MASK; 180 + hw_data->tx_rx_gap = ADF_GEN2_RX_RINGS_OFFSET; 181 + hw_data->tx_rings_mask = ADF_GEN2_TX_RINGS_MASK; 112 182 hw_data->alloc_irq = adf_isr_resource_alloc; 113 183 hw_data->free_irq = adf_isr_resource_free; 114 - hw_data->enable_error_correction = adf_enable_error_correction; 184 + hw_data->enable_error_correction = adf_gen2_enable_error_correction; 115 185 hw_data->get_accel_mask = get_accel_mask; 116 186 hw_data->get_ae_mask = get_ae_mask; 117 187 hw_data->get_accel_cap = adf_gen2_get_accel_cap; 118 - hw_data->get_num_accels = get_num_accels; 119 - hw_data->get_num_aes = get_num_aes; 188 + hw_data->get_num_accels = adf_gen2_get_num_accels; 189 + hw_data->get_num_aes = adf_gen2_get_num_aes; 120 190 hw_data->get_sram_bar_id = get_sram_bar_id; 121 191 hw_data->get_etr_bar_id = get_etr_bar_id; 122 192 hw_data->get_misc_bar_id = get_misc_bar_id; ··· 135 205 hw_data->enable_ints = adf_enable_ints; 136 206 hw_data->reset_device = adf_reset_flr; 137 207 hw_data->set_ssm_wdtimer = adf_gen2_set_ssm_wdtimer; 138 - hw_data->get_pf2vf_offset = get_pf2vf_offset; 208 + hw_data->get_pf2vf_offset = adf_gen2_get_pf2vf_offset; 209 + hw_data->get_vf2pf_sources = adf_gen2_get_vf2pf_sources; 210 + hw_data->enable_vf2pf_interrupts = adf_gen2_enable_vf2pf_interrupts; 211 + hw_data->disable_vf2pf_interrupts = adf_gen2_disable_vf2pf_interrupts; 139 212 hw_data->enable_pfvf_comms = adf_enable_pf2vf_comms; 140 213 hw_data->disable_iov = adf_disable_sriov; 141 214 hw_data->min_iov_compat_ver = ADF_PFVF_COMPAT_THIS_VERSION;
+1 -12
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.h
··· 6 6 /* PCIe configuration space */ 7 7 #define ADF_C3XXX_PMISC_BAR 0 8 8 #define ADF_C3XXX_ETR_BAR 1 9 - #define ADF_C3XXX_RX_RINGS_OFFSET 8 10 - #define ADF_C3XXX_TX_RINGS_MASK 0xFF 9 + #define ADF_C3XXX_SRAM_BAR 0 11 10 #define ADF_C3XXX_MAX_ACCELERATORS 3 12 11 #define ADF_C3XXX_MAX_ACCELENGINES 6 13 12 #define ADF_C3XXX_ACCELERATORS_REG_OFFSET 16 ··· 18 19 #define ADF_C3XXX_SMIA0_MASK 0xFFFF 19 20 #define ADF_C3XXX_SMIA1_MASK 0x1 20 21 #define ADF_C3XXX_SOFTSTRAP_CSR_OFFSET 0x2EC 21 - /* Error detection and correction */ 22 - #define ADF_C3XXX_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818) 23 - #define ADF_C3XXX_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960) 24 - #define ADF_C3XXX_ENABLE_AE_ECC_ERR BIT(28) 25 - #define ADF_C3XXX_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12)) 26 - #define ADF_C3XXX_UERRSSMSH(i) (i * 0x4000 + 0x18) 27 - #define ADF_C3XXX_CERRSSMSH(i) (i * 0x4000 + 0x10) 28 - #define ADF_C3XXX_ERRSSMSH_EN BIT(3) 29 - 30 - #define ADF_C3XXX_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 31 22 32 23 /* AE to function mapping */ 33 24 #define ADF_C3XXX_AE2FUNC_MAP_GRP_A_NUM_REGS 48
+10 -77
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
··· 48 48 return ~(fuses | straps) & ADF_C62X_ACCELENGINES_MASK; 49 49 } 50 50 51 - static u32 get_num_accels(struct adf_hw_device_data *self) 52 - { 53 - u32 i, ctr = 0; 54 - 55 - if (!self || !self->accel_mask) 56 - return 0; 57 - 58 - for (i = 0; i < ADF_C62X_MAX_ACCELERATORS; i++) { 59 - if (self->accel_mask & (1 << i)) 60 - ctr++; 61 - } 62 - return ctr; 63 - } 64 - 65 - static u32 get_num_aes(struct adf_hw_device_data *self) 66 - { 67 - u32 i, ctr = 0; 68 - 69 - if (!self || !self->ae_mask) 70 - return 0; 71 - 72 - for (i = 0; i < ADF_C62X_MAX_ACCELENGINES; i++) { 73 - if (self->ae_mask & (1 << i)) 74 - ctr++; 75 - } 76 - return ctr; 77 - } 78 - 79 51 static u32 get_misc_bar_id(struct adf_hw_device_data *self) 80 52 { 81 53 return ADF_C62X_PMISC_BAR; ··· 65 93 66 94 static enum dev_sku_info get_sku(struct adf_hw_device_data *self) 67 95 { 68 - int aes = get_num_aes(self); 96 + int aes = self->get_num_aes(self); 69 97 70 98 if (aes == 8) 71 99 return DEV_SKU_2; ··· 80 108 return thrd_to_arb_map; 81 109 } 82 110 83 - static u32 get_pf2vf_offset(u32 i) 84 - { 85 - return ADF_C62X_PF2VF_OFFSET(i); 86 - } 87 - 88 - static void adf_enable_error_correction(struct adf_accel_dev *accel_dev) 89 - { 90 - struct adf_hw_device_data *hw_device = accel_dev->hw_device; 91 - struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR]; 92 - unsigned long accel_mask = hw_device->accel_mask; 93 - unsigned long ae_mask = hw_device->ae_mask; 94 - void __iomem *csr = misc_bar->virt_addr; 95 - unsigned int val, i; 96 - 97 - /* Enable Accel Engine error detection & correction */ 98 - for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 99 - val = ADF_CSR_RD(csr, ADF_C62X_AE_CTX_ENABLES(i)); 100 - val |= ADF_C62X_ENABLE_AE_ECC_ERR; 101 - ADF_CSR_WR(csr, ADF_C62X_AE_CTX_ENABLES(i), val); 102 - val = ADF_CSR_RD(csr, ADF_C62X_AE_MISC_CONTROL(i)); 103 - val |= ADF_C62X_ENABLE_AE_ECC_PARITY_CORR; 104 - ADF_CSR_WR(csr, ADF_C62X_AE_MISC_CONTROL(i), val); 105 - } 106 - 107 - /* Enable shared memory error detection & correction */ 108 - for_each_set_bit(i, &accel_mask, ADF_C62X_MAX_ACCELERATORS) { 109 - val = ADF_CSR_RD(csr, ADF_C62X_UERRSSMSH(i)); 110 - val |= ADF_C62X_ERRSSMSH_EN; 111 - ADF_CSR_WR(csr, ADF_C62X_UERRSSMSH(i), val); 112 - val = ADF_CSR_RD(csr, ADF_C62X_CERRSSMSH(i)); 113 - val |= ADF_C62X_ERRSSMSH_EN; 114 - ADF_CSR_WR(csr, ADF_C62X_CERRSSMSH(i), val); 115 - } 116 - } 117 - 118 111 static void adf_enable_ints(struct adf_accel_dev *accel_dev) 119 112 { 120 113 void __iomem *addr; ··· 91 154 ADF_C62X_SMIA0_MASK); 92 155 ADF_CSR_WR(addr, ADF_C62X_SMIAPF1_MASK_OFFSET, 93 156 ADF_C62X_SMIA1_MASK); 94 - } 95 - 96 - static int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 97 - { 98 - spin_lock_init(&accel_dev->pf.vf2pf_ints_lock); 99 - 100 - return 0; 101 157 } 102 158 103 159 static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) ··· 109 179 hw_data->num_accel = ADF_C62X_MAX_ACCELERATORS; 110 180 hw_data->num_logical_accel = 1; 111 181 hw_data->num_engines = ADF_C62X_MAX_ACCELENGINES; 112 - hw_data->tx_rx_gap = ADF_C62X_RX_RINGS_OFFSET; 113 - hw_data->tx_rings_mask = ADF_C62X_TX_RINGS_MASK; 182 + hw_data->tx_rx_gap = ADF_GEN2_RX_RINGS_OFFSET; 183 + hw_data->tx_rings_mask = ADF_GEN2_TX_RINGS_MASK; 114 184 hw_data->alloc_irq = adf_isr_resource_alloc; 115 185 hw_data->free_irq = adf_isr_resource_free; 116 - hw_data->enable_error_correction = adf_enable_error_correction; 186 + hw_data->enable_error_correction = adf_gen2_enable_error_correction; 117 187 hw_data->get_accel_mask = get_accel_mask; 118 188 hw_data->get_ae_mask = get_ae_mask; 119 189 hw_data->get_accel_cap = adf_gen2_get_accel_cap; 120 - hw_data->get_num_accels = get_num_accels; 121 - hw_data->get_num_aes = get_num_aes; 190 + hw_data->get_num_accels = adf_gen2_get_num_accels; 191 + hw_data->get_num_aes = adf_gen2_get_num_aes; 122 192 hw_data->get_sram_bar_id = get_sram_bar_id; 123 193 hw_data->get_etr_bar_id = get_etr_bar_id; 124 194 hw_data->get_misc_bar_id = get_misc_bar_id; ··· 137 207 hw_data->enable_ints = adf_enable_ints; 138 208 hw_data->reset_device = adf_reset_flr; 139 209 hw_data->set_ssm_wdtimer = adf_gen2_set_ssm_wdtimer; 140 - hw_data->get_pf2vf_offset = get_pf2vf_offset; 210 + hw_data->get_pf2vf_offset = adf_gen2_get_pf2vf_offset; 211 + hw_data->get_vf2pf_sources = adf_gen2_get_vf2pf_sources; 212 + hw_data->enable_vf2pf_interrupts = adf_gen2_enable_vf2pf_interrupts; 213 + hw_data->disable_vf2pf_interrupts = adf_gen2_disable_vf2pf_interrupts; 141 214 hw_data->enable_pfvf_comms = adf_enable_pf2vf_comms; 142 215 hw_data->disable_iov = adf_disable_sriov; 143 216 hw_data->min_iov_compat_ver = ADF_PFVF_COMPAT_THIS_VERSION;
-12
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h
··· 7 7 #define ADF_C62X_SRAM_BAR 0 8 8 #define ADF_C62X_PMISC_BAR 1 9 9 #define ADF_C62X_ETR_BAR 2 10 - #define ADF_C62X_RX_RINGS_OFFSET 8 11 - #define ADF_C62X_TX_RINGS_MASK 0xFF 12 10 #define ADF_C62X_MAX_ACCELERATORS 5 13 11 #define ADF_C62X_MAX_ACCELENGINES 10 14 12 #define ADF_C62X_ACCELERATORS_REG_OFFSET 16 ··· 18 20 #define ADF_C62X_SMIA0_MASK 0xFFFF 19 21 #define ADF_C62X_SMIA1_MASK 0x1 20 22 #define ADF_C62X_SOFTSTRAP_CSR_OFFSET 0x2EC 21 - /* Error detection and correction */ 22 - #define ADF_C62X_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818) 23 - #define ADF_C62X_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960) 24 - #define ADF_C62X_ENABLE_AE_ECC_ERR BIT(28) 25 - #define ADF_C62X_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12)) 26 - #define ADF_C62X_UERRSSMSH(i) (i * 0x4000 + 0x18) 27 - #define ADF_C62X_CERRSSMSH(i) (i * 0x4000 + 0x10) 28 - #define ADF_C62X_ERRSSMSH_EN BIT(3) 29 - 30 - #define ADF_C62X_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 31 23 32 24 /* AE to function mapping */ 33 25 #define ADF_C62X_AE2FUNC_MAP_GRP_A_NUM_REGS 80
+20 -9
drivers/crypto/qat/qat_common/adf_accel_devices.h
··· 42 42 resource_size_t base_addr; 43 43 void __iomem *virt_addr; 44 44 resource_size_t size; 45 - } __packed; 45 + }; 46 + 47 + struct adf_irq { 48 + bool enabled; 49 + char name[ADF_MAX_MSIX_VECTOR_NAME]; 50 + }; 46 51 47 52 struct adf_accel_msix { 48 - struct msix_entry *entries; 49 - char **names; 53 + struct adf_irq *irqs; 50 54 u32 num_entries; 51 - } __packed; 55 + }; 52 56 53 57 struct adf_accel_pci { 54 58 struct pci_dev *pci_dev; ··· 60 56 struct adf_bar pci_bars[ADF_PCI_MAX_BARS]; 61 57 u8 revid; 62 58 u8 sku; 63 - } __packed; 59 + }; 64 60 65 61 enum dev_state { 66 62 DEV_DOWN = 0, ··· 100 96 const char *name; 101 97 const enum adf_device_type type; 102 98 u32 instances; 103 - } __packed; 99 + }; 104 100 105 101 struct arb_info { 106 102 u32 arb_cfg; ··· 170 166 int (*init_arb)(struct adf_accel_dev *accel_dev); 171 167 void (*exit_arb)(struct adf_accel_dev *accel_dev); 172 168 const u32 *(*get_arb_mapping)(void); 169 + int (*init_device)(struct adf_accel_dev *accel_dev); 173 170 void (*disable_iov)(struct adf_accel_dev *accel_dev); 174 171 void (*configure_iov_threads)(struct adf_accel_dev *accel_dev, 175 172 bool enable); 176 173 void (*enable_ints)(struct adf_accel_dev *accel_dev); 177 174 void (*set_ssm_wdtimer)(struct adf_accel_dev *accel_dev); 178 175 int (*enable_pfvf_comms)(struct adf_accel_dev *accel_dev); 176 + u32 (*get_vf2pf_sources)(void __iomem *pmisc_addr); 177 + void (*enable_vf2pf_interrupts)(void __iomem *pmisc_bar_addr, 178 + u32 vf_mask); 179 + void (*disable_vf2pf_interrupts)(void __iomem *pmisc_bar_addr, 180 + u32 vf_mask); 179 181 void (*reset_device)(struct adf_accel_dev *accel_dev); 180 182 void (*set_msix_rttable)(struct adf_accel_dev *accel_dev); 181 183 char *(*uof_get_name)(u32 obj_num); ··· 205 195 u8 num_logical_accel; 206 196 u8 num_engines; 207 197 u8 min_iov_compat_ver; 208 - } __packed; 198 + }; 209 199 210 200 /* CSR write macro */ 211 201 #define ADF_CSR_WR(csr_base, csr_offset, val) \ ··· 261 251 struct adf_accel_vf_info *vf_info; 262 252 } pf; 263 253 struct { 264 - char *irq_name; 254 + bool irq_enabled; 255 + char irq_name[ADF_MAX_MSIX_VECTOR_NAME]; 265 256 struct tasklet_struct pf2vf_bh_tasklet; 266 257 struct mutex vf2pf_lock; /* protect CSR access */ 267 258 struct completion iov_msg_completion; ··· 272 261 }; 273 262 bool is_vf; 274 263 u32 accel_id; 275 - } __packed; 264 + }; 276 265 #endif
+7 -2
drivers/crypto/qat/qat_common/adf_common_drv.h
··· 62 62 void adf_dev_stop(struct adf_accel_dev *accel_dev); 63 63 void adf_dev_shutdown(struct adf_accel_dev *accel_dev); 64 64 65 - int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr); 66 65 void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev); 67 66 int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev); 68 67 void adf_vf2pf_req_hndl(struct adf_accel_vf_info *vf_info); ··· 196 197 u32 vf_mask); 197 198 void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, 198 199 u32 vf_mask); 200 + int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev); 199 201 void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev); 200 202 void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev); 201 203 void adf_schedule_vf2pf_handler(struct adf_accel_vf_info *vf_info); 202 - 204 + int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg); 203 205 int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev); 204 206 void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev); 205 207 int adf_init_pf_wq(void); ··· 210 210 void adf_flush_vf_wq(struct adf_accel_dev *accel_dev); 211 211 #else 212 212 #define adf_sriov_configure NULL 213 + 214 + static inline int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 215 + { 216 + return 0; 217 + } 213 218 214 219 static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev) 215 220 {
+98
drivers/crypto/qat/qat_common/adf_gen2_hw_data.c
··· 4 4 #include "icp_qat_hw.h" 5 5 #include <linux/pci.h> 6 6 7 + #define ADF_GEN2_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 8 + 9 + u32 adf_gen2_get_pf2vf_offset(u32 i) 10 + { 11 + return ADF_GEN2_PF2VF_OFFSET(i); 12 + } 13 + EXPORT_SYMBOL_GPL(adf_gen2_get_pf2vf_offset); 14 + 15 + u32 adf_gen2_get_vf2pf_sources(void __iomem *pmisc_addr) 16 + { 17 + u32 errsou3, errmsk3, vf_int_mask; 18 + 19 + /* Get the interrupt sources triggered by VFs */ 20 + errsou3 = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRSOU3); 21 + vf_int_mask = ADF_GEN2_ERR_REG_VF2PF(errsou3); 22 + 23 + /* To avoid adding duplicate entries to work queue, clear 24 + * vf_int_mask_sets bits that are already masked in ERRMSK register. 25 + */ 26 + errmsk3 = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRMSK3); 27 + vf_int_mask &= ~ADF_GEN2_ERR_REG_VF2PF(errmsk3); 28 + 29 + return vf_int_mask; 30 + } 31 + EXPORT_SYMBOL_GPL(adf_gen2_get_vf2pf_sources); 32 + 33 + void adf_gen2_enable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask) 34 + { 35 + /* Enable VF2PF Messaging Ints - VFs 0 through 15 per vf_mask[15:0] */ 36 + if (vf_mask & 0xFFFF) { 37 + u32 val = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRMSK3) 38 + & ~ADF_GEN2_ERR_MSK_VF2PF(vf_mask); 39 + ADF_CSR_WR(pmisc_addr, ADF_GEN2_ERRMSK3, val); 40 + } 41 + } 42 + EXPORT_SYMBOL_GPL(adf_gen2_enable_vf2pf_interrupts); 43 + 44 + void adf_gen2_disable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask) 45 + { 46 + /* Disable VF2PF interrupts for VFs 0 through 15 per vf_mask[15:0] */ 47 + if (vf_mask & 0xFFFF) { 48 + u32 val = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRMSK3) 49 + | ADF_GEN2_ERR_MSK_VF2PF(vf_mask); 50 + ADF_CSR_WR(pmisc_addr, ADF_GEN2_ERRMSK3, val); 51 + } 52 + } 53 + EXPORT_SYMBOL_GPL(adf_gen2_disable_vf2pf_interrupts); 54 + 55 + u32 adf_gen2_get_num_accels(struct adf_hw_device_data *self) 56 + { 57 + if (!self || !self->accel_mask) 58 + return 0; 59 + 60 + return hweight16(self->accel_mask); 61 + } 62 + EXPORT_SYMBOL_GPL(adf_gen2_get_num_accels); 63 + 64 + u32 adf_gen2_get_num_aes(struct adf_hw_device_data *self) 65 + { 66 + if (!self || !self->ae_mask) 67 + return 0; 68 + 69 + return hweight32(self->ae_mask); 70 + } 71 + EXPORT_SYMBOL_GPL(adf_gen2_get_num_aes); 72 + 73 + void adf_gen2_enable_error_correction(struct adf_accel_dev *accel_dev) 74 + { 75 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 76 + struct adf_bar *misc_bar = &GET_BARS(accel_dev) 77 + [hw_data->get_misc_bar_id(hw_data)]; 78 + unsigned long accel_mask = hw_data->accel_mask; 79 + unsigned long ae_mask = hw_data->ae_mask; 80 + void __iomem *csr = misc_bar->virt_addr; 81 + unsigned int val, i; 82 + 83 + /* Enable Accel Engine error detection & correction */ 84 + for_each_set_bit(i, &ae_mask, hw_data->num_engines) { 85 + val = ADF_CSR_RD(csr, ADF_GEN2_AE_CTX_ENABLES(i)); 86 + val |= ADF_GEN2_ENABLE_AE_ECC_ERR; 87 + ADF_CSR_WR(csr, ADF_GEN2_AE_CTX_ENABLES(i), val); 88 + val = ADF_CSR_RD(csr, ADF_GEN2_AE_MISC_CONTROL(i)); 89 + val |= ADF_GEN2_ENABLE_AE_ECC_PARITY_CORR; 90 + ADF_CSR_WR(csr, ADF_GEN2_AE_MISC_CONTROL(i), val); 91 + } 92 + 93 + /* Enable shared memory error detection & correction */ 94 + for_each_set_bit(i, &accel_mask, hw_data->num_accel) { 95 + val = ADF_CSR_RD(csr, ADF_GEN2_UERRSSMSH(i)); 96 + val |= ADF_GEN2_ERRSSMSH_EN; 97 + ADF_CSR_WR(csr, ADF_GEN2_UERRSSMSH(i), val); 98 + val = ADF_CSR_RD(csr, ADF_GEN2_CERRSSMSH(i)); 99 + val |= ADF_GEN2_ERRSSMSH_EN; 100 + ADF_CSR_WR(csr, ADF_GEN2_CERRSSMSH(i), val); 101 + } 102 + } 103 + EXPORT_SYMBOL_GPL(adf_gen2_enable_error_correction); 104 + 7 105 void adf_gen2_cfg_iov_thds(struct adf_accel_dev *accel_dev, bool enable, 8 106 int num_a_regs, int num_b_regs) 9 107 {
+27
drivers/crypto/qat/qat_common/adf_gen2_hw_data.h
··· 22 22 #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184 23 23 #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000 24 24 #define ADF_RING_BUNDLE_SIZE 0x1000 25 + #define ADF_GEN2_RX_RINGS_OFFSET 8 26 + #define ADF_GEN2_TX_RINGS_MASK 0xFF 25 27 26 28 #define BUILD_RING_BASE_ADDR(addr, size) \ 27 29 (((addr) >> 6) & (GENMASK_ULL(63, 0) << (size))) ··· 127 125 #define ADF_SSMWDT(i) (ADF_SSMWDT_OFFSET + ((i) * 0x4000)) 128 126 #define ADF_SSMWDTPKE(i) (ADF_SSMWDTPKE_OFFSET + ((i) * 0x4000)) 129 127 128 + /* Error detection and correction */ 129 + #define ADF_GEN2_AE_CTX_ENABLES(i) ((i) * 0x1000 + 0x20818) 130 + #define ADF_GEN2_AE_MISC_CONTROL(i) ((i) * 0x1000 + 0x20960) 131 + #define ADF_GEN2_ENABLE_AE_ECC_ERR BIT(28) 132 + #define ADF_GEN2_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12)) 133 + #define ADF_GEN2_UERRSSMSH(i) ((i) * 0x4000 + 0x18) 134 + #define ADF_GEN2_CERRSSMSH(i) ((i) * 0x4000 + 0x10) 135 + #define ADF_GEN2_ERRSSMSH_EN BIT(3) 136 + 137 + /* VF2PF interrupts */ 138 + #define ADF_GEN2_ERRSOU3 (0x3A000 + 0x0C) 139 + #define ADF_GEN2_ERRSOU5 (0x3A000 + 0xD8) 140 + #define ADF_GEN2_ERRMSK3 (0x3A000 + 0x1C) 141 + #define ADF_GEN2_ERRMSK5 (0x3A000 + 0xDC) 142 + #define ADF_GEN2_ERR_REG_VF2PF(vf_src) (((vf_src) & 0x01FFFE00) >> 9) 143 + #define ADF_GEN2_ERR_MSK_VF2PF(vf_mask) (((vf_mask) & 0xFFFF) << 9) 144 + 145 + u32 adf_gen2_get_pf2vf_offset(u32 i); 146 + u32 adf_gen2_get_vf2pf_sources(void __iomem *pmisc_bar); 147 + void adf_gen2_enable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask); 148 + void adf_gen2_disable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask); 149 + 150 + u32 adf_gen2_get_num_accels(struct adf_hw_device_data *self); 151 + u32 adf_gen2_get_num_aes(struct adf_hw_device_data *self); 152 + void adf_gen2_enable_error_correction(struct adf_accel_dev *accel_dev); 130 153 void adf_gen2_cfg_iov_thds(struct adf_accel_dev *accel_dev, bool enable, 131 154 int num_a_regs, int num_b_regs); 132 155 void adf_gen2_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops);
+5
drivers/crypto/qat/qat_common/adf_init.c
··· 79 79 return -EFAULT; 80 80 } 81 81 82 + if (hw_data->init_device && hw_data->init_device(accel_dev)) { 83 + dev_err(&GET_DEV(accel_dev), "Failed to initialize device\n"); 84 + return -EFAULT; 85 + } 86 + 82 87 if (hw_data->init_admin_comms && hw_data->init_admin_comms(accel_dev)) { 83 88 dev_err(&GET_DEV(accel_dev), "Failed initialize admin comms\n"); 84 89 return -EFAULT;
+83 -107
drivers/crypto/qat/qat_common/adf_isr.c
··· 16 16 #include "adf_transport_internal.h" 17 17 18 18 #define ADF_MAX_NUM_VFS 32 19 - #define ADF_ERRSOU3 (0x3A000 + 0x0C) 20 - #define ADF_ERRSOU5 (0x3A000 + 0xD8) 21 - #define ADF_ERRMSK3 (0x3A000 + 0x1C) 22 - #define ADF_ERRMSK5 (0x3A000 + 0xDC) 23 - #define ADF_ERR_REG_VF2PF_L(vf_src) (((vf_src) & 0x01FFFE00) >> 9) 24 - #define ADF_ERR_REG_VF2PF_U(vf_src) (((vf_src) & 0x0000FFFF) << 16) 25 19 26 20 static int adf_enable_msix(struct adf_accel_dev *accel_dev) 27 21 { 28 22 struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev; 29 23 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 30 - u32 msix_num_entries = 1; 24 + u32 msix_num_entries = hw_data->num_banks + 1; 25 + int ret; 31 26 32 27 if (hw_data->set_msix_rttable) 33 28 hw_data->set_msix_rttable(accel_dev); 34 29 35 - /* If SR-IOV is disabled, add entries for each bank */ 36 - if (!accel_dev->pf.vf_info) { 37 - int i; 38 - 39 - msix_num_entries += hw_data->num_banks; 40 - for (i = 0; i < msix_num_entries; i++) 41 - pci_dev_info->msix_entries.entries[i].entry = i; 42 - } else { 43 - pci_dev_info->msix_entries.entries[0].entry = 44 - hw_data->num_banks; 45 - } 46 - 47 - if (pci_enable_msix_exact(pci_dev_info->pci_dev, 48 - pci_dev_info->msix_entries.entries, 49 - msix_num_entries)) { 50 - dev_err(&GET_DEV(accel_dev), "Failed to enable MSI-X IRQ(s)\n"); 51 - return -EFAULT; 30 + ret = pci_alloc_irq_vectors(pci_dev_info->pci_dev, msix_num_entries, 31 + msix_num_entries, PCI_IRQ_MSIX); 32 + if (unlikely(ret < 0)) { 33 + dev_err(&GET_DEV(accel_dev), 34 + "Failed to allocate %d MSI-X vectors\n", 35 + msix_num_entries); 36 + return ret; 52 37 } 53 38 return 0; 54 39 } 55 40 56 41 static void adf_disable_msix(struct adf_accel_pci *pci_dev_info) 57 42 { 58 - pci_disable_msix(pci_dev_info->pci_dev); 43 + pci_free_irq_vectors(pci_dev_info->pci_dev); 59 44 } 60 45 61 46 static irqreturn_t adf_msix_isr_bundle(int irq, void *bank_ptr) ··· 65 80 struct adf_bar *pmisc = 66 81 &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 67 82 void __iomem *pmisc_addr = pmisc->virt_addr; 68 - u32 errsou3, errsou5, errmsk3, errmsk5; 69 83 unsigned long vf_mask; 70 84 71 85 /* Get the interrupt sources triggered by VFs */ 72 - errsou3 = ADF_CSR_RD(pmisc_addr, ADF_ERRSOU3); 73 - errsou5 = ADF_CSR_RD(pmisc_addr, ADF_ERRSOU5); 74 - vf_mask = ADF_ERR_REG_VF2PF_L(errsou3); 75 - vf_mask |= ADF_ERR_REG_VF2PF_U(errsou5); 76 - 77 - /* To avoid adding duplicate entries to work queue, clear 78 - * vf_int_mask_sets bits that are already masked in ERRMSK register. 79 - */ 80 - errmsk3 = ADF_CSR_RD(pmisc_addr, ADF_ERRMSK3); 81 - errmsk5 = ADF_CSR_RD(pmisc_addr, ADF_ERRMSK5); 82 - vf_mask &= ~ADF_ERR_REG_VF2PF_L(errmsk3); 83 - vf_mask &= ~ADF_ERR_REG_VF2PF_U(errmsk5); 86 + vf_mask = hw_data->get_vf2pf_sources(pmisc_addr); 84 87 85 88 if (vf_mask) { 86 89 struct adf_accel_vf_info *vf_info; ··· 108 135 return IRQ_NONE; 109 136 } 110 137 138 + static void adf_free_irqs(struct adf_accel_dev *accel_dev) 139 + { 140 + struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev; 141 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 142 + struct adf_irq *irqs = pci_dev_info->msix_entries.irqs; 143 + struct adf_etr_data *etr_data = accel_dev->transport; 144 + int clust_irq = hw_data->num_banks; 145 + int irq, i = 0; 146 + 147 + if (pci_dev_info->msix_entries.num_entries > 1) { 148 + for (i = 0; i < hw_data->num_banks; i++) { 149 + if (irqs[i].enabled) { 150 + irq = pci_irq_vector(pci_dev_info->pci_dev, i); 151 + irq_set_affinity_hint(irq, NULL); 152 + free_irq(irq, &etr_data->banks[i]); 153 + } 154 + } 155 + } 156 + 157 + if (irqs[i].enabled) { 158 + irq = pci_irq_vector(pci_dev_info->pci_dev, clust_irq); 159 + free_irq(irq, accel_dev); 160 + } 161 + } 162 + 111 163 static int adf_request_irqs(struct adf_accel_dev *accel_dev) 112 164 { 113 165 struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev; 114 166 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 115 - struct msix_entry *msixe = pci_dev_info->msix_entries.entries; 167 + struct adf_irq *irqs = pci_dev_info->msix_entries.irqs; 116 168 struct adf_etr_data *etr_data = accel_dev->transport; 117 - int ret, i = 0; 169 + int clust_irq = hw_data->num_banks; 170 + int ret, irq, i = 0; 118 171 char *name; 119 172 120 173 /* Request msix irq for all banks unless SR-IOV enabled */ ··· 149 150 struct adf_etr_bank_data *bank = &etr_data->banks[i]; 150 151 unsigned int cpu, cpus = num_online_cpus(); 151 152 152 - name = *(pci_dev_info->msix_entries.names + i); 153 + name = irqs[i].name; 153 154 snprintf(name, ADF_MAX_MSIX_VECTOR_NAME, 154 155 "qat%d-bundle%d", accel_dev->accel_id, i); 155 - ret = request_irq(msixe[i].vector, 156 - adf_msix_isr_bundle, 0, name, bank); 156 + irq = pci_irq_vector(pci_dev_info->pci_dev, i); 157 + if (unlikely(irq < 0)) { 158 + dev_err(&GET_DEV(accel_dev), 159 + "Failed to get IRQ number of device vector %d - %s\n", 160 + i, name); 161 + ret = irq; 162 + goto err; 163 + } 164 + ret = request_irq(irq, adf_msix_isr_bundle, 0, 165 + &name[0], bank); 157 166 if (ret) { 158 167 dev_err(&GET_DEV(accel_dev), 159 - "failed to enable irq %d for %s\n", 160 - msixe[i].vector, name); 161 - return ret; 168 + "Failed to allocate IRQ %d for %s\n", 169 + irq, name); 170 + goto err; 162 171 } 163 172 164 173 cpu = ((accel_dev->accel_id * hw_data->num_banks) + 165 174 i) % cpus; 166 - irq_set_affinity_hint(msixe[i].vector, 167 - get_cpu_mask(cpu)); 175 + irq_set_affinity_hint(irq, get_cpu_mask(cpu)); 176 + irqs[i].enabled = true; 168 177 } 169 178 } 170 179 171 180 /* Request msix irq for AE */ 172 - name = *(pci_dev_info->msix_entries.names + i); 181 + name = irqs[i].name; 173 182 snprintf(name, ADF_MAX_MSIX_VECTOR_NAME, 174 183 "qat%d-ae-cluster", accel_dev->accel_id); 175 - ret = request_irq(msixe[i].vector, adf_msix_isr_ae, 0, name, accel_dev); 184 + irq = pci_irq_vector(pci_dev_info->pci_dev, clust_irq); 185 + if (unlikely(irq < 0)) { 186 + dev_err(&GET_DEV(accel_dev), 187 + "Failed to get IRQ number of device vector %d - %s\n", 188 + i, name); 189 + ret = irq; 190 + goto err; 191 + } 192 + ret = request_irq(irq, adf_msix_isr_ae, 0, &name[0], accel_dev); 176 193 if (ret) { 177 194 dev_err(&GET_DEV(accel_dev), 178 - "failed to enable irq %d, for %s\n", 179 - msixe[i].vector, name); 180 - return ret; 195 + "Failed to allocate IRQ %d for %s\n", irq, name); 196 + goto err; 181 197 } 198 + irqs[i].enabled = true; 199 + return ret; 200 + err: 201 + adf_free_irqs(accel_dev); 182 202 return ret; 183 203 } 184 204 185 - static void adf_free_irqs(struct adf_accel_dev *accel_dev) 205 + static int adf_isr_alloc_msix_vectors_data(struct adf_accel_dev *accel_dev) 186 206 { 187 - struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev; 188 - struct adf_hw_device_data *hw_data = accel_dev->hw_device; 189 - struct msix_entry *msixe = pci_dev_info->msix_entries.entries; 190 - struct adf_etr_data *etr_data = accel_dev->transport; 191 - int i = 0; 192 - 193 - if (pci_dev_info->msix_entries.num_entries > 1) { 194 - for (i = 0; i < hw_data->num_banks; i++) { 195 - irq_set_affinity_hint(msixe[i].vector, NULL); 196 - free_irq(msixe[i].vector, &etr_data->banks[i]); 197 - } 198 - } 199 - irq_set_affinity_hint(msixe[i].vector, NULL); 200 - free_irq(msixe[i].vector, accel_dev); 201 - } 202 - 203 - static int adf_isr_alloc_msix_entry_table(struct adf_accel_dev *accel_dev) 204 - { 205 - int i; 206 - char **names; 207 - struct msix_entry *entries; 208 207 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 209 208 u32 msix_num_entries = 1; 209 + struct adf_irq *irqs; 210 210 211 211 /* If SR-IOV is disabled (vf_info is NULL), add entries for each bank */ 212 212 if (!accel_dev->pf.vf_info) 213 213 msix_num_entries += hw_data->num_banks; 214 214 215 - entries = kcalloc_node(msix_num_entries, sizeof(*entries), 216 - GFP_KERNEL, dev_to_node(&GET_DEV(accel_dev))); 217 - if (!entries) 215 + irqs = kzalloc_node(msix_num_entries * sizeof(*irqs), 216 + GFP_KERNEL, dev_to_node(&GET_DEV(accel_dev))); 217 + if (!irqs) 218 218 return -ENOMEM; 219 219 220 - names = kcalloc(msix_num_entries, sizeof(char *), GFP_KERNEL); 221 - if (!names) { 222 - kfree(entries); 223 - return -ENOMEM; 224 - } 225 - for (i = 0; i < msix_num_entries; i++) { 226 - *(names + i) = kzalloc(ADF_MAX_MSIX_VECTOR_NAME, GFP_KERNEL); 227 - if (!(*(names + i))) 228 - goto err; 229 - } 230 220 accel_dev->accel_pci_dev.msix_entries.num_entries = msix_num_entries; 231 - accel_dev->accel_pci_dev.msix_entries.entries = entries; 232 - accel_dev->accel_pci_dev.msix_entries.names = names; 221 + accel_dev->accel_pci_dev.msix_entries.irqs = irqs; 233 222 return 0; 234 - err: 235 - for (i = 0; i < msix_num_entries; i++) 236 - kfree(*(names + i)); 237 - kfree(entries); 238 - kfree(names); 239 - return -ENOMEM; 240 223 } 241 224 242 - static void adf_isr_free_msix_entry_table(struct adf_accel_dev *accel_dev) 225 + static void adf_isr_free_msix_vectors_data(struct adf_accel_dev *accel_dev) 243 226 { 244 - char **names = accel_dev->accel_pci_dev.msix_entries.names; 245 - int i; 246 - 247 - kfree(accel_dev->accel_pci_dev.msix_entries.entries); 248 - for (i = 0; i < accel_dev->accel_pci_dev.msix_entries.num_entries; i++) 249 - kfree(*(names + i)); 250 - kfree(names); 227 + kfree(accel_dev->accel_pci_dev.msix_entries.irqs); 228 + accel_dev->accel_pci_dev.msix_entries.irqs = NULL; 251 229 } 252 230 253 231 static int adf_setup_bh(struct adf_accel_dev *accel_dev) ··· 263 287 adf_free_irqs(accel_dev); 264 288 adf_cleanup_bh(accel_dev); 265 289 adf_disable_msix(&accel_dev->accel_pci_dev); 266 - adf_isr_free_msix_entry_table(accel_dev); 290 + adf_isr_free_msix_vectors_data(accel_dev); 267 291 } 268 292 EXPORT_SYMBOL_GPL(adf_isr_resource_free); 269 293 ··· 279 303 { 280 304 int ret; 281 305 282 - ret = adf_isr_alloc_msix_entry_table(accel_dev); 306 + ret = adf_isr_alloc_msix_vectors_data(accel_dev); 283 307 if (ret) 284 308 goto err_out; 285 309 ··· 304 328 adf_disable_msix(&accel_dev->accel_pci_dev); 305 329 306 330 err_free_msix_table: 307 - adf_isr_free_msix_entry_table(accel_dev); 331 + adf_isr_free_msix_vectors_data(accel_dev); 308 332 309 333 err_out: 310 334 return ret;
+138 -102
drivers/crypto/qat/qat_common/adf_pf2vf_msg.c
··· 5 5 #include "adf_common_drv.h" 6 6 #include "adf_pf2vf_msg.h" 7 7 8 - #define ADF_DH895XCC_EP_OFFSET 0x3A000 9 - #define ADF_DH895XCC_ERRMSK3 (ADF_DH895XCC_EP_OFFSET + 0x1C) 10 - #define ADF_DH895XCC_ERRMSK3_VF2PF_L_MASK(vf_mask) ((vf_mask & 0xFFFF) << 9) 11 - #define ADF_DH895XCC_ERRMSK5 (ADF_DH895XCC_EP_OFFSET + 0xDC) 12 - #define ADF_DH895XCC_ERRMSK5_VF2PF_U_MASK(vf_mask) (vf_mask >> 16) 13 - 14 - static void __adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, 15 - u32 vf_mask) 16 - { 17 - struct adf_hw_device_data *hw_data = accel_dev->hw_device; 18 - struct adf_bar *pmisc = 19 - &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 20 - void __iomem *pmisc_addr = pmisc->virt_addr; 21 - u32 reg; 22 - 23 - /* Enable VF2PF Messaging Ints - VFs 1 through 16 per vf_mask[15:0] */ 24 - if (vf_mask & 0xFFFF) { 25 - reg = ADF_CSR_RD(pmisc_addr, ADF_DH895XCC_ERRMSK3); 26 - reg &= ~ADF_DH895XCC_ERRMSK3_VF2PF_L_MASK(vf_mask); 27 - ADF_CSR_WR(pmisc_addr, ADF_DH895XCC_ERRMSK3, reg); 28 - } 29 - 30 - /* Enable VF2PF Messaging Ints - VFs 17 through 32 per vf_mask[31:16] */ 31 - if (vf_mask >> 16) { 32 - reg = ADF_CSR_RD(pmisc_addr, ADF_DH895XCC_ERRMSK5); 33 - reg &= ~ADF_DH895XCC_ERRMSK5_VF2PF_U_MASK(vf_mask); 34 - ADF_CSR_WR(pmisc_addr, ADF_DH895XCC_ERRMSK5, reg); 35 - } 36 - } 8 + #define ADF_PFVF_MSG_COLLISION_DETECT_DELAY 10 9 + #define ADF_PFVF_MSG_ACK_DELAY 2 10 + #define ADF_PFVF_MSG_ACK_MAX_RETRY 100 11 + #define ADF_PFVF_MSG_RETRY_DELAY 5 12 + #define ADF_PFVF_MSG_MAX_RETRIES 3 13 + #define ADF_PFVF_MSG_RESP_TIMEOUT (ADF_PFVF_MSG_ACK_DELAY * \ 14 + ADF_PFVF_MSG_ACK_MAX_RETRY + \ 15 + ADF_PFVF_MSG_COLLISION_DETECT_DELAY) 37 16 38 17 void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, u32 vf_mask) 39 18 { 19 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 20 + u32 misc_bar_id = hw_data->get_misc_bar_id(hw_data); 21 + struct adf_bar *pmisc = &GET_BARS(accel_dev)[misc_bar_id]; 22 + void __iomem *pmisc_addr = pmisc->virt_addr; 40 23 unsigned long flags; 41 24 42 25 spin_lock_irqsave(&accel_dev->pf.vf2pf_ints_lock, flags); 43 - __adf_enable_vf2pf_interrupts(accel_dev, vf_mask); 26 + hw_data->enable_vf2pf_interrupts(pmisc_addr, vf_mask); 44 27 spin_unlock_irqrestore(&accel_dev->pf.vf2pf_ints_lock, flags); 45 - } 46 - 47 - static void __adf_disable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, 48 - u32 vf_mask) 49 - { 50 - struct adf_hw_device_data *hw_data = accel_dev->hw_device; 51 - struct adf_bar *pmisc = 52 - &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 53 - void __iomem *pmisc_addr = pmisc->virt_addr; 54 - u32 reg; 55 - 56 - /* Disable VF2PF interrupts for VFs 1 through 16 per vf_mask[15:0] */ 57 - if (vf_mask & 0xFFFF) { 58 - reg = ADF_CSR_RD(pmisc_addr, ADF_DH895XCC_ERRMSK3) | 59 - ADF_DH895XCC_ERRMSK3_VF2PF_L_MASK(vf_mask); 60 - ADF_CSR_WR(pmisc_addr, ADF_DH895XCC_ERRMSK3, reg); 61 - } 62 - 63 - /* Disable VF2PF interrupts for VFs 17 through 32 per vf_mask[31:16] */ 64 - if (vf_mask >> 16) { 65 - reg = ADF_CSR_RD(pmisc_addr, ADF_DH895XCC_ERRMSK5) | 66 - ADF_DH895XCC_ERRMSK5_VF2PF_U_MASK(vf_mask); 67 - ADF_CSR_WR(pmisc_addr, ADF_DH895XCC_ERRMSK5, reg); 68 - } 69 28 } 70 29 71 30 void adf_disable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, u32 vf_mask) 72 31 { 32 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 33 + u32 misc_bar_id = hw_data->get_misc_bar_id(hw_data); 34 + struct adf_bar *pmisc = &GET_BARS(accel_dev)[misc_bar_id]; 35 + void __iomem *pmisc_addr = pmisc->virt_addr; 73 36 unsigned long flags; 74 37 75 38 spin_lock_irqsave(&accel_dev->pf.vf2pf_ints_lock, flags); 76 - __adf_disable_vf2pf_interrupts(accel_dev, vf_mask); 39 + hw_data->disable_vf2pf_interrupts(pmisc_addr, vf_mask); 77 40 spin_unlock_irqrestore(&accel_dev->pf.vf2pf_ints_lock, flags); 78 41 } 79 42 80 - void adf_disable_vf2pf_interrupts_irq(struct adf_accel_dev *accel_dev, u32 vf_mask) 43 + void adf_disable_vf2pf_interrupts_irq(struct adf_accel_dev *accel_dev, 44 + u32 vf_mask) 81 45 { 46 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 47 + u32 misc_bar_id = hw_data->get_misc_bar_id(hw_data); 48 + struct adf_bar *pmisc = &GET_BARS(accel_dev)[misc_bar_id]; 49 + void __iomem *pmisc_addr = pmisc->virt_addr; 50 + 82 51 spin_lock(&accel_dev->pf.vf2pf_ints_lock); 83 - __adf_disable_vf2pf_interrupts(accel_dev, vf_mask); 52 + hw_data->disable_vf2pf_interrupts(pmisc_addr, vf_mask); 84 53 spin_unlock(&accel_dev->pf.vf2pf_ints_lock); 85 54 } 86 55 ··· 86 117 87 118 mutex_lock(lock); 88 119 89 - /* Check if PF2VF CSR is in use by remote function */ 120 + /* Check if the PFVF CSR is in use by remote function */ 90 121 val = ADF_CSR_RD(pmisc_bar_addr, pf2vf_offset); 91 122 if ((val & remote_in_use_mask) == remote_in_use_pattern) { 92 123 dev_dbg(&GET_DEV(accel_dev), 93 - "PF2VF CSR in use by remote function\n"); 124 + "PFVF CSR in use by remote function\n"); 94 125 ret = -EBUSY; 95 126 goto out; 96 127 } 97 128 98 - /* Attempt to get ownership of PF2VF CSR */ 99 129 msg &= ~local_in_use_mask; 100 130 msg |= local_in_use_pattern; 101 - ADF_CSR_WR(pmisc_bar_addr, pf2vf_offset, msg); 102 131 103 - /* Wait in case remote func also attempting to get ownership */ 104 - msleep(ADF_IOV_MSG_COLLISION_DETECT_DELAY); 105 - 106 - val = ADF_CSR_RD(pmisc_bar_addr, pf2vf_offset); 107 - if ((val & local_in_use_mask) != local_in_use_pattern) { 108 - dev_dbg(&GET_DEV(accel_dev), 109 - "PF2VF CSR in use by remote - collision detected\n"); 110 - ret = -EBUSY; 111 - goto out; 112 - } 113 - 114 - /* 115 - * This function now owns the PV2VF CSR. The IN_USE_BY pattern must 116 - * remain in the PF2VF CSR for all writes including ACK from remote 117 - * until this local function relinquishes the CSR. Send the message 118 - * by interrupting the remote. 119 - */ 132 + /* Attempt to get ownership of the PFVF CSR */ 120 133 ADF_CSR_WR(pmisc_bar_addr, pf2vf_offset, msg | int_bit); 121 134 122 135 /* Wait for confirmation from remote func it received the message */ 123 136 do { 124 - msleep(ADF_IOV_MSG_ACK_DELAY); 137 + msleep(ADF_PFVF_MSG_ACK_DELAY); 125 138 val = ADF_CSR_RD(pmisc_bar_addr, pf2vf_offset); 126 - } while ((val & int_bit) && (count++ < ADF_IOV_MSG_ACK_MAX_RETRY)); 139 + } while ((val & int_bit) && (count++ < ADF_PFVF_MSG_ACK_MAX_RETRY)); 140 + 141 + if (val != msg) { 142 + dev_dbg(&GET_DEV(accel_dev), 143 + "Collision - PFVF CSR overwritten by remote function\n"); 144 + ret = -EIO; 145 + goto out; 146 + } 127 147 128 148 if (val & int_bit) { 129 149 dev_dbg(&GET_DEV(accel_dev), "ACK not received from remote\n"); ··· 120 162 ret = -EIO; 121 163 } 122 164 123 - /* Finished with PF2VF CSR; relinquish it and leave msg in CSR */ 165 + /* Finished with the PFVF CSR; relinquish it and leave msg in CSR */ 124 166 ADF_CSR_WR(pmisc_bar_addr, pf2vf_offset, val & ~local_in_use_mask); 125 167 out: 126 168 mutex_unlock(lock); ··· 128 170 } 129 171 130 172 /** 131 - * adf_iov_putmsg() - send PF2VF message 173 + * adf_iov_putmsg() - send PFVF message 132 174 * @accel_dev: Pointer to acceleration device. 133 175 * @msg: Message to send 134 - * @vf_nr: VF number to which the message will be sent 176 + * @vf_nr: VF number to which the message will be sent if on PF, ignored 177 + * otherwise 135 178 * 136 - * Function sends a message from the PF to a VF 179 + * Function sends a message through the PFVF channel 137 180 * 138 181 * Return: 0 on success, error code otherwise. 139 182 */ 140 - int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr) 183 + static int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr) 141 184 { 142 185 u32 count = 0; 143 186 int ret; ··· 146 187 do { 147 188 ret = __adf_iov_putmsg(accel_dev, msg, vf_nr); 148 189 if (ret) 149 - msleep(ADF_IOV_MSG_RETRY_DELAY); 150 - } while (ret && (count++ < ADF_IOV_MSG_MAX_RETRIES)); 190 + msleep(ADF_PFVF_MSG_RETRY_DELAY); 191 + } while (ret && (count++ < ADF_PFVF_MSG_MAX_RETRIES)); 151 192 152 193 return ret; 194 + } 195 + 196 + /** 197 + * adf_send_pf2vf_msg() - send PF to VF message 198 + * @accel_dev: Pointer to acceleration device 199 + * @vf_nr: VF number to which the message will be sent 200 + * @msg: Message to send 201 + * 202 + * This function allows the PF to send a message to a specific VF. 203 + * 204 + * Return: 0 on success, error code otherwise. 205 + */ 206 + static int adf_send_pf2vf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr, u32 msg) 207 + { 208 + return adf_iov_putmsg(accel_dev, msg, vf_nr); 209 + } 210 + 211 + /** 212 + * adf_send_vf2pf_msg() - send VF to PF message 213 + * @accel_dev: Pointer to acceleration device 214 + * @msg: Message to send 215 + * 216 + * This function allows the VF to send a message to the PF. 217 + * 218 + * Return: 0 on success, error code otherwise. 219 + */ 220 + int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg) 221 + { 222 + return adf_iov_putmsg(accel_dev, msg, 0); 223 + } 224 + 225 + /** 226 + * adf_send_vf2pf_req() - send VF2PF request message 227 + * @accel_dev: Pointer to acceleration device. 228 + * @msg: Request message to send 229 + * 230 + * This function sends a message that requires a response from the VF to the PF 231 + * and waits for a reply. 232 + * 233 + * Return: 0 on success, error code otherwise. 234 + */ 235 + static int adf_send_vf2pf_req(struct adf_accel_dev *accel_dev, u32 msg) 236 + { 237 + unsigned long timeout = msecs_to_jiffies(ADF_PFVF_MSG_RESP_TIMEOUT); 238 + int ret; 239 + 240 + reinit_completion(&accel_dev->vf.iov_msg_completion); 241 + 242 + /* Send request from VF to PF */ 243 + ret = adf_send_vf2pf_msg(accel_dev, msg); 244 + if (ret) { 245 + dev_err(&GET_DEV(accel_dev), 246 + "Failed to send request msg to PF\n"); 247 + return ret; 248 + } 249 + 250 + /* Wait for response */ 251 + if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion, 252 + timeout)) { 253 + dev_err(&GET_DEV(accel_dev), 254 + "PFVF request/response message timeout expired\n"); 255 + return -EIO; 256 + } 257 + 258 + return 0; 153 259 } 154 260 155 261 void adf_vf2pf_req_hndl(struct adf_accel_vf_info *vf_info) ··· 228 204 229 205 /* Read message from the VF */ 230 206 msg = ADF_CSR_RD(pmisc_addr, hw_data->get_pf2vf_offset(vf_nr)); 207 + if (!(msg & ADF_VF2PF_INT)) { 208 + dev_info(&GET_DEV(accel_dev), 209 + "Spurious VF2PF interrupt, msg %X. Ignored\n", msg); 210 + goto out; 211 + } 231 212 232 213 /* To ACK, clear the VF2PFINT bit */ 233 214 msg &= ~ADF_VF2PF_INT; ··· 313 284 goto err; 314 285 } 315 286 316 - if (resp && adf_iov_putmsg(accel_dev, resp, vf_nr)) 287 + if (resp && adf_send_pf2vf_msg(accel_dev, vf_nr, resp)) 317 288 dev_err(&GET_DEV(accel_dev), "Failed to send response to VF\n"); 318 289 290 + out: 319 291 /* re-enable interrupt on PF from this VF */ 320 292 adf_enable_vf2pf_interrupts(accel_dev, (1 << vf_nr)); 321 293 ··· 334 304 int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev)); 335 305 336 306 for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) { 337 - if (vf->init && adf_iov_putmsg(accel_dev, msg, i)) 307 + if (vf->init && adf_send_pf2vf_msg(accel_dev, i, msg)) 338 308 dev_err(&GET_DEV(accel_dev), 339 309 "Failed to send restarting msg to VF%d\n", i); 340 310 } ··· 342 312 343 313 static int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev) 344 314 { 345 - unsigned long timeout = msecs_to_jiffies(ADF_IOV_MSG_RESP_TIMEOUT); 346 315 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 347 316 u32 msg = 0; 348 317 int ret; ··· 351 322 msg |= ADF_PFVF_COMPAT_THIS_VERSION << ADF_VF2PF_COMPAT_VER_REQ_SHIFT; 352 323 BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255); 353 324 354 - reinit_completion(&accel_dev->vf.iov_msg_completion); 355 - 356 - /* Send request from VF to PF */ 357 - ret = adf_iov_putmsg(accel_dev, msg, 0); 325 + ret = adf_send_vf2pf_req(accel_dev, msg); 358 326 if (ret) { 359 327 dev_err(&GET_DEV(accel_dev), 360 328 "Failed to send Compatibility Version Request.\n"); 361 329 return ret; 362 - } 363 - 364 - /* Wait for response */ 365 - if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion, 366 - timeout)) { 367 - dev_err(&GET_DEV(accel_dev), 368 - "IOV request/response message timeout expired\n"); 369 - return -EIO; 370 330 } 371 331 372 332 /* Response from PF received, check compatibility */ ··· 396 378 return adf_vf2pf_request_version(accel_dev); 397 379 } 398 380 EXPORT_SYMBOL_GPL(adf_enable_vf2pf_comms); 381 + 382 + /** 383 + * adf_enable_pf2vf_comms() - Function enables communication from pf to vf 384 + * 385 + * @accel_dev: Pointer to acceleration device virtual function. 386 + * 387 + * This function carries out the necessary steps to setup and start the PFVF 388 + * communication channel, if any. 389 + * 390 + * Return: 0 on success, error code otherwise. 391 + */ 392 + int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 393 + { 394 + spin_lock_init(&accel_dev->pf.vf2pf_ints_lock); 395 + 396 + return 0; 397 + } 398 + EXPORT_SYMBOL_GPL(adf_enable_pf2vf_comms);
-9
drivers/crypto/qat/qat_common/adf_pf2vf_msg.h
··· 90 90 /* VF->PF Compatible Version Request */ 91 91 #define ADF_VF2PF_COMPAT_VER_REQ_SHIFT 22 92 92 93 - /* Collision detection */ 94 - #define ADF_IOV_MSG_COLLISION_DETECT_DELAY 10 95 - #define ADF_IOV_MSG_ACK_DELAY 2 96 - #define ADF_IOV_MSG_ACK_MAX_RETRY 100 97 - #define ADF_IOV_MSG_RETRY_DELAY 5 98 - #define ADF_IOV_MSG_MAX_RETRIES 3 99 - #define ADF_IOV_MSG_RESP_TIMEOUT (ADF_IOV_MSG_ACK_DELAY * \ 100 - ADF_IOV_MSG_ACK_MAX_RETRY + \ 101 - ADF_IOV_MSG_COLLISION_DETECT_DELAY) 102 93 #endif /* ADF_IOV_MSG_H */
+2 -2
drivers/crypto/qat/qat_common/adf_vf2pf_msg.c
··· 17 17 u32 msg = (ADF_VF2PF_MSGORIGIN_SYSTEM | 18 18 (ADF_VF2PF_MSGTYPE_INIT << ADF_VF2PF_MSGTYPE_SHIFT)); 19 19 20 - if (adf_iov_putmsg(accel_dev, msg, 0)) { 20 + if (adf_send_vf2pf_msg(accel_dev, msg)) { 21 21 dev_err(&GET_DEV(accel_dev), 22 22 "Failed to send Init event to PF\n"); 23 23 return -EFAULT; ··· 41 41 (ADF_VF2PF_MSGTYPE_SHUTDOWN << ADF_VF2PF_MSGTYPE_SHIFT)); 42 42 43 43 if (test_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status)) 44 - if (adf_iov_putmsg(accel_dev, msg, 0)) 44 + if (adf_send_vf2pf_msg(accel_dev, msg)) 45 45 dev_err(&GET_DEV(accel_dev), 46 46 "Failed to send Shutdown event to PF\n"); 47 47 }
+17 -13
drivers/crypto/qat/qat_common/adf_vf_isr.c
··· 53 53 static int adf_enable_msi(struct adf_accel_dev *accel_dev) 54 54 { 55 55 struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev; 56 - int stat = pci_enable_msi(pci_dev_info->pci_dev); 57 - 58 - if (stat) { 56 + int stat = pci_alloc_irq_vectors(pci_dev_info->pci_dev, 1, 1, 57 + PCI_IRQ_MSI); 58 + if (unlikely(stat < 0)) { 59 59 dev_err(&GET_DEV(accel_dev), 60 - "Failed to enable MSI interrupts\n"); 60 + "Failed to enable MSI interrupt: %d\n", stat); 61 61 return stat; 62 62 } 63 63 64 - accel_dev->vf.irq_name = kzalloc(ADF_MAX_MSIX_VECTOR_NAME, GFP_KERNEL); 65 - if (!accel_dev->vf.irq_name) 66 - return -ENOMEM; 67 - 68 - return stat; 64 + return 0; 69 65 } 70 66 71 67 static void adf_disable_msi(struct adf_accel_dev *accel_dev) 72 68 { 73 69 struct pci_dev *pdev = accel_to_pci_dev(accel_dev); 74 70 75 - kfree(accel_dev->vf.irq_name); 76 - pci_disable_msi(pdev); 71 + pci_free_irq_vectors(pdev); 77 72 } 78 73 79 74 static void adf_dev_stop_async(struct work_struct *work) ··· 96 101 97 102 /* Read the message from PF */ 98 103 msg = ADF_CSR_RD(pmisc_bar_addr, hw_data->get_pf2vf_offset(0)); 104 + if (!(msg & ADF_PF2VF_INT)) { 105 + dev_info(&GET_DEV(accel_dev), 106 + "Spurious PF2VF interrupt, msg %X. Ignored\n", msg); 107 + goto out; 108 + } 99 109 100 110 if (!(msg & ADF_PF2VF_MSGORIGIN_SYSTEM)) 101 111 /* Ignore legacy non-system (non-kernel) PF2VF messages */ ··· 149 149 msg &= ~ADF_PF2VF_INT; 150 150 ADF_CSR_WR(pmisc_bar_addr, hw_data->get_pf2vf_offset(0), msg); 151 151 152 + out: 152 153 /* Re-enable PF2VF interrupts */ 153 154 adf_enable_pf2vf_interrupts(accel_dev); 154 155 return; ··· 241 240 } 242 241 cpu = accel_dev->accel_id % num_online_cpus(); 243 242 irq_set_affinity_hint(pdev->irq, get_cpu_mask(cpu)); 243 + accel_dev->vf.irq_enabled = true; 244 244 245 245 return ret; 246 246 } ··· 273 271 { 274 272 struct pci_dev *pdev = accel_to_pci_dev(accel_dev); 275 273 276 - irq_set_affinity_hint(pdev->irq, NULL); 277 - free_irq(pdev->irq, (void *)accel_dev); 274 + if (accel_dev->vf.irq_enabled) { 275 + irq_set_affinity_hint(pdev->irq, NULL); 276 + free_irq(pdev->irq, accel_dev); 277 + } 278 278 adf_cleanup_bh(accel_dev); 279 279 adf_cleanup_pf2vf_bh(accel_dev); 280 280 adf_disable_msi(accel_dev);
+51 -72
drivers/crypto/qat/qat_dh895xcc/adf_dh895xcc_hw_data.c
··· 35 35 return ~fuses & ADF_DH895XCC_ACCELENGINES_MASK; 36 36 } 37 37 38 - static u32 get_num_accels(struct adf_hw_device_data *self) 39 - { 40 - u32 i, ctr = 0; 41 - 42 - if (!self || !self->accel_mask) 43 - return 0; 44 - 45 - for (i = 0; i < ADF_DH895XCC_MAX_ACCELERATORS; i++) { 46 - if (self->accel_mask & (1 << i)) 47 - ctr++; 48 - } 49 - return ctr; 50 - } 51 - 52 - static u32 get_num_aes(struct adf_hw_device_data *self) 53 - { 54 - u32 i, ctr = 0; 55 - 56 - if (!self || !self->ae_mask) 57 - return 0; 58 - 59 - for (i = 0; i < ADF_DH895XCC_MAX_ACCELENGINES; i++) { 60 - if (self->ae_mask & (1 << i)) 61 - ctr++; 62 - } 63 - return ctr; 64 - } 65 - 66 38 static u32 get_misc_bar_id(struct adf_hw_device_data *self) 67 39 { 68 40 return ADF_DH895XCC_PMISC_BAR; ··· 98 126 return thrd_to_arb_map; 99 127 } 100 128 101 - static u32 get_pf2vf_offset(u32 i) 102 - { 103 - return ADF_DH895XCC_PF2VF_OFFSET(i); 104 - } 105 - 106 - static void adf_enable_error_correction(struct adf_accel_dev *accel_dev) 107 - { 108 - struct adf_hw_device_data *hw_device = accel_dev->hw_device; 109 - struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_DH895XCC_PMISC_BAR]; 110 - unsigned long accel_mask = hw_device->accel_mask; 111 - unsigned long ae_mask = hw_device->ae_mask; 112 - void __iomem *csr = misc_bar->virt_addr; 113 - unsigned int val, i; 114 - 115 - /* Enable Accel Engine error detection & correction */ 116 - for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) { 117 - val = ADF_CSR_RD(csr, ADF_DH895XCC_AE_CTX_ENABLES(i)); 118 - val |= ADF_DH895XCC_ENABLE_AE_ECC_ERR; 119 - ADF_CSR_WR(csr, ADF_DH895XCC_AE_CTX_ENABLES(i), val); 120 - val = ADF_CSR_RD(csr, ADF_DH895XCC_AE_MISC_CONTROL(i)); 121 - val |= ADF_DH895XCC_ENABLE_AE_ECC_PARITY_CORR; 122 - ADF_CSR_WR(csr, ADF_DH895XCC_AE_MISC_CONTROL(i), val); 123 - } 124 - 125 - /* Enable shared memory error detection & correction */ 126 - for_each_set_bit(i, &accel_mask, ADF_DH895XCC_MAX_ACCELERATORS) { 127 - val = ADF_CSR_RD(csr, ADF_DH895XCC_UERRSSMSH(i)); 128 - val |= ADF_DH895XCC_ERRSSMSH_EN; 129 - ADF_CSR_WR(csr, ADF_DH895XCC_UERRSSMSH(i), val); 130 - val = ADF_CSR_RD(csr, ADF_DH895XCC_CERRSSMSH(i)); 131 - val |= ADF_DH895XCC_ERRSSMSH_EN; 132 - ADF_CSR_WR(csr, ADF_DH895XCC_CERRSSMSH(i), val); 133 - } 134 - } 135 - 136 129 static void adf_enable_ints(struct adf_accel_dev *accel_dev) 137 130 { 138 131 void __iomem *addr; ··· 112 175 ADF_DH895XCC_SMIA1_MASK); 113 176 } 114 177 115 - static int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev) 178 + static u32 get_vf2pf_sources(void __iomem *pmisc_bar) 116 179 { 117 - spin_lock_init(&accel_dev->pf.vf2pf_ints_lock); 180 + u32 errsou5, errmsk5, vf_int_mask; 118 181 119 - return 0; 182 + vf_int_mask = adf_gen2_get_vf2pf_sources(pmisc_bar); 183 + 184 + /* Get the interrupt sources triggered by VFs, but to avoid duplicates 185 + * in the work queue, clear vf_int_mask_sets bits that are already 186 + * masked in ERRMSK register. 187 + */ 188 + errsou5 = ADF_CSR_RD(pmisc_bar, ADF_GEN2_ERRSOU5); 189 + errmsk5 = ADF_CSR_RD(pmisc_bar, ADF_GEN2_ERRMSK5); 190 + vf_int_mask |= ADF_DH895XCC_ERR_REG_VF2PF_U(errsou5); 191 + vf_int_mask &= ~ADF_DH895XCC_ERR_REG_VF2PF_U(errmsk5); 192 + 193 + return vf_int_mask; 194 + } 195 + 196 + static void enable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask) 197 + { 198 + /* Enable VF2PF Messaging Ints - VFs 0 through 15 per vf_mask[15:0] */ 199 + adf_gen2_enable_vf2pf_interrupts(pmisc_addr, vf_mask); 200 + 201 + /* Enable VF2PF Messaging Ints - VFs 16 through 31 per vf_mask[31:16] */ 202 + if (vf_mask >> 16) { 203 + u32 val = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRMSK5) 204 + & ~ADF_DH895XCC_ERR_MSK_VF2PF_U(vf_mask); 205 + 206 + ADF_CSR_WR(pmisc_addr, ADF_GEN2_ERRMSK5, val); 207 + } 208 + } 209 + 210 + static void disable_vf2pf_interrupts(void __iomem *pmisc_addr, u32 vf_mask) 211 + { 212 + /* Disable VF2PF interrupts for VFs 0 through 15 per vf_mask[15:0] */ 213 + adf_gen2_disable_vf2pf_interrupts(pmisc_addr, vf_mask); 214 + 215 + /* Disable VF2PF interrupts for VFs 16 through 31 per vf_mask[31:16] */ 216 + if (vf_mask >> 16) { 217 + u32 val = ADF_CSR_RD(pmisc_addr, ADF_GEN2_ERRMSK5) 218 + | ADF_DH895XCC_ERR_MSK_VF2PF_U(vf_mask); 219 + 220 + ADF_CSR_WR(pmisc_addr, ADF_GEN2_ERRMSK5, val); 221 + } 120 222 } 121 223 122 224 static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable) ··· 174 198 hw_data->num_accel = ADF_DH895XCC_MAX_ACCELERATORS; 175 199 hw_data->num_logical_accel = 1; 176 200 hw_data->num_engines = ADF_DH895XCC_MAX_ACCELENGINES; 177 - hw_data->tx_rx_gap = ADF_DH895XCC_RX_RINGS_OFFSET; 178 - hw_data->tx_rings_mask = ADF_DH895XCC_TX_RINGS_MASK; 201 + hw_data->tx_rx_gap = ADF_GEN2_RX_RINGS_OFFSET; 202 + hw_data->tx_rings_mask = ADF_GEN2_TX_RINGS_MASK; 179 203 hw_data->alloc_irq = adf_isr_resource_alloc; 180 204 hw_data->free_irq = adf_isr_resource_free; 181 - hw_data->enable_error_correction = adf_enable_error_correction; 205 + hw_data->enable_error_correction = adf_gen2_enable_error_correction; 182 206 hw_data->get_accel_mask = get_accel_mask; 183 207 hw_data->get_ae_mask = get_ae_mask; 184 208 hw_data->get_accel_cap = get_accel_cap; 185 - hw_data->get_num_accels = get_num_accels; 186 - hw_data->get_num_aes = get_num_aes; 209 + hw_data->get_num_accels = adf_gen2_get_num_accels; 210 + hw_data->get_num_aes = adf_gen2_get_num_aes; 187 211 hw_data->get_etr_bar_id = get_etr_bar_id; 188 212 hw_data->get_misc_bar_id = get_misc_bar_id; 189 213 hw_data->get_admin_info = adf_gen2_get_admin_info; ··· 201 225 hw_data->get_arb_mapping = adf_get_arbiter_mapping; 202 226 hw_data->enable_ints = adf_enable_ints; 203 227 hw_data->reset_device = adf_reset_sbr; 204 - hw_data->get_pf2vf_offset = get_pf2vf_offset; 228 + hw_data->get_pf2vf_offset = adf_gen2_get_pf2vf_offset; 229 + hw_data->get_vf2pf_sources = get_vf2pf_sources; 230 + hw_data->enable_vf2pf_interrupts = enable_vf2pf_interrupts; 231 + hw_data->disable_vf2pf_interrupts = disable_vf2pf_interrupts; 205 232 hw_data->enable_pfvf_comms = adf_enable_pf2vf_comms; 206 233 hw_data->disable_iov = adf_disable_sriov; 207 234 hw_data->min_iov_compat_ver = ADF_PFVF_COMPAT_THIS_VERSION;
+3 -11
drivers/crypto/qat/qat_dh895xcc/adf_dh895xcc_hw_data.h
··· 7 7 #define ADF_DH895XCC_SRAM_BAR 0 8 8 #define ADF_DH895XCC_PMISC_BAR 1 9 9 #define ADF_DH895XCC_ETR_BAR 2 10 - #define ADF_DH895XCC_RX_RINGS_OFFSET 8 11 - #define ADF_DH895XCC_TX_RINGS_MASK 0xFF 12 10 #define ADF_DH895XCC_FUSECTL_SKU_MASK 0x300000 13 11 #define ADF_DH895XCC_FUSECTL_SKU_SHIFT 20 14 12 #define ADF_DH895XCC_FUSECTL_SKU_1 0x0 ··· 23 25 #define ADF_DH895XCC_SMIAPF1_MASK_OFFSET (0x3A000 + 0x30) 24 26 #define ADF_DH895XCC_SMIA0_MASK 0xFFFFFFFF 25 27 #define ADF_DH895XCC_SMIA1_MASK 0x1 26 - /* Error detection and correction */ 27 - #define ADF_DH895XCC_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818) 28 - #define ADF_DH895XCC_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960) 29 - #define ADF_DH895XCC_ENABLE_AE_ECC_ERR BIT(28) 30 - #define ADF_DH895XCC_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12)) 31 - #define ADF_DH895XCC_UERRSSMSH(i) (i * 0x4000 + 0x18) 32 - #define ADF_DH895XCC_CERRSSMSH(i) (i * 0x4000 + 0x10) 33 - #define ADF_DH895XCC_ERRSSMSH_EN BIT(3) 34 28 35 - #define ADF_DH895XCC_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 29 + /* Masks for VF2PF interrupts */ 30 + #define ADF_DH895XCC_ERR_REG_VF2PF_U(vf_src) (((vf_src) & 0x0000FFFF) << 16) 31 + #define ADF_DH895XCC_ERR_MSK_VF2PF_U(vf_mask) ((vf_mask) >> 16) 36 32 37 33 /* AE to function mapping */ 38 34 #define ADF_DH895XCC_AE2FUNC_MAP_GRP_A_NUM_REGS 96
+2
drivers/crypto/s5p-sss.c
··· 2171 2171 2172 2172 variant = find_s5p_sss_version(pdev); 2173 2173 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2174 + if (!res) 2175 + return -EINVAL; 2174 2176 2175 2177 /* 2176 2178 * Note: HASH and PRNG uses the same registers in secss, avoid
+6 -7
drivers/crypto/sa2ul.c
··· 2412 2412 pm_runtime_enable(dev); 2413 2413 ret = pm_runtime_resume_and_get(dev); 2414 2414 if (ret < 0) { 2415 - dev_err(&pdev->dev, "%s: failed to get sync: %d\n", __func__, 2416 - ret); 2415 + dev_err(dev, "%s: failed to get sync: %d\n", __func__, ret); 2417 2416 pm_runtime_disable(dev); 2418 2417 return ret; 2419 2418 } ··· 2434 2435 2435 2436 sa_register_algos(dev_data); 2436 2437 2437 - ret = of_platform_populate(node, NULL, NULL, &pdev->dev); 2438 + ret = of_platform_populate(node, NULL, NULL, dev); 2438 2439 if (ret) 2439 2440 goto release_dma; 2440 2441 2441 - device_for_each_child(&pdev->dev, &pdev->dev, sa_link_child); 2442 + device_for_each_child(dev, dev, sa_link_child); 2442 2443 2443 2444 return 0; 2444 2445 2445 2446 release_dma: 2446 - sa_unregister_algos(&pdev->dev); 2447 + sa_unregister_algos(dev); 2447 2448 2448 2449 dma_release_channel(dev_data->dma_rx2); 2449 2450 dma_release_channel(dev_data->dma_rx1); ··· 2452 2453 destroy_dma_pool: 2453 2454 dma_pool_destroy(dev_data->sc_pool); 2454 2455 2455 - pm_runtime_put_sync(&pdev->dev); 2456 - pm_runtime_disable(&pdev->dev); 2456 + pm_runtime_put_sync(dev); 2457 + pm_runtime_disable(dev); 2457 2458 2458 2459 return ret; 2459 2460 }
+5
include/crypto/engine.h
··· 16 16 #include <crypto/akcipher.h> 17 17 #include <crypto/hash.h> 18 18 #include <crypto/skcipher.h> 19 + #include <crypto/kpp.h> 19 20 20 21 #define ENGINE_NAME_LEN 30 21 22 /* ··· 97 96 struct akcipher_request *req); 98 97 int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, 99 98 struct ahash_request *req); 99 + int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine, 100 + struct kpp_request *req); 100 101 int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, 101 102 struct skcipher_request *req); 102 103 void crypto_finalize_aead_request(struct crypto_engine *engine, ··· 107 104 struct akcipher_request *req, int err); 108 105 void crypto_finalize_hash_request(struct crypto_engine *engine, 109 106 struct ahash_request *req, int err); 107 + void crypto_finalize_kpp_request(struct crypto_engine *engine, 108 + struct kpp_request *req, int err); 110 109 void crypto_finalize_skcipher_request(struct crypto_engine *engine, 111 110 struct skcipher_request *req, int err); 112 111 int crypto_engine_start(struct crypto_engine *engine);
+2 -2
lib/crypto/sm4.c
··· 15 15 0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc 16 16 }; 17 17 18 - static const u32 __cacheline_aligned ck[32] = { 18 + static const u32 ____cacheline_aligned ck[32] = { 19 19 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, 20 20 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, 21 21 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, ··· 26 26 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279 27 27 }; 28 28 29 - static const u8 __cacheline_aligned sbox[256] = { 29 + static const u8 ____cacheline_aligned sbox[256] = { 30 30 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 31 31 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, 32 32 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3,