nitrox_req.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 crypto_ctx_hdr {
  167. struct dma_pool *pool;
  168. dma_addr_t dma;
  169. void *vaddr;
  170. };
  171. struct nitrox_crypto_ctx {
  172. struct nitrox_device *ndev;
  173. union {
  174. u64 ctx_handle;
  175. struct flexi_crypto_context *fctx;
  176. } u;
  177. struct crypto_ctx_hdr *chdr;
  178. };
  179. struct nitrox_kcrypt_request {
  180. struct se_crypto_request creq;
  181. struct nitrox_crypto_ctx *nctx;
  182. struct skcipher_request *skreq;
  183. };
  184. /**
  185. * struct pkt_instr_hdr - Packet Instruction Header
  186. * @g: Gather used
  187. * When [G] is set and [GSZ] != 0, the instruction is
  188. * indirect gather instruction.
  189. * When [G] is set and [GSZ] = 0, the instruction is
  190. * direct gather instruction.
  191. * @gsz: Number of pointers in the indirect gather list
  192. * @ihi: When set hardware duplicates the 1st 8 bytes of pkt_instr_hdr
  193. * and adds them to the packet after the pkt_instr_hdr but before any UDD
  194. * @ssz: Not used by the input hardware. But can become slc_store_int[SSZ]
  195. * when [IHI] is set.
  196. * @fsz: The number of front data bytes directly included in the
  197. * PCIe instruction.
  198. * @tlen: The length of the input packet in bytes, include:
  199. * - 16B pkt_hdr
  200. * - Inline context bytes if any,
  201. * - UDD if any,
  202. * - packet payload bytes
  203. */
  204. union pkt_instr_hdr {
  205. u64 value;
  206. struct {
  207. #if defined(__BIG_ENDIAN_BITFIELD)
  208. u64 raz_48_63 : 16;
  209. u64 g : 1;
  210. u64 gsz : 7;
  211. u64 ihi : 1;
  212. u64 ssz : 7;
  213. u64 raz_30_31 : 2;
  214. u64 fsz : 6;
  215. u64 raz_16_23 : 8;
  216. u64 tlen : 16;
  217. #else
  218. u64 tlen : 16;
  219. u64 raz_16_23 : 8;
  220. u64 fsz : 6;
  221. u64 raz_30_31 : 2;
  222. u64 ssz : 7;
  223. u64 ihi : 1;
  224. u64 gsz : 7;
  225. u64 g : 1;
  226. u64 raz_48_63 : 16;
  227. #endif
  228. } s;
  229. };
  230. /**
  231. * struct pkt_hdr - Packet Input Header
  232. * @opcode: Request opcode (Major)
  233. * @arg: Request opcode (Minor)
  234. * @ctxc: Context control.
  235. * @unca: When set [UNC] is the uncertainty count for an input packet.
  236. * The hardware uses uncertainty counts to predict
  237. * output buffer use and avoid deadlock.
  238. * @info: Not used by input hardware. Available for use
  239. * during SE processing.
  240. * @destport: The expected destination port/ring/channel for the packet.
  241. * @unc: Uncertainty count for an input packet.
  242. * @grp: SE group that will process the input packet.
  243. * @ctxl: Context Length in 64-bit words.
  244. * @uddl: User-defined data (UDD) length in bytes.
  245. * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases.
  246. */
  247. union pkt_hdr {
  248. u64 value[2];
  249. struct {
  250. #if defined(__BIG_ENDIAN_BITFIELD)
  251. u64 opcode : 8;
  252. u64 arg : 8;
  253. u64 ctxc : 2;
  254. u64 unca : 1;
  255. u64 raz_44 : 1;
  256. u64 info : 3;
  257. u64 destport : 9;
  258. u64 unc : 8;
  259. u64 raz_19_23 : 5;
  260. u64 grp : 3;
  261. u64 raz_15 : 1;
  262. u64 ctxl : 7;
  263. u64 uddl : 8;
  264. #else
  265. u64 uddl : 8;
  266. u64 ctxl : 7;
  267. u64 raz_15 : 1;
  268. u64 grp : 3;
  269. u64 raz_19_23 : 5;
  270. u64 unc : 8;
  271. u64 destport : 9;
  272. u64 info : 3;
  273. u64 raz_44 : 1;
  274. u64 unca : 1;
  275. u64 ctxc : 2;
  276. u64 arg : 8;
  277. u64 opcode : 8;
  278. #endif
  279. __be64 ctxp;
  280. } s;
  281. };
  282. /**
  283. * struct slc_store_info - Solicited Paceket Output Store Information.
  284. * @ssz: The number of scatterlist pointers for the solicited output port
  285. * packet.
  286. * @rptr: The result pointer for the solicited output port packet.
  287. * If [SSZ]=0, [RPTR] must point directly to a buffer on the remote
  288. * host that is large enough to hold the entire output packet.
  289. * If [SSZ]!=0, [RPTR] must point to an array of ([SSZ]+3)/4
  290. * sglist components at [RPTR] on the remote host.
  291. */
  292. union slc_store_info {
  293. u64 value[2];
  294. struct {
  295. #if defined(__BIG_ENDIAN_BITFIELD)
  296. u64 raz_39_63 : 25;
  297. u64 ssz : 7;
  298. u64 raz_0_31 : 32;
  299. #else
  300. u64 raz_0_31 : 32;
  301. u64 ssz : 7;
  302. u64 raz_39_63 : 25;
  303. #endif
  304. __be64 rptr;
  305. } s;
  306. };
  307. /**
  308. * struct nps_pkt_instr - NPS Packet Instruction of SE cores.
  309. * @dptr0 : Input pointer points to buffer in remote host.
  310. * @ih: Packet Instruction Header (8 bytes)
  311. * @irh: Packet Input Header (16 bytes)
  312. * @slc: Solicited Packet Output Store Information (16 bytes)
  313. * @fdata: Front data
  314. *
  315. * 64-Byte Instruction Format
  316. */
  317. struct nps_pkt_instr {
  318. __be64 dptr0;
  319. union pkt_instr_hdr ih;
  320. union pkt_hdr irh;
  321. union slc_store_info slc;
  322. u64 fdata[2];
  323. };
  324. /**
  325. * struct ctx_hdr - Book keeping data about the crypto context
  326. * @pool: Pool used to allocate crypto context
  327. * @dma: Base DMA address of the cypto context
  328. * @ctx_dma: Actual usable crypto context for NITROX
  329. */
  330. struct ctx_hdr {
  331. struct dma_pool *pool;
  332. dma_addr_t dma;
  333. dma_addr_t ctx_dma;
  334. };
  335. /*
  336. * struct sglist_component - SG list component format
  337. * @len0: The number of bytes at [PTR0] on the remote host.
  338. * @len1: The number of bytes at [PTR1] on the remote host.
  339. * @len2: The number of bytes at [PTR2] on the remote host.
  340. * @len3: The number of bytes at [PTR3] on the remote host.
  341. * @dma0: First pointer point to buffer in remote host.
  342. * @dma1: Second pointer point to buffer in remote host.
  343. * @dma2: Third pointer point to buffer in remote host.
  344. * @dma3: Fourth pointer point to buffer in remote host.
  345. */
  346. struct nitrox_sgcomp {
  347. __be16 len[4];
  348. __be64 dma[4];
  349. };
  350. /*
  351. * strutct nitrox_sgtable - SG list information
  352. * @map_cnt: Number of buffers mapped
  353. * @nr_comp: Number of sglist components
  354. * @total_bytes: Total bytes in sglist.
  355. * @len: Total sglist components length.
  356. * @dma: DMA address of sglist component.
  357. * @dir: DMA direction.
  358. * @buf: crypto request buffer.
  359. * @sglist: SG list of input/output buffers.
  360. * @sgcomp: sglist component for NITROX.
  361. */
  362. struct nitrox_sgtable {
  363. u8 map_bufs_cnt;
  364. u8 nr_sgcomp;
  365. u16 total_bytes;
  366. u32 len;
  367. dma_addr_t dma;
  368. enum dma_data_direction dir;
  369. struct scatterlist *buf;
  370. struct nitrox_sglist *sglist;
  371. struct nitrox_sgcomp *sgcomp;
  372. };
  373. /* Response Header Length */
  374. #define ORH_HLEN 8
  375. /* Completion bytes Length */
  376. #define COMP_HLEN 8
  377. struct resp_hdr {
  378. u64 orh;
  379. dma_addr_t orh_dma;
  380. u64 completion;
  381. dma_addr_t completion_dma;
  382. };
  383. typedef void (*completion_t)(struct skcipher_request *skreq, int err);
  384. /**
  385. * struct nitrox_softreq - Represents the NIROX Request.
  386. * @response: response list entry
  387. * @backlog: Backlog list entry
  388. * @ndev: Device used to submit the request
  389. * @cmdq: Command queue for submission
  390. * @resp: Response headers
  391. * @instr: 64B instruction
  392. * @in: SG table for input
  393. * @out SG table for output
  394. * @tstamp: Request submitted time in jiffies
  395. * @callback: callback after request completion/timeout
  396. * @cb_arg: callback argument
  397. */
  398. struct nitrox_softreq {
  399. struct list_head response;
  400. struct list_head backlog;
  401. u32 flags;
  402. gfp_t gfp;
  403. atomic_t status;
  404. bool inplace;
  405. struct nitrox_device *ndev;
  406. struct nitrox_cmdq *cmdq;
  407. struct nps_pkt_instr instr;
  408. struct resp_hdr resp;
  409. struct nitrox_sgtable in;
  410. struct nitrox_sgtable out;
  411. unsigned long tstamp;
  412. completion_t callback;
  413. struct skcipher_request *skreq;
  414. };
  415. #endif /* __NITROX_REQ_H */