18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __NITROX_REQ_H
38c2ecf20Sopenharmony_ci#define __NITROX_REQ_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
68c2ecf20Sopenharmony_ci#include <crypto/aes.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "nitrox_dev.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define PENDING_SIG	0xFFFFFFFFFFFFFFFFUL
118c2ecf20Sopenharmony_ci#define PRIO 4001
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_citypedef void (*sereq_completion_t)(void *req, int err);
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/**
168c2ecf20Sopenharmony_ci * struct gphdr - General purpose Header
178c2ecf20Sopenharmony_ci * @param0: first parameter.
188c2ecf20Sopenharmony_ci * @param1: second parameter.
198c2ecf20Sopenharmony_ci * @param2: third parameter.
208c2ecf20Sopenharmony_ci * @param3: fourth parameter.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Params tell the iv and enc/dec data offsets.
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_cistruct gphdr {
258c2ecf20Sopenharmony_ci	__be16 param0;
268c2ecf20Sopenharmony_ci	__be16 param1;
278c2ecf20Sopenharmony_ci	__be16 param2;
288c2ecf20Sopenharmony_ci	__be16 param3;
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/**
328c2ecf20Sopenharmony_ci * struct se_req_ctrl - SE request information.
338c2ecf20Sopenharmony_ci * @arg: Minor number of the opcode
348c2ecf20Sopenharmony_ci * @ctxc: Context control.
358c2ecf20Sopenharmony_ci * @unca: Uncertainity enabled.
368c2ecf20Sopenharmony_ci * @info: Additional information for SE cores.
378c2ecf20Sopenharmony_ci * @ctxl: Context length in bytes.
388c2ecf20Sopenharmony_ci * @uddl: User defined data length
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ciunion se_req_ctrl {
418c2ecf20Sopenharmony_ci	u64 value;
428c2ecf20Sopenharmony_ci	struct {
438c2ecf20Sopenharmony_ci		u64 raz	: 22;
448c2ecf20Sopenharmony_ci		u64 arg	: 8;
458c2ecf20Sopenharmony_ci		u64 ctxc : 2;
468c2ecf20Sopenharmony_ci		u64 unca : 1;
478c2ecf20Sopenharmony_ci		u64 info : 3;
488c2ecf20Sopenharmony_ci		u64 unc : 8;
498c2ecf20Sopenharmony_ci		u64 ctxl : 12;
508c2ecf20Sopenharmony_ci		u64 uddl : 8;
518c2ecf20Sopenharmony_ci	} s;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define MAX_IV_LEN 16
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/**
578c2ecf20Sopenharmony_ci * struct se_crypto_request - SE crypto request structure.
588c2ecf20Sopenharmony_ci * @opcode: Request opcode (enc/dec)
598c2ecf20Sopenharmony_ci * @flags: flags from crypto subsystem
608c2ecf20Sopenharmony_ci * @ctx_handle: Crypto context handle.
618c2ecf20Sopenharmony_ci * @gph: GP Header
628c2ecf20Sopenharmony_ci * @ctrl: Request Information.
638c2ecf20Sopenharmony_ci * @orh: ORH address
648c2ecf20Sopenharmony_ci * @comp: completion address
658c2ecf20Sopenharmony_ci * @src: Input sglist
668c2ecf20Sopenharmony_ci * @dst: Output sglist
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_cistruct se_crypto_request {
698c2ecf20Sopenharmony_ci	u8 opcode;
708c2ecf20Sopenharmony_ci	gfp_t gfp;
718c2ecf20Sopenharmony_ci	u32 flags;
728c2ecf20Sopenharmony_ci	u64 ctx_handle;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	struct gphdr gph;
758c2ecf20Sopenharmony_ci	union se_req_ctrl ctrl;
768c2ecf20Sopenharmony_ci	u64 *orh;
778c2ecf20Sopenharmony_ci	u64 *comp;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	struct scatterlist *src;
808c2ecf20Sopenharmony_ci	struct scatterlist *dst;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* Crypto opcodes */
848c2ecf20Sopenharmony_ci#define FLEXI_CRYPTO_ENCRYPT_HMAC	0x33
858c2ecf20Sopenharmony_ci#define ENCRYPT	0
868c2ecf20Sopenharmony_ci#define DECRYPT 1
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* IV from context */
898c2ecf20Sopenharmony_ci#define IV_FROM_CTX	0
908c2ecf20Sopenharmony_ci/* IV from Input data */
918c2ecf20Sopenharmony_ci#define IV_FROM_DPTR	1
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/**
948c2ecf20Sopenharmony_ci * cipher opcodes for firmware
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cienum flexi_cipher {
978c2ecf20Sopenharmony_ci	CIPHER_NULL = 0,
988c2ecf20Sopenharmony_ci	CIPHER_3DES_CBC,
998c2ecf20Sopenharmony_ci	CIPHER_3DES_ECB,
1008c2ecf20Sopenharmony_ci	CIPHER_AES_CBC,
1018c2ecf20Sopenharmony_ci	CIPHER_AES_ECB,
1028c2ecf20Sopenharmony_ci	CIPHER_AES_CFB,
1038c2ecf20Sopenharmony_ci	CIPHER_AES_CTR,
1048c2ecf20Sopenharmony_ci	CIPHER_AES_GCM,
1058c2ecf20Sopenharmony_ci	CIPHER_AES_XTS,
1068c2ecf20Sopenharmony_ci	CIPHER_AES_CCM,
1078c2ecf20Sopenharmony_ci	CIPHER_AES_CBC_CTS,
1088c2ecf20Sopenharmony_ci	CIPHER_AES_ECB_CTS,
1098c2ecf20Sopenharmony_ci	CIPHER_INVALID
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cienum flexi_auth {
1138c2ecf20Sopenharmony_ci	AUTH_NULL = 0,
1148c2ecf20Sopenharmony_ci	AUTH_MD5,
1158c2ecf20Sopenharmony_ci	AUTH_SHA1,
1168c2ecf20Sopenharmony_ci	AUTH_SHA2_SHA224,
1178c2ecf20Sopenharmony_ci	AUTH_SHA2_SHA256,
1188c2ecf20Sopenharmony_ci	AUTH_SHA2_SHA384,
1198c2ecf20Sopenharmony_ci	AUTH_SHA2_SHA512,
1208c2ecf20Sopenharmony_ci	AUTH_GMAC,
1218c2ecf20Sopenharmony_ci	AUTH_INVALID
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/**
1258c2ecf20Sopenharmony_ci * struct crypto_keys - Crypto keys
1268c2ecf20Sopenharmony_ci * @key: Encryption key or KEY1 for AES-XTS
1278c2ecf20Sopenharmony_ci * @iv: Encryption IV or Tweak for AES-XTS
1288c2ecf20Sopenharmony_ci */
1298c2ecf20Sopenharmony_cistruct crypto_keys {
1308c2ecf20Sopenharmony_ci	union {
1318c2ecf20Sopenharmony_ci		u8 key[AES_MAX_KEY_SIZE];
1328c2ecf20Sopenharmony_ci		u8 key1[AES_MAX_KEY_SIZE];
1338c2ecf20Sopenharmony_ci	} u;
1348c2ecf20Sopenharmony_ci	u8 iv[AES_BLOCK_SIZE];
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/**
1388c2ecf20Sopenharmony_ci * struct auth_keys - Authentication keys
1398c2ecf20Sopenharmony_ci * @ipad: IPAD or KEY2 for AES-XTS
1408c2ecf20Sopenharmony_ci * @opad: OPAD or AUTH KEY if auth_input_type = 1
1418c2ecf20Sopenharmony_ci */
1428c2ecf20Sopenharmony_cistruct auth_keys {
1438c2ecf20Sopenharmony_ci	union {
1448c2ecf20Sopenharmony_ci		u8 ipad[64];
1458c2ecf20Sopenharmony_ci		u8 key2[64];
1468c2ecf20Sopenharmony_ci	} u;
1478c2ecf20Sopenharmony_ci	u8 opad[64];
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciunion fc_ctx_flags {
1518c2ecf20Sopenharmony_ci	__be64 f;
1528c2ecf20Sopenharmony_ci	struct {
1538c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD)
1548c2ecf20Sopenharmony_ci		u64 cipher_type	: 4;
1558c2ecf20Sopenharmony_ci		u64 reserved_59	: 1;
1568c2ecf20Sopenharmony_ci		u64 aes_keylen : 2;
1578c2ecf20Sopenharmony_ci		u64 iv_source : 1;
1588c2ecf20Sopenharmony_ci		u64 hash_type : 4;
1598c2ecf20Sopenharmony_ci		u64 reserved_49_51 : 3;
1608c2ecf20Sopenharmony_ci		u64 auth_input_type: 1;
1618c2ecf20Sopenharmony_ci		u64 mac_len : 8;
1628c2ecf20Sopenharmony_ci		u64 reserved_0_39 : 40;
1638c2ecf20Sopenharmony_ci#else
1648c2ecf20Sopenharmony_ci		u64 reserved_0_39 : 40;
1658c2ecf20Sopenharmony_ci		u64 mac_len : 8;
1668c2ecf20Sopenharmony_ci		u64 auth_input_type: 1;
1678c2ecf20Sopenharmony_ci		u64 reserved_49_51 : 3;
1688c2ecf20Sopenharmony_ci		u64 hash_type : 4;
1698c2ecf20Sopenharmony_ci		u64 iv_source : 1;
1708c2ecf20Sopenharmony_ci		u64 aes_keylen : 2;
1718c2ecf20Sopenharmony_ci		u64 reserved_59	: 1;
1728c2ecf20Sopenharmony_ci		u64 cipher_type	: 4;
1738c2ecf20Sopenharmony_ci#endif
1748c2ecf20Sopenharmony_ci	} w0;
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci/**
1778c2ecf20Sopenharmony_ci * struct flexi_crypto_context - Crypto context
1788c2ecf20Sopenharmony_ci * @cipher_type: Encryption cipher type
1798c2ecf20Sopenharmony_ci * @aes_keylen: AES key length
1808c2ecf20Sopenharmony_ci * @iv_source: Encryption IV source
1818c2ecf20Sopenharmony_ci * @hash_type: Authentication type
1828c2ecf20Sopenharmony_ci * @auth_input_type: Authentication input type
1838c2ecf20Sopenharmony_ci *   1 - Authentication IV and KEY, microcode calculates OPAD/IPAD
1848c2ecf20Sopenharmony_ci *   0 - Authentication OPAD/IPAD
1858c2ecf20Sopenharmony_ci * @mac_len: mac length
1868c2ecf20Sopenharmony_ci * @crypto: Crypto keys
1878c2ecf20Sopenharmony_ci * @auth: Authentication keys
1888c2ecf20Sopenharmony_ci */
1898c2ecf20Sopenharmony_cistruct flexi_crypto_context {
1908c2ecf20Sopenharmony_ci	union fc_ctx_flags flags;
1918c2ecf20Sopenharmony_ci	struct crypto_keys crypto;
1928c2ecf20Sopenharmony_ci	struct auth_keys auth;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistruct crypto_ctx_hdr {
1968c2ecf20Sopenharmony_ci	struct dma_pool *pool;
1978c2ecf20Sopenharmony_ci	dma_addr_t dma;
1988c2ecf20Sopenharmony_ci	void *vaddr;
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistruct nitrox_crypto_ctx {
2028c2ecf20Sopenharmony_ci	struct nitrox_device *ndev;
2038c2ecf20Sopenharmony_ci	union {
2048c2ecf20Sopenharmony_ci		u64 ctx_handle;
2058c2ecf20Sopenharmony_ci		struct flexi_crypto_context *fctx;
2068c2ecf20Sopenharmony_ci	} u;
2078c2ecf20Sopenharmony_ci	struct crypto_ctx_hdr *chdr;
2088c2ecf20Sopenharmony_ci	sereq_completion_t callback;
2098c2ecf20Sopenharmony_ci};
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistruct nitrox_kcrypt_request {
2128c2ecf20Sopenharmony_ci	struct se_crypto_request creq;
2138c2ecf20Sopenharmony_ci	u8 *src;
2148c2ecf20Sopenharmony_ci	u8 *dst;
2158c2ecf20Sopenharmony_ci	u8 *iv_out;
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/**
2198c2ecf20Sopenharmony_ci * struct nitrox_aead_rctx - AEAD request context
2208c2ecf20Sopenharmony_ci * @nkreq: Base request context
2218c2ecf20Sopenharmony_ci * @cryptlen: Encryption/Decryption data length
2228c2ecf20Sopenharmony_ci * @assoclen: AAD length
2238c2ecf20Sopenharmony_ci * @srclen: Input buffer length
2248c2ecf20Sopenharmony_ci * @dstlen: Output buffer length
2258c2ecf20Sopenharmony_ci * @iv: IV data
2268c2ecf20Sopenharmony_ci * @ivsize: IV data length
2278c2ecf20Sopenharmony_ci * @flags: AEAD req flags
2288c2ecf20Sopenharmony_ci * @ctx_handle: Device context handle
2298c2ecf20Sopenharmony_ci * @src: Source sglist
2308c2ecf20Sopenharmony_ci * @dst: Destination sglist
2318c2ecf20Sopenharmony_ci * @ctrl_arg: Identifies the request type (ENCRYPT/DECRYPT)
2328c2ecf20Sopenharmony_ci */
2338c2ecf20Sopenharmony_cistruct nitrox_aead_rctx {
2348c2ecf20Sopenharmony_ci	struct nitrox_kcrypt_request nkreq;
2358c2ecf20Sopenharmony_ci	unsigned int cryptlen;
2368c2ecf20Sopenharmony_ci	unsigned int assoclen;
2378c2ecf20Sopenharmony_ci	unsigned int srclen;
2388c2ecf20Sopenharmony_ci	unsigned int dstlen;
2398c2ecf20Sopenharmony_ci	u8 *iv;
2408c2ecf20Sopenharmony_ci	int ivsize;
2418c2ecf20Sopenharmony_ci	u32 flags;
2428c2ecf20Sopenharmony_ci	u64 ctx_handle;
2438c2ecf20Sopenharmony_ci	struct scatterlist *src;
2448c2ecf20Sopenharmony_ci	struct scatterlist *dst;
2458c2ecf20Sopenharmony_ci	u8 ctrl_arg;
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/**
2498c2ecf20Sopenharmony_ci * struct nitrox_rfc4106_rctx - rfc4106 cipher request context
2508c2ecf20Sopenharmony_ci * @base: AEAD request context
2518c2ecf20Sopenharmony_ci * @src: Source sglist
2528c2ecf20Sopenharmony_ci * @dst: Destination sglist
2538c2ecf20Sopenharmony_ci * @assoc: AAD
2548c2ecf20Sopenharmony_ci */
2558c2ecf20Sopenharmony_cistruct nitrox_rfc4106_rctx {
2568c2ecf20Sopenharmony_ci	struct nitrox_aead_rctx base;
2578c2ecf20Sopenharmony_ci	struct scatterlist src[3];
2588c2ecf20Sopenharmony_ci	struct scatterlist dst[3];
2598c2ecf20Sopenharmony_ci	u8 assoc[20];
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/**
2638c2ecf20Sopenharmony_ci * struct pkt_instr_hdr - Packet Instruction Header
2648c2ecf20Sopenharmony_ci * @g: Gather used
2658c2ecf20Sopenharmony_ci *   When [G] is set and [GSZ] != 0, the instruction is
2668c2ecf20Sopenharmony_ci *   indirect gather instruction.
2678c2ecf20Sopenharmony_ci *   When [G] is set and [GSZ] = 0, the instruction is
2688c2ecf20Sopenharmony_ci *   direct gather instruction.
2698c2ecf20Sopenharmony_ci * @gsz: Number of pointers in the indirect gather list
2708c2ecf20Sopenharmony_ci * @ihi: When set hardware duplicates the 1st 8 bytes of pkt_instr_hdr
2718c2ecf20Sopenharmony_ci *   and adds them to the packet after the pkt_instr_hdr but before any UDD
2728c2ecf20Sopenharmony_ci * @ssz: Not used by the input hardware. But can become slc_store_int[SSZ]
2738c2ecf20Sopenharmony_ci *   when [IHI] is set.
2748c2ecf20Sopenharmony_ci * @fsz: The number of front data bytes directly included in the
2758c2ecf20Sopenharmony_ci *   PCIe instruction.
2768c2ecf20Sopenharmony_ci * @tlen: The length of the input packet in bytes, include:
2778c2ecf20Sopenharmony_ci *   - 16B pkt_hdr
2788c2ecf20Sopenharmony_ci *   - Inline context bytes if any,
2798c2ecf20Sopenharmony_ci *   - UDD if any,
2808c2ecf20Sopenharmony_ci *   - packet payload bytes
2818c2ecf20Sopenharmony_ci */
2828c2ecf20Sopenharmony_ciunion pkt_instr_hdr {
2838c2ecf20Sopenharmony_ci	u64 value;
2848c2ecf20Sopenharmony_ci	struct {
2858c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD)
2868c2ecf20Sopenharmony_ci		u64 raz_48_63 : 16;
2878c2ecf20Sopenharmony_ci		u64 g : 1;
2888c2ecf20Sopenharmony_ci		u64 gsz	: 7;
2898c2ecf20Sopenharmony_ci		u64 ihi	: 1;
2908c2ecf20Sopenharmony_ci		u64 ssz	: 7;
2918c2ecf20Sopenharmony_ci		u64 raz_30_31 : 2;
2928c2ecf20Sopenharmony_ci		u64 fsz	: 6;
2938c2ecf20Sopenharmony_ci		u64 raz_16_23 : 8;
2948c2ecf20Sopenharmony_ci		u64 tlen : 16;
2958c2ecf20Sopenharmony_ci#else
2968c2ecf20Sopenharmony_ci		u64 tlen : 16;
2978c2ecf20Sopenharmony_ci		u64 raz_16_23 : 8;
2988c2ecf20Sopenharmony_ci		u64 fsz	: 6;
2998c2ecf20Sopenharmony_ci		u64 raz_30_31 : 2;
3008c2ecf20Sopenharmony_ci		u64 ssz	: 7;
3018c2ecf20Sopenharmony_ci		u64 ihi	: 1;
3028c2ecf20Sopenharmony_ci		u64 gsz	: 7;
3038c2ecf20Sopenharmony_ci		u64 g : 1;
3048c2ecf20Sopenharmony_ci		u64 raz_48_63 : 16;
3058c2ecf20Sopenharmony_ci#endif
3068c2ecf20Sopenharmony_ci	} s;
3078c2ecf20Sopenharmony_ci};
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/**
3108c2ecf20Sopenharmony_ci * struct pkt_hdr - Packet Input Header
3118c2ecf20Sopenharmony_ci * @opcode: Request opcode (Major)
3128c2ecf20Sopenharmony_ci * @arg: Request opcode (Minor)
3138c2ecf20Sopenharmony_ci * @ctxc: Context control.
3148c2ecf20Sopenharmony_ci * @unca: When set [UNC] is the uncertainty count for an input packet.
3158c2ecf20Sopenharmony_ci *        The hardware uses uncertainty counts to predict
3168c2ecf20Sopenharmony_ci *        output buffer use and avoid deadlock.
3178c2ecf20Sopenharmony_ci * @info: Not used by input hardware. Available for use
3188c2ecf20Sopenharmony_ci *        during SE processing.
3198c2ecf20Sopenharmony_ci * @destport: The expected destination port/ring/channel for the packet.
3208c2ecf20Sopenharmony_ci * @unc: Uncertainty count for an input packet.
3218c2ecf20Sopenharmony_ci * @grp: SE group that will process the input packet.
3228c2ecf20Sopenharmony_ci * @ctxl: Context Length in 64-bit words.
3238c2ecf20Sopenharmony_ci * @uddl: User-defined data (UDD) length in bytes.
3248c2ecf20Sopenharmony_ci * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases.
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_ciunion pkt_hdr {
3278c2ecf20Sopenharmony_ci	u64 value[2];
3288c2ecf20Sopenharmony_ci	struct {
3298c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD)
3308c2ecf20Sopenharmony_ci		u64 opcode : 8;
3318c2ecf20Sopenharmony_ci		u64 arg	: 8;
3328c2ecf20Sopenharmony_ci		u64 ctxc : 2;
3338c2ecf20Sopenharmony_ci		u64 unca : 1;
3348c2ecf20Sopenharmony_ci		u64 raz_44 : 1;
3358c2ecf20Sopenharmony_ci		u64 info : 3;
3368c2ecf20Sopenharmony_ci		u64 destport : 9;
3378c2ecf20Sopenharmony_ci		u64 unc	: 8;
3388c2ecf20Sopenharmony_ci		u64 raz_19_23 : 5;
3398c2ecf20Sopenharmony_ci		u64 grp	: 3;
3408c2ecf20Sopenharmony_ci		u64 raz_15 : 1;
3418c2ecf20Sopenharmony_ci		u64 ctxl : 7;
3428c2ecf20Sopenharmony_ci		u64 uddl : 8;
3438c2ecf20Sopenharmony_ci#else
3448c2ecf20Sopenharmony_ci		u64 uddl : 8;
3458c2ecf20Sopenharmony_ci		u64 ctxl : 7;
3468c2ecf20Sopenharmony_ci		u64 raz_15 : 1;
3478c2ecf20Sopenharmony_ci		u64 grp	: 3;
3488c2ecf20Sopenharmony_ci		u64 raz_19_23 : 5;
3498c2ecf20Sopenharmony_ci		u64 unc	: 8;
3508c2ecf20Sopenharmony_ci		u64 destport : 9;
3518c2ecf20Sopenharmony_ci		u64 info : 3;
3528c2ecf20Sopenharmony_ci		u64 raz_44 : 1;
3538c2ecf20Sopenharmony_ci		u64 unca : 1;
3548c2ecf20Sopenharmony_ci		u64 ctxc : 2;
3558c2ecf20Sopenharmony_ci		u64 arg	: 8;
3568c2ecf20Sopenharmony_ci		u64 opcode : 8;
3578c2ecf20Sopenharmony_ci#endif
3588c2ecf20Sopenharmony_ci		__be64 ctxp;
3598c2ecf20Sopenharmony_ci	} s;
3608c2ecf20Sopenharmony_ci};
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci/**
3638c2ecf20Sopenharmony_ci * struct slc_store_info - Solicited Paceket Output Store Information.
3648c2ecf20Sopenharmony_ci * @ssz: The number of scatterlist pointers for the solicited output port
3658c2ecf20Sopenharmony_ci *       packet.
3668c2ecf20Sopenharmony_ci * @rptr: The result pointer for the solicited output port packet.
3678c2ecf20Sopenharmony_ci *        If [SSZ]=0, [RPTR] must point directly to a buffer on the remote
3688c2ecf20Sopenharmony_ci *        host that is large enough to hold the entire output packet.
3698c2ecf20Sopenharmony_ci *        If [SSZ]!=0, [RPTR] must point to an array of ([SSZ]+3)/4
3708c2ecf20Sopenharmony_ci *        sglist components at [RPTR] on the remote host.
3718c2ecf20Sopenharmony_ci */
3728c2ecf20Sopenharmony_ciunion slc_store_info {
3738c2ecf20Sopenharmony_ci	u64 value[2];
3748c2ecf20Sopenharmony_ci	struct {
3758c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD)
3768c2ecf20Sopenharmony_ci		u64 raz_39_63 : 25;
3778c2ecf20Sopenharmony_ci		u64 ssz	: 7;
3788c2ecf20Sopenharmony_ci		u64 raz_0_31 : 32;
3798c2ecf20Sopenharmony_ci#else
3808c2ecf20Sopenharmony_ci		u64 raz_0_31 : 32;
3818c2ecf20Sopenharmony_ci		u64 ssz	: 7;
3828c2ecf20Sopenharmony_ci		u64 raz_39_63 : 25;
3838c2ecf20Sopenharmony_ci#endif
3848c2ecf20Sopenharmony_ci		__be64 rptr;
3858c2ecf20Sopenharmony_ci	} s;
3868c2ecf20Sopenharmony_ci};
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci/**
3898c2ecf20Sopenharmony_ci * struct nps_pkt_instr - NPS Packet Instruction of SE cores.
3908c2ecf20Sopenharmony_ci * @dptr0 : Input pointer points to buffer in remote host.
3918c2ecf20Sopenharmony_ci * @ih: Packet Instruction Header (8 bytes)
3928c2ecf20Sopenharmony_ci * @irh: Packet Input Header (16 bytes)
3938c2ecf20Sopenharmony_ci * @slc: Solicited Packet Output Store Information (16 bytes)
3948c2ecf20Sopenharmony_ci * @fdata: Front data
3958c2ecf20Sopenharmony_ci *
3968c2ecf20Sopenharmony_ci * 64-Byte Instruction Format
3978c2ecf20Sopenharmony_ci */
3988c2ecf20Sopenharmony_cistruct nps_pkt_instr {
3998c2ecf20Sopenharmony_ci	__be64 dptr0;
4008c2ecf20Sopenharmony_ci	union pkt_instr_hdr ih;
4018c2ecf20Sopenharmony_ci	union pkt_hdr irh;
4028c2ecf20Sopenharmony_ci	union slc_store_info slc;
4038c2ecf20Sopenharmony_ci	u64 fdata[2];
4048c2ecf20Sopenharmony_ci};
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/**
4078c2ecf20Sopenharmony_ci * struct aqmq_command_s - The 32 byte command for AE processing.
4088c2ecf20Sopenharmony_ci * @opcode: Request opcode
4098c2ecf20Sopenharmony_ci * @param1: Request control parameter 1
4108c2ecf20Sopenharmony_ci * @param2: Request control parameter 2
4118c2ecf20Sopenharmony_ci * @dlen: Input length
4128c2ecf20Sopenharmony_ci * @dptr: Input pointer points to buffer in remote host
4138c2ecf20Sopenharmony_ci * @rptr: Result pointer points to buffer in remote host
4148c2ecf20Sopenharmony_ci * @grp: AQM Group (0..7)
4158c2ecf20Sopenharmony_ci * @cptr: Context pointer
4168c2ecf20Sopenharmony_ci */
4178c2ecf20Sopenharmony_cistruct aqmq_command_s {
4188c2ecf20Sopenharmony_ci	__be16 opcode;
4198c2ecf20Sopenharmony_ci	__be16 param1;
4208c2ecf20Sopenharmony_ci	__be16 param2;
4218c2ecf20Sopenharmony_ci	__be16 dlen;
4228c2ecf20Sopenharmony_ci	__be64 dptr;
4238c2ecf20Sopenharmony_ci	__be64 rptr;
4248c2ecf20Sopenharmony_ci	union {
4258c2ecf20Sopenharmony_ci		__be64 word3;
4268c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD)
4278c2ecf20Sopenharmony_ci		u64 grp : 3;
4288c2ecf20Sopenharmony_ci		u64 cptr : 61;
4298c2ecf20Sopenharmony_ci#else
4308c2ecf20Sopenharmony_ci		u64 cptr : 61;
4318c2ecf20Sopenharmony_ci		u64 grp : 3;
4328c2ecf20Sopenharmony_ci#endif
4338c2ecf20Sopenharmony_ci	};
4348c2ecf20Sopenharmony_ci};
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci/**
4378c2ecf20Sopenharmony_ci * struct ctx_hdr - Book keeping data about the crypto context
4388c2ecf20Sopenharmony_ci * @pool: Pool used to allocate crypto context
4398c2ecf20Sopenharmony_ci * @dma: Base DMA address of the cypto context
4408c2ecf20Sopenharmony_ci * @ctx_dma: Actual usable crypto context for NITROX
4418c2ecf20Sopenharmony_ci */
4428c2ecf20Sopenharmony_cistruct ctx_hdr {
4438c2ecf20Sopenharmony_ci	struct dma_pool *pool;
4448c2ecf20Sopenharmony_ci	dma_addr_t dma;
4458c2ecf20Sopenharmony_ci	dma_addr_t ctx_dma;
4468c2ecf20Sopenharmony_ci};
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/*
4498c2ecf20Sopenharmony_ci * struct sglist_component - SG list component format
4508c2ecf20Sopenharmony_ci * @len0: The number of bytes at [PTR0] on the remote host.
4518c2ecf20Sopenharmony_ci * @len1: The number of bytes at [PTR1] on the remote host.
4528c2ecf20Sopenharmony_ci * @len2: The number of bytes at [PTR2] on the remote host.
4538c2ecf20Sopenharmony_ci * @len3: The number of bytes at [PTR3] on the remote host.
4548c2ecf20Sopenharmony_ci * @dma0: First pointer point to buffer in remote host.
4558c2ecf20Sopenharmony_ci * @dma1: Second pointer point to buffer in remote host.
4568c2ecf20Sopenharmony_ci * @dma2: Third pointer point to buffer in remote host.
4578c2ecf20Sopenharmony_ci * @dma3: Fourth pointer point to buffer in remote host.
4588c2ecf20Sopenharmony_ci */
4598c2ecf20Sopenharmony_cistruct nitrox_sgcomp {
4608c2ecf20Sopenharmony_ci	__be16 len[4];
4618c2ecf20Sopenharmony_ci	__be64 dma[4];
4628c2ecf20Sopenharmony_ci};
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci/*
4658c2ecf20Sopenharmony_ci * strutct nitrox_sgtable - SG list information
4668c2ecf20Sopenharmony_ci * @sgmap_cnt: Number of buffers mapped
4678c2ecf20Sopenharmony_ci * @total_bytes: Total bytes in sglist.
4688c2ecf20Sopenharmony_ci * @sgcomp_len: Total sglist components length.
4698c2ecf20Sopenharmony_ci * @sgcomp_dma: DMA address of sglist component.
4708c2ecf20Sopenharmony_ci * @sg: crypto request buffer.
4718c2ecf20Sopenharmony_ci * @sgcomp: sglist component for NITROX.
4728c2ecf20Sopenharmony_ci */
4738c2ecf20Sopenharmony_cistruct nitrox_sgtable {
4748c2ecf20Sopenharmony_ci	u8 sgmap_cnt;
4758c2ecf20Sopenharmony_ci	u16 total_bytes;
4768c2ecf20Sopenharmony_ci	u32 sgcomp_len;
4778c2ecf20Sopenharmony_ci	dma_addr_t sgcomp_dma;
4788c2ecf20Sopenharmony_ci	struct scatterlist *sg;
4798c2ecf20Sopenharmony_ci	struct nitrox_sgcomp *sgcomp;
4808c2ecf20Sopenharmony_ci};
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci/* Response Header Length */
4838c2ecf20Sopenharmony_ci#define ORH_HLEN	8
4848c2ecf20Sopenharmony_ci/* Completion bytes Length */
4858c2ecf20Sopenharmony_ci#define COMP_HLEN	8
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_cistruct resp_hdr {
4888c2ecf20Sopenharmony_ci	u64 *orh;
4898c2ecf20Sopenharmony_ci	u64 *completion;
4908c2ecf20Sopenharmony_ci};
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_citypedef void (*completion_t)(void *arg, int err);
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci/**
4958c2ecf20Sopenharmony_ci * struct nitrox_softreq - Represents the NIROX Request.
4968c2ecf20Sopenharmony_ci * @response: response list entry
4978c2ecf20Sopenharmony_ci * @backlog: Backlog list entry
4988c2ecf20Sopenharmony_ci * @ndev: Device used to submit the request
4998c2ecf20Sopenharmony_ci * @cmdq: Command queue for submission
5008c2ecf20Sopenharmony_ci * @resp: Response headers
5018c2ecf20Sopenharmony_ci * @instr: 64B instruction
5028c2ecf20Sopenharmony_ci * @in: SG table for input
5038c2ecf20Sopenharmony_ci * @out SG table for output
5048c2ecf20Sopenharmony_ci * @tstamp: Request submitted time in jiffies
5058c2ecf20Sopenharmony_ci * @callback: callback after request completion/timeout
5068c2ecf20Sopenharmony_ci * @cb_arg: callback argument
5078c2ecf20Sopenharmony_ci */
5088c2ecf20Sopenharmony_cistruct nitrox_softreq {
5098c2ecf20Sopenharmony_ci	struct list_head response;
5108c2ecf20Sopenharmony_ci	struct list_head backlog;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	u32 flags;
5138c2ecf20Sopenharmony_ci	gfp_t gfp;
5148c2ecf20Sopenharmony_ci	atomic_t status;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	struct nitrox_device *ndev;
5178c2ecf20Sopenharmony_ci	struct nitrox_cmdq *cmdq;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	struct nps_pkt_instr instr;
5208c2ecf20Sopenharmony_ci	struct resp_hdr resp;
5218c2ecf20Sopenharmony_ci	struct nitrox_sgtable in;
5228c2ecf20Sopenharmony_ci	struct nitrox_sgtable out;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	unsigned long tstamp;
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	completion_t callback;
5278c2ecf20Sopenharmony_ci	void *cb_arg;
5288c2ecf20Sopenharmony_ci};
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic inline int flexi_aes_keylen(int keylen)
5318c2ecf20Sopenharmony_ci{
5328c2ecf20Sopenharmony_ci	int aes_keylen;
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci	switch (keylen) {
5358c2ecf20Sopenharmony_ci	case AES_KEYSIZE_128:
5368c2ecf20Sopenharmony_ci		aes_keylen = 1;
5378c2ecf20Sopenharmony_ci		break;
5388c2ecf20Sopenharmony_ci	case AES_KEYSIZE_192:
5398c2ecf20Sopenharmony_ci		aes_keylen = 2;
5408c2ecf20Sopenharmony_ci		break;
5418c2ecf20Sopenharmony_ci	case AES_KEYSIZE_256:
5428c2ecf20Sopenharmony_ci		aes_keylen = 3;
5438c2ecf20Sopenharmony_ci		break;
5448c2ecf20Sopenharmony_ci	default:
5458c2ecf20Sopenharmony_ci		aes_keylen = -EINVAL;
5468c2ecf20Sopenharmony_ci		break;
5478c2ecf20Sopenharmony_ci	}
5488c2ecf20Sopenharmony_ci	return aes_keylen;
5498c2ecf20Sopenharmony_ci}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_cistatic inline void *alloc_req_buf(int nents, int extralen, gfp_t gfp)
5528c2ecf20Sopenharmony_ci{
5538c2ecf20Sopenharmony_ci	size_t size;
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_ci	size = sizeof(struct scatterlist) * nents;
5568c2ecf20Sopenharmony_ci	size += extralen;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	return kzalloc(size, gfp);
5598c2ecf20Sopenharmony_ci}
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci/**
5628c2ecf20Sopenharmony_ci * create_single_sg - Point SG entry to the data
5638c2ecf20Sopenharmony_ci * @sg:		Destination SG list
5648c2ecf20Sopenharmony_ci * @buf:	Data
5658c2ecf20Sopenharmony_ci * @buflen:	Data length
5668c2ecf20Sopenharmony_ci *
5678c2ecf20Sopenharmony_ci * Returns next free entry in the destination SG list
5688c2ecf20Sopenharmony_ci **/
5698c2ecf20Sopenharmony_cistatic inline struct scatterlist *create_single_sg(struct scatterlist *sg,
5708c2ecf20Sopenharmony_ci						   void *buf, int buflen)
5718c2ecf20Sopenharmony_ci{
5728c2ecf20Sopenharmony_ci	sg_set_buf(sg, buf, buflen);
5738c2ecf20Sopenharmony_ci	sg++;
5748c2ecf20Sopenharmony_ci	return sg;
5758c2ecf20Sopenharmony_ci}
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci/**
5788c2ecf20Sopenharmony_ci * create_multi_sg - Create multiple sg entries with buflen data length from
5798c2ecf20Sopenharmony_ci *		     source sglist
5808c2ecf20Sopenharmony_ci * @to_sg:	Destination SG list
5818c2ecf20Sopenharmony_ci * @from_sg:	Source SG list
5828c2ecf20Sopenharmony_ci * @buflen:	Data length
5838c2ecf20Sopenharmony_ci *
5848c2ecf20Sopenharmony_ci * Returns next free entry in the destination SG list
5858c2ecf20Sopenharmony_ci **/
5868c2ecf20Sopenharmony_cistatic inline struct scatterlist *create_multi_sg(struct scatterlist *to_sg,
5878c2ecf20Sopenharmony_ci						  struct scatterlist *from_sg,
5888c2ecf20Sopenharmony_ci						  int buflen)
5898c2ecf20Sopenharmony_ci{
5908c2ecf20Sopenharmony_ci	struct scatterlist *sg = to_sg;
5918c2ecf20Sopenharmony_ci	unsigned int sglen;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	for (; buflen && from_sg; buflen -= sglen) {
5948c2ecf20Sopenharmony_ci		sglen = from_sg->length;
5958c2ecf20Sopenharmony_ci		if (sglen > buflen)
5968c2ecf20Sopenharmony_ci			sglen = buflen;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci		sg_set_buf(sg, sg_virt(from_sg), sglen);
5998c2ecf20Sopenharmony_ci		from_sg = sg_next(from_sg);
6008c2ecf20Sopenharmony_ci		sg++;
6018c2ecf20Sopenharmony_ci	}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	return sg;
6048c2ecf20Sopenharmony_ci}
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_cistatic inline void set_orh_value(u64 *orh)
6078c2ecf20Sopenharmony_ci{
6088c2ecf20Sopenharmony_ci	WRITE_ONCE(*orh, PENDING_SIG);
6098c2ecf20Sopenharmony_ci}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_cistatic inline void set_comp_value(u64 *comp)
6128c2ecf20Sopenharmony_ci{
6138c2ecf20Sopenharmony_ci	WRITE_ONCE(*comp, PENDING_SIG);
6148c2ecf20Sopenharmony_ci}
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_cistatic inline int alloc_src_req_buf(struct nitrox_kcrypt_request *nkreq,
6178c2ecf20Sopenharmony_ci				    int nents, int ivsize)
6188c2ecf20Sopenharmony_ci{
6198c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	nkreq->src = alloc_req_buf(nents, ivsize, creq->gfp);
6228c2ecf20Sopenharmony_ci	if (!nkreq->src)
6238c2ecf20Sopenharmony_ci		return -ENOMEM;
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_ci	return 0;
6268c2ecf20Sopenharmony_ci}
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_cistatic inline void nitrox_creq_copy_iv(char *dst, char *src, int size)
6298c2ecf20Sopenharmony_ci{
6308c2ecf20Sopenharmony_ci	memcpy(dst, src, size);
6318c2ecf20Sopenharmony_ci}
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_cistatic inline struct scatterlist *nitrox_creq_src_sg(char *iv, int ivsize)
6348c2ecf20Sopenharmony_ci{
6358c2ecf20Sopenharmony_ci	return (struct scatterlist *)(iv + ivsize);
6368c2ecf20Sopenharmony_ci}
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cistatic inline void nitrox_creq_set_src_sg(struct nitrox_kcrypt_request *nkreq,
6398c2ecf20Sopenharmony_ci					  int nents, int ivsize,
6408c2ecf20Sopenharmony_ci					  struct scatterlist *src, int buflen)
6418c2ecf20Sopenharmony_ci{
6428c2ecf20Sopenharmony_ci	char *iv = nkreq->src;
6438c2ecf20Sopenharmony_ci	struct scatterlist *sg;
6448c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci	creq->src = nitrox_creq_src_sg(iv, ivsize);
6478c2ecf20Sopenharmony_ci	sg = creq->src;
6488c2ecf20Sopenharmony_ci	sg_init_table(sg, nents);
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	/* Input format:
6518c2ecf20Sopenharmony_ci	 * +----+----------------+
6528c2ecf20Sopenharmony_ci	 * | IV | SRC sg entries |
6538c2ecf20Sopenharmony_ci	 * +----+----------------+
6548c2ecf20Sopenharmony_ci	 */
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	/* IV */
6578c2ecf20Sopenharmony_ci	sg = create_single_sg(sg, iv, ivsize);
6588c2ecf20Sopenharmony_ci	/* SRC entries */
6598c2ecf20Sopenharmony_ci	create_multi_sg(sg, src, buflen);
6608c2ecf20Sopenharmony_ci}
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_cistatic inline int alloc_dst_req_buf(struct nitrox_kcrypt_request *nkreq,
6638c2ecf20Sopenharmony_ci				    int nents)
6648c2ecf20Sopenharmony_ci{
6658c2ecf20Sopenharmony_ci	int extralen = ORH_HLEN + COMP_HLEN;
6668c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	nkreq->dst = alloc_req_buf(nents, extralen, creq->gfp);
6698c2ecf20Sopenharmony_ci	if (!nkreq->dst)
6708c2ecf20Sopenharmony_ci		return -ENOMEM;
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci	return 0;
6738c2ecf20Sopenharmony_ci}
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_cistatic inline void nitrox_creq_set_orh(struct nitrox_kcrypt_request *nkreq)
6768c2ecf20Sopenharmony_ci{
6778c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	creq->orh = (u64 *)(nkreq->dst);
6808c2ecf20Sopenharmony_ci	set_orh_value(creq->orh);
6818c2ecf20Sopenharmony_ci}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_cistatic inline void nitrox_creq_set_comp(struct nitrox_kcrypt_request *nkreq)
6848c2ecf20Sopenharmony_ci{
6858c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci	creq->comp = (u64 *)(nkreq->dst + ORH_HLEN);
6888c2ecf20Sopenharmony_ci	set_comp_value(creq->comp);
6898c2ecf20Sopenharmony_ci}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cistatic inline struct scatterlist *nitrox_creq_dst_sg(char *dst)
6928c2ecf20Sopenharmony_ci{
6938c2ecf20Sopenharmony_ci	return (struct scatterlist *)(dst + ORH_HLEN + COMP_HLEN);
6948c2ecf20Sopenharmony_ci}
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_cistatic inline void nitrox_creq_set_dst_sg(struct nitrox_kcrypt_request *nkreq,
6978c2ecf20Sopenharmony_ci					  int nents, int ivsize,
6988c2ecf20Sopenharmony_ci					  struct scatterlist *dst, int buflen)
6998c2ecf20Sopenharmony_ci{
7008c2ecf20Sopenharmony_ci	struct se_crypto_request *creq = &nkreq->creq;
7018c2ecf20Sopenharmony_ci	struct scatterlist *sg;
7028c2ecf20Sopenharmony_ci	char *iv = nkreq->src;
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	creq->dst = nitrox_creq_dst_sg(nkreq->dst);
7058c2ecf20Sopenharmony_ci	sg = creq->dst;
7068c2ecf20Sopenharmony_ci	sg_init_table(sg, nents);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	/* Output format:
7098c2ecf20Sopenharmony_ci	 * +-----+----+----------------+-----------------+
7108c2ecf20Sopenharmony_ci	 * | ORH | IV | DST sg entries | COMPLETION Bytes|
7118c2ecf20Sopenharmony_ci	 * +-----+----+----------------+-----------------+
7128c2ecf20Sopenharmony_ci	 */
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	/* ORH */
7158c2ecf20Sopenharmony_ci	sg = create_single_sg(sg, creq->orh, ORH_HLEN);
7168c2ecf20Sopenharmony_ci	/* IV */
7178c2ecf20Sopenharmony_ci	sg = create_single_sg(sg, iv, ivsize);
7188c2ecf20Sopenharmony_ci	/* DST entries */
7198c2ecf20Sopenharmony_ci	sg = create_multi_sg(sg, dst, buflen);
7208c2ecf20Sopenharmony_ci	/* COMPLETION Bytes */
7218c2ecf20Sopenharmony_ci	create_single_sg(sg, creq->comp, COMP_HLEN);
7228c2ecf20Sopenharmony_ci}
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci#endif /* __NITROX_REQ_H */
725