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