8d421a5dbee7f8f0cb33d75dd7b2452c402f3b34
[deb_dpdk.git] / drivers / crypto / dpaa2_sec / hw / rta / seq_in_out_ptr_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_SEQ_IN_OUT_PTR_CMD_H__
42 #define __RTA_SEQ_IN_OUT_PTR_CMD_H__
43
44 extern enum rta_sec_era rta_sec_era;
45
46 /* Allowed SEQ IN PTR flags for each SEC Era. */
47 static const uint32_t seq_in_ptr_flags[] = {
48         RBS | INL | SGF | PRE | EXT | RTO,
49         RBS | INL | SGF | PRE | EXT | RTO | RJD,
50         RBS | INL | SGF | PRE | EXT | RTO | RJD,
51         RBS | INL | SGF | PRE | EXT | RTO | RJD,
52         RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
53         RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
54         RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
55         RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP
56 };
57
58 /* Allowed SEQ OUT PTR flags for each SEC Era. */
59 static const uint32_t seq_out_ptr_flags[] = {
60         SGF | PRE | EXT,
61         SGF | PRE | EXT | RTO,
62         SGF | PRE | EXT | RTO,
63         SGF | PRE | EXT | RTO,
64         SGF | PRE | EXT | RTO | RST | EWS,
65         SGF | PRE | EXT | RTO | RST | EWS,
66         SGF | PRE | EXT | RTO | RST | EWS,
67         SGF | PRE | EXT | RTO | RST | EWS
68 };
69
70 static inline int
71 rta_seq_in_ptr(struct program *program, uint64_t src,
72                uint32_t length, uint32_t flags)
73 {
74         uint32_t opcode = CMD_SEQ_IN_PTR;
75         unsigned int start_pc = program->current_pc;
76         int ret = -EINVAL;
77
78         /* Parameters checking */
79         if ((flags & RTO) && (flags & PRE)) {
80                 pr_err("SEQ IN PTR: Invalid usage of RTO and PRE flags\n");
81                 goto err;
82         }
83         if (flags & ~seq_in_ptr_flags[rta_sec_era]) {
84                 pr_err("SEQ IN PTR: Flag(s) not supported by SEC Era %d\n",
85                        USER_SEC_ERA(rta_sec_era));
86                 goto err;
87         }
88         if ((flags & INL) && (flags & RJD)) {
89                 pr_err("SEQ IN PTR: Invalid usage of INL and RJD flags\n");
90                 goto err;
91         }
92         if ((src) && (flags & (SOP | RTO | PRE))) {
93                 pr_err("SEQ IN PTR: Invalid usage of RTO or PRE flag\n");
94                 goto err;
95         }
96         if ((flags & SOP) && (flags & (RBS | PRE | RTO | EXT))) {
97                 pr_err("SEQ IN PTR: Invalid usage of SOP and (RBS or PRE or RTO or EXT) flags\n");
98                 goto err;
99         }
100
101         /* write flag fields */
102         if (flags & RBS)
103                 opcode |= SQIN_RBS;
104         if (flags & INL)
105                 opcode |= SQIN_INL;
106         if (flags & SGF)
107                 opcode |= SQIN_SGF;
108         if (flags & PRE)
109                 opcode |= SQIN_PRE;
110         if (flags & RTO)
111                 opcode |= SQIN_RTO;
112         if (flags & RJD)
113                 opcode |= SQIN_RJD;
114         if (flags & SOP)
115                 opcode |= SQIN_SOP;
116         if ((length >> 16) || (flags & EXT)) {
117                 if (flags & SOP) {
118                         pr_err("SEQ IN PTR: Invalid usage of SOP and EXT flags\n");
119                         goto err;
120                 }
121
122                 opcode |= SQIN_EXT;
123         } else {
124                 opcode |= length & SQIN_LEN_MASK;
125         }
126
127         __rta_out32(program, opcode);
128         program->current_instruction++;
129
130         /* write pointer or immediate data field */
131         if (!(opcode & (SQIN_PRE | SQIN_RTO | SQIN_SOP)))
132                 __rta_out64(program, program->ps, src);
133
134         /* write extended length field */
135         if (opcode & SQIN_EXT)
136                 __rta_out32(program, length);
137
138         return (int)start_pc;
139
140  err:
141         program->first_error_pc = start_pc;
142         program->current_instruction++;
143         return ret;
144 }
145
146 static inline int
147 rta_seq_out_ptr(struct program *program, uint64_t dst,
148                 uint32_t length, uint32_t flags)
149 {
150         uint32_t opcode = CMD_SEQ_OUT_PTR;
151         unsigned int start_pc = program->current_pc;
152         int ret = -EINVAL;
153
154         /* Parameters checking */
155         if (flags & ~seq_out_ptr_flags[rta_sec_era]) {
156                 pr_err("SEQ OUT PTR: Flag(s) not supported by SEC Era %d\n",
157                        USER_SEC_ERA(rta_sec_era));
158                 goto err;
159         }
160         if ((flags & RTO) && (flags & PRE)) {
161                 pr_err("SEQ OUT PTR: Invalid usage of RTO and PRE flags\n");
162                 goto err;
163         }
164         if ((dst) && (flags & (RTO | PRE))) {
165                 pr_err("SEQ OUT PTR: Invalid usage of RTO or PRE flag\n");
166                 goto err;
167         }
168         if ((flags & RST) && !(flags & RTO)) {
169                 pr_err("SEQ OUT PTR: RST flag must be used with RTO flag\n");
170                 goto err;
171         }
172
173         /* write flag fields */
174         if (flags & SGF)
175                 opcode |= SQOUT_SGF;
176         if (flags & PRE)
177                 opcode |= SQOUT_PRE;
178         if (flags & RTO)
179                 opcode |= SQOUT_RTO;
180         if (flags & RST)
181                 opcode |= SQOUT_RST;
182         if (flags & EWS)
183                 opcode |= SQOUT_EWS;
184         if ((length >> 16) || (flags & EXT))
185                 opcode |= SQOUT_EXT;
186         else
187                 opcode |= length & SQOUT_LEN_MASK;
188
189         __rta_out32(program, opcode);
190         program->current_instruction++;
191
192         /* write pointer or immediate data field */
193         if (!(opcode & (SQOUT_PRE | SQOUT_RTO)))
194                 __rta_out64(program, program->ps, dst);
195
196         /* write extended length field */
197         if (opcode & SQOUT_EXT)
198                 __rta_out32(program, length);
199
200         return (int)start_pc;
201
202  err:
203         program->first_error_pc = start_pc;
204         program->current_instruction++;
205         return ret;
206 }
207
208 #endif /* __RTA_SEQ_IN_OUT_PTR_CMD_H__ */