New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / crypto / caam_jr / caam_jr_desc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017-2018 NXP
3  */
4
5 #ifndef CAAM_JR_DESC_H
6 #define CAAM_JR_DESC_H
7
8 #define CMD_HDR_CTYPE_SD                0x16
9 #define CMD_HDR_CTYPE_JD                0x17
10
11 /* The maximum size of a SEC descriptor, in WORDs (32 bits). */
12 #define MAX_DESC_SIZE_WORDS                     64
13
14 /*
15  * Macros manipulating descriptors
16  */
17 /* Macro for setting the SD pointer in a JD. Common for all protocols
18  * supported by the SEC driver.
19  */
20 #define SEC_JD_SET_SD(descriptor, ptr, len)        {      \
21         (descriptor)->sd_ptr = (ptr);                          \
22         (descriptor)->deschdr.command.jd.shr_desc_len = (len);      \
23 }
24
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
27  * completed.
28  */
29 #define SEC_JD_SET_JOB_PTR(descriptor, ptr) \
30         ((descriptor)->job_ptr = (ptr))
31
32 /* Macro for setting up a JD. The structure of the JD is common across all
33  * supported protocols, thus its structure is identical.
34  */
35 #define SEC_JD_INIT(descriptor)       ({ \
36         /* CTYPE = job descriptor                              \
37          * RSMS, DNR = 0
38          * ONE = 1
39          * Start Index = 0
40          * ZRO,TD, MTD = 0
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
44          *        after)
45          * SHARE = DEFER
46          * Descriptor Length = 0 ( to be completed @ runtime ) */ \
47         (descriptor)->deschdr.command.word = 0xB0801C0D;        \
48         /*
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)
52          * RTO = 0 */                                           \
53         (descriptor)->seq_out.command.word = 0xF8400000; /**/   \
54         /*
55          * CTYPE = SEQ IN command
56          * Scater Gather Flag = 0 (can be updated @ runtime)
57          * PRE = 0
58          * EXT = 1 ( data length is in next word, following the
59          *         command)
60          * RTO = 0 */                                           \
61         (descriptor)->seq_in.command.word  = 0xF0400000; /**/   \
62         /*
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
69          * 0x0000_0000. */                                      \
70         (descriptor)->dpovrd = 0x00000000;                      \
71 })
72
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.
75  */
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);                  \
79 }
80
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.
83  */
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);                        \
87 }
88
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
91  * specification.
92  */
93 #define SEC_JD_SET_SG_IN(descriptor) \
94         ((descriptor)->seq_in.command.field.sgf =  1)
95
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
98  * specification.
99  */
100 #define SEC_JD_SET_SG_OUT(descriptor) \
101         ((descriptor)->seq_out.command.field.sgf = 1)
102
103 #define SEC_JD_SET_DPOVRD(descriptor) \
104
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)
111
112 /* Helper macro for dumping the hex representation of a descriptor */
113 #define SEC_DUMP_DESC(descriptor) {                                     \
114         int __i;                                                        \
115         CAAM_JR_INFO("Des@ 0x%08x\n", (uint32_t)((uint32_t *)(descriptor)));\
116         for (__i = 0;                                           \
117                 __i < SEC_GET_DESC_LEN(descriptor);                     \
118                 __i++) {                                                \
119                 printf("0x%08x: 0x%08x\n",                      \
120                         (uint32_t)(((uint32_t *)(descriptor)) + __i),   \
121                         *(((uint32_t *)(descriptor)) + __i));           \
122         }                                                               \
123 }
124 /* Union describing a descriptor header.
125  */
126 struct descriptor_header_s {
127         union {
128                 uint32_t word;
129                 struct {
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;
144                 } sd;
145                 struct {
146                         /* TODO only below struct members are corrected,
147                          * all others also need to be reversed please verify it
148                          */
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;
164                 } jd;
165         } __rte_packed command;
166 } __rte_packed;
167
168 /* Union describing a KEY command in a descriptor.
169  */
170 struct key_command_s {
171         union {
172                 uint32_t word;
173                 struct {
174                         unsigned int ctype:5;
175                         unsigned int cls:2;
176                         unsigned int sgf:1;
177                         unsigned int imm:1;
178                         unsigned int enc:1;
179                         unsigned int nwb:1;
180                         unsigned int ekt:1;
181                         unsigned int kdest:4;
182                         unsigned int tk:1;
183                         unsigned int rsvd1:5;
184                         unsigned int length:10;
185                 } __rte_packed field;
186         } __rte_packed command;
187 } __rte_packed;
188
189 /* Union describing a PROTOCOL command
190  * in a descriptor.
191  */
192 struct protocol_operation_command_s {
193         union {
194                 uint32_t word;
195                 struct {
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;
202 } __rte_packed;
203
204 /* Union describing a SEQIN command in a
205  * descriptor.
206  */
207 struct seq_in_command_s {
208         union {
209                 uint32_t word;
210                 struct {
211                         unsigned int ctype:5;
212                         unsigned int res1:1;
213                         unsigned int inl:1;
214                         unsigned int sgf:1;
215                         unsigned int pre:1;
216                         unsigned int ext:1;
217                         unsigned int rto:1;
218                         unsigned int rjd:1;
219                         unsigned int res2:4;
220                         unsigned int length:16;
221                 } field;
222         } __rte_packed command;
223 } __rte_packed;
224
225 /* Union describing a SEQOUT command in a
226  * descriptor.
227  */
228 struct seq_out_command_s {
229         union {
230                 uint32_t word;
231                 struct {
232                         unsigned int ctype:5;
233                         unsigned int res1:2;
234                         unsigned int sgf:1;
235                         unsigned int pre:1;
236                         unsigned int ext:1;
237                         unsigned int rto:1;
238                         unsigned int res2:5;
239                         unsigned int length:16;
240                 } field;
241         } __rte_packed command;
242 } __rte_packed;
243
244 struct load_command_s {
245         union {
246                 uint32_t word;
247                 struct {
248                         unsigned int ctype:5;
249                         unsigned int class:2;
250                         unsigned int sgf:1;
251                         unsigned int imm:1;
252                         unsigned int dst:7;
253                         unsigned char offset;
254                         unsigned char length;
255                 } fields;
256         } __rte_packed command;
257 } __rte_packed;
258
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
262  * this one.
263  */
264 struct sec_sd_t {
265         uint32_t rsvd[MAX_DESC_SIZE_WORDS];
266 } __attribute__((packed, aligned(64)));
267
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.
271  */
272 struct sec_job_descriptor_t {
273         struct descriptor_header_s deschdr;
274         dma_addr_t sd_ptr;
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;
282         uint32_t dpovrd;
283 } __attribute__((packed, aligned(64)));
284
285 #endif