1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017-2018 NXP
8 #define CMD_HDR_CTYPE_SD 0x16
9 #define CMD_HDR_CTYPE_JD 0x17
11 /* The maximum size of a SEC descriptor, in WORDs (32 bits). */
12 #define MAX_DESC_SIZE_WORDS 64
15 * Macros manipulating descriptors
17 /* Macro for setting the SD pointer in a JD. Common for all protocols
18 * supported by the SEC driver.
20 #define SEC_JD_SET_SD(descriptor, ptr, len) { \
21 (descriptor)->sd_ptr = (ptr); \
22 (descriptor)->deschdr.command.jd.shr_desc_len = (len); \
25 /* Macro for setting a pointer to the job which this descriptor processes.
26 * It eases the lookup procedure for identifying the descriptor that has
29 #define SEC_JD_SET_JOB_PTR(descriptor, ptr) \
30 ((descriptor)->job_ptr = (ptr))
32 /* Macro for setting up a JD. The structure of the JD is common across all
33 * supported protocols, thus its structure is identical.
35 #define SEC_JD_INIT(descriptor) ({ \
36 /* CTYPE = job descriptor \
41 * SHR = 1 (there's a shared descriptor referenced
42 * by this job descriptor,pointer in next word)
43 * REO = 1 (execute job descr. first, shared descriptor
46 * Descriptor Length = 0 ( to be completed @ runtime ) */ \
47 (descriptor)->deschdr.command.word = 0xB0801C0D; \
49 * CTYPE = SEQ OUT command * Scater Gather Flag = 0
50 * (can be updated @ runtime) PRE = 0 * EXT = 1
51 * (data length is in next word, following the * command)
53 (descriptor)->seq_out.command.word = 0xF8400000; /**/ \
55 * CTYPE = SEQ IN command
56 * Scater Gather Flag = 0 (can be updated @ runtime)
58 * EXT = 1 ( data length is in next word, following the
61 (descriptor)->seq_in.command.word = 0xF0400000; /**/ \
63 * In order to be compatible with QI scenarios, the DPOVRD value
64 * loaded must be formated like this:
65 * DPOVRD_EN (1b) | Res| DPOVRD Value (right aligned). */ \
66 (descriptor)->load_dpovrd.command.word = 0x16870004; \
67 /* By default, DPOVRD mechanism is disabled, thus the value to be
68 * LOAD-ed through the above descriptor command will be
70 (descriptor)->dpovrd = 0x00000000; \
73 /* Macro for setting the pointer to the input buffer in the JD, according to
74 * the parameters set by the user in the ::sec_packet_t structure.
76 #define SEC_JD_SET_IN_PTR(descriptor, phys_addr, offset, length) { \
77 (descriptor)->seq_in_ptr = (phys_addr) + (offset); \
78 (descriptor)->in_ext_length = (length); \
81 /* Macro for setting the pointer to the output buffer in the JD, according to
82 * the parameters set by the user in the ::sec_packet_t structure.
84 #define SEC_JD_SET_OUT_PTR(descriptor, phys_addr, offset, length) { \
85 (descriptor)->seq_out_ptr = (phys_addr) + (offset); \
86 (descriptor)->out_ext_length = (length); \
89 /* Macro for setting the Scatter-Gather flag in the SEQ IN command. Used in
90 * case the input buffer is split in multiple buffers, according to the user
93 #define SEC_JD_SET_SG_IN(descriptor) \
94 ((descriptor)->seq_in.command.field.sgf = 1)
96 /* Macro for setting the Scatter-Gather flag in the SEQ OUT command. Used in
97 * case the output buffer is split in multiple buffers, according to the user
100 #define SEC_JD_SET_SG_OUT(descriptor) \
101 ((descriptor)->seq_out.command.field.sgf = 1)
103 #define SEC_JD_SET_DPOVRD(descriptor) \
105 /* Macro for retrieving a descriptor's length. Works for both SD and JD. */
106 #define SEC_GET_DESC_LEN(descriptor) \
107 (((struct descriptor_header_s *)(descriptor))->command.sd.ctype == \
108 CMD_HDR_CTYPE_SD ? ((struct descriptor_header_s *) \
109 (descriptor))->command.sd.desclen : \
110 ((struct descriptor_header_s *)(descriptor))->command.jd.desclen)
112 /* Helper macro for dumping the hex representation of a descriptor */
113 #define SEC_DUMP_DESC(descriptor) { \
115 CAAM_JR_INFO("Des@ 0x%08x\n", (uint32_t)((uint32_t *)(descriptor)));\
117 __i < SEC_GET_DESC_LEN(descriptor); \
119 printf("0x%08x: 0x%08x\n", \
120 (uint32_t)(((uint32_t *)(descriptor)) + __i), \
121 *(((uint32_t *)(descriptor)) + __i)); \
124 /* Union describing a descriptor header.
126 struct descriptor_header_s {
130 /* 4 */ unsigned int ctype:5;
131 /* 5 */ unsigned int res1:2;
132 /* 7 */ unsigned int dnr:1;
133 /* 8 */ unsigned int one:1;
134 /* 9 */ unsigned int res2:1;
135 /* 10 */ unsigned int start_idx:6;
136 /* 16 */ unsigned int res3:2;
137 /* 18 */ unsigned int cif:1;
138 /* 19 */ unsigned int sc:1;
139 /* 20 */ unsigned int pd:1;
140 /* 21 */ unsigned int res4:1;
141 /* 22 */ unsigned int share:2;
142 /* 24 */ unsigned int res5:2;
143 /* 26 */ unsigned int desclen:6;
146 /* TODO only below struct members are corrected,
147 * all others also need to be reversed please verify it
149 /* 0 */ unsigned int desclen:7;
150 /* 7 */ unsigned int res4:1;
151 /* 8 */ unsigned int share:3;
152 /* 11 */ unsigned int reo:1;
153 /* 12 */ unsigned int shr:1;
154 /* 13 */ unsigned int mtd:1;
155 /* 14 */ unsigned int td:1;
156 /* 15 */ unsigned int zero:1;
157 /* 16 */ unsigned int shr_desc_len:6;
158 /* 22 */ unsigned int res2:1;
159 /* 23 */ unsigned int one:1;
160 /* 24 */ unsigned int dnr:1;
161 /* 25 */ unsigned int rsms:1;
162 /* 26 */ unsigned int res1:1;
163 /* 27 */ unsigned int ctype:5;
165 } __rte_packed command;
168 /* Union describing a KEY command in a descriptor.
170 struct key_command_s {
174 unsigned int ctype:5;
181 unsigned int kdest:4;
183 unsigned int rsvd1:5;
184 unsigned int length:10;
185 } __rte_packed field;
186 } __rte_packed command;
189 /* Union describing a PROTOCOL command
192 struct protocol_operation_command_s {
196 unsigned int ctype:5;
197 unsigned int optype:3;
198 unsigned char protid;
199 unsigned short protinfo;
200 } __rte_packed field;
201 } __rte_packed command;
204 /* Union describing a SEQIN command in a
207 struct seq_in_command_s {
211 unsigned int ctype:5;
220 unsigned int length:16;
222 } __rte_packed command;
225 /* Union describing a SEQOUT command in a
228 struct seq_out_command_s {
232 unsigned int ctype:5;
239 unsigned int length:16;
241 } __rte_packed command;
244 struct load_command_s {
248 unsigned int ctype:5;
249 unsigned int class:2;
253 unsigned char offset;
254 unsigned char length;
256 } __rte_packed command;
259 /* Structure encompassing a general shared descriptor of maximum
260 * size (64 WORDs). Usually, other specific shared descriptor structures
261 * will be type-casted to this one
265 uint32_t rsvd[MAX_DESC_SIZE_WORDS];
266 } __rte_packed __rte_aligned(64);
268 /* Structure encompassing a job descriptor which processes
269 * a single packet from a context. The job descriptor references
270 * a shared descriptor from a SEC context.
272 struct sec_job_descriptor_t {
273 struct descriptor_header_s deschdr;
275 struct seq_out_command_s seq_out;
276 dma_addr_t seq_out_ptr;
277 uint32_t out_ext_length;
278 struct seq_in_command_s seq_in;
279 dma_addr_t seq_in_ptr;
280 uint32_t in_ext_length;
281 struct load_command_s load_dpovrd;
283 } __rte_packed __rte_aligned(64);