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:

- crypto_destroy_tfm now ignores errors as well as NULL pointers

Algorithms:

- Add explicit curve IDs in ECDH algorithm names

- Add NIST P384 curve parameters

- Add ECDSA

Drivers:

- Add support for Green Sardine in ccp

- Add ecdh/curve25519 to hisilicon/hpre

- Add support for AM64 in sa2ul"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (184 commits)
fsverity: relax build time dependency on CRYPTO_SHA256
fscrypt: relax Kconfig dependencies for crypto API algorithms
crypto: camellia - drop duplicate "depends on CRYPTO"
crypto: s5p-sss - consistently use local 'dev' variable in probe()
crypto: s5p-sss - remove unneeded local variable initialization
crypto: s5p-sss - simplify getting of_device_id match data
ccp: ccp - add support for Green Sardine
crypto: ccp - Make ccp_dev_suspend and ccp_dev_resume void functions
crypto: octeontx2 - add support for OcteonTX2 98xx CPT block.
crypto: chelsio/chcr - Remove useless MODULE_VERSION
crypto: ux500/cryp - Remove duplicate argument
crypto: chelsio - remove unused function
crypto: sa2ul - Add support for AM64
crypto: sa2ul - Support for per channel coherency
dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64
crypto: hisilicon - enable new error types for QM
crypto: hisilicon - add new error type for SEC
crypto: hisilicon - support new error types for ZIP
crypto: hisilicon - dynamic configuration 'err_info'
crypto: doc - fix kernel-doc notation in chacha.c and af_alg.c
...

+4598 -2026
+23 -1
Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
··· 14 14 enum: 15 15 - ti,j721e-sa2ul 16 16 - ti,am654-sa2ul 17 + - ti,am64-sa2ul 17 18 18 19 reg: 19 20 maxItems: 1 ··· 46 45 description: 47 46 Address translation for the possible RNG child node for SA2UL 48 47 48 + clocks: 49 + items: 50 + - description: Clock used by PKA 51 + - description: Main Input Clock 52 + - description: Clock used by rng 53 + 54 + clock-names: 55 + items: 56 + - const: pka_in_clk 57 + - const: x1_clk 58 + - const: x2_clk 59 + 49 60 patternProperties: 50 61 "^rng@[a-f0-9]+$": 51 62 type: object ··· 70 57 - power-domains 71 58 - dmas 72 59 - dma-names 73 - - dma-coherent 60 + 61 + if: 62 + properties: 63 + compatible: 64 + enum: 65 + - ti,j721e-sa2ul 66 + - ti,am654-sa2ul 67 + then: 68 + required: 69 + - dma-coherent 74 70 75 71 additionalProperties: false 76 72
+21
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml
··· 28 28 clock-names: 29 29 const: ipsec 30 30 31 + resets: 32 + maxItems: 1 33 + 34 + reset-names: 35 + const: ipsec 36 + 31 37 interrupts: 32 38 maxItems: 1 33 39 34 40 required: 35 41 - compatible 36 42 - reg 43 + 44 + if: 45 + properties: 46 + compatible: 47 + enum: 48 + - brcm,bcm6368-rng 49 + then: 50 + required: 51 + - clocks 52 + - clock-names 53 + - resets 54 + - reset-names 37 55 38 56 additionalProperties: false 39 57 ··· 76 58 77 59 clocks = <&periph_clk 18>; 78 60 clock-names = "ipsec"; 61 + 62 + resets = <&periph_rst 4>; 63 + reset-names = "ipsec"; 79 64 };
+10 -32
arch/arm/crypto/aes-cipher-core.S
··· 99 99 __hround \out2, \out3, \in2, \in1, \in0, \in3, \in1, \in0, 0, \sz, \op, \oldcpsr 100 100 .endm 101 101 102 - .macro __rev, out, in 103 - .if __LINUX_ARM_ARCH__ < 6 104 - lsl t0, \in, #24 105 - and t1, \in, #0xff00 106 - and t2, \in, #0xff0000 107 - orr \out, t0, \in, lsr #24 108 - orr \out, \out, t1, lsl #8 109 - orr \out, \out, t2, lsr #8 110 - .else 111 - rev \out, \in 112 - .endif 113 - .endm 114 - 115 - .macro __adrl, out, sym, c 116 - .if __LINUX_ARM_ARCH__ < 7 117 - ldr\c \out, =\sym 118 - .else 119 - movw\c \out, #:lower16:\sym 120 - movt\c \out, #:upper16:\sym 121 - .endif 122 - .endm 123 - 124 102 .macro do_crypt, round, ttab, ltab, bsz 125 103 push {r3-r11, lr} 126 104 ··· 111 133 ldr r7, [in, #12] 112 134 113 135 #ifdef CONFIG_CPU_BIG_ENDIAN 114 - __rev r4, r4 115 - __rev r5, r5 116 - __rev r6, r6 117 - __rev r7, r7 136 + rev_l r4, t0 137 + rev_l r5, t0 138 + rev_l r6, t0 139 + rev_l r7, t0 118 140 #endif 119 141 120 142 eor r4, r4, r8 ··· 122 144 eor r6, r6, r10 123 145 eor r7, r7, r11 124 146 125 - __adrl ttab, \ttab 147 + mov_l ttab, \ttab 126 148 /* 127 149 * Disable interrupts and prefetch the 1024-byte 'ft' or 'it' table into 128 150 * L1 cache, assuming cacheline size >= 32. This is a hardening measure ··· 158 180 2: .ifb \ltab 159 181 add ttab, ttab, #1 160 182 .else 161 - __adrl ttab, \ltab 183 + mov_l ttab, \ltab 162 184 // Prefetch inverse S-box for final round; see explanation above 163 185 .set i, 0 164 186 .rept 256 / 64 ··· 172 194 \round r4, r5, r6, r7, r8, r9, r10, r11, \bsz, b, rounds 173 195 174 196 #ifdef CONFIG_CPU_BIG_ENDIAN 175 - __rev r4, r4 176 - __rev r5, r5 177 - __rev r6, r6 178 - __rev r7, r7 197 + rev_l r4, t0 198 + rev_l r5, t0 199 + rev_l r6, t0 200 + rev_l r7, t0 179 201 #endif 180 202 181 203 ldr out, [sp]
+2 -2
arch/arm/crypto/blake2b-neon-glue.c
··· 85 85 86 86 static void __exit blake2b_neon_mod_exit(void) 87 87 { 88 - return crypto_unregister_shashes(blake2b_neon_algs, 89 - ARRAY_SIZE(blake2b_neon_algs)); 88 + crypto_unregister_shashes(blake2b_neon_algs, 89 + ARRAY_SIZE(blake2b_neon_algs)); 90 90 } 91 91 92 92 module_init(blake2b_neon_mod_init);
+21
arch/arm/crypto/blake2s-core.S
··· 8 8 */ 9 9 10 10 #include <linux/linkage.h> 11 + #include <asm/assembler.h> 11 12 12 13 // Registers used to hold message words temporarily. There aren't 13 14 // enough ARM registers to hold the whole message block, so we have to ··· 37 36 str \a, [\dst, #\offset] 38 37 str \b, [\dst, #\offset + 4] 39 38 #endif 39 + .endm 40 + 41 + .macro _le32_bswap a, tmp 42 + #ifdef __ARMEB__ 43 + rev_l \a, \tmp 44 + #endif 45 + .endm 46 + 47 + .macro _le32_bswap_8x a, b, c, d, e, f, g, h, tmp 48 + _le32_bswap \a, \tmp 49 + _le32_bswap \b, \tmp 50 + _le32_bswap \c, \tmp 51 + _le32_bswap \d, \tmp 52 + _le32_bswap \e, \tmp 53 + _le32_bswap \f, \tmp 54 + _le32_bswap \g, \tmp 55 + _le32_bswap \h, \tmp 40 56 .endm 41 57 42 58 // Execute a quarter-round of BLAKE2s by mixing two columns or two diagonals. ··· 198 180 tst r1, #3 199 181 bne .Lcopy_block_misaligned 200 182 ldmia r1!, {r2-r9} 183 + _le32_bswap_8x r2, r3, r4, r5, r6, r7, r8, r9, r14 201 184 stmia r12!, {r2-r9} 202 185 ldmia r1!, {r2-r9} 186 + _le32_bswap_8x r2, r3, r4, r5, r6, r7, r8, r9, r14 203 187 stmia r12, {r2-r9} 204 188 .Lcopy_block_done: 205 189 str r1, [sp, #68] // Update message pointer ··· 288 268 1: 289 269 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 290 270 ldr r3, [r1], #4 271 + _le32_bswap r3, r4 291 272 #else 292 273 ldrb r3, [r1, #0] 293 274 ldrb r4, [r1, #1]
+13 -30
arch/arm/crypto/chacha-scalar-core.S
··· 41 41 X14 .req r12 42 42 X15 .req r14 43 43 44 - .macro __rev out, in, t0, t1, t2 45 - .if __LINUX_ARM_ARCH__ >= 6 46 - rev \out, \in 47 - .else 48 - lsl \t0, \in, #24 49 - and \t1, \in, #0xff00 50 - and \t2, \in, #0xff0000 51 - orr \out, \t0, \in, lsr #24 52 - orr \out, \out, \t1, lsl #8 53 - orr \out, \out, \t2, lsr #8 54 - .endif 55 - .endm 56 - 57 - .macro _le32_bswap x, t0, t1, t2 44 + .macro _le32_bswap_4x a, b, c, d, tmp 58 45 #ifdef __ARMEB__ 59 - __rev \x, \x, \t0, \t1, \t2 46 + rev_l \a, \tmp 47 + rev_l \b, \tmp 48 + rev_l \c, \tmp 49 + rev_l \d, \tmp 60 50 #endif 61 - .endm 62 - 63 - .macro _le32_bswap_4x a, b, c, d, t0, t1, t2 64 - _le32_bswap \a, \t0, \t1, \t2 65 - _le32_bswap \b, \t0, \t1, \t2 66 - _le32_bswap \c, \t0, \t1, \t2 67 - _le32_bswap \d, \t0, \t1, \t2 68 51 .endm 69 52 70 53 .macro __ldrd a, b, src, offset ··· 183 200 add X1, X1, r9 184 201 add X2, X2, r10 185 202 add X3, X3, r11 186 - _le32_bswap_4x X0, X1, X2, X3, r8, r9, r10 203 + _le32_bswap_4x X0, X1, X2, X3, r8 187 204 ldmia r12!, {r8-r11} 188 205 eor X0, X0, r8 189 206 eor X1, X1, r9 ··· 199 216 ldmia r12!, {X0-X3} 200 217 add X6, r10, X6, ror #brot 201 218 add X7, r11, X7, ror #brot 202 - _le32_bswap_4x X4, X5, X6, X7, r8, r9, r10 219 + _le32_bswap_4x X4, X5, X6, X7, r8 203 220 eor X4, X4, X0 204 221 eor X5, X5, X1 205 222 eor X6, X6, X2 ··· 214 231 add r1, r1, r9 // x9 215 232 add r6, r6, r10 // x10 216 233 add r7, r7, r11 // x11 217 - _le32_bswap_4x r0, r1, r6, r7, r8, r9, r10 234 + _le32_bswap_4x r0, r1, r6, r7, r8 218 235 ldmia r12!, {r8-r11} 219 236 eor r0, r0, r8 // x8 220 237 eor r1, r1, r9 // x9 ··· 228 245 add r3, r9, r3, ror #drot // x13 229 246 add r4, r10, r4, ror #drot // x14 230 247 add r5, r11, r5, ror #drot // x15 231 - _le32_bswap_4x r2, r3, r4, r5, r9, r10, r11 248 + _le32_bswap_4x r2, r3, r4, r5, r9 232 249 ldr r9, [sp, #72] // load LEN 233 250 eor r2, r2, r0 // x12 234 251 eor r3, r3, r1 // x13 ··· 284 301 add X1, X1, r9 285 302 add X2, X2, r10 286 303 add X3, X3, r11 287 - _le32_bswap_4x X0, X1, X2, X3, r8, r9, r10 304 + _le32_bswap_4x X0, X1, X2, X3, r8 288 305 stmia r14!, {X0-X3} 289 306 290 307 // Save keystream for x4-x7 ··· 294 311 add X5, r9, X5, ror #brot 295 312 add X6, r10, X6, ror #brot 296 313 add X7, r11, X7, ror #brot 297 - _le32_bswap_4x X4, X5, X6, X7, r8, r9, r10 314 + _le32_bswap_4x X4, X5, X6, X7, r8 298 315 add r8, sp, #64 299 316 stmia r14!, {X4-X7} 300 317 ··· 306 323 add r1, r1, r9 // x9 307 324 add r6, r6, r10 // x10 308 325 add r7, r7, r11 // x11 309 - _le32_bswap_4x r0, r1, r6, r7, r8, r9, r10 326 + _le32_bswap_4x r0, r1, r6, r7, r8 310 327 stmia r14!, {r0,r1,r6,r7} 311 328 __ldrd r8, r9, sp, 144 312 329 __ldrd r10, r11, sp, 152 ··· 314 331 add r3, r9, r3, ror #drot // x13 315 332 add r4, r10, r4, ror #drot // x14 316 333 add r5, r11, r5, ror #drot // x15 317 - _le32_bswap_4x r2, r3, r4, r5, r9, r10, r11 334 + _le32_bswap_4x r2, r3, r4, r5, r9 318 335 stmia r14, {r2-r5} 319 336 320 337 // Stack: ks0-ks15 unused0-unused7 x0-x15 OUT IN LEN
+1 -1
arch/arm/crypto/curve25519-core.S
··· 10 10 #include <linux/linkage.h> 11 11 12 12 .text 13 - .fpu neon 14 13 .arch armv7-a 14 + .fpu neon 15 15 .align 4 16 16 17 17 ENTRY(curve25519_neon)
+1 -1
arch/arm/crypto/poly1305-glue.c
··· 29 29 30 30 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 31 31 32 - void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key) 32 + void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE]) 33 33 { 34 34 poly1305_init_arm(&dctx->h, key); 35 35 dctx->s[0] = get_unaligned_le32(key + 16);
+1
arch/arm64/crypto/aes-modes.S
··· 359 359 ins vctr.d[0], x8 360 360 361 361 /* apply carry to N counter blocks for N := x12 */ 362 + cbz x12, 2f 362 363 adr x16, 1f 363 364 sub x16, x16, x12, lsl #3 364 365 br x16
+1 -1
arch/arm64/crypto/poly1305-glue.c
··· 25 25 26 26 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 27 27 28 - void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key) 28 + void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE]) 29 29 { 30 30 poly1305_init_arm64(&dctx->h, key); 31 31 dctx->s[0] = get_unaligned_le32(key + 16);
+1 -1
arch/mips/crypto/poly1305-glue.c
··· 17 17 asmlinkage void poly1305_blocks_mips(void *state, const u8 *src, u32 len, u32 hibit); 18 18 asmlinkage void poly1305_emit_mips(void *state, u8 *digest, const u32 *nonce); 19 19 20 - void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key) 20 + void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE]) 21 21 { 22 22 poly1305_init_mips(&dctx->h, key); 23 23 dctx->s[0] = get_unaligned_le32(key + 16);
+1 -1
arch/powerpc/crypto/sha1-spe-glue.c
··· 107 107 108 108 src += bytes; 109 109 len -= bytes; 110 - }; 110 + } 111 111 112 112 memcpy((char *)sctx->buffer, src, len); 113 113 return 0;
+3 -3
arch/x86/crypto/poly1305_glue.c
··· 16 16 #include <asm/simd.h> 17 17 18 18 asmlinkage void poly1305_init_x86_64(void *ctx, 19 - const u8 key[POLY1305_KEY_SIZE]); 19 + const u8 key[POLY1305_BLOCK_SIZE]); 20 20 asmlinkage void poly1305_blocks_x86_64(void *ctx, const u8 *inp, 21 21 const size_t len, const u32 padbit); 22 22 asmlinkage void poly1305_emit_x86_64(void *ctx, u8 mac[POLY1305_DIGEST_SIZE], ··· 81 81 state->is_base2_26 = 0; 82 82 } 83 83 84 - static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_KEY_SIZE]) 84 + static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_BLOCK_SIZE]) 85 85 { 86 86 poly1305_init_x86_64(ctx, key); 87 87 } ··· 129 129 poly1305_emit_avx(ctx, mac, nonce); 130 130 } 131 131 132 - void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key) 132 + void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE]) 133 133 { 134 134 poly1305_simd_init(&dctx->h, key); 135 135 dctx->s[0] = get_unaligned_le32(&key[16]);
+10 -5
crypto/Kconfig
··· 242 242 help 243 243 Generic implementation of the ECDH algorithm 244 244 245 + config CRYPTO_ECDSA 246 + tristate "ECDSA (NIST P192, P256 etc.) algorithm" 247 + select CRYPTO_ECC 248 + select CRYPTO_AKCIPHER 249 + select ASN1 250 + help 251 + Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.) 252 + is A NIST cryptographic standard algorithm. Only signature verification 253 + is implemented. 254 + 245 255 config CRYPTO_ECRDSA 246 256 tristate "EC-RDSA (GOST 34.10) algorithm" 247 257 select CRYPTO_ECC ··· 1223 1213 1224 1214 config CRYPTO_CAMELLIA 1225 1215 tristate "Camellia cipher algorithms" 1226 - depends on CRYPTO 1227 1216 select CRYPTO_ALGAPI 1228 1217 help 1229 1218 Camellia cipher algorithms module. ··· 1238 1229 config CRYPTO_CAMELLIA_X86_64 1239 1230 tristate "Camellia cipher algorithm (x86_64)" 1240 1231 depends on X86 && 64BIT 1241 - depends on CRYPTO 1242 1232 select CRYPTO_SKCIPHER 1243 1233 imply CRYPTO_CTR 1244 1234 help ··· 1254 1246 config CRYPTO_CAMELLIA_AESNI_AVX_X86_64 1255 1247 tristate "Camellia cipher algorithm (x86_64/AES-NI/AVX)" 1256 1248 depends on X86 && 64BIT 1257 - depends on CRYPTO 1258 1249 select CRYPTO_SKCIPHER 1259 1250 select CRYPTO_CAMELLIA_X86_64 1260 1251 select CRYPTO_SIMD ··· 1272 1265 config CRYPTO_CAMELLIA_AESNI_AVX2_X86_64 1273 1266 tristate "Camellia cipher algorithm (x86_64/AES-NI/AVX2)" 1274 1267 depends on X86 && 64BIT 1275 - depends on CRYPTO 1276 1268 select CRYPTO_CAMELLIA_AESNI_AVX_X86_64 1277 1269 help 1278 1270 Camellia cipher algorithm module (x86_64/AES-NI/AVX2). ··· 1287 1281 config CRYPTO_CAMELLIA_SPARC64 1288 1282 tristate "Camellia cipher algorithm (SPARC64)" 1289 1283 depends on SPARC64 1290 - depends on CRYPTO 1291 1284 select CRYPTO_ALGAPI 1292 1285 select CRYPTO_SKCIPHER 1293 1286 help
+6
crypto/Makefile
··· 50 50 51 51 obj-$(CONFIG_CRYPTO_SM2) += sm2_generic.o 52 52 53 + $(obj)/ecdsasignature.asn1.o: $(obj)/ecdsasignature.asn1.c $(obj)/ecdsasignature.asn1.h 54 + $(obj)/ecdsa.o: $(obj)/ecdsasignature.asn1.h 55 + ecdsa_generic-y += ecdsa.o 56 + ecdsa_generic-y += ecdsasignature.asn1.o 57 + obj-$(CONFIG_CRYPTO_ECDSA) += ecdsa_generic.o 58 + 53 59 crypto_acompress-y := acompress.o 54 60 crypto_acompress-y += scompress.o 55 61 obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o
+19
crypto/aegis.h
··· 21 21 u8 bytes[AEGIS_BLOCK_SIZE]; 22 22 }; 23 23 24 + struct aegis_state; 25 + 26 + extern int aegis128_have_aes_insn; 27 + 24 28 #define AEGIS_BLOCK_ALIGN (__alignof__(union aegis_block)) 25 29 #define AEGIS_ALIGNED(p) IS_ALIGNED((uintptr_t)p, AEGIS_BLOCK_ALIGN) 30 + 31 + bool crypto_aegis128_have_simd(void); 32 + void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg); 33 + void crypto_aegis128_init_simd(struct aegis_state *state, 34 + const union aegis_block *key, 35 + const u8 *iv); 36 + void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst, 37 + const u8 *src, unsigned int size); 38 + void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst, 39 + const u8 *src, unsigned int size); 40 + int crypto_aegis128_final_simd(struct aegis_state *state, 41 + union aegis_block *tag_xor, 42 + unsigned int assoclen, 43 + unsigned int cryptlen, 44 + unsigned int authsize); 26 45 27 46 static __always_inline void crypto_aegis_block_xor(union aegis_block *dst, 28 47 const union aegis_block *src)
-15
crypto/aegis128-core.c
··· 58 58 return false; 59 59 } 60 60 61 - bool crypto_aegis128_have_simd(void); 62 - void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg); 63 - void crypto_aegis128_init_simd(struct aegis_state *state, 64 - const union aegis_block *key, 65 - const u8 *iv); 66 - void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst, 67 - const u8 *src, unsigned int size); 68 - void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst, 69 - const u8 *src, unsigned int size); 70 - int crypto_aegis128_final_simd(struct aegis_state *state, 71 - union aegis_block *tag_xor, 72 - unsigned int assoclen, 73 - unsigned int cryptlen, 74 - unsigned int authsize); 75 - 76 61 static void crypto_aegis128_update(struct aegis_state *state) 77 62 { 78 63 union aegis_block tmp;
+5 -5
crypto/aegis128-neon.c
··· 30 30 return IS_ENABLED(CONFIG_ARM64); 31 31 } 32 32 33 - void crypto_aegis128_init_simd(union aegis_block *state, 33 + void crypto_aegis128_init_simd(struct aegis_state *state, 34 34 const union aegis_block *key, 35 35 const u8 *iv) 36 36 { ··· 39 39 kernel_neon_end(); 40 40 } 41 41 42 - void crypto_aegis128_update_simd(union aegis_block *state, const void *msg) 42 + void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg) 43 43 { 44 44 kernel_neon_begin(); 45 45 crypto_aegis128_update_neon(state, msg); 46 46 kernel_neon_end(); 47 47 } 48 48 49 - void crypto_aegis128_encrypt_chunk_simd(union aegis_block *state, u8 *dst, 49 + void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst, 50 50 const u8 *src, unsigned int size) 51 51 { 52 52 kernel_neon_begin(); ··· 54 54 kernel_neon_end(); 55 55 } 56 56 57 - void crypto_aegis128_decrypt_chunk_simd(union aegis_block *state, u8 *dst, 57 + void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst, 58 58 const u8 *src, unsigned int size) 59 59 { 60 60 kernel_neon_begin(); ··· 62 62 kernel_neon_end(); 63 63 } 64 64 65 - int crypto_aegis128_final_simd(union aegis_block *state, 65 + int crypto_aegis128_final_simd(struct aegis_state *state, 66 66 union aegis_block *tag_xor, 67 67 unsigned int assoclen, 68 68 unsigned int cryptlen,
+53 -41
crypto/af_alg.c
··· 491 491 /** 492 492 * af_alg_alloc_tsgl - allocate the TX SGL 493 493 * 494 - * @sk socket of connection to user space 495 - * @return: 0 upon success, < 0 upon error 494 + * @sk: socket of connection to user space 495 + * Return: 0 upon success, < 0 upon error 496 496 */ 497 497 static int af_alg_alloc_tsgl(struct sock *sk) 498 498 { ··· 525 525 } 526 526 527 527 /** 528 - * aead_count_tsgl - Count number of TX SG entries 528 + * af_alg_count_tsgl - Count number of TX SG entries 529 529 * 530 530 * The counting starts from the beginning of the SGL to @bytes. If 531 - * an offset is provided, the counting of the SG entries starts at the offset. 531 + * an @offset is provided, the counting of the SG entries starts at the @offset. 532 532 * 533 - * @sk socket of connection to user space 534 - * @bytes Count the number of SG entries holding given number of bytes. 535 - * @offset Start the counting of SG entries from the given offset. 536 - * @return Number of TX SG entries found given the constraints 533 + * @sk: socket of connection to user space 534 + * @bytes: Count the number of SG entries holding given number of bytes. 535 + * @offset: Start the counting of SG entries from the given offset. 536 + * Return: Number of TX SG entries found given the constraints 537 537 */ 538 538 unsigned int af_alg_count_tsgl(struct sock *sk, size_t bytes, size_t offset) 539 539 { ··· 577 577 EXPORT_SYMBOL_GPL(af_alg_count_tsgl); 578 578 579 579 /** 580 - * aead_pull_tsgl - Release the specified buffers from TX SGL 580 + * af_alg_pull_tsgl - Release the specified buffers from TX SGL 581 581 * 582 - * If @dst is non-null, reassign the pages to dst. The caller must release 582 + * If @dst is non-null, reassign the pages to @dst. The caller must release 583 583 * the pages. If @dst_offset is given only reassign the pages to @dst starting 584 584 * at the @dst_offset (byte). The caller must ensure that @dst is large 585 585 * enough (e.g. by using af_alg_count_tsgl with the same offset). 586 586 * 587 - * @sk socket of connection to user space 588 - * @used Number of bytes to pull from TX SGL 589 - * @dst If non-NULL, buffer is reassigned to dst SGL instead of releasing. The 590 - * caller must release the buffers in dst. 591 - * @dst_offset Reassign the TX SGL from given offset. All buffers before 592 - * reaching the offset is released. 587 + * @sk: socket of connection to user space 588 + * @used: Number of bytes to pull from TX SGL 589 + * @dst: If non-NULL, buffer is reassigned to dst SGL instead of releasing. The 590 + * caller must release the buffers in dst. 591 + * @dst_offset: Reassign the TX SGL from given offset. All buffers before 592 + * reaching the offset is released. 593 593 */ 594 594 void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst, 595 595 size_t dst_offset) ··· 657 657 /** 658 658 * af_alg_free_areq_sgls - Release TX and RX SGLs of the request 659 659 * 660 - * @areq Request holding the TX and RX SGL 660 + * @areq: Request holding the TX and RX SGL 661 661 */ 662 662 static void af_alg_free_areq_sgls(struct af_alg_async_req *areq) 663 663 { ··· 692 692 /** 693 693 * af_alg_wait_for_wmem - wait for availability of writable memory 694 694 * 695 - * @sk socket of connection to user space 696 - * @flags If MSG_DONTWAIT is set, then only report if function would sleep 697 - * @return 0 when writable memory is available, < 0 upon error 695 + * @sk: socket of connection to user space 696 + * @flags: If MSG_DONTWAIT is set, then only report if function would sleep 697 + * Return: 0 when writable memory is available, < 0 upon error 698 698 */ 699 699 static int af_alg_wait_for_wmem(struct sock *sk, unsigned int flags) 700 700 { ··· 725 725 /** 726 726 * af_alg_wmem_wakeup - wakeup caller when writable memory is available 727 727 * 728 - * @sk socket of connection to user space 728 + * @sk: socket of connection to user space 729 729 */ 730 730 void af_alg_wmem_wakeup(struct sock *sk) 731 731 { ··· 748 748 /** 749 749 * af_alg_wait_for_data - wait for availability of TX data 750 750 * 751 - * @sk socket of connection to user space 752 - * @flags If MSG_DONTWAIT is set, then only report if function would sleep 753 - * @min Set to minimum request size if partial requests are allowed. 754 - * @return 0 when writable memory is available, < 0 upon error 751 + * @sk: socket of connection to user space 752 + * @flags: If MSG_DONTWAIT is set, then only report if function would sleep 753 + * @min: Set to minimum request size if partial requests are allowed. 754 + * Return: 0 when writable memory is available, < 0 upon error 755 755 */ 756 756 int af_alg_wait_for_data(struct sock *sk, unsigned flags, unsigned min) 757 757 { ··· 790 790 /** 791 791 * af_alg_data_wakeup - wakeup caller when new data can be sent to kernel 792 792 * 793 - * @sk socket of connection to user space 793 + * @sk: socket of connection to user space 794 794 */ 795 795 static void af_alg_data_wakeup(struct sock *sk) 796 796 { ··· 820 820 * 821 821 * In addition, the ctx is filled with the information sent via CMSG. 822 822 * 823 - * @sock socket of connection to user space 824 - * @msg message from user space 825 - * @size size of message from user space 826 - * @ivsize the size of the IV for the cipher operation to verify that the 823 + * @sock: socket of connection to user space 824 + * @msg: message from user space 825 + * @size: size of message from user space 826 + * @ivsize: the size of the IV for the cipher operation to verify that the 827 827 * user-space-provided IV has the right size 828 - * @return the number of copied data upon success, < 0 upon error 828 + * Return: the number of copied data upon success, < 0 upon error 829 829 */ 830 830 int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, 831 831 unsigned int ivsize) ··· 977 977 978 978 /** 979 979 * af_alg_sendpage - sendpage system call handler 980 + * @sock: socket of connection to user space to write to 981 + * @page: data to send 982 + * @offset: offset into page to begin sending 983 + * @size: length of data 984 + * @flags: message send/receive flags 980 985 * 981 986 * This is a generic implementation of sendpage to fill ctx->tsgl_list. 982 987 */ ··· 1040 1035 1041 1036 /** 1042 1037 * af_alg_free_resources - release resources required for crypto request 1038 + * @areq: Request holding the TX and RX SGL 1043 1039 */ 1044 1040 void af_alg_free_resources(struct af_alg_async_req *areq) 1045 1041 { ··· 1053 1047 1054 1048 /** 1055 1049 * af_alg_async_cb - AIO callback handler 1050 + * @_req: async request info 1051 + * @err: if non-zero, error result to be returned via ki_complete(); 1052 + * otherwise return the AIO output length via ki_complete(). 1056 1053 * 1057 1054 * This handler cleans up the struct af_alg_async_req upon completion of the 1058 1055 * AIO operation. ··· 1082 1073 1083 1074 /** 1084 1075 * af_alg_poll - poll system call handler 1076 + * @file: file pointer 1077 + * @sock: socket to poll 1078 + * @wait: poll_table 1085 1079 */ 1086 1080 __poll_t af_alg_poll(struct file *file, struct socket *sock, 1087 1081 poll_table *wait) ··· 1110 1098 /** 1111 1099 * af_alg_alloc_areq - allocate struct af_alg_async_req 1112 1100 * 1113 - * @sk socket of connection to user space 1114 - * @areqlen size of struct af_alg_async_req + crypto_*_reqsize 1115 - * @return allocated data structure or ERR_PTR upon error 1101 + * @sk: socket of connection to user space 1102 + * @areqlen: size of struct af_alg_async_req + crypto_*_reqsize 1103 + * Return: allocated data structure or ERR_PTR upon error 1116 1104 */ 1117 1105 struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk, 1118 1106 unsigned int areqlen) ··· 1137 1125 * af_alg_get_rsgl - create the RX SGL for the output data from the crypto 1138 1126 * operation 1139 1127 * 1140 - * @sk socket of connection to user space 1141 - * @msg user space message 1142 - * @flags flags used to invoke recvmsg with 1143 - * @areq instance of the cryptographic request that will hold the RX SGL 1144 - * @maxsize maximum number of bytes to be pulled from user space 1145 - * @outlen number of bytes in the RX SGL 1146 - * @return 0 on success, < 0 upon error 1128 + * @sk: socket of connection to user space 1129 + * @msg: user space message 1130 + * @flags: flags used to invoke recvmsg with 1131 + * @areq: instance of the cryptographic request that will hold the RX SGL 1132 + * @maxsize: maximum number of bytes to be pulled from user space 1133 + * @outlen: number of bytes in the RX SGL 1134 + * Return: 0 on success, < 0 upon error 1147 1135 */ 1148 1136 int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags, 1149 1137 struct af_alg_async_req *areq, size_t maxsize,
+1 -1
crypto/api.c
··· 562 562 { 563 563 struct crypto_alg *alg; 564 564 565 - if (unlikely(!mem)) 565 + if (IS_ERR_OR_NULL(mem)) 566 566 return; 567 567 568 568 alg = tfm->__crt_alg;
+3 -1
crypto/asymmetric_keys/public_key.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/seq_file.h> 16 16 #include <linux/scatterlist.h> 17 + #include <linux/asn1.h> 17 18 #include <keys/asymmetric-subtype.h> 18 19 #include <crypto/public_key.h> 19 20 #include <crypto/akcipher.h> ··· 86 85 return n >= CRYPTO_MAX_ALG_NAME ? -EINVAL : 0; 87 86 } 88 87 89 - if (strcmp(encoding, "raw") == 0) { 88 + if (strcmp(encoding, "raw") == 0 || 89 + strcmp(encoding, "x962") == 0) { 90 90 strcpy(alg_name, pkey->pkey_algo); 91 91 return 0; 92 92 }
+47 -2
crypto/asymmetric_keys/x509_cert_parser.c
··· 227 227 ctx->cert->sig->hash_algo = "sha224"; 228 228 goto rsa_pkcs1; 229 229 230 + case OID_id_ecdsa_with_sha1: 231 + ctx->cert->sig->hash_algo = "sha1"; 232 + goto ecdsa; 233 + 234 + case OID_id_ecdsa_with_sha224: 235 + ctx->cert->sig->hash_algo = "sha224"; 236 + goto ecdsa; 237 + 238 + case OID_id_ecdsa_with_sha256: 239 + ctx->cert->sig->hash_algo = "sha256"; 240 + goto ecdsa; 241 + 242 + case OID_id_ecdsa_with_sha384: 243 + ctx->cert->sig->hash_algo = "sha384"; 244 + goto ecdsa; 245 + 246 + case OID_id_ecdsa_with_sha512: 247 + ctx->cert->sig->hash_algo = "sha512"; 248 + goto ecdsa; 249 + 230 250 case OID_gost2012Signature256: 231 251 ctx->cert->sig->hash_algo = "streebog256"; 232 252 goto ecrdsa; ··· 275 255 ctx->cert->sig->encoding = "raw"; 276 256 ctx->algo_oid = ctx->last_oid; 277 257 return 0; 258 + ecdsa: 259 + ctx->cert->sig->pkey_algo = "ecdsa"; 260 + ctx->cert->sig->encoding = "x962"; 261 + ctx->algo_oid = ctx->last_oid; 262 + return 0; 278 263 } 279 264 280 265 /* ··· 301 276 302 277 if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 || 303 278 strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 || 304 - strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0) { 279 + strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0 || 280 + strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) { 305 281 /* Discard the BIT STRING metadata */ 306 282 if (vlen < 1 || *(const u8 *)value != 0) 307 283 return -EBADMSG; ··· 485 459 const void *value, size_t vlen) 486 460 { 487 461 struct x509_parse_context *ctx = context; 462 + enum OID oid; 488 463 489 464 ctx->key_algo = ctx->last_oid; 490 465 switch (ctx->last_oid) { ··· 497 470 ctx->cert->pub->pkey_algo = "ecrdsa"; 498 471 break; 499 472 case OID_id_ecPublicKey: 500 - ctx->cert->pub->pkey_algo = "sm2"; 473 + if (parse_OID(ctx->params, ctx->params_size, &oid) != 0) 474 + return -EBADMSG; 475 + 476 + switch (oid) { 477 + case OID_sm2: 478 + ctx->cert->pub->pkey_algo = "sm2"; 479 + break; 480 + case OID_id_prime192v1: 481 + ctx->cert->pub->pkey_algo = "ecdsa-nist-p192"; 482 + break; 483 + case OID_id_prime256v1: 484 + ctx->cert->pub->pkey_algo = "ecdsa-nist-p256"; 485 + break; 486 + case OID_id_ansip384r1: 487 + ctx->cert->pub->pkey_algo = "ecdsa-nist-p384"; 488 + break; 489 + default: 490 + return -ENOPKG; 491 + } 501 492 break; 502 493 default: 503 494 return -ENOPKG;
+3 -1
crypto/asymmetric_keys/x509_public_key.c
··· 129 129 } 130 130 131 131 ret = -EKEYREJECTED; 132 - if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0) 132 + if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0 && 133 + (strncmp(cert->pub->pkey_algo, "ecdsa-", 6) != 0 || 134 + strcmp(cert->sig->pkey_algo, "ecdsa") != 0)) 133 135 goto out; 134 136 135 137 ret = public_key_verify_signature(cert->pub, cert->sig);
+1 -23
crypto/crc32_generic.c
··· 1 - /* GPL HEADER START 2 - * 3 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License version 2 only, 7 - * as published by the Free Software Foundation. 8 - * 9 - * This program is distributed in the hope that it will be useful, but 10 - * WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * General Public License version 2 for more details (a copy is included 13 - * in the LICENSE file that accompanied this code). 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * version 2 along with this program; If not, see http://www.gnu.org/licenses 17 - * 18 - * Please visit http://www.xyratex.com/contact if you need additional 19 - * information or have any questions. 20 - * 21 - * GPL HEADER END 22 - */ 23 - 1 + // SPDX-License-Identifier: GPL-2.0-only 24 2 /* 25 3 * Copyright 2012 Xyratex Technology Limited 26 4 */
+205 -86
crypto/ecc.c
··· 24 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 25 */ 26 26 27 + #include <crypto/ecc_curve.h> 27 28 #include <linux/module.h> 28 29 #include <linux/random.h> 29 30 #include <linux/slab.h> ··· 43 42 u64 m_high; 44 43 } uint128_t; 45 44 46 - static inline const struct ecc_curve *ecc_get_curve(unsigned int curve_id) 45 + /* Returns curv25519 curve param */ 46 + const struct ecc_curve *ecc_get_curve25519(void) 47 + { 48 + return &ecc_25519; 49 + } 50 + EXPORT_SYMBOL(ecc_get_curve25519); 51 + 52 + const struct ecc_curve *ecc_get_curve(unsigned int curve_id) 47 53 { 48 54 switch (curve_id) { 49 55 /* In FIPS mode only allow P256 and higher */ ··· 58 50 return fips_enabled ? NULL : &nist_p192; 59 51 case ECC_CURVE_NIST_P256: 60 52 return &nist_p256; 53 + case ECC_CURVE_NIST_P384: 54 + return &nist_p384; 61 55 default: 62 56 return NULL; 63 57 } 64 58 } 59 + EXPORT_SYMBOL(ecc_get_curve); 65 60 66 61 static u64 *ecc_alloc_digits_space(unsigned int ndigits) 67 62 { ··· 139 128 } 140 129 EXPORT_SYMBOL(vli_is_zero); 141 130 142 - /* Returns nonzero if bit bit of vli is set. */ 131 + /* Returns nonzero if bit of vli is set. */ 143 132 static u64 vli_test_bit(const u64 *vli, unsigned int bit) 144 133 { 145 134 return (vli[bit / 64] & ((u64)1 << (bit % 64))); ··· 786 775 } 787 776 } 788 777 778 + #define SL32OR32(x32, y32) (((u64)x32 << 32) | y32) 779 + #define AND64H(x64) (x64 & 0xffFFffFF00000000ull) 780 + #define AND64L(x64) (x64 & 0x00000000ffFFffFFull) 781 + 782 + /* Computes result = product % curve_prime 783 + * from "Mathematical routines for the NIST prime elliptic curves" 784 + */ 785 + static void vli_mmod_fast_384(u64 *result, const u64 *product, 786 + const u64 *curve_prime, u64 *tmp) 787 + { 788 + int carry; 789 + const unsigned int ndigits = 6; 790 + 791 + /* t */ 792 + vli_set(result, product, ndigits); 793 + 794 + /* s1 */ 795 + tmp[0] = 0; // 0 || 0 796 + tmp[1] = 0; // 0 || 0 797 + tmp[2] = SL32OR32(product[11], (product[10]>>32)); //a22||a21 798 + tmp[3] = product[11]>>32; // 0 ||a23 799 + tmp[4] = 0; // 0 || 0 800 + tmp[5] = 0; // 0 || 0 801 + carry = vli_lshift(tmp, tmp, 1, ndigits); 802 + carry += vli_add(result, result, tmp, ndigits); 803 + 804 + /* s2 */ 805 + tmp[0] = product[6]; //a13||a12 806 + tmp[1] = product[7]; //a15||a14 807 + tmp[2] = product[8]; //a17||a16 808 + tmp[3] = product[9]; //a19||a18 809 + tmp[4] = product[10]; //a21||a20 810 + tmp[5] = product[11]; //a23||a22 811 + carry += vli_add(result, result, tmp, ndigits); 812 + 813 + /* s3 */ 814 + tmp[0] = SL32OR32(product[11], (product[10]>>32)); //a22||a21 815 + tmp[1] = SL32OR32(product[6], (product[11]>>32)); //a12||a23 816 + tmp[2] = SL32OR32(product[7], (product[6])>>32); //a14||a13 817 + tmp[3] = SL32OR32(product[8], (product[7]>>32)); //a16||a15 818 + tmp[4] = SL32OR32(product[9], (product[8]>>32)); //a18||a17 819 + tmp[5] = SL32OR32(product[10], (product[9]>>32)); //a20||a19 820 + carry += vli_add(result, result, tmp, ndigits); 821 + 822 + /* s4 */ 823 + tmp[0] = AND64H(product[11]); //a23|| 0 824 + tmp[1] = (product[10]<<32); //a20|| 0 825 + tmp[2] = product[6]; //a13||a12 826 + tmp[3] = product[7]; //a15||a14 827 + tmp[4] = product[8]; //a17||a16 828 + tmp[5] = product[9]; //a19||a18 829 + carry += vli_add(result, result, tmp, ndigits); 830 + 831 + /* s5 */ 832 + tmp[0] = 0; // 0|| 0 833 + tmp[1] = 0; // 0|| 0 834 + tmp[2] = product[10]; //a21||a20 835 + tmp[3] = product[11]; //a23||a22 836 + tmp[4] = 0; // 0|| 0 837 + tmp[5] = 0; // 0|| 0 838 + carry += vli_add(result, result, tmp, ndigits); 839 + 840 + /* s6 */ 841 + tmp[0] = AND64L(product[10]); // 0 ||a20 842 + tmp[1] = AND64H(product[10]); //a21|| 0 843 + tmp[2] = product[11]; //a23||a22 844 + tmp[3] = 0; // 0 || 0 845 + tmp[4] = 0; // 0 || 0 846 + tmp[5] = 0; // 0 || 0 847 + carry += vli_add(result, result, tmp, ndigits); 848 + 849 + /* d1 */ 850 + tmp[0] = SL32OR32(product[6], (product[11]>>32)); //a12||a23 851 + tmp[1] = SL32OR32(product[7], (product[6]>>32)); //a14||a13 852 + tmp[2] = SL32OR32(product[8], (product[7]>>32)); //a16||a15 853 + tmp[3] = SL32OR32(product[9], (product[8]>>32)); //a18||a17 854 + tmp[4] = SL32OR32(product[10], (product[9]>>32)); //a20||a19 855 + tmp[5] = SL32OR32(product[11], (product[10]>>32)); //a22||a21 856 + carry -= vli_sub(result, result, tmp, ndigits); 857 + 858 + /* d2 */ 859 + tmp[0] = (product[10]<<32); //a20|| 0 860 + tmp[1] = SL32OR32(product[11], (product[10]>>32)); //a22||a21 861 + tmp[2] = (product[11]>>32); // 0 ||a23 862 + tmp[3] = 0; // 0 || 0 863 + tmp[4] = 0; // 0 || 0 864 + tmp[5] = 0; // 0 || 0 865 + carry -= vli_sub(result, result, tmp, ndigits); 866 + 867 + /* d3 */ 868 + tmp[0] = 0; // 0 || 0 869 + tmp[1] = AND64H(product[11]); //a23|| 0 870 + tmp[2] = product[11]>>32; // 0 ||a23 871 + tmp[3] = 0; // 0 || 0 872 + tmp[4] = 0; // 0 || 0 873 + tmp[5] = 0; // 0 || 0 874 + carry -= vli_sub(result, result, tmp, ndigits); 875 + 876 + if (carry < 0) { 877 + do { 878 + carry += vli_add(result, result, curve_prime, ndigits); 879 + } while (carry < 0); 880 + } else { 881 + while (carry || vli_cmp(curve_prime, result, ndigits) != 1) 882 + carry -= vli_sub(result, result, curve_prime, ndigits); 883 + } 884 + 885 + } 886 + 887 + #undef SL32OR32 888 + #undef AND64H 889 + #undef AND64L 890 + 789 891 /* Computes result = product % curve_prime for different curve_primes. 790 892 * 791 893 * Note that curve_primes are distinguished just by heuristic check and 792 894 * not by complete conformance check. 793 895 */ 794 896 static bool vli_mmod_fast(u64 *result, u64 *product, 795 - const u64 *curve_prime, unsigned int ndigits) 897 + const struct ecc_curve *curve) 796 898 { 797 899 u64 tmp[2 * ECC_MAX_DIGITS]; 900 + const u64 *curve_prime = curve->p; 901 + const unsigned int ndigits = curve->g.ndigits; 798 902 799 - /* Currently, both NIST primes have -1 in lowest qword. */ 800 - if (curve_prime[0] != -1ull) { 903 + /* All NIST curves have name prefix 'nist_' */ 904 + if (strncmp(curve->name, "nist_", 5) != 0) { 801 905 /* Try to handle Pseudo-Marsenne primes. */ 802 906 if (curve_prime[ndigits - 1] == -1ull) { 803 907 vli_mmod_special(result, product, curve_prime, ··· 934 808 break; 935 809 case 4: 936 810 vli_mmod_fast_256(result, product, curve_prime, tmp); 811 + break; 812 + case 6: 813 + vli_mmod_fast_384(result, product, curve_prime, tmp); 937 814 break; 938 815 default: 939 816 pr_err_ratelimited("ecc: unsupported digits size!\n"); ··· 961 832 962 833 /* Computes result = (left * right) % curve_prime. */ 963 834 static void vli_mod_mult_fast(u64 *result, const u64 *left, const u64 *right, 964 - const u64 *curve_prime, unsigned int ndigits) 835 + const struct ecc_curve *curve) 965 836 { 966 837 u64 product[2 * ECC_MAX_DIGITS]; 967 838 968 - vli_mult(product, left, right, ndigits); 969 - vli_mmod_fast(result, product, curve_prime, ndigits); 839 + vli_mult(product, left, right, curve->g.ndigits); 840 + vli_mmod_fast(result, product, curve); 970 841 } 971 842 972 843 /* Computes result = left^2 % curve_prime. */ 973 844 static void vli_mod_square_fast(u64 *result, const u64 *left, 974 - const u64 *curve_prime, unsigned int ndigits) 845 + const struct ecc_curve *curve) 975 846 { 976 847 u64 product[2 * ECC_MAX_DIGITS]; 977 848 978 - vli_square(product, left, ndigits); 979 - vli_mmod_fast(result, product, curve_prime, ndigits); 849 + vli_square(product, left, curve->g.ndigits); 850 + vli_mmod_fast(result, product, curve); 980 851 } 981 852 982 853 #define EVEN(vli) (!(vli[0] & 1)) ··· 1074 945 1075 946 /* Double in place */ 1076 947 static void ecc_point_double_jacobian(u64 *x1, u64 *y1, u64 *z1, 1077 - u64 *curve_prime, unsigned int ndigits) 948 + const struct ecc_curve *curve) 1078 949 { 1079 950 /* t1 = x, t2 = y, t3 = z */ 1080 951 u64 t4[ECC_MAX_DIGITS]; 1081 952 u64 t5[ECC_MAX_DIGITS]; 953 + const u64 *curve_prime = curve->p; 954 + const unsigned int ndigits = curve->g.ndigits; 1082 955 1083 956 if (vli_is_zero(z1, ndigits)) 1084 957 return; 1085 958 1086 959 /* t4 = y1^2 */ 1087 - vli_mod_square_fast(t4, y1, curve_prime, ndigits); 960 + vli_mod_square_fast(t4, y1, curve); 1088 961 /* t5 = x1*y1^2 = A */ 1089 - vli_mod_mult_fast(t5, x1, t4, curve_prime, ndigits); 962 + vli_mod_mult_fast(t5, x1, t4, curve); 1090 963 /* t4 = y1^4 */ 1091 - vli_mod_square_fast(t4, t4, curve_prime, ndigits); 964 + vli_mod_square_fast(t4, t4, curve); 1092 965 /* t2 = y1*z1 = z3 */ 1093 - vli_mod_mult_fast(y1, y1, z1, curve_prime, ndigits); 966 + vli_mod_mult_fast(y1, y1, z1, curve); 1094 967 /* t3 = z1^2 */ 1095 - vli_mod_square_fast(z1, z1, curve_prime, ndigits); 968 + vli_mod_square_fast(z1, z1, curve); 1096 969 1097 970 /* t1 = x1 + z1^2 */ 1098 971 vli_mod_add(x1, x1, z1, curve_prime, ndigits); ··· 1103 972 /* t3 = x1 - z1^2 */ 1104 973 vli_mod_sub(z1, x1, z1, curve_prime, ndigits); 1105 974 /* t1 = x1^2 - z1^4 */ 1106 - vli_mod_mult_fast(x1, x1, z1, curve_prime, ndigits); 975 + vli_mod_mult_fast(x1, x1, z1, curve); 1107 976 1108 977 /* t3 = 2*(x1^2 - z1^4) */ 1109 978 vli_mod_add(z1, x1, x1, curve_prime, ndigits); ··· 1120 989 /* t1 = 3/2*(x1^2 - z1^4) = B */ 1121 990 1122 991 /* t3 = B^2 */ 1123 - vli_mod_square_fast(z1, x1, curve_prime, ndigits); 992 + vli_mod_square_fast(z1, x1, curve); 1124 993 /* t3 = B^2 - A */ 1125 994 vli_mod_sub(z1, z1, t5, curve_prime, ndigits); 1126 995 /* t3 = B^2 - 2A = x3 */ ··· 1128 997 /* t5 = A - x3 */ 1129 998 vli_mod_sub(t5, t5, z1, curve_prime, ndigits); 1130 999 /* t1 = B * (A - x3) */ 1131 - vli_mod_mult_fast(x1, x1, t5, curve_prime, ndigits); 1000 + vli_mod_mult_fast(x1, x1, t5, curve); 1132 1001 /* t4 = B * (A - x3) - y1^4 = y3 */ 1133 1002 vli_mod_sub(t4, x1, t4, curve_prime, ndigits); 1134 1003 ··· 1138 1007 } 1139 1008 1140 1009 /* Modify (x1, y1) => (x1 * z^2, y1 * z^3) */ 1141 - static void apply_z(u64 *x1, u64 *y1, u64 *z, u64 *curve_prime, 1142 - unsigned int ndigits) 1010 + static void apply_z(u64 *x1, u64 *y1, u64 *z, const struct ecc_curve *curve) 1143 1011 { 1144 1012 u64 t1[ECC_MAX_DIGITS]; 1145 1013 1146 - vli_mod_square_fast(t1, z, curve_prime, ndigits); /* z^2 */ 1147 - vli_mod_mult_fast(x1, x1, t1, curve_prime, ndigits); /* x1 * z^2 */ 1148 - vli_mod_mult_fast(t1, t1, z, curve_prime, ndigits); /* z^3 */ 1149 - vli_mod_mult_fast(y1, y1, t1, curve_prime, ndigits); /* y1 * z^3 */ 1014 + vli_mod_square_fast(t1, z, curve); /* z^2 */ 1015 + vli_mod_mult_fast(x1, x1, t1, curve); /* x1 * z^2 */ 1016 + vli_mod_mult_fast(t1, t1, z, curve); /* z^3 */ 1017 + vli_mod_mult_fast(y1, y1, t1, curve); /* y1 * z^3 */ 1150 1018 } 1151 1019 1152 1020 /* P = (x1, y1) => 2P, (x2, y2) => P' */ 1153 1021 static void xycz_initial_double(u64 *x1, u64 *y1, u64 *x2, u64 *y2, 1154 - u64 *p_initial_z, u64 *curve_prime, 1155 - unsigned int ndigits) 1022 + u64 *p_initial_z, const struct ecc_curve *curve) 1156 1023 { 1157 1024 u64 z[ECC_MAX_DIGITS]; 1025 + const unsigned int ndigits = curve->g.ndigits; 1158 1026 1159 1027 vli_set(x2, x1, ndigits); 1160 1028 vli_set(y2, y1, ndigits); ··· 1164 1034 if (p_initial_z) 1165 1035 vli_set(z, p_initial_z, ndigits); 1166 1036 1167 - apply_z(x1, y1, z, curve_prime, ndigits); 1037 + apply_z(x1, y1, z, curve); 1168 1038 1169 - ecc_point_double_jacobian(x1, y1, z, curve_prime, ndigits); 1039 + ecc_point_double_jacobian(x1, y1, z, curve); 1170 1040 1171 - apply_z(x2, y2, z, curve_prime, ndigits); 1041 + apply_z(x2, y2, z, curve); 1172 1042 } 1173 1043 1174 1044 /* Input P = (x1, y1, Z), Q = (x2, y2, Z) 1175 1045 * Output P' = (x1', y1', Z3), P + Q = (x3, y3, Z3) 1176 1046 * or P => P', Q => P + Q 1177 1047 */ 1178 - static void xycz_add(u64 *x1, u64 *y1, u64 *x2, u64 *y2, u64 *curve_prime, 1179 - unsigned int ndigits) 1048 + static void xycz_add(u64 *x1, u64 *y1, u64 *x2, u64 *y2, 1049 + const struct ecc_curve *curve) 1180 1050 { 1181 1051 /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ 1182 1052 u64 t5[ECC_MAX_DIGITS]; 1053 + const u64 *curve_prime = curve->p; 1054 + const unsigned int ndigits = curve->g.ndigits; 1183 1055 1184 1056 /* t5 = x2 - x1 */ 1185 1057 vli_mod_sub(t5, x2, x1, curve_prime, ndigits); 1186 1058 /* t5 = (x2 - x1)^2 = A */ 1187 - vli_mod_square_fast(t5, t5, curve_prime, ndigits); 1059 + vli_mod_square_fast(t5, t5, curve); 1188 1060 /* t1 = x1*A = B */ 1189 - vli_mod_mult_fast(x1, x1, t5, curve_prime, ndigits); 1061 + vli_mod_mult_fast(x1, x1, t5, curve); 1190 1062 /* t3 = x2*A = C */ 1191 - vli_mod_mult_fast(x2, x2, t5, curve_prime, ndigits); 1063 + vli_mod_mult_fast(x2, x2, t5, curve); 1192 1064 /* t4 = y2 - y1 */ 1193 1065 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); 1194 1066 /* t5 = (y2 - y1)^2 = D */ 1195 - vli_mod_square_fast(t5, y2, curve_prime, ndigits); 1067 + vli_mod_square_fast(t5, y2, curve); 1196 1068 1197 1069 /* t5 = D - B */ 1198 1070 vli_mod_sub(t5, t5, x1, curve_prime, ndigits); ··· 1203 1071 /* t3 = C - B */ 1204 1072 vli_mod_sub(x2, x2, x1, curve_prime, ndigits); 1205 1073 /* t2 = y1*(C - B) */ 1206 - vli_mod_mult_fast(y1, y1, x2, curve_prime, ndigits); 1074 + vli_mod_mult_fast(y1, y1, x2, curve); 1207 1075 /* t3 = B - x3 */ 1208 1076 vli_mod_sub(x2, x1, t5, curve_prime, ndigits); 1209 1077 /* t4 = (y2 - y1)*(B - x3) */ 1210 - vli_mod_mult_fast(y2, y2, x2, curve_prime, ndigits); 1078 + vli_mod_mult_fast(y2, y2, x2, curve); 1211 1079 /* t4 = y3 */ 1212 1080 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); 1213 1081 ··· 1218 1086 * Output P + Q = (x3, y3, Z3), P - Q = (x3', y3', Z3) 1219 1087 * or P => P - Q, Q => P + Q 1220 1088 */ 1221 - static void xycz_add_c(u64 *x1, u64 *y1, u64 *x2, u64 *y2, u64 *curve_prime, 1222 - unsigned int ndigits) 1089 + static void xycz_add_c(u64 *x1, u64 *y1, u64 *x2, u64 *y2, 1090 + const struct ecc_curve *curve) 1223 1091 { 1224 1092 /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ 1225 1093 u64 t5[ECC_MAX_DIGITS]; 1226 1094 u64 t6[ECC_MAX_DIGITS]; 1227 1095 u64 t7[ECC_MAX_DIGITS]; 1096 + const u64 *curve_prime = curve->p; 1097 + const unsigned int ndigits = curve->g.ndigits; 1228 1098 1229 1099 /* t5 = x2 - x1 */ 1230 1100 vli_mod_sub(t5, x2, x1, curve_prime, ndigits); 1231 1101 /* t5 = (x2 - x1)^2 = A */ 1232 - vli_mod_square_fast(t5, t5, curve_prime, ndigits); 1102 + vli_mod_square_fast(t5, t5, curve); 1233 1103 /* t1 = x1*A = B */ 1234 - vli_mod_mult_fast(x1, x1, t5, curve_prime, ndigits); 1104 + vli_mod_mult_fast(x1, x1, t5, curve); 1235 1105 /* t3 = x2*A = C */ 1236 - vli_mod_mult_fast(x2, x2, t5, curve_prime, ndigits); 1106 + vli_mod_mult_fast(x2, x2, t5, curve); 1237 1107 /* t4 = y2 + y1 */ 1238 1108 vli_mod_add(t5, y2, y1, curve_prime, ndigits); 1239 1109 /* t4 = y2 - y1 */ ··· 1244 1110 /* t6 = C - B */ 1245 1111 vli_mod_sub(t6, x2, x1, curve_prime, ndigits); 1246 1112 /* t2 = y1 * (C - B) */ 1247 - vli_mod_mult_fast(y1, y1, t6, curve_prime, ndigits); 1113 + vli_mod_mult_fast(y1, y1, t6, curve); 1248 1114 /* t6 = B + C */ 1249 1115 vli_mod_add(t6, x1, x2, curve_prime, ndigits); 1250 1116 /* t3 = (y2 - y1)^2 */ 1251 - vli_mod_square_fast(x2, y2, curve_prime, ndigits); 1117 + vli_mod_square_fast(x2, y2, curve); 1252 1118 /* t3 = x3 */ 1253 1119 vli_mod_sub(x2, x2, t6, curve_prime, ndigits); 1254 1120 1255 1121 /* t7 = B - x3 */ 1256 1122 vli_mod_sub(t7, x1, x2, curve_prime, ndigits); 1257 1123 /* t4 = (y2 - y1)*(B - x3) */ 1258 - vli_mod_mult_fast(y2, y2, t7, curve_prime, ndigits); 1124 + vli_mod_mult_fast(y2, y2, t7, curve); 1259 1125 /* t4 = y3 */ 1260 1126 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); 1261 1127 1262 1128 /* t7 = (y2 + y1)^2 = F */ 1263 - vli_mod_square_fast(t7, t5, curve_prime, ndigits); 1129 + vli_mod_square_fast(t7, t5, curve); 1264 1130 /* t7 = x3' */ 1265 1131 vli_mod_sub(t7, t7, t6, curve_prime, ndigits); 1266 1132 /* t6 = x3' - B */ 1267 1133 vli_mod_sub(t6, t7, x1, curve_prime, ndigits); 1268 1134 /* t6 = (y2 + y1)*(x3' - B) */ 1269 - vli_mod_mult_fast(t6, t6, t5, curve_prime, ndigits); 1135 + vli_mod_mult_fast(t6, t6, t5, curve); 1270 1136 /* t2 = y3' */ 1271 1137 vli_mod_sub(y1, t6, y1, curve_prime, ndigits); 1272 1138 ··· 1296 1162 vli_set(rx[1], point->x, ndigits); 1297 1163 vli_set(ry[1], point->y, ndigits); 1298 1164 1299 - xycz_initial_double(rx[1], ry[1], rx[0], ry[0], initial_z, curve_prime, 1300 - ndigits); 1165 + xycz_initial_double(rx[1], ry[1], rx[0], ry[0], initial_z, curve); 1301 1166 1302 1167 for (i = num_bits - 2; i > 0; i--) { 1303 1168 nb = !vli_test_bit(scalar, i); 1304 - xycz_add_c(rx[1 - nb], ry[1 - nb], rx[nb], ry[nb], curve_prime, 1305 - ndigits); 1306 - xycz_add(rx[nb], ry[nb], rx[1 - nb], ry[1 - nb], curve_prime, 1307 - ndigits); 1169 + xycz_add_c(rx[1 - nb], ry[1 - nb], rx[nb], ry[nb], curve); 1170 + xycz_add(rx[nb], ry[nb], rx[1 - nb], ry[1 - nb], curve); 1308 1171 } 1309 1172 1310 1173 nb = !vli_test_bit(scalar, 0); 1311 - xycz_add_c(rx[1 - nb], ry[1 - nb], rx[nb], ry[nb], curve_prime, 1312 - ndigits); 1174 + xycz_add_c(rx[1 - nb], ry[1 - nb], rx[nb], ry[nb], curve); 1313 1175 1314 1176 /* Find final 1/Z value. */ 1315 1177 /* X1 - X0 */ 1316 1178 vli_mod_sub(z, rx[1], rx[0], curve_prime, ndigits); 1317 1179 /* Yb * (X1 - X0) */ 1318 - vli_mod_mult_fast(z, z, ry[1 - nb], curve_prime, ndigits); 1180 + vli_mod_mult_fast(z, z, ry[1 - nb], curve); 1319 1181 /* xP * Yb * (X1 - X0) */ 1320 - vli_mod_mult_fast(z, z, point->x, curve_prime, ndigits); 1182 + vli_mod_mult_fast(z, z, point->x, curve); 1321 1183 1322 1184 /* 1 / (xP * Yb * (X1 - X0)) */ 1323 1185 vli_mod_inv(z, z, curve_prime, point->ndigits); 1324 1186 1325 1187 /* yP / (xP * Yb * (X1 - X0)) */ 1326 - vli_mod_mult_fast(z, z, point->y, curve_prime, ndigits); 1188 + vli_mod_mult_fast(z, z, point->y, curve); 1327 1189 /* Xb * yP / (xP * Yb * (X1 - X0)) */ 1328 - vli_mod_mult_fast(z, z, rx[1 - nb], curve_prime, ndigits); 1190 + vli_mod_mult_fast(z, z, rx[1 - nb], curve); 1329 1191 /* End 1/Z calculation */ 1330 1192 1331 - xycz_add(rx[nb], ry[nb], rx[1 - nb], ry[1 - nb], curve_prime, ndigits); 1193 + xycz_add(rx[nb], ry[nb], rx[1 - nb], ry[1 - nb], curve); 1332 1194 1333 - apply_z(rx[0], ry[0], z, curve_prime, ndigits); 1195 + apply_z(rx[0], ry[0], z, curve); 1334 1196 1335 1197 vli_set(result->x, rx[0], ndigits); 1336 1198 vli_set(result->y, ry[0], ndigits); ··· 1347 1217 vli_mod_sub(z, result->x, p->x, curve->p, ndigits); 1348 1218 vli_set(px, p->x, ndigits); 1349 1219 vli_set(py, p->y, ndigits); 1350 - xycz_add(px, py, result->x, result->y, curve->p, ndigits); 1220 + xycz_add(px, py, result->x, result->y, curve); 1351 1221 vli_mod_inv(z, z, curve->p, ndigits); 1352 - apply_z(result->x, result->y, z, curve->p, ndigits); 1222 + apply_z(result->x, result->y, z, curve); 1353 1223 } 1354 1224 1355 1225 /* Computes R = u1P + u2Q mod p using Shamir's trick. ··· 1378 1248 points[2] = q; 1379 1249 points[3] = &sum; 1380 1250 1381 - num_bits = max(vli_num_bits(u1, ndigits), 1382 - vli_num_bits(u2, ndigits)); 1251 + num_bits = max(vli_num_bits(u1, ndigits), vli_num_bits(u2, ndigits)); 1383 1252 i = num_bits - 1; 1384 1253 idx = (!!vli_test_bit(u1, i)) | ((!!vli_test_bit(u2, i)) << 1); 1385 1254 point = points[idx]; ··· 1389 1260 z[0] = 1; 1390 1261 1391 1262 for (--i; i >= 0; i--) { 1392 - ecc_point_double_jacobian(rx, ry, z, curve->p, ndigits); 1263 + ecc_point_double_jacobian(rx, ry, z, curve); 1393 1264 idx = (!!vli_test_bit(u1, i)) | ((!!vli_test_bit(u2, i)) << 1); 1394 1265 point = points[idx]; 1395 1266 if (point) { ··· 1399 1270 1400 1271 vli_set(tx, point->x, ndigits); 1401 1272 vli_set(ty, point->y, ndigits); 1402 - apply_z(tx, ty, z, curve->p, ndigits); 1273 + apply_z(tx, ty, z, curve); 1403 1274 vli_mod_sub(tz, rx, tx, curve->p, ndigits); 1404 - xycz_add(tx, ty, rx, ry, curve->p, ndigits); 1405 - vli_mod_mult_fast(z, z, tz, curve->p, ndigits); 1275 + xycz_add(tx, ty, rx, ry, curve); 1276 + vli_mod_mult_fast(z, z, tz, curve); 1406 1277 } 1407 1278 } 1408 1279 vli_mod_inv(z, z, curve->p, ndigits); 1409 - apply_z(rx, ry, z, curve->p, ndigits); 1280 + apply_z(rx, ry, z, curve); 1410 1281 } 1411 1282 EXPORT_SYMBOL(ecc_point_mult_shamir); 1412 - 1413 - static inline void ecc_swap_digits(const u64 *in, u64 *out, 1414 - unsigned int ndigits) 1415 - { 1416 - const __be64 *src = (__force __be64 *)in; 1417 - int i; 1418 - 1419 - for (i = 0; i < ndigits; i++) 1420 - out[i] = be64_to_cpu(src[ndigits - 1 - i]); 1421 - } 1422 1283 1423 1284 static int __ecc_is_key_valid(const struct ecc_curve *curve, 1424 1285 const u64 *private_key, unsigned int ndigits) ··· 1560 1441 return -EINVAL; 1561 1442 1562 1443 /* Check 3: Verify that y^2 == (x^3 + a·x + b) mod p */ 1563 - vli_mod_square_fast(yy, pk->y, curve->p, pk->ndigits); /* y^2 */ 1564 - vli_mod_square_fast(xxx, pk->x, curve->p, pk->ndigits); /* x^2 */ 1565 - vli_mod_mult_fast(xxx, xxx, pk->x, curve->p, pk->ndigits); /* x^3 */ 1566 - vli_mod_mult_fast(w, curve->a, pk->x, curve->p, pk->ndigits); /* a·x */ 1444 + vli_mod_square_fast(yy, pk->y, curve); /* y^2 */ 1445 + vli_mod_square_fast(xxx, pk->x, curve); /* x^2 */ 1446 + vli_mod_mult_fast(xxx, xxx, pk->x, curve); /* x^3 */ 1447 + vli_mod_mult_fast(w, curve->a, pk->x, curve); /* a·x */ 1567 1448 vli_mod_add(w, w, curve->b, curve->p, pk->ndigits); /* a·x + b */ 1568 1449 vli_mod_add(w, w, xxx, curve->p, pk->ndigits); /* x^3 + a·x + b */ 1569 1450 if (vli_cmp(yy, w, pk->ndigits) != 0) /* Equation */
+17 -32
crypto/ecc.h
··· 26 26 #ifndef _CRYPTO_ECC_H 27 27 #define _CRYPTO_ECC_H 28 28 29 + #include <crypto/ecc_curve.h> 30 + 29 31 /* One digit is u64 qword. */ 30 32 #define ECC_CURVE_NIST_P192_DIGITS 3 31 33 #define ECC_CURVE_NIST_P256_DIGITS 4 32 - #define ECC_MAX_DIGITS (512 / 64) 34 + #define ECC_CURVE_NIST_P384_DIGITS 6 35 + #define ECC_MAX_DIGITS (512 / 64) /* due to ecrdsa */ 33 36 34 37 #define ECC_DIGITS_TO_BYTES_SHIFT 3 35 38 36 - /** 37 - * struct ecc_point - elliptic curve point in affine coordinates 38 - * 39 - * @x: X coordinate in vli form. 40 - * @y: Y coordinate in vli form. 41 - * @ndigits: Length of vlis in u64 qwords. 42 - */ 43 - struct ecc_point { 44 - u64 *x; 45 - u64 *y; 46 - u8 ndigits; 47 - }; 39 + #define ECC_MAX_BYTES (ECC_MAX_DIGITS << ECC_DIGITS_TO_BYTES_SHIFT) 48 40 49 41 #define ECC_POINT_INIT(x, y, ndigits) (struct ecc_point) { x, y, ndigits } 50 42 51 43 /** 52 - * struct ecc_curve - definition of elliptic curve 53 - * 54 - * @name: Short name of the curve. 55 - * @g: Generator point of the curve. 56 - * @p: Prime number, if Barrett's reduction is used for this curve 57 - * pre-calculated value 'mu' is appended to the @p after ndigits. 58 - * Use of Barrett's reduction is heuristically determined in 59 - * vli_mmod_fast(). 60 - * @n: Order of the curve group. 61 - * @a: Curve parameter a. 62 - * @b: Curve parameter b. 44 + * ecc_swap_digits() - Copy ndigits from big endian array to native array 45 + * @in: Input array 46 + * @out: Output array 47 + * @ndigits: Number of digits to copy 63 48 */ 64 - struct ecc_curve { 65 - char *name; 66 - struct ecc_point g; 67 - u64 *p; 68 - u64 *n; 69 - u64 *a; 70 - u64 *b; 71 - }; 49 + static inline void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits) 50 + { 51 + const __be64 *src = (__force __be64 *)in; 52 + int i; 53 + 54 + for (i = 0; i < ndigits; i++) 55 + out[i] = be64_to_cpu(src[ndigits - 1 - i]); 56 + } 72 57 73 58 /** 74 59 * ecc_is_key_valid() - Validate a given ECDH private key
+49
crypto/ecc_curve_defs.h
··· 54 54 .b = nist_p256_b 55 55 }; 56 56 57 + /* NIST P-384 */ 58 + static u64 nist_p384_g_x[] = { 0x3A545E3872760AB7ull, 0x5502F25DBF55296Cull, 59 + 0x59F741E082542A38ull, 0x6E1D3B628BA79B98ull, 60 + 0x8Eb1C71EF320AD74ull, 0xAA87CA22BE8B0537ull }; 61 + static u64 nist_p384_g_y[] = { 0x7A431D7C90EA0E5Full, 0x0A60B1CE1D7E819Dull, 62 + 0xE9DA3113B5F0B8C0ull, 0xF8F41DBD289A147Cull, 63 + 0x5D9E98BF9292DC29ull, 0x3617DE4A96262C6Full }; 64 + static u64 nist_p384_p[] = { 0x00000000FFFFFFFFull, 0xFFFFFFFF00000000ull, 65 + 0xFFFFFFFFFFFFFFFEull, 0xFFFFFFFFFFFFFFFFull, 66 + 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull }; 67 + static u64 nist_p384_n[] = { 0xECEC196ACCC52973ull, 0x581A0DB248B0A77Aull, 68 + 0xC7634D81F4372DDFull, 0xFFFFFFFFFFFFFFFFull, 69 + 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull }; 70 + static u64 nist_p384_a[] = { 0x00000000FFFFFFFCull, 0xFFFFFFFF00000000ull, 71 + 0xFFFFFFFFFFFFFFFEull, 0xFFFFFFFFFFFFFFFFull, 72 + 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull }; 73 + static u64 nist_p384_b[] = { 0x2a85c8edd3ec2aefull, 0xc656398d8a2ed19dull, 74 + 0x0314088f5013875aull, 0x181d9c6efe814112ull, 75 + 0x988e056be3f82d19ull, 0xb3312fa7e23ee7e4ull }; 76 + static struct ecc_curve nist_p384 = { 77 + .name = "nist_384", 78 + .g = { 79 + .x = nist_p384_g_x, 80 + .y = nist_p384_g_y, 81 + .ndigits = 6, 82 + }, 83 + .p = nist_p384_p, 84 + .n = nist_p384_n, 85 + .a = nist_p384_a, 86 + .b = nist_p384_b 87 + }; 88 + 89 + /* curve25519 */ 90 + static u64 curve25519_g_x[] = { 0x0000000000000009, 0x0000000000000000, 91 + 0x0000000000000000, 0x0000000000000000 }; 92 + static u64 curve25519_p[] = { 0xffffffffffffffed, 0xffffffffffffffff, 93 + 0xffffffffffffffff, 0x7fffffffffffffff }; 94 + static u64 curve25519_a[] = { 0x000000000001DB41, 0x0000000000000000, 95 + 0x0000000000000000, 0x0000000000000000 }; 96 + static const struct ecc_curve ecc_25519 = { 97 + .name = "curve25519", 98 + .g = { 99 + .x = curve25519_g_x, 100 + .ndigits = 4, 101 + }, 102 + .p = curve25519_p, 103 + .a = curve25519_a, 104 + }; 105 + 57 106 #endif
+50 -22
crypto/ecdh.c
··· 23 23 return kpp_tfm_ctx(tfm); 24 24 } 25 25 26 - static unsigned int ecdh_supported_curve(unsigned int curve_id) 27 - { 28 - switch (curve_id) { 29 - case ECC_CURVE_NIST_P192: return ECC_CURVE_NIST_P192_DIGITS; 30 - case ECC_CURVE_NIST_P256: return ECC_CURVE_NIST_P256_DIGITS; 31 - default: return 0; 32 - } 33 - } 34 - 35 26 static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, 36 27 unsigned int len) 37 28 { 38 29 struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); 39 30 struct ecdh params; 40 - unsigned int ndigits; 41 31 42 32 if (crypto_ecdh_decode_key(buf, len, &params) < 0 || 43 - params.key_size > sizeof(ctx->private_key)) 33 + params.key_size > sizeof(u64) * ctx->ndigits) 44 34 return -EINVAL; 45 - 46 - ndigits = ecdh_supported_curve(params.curve_id); 47 - if (!ndigits) 48 - return -EINVAL; 49 - 50 - ctx->curve_id = params.curve_id; 51 - ctx->ndigits = ndigits; 52 35 53 36 if (!params.key || !params.key_size) 54 37 return ecc_gen_privkey(ctx->curve_id, ctx->ndigits, ··· 123 140 return ctx->ndigits << (ECC_DIGITS_TO_BYTES_SHIFT + 1); 124 141 } 125 142 126 - static struct kpp_alg ecdh = { 143 + static int ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm) 144 + { 145 + struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); 146 + 147 + ctx->curve_id = ECC_CURVE_NIST_P192; 148 + ctx->ndigits = ECC_CURVE_NIST_P192_DIGITS; 149 + 150 + return 0; 151 + } 152 + 153 + static struct kpp_alg ecdh_nist_p192 = { 127 154 .set_secret = ecdh_set_secret, 128 155 .generate_public_key = ecdh_compute_value, 129 156 .compute_shared_secret = ecdh_compute_value, 130 157 .max_size = ecdh_max_size, 158 + .init = ecdh_nist_p192_init_tfm, 131 159 .base = { 132 - .cra_name = "ecdh", 160 + .cra_name = "ecdh-nist-p192", 133 161 .cra_driver_name = "ecdh-generic", 134 162 .cra_priority = 100, 135 163 .cra_module = THIS_MODULE, ··· 148 154 }, 149 155 }; 150 156 157 + static int ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm) 158 + { 159 + struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); 160 + 161 + ctx->curve_id = ECC_CURVE_NIST_P256; 162 + ctx->ndigits = ECC_CURVE_NIST_P256_DIGITS; 163 + 164 + return 0; 165 + } 166 + 167 + static struct kpp_alg ecdh_nist_p256 = { 168 + .set_secret = ecdh_set_secret, 169 + .generate_public_key = ecdh_compute_value, 170 + .compute_shared_secret = ecdh_compute_value, 171 + .max_size = ecdh_max_size, 172 + .init = ecdh_nist_p256_init_tfm, 173 + .base = { 174 + .cra_name = "ecdh-nist-p256", 175 + .cra_driver_name = "ecdh-generic", 176 + .cra_priority = 100, 177 + .cra_module = THIS_MODULE, 178 + .cra_ctxsize = sizeof(struct ecdh_ctx), 179 + }, 180 + }; 181 + 182 + static bool ecdh_nist_p192_registered; 183 + 151 184 static int ecdh_init(void) 152 185 { 153 - return crypto_register_kpp(&ecdh); 186 + int ret; 187 + 188 + ret = crypto_register_kpp(&ecdh_nist_p192); 189 + ecdh_nist_p192_registered = ret == 0; 190 + 191 + return crypto_register_kpp(&ecdh_nist_p256); 154 192 } 155 193 156 194 static void ecdh_exit(void) 157 195 { 158 - crypto_unregister_kpp(&ecdh); 196 + if (ecdh_nist_p192_registered) 197 + crypto_unregister_kpp(&ecdh_nist_p192); 198 + crypto_unregister_kpp(&ecdh_nist_p256); 159 199 } 160 200 161 201 subsys_initcall(ecdh_init);
+1 -3
crypto/ecdh_helper.c
··· 10 10 #include <crypto/ecdh.h> 11 11 #include <crypto/kpp.h> 12 12 13 - #define ECDH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + 2 * sizeof(short)) 13 + #define ECDH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + sizeof(short)) 14 14 15 15 static inline u8 *ecdh_pack_data(void *dst, const void *src, size_t sz) 16 16 { ··· 46 46 return -EINVAL; 47 47 48 48 ptr = ecdh_pack_data(ptr, &secret, sizeof(secret)); 49 - ptr = ecdh_pack_data(ptr, &params->curve_id, sizeof(params->curve_id)); 50 49 ptr = ecdh_pack_data(ptr, &params->key_size, sizeof(params->key_size)); 51 50 ecdh_pack_data(ptr, params->key, params->key_size); 52 51 ··· 69 70 if (unlikely(len < secret.len)) 70 71 return -EINVAL; 71 72 72 - ptr = ecdh_unpack_data(&params->curve_id, ptr, sizeof(params->curve_id)); 73 73 ptr = ecdh_unpack_data(&params->key_size, ptr, sizeof(params->key_size)); 74 74 if (secret.len != crypto_ecdh_key_len(params)) 75 75 return -EINVAL;
+376
crypto/ecdsa.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright (c) 2021 IBM Corporation 4 + */ 5 + 6 + #include <linux/module.h> 7 + #include <crypto/internal/akcipher.h> 8 + #include <crypto/akcipher.h> 9 + #include <crypto/ecdh.h> 10 + #include <linux/asn1_decoder.h> 11 + #include <linux/scatterlist.h> 12 + 13 + #include "ecc.h" 14 + #include "ecdsasignature.asn1.h" 15 + 16 + struct ecc_ctx { 17 + unsigned int curve_id; 18 + const struct ecc_curve *curve; 19 + 20 + bool pub_key_set; 21 + u64 x[ECC_MAX_DIGITS]; /* pub key x and y coordinates */ 22 + u64 y[ECC_MAX_DIGITS]; 23 + struct ecc_point pub_key; 24 + }; 25 + 26 + struct ecdsa_signature_ctx { 27 + const struct ecc_curve *curve; 28 + u64 r[ECC_MAX_DIGITS]; 29 + u64 s[ECC_MAX_DIGITS]; 30 + }; 31 + 32 + /* 33 + * Get the r and s components of a signature from the X509 certificate. 34 + */ 35 + static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, 36 + const void *value, size_t vlen, unsigned int ndigits) 37 + { 38 + size_t keylen = ndigits * sizeof(u64); 39 + ssize_t diff = vlen - keylen; 40 + const char *d = value; 41 + u8 rs[ECC_MAX_BYTES]; 42 + 43 + if (!value || !vlen) 44 + return -EINVAL; 45 + 46 + /* diff = 0: 'value' has exacly the right size 47 + * diff > 0: 'value' has too many bytes; one leading zero is allowed that 48 + * makes the value a positive integer; error on more 49 + * diff < 0: 'value' is missing leading zeros, which we add 50 + */ 51 + if (diff > 0) { 52 + /* skip over leading zeros that make 'value' a positive int */ 53 + if (*d == 0) { 54 + vlen -= 1; 55 + diff--; 56 + d++; 57 + } 58 + if (diff) 59 + return -EINVAL; 60 + } 61 + if (-diff >= keylen) 62 + return -EINVAL; 63 + 64 + if (diff) { 65 + /* leading zeros not given in 'value' */ 66 + memset(rs, 0, -diff); 67 + } 68 + 69 + memcpy(&rs[-diff], d, vlen); 70 + 71 + ecc_swap_digits((u64 *)rs, dest, ndigits); 72 + 73 + return 0; 74 + } 75 + 76 + int ecdsa_get_signature_r(void *context, size_t hdrlen, unsigned char tag, 77 + const void *value, size_t vlen) 78 + { 79 + struct ecdsa_signature_ctx *sig = context; 80 + 81 + return ecdsa_get_signature_rs(sig->r, hdrlen, tag, value, vlen, 82 + sig->curve->g.ndigits); 83 + } 84 + 85 + int ecdsa_get_signature_s(void *context, size_t hdrlen, unsigned char tag, 86 + const void *value, size_t vlen) 87 + { 88 + struct ecdsa_signature_ctx *sig = context; 89 + 90 + return ecdsa_get_signature_rs(sig->s, hdrlen, tag, value, vlen, 91 + sig->curve->g.ndigits); 92 + } 93 + 94 + static int _ecdsa_verify(struct ecc_ctx *ctx, const u64 *hash, const u64 *r, const u64 *s) 95 + { 96 + const struct ecc_curve *curve = ctx->curve; 97 + unsigned int ndigits = curve->g.ndigits; 98 + u64 s1[ECC_MAX_DIGITS]; 99 + u64 u1[ECC_MAX_DIGITS]; 100 + u64 u2[ECC_MAX_DIGITS]; 101 + u64 x1[ECC_MAX_DIGITS]; 102 + u64 y1[ECC_MAX_DIGITS]; 103 + struct ecc_point res = ECC_POINT_INIT(x1, y1, ndigits); 104 + 105 + /* 0 < r < n and 0 < s < n */ 106 + if (vli_is_zero(r, ndigits) || vli_cmp(r, curve->n, ndigits) >= 0 || 107 + vli_is_zero(s, ndigits) || vli_cmp(s, curve->n, ndigits) >= 0) 108 + return -EBADMSG; 109 + 110 + /* hash is given */ 111 + pr_devel("hash : %016llx %016llx ... %016llx\n", 112 + hash[ndigits - 1], hash[ndigits - 2], hash[0]); 113 + 114 + /* s1 = (s^-1) mod n */ 115 + vli_mod_inv(s1, s, curve->n, ndigits); 116 + /* u1 = (hash * s1) mod n */ 117 + vli_mod_mult_slow(u1, hash, s1, curve->n, ndigits); 118 + /* u2 = (r * s1) mod n */ 119 + vli_mod_mult_slow(u2, r, s1, curve->n, ndigits); 120 + /* res = u1*G + u2 * pub_key */ 121 + ecc_point_mult_shamir(&res, u1, &curve->g, u2, &ctx->pub_key, curve); 122 + 123 + /* res.x = res.x mod n (if res.x > order) */ 124 + if (unlikely(vli_cmp(res.x, curve->n, ndigits) == 1)) 125 + /* faster alternative for NIST p384, p256 & p192 */ 126 + vli_sub(res.x, res.x, curve->n, ndigits); 127 + 128 + if (!vli_cmp(res.x, r, ndigits)) 129 + return 0; 130 + 131 + return -EKEYREJECTED; 132 + } 133 + 134 + /* 135 + * Verify an ECDSA signature. 136 + */ 137 + static int ecdsa_verify(struct akcipher_request *req) 138 + { 139 + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); 140 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 141 + size_t keylen = ctx->curve->g.ndigits * sizeof(u64); 142 + struct ecdsa_signature_ctx sig_ctx = { 143 + .curve = ctx->curve, 144 + }; 145 + u8 rawhash[ECC_MAX_BYTES]; 146 + u64 hash[ECC_MAX_DIGITS]; 147 + unsigned char *buffer; 148 + ssize_t diff; 149 + int ret; 150 + 151 + if (unlikely(!ctx->pub_key_set)) 152 + return -EINVAL; 153 + 154 + buffer = kmalloc(req->src_len + req->dst_len, GFP_KERNEL); 155 + if (!buffer) 156 + return -ENOMEM; 157 + 158 + sg_pcopy_to_buffer(req->src, 159 + sg_nents_for_len(req->src, req->src_len + req->dst_len), 160 + buffer, req->src_len + req->dst_len, 0); 161 + 162 + ret = asn1_ber_decoder(&ecdsasignature_decoder, &sig_ctx, 163 + buffer, req->src_len); 164 + if (ret < 0) 165 + goto error; 166 + 167 + /* if the hash is shorter then we will add leading zeros to fit to ndigits */ 168 + diff = keylen - req->dst_len; 169 + if (diff >= 0) { 170 + if (diff) 171 + memset(rawhash, 0, diff); 172 + memcpy(&rawhash[diff], buffer + req->src_len, req->dst_len); 173 + } else if (diff < 0) { 174 + /* given hash is longer, we take the left-most bytes */ 175 + memcpy(&rawhash, buffer + req->src_len, keylen); 176 + } 177 + 178 + ecc_swap_digits((u64 *)rawhash, hash, ctx->curve->g.ndigits); 179 + 180 + ret = _ecdsa_verify(ctx, hash, sig_ctx.r, sig_ctx.s); 181 + 182 + error: 183 + kfree(buffer); 184 + 185 + return ret; 186 + } 187 + 188 + static int ecdsa_ecc_ctx_init(struct ecc_ctx *ctx, unsigned int curve_id) 189 + { 190 + ctx->curve_id = curve_id; 191 + ctx->curve = ecc_get_curve(curve_id); 192 + if (!ctx->curve) 193 + return -EINVAL; 194 + 195 + return 0; 196 + } 197 + 198 + 199 + static void ecdsa_ecc_ctx_deinit(struct ecc_ctx *ctx) 200 + { 201 + ctx->pub_key_set = false; 202 + } 203 + 204 + static int ecdsa_ecc_ctx_reset(struct ecc_ctx *ctx) 205 + { 206 + unsigned int curve_id = ctx->curve_id; 207 + int ret; 208 + 209 + ecdsa_ecc_ctx_deinit(ctx); 210 + ret = ecdsa_ecc_ctx_init(ctx, curve_id); 211 + if (ret == 0) 212 + ctx->pub_key = ECC_POINT_INIT(ctx->x, ctx->y, 213 + ctx->curve->g.ndigits); 214 + return ret; 215 + } 216 + 217 + /* 218 + * Set the public key given the raw uncompressed key data from an X509 219 + * certificate. The key data contain the concatenated X and Y coordinates of 220 + * the public key. 221 + */ 222 + static int ecdsa_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen) 223 + { 224 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 225 + const unsigned char *d = key; 226 + const u64 *digits = (const u64 *)&d[1]; 227 + unsigned int ndigits; 228 + int ret; 229 + 230 + ret = ecdsa_ecc_ctx_reset(ctx); 231 + if (ret < 0) 232 + return ret; 233 + 234 + if (keylen < 1 || (((keylen - 1) >> 1) % sizeof(u64)) != 0) 235 + return -EINVAL; 236 + /* we only accept uncompressed format indicated by '4' */ 237 + if (d[0] != 4) 238 + return -EINVAL; 239 + 240 + keylen--; 241 + ndigits = (keylen >> 1) / sizeof(u64); 242 + if (ndigits != ctx->curve->g.ndigits) 243 + return -EINVAL; 244 + 245 + ecc_swap_digits(digits, ctx->pub_key.x, ndigits); 246 + ecc_swap_digits(&digits[ndigits], ctx->pub_key.y, ndigits); 247 + ret = ecc_is_pubkey_valid_full(ctx->curve, &ctx->pub_key); 248 + 249 + ctx->pub_key_set = ret == 0; 250 + 251 + return ret; 252 + } 253 + 254 + static void ecdsa_exit_tfm(struct crypto_akcipher *tfm) 255 + { 256 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 257 + 258 + ecdsa_ecc_ctx_deinit(ctx); 259 + } 260 + 261 + static unsigned int ecdsa_max_size(struct crypto_akcipher *tfm) 262 + { 263 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 264 + 265 + return ctx->pub_key.ndigits << ECC_DIGITS_TO_BYTES_SHIFT; 266 + } 267 + 268 + static int ecdsa_nist_p384_init_tfm(struct crypto_akcipher *tfm) 269 + { 270 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 271 + 272 + return ecdsa_ecc_ctx_init(ctx, ECC_CURVE_NIST_P384); 273 + } 274 + 275 + static struct akcipher_alg ecdsa_nist_p384 = { 276 + .verify = ecdsa_verify, 277 + .set_pub_key = ecdsa_set_pub_key, 278 + .max_size = ecdsa_max_size, 279 + .init = ecdsa_nist_p384_init_tfm, 280 + .exit = ecdsa_exit_tfm, 281 + .base = { 282 + .cra_name = "ecdsa-nist-p384", 283 + .cra_driver_name = "ecdsa-nist-p384-generic", 284 + .cra_priority = 100, 285 + .cra_module = THIS_MODULE, 286 + .cra_ctxsize = sizeof(struct ecc_ctx), 287 + }, 288 + }; 289 + 290 + static int ecdsa_nist_p256_init_tfm(struct crypto_akcipher *tfm) 291 + { 292 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 293 + 294 + return ecdsa_ecc_ctx_init(ctx, ECC_CURVE_NIST_P256); 295 + } 296 + 297 + static struct akcipher_alg ecdsa_nist_p256 = { 298 + .verify = ecdsa_verify, 299 + .set_pub_key = ecdsa_set_pub_key, 300 + .max_size = ecdsa_max_size, 301 + .init = ecdsa_nist_p256_init_tfm, 302 + .exit = ecdsa_exit_tfm, 303 + .base = { 304 + .cra_name = "ecdsa-nist-p256", 305 + .cra_driver_name = "ecdsa-nist-p256-generic", 306 + .cra_priority = 100, 307 + .cra_module = THIS_MODULE, 308 + .cra_ctxsize = sizeof(struct ecc_ctx), 309 + }, 310 + }; 311 + 312 + static int ecdsa_nist_p192_init_tfm(struct crypto_akcipher *tfm) 313 + { 314 + struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm); 315 + 316 + return ecdsa_ecc_ctx_init(ctx, ECC_CURVE_NIST_P192); 317 + } 318 + 319 + static struct akcipher_alg ecdsa_nist_p192 = { 320 + .verify = ecdsa_verify, 321 + .set_pub_key = ecdsa_set_pub_key, 322 + .max_size = ecdsa_max_size, 323 + .init = ecdsa_nist_p192_init_tfm, 324 + .exit = ecdsa_exit_tfm, 325 + .base = { 326 + .cra_name = "ecdsa-nist-p192", 327 + .cra_driver_name = "ecdsa-nist-p192-generic", 328 + .cra_priority = 100, 329 + .cra_module = THIS_MODULE, 330 + .cra_ctxsize = sizeof(struct ecc_ctx), 331 + }, 332 + }; 333 + static bool ecdsa_nist_p192_registered; 334 + 335 + static int ecdsa_init(void) 336 + { 337 + int ret; 338 + 339 + /* NIST p192 may not be available in FIPS mode */ 340 + ret = crypto_register_akcipher(&ecdsa_nist_p192); 341 + ecdsa_nist_p192_registered = ret == 0; 342 + 343 + ret = crypto_register_akcipher(&ecdsa_nist_p256); 344 + if (ret) 345 + goto nist_p256_error; 346 + 347 + ret = crypto_register_akcipher(&ecdsa_nist_p384); 348 + if (ret) 349 + goto nist_p384_error; 350 + 351 + return 0; 352 + 353 + nist_p384_error: 354 + crypto_unregister_akcipher(&ecdsa_nist_p256); 355 + 356 + nist_p256_error: 357 + if (ecdsa_nist_p192_registered) 358 + crypto_unregister_akcipher(&ecdsa_nist_p192); 359 + return ret; 360 + } 361 + 362 + static void ecdsa_exit(void) 363 + { 364 + if (ecdsa_nist_p192_registered) 365 + crypto_unregister_akcipher(&ecdsa_nist_p192); 366 + crypto_unregister_akcipher(&ecdsa_nist_p256); 367 + crypto_unregister_akcipher(&ecdsa_nist_p384); 368 + } 369 + 370 + subsys_initcall(ecdsa_init); 371 + module_exit(ecdsa_exit); 372 + 373 + MODULE_LICENSE("GPL"); 374 + MODULE_AUTHOR("Stefan Berger <stefanb@linux.ibm.com>"); 375 + MODULE_DESCRIPTION("ECDSA generic algorithm"); 376 + MODULE_ALIAS_CRYPTO("ecdsa-generic");
+4
crypto/ecdsasignature.asn1
··· 1 + ECDSASignature ::= SEQUENCE { 2 + r INTEGER ({ ecdsa_get_signature_r }), 3 + s INTEGER ({ ecdsa_get_signature_s }) 4 + }
+1 -4
crypto/fcrypt.c
··· 63 63 } while (0) 64 64 65 65 /* Rotate right one 64 bit number as a 56 bit number */ 66 - #define ror56_64(k, n) \ 67 - do { \ 68 - k = (k >> n) | ((k & ((1 << n) - 1)) << (56 - n)); \ 69 - } while (0) 66 + #define ror56_64(k, n) (k = (k >> n) | ((k & ((1 << n) - 1)) << (56 - n))) 70 67 71 68 /* 72 69 * Sboxes for Feistel network derived from
+4 -4
crypto/jitterentropy.c
··· 597 597 if (!ec) 598 598 return -1; 599 599 600 - while (0 < len) { 600 + while (len > 0) { 601 601 unsigned int tocopy; 602 602 603 603 jent_gen_entropy(ec); ··· 678 678 } 679 679 680 680 /* verify and set the oversampling rate */ 681 - if (0 == osr) 681 + if (osr == 0) 682 682 osr = 1; /* minimum sampling rate is 1 */ 683 683 entropy_collector->osr = osr; 684 684 ··· 769 769 * etc. with the goal to clear it to get the worst case 770 770 * measurements. 771 771 */ 772 - if (CLEARCACHE > i) 772 + if (i < CLEARCACHE) 773 773 continue; 774 774 775 775 if (stuck) ··· 826 826 * should not fail. The value of 3 should cover the NTP case being 827 827 * performed during our test run. 828 828 */ 829 - if (3 < time_backwards) 829 + if (time_backwards > 3) 830 830 return JENT_ENOMONOTONIC; 831 831 832 832 /*
+2 -2
crypto/keywrap.c
··· 114 114 scatterwalk_start(walk, sg); 115 115 scatterwalk_advance(walk, skip); 116 116 break; 117 - } else 118 - skip -= sg->length; 117 + } 119 118 119 + skip -= sg->length; 120 120 sg = sg_next(sg); 121 121 } 122 122 }
+3 -7
crypto/rng.c
··· 34 34 u8 *buf = NULL; 35 35 int err; 36 36 37 - crypto_stats_get(alg); 38 37 if (!seed && slen) { 39 38 buf = kmalloc(slen, GFP_KERNEL); 40 - if (!buf) { 41 - crypto_alg_put(alg); 39 + if (!buf) 42 40 return -ENOMEM; 43 - } 44 41 45 42 err = get_random_bytes_wait(buf, slen); 46 - if (err) { 47 - crypto_alg_put(alg); 43 + if (err) 48 44 goto out; 49 - } 50 45 seed = buf; 51 46 } 52 47 48 + crypto_stats_get(alg); 53 49 err = crypto_rng_alg(tfm)->seed(tfm, seed, slen); 54 50 crypto_stats_rng_seed(alg, err); 55 51 out:
+24 -13
crypto/serpent_generic.c
··· 272 272 u32 *k = ctx->expkey; 273 273 u8 *k8 = (u8 *)k; 274 274 u32 r0, r1, r2, r3, r4; 275 + __le32 *lk; 275 276 int i; 276 277 277 278 /* Copy key, add padding */ ··· 284 283 while (i < SERPENT_MAX_KEY_SIZE) 285 284 k8[i++] = 0; 286 285 286 + lk = (__le32 *)k; 287 + k[0] = le32_to_cpu(lk[0]); 288 + k[1] = le32_to_cpu(lk[1]); 289 + k[2] = le32_to_cpu(lk[2]); 290 + k[3] = le32_to_cpu(lk[3]); 291 + k[4] = le32_to_cpu(lk[4]); 292 + k[5] = le32_to_cpu(lk[5]); 293 + k[6] = le32_to_cpu(lk[6]); 294 + k[7] = le32_to_cpu(lk[7]); 295 + 287 296 /* Expand key using polynomial */ 288 297 289 - r0 = le32_to_cpu(k[3]); 290 - r1 = le32_to_cpu(k[4]); 291 - r2 = le32_to_cpu(k[5]); 292 - r3 = le32_to_cpu(k[6]); 293 - r4 = le32_to_cpu(k[7]); 298 + r0 = k[3]; 299 + r1 = k[4]; 300 + r2 = k[5]; 301 + r3 = k[6]; 302 + r4 = k[7]; 294 303 295 - keyiter(le32_to_cpu(k[0]), r0, r4, r2, 0, 0); 296 - keyiter(le32_to_cpu(k[1]), r1, r0, r3, 1, 1); 297 - keyiter(le32_to_cpu(k[2]), r2, r1, r4, 2, 2); 298 - keyiter(le32_to_cpu(k[3]), r3, r2, r0, 3, 3); 299 - keyiter(le32_to_cpu(k[4]), r4, r3, r1, 4, 4); 300 - keyiter(le32_to_cpu(k[5]), r0, r4, r2, 5, 5); 301 - keyiter(le32_to_cpu(k[6]), r1, r0, r3, 6, 6); 302 - keyiter(le32_to_cpu(k[7]), r2, r1, r4, 7, 7); 304 + keyiter(k[0], r0, r4, r2, 0, 0); 305 + keyiter(k[1], r1, r0, r3, 1, 1); 306 + keyiter(k[2], r2, r1, r4, 2, 2); 307 + keyiter(k[3], r3, r2, r0, 3, 3); 308 + keyiter(k[4], r4, r3, r1, 4, 4); 309 + keyiter(k[5], r0, r4, r2, 5, 5); 310 + keyiter(k[6], r1, r0, r3, 6, 6); 311 + keyiter(k[7], r2, r1, r4, 7, 7); 303 312 304 313 keyiter(k[0], r3, r2, r0, 8, 8); 305 314 keyiter(k[1], r4, r3, r1, 9, 9);
+32 -10
crypto/testmgr.c
··· 1168 1168 return err; 1169 1169 } 1170 1170 1171 - static inline const void *sg_data(struct scatterlist *sg) 1172 - { 1173 - return page_address(sg_page(sg)) + sg->offset; 1174 - } 1175 - 1176 1171 /* Test one hash test vector in one configuration, using the shash API */ 1177 1172 static int test_shash_vec_cfg(const struct hash_testvec *vec, 1178 1173 const char *vec_name, ··· 1225 1230 return 0; 1226 1231 if (cfg->nosimd) 1227 1232 crypto_disable_simd_for_test(); 1228 - err = crypto_shash_digest(desc, sg_data(&tsgl->sgl[0]), 1233 + err = crypto_shash_digest(desc, sg_virt(&tsgl->sgl[0]), 1229 1234 tsgl->sgl[0].length, result); 1230 1235 if (cfg->nosimd) 1231 1236 crypto_reenable_simd_for_test(); ··· 1261 1266 cfg->finalization_type == FINALIZATION_TYPE_FINUP) { 1262 1267 if (divs[i]->nosimd) 1263 1268 crypto_disable_simd_for_test(); 1264 - err = crypto_shash_finup(desc, sg_data(&tsgl->sgl[i]), 1269 + err = crypto_shash_finup(desc, sg_virt(&tsgl->sgl[i]), 1265 1270 tsgl->sgl[i].length, result); 1266 1271 if (divs[i]->nosimd) 1267 1272 crypto_reenable_simd_for_test(); ··· 1273 1278 } 1274 1279 if (divs[i]->nosimd) 1275 1280 crypto_disable_simd_for_test(); 1276 - err = crypto_shash_update(desc, sg_data(&tsgl->sgl[i]), 1281 + err = crypto_shash_update(desc, sg_virt(&tsgl->sgl[i]), 1277 1282 tsgl->sgl[i].length); 1278 1283 if (divs[i]->nosimd) 1279 1284 crypto_reenable_simd_for_test(); ··· 4899 4904 } 4900 4905 }, { 4901 4906 #endif 4902 - .alg = "ecdh", 4907 + #ifndef CONFIG_CRYPTO_FIPS 4908 + .alg = "ecdh-nist-p192", 4903 4909 .test = alg_test_kpp, 4904 4910 .fips_allowed = 1, 4905 4911 .suite = { 4906 - .kpp = __VECS(ecdh_tv_template) 4912 + .kpp = __VECS(ecdh_p192_tv_template) 4913 + } 4914 + }, { 4915 + #endif 4916 + .alg = "ecdh-nist-p256", 4917 + .test = alg_test_kpp, 4918 + .fips_allowed = 1, 4919 + .suite = { 4920 + .kpp = __VECS(ecdh_p256_tv_template) 4921 + } 4922 + }, { 4923 + .alg = "ecdsa-nist-p192", 4924 + .test = alg_test_akcipher, 4925 + .suite = { 4926 + .akcipher = __VECS(ecdsa_nist_p192_tv_template) 4927 + } 4928 + }, { 4929 + .alg = "ecdsa-nist-p256", 4930 + .test = alg_test_akcipher, 4931 + .suite = { 4932 + .akcipher = __VECS(ecdsa_nist_p256_tv_template) 4933 + } 4934 + }, { 4935 + .alg = "ecdsa-nist-p384", 4936 + .test = alg_test_akcipher, 4937 + .suite = { 4938 + .akcipher = __VECS(ecdsa_nist_p384_tv_template) 4907 4939 } 4908 4940 }, { 4909 4941 .alg = "ecrdsa",
+439 -19
crypto/testmgr.h
··· 567 567 }; 568 568 569 569 /* 570 + * ECDSA test vectors. 571 + */ 572 + static const struct akcipher_testvec ecdsa_nist_p192_tv_template[] = { 573 + { 574 + .key = 575 + "\x04\xf7\x46\xf8\x2f\x15\xf6\x22\x8e\xd7\x57\x4f\xcc\xe7\xbb\xc1" 576 + "\xd4\x09\x73\xcf\xea\xd0\x15\x07\x3d\xa5\x8a\x8a\x95\x43\xe4\x68" 577 + "\xea\xc6\x25\xc1\xc1\x01\x25\x4c\x7e\xc3\x3c\xa6\x04\x0a\xe7\x08" 578 + "\x98", 579 + .key_len = 49, 580 + .params = 581 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 582 + "\xce\x3d\x03\x01\x01", 583 + .param_len = 21, 584 + .m = 585 + "\xcd\xb9\xd2\x1c\xb7\x6f\xcd\x44\xb3\xfd\x63\xea\xa3\x66\x7f\xae" 586 + "\x63\x85\xe7\x82", 587 + .m_size = 20, 588 + .algo = OID_id_ecdsa_with_sha1, 589 + .c = 590 + "\x30\x35\x02\x19\x00\xba\xe5\x93\x83\x6e\xb6\x3b\x63\xa0\x27\x91" 591 + "\xc6\xf6\x7f\xc3\x09\xad\x59\xad\x88\x27\xd6\x92\x6b\x02\x18\x10" 592 + "\x68\x01\x9d\xba\xce\x83\x08\xef\x95\x52\x7b\xa0\x0f\xe4\x18\x86" 593 + "\x80\x6f\xa5\x79\x77\xda\xd0", 594 + .c_size = 55, 595 + .public_key_vec = true, 596 + .siggen_sigver_test = true, 597 + }, { 598 + .key = 599 + "\x04\xb6\x4b\xb1\xd1\xac\xba\x24\x8f\x65\xb2\x60\x00\x90\xbf\xbd" 600 + "\x78\x05\x73\xe9\x79\x1d\x6f\x7c\x0b\xd2\xc3\x93\xa7\x28\xe1\x75" 601 + "\xf7\xd5\x95\x1d\x28\x10\xc0\x75\x50\x5c\x1a\x4f\x3f\x8f\xa5\xee" 602 + "\xa3", 603 + .key_len = 49, 604 + .params = 605 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 606 + "\xce\x3d\x03\x01\x01", 607 + .param_len = 21, 608 + .m = 609 + "\x8d\xd6\xb8\x3e\xe5\xff\x23\xf6\x25\xa2\x43\x42\x74\x45\xa7\x40" 610 + "\x3a\xff\x2f\xe1\xd3\xf6\x9f\xe8\x33\xcb\x12\x11", 611 + .m_size = 28, 612 + .algo = OID_id_ecdsa_with_sha224, 613 + .c = 614 + "\x30\x34\x02\x18\x5a\x8b\x82\x69\x7e\x8a\x0a\x09\x14\xf8\x11\x2b" 615 + "\x55\xdc\xae\x37\x83\x7b\x12\xe6\xb6\x5b\xcb\xd4\x02\x18\x6a\x14" 616 + "\x4f\x53\x75\xc8\x02\x48\xeb\xc3\x92\x0f\x1e\x72\xee\xc4\xa3\xe3" 617 + "\x5c\x99\xdb\x92\x5b\x36", 618 + .c_size = 54, 619 + .public_key_vec = true, 620 + .siggen_sigver_test = true, 621 + }, { 622 + .key = 623 + "\x04\xe2\x51\x24\x9b\xf7\xb6\x32\x82\x39\x66\x3d\x5b\xec\x3b\xae" 624 + "\x0c\xd5\xf2\x67\xd1\xc7\xe1\x02\xe4\xbf\x90\x62\xb8\x55\x75\x56" 625 + "\x69\x20\x5e\xcb\x4e\xca\x33\xd6\xcb\x62\x6b\x94\xa9\xa2\xe9\x58" 626 + "\x91", 627 + .key_len = 49, 628 + .params = 629 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 630 + "\xce\x3d\x03\x01\x01", 631 + .param_len = 21, 632 + .m = 633 + "\x35\xec\xa1\xa0\x9e\x14\xde\x33\x03\xb6\xf6\xbd\x0c\x2f\xb2\xfd" 634 + "\x1f\x27\x82\xa5\xd7\x70\x3f\xef\xa0\x82\x69\x8e\x73\x31\x8e\xd7", 635 + .m_size = 32, 636 + .algo = OID_id_ecdsa_with_sha256, 637 + .c = 638 + "\x30\x35\x02\x18\x3f\x72\x3f\x1f\x42\xd2\x3f\x1d\x6b\x1a\x58\x56" 639 + "\xf1\x8f\xf7\xfd\x01\x48\xfb\x5f\x72\x2a\xd4\x8f\x02\x19\x00\xb3" 640 + "\x69\x43\xfd\x48\x19\x86\xcf\x32\xdd\x41\x74\x6a\x51\xc7\xd9\x7d" 641 + "\x3a\x97\xd9\xcd\x1a\x6a\x49", 642 + .c_size = 55, 643 + .public_key_vec = true, 644 + .siggen_sigver_test = true, 645 + }, { 646 + .key = 647 + "\x04\x5a\x13\xfe\x68\x86\x4d\xf4\x17\xc7\xa4\xe5\x8c\x65\x57\xb7" 648 + "\x03\x73\x26\x57\xfb\xe5\x58\x40\xd8\xfd\x49\x05\xab\xf1\x66\x1f" 649 + "\xe2\x9d\x93\x9e\xc2\x22\x5a\x8b\x4f\xf3\x77\x22\x59\x7e\xa6\x4e" 650 + "\x8b", 651 + .key_len = 49, 652 + .params = 653 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 654 + "\xce\x3d\x03\x01\x01", 655 + .param_len = 21, 656 + .m = 657 + "\x9d\x2e\x1a\x8f\xed\x6c\x4b\x61\xae\xac\xd5\x19\x79\xce\x67\xf9" 658 + "\xa0\x34\xeb\xb0\x81\xf9\xd9\xdc\x6e\xb3\x5c\xa8\x69\xfc\x8a\x61" 659 + "\x39\x81\xfb\xfd\x5c\x30\x6b\xa8\xee\xed\x89\xaf\xa3\x05\xe4\x78", 660 + .m_size = 48, 661 + .algo = OID_id_ecdsa_with_sha384, 662 + .c = 663 + "\x30\x35\x02\x19\x00\xf0\xa3\x38\xce\x2b\xf8\x9d\x1a\xcf\x7f\x34" 664 + "\xb4\xb4\xe5\xc5\x00\xdd\x15\xbb\xd6\x8c\xa7\x03\x78\x02\x18\x64" 665 + "\xbc\x5a\x1f\x82\x96\x61\xd7\xd1\x01\x77\x44\x5d\x53\xa4\x7c\x93" 666 + "\x12\x3b\x3b\x28\xfb\x6d\xe1", 667 + .c_size = 55, 668 + .public_key_vec = true, 669 + .siggen_sigver_test = true, 670 + }, { 671 + .key = 672 + "\x04\xd5\xf2\x6e\xc3\x94\x5c\x52\xbc\xdf\x86\x6c\x14\xd1\xca\xea" 673 + "\xcc\x72\x3a\x8a\xf6\x7a\x3a\x56\x36\x3b\xca\xc6\x94\x0e\x17\x1d" 674 + "\x9e\xa0\x58\x28\xf9\x4b\xe6\xd1\xa5\x44\x91\x35\x0d\xe7\xf5\x11" 675 + "\x57", 676 + .key_len = 49, 677 + .params = 678 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 679 + "\xce\x3d\x03\x01\x01", 680 + .param_len = 21, 681 + .m = 682 + "\xd5\x4b\xe9\x36\xda\xd8\x6e\xc0\x50\x03\xbe\x00\x43\xff\xf0\x23" 683 + "\xac\xa2\x42\xe7\x37\x77\x79\x52\x8f\x3e\xc0\x16\xc1\xfc\x8c\x67" 684 + "\x16\xbc\x8a\x5d\x3b\xd3\x13\xbb\xb6\xc0\x26\x1b\xeb\x33\xcc\x70" 685 + "\x4a\xf2\x11\x37\xe8\x1b\xba\x55\xac\x69\xe1\x74\x62\x7c\x6e\xb5", 686 + .m_size = 64, 687 + .algo = OID_id_ecdsa_with_sha512, 688 + .c = 689 + "\x30\x35\x02\x19\x00\x88\x5b\x8f\x59\x43\xbf\xcf\xc6\xdd\x3f\x07" 690 + "\x87\x12\xa0\xd4\xac\x2b\x11\x2d\x1c\xb6\x06\xc9\x6c\x02\x18\x73" 691 + "\xb4\x22\x9a\x98\x73\x3c\x83\xa9\x14\x2a\x5e\xf5\xe5\xfb\x72\x28" 692 + "\x6a\xdf\x97\xfd\x82\x76\x24", 693 + .c_size = 55, 694 + .public_key_vec = true, 695 + .siggen_sigver_test = true, 696 + }, 697 + }; 698 + 699 + static const struct akcipher_testvec ecdsa_nist_p256_tv_template[] = { 700 + { 701 + .key = 702 + "\x04\xb9\x7b\xbb\xd7\x17\x64\xd2\x7e\xfc\x81\x5d\x87\x06\x83\x41" 703 + "\x22\xd6\x9a\xaa\x87\x17\xec\x4f\x63\x55\x2f\x94\xba\xdd\x83\xe9" 704 + "\x34\x4b\xf3\xe9\x91\x13\x50\xb6\xcb\xca\x62\x08\xe7\x3b\x09\xdc" 705 + "\xc3\x63\x4b\x2d\xb9\x73\x53\xe4\x45\xe6\x7c\xad\xe7\x6b\xb0\xe8" 706 + "\xaf", 707 + .key_len = 65, 708 + .params = 709 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 710 + "\xce\x3d\x03\x01\x07", 711 + .param_len = 21, 712 + .m = 713 + "\xc2\x2b\x5f\x91\x78\x34\x26\x09\x42\x8d\x6f\x51\xb2\xc5\xaf\x4c" 714 + "\x0b\xde\x6a\x42", 715 + .m_size = 20, 716 + .algo = OID_id_ecdsa_with_sha1, 717 + .c = 718 + "\x30\x46\x02\x21\x00\xf9\x25\xce\x9f\x3a\xa6\x35\x81\xcf\xd4\xe7" 719 + "\xb7\xf0\x82\x56\x41\xf7\xd4\xad\x8d\x94\x5a\x69\x89\xee\xca\x6a" 720 + "\x52\x0e\x48\x4d\xcc\x02\x21\x00\xd7\xe4\xef\x52\x66\xd3\x5b\x9d" 721 + "\x8a\xfa\x54\x93\x29\xa7\x70\x86\xf1\x03\x03\xf3\x3b\xe2\x73\xf7" 722 + "\xfb\x9d\x8b\xde\xd4\x8d\x6f\xad", 723 + .c_size = 72, 724 + .public_key_vec = true, 725 + .siggen_sigver_test = true, 726 + }, { 727 + .key = 728 + "\x04\x8b\x6d\xc0\x33\x8e\x2d\x8b\x67\xf5\xeb\xc4\x7f\xa0\xf5\xd9" 729 + "\x7b\x03\xa5\x78\x9a\xb5\xea\x14\xe4\x23\xd0\xaf\xd7\x0e\x2e\xa0" 730 + "\xc9\x8b\xdb\x95\xf8\xb3\xaf\xac\x00\x2c\x2c\x1f\x7a\xfd\x95\x88" 731 + "\x43\x13\xbf\xf3\x1c\x05\x1a\x14\x18\x09\x3f\xd6\x28\x3e\xc5\xa0" 732 + "\xd4", 733 + .key_len = 65, 734 + .params = 735 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 736 + "\xce\x3d\x03\x01\x07", 737 + .param_len = 21, 738 + .m = 739 + "\x1a\x15\xbc\xa3\xe4\xed\x3a\xb8\x23\x67\xc6\xc4\x34\xf8\x6c\x41" 740 + "\x04\x0b\xda\xc5\x77\xfa\x1c\x2d\xe6\x2c\x3b\xe0", 741 + .m_size = 28, 742 + .algo = OID_id_ecdsa_with_sha224, 743 + .c = 744 + "\x30\x44\x02\x20\x20\x43\xfa\xc0\x9f\x9d\x7b\xe7\xae\xce\x77\x59" 745 + "\x1a\xdb\x59\xd5\x34\x62\x79\xcb\x6a\x91\x67\x2e\x7d\x25\xd8\x25" 746 + "\xf5\x81\xd2\x1e\x02\x20\x5f\xf8\x74\xf8\x57\xd0\x5e\x54\x76\x20" 747 + "\x4a\x77\x22\xec\xc8\x66\xbf\x50\x05\x58\x39\x0e\x26\x92\xce\xd5" 748 + "\x2e\x8b\xde\x5a\x04\x0e", 749 + .c_size = 70, 750 + .public_key_vec = true, 751 + .siggen_sigver_test = true, 752 + }, { 753 + .key = 754 + "\x04\xf1\xea\xc4\x53\xf3\xb9\x0e\x9f\x7e\xad\xe3\xea\xd7\x0e\x0f" 755 + "\xd6\x98\x9a\xca\x92\x4d\x0a\x80\xdb\x2d\x45\xc7\xec\x4b\x97\x00" 756 + "\x2f\xe9\x42\x6c\x29\xdc\x55\x0e\x0b\x53\x12\x9b\x2b\xad\x2c\xe9" 757 + "\x80\xe6\xc5\x43\xc2\x1d\x5e\xbb\x65\x21\x50\xb6\x37\xb0\x03\x8e" 758 + "\xb8", 759 + .key_len = 65, 760 + .params = 761 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 762 + "\xce\x3d\x03\x01\x07", 763 + .param_len = 21, 764 + .m = 765 + "\x8f\x43\x43\x46\x64\x8f\x6b\x96\xdf\x89\xdd\xa9\x01\xc5\x17\x6b" 766 + "\x10\xa6\xd8\x39\x61\xdd\x3c\x1a\xc8\x8b\x59\xb2\xdc\x32\x7a\xa4", 767 + .m_size = 32, 768 + .algo = OID_id_ecdsa_with_sha256, 769 + .c = 770 + "\x30\x45\x02\x20\x08\x31\xfa\x74\x0d\x1d\x21\x5d\x09\xdc\x29\x63" 771 + "\xa8\x1a\xad\xfc\xac\x44\xc3\xe8\x24\x11\x2d\xa4\x91\xdc\x02\x67" 772 + "\xdc\x0c\xd0\x82\x02\x21\x00\xbd\xff\xce\xee\x42\xc3\x97\xff\xf9" 773 + "\xa9\x81\xac\x4a\x50\xd0\x91\x0a\x6e\x1b\xc4\xaf\xe1\x83\xc3\x4f" 774 + "\x2a\x65\x35\x23\xe3\x1d\xfa", 775 + .c_size = 71, 776 + .public_key_vec = true, 777 + .siggen_sigver_test = true, 778 + }, { 779 + .key = 780 + "\x04\xc5\xc6\xea\x60\xc9\xce\xad\x02\x8d\xf5\x3e\x24\xe3\x52\x1d" 781 + "\x28\x47\x3b\xc3\x6b\xa4\x99\x35\x99\x11\x88\x88\xc8\xf4\xee\x7e" 782 + "\x8c\x33\x8f\x41\x03\x24\x46\x2b\x1a\x82\xf9\x9f\xe1\x97\x1b\x00" 783 + "\xda\x3b\x24\x41\xf7\x66\x33\x58\x3d\x3a\x81\xad\xcf\x16\xe9\xe2" 784 + "\x7c", 785 + .key_len = 65, 786 + .params = 787 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 788 + "\xce\x3d\x03\x01\x07", 789 + .param_len = 21, 790 + .m = 791 + "\x3e\x78\x70\xfb\xcd\x66\xba\x91\xa1\x79\xff\x1e\x1c\x6b\x78\xe6" 792 + "\xc0\x81\x3a\x65\x97\x14\x84\x36\x14\x1a\x9a\xb7\xc5\xab\x84\x94" 793 + "\x5e\xbb\x1b\x34\x71\xcb\x41\xe1\xf6\xfc\x92\x7b\x34\xbb\x86\xbb", 794 + .m_size = 48, 795 + .algo = OID_id_ecdsa_with_sha384, 796 + .c = 797 + "\x30\x46\x02\x21\x00\x8e\xf3\x6f\xdc\xf8\x69\xa6\x2e\xd0\x2e\x95" 798 + "\x54\xd1\x95\x64\x93\x08\xb2\x6b\x24\x94\x48\x46\x5e\xf2\xe4\x6c" 799 + "\xc7\x94\xb1\xd5\xfe\x02\x21\x00\xeb\xa7\x80\x26\xdc\xf9\x3a\x44" 800 + "\x19\xfb\x5f\x92\xf4\xc9\x23\x37\x69\xf4\x3b\x4f\x47\xcf\x9b\x16" 801 + "\xc0\x60\x11\x92\xdc\x17\x89\x12", 802 + .c_size = 72, 803 + .public_key_vec = true, 804 + .siggen_sigver_test = true, 805 + }, { 806 + .key = 807 + "\x04\xd7\x27\x46\x49\xf6\x26\x85\x12\x40\x76\x8e\xe2\xe6\x2a\x7a" 808 + "\x83\xb1\x4e\x7a\xeb\x3b\x5c\x67\x4a\xb5\xa4\x92\x8c\x69\xff\x38" 809 + "\xee\xd9\x4e\x13\x29\x59\xad\xde\x6b\xbb\x45\x31\xee\xfd\xd1\x1b" 810 + "\x64\xd3\xb5\xfc\xaf\x9b\x4b\x88\x3b\x0e\xb7\xd6\xdf\xf1\xd5\x92" 811 + "\xbf", 812 + .key_len = 65, 813 + .params = 814 + "\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48" 815 + "\xce\x3d\x03\x01\x07", 816 + .param_len = 21, 817 + .m = 818 + "\x57\xb7\x9e\xe9\x05\x0a\x8c\x1b\xc9\x13\xe5\x4a\x24\xc7\xe2\xe9" 819 + "\x43\xc3\xd1\x76\x62\xf4\x98\x1a\x9c\x13\xb0\x20\x1b\xe5\x39\xca" 820 + "\x4f\xd9\x85\x34\x95\xa2\x31\xbc\xbb\xde\xdd\x76\xbb\x61\xe3\xcf" 821 + "\x9d\xc0\x49\x7a\xf3\x7a\xc4\x7d\xa8\x04\x4b\x8d\xb4\x4d\x5b\xd6", 822 + .m_size = 64, 823 + .algo = OID_id_ecdsa_with_sha512, 824 + .c = 825 + "\x30\x45\x02\x21\x00\xb8\x6d\x87\x81\x43\xdf\xfb\x9f\x40\xea\x44" 826 + "\x81\x00\x4e\x29\x08\xed\x8c\x73\x30\x6c\x22\xb3\x97\x76\xf6\x04" 827 + "\x99\x09\x37\x4d\xfa\x02\x20\x1e\xb9\x75\x31\xf6\x04\xa5\x4d\xf8" 828 + "\x00\xdd\xab\xd4\xc0\x2b\xe6\x5c\xad\xc3\x78\x1c\xc2\xc1\x19\x76" 829 + "\x31\x79\x4a\xe9\x81\x6a\xee", 830 + .c_size = 71, 831 + .public_key_vec = true, 832 + .siggen_sigver_test = true, 833 + }, 834 + }; 835 + 836 + static const struct akcipher_testvec ecdsa_nist_p384_tv_template[] = { 837 + { 838 + .key = /* secp384r1(sha1) */ 839 + "\x04\x89\x25\xf3\x97\x88\xcb\xb0\x78\xc5\x72\x9a\x14\x6e\x7a\xb1" 840 + "\x5a\xa5\x24\xf1\x95\x06\x9e\x28\xfb\xc4\xb9\xbe\x5a\x0d\xd9\x9f" 841 + "\xf3\xd1\x4d\x2d\x07\x99\xbd\xda\xa7\x66\xec\xbb\xea\xba\x79\x42" 842 + "\xc9\x34\x89\x6a\xe7\x0b\xc3\xf2\xfe\x32\x30\xbe\xba\xf9\xdf\x7e" 843 + "\x4b\x6a\x07\x8e\x26\x66\x3f\x1d\xec\xa2\x57\x91\x51\xdd\x17\x0e" 844 + "\x0b\x25\xd6\x80\x5c\x3b\xe6\x1a\x98\x48\x91\x45\x7a\x73\xb0\xc3" 845 + "\xf1", 846 + .key_len = 97, 847 + .params = 848 + "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04" 849 + "\x00\x22", 850 + .param_len = 18, 851 + .m = 852 + "\x12\x55\x28\xf0\x77\xd5\xb6\x21\x71\x32\x48\xcd\x28\xa8\x25\x22" 853 + "\x3a\x69\xc1\x93", 854 + .m_size = 20, 855 + .algo = OID_id_ecdsa_with_sha1, 856 + .c = 857 + "\x30\x66\x02\x31\x00\xf5\x0f\x24\x4c\x07\x93\x6f\x21\x57\x55\x07" 858 + "\x20\x43\x30\xde\xa0\x8d\x26\x8e\xae\x63\x3f\xbc\x20\x3a\xc6\xf1" 859 + "\x32\x3c\xce\x70\x2b\x78\xf1\x4c\x26\xe6\x5b\x86\xcf\xec\x7c\x7e" 860 + "\xd0\x87\xd7\xd7\x6e\x02\x31\x00\xcd\xbb\x7e\x81\x5d\x8f\x63\xc0" 861 + "\x5f\x63\xb1\xbe\x5e\x4c\x0e\xa1\xdf\x28\x8c\x1b\xfa\xf9\x95\x88" 862 + "\x74\xa0\x0f\xbf\xaf\xc3\x36\x76\x4a\xa1\x59\xf1\x1c\xa4\x58\x26" 863 + "\x79\x12\x2a\xb7\xc5\x15\x92\xc5", 864 + .c_size = 104, 865 + .public_key_vec = true, 866 + .siggen_sigver_test = true, 867 + }, { 868 + .key = /* secp384r1(sha224) */ 869 + "\x04\x69\x6c\xcf\x62\xee\xd0\x0d\xe5\xb5\x2f\x70\x54\xcf\x26\xa0" 870 + "\xd9\x98\x8d\x92\x2a\xab\x9b\x11\xcb\x48\x18\xa1\xa9\x0d\xd5\x18" 871 + "\x3e\xe8\x29\x6e\xf6\xe4\xb5\x8e\xc7\x4a\xc2\x5f\x37\x13\x99\x05" 872 + "\xb6\xa4\x9d\xf9\xfb\x79\x41\xe7\xd7\x96\x9f\x73\x3b\x39\x43\xdc" 873 + "\xda\xf4\x06\xb9\xa5\x29\x01\x9d\x3b\xe1\xd8\x68\x77\x2a\xf4\x50" 874 + "\x6b\x93\x99\x6c\x66\x4c\x42\x3f\x65\x60\x6c\x1c\x0b\x93\x9b\x9d" 875 + "\xe0", 876 + .key_len = 97, 877 + .params = 878 + "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04" 879 + "\x00\x22", 880 + .param_len = 18, 881 + .m = 882 + "\x12\x80\xb6\xeb\x25\xe2\x3d\xf0\x21\x32\x96\x17\x3a\x38\x39\xfd" 883 + "\x1f\x05\x34\x7b\xb8\xf9\x71\x66\x03\x4f\xd5\xe5", 884 + .m_size = 28, 885 + .algo = OID_id_ecdsa_with_sha224, 886 + .c = 887 + "\x30\x66\x02\x31\x00\x8a\x51\x84\xce\x13\x1e\xd2\xdc\xec\xcb\xe4" 888 + "\x89\x47\xb2\xf7\xbc\x97\xf1\xc8\x72\x26\xcf\x5a\x5e\xc5\xda\xb4" 889 + "\xe3\x93\x07\xe0\x99\xc9\x9c\x11\xb8\x10\x01\xc5\x41\x3f\xdd\x15" 890 + "\x1b\x68\x2b\x9d\x8b\x02\x31\x00\x8b\x03\x2c\xfc\x1f\xd1\xa9\xa4" 891 + "\x4b\x00\x08\x31\x6c\xf5\xd5\xf6\xdf\xd8\x68\xa2\x64\x42\x65\xf3" 892 + "\x4d\xd0\xc6\x6e\xb0\xe9\xfc\x14\x9f\x19\xd0\x42\x8b\x93\xc2\x11" 893 + "\x88\x2b\x82\x26\x5e\x1c\xda\xfb", 894 + .c_size = 104, 895 + .public_key_vec = true, 896 + .siggen_sigver_test = true, 897 + }, { 898 + .key = /* secp384r1(sha256) */ 899 + "\x04\xee\xd6\xda\x3e\x94\x90\x00\x27\xed\xf8\x64\x55\xd6\x51\x9a" 900 + "\x1f\x52\x00\x63\x78\xf1\xa9\xfd\x75\x4c\x9e\xb2\x20\x1a\x91\x5a" 901 + "\xba\x7a\xa3\xe5\x6c\xb6\x25\x68\x4b\xe8\x13\xa6\x54\x87\x2c\x0e" 902 + "\xd0\x83\x95\xbc\xbf\xc5\x28\x4f\x77\x1c\x46\xa6\xf0\xbc\xd4\xa4" 903 + "\x8d\xc2\x8f\xb3\x32\x37\x40\xd6\xca\xf8\xae\x07\x34\x52\x39\x52" 904 + "\x17\xc3\x34\x29\xd6\x40\xea\x5c\xb9\x3f\xfb\x32\x2e\x12\x33\xbc" 905 + "\xab", 906 + .key_len = 97, 907 + .params = 908 + "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04" 909 + "\x00\x22", 910 + .param_len = 18, 911 + .m = 912 + "\xaa\xe7\xfd\x03\x26\xcb\x94\x71\xe4\xce\x0f\xc5\xff\xa6\x29\xa3" 913 + "\xe1\xcc\x4c\x35\x4e\xde\xca\x80\xab\x26\x0c\x25\xe6\x68\x11\xc2", 914 + .m_size = 32, 915 + .algo = OID_id_ecdsa_with_sha256, 916 + .c = 917 + "\x30\x64\x02\x30\x08\x09\x12\x9d\x6e\x96\x64\xa6\x8e\x3f\x7e\xce" 918 + "\x0a\x9b\xaa\x59\xcc\x47\x53\x87\xbc\xbd\x83\x3f\xaf\x06\x3f\x84" 919 + "\x04\xe2\xf9\x67\xb6\xc6\xfc\x70\x2e\x66\x3c\x77\xc8\x8d\x2c\x79" 920 + "\x3a\x8e\x32\xc4\x02\x30\x40\x34\xb8\x90\xa9\x80\xab\x47\x26\xa2" 921 + "\xb0\x89\x42\x0a\xda\xd9\xdd\xce\xbc\xb2\x97\xf4\x9c\xf3\x15\x68" 922 + "\xc0\x75\x3e\x23\x5e\x36\x4f\x8d\xde\x1e\x93\x8d\x95\xbb\x10\x0e" 923 + "\xf4\x1f\x39\xca\x4d\x43", 924 + .c_size = 102, 925 + .public_key_vec = true, 926 + .siggen_sigver_test = true, 927 + }, { 928 + .key = /* secp384r1(sha384) */ 929 + "\x04\x3a\x2f\x62\xe7\x1a\xcf\x24\xd0\x0b\x7c\xe0\xed\x46\x0a\x4f" 930 + "\x74\x16\x43\xe9\x1a\x25\x7c\x55\xff\xf0\x29\x68\x66\x20\x91\xf9" 931 + "\xdb\x2b\xf6\xb3\x6c\x54\x01\xca\xc7\x6a\x5c\x0d\xeb\x68\xd9\x3c" 932 + "\xf1\x01\x74\x1f\xf9\x6c\xe5\x5b\x60\xe9\x7f\x5d\xb3\x12\x80\x2a" 933 + "\xd8\x67\x92\xc9\x0e\x4c\x4c\x6b\xa1\xb2\xa8\x1e\xac\x1c\x97\xd9" 934 + "\x21\x67\xe5\x1b\x5a\x52\x31\x68\xd6\xee\xf0\x19\xb0\x55\xed\x89" 935 + "\x9e", 936 + .key_len = 97, 937 + .params = 938 + "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04" 939 + "\x00\x22", 940 + .param_len = 18, 941 + .m = 942 + "\x8d\xf2\xc0\xe9\xa8\xf3\x8e\x44\xc4\x8c\x1a\xa0\xb8\xd7\x17\xdf" 943 + "\xf2\x37\x1b\xc6\xe3\xf5\x62\xcc\x68\xf5\xd5\x0b\xbf\x73\x2b\xb1" 944 + "\xb0\x4c\x04\x00\x31\xab\xfe\xc8\xd6\x09\xc8\xf2\xea\xd3\x28\xff", 945 + .m_size = 48, 946 + .algo = OID_id_ecdsa_with_sha384, 947 + .c = 948 + "\x30\x66\x02\x31\x00\x9b\x28\x68\xc0\xa1\xea\x8c\x50\xee\x2e\x62" 949 + "\x35\x46\xfa\x00\xd8\x2d\x7a\x91\x5f\x49\x2d\x22\x08\x29\xe6\xfb" 950 + "\xca\x8c\xd6\xb6\xb4\x3b\x1f\x07\x8f\x15\x02\xfe\x1d\xa2\xa4\xc8" 951 + "\xf2\xea\x9d\x11\x1f\x02\x31\x00\xfc\x50\xf6\x43\xbd\x50\x82\x0e" 952 + "\xbf\xe3\x75\x24\x49\xac\xfb\xc8\x71\xcd\x8f\x18\x99\xf0\x0f\x13" 953 + "\x44\x92\x8c\x86\x99\x65\xb3\x97\x96\x17\x04\xc9\x05\x77\xf1\x8e" 954 + "\xab\x8d\x4e\xde\xe6\x6d\x9b\x66", 955 + .c_size = 104, 956 + .public_key_vec = true, 957 + .siggen_sigver_test = true, 958 + }, { 959 + .key = /* secp384r1(sha512) */ 960 + "\x04\xb4\xe7\xc1\xeb\x64\x25\x22\x46\xc3\x86\x61\x80\xbe\x1e\x46" 961 + "\xcb\xf6\x05\xc2\xee\x73\x83\xbc\xea\x30\x61\x4d\x40\x05\x41\xf4" 962 + "\x8c\xe3\x0e\x5c\xf0\x50\xf2\x07\x19\xe8\x4f\x25\xbe\xee\x0c\x95" 963 + "\x54\x36\x86\xec\xc2\x20\x75\xf3\x89\xb5\x11\xa1\xb7\xf5\xaf\xbe" 964 + "\x81\xe4\xc3\x39\x06\xbd\xe4\xfe\x68\x1c\x6d\x99\x2b\x1b\x63\xfa" 965 + "\xdf\x42\x5c\xc2\x5a\xc7\x0c\xf4\x15\xf7\x1b\xa3\x2e\xd7\x00\xac" 966 + "\xa3", 967 + .key_len = 97, 968 + .params = 969 + "\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04" 970 + "\x00\x22", 971 + .param_len = 18, 972 + .m = 973 + "\xe8\xb7\x52\x7d\x1a\x44\x20\x05\x53\x6b\x3a\x68\xf2\xe7\x6c\xa1" 974 + "\xae\x9d\x84\xbb\xba\x52\x43\x3e\x2c\x42\x78\x49\xbf\x78\xb2\x71" 975 + "\xeb\xe1\xe0\xe8\x42\x7b\x11\xad\x2b\x99\x05\x1d\x36\xe6\xac\xfc" 976 + "\x55\x73\xf0\x15\x63\x39\xb8\x6a\x6a\xc5\x91\x5b\xca\x6a\xa8\x0e", 977 + .m_size = 64, 978 + .algo = OID_id_ecdsa_with_sha512, 979 + .c = 980 + "\x30\x63\x02\x2f\x1d\x20\x94\x77\xfe\x31\xfa\x4d\xc6\xef\xda\x02" 981 + "\xe7\x0f\x52\x9a\x02\xde\x93\xe8\x83\xe4\x84\x4c\xfc\x6f\x80\xe3" 982 + "\xaf\xb3\xd9\xdc\x2b\x43\x0e\x6a\xb3\x53\x6f\x3e\xb3\xc7\xa8\xb3" 983 + "\x17\x77\xd1\x02\x30\x63\xf6\xf0\x3d\x5f\x5f\x99\x3f\xde\x3a\x3d" 984 + "\x16\xaf\xb4\x52\x6a\xec\x63\xe3\x0c\xec\x50\xdc\xcc\xc4\x6a\x03" 985 + "\x5f\x8d\x7a\xf9\xfb\x34\xe4\x8b\x80\xa5\xb6\xda\x2c\x4e\x45\xcf" 986 + "\x3c\x93\xff\x50\x5d", 987 + .c_size = 101, 988 + .public_key_vec = true, 989 + .siggen_sigver_test = true, 990 + }, 991 + }; 992 + 993 + /* 570 994 * EC-RDSA test vectors are generated by gost-engine. 571 995 */ 572 996 static const struct akcipher_testvec ecrdsa_tv_template[] = { ··· 2685 2261 } 2686 2262 }; 2687 2263 2688 - static const struct kpp_testvec ecdh_tv_template[] = { 2689 - { 2690 2264 #ifndef CONFIG_CRYPTO_FIPS 2265 + static const struct kpp_testvec ecdh_p192_tv_template[] = { 2266 + { 2691 2267 .secret = 2692 2268 #ifdef __LITTLE_ENDIAN 2693 2269 "\x02\x00" /* type */ 2694 - "\x20\x00" /* len */ 2695 - "\x01\x00" /* curve_id */ 2270 + "\x1e\x00" /* len */ 2696 2271 "\x18\x00" /* key_size */ 2697 2272 #else 2698 2273 "\x00\x02" /* type */ 2699 - "\x00\x20" /* len */ 2700 - "\x00\x01" /* curve_id */ 2274 + "\x00\x1e" /* len */ 2701 2275 "\x00\x18" /* key_size */ 2702 2276 #endif 2703 2277 "\xb5\x05\xb1\x71\x1e\xbf\x8c\xda" ··· 2723 2301 .b_public_size = 48, 2724 2302 .expected_a_public_size = 48, 2725 2303 .expected_ss_size = 24 2726 - }, { 2304 + } 2305 + }; 2727 2306 #endif 2307 + 2308 + static const struct kpp_testvec ecdh_p256_tv_template[] = { 2309 + { 2728 2310 .secret = 2729 2311 #ifdef __LITTLE_ENDIAN 2730 2312 "\x02\x00" /* type */ 2731 - "\x28\x00" /* len */ 2732 - "\x02\x00" /* curve_id */ 2313 + "\x26\x00" /* len */ 2733 2314 "\x20\x00" /* key_size */ 2734 2315 #else 2735 2316 "\x00\x02" /* type */ 2736 - "\x00\x28" /* len */ 2737 - "\x00\x02" /* curve_id */ 2317 + "\x00\x26" /* len */ 2738 2318 "\x00\x20" /* key_size */ 2739 2319 #endif 2740 2320 "\x24\xd1\x21\xeb\xe5\xcf\x2d\x83" ··· 2774 2350 .secret = 2775 2351 #ifdef __LITTLE_ENDIAN 2776 2352 "\x02\x00" /* type */ 2777 - "\x08\x00" /* len */ 2778 - "\x02\x00" /* curve_id */ 2353 + "\x06\x00" /* len */ 2779 2354 "\x00\x00", /* key_size */ 2780 2355 #else 2781 2356 "\x00\x02" /* type */ 2782 - "\x00\x08" /* len */ 2783 - "\x00\x02" /* curve_id */ 2357 + "\x00\x06" /* len */ 2784 2358 "\x00\x00", /* key_size */ 2785 2359 #endif 2786 2360 .b_secret = 2787 2361 #ifdef __LITTLE_ENDIAN 2788 2362 "\x02\x00" /* type */ 2789 - "\x28\x00" /* len */ 2790 - "\x02\x00" /* curve_id */ 2363 + "\x26\x00" /* len */ 2791 2364 "\x20\x00" /* key_size */ 2792 2365 #else 2793 2366 "\x00\x02" /* type */ 2794 - "\x00\x28" /* len */ 2795 - "\x00\x02" /* curve_id */ 2367 + "\x00\x26" /* len */ 2796 2368 "\x00\x20" /* key_size */ 2797 2369 #endif 2798 2370 "\x24\xd1\x21\xeb\xe5\xcf\x2d\x83"
+2 -14
drivers/char/hw_random/ba431-rng.c
··· 170 170 static int ba431_trng_probe(struct platform_device *pdev) 171 171 { 172 172 struct ba431_trng *ba431; 173 - struct resource *res; 174 173 int ret; 175 174 176 175 ba431 = devm_kzalloc(&pdev->dev, sizeof(*ba431), GFP_KERNEL); ··· 178 179 179 180 ba431->dev = &pdev->dev; 180 181 181 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 182 - ba431->base = devm_ioremap_resource(&pdev->dev, res); 182 + ba431->base = devm_platform_ioremap_resource(pdev, 0); 183 183 if (IS_ERR(ba431->base)) 184 184 return PTR_ERR(ba431->base); 185 185 ··· 191 193 192 194 platform_set_drvdata(pdev, ba431); 193 195 194 - ret = hwrng_register(&ba431->rng); 196 + ret = devm_hwrng_register(&pdev->dev, &ba431->rng); 195 197 if (ret) { 196 198 dev_err(&pdev->dev, "BA431 registration failed (%d)\n", ret); 197 199 return ret; 198 200 } 199 201 200 202 dev_info(&pdev->dev, "BA431 TRNG registered\n"); 201 - 202 - return 0; 203 - } 204 - 205 - static int ba431_trng_remove(struct platform_device *pdev) 206 - { 207 - struct ba431_trng *ba431 = platform_get_drvdata(pdev); 208 - 209 - hwrng_unregister(&ba431->rng); 210 203 211 204 return 0; 212 205 } ··· 214 225 .of_match_table = ba431_trng_dt_ids, 215 226 }, 216 227 .probe = ba431_trng_probe, 217 - .remove = ba431_trng_remove, 218 228 }; 219 229 220 230 module_platform_driver(ba431_trng_driver);
+17 -10
drivers/char/hw_random/bcm2835-rng.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/printk.h> 15 15 #include <linux/clk.h> 16 + #include <linux/reset.h> 16 17 17 18 #define RNG_CTRL 0x0 18 19 #define RNG_STATUS 0x4 ··· 33 32 void __iomem *base; 34 33 bool mask_interrupts; 35 34 struct clk *clk; 35 + struct reset_control *reset; 36 36 }; 37 37 38 38 static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) ··· 90 88 int ret = 0; 91 89 u32 val; 92 90 93 - if (!IS_ERR(priv->clk)) { 94 - ret = clk_prepare_enable(priv->clk); 95 - if (ret) 96 - return ret; 97 - } 91 + ret = clk_prepare_enable(priv->clk); 92 + if (ret) 93 + return ret; 94 + 95 + ret = reset_control_reset(priv->reset); 96 + if (ret) 97 + return ret; 98 98 99 99 if (priv->mask_interrupts) { 100 100 /* mask the interrupt */ ··· 119 115 /* disable rng hardware */ 120 116 rng_writel(priv, 0, RNG_CTRL); 121 117 122 - if (!IS_ERR(priv->clk)) 123 - clk_disable_unprepare(priv->clk); 118 + clk_disable_unprepare(priv->clk); 124 119 } 125 120 126 121 struct bcm2835_rng_of_data { ··· 158 155 return PTR_ERR(priv->base); 159 156 160 157 /* Clock is optional on most platforms */ 161 - priv->clk = devm_clk_get(dev, NULL); 162 - if (PTR_ERR(priv->clk) == -EPROBE_DEFER) 163 - return -EPROBE_DEFER; 158 + priv->clk = devm_clk_get_optional(dev, NULL); 159 + if (IS_ERR(priv->clk)) 160 + return PTR_ERR(priv->clk); 161 + 162 + priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL); 163 + if (IS_ERR(priv->reset)) 164 + return PTR_ERR(priv->reset); 164 165 165 166 priv->rng.name = pdev->name; 166 167 priv->rng.init = bcm2835_rng_init;
+3 -17
drivers/char/hw_random/cctrng.c
··· 486 486 487 487 static int cctrng_probe(struct platform_device *pdev) 488 488 { 489 - struct resource *req_mem_cc_regs = NULL; 490 489 struct cctrng_drvdata *drvdata; 491 490 struct device *dev = &pdev->dev; 492 491 int rc = 0; ··· 509 510 510 511 drvdata->circ.buf = (char *)drvdata->data_buf; 511 512 512 - /* Get device resources */ 513 - /* First CC registers space */ 514 - req_mem_cc_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 515 - /* Map registers space */ 516 - drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs); 513 + drvdata->cc_base = devm_platform_ioremap_resource(pdev, 0); 517 514 if (IS_ERR(drvdata->cc_base)) { 518 515 dev_err(dev, "Failed to ioremap registers"); 519 516 return PTR_ERR(drvdata->cc_base); 520 517 } 521 518 522 - dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name, 523 - req_mem_cc_regs); 524 - dev_dbg(dev, "CC registers mapped from %pa to 0x%p\n", 525 - &req_mem_cc_regs->start, drvdata->cc_base); 526 - 527 519 /* Then IRQ */ 528 520 irq = platform_get_irq(pdev, 0); 529 - if (irq < 0) { 530 - dev_err(dev, "Failed getting IRQ resource\n"); 521 + if (irq < 0) 531 522 return irq; 532 - } 533 523 534 524 /* parse sampling rate from device tree */ 535 525 rc = cc_trng_parse_sampling_ratio(drvdata); ··· 573 585 atomic_set(&drvdata->pending_hw, 1); 574 586 575 587 /* registration of the hwrng device */ 576 - rc = hwrng_register(&drvdata->rng); 588 + rc = devm_hwrng_register(dev, &drvdata->rng); 577 589 if (rc) { 578 590 dev_err(dev, "Could not register hwrng device.\n"); 579 591 goto post_pm_err; ··· 605 617 struct device *dev = &pdev->dev; 606 618 607 619 dev_dbg(dev, "Releasing cctrng resources...\n"); 608 - 609 - hwrng_unregister(&drvdata->rng); 610 620 611 621 cc_trng_pm_fini(drvdata); 612 622
+1 -1
drivers/char/hw_random/core.c
··· 396 396 struct device_attribute *attr, 397 397 char *buf) 398 398 { 399 - return snprintf(buf, PAGE_SIZE, "%d\n", cur_rng_set_by_user); 399 + return sysfs_emit(buf, "%d\n", cur_rng_set_by_user); 400 400 } 401 401 402 402 static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR,
+1 -1
drivers/char/hw_random/intel-rng.c
··· 25 25 */ 26 26 27 27 #include <linux/hw_random.h> 28 + #include <linux/io.h> 28 29 #include <linux/kernel.h> 29 30 #include <linux/module.h> 30 31 #include <linux/pci.h> 31 32 #include <linux/stop_machine.h> 32 33 #include <linux/delay.h> 33 34 #include <linux/slab.h> 34 - #include <asm/io.h> 35 35 36 36 37 37 #define PFX KBUILD_MODNAME ": "
+5 -9
drivers/char/hw_random/omap-rng.c
··· 30 30 #include <linux/of_address.h> 31 31 #include <linux/interrupt.h> 32 32 #include <linux/clk.h> 33 - 34 - #include <asm/io.h> 33 + #include <linux/io.h> 35 34 36 35 #define RNG_REG_STATUS_RDY (1 << 0) 37 36 ··· 377 378 static int of_get_omap_rng_device_details(struct omap_rng_dev *priv, 378 379 struct platform_device *pdev) 379 380 { 380 - const struct of_device_id *match; 381 381 struct device *dev = &pdev->dev; 382 382 int irq, err; 383 383 384 - match = of_match_device(of_match_ptr(omap_rng_of_match), dev); 385 - if (!match) { 386 - dev_err(dev, "no compatible OF match\n"); 387 - return -EINVAL; 388 - } 389 - priv->pdata = match->data; 384 + priv->pdata = of_device_get_match_data(dev); 385 + if (!priv->pdata) 386 + return -ENODEV; 387 + 390 388 391 389 if (of_device_is_compatible(dev->of_node, "ti,omap4-rng") || 392 390 of_device_is_compatible(dev->of_node, "inside-secure,safexcel-eip76")) {
+1 -2
drivers/char/hw_random/pic32-rng.c
··· 96 96 priv->rng.name = pdev->name; 97 97 priv->rng.read = pic32_rng_read; 98 98 99 - ret = hwrng_register(&priv->rng); 99 + ret = devm_hwrng_register(&pdev->dev, &priv->rng); 100 100 if (ret) 101 101 goto err_register; 102 102 ··· 113 113 { 114 114 struct pic32_rng *rng = platform_get_drvdata(pdev); 115 115 116 - hwrng_unregister(&rng->rng); 117 116 writel(0, rng->base + RNGCON); 118 117 clk_disable_unprepare(rng->clk); 119 118 return 0;
+1 -3
drivers/char/hw_random/xiphera-trng.c
··· 63 63 int ret; 64 64 struct xiphera_trng *trng; 65 65 struct device *dev = &pdev->dev; 66 - struct resource *res; 67 66 68 67 trng = devm_kzalloc(dev, sizeof(*trng), GFP_KERNEL); 69 68 if (!trng) 70 69 return -ENOMEM; 71 70 72 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 73 - trng->mem = devm_ioremap_resource(dev, res); 71 + trng->mem = devm_platform_ioremap_resource(pdev, 0); 74 72 if (IS_ERR(trng->mem)) 75 73 return PTR_ERR(trng->mem); 76 74
+5 -16
drivers/char/random.c
··· 500 500 unsigned short add_ptr; 501 501 unsigned short input_rotate; 502 502 int entropy_count; 503 - unsigned int initialized:1; 504 503 unsigned int last_data_init:1; 505 504 __u8 last_data[EXTRACT_SIZE]; 506 505 }; ··· 659 660 */ 660 661 static void credit_entropy_bits(struct entropy_store *r, int nbits) 661 662 { 662 - int entropy_count, orig, has_initialized = 0; 663 + int entropy_count, orig; 663 664 const int pool_size = r->poolinfo->poolfracbits; 664 665 int nfrac = nbits << ENTROPY_SHIFT; 665 666 ··· 716 717 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) 717 718 goto retry; 718 719 719 - if (has_initialized) { 720 - r->initialized = 1; 721 - kill_fasync(&fasync, SIGIO, POLL_IN); 722 - } 723 - 724 720 trace_credit_entropy_bits(r->name, nbits, 725 721 entropy_count >> ENTROPY_SHIFT, _RET_IP_); 726 722 727 723 if (r == &input_pool) { 728 724 int entropy_bits = entropy_count >> ENTROPY_SHIFT; 729 725 730 - if (crng_init < 2) { 731 - if (entropy_bits < 128) 732 - return; 726 + if (crng_init < 2 && entropy_bits >= 128) 733 727 crng_reseed(&primary_crng, r); 734 - entropy_bits = ENTROPY_BITS(r); 735 - } 736 728 } 737 729 } 738 730 ··· 809 819 810 820 static void __maybe_unused crng_initialize_secondary(struct crng_state *crng) 811 821 { 812 - memcpy(&crng->state[0], "expand 32-byte k", 16); 822 + chacha_init_consts(crng->state); 813 823 _get_random_bytes(&crng->state[4], sizeof(__u32) * 12); 814 824 crng_init_try_arch(crng); 815 825 crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1; ··· 817 827 818 828 static void __init crng_initialize_primary(struct crng_state *crng) 819 829 { 820 - memcpy(&crng->state[0], "expand 32-byte k", 16); 830 + chacha_init_consts(crng->state); 821 831 _extract_entropy(&input_pool, &crng->state[4], sizeof(__u32) * 12, 0); 822 832 if (crng_init_try_arch_early(crng) && trust_cpu) { 823 833 invalidate_batched_entropy(); ··· 1362 1372 } 1363 1373 1364 1374 /* 1365 - * This function does the actual extraction for extract_entropy and 1366 - * extract_entropy_user. 1375 + * This function does the actual extraction for extract_entropy. 1367 1376 * 1368 1377 * Note: we assume that .poolwords is a multiple of 16 words. 1369 1378 */
+7 -7
drivers/crypto/allwinner/Kconfig
··· 71 71 config CRYPTO_DEV_SUN8I_CE_HASH 72 72 bool "Enable support for hash on sun8i-ce" 73 73 depends on CRYPTO_DEV_SUN8I_CE 74 - select MD5 75 - select SHA1 76 - select SHA256 77 - select SHA512 74 + select CRYPTO_MD5 75 + select CRYPTO_SHA1 76 + select CRYPTO_SHA256 77 + select CRYPTO_SHA512 78 78 help 79 79 Say y to enable support for hash algorithms. 80 80 ··· 132 132 config CRYPTO_DEV_SUN8I_SS_HASH 133 133 bool "Enable support for hash on sun8i-ss" 134 134 depends on CRYPTO_DEV_SUN8I_SS 135 - select MD5 136 - select SHA1 137 - select SHA256 135 + select CRYPTO_MD5 136 + select CRYPTO_SHA1 137 + select CRYPTO_SHA256 138 138 help 139 139 Say y to enable support for hash algorithms.
+1 -1
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
··· 561 561 sizeof(struct sun4i_cipher_req_ctx) + 562 562 crypto_skcipher_reqsize(op->fallback_tfm)); 563 563 564 - err = pm_runtime_get_sync(op->ss->dev); 564 + err = pm_runtime_resume_and_get(op->ss->dev); 565 565 if (err < 0) 566 566 goto error_pm; 567 567
+9 -14
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
··· 288 288 { 289 289 struct sun4i_ss_ctx *ss = dev_get_drvdata(dev); 290 290 291 - if (ss->reset) 292 - reset_control_assert(ss->reset); 291 + reset_control_assert(ss->reset); 293 292 294 293 clk_disable_unprepare(ss->ssclk); 295 294 clk_disable_unprepare(ss->busclk); ··· 313 314 goto err_enable; 314 315 } 315 316 316 - if (ss->reset) { 317 - err = reset_control_deassert(ss->reset); 318 - if (err) { 319 - dev_err(ss->dev, "Cannot deassert reset control\n"); 320 - goto err_enable; 321 - } 317 + err = reset_control_deassert(ss->reset); 318 + if (err) { 319 + dev_err(ss->dev, "Cannot deassert reset control\n"); 320 + goto err_enable; 322 321 } 323 322 324 323 return err; ··· 398 401 dev_dbg(&pdev->dev, "clock ahb_ss acquired\n"); 399 402 400 403 ss->reset = devm_reset_control_get_optional(&pdev->dev, "ahb"); 401 - if (IS_ERR(ss->reset)) { 402 - if (PTR_ERR(ss->reset) == -EPROBE_DEFER) 403 - return PTR_ERR(ss->reset); 404 + if (IS_ERR(ss->reset)) 405 + return PTR_ERR(ss->reset); 406 + if (!ss->reset) 404 407 dev_info(&pdev->dev, "no reset control found\n"); 405 - ss->reset = NULL; 406 - } 407 408 408 409 /* 409 410 * Check that clock have the correct rates given in the datasheet ··· 454 459 * this info could be useful 455 460 */ 456 461 457 - err = pm_runtime_get_sync(ss->dev); 462 + err = pm_runtime_resume_and_get(ss->dev); 458 463 if (err < 0) 459 464 goto error_pm; 460 465
+1 -1
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c
··· 27 27 algt = container_of(alg, struct sun4i_ss_alg_template, alg.hash); 28 28 op->ss = algt->ss; 29 29 30 - err = pm_runtime_get_sync(op->ss->dev); 30 + err = pm_runtime_resume_and_get(op->ss->dev); 31 31 if (err < 0) 32 32 return err; 33 33
+1 -1
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
··· 29 29 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng); 30 30 ss = algt->ss; 31 31 32 - err = pm_runtime_get_sync(ss->dev); 32 + err = pm_runtime_resume_and_get(ss->dev); 33 33 if (err < 0) 34 34 return err; 35 35
+6 -3
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
··· 240 240 241 241 theend_sgs: 242 242 if (areq->src == areq->dst) { 243 - dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL); 243 + dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src), 244 + DMA_BIDIRECTIONAL); 244 245 } else { 245 246 if (nr_sgs > 0) 246 - dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 247 - dma_unmap_sg(ce->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE); 247 + dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src), 248 + DMA_TO_DEVICE); 249 + dma_unmap_sg(ce->dev, areq->dst, sg_nents(areq->dst), 250 + DMA_FROM_DEVICE); 248 251 } 249 252 250 253 theend_iv:
+1 -1
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c
··· 932 932 if (err) 933 933 goto error_alg; 934 934 935 - err = pm_runtime_get_sync(ce->dev); 935 + err = pm_runtime_resume_and_get(ce->dev); 936 936 if (err < 0) 937 937 goto error_alg; 938 938
+2 -1
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
··· 405 405 err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(areq->base.tfm)); 406 406 407 407 dma_unmap_single(ce->dev, addr_pad, j * 4, DMA_TO_DEVICE); 408 - dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 408 + dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src), 409 + DMA_TO_DEVICE); 409 410 dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE); 410 411 411 412
+1
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
··· 99 99 dma_iv = dma_map_single(ce->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE); 100 100 if (dma_mapping_error(ce->dev, dma_iv)) { 101 101 dev_err(ce->dev, "Cannot DMA MAP IV\n"); 102 + err = -EFAULT; 102 103 goto err_iv; 103 104 } 104 105
+7 -4
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
··· 232 232 233 233 theend_sgs: 234 234 if (areq->src == areq->dst) { 235 - dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL); 235 + dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src), 236 + DMA_BIDIRECTIONAL); 236 237 } else { 237 - dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 238 - dma_unmap_sg(ss->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE); 238 + dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src), 239 + DMA_TO_DEVICE); 240 + dma_unmap_sg(ss->dev, areq->dst, sg_nents(areq->dst), 241 + DMA_FROM_DEVICE); 239 242 } 240 243 241 244 theend_iv: ··· 354 351 op->enginectx.op.prepare_request = NULL; 355 352 op->enginectx.op.unprepare_request = NULL; 356 353 357 - err = pm_runtime_get_sync(op->ss->dev); 354 + err = pm_runtime_resume_and_get(op->ss->dev); 358 355 if (err < 0) { 359 356 dev_err(op->ss->dev, "pm error %d\n", err); 360 357 goto error_pm;
+1 -1
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-core.c
··· 753 753 if (err) 754 754 goto error_alg; 755 755 756 - err = pm_runtime_get_sync(ss->dev); 756 + err = pm_runtime_resume_and_get(ss->dev); 757 757 if (err < 0) 758 758 goto error_alg; 759 759
+7 -5
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
··· 348 348 bf = (__le32 *)pad; 349 349 350 350 result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); 351 - if (!result) 351 + if (!result) { 352 + kfree(pad); 352 353 return -ENOMEM; 354 + } 353 355 354 356 for (i = 0; i < MAX_SG; i++) { 355 357 rctx->t_dst[i].addr = 0; ··· 434 432 err = sun8i_ss_run_hash_task(ss, rctx, crypto_tfm_alg_name(areq->base.tfm)); 435 433 436 434 dma_unmap_single(ss->dev, addr_pad, j * 4, DMA_TO_DEVICE); 437 - dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 435 + dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src), 436 + DMA_TO_DEVICE); 438 437 dma_unmap_single(ss->dev, addr_res, digestsize, DMA_FROM_DEVICE); 439 438 440 - kfree(pad); 441 - 442 439 memcpy(areq->result, result, algt->alg.hash.halg.digestsize); 443 - kfree(result); 444 440 theend: 441 + kfree(pad); 442 + kfree(result); 445 443 crypto_finalize_hash_request(engine, breq, err); 446 444 return 0; 447 445 }
+3 -1
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
··· 103 103 dma_iv = dma_map_single(ss->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE); 104 104 if (dma_mapping_error(ss->dev, dma_iv)) { 105 105 dev_err(ss->dev, "Cannot DMA MAP IV\n"); 106 - return -EFAULT; 106 + err = -EFAULT; 107 + goto err_free; 107 108 } 108 109 109 110 dma_dst = dma_map_single(ss->dev, d, todo, DMA_FROM_DEVICE); ··· 168 167 memcpy(ctx->seed, d + dlen, ctx->slen); 169 168 } 170 169 memzero_explicit(d, todo); 170 + err_free: 171 171 kfree(d); 172 172 173 173 return err;
+6 -6
drivers/crypto/amcc/crypto4xx_alg.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation. ··· 115 115 return crypto4xx_crypt(req, AES_IV_SIZE, true, true); 116 116 } 117 117 118 - /** 118 + /* 119 119 * AES Functions 120 120 */ 121 121 static int crypto4xx_setkey_aes(struct crypto_skcipher *cipher, ··· 374 374 return crypto_aead_setkey(ctx->sw_cipher.aead, key, keylen); 375 375 } 376 376 377 - /** 377 + /* 378 378 * AES-CCM Functions 379 379 */ 380 380 ··· 489 489 return crypto_aead_setauthsize(ctx->sw_cipher.aead, authsize); 490 490 } 491 491 492 - /** 492 + /* 493 493 * AES-GCM Functions 494 494 */ 495 495 ··· 617 617 return crypto4xx_crypt_aes_gcm(req, true); 618 618 } 619 619 620 - /** 620 + /* 621 621 * HASH SHA1 Functions 622 622 */ 623 623 static int crypto4xx_hash_alg_init(struct crypto_tfm *tfm, ··· 711 711 ctx->sa_len, 0, NULL); 712 712 } 713 713 714 - /** 714 + /* 715 715 * SHA1 Algorithm 716 716 */ 717 717 int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm)
+9 -9
drivers/crypto/amcc/crypto4xx_core.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation. ··· 44 44 45 45 #define PPC4XX_SEC_VERSION_STR "0.5" 46 46 47 - /** 47 + /* 48 48 * PPC4xx Crypto Engine Initialization Routine 49 49 */ 50 50 static void crypto4xx_hw_init(struct crypto4xx_device *dev) ··· 159 159 ctx->sa_len = 0; 160 160 } 161 161 162 - /** 162 + /* 163 163 * alloc memory for the gather ring 164 164 * no need to alloc buf for the ring 165 165 * gdr_tail, gdr_head and gdr_count are initialized by this function ··· 268 268 return tail; 269 269 } 270 270 271 - /** 271 + /* 272 272 * alloc memory for the gather ring 273 273 * no need to alloc buf for the ring 274 274 * gdr_tail, gdr_head and gdr_count are initialized by this function ··· 346 346 return &dev->gdr[idx]; 347 347 } 348 348 349 - /** 349 + /* 350 350 * alloc memory for the scatter ring 351 351 * need to alloc buf for the ring 352 352 * sdr_tail, sdr_head and sdr_count are initialized by this function ··· 930 930 return is_busy ? -EBUSY : -EINPROGRESS; 931 931 } 932 932 933 - /** 933 + /* 934 934 * Algorithm Registration Functions 935 935 */ 936 936 static void crypto4xx_ctx_init(struct crypto4xx_alg *amcc_alg, ··· 1097 1097 } while (head != tail); 1098 1098 } 1099 1099 1100 - /** 1100 + /* 1101 1101 * Top Half of isr. 1102 1102 */ 1103 1103 static inline irqreturn_t crypto4xx_interrupt_handler(int irq, void *data, ··· 1186 1186 return 0; 1187 1187 } 1188 1188 1189 - /** 1189 + /* 1190 1190 * Supported Crypto Algorithms 1191 1191 */ 1192 1192 static struct crypto4xx_alg_common crypto4xx_alg[] = { ··· 1369 1369 } }, 1370 1370 }; 1371 1371 1372 - /** 1372 + /* 1373 1373 * Module Initialization Routine 1374 1374 */ 1375 1375 static int crypto4xx_probe(struct platform_device *ofdev)
+2 -2
drivers/crypto/amcc/crypto4xx_core.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation. ··· 188 188 int crypto4xx_hash_update(struct ahash_request *req); 189 189 int crypto4xx_hash_init(struct ahash_request *req); 190 190 191 - /** 191 + /* 192 192 * Note: Only use this function to copy items that is word aligned. 193 193 */ 194 194 static inline void crypto4xx_memcpy_swab32(u32 *dst, const void *buf,
+4 -4
drivers/crypto/amcc/crypto4xx_reg_def.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation. ··· 104 104 #define CRYPTO4XX_PRNG_LFSR_L 0x00070030 105 105 #define CRYPTO4XX_PRNG_LFSR_H 0x00070034 106 106 107 - /** 107 + /* 108 108 * Initialize CRYPTO ENGINE registers, and memory bases. 109 109 */ 110 110 #define PPC4XX_PDR_POLL 0x3ff ··· 123 123 #define PPC4XX_INT_TIMEOUT_CNT 0 124 124 #define PPC4XX_INT_TIMEOUT_CNT_REVB 0x3FF 125 125 #define PPC4XX_INT_CFG 1 126 - /** 126 + /* 127 127 * all follow define are ad hoc 128 128 */ 129 129 #define PPC4XX_RING_RETRY 100 ··· 131 131 #define PPC4XX_SDR_SIZE PPC4XX_NUM_SD 132 132 #define PPC4XX_GDR_SIZE PPC4XX_NUM_GD 133 133 134 - /** 134 + /* 135 135 * Generic Security Association (SA) with all possible fields. These will 136 136 * never likely used except for reference purpose. These structure format 137 137 * can be not changed as the hardware expects them to be layout as defined.
+9 -9
drivers/crypto/amcc/crypto4xx_sa.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation. ··· 14 14 15 15 #define AES_IV_SIZE 16 16 16 17 - /** 17 + /* 18 18 * Contents of Dynamic Security Association (SA) with all possible fields 19 19 */ 20 20 union dynamic_sa_contents { ··· 122 122 #define SA_AES_KEY_LEN_256 4 123 123 124 124 #define SA_REV2 1 125 - /** 125 + /* 126 126 * The follow defines bits sa_command_1 127 127 * In Basic hash mode this bit define simple hash or hmac. 128 128 * In IPsec mode, this bit define muting control. ··· 172 172 union sa_command_1 sa_command_1; 173 173 } __attribute__((packed)); 174 174 175 - /** 175 + /* 176 176 * State Record for Security Association (SA) 177 177 */ 178 178 struct sa_state_record { ··· 184 184 }; 185 185 } __attribute__((packed)); 186 186 187 - /** 187 + /* 188 188 * Security Association (SA) for AES128 189 189 * 190 190 */ ··· 213 213 #define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4) 214 214 #define SA_AES192_CONTENTS 0x3e000062 215 215 216 - /** 216 + /* 217 217 * Security Association (SA) for AES256 218 218 */ 219 219 struct dynamic_sa_aes256 { ··· 228 228 #define SA_AES256_CONTENTS 0x3e000082 229 229 #define SA_AES_CONTENTS 0x3e000002 230 230 231 - /** 231 + /* 232 232 * Security Association (SA) for AES128 CCM 233 233 */ 234 234 struct dynamic_sa_aes128_ccm { ··· 242 242 #define SA_AES128_CCM_CONTENTS 0x3e000042 243 243 #define SA_AES_CCM_CONTENTS 0x3e000002 244 244 245 - /** 245 + /* 246 246 * Security Association (SA) for AES128_GCM 247 247 */ 248 248 struct dynamic_sa_aes128_gcm { ··· 258 258 #define SA_AES128_GCM_CONTENTS 0x3e000442 259 259 #define SA_AES_GCM_CONTENTS 0x3e000402 260 260 261 - /** 261 + /* 262 262 * Security Association (SA) for HASH160: HMAC-SHA1 263 263 */ 264 264 struct dynamic_sa_hash160 {
+1 -1
drivers/crypto/amcc/crypto4xx_trng.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /** 2 + /* 3 3 * AMCC SoC PPC4xx Crypto Driver 4 4 * 5 5 * Copyright (c) 2008 Applied Micro Circuits Corporation.
+3 -3
drivers/crypto/amlogic/amlogic-gxl-cipher.c
··· 236 236 dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); 237 237 238 238 if (areq->src == areq->dst) { 239 - dma_unmap_sg(mc->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL); 239 + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); 240 240 } else { 241 - dma_unmap_sg(mc->dev, areq->src, nr_sgs, DMA_TO_DEVICE); 242 - dma_unmap_sg(mc->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE); 241 + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); 242 + dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); 243 243 } 244 244 245 245 if (areq->iv && ivsize > 0) {
-3
drivers/crypto/amlogic/amlogic-gxl-core.c
··· 217 217 struct meson_dev *mc; 218 218 int err, i; 219 219 220 - if (!pdev->dev.of_node) 221 - return -ENODEV; 222 - 223 220 mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); 224 221 if (!mc) 225 222 return -ENOMEM;
+9 -21
drivers/crypto/atmel-ecc.c
··· 26 26 static struct atmel_ecc_driver_data driver_data; 27 27 28 28 /** 29 - * atmel_ecdh_ctx - transformation context 29 + * struct atmel_ecdh_ctx - transformation context 30 30 * @client : pointer to i2c client device 31 31 * @fallback : used for unsupported curves or when user wants to use its own 32 32 * private key. ··· 34 34 * of the user to not call set_secret() while 35 35 * generate_public_key() or compute_shared_secret() are in flight. 36 36 * @curve_id : elliptic curve id 37 - * @n_sz : size in bytes of the n prime 38 37 * @do_fallback: true when the device doesn't support the curve or when the user 39 38 * wants to use its own private key. 40 39 */ ··· 42 43 struct crypto_kpp *fallback; 43 44 const u8 *public_key; 44 45 unsigned int curve_id; 45 - size_t n_sz; 46 46 bool do_fallback; 47 47 }; 48 48 ··· 49 51 int status) 50 52 { 51 53 struct kpp_request *req = areq; 52 - struct atmel_ecdh_ctx *ctx = work_data->ctx; 53 54 struct atmel_i2c_cmd *cmd = &work_data->cmd; 54 55 size_t copied, n_sz; 55 56 ··· 56 59 goto free_work_data; 57 60 58 61 /* might want less than we've got */ 59 - n_sz = min_t(size_t, ctx->n_sz, req->dst_len); 62 + n_sz = min_t(size_t, ATMEL_ECC_NIST_P256_N_SIZE, req->dst_len); 60 63 61 64 /* copy the shared secret */ 62 65 copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst, n_sz), ··· 68 71 free_work_data: 69 72 kfree_sensitive(work_data); 70 73 kpp_request_complete(req, status); 71 - } 72 - 73 - static unsigned int atmel_ecdh_supported_curve(unsigned int curve_id) 74 - { 75 - if (curve_id == ECC_CURVE_NIST_P256) 76 - return ATMEL_ECC_NIST_P256_N_SIZE; 77 - 78 - return 0; 79 74 } 80 75 81 76 /* ··· 93 104 return -EINVAL; 94 105 } 95 106 96 - ctx->n_sz = atmel_ecdh_supported_curve(params.curve_id); 97 - if (!ctx->n_sz || params.key_size) { 107 + if (params.key_size) { 98 108 /* fallback to ecdh software implementation */ 99 109 ctx->do_fallback = true; 100 110 return crypto_kpp_set_secret(ctx->fallback, buf, len); ··· 113 125 goto free_cmd; 114 126 115 127 ctx->do_fallback = false; 116 - ctx->curve_id = params.curve_id; 117 128 118 129 atmel_i2c_init_genkey_cmd(cmd, DATA_SLOT_2); 119 130 ··· 250 263 struct crypto_kpp *fallback; 251 264 struct atmel_ecdh_ctx *ctx = kpp_tfm_ctx(tfm); 252 265 266 + ctx->curve_id = ECC_CURVE_NIST_P256; 253 267 ctx->client = atmel_ecc_i2c_client_alloc(); 254 268 if (IS_ERR(ctx->client)) { 255 269 pr_err("tfm - i2c_client binding failed\n"); ··· 294 306 return ATMEL_ECC_PUBKEY_SIZE; 295 307 } 296 308 297 - static struct kpp_alg atmel_ecdh = { 309 + static struct kpp_alg atmel_ecdh_nist_p256 = { 298 310 .set_secret = atmel_ecdh_set_secret, 299 311 .generate_public_key = atmel_ecdh_generate_public_key, 300 312 .compute_shared_secret = atmel_ecdh_compute_shared_secret, ··· 303 315 .max_size = atmel_ecdh_max_size, 304 316 .base = { 305 317 .cra_flags = CRYPTO_ALG_NEED_FALLBACK, 306 - .cra_name = "ecdh", 318 + .cra_name = "ecdh-nist-p256", 307 319 .cra_driver_name = "atmel-ecdh", 308 320 .cra_priority = ATMEL_ECC_PRIORITY, 309 321 .cra_module = THIS_MODULE, ··· 328 340 &driver_data.i2c_client_list); 329 341 spin_unlock(&driver_data.i2c_list_lock); 330 342 331 - ret = crypto_register_kpp(&atmel_ecdh); 343 + ret = crypto_register_kpp(&atmel_ecdh_nist_p256); 332 344 if (ret) { 333 345 spin_lock(&driver_data.i2c_list_lock); 334 346 list_del(&i2c_priv->i2c_client_list_node); 335 347 spin_unlock(&driver_data.i2c_list_lock); 336 348 337 349 dev_err(&client->dev, "%s alg registration failed\n", 338 - atmel_ecdh.base.cra_driver_name); 350 + atmel_ecdh_nist_p256.base.cra_driver_name); 339 351 } else { 340 352 dev_info(&client->dev, "atmel ecc algorithms registered in /proc/crypto\n"); 341 353 } ··· 353 365 return -EBUSY; 354 366 } 355 367 356 - crypto_unregister_kpp(&atmel_ecdh); 368 + crypto_unregister_kpp(&atmel_ecdh_nist_p256); 357 369 358 370 spin_lock(&driver_data.i2c_list_lock); 359 371 list_del(&i2c_priv->i2c_client_list_node);
+1 -1
drivers/crypto/atmel-i2c.c
··· 339 339 } 340 340 341 341 if (bus_clk_rate > 1000000L) { 342 - dev_err(dev, "%d exceeds maximum supported clock frequency (1MHz)\n", 342 + dev_err(dev, "%u exceeds maximum supported clock frequency (1MHz)\n", 343 343 bus_clk_rate); 344 344 return -EINVAL; 345 345 }
+2 -2
drivers/crypto/atmel-sha.c
··· 434 434 435 435 ctx->flags = 0; 436 436 437 - dev_dbg(dd->dev, "init: digest size: %d\n", 437 + dev_dbg(dd->dev, "init: digest size: %u\n", 438 438 crypto_ahash_digestsize(tfm)); 439 439 440 440 switch (crypto_ahash_digestsize(tfm)) { ··· 1102 1102 struct atmel_sha_reqctx *ctx = ahash_request_ctx(req); 1103 1103 int err; 1104 1104 1105 - dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %d\n", 1105 + dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %u\n", 1106 1106 ctx->op, req->nbytes); 1107 1107 1108 1108 err = atmel_sha_hw_init(dd);
-1
drivers/crypto/atmel-tdes.c
··· 1217 1217 1218 1218 tdes_dd->io_base = devm_ioremap_resource(&pdev->dev, tdes_res); 1219 1219 if (IS_ERR(tdes_dd->io_base)) { 1220 - dev_err(dev, "can't ioremap\n"); 1221 1220 err = PTR_ERR(tdes_dd->io_base); 1222 1221 goto err_tasklet_kill; 1223 1222 }
+4 -3
drivers/crypto/bcm/cipher.c
··· 1019 1019 * a SPU response message for an AEAD request. Includes buffers to catch SPU 1020 1020 * message headers and the response data. 1021 1021 * @mssg: mailbox message containing the receive sg 1022 + * @req: Crypto API request 1022 1023 * @rctx: crypto request context 1023 1024 * @rx_frag_num: number of scatterlist elements required to hold the 1024 1025 * SPU response message ··· 2953 2952 2954 2953 /** 2955 2954 * rfc4543_gcm_esp_setkey() - setkey operation for RFC4543 variant of GCM/GMAC. 2956 - * cipher: AEAD structure 2957 - * key: Key followed by 4 bytes of salt 2958 - * keylen: Length of key plus salt, in bytes 2955 + * @cipher: AEAD structure 2956 + * @key: Key followed by 4 bytes of salt 2957 + * @keylen: Length of key plus salt, in bytes 2959 2958 * 2960 2959 * Extracts salt from key and stores it to be prepended to IV on each request. 2961 2960 * Digest is always 16 bytes
+8 -8
drivers/crypto/bcm/spu.c
··· 457 457 * @cipher_mode: Algo type 458 458 * @data_size: Length of plaintext (bytes) 459 459 * 460 - * @Return: Length of padding, in bytes 460 + * Return: Length of padding, in bytes 461 461 */ 462 462 u32 spum_gcm_ccm_pad_len(enum spu_cipher_mode cipher_mode, 463 463 unsigned int data_size) ··· 510 510 } 511 511 512 512 /** 513 - * spu_aead_ivlen() - Calculate the length of the AEAD IV to be included 513 + * spum_aead_ivlen() - Calculate the length of the AEAD IV to be included 514 514 * in a SPU request after the AAD and before the payload. 515 515 * @cipher_mode: cipher mode 516 - * @iv_ctr_len: initialization vector length in bytes 516 + * @iv_len: initialization vector length in bytes 517 517 * 518 518 * In Linux ~4.2 and later, the assoc_data sg includes the IV. So no need 519 519 * to include the IV as a separate field in the SPU request msg. ··· 543 543 /** 544 544 * spum_digest_size() - Determine the size of a hash digest to expect the SPU to 545 545 * return. 546 - * alg_digest_size: Number of bytes in the final digest for the given algo 547 - * alg: The hash algorithm 548 - * htype: Type of hash operation (init, update, full, etc) 546 + * @alg_digest_size: Number of bytes in the final digest for the given algo 547 + * @alg: The hash algorithm 548 + * @htype: Type of hash operation (init, update, full, etc) 549 549 * 550 550 * When doing incremental hashing for an algorithm with a truncated hash 551 551 * (e.g., SHA224), the SPU returns the full digest so that it can be fed back as ··· 580 580 * @aead_parms: Parameters related to AEAD operation 581 581 * @data_size: Length of data to be encrypted or authenticated. If AEAD, does 582 582 * not include length of AAD. 583 - 583 + * 584 584 * Return: the length of the SPU header in bytes. 0 if an error occurs. 585 585 */ 586 586 u32 spum_create_request(u8 *spu_hdr, ··· 911 911 * setkey() time in spu_cipher_req_init(). 912 912 * @spu_hdr: Start of the request message header (MH field) 913 913 * @spu_req_hdr_len: Length in bytes of the SPU request header 914 - * @isInbound: 0 encrypt, 1 decrypt 914 + * @is_inbound: 0 encrypt, 1 decrypt 915 915 * @cipher_parms: Parameters describing cipher operation to be performed 916 916 * @data_size: Length of the data in the BD field 917 917 *
+24 -19
drivers/crypto/bcm/spu2.c
··· 543 543 /** 544 544 * spu2_fmd_init() - At setkey time, initialize the fixed meta data for 545 545 * subsequent skcipher requests for this context. 546 - * @spu2_cipher_type: Cipher algorithm 546 + * @fmd: Start of FMD field to be written 547 + * @spu2_type: Cipher algorithm 547 548 * @spu2_mode: Cipher mode 548 549 * @cipher_key_len: Length of cipher key, in bytes 549 550 * @cipher_iv_len: Length of cipher initialization vector, in bytes ··· 599 598 * SPU request packet. 600 599 * @fmd: Start of FMD field to be written 601 600 * @is_inbound: true if decrypting. false if encrypting. 602 - * @authFirst: true if alg authenticates before encrypting 601 + * @auth_first: true if alg authenticates before encrypting 603 602 * @protocol: protocol selector 604 603 * @cipher_type: cipher algorithm 605 604 * @cipher_mode: cipher mode ··· 641 640 * spu2_fmd_ctrl1_write() - Write ctrl1 field in fixed metadata (FMD) field of 642 641 * SPU request packet. 643 642 * @fmd: Start of FMD field to be written 643 + * @is_inbound: true if decrypting. false if encrypting. 644 644 * @assoc_size: Length of additional associated data, in bytes 645 645 * @auth_key_len: Length of authentication key, in bytes 646 646 * @cipher_key_len: Length of cipher key, in bytes ··· 795 793 } 796 794 797 795 /** 798 - * spu_payload_length() - Given a SPU2 message header, extract the payload 796 + * spu2_payload_length() - Given a SPU2 message header, extract the payload 799 797 * length. 800 798 * @spu_hdr: Start of SPU message header (FMD) 801 799 * ··· 814 812 } 815 813 816 814 /** 817 - * spu_response_hdr_len() - Determine the expected length of a SPU response 815 + * spu2_response_hdr_len() - Determine the expected length of a SPU response 818 816 * header. 819 817 * @auth_key_len: Length of authentication key, in bytes 820 818 * @enc_key_len: Length of encryption key, in bytes 819 + * @is_hash: Unused 821 820 * 822 821 * For SPU2, includes just FMD. OMD is never requested. 823 822 * ··· 830 827 } 831 828 832 829 /** 833 - * spu_hash_pad_len() - Calculate the length of hash padding required to extend 830 + * spu2_hash_pad_len() - Calculate the length of hash padding required to extend 834 831 * data to a full block size. 835 832 * @hash_alg: hash algorithm 836 833 * @hash_mode: hash mode ··· 848 845 } 849 846 850 847 /** 851 - * spu2_gcm_ccm_padlen() - Determine the length of GCM/CCM padding for either 848 + * spu2_gcm_ccm_pad_len() - Determine the length of GCM/CCM padding for either 852 849 * the AAD field or the data. 850 + * @cipher_mode: Unused 851 + * @data_size: Unused 853 852 * 854 853 * Return: 0. Unlike SPU-M, SPU2 hardware does any GCM/CCM padding required. 855 854 */ ··· 862 857 } 863 858 864 859 /** 865 - * spu_assoc_resp_len() - Determine the size of the AAD2 buffer needed to catch 860 + * spu2_assoc_resp_len() - Determine the size of the AAD2 buffer needed to catch 866 861 * associated data in a SPU2 output packet. 867 862 * @cipher_mode: cipher mode 868 863 * @assoc_len: length of additional associated data, in bytes ··· 883 878 return resp_len; 884 879 } 885 880 886 - /* 887 - * spu_aead_ivlen() - Calculate the length of the AEAD IV to be included 881 + /** 882 + * spu2_aead_ivlen() - Calculate the length of the AEAD IV to be included 888 883 * in a SPU request after the AAD and before the payload. 889 884 * @cipher_mode: cipher mode 890 - * @iv_ctr_len: initialization vector length in bytes 885 + * @iv_len: initialization vector length in bytes 891 886 * 892 887 * For SPU2, AEAD IV is included in OMD and does not need to be repeated 893 888 * prior to the payload. ··· 914 909 /** 915 910 * spu2_digest_size() - Determine the size of a hash digest to expect the SPU to 916 911 * return. 917 - * alg_digest_size: Number of bytes in the final digest for the given algo 918 - * alg: The hash algorithm 919 - * htype: Type of hash operation (init, update, full, etc) 912 + * @alg_digest_size: Number of bytes in the final digest for the given algo 913 + * @alg: The hash algorithm 914 + * @htype: Type of hash operation (init, update, full, etc) 920 915 * 921 916 */ 922 917 u32 spu2_digest_size(u32 alg_digest_size, enum hash_alg alg, ··· 926 921 } 927 922 928 923 /** 929 - * spu_create_request() - Build a SPU2 request message header, includint FMD and 924 + * spu2_create_request() - Build a SPU2 request message header, includint FMD and 930 925 * OMD. 931 926 * @spu_hdr: Start of buffer where SPU request header is to be written 932 927 * @req_opts: SPU request message options ··· 1110 1105 } 1111 1106 1112 1107 /** 1113 - * spu_cipher_req_init() - Build an skcipher SPU2 request message header, 1108 + * spu2_cipher_req_init() - Build an skcipher SPU2 request message header, 1114 1109 * including FMD and OMD. 1115 1110 * @spu_hdr: Location of start of SPU request (FMD field) 1116 1111 * @cipher_parms: Parameters describing cipher request ··· 1167 1162 } 1168 1163 1169 1164 /** 1170 - * spu_cipher_req_finish() - Finish building a SPU request message header for a 1165 + * spu2_cipher_req_finish() - Finish building a SPU request message header for a 1171 1166 * block cipher request. 1172 1167 * @spu_hdr: Start of the request message header (MH field) 1173 1168 * @spu_req_hdr_len: Length in bytes of the SPU request header 1174 - * @isInbound: 0 encrypt, 1 decrypt 1169 + * @is_inbound: 0 encrypt, 1 decrypt 1175 1170 * @cipher_parms: Parameters describing cipher operation to be performed 1176 1171 * @data_size: Length of the data in the BD field 1177 1172 * ··· 1227 1222 } 1228 1223 1229 1224 /** 1230 - * spu_request_pad() - Create pad bytes at the end of the data. 1225 + * spu2_request_pad() - Create pad bytes at the end of the data. 1231 1226 * @pad_start: Start of buffer where pad bytes are to be written 1232 1227 * @gcm_padding: Length of GCM padding, in bytes 1233 1228 * @hash_pad_len: Number of bytes of padding extend data to full block ··· 1316 1311 } 1317 1312 1318 1313 /** 1319 - * spu_status_process() - Process the status from a SPU response message. 1314 + * spu2_status_process() - Process the status from a SPU response message. 1320 1315 * @statp: start of STATUS word 1321 1316 * 1322 1317 * Return: 0 - if status is good and response should be processed
+2 -2
drivers/crypto/bcm/util.c
··· 119 119 * @from_skip: number of bytes to skip in from_sg. Non-zero when previous 120 120 * request included part of the buffer in entry in from_sg. 121 121 * Assumes from_skip < from_sg->length. 122 - * @from_nents number of entries in from_sg 123 - * @length number of bytes to copy. may reach this limit before exhausting 122 + * @from_nents: number of entries in from_sg 123 + * @length: number of bytes to copy. may reach this limit before exhausting 124 124 * from_sg. 125 125 * 126 126 * Copies the entries themselves, not the data in the entries. Assumes to_sg has
+3
drivers/crypto/caam/caamalg_qi2.c
··· 71 71 * @adata: authentication algorithm details 72 72 * @cdata: encryption algorithm details 73 73 * @authsize: authentication tag (a.k.a. ICV / MAC) size 74 + * @xts_key_fallback: true if fallback tfm needs to be used due 75 + * to unsupported xts key lengths 76 + * @fallback: xts fallback tfm 74 77 */ 75 78 struct caam_ctx { 76 79 struct caam_flc flc[NUM_OP];
+2 -1
drivers/crypto/caam/caampkc.c
··· 187 187 } 188 188 189 189 /** 190 - * Count leading zeros, need it to strip, from a given scatterlist 190 + * caam_rsa_count_leading_zeros - Count leading zeros, need it to strip, 191 + * from a given scatterlist 191 192 * 192 193 * @sgl : scatterlist to count zeros from 193 194 * @nbytes: number of zeros, in bytes, to strip
-1
drivers/crypto/cavium/cpt/cptpf_main.c
··· 10 10 #include <linux/moduleparam.h> 11 11 #include <linux/pci.h> 12 12 #include <linux/printk.h> 13 - #include <linux/version.h> 14 13 15 14 #include "cptpf.h" 16 15
+2 -2
drivers/crypto/cavium/nitrox/nitrox_isr.c
··· 10 10 #include "nitrox_isr.h" 11 11 #include "nitrox_mbx.h" 12 12 13 - /** 13 + /* 14 14 * One vector for each type of ring 15 15 * - NPS packet ring, AQMQ ring and ZQMQ ring 16 16 */ ··· 216 216 } 217 217 } 218 218 219 - /** 219 + /* 220 220 * nps_core_int_isr - interrupt handler for NITROX errors and 221 221 * mailbox communication 222 222 */
+5 -4
drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
··· 58 58 struct device *dev = DEV(ndev); 59 59 60 60 61 - dma_unmap_sg(dev, sr->in.sg, sr->in.sgmap_cnt, DMA_BIDIRECTIONAL); 61 + dma_unmap_sg(dev, sr->in.sg, sg_nents(sr->in.sg), 62 + DMA_BIDIRECTIONAL); 62 63 dma_unmap_single(dev, sr->in.sgcomp_dma, sr->in.sgcomp_len, 63 64 DMA_TO_DEVICE); 64 65 kfree(sr->in.sgcomp); 65 66 sr->in.sg = NULL; 66 67 sr->in.sgmap_cnt = 0; 67 68 68 - dma_unmap_sg(dev, sr->out.sg, sr->out.sgmap_cnt, 69 + dma_unmap_sg(dev, sr->out.sg, sg_nents(sr->out.sg), 69 70 DMA_BIDIRECTIONAL); 70 71 dma_unmap_single(dev, sr->out.sgcomp_dma, sr->out.sgcomp_len, 71 72 DMA_TO_DEVICE); ··· 179 178 return 0; 180 179 181 180 incomp_err: 182 - dma_unmap_sg(dev, req->src, nents, DMA_BIDIRECTIONAL); 181 + dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_BIDIRECTIONAL); 183 182 sr->in.sgmap_cnt = 0; 184 183 return ret; 185 184 } ··· 204 203 return 0; 205 204 206 205 outcomp_map_err: 207 - dma_unmap_sg(dev, req->dst, nents, DMA_BIDIRECTIONAL); 206 + dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_BIDIRECTIONAL); 208 207 sr->out.sgmap_cnt = 0; 209 208 sr->out.sg = NULL; 210 209 return ret;
-1
drivers/crypto/cavium/zip/common.h
··· 56 56 #include <linux/seq_file.h> 57 57 #include <linux/string.h> 58 58 #include <linux/types.h> 59 - #include <linux/version.h> 60 59 61 60 /* Device specific zlib function definitions */ 62 61 #include "zip_device.h"
+1 -2
drivers/crypto/ccp/ccp-crypto-main.c
··· 59 59 #define CCP_CRYPTO_MAX_QLEN 100 60 60 61 61 static struct ccp_crypto_queue req_queue; 62 - static spinlock_t req_queue_lock; 62 + static DEFINE_SPINLOCK(req_queue_lock); 63 63 64 64 struct ccp_crypto_cmd { 65 65 struct list_head entry; ··· 410 410 return ret; 411 411 } 412 412 413 - spin_lock_init(&req_queue_lock); 414 413 INIT_LIST_HEAD(&req_queue.cmds); 415 414 req_queue.backlog = &req_queue.cmds; 416 415 req_queue.cmd_count = 0;
+4 -8
drivers/crypto/ccp/ccp-dev.c
··· 548 548 return ccp->cmd_q_count == suspended; 549 549 } 550 550 551 - int ccp_dev_suspend(struct sp_device *sp) 551 + void ccp_dev_suspend(struct sp_device *sp) 552 552 { 553 553 struct ccp_device *ccp = sp->ccp_data; 554 554 unsigned long flags; ··· 556 556 557 557 /* If there's no device there's nothing to do */ 558 558 if (!ccp) 559 - return 0; 559 + return; 560 560 561 561 spin_lock_irqsave(&ccp->cmd_lock, flags); 562 562 ··· 572 572 while (!ccp_queues_suspended(ccp)) 573 573 wait_event_interruptible(ccp->suspend_queue, 574 574 ccp_queues_suspended(ccp)); 575 - 576 - return 0; 577 575 } 578 576 579 - int ccp_dev_resume(struct sp_device *sp) 577 + void ccp_dev_resume(struct sp_device *sp) 580 578 { 581 579 struct ccp_device *ccp = sp->ccp_data; 582 580 unsigned long flags; ··· 582 584 583 585 /* If there's no device there's nothing to do */ 584 586 if (!ccp) 585 - return 0; 587 + return; 586 588 587 589 spin_lock_irqsave(&ccp->cmd_lock, flags); 588 590 ··· 595 597 } 596 598 597 599 spin_unlock_irqrestore(&ccp->cmd_lock, flags); 598 - 599 - return 0; 600 600 } 601 601 602 602 int ccp_dev_init(struct sp_device *sp)
-1
drivers/crypto/ccp/ccp-ops.c
··· 2418 2418 dst.address += CCP_ECC_OUTPUT_SIZE; 2419 2419 ccp_reverse_get_dm_area(&dst, 0, ecc->u.pm.result.y, 0, 2420 2420 CCP_ECC_MODULUS_BYTES); 2421 - dst.address += CCP_ECC_OUTPUT_SIZE; 2422 2421 2423 2422 /* Restore the workarea address */ 2424 2423 dst.address = save;
+6
drivers/crypto/ccp/sev-dev.c
··· 21 21 #include <linux/ccp.h> 22 22 #include <linux/firmware.h> 23 23 #include <linux/gfp.h> 24 + #include <linux/cpufeature.h> 24 25 25 26 #include <asm/smp.h> 26 27 ··· 972 971 struct device *dev = psp->dev; 973 972 struct sev_device *sev; 974 973 int ret = -ENOMEM; 974 + 975 + if (!boot_cpu_has(X86_FEATURE_SEV)) { 976 + dev_info_once(dev, "SEV: memory encryption not enabled by BIOS\n"); 977 + return 0; 978 + } 975 979 976 980 sev = devm_kzalloc(dev, sizeof(*sev), GFP_KERNEL); 977 981 if (!sev)
+2 -10
drivers/crypto/ccp/sp-dev.c
··· 213 213 214 214 int sp_suspend(struct sp_device *sp) 215 215 { 216 - int ret; 217 - 218 216 if (sp->dev_vdata->ccp_vdata) { 219 - ret = ccp_dev_suspend(sp); 220 - if (ret) 221 - return ret; 217 + ccp_dev_suspend(sp); 222 218 } 223 219 224 220 return 0; ··· 222 226 223 227 int sp_resume(struct sp_device *sp) 224 228 { 225 - int ret; 226 - 227 229 if (sp->dev_vdata->ccp_vdata) { 228 - ret = ccp_dev_resume(sp); 229 - if (ret) 230 - return ret; 230 + ccp_dev_resume(sp); 231 231 } 232 232 233 233 return 0;
+4 -11
drivers/crypto/ccp/sp-dev.h
··· 134 134 int ccp_dev_init(struct sp_device *sp); 135 135 void ccp_dev_destroy(struct sp_device *sp); 136 136 137 - int ccp_dev_suspend(struct sp_device *sp); 138 - int ccp_dev_resume(struct sp_device *sp); 137 + void ccp_dev_suspend(struct sp_device *sp); 138 + void ccp_dev_resume(struct sp_device *sp); 139 139 140 140 #else /* !CONFIG_CRYPTO_DEV_SP_CCP */ 141 141 ··· 144 144 return 0; 145 145 } 146 146 static inline void ccp_dev_destroy(struct sp_device *sp) { } 147 - 148 - static inline int ccp_dev_suspend(struct sp_device *sp) 149 - { 150 - return 0; 151 - } 152 - static inline int ccp_dev_resume(struct sp_device *sp) 153 - { 154 - return 0; 155 - } 147 + static inline void ccp_dev_suspend(struct sp_device *sp) { } 148 + static inline void ccp_dev_resume(struct sp_device *sp) { } 156 149 #endif /* CONFIG_CRYPTO_DEV_SP_CCP */ 157 150 158 151 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
+1
drivers/crypto/ccp/sp-pci.c
··· 356 356 { PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] }, 357 357 { PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] }, 358 358 { PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] }, 359 + { PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[4] }, 359 360 /* Last entry must be zero */ 360 361 { 0, } 361 362 };
+39 -18
drivers/crypto/ccp/tee-dev.c
··· 5 5 * Author: Rijo Thomas <Rijo-john.Thomas@amd.com> 6 6 * Author: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com> 7 7 * 8 - * Copyright 2019 Advanced Micro Devices, Inc. 8 + * Copyright (C) 2019,2021 Advanced Micro Devices, Inc. 9 9 */ 10 10 11 11 #include <linux/types.h> ··· 36 36 if (!start_addr) 37 37 return -ENOMEM; 38 38 39 + memset(start_addr, 0x0, ring_size); 39 40 rb_mgr->ring_start = start_addr; 40 41 rb_mgr->ring_size = ring_size; 41 42 rb_mgr->ring_pa = __psp_pa(start_addr); ··· 245 244 void *buf, size_t len, struct tee_ring_cmd **resp) 246 245 { 247 246 struct tee_ring_cmd *cmd; 248 - u32 rptr, wptr; 249 247 int nloop = 1000, ret = 0; 248 + u32 rptr; 250 249 251 250 *resp = NULL; 252 251 253 252 mutex_lock(&tee->rb_mgr.mutex); 254 253 255 - wptr = tee->rb_mgr.wptr; 256 - 257 - /* Check if ring buffer is full */ 254 + /* Loop until empty entry found in ring buffer */ 258 255 do { 256 + /* Get pointer to ring buffer command entry */ 257 + cmd = (struct tee_ring_cmd *) 258 + (tee->rb_mgr.ring_start + tee->rb_mgr.wptr); 259 + 259 260 rptr = ioread32(tee->io_regs + tee->vdata->ring_rptr_reg); 260 261 261 - if (!(wptr + sizeof(struct tee_ring_cmd) == rptr)) 262 + /* Check if ring buffer is full or command entry is waiting 263 + * for response from TEE 264 + */ 265 + if (!(tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || 266 + cmd->flag == CMD_WAITING_FOR_RESPONSE)) 262 267 break; 263 268 264 - dev_info(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", 265 - rptr, wptr); 269 + dev_dbg(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", 270 + rptr, tee->rb_mgr.wptr); 266 271 267 - /* Wait if ring buffer is full */ 272 + /* Wait if ring buffer is full or TEE is processing data */ 268 273 mutex_unlock(&tee->rb_mgr.mutex); 269 274 schedule_timeout_interruptible(msecs_to_jiffies(10)); 270 275 mutex_lock(&tee->rb_mgr.mutex); 271 276 272 277 } while (--nloop); 273 278 274 - if (!nloop && (wptr + sizeof(struct tee_ring_cmd) == rptr)) { 275 - dev_err(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u\n", 276 - rptr, wptr); 279 + if (!nloop && 280 + (tee->rb_mgr.wptr + sizeof(struct tee_ring_cmd) == rptr || 281 + cmd->flag == CMD_WAITING_FOR_RESPONSE)) { 282 + dev_err(tee->dev, "tee: ring buffer full. rptr = %u wptr = %u response flag %u\n", 283 + rptr, tee->rb_mgr.wptr, cmd->flag); 277 284 ret = -EBUSY; 278 285 goto unlock; 279 286 } 280 287 281 - /* Pointer to empty data entry in ring buffer */ 282 - cmd = (struct tee_ring_cmd *)(tee->rb_mgr.ring_start + wptr); 288 + /* Do not submit command if PSP got disabled while processing any 289 + * command in another thread 290 + */ 291 + if (psp_dead) { 292 + ret = -EBUSY; 293 + goto unlock; 294 + } 283 295 284 296 /* Write command data into ring buffer */ 285 297 cmd->cmd_id = cmd_id; 286 298 cmd->cmd_state = TEE_CMD_STATE_INIT; 287 299 memset(&cmd->buf[0], 0, sizeof(cmd->buf)); 288 300 memcpy(&cmd->buf[0], buf, len); 301 + 302 + /* Indicate driver is waiting for response */ 303 + cmd->flag = CMD_WAITING_FOR_RESPONSE; 289 304 290 305 /* Update local copy of write pointer */ 291 306 tee->rb_mgr.wptr += sizeof(struct tee_ring_cmd); ··· 326 309 struct tee_ring_cmd *resp, 327 310 unsigned int timeout) 328 311 { 329 - /* ~5ms sleep per loop => nloop = timeout * 200 */ 330 - int nloop = timeout * 200; 312 + /* ~1ms sleep per loop => nloop = timeout * 1000 */ 313 + int nloop = timeout * 1000; 331 314 332 315 while (--nloop) { 333 316 if (resp->cmd_state == TEE_CMD_STATE_COMPLETED) 334 317 return 0; 335 318 336 - usleep_range(5000, 5100); 319 + usleep_range(1000, 1100); 337 320 } 338 321 339 322 dev_err(tee->dev, "tee: command 0x%x timed out, disabling PSP\n", ··· 370 353 return ret; 371 354 372 355 ret = tee_wait_cmd_completion(tee, resp, TEE_DEFAULT_TIMEOUT); 373 - if (ret) 356 + if (ret) { 357 + resp->flag = CMD_RESPONSE_TIMEDOUT; 374 358 return ret; 359 + } 375 360 376 361 memcpy(buf, &resp->buf[0], len); 377 362 *status = resp->status; 363 + 364 + resp->flag = CMD_RESPONSE_COPIED; 378 365 379 366 return 0; 380 367 }
+18 -2
drivers/crypto/ccp/tee-dev.h
··· 1 1 /* SPDX-License-Identifier: MIT */ 2 2 /* 3 - * Copyright 2019 Advanced Micro Devices, Inc. 3 + * Copyright (C) 2019,2021 Advanced Micro Devices, Inc. 4 4 * 5 5 * Author: Rijo Thomas <Rijo-john.Thomas@amd.com> 6 6 * Author: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com> ··· 18 18 #include <linux/mutex.h> 19 19 20 20 #define TEE_DEFAULT_TIMEOUT 10 21 - #define MAX_BUFFER_SIZE 992 21 + #define MAX_BUFFER_SIZE 988 22 22 23 23 /** 24 24 * enum tee_ring_cmd_id - TEE interface commands for ring buffer configuration ··· 82 82 }; 83 83 84 84 /** 85 + * enum cmd_resp_state - TEE command's response status maintained by driver 86 + * @CMD_RESPONSE_INVALID: initial state when no command is written to ring 87 + * @CMD_WAITING_FOR_RESPONSE: driver waiting for response from TEE 88 + * @CMD_RESPONSE_TIMEDOUT: failed to get response from TEE 89 + * @CMD_RESPONSE_COPIED: driver has copied response from TEE 90 + */ 91 + enum cmd_resp_state { 92 + CMD_RESPONSE_INVALID, 93 + CMD_WAITING_FOR_RESPONSE, 94 + CMD_RESPONSE_TIMEDOUT, 95 + CMD_RESPONSE_COPIED, 96 + }; 97 + 98 + /** 85 99 * struct tee_ring_cmd - Structure of the command buffer in TEE ring 86 100 * @cmd_id: refers to &enum tee_cmd_id. Command id for the ring buffer 87 101 * interface ··· 105 91 * @pdata: private data (currently unused) 106 92 * @res1: reserved region 107 93 * @buf: TEE command specific buffer 94 + * @flag: refers to &enum cmd_resp_state 108 95 */ 109 96 struct tee_ring_cmd { 110 97 u32 cmd_id; ··· 115 100 u64 pdata; 116 101 u32 res1[2]; 117 102 u8 buf[MAX_BUFFER_SIZE]; 103 + u32 flag; 118 104 119 105 /* Total size: 1024 bytes */ 120 106 } __packed;
+1 -3
drivers/crypto/ccree/cc_driver.c
··· 352 352 req_mem_cc_regs = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); 353 353 /* Map registers space */ 354 354 new_drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs); 355 - if (IS_ERR(new_drvdata->cc_base)) { 356 - dev_err(dev, "Failed to ioremap registers"); 355 + if (IS_ERR(new_drvdata->cc_base)) 357 356 return PTR_ERR(new_drvdata->cc_base); 358 - } 359 357 360 358 dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name, 361 359 req_mem_cc_regs);
+20 -12
drivers/crypto/chelsio/chcr_algo.c
··· 126 126 return container_of(ctx->dev, struct uld_ctx, dev); 127 127 } 128 128 129 - static inline int is_ofld_imm(const struct sk_buff *skb) 130 - { 131 - return (skb->len <= SGE_MAX_WR_LEN); 132 - } 133 - 134 129 static inline void chcr_init_hctx_per_wr(struct chcr_ahash_req_ctx *reqctx) 135 130 { 136 131 memset(&reqctx->hctx_wr, 0, sizeof(struct chcr_hctx_per_wr)); ··· 764 769 struct uld_ctx *u_ctx = ULD_CTX(ctx); 765 770 unsigned int tx_channel_id, rx_channel_id; 766 771 unsigned int txqidx = 0, rxqidx = 0; 767 - unsigned int qid, fid; 772 + unsigned int qid, fid, portno; 768 773 769 774 get_qidxs(req, &txqidx, &rxqidx); 770 775 qid = u_ctx->lldi.rxq_ids[rxqidx]; 771 776 fid = u_ctx->lldi.rxq_ids[0]; 777 + portno = rxqidx / ctx->rxq_perchan; 772 778 tx_channel_id = txqidx / ctx->txq_perchan; 773 - rx_channel_id = rxqidx / ctx->rxq_perchan; 779 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[portno]); 774 780 775 781 776 782 chcr_req->wreq.op_to_cctx_size = FILL_WR_OP_CCTX_SIZE; ··· 793 797 794 798 /** 795 799 * create_cipher_wr - form the WR for cipher operations 796 - * @req: cipher req. 797 - * @ctx: crypto driver context of the request. 798 - * @qid: ingress qid where response of this WR should be received. 799 - * @op_type: encryption or decryption 800 + * @wrparam: Container for create_cipher_wr()'s parameters 800 801 */ 801 802 static struct sk_buff *create_cipher_wr(struct cipher_wr_param *wrparam) 802 803 { 803 804 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(wrparam->req); 804 805 struct chcr_context *ctx = c_ctx(tfm); 806 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 805 807 struct ablk_ctx *ablkctx = ABLK_CTX(ctx); 806 808 struct sk_buff *skb = NULL; 807 809 struct chcr_wr *chcr_req; ··· 816 822 struct adapter *adap = padap(ctx->dev); 817 823 unsigned int rx_channel_id = reqctx->rxqidx / ctx->rxq_perchan; 818 824 825 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 819 826 nents = sg_nents_xlen(reqctx->dstsg, wrparam->bytes, CHCR_DST_SG_SIZE, 820 827 reqctx->dst_ofst); 821 828 dst_size = get_space_for_phys_dsgl(nents); ··· 1554 1559 1555 1560 /** 1556 1561 * create_hash_wr - Create hash work request 1557 - * @req - Cipher req base 1562 + * @req: Cipher req base 1563 + * @param: Container for create_hash_wr()'s parameters 1558 1564 */ 1559 1565 static struct sk_buff *create_hash_wr(struct ahash_request *req, 1560 1566 struct hash_wr_param *param) ··· 1576 1580 int error = 0; 1577 1581 unsigned int rx_channel_id = req_ctx->rxqidx / ctx->rxq_perchan; 1578 1582 1583 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 1579 1584 transhdr_len = HASH_TRANSHDR_SIZE(param->kctx_len); 1580 1585 req_ctx->hctx_wr.imm = (transhdr_len + param->bfr_len + 1581 1586 param->sg_len) <= SGE_MAX_WR_LEN; ··· 2435 2438 { 2436 2439 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2437 2440 struct chcr_context *ctx = a_ctx(tfm); 2441 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 2438 2442 struct chcr_aead_ctx *aeadctx = AEAD_CTX(ctx); 2439 2443 struct chcr_authenc_ctx *actx = AUTHENC_CTX(aeadctx); 2440 2444 struct chcr_aead_reqctx *reqctx = aead_request_ctx(req); ··· 2455 2457 struct adapter *adap = padap(ctx->dev); 2456 2458 unsigned int rx_channel_id = reqctx->rxqidx / ctx->rxq_perchan; 2457 2459 2460 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 2458 2461 if (req->cryptlen == 0) 2459 2462 return NULL; 2460 2463 ··· 2709 2710 struct dsgl_walk dsgl_walk; 2710 2711 unsigned int authsize = crypto_aead_authsize(tfm); 2711 2712 struct chcr_context *ctx = a_ctx(tfm); 2713 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 2712 2714 u32 temp; 2713 2715 unsigned int rx_channel_id = reqctx->rxqidx / ctx->rxq_perchan; 2714 2716 2717 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 2715 2718 dsgl_walk_init(&dsgl_walk, phys_cpl); 2716 2719 dsgl_walk_add_page(&dsgl_walk, IV + reqctx->b0_len, reqctx->iv_dma); 2717 2720 temp = req->assoclen + req->cryptlen + ··· 2753 2752 struct chcr_skcipher_req_ctx *reqctx = skcipher_request_ctx(req); 2754 2753 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(wrparam->req); 2755 2754 struct chcr_context *ctx = c_ctx(tfm); 2755 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 2756 2756 struct dsgl_walk dsgl_walk; 2757 2757 unsigned int rx_channel_id = reqctx->rxqidx / ctx->rxq_perchan; 2758 2758 2759 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 2759 2760 dsgl_walk_init(&dsgl_walk, phys_cpl); 2760 2761 dsgl_walk_add_sg(&dsgl_walk, reqctx->dstsg, wrparam->bytes, 2761 2762 reqctx->dst_ofst); ··· 2961 2958 { 2962 2959 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 2963 2960 struct chcr_context *ctx = a_ctx(tfm); 2961 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 2964 2962 struct chcr_aead_ctx *aeadctx = AEAD_CTX(ctx); 2965 2963 struct chcr_aead_reqctx *reqctx = aead_request_ctx(req); 2966 2964 unsigned int cipher_mode = CHCR_SCMD_CIPHER_MODE_AES_CCM; ··· 2970 2966 unsigned int ccm_xtra; 2971 2967 unsigned int tag_offset = 0, auth_offset = 0; 2972 2968 unsigned int assoclen; 2969 + 2970 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 2973 2971 2974 2972 if (get_aead_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_AEAD_RFC4309) 2975 2973 assoclen = req->assoclen - 8; ··· 3133 3127 { 3134 3128 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 3135 3129 struct chcr_context *ctx = a_ctx(tfm); 3130 + struct uld_ctx *u_ctx = ULD_CTX(ctx); 3136 3131 struct chcr_aead_ctx *aeadctx = AEAD_CTX(ctx); 3137 3132 struct chcr_aead_reqctx *reqctx = aead_request_ctx(req); 3138 3133 struct sk_buff *skb = NULL; ··· 3150 3143 struct adapter *adap = padap(ctx->dev); 3151 3144 unsigned int rx_channel_id = reqctx->rxqidx / ctx->rxq_perchan; 3152 3145 3146 + rx_channel_id = cxgb4_port_e2cchan(u_ctx->lldi.ports[rx_channel_id]); 3153 3147 if (get_aead_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106) 3154 3148 assoclen = req->assoclen - 8; 3155 3149
+2 -3
drivers/crypto/chelsio/chcr_core.c
··· 1 - /** 1 + /* 2 2 * This file is part of the Chelsio T4/T5/T6 Ethernet driver for Linux. 3 3 * 4 4 * Copyright (C) 2011-2016 Chelsio Communications. All rights reserved. ··· 184 184 struct uld_ctx *u_ctx; 185 185 186 186 /* Create the device and add it in the device list */ 187 - pr_info_once("%s - version %s\n", DRV_DESC, DRV_VERSION); 187 + pr_info_once("%s\n", DRV_DESC); 188 188 if (!(lld->ulp_crypto & ULP_CRYPTO_LOOKASIDE)) 189 189 return ERR_PTR(-EOPNOTSUPP); 190 190 ··· 309 309 MODULE_DESCRIPTION("Crypto Co-processor for Chelsio Terminator cards."); 310 310 MODULE_LICENSE("GPL"); 311 311 MODULE_AUTHOR("Chelsio Communications"); 312 - MODULE_VERSION(DRV_VERSION);
-1
drivers/crypto/chelsio/chcr_core.h
··· 44 44 #include "cxgb4_uld.h" 45 45 46 46 #define DRV_MODULE_NAME "chcr" 47 - #define DRV_VERSION "1.0.0.0-ko" 48 47 #define DRV_DESC "Chelsio T6 Crypto Co-processor Driver" 49 48 50 49 #define MAX_PENDING_REQ_TO_HW 20
+1 -3
drivers/crypto/geode-aes.c
··· 21 21 /* Static structures */ 22 22 23 23 static void __iomem *_iobase; 24 - static spinlock_t lock; 24 + static DEFINE_SPINLOCK(lock); 25 25 26 26 /* Write a 128 bit field (either a writable key or IV) */ 27 27 static inline void ··· 382 382 ret = -ENOMEM; 383 383 goto erequest; 384 384 } 385 - 386 - spin_lock_init(&lock); 387 385 388 386 /* Clear any pending activity */ 389 387 iowrite32(AES_INTR_PENDING | AES_INTR_MASK, _iobase + AES_INTR_REG);
+2
drivers/crypto/hisilicon/Kconfig
··· 68 68 select CRYPTO_DEV_HISI_QM 69 69 select CRYPTO_DH 70 70 select CRYPTO_RSA 71 + select CRYPTO_CURVE25519 72 + select CRYPTO_ECDH 71 73 help 72 74 Support for HiSilicon HPRE(High Performance RSA Engine) 73 75 accelerator, which can accelerate RSA and DH algorithms.
+14 -4
drivers/crypto/hisilicon/hpre/hpre.h
··· 10 10 #define HPRE_PF_DEF_Q_NUM 64 11 11 #define HPRE_PF_DEF_Q_BASE 0 12 12 13 + /* 14 + * type used in qm sqc DW6. 15 + * 0 - Algorithm which has been supported in V2, like RSA, DH and so on; 16 + * 1 - ECC algorithm in V3. 17 + */ 18 + #define HPRE_V2_ALG_TYPE 0 19 + #define HPRE_V3_ECC_ALG_TYPE 1 20 + 13 21 enum { 14 22 HPRE_CLUSTER0, 15 23 HPRE_CLUSTER1, ··· 26 18 }; 27 19 28 20 enum hpre_ctrl_dbgfs_file { 29 - HPRE_CURRENT_QM, 30 21 HPRE_CLEAR_ENABLE, 31 22 HPRE_CLUSTER_CTRL, 32 23 HPRE_DEBUG_FILE_NUM, ··· 82 75 HPRE_ALG_KG_CRT = 0x3, 83 76 HPRE_ALG_DH_G2 = 0x4, 84 77 HPRE_ALG_DH = 0x5, 78 + HPRE_ALG_ECC_MUL = 0xD, 79 + /* shared by x25519 and x448, but x448 is not supported now */ 80 + HPRE_ALG_CURVE25519_MUL = 0x10, 85 81 }; 86 82 87 83 struct hpre_sqe { ··· 102 92 __le32 rsvd1[_HPRE_SQE_ALIGN_EXT]; 103 93 }; 104 94 105 - struct hisi_qp *hpre_create_qp(void); 106 - int hpre_algs_register(void); 107 - void hpre_algs_unregister(void); 95 + struct hisi_qp *hpre_create_qp(u8 type); 96 + int hpre_algs_register(struct hisi_qm *qm); 97 + void hpre_algs_unregister(struct hisi_qm *qm); 108 98 109 99 #endif
+894 -27
drivers/crypto/hisilicon/hpre/hpre_crypto.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2019 HiSilicon Limited. */ 3 3 #include <crypto/akcipher.h> 4 + #include <crypto/curve25519.h> 4 5 #include <crypto/dh.h> 6 + #include <crypto/ecc_curve.h> 7 + #include <crypto/ecdh.h> 5 8 #include <crypto/internal/akcipher.h> 6 9 #include <crypto/internal/kpp.h> 7 10 #include <crypto/internal/rsa.h> ··· 39 36 #define HPRE_DFX_SEC_TO_US 1000000 40 37 #define HPRE_DFX_US_TO_NS 1000 41 38 39 + /* size in bytes of the n prime */ 40 + #define HPRE_ECC_NIST_P192_N_SIZE 24 41 + #define HPRE_ECC_NIST_P256_N_SIZE 32 42 + 43 + /* size in bytes */ 44 + #define HPRE_ECC_HW256_KSZ_B 32 45 + 42 46 typedef void (*hpre_cb)(struct hpre_ctx *ctx, void *sqe); 43 47 44 48 struct hpre_rsa_ctx { ··· 71 61 * else if base if the counterpart public key we 72 62 * compute the shared secret 73 63 * ZZ = yb^xa mod p; [RFC2631 sec 2.1.1] 64 + * low address: d--->n, please refer to Hisilicon HPRE UM 74 65 */ 75 - char *xa_p; /* low address: d--->n, please refer to Hisilicon HPRE UM */ 66 + char *xa_p; 76 67 dma_addr_t dma_xa_p; 77 68 78 69 char *g; /* m */ 70 + dma_addr_t dma_g; 71 + }; 72 + 73 + struct hpre_ecdh_ctx { 74 + /* low address: p->a->k->b */ 75 + unsigned char *p; 76 + dma_addr_t dma_p; 77 + 78 + /* low address: x->y */ 79 + unsigned char *g; 80 + dma_addr_t dma_g; 81 + }; 82 + 83 + struct hpre_curve25519_ctx { 84 + /* low address: p->a->k */ 85 + unsigned char *p; 86 + dma_addr_t dma_p; 87 + 88 + /* gx coordinate */ 89 + unsigned char *g; 79 90 dma_addr_t dma_g; 80 91 }; 81 92 ··· 111 80 union { 112 81 struct hpre_rsa_ctx rsa; 113 82 struct hpre_dh_ctx dh; 83 + struct hpre_ecdh_ctx ecdh; 84 + struct hpre_curve25519_ctx curve25519; 114 85 }; 86 + /* for ecc algorithms */ 87 + unsigned int curve_id; 115 88 }; 116 89 117 90 struct hpre_asym_request { ··· 126 91 union { 127 92 struct akcipher_request *rsa; 128 93 struct kpp_request *dh; 94 + struct kpp_request *ecdh; 95 + struct kpp_request *curve25519; 129 96 } areq; 130 97 int err; 131 98 int req_id; ··· 189 152 } 190 153 } 191 154 192 - static struct hisi_qp *hpre_get_qp_and_start(void) 155 + static struct hisi_qp *hpre_get_qp_and_start(u8 type) 193 156 { 194 157 struct hisi_qp *qp; 195 158 int ret; 196 159 197 - qp = hpre_create_qp(); 160 + qp = hpre_create_qp(type); 198 161 if (!qp) { 199 162 pr_err("Can not create hpre qp!\n"); 200 163 return ERR_PTR(-ENODEV); ··· 298 261 dma_addr_t tmp; 299 262 300 263 tmp = le64_to_cpu(sqe->in); 301 - if (unlikely(!tmp)) 302 - return; 303 264 304 265 if (src) { 305 266 if (req->src) ··· 307 272 } 308 273 309 274 tmp = le64_to_cpu(sqe->out); 310 - if (unlikely(!tmp)) 311 - return; 312 275 313 276 if (req->dst) { 314 277 if (dst) ··· 321 288 static int hpre_alg_res_post_hf(struct hpre_ctx *ctx, struct hpre_sqe *sqe, 322 289 void **kreq) 323 290 { 291 + struct device *dev = HPRE_DEV(ctx); 324 292 struct hpre_asym_request *req; 325 - int err, id, done; 293 + unsigned int err, done, alg; 294 + int id; 326 295 327 296 #define HPRE_NO_HW_ERR 0 328 297 #define HPRE_HW_TASK_DONE 3 329 298 #define HREE_HW_ERR_MASK 0x7ff 330 299 #define HREE_SQE_DONE_MASK 0x3 300 + #define HREE_ALG_TYPE_MASK 0x1f 331 301 id = (int)le16_to_cpu(sqe->tag); 332 302 req = ctx->req_list[id]; 333 303 hpre_rm_req_from_ctx(req); ··· 343 307 HREE_SQE_DONE_MASK; 344 308 345 309 if (likely(err == HPRE_NO_HW_ERR && done == HPRE_HW_TASK_DONE)) 346 - return 0; 310 + return 0; 311 + 312 + alg = le32_to_cpu(sqe->dw0) & HREE_ALG_TYPE_MASK; 313 + dev_err_ratelimited(dev, "alg[0x%x] error: done[0x%x], etype[0x%x]\n", 314 + alg, done, err); 347 315 348 316 return -EINVAL; 349 317 } ··· 453 413 struct hpre_sqe *sqe = resp; 454 414 struct hpre_asym_request *req = ctx->req_list[le16_to_cpu(sqe->tag)]; 455 415 456 - 457 416 if (unlikely(!req)) { 458 417 atomic64_inc(&dfx[HPRE_INVALID_REQ_CNT].value); 459 418 return; ··· 461 422 req->cb(ctx, resp); 462 423 } 463 424 464 - static int hpre_ctx_init(struct hpre_ctx *ctx) 425 + static void hpre_stop_qp_and_put(struct hisi_qp *qp) 426 + { 427 + hisi_qm_stop_qp(qp); 428 + hisi_qm_free_qps(&qp, 1); 429 + } 430 + 431 + static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type) 465 432 { 466 433 struct hisi_qp *qp; 434 + int ret; 467 435 468 - qp = hpre_get_qp_and_start(); 436 + qp = hpre_get_qp_and_start(type); 469 437 if (IS_ERR(qp)) 470 438 return PTR_ERR(qp); 471 439 472 440 qp->qp_ctx = ctx; 473 441 qp->req_cb = hpre_alg_cb; 474 442 475 - return hpre_ctx_set(ctx, qp, QM_Q_DEPTH); 443 + ret = hpre_ctx_set(ctx, qp, QM_Q_DEPTH); 444 + if (ret) 445 + hpre_stop_qp_and_put(qp); 446 + 447 + return ret; 476 448 } 477 449 478 450 static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa) ··· 560 510 return ret; 561 511 } 562 512 563 - #ifdef CONFIG_CRYPTO_DH 564 513 static int hpre_dh_compute_value(struct kpp_request *req) 565 514 { 566 515 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); ··· 723 674 { 724 675 struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 725 676 726 - return hpre_ctx_init(ctx); 677 + return hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE); 727 678 } 728 679 729 680 static void hpre_dh_exit_tfm(struct crypto_kpp *tfm) ··· 732 683 733 684 hpre_dh_clear_ctx(ctx, true); 734 685 } 735 - #endif 736 686 737 687 static void hpre_rsa_drop_leading_zeros(const char **ptr, size_t *len) 738 688 { ··· 1148 1100 return PTR_ERR(ctx->rsa.soft_tfm); 1149 1101 } 1150 1102 1151 - ret = hpre_ctx_init(ctx); 1103 + ret = hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE); 1152 1104 if (ret) 1153 1105 crypto_free_akcipher(ctx->rsa.soft_tfm); 1154 1106 ··· 1161 1113 1162 1114 hpre_rsa_clear_ctx(ctx, true); 1163 1115 crypto_free_akcipher(ctx->rsa.soft_tfm); 1116 + } 1117 + 1118 + static void hpre_key_to_big_end(u8 *data, int len) 1119 + { 1120 + int i, j; 1121 + u8 tmp; 1122 + 1123 + for (i = 0; i < len / 2; i++) { 1124 + j = len - i - 1; 1125 + tmp = data[j]; 1126 + data[j] = data[i]; 1127 + data[i] = tmp; 1128 + } 1129 + } 1130 + 1131 + static void hpre_ecc_clear_ctx(struct hpre_ctx *ctx, bool is_clear_all, 1132 + bool is_ecdh) 1133 + { 1134 + struct device *dev = HPRE_DEV(ctx); 1135 + unsigned int sz = ctx->key_sz; 1136 + unsigned int shift = sz << 1; 1137 + 1138 + if (is_clear_all) 1139 + hisi_qm_stop_qp(ctx->qp); 1140 + 1141 + if (is_ecdh && ctx->ecdh.p) { 1142 + /* ecdh: p->a->k->b */ 1143 + memzero_explicit(ctx->ecdh.p + shift, sz); 1144 + dma_free_coherent(dev, sz << 3, ctx->ecdh.p, ctx->ecdh.dma_p); 1145 + ctx->ecdh.p = NULL; 1146 + } else if (!is_ecdh && ctx->curve25519.p) { 1147 + /* curve25519: p->a->k */ 1148 + memzero_explicit(ctx->curve25519.p + shift, sz); 1149 + dma_free_coherent(dev, sz << 2, ctx->curve25519.p, 1150 + ctx->curve25519.dma_p); 1151 + ctx->curve25519.p = NULL; 1152 + } 1153 + 1154 + hpre_ctx_clear(ctx, is_clear_all); 1155 + } 1156 + 1157 + static unsigned int hpre_ecdh_supported_curve(unsigned short id) 1158 + { 1159 + switch (id) { 1160 + case ECC_CURVE_NIST_P192: 1161 + case ECC_CURVE_NIST_P256: 1162 + return HPRE_ECC_HW256_KSZ_B; 1163 + default: 1164 + break; 1165 + } 1166 + 1167 + return 0; 1168 + } 1169 + 1170 + static void fill_curve_param(void *addr, u64 *param, unsigned int cur_sz, u8 ndigits) 1171 + { 1172 + unsigned int sz = cur_sz - (ndigits - 1) * sizeof(u64); 1173 + u8 i = 0; 1174 + 1175 + while (i < ndigits - 1) { 1176 + memcpy(addr + sizeof(u64) * i, &param[i], sizeof(u64)); 1177 + i++; 1178 + } 1179 + 1180 + memcpy(addr + sizeof(u64) * i, &param[ndigits - 1], sz); 1181 + hpre_key_to_big_end((u8 *)addr, cur_sz); 1182 + } 1183 + 1184 + static int hpre_ecdh_fill_curve(struct hpre_ctx *ctx, struct ecdh *params, 1185 + unsigned int cur_sz) 1186 + { 1187 + unsigned int shifta = ctx->key_sz << 1; 1188 + unsigned int shiftb = ctx->key_sz << 2; 1189 + void *p = ctx->ecdh.p + ctx->key_sz - cur_sz; 1190 + void *a = ctx->ecdh.p + shifta - cur_sz; 1191 + void *b = ctx->ecdh.p + shiftb - cur_sz; 1192 + void *x = ctx->ecdh.g + ctx->key_sz - cur_sz; 1193 + void *y = ctx->ecdh.g + shifta - cur_sz; 1194 + const struct ecc_curve *curve = ecc_get_curve(ctx->curve_id); 1195 + char *n; 1196 + 1197 + if (unlikely(!curve)) 1198 + return -EINVAL; 1199 + 1200 + n = kzalloc(ctx->key_sz, GFP_KERNEL); 1201 + if (!n) 1202 + return -ENOMEM; 1203 + 1204 + fill_curve_param(p, curve->p, cur_sz, curve->g.ndigits); 1205 + fill_curve_param(a, curve->a, cur_sz, curve->g.ndigits); 1206 + fill_curve_param(b, curve->b, cur_sz, curve->g.ndigits); 1207 + fill_curve_param(x, curve->g.x, cur_sz, curve->g.ndigits); 1208 + fill_curve_param(y, curve->g.y, cur_sz, curve->g.ndigits); 1209 + fill_curve_param(n, curve->n, cur_sz, curve->g.ndigits); 1210 + 1211 + if (params->key_size == cur_sz && memcmp(params->key, n, cur_sz) >= 0) { 1212 + kfree(n); 1213 + return -EINVAL; 1214 + } 1215 + 1216 + kfree(n); 1217 + return 0; 1218 + } 1219 + 1220 + static unsigned int hpre_ecdh_get_curvesz(unsigned short id) 1221 + { 1222 + switch (id) { 1223 + case ECC_CURVE_NIST_P192: 1224 + return HPRE_ECC_NIST_P192_N_SIZE; 1225 + case ECC_CURVE_NIST_P256: 1226 + return HPRE_ECC_NIST_P256_N_SIZE; 1227 + default: 1228 + break; 1229 + } 1230 + 1231 + return 0; 1232 + } 1233 + 1234 + static int hpre_ecdh_set_param(struct hpre_ctx *ctx, struct ecdh *params) 1235 + { 1236 + struct device *dev = HPRE_DEV(ctx); 1237 + unsigned int sz, shift, curve_sz; 1238 + int ret; 1239 + 1240 + ctx->key_sz = hpre_ecdh_supported_curve(ctx->curve_id); 1241 + if (!ctx->key_sz) 1242 + return -EINVAL; 1243 + 1244 + curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id); 1245 + if (!curve_sz || params->key_size > curve_sz) 1246 + return -EINVAL; 1247 + 1248 + sz = ctx->key_sz; 1249 + 1250 + if (!ctx->ecdh.p) { 1251 + ctx->ecdh.p = dma_alloc_coherent(dev, sz << 3, &ctx->ecdh.dma_p, 1252 + GFP_KERNEL); 1253 + if (!ctx->ecdh.p) 1254 + return -ENOMEM; 1255 + } 1256 + 1257 + shift = sz << 2; 1258 + ctx->ecdh.g = ctx->ecdh.p + shift; 1259 + ctx->ecdh.dma_g = ctx->ecdh.dma_p + shift; 1260 + 1261 + ret = hpre_ecdh_fill_curve(ctx, params, curve_sz); 1262 + if (ret) { 1263 + dev_err(dev, "failed to fill curve_param, ret = %d!\n", ret); 1264 + dma_free_coherent(dev, sz << 3, ctx->ecdh.p, ctx->ecdh.dma_p); 1265 + ctx->ecdh.p = NULL; 1266 + return ret; 1267 + } 1268 + 1269 + return 0; 1270 + } 1271 + 1272 + static bool hpre_key_is_zero(char *key, unsigned short key_sz) 1273 + { 1274 + int i; 1275 + 1276 + for (i = 0; i < key_sz; i++) 1277 + if (key[i]) 1278 + return false; 1279 + 1280 + return true; 1281 + } 1282 + 1283 + static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, 1284 + unsigned int len) 1285 + { 1286 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1287 + struct device *dev = HPRE_DEV(ctx); 1288 + unsigned int sz, sz_shift; 1289 + struct ecdh params; 1290 + int ret; 1291 + 1292 + if (crypto_ecdh_decode_key(buf, len, &params) < 0) { 1293 + dev_err(dev, "failed to decode ecdh key!\n"); 1294 + return -EINVAL; 1295 + } 1296 + 1297 + if (hpre_key_is_zero(params.key, params.key_size)) { 1298 + dev_err(dev, "Invalid hpre key!\n"); 1299 + return -EINVAL; 1300 + } 1301 + 1302 + hpre_ecc_clear_ctx(ctx, false, true); 1303 + 1304 + ret = hpre_ecdh_set_param(ctx, &params); 1305 + if (ret < 0) { 1306 + dev_err(dev, "failed to set hpre param, ret = %d!\n", ret); 1307 + return ret; 1308 + } 1309 + 1310 + sz = ctx->key_sz; 1311 + sz_shift = (sz << 1) + sz - params.key_size; 1312 + memcpy(ctx->ecdh.p + sz_shift, params.key, params.key_size); 1313 + 1314 + return 0; 1315 + } 1316 + 1317 + static void hpre_ecdh_hw_data_clr_all(struct hpre_ctx *ctx, 1318 + struct hpre_asym_request *req, 1319 + struct scatterlist *dst, 1320 + struct scatterlist *src) 1321 + { 1322 + struct device *dev = HPRE_DEV(ctx); 1323 + struct hpre_sqe *sqe = &req->req; 1324 + dma_addr_t dma; 1325 + 1326 + dma = le64_to_cpu(sqe->in); 1327 + 1328 + if (src && req->src) 1329 + dma_free_coherent(dev, ctx->key_sz << 2, req->src, dma); 1330 + 1331 + dma = le64_to_cpu(sqe->out); 1332 + 1333 + if (req->dst) 1334 + dma_free_coherent(dev, ctx->key_sz << 1, req->dst, dma); 1335 + if (dst) 1336 + dma_unmap_single(dev, dma, ctx->key_sz << 1, DMA_FROM_DEVICE); 1337 + } 1338 + 1339 + static void hpre_ecdh_cb(struct hpre_ctx *ctx, void *resp) 1340 + { 1341 + unsigned int curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id); 1342 + struct hpre_dfx *dfx = ctx->hpre->debug.dfx; 1343 + struct hpre_asym_request *req = NULL; 1344 + struct kpp_request *areq; 1345 + u64 overtime_thrhld; 1346 + char *p; 1347 + int ret; 1348 + 1349 + ret = hpre_alg_res_post_hf(ctx, resp, (void **)&req); 1350 + areq = req->areq.ecdh; 1351 + areq->dst_len = ctx->key_sz << 1; 1352 + 1353 + overtime_thrhld = atomic64_read(&dfx[HPRE_OVERTIME_THRHLD].value); 1354 + if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld)) 1355 + atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value); 1356 + 1357 + p = sg_virt(areq->dst); 1358 + memmove(p, p + ctx->key_sz - curve_sz, curve_sz); 1359 + memmove(p + curve_sz, p + areq->dst_len - curve_sz, curve_sz); 1360 + 1361 + hpre_ecdh_hw_data_clr_all(ctx, req, areq->dst, areq->src); 1362 + kpp_request_complete(areq, ret); 1363 + 1364 + atomic64_inc(&dfx[HPRE_RECV_CNT].value); 1365 + } 1366 + 1367 + static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx, 1368 + struct kpp_request *req) 1369 + { 1370 + struct hpre_asym_request *h_req; 1371 + struct hpre_sqe *msg; 1372 + int req_id; 1373 + void *tmp; 1374 + 1375 + if (req->dst_len < ctx->key_sz << 1) { 1376 + req->dst_len = ctx->key_sz << 1; 1377 + return -EINVAL; 1378 + } 1379 + 1380 + tmp = kpp_request_ctx(req); 1381 + h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ); 1382 + h_req->cb = hpre_ecdh_cb; 1383 + h_req->areq.ecdh = req; 1384 + msg = &h_req->req; 1385 + memset(msg, 0, sizeof(*msg)); 1386 + msg->key = cpu_to_le64(ctx->ecdh.dma_p); 1387 + 1388 + msg->dw0 |= cpu_to_le32(0x1U << HPRE_SQE_DONE_SHIFT); 1389 + msg->task_len1 = (ctx->key_sz >> HPRE_BITS_2_BYTES_SHIFT) - 1; 1390 + h_req->ctx = ctx; 1391 + 1392 + req_id = hpre_add_req_to_ctx(h_req); 1393 + if (req_id < 0) 1394 + return -EBUSY; 1395 + 1396 + msg->tag = cpu_to_le16((u16)req_id); 1397 + return 0; 1398 + } 1399 + 1400 + static int hpre_ecdh_src_data_init(struct hpre_asym_request *hpre_req, 1401 + struct scatterlist *data, unsigned int len) 1402 + { 1403 + struct hpre_sqe *msg = &hpre_req->req; 1404 + struct hpre_ctx *ctx = hpre_req->ctx; 1405 + struct device *dev = HPRE_DEV(ctx); 1406 + unsigned int tmpshift; 1407 + dma_addr_t dma = 0; 1408 + void *ptr; 1409 + int shift; 1410 + 1411 + /* Src_data include gx and gy. */ 1412 + shift = ctx->key_sz - (len >> 1); 1413 + if (unlikely(shift < 0)) 1414 + return -EINVAL; 1415 + 1416 + ptr = dma_alloc_coherent(dev, ctx->key_sz << 2, &dma, GFP_KERNEL); 1417 + if (unlikely(!ptr)) 1418 + return -ENOMEM; 1419 + 1420 + tmpshift = ctx->key_sz << 1; 1421 + scatterwalk_map_and_copy(ptr + tmpshift, data, 0, len, 0); 1422 + memcpy(ptr + shift, ptr + tmpshift, len >> 1); 1423 + memcpy(ptr + ctx->key_sz + shift, ptr + tmpshift + (len >> 1), len >> 1); 1424 + 1425 + hpre_req->src = ptr; 1426 + msg->in = cpu_to_le64(dma); 1427 + return 0; 1428 + } 1429 + 1430 + static int hpre_ecdh_dst_data_init(struct hpre_asym_request *hpre_req, 1431 + struct scatterlist *data, unsigned int len) 1432 + { 1433 + struct hpre_sqe *msg = &hpre_req->req; 1434 + struct hpre_ctx *ctx = hpre_req->ctx; 1435 + struct device *dev = HPRE_DEV(ctx); 1436 + dma_addr_t dma = 0; 1437 + 1438 + if (unlikely(!data || !sg_is_last(data) || len != ctx->key_sz << 1)) { 1439 + dev_err(dev, "data or data length is illegal!\n"); 1440 + return -EINVAL; 1441 + } 1442 + 1443 + hpre_req->dst = NULL; 1444 + dma = dma_map_single(dev, sg_virt(data), len, DMA_FROM_DEVICE); 1445 + if (unlikely(dma_mapping_error(dev, dma))) { 1446 + dev_err(dev, "dma map data err!\n"); 1447 + return -ENOMEM; 1448 + } 1449 + 1450 + msg->out = cpu_to_le64(dma); 1451 + return 0; 1452 + } 1453 + 1454 + static int hpre_ecdh_compute_value(struct kpp_request *req) 1455 + { 1456 + struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 1457 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1458 + struct device *dev = HPRE_DEV(ctx); 1459 + void *tmp = kpp_request_ctx(req); 1460 + struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ); 1461 + struct hpre_sqe *msg = &hpre_req->req; 1462 + int ret; 1463 + 1464 + ret = hpre_ecdh_msg_request_set(ctx, req); 1465 + if (unlikely(ret)) { 1466 + dev_err(dev, "failed to set ecdh request, ret = %d!\n", ret); 1467 + return ret; 1468 + } 1469 + 1470 + if (req->src) { 1471 + ret = hpre_ecdh_src_data_init(hpre_req, req->src, req->src_len); 1472 + if (unlikely(ret)) { 1473 + dev_err(dev, "failed to init src data, ret = %d!\n", ret); 1474 + goto clear_all; 1475 + } 1476 + } else { 1477 + msg->in = cpu_to_le64(ctx->ecdh.dma_g); 1478 + } 1479 + 1480 + ret = hpre_ecdh_dst_data_init(hpre_req, req->dst, req->dst_len); 1481 + if (unlikely(ret)) { 1482 + dev_err(dev, "failed to init dst data, ret = %d!\n", ret); 1483 + goto clear_all; 1484 + } 1485 + 1486 + msg->dw0 = cpu_to_le32(le32_to_cpu(msg->dw0) | HPRE_ALG_ECC_MUL); 1487 + ret = hpre_send(ctx, msg); 1488 + if (likely(!ret)) 1489 + return -EINPROGRESS; 1490 + 1491 + clear_all: 1492 + hpre_rm_req_from_ctx(hpre_req); 1493 + hpre_ecdh_hw_data_clr_all(ctx, hpre_req, req->dst, req->src); 1494 + return ret; 1495 + } 1496 + 1497 + static unsigned int hpre_ecdh_max_size(struct crypto_kpp *tfm) 1498 + { 1499 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1500 + 1501 + /* max size is the pub_key_size, include x and y */ 1502 + return ctx->key_sz << 1; 1503 + } 1504 + 1505 + static int hpre_ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm) 1506 + { 1507 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1508 + 1509 + ctx->curve_id = ECC_CURVE_NIST_P192; 1510 + 1511 + return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE); 1512 + } 1513 + 1514 + static int hpre_ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm) 1515 + { 1516 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1517 + 1518 + ctx->curve_id = ECC_CURVE_NIST_P256; 1519 + 1520 + return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE); 1521 + } 1522 + 1523 + static void hpre_ecdh_exit_tfm(struct crypto_kpp *tfm) 1524 + { 1525 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1526 + 1527 + hpre_ecc_clear_ctx(ctx, true, true); 1528 + } 1529 + 1530 + static void hpre_curve25519_fill_curve(struct hpre_ctx *ctx, const void *buf, 1531 + unsigned int len) 1532 + { 1533 + u8 secret[CURVE25519_KEY_SIZE] = { 0 }; 1534 + unsigned int sz = ctx->key_sz; 1535 + const struct ecc_curve *curve; 1536 + unsigned int shift = sz << 1; 1537 + void *p; 1538 + 1539 + /* 1540 + * The key from 'buf' is in little-endian, we should preprocess it as 1541 + * the description in rfc7748: "k[0] &= 248, k[31] &= 127, k[31] |= 64", 1542 + * then convert it to big endian. Only in this way, the result can be 1543 + * the same as the software curve-25519 that exists in crypto. 1544 + */ 1545 + memcpy(secret, buf, len); 1546 + curve25519_clamp_secret(secret); 1547 + hpre_key_to_big_end(secret, CURVE25519_KEY_SIZE); 1548 + 1549 + p = ctx->curve25519.p + sz - len; 1550 + 1551 + curve = ecc_get_curve25519(); 1552 + 1553 + /* fill curve parameters */ 1554 + fill_curve_param(p, curve->p, len, curve->g.ndigits); 1555 + fill_curve_param(p + sz, curve->a, len, curve->g.ndigits); 1556 + memcpy(p + shift, secret, len); 1557 + fill_curve_param(p + shift + sz, curve->g.x, len, curve->g.ndigits); 1558 + memzero_explicit(secret, CURVE25519_KEY_SIZE); 1559 + } 1560 + 1561 + static int hpre_curve25519_set_param(struct hpre_ctx *ctx, const void *buf, 1562 + unsigned int len) 1563 + { 1564 + struct device *dev = HPRE_DEV(ctx); 1565 + unsigned int sz = ctx->key_sz; 1566 + unsigned int shift = sz << 1; 1567 + 1568 + /* p->a->k->gx */ 1569 + if (!ctx->curve25519.p) { 1570 + ctx->curve25519.p = dma_alloc_coherent(dev, sz << 2, 1571 + &ctx->curve25519.dma_p, 1572 + GFP_KERNEL); 1573 + if (!ctx->curve25519.p) 1574 + return -ENOMEM; 1575 + } 1576 + 1577 + ctx->curve25519.g = ctx->curve25519.p + shift + sz; 1578 + ctx->curve25519.dma_g = ctx->curve25519.dma_p + shift + sz; 1579 + 1580 + hpre_curve25519_fill_curve(ctx, buf, len); 1581 + 1582 + return 0; 1583 + } 1584 + 1585 + static int hpre_curve25519_set_secret(struct crypto_kpp *tfm, const void *buf, 1586 + unsigned int len) 1587 + { 1588 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1589 + struct device *dev = HPRE_DEV(ctx); 1590 + int ret = -EINVAL; 1591 + 1592 + if (len != CURVE25519_KEY_SIZE || 1593 + !crypto_memneq(buf, curve25519_null_point, CURVE25519_KEY_SIZE)) { 1594 + dev_err(dev, "key is null or key len is not 32bytes!\n"); 1595 + return ret; 1596 + } 1597 + 1598 + /* Free old secret if any */ 1599 + hpre_ecc_clear_ctx(ctx, false, false); 1600 + 1601 + ctx->key_sz = CURVE25519_KEY_SIZE; 1602 + ret = hpre_curve25519_set_param(ctx, buf, CURVE25519_KEY_SIZE); 1603 + if (ret) { 1604 + dev_err(dev, "failed to set curve25519 param, ret = %d!\n", ret); 1605 + hpre_ecc_clear_ctx(ctx, false, false); 1606 + return ret; 1607 + } 1608 + 1609 + return 0; 1610 + } 1611 + 1612 + static void hpre_curve25519_hw_data_clr_all(struct hpre_ctx *ctx, 1613 + struct hpre_asym_request *req, 1614 + struct scatterlist *dst, 1615 + struct scatterlist *src) 1616 + { 1617 + struct device *dev = HPRE_DEV(ctx); 1618 + struct hpre_sqe *sqe = &req->req; 1619 + dma_addr_t dma; 1620 + 1621 + dma = le64_to_cpu(sqe->in); 1622 + 1623 + if (src && req->src) 1624 + dma_free_coherent(dev, ctx->key_sz, req->src, dma); 1625 + 1626 + dma = le64_to_cpu(sqe->out); 1627 + 1628 + if (req->dst) 1629 + dma_free_coherent(dev, ctx->key_sz, req->dst, dma); 1630 + if (dst) 1631 + dma_unmap_single(dev, dma, ctx->key_sz, DMA_FROM_DEVICE); 1632 + } 1633 + 1634 + static void hpre_curve25519_cb(struct hpre_ctx *ctx, void *resp) 1635 + { 1636 + struct hpre_dfx *dfx = ctx->hpre->debug.dfx; 1637 + struct hpre_asym_request *req = NULL; 1638 + struct kpp_request *areq; 1639 + u64 overtime_thrhld; 1640 + int ret; 1641 + 1642 + ret = hpre_alg_res_post_hf(ctx, resp, (void **)&req); 1643 + areq = req->areq.curve25519; 1644 + areq->dst_len = ctx->key_sz; 1645 + 1646 + overtime_thrhld = atomic64_read(&dfx[HPRE_OVERTIME_THRHLD].value); 1647 + if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld)) 1648 + atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value); 1649 + 1650 + hpre_key_to_big_end(sg_virt(areq->dst), CURVE25519_KEY_SIZE); 1651 + 1652 + hpre_curve25519_hw_data_clr_all(ctx, req, areq->dst, areq->src); 1653 + kpp_request_complete(areq, ret); 1654 + 1655 + atomic64_inc(&dfx[HPRE_RECV_CNT].value); 1656 + } 1657 + 1658 + static int hpre_curve25519_msg_request_set(struct hpre_ctx *ctx, 1659 + struct kpp_request *req) 1660 + { 1661 + struct hpre_asym_request *h_req; 1662 + struct hpre_sqe *msg; 1663 + int req_id; 1664 + void *tmp; 1665 + 1666 + if (unlikely(req->dst_len < ctx->key_sz)) { 1667 + req->dst_len = ctx->key_sz; 1668 + return -EINVAL; 1669 + } 1670 + 1671 + tmp = kpp_request_ctx(req); 1672 + h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ); 1673 + h_req->cb = hpre_curve25519_cb; 1674 + h_req->areq.curve25519 = req; 1675 + msg = &h_req->req; 1676 + memset(msg, 0, sizeof(*msg)); 1677 + msg->key = cpu_to_le64(ctx->curve25519.dma_p); 1678 + 1679 + msg->dw0 |= cpu_to_le32(0x1U << HPRE_SQE_DONE_SHIFT); 1680 + msg->task_len1 = (ctx->key_sz >> HPRE_BITS_2_BYTES_SHIFT) - 1; 1681 + h_req->ctx = ctx; 1682 + 1683 + req_id = hpre_add_req_to_ctx(h_req); 1684 + if (req_id < 0) 1685 + return -EBUSY; 1686 + 1687 + msg->tag = cpu_to_le16((u16)req_id); 1688 + return 0; 1689 + } 1690 + 1691 + static void hpre_curve25519_src_modulo_p(u8 *ptr) 1692 + { 1693 + int i; 1694 + 1695 + for (i = 0; i < CURVE25519_KEY_SIZE - 1; i++) 1696 + ptr[i] = 0; 1697 + 1698 + /* The modulus is ptr's last byte minus '0xed'(last byte of p) */ 1699 + ptr[i] -= 0xed; 1700 + } 1701 + 1702 + static int hpre_curve25519_src_init(struct hpre_asym_request *hpre_req, 1703 + struct scatterlist *data, unsigned int len) 1704 + { 1705 + struct hpre_sqe *msg = &hpre_req->req; 1706 + struct hpre_ctx *ctx = hpre_req->ctx; 1707 + struct device *dev = HPRE_DEV(ctx); 1708 + u8 p[CURVE25519_KEY_SIZE] = { 0 }; 1709 + const struct ecc_curve *curve; 1710 + dma_addr_t dma = 0; 1711 + u8 *ptr; 1712 + 1713 + if (len != CURVE25519_KEY_SIZE) { 1714 + dev_err(dev, "sourc_data len is not 32bytes, len = %u!\n", len); 1715 + return -EINVAL; 1716 + } 1717 + 1718 + ptr = dma_alloc_coherent(dev, ctx->key_sz, &dma, GFP_KERNEL); 1719 + if (unlikely(!ptr)) 1720 + return -ENOMEM; 1721 + 1722 + scatterwalk_map_and_copy(ptr, data, 0, len, 0); 1723 + 1724 + if (!crypto_memneq(ptr, curve25519_null_point, CURVE25519_KEY_SIZE)) { 1725 + dev_err(dev, "gx is null!\n"); 1726 + goto err; 1727 + } 1728 + 1729 + /* 1730 + * Src_data(gx) is in little-endian order, MSB in the final byte should 1731 + * be masked as described in RFC7748, then transform it to big-endian 1732 + * form, then hisi_hpre can use the data. 1733 + */ 1734 + ptr[31] &= 0x7f; 1735 + hpre_key_to_big_end(ptr, CURVE25519_KEY_SIZE); 1736 + 1737 + curve = ecc_get_curve25519(); 1738 + 1739 + fill_curve_param(p, curve->p, CURVE25519_KEY_SIZE, curve->g.ndigits); 1740 + 1741 + /* 1742 + * When src_data equals (2^255 - 19) ~ (2^255 - 1), it is out of p, 1743 + * we get its modulus to p, and then use it. 1744 + */ 1745 + if (memcmp(ptr, p, ctx->key_sz) >= 0) 1746 + hpre_curve25519_src_modulo_p(ptr); 1747 + 1748 + hpre_req->src = ptr; 1749 + msg->in = cpu_to_le64(dma); 1750 + return 0; 1751 + 1752 + err: 1753 + dma_free_coherent(dev, ctx->key_sz, ptr, dma); 1754 + return -EINVAL; 1755 + } 1756 + 1757 + static int hpre_curve25519_dst_init(struct hpre_asym_request *hpre_req, 1758 + struct scatterlist *data, unsigned int len) 1759 + { 1760 + struct hpre_sqe *msg = &hpre_req->req; 1761 + struct hpre_ctx *ctx = hpre_req->ctx; 1762 + struct device *dev = HPRE_DEV(ctx); 1763 + dma_addr_t dma = 0; 1764 + 1765 + if (!data || !sg_is_last(data) || len != ctx->key_sz) { 1766 + dev_err(dev, "data or data length is illegal!\n"); 1767 + return -EINVAL; 1768 + } 1769 + 1770 + hpre_req->dst = NULL; 1771 + dma = dma_map_single(dev, sg_virt(data), len, DMA_FROM_DEVICE); 1772 + if (unlikely(dma_mapping_error(dev, dma))) { 1773 + dev_err(dev, "dma map data err!\n"); 1774 + return -ENOMEM; 1775 + } 1776 + 1777 + msg->out = cpu_to_le64(dma); 1778 + return 0; 1779 + } 1780 + 1781 + static int hpre_curve25519_compute_value(struct kpp_request *req) 1782 + { 1783 + struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 1784 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1785 + struct device *dev = HPRE_DEV(ctx); 1786 + void *tmp = kpp_request_ctx(req); 1787 + struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ); 1788 + struct hpre_sqe *msg = &hpre_req->req; 1789 + int ret; 1790 + 1791 + ret = hpre_curve25519_msg_request_set(ctx, req); 1792 + if (unlikely(ret)) { 1793 + dev_err(dev, "failed to set curve25519 request, ret = %d!\n", ret); 1794 + return ret; 1795 + } 1796 + 1797 + if (req->src) { 1798 + ret = hpre_curve25519_src_init(hpre_req, req->src, req->src_len); 1799 + if (unlikely(ret)) { 1800 + dev_err(dev, "failed to init src data, ret = %d!\n", 1801 + ret); 1802 + goto clear_all; 1803 + } 1804 + } else { 1805 + msg->in = cpu_to_le64(ctx->curve25519.dma_g); 1806 + } 1807 + 1808 + ret = hpre_curve25519_dst_init(hpre_req, req->dst, req->dst_len); 1809 + if (unlikely(ret)) { 1810 + dev_err(dev, "failed to init dst data, ret = %d!\n", ret); 1811 + goto clear_all; 1812 + } 1813 + 1814 + msg->dw0 = cpu_to_le32(le32_to_cpu(msg->dw0) | HPRE_ALG_CURVE25519_MUL); 1815 + ret = hpre_send(ctx, msg); 1816 + if (likely(!ret)) 1817 + return -EINPROGRESS; 1818 + 1819 + clear_all: 1820 + hpre_rm_req_from_ctx(hpre_req); 1821 + hpre_curve25519_hw_data_clr_all(ctx, hpre_req, req->dst, req->src); 1822 + return ret; 1823 + } 1824 + 1825 + static unsigned int hpre_curve25519_max_size(struct crypto_kpp *tfm) 1826 + { 1827 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1828 + 1829 + return ctx->key_sz; 1830 + } 1831 + 1832 + static int hpre_curve25519_init_tfm(struct crypto_kpp *tfm) 1833 + { 1834 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1835 + 1836 + return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE); 1837 + } 1838 + 1839 + static void hpre_curve25519_exit_tfm(struct crypto_kpp *tfm) 1840 + { 1841 + struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); 1842 + 1843 + hpre_ecc_clear_ctx(ctx, true, false); 1164 1844 } 1165 1845 1166 1846 static struct akcipher_alg rsa = { ··· 1911 1135 }, 1912 1136 }; 1913 1137 1914 - #ifdef CONFIG_CRYPTO_DH 1915 1138 static struct kpp_alg dh = { 1916 1139 .set_secret = hpre_dh_set_secret, 1917 1140 .generate_public_key = hpre_dh_compute_value, ··· 1927 1152 .cra_module = THIS_MODULE, 1928 1153 }, 1929 1154 }; 1930 - #endif 1931 1155 1932 - int hpre_algs_register(void) 1156 + static struct kpp_alg ecdh_nist_p192 = { 1157 + .set_secret = hpre_ecdh_set_secret, 1158 + .generate_public_key = hpre_ecdh_compute_value, 1159 + .compute_shared_secret = hpre_ecdh_compute_value, 1160 + .max_size = hpre_ecdh_max_size, 1161 + .init = hpre_ecdh_nist_p192_init_tfm, 1162 + .exit = hpre_ecdh_exit_tfm, 1163 + .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, 1164 + .base = { 1165 + .cra_ctxsize = sizeof(struct hpre_ctx), 1166 + .cra_priority = HPRE_CRYPTO_ALG_PRI, 1167 + .cra_name = "ecdh-nist-p192", 1168 + .cra_driver_name = "hpre-ecdh", 1169 + .cra_module = THIS_MODULE, 1170 + }, 1171 + }; 1172 + 1173 + static struct kpp_alg ecdh_nist_p256 = { 1174 + .set_secret = hpre_ecdh_set_secret, 1175 + .generate_public_key = hpre_ecdh_compute_value, 1176 + .compute_shared_secret = hpre_ecdh_compute_value, 1177 + .max_size = hpre_ecdh_max_size, 1178 + .init = hpre_ecdh_nist_p256_init_tfm, 1179 + .exit = hpre_ecdh_exit_tfm, 1180 + .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, 1181 + .base = { 1182 + .cra_ctxsize = sizeof(struct hpre_ctx), 1183 + .cra_priority = HPRE_CRYPTO_ALG_PRI, 1184 + .cra_name = "ecdh-nist-p256", 1185 + .cra_driver_name = "hpre-ecdh", 1186 + .cra_module = THIS_MODULE, 1187 + }, 1188 + }; 1189 + 1190 + static struct kpp_alg curve25519_alg = { 1191 + .set_secret = hpre_curve25519_set_secret, 1192 + .generate_public_key = hpre_curve25519_compute_value, 1193 + .compute_shared_secret = hpre_curve25519_compute_value, 1194 + .max_size = hpre_curve25519_max_size, 1195 + .init = hpre_curve25519_init_tfm, 1196 + .exit = hpre_curve25519_exit_tfm, 1197 + .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, 1198 + .base = { 1199 + .cra_ctxsize = sizeof(struct hpre_ctx), 1200 + .cra_priority = HPRE_CRYPTO_ALG_PRI, 1201 + .cra_name = "curve25519", 1202 + .cra_driver_name = "hpre-curve25519", 1203 + .cra_module = THIS_MODULE, 1204 + }, 1205 + }; 1206 + 1207 + 1208 + static int hpre_register_ecdh(void) 1209 + { 1210 + int ret; 1211 + 1212 + ret = crypto_register_kpp(&ecdh_nist_p192); 1213 + if (ret) 1214 + return ret; 1215 + 1216 + ret = crypto_register_kpp(&ecdh_nist_p256); 1217 + if (ret) { 1218 + crypto_unregister_kpp(&ecdh_nist_p192); 1219 + return ret; 1220 + } 1221 + 1222 + return 0; 1223 + } 1224 + 1225 + static void hpre_unregister_ecdh(void) 1226 + { 1227 + crypto_unregister_kpp(&ecdh_nist_p256); 1228 + crypto_unregister_kpp(&ecdh_nist_p192); 1229 + } 1230 + 1231 + int hpre_algs_register(struct hisi_qm *qm) 1933 1232 { 1934 1233 int ret; 1935 1234 ··· 2011 1162 ret = crypto_register_akcipher(&rsa); 2012 1163 if (ret) 2013 1164 return ret; 2014 - #ifdef CONFIG_CRYPTO_DH 1165 + 2015 1166 ret = crypto_register_kpp(&dh); 2016 1167 if (ret) 2017 - crypto_unregister_akcipher(&rsa); 2018 - #endif 1168 + goto unreg_rsa; 2019 1169 1170 + if (qm->ver >= QM_HW_V3) { 1171 + ret = hpre_register_ecdh(); 1172 + if (ret) 1173 + goto unreg_dh; 1174 + ret = crypto_register_kpp(&curve25519_alg); 1175 + if (ret) 1176 + goto unreg_ecdh; 1177 + } 1178 + return 0; 1179 + 1180 + unreg_ecdh: 1181 + hpre_unregister_ecdh(); 1182 + unreg_dh: 1183 + crypto_unregister_kpp(&dh); 1184 + unreg_rsa: 1185 + crypto_unregister_akcipher(&rsa); 2020 1186 return ret; 2021 1187 } 2022 1188 2023 - void hpre_algs_unregister(void) 1189 + void hpre_algs_unregister(struct hisi_qm *qm) 2024 1190 { 2025 - crypto_unregister_akcipher(&rsa); 2026 - #ifdef CONFIG_CRYPTO_DH 1191 + if (qm->ver >= QM_HW_V3) { 1192 + crypto_unregister_kpp(&curve25519_alg); 1193 + hpre_unregister_ecdh(); 1194 + } 1195 + 2027 1196 crypto_unregister_kpp(&dh); 2028 - #endif 1197 + crypto_unregister_akcipher(&rsa); 2029 1198 }
+50 -108
drivers/crypto/hisilicon/hpre/hpre_main.c
··· 13 13 #include <linux/uacce.h> 14 14 #include "hpre.h" 15 15 16 - #define HPRE_QUEUE_NUM_V2 1024 17 16 #define HPRE_QM_ABNML_INT_MASK 0x100004 18 17 #define HPRE_CTRL_CNT_CLR_CE_BIT BIT(0) 19 18 #define HPRE_COMM_CNT_CLR_CE 0x0 ··· 118 119 }; 119 120 120 121 static const char * const hpre_debug_file_name[] = { 121 - [HPRE_CURRENT_QM] = "current_qm", 122 122 [HPRE_CLEAR_ENABLE] = "rdclr_en", 123 123 [HPRE_CLUSTER_CTRL] = "cluster_ctrl", 124 124 }; ··· 224 226 module_param_cb(vfs_num, &vfs_num_ops, &vfs_num, 0444); 225 227 MODULE_PARM_DESC(vfs_num, "Number of VFs to enable(1-63), 0(default)"); 226 228 227 - struct hisi_qp *hpre_create_qp(void) 229 + struct hisi_qp *hpre_create_qp(u8 type) 228 230 { 229 231 int node = cpu_to_node(smp_processor_id()); 230 232 struct hisi_qp *qp = NULL; 231 233 int ret; 232 234 233 - ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp); 235 + if (type != HPRE_V2_ALG_TYPE && type != HPRE_V3_ECC_ALG_TYPE) 236 + return NULL; 237 + 238 + /* 239 + * type: 0 - RSA/DH. algorithm supported in V2, 240 + * 1 - ECC algorithm in V3. 241 + */ 242 + ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, type, node, &qp); 234 243 if (!ret) 235 244 return qp; 236 245 237 246 return NULL; 238 247 } 239 248 240 - static void hpre_pasid_enable(struct hisi_qm *qm) 249 + static void hpre_config_pasid(struct hisi_qm *qm) 241 250 { 242 - u32 val; 251 + u32 val1, val2; 243 252 244 - val = readl_relaxed(qm->io_base + HPRE_DATA_RUSER_CFG); 245 - val |= BIT(HPRE_PASID_EN_BIT); 246 - writel_relaxed(val, qm->io_base + HPRE_DATA_RUSER_CFG); 247 - val = readl_relaxed(qm->io_base + HPRE_DATA_WUSER_CFG); 248 - val |= BIT(HPRE_PASID_EN_BIT); 249 - writel_relaxed(val, qm->io_base + HPRE_DATA_WUSER_CFG); 250 - } 253 + if (qm->ver >= QM_HW_V3) 254 + return; 251 255 252 - static void hpre_pasid_disable(struct hisi_qm *qm) 253 - { 254 - u32 val; 255 - 256 - val = readl_relaxed(qm->io_base + HPRE_DATA_RUSER_CFG); 257 - val &= ~BIT(HPRE_PASID_EN_BIT); 258 - writel_relaxed(val, qm->io_base + HPRE_DATA_RUSER_CFG); 259 - val = readl_relaxed(qm->io_base + HPRE_DATA_WUSER_CFG); 260 - val &= ~BIT(HPRE_PASID_EN_BIT); 261 - writel_relaxed(val, qm->io_base + HPRE_DATA_WUSER_CFG); 256 + val1 = readl_relaxed(qm->io_base + HPRE_DATA_RUSER_CFG); 257 + val2 = readl_relaxed(qm->io_base + HPRE_DATA_WUSER_CFG); 258 + if (qm->use_sva) { 259 + val1 |= BIT(HPRE_PASID_EN_BIT); 260 + val2 |= BIT(HPRE_PASID_EN_BIT); 261 + } else { 262 + val1 &= ~BIT(HPRE_PASID_EN_BIT); 263 + val2 &= ~BIT(HPRE_PASID_EN_BIT); 264 + } 265 + writel_relaxed(val1, qm->io_base + HPRE_DATA_RUSER_CFG); 266 + writel_relaxed(val2, qm->io_base + HPRE_DATA_WUSER_CFG); 262 267 } 263 268 264 269 static int hpre_cfg_by_dsm(struct hisi_qm *qm) ··· 321 320 } 322 321 323 322 /* 324 - * For Kunpeng 920, we shoul disable FLR triggered by hardware (BME/PM/SRIOV). 323 + * For Kunpeng 920, we should disable FLR triggered by hardware (BME/PM/SRIOV). 325 324 * Or it may stay in D3 state when we bind and unbind hpre quickly, 326 325 * as it does FLR triggered by hardware. 327 326 */ ··· 384 383 if (qm->ver == QM_HW_V2) { 385 384 ret = hpre_cfg_by_dsm(qm); 386 385 if (ret) 387 - dev_err(dev, "acpi_evaluate_dsm err.\n"); 386 + return ret; 388 387 389 388 disable_flr_of_bme(qm); 390 - 391 - /* Enable data buffer pasid */ 392 - if (qm->use_sva) 393 - hpre_pasid_enable(qm); 394 389 } 390 + 391 + /* Config data buffer pasid needed by Kunpeng 920 */ 392 + hpre_config_pasid(qm); 395 393 396 394 return ret; 397 395 } ··· 400 400 u8 clusters_num = HPRE_CLUSTERS_NUM(qm); 401 401 unsigned long offset; 402 402 int i; 403 - 404 - /* clear current_qm */ 405 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 406 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 407 403 408 404 /* clear clusterX/cluster_ctrl */ 409 405 for (i = 0; i < clusters_num; i++) { ··· 452 456 return &hpre->qm; 453 457 } 454 458 455 - static u32 hpre_current_qm_read(struct hpre_debugfs_file *file) 456 - { 457 - struct hisi_qm *qm = hpre_file_to_qm(file); 458 - 459 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 460 - } 461 - 462 - static int hpre_current_qm_write(struct hpre_debugfs_file *file, u32 val) 463 - { 464 - struct hisi_qm *qm = hpre_file_to_qm(file); 465 - u32 num_vfs = qm->vfs_num; 466 - u32 vfq_num, tmp; 467 - 468 - if (val > num_vfs) 469 - return -EINVAL; 470 - 471 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 472 - if (val == 0) { 473 - qm->debug.curr_qm_qp_num = qm->qp_num; 474 - } else { 475 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / num_vfs; 476 - if (val == num_vfs) { 477 - qm->debug.curr_qm_qp_num = 478 - qm->ctrl_qp_num - qm->qp_num - (num_vfs - 1) * vfq_num; 479 - } else { 480 - qm->debug.curr_qm_qp_num = vfq_num; 481 - } 482 - } 483 - 484 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 485 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 486 - 487 - tmp = val | 488 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 489 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 490 - 491 - tmp = val | 492 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 493 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 494 - 495 - return 0; 496 - } 497 - 498 459 static u32 hpre_clear_enable_read(struct hpre_debugfs_file *file) 499 460 { 500 461 struct hisi_qm *qm = hpre_file_to_qm(file); ··· 472 519 ~HPRE_CTRL_CNT_CLR_CE_BIT) | val; 473 520 writel(tmp, qm->io_base + HPRE_CTRL_CNT_CLR_CE); 474 521 475 - return 0; 522 + return 0; 476 523 } 477 524 478 525 static u32 hpre_cluster_inqry_read(struct hpre_debugfs_file *file) ··· 494 541 495 542 writel(val, qm->io_base + offset + HPRE_CLUSTER_INQURY); 496 543 497 - return 0; 544 + return 0; 498 545 } 499 546 500 547 static ssize_t hpre_ctrl_debug_read(struct file *filp, char __user *buf, ··· 507 554 508 555 spin_lock_irq(&file->lock); 509 556 switch (file->type) { 510 - case HPRE_CURRENT_QM: 511 - val = hpre_current_qm_read(file); 512 - break; 513 557 case HPRE_CLEAR_ENABLE: 514 558 val = hpre_clear_enable_read(file); 515 559 break; ··· 547 597 548 598 spin_lock_irq(&file->lock); 549 599 switch (file->type) { 550 - case HPRE_CURRENT_QM: 551 - ret = hpre_current_qm_write(file, val); 552 - if (ret) 553 - goto err_input; 554 - break; 555 600 case HPRE_CLEAR_ENABLE: 556 601 ret = hpre_clear_enable_write(file, val); 557 602 if (ret) ··· 685 740 { 686 741 int ret; 687 742 688 - ret = hpre_create_debugfs_file(qm, NULL, HPRE_CURRENT_QM, 689 - HPRE_CURRENT_QM); 690 - if (ret) 691 - return ret; 692 - 693 743 ret = hpre_create_debugfs_file(qm, NULL, HPRE_CLEAR_ENABLE, 694 744 HPRE_CLEAR_ENABLE); 695 745 if (ret) ··· 752 812 } 753 813 754 814 if (pdev->revision >= QM_HW_V3) 755 - qm->algs = "rsa\ndh\necdh\nx25519\nx448\necdsa\nsm2\n"; 815 + qm->algs = "rsa\ndh\necdh\nx25519\nx448\necdsa\nsm2"; 756 816 else 757 - qm->algs = "rsa\ndh\n"; 817 + qm->algs = "rsa\ndh"; 758 818 qm->mode = uacce_mode; 759 819 qm->pdev = pdev; 760 820 qm->ver = pdev->revision; ··· 807 867 HPRE_ADDR(qm, HPRE_AM_OOO_SHUTDOWN_ENB)); 808 868 } 809 869 870 + static void hpre_err_info_init(struct hisi_qm *qm) 871 + { 872 + struct hisi_qm_err_info *err_info = &qm->err_info; 873 + 874 + err_info->ce = QM_BASE_CE; 875 + err_info->fe = 0; 876 + err_info->ecc_2bits_mask = HPRE_CORE_ECC_2BIT_ERR | 877 + HPRE_OOO_ECC_2BIT_ERR; 878 + err_info->dev_ce_mask = HPRE_HAC_RAS_CE_ENABLE; 879 + err_info->msi_wr_port = HPRE_WR_MSI_PORT; 880 + err_info->acpi_rst = "HRST"; 881 + err_info->nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT; 882 + } 883 + 810 884 static const struct hisi_qm_err_ini hpre_err_ini = { 811 885 .hw_init = hpre_set_user_domain_and_cache, 812 886 .hw_err_enable = hpre_hw_error_enable, ··· 829 875 .clear_dev_hw_err_status = hpre_clear_hw_err_status, 830 876 .log_dev_hw_err = hpre_log_hw_error, 831 877 .open_axi_master_ooo = hpre_open_axi_master_ooo, 832 - .err_info = { 833 - .ce = QM_BASE_CE, 834 - .nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT, 835 - .fe = 0, 836 - .ecc_2bits_mask = HPRE_CORE_ECC_2BIT_ERR | 837 - HPRE_OOO_ECC_2BIT_ERR, 838 - .dev_ce_mask = HPRE_HAC_RAS_CE_ENABLE, 839 - .msi_wr_port = HPRE_WR_MSI_PORT, 840 - .acpi_rst = "HRST", 841 - } 878 + .err_info_init = hpre_err_info_init, 842 879 }; 843 880 844 881 static int hpre_pf_probe_init(struct hpre *hpre) ··· 837 892 struct hisi_qm *qm = &hpre->qm; 838 893 int ret; 839 894 840 - qm->ctrl_qp_num = HPRE_QUEUE_NUM_V2; 841 - 842 895 ret = hpre_set_user_domain_and_cache(qm); 843 896 if (ret) 844 897 return ret; 845 898 846 899 qm->err_ini = &hpre_err_ini; 900 + qm->err_ini->err_info_init(qm); 847 901 hisi_qm_dev_err_init(qm); 848 902 849 903 return 0; ··· 950 1006 hisi_qm_stop(qm, QM_NORMAL); 951 1007 952 1008 if (qm->fun_type == QM_HW_PF) { 953 - if (qm->use_sva && qm->ver == QM_HW_V2) 954 - hpre_pasid_disable(qm); 955 1009 hpre_cnt_regs_clear(qm); 956 1010 qm->debug.curr_qm_qp_num = 0; 957 1011 hisi_qm_dev_err_uninit(qm); ··· 957 1015 958 1016 hisi_qm_uninit(qm); 959 1017 } 960 - 961 1018 962 1019 static const struct pci_error_handlers hpre_err_handler = { 963 1020 .error_detected = hisi_qm_dev_err_detected, ··· 1016 1075 1017 1076 MODULE_LICENSE("GPL v2"); 1018 1077 MODULE_AUTHOR("Zaibo Xu <xuzaibo@huawei.com>"); 1078 + MODULE_AUTHOR("Meng Yu <yumeng18@huawei.com>"); 1019 1079 MODULE_DESCRIPTION("Driver for HiSilicon HPRE accelerator");
+306 -90
drivers/crypto/hisilicon/qm.c
··· 38 38 #define QM_MB_CMD_SQC_BT 0x4 39 39 #define QM_MB_CMD_CQC_BT 0x5 40 40 #define QM_MB_CMD_SQC_VFT_V2 0x6 41 + #define QM_MB_CMD_STOP_QP 0x8 41 42 42 43 #define QM_MB_CMD_SEND_BASE 0x300 43 44 #define QM_MB_EVENT_SHIFT 8 ··· 94 93 #define QM_DB_PRIORITY_SHIFT_V1 48 95 94 #define QM_DOORBELL_SQ_CQ_BASE_V2 0x1000 96 95 #define QM_DOORBELL_EQ_AEQ_BASE_V2 0x2000 96 + #define QM_QUE_ISO_CFG_V 0x0030 97 + #define QM_QUE_ISO_EN 0x100154 98 + #define QM_CAPBILITY 0x100158 99 + #define QM_QP_NUN_MASK GENMASK(10, 0) 100 + #define QM_QP_DB_INTERVAL 0x10000 101 + #define QM_QP_MAX_NUM_SHIFT 11 97 102 #define QM_DB_CMD_SHIFT_V2 12 98 103 #define QM_DB_RAND_SHIFT_V2 16 99 104 #define QM_DB_INDEX_SHIFT_V2 32 ··· 136 129 #define QM_DFX_CNT_CLR_CE 0x100118 137 130 138 131 #define QM_ABNORMAL_INT_SOURCE 0x100000 139 - #define QM_ABNORMAL_INT_SOURCE_CLR GENMASK(12, 0) 132 + #define QM_ABNORMAL_INT_SOURCE_CLR GENMASK(14, 0) 140 133 #define QM_ABNORMAL_INT_MASK 0x100004 141 - #define QM_ABNORMAL_INT_MASK_VALUE 0x1fff 134 + #define QM_ABNORMAL_INT_MASK_VALUE 0x7fff 142 135 #define QM_ABNORMAL_INT_STATUS 0x100008 143 136 #define QM_ABNORMAL_INT_SET 0x10000c 144 137 #define QM_ABNORMAL_INF00 0x100010 ··· 171 164 #define ACC_AM_ROB_ECC_INT_STS 0x300104 172 165 #define ACC_ROB_ECC_ERR_MULTPL BIT(1) 173 166 167 + #define QM_DFX_MB_CNT_VF 0x104010 168 + #define QM_DFX_DB_CNT_VF 0x104020 169 + #define QM_DFX_SQE_CNT_VF_SQN 0x104030 170 + #define QM_DFX_CQE_CNT_VF_CQN 0x104040 171 + #define QM_DFX_QN_SHIFT 16 172 + #define CURRENT_FUN_MASK GENMASK(5, 0) 173 + #define CURRENT_Q_MASK GENMASK(31, 16) 174 + 174 175 #define POLL_PERIOD 10 175 176 #define POLL_TIMEOUT 1000 176 177 #define WAIT_PERIOD_US_MAX 200 ··· 188 173 #define QM_CACHE_WB_DONE 0x208 189 174 190 175 #define PCI_BAR_2 2 176 + #define PCI_BAR_4 4 191 177 #define QM_SQE_DATA_ALIGN_MASK GENMASK(6, 0) 192 178 #define QMC_ALIGN(sz) ALIGN(sz, 32) 193 179 ··· 350 334 void (*hw_error_init)(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe); 351 335 void (*hw_error_uninit)(struct hisi_qm *qm); 352 336 enum acc_err_result (*hw_error_handle)(struct hisi_qm *qm); 337 + int (*stop_qp)(struct hisi_qp *qp); 353 338 }; 354 339 355 340 struct qm_dfx_item { ··· 367 350 }; 368 351 369 352 static const char * const qm_debug_file_name[] = { 353 + [CURRENT_QM] = "current_qm", 370 354 [CURRENT_Q] = "current_q", 371 355 [CLEAR_ENABLE] = "clear_enable", 372 356 }; ··· 391 373 { .int_msk = BIT(10), .msg = "qm_db_timeout" }, 392 374 { .int_msk = BIT(11), .msg = "qm_of_fifo_of" }, 393 375 { .int_msk = BIT(12), .msg = "qm_db_random_invalid" }, 376 + { .int_msk = BIT(13), .msg = "qm_mailbox_timeout" }, 377 + { .int_msk = BIT(14), .msg = "qm_flr_timeout" }, 394 378 { /* sentinel */ } 395 379 }; 396 380 ··· 577 557 578 558 static void qm_db_v2(struct hisi_qm *qm, u16 qn, u8 cmd, u16 index, u8 priority) 579 559 { 580 - u64 doorbell; 581 - u64 dbase; 560 + void __iomem *io_base = qm->io_base; 582 561 u16 randata = 0; 562 + u64 doorbell; 583 563 584 564 if (cmd == QM_DOORBELL_CMD_SQ || cmd == QM_DOORBELL_CMD_CQ) 585 - dbase = QM_DOORBELL_SQ_CQ_BASE_V2; 565 + io_base = qm->db_io_base + (u64)qn * qm->db_interval + 566 + QM_DOORBELL_SQ_CQ_BASE_V2; 586 567 else 587 - dbase = QM_DOORBELL_EQ_AEQ_BASE_V2; 568 + io_base += QM_DOORBELL_EQ_AEQ_BASE_V2; 588 569 589 570 doorbell = qn | ((u64)cmd << QM_DB_CMD_SHIFT_V2) | 590 571 ((u64)randata << QM_DB_RAND_SHIFT_V2) | 591 572 ((u64)index << QM_DB_INDEX_SHIFT_V2) | 592 573 ((u64)priority << QM_DB_PRIORITY_SHIFT_V2); 593 574 594 - writeq(doorbell, qm->io_base + dbase); 575 + writeq(doorbell, io_base); 595 576 } 596 577 597 578 static void qm_db(struct hisi_qm *qm, u16 qn, u8 cmd, u16 index, u8 priority) ··· 886 865 return 0; 887 866 } 888 867 868 + static int qm_get_vf_qp_num(struct hisi_qm *qm, u32 fun_num) 869 + { 870 + u32 remain_q_num, vfq_num; 871 + u32 num_vfs = qm->vfs_num; 872 + 873 + vfq_num = (qm->ctrl_qp_num - qm->qp_num) / num_vfs; 874 + if (vfq_num >= qm->max_qp_num) 875 + return qm->max_qp_num; 876 + 877 + remain_q_num = (qm->ctrl_qp_num - qm->qp_num) % num_vfs; 878 + if (vfq_num + remain_q_num <= qm->max_qp_num) 879 + return fun_num == num_vfs ? vfq_num + remain_q_num : vfq_num; 880 + 881 + /* 882 + * if vfq_num + remain_q_num > max_qp_num, the last VFs, 883 + * each with one more queue. 884 + */ 885 + return fun_num + remain_q_num > num_vfs ? vfq_num + 1 : vfq_num; 886 + } 887 + 889 888 static struct hisi_qm *file_to_qm(struct debugfs_file *file) 890 889 { 891 890 struct qm_debug *debug = file->debug; ··· 959 918 return 0; 960 919 } 961 920 921 + static u32 current_qm_read(struct debugfs_file *file) 922 + { 923 + struct hisi_qm *qm = file_to_qm(file); 924 + 925 + return readl(qm->io_base + QM_DFX_MB_CNT_VF); 926 + } 927 + 928 + static int current_qm_write(struct debugfs_file *file, u32 val) 929 + { 930 + struct hisi_qm *qm = file_to_qm(file); 931 + u32 tmp; 932 + 933 + if (val > qm->vfs_num) 934 + return -EINVAL; 935 + 936 + /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 937 + if (!val) 938 + qm->debug.curr_qm_qp_num = qm->qp_num; 939 + else 940 + qm->debug.curr_qm_qp_num = qm_get_vf_qp_num(qm, val); 941 + 942 + writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 943 + writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 944 + 945 + tmp = val | 946 + (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 947 + writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 948 + 949 + tmp = val | 950 + (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 951 + writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 952 + 953 + return 0; 954 + } 955 + 962 956 static ssize_t qm_debug_read(struct file *filp, char __user *buf, 963 957 size_t count, loff_t *pos) 964 958 { ··· 1005 929 1006 930 mutex_lock(&file->lock); 1007 931 switch (index) { 932 + case CURRENT_QM: 933 + val = current_qm_read(file); 934 + break; 1008 935 case CURRENT_Q: 1009 936 val = current_q_read(file); 1010 937 break; ··· 1050 971 1051 972 mutex_lock(&file->lock); 1052 973 switch (index) { 974 + case CURRENT_QM: 975 + ret = current_qm_write(file, val); 976 + break; 1053 977 case CURRENT_Q: 1054 978 ret = current_q_write(file, val); 1055 - if (ret) 1056 - goto err_input; 1057 979 break; 1058 980 case CLEAR_ENABLE: 1059 981 ret = clear_enable_write(file, val); 1060 - if (ret) 1061 - goto err_input; 1062 982 break; 1063 983 default: 1064 984 ret = -EINVAL; 1065 - goto err_input; 1066 985 } 1067 986 mutex_unlock(&file->lock); 1068 987 1069 - return count; 988 + if (ret) 989 + return ret; 1070 990 1071 - err_input: 1072 - mutex_unlock(&file->lock); 1073 - return ret; 991 + return count; 1074 992 } 1075 993 1076 994 static const struct file_operations qm_debug_fops = { ··· 1605 1529 .write = qm_cmd_write, 1606 1530 }; 1607 1531 1608 - static void qm_create_debugfs_file(struct hisi_qm *qm, enum qm_debug_file index) 1532 + static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir, 1533 + enum qm_debug_file index) 1609 1534 { 1610 - struct dentry *qm_d = qm->debug.qm_d; 1611 1535 struct debugfs_file *file = qm->debug.files + index; 1612 1536 1613 - debugfs_create_file(qm_debug_file_name[index], 0600, qm_d, file, 1537 + debugfs_create_file(qm_debug_file_name[index], 0600, dir, file, 1614 1538 &qm_debug_fops); 1615 1539 1616 1540 file->index = index; ··· 1704 1628 if (val == (QM_DB_RANDOM_INVALID | QM_BASE_CE)) { 1705 1629 writel(error_status, qm->io_base + 1706 1630 QM_ABNORMAL_INT_SOURCE); 1707 - writel(qm->err_ini->err_info.nfe, 1631 + writel(qm->err_info.nfe, 1708 1632 qm->io_base + QM_RAS_NFE_ENABLE); 1709 1633 return ACC_ERR_RECOVERED; 1710 1634 } ··· 1713 1637 } 1714 1638 1715 1639 return ACC_ERR_RECOVERED; 1640 + } 1641 + 1642 + static int qm_stop_qp(struct hisi_qp *qp) 1643 + { 1644 + return qm_mb(qp->qm, QM_MB_CMD_STOP_QP, 0, qp->qp_id, 0); 1716 1645 } 1717 1646 1718 1647 static const struct hisi_qm_hw_ops qm_hw_ops_v1 = { ··· 1733 1652 .hw_error_init = qm_hw_error_init_v2, 1734 1653 .hw_error_uninit = qm_hw_error_uninit_v2, 1735 1654 .hw_error_handle = qm_hw_error_handle_v2, 1655 + }; 1656 + 1657 + static const struct hisi_qm_hw_ops qm_hw_ops_v3 = { 1658 + .get_vft = qm_get_vft_v2, 1659 + .qm_db = qm_db_v2, 1660 + .get_irq_num = qm_get_irq_num_v2, 1661 + .hw_error_init = qm_hw_error_init_v2, 1662 + .hw_error_uninit = qm_hw_error_uninit_v2, 1663 + .hw_error_handle = qm_hw_error_handle_v2, 1664 + .stop_qp = qm_stop_qp, 1736 1665 }; 1737 1666 1738 1667 static void *qm_get_avail_sqe(struct hisi_qp *qp) ··· 2024 1933 if (qm->err_status.is_qm_ecc_mbit || qm->err_status.is_dev_ecc_mbit) 2025 1934 return 0; 2026 1935 1936 + /* Kunpeng930 supports drain qp by device */ 1937 + if (qm->ops->stop_qp) { 1938 + ret = qm->ops->stop_qp(qp); 1939 + if (ret) 1940 + dev_err(dev, "Failed to stop qp(%u)!\n", qp->qp_id); 1941 + return ret; 1942 + } 1943 + 2027 1944 addr = qm_ctx_alloc(qm, size, &dma_addr); 2028 1945 if (IS_ERR(addr)) { 2029 1946 dev_err(dev, "Failed to alloc ctx for sqc and cqc!\n"); ··· 2231 2132 { 2232 2133 struct hisi_qp *qp = q->priv; 2233 2134 struct hisi_qm *qm = qp->qm; 2135 + resource_size_t phys_base = qm->db_phys_base + 2136 + qp->qp_id * qm->db_interval; 2234 2137 size_t sz = vma->vm_end - vma->vm_start; 2235 2138 struct pci_dev *pdev = qm->pdev; 2236 2139 struct device *dev = &pdev->dev; ··· 2244 2143 if (qm->ver == QM_HW_V1) { 2245 2144 if (sz > PAGE_SIZE * QM_DOORBELL_PAGE_NR) 2246 2145 return -EINVAL; 2247 - } else { 2146 + } else if (qm->ver == QM_HW_V2 || !qm->use_db_isolation) { 2248 2147 if (sz > PAGE_SIZE * (QM_DOORBELL_PAGE_NR + 2249 2148 QM_DOORBELL_SQ_CQ_BASE_V2 / PAGE_SIZE)) 2149 + return -EINVAL; 2150 + } else { 2151 + if (sz > qm->db_interval) 2250 2152 return -EINVAL; 2251 2153 } 2252 2154 2253 2155 vma->vm_flags |= VM_IO; 2254 2156 2255 2157 return remap_pfn_range(vma, vma->vm_start, 2256 - qm->phys_base >> PAGE_SHIFT, 2158 + phys_base >> PAGE_SHIFT, 2257 2159 sz, pgprot_noncached(vma->vm_page_prot)); 2258 2160 case UACCE_QFRT_DUS: 2259 2161 if (sz != qp->qdma.size) ··· 2371 2267 uacce->priv = qm; 2372 2268 uacce->algs = qm->algs; 2373 2269 2374 - if (qm->ver == QM_HW_V1) { 2375 - mmio_page_nr = QM_DOORBELL_PAGE_NR; 2270 + if (qm->ver == QM_HW_V1) 2376 2271 uacce->api_ver = HISI_QM_API_VER_BASE; 2377 - } else { 2272 + else if (qm->ver == QM_HW_V2) 2273 + uacce->api_ver = HISI_QM_API_VER2_BASE; 2274 + else 2275 + uacce->api_ver = HISI_QM_API_VER3_BASE; 2276 + 2277 + if (qm->ver == QM_HW_V1) 2278 + mmio_page_nr = QM_DOORBELL_PAGE_NR; 2279 + else if (qm->ver == QM_HW_V2 || !qm->use_db_isolation) 2378 2280 mmio_page_nr = QM_DOORBELL_PAGE_NR + 2379 2281 QM_DOORBELL_SQ_CQ_BASE_V2 / PAGE_SIZE; 2380 - uacce->api_ver = HISI_QM_API_VER2_BASE; 2381 - } 2282 + else 2283 + mmio_page_nr = qm->db_interval / PAGE_SIZE; 2382 2284 2383 2285 dus_page_nr = (PAGE_SIZE - 1 + qm->sqe_size * QM_Q_DEPTH + 2384 2286 sizeof(struct qm_cqe) * QM_Q_DEPTH) >> PAGE_SHIFT; ··· 2592 2482 2593 2483 if (qm->ver == QM_HW_V1) 2594 2484 qm->ops = &qm_hw_ops_v1; 2595 - else 2485 + else if (qm->ver == QM_HW_V2) 2596 2486 qm->ops = &qm_hw_ops_v2; 2487 + else 2488 + qm->ops = &qm_hw_ops_v3; 2597 2489 2598 2490 pci_set_drvdata(pdev, qm); 2599 2491 mutex_init(&qm->mailbox_lock); ··· 2604 2492 qm->misc_ctl = false; 2605 2493 } 2606 2494 2495 + static void qm_put_pci_res(struct hisi_qm *qm) 2496 + { 2497 + struct pci_dev *pdev = qm->pdev; 2498 + 2499 + if (qm->use_db_isolation) 2500 + iounmap(qm->db_io_base); 2501 + 2502 + iounmap(qm->io_base); 2503 + pci_release_mem_regions(pdev); 2504 + } 2505 + 2607 2506 static void hisi_qm_pci_uninit(struct hisi_qm *qm) 2608 2507 { 2609 2508 struct pci_dev *pdev = qm->pdev; 2610 2509 2611 2510 pci_free_irq_vectors(pdev); 2612 - iounmap(qm->io_base); 2613 - pci_release_mem_regions(pdev); 2511 + qm_put_pci_res(qm); 2614 2512 pci_disable_device(pdev); 2615 2513 } 2616 2514 ··· 2649 2527 hisi_qm_cache_wb(qm); 2650 2528 dma_free_coherent(dev, qm->qdma.size, 2651 2529 qm->qdma.va, qm->qdma.dma); 2652 - memset(&qm->qdma, 0, sizeof(qm->qdma)); 2653 2530 } 2654 2531 2655 2532 qm_irq_unregister(qm); ··· 2802 2681 { 2803 2682 int ret; 2804 2683 2805 - WARN_ON(!qm->qdma.dma); 2684 + WARN_ON(!qm->qdma.va); 2806 2685 2807 2686 if (qm->fun_type == QM_HW_PF) { 2808 2687 ret = qm_dev_mem_reset(qm); ··· 3051 2930 qm->debug.qm_d = qm_d; 3052 2931 3053 2932 /* only show this in PF */ 3054 - if (qm->fun_type == QM_HW_PF) 2933 + if (qm->fun_type == QM_HW_PF) { 2934 + qm_create_debugfs_file(qm, qm->debug.debug_root, CURRENT_QM); 3055 2935 for (i = CURRENT_Q; i < DEBUG_FILE_NUM; i++) 3056 - qm_create_debugfs_file(qm, i); 2936 + qm_create_debugfs_file(qm, qm_d, i); 2937 + } 3057 2938 3058 2939 debugfs_create_file("regs", 0444, qm->debug.qm_d, qm, &qm_regs_fops); 3059 2940 ··· 3083 2960 struct qm_dfx_registers *regs; 3084 2961 int i; 3085 2962 2963 + /* clear current_qm */ 2964 + writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 2965 + writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 2966 + 3086 2967 /* clear current_q */ 3087 2968 writel(0x0, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 3088 2969 writel(0x0, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); ··· 3109 2982 3110 2983 static void qm_hw_error_init(struct hisi_qm *qm) 3111 2984 { 3112 - const struct hisi_qm_err_info *err_info = &qm->err_ini->err_info; 2985 + struct hisi_qm_err_info *err_info = &qm->err_info; 3113 2986 3114 2987 if (!qm->ops->hw_error_init) { 3115 2988 dev_err(&qm->pdev->dev, "QM doesn't support hw error handling!\n"); ··· 3302 3175 3303 3176 static int qm_vf_q_assign(struct hisi_qm *qm, u32 num_vfs) 3304 3177 { 3305 - u32 remain_q_num, q_num, i, j; 3178 + u32 remain_q_num, vfs_q_num, act_q_num, q_num, i, j; 3179 + u32 max_qp_num = qm->max_qp_num; 3306 3180 u32 q_base = qm->qp_num; 3307 3181 int ret; 3308 3182 3309 3183 if (!num_vfs) 3310 3184 return -EINVAL; 3311 3185 3312 - remain_q_num = qm->ctrl_qp_num - qm->qp_num; 3186 + vfs_q_num = qm->ctrl_qp_num - qm->qp_num; 3313 3187 3314 - /* If remain queues not enough, return error. */ 3315 - if (qm->ctrl_qp_num < qm->qp_num || remain_q_num < num_vfs) 3188 + /* If vfs_q_num is less than num_vfs, return error. */ 3189 + if (vfs_q_num < num_vfs) 3316 3190 return -EINVAL; 3317 3191 3318 - q_num = remain_q_num / num_vfs; 3319 - for (i = 1; i <= num_vfs; i++) { 3320 - if (i == num_vfs) 3321 - q_num += remain_q_num % num_vfs; 3322 - ret = hisi_qm_set_vft(qm, i, q_base, q_num); 3192 + q_num = vfs_q_num / num_vfs; 3193 + remain_q_num = vfs_q_num % num_vfs; 3194 + 3195 + for (i = num_vfs; i > 0; i--) { 3196 + /* 3197 + * if q_num + remain_q_num > max_qp_num in last vf, divide the 3198 + * remaining queues equally. 3199 + */ 3200 + if (i == num_vfs && q_num + remain_q_num <= max_qp_num) { 3201 + act_q_num = q_num + remain_q_num; 3202 + remain_q_num = 0; 3203 + } else if (remain_q_num > 0) { 3204 + act_q_num = q_num + 1; 3205 + remain_q_num--; 3206 + } else { 3207 + act_q_num = q_num; 3208 + } 3209 + 3210 + act_q_num = min_t(int, act_q_num, max_qp_num); 3211 + ret = hisi_qm_set_vft(qm, i, q_base, act_q_num); 3323 3212 if (ret) { 3324 - for (j = i; j > 0; j--) 3213 + for (j = num_vfs; j > i; j--) 3325 3214 hisi_qm_set_vft(qm, j, 0, 0); 3326 3215 return ret; 3327 3216 } 3328 - q_base += q_num; 3217 + q_base += act_q_num; 3329 3218 } 3330 3219 3331 3220 return 0; ··· 3461 3318 /* get device hardware error status */ 3462 3319 err_sts = qm->err_ini->get_dev_hw_err_status(qm); 3463 3320 if (err_sts) { 3464 - if (err_sts & qm->err_ini->err_info.ecc_2bits_mask) 3321 + if (err_sts & qm->err_info.ecc_2bits_mask) 3465 3322 qm->err_status.is_dev_ecc_mbit = true; 3466 3323 3467 3324 if (qm->err_ini->log_dev_hw_err) 3468 3325 qm->err_ini->log_dev_hw_err(qm, err_sts); 3469 3326 3470 3327 /* ce error does not need to be reset */ 3471 - if ((err_sts | qm->err_ini->err_info.dev_ce_mask) == 3472 - qm->err_ini->err_info.dev_ce_mask) { 3328 + if ((err_sts | qm->err_info.dev_ce_mask) == 3329 + qm->err_info.dev_ce_mask) { 3473 3330 if (qm->err_ini->clear_dev_hw_err_status) 3474 3331 qm->err_ini->clear_dev_hw_err_status(qm, 3475 3332 err_sts); ··· 3782 3639 acpi_status s; 3783 3640 3784 3641 s = acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev), 3785 - qm->err_ini->err_info.acpi_rst, 3642 + qm->err_info.acpi_rst, 3786 3643 NULL, &value); 3787 3644 if (ACPI_FAILURE(s)) { 3788 3645 pci_err(pdev, "NO controller reset method!\n"); ··· 3850 3707 3851 3708 /* temporarily close the OOO port used for PEH to write out MSI */ 3852 3709 value = readl(qm->io_base + ACC_AM_CFG_PORT_WR_EN); 3853 - writel(value & ~qm->err_ini->err_info.msi_wr_port, 3710 + writel(value & ~qm->err_info.msi_wr_port, 3854 3711 qm->io_base + ACC_AM_CFG_PORT_WR_EN); 3855 3712 3856 3713 /* clear dev ecc 2bit error source if having */ 3857 - value = qm_get_dev_err_status(qm) & 3858 - qm->err_ini->err_info.ecc_2bits_mask; 3714 + value = qm_get_dev_err_status(qm) & qm->err_info.ecc_2bits_mask; 3859 3715 if (value && qm->err_ini->clear_dev_hw_err_status) 3860 3716 qm->err_ini->clear_dev_hw_err_status(qm, value); 3861 3717 ··· 3878 3736 3879 3737 /* open the OOO port for PEH to write out MSI */ 3880 3738 value = readl(qm->io_base + ACC_AM_CFG_PORT_WR_EN); 3881 - value |= qm->err_ini->err_info.msi_wr_port; 3739 + value |= qm->err_info.msi_wr_port; 3882 3740 writel(value, qm->io_base + ACC_AM_CFG_PORT_WR_EN); 3883 3741 3884 3742 qm->err_status.is_qm_ecc_mbit = false; ··· 4017 3875 if (ret) 4018 3876 return ret; 4019 3877 4020 - return (qm_get_dev_err_status(qm) & 4021 - qm->err_ini->err_info.ecc_2bits_mask); 3878 + return (qm_get_dev_err_status(qm) & qm->err_info.ecc_2bits_mask); 4022 3879 } 4023 3880 4024 3881 void hisi_qm_reset_prepare(struct pci_dev *pdev) ··· 4225 4084 mutex_unlock(&qm_list->lock); 4226 4085 4227 4086 if (flag) { 4228 - ret = qm_list->register_to_crypto(); 4087 + ret = qm_list->register_to_crypto(qm); 4229 4088 if (ret) { 4230 4089 mutex_lock(&qm_list->lock); 4231 4090 list_del(&qm->list); ··· 4256 4115 mutex_unlock(&qm_list->lock); 4257 4116 4258 4117 if (list_empty(&qm_list->list)) 4259 - qm_list->unregister_from_crypto(); 4118 + qm_list->unregister_from_crypto(qm); 4260 4119 } 4261 4120 EXPORT_SYMBOL_GPL(hisi_qm_alg_unregister); 4121 + 4122 + static int qm_get_qp_num(struct hisi_qm *qm) 4123 + { 4124 + if (qm->ver == QM_HW_V1) 4125 + qm->ctrl_qp_num = QM_QNUM_V1; 4126 + else if (qm->ver == QM_HW_V2) 4127 + qm->ctrl_qp_num = QM_QNUM_V2; 4128 + else 4129 + qm->ctrl_qp_num = readl(qm->io_base + QM_CAPBILITY) & 4130 + QM_QP_NUN_MASK; 4131 + 4132 + if (qm->use_db_isolation) 4133 + qm->max_qp_num = (readl(qm->io_base + QM_CAPBILITY) >> 4134 + QM_QP_MAX_NUM_SHIFT) & QM_QP_NUN_MASK; 4135 + else 4136 + qm->max_qp_num = qm->ctrl_qp_num; 4137 + 4138 + /* check if qp number is valid */ 4139 + if (qm->qp_num > qm->max_qp_num) { 4140 + dev_err(&qm->pdev->dev, "qp num(%u) is more than max qp num(%u)!\n", 4141 + qm->qp_num, qm->max_qp_num); 4142 + return -EINVAL; 4143 + } 4144 + 4145 + return 0; 4146 + } 4147 + 4148 + static int qm_get_pci_res(struct hisi_qm *qm) 4149 + { 4150 + struct pci_dev *pdev = qm->pdev; 4151 + struct device *dev = &pdev->dev; 4152 + int ret; 4153 + 4154 + ret = pci_request_mem_regions(pdev, qm->dev_name); 4155 + if (ret < 0) { 4156 + dev_err(dev, "Failed to request mem regions!\n"); 4157 + return ret; 4158 + } 4159 + 4160 + qm->phys_base = pci_resource_start(pdev, PCI_BAR_2); 4161 + qm->io_base = ioremap(qm->phys_base, pci_resource_len(pdev, PCI_BAR_2)); 4162 + if (!qm->io_base) { 4163 + ret = -EIO; 4164 + goto err_request_mem_regions; 4165 + } 4166 + 4167 + if (qm->ver > QM_HW_V2) { 4168 + if (qm->fun_type == QM_HW_PF) 4169 + qm->use_db_isolation = readl(qm->io_base + 4170 + QM_QUE_ISO_EN) & BIT(0); 4171 + else 4172 + qm->use_db_isolation = readl(qm->io_base + 4173 + QM_QUE_ISO_CFG_V) & BIT(0); 4174 + } 4175 + 4176 + if (qm->use_db_isolation) { 4177 + qm->db_interval = QM_QP_DB_INTERVAL; 4178 + qm->db_phys_base = pci_resource_start(pdev, PCI_BAR_4); 4179 + qm->db_io_base = ioremap(qm->db_phys_base, 4180 + pci_resource_len(pdev, PCI_BAR_4)); 4181 + if (!qm->db_io_base) { 4182 + ret = -EIO; 4183 + goto err_ioremap; 4184 + } 4185 + } else { 4186 + qm->db_phys_base = qm->phys_base; 4187 + qm->db_io_base = qm->io_base; 4188 + qm->db_interval = 0; 4189 + } 4190 + 4191 + if (qm->fun_type == QM_HW_PF) { 4192 + ret = qm_get_qp_num(qm); 4193 + if (ret) 4194 + goto err_db_ioremap; 4195 + } 4196 + 4197 + return 0; 4198 + 4199 + err_db_ioremap: 4200 + if (qm->use_db_isolation) 4201 + iounmap(qm->db_io_base); 4202 + err_ioremap: 4203 + iounmap(qm->io_base); 4204 + err_request_mem_regions: 4205 + pci_release_mem_regions(pdev); 4206 + return ret; 4207 + } 4262 4208 4263 4209 static int hisi_qm_pci_init(struct hisi_qm *qm) 4264 4210 { ··· 4360 4132 return ret; 4361 4133 } 4362 4134 4363 - ret = pci_request_mem_regions(pdev, qm->dev_name); 4364 - if (ret < 0) { 4365 - dev_err(dev, "Failed to request mem regions!\n"); 4135 + ret = qm_get_pci_res(qm); 4136 + if (ret) 4366 4137 goto err_disable_pcidev; 4367 - } 4368 - 4369 - qm->phys_base = pci_resource_start(pdev, PCI_BAR_2); 4370 - qm->phys_size = pci_resource_len(qm->pdev, PCI_BAR_2); 4371 - qm->io_base = ioremap(qm->phys_base, qm->phys_size); 4372 - if (!qm->io_base) { 4373 - ret = -EIO; 4374 - goto err_release_mem_regions; 4375 - } 4376 4138 4377 4139 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); 4378 4140 if (ret < 0) 4379 - goto err_iounmap; 4141 + goto err_get_pci_res; 4380 4142 pci_set_master(pdev); 4381 4143 4382 4144 if (!qm->ops->get_irq_num) { 4383 4145 ret = -EOPNOTSUPP; 4384 - goto err_iounmap; 4146 + goto err_get_pci_res; 4385 4147 } 4386 4148 num_vec = qm->ops->get_irq_num(qm); 4387 4149 ret = pci_alloc_irq_vectors(pdev, num_vec, num_vec, PCI_IRQ_MSI); 4388 4150 if (ret < 0) { 4389 4151 dev_err(dev, "Failed to enable MSI vectors!\n"); 4390 - goto err_iounmap; 4152 + goto err_get_pci_res; 4391 4153 } 4392 4154 4393 4155 return 0; 4394 4156 4395 - err_iounmap: 4396 - iounmap(qm->io_base); 4397 - err_release_mem_regions: 4398 - pci_release_mem_regions(pdev); 4157 + err_get_pci_res: 4158 + qm_put_pci_res(qm); 4399 4159 err_disable_pcidev: 4400 4160 pci_disable_device(pdev); 4401 4161 return ret; ··· 4403 4187 4404 4188 hisi_qm_pre_init(qm); 4405 4189 4406 - ret = qm_alloc_uacce(qm); 4407 - if (ret < 0) 4408 - dev_warn(dev, "fail to alloc uacce (%d)\n", ret); 4409 - 4410 4190 ret = hisi_qm_pci_init(qm); 4411 4191 if (ret) 4412 - goto err_remove_uacce; 4192 + return ret; 4413 4193 4414 4194 ret = qm_irq_register(qm); 4415 4195 if (ret) 4416 - goto err_pci_uninit; 4196 + goto err_pci_init; 4417 4197 4418 4198 if (qm->fun_type == QM_HW_VF && qm->ver != QM_HW_V1) { 4419 4199 /* v2 starts to support get vft by mailbox */ 4420 4200 ret = hisi_qm_get_vft(qm, &qm->qp_base, &qm->qp_num); 4421 4201 if (ret) 4422 - goto err_irq_unregister; 4202 + goto err_irq_register; 4423 4203 } 4204 + 4205 + ret = qm_alloc_uacce(qm); 4206 + if (ret < 0) 4207 + dev_warn(dev, "fail to alloc uacce (%d)\n", ret); 4424 4208 4425 4209 ret = hisi_qm_memory_init(qm); 4426 4210 if (ret) 4427 - goto err_irq_unregister; 4211 + goto err_alloc_uacce; 4428 4212 4429 4213 INIT_WORK(&qm->work, qm_work_process); 4430 4214 if (qm->fun_type == QM_HW_PF) ··· 4434 4218 4435 4219 return 0; 4436 4220 4437 - err_irq_unregister: 4438 - qm_irq_unregister(qm); 4439 - err_pci_uninit: 4440 - hisi_qm_pci_uninit(qm); 4441 - err_remove_uacce: 4221 + err_alloc_uacce: 4442 4222 uacce_remove(qm->uacce); 4443 4223 qm->uacce = NULL; 4224 + err_irq_register: 4225 + qm_irq_unregister(qm); 4226 + err_pci_init: 4227 + hisi_qm_pci_uninit(qm); 4444 4228 return ret; 4445 4229 } 4446 4230 EXPORT_SYMBOL_GPL(hisi_qm_init);
+16 -13
drivers/crypto/hisilicon/qm.h
··· 51 51 #define PEH_AXUSER_CFG 0x401001 52 52 #define PEH_AXUSER_CFG_ENABLE 0xffffffff 53 53 54 - #define QM_DFX_MB_CNT_VF 0x104010 55 - #define QM_DFX_DB_CNT_VF 0x104020 56 - #define QM_DFX_SQE_CNT_VF_SQN 0x104030 57 - #define QM_DFX_CQE_CNT_VF_CQN 0x104040 58 - #define QM_DFX_QN_SHIFT 16 59 - #define CURRENT_FUN_MASK GENMASK(5, 0) 60 - #define CURRENT_Q_MASK GENMASK(31, 16) 61 - 62 54 #define QM_AXI_RRESP BIT(0) 63 55 #define QM_AXI_BRESP BIT(1) 64 56 #define QM_ECC_MBIT BIT(2) ··· 64 72 #define QM_DB_TIMEOUT BIT(10) 65 73 #define QM_OF_FIFO_OF BIT(11) 66 74 #define QM_DB_RANDOM_INVALID BIT(12) 75 + #define QM_MAILBOX_TIMEOUT BIT(13) 76 + #define QM_FLR_TIMEOUT BIT(14) 67 77 68 78 #define QM_BASE_NFE (QM_AXI_RRESP | QM_AXI_BRESP | QM_ECC_MBIT | \ 69 79 QM_ACC_GET_TASK_TIMEOUT | QM_DB_TIMEOUT | \ 70 - QM_OF_FIFO_OF | QM_DB_RANDOM_INVALID) 80 + QM_OF_FIFO_OF | QM_DB_RANDOM_INVALID | \ 81 + QM_MAILBOX_TIMEOUT | QM_FLR_TIMEOUT) 71 82 #define QM_BASE_CE QM_ECC_1BIT 72 83 73 84 #define QM_Q_DEPTH 1024 ··· 118 123 }; 119 124 120 125 enum qm_debug_file { 126 + CURRENT_QM, 121 127 CURRENT_Q, 122 128 CLEAR_ENABLE, 123 129 DEBUG_FILE_NUM, ··· 189 193 void (*open_axi_master_ooo)(struct hisi_qm *qm); 190 194 void (*close_axi_master_ooo)(struct hisi_qm *qm); 191 195 void (*log_dev_hw_err)(struct hisi_qm *qm, u32 err_sts); 192 - struct hisi_qm_err_info err_info; 196 + void (*err_info_init)(struct hisi_qm *qm); 193 197 }; 194 198 195 199 struct hisi_qm_list { 196 200 struct mutex lock; 197 201 struct list_head list; 198 - int (*register_to_crypto)(void); 199 - void (*unregister_from_crypto)(void); 202 + int (*register_to_crypto)(struct hisi_qm *qm); 203 + void (*unregister_from_crypto)(struct hisi_qm *qm); 200 204 }; 201 205 202 206 struct hisi_qm { ··· 205 209 const char *dev_name; 206 210 struct pci_dev *pdev; 207 211 void __iomem *io_base; 212 + void __iomem *db_io_base; 208 213 u32 sqe_size; 209 214 u32 qp_base; 210 215 u32 qp_num; 211 216 u32 qp_in_used; 212 217 u32 ctrl_qp_num; 218 + u32 max_qp_num; 213 219 u32 vfs_num; 220 + u32 db_interval; 214 221 struct list_head list; 215 222 struct hisi_qm_list *qm_list; 216 223 ··· 229 230 230 231 struct hisi_qm_status status; 231 232 const struct hisi_qm_err_ini *err_ini; 233 + struct hisi_qm_err_info err_info; 232 234 struct hisi_qm_err_status err_status; 233 235 unsigned long misc_ctl; /* driver removing and reset sched */ 234 236 ··· 252 252 const char *algs; 253 253 bool use_sva; 254 254 bool is_frozen; 255 + 256 + /* doorbell isolation enable */ 257 + bool use_db_isolation; 255 258 resource_size_t phys_base; 256 - resource_size_t phys_size; 259 + resource_size_t db_phys_base; 257 260 struct uacce_device *uacce; 258 261 int mode; 259 262 };
+1 -1
drivers/crypto/hisilicon/sec/sec_algs.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - /* Copyright (c) 2016-2017 Hisilicon Limited. */ 2 + /* Copyright (c) 2016-2017 HiSilicon Limited. */ 3 3 #include <linux/crypto.h> 4 4 #include <linux/dma-mapping.h> 5 5 #include <linux/dmapool.h>
+7 -6
drivers/crypto/hisilicon/sec/sec_drv.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * Driver for the Hisilicon SEC units found on Hip06 Hip07 3 + * Driver for the HiSilicon SEC units found on Hip06 Hip07 4 4 * 5 - * Copyright (c) 2016-2017 Hisilicon Limited. 5 + * Copyright (c) 2016-2017 HiSilicon Limited. 6 6 */ 7 7 #include <linux/acpi.h> 8 8 #include <linux/atomic.h> ··· 233 233 IORESOURCE_MEM, 234 234 2 + queue->queue_id); 235 235 if (!res) { 236 - dev_err(dev, "Failed to get queue %d memory resource\n", 236 + dev_err(dev, "Failed to get queue %u memory resource\n", 237 237 queue->queue_id); 238 238 return -ENOMEM; 239 239 } ··· 653 653 struct sec_dev_info *info = queue->dev_info; 654 654 655 655 if (queue->queue_id >= SEC_Q_NUM) { 656 - dev_err(info->dev, "No queue %d\n", queue->queue_id); 656 + dev_err(info->dev, "No queue %u\n", queue->queue_id); 657 657 return -ENODEV; 658 658 } 659 659 660 660 if (!queue->in_use) { 661 - dev_err(info->dev, "Queue %d is idle\n", queue->queue_id); 661 + dev_err(info->dev, "Queue %u is idle\n", queue->queue_id); 662 662 return -ENODEV; 663 663 } 664 664 ··· 834 834 835 835 /** 836 836 * sec_queue_empty() - Is this hardware queue currently empty. 837 + * @queue: The queue to test 837 838 * 838 839 * We need to know if we have an empty queue for some of the chaining modes 839 840 * as if it is not empty we may need to hold the message in a software queue ··· 1316 1315 module_platform_driver(sec_driver); 1317 1316 1318 1317 MODULE_LICENSE("GPL"); 1319 - MODULE_DESCRIPTION("Hisilicon Security Accelerators"); 1318 + MODULE_DESCRIPTION("HiSilicon Security Accelerators"); 1320 1319 MODULE_AUTHOR("Zaibo Xu <xuzaibo@huawei.com"); 1321 1320 MODULE_AUTHOR("Jonathan Cameron <jonathan.cameron@huawei.com>");
+1 -1
drivers/crypto/hisilicon/sec/sec_drv.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* Copyright (c) 2016-2017 Hisilicon Limited. */ 2 + /* Copyright (c) 2016-2017 HiSilicon Limited. */ 3 3 4 4 #ifndef _SEC_DRV_H_ 5 5 #define _SEC_DRV_H_
+4 -6
drivers/crypto/hisilicon/sec2/sec.h
··· 4 4 #ifndef __HISI_SEC_V2_H 5 5 #define __HISI_SEC_V2_H 6 6 7 - #include <linux/list.h> 8 - 9 7 #include "../qm.h" 10 8 #include "sec_crypto.h" 11 9 ··· 48 50 49 51 int err_type; 50 52 int req_id; 51 - int flag; 53 + u32 flag; 52 54 53 55 /* Status of the SEC request */ 54 56 bool fake_busy; ··· 137 139 bool pbuf_supported; 138 140 struct sec_cipher_ctx c_ctx; 139 141 struct sec_auth_ctx a_ctx; 142 + struct device *dev; 140 143 }; 141 144 142 145 enum sec_endian { ··· 147 148 }; 148 149 149 150 enum sec_debug_file_index { 150 - SEC_CURRENT_QM, 151 151 SEC_CLEAR_ENABLE, 152 152 SEC_DEBUG_FILE_NUM, 153 153 }; ··· 181 183 182 184 void sec_destroy_qps(struct hisi_qp **qps, int qp_num); 183 185 struct hisi_qp **sec_create_qps(void); 184 - int sec_register_to_crypto(void); 185 - void sec_unregister_from_crypto(void); 186 + int sec_register_to_crypto(struct hisi_qm *qm); 187 + void sec_unregister_from_crypto(struct hisi_qm *qm); 186 188 #endif
+83 -54
drivers/crypto/hisilicon/sec2/sec_crypto.c
··· 7 7 #include <crypto/des.h> 8 8 #include <crypto/hash.h> 9 9 #include <crypto/internal/aead.h> 10 + #include <crypto/internal/des.h> 10 11 #include <crypto/sha1.h> 11 12 #include <crypto/sha2.h> 12 13 #include <crypto/skcipher.h> ··· 44 43 45 44 #define SEC_TOTAL_IV_SZ (SEC_IV_SIZE * QM_Q_DEPTH) 46 45 #define SEC_SGL_SGE_NR 128 47 - #define SEC_CTX_DEV(ctx) (&(ctx)->sec->qm.pdev->dev) 48 46 #define SEC_CIPHER_AUTH 0xfe 49 47 #define SEC_AUTH_CIPHER 0x1 50 48 #define SEC_MAX_MAC_LEN 64 ··· 96 96 0, QM_Q_DEPTH, GFP_ATOMIC); 97 97 mutex_unlock(&qp_ctx->req_lock); 98 98 if (unlikely(req_id < 0)) { 99 - dev_err(SEC_CTX_DEV(req->ctx), "alloc req id fail!\n"); 99 + dev_err(req->ctx->dev, "alloc req id fail!\n"); 100 100 return req_id; 101 101 } 102 102 ··· 112 112 int req_id = req->req_id; 113 113 114 114 if (unlikely(req_id < 0 || req_id >= QM_Q_DEPTH)) { 115 - dev_err(SEC_CTX_DEV(req->ctx), "free request id invalid!\n"); 115 + dev_err(req->ctx->dev, "free request id invalid!\n"); 116 116 return; 117 117 } 118 118 ··· 138 138 aead_req->cryptlen + aead_req->assoclen - 139 139 authsize); 140 140 if (unlikely(sz != authsize || memcmp(mac_out, mac, sz))) { 141 - dev_err(SEC_CTX_DEV(req->ctx), "aead verify failure!\n"); 141 + dev_err(req->ctx->dev, "aead verify failure!\n"); 142 142 return -EBADMSG; 143 143 } 144 144 ··· 177 177 if (unlikely(req->err_type || done != SEC_SQE_DONE || 178 178 (ctx->alg_type == SEC_SKCIPHER && flag != SEC_SQE_CFLAG) || 179 179 (ctx->alg_type == SEC_AEAD && flag != SEC_SQE_AEAD_FLAG))) { 180 - dev_err(SEC_CTX_DEV(ctx), 180 + dev_err_ratelimited(ctx->dev, 181 181 "err_type[%d],done[%d],flag[%d]\n", 182 182 req->err_type, done, flag); 183 183 err = -EIO; ··· 326 326 static int sec_alg_resource_alloc(struct sec_ctx *ctx, 327 327 struct sec_qp_ctx *qp_ctx) 328 328 { 329 - struct device *dev = SEC_CTX_DEV(ctx); 330 329 struct sec_alg_res *res = qp_ctx->res; 330 + struct device *dev = ctx->dev; 331 331 int ret; 332 332 333 333 ret = sec_alloc_civ_resource(dev, res); ··· 360 360 static void sec_alg_resource_free(struct sec_ctx *ctx, 361 361 struct sec_qp_ctx *qp_ctx) 362 362 { 363 - struct device *dev = SEC_CTX_DEV(ctx); 363 + struct device *dev = ctx->dev; 364 364 365 365 sec_free_civ_resource(dev, qp_ctx->res); 366 366 ··· 373 373 static int sec_create_qp_ctx(struct hisi_qm *qm, struct sec_ctx *ctx, 374 374 int qp_ctx_id, int alg_type) 375 375 { 376 - struct device *dev = SEC_CTX_DEV(ctx); 376 + struct device *dev = ctx->dev; 377 377 struct sec_qp_ctx *qp_ctx; 378 378 struct hisi_qp *qp; 379 379 int ret = -ENOMEM; ··· 428 428 static void sec_release_qp_ctx(struct sec_ctx *ctx, 429 429 struct sec_qp_ctx *qp_ctx) 430 430 { 431 - struct device *dev = SEC_CTX_DEV(ctx); 431 + struct device *dev = ctx->dev; 432 432 433 433 hisi_qm_stop_qp(qp_ctx->qp); 434 434 sec_alg_resource_free(ctx, qp_ctx); ··· 452 452 453 453 sec = container_of(ctx->qps[0]->qm, struct sec_dev, qm); 454 454 ctx->sec = sec; 455 + ctx->dev = &sec->qm.pdev->dev; 455 456 ctx->hlf_q_num = sec->ctx_q_num >> 1; 456 457 457 458 ctx->pbuf_supported = ctx->sec->iommu_used; ··· 477 476 err_sec_release_qp_ctx: 478 477 for (i = i - 1; i >= 0; i--) 479 478 sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]); 480 - 481 479 kfree(ctx->qp_ctx); 482 480 err_destroy_qps: 483 481 sec_destroy_qps(ctx->qps, sec->ctx_q_num); 484 - 485 482 return ret; 486 483 } 487 484 ··· 498 499 { 499 500 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 500 501 501 - c_ctx->c_key = dma_alloc_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, 502 + c_ctx->c_key = dma_alloc_coherent(ctx->dev, SEC_MAX_KEY_SIZE, 502 503 &c_ctx->c_key_dma, GFP_KERNEL); 503 504 if (!c_ctx->c_key) 504 505 return -ENOMEM; ··· 511 512 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 512 513 513 514 memzero_explicit(c_ctx->c_key, SEC_MAX_KEY_SIZE); 514 - dma_free_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, 515 + dma_free_coherent(ctx->dev, SEC_MAX_KEY_SIZE, 515 516 c_ctx->c_key, c_ctx->c_key_dma); 516 517 } 517 518 ··· 519 520 { 520 521 struct sec_auth_ctx *a_ctx = &ctx->a_ctx; 521 522 522 - a_ctx->a_key = dma_alloc_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, 523 + a_ctx->a_key = dma_alloc_coherent(ctx->dev, SEC_MAX_KEY_SIZE, 523 524 &a_ctx->a_key_dma, GFP_KERNEL); 524 525 if (!a_ctx->a_key) 525 526 return -ENOMEM; ··· 532 533 struct sec_auth_ctx *a_ctx = &ctx->a_ctx; 533 534 534 535 memzero_explicit(a_ctx->a_key, SEC_MAX_KEY_SIZE); 535 - dma_free_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, 536 + dma_free_coherent(ctx->dev, SEC_MAX_KEY_SIZE, 536 537 a_ctx->a_key, a_ctx->a_key_dma); 537 538 } 538 539 ··· 545 546 crypto_skcipher_set_reqsize(tfm, sizeof(struct sec_req)); 546 547 ctx->c_ctx.ivsize = crypto_skcipher_ivsize(tfm); 547 548 if (ctx->c_ctx.ivsize > SEC_IV_SIZE) { 548 - dev_err(SEC_CTX_DEV(ctx), "get error skcipher iv size!\n"); 549 + pr_err("get error skcipher iv size!\n"); 549 550 return -EINVAL; 550 551 } 551 552 ··· 572 573 sec_ctx_base_uninit(ctx); 573 574 } 574 575 575 - static int sec_skcipher_3des_setkey(struct sec_cipher_ctx *c_ctx, 576 + static int sec_skcipher_3des_setkey(struct crypto_skcipher *tfm, const u8 *key, 576 577 const u32 keylen, 577 578 const enum sec_cmode c_mode) 578 579 { 580 + struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); 581 + struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 582 + int ret; 583 + 584 + ret = verify_skcipher_des3_key(tfm, key); 585 + if (ret) 586 + return ret; 587 + 579 588 switch (keylen) { 580 589 case SEC_DES3_2KEY_SIZE: 581 590 c_ctx->c_key_len = SEC_CKEY_3DES_2KEY; ··· 640 633 { 641 634 struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); 642 635 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 636 + struct device *dev = ctx->dev; 643 637 int ret; 644 638 645 639 if (c_mode == SEC_CMODE_XTS) { 646 640 ret = xts_verify_key(tfm, key, keylen); 647 641 if (ret) { 648 - dev_err(SEC_CTX_DEV(ctx), "xts mode key err!\n"); 642 + dev_err(dev, "xts mode key err!\n"); 649 643 return ret; 650 644 } 651 645 } ··· 656 648 657 649 switch (c_alg) { 658 650 case SEC_CALG_3DES: 659 - ret = sec_skcipher_3des_setkey(c_ctx, keylen, c_mode); 651 + ret = sec_skcipher_3des_setkey(tfm, key, keylen, c_mode); 660 652 break; 661 653 case SEC_CALG_AES: 662 654 case SEC_CALG_SM4: ··· 667 659 } 668 660 669 661 if (ret) { 670 - dev_err(SEC_CTX_DEV(ctx), "set sec key err!\n"); 662 + dev_err(dev, "set sec key err!\n"); 671 663 return ret; 672 664 } 673 665 ··· 699 691 struct aead_request *aead_req = req->aead_req.aead_req; 700 692 struct sec_cipher_req *c_req = &req->c_req; 701 693 struct sec_qp_ctx *qp_ctx = req->qp_ctx; 702 - struct device *dev = SEC_CTX_DEV(ctx); 694 + struct device *dev = ctx->dev; 703 695 int copy_size, pbuf_length; 704 696 int req_id = req->req_id; 705 697 ··· 709 701 copy_size = c_req->c_len; 710 702 711 703 pbuf_length = sg_copy_to_buffer(src, sg_nents(src), 712 - qp_ctx->res[req_id].pbuf, 713 - copy_size); 714 - 704 + qp_ctx->res[req_id].pbuf, 705 + copy_size); 715 706 if (unlikely(pbuf_length != copy_size)) { 716 707 dev_err(dev, "copy src data to pbuf error!\n"); 717 708 return -EINVAL; 718 709 } 719 710 720 711 c_req->c_in_dma = qp_ctx->res[req_id].pbuf_dma; 721 - 722 - if (!c_req->c_in_dma) { 723 - dev_err(dev, "fail to set pbuffer address!\n"); 724 - return -ENOMEM; 725 - } 726 - 727 712 c_req->c_out_dma = c_req->c_in_dma; 728 713 729 714 return 0; ··· 728 727 struct aead_request *aead_req = req->aead_req.aead_req; 729 728 struct sec_cipher_req *c_req = &req->c_req; 730 729 struct sec_qp_ctx *qp_ctx = req->qp_ctx; 731 - struct device *dev = SEC_CTX_DEV(ctx); 730 + struct device *dev = ctx->dev; 732 731 int copy_size, pbuf_length; 733 732 int req_id = req->req_id; 734 733 ··· 740 739 pbuf_length = sg_copy_from_buffer(dst, sg_nents(dst), 741 740 qp_ctx->res[req_id].pbuf, 742 741 copy_size); 743 - 744 742 if (unlikely(pbuf_length != copy_size)) 745 743 dev_err(dev, "copy pbuf data to dst error!\n"); 746 744 } ··· 751 751 struct sec_aead_req *a_req = &req->aead_req; 752 752 struct sec_qp_ctx *qp_ctx = req->qp_ctx; 753 753 struct sec_alg_res *res = &qp_ctx->res[req->req_id]; 754 - struct device *dev = SEC_CTX_DEV(ctx); 754 + struct device *dev = ctx->dev; 755 755 int ret; 756 756 757 757 if (req->use_pbuf) { ··· 806 806 struct scatterlist *src, struct scatterlist *dst) 807 807 { 808 808 struct sec_cipher_req *c_req = &req->c_req; 809 - struct device *dev = SEC_CTX_DEV(ctx); 809 + struct device *dev = ctx->dev; 810 810 811 811 if (req->use_pbuf) { 812 812 sec_cipher_pbuf_unmap(ctx, req, dst); ··· 891 891 { 892 892 struct sec_ctx *ctx = crypto_aead_ctx(tfm); 893 893 struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; 894 + struct device *dev = ctx->dev; 894 895 struct crypto_authenc_keys keys; 895 896 int ret; 896 897 ··· 905 904 906 905 ret = sec_aead_aes_set_key(c_ctx, &keys); 907 906 if (ret) { 908 - dev_err(SEC_CTX_DEV(ctx), "set sec cipher key err!\n"); 907 + dev_err(dev, "set sec cipher key err!\n"); 909 908 goto bad_key; 910 909 } 911 910 912 911 ret = sec_aead_auth_set_key(&ctx->a_ctx, &keys); 913 912 if (ret) { 914 - dev_err(SEC_CTX_DEV(ctx), "set sec auth key err!\n"); 913 + dev_err(dev, "set sec auth key err!\n"); 915 914 goto bad_key; 916 915 } 917 916 ··· 1063 1062 sz = sg_pcopy_to_buffer(sgl, sg_nents(sgl), iv, iv_size, 1064 1063 cryptlen - iv_size); 1065 1064 if (unlikely(sz != iv_size)) 1066 - dev_err(SEC_CTX_DEV(req->ctx), "copy output iv error!\n"); 1065 + dev_err(req->ctx->dev, "copy output iv error!\n"); 1067 1066 } 1068 1067 1069 1068 static struct sec_req *sec_back_req_clear(struct sec_ctx *ctx, ··· 1161 1160 1162 1161 ret = sec_skcipher_bd_fill(ctx, req); 1163 1162 if (unlikely(ret)) { 1164 - dev_err(SEC_CTX_DEV(ctx), "skcipher bd fill is error!\n"); 1163 + dev_err(ctx->dev, "skcipher bd fill is error!\n"); 1165 1164 return ret; 1166 1165 } 1167 1166 ··· 1195 1194 a_req->assoclen); 1196 1195 1197 1196 if (unlikely(sz != authsize)) { 1198 - dev_err(SEC_CTX_DEV(req->ctx), "copy out mac err!\n"); 1197 + dev_err(c->dev, "copy out mac err!\n"); 1199 1198 err = -EINVAL; 1200 1199 } 1201 1200 } ··· 1260 1259 ret = ctx->req_op->bd_send(ctx, req); 1261 1260 if (unlikely((ret != -EBUSY && ret != -EINPROGRESS) || 1262 1261 (ret == -EBUSY && !(req->flag & CRYPTO_TFM_REQ_MAY_BACKLOG)))) { 1263 - dev_err_ratelimited(SEC_CTX_DEV(ctx), "send sec request failed!\n"); 1262 + dev_err_ratelimited(ctx->dev, "send sec request failed!\n"); 1264 1263 goto err_send_req; 1265 1264 } 1266 1265 ··· 1326 1325 ctx->alg_type = SEC_AEAD; 1327 1326 ctx->c_ctx.ivsize = crypto_aead_ivsize(tfm); 1328 1327 if (ctx->c_ctx.ivsize > SEC_IV_SIZE) { 1329 - dev_err(SEC_CTX_DEV(ctx), "get error aead iv size!\n"); 1328 + dev_err(ctx->dev, "get error aead iv size!\n"); 1330 1329 return -EINVAL; 1331 1330 } 1332 1331 ··· 1375 1374 1376 1375 auth_ctx->hash_tfm = crypto_alloc_shash(hash_name, 0, 0); 1377 1376 if (IS_ERR(auth_ctx->hash_tfm)) { 1378 - dev_err(SEC_CTX_DEV(ctx), "aead alloc shash error!\n"); 1377 + dev_err(ctx->dev, "aead alloc shash error!\n"); 1379 1378 sec_aead_exit(tfm); 1380 1379 return PTR_ERR(auth_ctx->hash_tfm); 1381 1380 } ··· 1406 1405 return sec_aead_ctx_init(tfm, "sha512"); 1407 1406 } 1408 1407 1408 + 1409 + static int sec_skcipher_cryptlen_ckeck(struct sec_ctx *ctx, 1410 + struct sec_req *sreq) 1411 + { 1412 + u32 cryptlen = sreq->c_req.sk_req->cryptlen; 1413 + struct device *dev = ctx->dev; 1414 + u8 c_mode = ctx->c_ctx.c_mode; 1415 + int ret = 0; 1416 + 1417 + switch (c_mode) { 1418 + case SEC_CMODE_XTS: 1419 + if (unlikely(cryptlen < AES_BLOCK_SIZE)) { 1420 + dev_err(dev, "skcipher XTS mode input length error!\n"); 1421 + ret = -EINVAL; 1422 + } 1423 + break; 1424 + case SEC_CMODE_ECB: 1425 + case SEC_CMODE_CBC: 1426 + if (unlikely(cryptlen & (AES_BLOCK_SIZE - 1))) { 1427 + dev_err(dev, "skcipher AES input length error!\n"); 1428 + ret = -EINVAL; 1429 + } 1430 + break; 1431 + default: 1432 + ret = -EINVAL; 1433 + } 1434 + 1435 + return ret; 1436 + } 1437 + 1409 1438 static int sec_skcipher_param_check(struct sec_ctx *ctx, struct sec_req *sreq) 1410 1439 { 1411 1440 struct skcipher_request *sk_req = sreq->c_req.sk_req; 1412 - struct device *dev = SEC_CTX_DEV(ctx); 1441 + struct device *dev = ctx->dev; 1413 1442 u8 c_alg = ctx->c_ctx.c_alg; 1414 1443 1415 1444 if (unlikely(!sk_req->src || !sk_req->dst)) { ··· 1460 1429 } 1461 1430 return 0; 1462 1431 } else if (c_alg == SEC_CALG_AES || c_alg == SEC_CALG_SM4) { 1463 - if (unlikely(sk_req->cryptlen & (AES_BLOCK_SIZE - 1))) { 1464 - dev_err(dev, "skcipher aes input length error!\n"); 1465 - return -EINVAL; 1466 - } 1467 - return 0; 1432 + return sec_skcipher_cryptlen_ckeck(ctx, sreq); 1468 1433 } 1434 + 1469 1435 dev_err(dev, "skcipher algorithm error!\n"); 1470 1436 1471 1437 return -EINVAL; ··· 1559 1531 1560 1532 static int sec_aead_param_check(struct sec_ctx *ctx, struct sec_req *sreq) 1561 1533 { 1562 - u8 c_alg = ctx->c_ctx.c_alg; 1563 1534 struct aead_request *req = sreq->aead_req.aead_req; 1564 1535 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 1565 1536 size_t authsize = crypto_aead_authsize(tfm); 1537 + struct device *dev = ctx->dev; 1538 + u8 c_alg = ctx->c_ctx.c_alg; 1566 1539 1567 1540 if (unlikely(!req->src || !req->dst || !req->cryptlen || 1568 1541 req->assoclen > SEC_MAX_AAD_LEN)) { 1569 - dev_err(SEC_CTX_DEV(ctx), "aead input param error!\n"); 1542 + dev_err(dev, "aead input param error!\n"); 1570 1543 return -EINVAL; 1571 1544 } 1572 1545 ··· 1579 1550 1580 1551 /* Support AES only */ 1581 1552 if (unlikely(c_alg != SEC_CALG_AES)) { 1582 - dev_err(SEC_CTX_DEV(ctx), "aead crypto alg error!\n"); 1553 + dev_err(dev, "aead crypto alg error!\n"); 1583 1554 return -EINVAL; 1584 1555 } 1585 1556 if (sreq->c_req.encrypt) ··· 1588 1559 sreq->c_req.c_len = req->cryptlen - authsize; 1589 1560 1590 1561 if (unlikely(sreq->c_req.c_len & (AES_BLOCK_SIZE - 1))) { 1591 - dev_err(SEC_CTX_DEV(ctx), "aead crypto length error!\n"); 1562 + dev_err(dev, "aead crypto length error!\n"); 1592 1563 return -EINVAL; 1593 1564 } 1594 1565 ··· 1663 1634 AES_BLOCK_SIZE, AES_BLOCK_SIZE, SHA512_DIGEST_SIZE), 1664 1635 }; 1665 1636 1666 - int sec_register_to_crypto(void) 1637 + int sec_register_to_crypto(struct hisi_qm *qm) 1667 1638 { 1668 1639 int ret; 1669 1640 ··· 1680 1651 return ret; 1681 1652 } 1682 1653 1683 - void sec_unregister_from_crypto(void) 1654 + void sec_unregister_from_crypto(struct hisi_qm *qm) 1684 1655 { 1685 1656 crypto_unregister_skciphers(sec_skciphers, 1686 1657 ARRAY_SIZE(sec_skciphers));
+2 -4
drivers/crypto/hisilicon/sec2/sec_crypto.h
··· 64 64 }; 65 65 66 66 struct sec_sqe_type2 { 67 - 68 67 /* 69 68 * mac_len: 0~4 bits 70 69 * a_key_len: 5~10 bits ··· 118 119 119 120 /* c_pad_len_field: 0~1 bits */ 120 121 __le16 c_pad_len_field; 121 - 122 122 123 123 __le64 long_a_data_len; 124 124 __le64 a_ivin_addr; ··· 209 211 struct sec_sqe_type2 type2; 210 212 }; 211 213 212 - int sec_register_to_crypto(void); 213 - void sec_unregister_from_crypto(void); 214 + int sec_register_to_crypto(struct hisi_qm *qm); 215 + void sec_unregister_from_crypto(struct hisi_qm *qm); 214 216 #endif
+129 -138
drivers/crypto/hisilicon/sec2/sec_main.c
··· 19 19 20 20 #define SEC_VF_NUM 63 21 21 #define SEC_QUEUE_NUM_V1 4096 22 - #define SEC_QUEUE_NUM_V2 1024 23 22 #define SEC_PF_PCI_DEVICE_ID 0xa255 24 23 #define SEC_VF_PCI_DEVICE_ID 0xa256 25 24 ··· 34 35 #define SEC_CTX_Q_NUM_MAX 32 35 36 36 37 #define SEC_CTRL_CNT_CLR_CE 0x301120 37 - #define SEC_CTRL_CNT_CLR_CE_BIT BIT(0) 38 - #define SEC_ENGINE_PF_CFG_OFF 0x300000 39 - #define SEC_ACC_COMMON_REG_OFF 0x1000 38 + #define SEC_CTRL_CNT_CLR_CE_BIT BIT(0) 40 39 #define SEC_CORE_INT_SOURCE 0x301010 41 40 #define SEC_CORE_INT_MASK 0x301000 42 41 #define SEC_CORE_INT_STATUS 0x301008 43 42 #define SEC_CORE_SRAM_ECC_ERR_INFO 0x301C14 44 - #define SEC_ECC_NUM(err) (((err) >> 16) & 0xFF) 45 - #define SEC_ECC_ADDR(err) ((err) >> 0) 43 + #define SEC_ECC_NUM 16 44 + #define SEC_ECC_MASH 0xFF 46 45 #define SEC_CORE_INT_DISABLE 0x0 47 - #define SEC_CORE_INT_ENABLE 0x1ff 48 - #define SEC_CORE_INT_CLEAR 0x1ff 46 + #define SEC_CORE_INT_ENABLE 0x7c1ff 47 + #define SEC_CORE_INT_CLEAR 0x7c1ff 49 48 #define SEC_SAA_ENABLE 0x17f 50 49 51 50 #define SEC_RAS_CE_REG 0x301050 ··· 51 54 #define SEC_RAS_NFE_REG 0x301058 52 55 #define SEC_RAS_CE_ENB_MSK 0x88 53 56 #define SEC_RAS_FE_ENB_MSK 0x0 54 - #define SEC_RAS_NFE_ENB_MSK 0x177 55 - #define SEC_RAS_DISABLE 0x0 56 - #define SEC_MEM_START_INIT_REG 0x0100 57 - #define SEC_MEM_INIT_DONE_REG 0x0104 57 + #define SEC_RAS_NFE_ENB_MSK 0x7c177 58 + #define SEC_RAS_DISABLE 0x0 59 + #define SEC_MEM_START_INIT_REG 0x301100 60 + #define SEC_MEM_INIT_DONE_REG 0x301104 58 61 59 - #define SEC_CONTROL_REG 0x0200 62 + #define SEC_CONTROL_REG 0x301200 60 63 #define SEC_TRNG_EN_SHIFT 8 61 64 #define SEC_CLK_GATE_ENABLE BIT(3) 62 65 #define SEC_CLK_GATE_DISABLE (~BIT(3)) 63 66 #define SEC_AXI_SHUTDOWN_ENABLE BIT(12) 64 67 #define SEC_AXI_SHUTDOWN_DISABLE 0xFFFFEFFF 65 68 66 - #define SEC_INTERFACE_USER_CTRL0_REG 0x0220 67 - #define SEC_INTERFACE_USER_CTRL1_REG 0x0224 68 - #define SEC_SAA_EN_REG 0x0270 69 - #define SEC_BD_ERR_CHK_EN_REG0 0x0380 70 - #define SEC_BD_ERR_CHK_EN_REG1 0x0384 71 - #define SEC_BD_ERR_CHK_EN_REG3 0x038c 69 + #define SEC_INTERFACE_USER_CTRL0_REG 0x301220 70 + #define SEC_INTERFACE_USER_CTRL1_REG 0x301224 71 + #define SEC_SAA_EN_REG 0x301270 72 + #define SEC_BD_ERR_CHK_EN_REG0 0x301380 73 + #define SEC_BD_ERR_CHK_EN_REG1 0x301384 74 + #define SEC_BD_ERR_CHK_EN_REG3 0x30138c 72 75 73 76 #define SEC_USER0_SMMU_NORMAL (BIT(23) | BIT(15)) 74 77 #define SEC_USER1_SMMU_NORMAL (BIT(31) | BIT(23) | BIT(15) | BIT(7)) ··· 92 95 #define SEC_SQE_MASK_OFFSET 64 93 96 #define SEC_SQE_MASK_LEN 48 94 97 95 - #define SEC_ADDR(qm, offset) ((qm)->io_base + (offset) + \ 96 - SEC_ENGINE_PF_CFG_OFF + SEC_ACC_COMMON_REG_OFF) 97 - 98 98 struct sec_hw_error { 99 99 u32 int_msk; 100 100 const char *msg; ··· 111 117 }; 112 118 113 119 static const struct sec_hw_error sec_hw_errors[] = { 114 - {.int_msk = BIT(0), .msg = "sec_axi_rresp_err_rint"}, 115 - {.int_msk = BIT(1), .msg = "sec_axi_bresp_err_rint"}, 116 - {.int_msk = BIT(2), .msg = "sec_ecc_2bit_err_rint"}, 117 - {.int_msk = BIT(3), .msg = "sec_ecc_1bit_err_rint"}, 118 - {.int_msk = BIT(4), .msg = "sec_req_trng_timeout_rint"}, 119 - {.int_msk = BIT(5), .msg = "sec_fsm_hbeat_rint"}, 120 - {.int_msk = BIT(6), .msg = "sec_channel_req_rng_timeout_rint"}, 121 - {.int_msk = BIT(7), .msg = "sec_bd_err_rint"}, 122 - {.int_msk = BIT(8), .msg = "sec_chain_buff_err_rint"}, 123 - { /* sentinel */ } 120 + { 121 + .int_msk = BIT(0), 122 + .msg = "sec_axi_rresp_err_rint" 123 + }, 124 + { 125 + .int_msk = BIT(1), 126 + .msg = "sec_axi_bresp_err_rint" 127 + }, 128 + { 129 + .int_msk = BIT(2), 130 + .msg = "sec_ecc_2bit_err_rint" 131 + }, 132 + { 133 + .int_msk = BIT(3), 134 + .msg = "sec_ecc_1bit_err_rint" 135 + }, 136 + { 137 + .int_msk = BIT(4), 138 + .msg = "sec_req_trng_timeout_rint" 139 + }, 140 + { 141 + .int_msk = BIT(5), 142 + .msg = "sec_fsm_hbeat_rint" 143 + }, 144 + { 145 + .int_msk = BIT(6), 146 + .msg = "sec_channel_req_rng_timeout_rint" 147 + }, 148 + { 149 + .int_msk = BIT(7), 150 + .msg = "sec_bd_err_rint" 151 + }, 152 + { 153 + .int_msk = BIT(8), 154 + .msg = "sec_chain_buff_err_rint" 155 + }, 156 + { 157 + .int_msk = BIT(14), 158 + .msg = "sec_no_secure_access" 159 + }, 160 + { 161 + .int_msk = BIT(15), 162 + .msg = "sec_wrapping_key_auth_err" 163 + }, 164 + { 165 + .int_msk = BIT(16), 166 + .msg = "sec_km_key_crc_fail" 167 + }, 168 + { 169 + .int_msk = BIT(17), 170 + .msg = "sec_axi_poison_err" 171 + }, 172 + { 173 + .int_msk = BIT(18), 174 + .msg = "sec_sva_err" 175 + }, 176 + {} 124 177 }; 125 178 126 179 static const char * const sec_dbg_file_name[] = { 127 - [SEC_CURRENT_QM] = "current_qm", 128 180 [SEC_CLEAR_ENABLE] = "clear_enable", 129 181 }; 130 182 ··· 317 277 "cannot access a register in VF!\n"); 318 278 return SEC_LE; 319 279 } 320 - reg = readl_relaxed(qm->io_base + SEC_ENGINE_PF_CFG_OFF + 321 - SEC_ACC_COMMON_REG_OFF + SEC_CONTROL_REG); 322 - 280 + reg = readl_relaxed(qm->io_base + SEC_CONTROL_REG); 323 281 /* BD little endian mode */ 324 282 if (!(reg & BIT(0))) 325 283 return SEC_LE; ··· 337 299 u32 reg; 338 300 339 301 /* disable clock gate control */ 340 - reg = readl_relaxed(SEC_ADDR(qm, SEC_CONTROL_REG)); 302 + reg = readl_relaxed(qm->io_base + SEC_CONTROL_REG); 341 303 reg &= SEC_CLK_GATE_DISABLE; 342 - writel_relaxed(reg, SEC_ADDR(qm, SEC_CONTROL_REG)); 304 + writel_relaxed(reg, qm->io_base + SEC_CONTROL_REG); 343 305 344 - writel_relaxed(0x1, SEC_ADDR(qm, SEC_MEM_START_INIT_REG)); 306 + writel_relaxed(0x1, qm->io_base + SEC_MEM_START_INIT_REG); 345 307 346 - ret = readl_relaxed_poll_timeout(SEC_ADDR(qm, SEC_MEM_INIT_DONE_REG), 308 + ret = readl_relaxed_poll_timeout(qm->io_base + SEC_MEM_INIT_DONE_REG, 347 309 reg, reg & 0x1, SEC_DELAY_10_US, 348 310 SEC_POLL_TIMEOUT_US); 349 311 if (ret) { ··· 351 313 return ret; 352 314 } 353 315 354 - reg = readl_relaxed(SEC_ADDR(qm, SEC_CONTROL_REG)); 316 + reg = readl_relaxed(qm->io_base + SEC_CONTROL_REG); 355 317 reg |= (0x1 << SEC_TRNG_EN_SHIFT); 356 - writel_relaxed(reg, SEC_ADDR(qm, SEC_CONTROL_REG)); 318 + writel_relaxed(reg, qm->io_base + SEC_CONTROL_REG); 357 319 358 - reg = readl_relaxed(SEC_ADDR(qm, SEC_INTERFACE_USER_CTRL0_REG)); 320 + reg = readl_relaxed(qm->io_base + SEC_INTERFACE_USER_CTRL0_REG); 359 321 reg |= SEC_USER0_SMMU_NORMAL; 360 - writel_relaxed(reg, SEC_ADDR(qm, SEC_INTERFACE_USER_CTRL0_REG)); 322 + writel_relaxed(reg, qm->io_base + SEC_INTERFACE_USER_CTRL0_REG); 361 323 362 - reg = readl_relaxed(SEC_ADDR(qm, SEC_INTERFACE_USER_CTRL1_REG)); 324 + reg = readl_relaxed(qm->io_base + SEC_INTERFACE_USER_CTRL1_REG); 363 325 reg &= SEC_USER1_SMMU_MASK; 364 326 if (qm->use_sva && qm->ver == QM_HW_V2) 365 327 reg |= SEC_USER1_SMMU_SVA; 366 328 else 367 329 reg |= SEC_USER1_SMMU_NORMAL; 368 - writel_relaxed(reg, SEC_ADDR(qm, SEC_INTERFACE_USER_CTRL1_REG)); 330 + writel_relaxed(reg, qm->io_base + SEC_INTERFACE_USER_CTRL1_REG); 369 331 370 332 writel(SEC_SINGLE_PORT_MAX_TRANS, 371 333 qm->io_base + AM_CFG_SINGLE_PORT_MAX_TRANS); 372 334 373 - writel(SEC_SAA_ENABLE, SEC_ADDR(qm, SEC_SAA_EN_REG)); 335 + writel(SEC_SAA_ENABLE, qm->io_base + SEC_SAA_EN_REG); 374 336 375 337 /* Enable sm4 extra mode, as ctr/ecb */ 376 338 writel_relaxed(SEC_BD_ERR_CHK_EN0, 377 - SEC_ADDR(qm, SEC_BD_ERR_CHK_EN_REG0)); 339 + qm->io_base + SEC_BD_ERR_CHK_EN_REG0); 378 340 /* Enable sm4 xts mode multiple iv */ 379 341 writel_relaxed(SEC_BD_ERR_CHK_EN1, 380 - SEC_ADDR(qm, SEC_BD_ERR_CHK_EN_REG1)); 342 + qm->io_base + SEC_BD_ERR_CHK_EN_REG1); 381 343 writel_relaxed(SEC_BD_ERR_CHK_EN3, 382 - SEC_ADDR(qm, SEC_BD_ERR_CHK_EN_REG3)); 344 + qm->io_base + SEC_BD_ERR_CHK_EN_REG3); 383 345 384 346 /* config endian */ 385 - reg = readl_relaxed(SEC_ADDR(qm, SEC_CONTROL_REG)); 347 + reg = readl_relaxed(qm->io_base + SEC_CONTROL_REG); 386 348 reg |= sec_get_endian(qm); 387 - writel_relaxed(reg, SEC_ADDR(qm, SEC_CONTROL_REG)); 349 + writel_relaxed(reg, qm->io_base + SEC_CONTROL_REG); 388 350 389 351 return 0; 390 352 } ··· 419 381 { 420 382 int i; 421 383 422 - /* clear current_qm */ 423 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 424 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 425 - 426 384 /* clear sec dfx regs */ 427 385 writel(0x1, qm->io_base + SEC_CTRL_CNT_CLR_CE); 428 386 for (i = 0; i < ARRAY_SIZE(sec_dfx_regs); i++) ··· 440 406 return; 441 407 } 442 408 443 - val = readl(SEC_ADDR(qm, SEC_CONTROL_REG)); 409 + val = readl(qm->io_base + SEC_CONTROL_REG); 444 410 445 411 /* clear SEC hw error source if having */ 446 412 writel(SEC_CORE_INT_CLEAR, qm->io_base + SEC_CORE_INT_SOURCE); ··· 456 422 /* enable SEC block master OOO when m-bit error occur */ 457 423 val = val | SEC_AXI_SHUTDOWN_ENABLE; 458 424 459 - writel(val, SEC_ADDR(qm, SEC_CONTROL_REG)); 425 + writel(val, qm->io_base + SEC_CONTROL_REG); 460 426 } 461 427 462 428 static void sec_hw_error_disable(struct hisi_qm *qm) 463 429 { 464 430 u32 val; 465 431 466 - val = readl(SEC_ADDR(qm, SEC_CONTROL_REG)); 432 + val = readl(qm->io_base + SEC_CONTROL_REG); 467 433 468 434 /* disable RAS int */ 469 435 writel(SEC_RAS_DISABLE, qm->io_base + SEC_RAS_CE_REG); ··· 476 442 /* disable SEC block master OOO when m-bit error occur */ 477 443 val = val & SEC_AXI_SHUTDOWN_DISABLE; 478 444 479 - writel(val, SEC_ADDR(qm, SEC_CONTROL_REG)); 480 - } 481 - 482 - static u32 sec_current_qm_read(struct sec_debug_file *file) 483 - { 484 - struct hisi_qm *qm = file->qm; 485 - 486 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 487 - } 488 - 489 - static int sec_current_qm_write(struct sec_debug_file *file, u32 val) 490 - { 491 - struct hisi_qm *qm = file->qm; 492 - u32 vfq_num; 493 - u32 tmp; 494 - 495 - if (val > qm->vfs_num) 496 - return -EINVAL; 497 - 498 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 499 - if (!val) { 500 - qm->debug.curr_qm_qp_num = qm->qp_num; 501 - } else { 502 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num; 503 - 504 - if (val == qm->vfs_num) 505 - qm->debug.curr_qm_qp_num = 506 - qm->ctrl_qp_num - qm->qp_num - 507 - (qm->vfs_num - 1) * vfq_num; 508 - else 509 - qm->debug.curr_qm_qp_num = vfq_num; 510 - } 511 - 512 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 513 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 514 - 515 - tmp = val | 516 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 517 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 518 - 519 - tmp = val | 520 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 521 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 522 - 523 - return 0; 445 + writel(val, qm->io_base + SEC_CONTROL_REG); 524 446 } 525 447 526 448 static u32 sec_clear_enable_read(struct sec_debug_file *file) ··· 513 523 spin_lock_irq(&file->lock); 514 524 515 525 switch (file->index) { 516 - case SEC_CURRENT_QM: 517 - val = sec_current_qm_read(file); 518 - break; 519 526 case SEC_CLEAR_ENABLE: 520 527 val = sec_clear_enable_read(file); 521 528 break; ··· 553 566 spin_lock_irq(&file->lock); 554 567 555 568 switch (file->index) { 556 - case SEC_CURRENT_QM: 557 - ret = sec_current_qm_write(file, val); 558 - if (ret) 559 - goto err_input; 560 - break; 561 569 case SEC_CLEAR_ENABLE: 562 570 ret = sec_clear_enable_write(file, val); 563 571 if (ret) ··· 637 655 int i; 638 656 639 657 if (qm->pdev->device == SEC_PF_PCI_DEVICE_ID) { 640 - for (i = SEC_CURRENT_QM; i < SEC_DEBUG_FILE_NUM; i++) { 658 + for (i = SEC_CLEAR_ENABLE; i < SEC_DEBUG_FILE_NUM; i++) { 641 659 spin_lock_init(&sec->debug.files[i].lock); 642 660 sec->debug.files[i].index = i; 643 661 sec->debug.files[i].qm = qm; ··· 694 712 err_val = readl(qm->io_base + 695 713 SEC_CORE_SRAM_ECC_ERR_INFO); 696 714 dev_err(dev, "multi ecc sram num=0x%x\n", 697 - SEC_ECC_NUM(err_val)); 715 + ((err_val) >> SEC_ECC_NUM) & 716 + SEC_ECC_MASH); 698 717 } 699 718 } 700 719 errs++; ··· 716 733 { 717 734 u32 val; 718 735 719 - val = readl(SEC_ADDR(qm, SEC_CONTROL_REG)); 720 - writel(val & SEC_AXI_SHUTDOWN_DISABLE, SEC_ADDR(qm, SEC_CONTROL_REG)); 721 - writel(val | SEC_AXI_SHUTDOWN_ENABLE, SEC_ADDR(qm, SEC_CONTROL_REG)); 736 + val = readl(qm->io_base + SEC_CONTROL_REG); 737 + writel(val & SEC_AXI_SHUTDOWN_DISABLE, qm->io_base + SEC_CONTROL_REG); 738 + writel(val | SEC_AXI_SHUTDOWN_ENABLE, qm->io_base + SEC_CONTROL_REG); 739 + } 740 + 741 + static void sec_err_info_init(struct hisi_qm *qm) 742 + { 743 + struct hisi_qm_err_info *err_info = &qm->err_info; 744 + 745 + err_info->ce = QM_BASE_CE; 746 + err_info->fe = 0; 747 + err_info->ecc_2bits_mask = SEC_CORE_INT_STATUS_M_ECC; 748 + err_info->dev_ce_mask = SEC_RAS_CE_ENB_MSK; 749 + err_info->msi_wr_port = BIT(0); 750 + err_info->acpi_rst = "SRST"; 751 + err_info->nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT | 752 + QM_ACC_WB_NOT_READY_TIMEOUT; 722 753 } 723 754 724 755 static const struct hisi_qm_err_ini sec_err_ini = { ··· 743 746 .clear_dev_hw_err_status = sec_clear_hw_err_status, 744 747 .log_dev_hw_err = sec_log_hw_error, 745 748 .open_axi_master_ooo = sec_open_axi_master_ooo, 746 - .err_info = { 747 - .ce = QM_BASE_CE, 748 - .nfe = QM_BASE_NFE | QM_ACC_DO_TASK_TIMEOUT | 749 - QM_ACC_WB_NOT_READY_TIMEOUT, 750 - .fe = 0, 751 - .ecc_2bits_mask = SEC_CORE_INT_STATUS_M_ECC, 752 - .dev_ce_mask = SEC_RAS_CE_ENB_MSK, 753 - .msi_wr_port = BIT(0), 754 - .acpi_rst = "SRST", 755 - } 749 + .err_info_init = sec_err_info_init, 756 750 }; 757 751 758 752 static int sec_pf_probe_init(struct sec_dev *sec) ··· 751 763 struct hisi_qm *qm = &sec->qm; 752 764 int ret; 753 765 754 - if (qm->ver == QM_HW_V1) 755 - qm->ctrl_qp_num = SEC_QUEUE_NUM_V1; 756 - else 757 - qm->ctrl_qp_num = SEC_QUEUE_NUM_V2; 758 - 759 766 qm->err_ini = &sec_err_ini; 767 + qm->err_ini->err_info_init(qm); 760 768 761 769 ret = sec_set_user_domain_and_cache(qm); 762 770 if (ret) ··· 770 786 771 787 qm->pdev = pdev; 772 788 qm->ver = pdev->revision; 773 - qm->algs = "cipher\ndigest\naead\n"; 789 + qm->algs = "cipher\ndigest\naead"; 774 790 qm->mode = uacce_mode; 775 791 qm->sqe_size = SEC_SQE_SIZE; 776 792 qm->dev_name = sec_name; ··· 893 909 if (ret) 894 910 pci_warn(pdev, "Failed to init debugfs!\n"); 895 911 896 - ret = hisi_qm_alg_register(qm, &sec_devices); 897 - if (ret < 0) { 898 - pr_err("Failed to register driver to crypto.\n"); 899 - goto err_qm_stop; 912 + if (qm->qp_num >= ctx_q_num) { 913 + ret = hisi_qm_alg_register(qm, &sec_devices); 914 + if (ret < 0) { 915 + pr_err("Failed to register driver to crypto.\n"); 916 + goto err_qm_stop; 917 + } 918 + } else { 919 + pci_warn(qm->pdev, 920 + "Failed to use kernel mode, qp not enough!\n"); 900 921 } 901 922 902 923 if (qm->uacce) { ··· 937 948 struct hisi_qm *qm = pci_get_drvdata(pdev); 938 949 939 950 hisi_qm_wait_task_finish(qm, &sec_devices); 940 - hisi_qm_alg_unregister(qm, &sec_devices); 951 + if (qm->qp_num >= ctx_q_num) 952 + hisi_qm_alg_unregister(qm, &sec_devices); 953 + 941 954 if (qm->fun_type == QM_HW_PF && qm->vfs_num) 942 955 hisi_qm_sriov_disable(pdev, true); 943 956
+31 -6
drivers/crypto/hisilicon/sgl.c
··· 56 56 struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, 57 57 u32 count, u32 sge_nr) 58 58 { 59 - u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl = 0; 59 + u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl; 60 60 struct hisi_acc_sgl_pool *pool; 61 61 struct mem_block *block; 62 62 u32 i, j; ··· 66 66 67 67 sgl_size = sizeof(struct acc_hw_sge) * sge_nr + 68 68 sizeof(struct hisi_acc_hw_sgl); 69 + 70 + /* 71 + * the pool may allocate a block of memory of size PAGE_SIZE * 2^(MAX_ORDER - 1), 72 + * block size may exceed 2^31 on ia64, so the max of block size is 2^31 73 + */ 69 74 block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ? 70 75 PAGE_SHIFT + MAX_ORDER - 1 : 31); 71 76 sgl_num_per_block = block_size / sgl_size; ··· 90 85 block[i].sgl = dma_alloc_coherent(dev, block_size, 91 86 &block[i].sgl_dma, 92 87 GFP_KERNEL); 93 - if (!block[i].sgl) 88 + if (!block[i].sgl) { 89 + dev_err(dev, "Fail to allocate hw SG buffer!\n"); 94 90 goto err_free_mem; 91 + } 95 92 96 93 block[i].size = block_size; 97 94 } ··· 102 95 block[i].sgl = dma_alloc_coherent(dev, remain_sgl * sgl_size, 103 96 &block[i].sgl_dma, 104 97 GFP_KERNEL); 105 - if (!block[i].sgl) 98 + if (!block[i].sgl) { 99 + dev_err(dev, "Fail to allocate remained hw SG buffer!\n"); 106 100 goto err_free_mem; 101 + } 107 102 108 103 block[i].size = remain_sgl * sgl_size; 109 104 } ··· 176 167 { 177 168 hw_sge->buf = sg_dma_address(sgl); 178 169 hw_sge->len = cpu_to_le32(sg_dma_len(sgl)); 170 + hw_sge->page_ctrl = sg_virt(sgl); 179 171 } 180 172 181 173 static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl) ··· 190 180 static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum) 191 181 { 192 182 hw_sgl->entry_sum_in_chain = cpu_to_le16(sum); 183 + } 184 + 185 + static void clear_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl) 186 + { 187 + struct acc_hw_sge *hw_sge = hw_sgl->sge_entries; 188 + int i; 189 + 190 + for (i = 0; i < le16_to_cpu(hw_sgl->entry_sum_in_sgl); i++) { 191 + hw_sge[i].page_ctrl = NULL; 192 + hw_sge[i].buf = 0; 193 + hw_sge[i].len = 0; 194 + } 193 195 } 194 196 195 197 /** ··· 233 211 sg_n = sg_nents(sgl); 234 212 235 213 sg_n_mapped = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); 236 - if (!sg_n_mapped) 214 + if (!sg_n_mapped) { 215 + dev_err(dev, "DMA mapping for SG error!\n"); 237 216 return ERR_PTR(-EINVAL); 217 + } 238 218 239 219 if (sg_n_mapped > pool->sge_nr) { 240 - dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); 220 + dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n"); 241 221 return ERR_PTR(-EINVAL); 242 222 } 243 223 244 224 curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma); 245 225 if (IS_ERR(curr_hw_sgl)) { 226 + dev_err(dev, "Get SGL error!\n"); 246 227 dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); 247 228 return ERR_PTR(-ENOMEM); 248 229 ··· 281 256 return; 282 257 283 258 dma_unmap_sg(dev, sgl, sg_nents(sgl), DMA_BIDIRECTIONAL); 284 - 259 + clear_hw_sgl_sge(hw_sgl); 285 260 hw_sgl->entry_sum_in_chain = 0; 286 261 hw_sgl->entry_sum_in_sgl = 0; 287 262 hw_sgl->entry_length_in_sgl = 0;
+10 -3
drivers/crypto/hisilicon/trng/trng.c
··· 18 18 #define HISI_TRNG_REG 0x00F0 19 19 #define HISI_TRNG_BYTES 4 20 20 #define HISI_TRNG_QUALITY 512 21 + #define HISI_TRNG_VERSION 0x01B8 22 + #define HISI_TRNG_VER_V1 GENMASK(31, 0) 21 23 #define SLEEP_US 10 22 24 #define TIMEOUT_US 10000 23 25 #define SW_DRBG_NUM_SHIFT 2 ··· 52 50 struct hisi_trng_list *trng_list; 53 51 struct list_head list; 54 52 struct hwrng rng; 53 + u32 ver; 55 54 bool is_used; 56 55 struct mutex mutex; 57 56 }; ··· 263 260 return PTR_ERR(trng->base); 264 261 265 262 trng->is_used = false; 263 + trng->ver = readl(trng->base + HISI_TRNG_VERSION); 266 264 if (!trng_devices.is_init) { 267 265 INIT_LIST_HEAD(&trng_devices.list); 268 266 mutex_init(&trng_devices.lock); ··· 271 267 } 272 268 273 269 hisi_trng_add_to_list(trng); 274 - if (atomic_inc_return(&trng_active_devs) == 1) { 270 + if (trng->ver != HISI_TRNG_VER_V1 && 271 + atomic_inc_return(&trng_active_devs) == 1) { 275 272 ret = crypto_register_rng(&hisi_trng_alg); 276 273 if (ret) { 277 274 dev_err(&pdev->dev, ··· 294 289 return ret; 295 290 296 291 err_crypto_unregister: 297 - if (atomic_dec_return(&trng_active_devs) == 0) 292 + if (trng->ver != HISI_TRNG_VER_V1 && 293 + atomic_dec_return(&trng_active_devs) == 0) 298 294 crypto_unregister_rng(&hisi_trng_alg); 299 295 300 296 err_remove_from_list: ··· 311 305 while (hisi_trng_del_from_list(trng)) 312 306 ; 313 307 314 - if (atomic_dec_return(&trng_active_devs) == 0) 308 + if (trng->ver != HISI_TRNG_VER_V1 && 309 + atomic_dec_return(&trng_active_devs) == 0) 315 310 crypto_unregister_rng(&hisi_trng_alg); 316 311 317 312 return 0;
+35 -15
drivers/crypto/hisilicon/zip/zip.h
··· 33 33 u32 consumed; 34 34 u32 produced; 35 35 u32 comp_data_length; 36 + /* 37 + * status: 0~7 bits 38 + * rsvd: 8~31 bits 39 + */ 36 40 u32 dw3; 37 41 u32 input_data_length; 38 - u32 lba_l; 39 - u32 lba_h; 42 + u32 dw5; 43 + u32 dw6; 44 + /* 45 + * in_sge_data_offset: 0~23 bits 46 + * rsvd: 24~27 bits 47 + * sqe_type: 29~31 bits 48 + */ 40 49 u32 dw7; 50 + /* 51 + * out_sge_data_offset: 0~23 bits 52 + * rsvd: 24~31 bits 53 + */ 41 54 u32 dw8; 55 + /* 56 + * request_type: 0~7 bits 57 + * buffer_type: 8~11 bits 58 + * rsvd: 13~31 bits 59 + */ 42 60 u32 dw9; 43 61 u32 dw10; 44 - u32 priv_info; 62 + u32 dw11; 45 63 u32 dw12; 46 - u32 tag; 64 + /* tag: in sqe type 0 */ 65 + u32 dw13; 47 66 u32 dest_avail_out; 48 - u32 rsvd0; 49 - u32 comp_head_addr_l; 50 - u32 comp_head_addr_h; 67 + u32 dw15; 68 + u32 dw16; 69 + u32 dw17; 51 70 u32 source_addr_l; 52 71 u32 source_addr_h; 53 72 u32 dest_addr_l; 54 73 u32 dest_addr_h; 55 - u32 stream_ctx_addr_l; 56 - u32 stream_ctx_addr_h; 57 - u32 cipher_key1_addr_l; 58 - u32 cipher_key1_addr_h; 59 - u32 cipher_key2_addr_l; 60 - u32 cipher_key2_addr_h; 74 + u32 dw22; 75 + u32 dw23; 76 + u32 dw24; 77 + u32 dw25; 78 + /* tag: in sqe type 3 */ 79 + u32 dw26; 80 + u32 dw27; 61 81 u32 rsvd1[4]; 62 82 }; 63 83 64 84 int zip_create_qps(struct hisi_qp **qps, int ctx_num, int node); 65 - int hisi_zip_register_to_crypto(void); 66 - void hisi_zip_unregister_from_crypto(void); 85 + int hisi_zip_register_to_crypto(struct hisi_qm *qm); 86 + void hisi_zip_unregister_from_crypto(struct hisi_qm *qm); 67 87 #endif
+448 -344
drivers/crypto/hisilicon/zip/zip_crypto.c
··· 10 10 #define HZIP_BD_STATUS_M GENMASK(7, 0) 11 11 /* hisi_zip_sqe dw7 */ 12 12 #define HZIP_IN_SGE_DATA_OFFSET_M GENMASK(23, 0) 13 + #define HZIP_SQE_TYPE_M GENMASK(31, 28) 13 14 /* hisi_zip_sqe dw8 */ 14 15 #define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0) 15 16 /* hisi_zip_sqe dw9 */ ··· 92 91 struct hisi_zip_ctx *ctx; 93 92 }; 94 93 94 + struct hisi_zip_sqe_ops { 95 + u8 sqe_type; 96 + void (*fill_addr)(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req); 97 + void (*fill_buf_size)(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req); 98 + void (*fill_buf_type)(struct hisi_zip_sqe *sqe, u8 buf_type); 99 + void (*fill_req_type)(struct hisi_zip_sqe *sqe, u8 req_type); 100 + void (*fill_tag)(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req); 101 + void (*fill_sqe_type)(struct hisi_zip_sqe *sqe, u8 sqe_type); 102 + u32 (*get_tag)(struct hisi_zip_sqe *sqe); 103 + u32 (*get_status)(struct hisi_zip_sqe *sqe); 104 + u32 (*get_dstlen)(struct hisi_zip_sqe *sqe); 105 + }; 106 + 95 107 struct hisi_zip_ctx { 96 108 struct hisi_zip_qp_ctx qp_ctx[HZIP_CTX_Q_NUM]; 109 + const struct hisi_zip_sqe_ops *ops; 97 110 }; 98 111 99 112 static int sgl_sge_nr_set(const char *val, const struct kernel_param *kp) ··· 133 118 static u16 sgl_sge_nr = HZIP_SGL_SGE_NR; 134 119 module_param_cb(sgl_sge_nr, &sgl_sge_nr_ops, &sgl_sge_nr, 0444); 135 120 MODULE_PARM_DESC(sgl_sge_nr, "Number of sge in sgl(1-255)"); 136 - 137 - static void hisi_zip_config_buf_type(struct hisi_zip_sqe *sqe, u8 buf_type) 138 - { 139 - u32 val; 140 - 141 - val = (sqe->dw9) & ~HZIP_BUF_TYPE_M; 142 - val |= FIELD_PREP(HZIP_BUF_TYPE_M, buf_type); 143 - sqe->dw9 = val; 144 - } 145 - 146 - static void hisi_zip_config_tag(struct hisi_zip_sqe *sqe, u32 tag) 147 - { 148 - sqe->tag = tag; 149 - } 150 - 151 - static void hisi_zip_fill_sqe(struct hisi_zip_sqe *sqe, u8 req_type, 152 - dma_addr_t s_addr, dma_addr_t d_addr, u32 slen, 153 - u32 dlen, u32 sskip, u32 dskip) 154 - { 155 - memset(sqe, 0, sizeof(struct hisi_zip_sqe)); 156 - 157 - sqe->input_data_length = slen - sskip; 158 - sqe->dw7 = FIELD_PREP(HZIP_IN_SGE_DATA_OFFSET_M, sskip); 159 - sqe->dw8 = FIELD_PREP(HZIP_OUT_SGE_DATA_OFFSET_M, dskip); 160 - sqe->dw9 = FIELD_PREP(HZIP_REQ_TYPE_M, req_type); 161 - sqe->dest_avail_out = dlen - dskip; 162 - sqe->source_addr_l = lower_32_bits(s_addr); 163 - sqe->source_addr_h = upper_32_bits(s_addr); 164 - sqe->dest_addr_l = lower_32_bits(d_addr); 165 - sqe->dest_addr_h = upper_32_bits(d_addr); 166 - } 167 - 168 - static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *ctx, 169 - int alg_type, int req_type) 170 - { 171 - struct device *dev = &qp->qm->pdev->dev; 172 - int ret; 173 - 174 - qp->req_type = req_type; 175 - qp->alg_type = alg_type; 176 - qp->qp_ctx = ctx; 177 - 178 - ret = hisi_qm_start_qp(qp, 0); 179 - if (ret < 0) { 180 - dev_err(dev, "failed to start qp (%d)!\n", ret); 181 - return ret; 182 - } 183 - 184 - ctx->qp = qp; 185 - 186 - return 0; 187 - } 188 - 189 - static void hisi_zip_release_qp(struct hisi_zip_qp_ctx *ctx) 190 - { 191 - hisi_qm_stop_qp(ctx->qp); 192 - hisi_qm_release_qp(ctx->qp); 193 - } 194 - 195 - static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int node) 196 - { 197 - struct hisi_qp *qps[HZIP_CTX_Q_NUM] = { NULL }; 198 - struct hisi_zip *hisi_zip; 199 - int ret, i, j; 200 - 201 - ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node); 202 - if (ret) { 203 - pr_err("failed to create zip qps (%d)!\n", ret); 204 - return -ENODEV; 205 - } 206 - 207 - hisi_zip = container_of(qps[0]->qm, struct hisi_zip, qm); 208 - 209 - for (i = 0; i < HZIP_CTX_Q_NUM; i++) { 210 - /* alg_type = 0 for compress, 1 for decompress in hw sqe */ 211 - ret = hisi_zip_start_qp(qps[i], &hisi_zip_ctx->qp_ctx[i], i, 212 - req_type); 213 - if (ret) { 214 - for (j = i - 1; j >= 0; j--) 215 - hisi_qm_stop_qp(hisi_zip_ctx->qp_ctx[j].qp); 216 - 217 - hisi_qm_free_qps(qps, HZIP_CTX_Q_NUM); 218 - return ret; 219 - } 220 - 221 - hisi_zip_ctx->qp_ctx[i].zip_dev = hisi_zip; 222 - } 223 - 224 - return 0; 225 - } 226 - 227 - static void hisi_zip_ctx_exit(struct hisi_zip_ctx *hisi_zip_ctx) 228 - { 229 - int i; 230 - 231 - for (i = 1; i >= 0; i--) 232 - hisi_zip_release_qp(&hisi_zip_ctx->qp_ctx[i]); 233 - } 234 121 235 122 static u16 get_extra_field_size(const u8 *start) 236 123 { ··· 164 247 size += GZIP_HEAD_FHCRC_SIZE; 165 248 166 249 return size; 250 + } 251 + 252 + static size_t __maybe_unused get_gzip_head_size(struct scatterlist *sgl) 253 + { 254 + char buf[HZIP_GZIP_HEAD_BUF]; 255 + 256 + sg_copy_to_buffer(sgl, sg_nents(sgl), buf, sizeof(buf)); 257 + 258 + return __get_gzip_head_size(buf); 259 + } 260 + 261 + static int add_comp_head(struct scatterlist *dst, u8 req_type) 262 + { 263 + int head_size = TO_HEAD_SIZE(req_type); 264 + const u8 *head = TO_HEAD(req_type); 265 + int ret; 266 + 267 + ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size); 268 + if (ret != head_size) { 269 + pr_err("the head size of buffer is wrong (%d)!\n", ret); 270 + return -ENOMEM; 271 + } 272 + 273 + return head_size; 274 + } 275 + 276 + static int get_comp_head_size(struct acomp_req *acomp_req, u8 req_type) 277 + { 278 + if (!acomp_req->src || !acomp_req->slen) 279 + return -EINVAL; 280 + 281 + if (req_type == HZIP_ALG_TYPE_GZIP && 282 + acomp_req->slen < GZIP_HEAD_FEXTRA_SHIFT) 283 + return -EINVAL; 284 + 285 + switch (req_type) { 286 + case HZIP_ALG_TYPE_ZLIB: 287 + return TO_HEAD_SIZE(HZIP_ALG_TYPE_ZLIB); 288 + case HZIP_ALG_TYPE_GZIP: 289 + return TO_HEAD_SIZE(HZIP_ALG_TYPE_GZIP); 290 + default: 291 + pr_err("request type does not support!\n"); 292 + return -EINVAL; 293 + } 294 + } 295 + 296 + static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req, 297 + struct hisi_zip_qp_ctx *qp_ctx, 298 + size_t head_size, bool is_comp) 299 + { 300 + struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 301 + struct hisi_zip_req *q = req_q->q; 302 + struct hisi_zip_req *req_cache; 303 + int req_id; 304 + 305 + write_lock(&req_q->req_lock); 306 + 307 + req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size); 308 + if (req_id >= req_q->size) { 309 + write_unlock(&req_q->req_lock); 310 + dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n"); 311 + return ERR_PTR(-EAGAIN); 312 + } 313 + set_bit(req_id, req_q->req_bitmap); 314 + 315 + req_cache = q + req_id; 316 + req_cache->req_id = req_id; 317 + req_cache->req = req; 318 + 319 + if (is_comp) { 320 + req_cache->sskip = 0; 321 + req_cache->dskip = head_size; 322 + } else { 323 + req_cache->sskip = head_size; 324 + req_cache->dskip = 0; 325 + } 326 + 327 + write_unlock(&req_q->req_lock); 328 + 329 + return req_cache; 330 + } 331 + 332 + static void hisi_zip_remove_req(struct hisi_zip_qp_ctx *qp_ctx, 333 + struct hisi_zip_req *req) 334 + { 335 + struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 336 + 337 + write_lock(&req_q->req_lock); 338 + clear_bit(req->req_id, req_q->req_bitmap); 339 + memset(req, 0, sizeof(struct hisi_zip_req)); 340 + write_unlock(&req_q->req_lock); 341 + } 342 + 343 + static void hisi_zip_fill_addr(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req) 344 + { 345 + sqe->source_addr_l = lower_32_bits(req->dma_src); 346 + sqe->source_addr_h = upper_32_bits(req->dma_src); 347 + sqe->dest_addr_l = lower_32_bits(req->dma_dst); 348 + sqe->dest_addr_h = upper_32_bits(req->dma_dst); 349 + } 350 + 351 + static void hisi_zip_fill_buf_size(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req) 352 + { 353 + struct acomp_req *a_req = req->req; 354 + 355 + sqe->input_data_length = a_req->slen - req->sskip; 356 + sqe->dest_avail_out = a_req->dlen - req->dskip; 357 + sqe->dw7 = FIELD_PREP(HZIP_IN_SGE_DATA_OFFSET_M, req->sskip); 358 + sqe->dw8 = FIELD_PREP(HZIP_OUT_SGE_DATA_OFFSET_M, req->dskip); 359 + } 360 + 361 + static void hisi_zip_fill_buf_type(struct hisi_zip_sqe *sqe, u8 buf_type) 362 + { 363 + u32 val; 364 + 365 + val = sqe->dw9 & ~HZIP_BUF_TYPE_M; 366 + val |= FIELD_PREP(HZIP_BUF_TYPE_M, buf_type); 367 + sqe->dw9 = val; 368 + } 369 + 370 + static void hisi_zip_fill_req_type(struct hisi_zip_sqe *sqe, u8 req_type) 371 + { 372 + u32 val; 373 + 374 + val = sqe->dw9 & ~HZIP_REQ_TYPE_M; 375 + val |= FIELD_PREP(HZIP_REQ_TYPE_M, req_type); 376 + sqe->dw9 = val; 377 + } 378 + 379 + static void hisi_zip_fill_tag_v1(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req) 380 + { 381 + sqe->dw13 = req->req_id; 382 + } 383 + 384 + static void hisi_zip_fill_tag_v2(struct hisi_zip_sqe *sqe, struct hisi_zip_req *req) 385 + { 386 + sqe->dw26 = req->req_id; 387 + } 388 + 389 + static void hisi_zip_fill_sqe_type(struct hisi_zip_sqe *sqe, u8 sqe_type) 390 + { 391 + u32 val; 392 + 393 + val = sqe->dw7 & ~HZIP_SQE_TYPE_M; 394 + val |= FIELD_PREP(HZIP_SQE_TYPE_M, sqe_type); 395 + sqe->dw7 = val; 396 + } 397 + 398 + static void hisi_zip_fill_sqe(struct hisi_zip_ctx *ctx, struct hisi_zip_sqe *sqe, 399 + u8 req_type, struct hisi_zip_req *req) 400 + { 401 + const struct hisi_zip_sqe_ops *ops = ctx->ops; 402 + 403 + memset(sqe, 0, sizeof(struct hisi_zip_sqe)); 404 + 405 + ops->fill_addr(sqe, req); 406 + ops->fill_buf_size(sqe, req); 407 + ops->fill_buf_type(sqe, HZIP_SGL); 408 + ops->fill_req_type(sqe, req_type); 409 + ops->fill_tag(sqe, req); 410 + ops->fill_sqe_type(sqe, ops->sqe_type); 411 + } 412 + 413 + static int hisi_zip_do_work(struct hisi_zip_req *req, 414 + struct hisi_zip_qp_ctx *qp_ctx) 415 + { 416 + struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool; 417 + struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx; 418 + struct acomp_req *a_req = req->req; 419 + struct hisi_qp *qp = qp_ctx->qp; 420 + struct device *dev = &qp->qm->pdev->dev; 421 + struct hisi_zip_sqe zip_sqe; 422 + int ret; 423 + 424 + if (!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen) 425 + return -EINVAL; 426 + 427 + req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool, 428 + req->req_id << 1, &req->dma_src); 429 + if (IS_ERR(req->hw_src)) { 430 + dev_err(dev, "failed to map the src buffer to hw sgl (%ld)!\n", 431 + PTR_ERR(req->hw_src)); 432 + return PTR_ERR(req->hw_src); 433 + } 434 + 435 + req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->dst, pool, 436 + (req->req_id << 1) + 1, 437 + &req->dma_dst); 438 + if (IS_ERR(req->hw_dst)) { 439 + ret = PTR_ERR(req->hw_dst); 440 + dev_err(dev, "failed to map the dst buffer to hw slg (%d)!\n", 441 + ret); 442 + goto err_unmap_input; 443 + } 444 + 445 + hisi_zip_fill_sqe(qp_ctx->ctx, &zip_sqe, qp->req_type, req); 446 + 447 + /* send command to start a task */ 448 + atomic64_inc(&dfx->send_cnt); 449 + ret = hisi_qp_send(qp, &zip_sqe); 450 + if (ret < 0) { 451 + atomic64_inc(&dfx->send_busy_cnt); 452 + ret = -EAGAIN; 453 + dev_dbg_ratelimited(dev, "failed to send request!\n"); 454 + goto err_unmap_output; 455 + } 456 + 457 + return -EINPROGRESS; 458 + 459 + err_unmap_output: 460 + hisi_acc_sg_buf_unmap(dev, a_req->dst, req->hw_dst); 461 + err_unmap_input: 462 + hisi_acc_sg_buf_unmap(dev, a_req->src, req->hw_src); 463 + return ret; 464 + } 465 + 466 + static u32 hisi_zip_get_tag_v1(struct hisi_zip_sqe *sqe) 467 + { 468 + return sqe->dw13; 469 + } 470 + 471 + static u32 hisi_zip_get_tag_v2(struct hisi_zip_sqe *sqe) 472 + { 473 + return sqe->dw26; 474 + } 475 + 476 + static u32 hisi_zip_get_status(struct hisi_zip_sqe *sqe) 477 + { 478 + return sqe->dw3 & HZIP_BD_STATUS_M; 479 + } 480 + 481 + static u32 hisi_zip_get_dstlen(struct hisi_zip_sqe *sqe) 482 + { 483 + return sqe->produced; 484 + } 485 + 486 + static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data) 487 + { 488 + struct hisi_zip_qp_ctx *qp_ctx = qp->qp_ctx; 489 + const struct hisi_zip_sqe_ops *ops = qp_ctx->ctx->ops; 490 + struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx; 491 + struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 492 + struct device *dev = &qp->qm->pdev->dev; 493 + struct hisi_zip_sqe *sqe = data; 494 + u32 tag = ops->get_tag(sqe); 495 + struct hisi_zip_req *req = req_q->q + tag; 496 + struct acomp_req *acomp_req = req->req; 497 + u32 status, dlen, head_size; 498 + int err = 0; 499 + 500 + atomic64_inc(&dfx->recv_cnt); 501 + status = ops->get_status(sqe); 502 + if (status != 0 && status != HZIP_NC_ERR) { 503 + dev_err(dev, "%scompress fail in qp%u: %u, output: %u\n", 504 + (qp->alg_type == 0) ? "" : "de", qp->qp_id, status, 505 + sqe->produced); 506 + atomic64_inc(&dfx->err_bd_cnt); 507 + err = -EIO; 508 + } 509 + 510 + dlen = ops->get_dstlen(sqe); 511 + 512 + hisi_acc_sg_buf_unmap(dev, acomp_req->src, req->hw_src); 513 + hisi_acc_sg_buf_unmap(dev, acomp_req->dst, req->hw_dst); 514 + 515 + head_size = (qp->alg_type == 0) ? TO_HEAD_SIZE(qp->req_type) : 0; 516 + acomp_req->dlen = dlen + head_size; 517 + 518 + if (acomp_req->base.complete) 519 + acomp_request_complete(acomp_req, err); 520 + 521 + hisi_zip_remove_req(qp_ctx, req); 522 + } 523 + 524 + static int hisi_zip_acompress(struct acomp_req *acomp_req) 525 + { 526 + struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 527 + struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP]; 528 + struct device *dev = &qp_ctx->qp->qm->pdev->dev; 529 + struct hisi_zip_req *req; 530 + int head_size; 531 + int ret; 532 + 533 + /* let's output compression head now */ 534 + head_size = add_comp_head(acomp_req->dst, qp_ctx->qp->req_type); 535 + if (head_size < 0) { 536 + dev_err_ratelimited(dev, "failed to add comp head (%d)!\n", 537 + head_size); 538 + return head_size; 539 + } 540 + 541 + req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true); 542 + if (IS_ERR(req)) 543 + return PTR_ERR(req); 544 + 545 + ret = hisi_zip_do_work(req, qp_ctx); 546 + if (ret != -EINPROGRESS) { 547 + dev_info_ratelimited(dev, "failed to do compress (%d)!\n", ret); 548 + hisi_zip_remove_req(qp_ctx, req); 549 + } 550 + 551 + return ret; 552 + } 553 + 554 + static int hisi_zip_adecompress(struct acomp_req *acomp_req) 555 + { 556 + struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 557 + struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP]; 558 + struct device *dev = &qp_ctx->qp->qm->pdev->dev; 559 + struct hisi_zip_req *req; 560 + int head_size, ret; 561 + 562 + head_size = get_comp_head_size(acomp_req, qp_ctx->qp->req_type); 563 + if (head_size < 0) { 564 + dev_err_ratelimited(dev, "failed to get comp head size (%d)!\n", 565 + head_size); 566 + return head_size; 567 + } 568 + 569 + req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false); 570 + if (IS_ERR(req)) 571 + return PTR_ERR(req); 572 + 573 + ret = hisi_zip_do_work(req, qp_ctx); 574 + if (ret != -EINPROGRESS) { 575 + dev_info_ratelimited(dev, "failed to do decompress (%d)!\n", 576 + ret); 577 + hisi_zip_remove_req(qp_ctx, req); 578 + } 579 + 580 + return ret; 581 + } 582 + 583 + static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *ctx, 584 + int alg_type, int req_type) 585 + { 586 + struct device *dev = &qp->qm->pdev->dev; 587 + int ret; 588 + 589 + qp->req_type = req_type; 590 + qp->alg_type = alg_type; 591 + qp->qp_ctx = ctx; 592 + 593 + ret = hisi_qm_start_qp(qp, 0); 594 + if (ret < 0) { 595 + dev_err(dev, "failed to start qp (%d)!\n", ret); 596 + return ret; 597 + } 598 + 599 + ctx->qp = qp; 600 + 601 + return 0; 602 + } 603 + 604 + static void hisi_zip_release_qp(struct hisi_zip_qp_ctx *ctx) 605 + { 606 + hisi_qm_stop_qp(ctx->qp); 607 + hisi_qm_release_qp(ctx->qp); 608 + } 609 + 610 + static const struct hisi_zip_sqe_ops hisi_zip_ops_v1 = { 611 + .sqe_type = 0, 612 + .fill_addr = hisi_zip_fill_addr, 613 + .fill_buf_size = hisi_zip_fill_buf_size, 614 + .fill_buf_type = hisi_zip_fill_buf_type, 615 + .fill_req_type = hisi_zip_fill_req_type, 616 + .fill_tag = hisi_zip_fill_tag_v1, 617 + .fill_sqe_type = hisi_zip_fill_sqe_type, 618 + .get_tag = hisi_zip_get_tag_v1, 619 + .get_status = hisi_zip_get_status, 620 + .get_dstlen = hisi_zip_get_dstlen, 621 + }; 622 + 623 + static const struct hisi_zip_sqe_ops hisi_zip_ops_v2 = { 624 + .sqe_type = 0x3, 625 + .fill_addr = hisi_zip_fill_addr, 626 + .fill_buf_size = hisi_zip_fill_buf_size, 627 + .fill_buf_type = hisi_zip_fill_buf_type, 628 + .fill_req_type = hisi_zip_fill_req_type, 629 + .fill_tag = hisi_zip_fill_tag_v2, 630 + .fill_sqe_type = hisi_zip_fill_sqe_type, 631 + .get_tag = hisi_zip_get_tag_v2, 632 + .get_status = hisi_zip_get_status, 633 + .get_dstlen = hisi_zip_get_dstlen, 634 + }; 635 + 636 + static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int node) 637 + { 638 + struct hisi_qp *qps[HZIP_CTX_Q_NUM] = { NULL }; 639 + struct hisi_zip_qp_ctx *qp_ctx; 640 + struct hisi_zip *hisi_zip; 641 + int ret, i, j; 642 + 643 + ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node); 644 + if (ret) { 645 + pr_err("failed to create zip qps (%d)!\n", ret); 646 + return -ENODEV; 647 + } 648 + 649 + hisi_zip = container_of(qps[0]->qm, struct hisi_zip, qm); 650 + 651 + for (i = 0; i < HZIP_CTX_Q_NUM; i++) { 652 + /* alg_type = 0 for compress, 1 for decompress in hw sqe */ 653 + qp_ctx = &hisi_zip_ctx->qp_ctx[i]; 654 + qp_ctx->ctx = hisi_zip_ctx; 655 + ret = hisi_zip_start_qp(qps[i], qp_ctx, i, req_type); 656 + if (ret) { 657 + for (j = i - 1; j >= 0; j--) 658 + hisi_qm_stop_qp(hisi_zip_ctx->qp_ctx[j].qp); 659 + 660 + hisi_qm_free_qps(qps, HZIP_CTX_Q_NUM); 661 + return ret; 662 + } 663 + 664 + qp_ctx->zip_dev = hisi_zip; 665 + } 666 + 667 + if (hisi_zip->qm.ver < QM_HW_V3) 668 + hisi_zip_ctx->ops = &hisi_zip_ops_v1; 669 + else 670 + hisi_zip_ctx->ops = &hisi_zip_ops_v2; 671 + 672 + return 0; 673 + } 674 + 675 + static void hisi_zip_ctx_exit(struct hisi_zip_ctx *hisi_zip_ctx) 676 + { 677 + int i; 678 + 679 + for (i = 1; i >= 0; i--) 680 + hisi_zip_release_qp(&hisi_zip_ctx->qp_ctx[i]); 167 681 } 168 682 169 683 static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx) ··· 684 336 ctx->qp_ctx[i].sgl_pool); 685 337 } 686 338 687 - static void hisi_zip_remove_req(struct hisi_zip_qp_ctx *qp_ctx, 688 - struct hisi_zip_req *req) 689 - { 690 - struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 691 - 692 - write_lock(&req_q->req_lock); 693 - clear_bit(req->req_id, req_q->req_bitmap); 694 - memset(req, 0, sizeof(struct hisi_zip_req)); 695 - write_unlock(&req_q->req_lock); 696 - } 697 - 698 - static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data) 699 - { 700 - struct hisi_zip_sqe *sqe = data; 701 - struct hisi_zip_qp_ctx *qp_ctx = qp->qp_ctx; 702 - struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx; 703 - struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 704 - struct hisi_zip_req *req = req_q->q + sqe->tag; 705 - struct acomp_req *acomp_req = req->req; 706 - struct device *dev = &qp->qm->pdev->dev; 707 - u32 status, dlen, head_size; 708 - int err = 0; 709 - 710 - atomic64_inc(&dfx->recv_cnt); 711 - status = sqe->dw3 & HZIP_BD_STATUS_M; 712 - if (status != 0 && status != HZIP_NC_ERR) { 713 - dev_err(dev, "%scompress fail in qp%u: %u, output: %u\n", 714 - (qp->alg_type == 0) ? "" : "de", qp->qp_id, status, 715 - sqe->produced); 716 - atomic64_inc(&dfx->err_bd_cnt); 717 - err = -EIO; 718 - } 719 - dlen = sqe->produced; 720 - 721 - hisi_acc_sg_buf_unmap(dev, acomp_req->src, req->hw_src); 722 - hisi_acc_sg_buf_unmap(dev, acomp_req->dst, req->hw_dst); 723 - 724 - head_size = (qp->alg_type == 0) ? TO_HEAD_SIZE(qp->req_type) : 0; 725 - acomp_req->dlen = dlen + head_size; 726 - 727 - if (acomp_req->base.complete) 728 - acomp_request_complete(acomp_req, err); 729 - 730 - hisi_zip_remove_req(qp_ctx, req); 731 - } 732 - 733 339 static void hisi_zip_set_acomp_cb(struct hisi_zip_ctx *ctx, 734 340 void (*fn)(struct hisi_qp *, void *)) 735 341 { ··· 741 439 hisi_zip_ctx_exit(ctx); 742 440 } 743 441 744 - static int add_comp_head(struct scatterlist *dst, u8 req_type) 745 - { 746 - int head_size = TO_HEAD_SIZE(req_type); 747 - const u8 *head = TO_HEAD(req_type); 748 - int ret; 749 - 750 - ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size); 751 - if (ret != head_size) { 752 - pr_err("the head size of buffer is wrong (%d)!\n", ret); 753 - return -ENOMEM; 754 - } 755 - 756 - return head_size; 757 - } 758 - 759 - static size_t __maybe_unused get_gzip_head_size(struct scatterlist *sgl) 760 - { 761 - char buf[HZIP_GZIP_HEAD_BUF]; 762 - 763 - sg_copy_to_buffer(sgl, sg_nents(sgl), buf, sizeof(buf)); 764 - 765 - return __get_gzip_head_size(buf); 766 - } 767 - 768 - static int get_comp_head_size(struct acomp_req *acomp_req, u8 req_type) 769 - { 770 - if (!acomp_req->src || !acomp_req->slen) 771 - return -EINVAL; 772 - 773 - if ((req_type == HZIP_ALG_TYPE_GZIP) && 774 - (acomp_req->slen < GZIP_HEAD_FEXTRA_SHIFT)) 775 - return -EINVAL; 776 - 777 - switch (req_type) { 778 - case HZIP_ALG_TYPE_ZLIB: 779 - return TO_HEAD_SIZE(HZIP_ALG_TYPE_ZLIB); 780 - case HZIP_ALG_TYPE_GZIP: 781 - return TO_HEAD_SIZE(HZIP_ALG_TYPE_GZIP); 782 - default: 783 - pr_err("request type does not support!\n"); 784 - return -EINVAL; 785 - } 786 - } 787 - 788 - static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req, 789 - struct hisi_zip_qp_ctx *qp_ctx, 790 - size_t head_size, bool is_comp) 791 - { 792 - struct hisi_zip_req_q *req_q = &qp_ctx->req_q; 793 - struct hisi_zip_req *q = req_q->q; 794 - struct hisi_zip_req *req_cache; 795 - int req_id; 796 - 797 - write_lock(&req_q->req_lock); 798 - 799 - req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size); 800 - if (req_id >= req_q->size) { 801 - write_unlock(&req_q->req_lock); 802 - dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n"); 803 - return ERR_PTR(-EAGAIN); 804 - } 805 - set_bit(req_id, req_q->req_bitmap); 806 - 807 - req_cache = q + req_id; 808 - req_cache->req_id = req_id; 809 - req_cache->req = req; 810 - 811 - if (is_comp) { 812 - req_cache->sskip = 0; 813 - req_cache->dskip = head_size; 814 - } else { 815 - req_cache->sskip = head_size; 816 - req_cache->dskip = 0; 817 - } 818 - 819 - write_unlock(&req_q->req_lock); 820 - 821 - return req_cache; 822 - } 823 - 824 - static int hisi_zip_do_work(struct hisi_zip_req *req, 825 - struct hisi_zip_qp_ctx *qp_ctx) 826 - { 827 - struct acomp_req *a_req = req->req; 828 - struct hisi_qp *qp = qp_ctx->qp; 829 - struct device *dev = &qp->qm->pdev->dev; 830 - struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool; 831 - struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx; 832 - struct hisi_zip_sqe zip_sqe; 833 - dma_addr_t input, output; 834 - int ret; 835 - 836 - if (!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen) 837 - return -EINVAL; 838 - 839 - req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool, 840 - req->req_id << 1, &input); 841 - if (IS_ERR(req->hw_src)) { 842 - dev_err(dev, "failed to map the src buffer to hw sgl (%ld)!\n", 843 - PTR_ERR(req->hw_src)); 844 - return PTR_ERR(req->hw_src); 845 - } 846 - req->dma_src = input; 847 - 848 - req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->dst, pool, 849 - (req->req_id << 1) + 1, 850 - &output); 851 - if (IS_ERR(req->hw_dst)) { 852 - ret = PTR_ERR(req->hw_dst); 853 - dev_err(dev, "failed to map the dst buffer to hw slg (%d)!\n", 854 - ret); 855 - goto err_unmap_input; 856 - } 857 - req->dma_dst = output; 858 - 859 - hisi_zip_fill_sqe(&zip_sqe, qp->req_type, input, output, a_req->slen, 860 - a_req->dlen, req->sskip, req->dskip); 861 - hisi_zip_config_buf_type(&zip_sqe, HZIP_SGL); 862 - hisi_zip_config_tag(&zip_sqe, req->req_id); 863 - 864 - /* send command to start a task */ 865 - atomic64_inc(&dfx->send_cnt); 866 - ret = hisi_qp_send(qp, &zip_sqe); 867 - if (ret < 0) { 868 - atomic64_inc(&dfx->send_busy_cnt); 869 - ret = -EAGAIN; 870 - dev_dbg_ratelimited(dev, "failed to send request!\n"); 871 - goto err_unmap_output; 872 - } 873 - 874 - return -EINPROGRESS; 875 - 876 - err_unmap_output: 877 - hisi_acc_sg_buf_unmap(dev, a_req->dst, req->hw_dst); 878 - err_unmap_input: 879 - hisi_acc_sg_buf_unmap(dev, a_req->src, req->hw_src); 880 - return ret; 881 - } 882 - 883 - static int hisi_zip_acompress(struct acomp_req *acomp_req) 884 - { 885 - struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 886 - struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP]; 887 - struct device *dev = &qp_ctx->qp->qm->pdev->dev; 888 - struct hisi_zip_req *req; 889 - int head_size; 890 - int ret; 891 - 892 - /* let's output compression head now */ 893 - head_size = add_comp_head(acomp_req->dst, qp_ctx->qp->req_type); 894 - if (head_size < 0) { 895 - dev_err_ratelimited(dev, "failed to add comp head (%d)!\n", 896 - head_size); 897 - return head_size; 898 - } 899 - 900 - req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true); 901 - if (IS_ERR(req)) 902 - return PTR_ERR(req); 903 - 904 - ret = hisi_zip_do_work(req, qp_ctx); 905 - if (ret != -EINPROGRESS) { 906 - dev_info_ratelimited(dev, "failed to do compress (%d)!\n", ret); 907 - hisi_zip_remove_req(qp_ctx, req); 908 - } 909 - 910 - return ret; 911 - } 912 - 913 - static int hisi_zip_adecompress(struct acomp_req *acomp_req) 914 - { 915 - struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 916 - struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP]; 917 - struct device *dev = &qp_ctx->qp->qm->pdev->dev; 918 - struct hisi_zip_req *req; 919 - int head_size, ret; 920 - 921 - head_size = get_comp_head_size(acomp_req, qp_ctx->qp->req_type); 922 - if (head_size < 0) { 923 - dev_err_ratelimited(dev, "failed to get comp head size (%d)!\n", 924 - head_size); 925 - return head_size; 926 - } 927 - 928 - req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false); 929 - if (IS_ERR(req)) 930 - return PTR_ERR(req); 931 - 932 - ret = hisi_zip_do_work(req, qp_ctx); 933 - if (ret != -EINPROGRESS) { 934 - dev_info_ratelimited(dev, "failed to do decompress (%d)!\n", 935 - ret); 936 - hisi_zip_remove_req(qp_ctx, req); 937 - } 938 - 939 - return ret; 940 - } 941 - 942 442 static struct acomp_alg hisi_zip_acomp_zlib = { 943 443 .init = hisi_zip_acomp_init, 944 444 .exit = hisi_zip_acomp_exit, ··· 769 665 } 770 666 }; 771 667 772 - int hisi_zip_register_to_crypto(void) 668 + int hisi_zip_register_to_crypto(struct hisi_qm *qm) 773 669 { 774 670 int ret; 775 671 ··· 788 684 return ret; 789 685 } 790 686 791 - void hisi_zip_unregister_from_crypto(void) 687 + void hisi_zip_unregister_from_crypto(struct hisi_qm *qm) 792 688 { 793 689 crypto_unregister_acomp(&hisi_zip_acomp_gzip); 794 690 crypto_unregister_acomp(&hisi_zip_acomp_zlib);
+23 -76
drivers/crypto/hisilicon/zip/zip_main.c
··· 18 18 #define PCI_DEVICE_ID_ZIP_VF 0xa251 19 19 20 20 #define HZIP_QUEUE_NUM_V1 4096 21 - #define HZIP_QUEUE_NUM_V2 1024 22 21 23 22 #define HZIP_CLOCK_GATE_CTRL 0x301004 24 23 #define COMP0_ENABLE BIT(0) ··· 68 69 #define HZIP_CORE_INT_RAS_CE_ENABLE 0x1 69 70 #define HZIP_CORE_INT_RAS_NFE_ENB 0x301164 70 71 #define HZIP_CORE_INT_RAS_FE_ENB 0x301168 71 - #define HZIP_CORE_INT_RAS_NFE_ENABLE 0x7FE 72 + #define HZIP_CORE_INT_RAS_NFE_ENABLE 0x1FFE 72 73 #define HZIP_SRAM_ECC_ERR_NUM_SHIFT 16 73 74 #define HZIP_SRAM_ECC_ERR_ADDR_SHIFT 24 74 - #define HZIP_CORE_INT_MASK_ALL GENMASK(10, 0) 75 + #define HZIP_CORE_INT_MASK_ALL GENMASK(12, 0) 75 76 #define HZIP_COMP_CORE_NUM 2 76 77 #define HZIP_DECOMP_CORE_NUM 6 77 78 #define HZIP_CORE_NUM (HZIP_COMP_CORE_NUM + \ ··· 133 134 { .int_msk = BIT(8), .msg = "zip_com_inf_err" }, 134 135 { .int_msk = BIT(9), .msg = "zip_enc_inf_err" }, 135 136 { .int_msk = BIT(10), .msg = "zip_pre_out_err" }, 137 + { .int_msk = BIT(11), .msg = "zip_axi_poison_err" }, 138 + { .int_msk = BIT(12), .msg = "zip_sva_err" }, 136 139 { /* sentinel */ } 137 140 }; 138 141 139 142 enum ctrl_debug_file_index { 140 - HZIP_CURRENT_QM, 141 143 HZIP_CLEAR_ENABLE, 142 144 HZIP_DEBUG_FILE_NUM, 143 145 }; 144 146 145 147 static const char * const ctrl_debug_file_name[] = { 146 - [HZIP_CURRENT_QM] = "current_qm", 147 148 [HZIP_CLEAR_ENABLE] = "clear_enable", 148 149 }; 149 150 ··· 362 363 return &hisi_zip->qm; 363 364 } 364 365 365 - static u32 current_qm_read(struct ctrl_debug_file *file) 366 - { 367 - struct hisi_qm *qm = file_to_qm(file); 368 - 369 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 370 - } 371 - 372 - static int current_qm_write(struct ctrl_debug_file *file, u32 val) 373 - { 374 - struct hisi_qm *qm = file_to_qm(file); 375 - u32 vfq_num; 376 - u32 tmp; 377 - 378 - if (val > qm->vfs_num) 379 - return -EINVAL; 380 - 381 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 382 - if (val == 0) { 383 - qm->debug.curr_qm_qp_num = qm->qp_num; 384 - } else { 385 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num; 386 - if (val == qm->vfs_num) 387 - qm->debug.curr_qm_qp_num = qm->ctrl_qp_num - 388 - qm->qp_num - (qm->vfs_num - 1) * vfq_num; 389 - else 390 - qm->debug.curr_qm_qp_num = vfq_num; 391 - } 392 - 393 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 394 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 395 - 396 - tmp = val | 397 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 398 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 399 - 400 - tmp = val | 401 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 402 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 403 - 404 - return 0; 405 - } 406 - 407 366 static u32 clear_enable_read(struct ctrl_debug_file *file) 408 367 { 409 368 struct hisi_qm *qm = file_to_qm(file); ··· 395 438 396 439 spin_lock_irq(&file->lock); 397 440 switch (file->index) { 398 - case HZIP_CURRENT_QM: 399 - val = current_qm_read(file); 400 - break; 401 441 case HZIP_CLEAR_ENABLE: 402 442 val = clear_enable_read(file); 403 443 break; ··· 432 478 433 479 spin_lock_irq(&file->lock); 434 480 switch (file->index) { 435 - case HZIP_CURRENT_QM: 436 - ret = current_qm_write(file, val); 437 - if (ret) 438 - goto err_input; 439 - break; 440 481 case HZIP_CLEAR_ENABLE: 441 482 ret = clear_enable_write(file, val); 442 483 if (ret) ··· 529 580 struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm); 530 581 int i; 531 582 532 - for (i = HZIP_CURRENT_QM; i < HZIP_DEBUG_FILE_NUM; i++) { 583 + for (i = HZIP_CLEAR_ENABLE; i < HZIP_DEBUG_FILE_NUM; i++) { 533 584 spin_lock_init(&zip->ctrl->files[i].lock); 534 585 zip->ctrl->files[i].ctrl = zip->ctrl; 535 586 zip->ctrl->files[i].index = i; ··· 575 626 static void hisi_zip_debug_regs_clear(struct hisi_qm *qm) 576 627 { 577 628 int i, j; 578 - 579 - /* clear current_qm */ 580 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 581 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 582 629 583 630 /* enable register read_clear bit */ 584 631 writel(HZIP_RD_CNT_CLR_CE_EN, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE); ··· 659 714 qm->io_base + HZIP_CORE_INT_SET); 660 715 } 661 716 717 + static void hisi_zip_err_info_init(struct hisi_qm *qm) 718 + { 719 + struct hisi_qm_err_info *err_info = &qm->err_info; 720 + 721 + err_info->ce = QM_BASE_CE; 722 + err_info->fe = 0; 723 + err_info->ecc_2bits_mask = HZIP_CORE_INT_STATUS_M_ECC; 724 + err_info->dev_ce_mask = HZIP_CORE_INT_RAS_CE_ENABLE; 725 + err_info->msi_wr_port = HZIP_WR_PORT; 726 + err_info->acpi_rst = "ZRST"; 727 + err_info->nfe = QM_BASE_NFE | QM_ACC_WB_NOT_READY_TIMEOUT; 728 + 729 + if (qm->ver >= QM_HW_V3) 730 + err_info->nfe |= QM_ACC_DO_TASK_TIMEOUT; 731 + } 732 + 662 733 static const struct hisi_qm_err_ini hisi_zip_err_ini = { 663 734 .hw_init = hisi_zip_set_user_domain_and_cache, 664 735 .hw_err_enable = hisi_zip_hw_error_enable, ··· 684 723 .log_dev_hw_err = hisi_zip_log_hw_error, 685 724 .open_axi_master_ooo = hisi_zip_open_axi_master_ooo, 686 725 .close_axi_master_ooo = hisi_zip_close_axi_master_ooo, 687 - .err_info = { 688 - .ce = QM_BASE_CE, 689 - .nfe = QM_BASE_NFE | 690 - QM_ACC_WB_NOT_READY_TIMEOUT, 691 - .fe = 0, 692 - .ecc_2bits_mask = HZIP_CORE_INT_STATUS_M_ECC, 693 - .dev_ce_mask = HZIP_CORE_INT_RAS_CE_ENABLE, 694 - .msi_wr_port = HZIP_WR_PORT, 695 - .acpi_rst = "ZRST", 696 - } 726 + .err_info_init = hisi_zip_err_info_init, 697 727 }; 698 728 699 729 static int hisi_zip_pf_probe_init(struct hisi_zip *hisi_zip) ··· 698 746 699 747 hisi_zip->ctrl = ctrl; 700 748 ctrl->hisi_zip = hisi_zip; 701 - 702 - if (qm->ver == QM_HW_V1) 703 - qm->ctrl_qp_num = HZIP_QUEUE_NUM_V1; 704 - else 705 - qm->ctrl_qp_num = HZIP_QUEUE_NUM_V2; 706 - 707 749 qm->err_ini = &hisi_zip_err_ini; 750 + qm->err_ini->err_info_init(qm); 708 751 709 752 hisi_zip_set_user_domain_and_cache(qm); 710 753 hisi_qm_dev_err_init(qm);
-3
drivers/crypto/img-hash.c
··· 963 963 hdev->io_base = devm_platform_ioremap_resource(pdev, 0); 964 964 if (IS_ERR(hdev->io_base)) { 965 965 err = PTR_ERR(hdev->io_base); 966 - dev_err(dev, "can't ioremap, returned %d\n", err); 967 - 968 966 goto res_err; 969 967 } 970 968 ··· 970 972 hash_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 971 973 hdev->cpu_addr = devm_ioremap_resource(dev, hash_res); 972 974 if (IS_ERR(hdev->cpu_addr)) { 973 - dev_err(dev, "can't ioremap write port\n"); 974 975 err = PTR_ERR(hdev->cpu_addr); 975 976 goto res_err; 976 977 }
+1 -1
drivers/crypto/inside-secure/safexcel.c
··· 688 688 /* Leave the DSE threads reset state */ 689 689 writel(0, EIP197_HIA_DSE_THR(priv) + EIP197_HIA_DSE_THR_CTRL(pe)); 690 690 691 - /* Configure the procesing engine thresholds */ 691 + /* Configure the processing engine thresholds */ 692 692 writel(EIP197_PE_OUT_DBUF_THRES_MIN(opbuflo) | 693 693 EIP197_PE_OUT_DBUF_THRES_MAX(opbufhi), 694 694 EIP197_PE(priv) + EIP197_PE_OUT_DBUF_THRES(pe));
+2 -5
drivers/crypto/ixp4xx_crypto.c
··· 265 265 return 0; 266 266 } 267 267 268 - static spinlock_t desc_lock; 268 + static DEFINE_SPINLOCK(desc_lock); 269 269 static struct crypt_ctl *get_crypt_desc(void) 270 270 { 271 271 int i; ··· 293 293 } 294 294 } 295 295 296 - static spinlock_t emerg_lock; 296 + static DEFINE_SPINLOCK(emerg_lock); 297 297 static struct crypt_ctl *get_crypt_desc_emerg(void) 298 298 { 299 299 int i; ··· 1378 1378 pdev = platform_device_register_full(&ixp_dev_info); 1379 1379 if (IS_ERR(pdev)) 1380 1380 return PTR_ERR(pdev); 1381 - 1382 - spin_lock_init(&desc_lock); 1383 - spin_lock_init(&emerg_lock); 1384 1381 1385 1382 err = init_ixp_crypto(&pdev->dev); 1386 1383 if (err) {
+4 -4
drivers/crypto/keembay/keembay-ocs-aes-core.c
··· 1623 1623 } 1624 1624 1625 1625 aes_dev->base_reg = devm_ioremap_resource(&pdev->dev, aes_mem); 1626 - if (IS_ERR(aes_dev->base_reg)) { 1627 - dev_err(dev, "Failed to get base address\n"); 1626 + if (IS_ERR(aes_dev->base_reg)) 1628 1627 return PTR_ERR(aes_dev->base_reg); 1629 - } 1630 1628 1631 1629 /* Get and request IRQ */ 1632 1630 aes_dev->irq = platform_get_irq(pdev, 0); ··· 1647 1649 1648 1650 /* Initialize crypto engine */ 1649 1651 aes_dev->engine = crypto_engine_alloc_init(dev, true); 1650 - if (!aes_dev->engine) 1652 + if (!aes_dev->engine) { 1653 + rc = -ENOMEM; 1651 1654 goto list_del; 1655 + } 1652 1656 1653 1657 rc = crypto_engine_start(aes_dev->engine); 1654 1658 if (rc) {
+4 -4
drivers/crypto/keembay/keembay-ocs-hcu-core.c
··· 1192 1192 } 1193 1193 1194 1194 hcu_dev->io_base = devm_ioremap_resource(dev, hcu_mem); 1195 - if (IS_ERR(hcu_dev->io_base)) { 1196 - dev_err(dev, "Could not io-remap mem resource.\n"); 1195 + if (IS_ERR(hcu_dev->io_base)) 1197 1196 return PTR_ERR(hcu_dev->io_base); 1198 - } 1199 1197 1200 1198 init_completion(&hcu_dev->irq_done); 1201 1199 ··· 1218 1220 1219 1221 /* Initialize crypto engine */ 1220 1222 hcu_dev->engine = crypto_engine_alloc_init(dev, 1); 1221 - if (!hcu_dev->engine) 1223 + if (!hcu_dev->engine) { 1224 + rc = -ENOMEM; 1222 1225 goto list_del; 1226 + } 1223 1227 1224 1228 rc = crypto_engine_start(hcu_dev->engine); 1225 1229 if (rc) {
+4 -4
drivers/crypto/keembay/ocs-hcu.c
··· 93 93 #define OCS_HCU_WAIT_BUSY_TIMEOUT_US 1000000 94 94 95 95 /** 96 - * struct ocs_hcu_dma_list - An entry in an OCS DMA linked list. 96 + * struct ocs_hcu_dma_entry - An entry in an OCS DMA linked list. 97 97 * @src_addr: Source address of the data. 98 98 * @src_len: Length of data to be fetched. 99 99 * @nxt_desc: Next descriptor to fetch. ··· 107 107 }; 108 108 109 109 /** 110 - * struct ocs_dma_list - OCS-specific DMA linked list. 110 + * struct ocs_hcu_dma_list - OCS-specific DMA linked list. 111 111 * @head: The head of the list (points to the array backing the list). 112 112 * @tail: The current tail of the list; NULL if the list is empty. 113 113 * @dma_addr: The DMA address of @head (i.e., the DMA address of the backing ··· 597 597 } 598 598 599 599 /** 600 - * ocs_hcu_digest() - Perform a hashing iteration. 600 + * ocs_hcu_hash_update() - Perform a hashing iteration. 601 601 * @hcu_dev: The OCS HCU device to use. 602 602 * @ctx: The OCS HCU hashing context. 603 603 * @dma_list: The OCS DMA list mapping the input data to process. ··· 632 632 } 633 633 634 634 /** 635 - * ocs_hcu_hash_final() - Update and finalize hash computation. 635 + * ocs_hcu_hash_finup() - Update and finalize hash computation. 636 636 * @hcu_dev: The OCS HCU device to use. 637 637 * @ctx: The OCS HCU hashing context. 638 638 * @dma_list: The OCS DMA list mapping the input data to process.
+5 -5
drivers/crypto/marvell/octeontx2/otx2_cpt_common.h
··· 121 121 122 122 int otx2_cpt_send_af_reg_requests(struct otx2_mbox *mbox, 123 123 struct pci_dev *pdev); 124 - int otx2_cpt_add_read_af_reg(struct otx2_mbox *mbox, 125 - struct pci_dev *pdev, u64 reg, u64 *val); 124 + int otx2_cpt_add_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 125 + u64 reg, u64 *val, int blkaddr); 126 126 int otx2_cpt_add_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 127 - u64 reg, u64 val); 127 + u64 reg, u64 val, int blkaddr); 128 128 int otx2_cpt_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 129 - u64 reg, u64 *val); 129 + u64 reg, u64 *val, int blkaddr); 130 130 int otx2_cpt_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 131 - u64 reg, u64 val); 131 + u64 reg, u64 val, int blkaddr); 132 132 struct otx2_cptlfs_info; 133 133 int otx2_cpt_attach_rscrs_msg(struct otx2_cptlfs_info *lfs); 134 134 int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs);
+8 -6
drivers/crypto/marvell/octeontx2/otx2_cpt_mbox_common.c
··· 43 43 } 44 44 45 45 int otx2_cpt_add_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 46 - u64 reg, u64 *val) 46 + u64 reg, u64 *val, int blkaddr) 47 47 { 48 48 struct cpt_rd_wr_reg_msg *reg_msg; 49 49 ··· 62 62 reg_msg->is_write = 0; 63 63 reg_msg->reg_offset = reg; 64 64 reg_msg->ret_val = val; 65 + reg_msg->blkaddr = blkaddr; 65 66 66 67 return 0; 67 68 } 68 69 69 70 int otx2_cpt_add_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 70 - u64 reg, u64 val) 71 + u64 reg, u64 val, int blkaddr) 71 72 { 72 73 struct cpt_rd_wr_reg_msg *reg_msg; 73 74 ··· 87 86 reg_msg->is_write = 1; 88 87 reg_msg->reg_offset = reg; 89 88 reg_msg->val = val; 89 + reg_msg->blkaddr = blkaddr; 90 90 91 91 return 0; 92 92 } 93 93 94 94 int otx2_cpt_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 95 - u64 reg, u64 *val) 95 + u64 reg, u64 *val, int blkaddr) 96 96 { 97 97 int ret; 98 98 99 - ret = otx2_cpt_add_read_af_reg(mbox, pdev, reg, val); 99 + ret = otx2_cpt_add_read_af_reg(mbox, pdev, reg, val, blkaddr); 100 100 if (ret) 101 101 return ret; 102 102 ··· 105 103 } 106 104 107 105 int otx2_cpt_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 108 - u64 reg, u64 val) 106 + u64 reg, u64 val, int blkaddr) 109 107 { 110 108 int ret; 111 109 112 - ret = otx2_cpt_add_write_af_reg(mbox, pdev, reg, val); 110 + ret = otx2_cpt_add_write_af_reg(mbox, pdev, reg, val, blkaddr); 113 111 if (ret) 114 112 return ret; 115 113
+4 -4
drivers/crypto/marvell/octeontx2/otx2_cptlf.c
··· 56 56 57 57 ret = otx2_cpt_read_af_reg(lfs->mbox, lfs->pdev, 58 58 CPT_AF_LFX_CTL(lf->slot), 59 - &lf_ctrl.u); 59 + &lf_ctrl.u, lfs->blkaddr); 60 60 if (ret) 61 61 return ret; 62 62 ··· 64 64 65 65 ret = otx2_cpt_write_af_reg(lfs->mbox, lfs->pdev, 66 66 CPT_AF_LFX_CTL(lf->slot), 67 - lf_ctrl.u); 67 + lf_ctrl.u, lfs->blkaddr); 68 68 return ret; 69 69 } 70 70 ··· 77 77 78 78 ret = otx2_cpt_read_af_reg(lfs->mbox, lfs->pdev, 79 79 CPT_AF_LFX_CTL(lf->slot), 80 - &lf_ctrl.u); 80 + &lf_ctrl.u, lfs->blkaddr); 81 81 if (ret) 82 82 return ret; 83 83 ··· 85 85 86 86 ret = otx2_cpt_write_af_reg(lfs->mbox, lfs->pdev, 87 87 CPT_AF_LFX_CTL(lf->slot), 88 - lf_ctrl.u); 88 + lf_ctrl.u, lfs->blkaddr); 89 89 return ret; 90 90 } 91 91
+1
drivers/crypto/marvell/octeontx2/otx2_cptlf.h
··· 95 95 u8 kcrypto_eng_grp_num; /* Kernel crypto engine group number */ 96 96 u8 kvf_limits; /* Kernel crypto limits */ 97 97 atomic_t state; /* LF's state. started/reset */ 98 + int blkaddr; /* CPT blkaddr: BLKADDR_CPT0/BLKADDR_CPT1 */ 98 99 }; 99 100 100 101 static inline void otx2_cpt_free_instruction_queues(
+1
drivers/crypto/marvell/octeontx2/otx2_cptpf.h
··· 51 51 u8 max_vfs; /* Maximum number of VFs supported by CPT */ 52 52 u8 enabled_vfs; /* Number of enabled VFs */ 53 53 u8 kvf_limits; /* Kernel crypto limits */ 54 + bool has_cpt1; 54 55 }; 55 56 56 57 irqreturn_t otx2_cptpf_afpf_mbox_intr(int irq, void *arg);
+29 -4
drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c
··· 451 451 return 0; 452 452 } 453 453 454 - static int cptpf_device_reset(struct otx2_cptpf_dev *cptpf) 454 + static int cptx_device_reset(struct otx2_cptpf_dev *cptpf, int blkaddr) 455 455 { 456 456 int timeout = 10, ret; 457 457 u64 reg = 0; 458 458 459 459 ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 460 - CPT_AF_BLK_RST, 0x1); 460 + CPT_AF_BLK_RST, 0x1, blkaddr); 461 461 if (ret) 462 462 return ret; 463 463 464 464 do { 465 465 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 466 - CPT_AF_BLK_RST, &reg); 466 + CPT_AF_BLK_RST, &reg, blkaddr); 467 467 if (ret) 468 468 return ret; 469 469 ··· 478 478 return ret; 479 479 } 480 480 481 + static int cptpf_device_reset(struct otx2_cptpf_dev *cptpf) 482 + { 483 + int ret = 0; 484 + 485 + if (cptpf->has_cpt1) { 486 + ret = cptx_device_reset(cptpf, BLKADDR_CPT1); 487 + if (ret) 488 + return ret; 489 + } 490 + return cptx_device_reset(cptpf, BLKADDR_CPT0); 491 + } 492 + 493 + static void cptpf_check_block_implemented(struct otx2_cptpf_dev *cptpf) 494 + { 495 + u64 cfg; 496 + 497 + cfg = otx2_cpt_read64(cptpf->reg_base, BLKADDR_RVUM, 0, 498 + RVU_PF_BLOCK_ADDRX_DISC(BLKADDR_CPT1)); 499 + if (cfg & BIT_ULL(11)) 500 + cptpf->has_cpt1 = true; 501 + } 502 + 481 503 static int cptpf_device_init(struct otx2_cptpf_dev *cptpf) 482 504 { 483 505 union otx2_cptx_af_constants1 af_cnsts1 = {0}; 484 506 int ret = 0; 485 507 508 + /* check if 'implemented' bit is set for block BLKADDR_CPT1 */ 509 + cptpf_check_block_implemented(cptpf); 486 510 /* Reset the CPT PF device */ 487 511 ret = cptpf_device_reset(cptpf); 488 512 if (ret) ··· 514 490 515 491 /* Get number of SE, IE and AE engines */ 516 492 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 517 - CPT_AF_CONSTANTS1, &af_cnsts1.u); 493 + CPT_AF_CONSTANTS1, &af_cnsts1.u, 494 + BLKADDR_CPT0); 518 495 if (ret) 519 496 return ret; 520 497
+105 -39
drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c
··· 153 153 } 154 154 155 155 static int __write_ucode_base(struct otx2_cptpf_dev *cptpf, int eng, 156 - dma_addr_t dma_addr) 156 + dma_addr_t dma_addr, int blkaddr) 157 157 { 158 158 return otx2_cpt_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 159 159 CPT_AF_EXEX_UCODE_BASE(eng), 160 - (u64)dma_addr); 160 + (u64)dma_addr, blkaddr); 161 161 } 162 162 163 - static int cpt_set_ucode_base(struct otx2_cpt_eng_grp_info *eng_grp, void *obj) 163 + static int cptx_set_ucode_base(struct otx2_cpt_eng_grp_info *eng_grp, 164 + struct otx2_cptpf_dev *cptpf, int blkaddr) 164 165 { 165 - struct otx2_cptpf_dev *cptpf = obj; 166 166 struct otx2_cpt_engs_rsvd *engs; 167 167 dma_addr_t dma_addr; 168 168 int i, bit, ret; ··· 170 170 /* Set PF number for microcode fetches */ 171 171 ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 172 172 CPT_AF_PF_FUNC, 173 - cptpf->pf_id << RVU_PFVF_PF_SHIFT); 173 + cptpf->pf_id << RVU_PFVF_PF_SHIFT, blkaddr); 174 174 if (ret) 175 175 return ret; 176 176 ··· 187 187 */ 188 188 for_each_set_bit(bit, engs->bmap, eng_grp->g->engs_num) 189 189 if (!eng_grp->g->eng_ref_cnt[bit]) { 190 - ret = __write_ucode_base(cptpf, bit, dma_addr); 190 + ret = __write_ucode_base(cptpf, bit, dma_addr, 191 + blkaddr); 191 192 if (ret) 192 193 return ret; 193 194 } ··· 196 195 return 0; 197 196 } 198 197 199 - static int cpt_detach_and_disable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 200 - void *obj) 198 + static int cpt_set_ucode_base(struct otx2_cpt_eng_grp_info *eng_grp, void *obj) 201 199 { 202 200 struct otx2_cptpf_dev *cptpf = obj; 203 - struct otx2_cpt_bitmap bmap; 201 + int ret; 202 + 203 + if (cptpf->has_cpt1) { 204 + ret = cptx_set_ucode_base(eng_grp, cptpf, BLKADDR_CPT1); 205 + if (ret) 206 + return ret; 207 + } 208 + return cptx_set_ucode_base(eng_grp, cptpf, BLKADDR_CPT0); 209 + } 210 + 211 + static int cptx_detach_and_disable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 212 + struct otx2_cptpf_dev *cptpf, 213 + struct otx2_cpt_bitmap bmap, 214 + int blkaddr) 215 + { 204 216 int i, timeout = 10; 205 217 int busy, ret; 206 218 u64 reg = 0; 207 219 208 - bmap = get_cores_bmap(&cptpf->pdev->dev, eng_grp); 209 - if (!bmap.size) 210 - return -EINVAL; 211 - 212 220 /* Detach the cores from group */ 213 221 for_each_set_bit(i, bmap.bits, bmap.size) { 214 222 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 215 - CPT_AF_EXEX_CTL2(i), &reg); 223 + CPT_AF_EXEX_CTL2(i), &reg, blkaddr); 216 224 if (ret) 217 225 return ret; 218 226 ··· 231 221 232 222 ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, 233 223 cptpf->pdev, 234 - CPT_AF_EXEX_CTL2(i), reg); 224 + CPT_AF_EXEX_CTL2(i), reg, 225 + blkaddr); 235 226 if (ret) 236 227 return ret; 237 228 } ··· 248 237 for_each_set_bit(i, bmap.bits, bmap.size) { 249 238 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, 250 239 cptpf->pdev, 251 - CPT_AF_EXEX_STS(i), &reg); 240 + CPT_AF_EXEX_STS(i), &reg, 241 + blkaddr); 252 242 if (ret) 253 243 return ret; 254 244 ··· 265 253 if (!eng_grp->g->eng_ref_cnt[i]) { 266 254 ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, 267 255 cptpf->pdev, 268 - CPT_AF_EXEX_CTL(i), 0x0); 256 + CPT_AF_EXEX_CTL(i), 0x0, 257 + blkaddr); 269 258 if (ret) 270 259 return ret; 271 260 } ··· 275 262 return 0; 276 263 } 277 264 278 - static int cpt_attach_and_enable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 279 - void *obj) 265 + static int cpt_detach_and_disable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 266 + void *obj) 280 267 { 281 268 struct otx2_cptpf_dev *cptpf = obj; 282 269 struct otx2_cpt_bitmap bmap; 283 - u64 reg = 0; 284 - int i, ret; 270 + int ret; 285 271 286 272 bmap = get_cores_bmap(&cptpf->pdev->dev, eng_grp); 287 273 if (!bmap.size) 288 274 return -EINVAL; 289 275 276 + if (cptpf->has_cpt1) { 277 + ret = cptx_detach_and_disable_cores(eng_grp, cptpf, bmap, 278 + BLKADDR_CPT1); 279 + if (ret) 280 + return ret; 281 + } 282 + return cptx_detach_and_disable_cores(eng_grp, cptpf, bmap, 283 + BLKADDR_CPT0); 284 + } 285 + 286 + static int cptx_attach_and_enable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 287 + struct otx2_cptpf_dev *cptpf, 288 + struct otx2_cpt_bitmap bmap, 289 + int blkaddr) 290 + { 291 + u64 reg = 0; 292 + int i, ret; 293 + 290 294 /* Attach the cores to the group */ 291 295 for_each_set_bit(i, bmap.bits, bmap.size) { 292 296 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 293 - CPT_AF_EXEX_CTL2(i), &reg); 297 + CPT_AF_EXEX_CTL2(i), &reg, blkaddr); 294 298 if (ret) 295 299 return ret; 296 300 ··· 317 287 318 288 ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, 319 289 cptpf->pdev, 320 - CPT_AF_EXEX_CTL2(i), reg); 290 + CPT_AF_EXEX_CTL2(i), reg, 291 + blkaddr); 321 292 if (ret) 322 293 return ret; 323 294 } ··· 326 295 327 296 /* Enable the cores */ 328 297 for_each_set_bit(i, bmap.bits, bmap.size) { 329 - ret = otx2_cpt_add_write_af_reg(&cptpf->afpf_mbox, 330 - cptpf->pdev, 331 - CPT_AF_EXEX_CTL(i), 0x1); 298 + ret = otx2_cpt_add_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 299 + CPT_AF_EXEX_CTL(i), 0x1, 300 + blkaddr); 332 301 if (ret) 333 302 return ret; 334 303 } 335 - ret = otx2_cpt_send_af_reg_requests(&cptpf->afpf_mbox, cptpf->pdev); 304 + return otx2_cpt_send_af_reg_requests(&cptpf->afpf_mbox, cptpf->pdev); 305 + } 336 306 337 - return ret; 307 + static int cpt_attach_and_enable_cores(struct otx2_cpt_eng_grp_info *eng_grp, 308 + void *obj) 309 + { 310 + struct otx2_cptpf_dev *cptpf = obj; 311 + struct otx2_cpt_bitmap bmap; 312 + int ret; 313 + 314 + bmap = get_cores_bmap(&cptpf->pdev->dev, eng_grp); 315 + if (!bmap.size) 316 + return -EINVAL; 317 + 318 + if (cptpf->has_cpt1) { 319 + ret = cptx_attach_and_enable_cores(eng_grp, cptpf, bmap, 320 + BLKADDR_CPT1); 321 + if (ret) 322 + return ret; 323 + } 324 + return cptx_attach_and_enable_cores(eng_grp, cptpf, bmap, BLKADDR_CPT0); 338 325 } 339 326 340 327 static int load_fw(struct device *dev, struct fw_info_t *fw_info, ··· 1189 1140 return ret; 1190 1141 } 1191 1142 1192 - int otx2_cpt_disable_all_cores(struct otx2_cptpf_dev *cptpf) 1143 + static int cptx_disable_all_cores(struct otx2_cptpf_dev *cptpf, int total_cores, 1144 + int blkaddr) 1193 1145 { 1194 - int i, ret, busy, total_cores; 1195 - int timeout = 10; 1196 - u64 reg = 0; 1197 - 1198 - total_cores = cptpf->eng_grps.avail.max_se_cnt + 1199 - cptpf->eng_grps.avail.max_ie_cnt + 1200 - cptpf->eng_grps.avail.max_ae_cnt; 1146 + int timeout = 10, ret; 1147 + int i, busy; 1148 + u64 reg; 1201 1149 1202 1150 /* Disengage the cores from groups */ 1203 1151 for (i = 0; i < total_cores; i++) { 1204 1152 ret = otx2_cpt_add_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 1205 - CPT_AF_EXEX_CTL2(i), 0x0); 1153 + CPT_AF_EXEX_CTL2(i), 0x0, 1154 + blkaddr); 1206 1155 if (ret) 1207 1156 return ret; 1208 1157 ··· 1220 1173 for (i = 0; i < total_cores; i++) { 1221 1174 ret = otx2_cpt_read_af_reg(&cptpf->afpf_mbox, 1222 1175 cptpf->pdev, 1223 - CPT_AF_EXEX_STS(i), &reg); 1176 + CPT_AF_EXEX_STS(i), &reg, 1177 + blkaddr); 1224 1178 if (ret) 1225 1179 return ret; 1226 1180 ··· 1235 1187 /* Disable the cores */ 1236 1188 for (i = 0; i < total_cores; i++) { 1237 1189 ret = otx2_cpt_add_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev, 1238 - CPT_AF_EXEX_CTL(i), 0x0); 1190 + CPT_AF_EXEX_CTL(i), 0x0, 1191 + blkaddr); 1239 1192 if (ret) 1240 1193 return ret; 1241 1194 } 1242 1195 return otx2_cpt_send_af_reg_requests(&cptpf->afpf_mbox, cptpf->pdev); 1196 + } 1197 + 1198 + int otx2_cpt_disable_all_cores(struct otx2_cptpf_dev *cptpf) 1199 + { 1200 + int total_cores, ret; 1201 + 1202 + total_cores = cptpf->eng_grps.avail.max_se_cnt + 1203 + cptpf->eng_grps.avail.max_ie_cnt + 1204 + cptpf->eng_grps.avail.max_ae_cnt; 1205 + 1206 + if (cptpf->has_cpt1) { 1207 + ret = cptx_disable_all_cores(cptpf, total_cores, BLKADDR_CPT1); 1208 + if (ret) 1209 + return ret; 1210 + } 1211 + return cptx_disable_all_cores(cptpf, total_cores, BLKADDR_CPT0); 1243 1212 } 1244 1213 1245 1214 void otx2_cpt_cleanup_eng_grps(struct pci_dev *pdev, ··· 1419 1354 lfs->pdev = pdev; 1420 1355 lfs->reg_base = cptpf->reg_base; 1421 1356 lfs->mbox = &cptpf->afpf_mbox; 1357 + lfs->blkaddr = BLKADDR_CPT0; 1422 1358 ret = otx2_cptlf_init(&cptpf->lfs, OTX2_CPT_ALL_ENG_GRPS_MASK, 1423 1359 OTX2_CPT_QUEUE_HI_PRIO, 1); 1424 1360 if (ret)
+1 -1
drivers/crypto/nx/nx-aes-cbc.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES CBC routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-aes-ccm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES CCM routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-aes-ctr.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES CTR routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-aes-ecb.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES ECB routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-aes-gcm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES GCM routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-aes-xcbc.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES XCBC routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+3 -1
drivers/crypto/nx/nx-common-powernv.c
··· 932 932 ret = find_nx_device_tree(dn, chip_id, vasid, 933 933 NX_CT_GZIP, "ibm,p9-nx-gzip", &ct_gzip); 934 934 935 - if (ret) 935 + if (ret) { 936 + of_node_put(dn); 936 937 return ret; 938 + } 937 939 } 938 940 939 941 if (!ct_842 || !ct_gzip) {
+1 -1
drivers/crypto/nx/nx-sha256.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * SHA-256 routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+1 -1
drivers/crypto/nx/nx-sha512.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * SHA-512 routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+3 -2
drivers/crypto/nx/nx.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * Routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc. ··· 200 200 * @sg: sg list head 201 201 * @end: sg lisg end 202 202 * @delta: is the amount we need to crop in order to bound the list. 203 - * 203 + * @nbytes: length of data in the scatterlists or data length - whichever 204 + * is greater. 204 205 */ 205 206 static long int trim_sg_list(struct nx_sg *sg, 206 207 struct nx_sg *end,
+1 -1
drivers/crypto/nx/nx_debugfs.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * debugfs routines supporting the Power 7+ Nest Accelerators driver 4 4 * 5 5 * Copyright (C) 2011-2012 International Business Machines Inc.
+3 -4
drivers/crypto/omap-aes.c
··· 103 103 dd->err = 0; 104 104 } 105 105 106 - err = pm_runtime_get_sync(dd->dev); 106 + err = pm_runtime_resume_and_get(dd->dev); 107 107 if (err < 0) { 108 - pm_runtime_put_noidle(dd->dev); 109 108 dev_err(dd->dev, "failed to get sync: %d\n", err); 110 109 return err; 111 110 } ··· 1133 1134 pm_runtime_set_autosuspend_delay(dev, DEFAULT_AUTOSUSPEND_DELAY); 1134 1135 1135 1136 pm_runtime_enable(dev); 1136 - err = pm_runtime_get_sync(dev); 1137 + err = pm_runtime_resume_and_get(dev); 1137 1138 if (err < 0) { 1138 1139 dev_err(dev, "%s: failed to get_sync(%d)\n", 1139 1140 __func__, err); ··· 1302 1303 1303 1304 static int omap_aes_resume(struct device *dev) 1304 1305 { 1305 - pm_runtime_get_sync(dev); 1306 + pm_runtime_resume_and_get(dev); 1306 1307 return 0; 1307 1308 } 1308 1309 #endif
+1
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.c
··· 224 224 hw_data->uof_get_name = uof_get_name; 225 225 hw_data->uof_get_ae_mask = uof_get_ae_mask; 226 226 hw_data->set_msix_rttable = set_msix_default_rttable; 227 + hw_data->set_ssm_wdtimer = adf_gen4_set_ssm_wdtimer; 227 228 228 229 adf_gen4_init_hw_csr_ops(&hw_data->csr_ops); 229 230 }
+1
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.c
··· 212 212 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 213 213 hw_data->reset_device = adf_reset_flr; 214 214 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 215 + hw_data->set_ssm_wdtimer = adf_gen2_set_ssm_wdtimer; 215 216 adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 216 217 } 217 218
+2 -2
drivers/crypto/qat/qat_c3xxxvf/adf_drv.c
··· 184 184 if (ret) 185 185 goto out_err_free_reg; 186 186 187 - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 188 - 189 187 ret = adf_dev_init(accel_dev); 190 188 if (ret) 191 189 goto out_err_dev_shutdown; 190 + 191 + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 192 192 193 193 ret = adf_dev_start(accel_dev); 194 194 if (ret)
+1
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
··· 214 214 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms; 215 215 hw_data->reset_device = adf_reset_flr; 216 216 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION; 217 + hw_data->set_ssm_wdtimer = adf_gen2_set_ssm_wdtimer; 217 218 adf_gen2_init_hw_csr_ops(&hw_data->csr_ops); 218 219 } 219 220
+2 -2
drivers/crypto/qat/qat_c62xvf/adf_drv.c
··· 184 184 if (ret) 185 185 goto out_err_free_reg; 186 186 187 - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 188 - 189 187 ret = adf_dev_init(accel_dev); 190 188 if (ret) 191 189 goto out_err_dev_shutdown; 190 + 191 + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 192 192 193 193 ret = adf_dev_start(accel_dev); 194 194 if (ret)
+1
drivers/crypto/qat/qat_common/adf_accel_devices.h
··· 173 173 void (*configure_iov_threads)(struct adf_accel_dev *accel_dev, 174 174 bool enable); 175 175 void (*enable_ints)(struct adf_accel_dev *accel_dev); 176 + void (*set_ssm_wdtimer)(struct adf_accel_dev *accel_dev); 176 177 int (*enable_vf2pf_comms)(struct adf_accel_dev *accel_dev); 177 178 void (*reset_device)(struct adf_accel_dev *accel_dev); 178 179 void (*set_msix_rttable)(struct adf_accel_dev *accel_dev);
+25
drivers/crypto/qat/qat_common/adf_gen2_hw_data.c
··· 179 179 return capabilities; 180 180 } 181 181 EXPORT_SYMBOL_GPL(adf_gen2_get_accel_cap); 182 + 183 + void adf_gen2_set_ssm_wdtimer(struct adf_accel_dev *accel_dev) 184 + { 185 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 186 + u32 timer_val_pke = ADF_SSM_WDT_PKE_DEFAULT_VALUE; 187 + u32 timer_val = ADF_SSM_WDT_DEFAULT_VALUE; 188 + unsigned long accel_mask = hw_data->accel_mask; 189 + void __iomem *pmisc_addr; 190 + struct adf_bar *pmisc; 191 + int pmisc_id; 192 + u32 i = 0; 193 + 194 + pmisc_id = hw_data->get_misc_bar_id(hw_data); 195 + pmisc = &GET_BARS(accel_dev)[pmisc_id]; 196 + pmisc_addr = pmisc->virt_addr; 197 + 198 + /* Configures WDT timers */ 199 + for_each_set_bit(i, &accel_mask, hw_data->num_accel) { 200 + /* Enable WDT for sym and dc */ 201 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDT(i), timer_val); 202 + /* Enable WDT for pke */ 203 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDTPKE(i), timer_val_pke); 204 + } 205 + } 206 + EXPORT_SYMBOL_GPL(adf_gen2_set_ssm_wdtimer);
+13
drivers/crypto/qat/qat_common/adf_gen2_hw_data.h
··· 113 113 /* Power gating */ 114 114 #define ADF_POWERGATE_PKE BIT(24) 115 115 116 + /* WDT timers 117 + * 118 + * Timeout is in cycles. Clock speed may vary across products but this 119 + * value should be a few milli-seconds. 120 + */ 121 + #define ADF_SSM_WDT_DEFAULT_VALUE 0x200000 122 + #define ADF_SSM_WDT_PKE_DEFAULT_VALUE 0x2000000 123 + #define ADF_SSMWDT_OFFSET 0x54 124 + #define ADF_SSMWDTPKE_OFFSET 0x58 125 + #define ADF_SSMWDT(i) (ADF_SSMWDT_OFFSET + ((i) * 0x4000)) 126 + #define ADF_SSMWDTPKE(i) (ADF_SSMWDTPKE_OFFSET + ((i) * 0x4000)) 127 + 116 128 void adf_gen2_cfg_iov_thds(struct adf_accel_dev *accel_dev, bool enable, 117 129 int num_a_regs, int num_b_regs); 118 130 void adf_gen2_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops); 119 131 void adf_gen2_get_admin_info(struct admin_info *admin_csrs_info); 120 132 void adf_gen2_get_arb_info(struct arb_info *arb_info); 121 133 u32 adf_gen2_get_accel_cap(struct adf_accel_dev *accel_dev); 134 + void adf_gen2_set_ssm_wdtimer(struct adf_accel_dev *accel_dev); 122 135 123 136 #endif
+40
drivers/crypto/qat/qat_common/adf_gen4_hw_data.c
··· 99 99 csr_ops->write_csr_ring_srv_arb_en = write_csr_ring_srv_arb_en; 100 100 } 101 101 EXPORT_SYMBOL_GPL(adf_gen4_init_hw_csr_ops); 102 + 103 + static inline void adf_gen4_unpack_ssm_wdtimer(u64 value, u32 *upper, 104 + u32 *lower) 105 + { 106 + *lower = lower_32_bits(value); 107 + *upper = upper_32_bits(value); 108 + } 109 + 110 + void adf_gen4_set_ssm_wdtimer(struct adf_accel_dev *accel_dev) 111 + { 112 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 113 + u64 timer_val_pke = ADF_SSM_WDT_PKE_DEFAULT_VALUE; 114 + u64 timer_val = ADF_SSM_WDT_DEFAULT_VALUE; 115 + u32 ssm_wdt_pke_high = 0; 116 + u32 ssm_wdt_pke_low = 0; 117 + u32 ssm_wdt_high = 0; 118 + u32 ssm_wdt_low = 0; 119 + void __iomem *pmisc_addr; 120 + struct adf_bar *pmisc; 121 + int pmisc_id; 122 + 123 + pmisc_id = hw_data->get_misc_bar_id(hw_data); 124 + pmisc = &GET_BARS(accel_dev)[pmisc_id]; 125 + pmisc_addr = pmisc->virt_addr; 126 + 127 + /* Convert 64bit WDT timer value into 32bit values for 128 + * mmio write to 32bit CSRs. 129 + */ 130 + adf_gen4_unpack_ssm_wdtimer(timer_val, &ssm_wdt_high, &ssm_wdt_low); 131 + adf_gen4_unpack_ssm_wdtimer(timer_val_pke, &ssm_wdt_pke_high, 132 + &ssm_wdt_pke_low); 133 + 134 + /* Enable WDT for sym and dc */ 135 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDTL_OFFSET, ssm_wdt_low); 136 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDTH_OFFSET, ssm_wdt_high); 137 + /* Enable WDT for pke */ 138 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDTPKEL_OFFSET, ssm_wdt_pke_low); 139 + ADF_CSR_WR(pmisc_addr, ADF_SSMWDTPKEH_OFFSET, ssm_wdt_pke_high); 140 + } 141 + EXPORT_SYMBOL_GPL(adf_gen4_set_ssm_wdtimer);
+13 -1
drivers/crypto/qat/qat_common/adf_gen4_hw_data.h
··· 94 94 ADF_RING_BUNDLE_SIZE * (bank) + \ 95 95 ADF_RING_CSR_RING_SRV_ARB_EN, (value)) 96 96 97 - void adf_gen4_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops); 97 + /* WDT timers 98 + * 99 + * Timeout is in cycles. Clock speed may vary across products but this 100 + * value should be a few milli-seconds. 101 + */ 102 + #define ADF_SSM_WDT_DEFAULT_VALUE 0x200000 103 + #define ADF_SSM_WDT_PKE_DEFAULT_VALUE 0x8000000 104 + #define ADF_SSMWDTL_OFFSET 0x54 105 + #define ADF_SSMWDTH_OFFSET 0x5C 106 + #define ADF_SSMWDTPKEL_OFFSET 0x58 107 + #define ADF_SSMWDTPKEH_OFFSET 0x60 98 108 109 + void adf_gen4_set_ssm_wdtimer(struct adf_accel_dev *accel_dev); 110 + void adf_gen4_init_hw_csr_ops(struct adf_hw_csr_ops *csr_ops); 99 111 #endif
+4
drivers/crypto/qat/qat_common/adf_init.c
··· 162 162 return -EFAULT; 163 163 } 164 164 165 + /* Set ssm watch dog timer */ 166 + if (hw_data->set_ssm_wdtimer) 167 + hw_data->set_ssm_wdtimer(accel_dev); 168 + 165 169 list_for_each(list_itr, &service_table) { 166 170 service = list_entry(list_itr, struct service_hndl, list); 167 171 if (service->event_hld(accel_dev, ADF_EVENT_START)) {
+21 -8
drivers/crypto/qat/qat_common/adf_isr.c
··· 291 291 292 292 ret = adf_isr_alloc_msix_entry_table(accel_dev); 293 293 if (ret) 294 - return ret; 295 - if (adf_enable_msix(accel_dev)) 296 294 goto err_out; 297 295 298 - if (adf_setup_bh(accel_dev)) 299 - goto err_out; 296 + ret = adf_enable_msix(accel_dev); 297 + if (ret) 298 + goto err_free_msix_table; 300 299 301 - if (adf_request_irqs(accel_dev)) 302 - goto err_out; 300 + ret = adf_setup_bh(accel_dev); 301 + if (ret) 302 + goto err_disable_msix; 303 + 304 + ret = adf_request_irqs(accel_dev); 305 + if (ret) 306 + goto err_cleanup_bh; 303 307 304 308 return 0; 309 + 310 + err_cleanup_bh: 311 + adf_cleanup_bh(accel_dev); 312 + 313 + err_disable_msix: 314 + adf_disable_msix(&accel_dev->accel_pci_dev); 315 + 316 + err_free_msix_table: 317 + adf_isr_free_msix_entry_table(accel_dev); 318 + 305 319 err_out: 306 - adf_isr_resource_free(accel_dev); 307 - return -EFAULT; 320 + return ret; 308 321 } 309 322 EXPORT_SYMBOL_GPL(adf_isr_resource_alloc);
+1 -1
drivers/crypto/qat/qat_common/adf_pf2vf_msg.c
··· 169 169 * @msg: Message to send 170 170 * @vf_nr: VF number to which the message will be sent 171 171 * 172 - * Function sends a messge from the PF to a VF 172 + * Function sends a message from the PF to a VF 173 173 * 174 174 * Return: 0 on success, error code otherwise. 175 175 */
+1
drivers/crypto/qat/qat_common/adf_transport.c
··· 172 172 dev_err(&GET_DEV(accel_dev), "Ring address not aligned\n"); 173 173 dma_free_coherent(&GET_DEV(accel_dev), ring_size_bytes, 174 174 ring->base_addr, ring->dma_addr); 175 + ring->base_addr = NULL; 175 176 return -EFAULT; 176 177 } 177 178
+2 -2
drivers/crypto/qat/qat_common/adf_vf2pf_msg.c
··· 8 8 * adf_vf2pf_init() - send init msg to PF 9 9 * @accel_dev: Pointer to acceleration VF device. 10 10 * 11 - * Function sends an init messge from the VF to a PF 11 + * Function sends an init message from the VF to a PF 12 12 * 13 13 * Return: 0 on success, error code otherwise. 14 14 */ ··· 31 31 * adf_vf2pf_shutdown() - send shutdown msg to PF 32 32 * @accel_dev: Pointer to acceleration VF device. 33 33 * 34 - * Function sends a shutdown messge from the VF to a PF 34 + * Function sends a shutdown message from the VF to a PF 35 35 * 36 36 * Return: void 37 37 */
+13 -4
drivers/crypto/qat/qat_common/adf_vf_isr.c
··· 261 261 goto err_out; 262 262 263 263 if (adf_setup_pf2vf_bh(accel_dev)) 264 - goto err_out; 264 + goto err_disable_msi; 265 265 266 266 if (adf_setup_bh(accel_dev)) 267 - goto err_out; 267 + goto err_cleanup_pf2vf_bh; 268 268 269 269 if (adf_request_msi_irq(accel_dev)) 270 - goto err_out; 270 + goto err_cleanup_bh; 271 271 272 272 return 0; 273 + 274 + err_cleanup_bh: 275 + adf_cleanup_bh(accel_dev); 276 + 277 + err_cleanup_pf2vf_bh: 278 + adf_cleanup_pf2vf_bh(accel_dev); 279 + 280 + err_disable_msi: 281 + adf_disable_msi(accel_dev); 282 + 273 283 err_out: 274 - adf_vf_isr_resource_free(accel_dev); 275 284 return -EFAULT; 276 285 } 277 286 EXPORT_SYMBOL_GPL(adf_vf_isr_resource_alloc);
+20 -12
drivers/crypto/qat/qat_common/qat_algs.c
··· 718 718 int n = sg_nents(sgl); 719 719 struct qat_alg_buf_list *bufl; 720 720 struct qat_alg_buf_list *buflout = NULL; 721 - dma_addr_t blp; 722 - dma_addr_t bloutp = 0; 721 + dma_addr_t blp = DMA_MAPPING_ERROR; 722 + dma_addr_t bloutp = DMA_MAPPING_ERROR; 723 723 struct scatterlist *sg; 724 724 size_t sz_out, sz = struct_size(bufl, bufers, n + 1); 725 725 ··· 731 731 if (unlikely(!bufl)) 732 732 return -ENOMEM; 733 733 734 - blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); 735 - if (unlikely(dma_mapping_error(dev, blp))) 736 - goto err_in; 734 + for_each_sg(sgl, sg, n, i) 735 + bufl->bufers[i].addr = DMA_MAPPING_ERROR; 737 736 738 737 for_each_sg(sgl, sg, n, i) { 739 738 int y = sg_nctr; ··· 749 750 sg_nctr++; 750 751 } 751 752 bufl->num_bufs = sg_nctr; 753 + blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); 754 + if (unlikely(dma_mapping_error(dev, blp))) 755 + goto err_in; 752 756 qat_req->buf.bl = bufl; 753 757 qat_req->buf.blp = blp; 754 758 qat_req->buf.sz = sz; ··· 766 764 dev_to_node(&GET_DEV(inst->accel_dev))); 767 765 if (unlikely(!buflout)) 768 766 goto err_in; 769 - bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); 770 - if (unlikely(dma_mapping_error(dev, bloutp))) 771 - goto err_out; 767 + 772 768 bufers = buflout->bufers; 769 + for_each_sg(sglout, sg, n, i) 770 + bufers[i].addr = DMA_MAPPING_ERROR; 771 + 773 772 for_each_sg(sglout, sg, n, i) { 774 773 int y = sg_nctr; 775 774 ··· 787 784 } 788 785 buflout->num_bufs = sg_nctr; 789 786 buflout->num_mapped_bufs = sg_nctr; 787 + bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); 788 + if (unlikely(dma_mapping_error(dev, bloutp))) 789 + goto err_out; 790 790 qat_req->buf.blout = buflout; 791 791 qat_req->buf.bloutp = bloutp; 792 792 qat_req->buf.sz_out = sz_out; ··· 801 795 return 0; 802 796 803 797 err_out: 798 + if (!dma_mapping_error(dev, bloutp)) 799 + dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); 800 + 804 801 n = sg_nents(sglout); 805 802 for (i = 0; i < n; i++) 806 803 if (!dma_mapping_error(dev, buflout->bufers[i].addr)) 807 804 dma_unmap_single(dev, buflout->bufers[i].addr, 808 805 buflout->bufers[i].len, 809 806 DMA_BIDIRECTIONAL); 810 - if (!dma_mapping_error(dev, bloutp)) 811 - dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); 812 807 kfree(buflout); 813 808 814 809 err_in: 810 + if (!dma_mapping_error(dev, blp)) 811 + dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); 812 + 815 813 n = sg_nents(sgl); 816 814 for (i = 0; i < n; i++) 817 815 if (!dma_mapping_error(dev, bufl->bufers[i].addr)) ··· 823 813 bufl->bufers[i].len, 824 814 DMA_BIDIRECTIONAL); 825 815 826 - if (!dma_mapping_error(dev, blp)) 827 - dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); 828 816 kfree(bufl); 829 817 830 818 dev_err(dev, "Failed to map buf for dma\n");
+2 -2
drivers/crypto/qat/qat_dh895xccvf/adf_drv.c
··· 184 184 if (ret) 185 185 goto out_err_free_reg; 186 186 187 - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 188 - 189 187 ret = adf_dev_init(accel_dev); 190 188 if (ret) 191 189 goto out_err_dev_shutdown; 190 + 191 + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); 192 192 193 193 ret = adf_dev_start(accel_dev); 194 194 if (ret)
-1
drivers/crypto/qce/cipher.h
··· 40 40 struct scatterlist result_sg; 41 41 struct sg_table dst_tbl; 42 42 struct scatterlist *dst_sg; 43 - struct sg_table src_tbl; 44 43 struct scatterlist *src_sg; 45 44 unsigned int cryptlen; 46 45 struct skcipher_request fallback_req; // keep at the end
+11 -14
drivers/crypto/qce/common.c
··· 140 140 return cfg; 141 141 } 142 142 143 - static int qce_setup_regs_ahash(struct crypto_async_request *async_req, 144 - u32 totallen, u32 offset) 143 + static int qce_setup_regs_ahash(struct crypto_async_request *async_req) 145 144 { 146 145 struct ahash_request *req = ahash_request_cast(async_req); 147 146 struct crypto_ahash *ahash = __crypto_ahash_cast(async_req->tfm); ··· 294 295 { 295 296 u32 xtskey[QCE_MAX_CIPHER_KEY_SIZE / sizeof(u32)] = {0}; 296 297 unsigned int xtsklen = enckeylen / (2 * sizeof(u32)); 297 - unsigned int xtsdusize; 298 298 299 299 qce_cpu_to_be32p_array((__be32 *)xtskey, enckey + enckeylen / 2, 300 300 enckeylen / 2); 301 301 qce_write_array(qce, REG_ENCR_XTS_KEY0, xtskey, xtsklen); 302 302 303 - /* xts du size 512B */ 304 - xtsdusize = min_t(u32, QCE_SECTOR_SIZE, cryptlen); 305 - qce_write(qce, REG_ENCR_XTS_DU_SIZE, xtsdusize); 303 + /* Set data unit size to cryptlen. Anything else causes 304 + * crypto engine to return back incorrect results. 305 + */ 306 + qce_write(qce, REG_ENCR_XTS_DU_SIZE, cryptlen); 306 307 } 307 308 308 - static int qce_setup_regs_skcipher(struct crypto_async_request *async_req, 309 - u32 totallen, u32 offset) 309 + static int qce_setup_regs_skcipher(struct crypto_async_request *async_req) 310 310 { 311 311 struct skcipher_request *req = skcipher_request_cast(async_req); 312 312 struct qce_cipher_reqctx *rctx = skcipher_request_ctx(req); ··· 365 367 366 368 qce_write(qce, REG_ENCR_SEG_CFG, encr_cfg); 367 369 qce_write(qce, REG_ENCR_SEG_SIZE, rctx->cryptlen); 368 - qce_write(qce, REG_ENCR_SEG_START, offset & 0xffff); 370 + qce_write(qce, REG_ENCR_SEG_START, 0); 369 371 370 372 if (IS_CTR(flags)) { 371 373 qce_write(qce, REG_CNTR_MASK, ~0); ··· 374 376 qce_write(qce, REG_CNTR_MASK2, ~0); 375 377 } 376 378 377 - qce_write(qce, REG_SEG_SIZE, totallen); 379 + qce_write(qce, REG_SEG_SIZE, rctx->cryptlen); 378 380 379 381 /* get little endianness */ 380 382 config = qce_config_reg(qce, 1); ··· 386 388 } 387 389 #endif 388 390 389 - int qce_start(struct crypto_async_request *async_req, u32 type, u32 totallen, 390 - u32 offset) 391 + int qce_start(struct crypto_async_request *async_req, u32 type) 391 392 { 392 393 switch (type) { 393 394 #ifdef CONFIG_CRYPTO_DEV_QCE_SKCIPHER 394 395 case CRYPTO_ALG_TYPE_SKCIPHER: 395 - return qce_setup_regs_skcipher(async_req, totallen, offset); 396 + return qce_setup_regs_skcipher(async_req); 396 397 #endif 397 398 #ifdef CONFIG_CRYPTO_DEV_QCE_SHA 398 399 case CRYPTO_ALG_TYPE_AHASH: 399 - return qce_setup_regs_ahash(async_req, totallen, offset); 400 + return qce_setup_regs_ahash(async_req); 400 401 #endif 401 402 default: 402 403 return -EINVAL;
+1 -2
drivers/crypto/qce/common.h
··· 94 94 void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len); 95 95 int qce_check_status(struct qce_device *qce, u32 *status); 96 96 void qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step); 97 - int qce_start(struct crypto_async_request *async_req, u32 type, u32 totallen, 98 - u32 offset); 97 + int qce_start(struct crypto_async_request *async_req, u32 type); 99 98 100 99 #endif /* _COMMON_H_ */
+54 -89
drivers/crypto/qce/sha.c
··· 12 12 #include "core.h" 13 13 #include "sha.h" 14 14 15 - /* crypto hw padding constant for first operation */ 16 - #define SHA_PADDING 64 17 - #define SHA_PADDING_MASK (SHA_PADDING - 1) 15 + struct qce_sha_saved_state { 16 + u8 pending_buf[QCE_SHA_MAX_BLOCKSIZE]; 17 + u8 partial_digest[QCE_SHA_MAX_DIGESTSIZE]; 18 + __be32 byte_count[2]; 19 + unsigned int pending_buflen; 20 + unsigned int flags; 21 + u64 count; 22 + bool first_blk; 23 + }; 18 24 19 25 static LIST_HEAD(ahash_algs); 20 26 ··· 113 107 114 108 qce_dma_issue_pending(&qce->dma); 115 109 116 - ret = qce_start(async_req, tmpl->crypto_alg_type, 0, 0); 110 + ret = qce_start(async_req, tmpl->crypto_alg_type); 117 111 if (ret) 118 112 goto error_terminate; 119 113 ··· 145 139 146 140 static int qce_ahash_export(struct ahash_request *req, void *out) 147 141 { 148 - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); 149 142 struct qce_sha_reqctx *rctx = ahash_request_ctx(req); 150 - unsigned long flags = rctx->flags; 151 - unsigned int digestsize = crypto_ahash_digestsize(ahash); 152 - unsigned int blocksize = 153 - crypto_tfm_alg_blocksize(crypto_ahash_tfm(ahash)); 143 + struct qce_sha_saved_state *export_state = out; 154 144 155 - if (IS_SHA1(flags) || IS_SHA1_HMAC(flags)) { 156 - struct sha1_state *out_state = out; 157 - 158 - out_state->count = rctx->count; 159 - qce_cpu_to_be32p_array((__be32 *)out_state->state, 160 - rctx->digest, digestsize); 161 - memcpy(out_state->buffer, rctx->buf, blocksize); 162 - } else if (IS_SHA256(flags) || IS_SHA256_HMAC(flags)) { 163 - struct sha256_state *out_state = out; 164 - 165 - out_state->count = rctx->count; 166 - qce_cpu_to_be32p_array((__be32 *)out_state->state, 167 - rctx->digest, digestsize); 168 - memcpy(out_state->buf, rctx->buf, blocksize); 169 - } else { 170 - return -EINVAL; 171 - } 172 - 173 - return 0; 174 - } 175 - 176 - static int qce_import_common(struct ahash_request *req, u64 in_count, 177 - const u32 *state, const u8 *buffer, bool hmac) 178 - { 179 - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); 180 - struct qce_sha_reqctx *rctx = ahash_request_ctx(req); 181 - unsigned int digestsize = crypto_ahash_digestsize(ahash); 182 - unsigned int blocksize; 183 - u64 count = in_count; 184 - 185 - blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(ahash)); 186 - rctx->count = in_count; 187 - memcpy(rctx->buf, buffer, blocksize); 188 - 189 - if (in_count <= blocksize) { 190 - rctx->first_blk = 1; 191 - } else { 192 - rctx->first_blk = 0; 193 - /* 194 - * For HMAC, there is a hardware padding done when first block 195 - * is set. Therefore the byte_count must be incremened by 64 196 - * after the first block operation. 197 - */ 198 - if (hmac) 199 - count += SHA_PADDING; 200 - } 201 - 202 - rctx->byte_count[0] = (__force __be32)(count & ~SHA_PADDING_MASK); 203 - rctx->byte_count[1] = (__force __be32)(count >> 32); 204 - qce_cpu_to_be32p_array((__be32 *)rctx->digest, (const u8 *)state, 205 - digestsize); 206 - rctx->buflen = (unsigned int)(in_count & (blocksize - 1)); 145 + memcpy(export_state->pending_buf, rctx->buf, rctx->buflen); 146 + memcpy(export_state->partial_digest, rctx->digest, sizeof(rctx->digest)); 147 + export_state->byte_count[0] = rctx->byte_count[0]; 148 + export_state->byte_count[1] = rctx->byte_count[1]; 149 + export_state->pending_buflen = rctx->buflen; 150 + export_state->count = rctx->count; 151 + export_state->first_blk = rctx->first_blk; 152 + export_state->flags = rctx->flags; 207 153 208 154 return 0; 209 155 } 210 156 211 157 static int qce_ahash_import(struct ahash_request *req, const void *in) 212 158 { 213 - struct qce_sha_reqctx *rctx; 214 - unsigned long flags; 215 - bool hmac; 216 - int ret; 159 + struct qce_sha_reqctx *rctx = ahash_request_ctx(req); 160 + const struct qce_sha_saved_state *import_state = in; 217 161 218 - ret = qce_ahash_init(req); 219 - if (ret) 220 - return ret; 162 + memset(rctx, 0, sizeof(*rctx)); 163 + rctx->count = import_state->count; 164 + rctx->buflen = import_state->pending_buflen; 165 + rctx->first_blk = import_state->first_blk; 166 + rctx->flags = import_state->flags; 167 + rctx->byte_count[0] = import_state->byte_count[0]; 168 + rctx->byte_count[1] = import_state->byte_count[1]; 169 + memcpy(rctx->buf, import_state->pending_buf, rctx->buflen); 170 + memcpy(rctx->digest, import_state->partial_digest, sizeof(rctx->digest)); 221 171 222 - rctx = ahash_request_ctx(req); 223 - flags = rctx->flags; 224 - hmac = IS_SHA_HMAC(flags); 225 - 226 - if (IS_SHA1(flags) || IS_SHA1_HMAC(flags)) { 227 - const struct sha1_state *state = in; 228 - 229 - ret = qce_import_common(req, state->count, state->state, 230 - state->buffer, hmac); 231 - } else if (IS_SHA256(flags) || IS_SHA256_HMAC(flags)) { 232 - const struct sha256_state *state = in; 233 - 234 - ret = qce_import_common(req, state->count, state->state, 235 - state->buf, hmac); 236 - } 237 - 238 - return ret; 172 + return 0; 239 173 } 240 174 241 175 static int qce_ahash_update(struct ahash_request *req) ··· 216 270 217 271 /* calculate how many bytes will be hashed later */ 218 272 hash_later = total % blocksize; 273 + 274 + /* 275 + * At this point, there is more than one block size of data. If 276 + * the available data to transfer is exactly a multiple of block 277 + * size, save the last block to be transferred in qce_ahash_final 278 + * (with the last block bit set) if this is indeed the end of data 279 + * stream. If not this saved block will be transferred as part of 280 + * next update. If this block is not held back and if this is 281 + * indeed the end of data stream, the digest obtained will be wrong 282 + * since qce_ahash_final will see that rctx->buflen is 0 and return 283 + * doing nothing which in turn means that a digest will not be 284 + * copied to the destination result buffer. qce_ahash_final cannot 285 + * be made to alter this behavior and allowed to proceed if 286 + * rctx->buflen is 0 because the crypto engine BAM does not allow 287 + * for zero length transfers. 288 + */ 289 + if (!hash_later) 290 + hash_later = blocksize; 291 + 219 292 if (hash_later) { 220 293 unsigned int src_offset = req->nbytes - hash_later; 221 294 scatterwalk_map_and_copy(rctx->buf, req->src, src_offset, ··· 415 450 .drv_name = "sha1-qce", 416 451 .digestsize = SHA1_DIGEST_SIZE, 417 452 .blocksize = SHA1_BLOCK_SIZE, 418 - .statesize = sizeof(struct sha1_state), 453 + .statesize = sizeof(struct qce_sha_saved_state), 419 454 .std_iv = std_iv_sha1, 420 455 }, 421 456 { ··· 424 459 .drv_name = "sha256-qce", 425 460 .digestsize = SHA256_DIGEST_SIZE, 426 461 .blocksize = SHA256_BLOCK_SIZE, 427 - .statesize = sizeof(struct sha256_state), 462 + .statesize = sizeof(struct qce_sha_saved_state), 428 463 .std_iv = std_iv_sha256, 429 464 }, 430 465 { ··· 433 468 .drv_name = "hmac-sha1-qce", 434 469 .digestsize = SHA1_DIGEST_SIZE, 435 470 .blocksize = SHA1_BLOCK_SIZE, 436 - .statesize = sizeof(struct sha1_state), 471 + .statesize = sizeof(struct qce_sha_saved_state), 437 472 .std_iv = std_iv_sha1, 438 473 }, 439 474 { ··· 442 477 .drv_name = "hmac-sha256-qce", 443 478 .digestsize = SHA256_DIGEST_SIZE, 444 479 .blocksize = SHA256_BLOCK_SIZE, 445 - .statesize = sizeof(struct sha256_state), 480 + .statesize = sizeof(struct qce_sha_saved_state), 446 481 .std_iv = std_iv_sha256, 447 482 }, 448 483 };
+60 -9
drivers/crypto/qce/skcipher.c
··· 8 8 #include <linux/interrupt.h> 9 9 #include <linux/moduleparam.h> 10 10 #include <linux/types.h> 11 + #include <linux/errno.h> 11 12 #include <crypto/aes.h> 12 13 #include <crypto/internal/des.h> 13 14 #include <crypto/internal/skcipher.h> ··· 144 143 145 144 qce_dma_issue_pending(&qce->dma); 146 145 147 - ret = qce_start(async_req, tmpl->crypto_alg_type, req->cryptlen, 0); 146 + ret = qce_start(async_req, tmpl->crypto_alg_type); 148 147 if (ret) 149 148 goto error_terminate; 150 149 ··· 168 167 struct crypto_tfm *tfm = crypto_skcipher_tfm(ablk); 169 168 struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 170 169 unsigned long flags = to_cipher_tmpl(ablk)->alg_flags; 170 + unsigned int __keylen; 171 171 int ret; 172 172 173 173 if (!key || !keylen) 174 174 return -EINVAL; 175 175 176 - switch (IS_XTS(flags) ? keylen >> 1 : keylen) { 176 + /* 177 + * AES XTS key1 = key2 not supported by crypto engine. 178 + * Revisit to request a fallback cipher in this case. 179 + */ 180 + if (IS_XTS(flags)) { 181 + __keylen = keylen >> 1; 182 + if (!memcmp(key, key + __keylen, __keylen)) 183 + return -ENOKEY; 184 + } else { 185 + __keylen = keylen; 186 + } 187 + 188 + switch (__keylen) { 177 189 case AES_KEYSIZE_128: 178 190 case AES_KEYSIZE_256: 179 191 memcpy(ctx->enc_key, key, keylen); 180 192 break; 193 + case AES_KEYSIZE_192: 194 + break; 195 + default: 196 + return -EINVAL; 181 197 } 182 198 183 199 ret = crypto_skcipher_setkey(ctx->fallback, key, keylen); ··· 222 204 unsigned int keylen) 223 205 { 224 206 struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(ablk); 207 + u32 _key[6]; 225 208 int err; 226 209 227 210 err = verify_skcipher_des3_key(ablk, key); 228 211 if (err) 229 212 return err; 213 + 214 + /* 215 + * The crypto engine does not support any two keys 216 + * being the same for triple des algorithms. The 217 + * verify_skcipher_des3_key does not check for all the 218 + * below conditions. Return -ENOKEY in case any two keys 219 + * are the same. Revisit to see if a fallback cipher 220 + * is needed to handle this condition. 221 + */ 222 + memcpy(_key, key, DES3_EDE_KEY_SIZE); 223 + if (!((_key[0] ^ _key[2]) | (_key[1] ^ _key[3])) || 224 + !((_key[2] ^ _key[4]) | (_key[3] ^ _key[5])) || 225 + !((_key[0] ^ _key[4]) | (_key[1] ^ _key[5]))) 226 + return -ENOKEY; 230 227 231 228 ctx->enc_keylen = keylen; 232 229 memcpy(ctx->enc_key, key, keylen); ··· 254 221 struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm); 255 222 struct qce_cipher_reqctx *rctx = skcipher_request_ctx(req); 256 223 struct qce_alg_template *tmpl = to_cipher_tmpl(tfm); 224 + unsigned int blocksize = crypto_skcipher_blocksize(tfm); 257 225 int keylen; 258 226 int ret; 259 227 ··· 262 228 rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT; 263 229 keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen; 264 230 265 - /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and 266 - * is not a multiple of it; pass such requests to the fallback 231 + /* CE does not handle 0 length messages */ 232 + if (!req->cryptlen) 233 + return 0; 234 + 235 + /* 236 + * ECB and CBC algorithms require message lengths to be 237 + * multiples of block size. 238 + */ 239 + if (IS_ECB(rctx->flags) || IS_CBC(rctx->flags)) 240 + if (!IS_ALIGNED(req->cryptlen, blocksize)) 241 + return -EINVAL; 242 + 243 + /* 244 + * Conditions for requesting a fallback cipher 245 + * AES-192 (not supported by crypto engine (CE)) 246 + * AES-XTS request with len <= 512 byte (not recommended to use CE) 247 + * AES-XTS request with len > QCE_SECTOR_SIZE and 248 + * is not a multiple of it.(Revisit this condition to check if it is 249 + * needed in all versions of CE) 267 250 */ 268 251 if (IS_AES(rctx->flags) && 269 - (((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) || 270 - req->cryptlen <= aes_sw_max_len) || 271 - (IS_XTS(rctx->flags) && req->cryptlen > QCE_SECTOR_SIZE && 272 - req->cryptlen % QCE_SECTOR_SIZE))) { 252 + ((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) || 253 + (IS_XTS(rctx->flags) && ((req->cryptlen <= aes_sw_max_len) || 254 + (req->cryptlen > QCE_SECTOR_SIZE && 255 + req->cryptlen % QCE_SECTOR_SIZE))))) { 273 256 skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback); 274 257 skcipher_request_set_callback(&rctx->fallback_req, 275 258 req->base.flags, ··· 358 307 .name = "ecb(aes)", 359 308 .drv_name = "ecb-aes-qce", 360 309 .blocksize = AES_BLOCK_SIZE, 361 - .ivsize = AES_BLOCK_SIZE, 310 + .ivsize = 0, 362 311 .min_keysize = AES_MIN_KEY_SIZE, 363 312 .max_keysize = AES_MAX_KEY_SIZE, 364 313 },
+1 -1
drivers/crypto/rockchip/rk3288_crypto_ahash.c
··· 48 48 { 49 49 struct ahash_request *req = ahash_request_cast(dev->async_req); 50 50 struct rk_ahash_rctx *rctx = ahash_request_ctx(req); 51 - int reg_status = 0; 51 + int reg_status; 52 52 53 53 reg_status = CRYPTO_READ(dev, RK_CRYPTO_CTRL) | 54 54 RK_CRYPTO_HASH_FLUSH | _SBF(0xffff, 16);
+7 -10
drivers/crypto/s5p-sss.c
··· 20 20 #include <linux/kernel.h> 21 21 #include <linux/module.h> 22 22 #include <linux/of.h> 23 + #include <linux/of_device.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/scatterlist.h> 25 26 ··· 402 401 static const struct samsung_aes_variant exynos5433_slim_aes_data = { 403 402 .aes_offset = 0x400, 404 403 .hash_offset = 0x800, 405 - .clk_names = { "pclk", "aclk", }, 404 + .clk_names = { "aclk", "pclk", }, 406 405 }; 407 406 408 407 static const struct of_device_id s5p_sss_dt_match[] = { ··· 425 424 static inline const struct samsung_aes_variant *find_s5p_sss_version 426 425 (const struct platform_device *pdev) 427 426 { 428 - if (IS_ENABLED(CONFIG_OF) && (pdev->dev.of_node)) { 429 - const struct of_device_id *match; 427 + if (IS_ENABLED(CONFIG_OF) && (pdev->dev.of_node)) 428 + return of_device_get_match_data(&pdev->dev); 430 429 431 - match = of_match_node(s5p_sss_dt_match, 432 - pdev->dev.of_node); 433 - return (const struct samsung_aes_variant *)match->data; 434 - } 435 430 return (const struct samsung_aes_variant *) 436 431 platform_get_device_id(pdev)->driver_data; 437 432 } ··· 2156 2159 static int s5p_aes_probe(struct platform_device *pdev) 2157 2160 { 2158 2161 struct device *dev = &pdev->dev; 2159 - int i, j, err = -ENODEV; 2162 + int i, j, err; 2160 2163 const struct samsung_aes_variant *variant; 2161 2164 struct s5p_aes_dev *pdata; 2162 2165 struct resource *res; ··· 2186 2189 } 2187 2190 2188 2191 pdata->res = res; 2189 - pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); 2192 + pdata->ioaddr = devm_ioremap_resource(dev, res); 2190 2193 if (IS_ERR(pdata->ioaddr)) { 2191 2194 if (!pdata->use_hash) 2192 2195 return PTR_ERR(pdata->ioaddr); 2193 2196 /* try AES without HASH */ 2194 2197 res->end -= 0x300; 2195 2198 pdata->use_hash = false; 2196 - pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); 2199 + pdata->ioaddr = devm_ioremap_resource(dev, res); 2197 2200 if (IS_ERR(pdata->ioaddr)) 2198 2201 return PTR_ERR(pdata->ioaddr); 2199 2202 }
+100 -43
drivers/crypto/sa2ul.c
··· 69 69 /* Max Authentication tag size */ 70 70 #define SA_MAX_AUTH_TAG_SZ 64 71 71 72 - #define PRIV_ID 0x1 73 - #define PRIV 0x1 72 + enum sa_algo_id { 73 + SA_ALG_CBC_AES = 0, 74 + SA_ALG_EBC_AES, 75 + SA_ALG_CBC_DES3, 76 + SA_ALG_ECB_DES3, 77 + SA_ALG_SHA1, 78 + SA_ALG_SHA256, 79 + SA_ALG_SHA512, 80 + SA_ALG_AUTHENC_SHA1_AES, 81 + SA_ALG_AUTHENC_SHA256_AES, 82 + }; 83 + 84 + struct sa_match_data { 85 + u8 priv; 86 + u8 priv_id; 87 + u32 supported_algos; 88 + bool skip_engine_control; 89 + }; 74 90 75 91 static struct device *sa_k3_dev; 76 92 ··· 712 696 } 713 697 714 698 static 715 - int sa_init_sc(struct sa_ctx_info *ctx, const u8 *enc_key, 716 - u16 enc_key_sz, const u8 *auth_key, u16 auth_key_sz, 699 + int sa_init_sc(struct sa_ctx_info *ctx, const struct sa_match_data *match_data, 700 + const u8 *enc_key, u16 enc_key_sz, 701 + const u8 *auth_key, u16 auth_key_sz, 717 702 struct algo_data *ad, u8 enc, u32 *swinfo) 718 703 { 719 704 int enc_sc_offset = 0; ··· 749 732 sc_buf[SA_CTX_SCCTL_OWNER_OFFSET] = 0; 750 733 memcpy(&sc_buf[2], &sc_id, 2); 751 734 sc_buf[4] = 0x0; 752 - sc_buf[5] = PRIV_ID; 753 - sc_buf[6] = PRIV; 735 + sc_buf[5] = match_data->priv_id; 736 + sc_buf[6] = match_data->priv; 754 737 sc_buf[7] = 0x0; 755 738 756 739 /* Prepare context for encryption engine */ ··· 909 892 return ret; 910 893 911 894 /* Setup Encryption Security Context & Command label template */ 912 - if (sa_init_sc(&ctx->enc, key, keylen, NULL, 0, ad, 1, 913 - &ctx->enc.epib[1])) 895 + if (sa_init_sc(&ctx->enc, ctx->dev_data->match_data, key, keylen, NULL, 0, 896 + ad, 1, &ctx->enc.epib[1])) 914 897 goto badkey; 915 898 916 899 cmdl_len = sa_format_cmdl_gen(&cfg, ··· 922 905 ctx->enc.cmdl_size = cmdl_len; 923 906 924 907 /* Setup Decryption Security Context & Command label template */ 925 - if (sa_init_sc(&ctx->dec, key, keylen, NULL, 0, ad, 0, 926 - &ctx->dec.epib[1])) 908 + if (sa_init_sc(&ctx->dec, ctx->dev_data->match_data, key, keylen, NULL, 0, 909 + ad, 0, &ctx->dec.epib[1])) 927 910 goto badkey; 928 911 929 912 cfg.enc_eng_id = ad->enc_eng.eng_id; ··· 1123 1106 else 1124 1107 dma_rx = pdata->dma_rx1; 1125 1108 1126 - ddev = dma_rx->device->dev; 1109 + ddev = dmaengine_get_dma_device(pdata->dma_tx); 1127 1110 rxd->ddev = ddev; 1128 1111 1129 1112 memcpy(cmdl, sa_ctx->cmdl, sa_ctx->cmdl_size); ··· 1163 1146 mapped_sg->sgt.sgl = src; 1164 1147 mapped_sg->sgt.orig_nents = src_nents; 1165 1148 ret = dma_map_sgtable(ddev, &mapped_sg->sgt, dir_src, 0); 1166 - if (ret) 1149 + if (ret) { 1150 + kfree(rxd); 1167 1151 return ret; 1152 + } 1168 1153 1169 1154 mapped_sg->dir = dir_src; 1170 1155 mapped_sg->mapped = true; ··· 1174 1155 mapped_sg->sgt.sgl = req->src; 1175 1156 mapped_sg->sgt.orig_nents = sg_nents; 1176 1157 ret = dma_map_sgtable(ddev, &mapped_sg->sgt, dir_src, 0); 1177 - if (ret) 1158 + if (ret) { 1159 + kfree(rxd); 1178 1160 return ret; 1161 + } 1179 1162 1180 1163 mapped_sg->dir = dir_src; 1181 1164 mapped_sg->mapped = true; ··· 1467 1446 cfg.akey = NULL; 1468 1447 cfg.akey_len = 0; 1469 1448 1449 + ctx->dev_data = dev_get_drvdata(sa_k3_dev); 1470 1450 /* Setup Encryption Security Context & Command label template */ 1471 - if (sa_init_sc(&ctx->enc, NULL, 0, NULL, 0, ad, 0, 1472 - &ctx->enc.epib[1])) 1451 + if (sa_init_sc(&ctx->enc, ctx->dev_data->match_data, NULL, 0, NULL, 0, 1452 + ad, 0, &ctx->enc.epib[1])) 1473 1453 goto badkey; 1474 1454 1475 1455 cmdl_len = sa_format_cmdl_gen(&cfg, ··· 1738 1716 int ret; 1739 1717 1740 1718 memzero_explicit(ctx, sizeof(*ctx)); 1719 + ctx->dev_data = data; 1741 1720 1742 1721 ctx->shash = crypto_alloc_shash(hash, 0, CRYPTO_ALG_NEED_FALLBACK); 1743 1722 if (IS_ERR(ctx->shash)) { ··· 1840 1817 cfg.akey_len = keys.authkeylen; 1841 1818 1842 1819 /* Setup Encryption Security Context & Command label template */ 1843 - if (sa_init_sc(&ctx->enc, keys.enckey, keys.enckeylen, 1844 - keys.authkey, keys.authkeylen, 1820 + if (sa_init_sc(&ctx->enc, ctx->dev_data->match_data, keys.enckey, 1821 + keys.enckeylen, keys.authkey, keys.authkeylen, 1845 1822 ad, 1, &ctx->enc.epib[1])) 1846 1823 return -EINVAL; 1847 1824 ··· 1854 1831 ctx->enc.cmdl_size = cmdl_len; 1855 1832 1856 1833 /* Setup Decryption Security Context & Command label template */ 1857 - if (sa_init_sc(&ctx->dec, keys.enckey, keys.enckeylen, 1858 - keys.authkey, keys.authkeylen, 1834 + if (sa_init_sc(&ctx->dec, ctx->dev_data->match_data, keys.enckey, 1835 + keys.enckeylen, keys.authkey, keys.authkeylen, 1859 1836 ad, 0, &ctx->dec.epib[1])) 1860 1837 return -EINVAL; 1861 1838 ··· 1973 1950 } 1974 1951 1975 1952 static struct sa_alg_tmpl sa_algs[] = { 1976 - { 1953 + [SA_ALG_CBC_AES] = { 1977 1954 .type = CRYPTO_ALG_TYPE_SKCIPHER, 1978 1955 .alg.skcipher = { 1979 1956 .base.cra_name = "cbc(aes)", ··· 1996 1973 .decrypt = sa_decrypt, 1997 1974 } 1998 1975 }, 1999 - { 1976 + [SA_ALG_EBC_AES] = { 2000 1977 .type = CRYPTO_ALG_TYPE_SKCIPHER, 2001 1978 .alg.skcipher = { 2002 1979 .base.cra_name = "ecb(aes)", ··· 2018 1995 .decrypt = sa_decrypt, 2019 1996 } 2020 1997 }, 2021 - { 1998 + [SA_ALG_CBC_DES3] = { 2022 1999 .type = CRYPTO_ALG_TYPE_SKCIPHER, 2023 2000 .alg.skcipher = { 2024 2001 .base.cra_name = "cbc(des3_ede)", ··· 2041 2018 .decrypt = sa_decrypt, 2042 2019 } 2043 2020 }, 2044 - { 2021 + [SA_ALG_ECB_DES3] = { 2045 2022 .type = CRYPTO_ALG_TYPE_SKCIPHER, 2046 2023 .alg.skcipher = { 2047 2024 .base.cra_name = "ecb(des3_ede)", ··· 2063 2040 .decrypt = sa_decrypt, 2064 2041 } 2065 2042 }, 2066 - { 2043 + [SA_ALG_SHA1] = { 2067 2044 .type = CRYPTO_ALG_TYPE_AHASH, 2068 2045 .alg.ahash = { 2069 2046 .halg.base = { ··· 2092 2069 .import = sa_sha_import, 2093 2070 }, 2094 2071 }, 2095 - { 2072 + [SA_ALG_SHA256] = { 2096 2073 .type = CRYPTO_ALG_TYPE_AHASH, 2097 2074 .alg.ahash = { 2098 2075 .halg.base = { ··· 2121 2098 .import = sa_sha_import, 2122 2099 }, 2123 2100 }, 2124 - { 2101 + [SA_ALG_SHA512] = { 2125 2102 .type = CRYPTO_ALG_TYPE_AHASH, 2126 2103 .alg.ahash = { 2127 2104 .halg.base = { ··· 2150 2127 .import = sa_sha_import, 2151 2128 }, 2152 2129 }, 2153 - { 2130 + [SA_ALG_AUTHENC_SHA1_AES] = { 2154 2131 .type = CRYPTO_ALG_TYPE_AEAD, 2155 2132 .alg.aead = { 2156 2133 .base = { ··· 2177 2154 .decrypt = sa_aead_decrypt, 2178 2155 }, 2179 2156 }, 2180 - { 2157 + [SA_ALG_AUTHENC_SHA256_AES] = { 2181 2158 .type = CRYPTO_ALG_TYPE_AEAD, 2182 2159 .alg.aead = { 2183 2160 .base = { ··· 2208 2185 }; 2209 2186 2210 2187 /* Register the algorithms in crypto framework */ 2211 - static void sa_register_algos(const struct device *dev) 2188 + static void sa_register_algos(struct sa_crypto_data *dev_data) 2212 2189 { 2190 + const struct sa_match_data *match_data = dev_data->match_data; 2191 + struct device *dev = dev_data->dev; 2213 2192 char *alg_name; 2214 2193 u32 type; 2215 2194 int i, err; 2216 2195 2217 2196 for (i = 0; i < ARRAY_SIZE(sa_algs); i++) { 2197 + /* Skip unsupported algos */ 2198 + if (!(match_data->supported_algos & BIT(i))) 2199 + continue; 2200 + 2218 2201 type = sa_algs[i].type; 2219 2202 if (type == CRYPTO_ALG_TYPE_SKCIPHER) { 2220 2203 alg_name = sa_algs[i].alg.skcipher.base.cra_name; ··· 2358 2329 return 0; 2359 2330 } 2360 2331 2332 + static struct sa_match_data am654_match_data = { 2333 + .priv = 1, 2334 + .priv_id = 1, 2335 + .supported_algos = GENMASK(SA_ALG_AUTHENC_SHA256_AES, 0), 2336 + }; 2337 + 2338 + static struct sa_match_data am64_match_data = { 2339 + .priv = 0, 2340 + .priv_id = 0, 2341 + .supported_algos = BIT(SA_ALG_CBC_AES) | 2342 + BIT(SA_ALG_EBC_AES) | 2343 + BIT(SA_ALG_SHA256) | 2344 + BIT(SA_ALG_SHA512) | 2345 + BIT(SA_ALG_AUTHENC_SHA256_AES), 2346 + .skip_engine_control = true, 2347 + }; 2348 + 2349 + static const struct of_device_id of_match[] = { 2350 + { .compatible = "ti,j721e-sa2ul", .data = &am654_match_data, }, 2351 + { .compatible = "ti,am654-sa2ul", .data = &am654_match_data, }, 2352 + { .compatible = "ti,am64-sa2ul", .data = &am64_match_data, }, 2353 + {}, 2354 + }; 2355 + MODULE_DEVICE_TABLE(of, of_match); 2356 + 2361 2357 static int sa_ul_probe(struct platform_device *pdev) 2362 2358 { 2359 + const struct of_device_id *match; 2363 2360 struct device *dev = &pdev->dev; 2364 2361 struct device_node *node = dev->of_node; 2365 2362 struct resource *res; 2366 2363 static void __iomem *saul_base; 2367 2364 struct sa_crypto_data *dev_data; 2368 - u32 val; 2369 2365 int ret; 2370 2366 2371 2367 dev_data = devm_kzalloc(dev, sizeof(*dev_data), GFP_KERNEL); ··· 2404 2350 dev_set_drvdata(sa_k3_dev, dev_data); 2405 2351 2406 2352 pm_runtime_enable(dev); 2407 - ret = pm_runtime_get_sync(dev); 2353 + ret = pm_runtime_resume_and_get(dev); 2408 2354 if (ret < 0) { 2409 2355 dev_err(&pdev->dev, "%s: failed to get sync: %d\n", __func__, 2410 2356 ret); ··· 2416 2362 if (ret) 2417 2363 goto disable_pm_runtime; 2418 2364 2365 + match = of_match_node(of_match, dev->of_node); 2366 + if (!match) { 2367 + dev_err(dev, "No compatible match found\n"); 2368 + return -ENODEV; 2369 + } 2370 + dev_data->match_data = match->data; 2371 + 2419 2372 spin_lock_init(&dev_data->scid_lock); 2420 2373 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2421 2374 saul_base = devm_ioremap_resource(dev, res); 2422 2375 2423 2376 dev_data->base = saul_base; 2424 - val = SA_EEC_ENCSS_EN | SA_EEC_AUTHSS_EN | SA_EEC_CTXCACH_EN | 2425 - SA_EEC_CPPI_PORT_IN_EN | SA_EEC_CPPI_PORT_OUT_EN | 2426 - SA_EEC_TRNG_EN; 2427 2377 2428 - writel_relaxed(val, saul_base + SA_ENGINE_ENABLE_CONTROL); 2378 + if (!dev_data->match_data->skip_engine_control) { 2379 + u32 val = SA_EEC_ENCSS_EN | SA_EEC_AUTHSS_EN | SA_EEC_CTXCACH_EN | 2380 + SA_EEC_CPPI_PORT_IN_EN | SA_EEC_CPPI_PORT_OUT_EN | 2381 + SA_EEC_TRNG_EN; 2429 2382 2430 - sa_register_algos(dev); 2383 + writel_relaxed(val, saul_base + SA_ENGINE_ENABLE_CONTROL); 2384 + } 2385 + 2386 + sa_register_algos(dev_data); 2431 2387 2432 2388 ret = of_platform_populate(node, NULL, NULL, &pdev->dev); 2433 2389 if (ret) ··· 2482 2418 2483 2419 return 0; 2484 2420 } 2485 - 2486 - static const struct of_device_id of_match[] = { 2487 - {.compatible = "ti,j721e-sa2ul",}, 2488 - {.compatible = "ti,am654-sa2ul",}, 2489 - {}, 2490 - }; 2491 - MODULE_DEVICE_TABLE(of, of_match); 2492 2421 2493 2422 static struct platform_driver sa_ul_driver = { 2494 2423 .probe = sa_ul_probe,
+4
drivers/crypto/sa2ul.h
··· 171 171 #define SA_UNSAFE_DATA_SZ_MIN 240 172 172 #define SA_UNSAFE_DATA_SZ_MAX 256 173 173 174 + struct sa_match_data; 175 + 174 176 /** 175 177 * struct sa_crypto_data - Crypto driver instance data 176 178 * @base: Base address of the register space 179 + * @soc_data: Pointer to SoC specific data 177 180 * @pdev: Platform device pointer 178 181 * @sc_pool: security context pool 179 182 * @dev: Device pointer ··· 192 189 */ 193 190 struct sa_crypto_data { 194 191 void __iomem *base; 192 + const struct sa_match_data *match_data; 195 193 struct platform_device *pdev; 196 194 struct dma_pool *sc_pool; 197 195 struct device *dev;
+2 -2
drivers/crypto/stm32/stm32-cryp.c
··· 542 542 int ret; 543 543 u32 cfg, hw_mode; 544 544 545 - pm_runtime_get_sync(cryp->dev); 545 + pm_runtime_resume_and_get(cryp->dev); 546 546 547 547 /* Disable interrupt */ 548 548 stm32_cryp_write(cryp, CRYP_IMSCR, 0); ··· 2043 2043 if (!cryp) 2044 2044 return -ENODEV; 2045 2045 2046 - ret = pm_runtime_get_sync(cryp->dev); 2046 + ret = pm_runtime_resume_and_get(cryp->dev); 2047 2047 if (ret < 0) 2048 2048 return ret; 2049 2049
+4 -4
drivers/crypto/stm32/stm32-hash.c
··· 813 813 static int stm32_hash_hw_init(struct stm32_hash_dev *hdev, 814 814 struct stm32_hash_request_ctx *rctx) 815 815 { 816 - pm_runtime_get_sync(hdev->dev); 816 + pm_runtime_resume_and_get(hdev->dev); 817 817 818 818 if (!(HASH_FLAGS_INIT & hdev->flags)) { 819 819 stm32_hash_write(hdev, HASH_CR, HASH_CR_INIT); ··· 962 962 u32 *preg; 963 963 unsigned int i; 964 964 965 - pm_runtime_get_sync(hdev->dev); 965 + pm_runtime_resume_and_get(hdev->dev); 966 966 967 967 while ((stm32_hash_read(hdev, HASH_SR) & HASH_SR_BUSY)) 968 968 cpu_relax(); ··· 1000 1000 1001 1001 preg = rctx->hw_context; 1002 1002 1003 - pm_runtime_get_sync(hdev->dev); 1003 + pm_runtime_resume_and_get(hdev->dev); 1004 1004 1005 1005 stm32_hash_write(hdev, HASH_IMR, *preg++); 1006 1006 stm32_hash_write(hdev, HASH_STR, *preg++); ··· 1566 1566 if (!hdev) 1567 1567 return -ENODEV; 1568 1568 1569 - ret = pm_runtime_get_sync(hdev->dev); 1569 + ret = pm_runtime_resume_and_get(hdev->dev); 1570 1570 if (ret < 0) 1571 1571 return ret; 1572 1572
+3 -2
drivers/crypto/ux500/cryp/cryp.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson. ··· 15 15 #include "cryp_p.h" 16 16 #include "cryp.h" 17 17 18 - /** 18 + /* 19 19 * cryp_wait_until_done - wait until the device logic is not busy 20 20 */ 21 21 void cryp_wait_until_done(struct cryp_device_data *device_data) ··· 285 285 * other device context parameter 286 286 * @device_data: Pointer to the device data struct for base address. 287 287 * @ctx: Crypto device context 288 + * @cryp_mode: Mode: Polling, Interrupt or DMA 288 289 */ 289 290 void cryp_save_device_context(struct cryp_device_data *device_data, 290 291 struct cryp_device_context *ctx,
+1 -1
drivers/crypto/ux500/cryp/cryp.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson.
+5 -5
drivers/crypto/ux500/cryp/cryp_core.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Joakim Bech <joakim.xx.bech@stericsson.com> for ST-Ericsson. ··· 62 62 /** 63 63 * struct cryp_ctx - Crypto context 64 64 * @config: Crypto mode. 65 - * @key[CRYP_MAX_KEY_SIZE]: Key. 65 + * @key: Key array. 66 66 * @keylen: Length of key. 67 67 * @iv: Pointer to initialization vector. 68 68 * @indata: Pointer to indata. ··· 73 73 * @updated: Updated flag. 74 74 * @dev_ctx: Device dependent context. 75 75 * @device: Pointer to the device. 76 + * @session_id: Atomic session ID. 76 77 */ 77 78 struct cryp_ctx { 78 79 struct cryp_config config; ··· 609 608 chan = ctx->device->dma.chan_mem2cryp; 610 609 dmaengine_terminate_all(chan); 611 610 dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_src, 612 - ctx->device->dma.sg_src_len, DMA_TO_DEVICE); 611 + ctx->device->dma.nents_src, DMA_TO_DEVICE); 613 612 614 613 chan = ctx->device->dma.chan_cryp2mem; 615 614 dmaengine_terminate_all(chan); 616 615 dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_dst, 617 - ctx->device->dma.sg_dst_len, DMA_FROM_DEVICE); 616 + ctx->device->dma.nents_dst, DMA_FROM_DEVICE); 618 617 } 619 618 620 619 static int cryp_dma_write(struct cryp_ctx *ctx, struct scatterlist *sg, ··· 1291 1290 device_data->phybase = res->start; 1292 1291 device_data->base = devm_ioremap_resource(dev, res); 1293 1292 if (IS_ERR(device_data->base)) { 1294 - dev_err(dev, "[%s]: ioremap failed!", __func__); 1295 1293 ret = PTR_ERR(device_data->base); 1296 1294 goto out; 1297 1295 }
+1 -1
drivers/crypto/ux500/cryp/cryp_irq.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson.
+2 -2
drivers/crypto/ux500/cryp/cryp_irq.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson. ··· 19 19 CRYP_IRQ_SRC_ALL = 0x3 20 20 }; 21 21 22 - /** 22 + /* 23 23 * M0 Funtions 24 24 */ 25 25 void cryp_enable_irq_src(struct cryp_device_data *device_data, u32 irq_src);
+2 -2
drivers/crypto/ux500/cryp/cryp_irqp.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson. ··· 13 13 14 14 #include "cryp_irq.h" 15 15 16 - /** 16 + /* 17 17 * 18 18 * CRYP Registers - Offset mapping 19 19 * +-----------------+
+7 -8
drivers/crypto/ux500/cryp/cryp_p.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /** 2 + /* 3 3 * Copyright (C) ST-Ericsson SA 2010 4 4 * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson. 5 5 * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson. ··· 17 17 #include "cryp.h" 18 18 #include "cryp_irqp.h" 19 19 20 - /** 20 + /* 21 21 * Generic Macros 22 22 */ 23 23 #define CRYP_SET_BITS(reg_name, mask) \ ··· 34 34 writel_relaxed(((readl_relaxed(reg) & ~(mask)) | \ 35 35 (((u32)val << shift) & (mask))), reg) 36 36 37 - /** 37 + /* 38 38 * CRYP specific Macros 39 39 */ 40 40 #define CRYP_PERIPHERAL_ID0 0xE3 ··· 48 48 #define CRYP_PCELL_ID2 0x05 49 49 #define CRYP_PCELL_ID3 0xB1 50 50 51 - /** 51 + /* 52 52 * CRYP register default values 53 53 */ 54 54 #define MAX_DEVICE_SUPPORT 2 ··· 62 62 #define CRYP_KEY_DEFAULT 0x0 63 63 #define CRYP_INIT_VECT_DEFAULT 0x0 64 64 65 - /** 65 + /* 66 66 * CRYP Control register specific mask 67 67 */ 68 68 #define CRYP_CR_SECURE_MASK BIT(0) ··· 81 81 CRYP_CR_PRLG_MASK |\ 82 82 CRYP_CR_ALGODIR_MASK |\ 83 83 CRYP_CR_ALGOMODE_MASK |\ 84 - CRYP_CR_DATATYPE_MASK |\ 85 84 CRYP_CR_KEYSIZE_MASK |\ 86 85 CRYP_CR_KEYRDEN_MASK |\ 87 86 CRYP_CR_DATATYPE_MASK) ··· 90 91 #define CRYP_SR_IFEM_MASK BIT(0) 91 92 #define CRYP_SR_BUSY_MASK BIT(4) 92 93 93 - /** 94 + /* 94 95 * Bit position used while setting bits in register 95 96 */ 96 97 #define CRYP_CR_PRLG_POS 1 ··· 106 107 107 108 #define CRYP_SR_BUSY_POS 4 108 109 109 - /** 110 + /* 110 111 * CRYP PCRs------PC_NAND control register 111 112 * BIT_MASK 112 113 */
+6 -12
drivers/crypto/ux500/hash/hash_core.c
··· 190 190 chan = ctx->device->dma.chan_mem2hash; 191 191 dmaengine_terminate_all(chan); 192 192 dma_unmap_sg(chan->device->dev, ctx->device->dma.sg, 193 - ctx->device->dma.sg_len, DMA_TO_DEVICE); 193 + ctx->device->dma.nents, DMA_TO_DEVICE); 194 194 } 195 195 196 196 static int hash_dma_write(struct hash_ctx *ctx, ··· 356 356 357 357 /** 358 358 * hash_get_device_data - Checks for an available hash device and return it. 359 - * @hash_ctx: Structure for the hash context. 359 + * @ctx: Structure for the hash context. 360 360 * @device_data: Structure for the hash device. 361 361 * 362 362 * This function check for an available hash device and return it to ··· 542 542 } 543 543 544 544 /** 545 - * hash_init - Common hash init function for SHA1/SHA2 (SHA256). 545 + * ux500_hash_init - Common hash init function for SHA1/SHA2 (SHA256). 546 546 * @req: The hash request for the job. 547 547 * 548 548 * Initialize structures. ··· 585 585 * @device_data: Structure for the hash device. 586 586 * @message: Block (512 bits) of message to be written to 587 587 * the HASH hardware. 588 + * @length: Message length 588 589 * 589 590 */ 590 591 static void hash_processblock(struct hash_device_data *device_data, ··· 1296 1295 } 1297 1296 1298 1297 /** 1299 - * hash_update - The hash update function for SHA1/SHA2 (SHA256). 1298 + * ahash_update - The hash update function for SHA1/SHA2 (SHA256). 1300 1299 * @req: The hash request for the job. 1301 1300 */ 1302 1301 static int ahash_update(struct ahash_request *req) ··· 1316 1315 } 1317 1316 1318 1317 /** 1319 - * hash_final - The hash final function for SHA1/SHA2 (SHA256). 1318 + * ahash_final - The hash final function for SHA1/SHA2 (SHA256). 1320 1319 * @req: The hash request for the job. 1321 1320 */ 1322 1321 static int ahash_final(struct ahash_request *req) ··· 1616 1615 } 1617 1616 }; 1618 1617 1619 - /** 1620 - * hash_algs_register_all - 1621 - */ 1622 1618 static int ahash_algs_register_all(struct hash_device_data *device_data) 1623 1619 { 1624 1620 int ret; ··· 1638 1640 return ret; 1639 1641 } 1640 1642 1641 - /** 1642 - * hash_algs_unregister_all - 1643 - */ 1644 1643 static void ahash_algs_unregister_all(struct hash_device_data *device_data) 1645 1644 { 1646 1645 int i; ··· 1676 1681 device_data->phybase = res->start; 1677 1682 device_data->base = devm_ioremap_resource(dev, res); 1678 1683 if (IS_ERR(device_data->base)) { 1679 - dev_err(dev, "%s: ioremap() failed!\n", __func__); 1680 1684 ret = PTR_ERR(device_data->base); 1681 1685 goto out; 1682 1686 }
+1 -1
drivers/crypto/vmx/aes.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES routines supporting VMX instructions on the Power 8 4 4 * 5 5 * Copyright (C) 2015 International Business Machines Inc.
+1 -1
drivers/crypto/vmx/aes_cbc.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES CBC routines supporting VMX instructions on the Power 8 4 4 * 5 5 * Copyright (C) 2015 International Business Machines Inc.
+1 -1
drivers/crypto/vmx/aes_ctr.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES CTR routines supporting VMX instructions on the Power 8 4 4 * 5 5 * Copyright (C) 2015 International Business Machines Inc.
+1 -1
drivers/crypto/vmx/aes_xts.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * AES XTS routines supporting VMX In-core instructions on Power 8 4 4 * 5 5 * Copyright (C) 2015 International Business Machines Inc.
+1 -1
drivers/crypto/vmx/ghash.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - /** 2 + /* 3 3 * GHASH routines supporting VMX instructions on the Power 8 4 4 * 5 5 * Copyright (C) 2015, 2019 International Business Machines Inc.
+1 -1
drivers/crypto/vmx/vmx.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - /** 2 + /* 3 3 * Routines supporting VMX instructions on the Power 8 4 4 * 5 5 * Copyright (C) 2015 International Business Machines Inc.
+22 -8
fs/crypto/Kconfig
··· 14 14 F2FS and UBIFS make use of this feature. 15 15 16 16 # Filesystems supporting encryption must select this if FS_ENCRYPTION. This 17 - # allows the algorithms to be built as modules when all the filesystems are. 17 + # allows the algorithms to be built as modules when all the filesystems are, 18 + # whereas selecting them from FS_ENCRYPTION would force them to be built-in. 19 + # 20 + # Note: this option only pulls in the algorithms that filesystem encryption 21 + # needs "by default". If userspace will use "non-default" encryption modes such 22 + # as Adiantum encryption, then those other modes need to be explicitly enabled 23 + # in the crypto API; see Documentation/filesystems/fscrypt.rst for details. 24 + # 25 + # Also note that this option only pulls in the generic implementations of the 26 + # algorithms, not any per-architecture optimized implementations. It is 27 + # strongly recommended to enable optimized implementations too. It is safe to 28 + # disable these generic implementations if corresponding optimized 29 + # implementations will always be available too; for this reason, these are soft 30 + # dependencies ('imply' rather than 'select'). Only disable these generic 31 + # implementations if you're sure they will never be needed, though. 18 32 config FS_ENCRYPTION_ALGS 19 33 tristate 20 - select CRYPTO_AES 21 - select CRYPTO_CBC 22 - select CRYPTO_CTS 23 - select CRYPTO_ECB 24 - select CRYPTO_HMAC 25 - select CRYPTO_SHA512 26 - select CRYPTO_XTS 34 + imply CRYPTO_AES 35 + imply CRYPTO_CBC 36 + imply CRYPTO_CTS 37 + imply CRYPTO_ECB 38 + imply CRYPTO_HMAC 39 + imply CRYPTO_SHA512 40 + imply CRYPTO_XTS 27 41 28 42 config FS_ENCRYPTION_INLINE_CRYPT 29 43 bool "Enable fscrypt to use inline crypto"
+6 -2
fs/verity/Kconfig
··· 3 3 config FS_VERITY 4 4 bool "FS Verity (read-only file-based authenticity protection)" 5 5 select CRYPTO 6 - # SHA-256 is selected as it's intended to be the default hash algorithm. 6 + # SHA-256 is implied as it's intended to be the default hash algorithm. 7 7 # To avoid bloat, other wanted algorithms must be selected explicitly. 8 - select CRYPTO_SHA256 8 + # Note that CRYPTO_SHA256 denotes the generic C implementation, but 9 + # some architectures provided optimized implementations of the same 10 + # algorithm that may be used instead. In this case, CRYPTO_SHA256 may 11 + # be omitted even if SHA-256 is being used. 12 + imply CRYPTO_SHA256 9 13 help 10 14 This option enables fs-verity. fs-verity is the dm-verity 11 15 mechanism implemented at the file level. On supported
+2
include/crypto/acompress.h
··· 165 165 * crypto_free_acomp() -- free ACOMPRESS tfm handle 166 166 * 167 167 * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() 168 + * 169 + * If @tfm is a NULL or error pointer, this function does nothing. 168 170 */ 169 171 static inline void crypto_free_acomp(struct crypto_acomp *tfm) 170 172 {
+2
include/crypto/aead.h
··· 185 185 /** 186 186 * crypto_free_aead() - zeroize and free aead handle 187 187 * @tfm: cipher handle to be freed 188 + * 189 + * If @tfm is a NULL or error pointer, this function does nothing. 188 190 */ 189 191 static inline void crypto_free_aead(struct crypto_aead *tfm) 190 192 {
+2
include/crypto/akcipher.h
··· 174 174 * crypto_free_akcipher() - free AKCIPHER tfm handle 175 175 * 176 176 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() 177 + * 178 + * If @tfm is a NULL or error pointer, this function does nothing. 177 179 */ 178 180 static inline void crypto_free_akcipher(struct crypto_akcipher *tfm) 179 181 {
+7 -2
include/crypto/chacha.h
··· 47 47 hchacha_block_generic(state, out, nrounds); 48 48 } 49 49 50 - void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv); 51 - static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) 50 + static inline void chacha_init_consts(u32 *state) 52 51 { 53 52 state[0] = 0x61707865; /* "expa" */ 54 53 state[1] = 0x3320646e; /* "nd 3" */ 55 54 state[2] = 0x79622d32; /* "2-by" */ 56 55 state[3] = 0x6b206574; /* "te k" */ 56 + } 57 + 58 + void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv); 59 + static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) 60 + { 61 + chacha_init_consts(state); 57 62 state[4] = key[0]; 58 63 state[5] = key[1]; 59 64 state[6] = key[2];
+60
include/crypto/ecc_curve.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* Copyright (c) 2021 HiSilicon */ 3 + 4 + #ifndef _CRYTO_ECC_CURVE_H 5 + #define _CRYTO_ECC_CURVE_H 6 + 7 + #include <linux/types.h> 8 + 9 + /** 10 + * struct ecc_point - elliptic curve point in affine coordinates 11 + * 12 + * @x: X coordinate in vli form. 13 + * @y: Y coordinate in vli form. 14 + * @ndigits: Length of vlis in u64 qwords. 15 + */ 16 + struct ecc_point { 17 + u64 *x; 18 + u64 *y; 19 + u8 ndigits; 20 + }; 21 + 22 + /** 23 + * struct ecc_curve - definition of elliptic curve 24 + * 25 + * @name: Short name of the curve. 26 + * @g: Generator point of the curve. 27 + * @p: Prime number, if Barrett's reduction is used for this curve 28 + * pre-calculated value 'mu' is appended to the @p after ndigits. 29 + * Use of Barrett's reduction is heuristically determined in 30 + * vli_mmod_fast(). 31 + * @n: Order of the curve group. 32 + * @a: Curve parameter a. 33 + * @b: Curve parameter b. 34 + */ 35 + struct ecc_curve { 36 + char *name; 37 + struct ecc_point g; 38 + u64 *p; 39 + u64 *n; 40 + u64 *a; 41 + u64 *b; 42 + }; 43 + 44 + /** 45 + * ecc_get_curve() - get elliptic curve; 46 + * @curve_id: Curves IDs: 47 + * defined in 'include/crypto/ecdh.h'; 48 + * 49 + * Returns curve if get curve succssful, NULL otherwise 50 + */ 51 + const struct ecc_curve *ecc_get_curve(unsigned int curve_id); 52 + 53 + /** 54 + * ecc_get_curve25519() - get curve25519 curve; 55 + * 56 + * Returns curve25519 57 + */ 58 + const struct ecc_curve *ecc_get_curve25519(void); 59 + 60 + #endif
+1 -2
include/crypto/ecdh.h
··· 25 25 /* Curves IDs */ 26 26 #define ECC_CURVE_NIST_P192 0x0001 27 27 #define ECC_CURVE_NIST_P256 0x0002 28 + #define ECC_CURVE_NIST_P384 0x0003 28 29 29 30 /** 30 31 * struct ecdh - define an ECDH private key 31 32 * 32 - * @curve_id: ECC curve the key is based on. 33 33 * @key: Private ECDH key 34 34 * @key_size: Size of the private ECDH key 35 35 */ 36 36 struct ecdh { 37 - unsigned short curve_id; 38 37 char *key; 39 38 unsigned short key_size; 40 39 };
+4
include/crypto/hash.h
··· 281 281 /** 282 282 * crypto_free_ahash() - zeroize and free the ahash handle 283 283 * @tfm: cipher handle to be freed 284 + * 285 + * If @tfm is a NULL or error pointer, this function does nothing. 284 286 */ 285 287 static inline void crypto_free_ahash(struct crypto_ahash *tfm) 286 288 { ··· 726 724 /** 727 725 * crypto_free_shash() - zeroize and free the message digest handle 728 726 * @tfm: cipher handle to be freed 727 + * 728 + * If @tfm is a NULL or error pointer, this function does nothing. 729 729 */ 730 730 static inline void crypto_free_shash(struct crypto_shash *tfm) 731 731 {
+2 -1
include/crypto/internal/poly1305.h
··· 18 18 * only the ε-almost-∆-universal hash function (not the full MAC) is computed. 19 19 */ 20 20 21 - void poly1305_core_setkey(struct poly1305_core_key *key, const u8 *raw_key); 21 + void poly1305_core_setkey(struct poly1305_core_key *key, 22 + const u8 raw_key[POLY1305_BLOCK_SIZE]); 22 23 static inline void poly1305_core_init(struct poly1305_state *state) 23 24 { 24 25 *state = (struct poly1305_state){};
+2
include/crypto/kpp.h
··· 154 154 * crypto_free_kpp() - free KPP tfm handle 155 155 * 156 156 * @tfm: KPP tfm handle allocated with crypto_alloc_kpp() 157 + * 158 + * If @tfm is a NULL or error pointer, this function does nothing. 157 159 */ 158 160 static inline void crypto_free_kpp(struct crypto_kpp *tfm) 159 161 {
+4 -2
include/crypto/poly1305.h
··· 58 58 }; 59 59 }; 60 60 61 - void poly1305_init_arch(struct poly1305_desc_ctx *desc, const u8 *key); 62 - void poly1305_init_generic(struct poly1305_desc_ctx *desc, const u8 *key); 61 + void poly1305_init_arch(struct poly1305_desc_ctx *desc, 62 + const u8 key[POLY1305_KEY_SIZE]); 63 + void poly1305_init_generic(struct poly1305_desc_ctx *desc, 64 + const u8 key[POLY1305_KEY_SIZE]); 63 65 64 66 static inline void poly1305_init(struct poly1305_desc_ctx *desc, const u8 *key) 65 67 {
+2
include/crypto/rng.h
··· 111 111 /** 112 112 * crypto_free_rng() - zeroize and free RNG handle 113 113 * @tfm: cipher handle to be freed 114 + * 115 + * If @tfm is a NULL or error pointer, this function does nothing. 114 116 */ 115 117 static inline void crypto_free_rng(struct crypto_rng *tfm) 116 118 {
+2
include/crypto/skcipher.h
··· 196 196 /** 197 197 * crypto_free_skcipher() - zeroize and free cipher handle 198 198 * @tfm: cipher handle to be freed 199 + * 200 + * If @tfm is a NULL or error pointer, this function does nothing. 199 201 */ 200 202 static inline void crypto_free_skcipher(struct crypto_skcipher *tfm) 201 203 {
+6
include/keys/asymmetric-type.h
··· 72 72 return key->payload.data[asym_key_ids]; 73 73 } 74 74 75 + static inline 76 + const struct public_key *asymmetric_key_public_key(const struct key *key) 77 + { 78 + return key->payload.data[asym_crypto]; 79 + } 80 + 75 81 extern struct key *find_asymmetric_key(struct key *keyring, 76 82 const struct asymmetric_key_id *id_0, 77 83 const struct asymmetric_key_id *id_1,
+9 -1
include/linux/oid_registry.h
··· 19 19 enum OID { 20 20 OID_id_dsa_with_sha1, /* 1.2.840.10030.4.3 */ 21 21 OID_id_dsa, /* 1.2.840.10040.4.1 */ 22 - OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */ 23 22 OID_id_ecPublicKey, /* 1.2.840.10045.2.1 */ 23 + OID_id_prime192v1, /* 1.2.840.10045.3.1.1 */ 24 + OID_id_prime256v1, /* 1.2.840.10045.3.1.7 */ 25 + OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */ 26 + OID_id_ecdsa_with_sha224, /* 1.2.840.10045.4.3.1 */ 27 + OID_id_ecdsa_with_sha256, /* 1.2.840.10045.4.3.2 */ 28 + OID_id_ecdsa_with_sha384, /* 1.2.840.10045.4.3.3 */ 29 + OID_id_ecdsa_with_sha512, /* 1.2.840.10045.4.3.4 */ 24 30 25 31 /* PKCS#1 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)} */ 26 32 OID_rsaEncryption, /* 1.2.840.113549.1.1.1 */ ··· 64 58 65 59 OID_certAuthInfoAccess, /* 1.3.6.1.5.5.7.1.1 */ 66 60 OID_sha1, /* 1.3.14.3.2.26 */ 61 + OID_id_ansip384r1, /* 1.3.132.0.34 */ 67 62 OID_sha256, /* 2.16.840.1.101.3.4.2.1 */ 68 63 OID_sha384, /* 2.16.840.1.101.3.4.2.2 */ 69 64 OID_sha512, /* 2.16.840.1.101.3.4.2.3 */ ··· 129 122 }; 130 123 131 124 extern enum OID look_up_OID(const void *data, size_t datasize); 125 + extern int parse_OID(const void *data, size_t datasize, enum OID *oid); 132 126 extern int sprint_oid(const void *, size_t, char *, size_t); 133 127 extern int sprint_OID(enum OID, char *, size_t); 134 128
-83
include/trace/events/random.h
··· 85 85 __entry->entropy_count, (void *)__entry->IP) 86 86 ); 87 87 88 - TRACE_EVENT(push_to_pool, 89 - TP_PROTO(const char *pool_name, int pool_bits, int input_bits), 90 - 91 - TP_ARGS(pool_name, pool_bits, input_bits), 92 - 93 - TP_STRUCT__entry( 94 - __field( const char *, pool_name ) 95 - __field( int, pool_bits ) 96 - __field( int, input_bits ) 97 - ), 98 - 99 - TP_fast_assign( 100 - __entry->pool_name = pool_name; 101 - __entry->pool_bits = pool_bits; 102 - __entry->input_bits = input_bits; 103 - ), 104 - 105 - TP_printk("%s: pool_bits %d input_pool_bits %d", 106 - __entry->pool_name, __entry->pool_bits, 107 - __entry->input_bits) 108 - ); 109 - 110 88 TRACE_EVENT(debit_entropy, 111 89 TP_PROTO(const char *pool_name, int debit_bits), 112 90 ··· 137 159 138 160 TP_printk("dev %d,%d input_pool_bits %d", MAJOR(__entry->dev), 139 161 MINOR(__entry->dev), __entry->input_bits) 140 - ); 141 - 142 - TRACE_EVENT(xfer_secondary_pool, 143 - TP_PROTO(const char *pool_name, int xfer_bits, int request_bits, 144 - int pool_entropy, int input_entropy), 145 - 146 - TP_ARGS(pool_name, xfer_bits, request_bits, pool_entropy, 147 - input_entropy), 148 - 149 - TP_STRUCT__entry( 150 - __field( const char *, pool_name ) 151 - __field( int, xfer_bits ) 152 - __field( int, request_bits ) 153 - __field( int, pool_entropy ) 154 - __field( int, input_entropy ) 155 - ), 156 - 157 - TP_fast_assign( 158 - __entry->pool_name = pool_name; 159 - __entry->xfer_bits = xfer_bits; 160 - __entry->request_bits = request_bits; 161 - __entry->pool_entropy = pool_entropy; 162 - __entry->input_entropy = input_entropy; 163 - ), 164 - 165 - TP_printk("pool %s xfer_bits %d request_bits %d pool_entropy %d " 166 - "input_entropy %d", __entry->pool_name, __entry->xfer_bits, 167 - __entry->request_bits, __entry->pool_entropy, 168 - __entry->input_entropy) 169 162 ); 170 163 171 164 DECLARE_EVENT_CLASS(random__get_random_bytes, ··· 200 251 unsigned long IP), 201 252 202 253 TP_ARGS(pool_name, nbytes, entropy_count, IP) 203 - ); 204 - 205 - DEFINE_EVENT(random__extract_entropy, extract_entropy_user, 206 - TP_PROTO(const char *pool_name, int nbytes, int entropy_count, 207 - unsigned long IP), 208 - 209 - TP_ARGS(pool_name, nbytes, entropy_count, IP) 210 - ); 211 - 212 - TRACE_EVENT(random_read, 213 - TP_PROTO(int got_bits, int need_bits, int pool_left, int input_left), 214 - 215 - TP_ARGS(got_bits, need_bits, pool_left, input_left), 216 - 217 - TP_STRUCT__entry( 218 - __field( int, got_bits ) 219 - __field( int, need_bits ) 220 - __field( int, pool_left ) 221 - __field( int, input_left ) 222 - ), 223 - 224 - TP_fast_assign( 225 - __entry->got_bits = got_bits; 226 - __entry->need_bits = need_bits; 227 - __entry->pool_left = pool_left; 228 - __entry->input_left = input_left; 229 - ), 230 - 231 - TP_printk("got_bits %d still_needed_bits %d " 232 - "blocking_pool_entropy_left %d input_entropy_left %d", 233 - __entry->got_bits, __entry->got_bits, __entry->pool_left, 234 - __entry->input_left) 235 254 ); 236 255 237 256 TRACE_EVENT(urandom_read,
+1
include/uapi/misc/uacce/hisi_qm.h
··· 16 16 17 17 #define HISI_QM_API_VER_BASE "hisi_qm_v1" 18 18 #define HISI_QM_API_VER2_BASE "hisi_qm_v2" 19 + #define HISI_QM_API_VER3_BASE "hisi_qm_v3" 19 20 20 21 /* UACCE_CMD_QM_SET_QP_CTX: Set qp algorithm type */ 21 22 #define UACCE_CMD_QM_SET_QP_CTX _IOWR('H', 10, struct hisi_qp_ctx)
+2 -2
lib/crypto/chacha.c
··· 64 64 } 65 65 66 66 /** 67 - * chacha_block - generate one keystream block and increment block counter 67 + * chacha_block_generic - generate one keystream block and increment block counter 68 68 * @state: input state matrix (16 32-bit words) 69 69 * @stream: output keystream block (64 bytes) 70 70 * @nrounds: number of rounds (20 or 12; 20 is recommended) ··· 92 92 /** 93 93 * hchacha_block_generic - abbreviated ChaCha core, for XChaCha 94 94 * @state: input state matrix (16 32-bit words) 95 - * @out: output (8 32-bit words) 95 + * @stream: output (8 32-bit words) 96 96 * @nrounds: number of rounds (20 or 12; 20 is recommended) 97 97 * 98 98 * HChaCha is the ChaCha equivalent of HSalsa and is an intermediate step
+2 -1
lib/crypto/poly1305-donna32.c
··· 10 10 #include <asm/unaligned.h> 11 11 #include <crypto/internal/poly1305.h> 12 12 13 - void poly1305_core_setkey(struct poly1305_core_key *key, const u8 raw_key[16]) 13 + void poly1305_core_setkey(struct poly1305_core_key *key, 14 + const u8 raw_key[POLY1305_BLOCK_SIZE]) 14 15 { 15 16 /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ 16 17 key->key.r[0] = (get_unaligned_le32(&raw_key[0])) & 0x3ffffff;
+2 -1
lib/crypto/poly1305-donna64.c
··· 12 12 13 13 typedef __uint128_t u128; 14 14 15 - void poly1305_core_setkey(struct poly1305_core_key *key, const u8 raw_key[16]) 15 + void poly1305_core_setkey(struct poly1305_core_key *key, 16 + const u8 raw_key[POLY1305_BLOCK_SIZE]) 16 17 { 17 18 u64 t0, t1; 18 19
+2 -1
lib/crypto/poly1305.c
··· 12 12 #include <linux/module.h> 13 13 #include <asm/unaligned.h> 14 14 15 - void poly1305_init_generic(struct poly1305_desc_ctx *desc, const u8 *key) 15 + void poly1305_init_generic(struct poly1305_desc_ctx *desc, 16 + const u8 key[POLY1305_KEY_SIZE]) 16 17 { 17 18 poly1305_core_setkey(&desc->core_r, key); 18 19 desc->s[0] = get_unaligned_le32(key + 16);
+24
lib/oid_registry.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/errno.h> 13 13 #include <linux/bug.h> 14 + #include <linux/asn1.h> 14 15 #include "oid_registry_data.c" 15 16 16 17 MODULE_DESCRIPTION("OID Registry"); ··· 92 91 return OID__NR; 93 92 } 94 93 EXPORT_SYMBOL_GPL(look_up_OID); 94 + 95 + /** 96 + * parse_OID - Parse an OID from a bytestream 97 + * @data: Binary representation of the header + OID 98 + * @datasize: Size of the binary representation 99 + * @oid: Pointer to oid to return result 100 + * 101 + * Parse an OID from a bytestream that holds the OID in the format 102 + * ASN1_OID | length | oid. The length indicator must equal to datasize - 2. 103 + * -EBADMSG is returned if the bytestream is too short. 104 + */ 105 + int parse_OID(const void *data, size_t datasize, enum OID *oid) 106 + { 107 + const unsigned char *v = data; 108 + 109 + /* we need 2 bytes of header and at least 1 byte for oid */ 110 + if (datasize < 3 || v[0] != ASN1_OID || v[1] != datasize - 2) 111 + return -EBADMSG; 112 + 113 + *oid = look_up_OID(data + 2, datasize - 2); 114 + return 0; 115 + } 116 + EXPORT_SYMBOL_GPL(parse_OID); 95 117 96 118 /* 97 119 * sprint_OID - Print an Object Identifier into a buffer
-2
net/bluetooth/ecdh_helper.c
··· 126 126 int err; 127 127 struct ecdh p = {0}; 128 128 129 - p.curve_id = ECC_CURVE_NIST_P256; 130 - 131 129 if (private_key) { 132 130 tmp = kmalloc(32, GFP_KERNEL); 133 131 if (!tmp)
+1 -1
net/bluetooth/selftest.c
··· 205 205 206 206 calltime = ktime_get(); 207 207 208 - tfm = crypto_alloc_kpp("ecdh", 0, 0); 208 + tfm = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); 209 209 if (IS_ERR(tfm)) { 210 210 BT_ERR("Unable to create ECDH crypto context"); 211 211 err = PTR_ERR(tfm);
+3 -3
net/bluetooth/smp.c
··· 1386 1386 goto zfree_smp; 1387 1387 } 1388 1388 1389 - smp->tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); 1389 + smp->tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); 1390 1390 if (IS_ERR(smp->tfm_ecdh)) { 1391 1391 BT_ERR("Unable to create ECDH crypto context"); 1392 1392 goto free_shash; ··· 3281 3281 return ERR_CAST(tfm_cmac); 3282 3282 } 3283 3283 3284 - tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); 3284 + tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); 3285 3285 if (IS_ERR(tfm_ecdh)) { 3286 3286 BT_ERR("Unable to create ECDH crypto context"); 3287 3287 crypto_free_shash(tfm_cmac); ··· 3806 3806 return PTR_ERR(tfm_cmac); 3807 3807 } 3808 3808 3809 - tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); 3809 + tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); 3810 3810 if (IS_ERR(tfm_ecdh)) { 3811 3811 BT_ERR("Unable to create ECDH crypto context"); 3812 3812 crypto_free_shash(tfm_cmac);
+14 -16
security/integrity/digsig_asymmetric.c
··· 84 84 { 85 85 struct public_key_signature pks; 86 86 struct signature_v2_hdr *hdr = (struct signature_v2_hdr *)sig; 87 + const struct public_key *pk; 87 88 struct key *key; 88 89 int ret; 89 90 ··· 106 105 memset(&pks, 0, sizeof(pks)); 107 106 108 107 pks.hash_algo = hash_algo_name[hdr->hash_algo]; 109 - switch (hdr->hash_algo) { 110 - case HASH_ALGO_STREEBOG_256: 111 - case HASH_ALGO_STREEBOG_512: 112 - /* EC-RDSA and Streebog should go together. */ 113 - pks.pkey_algo = "ecrdsa"; 114 - pks.encoding = "raw"; 115 - break; 116 - case HASH_ALGO_SM3_256: 117 - /* SM2 and SM3 should go together. */ 118 - pks.pkey_algo = "sm2"; 119 - pks.encoding = "raw"; 120 - break; 121 - default: 122 - pks.pkey_algo = "rsa"; 108 + 109 + pk = asymmetric_key_public_key(key); 110 + pks.pkey_algo = pk->pkey_algo; 111 + if (!strcmp(pk->pkey_algo, "rsa")) 123 112 pks.encoding = "pkcs1"; 124 - break; 125 - } 113 + else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) 114 + /* edcsa-nist-p192 etc. */ 115 + pks.encoding = "x962"; 116 + else if (!strcmp(pk->pkey_algo, "ecrdsa") || 117 + !strcmp(pk->pkey_algo, "sm2")) 118 + pks.encoding = "raw"; 119 + else 120 + return -ENOPKG; 121 + 126 122 pks.digest = (u8 *)data; 127 123 pks.digest_size = datalen; 128 124 pks.s = hdr->sig;