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.
7 * Copyright 2008-2016 Freescale Semiconductor Inc.
8 * Copyright (c) 2016 NXP.
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.
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
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.
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"
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.
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.
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).
80 * RTA is used in user space by USDPAA - User Space DataPath Acceleration
81 * Architecture (Freescale QorIQ SDK).
85 * DOC: Descriptor Buffer Management Routines
87 * Contains details of RTA descriptor buffer management and SEC Era
88 * management routines.
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
100 #define PROGRAM_CNTXT_INIT(program, buffer, offset) \
101 rta_program_cntxt_init(program, buffer, offset)
104 * PROGRAM_FINALIZE - must be called to mark completion of RTA call.
105 * @program: pointer to struct program
107 * Return: total size of the descriptor in words or negative number on error.
109 #define PROGRAM_FINALIZE(program) rta_program_finalize(program)
112 * PROGRAM_SET_36BIT_ADDR - must be called to set pointer size to 36 bits
113 * @program: pointer to struct program
115 * Return: current size of the descriptor in words (unsigned int).
117 #define PROGRAM_SET_36BIT_ADDR(program) rta_program_set_36bit_addr(program)
120 * PROGRAM_SET_BSWAP - must be called to enable byte swapping
121 * @program: pointer to struct program
123 * Byte swapping on a 4-byte boundary will be performed at the end - when
124 * calling PROGRAM_FINALIZE().
126 * Return: current size of the descriptor in words (unsigned int).
128 #define PROGRAM_SET_BSWAP(program) rta_program_set_bswap(program)
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)
135 * Return: the descriptor buffer offset where this command is inserted
138 #define WORD(program, val) rta_word(program, val)
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)
145 * Return: the descriptor buffer offset where this command is inserted
148 #define DWORD(program, val) rta_dword(program, val)
151 * COPY_DATA - must be called to insert in descriptor buffer data larger than
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)
157 * Return: the descriptor buffer offset where this command is inserted
160 #define COPY_DATA(program, data, len) rta_copy_data(program, (data), (len))
163 * DESC_LEN - determines job / shared descriptor buffer length (in words)
164 * @buffer: descriptor buffer (uint32_t *)
166 * Return: descriptor buffer length in words (unsigned int).
168 #define DESC_LEN(buffer) rta_desc_len(buffer)
171 * DESC_BYTES - determines job / shared descriptor buffer length (in bytes)
172 * @buffer: descriptor buffer (uint32_t *)
174 * Return: descriptor buffer length in bytes (unsigned int).
176 #define DESC_BYTES(buffer) rta_desc_bytes(buffer)
179 * SEC HW block revision.
181 * This *must not be confused with SEC version*:
182 * - SEC HW block revision format is "v"
183 * - SEC revision format is "x.y"
185 extern enum rta_sec_era rta_sec_era;
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)
192 * Return: 0 if the ERA was set successfully, -1 otherwise (int)
194 * Warning 1: Must be called *only once*, *before* using any other RTA API
197 * Warning 2: *Not thread safe*.
200 rta_set_sec_era(enum rta_sec_era era)
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);
214 * rta_get_sec_era - Get SEC Era HW block revision for which the RTA library
215 * will generate the descriptors.
217 * Return: SEC Era (unsigned int).
219 static inline unsigned int
220 rta_get_sec_era(void)
226 * DOC: SEC Commands Routines
228 * Contains details of RTA wrapper routines over SEC engine commands.
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
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
244 #define SHR_HDR(program, share, start_idx, flags) \
245 rta_shr_header(program, share, start_idx, flags)
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
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
262 #define JOB_HDR(program, share, start_idx, share_desc, flags) \
263 rta_job_header(program, share, start_idx, share_desc, flags, 0)
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
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
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, \
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,
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
299 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
300 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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
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)
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,
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
323 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
324 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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.
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
335 #define MOVEB(program, src, src_offset, dst, dst_offset, length, opt) \
336 rta_move(program, __MOVEB, src, src_offset, dst, dst_offset, length, \
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,
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
352 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
353 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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
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
364 #define MOVEDW(program, src, src_offset, dst, dst_offset, length, opt) \
365 rta_move(program, __MOVEDW, src, src_offset, dst, dst_offset, length, \
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
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.
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
386 #define FIFOLOAD(program, data, src, length, flags) \
387 rta_fifo_load(program, data, src, length, flags)
390 * SEQFIFOLOAD - Configures SEQ FIFOLOAD command to load message data, PKHA
391 * data, IV, ICV, AAD and bit length message data into Input Data
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
398 * @flags: operational flags: VLF, CLASS1, CLASS2, BOTH, FLUSH1, LAST1, LAST2,
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
406 #define SEQFIFOLOAD(program, data, length, flags) \
407 rta_fifo_load(program, data, NONE, length, flags|SEQ)
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
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
425 #define FIFOSTORE(program, data, encrypt_flags, dst, length, flags) \
426 rta_fifo_store(program, data, encrypt_flags, dst, length, flags)
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
437 * @flags: operational flags: VLF, CONT, EXT, CLASS1, CLASS2, BOTH
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
444 #define SEQFIFOSTORE(program, data, encrypt_flags, length, flags) \
445 rta_fifo_store(program, data, encrypt_flags, 0, length, flags|SEQ)
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
457 * @flags: operational flags: for KEY: SGF, IMMED, COPY, DCOPY; for SEQKEY: SEQ,
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
465 #define KEY(program, key_dst, encrypt_flags, src, length, flags) \
466 rta_key(program, key_dst, encrypt_flags, src, length, flags)
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).
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
481 #define SEQINPTR(program, src, length, flags) \
482 rta_seq_in_ptr(program, src, length, flags)
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).
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
497 #define SEQOUTPTR(program, dst, length, flags) \
498 rta_seq_out_ptr(program, dst, length, flags)
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,
511 * @enc: selects between encryption and decryption: DIR_ENC, DIR_DEC
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
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)
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)
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
534 #define PROTOCOL(program, optype, protid, protoinfo) \
535 rta_proto_operation(program, optype, protid, protoinfo)
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
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
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)
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).
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
572 #define PKHA_OPERATION(program, op_pkha) rta_pkha_operation(program, op_pkha)
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.
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
591 #define JUMP(program, addr, jump_type, test_type, cond) \
592 rta_jump(program, addr, jump_type, test_type, cond, NONE)
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.
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
608 #define JUMP_INC(program, addr, test_type, cond, src_dst) \
609 rta_jump(program, addr, LOCAL_JUMP_INC, test_type, cond, src_dst)
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.
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
625 #define JUMP_DEC(program, addr, test_type, cond, src_dst) \
626 rta_jump(program, addr, LOCAL_JUMP_DEC, test_type, cond, src_dst)
629 * LOAD - Configures LOAD command to load data registers from descriptor or from
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
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
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
645 #define LOAD(program, addr, dst, offset, length, flags) \
646 rta_load(program, addr, dst, offset, length, flags)
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
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
662 #define SEQLOAD(program, dst, offset, length, flags) \
663 rta_load(program, NONE, dst, offset, length, flags|SEQ)
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
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
685 #define STORE(program, src, offset, dst, length, flags) \
686 rta_store(program, src, offset, dst, length, flags)
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
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
707 #define SEQSTORE(program, src, offset, length, flags) \
708 rta_store(program, src, offset, NONE, length, flags|SEQ)
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
725 * @opt: operational flags: IFB, NFU, STL, SWP, IMMED, IMMED2
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
732 #define MATHB(program, operand1, operator, operand2, result, length, opt) \
733 rta_math(program, operand1, MATH_FUN_##operator, operand2, result, \
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,
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
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
753 * If !SSEL, @operand <@operator> @imm -> @result
754 * If SSEL, @imm <@operator> @operand -> @result
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
761 #define MATHI(program, operand, operator, imm, result, length, opt) \
762 rta_mathi(program, operand, MATH_FUN_##operator, imm, result, length, \
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
776 * @opt: operational flags: NFU, STL, SWP, IMMED
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
783 #define MATHU(program, operand1, operator, result, length, opt) \
784 rta_math(program, operand1, MATH_FUN_##operator, NONE, result, length, \
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,
794 * After SIGNATURE command, DWORD or WORD must be used to insert signature in
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
802 #define SIGNATURE(program, sign_type) rta_signature(program, sign_type)
805 * NFIFOADD - Configures NFIFO command, a shortcut of RTA Load command to write
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
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
825 #define NFIFOADD(program, src, data, length, flags) \
826 rta_nfifo_load(program, src, data, length, flags)
829 * DOC: Self Referential Code Management Routines
831 * Contains details of RTA self referential code routines.
835 * REFERENCE - initialize a variable used for storing an index inside a
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.
840 #define REFERENCE(ref) int ref = -1
843 * LABEL - initialize a variable used for storing an index inside a descriptor
845 * @label: label stores the value with what should be updated the REFERENCE line
846 * in the descriptor buffer.
848 #define LABEL(label) unsigned int label = 0
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
856 #define SET_LABEL(program, label) (label = rta_set_label(program))
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).
869 * Return: 0 in case of success, a negative error code if it fails
871 #define PATCH_JUMP(program, line, new_ref) rta_patch_jmp(program, line, new_ref)
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).
884 * Return: 0 in case of success, a negative error code if it fails
886 #define PATCH_MOVE(program, line, new_ref) \
887 rta_patch_move(program, line, new_ref)
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).
900 * Return: 0 in case of success, a negative error code if it fails
902 #define PATCH_LOAD(program, line, new_ref) \
903 rta_patch_load(program, line, new_ref)
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).
916 * Return: 0 in case of success, a negative error code if it fails
918 #define PATCH_STORE(program, line, new_ref) \
919 rta_patch_store(program, line, new_ref)
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.
932 * Return: 0 in case of success, a negative error code if it fails
934 #define PATCH_HDR(program, line, new_ref) \
935 rta_patch_header(program, line, new_ref)
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.
949 * Return: 0 in case of success, a negative error code if it fails
951 #define PATCH_RAW(program, line, mask, new_val) \
952 rta_patch_raw(program, line, mask, new_val)
954 #endif /* __RTA_RTA_H__ */