c2a27a2d9e2a0a3f2948c110f2b083db65080f8e
[deb_dpdk.git] / drivers / crypto / dpaa2_sec / hw / rta / header_cmd.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2008-2016 Freescale Semiconductor Inc.
8  * Copyright (c) 2016 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 #ifndef __RTA_HEADER_CMD_H__
42 #define __RTA_HEADER_CMD_H__
43
44 extern enum rta_sec_era rta_sec_era;
45
46 /* Allowed job header flags for each SEC Era. */
47 static const uint32_t job_header_flags[] = {
48         DNR | TD | MTD | SHR | REO,
49         DNR | TD | MTD | SHR | REO | RSMS,
50         DNR | TD | MTD | SHR | REO | RSMS,
51         DNR | TD | MTD | SHR | REO | RSMS,
52         DNR | TD | MTD | SHR | REO | RSMS | EXT,
53         DNR | TD | MTD | SHR | REO | RSMS | EXT,
54         DNR | TD | MTD | SHR | REO | RSMS | EXT,
55         DNR | TD | MTD | SHR | REO | EXT
56 };
57
58 /* Allowed shared header flags for each SEC Era. */
59 static const uint32_t shr_header_flags[] = {
60         DNR | SC | PD,
61         DNR | SC | PD | CIF,
62         DNR | SC | PD | CIF,
63         DNR | SC | PD | CIF | RIF,
64         DNR | SC | PD | CIF | RIF,
65         DNR | SC | PD | CIF | RIF,
66         DNR | SC | PD | CIF | RIF,
67         DNR | SC | PD | CIF | RIF
68 };
69
70 static inline int
71 rta_shr_header(struct program *program,
72                enum rta_share_type share,
73                unsigned int start_idx,
74                uint32_t flags)
75 {
76         uint32_t opcode = CMD_SHARED_DESC_HDR;
77         unsigned int start_pc = program->current_pc;
78
79         if (flags & ~shr_header_flags[rta_sec_era]) {
80                 pr_err("SHR_DESC: Flag(s) not supported by SEC Era %d\n",
81                        USER_SEC_ERA(rta_sec_era));
82                 goto err;
83         }
84
85         switch (share) {
86         case SHR_ALWAYS:
87                 opcode |= HDR_SHARE_ALWAYS;
88                 break;
89         case SHR_SERIAL:
90                 opcode |= HDR_SHARE_SERIAL;
91                 break;
92         case SHR_NEVER:
93                 /*
94                  * opcode |= HDR_SHARE_NEVER;
95                  * HDR_SHARE_NEVER is 0
96                  */
97                 break;
98         case SHR_WAIT:
99                 opcode |= HDR_SHARE_WAIT;
100                 break;
101         default:
102                 pr_err("SHR_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
103                        program->current_pc);
104                 goto err;
105         }
106
107         opcode |= HDR_ONE;
108         opcode |= (start_idx << HDR_START_IDX_SHIFT) & HDR_START_IDX_MASK;
109
110         if (flags & DNR)
111                 opcode |= HDR_DNR;
112         if (flags & CIF)
113                 opcode |= HDR_CLEAR_IFIFO;
114         if (flags & SC)
115                 opcode |= HDR_SAVECTX;
116         if (flags & PD)
117                 opcode |= HDR_PROP_DNR;
118         if (flags & RIF)
119                 opcode |= HDR_RIF;
120
121         __rta_out32(program, opcode);
122         program->current_instruction++;
123
124         if (program->current_instruction == 1)
125                 program->shrhdr = program->buffer;
126
127         return (int)start_pc;
128
129  err:
130         program->first_error_pc = start_pc;
131         program->current_instruction++;
132         return -EINVAL;
133 }
134
135 static inline int
136 rta_job_header(struct program *program,
137                enum rta_share_type share,
138                unsigned int start_idx,
139                uint64_t shr_desc, uint32_t flags,
140                uint32_t ext_flags)
141 {
142         uint32_t opcode = CMD_DESC_HDR;
143         uint32_t hdr_ext = 0;
144         unsigned int start_pc = program->current_pc;
145
146         if (flags & ~job_header_flags[rta_sec_era]) {
147                 pr_err("JOB_DESC: Flag(s) not supported by SEC Era %d\n",
148                        USER_SEC_ERA(rta_sec_era));
149                 goto err;
150         }
151
152         switch (share) {
153         case SHR_ALWAYS:
154                 opcode |= HDR_SHARE_ALWAYS;
155                 break;
156         case SHR_SERIAL:
157                 opcode |= HDR_SHARE_SERIAL;
158                 break;
159         case SHR_NEVER:
160                 /*
161                  * opcode |= HDR_SHARE_NEVER;
162                  * HDR_SHARE_NEVER is 0
163                  */
164                 break;
165         case SHR_WAIT:
166                 opcode |= HDR_SHARE_WAIT;
167                 break;
168         case SHR_DEFER:
169                 opcode |= HDR_SHARE_DEFER;
170                 break;
171         default:
172                 pr_err("JOB_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
173                        program->current_pc);
174                 goto err;
175         }
176
177         if ((flags & TD) && (flags & REO)) {
178                 pr_err("JOB_DESC: REO flag not supported for trusted descriptors. SEC Program Line: %d\n",
179                        program->current_pc);
180                 goto err;
181         }
182
183         if ((rta_sec_era < RTA_SEC_ERA_7) && (flags & MTD) && !(flags & TD)) {
184                 pr_err("JOB_DESC: Trying to MTD a descriptor that is not a TD. SEC Program Line: %d\n",
185                        program->current_pc);
186                 goto err;
187         }
188
189         if ((flags & EXT) && !(flags & SHR) && (start_idx < 2)) {
190                 pr_err("JOB_DESC: Start index must be >= 2 in case of no SHR and EXT. SEC Program Line: %d\n",
191                        program->current_pc);
192                 goto err;
193         }
194
195         opcode |= HDR_ONE;
196         opcode |= ((start_idx << HDR_START_IDX_SHIFT) & HDR_START_IDX_MASK);
197
198         if (flags & EXT) {
199                 opcode |= HDR_EXT;
200
201                 if (ext_flags & DSV) {
202                         hdr_ext |= HDR_EXT_DSEL_VALID;
203                         hdr_ext |= ext_flags & DSEL_MASK;
204                 }
205
206                 if (ext_flags & FTD) {
207                         if (rta_sec_era <= RTA_SEC_ERA_5) {
208                                 pr_err("JOB_DESC: Fake trusted descriptor not supported by SEC Era %d\n",
209                                        USER_SEC_ERA(rta_sec_era));
210                                 goto err;
211                         }
212
213                         hdr_ext |= HDR_EXT_FTD;
214                 }
215         }
216         if (flags & RSMS)
217                 opcode |= HDR_RSLS;
218         if (flags & DNR)
219                 opcode |= HDR_DNR;
220         if (flags & TD)
221                 opcode |= HDR_TRUSTED;
222         if (flags & MTD)
223                 opcode |= HDR_MAKE_TRUSTED;
224         if (flags & REO)
225                 opcode |= HDR_REVERSE;
226         if (flags & SHR)
227                 opcode |= HDR_SHARED;
228
229         __rta_out32(program, opcode);
230         program->current_instruction++;
231
232         if (program->current_instruction == 1) {
233                 program->jobhdr = program->buffer;
234
235                 if (opcode & HDR_SHARED)
236                         __rta_out64(program, program->ps, shr_desc);
237         }
238
239         if (flags & EXT)
240                 __rta_out32(program, hdr_ext);
241
242         /* Note: descriptor length is set in program_finalize routine */
243         return (int)start_pc;
244
245  err:
246         program->first_error_pc = start_pc;
247         program->current_instruction++;
248         return -EINVAL;
249 }
250
251 #endif /* __RTA_HEADER_CMD_H__ */