crypto/dpaa2_sec: support CAAM HW era 10
[dpdk.git] / drivers / crypto / dpaa2_sec / hw / rta / header_cmd.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2008-2016 Freescale Semiconductor Inc.
4  * Copyright 2016,2019 NXP
5  */
6
7 #ifndef __RTA_HEADER_CMD_H__
8 #define __RTA_HEADER_CMD_H__
9
10 extern enum rta_sec_era rta_sec_era;
11
12 /* Allowed job header flags for each SEC Era. */
13 static const uint32_t job_header_flags[] = {
14         DNR | TD | MTD | SHR | REO,
15         DNR | TD | MTD | SHR | REO | RSMS,
16         DNR | TD | MTD | SHR | REO | RSMS,
17         DNR | TD | MTD | SHR | REO | RSMS,
18         DNR | TD | MTD | SHR | REO | RSMS | EXT,
19         DNR | TD | MTD | SHR | REO | RSMS | EXT,
20         DNR | TD | MTD | SHR | REO | RSMS | EXT,
21         DNR | TD | MTD | SHR | REO | EXT,
22         DNR | TD | MTD | SHR | REO | EXT,
23         DNR | TD | MTD | SHR | REO | EXT
24 };
25
26 /* Allowed shared header flags for each SEC Era. */
27 static const uint32_t shr_header_flags[] = {
28         DNR | SC | PD,
29         DNR | SC | PD | CIF,
30         DNR | SC | PD | CIF,
31         DNR | SC | PD | CIF | RIF,
32         DNR | SC | PD | CIF | RIF,
33         DNR | SC | PD | CIF | RIF,
34         DNR | SC | PD | CIF | RIF,
35         DNR | SC | PD | CIF | RIF,
36         DNR | SC | PD | CIF | RIF,
37         DNR | SC | PD | CIF | RIF
38 };
39
40 static inline int
41 rta_shr_header(struct program *program,
42                enum rta_share_type share,
43                unsigned int start_idx,
44                uint32_t flags)
45 {
46         uint32_t opcode = CMD_SHARED_DESC_HDR;
47         unsigned int start_pc = program->current_pc;
48
49         if (flags & ~shr_header_flags[rta_sec_era]) {
50                 pr_err("SHR_DESC: Flag(s) not supported by SEC Era %d\n",
51                        USER_SEC_ERA(rta_sec_era));
52                 goto err;
53         }
54
55         switch (share) {
56         case SHR_ALWAYS:
57                 opcode |= HDR_SHARE_ALWAYS;
58                 break;
59         case SHR_SERIAL:
60                 opcode |= HDR_SHARE_SERIAL;
61                 break;
62         case SHR_NEVER:
63                 /*
64                  * opcode |= HDR_SHARE_NEVER;
65                  * HDR_SHARE_NEVER is 0
66                  */
67                 break;
68         case SHR_WAIT:
69                 opcode |= HDR_SHARE_WAIT;
70                 break;
71         default:
72                 pr_err("SHR_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
73                        program->current_pc);
74                 goto err;
75         }
76
77         opcode |= HDR_ONE;
78         if (rta_sec_era >= RTA_SEC_ERA_10)
79                 opcode |= (start_idx << HDR_START_IDX_SHIFT) &
80                                 HDR_START_IDX_MASK_ERA10;
81         else
82                 opcode |= (start_idx << HDR_START_IDX_SHIFT) &
83                                 HDR_START_IDX_MASK;
84
85         if (flags & DNR)
86                 opcode |= HDR_DNR;
87         if (flags & CIF)
88                 opcode |= HDR_CLEAR_IFIFO;
89         if (flags & SC)
90                 opcode |= HDR_SAVECTX;
91         if (flags & PD)
92                 opcode |= HDR_PROP_DNR;
93         if (flags & RIF)
94                 opcode |= HDR_RIF;
95
96         __rta_out32(program, opcode);
97         program->current_instruction++;
98
99         if (program->current_instruction == 1)
100                 program->shrhdr = program->buffer;
101
102         return (int)start_pc;
103
104  err:
105         program->first_error_pc = start_pc;
106         program->current_instruction++;
107         return -EINVAL;
108 }
109
110 static inline int
111 rta_job_header(struct program *program,
112                enum rta_share_type share,
113                unsigned int start_idx,
114                uint64_t shr_desc, uint32_t flags,
115                uint32_t ext_flags)
116 {
117         uint32_t opcode = CMD_DESC_HDR;
118         uint32_t hdr_ext = 0;
119         unsigned int start_pc = program->current_pc;
120
121         if (flags & ~job_header_flags[rta_sec_era]) {
122                 pr_err("JOB_DESC: Flag(s) not supported by SEC Era %d\n",
123                        USER_SEC_ERA(rta_sec_era));
124                 goto err;
125         }
126
127         switch (share) {
128         case SHR_ALWAYS:
129                 opcode |= HDR_SHARE_ALWAYS;
130                 break;
131         case SHR_SERIAL:
132                 opcode |= HDR_SHARE_SERIAL;
133                 break;
134         case SHR_NEVER:
135                 /*
136                  * opcode |= HDR_SHARE_NEVER;
137                  * HDR_SHARE_NEVER is 0
138                  */
139                 break;
140         case SHR_WAIT:
141                 opcode |= HDR_SHARE_WAIT;
142                 break;
143         case SHR_DEFER:
144                 opcode |= HDR_SHARE_DEFER;
145                 break;
146         default:
147                 pr_err("JOB_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
148                        program->current_pc);
149                 goto err;
150         }
151
152         if ((flags & TD) && (flags & REO)) {
153                 pr_err("JOB_DESC: REO flag not supported for trusted descriptors. SEC Program Line: %d\n",
154                        program->current_pc);
155                 goto err;
156         }
157
158         if ((rta_sec_era < RTA_SEC_ERA_7) && (flags & MTD) && !(flags & TD)) {
159                 pr_err("JOB_DESC: Trying to MTD a descriptor that is not a TD. SEC Program Line: %d\n",
160                        program->current_pc);
161                 goto err;
162         }
163
164         if ((flags & EXT) && !(flags & SHR) && (start_idx < 2)) {
165                 pr_err("JOB_DESC: Start index must be >= 2 in case of no SHR and EXT. SEC Program Line: %d\n",
166                        program->current_pc);
167                 goto err;
168         }
169
170         opcode |= HDR_ONE;
171         if (rta_sec_era >= RTA_SEC_ERA_10)
172                 opcode |= (start_idx << HDR_START_IDX_SHIFT) &
173                                 HDR_START_IDX_MASK_ERA10;
174         else
175                 opcode |= (start_idx << HDR_START_IDX_SHIFT) &
176                                 HDR_START_IDX_MASK;
177
178         if (flags & EXT) {
179                 opcode |= HDR_EXT;
180
181                 if (ext_flags & DSV) {
182                         hdr_ext |= HDR_EXT_DSEL_VALID;
183                         hdr_ext |= ext_flags & DSEL_MASK;
184                 }
185
186                 if (ext_flags & FTD) {
187                         if (rta_sec_era <= RTA_SEC_ERA_5) {
188                                 pr_err("JOB_DESC: Fake trusted descriptor not supported by SEC Era %d\n",
189                                        USER_SEC_ERA(rta_sec_era));
190                                 goto err;
191                         }
192
193                         hdr_ext |= HDR_EXT_FTD;
194                 }
195         }
196         if (flags & RSMS)
197                 opcode |= HDR_RSLS;
198         if (flags & DNR)
199                 opcode |= HDR_DNR;
200         if (flags & TD)
201                 opcode |= HDR_TRUSTED;
202         if (flags & MTD)
203                 opcode |= HDR_MAKE_TRUSTED;
204         if (flags & REO)
205                 opcode |= HDR_REVERSE;
206         if (flags & SHR)
207                 opcode |= HDR_SHARED;
208
209         __rta_out32(program, opcode);
210         program->current_instruction++;
211
212         if (program->current_instruction == 1) {
213                 program->jobhdr = program->buffer;
214
215                 if (opcode & HDR_SHARED)
216                         __rta_out64(program, program->ps, shr_desc);
217         }
218
219         if (flags & EXT)
220                 __rta_out32(program, hdr_ext);
221
222         /* Note: descriptor length is set in program_finalize routine */
223         return (int)start_pc;
224
225  err:
226         program->first_error_pc = start_pc;
227         program->current_instruction++;
228         return -EINVAL;
229 }
230
231 #endif /* __RTA_HEADER_CMD_H__ */