nitrox_req.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. #define PENDING_SIG 0xFFFFFFFFFFFFFFFFUL
  8. #define PRIO 4001
  9. typedef void (*sereq_completion_t)(void *req, int err);
  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. * struct se_req_ctrl - SE request information.
  27. * @arg: Minor number of the opcode
  28. * @ctxc: Context control.
  29. * @unca: Uncertainity enabled.
  30. * @info: Additional information for SE cores.
  31. * @ctxl: Context length in bytes.
  32. * @uddl: User defined data length
  33. */
  34. union se_req_ctrl {
  35. u64 value;
  36. struct {
  37. u64 raz : 22;
  38. u64 arg : 8;
  39. u64 ctxc : 2;
  40. u64 unca : 1;
  41. u64 info : 3;
  42. u64 unc : 8;
  43. u64 ctxl : 12;
  44. u64 uddl : 8;
  45. } s;
  46. };
  47. #define MAX_IV_LEN 16
  48. /**
  49. * struct se_crypto_request - SE crypto request structure.
  50. * @opcode: Request opcode (enc/dec)
  51. * @flags: flags from crypto subsystem
  52. * @ctx_handle: Crypto context handle.
  53. * @gph: GP Header
  54. * @ctrl: Request Information.
  55. * @orh: ORH address
  56. * @comp: completion address
  57. * @src: Input sglist
  58. * @dst: Output sglist
  59. */
  60. struct se_crypto_request {
  61. u8 opcode;
  62. gfp_t gfp;
  63. u32 flags;
  64. u64 ctx_handle;
  65. struct gphdr gph;
  66. union se_req_ctrl ctrl;
  67. u64 *orh;
  68. u64 *comp;
  69. struct scatterlist *src;
  70. struct scatterlist *dst;
  71. };
  72. /* Crypto opcodes */
  73. #define FLEXI_CRYPTO_ENCRYPT_HMAC 0x33
  74. #define ENCRYPT 0
  75. #define DECRYPT 1
  76. /* IV from context */
  77. #define IV_FROM_CTX 0
  78. /* IV from Input data */
  79. #define IV_FROM_DPTR 1
  80. /**
  81. * cipher opcodes for firmware
  82. */
  83. enum flexi_cipher {
  84. CIPHER_NULL = 0,
  85. CIPHER_3DES_CBC,
  86. CIPHER_3DES_ECB,
  87. CIPHER_AES_CBC,
  88. CIPHER_AES_ECB,
  89. CIPHER_AES_CFB,
  90. CIPHER_AES_CTR,
  91. CIPHER_AES_GCM,
  92. CIPHER_AES_XTS,
  93. CIPHER_AES_CCM,
  94. CIPHER_AES_CBC_CTS,
  95. CIPHER_AES_ECB_CTS,
  96. CIPHER_INVALID
  97. };
  98. enum flexi_auth {
  99. AUTH_NULL = 0,
  100. AUTH_MD5,
  101. AUTH_SHA1,
  102. AUTH_SHA2_SHA224,
  103. AUTH_SHA2_SHA256,
  104. AUTH_SHA2_SHA384,
  105. AUTH_SHA2_SHA512,
  106. AUTH_GMAC,
  107. AUTH_INVALID
  108. };
  109. /**
  110. * struct crypto_keys - Crypto keys
  111. * @key: Encryption key or KEY1 for AES-XTS
  112. * @iv: Encryption IV or Tweak for AES-XTS
  113. */
  114. struct crypto_keys {
  115. union {
  116. u8 key[AES_MAX_KEY_SIZE];
  117. u8 key1[AES_MAX_KEY_SIZE];
  118. } u;
  119. u8 iv[AES_BLOCK_SIZE];
  120. };
  121. /**
  122. * struct auth_keys - Authentication keys
  123. * @ipad: IPAD or KEY2 for AES-XTS
  124. * @opad: OPAD or AUTH KEY if auth_input_type = 1
  125. */
  126. struct auth_keys {
  127. union {
  128. u8 ipad[64];
  129. u8 key2[64];
  130. } u;
  131. u8 opad[64];
  132. };
  133. union fc_ctx_flags {
  134. __be64 f;
  135. u64 fu;
  136. struct {
  137. #if defined(__BIG_ENDIAN_BITFIELD)
  138. u64 cipher_type : 4;
  139. u64 reserved_59 : 1;
  140. u64 aes_keylen : 2;
  141. u64 iv_source : 1;
  142. u64 hash_type : 4;
  143. u64 reserved_49_51 : 3;
  144. u64 auth_input_type: 1;
  145. u64 mac_len : 8;
  146. u64 reserved_0_39 : 40;
  147. #else
  148. u64 reserved_0_39 : 40;
  149. u64 mac_len : 8;
  150. u64 auth_input_type: 1;
  151. u64 reserved_49_51 : 3;
  152. u64 hash_type : 4;
  153. u64 iv_source : 1;
  154. u64 aes_keylen : 2;
  155. u64 reserved_59 : 1;
  156. u64 cipher_type : 4;
  157. #endif
  158. } w0;
  159. };
  160. /**
  161. * struct flexi_crypto_context - Crypto context
  162. * @cipher_type: Encryption cipher type
  163. * @aes_keylen: AES key length
  164. * @iv_source: Encryption IV source
  165. * @hash_type: Authentication type
  166. * @auth_input_type: Authentication input type
  167. * 1 - Authentication IV and KEY, microcode calculates OPAD/IPAD
  168. * 0 - Authentication OPAD/IPAD
  169. * @mac_len: mac length
  170. * @crypto: Crypto keys
  171. * @auth: Authentication keys
  172. */
  173. struct flexi_crypto_context {
  174. union fc_ctx_flags flags;
  175. struct crypto_keys crypto;
  176. struct auth_keys auth;
  177. };
  178. struct crypto_ctx_hdr {
  179. struct dma_pool *pool;
  180. dma_addr_t dma;
  181. void *vaddr;
  182. };
  183. struct nitrox_crypto_ctx {
  184. struct nitrox_device *ndev;
  185. union {
  186. u64 ctx_handle;
  187. struct flexi_crypto_context *fctx;
  188. } u;
  189. struct crypto_ctx_hdr *chdr;
  190. sereq_completion_t callback;
  191. };
  192. struct nitrox_kcrypt_request {
  193. struct se_crypto_request creq;
  194. u8 *src;
  195. u8 *dst;
  196. u8 *iv_out;
  197. };
  198. /**
  199. * struct nitrox_aead_rctx - AEAD request context
  200. * @nkreq: Base request context
  201. * @cryptlen: Encryption/Decryption data length
  202. * @assoclen: AAD length
  203. * @srclen: Input buffer length
  204. * @dstlen: Output buffer length
  205. * @iv: IV data
  206. * @ivsize: IV data length
  207. * @flags: AEAD req flags
  208. * @ctx_handle: Device context handle
  209. * @src: Source sglist
  210. * @dst: Destination sglist
  211. * @ctrl_arg: Identifies the request type (ENCRYPT/DECRYPT)
  212. */
  213. struct nitrox_aead_rctx {
  214. struct nitrox_kcrypt_request nkreq;
  215. unsigned int cryptlen;
  216. unsigned int assoclen;
  217. unsigned int srclen;
  218. unsigned int dstlen;
  219. u8 *iv;
  220. int ivsize;
  221. u32 flags;
  222. u64 ctx_handle;
  223. struct scatterlist *src;
  224. struct scatterlist *dst;
  225. u8 ctrl_arg;
  226. };
  227. /**
  228. * struct nitrox_rfc4106_rctx - rfc4106 cipher request context
  229. * @base: AEAD request context
  230. * @src: Source sglist
  231. * @dst: Destination sglist
  232. * @assoc: AAD
  233. */
  234. struct nitrox_rfc4106_rctx {
  235. struct nitrox_aead_rctx base;
  236. struct scatterlist src[3];
  237. struct scatterlist dst[3];
  238. u8 assoc[20];
  239. };
  240. /**
  241. * struct pkt_instr_hdr - Packet Instruction Header
  242. * @g: Gather used
  243. * When [G] is set and [GSZ] != 0, the instruction is
  244. * indirect gather instruction.
  245. * When [G] is set and [GSZ] = 0, the instruction is
  246. * direct gather instruction.
  247. * @gsz: Number of pointers in the indirect gather list
  248. * @ihi: When set hardware duplicates the 1st 8 bytes of pkt_instr_hdr
  249. * and adds them to the packet after the pkt_instr_hdr but before any UDD
  250. * @ssz: Not used by the input hardware. But can become slc_store_int[SSZ]
  251. * when [IHI] is set.
  252. * @fsz: The number of front data bytes directly included in the
  253. * PCIe instruction.
  254. * @tlen: The length of the input packet in bytes, include:
  255. * - 16B pkt_hdr
  256. * - Inline context bytes if any,
  257. * - UDD if any,
  258. * - packet payload bytes
  259. */
  260. union pkt_instr_hdr {
  261. __be64 bev;
  262. u64 value;
  263. struct {
  264. #if defined(__BIG_ENDIAN_BITFIELD)
  265. u64 raz_48_63 : 16;
  266. u64 g : 1;
  267. u64 gsz : 7;
  268. u64 ihi : 1;
  269. u64 ssz : 7;
  270. u64 raz_30_31 : 2;
  271. u64 fsz : 6;
  272. u64 raz_16_23 : 8;
  273. u64 tlen : 16;
  274. #else
  275. u64 tlen : 16;
  276. u64 raz_16_23 : 8;
  277. u64 fsz : 6;
  278. u64 raz_30_31 : 2;
  279. u64 ssz : 7;
  280. u64 ihi : 1;
  281. u64 gsz : 7;
  282. u64 g : 1;
  283. u64 raz_48_63 : 16;
  284. #endif
  285. } s;
  286. };
  287. /**
  288. * struct pkt_hdr - Packet Input Header
  289. * @opcode: Request opcode (Major)
  290. * @arg: Request opcode (Minor)
  291. * @ctxc: Context control.
  292. * @unca: When set [UNC] is the uncertainty count for an input packet.
  293. * The hardware uses uncertainty counts to predict
  294. * output buffer use and avoid deadlock.
  295. * @info: Not used by input hardware. Available for use
  296. * during SE processing.
  297. * @destport: The expected destination port/ring/channel for the packet.
  298. * @unc: Uncertainty count for an input packet.
  299. * @grp: SE group that will process the input packet.
  300. * @ctxl: Context Length in 64-bit words.
  301. * @uddl: User-defined data (UDD) length in bytes.
  302. * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases.
  303. */
  304. union pkt_hdr {
  305. __be64 bev[2];
  306. u64 value[2];
  307. struct {
  308. #if defined(__BIG_ENDIAN_BITFIELD)
  309. u64 opcode : 8;
  310. u64 arg : 8;
  311. u64 ctxc : 2;
  312. u64 unca : 1;
  313. u64 raz_44 : 1;
  314. u64 info : 3;
  315. u64 destport : 9;
  316. u64 unc : 8;
  317. u64 raz_19_23 : 5;
  318. u64 grp : 3;
  319. u64 raz_15 : 1;
  320. u64 ctxl : 7;
  321. u64 uddl : 8;
  322. #else
  323. u64 uddl : 8;
  324. u64 ctxl : 7;
  325. u64 raz_15 : 1;
  326. u64 grp : 3;
  327. u64 raz_19_23 : 5;
  328. u64 unc : 8;
  329. u64 destport : 9;
  330. u64 info : 3;
  331. u64 raz_44 : 1;
  332. u64 unca : 1;
  333. u64 ctxc : 2;
  334. u64 arg : 8;
  335. u64 opcode : 8;
  336. #endif
  337. __be64 ctxp;
  338. } s;
  339. };
  340. /**
  341. * struct slc_store_info - Solicited Paceket Output Store Information.
  342. * @ssz: The number of scatterlist pointers for the solicited output port
  343. * packet.
  344. * @rptr: The result pointer for the solicited output port packet.
  345. * If [SSZ]=0, [RPTR] must point directly to a buffer on the remote
  346. * host that is large enough to hold the entire output packet.
  347. * If [SSZ]!=0, [RPTR] must point to an array of ([SSZ]+3)/4
  348. * sglist components at [RPTR] on the remote host.
  349. */
  350. union slc_store_info {
  351. __be64 bev[2];
  352. u64 value[2];
  353. struct {
  354. #if defined(__BIG_ENDIAN_BITFIELD)
  355. u64 raz_39_63 : 25;
  356. u64 ssz : 7;
  357. u64 raz_0_31 : 32;
  358. #else
  359. u64 raz_0_31 : 32;
  360. u64 ssz : 7;
  361. u64 raz_39_63 : 25;
  362. #endif
  363. __be64 rptr;
  364. } s;
  365. };
  366. /**
  367. * struct nps_pkt_instr - NPS Packet Instruction of SE cores.
  368. * @dptr0 : Input pointer points to buffer in remote host.
  369. * @ih: Packet Instruction Header (8 bytes)
  370. * @irh: Packet Input Header (16 bytes)
  371. * @slc: Solicited Packet Output Store Information (16 bytes)
  372. * @fdata: Front data
  373. *
  374. * 64-Byte Instruction Format
  375. */
  376. struct nps_pkt_instr {
  377. __be64 dptr0;
  378. union pkt_instr_hdr ih;
  379. union pkt_hdr irh;
  380. union slc_store_info slc;
  381. u64 fdata[2];
  382. };
  383. /**
  384. * struct aqmq_command_s - The 32 byte command for AE processing.
  385. * @opcode: Request opcode
  386. * @param1: Request control parameter 1
  387. * @param2: Request control parameter 2
  388. * @dlen: Input length
  389. * @dptr: Input pointer points to buffer in remote host
  390. * @rptr: Result pointer points to buffer in remote host
  391. * @grp: AQM Group (0..7)
  392. * @cptr: Context pointer
  393. */
  394. struct aqmq_command_s {
  395. __be16 opcode;
  396. __be16 param1;
  397. __be16 param2;
  398. __be16 dlen;
  399. __be64 dptr;
  400. __be64 rptr;
  401. union {
  402. __be64 word3;
  403. #if defined(__BIG_ENDIAN_BITFIELD)
  404. u64 grp : 3;
  405. u64 cptr : 61;
  406. #else
  407. u64 cptr : 61;
  408. u64 grp : 3;
  409. #endif
  410. };
  411. };
  412. /**
  413. * struct ctx_hdr - Book keeping data about the crypto context
  414. * @pool: Pool used to allocate crypto context
  415. * @dma: Base DMA address of the crypto context
  416. * @ctx_dma: Actual usable crypto context for NITROX
  417. */
  418. struct ctx_hdr {
  419. struct dma_pool *pool;
  420. dma_addr_t dma;
  421. dma_addr_t ctx_dma;
  422. };
  423. /*
  424. * struct sglist_component - SG list component format
  425. * @len0: The number of bytes at [PTR0] on the remote host.
  426. * @len1: The number of bytes at [PTR1] on the remote host.
  427. * @len2: The number of bytes at [PTR2] on the remote host.
  428. * @len3: The number of bytes at [PTR3] on the remote host.
  429. * @dma0: First pointer point to buffer in remote host.
  430. * @dma1: Second pointer point to buffer in remote host.
  431. * @dma2: Third pointer point to buffer in remote host.
  432. * @dma3: Fourth pointer point to buffer in remote host.
  433. */
  434. struct nitrox_sgcomp {
  435. __be16 len[4];
  436. __be64 dma[4];
  437. };
  438. /*
  439. * strutct nitrox_sgtable - SG list information
  440. * @sgmap_cnt: Number of buffers mapped
  441. * @total_bytes: Total bytes in sglist.
  442. * @sgcomp_len: Total sglist components length.
  443. * @sgcomp_dma: DMA address of sglist component.
  444. * @sg: crypto request buffer.
  445. * @sgcomp: sglist component for NITROX.
  446. */
  447. struct nitrox_sgtable {
  448. u8 sgmap_cnt;
  449. u16 total_bytes;
  450. u32 sgcomp_len;
  451. dma_addr_t sgcomp_dma;
  452. struct scatterlist *sg;
  453. struct nitrox_sgcomp *sgcomp;
  454. };
  455. /* Response Header Length */
  456. #define ORH_HLEN 8
  457. /* Completion bytes Length */
  458. #define COMP_HLEN 8
  459. struct resp_hdr {
  460. u64 *orh;
  461. u64 *completion;
  462. };
  463. typedef void (*completion_t)(void *arg, int err);
  464. /**
  465. * struct nitrox_softreq - Represents the NIROX Request.
  466. * @response: response list entry
  467. * @backlog: Backlog list entry
  468. * @ndev: Device used to submit the request
  469. * @cmdq: Command queue for submission
  470. * @resp: Response headers
  471. * @instr: 64B instruction
  472. * @in: SG table for input
  473. * @out SG table for output
  474. * @tstamp: Request submitted time in jiffies
  475. * @callback: callback after request completion/timeout
  476. * @cb_arg: callback argument
  477. */
  478. struct nitrox_softreq {
  479. struct list_head response;
  480. struct list_head backlog;
  481. u32 flags;
  482. gfp_t gfp;
  483. atomic_t status;
  484. struct nitrox_device *ndev;
  485. struct nitrox_cmdq *cmdq;
  486. struct nps_pkt_instr instr;
  487. struct resp_hdr resp;
  488. struct nitrox_sgtable in;
  489. struct nitrox_sgtable out;
  490. unsigned long tstamp;
  491. completion_t callback;
  492. void *cb_arg;
  493. };
  494. static inline int flexi_aes_keylen(int keylen)
  495. {
  496. int aes_keylen;
  497. switch (keylen) {
  498. case AES_KEYSIZE_128:
  499. aes_keylen = 1;
  500. break;
  501. case AES_KEYSIZE_192:
  502. aes_keylen = 2;
  503. break;
  504. case AES_KEYSIZE_256:
  505. aes_keylen = 3;
  506. break;
  507. default:
  508. aes_keylen = -EINVAL;
  509. break;
  510. }
  511. return aes_keylen;
  512. }
  513. static inline void *alloc_req_buf(int nents, int extralen, gfp_t gfp)
  514. {
  515. size_t size;
  516. size = sizeof(struct scatterlist) * nents;
  517. size += extralen;
  518. return kzalloc(size, gfp);
  519. }
  520. /**
  521. * create_single_sg - Point SG entry to the data
  522. * @sg: Destination SG list
  523. * @buf: Data
  524. * @buflen: Data length
  525. *
  526. * Returns next free entry in the destination SG list
  527. **/
  528. static inline struct scatterlist *create_single_sg(struct scatterlist *sg,
  529. void *buf, int buflen)
  530. {
  531. sg_set_buf(sg, buf, buflen);
  532. sg++;
  533. return sg;
  534. }
  535. /**
  536. * create_multi_sg - Create multiple sg entries with buflen data length from
  537. * source sglist
  538. * @to_sg: Destination SG list
  539. * @from_sg: Source SG list
  540. * @buflen: Data length
  541. *
  542. * Returns next free entry in the destination SG list
  543. **/
  544. static inline struct scatterlist *create_multi_sg(struct scatterlist *to_sg,
  545. struct scatterlist *from_sg,
  546. int buflen)
  547. {
  548. struct scatterlist *sg = to_sg;
  549. unsigned int sglen;
  550. for (; buflen && from_sg; buflen -= sglen) {
  551. sglen = from_sg->length;
  552. if (sglen > buflen)
  553. sglen = buflen;
  554. sg_set_buf(sg, sg_virt(from_sg), sglen);
  555. from_sg = sg_next(from_sg);
  556. sg++;
  557. }
  558. return sg;
  559. }
  560. static inline void set_orh_value(u64 *orh)
  561. {
  562. WRITE_ONCE(*orh, PENDING_SIG);
  563. }
  564. static inline void set_comp_value(u64 *comp)
  565. {
  566. WRITE_ONCE(*comp, PENDING_SIG);
  567. }
  568. static inline int alloc_src_req_buf(struct nitrox_kcrypt_request *nkreq,
  569. int nents, int ivsize)
  570. {
  571. struct se_crypto_request *creq = &nkreq->creq;
  572. nkreq->src = alloc_req_buf(nents, ivsize, creq->gfp);
  573. if (!nkreq->src)
  574. return -ENOMEM;
  575. return 0;
  576. }
  577. static inline void nitrox_creq_copy_iv(char *dst, char *src, int size)
  578. {
  579. memcpy(dst, src, size);
  580. }
  581. static inline struct scatterlist *nitrox_creq_src_sg(char *iv, int ivsize)
  582. {
  583. return (struct scatterlist *)(iv + ivsize);
  584. }
  585. static inline void nitrox_creq_set_src_sg(struct nitrox_kcrypt_request *nkreq,
  586. int nents, int ivsize,
  587. struct scatterlist *src, int buflen)
  588. {
  589. char *iv = nkreq->src;
  590. struct scatterlist *sg;
  591. struct se_crypto_request *creq = &nkreq->creq;
  592. creq->src = nitrox_creq_src_sg(iv, ivsize);
  593. sg = creq->src;
  594. sg_init_table(sg, nents);
  595. /* Input format:
  596. * +----+----------------+
  597. * | IV | SRC sg entries |
  598. * +----+----------------+
  599. */
  600. /* IV */
  601. sg = create_single_sg(sg, iv, ivsize);
  602. /* SRC entries */
  603. create_multi_sg(sg, src, buflen);
  604. }
  605. static inline int alloc_dst_req_buf(struct nitrox_kcrypt_request *nkreq,
  606. int nents)
  607. {
  608. int extralen = ORH_HLEN + COMP_HLEN;
  609. struct se_crypto_request *creq = &nkreq->creq;
  610. nkreq->dst = alloc_req_buf(nents, extralen, creq->gfp);
  611. if (!nkreq->dst)
  612. return -ENOMEM;
  613. return 0;
  614. }
  615. static inline void nitrox_creq_set_orh(struct nitrox_kcrypt_request *nkreq)
  616. {
  617. struct se_crypto_request *creq = &nkreq->creq;
  618. creq->orh = (u64 *)(nkreq->dst);
  619. set_orh_value(creq->orh);
  620. }
  621. static inline void nitrox_creq_set_comp(struct nitrox_kcrypt_request *nkreq)
  622. {
  623. struct se_crypto_request *creq = &nkreq->creq;
  624. creq->comp = (u64 *)(nkreq->dst + ORH_HLEN);
  625. set_comp_value(creq->comp);
  626. }
  627. static inline struct scatterlist *nitrox_creq_dst_sg(char *dst)
  628. {
  629. return (struct scatterlist *)(dst + ORH_HLEN + COMP_HLEN);
  630. }
  631. static inline void nitrox_creq_set_dst_sg(struct nitrox_kcrypt_request *nkreq,
  632. int nents, int ivsize,
  633. struct scatterlist *dst, int buflen)
  634. {
  635. struct se_crypto_request *creq = &nkreq->creq;
  636. struct scatterlist *sg;
  637. char *iv = nkreq->src;
  638. creq->dst = nitrox_creq_dst_sg(nkreq->dst);
  639. sg = creq->dst;
  640. sg_init_table(sg, nents);
  641. /* Output format:
  642. * +-----+----+----------------+-----------------+
  643. * | ORH | IV | DST sg entries | COMPLETION Bytes|
  644. * +-----+----+----------------+-----------------+
  645. */
  646. /* ORH */
  647. sg = create_single_sg(sg, creq->orh, ORH_HLEN);
  648. /* IV */
  649. sg = create_single_sg(sg, iv, ivsize);
  650. /* DST entries */
  651. sg = create_multi_sg(sg, dst, buflen);
  652. /* COMPLETION Bytes */
  653. create_single_sg(sg, creq->comp, COMP_HLEN);
  654. }
  655. #endif /* __NITROX_REQ_H */