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