1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2016 Freescale Semiconductor Inc.
4 * Copyright 2016,2021 NXP
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"
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.
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.
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).
47 * RTA is used in user space by USDPAA - User Space DataPath Acceleration
48 * Architecture (Freescale QorIQ SDK).
52 * DOC: Descriptor Buffer Management Routines
54 * Contains details of RTA descriptor buffer management and SEC Era
55 * management routines.
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
67 #define PROGRAM_CNTXT_INIT(program, buffer, offset) \
68 rta_program_cntxt_init(program, buffer, offset)
71 * PROGRAM_FINALIZE - must be called to mark completion of RTA call.
72 * @program: pointer to struct program
74 * Return: total size of the descriptor in words or negative number on error.
76 #define PROGRAM_FINALIZE(program) rta_program_finalize(program)
79 * PROGRAM_SET_36BIT_ADDR - must be called to set pointer size to 36 bits
80 * @program: pointer to struct program
82 * Return: current size of the descriptor in words (unsigned int).
84 #define PROGRAM_SET_36BIT_ADDR(program) rta_program_set_36bit_addr(program)
87 * PROGRAM_SET_BSWAP - must be called to enable byte swapping
88 * @program: pointer to struct program
90 * Byte swapping on a 4-byte boundary will be performed at the end - when
91 * calling PROGRAM_FINALIZE().
93 * Return: current size of the descriptor in words (unsigned int).
95 #define PROGRAM_SET_BSWAP(program) rta_program_set_bswap(program)
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)
102 * Return: the descriptor buffer offset where this command is inserted
105 #define WORD(program, val) rta_word(program, val)
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)
112 * Return: the descriptor buffer offset where this command is inserted
115 #define DWORD(program, val) rta_dword(program, val)
118 * COPY_DATA - must be called to insert in descriptor buffer data larger than
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)
124 * Return: the descriptor buffer offset where this command is inserted
127 #define COPY_DATA(program, data, len) rta_copy_data(program, (data), (len))
130 * DESC_LEN - determines job / shared descriptor buffer length (in words)
131 * @buffer: descriptor buffer (uint32_t *)
133 * Return: descriptor buffer length in words (unsigned int).
135 #define DESC_LEN(buffer) rta_desc_len(buffer)
138 * DESC_BYTES - determines job / shared descriptor buffer length (in bytes)
139 * @buffer: descriptor buffer (uint32_t *)
141 * Return: descriptor buffer length in bytes (unsigned int).
143 #define DESC_BYTES(buffer) rta_desc_bytes(buffer)
146 * SEC HW block revision.
148 * This *must not be confused with SEC version*:
149 * - SEC HW block revision format is "v"
150 * - SEC revision format is "x.y"
152 extern enum rta_sec_era rta_sec_era;
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)
159 * Return: 0 if the ERA was set successfully, -1 otherwise (int)
161 * Warning 1: Must be called *only once*, *before* using any other RTA API
164 * Warning 2: *Not thread safe*.
167 rta_set_sec_era(enum rta_sec_era era)
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);
181 * rta_get_sec_era - Get SEC Era HW block revision for which the RTA library
182 * will generate the descriptors.
184 * Return: SEC Era (unsigned int).
186 static inline unsigned int
187 rta_get_sec_era(void)
193 * DOC: SEC Commands Routines
195 * Contains details of RTA wrapper routines over SEC engine commands.
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
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
211 #define SHR_HDR(program, share, start_idx, flags) \
212 rta_shr_header(program, share, start_idx, flags)
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
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
229 #define JOB_HDR(program, share, start_idx, share_desc, flags) \
230 rta_job_header(program, share, start_idx, share_desc, flags, 0)
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
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
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, \
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,
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
266 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
267 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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
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)
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,
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
290 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
291 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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.
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
302 #define MOVEB(program, src, src_offset, dst, dst_offset, length, opt) \
303 rta_move(program, __MOVEB, src, src_offset, dst, dst_offset, length, \
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,
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
319 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
320 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
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
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
331 #define MOVEDW(program, src, src_offset, dst, dst_offset, length, opt) \
332 rta_move(program, __MOVEDW, src, src_offset, dst, dst_offset, length, \
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
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.
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
353 #define FIFOLOAD(program, data, src, length, flags) \
354 rta_fifo_load(program, data, src, length, flags)
357 * SEQFIFOLOAD - Configures SEQ FIFOLOAD command to load message data, PKHA
358 * data, IV, ICV, AAD and bit length message data into Input Data
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
365 * @flags: operational flags: VLF, CLASS1, CLASS2, BOTH, FLUSH1, LAST1, LAST2,
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
373 #define SEQFIFOLOAD(program, data, length, flags) \
374 rta_fifo_load(program, data, NONE, length, flags|SEQ)
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
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
392 #define FIFOSTORE(program, data, encrypt_flags, dst, length, flags) \
393 rta_fifo_store(program, data, encrypt_flags, dst, length, flags)
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
404 * @flags: operational flags: VLF, CONT, EXT, CLASS1, CLASS2, BOTH
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
411 #define SEQFIFOSTORE(program, data, encrypt_flags, length, flags) \
412 rta_fifo_store(program, data, encrypt_flags, 0, length, flags|SEQ)
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
424 * @flags: operational flags: for KEY: SGF, IMMED, COPY, DCOPY; for SEQKEY: SEQ,
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
432 #define KEY(program, key_dst, encrypt_flags, src, length, flags) \
433 rta_key(program, key_dst, encrypt_flags, src, length, flags)
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).
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
448 #define SEQINPTR(program, src, length, flags) \
449 rta_seq_in_ptr(program, src, length, flags)
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).
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
464 #define SEQOUTPTR(program, dst, length, flags) \
465 rta_seq_out_ptr(program, dst, length, flags)
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,
478 * @enc: selects between encryption and decryption: DIR_ENC, DIR_DEC
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
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)
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)
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)
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
504 #define PROTOCOL(program, optype, protid, protoinfo) \
505 rta_proto_operation(program, optype, protid, protoinfo)
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
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
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)
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).
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
542 #define PKHA_OPERATION(program, op_pkha) rta_pkha_operation(program, op_pkha)
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.
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
561 #define JUMP(program, addr, jump_type, test_type, cond) \
562 rta_jump(program, addr, jump_type, test_type, cond, NONE)
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.
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
578 #define JUMP_INC(program, addr, test_type, cond, src_dst) \
579 rta_jump(program, addr, LOCAL_JUMP_INC, test_type, cond, src_dst)
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.
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
595 #define JUMP_DEC(program, addr, test_type, cond, src_dst) \
596 rta_jump(program, addr, LOCAL_JUMP_DEC, test_type, cond, src_dst)
599 * LOAD - Configures LOAD command to load data registers from descriptor or from
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
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
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
615 #define LOAD(program, addr, dst, offset, length, flags) \
616 rta_load(program, addr, dst, offset, length, flags)
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
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
632 #define SEQLOAD(program, dst, offset, length, flags) \
633 rta_load(program, NONE, dst, offset, length, flags|SEQ)
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
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
655 #define STORE(program, src, offset, dst, length, flags) \
656 rta_store(program, src, offset, dst, length, flags)
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
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
677 #define SEQSTORE(program, src, offset, length, flags) \
678 rta_store(program, src, offset, NONE, length, flags|SEQ)
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
695 * @opt: operational flags: IFB, NFU, STL, SWP, IMMED, IMMED2
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
702 #define MATHB(program, operand1, operator, operand2, result, length, opt) \
703 rta_math(program, operand1, MATH_FUN_##operator, operand2, result, \
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,
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
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
723 * If !SSEL, @operand <@operator> @imm -> @result
724 * If SSEL, @imm <@operator> @operand -> @result
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
731 #define MATHI(program, operand, operator, imm, result, length, opt) \
732 rta_mathi(program, operand, MATH_FUN_##operator, imm, result, length, \
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
746 * @opt: operational flags: NFU, STL, SWP, IMMED
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
753 #define MATHU(program, operand1, operator, result, length, opt) \
754 rta_math(program, operand1, MATH_FUN_##operator, NONE, result, length, \
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,
764 * After SIGNATURE command, DWORD or WORD must be used to insert signature in
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
772 #define SIGNATURE(program, sign_type) rta_signature(program, sign_type)
775 * NFIFOADD - Configures NFIFO command, a shortcut of RTA Load command to write
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
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
795 #define NFIFOADD(program, src, data, length, flags) \
796 rta_nfifo_load(program, src, data, length, flags)
799 * DOC: Self Referential Code Management Routines
801 * Contains details of RTA self referential code routines.
805 * REFERENCE - initialize a variable used for storing an index inside a
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.
810 #define REFERENCE(ref) int ref = -1
813 * LABEL - initialize a variable used for storing an index inside a descriptor
815 * @label: label stores the value with what should be updated the REFERENCE line
816 * in the descriptor buffer.
818 #define LABEL(label) unsigned int label = 0
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
826 #define SET_LABEL(program, label) (label = rta_set_label(program))
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).
839 * Return: 0 in case of success, a negative error code if it fails
841 #define PATCH_JUMP(program, line, new_ref) rta_patch_jmp(program, line, new_ref)
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).
854 * Return: 0 in case of success, a negative error code if it fails
856 #define PATCH_MOVE(program, line, new_ref) \
857 rta_patch_move(program, line, new_ref)
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).
870 * Return: 0 in case of success, a negative error code if it fails
872 #define PATCH_LOAD(program, line, new_ref) \
873 rta_patch_load(program, line, new_ref)
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).
886 * Return: 0 in case of success, a negative error code if it fails
888 #define PATCH_STORE(program, line, new_ref) \
889 rta_patch_store(program, line, new_ref)
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.
902 * Return: 0 in case of success, a negative error code if it fails
904 #define PATCH_HDR(program, line, new_ref) \
905 rta_patch_header(program, line, new_ref)
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.
919 * Return: 0 in case of success, a negative error code if it fails
921 #define PATCH_RAW(program, line, mask, new_val) \
922 rta_patch_raw(program, line, mask, new_val)
924 #endif /* __RTA_RTA_H__ */