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 nitrox_crypto_ctx
{
185 struct nitrox_device
*ndev
;
188 struct flexi_crypto_context
*fctx
;
192 struct nitrox_kcrypt_request
{
193 struct se_crypto_request creq
;
194 struct nitrox_crypto_ctx
*nctx
;
195 struct skcipher_request
*skreq
;
199 * struct pkt_instr_hdr - Packet Instruction Header
201 * When [G] is set and [GSZ] != 0, the instruction is
202 * indirect gather instruction.
203 * When [G] is set and [GSZ] = 0, the instruction is
204 * direct gather instruction.
205 * @gsz: Number of pointers in the indirect gather list
206 * @ihi: When set hardware duplicates the 1st 8 bytes of pkt_instr_hdr
207 * and adds them to the packet after the pkt_instr_hdr but before any UDD
208 * @ssz: Not used by the input hardware. But can become slc_store_int[SSZ]
210 * @fsz: The number of front data bytes directly included in the
212 * @tlen: The length of the input packet in bytes, include:
214 * - Inline context bytes if any,
216 * - packet payload bytes
218 union pkt_instr_hdr
{
221 #if defined(__BIG_ENDIAN_BITFIELD)
246 * struct pkt_hdr - Packet Input Header
247 * @opcode: Request opcode (Major)
248 * @arg: Request opcode (Minor)
249 * @ctxc: Context control.
250 * @unca: When set [UNC] is the uncertainty count for an input packet.
251 * The hardware uses uncertainty counts to predict
252 * output buffer use and avoid deadlock.
253 * @info: Not used by input hardware. Available for use
254 * during SE processing.
255 * @destport: The expected destination port/ring/channel for the packet.
256 * @unc: Uncertainty count for an input packet.
257 * @grp: SE group that will process the input packet.
258 * @ctxl: Context Length in 64-bit words.
259 * @uddl: User-defined data (UDD) length in bytes.
260 * @ctxp: Context pointer. CTXP<63,2:0> must be zero in all cases.
265 #if defined(__BIG_ENDIAN_BITFIELD)
299 * struct slc_store_info - Solicited Paceket Output Store Information.
300 * @ssz: The number of scatterlist pointers for the solicited output port
302 * @rptr: The result pointer for the solicited output port packet.
303 * If [SSZ]=0, [RPTR] must point directly to a buffer on the remote
304 * host that is large enough to hold the entire output packet.
305 * If [SSZ]!=0, [RPTR] must point to an array of ([SSZ]+3)/4
306 * sglist components at [RPTR] on the remote host.
308 union slc_store_info
{
311 #if defined(__BIG_ENDIAN_BITFIELD)
325 * struct nps_pkt_instr - NPS Packet Instruction of SE cores.
326 * @dptr0 : Input pointer points to buffer in remote host.
327 * @ih: Packet Instruction Header (8 bytes)
328 * @irh: Packet Input Header (16 bytes)
329 * @slc: Solicited Packet Output Store Information (16 bytes)
332 * 64-Byte Instruction Format
334 struct nps_pkt_instr
{
336 union pkt_instr_hdr ih
;
338 union slc_store_info slc
;
343 * struct ctx_hdr - Book keeping data about the crypto context
344 * @pool: Pool used to allocate crypto context
345 * @dma: Base DMA address of the cypto context
346 * @ctx_dma: Actual usable crypto context for NITROX
349 struct dma_pool
*pool
;
355 * struct sglist_component - SG list component format
356 * @len0: The number of bytes at [PTR0] on the remote host.
357 * @len1: The number of bytes at [PTR1] on the remote host.
358 * @len2: The number of bytes at [PTR2] on the remote host.
359 * @len3: The number of bytes at [PTR3] on the remote host.
360 * @dma0: First pointer point to buffer in remote host.
361 * @dma1: Second pointer point to buffer in remote host.
362 * @dma2: Third pointer point to buffer in remote host.
363 * @dma3: Fourth pointer point to buffer in remote host.
365 struct nitrox_sgcomp
{
371 * strutct nitrox_sgtable - SG list information
372 * @map_cnt: Number of buffers mapped
373 * @nr_comp: Number of sglist components
374 * @total_bytes: Total bytes in sglist.
375 * @len: Total sglist components length.
376 * @dma: DMA address of sglist component.
377 * @dir: DMA direction.
378 * @buf: crypto request buffer.
379 * @sglist: SG list of input/output buffers.
380 * @sgcomp: sglist component for NITROX.
382 struct nitrox_sgtable
{
388 enum dma_data_direction dir
;
390 struct scatterlist
*buf
;
391 struct nitrox_sglist
*sglist
;
392 struct nitrox_sgcomp
*sgcomp
;
395 /* Response Header Length */
397 /* Completion bytes Length */
404 dma_addr_t completion_dma
;
407 typedef void (*completion_t
)(struct skcipher_request
*skreq
, int err
);
410 * struct nitrox_softreq - Represents the NIROX Request.
411 * @response: response list entry
412 * @backlog: Backlog list entry
413 * @ndev: Device used to submit the request
414 * @cmdq: Command queue for submission
415 * @resp: Response headers
416 * @instr: 64B instruction
417 * @in: SG table for input
418 * @out SG table for output
419 * @tstamp: Request submitted time in jiffies
420 * @callback: callback after request completion/timeout
421 * @cb_arg: callback argument
423 struct nitrox_softreq
{
424 struct list_head response
;
425 struct list_head backlog
;
432 struct nitrox_device
*ndev
;
433 struct nitrox_cmdq
*cmdq
;
435 struct nps_pkt_instr instr
;
436 struct resp_hdr resp
;
437 struct nitrox_sgtable in
;
438 struct nitrox_sgtable out
;
440 unsigned long tstamp
;
442 completion_t callback
;
443 struct skcipher_request
*skreq
;
446 #endif /* __NITROX_REQ_H */