nitrox_req.h 9.9 KB

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