1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2016 Freescale Semiconductor Inc.
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)
489 * PROTOCOL - Configures PROTOCOL OPERATION command
490 * @program: pointer to struct program
491 * @optype: operation type: OP_TYPE_UNI_PROTOCOL / OP_TYPE_DECAP_PROTOCOL /
492 * OP_TYPE_ENCAP_PROTOCOL.
493 * @protid: protocol identifier value (check desc.h file for specific values)
494 * @protoinfo: protocol dependent value (check desc.h file for specific values)
496 * Return: On success, descriptor buffer offset where this command is inserted.
497 * On error, a negative error code; first error program counter will
498 * point to offset in descriptor buffer where the instruction should
501 #define PROTOCOL(program, optype, protid, protoinfo) \
502 rta_proto_operation(program, optype, protid, protoinfo)
505 * DKP_PROTOCOL - Configures DKP (Derived Key Protocol) PROTOCOL command
506 * @program: pointer to struct program
507 * @protid: protocol identifier value - one of the following:
508 * OP_PCLID_DKP_{MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512}
509 * @key_src: How the initial ("negotiated") key is provided to the DKP protocol.
510 * Valid values - one of OP_PCL_DKP_SRC_{IMM, SEQ, PTR, SGF}. Not all
511 * (key_src,key_dst) combinations are allowed.
512 * @key_dst: How the derived ("split") key is returned by the DKP protocol.
513 * Valid values - one of OP_PCL_DKP_DST_{IMM, SEQ, PTR, SGF}. Not all
514 * (key_src,key_dst) combinations are allowed.
515 * @keylen: length of the initial key, in bytes (uint16_t)
516 * @key: address where algorithm key resides; virtual address if key_type is
517 * RTA_DATA_IMM, physical (bus) address if key_type is RTA_DATA_PTR or
519 * @key_type: enum rta_data_type
520 * Return: On success, descriptor buffer offset where this command is inserted.
521 * On error, a negative error code; first error program counter will
522 * point to offset in descriptor buffer where the instruction should
525 #define DKP_PROTOCOL(program, protid, key_src, key_dst, keylen, key, key_type) \
526 rta_dkp_proto(program, protid, key_src, key_dst, keylen, key, key_type)
529 * PKHA_OPERATION - Configures PKHA OPERATION command
530 * @program: pointer to struct program
531 * @op_pkha: PKHA operation; indicates the modular arithmetic function to
532 * execute (check desc.h file for specific values).
534 * Return: On success, descriptor buffer offset where this command is inserted.
535 * On error, a negative error code; first error program counter will
536 * point to offset in descriptor buffer where the instruction should
539 #define PKHA_OPERATION(program, op_pkha) rta_pkha_operation(program, op_pkha)
542 * JUMP - Configures JUMP command
543 * @program: pointer to struct program
544 * @addr: local offset for local jumps or address pointer for non-local jumps;
545 * IMM or PTR macros must be used to indicate type.
546 * @jump_type: type of action taken by jump (enum rta_jump_type)
547 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
548 * @cond: jump conditions: operational flags - DONE1, DONE2, BOTH; various
549 * sharing and wait conditions (JSL = 1) - NIFP, NIP, NOP, NCP, CALM,
550 * SELF, SHARED, JQP; Math and PKHA status conditions (JSL = 0) - Z, N,
551 * NV, C, PK0, PK1, PKP.
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 JUMP(program, addr, jump_type, test_type, cond) \
559 rta_jump(program, addr, jump_type, test_type, cond, NONE)
562 * JUMP_INC - Configures JUMP_INC command
563 * @program: pointer to struct program
564 * @addr: local offset; IMM or PTR macros must be used to indicate type
565 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
566 * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
567 * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
568 * SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
570 * Return: On success, descriptor buffer offset where this command is inserted.
571 * On error, a negative error code; first error program counter will
572 * point to offset in descriptor buffer where the instruction should
575 #define JUMP_INC(program, addr, test_type, cond, src_dst) \
576 rta_jump(program, addr, LOCAL_JUMP_INC, test_type, cond, src_dst)
579 * JUMP_DEC - Configures JUMP_DEC command
580 * @program: pointer to struct program
581 * @addr: local offset; IMM or PTR macros must be used to indicate type
582 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
583 * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
584 * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
585 * SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
587 * Return: On success, descriptor buffer offset where this command is inserted.
588 * On error, a negative error code; first error program counter will
589 * point to offset in descriptor buffer where the instruction should
592 #define JUMP_DEC(program, addr, test_type, cond, src_dst) \
593 rta_jump(program, addr, LOCAL_JUMP_DEC, test_type, cond, src_dst)
596 * LOAD - Configures LOAD command to load data registers from descriptor or from
598 * @program: pointer to struct program
599 * @addr: immediate value or pointer to the data to be loaded; IMMED, COPY and
600 * DCOPY flags indicate action taken (inline imm data, inline ptr, inline
602 * @dst: destination register (uint64_t)
603 * @offset: start point to write data in destination register (uint32_t)
604 * @length: number of bytes to load (uint32_t)
605 * @flags: operational flags: VLF, IMMED, COPY, DCOPY
607 * Return: On success, descriptor buffer offset where this command is inserted.
608 * On error, a negative error code; first error program counter will
609 * point to offset in descriptor buffer where the instruction should
612 #define LOAD(program, addr, dst, offset, length, flags) \
613 rta_load(program, addr, dst, offset, length, flags)
616 * SEQLOAD - Configures SEQ LOAD command to load data registers from descriptor
617 * or from a memory location.
618 * @program: pointer to struct program
619 * @dst: destination register (uint64_t)
620 * @offset: start point to write data in destination register (uint32_t)
621 * @length: number of bytes to load (uint32_t)
622 * @flags: operational flags: SGF
624 * Return: On success, descriptor buffer offset where this command is inserted.
625 * On error, a negative error code; first error program counter will
626 * point to offset in descriptor buffer where the instruction should
629 #define SEQLOAD(program, dst, offset, length, flags) \
630 rta_load(program, NONE, dst, offset, length, flags|SEQ)
633 * STORE - Configures STORE command to read data from registers and write them
634 * to a memory location.
635 * @program: pointer to struct program
636 * @src: immediate value or source register for data to be stored: KEY1SZ,
637 * KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
638 * ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
639 * CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
640 * immediate value, IMMED, COPY and DCOPY flags indicate action taken
641 * (inline imm data, inline ptr, inline from ptr).
642 * @offset: start point for reading from source register (uint16_t)
643 * @dst: pointer to store location (uint64_t)
644 * @length: number of bytes to store (uint32_t)
645 * @flags: operational flags: VLF, IMMED, COPY, DCOPY
647 * Return: On success, descriptor buffer offset where this command is inserted.
648 * On error, a negative error code; first error program counter will
649 * point to offset in descriptor buffer where the instruction should
652 #define STORE(program, src, offset, dst, length, flags) \
653 rta_store(program, src, offset, dst, length, flags)
656 * SEQSTORE - Configures SEQ STORE command to read data from registers and write
657 * them to a memory location.
658 * @program: pointer to struct program
659 * @src: immediate value or source register for data to be stored: KEY1SZ,
660 * KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
661 * ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
662 * CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
663 * immediate value, IMMED, COPY and DCOPY flags indicate action taken
664 * (inline imm data, inline ptr, inline from ptr).
665 * @offset: start point for reading from source register (uint16_t)
666 * @length: number of bytes to store (uint32_t)
667 * @flags: operational flags: SGF, IMMED, COPY, DCOPY
669 * Return: On success, descriptor buffer offset where this command is inserted.
670 * On error, a negative error code; first error program counter will
671 * point to offset in descriptor buffer where the instruction should
674 #define SEQSTORE(program, src, offset, length, flags) \
675 rta_store(program, src, offset, NONE, length, flags|SEQ)
678 * MATHB - Configures MATHB command to perform binary operations
679 * @program: pointer to struct program
680 * @operand1: first operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
681 * VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
682 * indicate immediate value.
683 * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
684 * LSHIFT, RSHIFT, SHLD.
685 * @operand2: second operand: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD,
686 * OFIFO, JOBSRC, ZERO, ONE, Immediate value. IMMED2 must be used to
687 * indicate immediate value.
688 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
689 * NONE, VSEQINSZ, VSEQOUTSZ.
690 * @length: length in bytes of the operation and the immediate value, if there
692 * @opt: operational flags: IFB, NFU, STL, SWP, IMMED, IMMED2
694 * Return: On success, descriptor buffer offset where this command is inserted.
695 * On error, a negative error code; first error program counter will
696 * point to offset in descriptor buffer where the instruction should
699 #define MATHB(program, operand1, operator, operand2, result, length, opt) \
700 rta_math(program, operand1, MATH_FUN_##operator, operand2, result, \
704 * MATHI - Configures MATHI command to perform binary operations
705 * @program: pointer to struct program
706 * @operand: if !SSEL: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
707 * VSEQOUTSZ, ZERO, ONE.
708 * if SSEL: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD, OFIFO,
710 * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
711 * LSHIFT, RSHIFT, FBYT (for !SSEL only).
712 * @imm: Immediate value (uint8_t). IMMED must be used to indicate immediate
714 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
715 * NONE, VSEQINSZ, VSEQOUTSZ.
716 * @length: length in bytes of the operation and the immediate value, if there
717 * is one (int). @imm is left-extended with zeros if needed.
718 * @opt: operational flags: NFU, SSEL, SWP, IMMED
720 * If !SSEL, @operand <@operator> @imm -> @result
721 * If SSEL, @imm <@operator> @operand -> @result
723 * Return: On success, descriptor buffer offset where this command is inserted.
724 * On error, a negative error code; first error program counter will
725 * point to offset in descriptor buffer where the instruction should
728 #define MATHI(program, operand, operator, imm, result, length, opt) \
729 rta_mathi(program, operand, MATH_FUN_##operator, imm, result, length, \
733 * MATHU - Configures MATHU command to perform unary operations
734 * @program: pointer to struct program
735 * @operand1: operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
736 * VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
737 * indicate immediate value.
738 * @operator: function to be performed: ZBYT, BSWAP
739 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
740 * NONE, VSEQINSZ, VSEQOUTSZ.
741 * @length: length in bytes of the operation and the immediate value, if there
743 * @opt: operational flags: NFU, STL, SWP, IMMED
745 * Return: On success, descriptor buffer offset where this command is inserted.
746 * On error, a negative error code; first error program counter will
747 * point to offset in descriptor buffer where the instruction should
750 #define MATHU(program, operand1, operator, result, length, opt) \
751 rta_math(program, operand1, MATH_FUN_##operator, NONE, result, length, \
755 * SIGNATURE - Configures SIGNATURE command
756 * @program: pointer to struct program
757 * @sign_type: signature type: SIGN_TYPE_FINAL, SIGN_TYPE_FINAL_RESTORE,
758 * SIGN_TYPE_FINAL_NONZERO, SIGN_TYPE_IMM_2, SIGN_TYPE_IMM_3,
761 * After SIGNATURE command, DWORD or WORD must be used to insert signature in
764 * Return: On success, descriptor buffer offset where this command is inserted.
765 * On error, a negative error code; first error program counter will
766 * point to offset in descriptor buffer where the instruction should
769 #define SIGNATURE(program, sign_type) rta_signature(program, sign_type)
772 * NFIFOADD - Configures NFIFO command, a shortcut of RTA Load command to write
774 * @program: pointer to struct program
775 * @src: source for the input data in Alignment Block:IFIFO, OFIFO, PAD,
776 * MSGOUTSNOOP, ALTSOURCE, OFIFO_SYNC, MSGOUTSNOOP_ALT.
777 * @data: type of data that is going through the Input Data FIFO: MSG, MSG1,
778 * MSG2, IV1, IV2, ICV1, ICV2, SAD1, AAD1, AAD2, AFHA_SBOX, SKIP,
779 * PKHA registers, AB1, AB2, ABD.
780 * @length: length of the data copied in FIFO registers (uint32_t)
781 * @flags: select options between:
782 * -operational flags: LAST1, LAST2, FLUSH1, FLUSH2, OC, BP
783 * -when PAD is selected as source: BM, PR, PS
784 * -padding type: <em>PAD_ZERO, PAD_NONZERO, PAD_INCREMENT, PAD_RANDOM,
785 * PAD_ZERO_N1, PAD_NONZERO_0, PAD_N1, PAD_NONZERO_N
787 * Return: On success, descriptor buffer offset where this command is inserted.
788 * On error, a negative error code; first error program counter will
789 * point to offset in descriptor buffer where the instruction should
792 #define NFIFOADD(program, src, data, length, flags) \
793 rta_nfifo_load(program, src, data, length, flags)
796 * DOC: Self Referential Code Management Routines
798 * Contains details of RTA self referential code routines.
802 * REFERENCE - initialize a variable used for storing an index inside a
804 * @ref: reference to a descriptor buffer's index where an update is required
805 * with a value that will be known latter in the program flow.
807 #define REFERENCE(ref) int ref = -1
810 * LABEL - initialize a variable used for storing an index inside a descriptor
812 * @label: label stores the value with what should be updated the REFERENCE line
813 * in the descriptor buffer.
815 #define LABEL(label) unsigned int label = 0
818 * SET_LABEL - set a LABEL value
819 * @program: pointer to struct program
820 * @label: value that will be inserted in a line previously written in the
823 #define SET_LABEL(program, label) (label = rta_set_label(program))
826 * PATCH_JUMP - Auxiliary command to resolve self referential code
827 * @program: buffer to be updated (struct program *)
828 * @line: position in descriptor buffer where the update will be done; this
829 * value is previously retained in program flow using a reference near
830 * the sequence to be modified.
831 * @new_ref: updated value that will be inserted in descriptor buffer at the
832 * specified line; this value is previously obtained using SET_LABEL
833 * macro near the line that will be used as reference (unsigned int).
834 * For JUMP command, the value represents the offset field (in words).
836 * Return: 0 in case of success, a negative error code if it fails
838 #define PATCH_JUMP(program, line, new_ref) rta_patch_jmp(program, line, new_ref)
841 * PATCH_MOVE - Auxiliary command to resolve self referential code
842 * @program: buffer to be updated (struct program *)
843 * @line: position in descriptor buffer where the update will be done; this
844 * value is previously retained in program flow using a reference near
845 * the sequence to be modified.
846 * @new_ref: updated value that will be inserted in descriptor buffer at the
847 * specified line; this value is previously obtained using SET_LABEL
848 * macro near the line that will be used as reference (unsigned int).
849 * For MOVE command, the value represents the offset field (in words).
851 * Return: 0 in case of success, a negative error code if it fails
853 #define PATCH_MOVE(program, line, new_ref) \
854 rta_patch_move(program, line, new_ref)
857 * PATCH_LOAD - Auxiliary command to resolve self referential code
858 * @program: buffer to be updated (struct program *)
859 * @line: position in descriptor buffer where the update will be done; this
860 * value is previously retained in program flow using a reference near
861 * the sequence to be modified.
862 * @new_ref: updated value that will be inserted in descriptor buffer at the
863 * specified line; this value is previously obtained using SET_LABEL
864 * macro near the line that will be used as reference (unsigned int).
865 * For LOAD command, the value represents the offset field (in words).
867 * Return: 0 in case of success, a negative error code if it fails
869 #define PATCH_LOAD(program, line, new_ref) \
870 rta_patch_load(program, line, new_ref)
873 * PATCH_STORE - Auxiliary command to resolve self referential code
874 * @program: buffer to be updated (struct program *)
875 * @line: position in descriptor buffer where the update will be done; this
876 * value is previously retained in program flow using a reference near
877 * the sequence to be modified.
878 * @new_ref: updated value that will be inserted in descriptor buffer at the
879 * specified line; this value is previously obtained using SET_LABEL
880 * macro near the line that will be used as reference (unsigned int).
881 * For STORE command, the value represents the offset field (in words).
883 * Return: 0 in case of success, a negative error code if it fails
885 #define PATCH_STORE(program, line, new_ref) \
886 rta_patch_store(program, line, new_ref)
889 * PATCH_HDR - Auxiliary command to resolve self referential code
890 * @program: buffer to be updated (struct program *)
891 * @line: position in descriptor buffer where the update will be done; this
892 * value is previously retained in program flow using a reference near
893 * the sequence to be modified.
894 * @new_ref: updated value that will be inserted in descriptor buffer at the
895 * specified line; this value is previously obtained using SET_LABEL
896 * macro near the line that will be used as reference (unsigned int).
897 * For HEADER command, the value represents the start index field.
899 * Return: 0 in case of success, a negative error code if it fails
901 #define PATCH_HDR(program, line, new_ref) \
902 rta_patch_header(program, line, new_ref)
905 * PATCH_RAW - Auxiliary command to resolve self referential code
906 * @program: buffer to be updated (struct program *)
907 * @line: position in descriptor buffer where the update will be done; this
908 * value is previously retained in program flow using a reference near
909 * the sequence to be modified.
910 * @mask: mask to be used for applying the new value (unsigned int). The mask
911 * selects which bits from the provided @new_val are taken into
912 * consideration when overwriting the existing value.
913 * @new_val: updated value that will be masked using the provided mask value
914 * and inserted in descriptor buffer at the specified line.
916 * Return: 0 in case of success, a negative error code if it fails
918 #define PATCH_RAW(program, line, mask, new_val) \
919 rta_patch_raw(program, line, mask, new_val)
921 #endif /* __RTA_RTA_H__ */