2 * Copyright 2008-2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: BSD-3-Clause or GPL-2.0+
10 #include "rta/sec_run_time_asm.h"
11 #include "rta/fifo_load_store_cmd.h"
12 #include "rta/header_cmd.h"
13 #include "rta/jump_cmd.h"
14 #include "rta/key_cmd.h"
15 #include "rta/load_cmd.h"
16 #include "rta/math_cmd.h"
17 #include "rta/move_cmd.h"
18 #include "rta/nfifo_cmd.h"
19 #include "rta/operation_cmd.h"
20 #include "rta/protocol_cmd.h"
21 #include "rta/seq_in_out_ptr_cmd.h"
22 #include "rta/signature_cmd.h"
23 #include "rta/store_cmd.h"
28 * RTA (Runtime Assembler) Library is an easy and flexible runtime method for
29 * writing SEC descriptors. It implements a thin abstraction layer above
30 * SEC commands set; the resulting code is compact and similar to a
31 * descriptor sequence.
33 * RTA library improves comprehension of the SEC code, adds flexibility for
34 * writing complex descriptors and keeps the code lightweight. Should be used
35 * by whom needs to encode descriptors at runtime, with comprehensible flow
36 * control in descriptor.
42 * RTA is used in kernel space by the SEC / CAAM (Cryptographic Acceleration and
43 * Assurance Module) kernel module (drivers/crypto/caam) and SEC / CAAM QI
44 * kernel module (Freescale QorIQ SDK).
46 * RTA is used in user space by USDPAA - User Space DataPath Acceleration
47 * Architecture (Freescale QorIQ SDK).
51 * DOC: Descriptor Buffer Management Routines
53 * Contains details of RTA descriptor buffer management and SEC Era
54 * management routines.
58 * PROGRAM_CNTXT_INIT - must be called before any descriptor run-time assembly
59 * call type field carry info i.e. whether descriptor is
60 * shared or job descriptor.
61 * @program: pointer to struct program
62 * @buffer: input buffer where the descriptor will be placed (uint32_t *)
63 * @offset: offset in input buffer from where the data will be written
66 #define PROGRAM_CNTXT_INIT(program, buffer, offset) \
67 rta_program_cntxt_init(program, buffer, offset)
70 * PROGRAM_FINALIZE - must be called to mark completion of RTA call.
71 * @program: pointer to struct program
73 * Return: total size of the descriptor in words or negative number on error.
75 #define PROGRAM_FINALIZE(program) rta_program_finalize(program)
78 * PROGRAM_SET_36BIT_ADDR - must be called to set pointer size to 36 bits
79 * @program: pointer to struct program
81 * Return: current size of the descriptor in words (unsigned int).
83 #define PROGRAM_SET_36BIT_ADDR(program) rta_program_set_36bit_addr(program)
86 * PROGRAM_SET_BSWAP - must be called to enable byte swapping
87 * @program: pointer to struct program
89 * Byte swapping on a 4-byte boundary will be performed at the end - when
90 * calling PROGRAM_FINALIZE().
92 * Return: current size of the descriptor in words (unsigned int).
94 #define PROGRAM_SET_BSWAP(program) rta_program_set_bswap(program)
97 * WORD - must be called to insert in descriptor buffer a 32bit value
98 * @program: pointer to struct program
99 * @val: input value to be written in descriptor buffer (uint32_t)
101 * Return: the descriptor buffer offset where this command is inserted
104 #define WORD(program, val) rta_word(program, val)
107 * DWORD - must be called to insert in descriptor buffer a 64bit value
108 * @program: pointer to struct program
109 * @val: input value to be written in descriptor buffer (uint64_t)
111 * Return: the descriptor buffer offset where this command is inserted
114 #define DWORD(program, val) rta_dword(program, val)
117 * COPY_DATA - must be called to insert in descriptor buffer data larger than
119 * @program: pointer to struct program
120 * @data: input data to be written in descriptor buffer (uint8_t *)
121 * @len: length of input data (unsigned int)
123 * Return: the descriptor buffer offset where this command is inserted
126 #define COPY_DATA(program, data, len) rta_copy_data(program, (data), (len))
129 * DESC_LEN - determines job / shared descriptor buffer length (in words)
130 * @buffer: descriptor buffer (uint32_t *)
132 * Return: descriptor buffer length in words (unsigned int).
134 #define DESC_LEN(buffer) rta_desc_len(buffer)
137 * DESC_BYTES - determines job / shared descriptor buffer length (in bytes)
138 * @buffer: descriptor buffer (uint32_t *)
140 * Return: descriptor buffer length in bytes (unsigned int).
142 #define DESC_BYTES(buffer) rta_desc_bytes(buffer)
145 * SEC HW block revision.
147 * This *must not be confused with SEC version*:
148 * - SEC HW block revision format is "v"
149 * - SEC revision format is "x.y"
151 extern enum rta_sec_era rta_sec_era;
154 * rta_set_sec_era - Set SEC Era HW block revision for which the RTA library
155 * will generate the descriptors.
156 * @era: SEC Era (enum rta_sec_era)
158 * Return: 0 if the ERA was set successfully, -1 otherwise (int)
160 * Warning 1: Must be called *only once*, *before* using any other RTA API
163 * Warning 2: *Not thread safe*.
166 rta_set_sec_era(enum rta_sec_era era)
168 if (era > MAX_SEC_ERA) {
169 rta_sec_era = DEFAULT_SEC_ERA;
170 pr_err("Unsupported SEC ERA. Defaulting to ERA %d\n",
171 DEFAULT_SEC_ERA + 1);
180 * rta_get_sec_era - Get SEC Era HW block revision for which the RTA library
181 * will generate the descriptors.
183 * Return: SEC Era (unsigned int).
185 static inline unsigned int
186 rta_get_sec_era(void)
192 * DOC: SEC Commands Routines
194 * Contains details of RTA wrapper routines over SEC engine commands.
198 * SHR_HDR - Configures Shared Descriptor HEADER command
199 * @program: pointer to struct program
200 * @share: descriptor share state (enum rta_share_type)
201 * @start_idx: index in descriptor buffer where the execution of the shared
202 * descriptor should start (@c unsigned int).
203 * @flags: operational flags: RIF, DNR, CIF, SC, PD
205 * Return: On success, descriptor buffer offset where this command is inserted.
206 * On error, a negative error code; first error program counter will
207 * point to offset in descriptor buffer where the instruction should
210 #define SHR_HDR(program, share, start_idx, flags) \
211 rta_shr_header(program, share, start_idx, flags)
214 * JOB_HDR - Configures JOB Descriptor HEADER command
215 * @program: pointer to struct program
216 * @share: descriptor share state (enum rta_share_type)
217 * @start_idx: index in descriptor buffer where the execution of the job
218 * descriptor should start (unsigned int). In case SHR bit is present
219 * in flags, this will be the shared descriptor length.
220 * @share_desc: pointer to shared descriptor, in case SHR bit is set (uint64_t)
221 * @flags: operational flags: RSMS, DNR, TD, MTD, REO, SHR
223 * Return: On success, descriptor buffer offset where this command is inserted.
224 * On error, a negative error code; first error program counter will
225 * point to offset in descriptor buffer where the instruction should
228 #define JOB_HDR(program, share, start_idx, share_desc, flags) \
229 rta_job_header(program, share, start_idx, share_desc, flags, 0)
232 * JOB_HDR_EXT - Configures JOB 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 job
236 * descriptor should start (unsigned int). In case SHR bit is present
237 * in flags, this will be the shared descriptor length.
238 * @share_desc: pointer to shared descriptor, in case SHR bit is set (uint64_t)
239 * @flags: operational flags: RSMS, DNR, TD, MTD, REO, SHR
240 * @ext_flags: extended header flags: DSV (DECO Select Valid), DECO Id (limited
243 * Return: On success, descriptor buffer offset where this command is inserted.
244 * On error, a negative error code; first error program counter will
245 * point to offset in descriptor buffer where the instruction should
248 #define JOB_HDR_EXT(program, share, start_idx, share_desc, flags, ext_flags) \
249 rta_job_header(program, share, start_idx, share_desc, flags | EXT, \
253 * MOVE - Configures MOVE and MOVE_LEN commands
254 * @program: pointer to struct program
255 * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
256 * DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
257 * @src_offset: offset in source data (uint16_t)
258 * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
259 * OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
261 * @dst_offset: offset in destination data (uint16_t)
262 * @length: size of data to be moved: for MOVE must be specified as immediate
263 * value and IMMED flag must be set; for MOVE_LEN must be specified
265 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
266 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
268 * Return: On success, descriptor buffer offset where this command is inserted.
269 * On error, a negative error code; first error program counter will
270 * point to offset in descriptor buffer where the instruction should
273 #define MOVE(program, src, src_offset, dst, dst_offset, length, opt) \
274 rta_move(program, __MOVE, src, src_offset, dst, dst_offset, length, opt)
277 * MOVEB - Configures MOVEB command
278 * @program: pointer to struct program
279 * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
280 * DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
281 * @src_offset: offset in source data (uint16_t)
282 * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
283 * OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
285 * @dst_offset: offset in destination data (uint16_t)
286 * @length: size of data to be moved: for MOVE must be specified as immediate
287 * value and IMMED flag must be set; for MOVE_LEN must be specified
289 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
290 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
292 * Identical with MOVE command if byte swapping not enabled; else - when src/dst
293 * is descriptor buffer or MATH registers, data type is byte array when MOVE
294 * data type is 4-byte array and vice versa.
296 * Return: On success, descriptor buffer offset where this command is inserted.
297 * On error, a negative error code; first error program counter will
298 * point to offset in descriptor buffer where the instruction should
301 #define MOVEB(program, src, src_offset, dst, dst_offset, length, opt) \
302 rta_move(program, __MOVEB, src, src_offset, dst, dst_offset, length, \
306 * MOVEDW - Configures MOVEDW command
307 * @program: pointer to struct program
308 * @src: internal source of data that will be moved: CONTEXT1, CONTEXT2, OFIFO,
309 * DESCBUF, MATH0-MATH3, IFIFOABD, IFIFOAB1, IFIFOAB2, AB1, AB2, ABD.
310 * @src_offset: offset in source data (uint16_t)
311 * @dst: internal destination of data that will be moved: CONTEXT1, CONTEXT2,
312 * OFIFO, DESCBUF, MATH0-MATH3, IFIFOAB1, IFIFOAB2, IFIFO, PKA, KEY1,
314 * @dst_offset: offset in destination data (uint16_t)
315 * @length: size of data to be moved: for MOVE must be specified as immediate
316 * value and IMMED flag must be set; for MOVE_LEN must be specified
318 * @opt: operational flags: WAITCOMP, FLUSH1, FLUSH2, LAST1, LAST2, SIZE_WORD,
319 * SIZE_BYTE, SIZE_DWORD, IMMED (not valid for MOVE_LEN).
321 * Identical with MOVE command, with the following differences: data type is
322 * 8-byte array; word swapping is performed when SEC is programmed in little
325 * Return: On success, descriptor buffer offset where this command is inserted.
326 * On error, a negative error code; first error program counter will
327 * point to offset in descriptor buffer where the instruction should
330 #define MOVEDW(program, src, src_offset, dst, dst_offset, length, opt) \
331 rta_move(program, __MOVEDW, src, src_offset, dst, dst_offset, length, \
335 * FIFOLOAD - Configures FIFOLOAD command to load message data, PKHA data, IV,
336 * ICV, AAD and bit length message data into Input Data FIFO.
337 * @program: pointer to struct program
338 * @data: input data type to store: PKHA registers, IFIFO, MSG1, MSG2,
339 * MSGOUTSNOOP, MSGINSNOOP, IV1, IV2, AAD1, ICV1, ICV2, BIT_DATA, SKIP.
340 * @src: pointer or actual data in case of immediate load; IMMED, COPY and DCOPY
341 * flags indicate action taken (inline imm data, inline ptr, inline from
343 * @length: number of bytes to load (uint32_t)
344 * @flags: operational flags: SGF, IMMED, EXT, CLASS1, CLASS2, BOTH, FLUSH1,
345 * LAST1, LAST2, COPY, DCOPY.
347 * Return: On success, descriptor buffer offset where this command is inserted.
348 * On error, a negative error code; first error program counter will
349 * point to offset in descriptor buffer where the instruction should
352 #define FIFOLOAD(program, data, src, length, flags) \
353 rta_fifo_load(program, data, src, length, flags)
356 * SEQFIFOLOAD - Configures SEQ FIFOLOAD command to load message data, PKHA
357 * data, IV, ICV, AAD and bit length message data into Input Data
359 * @program: pointer to struct program
360 * @data: input data type to store: PKHA registers, IFIFO, MSG1, MSG2,
361 * MSGOUTSNOOP, MSGINSNOOP, IV1, IV2, AAD1, ICV1, ICV2, BIT_DATA, SKIP.
362 * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
364 * @flags: operational flags: VLF, CLASS1, CLASS2, BOTH, FLUSH1, LAST1, LAST2,
367 * Return: On success, descriptor buffer offset where this command is inserted.
368 * On error, a negative error code; first error program counter will
369 * point to offset in descriptor buffer where the instruction should
372 #define SEQFIFOLOAD(program, data, length, flags) \
373 rta_fifo_load(program, data, NONE, length, flags|SEQ)
376 * FIFOSTORE - Configures FIFOSTORE command, to move data from Output Data FIFO
377 * to external memory via DMA.
378 * @program: pointer to struct program
379 * @data: output data type to store: PKHA registers, IFIFO, OFIFO, RNG,
380 * RNGOFIFO, AFHA_SBOX, MDHA_SPLIT_KEY, MSG, KEY1, KEY2, SKIP.
381 * @encrypt_flags: store data encryption mode: EKT, TK
382 * @dst: pointer to store location (uint64_t)
383 * @length: number of bytes to load (uint32_t)
384 * @flags: operational flags: SGF, CONT, EXT, CLASS1, CLASS2, BOTH
386 * Return: On success, descriptor buffer offset where this command is inserted.
387 * On error, a negative error code; first error program counter will
388 * point to offset in descriptor buffer where the instruction should
391 #define FIFOSTORE(program, data, encrypt_flags, dst, length, flags) \
392 rta_fifo_store(program, data, encrypt_flags, dst, length, flags)
395 * SEQFIFOSTORE - Configures SEQ FIFOSTORE command, to move data from Output
396 * Data FIFO to external memory via DMA.
397 * @program: pointer to struct program
398 * @data: output data type to store: PKHA registers, IFIFO, OFIFO, RNG,
399 * RNGOFIFO, AFHA_SBOX, MDHA_SPLIT_KEY, MSG, KEY1, KEY2, METADATA, SKIP.
400 * @encrypt_flags: store data encryption mode: EKT, TK
401 * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
403 * @flags: operational flags: VLF, CONT, EXT, CLASS1, CLASS2, BOTH
405 * Return: On success, descriptor buffer offset where this command is inserted.
406 * On error, a negative error code; first error program counter will
407 * point to offset in descriptor buffer where the instruction should
410 #define SEQFIFOSTORE(program, data, encrypt_flags, length, flags) \
411 rta_fifo_store(program, data, encrypt_flags, 0, length, flags|SEQ)
414 * KEY - Configures KEY and SEQ KEY commands
415 * @program: pointer to struct program
416 * @key_dst: key store location: KEY1, KEY2, PKE, AFHA_SBOX, MDHA_SPLIT_KEY
417 * @encrypt_flags: key encryption mode: ENC, EKT, TK, NWB, PTS
418 * @src: pointer or actual data in case of immediate load (uint64_t); IMMED,
419 * COPY and DCOPY flags indicate action taken (inline imm data,
420 * inline ptr, inline from ptr).
421 * @length: number of bytes to load; can be set to 0 for SEQ command w/ VLF set
423 * @flags: operational flags: for KEY: SGF, IMMED, COPY, DCOPY; for SEQKEY: SEQ,
426 * Return: On success, descriptor buffer offset where this command is inserted.
427 * On error, a negative error code; first error program counter will
428 * point to offset in descriptor buffer where the instruction should
431 #define KEY(program, key_dst, encrypt_flags, src, length, flags) \
432 rta_key(program, key_dst, encrypt_flags, src, length, flags)
435 * SEQINPTR - Configures SEQ IN PTR command
436 * @program: pointer to struct program
437 * @src: starting address for Input Sequence (uint64_t)
438 * @length: number of bytes in (or to be added to) Input Sequence (uint32_t)
439 * @flags: operational flags: RBS, INL, SGF, PRE, EXT, RTO, RJD, SOP (when PRE,
440 * RTO or SOP are set, @src parameter must be 0).
442 * Return: On success, descriptor buffer offset where this command is inserted.
443 * On error, a negative error code; first error program counter will
444 * point to offset in descriptor buffer where the instruction should
447 #define SEQINPTR(program, src, length, flags) \
448 rta_seq_in_ptr(program, src, length, flags)
451 * SEQOUTPTR - Configures SEQ OUT PTR command
452 * @program: pointer to struct program
453 * @dst: starting address for Output Sequence (uint64_t)
454 * @length: number of bytes in (or to be added to) Output Sequence (uint32_t)
455 * @flags: operational flags: SGF, PRE, EXT, RTO, RST, EWS (when PRE or RTO are
456 * set, @dst parameter must be 0).
458 * Return: On success, descriptor buffer offset where this command is inserted.
459 * On error, a negative error code; first error program counter will
460 * point to offset in descriptor buffer where the instruction should
463 #define SEQOUTPTR(program, dst, length, flags) \
464 rta_seq_out_ptr(program, dst, length, flags)
467 * ALG_OPERATION - Configures ALGORITHM OPERATION command
468 * @program: pointer to struct program
469 * @cipher_alg: algorithm to be used
470 * @aai: Additional Algorithm Information; contains mode information that is
471 * associated with the algorithm (check desc.h for specific values).
472 * @algo_state: algorithm state; defines the state of the algorithm that is
473 * being executed (check desc.h file for specific values).
474 * @icv_check: ICV checking; selects whether the algorithm should check
475 * calculated ICV with known ICV: ICV_CHECK_ENABLE,
477 * @enc: selects between encryption and decryption: DIR_ENC, DIR_DEC
479 * Return: On success, descriptor buffer offset where this command is inserted.
480 * On error, a negative error code; first error program counter will
481 * point to offset in descriptor buffer where the instruction should
484 #define ALG_OPERATION(program, cipher_alg, aai, algo_state, icv_check, enc) \
485 rta_operation(program, cipher_alg, aai, algo_state, icv_check, enc)
488 * PROTOCOL - Configures PROTOCOL OPERATION command
489 * @program: pointer to struct program
490 * @optype: operation type: OP_TYPE_UNI_PROTOCOL / OP_TYPE_DECAP_PROTOCOL /
491 * OP_TYPE_ENCAP_PROTOCOL.
492 * @protid: protocol identifier value (check desc.h file for specific values)
493 * @protoinfo: protocol dependent value (check desc.h file for specific values)
495 * Return: On success, descriptor buffer offset where this command is inserted.
496 * On error, a negative error code; first error program counter will
497 * point to offset in descriptor buffer where the instruction should
500 #define PROTOCOL(program, optype, protid, protoinfo) \
501 rta_proto_operation(program, optype, protid, protoinfo)
504 * DKP_PROTOCOL - Configures DKP (Derived Key Protocol) PROTOCOL command
505 * @program: pointer to struct program
506 * @protid: protocol identifier value - one of the following:
507 * OP_PCLID_DKP_{MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512}
508 * @key_src: How the initial ("negotiated") key is provided to the DKP protocol.
509 * Valid values - one of OP_PCL_DKP_SRC_{IMM, SEQ, PTR, SGF}. Not all
510 * (key_src,key_dst) combinations are allowed.
511 * @key_dst: How the derived ("split") key is returned by the DKP protocol.
512 * Valid values - one of OP_PCL_DKP_DST_{IMM, SEQ, PTR, SGF}. Not all
513 * (key_src,key_dst) combinations are allowed.
514 * @keylen: length of the initial key, in bytes (uint16_t)
515 * @key: address where algorithm key resides; virtual address if key_type is
516 * RTA_DATA_IMM, physical (bus) address if key_type is RTA_DATA_PTR or
518 * @key_type: enum rta_data_type
519 * Return: On success, descriptor buffer offset where this command is inserted.
520 * On error, a negative error code; first error program counter will
521 * point to offset in descriptor buffer where the instruction should
524 #define DKP_PROTOCOL(program, protid, key_src, key_dst, keylen, key, key_type) \
525 rta_dkp_proto(program, protid, key_src, key_dst, keylen, key, key_type)
528 * PKHA_OPERATION - Configures PKHA OPERATION command
529 * @program: pointer to struct program
530 * @op_pkha: PKHA operation; indicates the modular arithmetic function to
531 * execute (check desc.h file for specific values).
533 * Return: On success, descriptor buffer offset where this command is inserted.
534 * On error, a negative error code; first error program counter will
535 * point to offset in descriptor buffer where the instruction should
538 #define PKHA_OPERATION(program, op_pkha) rta_pkha_operation(program, op_pkha)
541 * JUMP - Configures JUMP command
542 * @program: pointer to struct program
543 * @addr: local offset for local jumps or address pointer for non-local jumps;
544 * IMM or PTR macros must be used to indicate type.
545 * @jump_type: type of action taken by jump (enum rta_jump_type)
546 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
547 * @cond: jump conditions: operational flags - DONE1, DONE2, BOTH; various
548 * sharing and wait conditions (JSL = 1) - NIFP, NIP, NOP, NCP, CALM,
549 * SELF, SHARED, JQP; Math and PKHA status conditions (JSL = 0) - Z, N,
550 * NV, C, PK0, PK1, PKP.
552 * Return: On success, descriptor buffer offset where this command is inserted.
553 * On error, a negative error code; first error program counter will
554 * point to offset in descriptor buffer where the instruction should
557 #define JUMP(program, addr, jump_type, test_type, cond) \
558 rta_jump(program, addr, jump_type, test_type, cond, NONE)
561 * JUMP_INC - Configures JUMP_INC command
562 * @program: pointer to struct program
563 * @addr: local offset; IMM or PTR macros must be used to indicate type
564 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
565 * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
566 * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
567 * SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
569 * Return: On success, descriptor buffer offset where this command is inserted.
570 * On error, a negative error code; first error program counter will
571 * point to offset in descriptor buffer where the instruction should
574 #define JUMP_INC(program, addr, test_type, cond, src_dst) \
575 rta_jump(program, addr, LOCAL_JUMP_INC, test_type, cond, src_dst)
578 * JUMP_DEC - Configures JUMP_DEC command
579 * @program: pointer to struct program
580 * @addr: local offset; IMM or PTR macros must be used to indicate type
581 * @test_type: defines how jump conditions are evaluated (enum rta_jump_cond)
582 * @cond: jump conditions: Math status conditions (JSL = 0): Z, N, NV, C
583 * @src_dst: register to increment / decrement: MATH0-MATH3, DPOVRD, SEQINSZ,
584 * SEQOUTSZ, VSEQINSZ, VSEQOUTSZ.
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_DEC(program, addr, test_type, cond, src_dst) \
592 rta_jump(program, addr, LOCAL_JUMP_DEC, test_type, cond, src_dst)
595 * LOAD - Configures LOAD command to load data registers from descriptor or from
597 * @program: pointer to struct program
598 * @addr: immediate value or pointer to the data to be loaded; IMMED, COPY and
599 * DCOPY flags indicate action taken (inline imm data, inline ptr, inline
601 * @dst: destination register (uint64_t)
602 * @offset: start point to write data in destination register (uint32_t)
603 * @length: number of bytes to load (uint32_t)
604 * @flags: operational flags: VLF, IMMED, COPY, DCOPY
606 * Return: On success, descriptor buffer offset where this command is inserted.
607 * On error, a negative error code; first error program counter will
608 * point to offset in descriptor buffer where the instruction should
611 #define LOAD(program, addr, dst, offset, length, flags) \
612 rta_load(program, addr, dst, offset, length, flags)
615 * SEQLOAD - Configures SEQ LOAD command to load data registers from descriptor
616 * or from a memory location.
617 * @program: pointer to struct program
618 * @dst: destination register (uint64_t)
619 * @offset: start point to write data in destination register (uint32_t)
620 * @length: number of bytes to load (uint32_t)
621 * @flags: operational flags: SGF
623 * Return: On success, descriptor buffer offset where this command is inserted.
624 * On error, a negative error code; first error program counter will
625 * point to offset in descriptor buffer where the instruction should
628 #define SEQLOAD(program, dst, offset, length, flags) \
629 rta_load(program, NONE, dst, offset, length, flags|SEQ)
632 * STORE - Configures STORE command to read data from registers and write them
633 * to a memory location.
634 * @program: pointer to struct program
635 * @src: immediate value or source register for data to be stored: KEY1SZ,
636 * KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
637 * ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
638 * CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
639 * immediate value, IMMED, COPY and DCOPY flags indicate action taken
640 * (inline imm data, inline ptr, inline from ptr).
641 * @offset: start point for reading from source register (uint16_t)
642 * @dst: pointer to store location (uint64_t)
643 * @length: number of bytes to store (uint32_t)
644 * @flags: operational flags: VLF, IMMED, COPY, DCOPY
646 * Return: On success, descriptor buffer offset where this command is inserted.
647 * On error, a negative error code; first error program counter will
648 * point to offset in descriptor buffer where the instruction should
651 #define STORE(program, src, offset, dst, length, flags) \
652 rta_store(program, src, offset, dst, length, flags)
655 * SEQSTORE - Configures SEQ STORE command to read data from registers and write
656 * them to a memory location.
657 * @program: pointer to struct program
658 * @src: immediate value or source register for data to be stored: KEY1SZ,
659 * KEY2SZ, DJQDA, MODE1, MODE2, DJQCTRL, DATA1SZ, DATA2SZ, DSTAT, ICV1SZ,
660 * ICV2SZ, DPID, CCTRL, ICTRL, CLRW, CSTAT, MATH0-MATH3, PKHA registers,
661 * CONTEXT1, CONTEXT2, DESCBUF, JOBDESCBUF, SHAREDESCBUF. In case of
662 * immediate value, IMMED, COPY and DCOPY flags indicate action taken
663 * (inline imm data, inline ptr, inline from ptr).
664 * @offset: start point for reading from source register (uint16_t)
665 * @length: number of bytes to store (uint32_t)
666 * @flags: operational flags: SGF, IMMED, COPY, DCOPY
668 * Return: On success, descriptor buffer offset where this command is inserted.
669 * On error, a negative error code; first error program counter will
670 * point to offset in descriptor buffer where the instruction should
673 #define SEQSTORE(program, src, offset, length, flags) \
674 rta_store(program, src, offset, NONE, length, flags|SEQ)
677 * MATHB - Configures MATHB command to perform binary operations
678 * @program: pointer to struct program
679 * @operand1: first operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
680 * VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
681 * indicate immediate value.
682 * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
683 * LSHIFT, RSHIFT, SHLD.
684 * @operand2: second operand: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD,
685 * OFIFO, JOBSRC, ZERO, ONE, Immediate value. IMMED2 must be used to
686 * indicate immediate value.
687 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
688 * NONE, VSEQINSZ, VSEQOUTSZ.
689 * @length: length in bytes of the operation and the immediate value, if there
691 * @opt: operational flags: IFB, NFU, STL, SWP, IMMED, IMMED2
693 * Return: On success, descriptor buffer offset where this command is inserted.
694 * On error, a negative error code; first error program counter will
695 * point to offset in descriptor buffer where the instruction should
698 #define MATHB(program, operand1, operator, operand2, result, length, opt) \
699 rta_math(program, operand1, MATH_FUN_##operator, operand2, result, \
703 * MATHI - Configures MATHI command to perform binary operations
704 * @program: pointer to struct program
705 * @operand: if !SSEL: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
706 * VSEQOUTSZ, ZERO, ONE.
707 * if SSEL: MATH0-MATH3, DPOVRD, VSEQINSZ, VSEQOUTSZ, ABD, OFIFO,
709 * @operator: function to be performed: ADD, ADDC, SUB, SUBB, OR, AND, XOR,
710 * LSHIFT, RSHIFT, FBYT (for !SSEL only).
711 * @imm: Immediate value (uint8_t). IMMED must be used to indicate immediate
713 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
714 * NONE, VSEQINSZ, VSEQOUTSZ.
715 * @length: length in bytes of the operation and the immediate value, if there
716 * is one (int). @imm is left-extended with zeros if needed.
717 * @opt: operational flags: NFU, SSEL, SWP, IMMED
719 * If !SSEL, @operand <@operator> @imm -> @result
720 * If SSEL, @imm <@operator> @operand -> @result
722 * Return: On success, descriptor buffer offset where this command is inserted.
723 * On error, a negative error code; first error program counter will
724 * point to offset in descriptor buffer where the instruction should
727 #define MATHI(program, operand, operator, imm, result, length, opt) \
728 rta_mathi(program, operand, MATH_FUN_##operator, imm, result, length, \
732 * MATHU - Configures MATHU command to perform unary operations
733 * @program: pointer to struct program
734 * @operand1: operand: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ, VSEQINSZ,
735 * VSEQOUTSZ, ZERO, ONE, NONE, Immediate value. IMMED must be used to
736 * indicate immediate value.
737 * @operator: function to be performed: ZBYT, BSWAP
738 * @result: destination for the result: MATH0-MATH3, DPOVRD, SEQINSZ, SEQOUTSZ,
739 * NONE, VSEQINSZ, VSEQOUTSZ.
740 * @length: length in bytes of the operation and the immediate value, if there
742 * @opt: operational flags: NFU, STL, SWP, IMMED
744 * Return: On success, descriptor buffer offset where this command is inserted.
745 * On error, a negative error code; first error program counter will
746 * point to offset in descriptor buffer where the instruction should
749 #define MATHU(program, operand1, operator, result, length, opt) \
750 rta_math(program, operand1, MATH_FUN_##operator, NONE, result, length, \
754 * SIGNATURE - Configures SIGNATURE command
755 * @program: pointer to struct program
756 * @sign_type: signature type: SIGN_TYPE_FINAL, SIGN_TYPE_FINAL_RESTORE,
757 * SIGN_TYPE_FINAL_NONZERO, SIGN_TYPE_IMM_2, SIGN_TYPE_IMM_3,
760 * After SIGNATURE command, DWORD or WORD must be used to insert signature in
763 * Return: On success, descriptor buffer offset where this command is inserted.
764 * On error, a negative error code; first error program counter will
765 * point to offset in descriptor buffer where the instruction should
768 #define SIGNATURE(program, sign_type) rta_signature(program, sign_type)
771 * NFIFOADD - Configures NFIFO command, a shortcut of RTA Load command to write
773 * @program: pointer to struct program
774 * @src: source for the input data in Alignment Block:IFIFO, OFIFO, PAD,
775 * MSGOUTSNOOP, ALTSOURCE, OFIFO_SYNC, MSGOUTSNOOP_ALT.
776 * @data: type of data that is going through the Input Data FIFO: MSG, MSG1,
777 * MSG2, IV1, IV2, ICV1, ICV2, SAD1, AAD1, AAD2, AFHA_SBOX, SKIP,
778 * PKHA registers, AB1, AB2, ABD.
779 * @length: length of the data copied in FIFO registers (uint32_t)
780 * @flags: select options between:
781 * -operational flags: LAST1, LAST2, FLUSH1, FLUSH2, OC, BP
782 * -when PAD is selected as source: BM, PR, PS
783 * -padding type: <em>PAD_ZERO, PAD_NONZERO, PAD_INCREMENT, PAD_RANDOM,
784 * PAD_ZERO_N1, PAD_NONZERO_0, PAD_N1, PAD_NONZERO_N
786 * Return: On success, descriptor buffer offset where this command is inserted.
787 * On error, a negative error code; first error program counter will
788 * point to offset in descriptor buffer where the instruction should
791 #define NFIFOADD(program, src, data, length, flags) \
792 rta_nfifo_load(program, src, data, length, flags)
795 * DOC: Self Referential Code Management Routines
797 * Contains details of RTA self referential code routines.
801 * REFERENCE - initialize a variable used for storing an index inside a
803 * @ref: reference to a descriptor buffer's index where an update is required
804 * with a value that will be known latter in the program flow.
806 #define REFERENCE(ref) int ref = -1
809 * LABEL - initialize a variable used for storing an index inside a descriptor
811 * @label: label stores the value with what should be updated the REFERENCE line
812 * in the descriptor buffer.
814 #define LABEL(label) unsigned int label = 0
817 * SET_LABEL - set a LABEL value
818 * @program: pointer to struct program
819 * @label: value that will be inserted in a line previously written in the
822 #define SET_LABEL(program, label) (label = rta_set_label(program))
825 * PATCH_JUMP - Auxiliary command to resolve self referential code
826 * @program: buffer to be updated (struct program *)
827 * @line: position in descriptor buffer where the update will be done; this
828 * value is previously retained in program flow using a reference near
829 * the sequence to be modified.
830 * @new_ref: updated value that will be inserted in descriptor buffer at the
831 * specified line; this value is previously obtained using SET_LABEL
832 * macro near the line that will be used as reference (unsigned int).
833 * For JUMP command, the value represents the offset field (in words).
835 * Return: 0 in case of success, a negative error code if it fails
837 #define PATCH_JUMP(program, line, new_ref) rta_patch_jmp(program, line, new_ref)
840 * PATCH_MOVE - Auxiliary command to resolve self referential code
841 * @program: buffer to be updated (struct program *)
842 * @line: position in descriptor buffer where the update will be done; this
843 * value is previously retained in program flow using a reference near
844 * the sequence to be modified.
845 * @new_ref: updated value that will be inserted in descriptor buffer at the
846 * specified line; this value is previously obtained using SET_LABEL
847 * macro near the line that will be used as reference (unsigned int).
848 * For MOVE command, the value represents the offset field (in words).
850 * Return: 0 in case of success, a negative error code if it fails
852 #define PATCH_MOVE(program, line, new_ref) \
853 rta_patch_move(program, line, new_ref)
856 * PATCH_LOAD - Auxiliary command to resolve self referential code
857 * @program: buffer to be updated (struct program *)
858 * @line: position in descriptor buffer where the update will be done; this
859 * value is previously retained in program flow using a reference near
860 * the sequence to be modified.
861 * @new_ref: updated value that will be inserted in descriptor buffer at the
862 * specified line; this value is previously obtained using SET_LABEL
863 * macro near the line that will be used as reference (unsigned int).
864 * For LOAD command, the value represents the offset field (in words).
866 * Return: 0 in case of success, a negative error code if it fails
868 #define PATCH_LOAD(program, line, new_ref) \
869 rta_patch_load(program, line, new_ref)
872 * PATCH_STORE - Auxiliary command to resolve self referential code
873 * @program: buffer to be updated (struct program *)
874 * @line: position in descriptor buffer where the update will be done; this
875 * value is previously retained in program flow using a reference near
876 * the sequence to be modified.
877 * @new_ref: updated value that will be inserted in descriptor buffer at the
878 * specified line; this value is previously obtained using SET_LABEL
879 * macro near the line that will be used as reference (unsigned int).
880 * For STORE command, the value represents the offset field (in words).
882 * Return: 0 in case of success, a negative error code if it fails
884 #define PATCH_STORE(program, line, new_ref) \
885 rta_patch_store(program, line, new_ref)
888 * PATCH_HDR - Auxiliary command to resolve self referential code
889 * @program: buffer to be updated (struct program *)
890 * @line: position in descriptor buffer where the update will be done; this
891 * value is previously retained in program flow using a reference near
892 * the sequence to be modified.
893 * @new_ref: updated value that will be inserted in descriptor buffer at the
894 * specified line; this value is previously obtained using SET_LABEL
895 * macro near the line that will be used as reference (unsigned int).
896 * For HEADER command, the value represents the start index field.
898 * Return: 0 in case of success, a negative error code if it fails
900 #define PATCH_HDR(program, line, new_ref) \
901 rta_patch_header(program, line, new_ref)
904 * PATCH_RAW - Auxiliary command to resolve self referential code
905 * @program: buffer to be updated (struct program *)
906 * @line: position in descriptor buffer where the update will be done; this
907 * value is previously retained in program flow using a reference near
908 * the sequence to be modified.
909 * @mask: mask to be used for applying the new value (unsigned int). The mask
910 * selects which bits from the provided @new_val are taken into
911 * consideration when overwriting the existing value.
912 * @new_val: updated value that will be masked using the provided mask value
913 * and inserted in descriptor buffer at the specified line.
915 * Return: 0 in case of success, a negative error code if it fails
917 #define PATCH_RAW(program, line, mask, new_val) \
918 rta_patch_raw(program, line, mask, new_val)
920 #endif /* __RTA_RTA_H__ */