1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2016 Freescale Semiconductor Inc.
4 * Copyright 2016,2019 NXP
7 #ifndef __RTA_LOAD_CMD_H__
8 #define __RTA_LOAD_CMD_H__
10 extern enum rta_sec_era rta_sec_era;
12 /* Allowed length and offset masks for each SEC Era in case DST = DCTRL */
13 static const uint32_t load_len_mask_allowed[] = {
26 static const uint32_t load_off_mask_allowed[] = {
42 #define IMM_DSNM 3 /* it doesn't matter the src type */
56 DSNM /* it doesn't matter the length/offset values */
62 enum e_lenoff len_off;
67 static const struct load_map load_dst[] = {
68 /*1*/ { KEY1SZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_KEYSZ_REG,
70 { KEY2SZ, LDST_CLASS_2_CCB | LDST_SRCDST_WORD_KEYSZ_REG,
72 { DATA1SZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_DATASZ_REG,
73 LENOF_448, IMM_MUST },
74 { DATA2SZ, LDST_CLASS_2_CCB | LDST_SRCDST_WORD_DATASZ_REG,
75 LENOF_448, IMM_MUST },
76 { ICV1SZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_ICVSZ_REG,
78 { ICV2SZ, LDST_CLASS_2_CCB | LDST_SRCDST_WORD_ICVSZ_REG,
80 { CCTRL, LDST_CLASS_IND_CCB | LDST_SRCDST_WORD_CHACTRL,
82 { DCTRL, LDST_CLASS_DECO | LDST_IMM | LDST_SRCDST_WORD_DECOCTRL,
84 { ICTRL, LDST_CLASS_IND_CCB | LDST_SRCDST_WORD_IRQCTRL,
86 { DPOVRD, LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_PCLOVRD,
88 { CLRW, LDST_CLASS_IND_CCB | LDST_SRCDST_WORD_CLRW,
90 { AAD1SZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_DECO_AAD_SZ,
92 { IV1SZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_CLASS1_IV_SZ,
94 { ALTDS1, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_ALTDS_CLASS1,
95 LENOF_448, IMM_MUST },
96 { PKASZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_A_SZ,
98 { PKBSZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_B_SZ,
100 { PKNSZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_N_SZ,
102 { PKESZ, LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_E_SZ,
104 { NFIFO, LDST_CLASS_IND_CCB | LDST_SRCDST_WORD_INFO_FIFO,
105 LENOF_48, IMM_MUST },
106 { IFIFO, LDST_SRCDST_BYTE_INFIFO, LENOF_18, IMM_MUST },
107 { OFIFO, LDST_SRCDST_BYTE_OUTFIFO, LENOF_18, IMM_MUST },
108 { MATH0, LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH0,
110 { MATH1, LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH1,
112 { MATH2, LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH2,
114 { MATH3, LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH3,
116 { CONTEXT1, LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_CONTEXT,
117 LENOF_128, IMM_CAN },
118 { CONTEXT2, LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_CONTEXT,
119 LENOF_128, IMM_CAN },
120 { KEY1, LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_KEY,
122 { KEY2, LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_KEY,
124 { DESCBUF, LDST_CLASS_DECO | LDST_SRCDST_WORD_DESCBUF,
126 { DPID, LDST_CLASS_DECO | LDST_SRCDST_WORD_PID,
127 LENOF_448, IMM_MUST },
128 /*32*/ { IDFNS, LDST_SRCDST_WORD_IFNSR, LENOF_18, IMM_MUST },
129 { ODFNS, LDST_SRCDST_WORD_OFNSR, LENOF_18, IMM_MUST },
130 { ALTSOURCE, LDST_SRCDST_BYTE_ALTSOURCE, LENOF_18, IMM_MUST },
131 /*35*/ { NFIFO_SZL, LDST_SRCDST_WORD_INFO_FIFO_SZL, LENOF_48, IMM_MUST },
132 { NFIFO_SZM, LDST_SRCDST_WORD_INFO_FIFO_SZM, LENOF_03, IMM_MUST },
133 { NFIFO_L, LDST_SRCDST_WORD_INFO_FIFO_L, LENOF_48, IMM_MUST },
134 { NFIFO_M, LDST_SRCDST_WORD_INFO_FIFO_M, LENOF_03, IMM_MUST },
135 { SZL, LDST_SRCDST_WORD_SZL, LENOF_48, IMM_MUST },
136 /*40*/ { SZM, LDST_SRCDST_WORD_SZM, LENOF_03, IMM_MUST }
140 * Allowed LOAD destinations for each SEC Era.
141 * Values represent the number of entries from load_dst[] that are supported.
143 static const unsigned int load_dst_sz[] = { 31, 34, 34, 40, 40,
147 load_check_len_offset(int pos, uint32_t length, uint32_t offset)
149 if ((load_dst[pos].dst == DCTRL) &&
150 ((length & ~load_len_mask_allowed[rta_sec_era]) ||
151 (offset & ~load_off_mask_allowed[rta_sec_era])))
154 switch (load_dst[pos].len_off) {
156 if ((length > 3) || (offset))
160 if ((length != 4) || (offset != 0))
164 if (!(((length == 4) && (offset == 0)) ||
165 ((length == 8) && (offset == 0))))
169 if (!(((length == 4) && (offset == 0)) ||
170 ((length == 4) && (offset == 4)) ||
171 ((length == 8) && (offset == 0))))
175 if ((length < 1) || (length > 8) || (offset != 0))
179 if ((length > 32) || (offset > 32) || ((offset + length) > 32))
183 if ((length > 24) || (offset > 24) || ((offset + length) > 24))
187 if ((length > 16) || (offset > 16) || ((offset + length) > 16))
191 if ((length > 8) || (offset > 8) || ((offset + length) > 8))
195 if ((length > 128) || (offset > 128) ||
196 ((offset + length) > 128))
200 if ((length < 1) || (length > 256) || ((length + offset) > 256))
215 rta_load(struct program *program, uint64_t src, uint64_t dst,
216 uint32_t offset, uint32_t length, uint32_t flags)
219 int pos = -1, ret = -EINVAL;
220 unsigned int start_pc = program->current_pc, i;
223 opcode = CMD_SEQ_LOAD;
227 if ((length & 0xffffff00) || (offset & 0xffffff00)) {
228 pr_err("LOAD: Bad length/offset passed. Should be 8 bits\n");
237 /* check load destination, length and offset and source type */
238 for (i = 0; i < load_dst_sz[rta_sec_era]; i++)
239 if (dst == load_dst[i].dst) {
244 pr_err("LOAD: Invalid dst. SEC Program Line: %d\n",
245 program->current_pc);
250 if (load_dst[pos].imm_src == IMM_NO) {
251 pr_err("LOAD: Invalid source type. SEC Program Line: %d\n",
252 program->current_pc);
256 } else if (load_dst[pos].imm_src == IMM_MUST) {
257 pr_err("LOAD IMM: Invalid source type. SEC Program Line: %d\n",
258 program->current_pc);
262 ret = load_check_len_offset(pos, length, offset);
264 pr_err("LOAD: Invalid length/offset. SEC Program Line: %d\n",
265 program->current_pc);
269 opcode |= load_dst[pos].dst_opcode;
271 /* DESC BUFFER: length / offset values are specified in 4-byte words */
272 if (dst == DESCBUF) {
273 opcode |= (length >> 2);
274 opcode |= ((offset >> 2) << LDST_OFFSET_SHIFT);
277 opcode |= (offset << LDST_OFFSET_SHIFT);
280 __rta_out32(program, opcode);
281 program->current_instruction++;
283 /* DECO CONTROL: skip writing pointer of imm data */
285 return (int)start_pc;
288 * For data copy, 3 possible ways to specify how to copy data:
289 * - IMMED & !COPY: copy data directly from src( max 8 bytes)
290 * - IMMED & COPY: copy data imm from the location specified by user
291 * - !IMMED and is not SEQ cmd: copy the address
294 __rta_inline_data(program, src, flags & __COPY_MASK, length);
295 else if (!(flags & SEQ))
296 __rta_out64(program, program->ps, src);
298 return (int)start_pc;
301 program->first_error_pc = start_pc;
302 program->current_instruction++;
306 #endif /* __RTA_LOAD_CMD_H__*/