common/mlx5: extend virtq modifiable fields
[dpdk.git] / drivers / common / dpaax / caamflib / rta.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2008-2016 Freescale Semiconductor Inc.
4  * Copyright 2016,2021 NXP
5  *
6  */
7
8 #ifndef __RTA_RTA_H__
9 #define __RTA_RTA_H__
10
11 #include "rta/sec_run_time_asm.h"
12 #include "rta/fifo_load_store_cmd.h"
13 #include "rta/header_cmd.h"
14 #include "rta/jump_cmd.h"
15 #include "rta/key_cmd.h"
16 #include "rta/load_cmd.h"
17 #include "rta/math_cmd.h"
18 #include "rta/move_cmd.h"
19 #include "rta/nfifo_cmd.h"
20 #include "rta/operation_cmd.h"
21 #include "rta/protocol_cmd.h"
22 #include "rta/seq_in_out_ptr_cmd.h"
23 #include "rta/signature_cmd.h"
24 #include "rta/store_cmd.h"
25
26 /**
27  * DOC: About
28  *
29  * RTA (Runtime Assembler) Library is an easy and flexible runtime method for
30  * writing SEC descriptors. It implements a thin abstraction layer above
31  * SEC commands set; the resulting code is compact and similar to a
32  * descriptor sequence.
33  *
34  * RTA library improves comprehension of the SEC code, adds flexibility for
35  * writing complex descriptors and keeps the code lightweight. Should be used
36  * by whom needs to encode descriptors at runtime, with comprehensible flow
37  * control in descriptor.
38  */
39
40 /**
41  * DOC: Usage
42  *
43  * RTA is used in kernel space by the SEC / CAAM (Cryptographic Acceleration and
44  * Assurance Module) kernel module (drivers/crypto/caam) and SEC / CAAM QI
45  * kernel module (Freescale QorIQ SDK).
46  *
47  * RTA is used in user space by USDPAA - User Space DataPath Acceleration
48  * Architecture (Freescale QorIQ SDK).
49  */
50
51 /**
52  * DOC: Descriptor Buffer Management Routines
53  *
54  * Contains details of RTA descriptor buffer management and SEC Era
55  * management routines.
56  */
57
58 /**
59  * PROGRAM_CNTXT_INIT - must be called before any descriptor run-time assembly
60  *                      call type field carry info i.e. whether descriptor is
61  *                      shared or job descriptor.
62  * @program: pointer to struct program
63  * @buffer: input buffer where the descriptor will be placed (uint32_t *)
64  * @offset: offset in input buffer from where the data will be written
65  *          (unsigned int)
66  */
67 #define PROGRAM_CNTXT_INIT(program, buffer, offset) \
68         rta_program_cntxt_init(program, buffer, offset)
69
70 /**
71  * PROGRAM_FINALIZE - must be called to mark completion of RTA call.
72  * @program: pointer to struct program
73  *
74  * Return: total size of the descriptor in words or negative number on error.
75  */
76 #define PROGRAM_FINALIZE(program) rta_program_finalize(program)
77
78 /**
79  * PROGRAM_SET_36BIT_ADDR - must be called to set pointer size to 36 bits
80  * @program: pointer to struct program
81  *
82  * Return: current size of the descriptor in words (unsigned int).
83  */
84 #define PROGRAM_SET_36BIT_ADDR(program) rta_program_set_36bit_addr(program)
85
86 /**
87  * PROGRAM_SET_BSWAP - must be called to enable byte swapping
88  * @program: pointer to struct program
89  *
90  * Byte swapping on a 4-byte boundary will be performed at the end - when
91  * calling PROGRAM_FINALIZE().
92  *
93  * Return: current size of the descriptor in words (unsigned int).
94  */
95 #define PROGRAM_SET_BSWAP(program) rta_program_set_bswap(program)
96
97 /**
98  * WORD - must be called to insert in descriptor buffer a 32bit value
99  * @program: pointer to struct program
100  * @val: input value to be written in descriptor buffer (uint32_t)
101  *
102  * Return: the descriptor buffer offset where this command is inserted
103  * (unsigned int).
104  */
105 #define WORD(program, val) rta_word(program, val)
106
107 /**
108  * DWORD - must be called to insert in descriptor buffer a 64bit value
109  * @program: pointer to struct program
110  * @val: input value to be written in descriptor buffer (uint64_t)
111  *
112  * Return: the descriptor buffer offset where this command is inserted
113  * (unsigned int).
114  */
115 #define DWORD(program, val) rta_dword(program, val)
116
117 /**
118  * COPY_DATA - must be called to insert in descriptor buffer data larger than
119  *             64bits.
120  * @program: pointer to struct program
121  * @data: input data to be written in descriptor buffer (uint8_t *)
122  * @len: length of input data (unsigned int)
123  *
124  * Return: the descriptor buffer offset where this command is inserted
125  * (unsigned int).
126  */
127 #define COPY_DATA(program, data, len) rta_copy_data(program, (data), (len))
128
129 /**
130  * DESC_LEN -  determines job / shared descriptor buffer length (in words)
131  * @buffer: descriptor buffer (uint32_t *)
132  *
133  * Return: descriptor buffer length in words (unsigned int).
134  */
135 #define DESC_LEN(buffer) rta_desc_len(buffer)
136
137 /**
138  * DESC_BYTES - determines job / shared descriptor buffer length (in bytes)
139  * @buffer: descriptor buffer (uint32_t *)
140  *
141  * Return: descriptor buffer length in bytes (unsigned int).
142  */
143 #define DESC_BYTES(buffer) rta_desc_bytes(buffer)
144
145 /*
146  * SEC HW block revision.
147  *
148  * This *must not be confused with SEC version*:
149  * - SEC HW block revision format is "v"
150  * - SEC revision format is "x.y"
151  */
152 extern enum rta_sec_era rta_sec_era;
153
154 /**
155  * rta_set_sec_era - Set SEC Era HW block revision for which the RTA library
156  *                   will generate the descriptors.
157  * @era: SEC Era (enum rta_sec_era)
158  *
159  * Return: 0 if the ERA was set successfully, -1 otherwise (int)
160  *
161  * Warning 1: Must be called *only once*, *before* using any other RTA API
162  * routine.
163  *
164  * Warning 2: *Not thread safe*.
165  */
166 static inline int
167 rta_set_sec_era(enum rta_sec_era era)
168 {
169         if (era > MAX_SEC_ERA) {
170                 rta_sec_era = DEFAULT_SEC_ERA;
171                 pr_err("Unsupported SEC ERA. Defaulting to ERA %d\n",
172                        DEFAULT_SEC_ERA + 1);
173                 return -1;
174         }
175
176         rta_sec_era = era;
177         return 0;
178 }
179
180 /**
181  * rta_get_sec_era - Get SEC Era HW block revision for which the RTA library
182  *                   will generate the descriptors.
183  *
184  * Return: SEC Era (unsigned int).
185  */
186 static inline unsigned int
187 rta_get_sec_era(void)
188 {
189         return rta_sec_era;
190 }
191
192 /**
193  * DOC: SEC Commands Routines
194  *
195  * Contains details of RTA wrapper routines over SEC engine commands.
196  */
197
198 /**
199  * SHR_HDR - Configures Shared Descriptor HEADER command
200  * @program: pointer to struct program
201  * @share: descriptor share state (enum rta_share_type)
202  * @start_idx: index in descriptor buffer where the execution of the shared
203  *             descriptor should start (@c unsigned int).
204  * @flags: operational flags: RIF, DNR, CIF, SC, PD
205  *
206  * Return: On success, descriptor buffer offset where this command is inserted.
207  *         On error, a negative error code; first error program counter will
208  *         point to offset in descriptor buffer where the instruction should
209  *         have been written.
210  */
211 #define SHR_HDR(program, share, start_idx, flags) \
212         rta_shr_header(program, share, start_idx, flags)
213
214 /**
215  * JOB_HDR - Configures JOB Descriptor HEADER command
216  * @program: pointer to struct program
217  * @share: descriptor share state (enum rta_share_type)
218  * @start_idx: index in descriptor buffer where the execution of the job
219  *            descriptor should start (unsigned int). In case SHR bit is present
220  *            in flags, this will be the shared descriptor length.
221  * @share_desc: pointer to shared descriptor, in case SHR bit is set (uint64_t)
222  * @flags: operational flags: RSMS, DNR, TD, MTD, REO, SHR
223  *
224  * Return: On success, descriptor buffer offset where this command is inserted.
225  *         On error, a negative error code; first error program counter will
226  *         point to offset in descriptor buffer where the instruction should
227  *         have been written.
228  */
229 #define JOB_HDR(program, share, start_idx, share_desc, flags) \
230         rta_job_header(program, share, start_idx, share_desc, flags, 0)
231
232 /**
233  * JOB_HDR_EXT - Configures JOB Descriptor HEADER command
234  * @program: pointer to struct program
235  * @share: descriptor share state (enum rta_share_type)
236  * @start_idx: index in descriptor buffer where the execution of the job
237  *            descriptor should start (unsigned int). In case SHR bit is present
238  *            in flags, this will be the shared descriptor length.
239  * @share_desc: pointer to shared descriptor, in case SHR bit is set (uint64_t)
240  * @flags: operational flags: RSMS, DNR, TD, MTD, REO, SHR
241  * @ext_flags: extended header flags: DSV (DECO Select Valid), DECO Id (limited
242  *             by DSEL_MASK).
243  *
244  * Return: On success, descriptor buffer offset where this command is inserted.
245  *         On error, a negative error code; first error program counter will
246  *         point to offset in descriptor buffer where the instruction should
247  *         have been written.
248  */
249 #define JOB_HDR_EXT(program, share, start_idx, share_desc, flags, ext_flags) \
250         rta_job_header(program, share, start_idx, share_desc, flags | EXT, \
251                        ext_flags)
252
253 /**
254  * MOVE - Configures MOVE and MOVE_LEN commands
255  * @program: pointer to struct program
256  * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
257  *       DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
258  * @src_offset: offset in source data (uint16_t)
259  * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
260  *       OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
261  *       KEY2, ALTSOURCE.
262  * @dst_offset: offset in destination data (uint16_t)
263  * @length: size of data to be moved: for MOVE must be specified as immediate
264  *          value and IMMED flag must be set; for MOVE_LEN must be specified
265  *          using MATH0-MATH3.
266  * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
267  *       SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
268  *
269  * Return: On success, descriptor buffer offset where this command is inserted.
270  *         On error, a negative error code; first error program counter will
271  *         point to offset in descriptor buffer where the instruction should
272  *         have been written.
273  */
274 #define MOVE(program, src, src_offset, dst, dst_offset, length, opt) \
275         rta_move(program, __MOVE, src, src_offset, dst, dst_offset, length, opt)
276
277 /**
278  * MOVEB - Configures MOVEB command
279  * @program: pointer to struct program
280  * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
281  *       DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
282  * @src_offset: offset in source data (uint16_t)
283  * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
284  *       OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
285  *       KEY2, ALTSOURCE.
286  * @dst_offset: offset in destination data (uint16_t)
287  * @length: size of data to be moved: for MOVE must be specified as immediate
288  *          value and IMMED flag must be set; for MOVE_LEN must be specified
289  *          using MATH0-MATH3.
290  * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
291  *       SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
292  *
293  * Identical with MOVE command if byte swapping not enabled; else - when src/dst
294  * is descriptor buffer or MATH registers, data type is byte array when MOVE
295  * data type is 4-byte array and vice versa.
296  *
297  * Return: On success, descriptor buffer offset where this command is inserted.
298  *         On error, a negative error code; first error program counter will
299  *         point to offset in descriptor buffer where the instruction should
300  *         have been written.
301  */
302 #define MOVEB(program, src, src_offset, dst, dst_offset, length, opt) \
303         rta_move(program, __MOVEB, src, src_offset, dst, dst_offset, length, \
304                  opt)
305
306 /**
307  * MOVEDW - Configures MOVEDW command
308  * @program: pointer to struct program
309  * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
310  *       DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
311  * @src_offset: offset in source data (uint16_t)
312  * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
313  *       OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
314  *       KEY2, ALTSOURCE.
315  * @dst_offset: offset in destination data (uint16_t)
316  * @length: size of data to be moved: for MOVE must be specified as immediate
317  *          value and IMMED flag must be set; for MOVE_LEN must be specified
318  *          using MATH0-MATH3.
319  * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
320  *       SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
321  *
322  * Identical with MOVE command, with the following differences: data type is
323  * 8-byte array; word swapping is performed when SEC is programmed in little
324  * endian mode.
325  *
326  * Return: On success, descriptor buffer offset where this command is inserted.
327  *         On error, a negative error code; first error program counter will
328  *         point to offset in descriptor buffer where the instruction should
329  *         have been written.
330  */
331 #define MOVEDW(program, src, src_offset, dst, dst_offset, length, opt) \
332         rta_move(program, __MOVEDW, src, src_offset, dst, dst_offset, length, \
333                  opt)
334
335 /**
336  * FIFOLOAD - Configures FIFOLOAD command to load message data, PKHA data, IV,
337  *            ICV, AAD and bit length message data into Input Data FIFO.
338  * @program: pointer to struct program
339  * @data: input data type to store: PKHA registers, IFIFO, MSG1, MSG2,
340  *        MSGOUTSNOOP, MSGINSNOOP, IV1, IV2, AAD1, ICV1, ICV2, BIT_DATA, SKIP.
341  * @src: pointer or actual data in case of immediate load; IMMED, COPY and DCOPY
342  *       flags indicate action taken (inline imm data, inline ptr, inline from
343  *       ptr).
344  * @length: number of bytes to load (uint32_t)
345  * @flags: operational flags: SGF, IMMED, EXT, CLASS1, CLASS2, BOTH, FLUSH1,
346  *         LAST1, LAST2, COPY, DCOPY.
347  *
348  * Return: On success, descriptor buffer offset where this command is inserted.
349  *         On error, a negative error code; first error program counter will
350  *         point to offset in descriptor buffer where the instruction should
351  *         have been written.
352  */
353 #define FIFOLOAD(program, data, src, length, flags) \
354         rta_fifo_load(program, data, src, length, flags)
355
356 /**
357  * SEQFIFOLOAD - Configures SEQ FIFOLOAD command to load message data, PKHA
358  *               data, IV, ICV, AAD and bit length message data into Input Data
359  *               FIFO.
360  * @program: pointer to struct program
361  * @data: input data type to store: PKHA registers, IFIFO, MSG1, MSG2,
362  *        MSGOUTSNOOP, MSGINSNOOP, IV1, IV2, AAD1, ICV1, ICV2, BIT_DATA, SKIP.
363  * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
364  *          (uint32_t).
365  * @flags: operational flags: VLF, CLASS1, CLASS2, BOTH, FLUSH1, LAST1, LAST2,
366  *         AIDF.
367  *
368  * Return: On success, descriptor buffer offset where this command is inserted.
369  *         On error, a negative error code; first error program counter will
370  *         point to offset in descriptor buffer where the instruction should
371  *         have been written.
372  */
373 #define SEQFIFOLOAD(program, data, length, flags) \
374         rta_fifo_load(program, data, NONE, length, flags|SEQ)
375
376 /**
377  * FIFOSTORE - Configures FIFOSTORE command, to move data from Output Data FIFO
378  *             to external memory via DMA.
379  * @program: pointer to struct program
380  * @data: output data type to store: PKHA registers, IFIFO, OFIFO, RNG,
381  *        RNGOFIFO, AFHA_SBOX, MDHA_SPLIT_KEY, MSG, KEY1, KEY2, SKIP.
382  * @encrypt_flags: store data encryption mode: EKT, TK
383  * @dst: pointer to store location (uint64_t)
384  * @length: number of bytes to load (uint32_t)
385  * @flags: operational flags: SGF, CONT, EXT, CLASS1, CLASS2, BOTH
386  *
387  * Return: On success, descriptor buffer offset where this command is inserted.
388  *         On error, a negative error code; first error program counter will
389  *         point to offset in descriptor buffer where the instruction should
390  *         have been written.
391  */
392 #define FIFOSTORE(program, data, encrypt_flags, dst, length, flags) \
393         rta_fifo_store(program, data, encrypt_flags, dst, length, flags)
394
395 /**
396  * SEQFIFOSTORE - Configures SEQ FIFOSTORE command, to move data from Output
397  *                Data FIFO to external memory via DMA.
398  * @program: pointer to struct program
399  * @data: output data type to store: PKHA registers, IFIFO, OFIFO, RNG,
400  *        RNGOFIFO, AFHA_SBOX, MDHA_SPLIT_KEY, MSG, KEY1, KEY2, METADATA, SKIP.
401  * @encrypt_flags: store data encryption mode: EKT, TK
402  * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
403  *          (uint32_t).
404  * @flags: operational flags: VLF, CONT, EXT, CLASS1, CLASS2, BOTH
405  *
406  * Return: On success, descriptor buffer offset where this command is inserted.
407  *         On error, a negative error code; first error program counter will
408  *         point to offset in descriptor buffer where the instruction should
409  *         have been written.
410  */
411 #define SEQFIFOSTORE(program, data, encrypt_flags, length, flags) \
412         rta_fifo_store(program, data, encrypt_flags, 0, length, flags|SEQ)
413
414 /**
415  * KEY - Configures KEY and SEQ KEY commands
416  * @program: pointer to struct program
417  * @key_dst: key store location: KEY1, KEY2, PKE, AFHA_SBOX, MDHA_SPLIT_KEY
418  * @encrypt_flags: key encryption mode: ENC, EKT, TK, NWB, PTS
419  * @src: pointer or actual data in case of immediate load (uint64_t); IMMED,
420  *       COPY and DCOPY flags indicate action taken (inline imm data,
421  *       inline ptr, inline from ptr).
422  * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
423  *          (uint32_t).
424  * @flags: operational flags: for KEY: SGF, IMMED, COPY, DCOPY; for SEQKEY: SEQ,
425  *         VLF, AIDF.
426  *
427  * Return: On success, descriptor buffer offset where this command is inserted.
428  *         On error, a negative error code; first error program counter will
429  *         point to offset in descriptor buffer where the instruction should
430  *         have been written.
431  */
432 #define KEY(program, key_dst, encrypt_flags, src, length, flags) \
433         rta_key(program, key_dst, encrypt_flags, src, length, flags)
434
435 /**
436  * SEQINPTR - Configures SEQ IN PTR command
437  * @program: pointer to struct program
438  * @src: starting address for Input Sequence (uint64_t)
439  * @length: number of bytes in (or to be added to) Input Sequence (uint32_t)
440  * @flags: operational flags: RBS, INL, SGF, PRE, EXT, RTO, RJD, SOP (when PRE,
441  *         RTO or SOP are set, @src parameter must be 0).
442  *
443  * Return: On success, descriptor buffer offset where this command is inserted.
444  *         On error, a negative error code; first error program counter will
445  *         point to offset in descriptor buffer where the instruction should
446  *         have been written.
447  */
448 #define SEQINPTR(program, src, length, flags) \
449         rta_seq_in_ptr(program, src, length, flags)
450
451 /**
452  * SEQOUTPTR - Configures SEQ OUT PTR command
453  * @program: pointer to struct program
454  * @dst: starting address for Output Sequence (uint64_t)
455  * @length: number of bytes in (or to be added to) Output Sequence (uint32_t)
456  * @flags: operational flags: SGF, PRE, EXT, RTO, RST, EWS (when PRE or RTO are
457  *         set, @dst parameter must be 0).
458  *
459  * Return: On success, descriptor buffer offset where this command is inserted.
460  *         On error, a negative error code; first error program counter will
461  *         point to offset in descriptor buffer where the instruction should
462  *         have been written.
463  */
464 #define SEQOUTPTR(program, dst, length, flags) \
465         rta_seq_out_ptr(program, dst, length, flags)
466
467 /**
468  * ALG_OPERATION - Configures ALGORITHM OPERATION command
469  * @program: pointer to struct program
470  * @cipher_alg: algorithm to be used
471  * @aai: Additional Algorithm Information; contains mode information that is
472  *       associated with the algorithm (check desc.h for specific values).
473  * @algo_state: algorithm state; defines the state of the algorithm that is
474  *              being executed (check desc.h file for specific values).
475  * @icv_check: ICV checking; selects whether the algorithm should check
476  *             calculated ICV with known ICV: ICV_CHECK_ENABLE,
477  *             ICV_CHECK_DISABLE.
478  * @enc: selects between encryption and decryption: DIR_ENC, DIR_DEC
479  *
480  * Return: On success, descriptor buffer offset where this command is inserted.
481  *         On error, a negative error code; first error program counter will
482  *         point to offset in descriptor buffer where the instruction should
483  *         have been written.
484  */
485 #define ALG_OPERATION(program, cipher_alg, aai, algo_state, icv_check, enc) \
486         rta_operation(program, cipher_alg, aai, algo_state, icv_check, enc)
487
488 #define ALG_OPERATION_NP(program, cipher_alg, aai, algo_state, icv_check, enc) \
489         rta_operation2(program, cipher_alg, aai, algo_state, icv_check, enc)
490
491 /**
492  * PROTOCOL - Configures PROTOCOL OPERATION command
493  * @program: pointer to struct program
494  * @optype: operation type: OP_TYPE_UNI_PROTOCOL / OP_TYPE_DECAP_PROTOCOL /
495  *          OP_TYPE_ENCAP_PROTOCOL.
496  * @protid: protocol identifier value (check desc.h file for specific values)
497  * @protoinfo: protocol dependent value (check desc.h file for specific values)
498  *
499  * Return: On success, descriptor buffer offset where this command is inserted.
500  *         On error, a negative error code; first error program counter will
501  *         point to offset in descriptor buffer where the instruction should
502  *         have been written.
503  */
504 #define PROTOCOL(program, optype, protid, protoinfo) \
505         rta_proto_operation(program, optype, protid, protoinfo)
506
507 /**
508  * DKP_PROTOCOL - Configures DKP (Derived Key Protocol) PROTOCOL command
509  * @program: pointer to struct program
510  * @protid: protocol identifier value - one of the following:
511  *          OP_PCLID_DKP_{MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512}
512  * @key_src: How the initial ("negotiated") key is provided to the DKP protocol.
513  *           Valid values - one of OP_PCL_DKP_SRC_{IMM, SEQ, PTR, SGF}. Not all
514  *           (key_src,key_dst) combinations are allowed.
515  * @key_dst: How the derived ("split") key is returned by the DKP protocol.
516  *           Valid values - one of OP_PCL_DKP_DST_{IMM, SEQ, PTR, SGF}. Not all
517  *           (key_src,key_dst) combinations are allowed.
518  * @keylen: length of the initial key, in bytes (uint16_t)
519  * @key: address where algorithm key resides; virtual address if key_type is
520  *       RTA_DATA_IMM, physical (bus) address if key_type is RTA_DATA_PTR or
521  *       RTA_DATA_IMM_DMA.
522  * @key_type: enum rta_data_type
523  * Return: On success, descriptor buffer offset where this command is inserted.
524  *         On error, a negative error code; first error program counter will
525  *         point to offset in descriptor buffer where the instruction should
526  *         have been written.
527  */
528 #define DKP_PROTOCOL(program, protid, key_src, key_dst, keylen, key, key_type) \
529         rta_dkp_proto(program, protid, key_src, key_dst, keylen, key, key_type)
530
531 /**
532  * PKHA_OPERATION - Configures PKHA OPERATION command
533  * @program: pointer to struct program
534  * @op_pkha: PKHA operation; indicates the modular arithmetic function to
535  *           execute (check desc.h file for specific values).
536  *
537  * Return: On success, descriptor buffer offset where this command is inserted.
538  *         On error, a negative error code; first error program counter will
539  *         point to offset in descriptor buffer where the instruction should
540  *         have been written.
541  */
542 #define PKHA_OPERATION(program, op_pkha)   rta_pkha_operation(program, op_pkha)
543
544 /**
545  * JUMP - Configures JUMP command
546  * @program: pointer to struct program
547  * @addr: local offset for local jumps or address pointer for non-local jumps;
548  *        IMM or PTR macros must be used to indicate type.
549  * @jump_type: type of action taken by jump (enum rta_jump_type)
550  * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
551  * @cond: jump conditions: operational flags - DONE1, DONE2, BOTH; various
552  *        sharing and wait conditions (JSL = 1) - NIFP, NIP, NOP, NCP, CALM,
553  *        SELF, SHARED, JQP; Math and PKHA status conditions (JSL = 0) - Z, N,
554  *        NV, C, PK0, PK1, PKP.
555  *
556  * Return: On success, descriptor buffer offset where this command is inserted.
557  *         On error, a negative error code; first error program counter will
558  *         point to offset in descriptor buffer where the instruction should
559  *         have been written.
560  */
561 #define JUMP(program, addr, jump_type, test_type, cond) \
562         rta_jump(program, addr, jump_type, test_type, cond, NONE)
563
564 /**
565  * JUMP_INC - Configures JUMP_INC command
566  * @program: pointer to struct program
567  * @addr: local offset; IMM or PTR macros must be used to indicate type
568  * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
569  * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
570  * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
571  *           SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
572  *
573  * Return: On success, descriptor buffer offset where this command is inserted.
574  *         On error, a negative error code; first error program counter will
575  *         point to offset in descriptor buffer where the instruction should
576  *         have been written.
577  */
578 #define JUMP_INC(program, addr, test_type, cond, src_dst) \
579         rta_jump(program, addr, LOCAL_JUMP_INC, test_type, cond, src_dst)
580
581 /**
582  * JUMP_DEC - Configures JUMP_DEC command
583  * @program: pointer to struct program
584  * @addr: local offset; IMM or PTR macros must be used to indicate type
585  * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
586  * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
587  * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
588  *           SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
589  *
590  * Return: On success, descriptor buffer offset where this command is inserted.
591  *         On error, a negative error code; first error program counter will
592  *         point to offset in descriptor buffer where the instruction should
593  *         have been written.
594  */
595 #define JUMP_DEC(program, addr, test_type, cond, src_dst) \
596         rta_jump(program, addr, LOCAL_JUMP_DEC, test_type, cond, src_dst)
597
598 /**
599  * LOAD - Configures LOAD command to load data registers from descriptor or from
600  *        a memory location.
601  * @program: pointer to struct program
602  * @addr: immediate value or pointer to the data to be loaded; IMMED, COPY and
603  *        DCOPY flags indicate action taken (inline imm data, inline ptr, inline
604  *        from ptr).
605  * @dst: destination register (uint64_t)
606  * @offset: start point to write data in destination register (uint32_t)
607  * @length: number of bytes to load (uint32_t)
608  * @flags: operational flags: VLF, IMMED, COPY, DCOPY
609  *
610  * Return: On success, descriptor buffer offset where this command is inserted.
611  *         On error, a negative error code; first error program counter will
612  *         point to offset in descriptor buffer where the instruction should
613  *         have been written.
614  */
615 #define LOAD(program, addr, dst, offset, length, flags) \
616         rta_load(program, addr, dst, offset, length, flags)
617
618 /**
619  * SEQLOAD - Configures SEQ LOAD command to load data registers from descriptor
620  *           or from a memory location.
621  * @program: pointer to struct program
622  * @dst: destination register (uint64_t)
623  * @offset: start point to write data in destination register (uint32_t)
624  * @length: number of bytes to load (uint32_t)
625  * @flags: operational flags: SGF
626  *
627  * Return: On success, descriptor buffer offset where this command is inserted.
628  *         On error, a negative error code; first error program counter will
629  *         point to offset in descriptor buffer where the instruction should
630  *         have been written.
631  */
632 #define SEQLOAD(program, dst, offset, length, flags) \
633         rta_load(program, NONE, dst, offset, length, flags|SEQ)
634
635 /**
636  * STORE - Configures STORE command to read data from registers and write them
637  *         to a memory location.
638  * @program: pointer to struct program
639  * @src: immediate value or source register for data to be stored: KEY1SZ,
640  *       KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
641  *       ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
642  *       CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
643  *       immediate value, IMMED, COPY and DCOPY flags indicate action taken
644  *       (inline imm data, inline ptr, inline from ptr).
645  * @offset: start point for reading from source register (uint16_t)
646  * @dst: pointer to store location (uint64_t)
647  * @length: number of bytes to store (uint32_t)
648  * @flags: operational flags: VLF, IMMED, COPY, DCOPY
649  *
650  * Return: On success, descriptor buffer offset where this command is inserted.
651  *         On error, a negative error code; first error program counter will
652  *         point to offset in descriptor buffer where the instruction should
653  *         have been written.
654  */
655 #define STORE(program, src, offset, dst, length, flags) \
656         rta_store(program, src, offset, dst, length, flags)
657
658 /**
659  * SEQSTORE - Configures SEQ STORE command to read data from registers and write
660  *            them to a memory location.
661  * @program: pointer to struct program
662  * @src: immediate value or source register for data to be stored: KEY1SZ,
663  *       KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
664  *       ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
665  *       CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
666  *       immediate value, IMMED, COPY and DCOPY flags indicate action taken
667  *       (inline imm data, inline ptr, inline from ptr).
668  * @offset: start point for reading from source register (uint16_t)
669  * @length: number of bytes to store (uint32_t)
670  * @flags: operational flags: SGF, IMMED, COPY, DCOPY
671  *
672  * Return: On success, descriptor buffer offset where this command is inserted.
673  *         On error, a negative error code; first error program counter will
674  *         point to offset in descriptor buffer where the instruction should
675  *         have been written.
676  */
677 #define SEQSTORE(program, src, offset, length, flags) \
678         rta_store(program, src, offset, NONE, length, flags|SEQ)
679
680 /**
681  * MATHB - Configures MATHB command to perform binary operations
682  * @program: pointer to struct program
683  * @operand1: first operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
684  *            VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
685  *            indicate immediate value.
686  * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
687  *            LSHIFT, RSHIFT, SHLD.
688  * @operand2: second operand: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD,
689  *            OFIFO, JOBSRC, ZERO, ONE, Immediate value. IMMED2 must be used to
690  *            indicate immediate value.
691  * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
692  *          NONE, VSEQINSZ, VSEQOUTSZ.
693  * @length: length in bytes of the operation and the immediate value, if there
694  *          is one (int).
695  * @opt: operational flags: IFB, NFU, STL, SWP, IMMED, IMMED2
696  *
697  * Return: On success, descriptor buffer offset where this command is inserted.
698  *         On error, a negative error code; first error program counter will
699  *         point to offset in descriptor buffer where the instruction should
700  *         have been written.
701  */
702 #define MATHB(program, operand1, operator, operand2, result, length, opt) \
703         rta_math(program, operand1, MATH_FUN_##operator, operand2, result, \
704                  length, opt)
705
706 /**
707  * MATHI - Configures MATHI command to perform binary operations
708  * @program: pointer to struct program
709  * @operand: if !SSEL: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
710  *           VSEQOUTSZ, ZERO, ONE.
711  *           if SSEL: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD, OFIFO,
712  *           JOBSRC, ZERO, ONE.
713  * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
714  *            LSHIFT, RSHIFT, FBYT (for !SSEL only).
715  * @imm: Immediate value (uint8_t). IMMED must be used to indicate immediate
716  *       value.
717  * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
718  *          NONE, VSEQINSZ, VSEQOUTSZ.
719  * @length: length in bytes of the operation and the immediate value, if there
720  *          is one (int). @imm is left-extended with zeros if needed.
721  * @opt: operational flags: NFU, SSEL, SWP, IMMED
722  *
723  * If !SSEL, @operand <@operator> @imm -> @result
724  * If SSEL, @imm <@operator> @operand -> @result
725  *
726  * Return: On success, descriptor buffer offset where this command is inserted.
727  *         On error, a negative error code; first error program counter will
728  *         point to offset in descriptor buffer where the instruction should
729  *         have been written.
730  */
731 #define MATHI(program, operand, operator, imm, result, length, opt) \
732         rta_mathi(program, operand, MATH_FUN_##operator, imm, result, length, \
733                   opt)
734
735 /**
736  * MATHU - Configures MATHU command to perform unary operations
737  * @program: pointer to struct program
738  * @operand1: operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
739  *            VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
740  *            indicate immediate value.
741  * @operator: function to be performed: ZBYT, BSWAP
742  * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
743  *          NONE, VSEQINSZ, VSEQOUTSZ.
744  * @length: length in bytes of the operation and the immediate value, if there
745  *          is one (int).
746  * @opt: operational flags: NFU, STL, SWP, IMMED
747  *
748  * Return: On success, descriptor buffer offset where this command is inserted.
749  *         On error, a negative error code; first error program counter will
750  *         point to offset in descriptor buffer where the instruction should
751  *         have been written.
752  */
753 #define MATHU(program, operand1, operator, result, length, opt) \
754         rta_math(program, operand1, MATH_FUN_##operator, NONE, result, length, \
755                  opt)
756
757 /**
758  * SIGNATURE - Configures SIGNATURE command
759  * @program: pointer to struct program
760  * @sign_type: signature type: SIGN_TYPE_FINAL, SIGN_TYPE_FINAL_RESTORE,
761  *             SIGN_TYPE_FINAL_NONZERO, SIGN_TYPE_IMM_2, SIGN_TYPE_IMM_3,
762  *             SIGN_TYPE_IMM_4.
763  *
764  * After SIGNATURE command, DWORD or WORD must be used to insert signature in
765  * descriptor buffer.
766  *
767  * Return: On success, descriptor buffer offset where this command is inserted.
768  *         On error, a negative error code; first error program counter will
769  *         point to offset in descriptor buffer where the instruction should
770  *         have been written.
771  */
772 #define SIGNATURE(program, sign_type)   rta_signature(program, sign_type)
773
774 /**
775  * NFIFOADD - Configures NFIFO command, a shortcut of RTA Load command to write
776  *            to iNfo FIFO.
777  * @program: pointer to struct program
778  * @src: source for the input data in Alignment Block:IFIFO, OFIFO, PAD,
779  *       MSGOUTSNOOP, ALTSOURCE, OFIFO_SYNC, MSGOUTSNOOP_ALT.
780  * @data: type of data that is going through the Input Data FIFO: MSG, MSG1,
781  *        MSG2, IV1, IV2, ICV1, ICV2, SAD1, AAD1, AAD2, AFHA_SBOX, SKIP,
782  *        PKHA registers, AB1, AB2, ABD.
783  * @length: length of the data copied in FIFO registers (uint32_t)
784  * @flags: select options between:
785  *         -operational flags: LAST1, LAST2, FLUSH1, FLUSH2, OC, BP
786  *         -when PAD is selected as source: BM, PR, PS
787  *         -padding type: <em>PAD_ZERO, PAD_NONZERO, PAD_INCREMENT, PAD_RANDOM,
788  *          PAD_ZERO_N1, PAD_NONZERO_0, PAD_N1, PAD_NONZERO_N
789  *
790  * Return: On success, descriptor buffer offset where this command is inserted.
791  *         On error, a negative error code; first error program counter will
792  *         point to offset in descriptor buffer where the instruction should
793  *         have been written.
794  */
795 #define NFIFOADD(program, src, data, length, flags) \
796         rta_nfifo_load(program, src, data, length, flags)
797
798 /**
799  * DOC: Self Referential Code Management Routines
800  *
801  * Contains details of RTA self referential code routines.
802  */
803
804 /**
805  * REFERENCE - initialize a variable used for storing an index inside a
806  *             descriptor buffer.
807  * @ref: reference to a descriptor buffer's index where an update is required
808  *       with a value that will be known latter in the program flow.
809  */
810 #define REFERENCE(ref)    int ref = -1
811
812 /**
813  * LABEL - initialize a variable used for storing an index inside a descriptor
814  *         buffer.
815  * @label: label stores the value with what should be updated the REFERENCE line
816  *         in the descriptor buffer.
817  */
818 #define LABEL(label)      unsigned int label = 0
819
820 /**
821  * SET_LABEL - set a LABEL value
822  * @program: pointer to struct program
823  * @label: value that will be inserted in a line previously written in the
824  *         descriptor buffer.
825  */
826 #define SET_LABEL(program, label)  (label = rta_set_label(program))
827
828 /**
829  * PATCH_JUMP - Auxiliary command to resolve self referential code
830  * @program: buffer to be updated (struct program *)
831  * @line: position in descriptor buffer where the update will be done; this
832  *        value is previously retained in program flow using a reference near
833  *        the sequence to be modified.
834  * @new_ref: updated value that will be inserted in descriptor buffer at the
835  *          specified line; this value is previously obtained using SET_LABEL
836  *          macro near the line that will be used as reference (unsigned int).
837  *          For JUMP command, the value represents the offset field (in words).
838  *
839  * Return: 0 in case of success, a negative error code if it fails
840  */
841 #define PATCH_JUMP(program, line, new_ref) rta_patch_jmp(program, line, new_ref)
842
843 /**
844  * PATCH_MOVE - Auxiliary command to resolve self referential code
845  * @program: buffer to be updated (struct program *)
846  * @line: position in descriptor buffer where the update will be done; this
847  *        value is previously retained in program flow using a reference near
848  *        the sequence to be modified.
849  * @new_ref: updated value that will be inserted in descriptor buffer at the
850  *          specified line; this value is previously obtained using SET_LABEL
851  *          macro near the line that will be used as reference (unsigned int).
852  *          For MOVE command, the value represents the offset field (in words).
853  *
854  * Return: 0 in case of success, a negative error code if it fails
855  */
856 #define PATCH_MOVE(program, line, new_ref) \
857         rta_patch_move(program, line, new_ref)
858
859 /**
860  * PATCH_LOAD - Auxiliary command to resolve self referential code
861  * @program: buffer to be updated (struct program *)
862  * @line: position in descriptor buffer where the update will be done; this
863  *        value is previously retained in program flow using a reference near
864  *        the sequence to be modified.
865  * @new_ref: updated value that will be inserted in descriptor buffer at the
866  *          specified line; this value is previously obtained using SET_LABEL
867  *          macro near the line that will be used as reference (unsigned int).
868  *          For LOAD command, the value represents the offset field (in words).
869  *
870  * Return: 0 in case of success, a negative error code if it fails
871  */
872 #define PATCH_LOAD(program, line, new_ref) \
873         rta_patch_load(program, line, new_ref)
874
875 /**
876  * PATCH_STORE - Auxiliary command to resolve self referential code
877  * @program: buffer to be updated (struct program *)
878  * @line: position in descriptor buffer where the update will be done; this
879  *        value is previously retained in program flow using a reference near
880  *        the sequence to be modified.
881  * @new_ref: updated value that will be inserted in descriptor buffer at the
882  *          specified line; this value is previously obtained using SET_LABEL
883  *          macro near the line that will be used as reference (unsigned int).
884  *          For STORE command, the value represents the offset field (in words).
885  *
886  * Return: 0 in case of success, a negative error code if it fails
887  */
888 #define PATCH_STORE(program, line, new_ref) \
889         rta_patch_store(program, line, new_ref)
890
891 /**
892  * PATCH_HDR - Auxiliary command to resolve self referential code
893  * @program: buffer to be updated (struct program *)
894  * @line: position in descriptor buffer where the update will be done; this
895  *        value is previously retained in program flow using a reference near
896  *        the sequence to be modified.
897  * @new_ref: updated value that will be inserted in descriptor buffer at the
898  *          specified line; this value is previously obtained using SET_LABEL
899  *          macro near the line that will be used as reference (unsigned int).
900  *          For HEADER command, the value represents the start index field.
901  *
902  * Return: 0 in case of success, a negative error code if it fails
903  */
904 #define PATCH_HDR(program, line, new_ref) \
905         rta_patch_header(program, line, new_ref)
906
907 /**
908  * PATCH_RAW - Auxiliary command to resolve self referential code
909  * @program: buffer to be updated (struct program *)
910  * @line: position in descriptor buffer where the update will be done; this
911  *        value is previously retained in program flow using a reference near
912  *        the sequence to be modified.
913  * @mask: mask to be used for applying the new value (unsigned int). The mask
914  *        selects which bits from the provided @new_val are taken into
915  *        consideration when overwriting the existing value.
916  * @new_val: updated value that will be masked using the provided mask value
917  *           and inserted in descriptor buffer at the specified line.
918  *
919  * Return: 0 in case of success, a negative error code if it fails
920  */
921 #define PATCH_RAW(program, line, mask, new_val) \
922         rta_patch_raw(program, line, mask, new_val)
923
924 #endif /* __RTA_RTA_H__ */