1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __NITROX_REQ_H 3 #define __NITROX_REQ_H 4 5 #include <linux/dma-mapping.h> 6 #include <crypto/aes.h> 7 8 #include "nitrox_dev.h" 9 10 /** 11 * struct gphdr - General purpose Header 12 * @param0: first parameter. 13 * @param1: second parameter. 14 * @param2: third parameter. 15 * @param3: fourth parameter. 16 * 17 * Params tell the iv and enc/dec data offsets. 18 */ 19 struct gphdr { 20 __be16 param0; 21 __be16 param1; 22 __be16 param2; 23 __be16 param3; 24 }; 25 26 /** 27 * struct se_req_ctrl - SE request information. 28 * @arg: Minor number of the opcode 29 * @ctxc: Context control. 30 * @unca: Uncertainity enabled. 31 * @info: Additional information for SE cores. 32 * @ctxl: Context length in bytes. 33 * @uddl: User defined data length 34 */ 35 union se_req_ctrl { 36 u64 value; 37 struct { 38 u64 raz : 22; 39 u64 arg : 8; 40 u64 ctxc : 2; 41 u64 unca : 1; 42 u64 info : 3; 43 u64 unc : 8; 44 u64 ctxl : 12; 45 u64 uddl : 8; 46 } s; 47 }; 48 49 struct nitrox_sglist { 50 u16 len; 51 u16 raz0; 52 u32 raz1; 53 dma_addr_t dma; 54 }; 55 56 #define MAX_IV_LEN 16 57 58 /** 59 * struct se_crypto_request - SE crypto request structure. 60 * @opcode: Request opcode (enc/dec) 61 * @flags: flags from crypto subsystem 62 * @ctx_handle: Crypto context handle. 63 * @gph: GP Header 64 * @ctrl: Request Information. 65 * @in: Input sglist 66 * @out: Output sglist 67 */ 68 struct se_crypto_request { 69 u8 opcode; 70 gfp_t gfp; 71 u32 flags; 72 u64 ctx_handle; 73 74 struct gphdr gph; 75 union se_req_ctrl ctrl; 76 77 u8 iv[MAX_IV_LEN]; 78 u16 ivsize; 79 80 struct scatterlist *src; 81 struct scatterlist *dst; 82 }; 83 84 /* Crypto opcodes */ 85 #define FLEXI_CRYPTO_ENCRYPT_HMAC 0x33 86 #define ENCRYPT 0 87 #define DECRYPT 1 88 89 /* IV from context */ 90 #define IV_FROM_CTX 0 91 /* IV from Input data */ 92 #define IV_FROM_DPTR 1 93 94 /** 95 * cipher opcodes for firmware 96 */ 97 enum flexi_cipher { 98 CIPHER_NULL = 0, 99 CIPHER_3DES_CBC, 100 CIPHER_3DES_ECB, 101 CIPHER_AES_CBC, 102 CIPHER_AES_ECB, 103 CIPHER_AES_CFB, 104 CIPHER_AES_CTR, 105 CIPHER_AES_GCM, 106 CIPHER_AES_XTS, 107 CIPHER_AES_CCM, 108 CIPHER_AES_CBC_CTS, 109 CIPHER_AES_ECB_CTS, 110 CIPHER_INVALID 111 }; 112 113 /** 114 * struct crypto_keys - Crypto keys 115 * @key: Encryption key or KEY1 for AES-XTS 116 * @iv: Encryption IV or Tweak for AES-XTS 117 */ 118 struct crypto_keys { 119 union { 120 u8 key[AES_MAX_KEY_SIZE]; 121 u8 key1[AES_MAX_KEY_SIZE]; 122 } u; 123 u8 iv[AES_BLOCK_SIZE]; 124 }; 125 126 /** 127 * struct auth_keys - Authentication keys 128 * @ipad: IPAD or KEY2 for AES-XTS 129 * @opad: OPAD or AUTH KEY if auth_input_type = 1 130 */ 131 struct auth_keys { 132 union { 133 u8 ipad[64]; 134 u8 key2[64]; 135 } u; 136 u8 opad[64]; 137 }; 138 139 /** 140 * struct flexi_crypto_context - Crypto context 141 * @cipher_type: Encryption cipher type 142 * @aes_keylen: AES key length 143 * @iv_source: Encryption IV source 144 * @hash_type: Authentication type 145 * @auth_input_type: Authentication input type 146 * 1 - Authentication IV and KEY, microcode calculates OPAD/IPAD 147 * 0 - Authentication OPAD/IPAD 148 * @mac_len: mac length 149 * @crypto: Crypto keys 150 * @auth: Authentication keys 151 */ 152 struct flexi_crypto_context { 153 union { 154 __be64 flags; 155 struct { 156 #if defined(__BIG_ENDIAN_BITFIELD) 157 u64 cipher_type : 4; 158 u64 reserved_59 : 1; 159 u64 aes_keylen : 2; 160 u64 iv_source : 1; 161 u64 hash_type : 4; 162 u64 reserved_49_51 : 3; 163 u64 auth_input_type: 1; 164 u64 mac_len : 8; 165 u64 reserved_0_39 : 40; 166 #else 167 u64 reserved_0_39 : 40; 168 u64 mac_len : 8; 169 u64 auth_input_type: 1; 170 u64 reserved_49_51 : 3; 171 u64 hash_type : 4; 172 u64 iv_source : 1; 173 u64 aes_keylen : 2; 174 u64 reserved_59 : 1; 175 u64 cipher_type : 4; 176 #endif 177 } w0; 178 }; 179 180 struct crypto_keys crypto; 181 struct auth_keys auth; 182 }; 183 184 struct crypto_ctx_hdr { 185 struct dma_pool *pool; 186 dma_addr_t dma; 187 void *vaddr; 188 }; 189 190 struct nitrox_crypto_ctx { 191 struct nitrox_device *ndev; 192 union { 193 u64 ctx_handle; 194 struct flexi_crypto_context *fctx; 195 } u; 196 struct crypto_ctx_hdr *chdr; 197 }; 198 199 struct nitrox_kcrypt_request { 200 struct se_crypto_request creq; 201 struct nitrox_crypto_ctx *nctx; 202 struct skcipher_request *skreq; 203 }; 204 205 /** 206 * struct pkt_instr_hdr - Packet Instruction Header 207 * @g: Gather used 208 * When [G] is set and [GSZ] != 0, the instruction is 209 * indirect gather instruction. 210 * When [G] is set and [GSZ] = 0, the instruction is 211 * direct gather instruction. 212 * @gsz: Number of pointers in the indirect gather list 213 * @ihi: When set hardware duplicates the 1st 8 bytes of pkt_instr_hdr 214 * and adds them to the packet after the pkt_instr_hdr but before any UDD 215 * @ssz: Not used by the input hardware. But can become slc_store_int[SSZ] 216 * when [IHI] is set. 217 * @fsz: The number of front data bytes directly included in the 218 * PCIe instruction. 219 * @tlen: The length of the input packet in bytes, include: 220 * - 16B pkt_hdr 221 * - Inline context bytes if any, 222 * - UDD if any, 223 * - packet payload bytes 224 */ 225 union pkt_instr_hdr { 226 u64 value; 227 struct { 228 #if defined(__BIG_ENDIAN_BITFIELD) 229 u64 raz_48_63 : 16; 230 u64 g : 1; 231 u64 gsz : 7; 232 u64 ihi : 1; 233 u64 ssz : 7; 234 u64 raz_30_31 : 2; 235 u64 fsz : 6; 236 u64 raz_16_23 : 8; 237 u64 tlen : 16; 238 #else 239 u64 tlen : 16; 240 u64 raz_16_23 : 8; 241 u64 fsz : 6; 242 u64 raz_30_31 : 2; 243 u64 ssz : 7; 244 u64 ihi : 1; 245 u64 gsz : 7; 246 u64 g : 1; 247 u64 raz_48_63 : 16; 248 #endif 249 } s; 250 }; 251 252 /** 253 * struct pkt_hdr - Packet Input Header 254 * @opcode: Request opcode (Major) 255 * @arg: Request opcode (Minor) 256 * @ctxc: Context control. 257 * @unca: When set [UNC] is the uncertainty count for an input packet. 258 * The hardware uses uncertainty counts to predict 259 * output buffer use and avoid deadlock. 260 * @info: Not used by input hardware. Available for use 261 * during SE processing. 262 * @destport: The expected destination port/ring/channel for the packet. 263 * @unc: Uncertainty count for an input packet. 264 * @grp: SE group that will process the input packet. 265 * @ctxl: Context Length in 64-bit words. 266 * @uddl: User-defined data (UDD) length in bytes. 267 * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases. 268 */ 269 union pkt_hdr { 270 u64 value[2]; 271 struct { 272 #if defined(__BIG_ENDIAN_BITFIELD) 273 u64 opcode : 8; 274 u64 arg : 8; 275 u64 ctxc : 2; 276 u64 unca : 1; 277 u64 raz_44 : 1; 278 u64 info : 3; 279 u64 destport : 9; 280 u64 unc : 8; 281 u64 raz_19_23 : 5; 282 u64 grp : 3; 283 u64 raz_15 : 1; 284 u64 ctxl : 7; 285 u64 uddl : 8; 286 #else 287 u64 uddl : 8; 288 u64 ctxl : 7; 289 u64 raz_15 : 1; 290 u64 grp : 3; 291 u64 raz_19_23 : 5; 292 u64 unc : 8; 293 u64 destport : 9; 294 u64 info : 3; 295 u64 raz_44 : 1; 296 u64 unca : 1; 297 u64 ctxc : 2; 298 u64 arg : 8; 299 u64 opcode : 8; 300 #endif 301 __be64 ctxp; 302 } s; 303 }; 304 305 /** 306 * struct slc_store_info - Solicited Paceket Output Store Information. 307 * @ssz: The number of scatterlist pointers for the solicited output port 308 * packet. 309 * @rptr: The result pointer for the solicited output port packet. 310 * If [SSZ]=0, [RPTR] must point directly to a buffer on the remote 311 * host that is large enough to hold the entire output packet. 312 * If [SSZ]!=0, [RPTR] must point to an array of ([SSZ]+3)/4 313 * sglist components at [RPTR] on the remote host. 314 */ 315 union slc_store_info { 316 u64 value[2]; 317 struct { 318 #if defined(__BIG_ENDIAN_BITFIELD) 319 u64 raz_39_63 : 25; 320 u64 ssz : 7; 321 u64 raz_0_31 : 32; 322 #else 323 u64 raz_0_31 : 32; 324 u64 ssz : 7; 325 u64 raz_39_63 : 25; 326 #endif 327 __be64 rptr; 328 } s; 329 }; 330 331 /** 332 * struct nps_pkt_instr - NPS Packet Instruction of SE cores. 333 * @dptr0 : Input pointer points to buffer in remote host. 334 * @ih: Packet Instruction Header (8 bytes) 335 * @irh: Packet Input Header (16 bytes) 336 * @slc: Solicited Packet Output Store Information (16 bytes) 337 * @fdata: Front data 338 * 339 * 64-Byte Instruction Format 340 */ 341 struct nps_pkt_instr { 342 __be64 dptr0; 343 union pkt_instr_hdr ih; 344 union pkt_hdr irh; 345 union slc_store_info slc; 346 u64 fdata[2]; 347 }; 348 349 /** 350 * struct ctx_hdr - Book keeping data about the crypto context 351 * @pool: Pool used to allocate crypto context 352 * @dma: Base DMA address of the cypto context 353 * @ctx_dma: Actual usable crypto context for NITROX 354 */ 355 struct ctx_hdr { 356 struct dma_pool *pool; 357 dma_addr_t dma; 358 dma_addr_t ctx_dma; 359 }; 360 361 /* 362 * struct sglist_component - SG list component format 363 * @len0: The number of bytes at [PTR0] on the remote host. 364 * @len1: The number of bytes at [PTR1] on the remote host. 365 * @len2: The number of bytes at [PTR2] on the remote host. 366 * @len3: The number of bytes at [PTR3] on the remote host. 367 * @dma0: First pointer point to buffer in remote host. 368 * @dma1: Second pointer point to buffer in remote host. 369 * @dma2: Third pointer point to buffer in remote host. 370 * @dma3: Fourth pointer point to buffer in remote host. 371 */ 372 struct nitrox_sgcomp { 373 __be16 len[4]; 374 __be64 dma[4]; 375 }; 376 377 /* 378 * strutct nitrox_sgtable - SG list information 379 * @map_cnt: Number of buffers mapped 380 * @nr_comp: Number of sglist components 381 * @total_bytes: Total bytes in sglist. 382 * @len: Total sglist components length. 383 * @dma: DMA address of sglist component. 384 * @dir: DMA direction. 385 * @buf: crypto request buffer. 386 * @sglist: SG list of input/output buffers. 387 * @sgcomp: sglist component for NITROX. 388 */ 389 struct nitrox_sgtable { 390 u8 map_bufs_cnt; 391 u8 nr_sgcomp; 392 u16 total_bytes; 393 u32 len; 394 dma_addr_t dma; 395 enum dma_data_direction dir; 396 397 struct scatterlist *buf; 398 struct nitrox_sglist *sglist; 399 struct nitrox_sgcomp *sgcomp; 400 }; 401 402 /* Response Header Length */ 403 #define ORH_HLEN 8 404 /* Completion bytes Length */ 405 #define COMP_HLEN 8 406 407 struct resp_hdr { 408 u64 orh; 409 dma_addr_t orh_dma; 410 u64 completion; 411 dma_addr_t completion_dma; 412 }; 413 414 typedef void (*completion_t)(struct skcipher_request *skreq, int err); 415 416 /** 417 * struct nitrox_softreq - Represents the NIROX Request. 418 * @response: response list entry 419 * @backlog: Backlog list entry 420 * @ndev: Device used to submit the request 421 * @cmdq: Command queue for submission 422 * @resp: Response headers 423 * @instr: 64B instruction 424 * @in: SG table for input 425 * @out SG table for output 426 * @tstamp: Request submitted time in jiffies 427 * @callback: callback after request completion/timeout 428 * @cb_arg: callback argument 429 */ 430 struct nitrox_softreq { 431 struct list_head response; 432 struct list_head backlog; 433 434 u32 flags; 435 gfp_t gfp; 436 atomic_t status; 437 bool inplace; 438 439 struct nitrox_device *ndev; 440 struct nitrox_cmdq *cmdq; 441 442 struct nps_pkt_instr instr; 443 struct resp_hdr resp; 444 struct nitrox_sgtable in; 445 struct nitrox_sgtable out; 446 447 unsigned long tstamp; 448 449 completion_t callback; 450 struct skcipher_request *skreq; 451 }; 452 453 #endif /* __NITROX_REQ_H */ 454