1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/dma-mapping.h>
6 #include <crypto/aes.h>
8 #include "nitrox_dev.h"
11 * struct gphdr - General purpose Header
12 * @param0: first parameter.
13 * @param1: second parameter.
14 * @param2: third parameter.
15 * @param3: fourth parameter.
17 * Params tell the iv and enc/dec data offsets.
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
49 struct nitrox_sglist
{
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.
64 * @ctrl: Request Information.
68 struct se_crypto_request
{
75 union se_req_ctrl ctrl
;
80 struct scatterlist
*src
;
81 struct scatterlist
*dst
;
85 #define FLEXI_CRYPTO_ENCRYPT_HMAC 0x33
91 /* IV from Input data */
92 #define IV_FROM_DPTR 1
95 * cipher opcodes for firmware
114 * struct crypto_keys - Crypto keys
115 * @key: Encryption key or KEY1 for AES-XTS
116 * @iv: Encryption IV or Tweak for AES-XTS
120 u8 key
[AES_MAX_KEY_SIZE
];
121 u8 key1
[AES_MAX_KEY_SIZE
];
123 u8 iv
[AES_BLOCK_SIZE
];
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
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
152 struct flexi_crypto_context
{
156 #if defined(__BIG_ENDIAN_BITFIELD)
162 u64 reserved_49_51
: 3;
163 u64 auth_input_type
: 1;
165 u64 reserved_0_39
: 40;
167 u64 reserved_0_39
: 40;
169 u64 auth_input_type
: 1;
170 u64 reserved_49_51
: 3;
180 struct crypto_keys crypto
;
181 struct auth_keys auth
;
184 struct crypto_ctx_hdr
{
185 struct dma_pool
*pool
;
190 struct nitrox_crypto_ctx
{
191 struct nitrox_device
*ndev
;
194 struct flexi_crypto_context
*fctx
;
196 struct crypto_ctx_hdr
*chdr
;
199 struct nitrox_kcrypt_request
{
200 struct se_crypto_request creq
;
201 struct nitrox_crypto_ctx
*nctx
;
202 struct skcipher_request
*skreq
;
206 * struct pkt_instr_hdr - Packet Instruction Header
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]
217 * @fsz: The number of front data bytes directly included in the
219 * @tlen: The length of the input packet in bytes, include:
221 * - Inline context bytes if any,
223 * - packet payload bytes
225 union pkt_instr_hdr
{
228 #if defined(__BIG_ENDIAN_BITFIELD)
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.
272 #if defined(__BIG_ENDIAN_BITFIELD)
306 * struct slc_store_info - Solicited Paceket Output Store Information.
307 * @ssz: The number of scatterlist pointers for the solicited output port
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.
315 union slc_store_info
{
318 #if defined(__BIG_ENDIAN_BITFIELD)
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)
339 * 64-Byte Instruction Format
341 struct nps_pkt_instr
{
343 union pkt_instr_hdr ih
;
345 union slc_store_info slc
;
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
356 struct dma_pool
*pool
;
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.
372 struct nitrox_sgcomp
{
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.
389 struct nitrox_sgtable
{
395 enum dma_data_direction dir
;
397 struct scatterlist
*buf
;
398 struct nitrox_sglist
*sglist
;
399 struct nitrox_sgcomp
*sgcomp
;
402 /* Response Header Length */
404 /* Completion bytes Length */
411 dma_addr_t completion_dma
;
414 typedef void (*completion_t
)(struct skcipher_request
*skreq
, int err
);
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
430 struct nitrox_softreq
{
431 struct list_head response
;
432 struct list_head backlog
;
439 struct nitrox_device
*ndev
;
440 struct nitrox_cmdq
*cmdq
;
442 struct nps_pkt_instr instr
;
443 struct resp_hdr resp
;
444 struct nitrox_sgtable in
;
445 struct nitrox_sgtable out
;
447 unsigned long tstamp
;
449 completion_t callback
;
450 struct skcipher_request
*skreq
;
453 #endif /* __NITROX_REQ_H */