8fd01801d49da6e4f6de5fc9359ac4e9b9e56838
[deb_dpdk.git] / drivers / crypto / dpaa2_sec / hw / rta / store_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_STORE_CMD_H__
42 #define __RTA_STORE_CMD_H__
43
44 extern enum rta_sec_era rta_sec_era;
45
46 static const uint32_t store_src_table[][2] = {
47 /*1*/   { KEY1SZ,       LDST_CLASS_1_CCB | LDST_SRCDST_WORD_KEYSZ_REG },
48         { KEY2SZ,       LDST_CLASS_2_CCB | LDST_SRCDST_WORD_KEYSZ_REG },
49         { DJQDA,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_JQDAR },
50         { MODE1,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_MODE_REG },
51         { MODE2,        LDST_CLASS_2_CCB | LDST_SRCDST_WORD_MODE_REG },
52         { DJQCTRL,      LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_JQCTRL },
53         { DATA1SZ,      LDST_CLASS_1_CCB | LDST_SRCDST_WORD_DATASZ_REG },
54         { DATA2SZ,      LDST_CLASS_2_CCB | LDST_SRCDST_WORD_DATASZ_REG },
55         { DSTAT,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_STAT },
56         { ICV1SZ,       LDST_CLASS_1_CCB | LDST_SRCDST_WORD_ICVSZ_REG },
57         { ICV2SZ,       LDST_CLASS_2_CCB | LDST_SRCDST_WORD_ICVSZ_REG },
58         { DPID,         LDST_CLASS_DECO | LDST_SRCDST_WORD_PID },
59         { CCTRL,        LDST_SRCDST_WORD_CHACTRL },
60         { ICTRL,        LDST_SRCDST_WORD_IRQCTRL },
61         { CLRW,         LDST_SRCDST_WORD_CLRW },
62         { MATH0,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH0 },
63         { CSTAT,        LDST_SRCDST_WORD_STAT },
64         { MATH1,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH1 },
65         { MATH2,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH2 },
66         { AAD1SZ,       LDST_CLASS_1_CCB | LDST_SRCDST_WORD_DECO_AAD_SZ },
67         { MATH3,        LDST_CLASS_DECO | LDST_SRCDST_WORD_DECO_MATH3 },
68         { IV1SZ,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_CLASS1_IV_SZ },
69         { PKASZ,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_A_SZ },
70         { PKBSZ,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_B_SZ },
71         { PKESZ,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_E_SZ },
72         { PKNSZ,        LDST_CLASS_1_CCB | LDST_SRCDST_WORD_PKHA_N_SZ },
73         { CONTEXT1,     LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_CONTEXT },
74         { CONTEXT2,     LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_CONTEXT },
75         { DESCBUF,      LDST_CLASS_DECO | LDST_SRCDST_WORD_DESCBUF },
76 /*30*/  { JOBDESCBUF,   LDST_CLASS_DECO | LDST_SRCDST_WORD_DESCBUF_JOB },
77         { SHAREDESCBUF, LDST_CLASS_DECO | LDST_SRCDST_WORD_DESCBUF_SHARED },
78 /*32*/  { JOBDESCBUF_EFF,   LDST_CLASS_DECO |
79                 LDST_SRCDST_WORD_DESCBUF_JOB_WE },
80         { SHAREDESCBUF_EFF, LDST_CLASS_DECO |
81                 LDST_SRCDST_WORD_DESCBUF_SHARED_WE },
82 /*34*/  { GTR,          LDST_CLASS_DECO | LDST_SRCDST_WORD_GTR },
83         { STR,          LDST_CLASS_DECO | LDST_SRCDST_WORD_STR }
84 };
85
86 /*
87  * Allowed STORE sources for each SEC ERA.
88  * Values represent the number of entries from source_src_table[] that are
89  * supported.
90  */
91 static const unsigned int store_src_table_sz[] = {29, 31, 33, 33,
92                                                   33, 33, 35, 35};
93
94 static inline int
95 rta_store(struct program *program, uint64_t src,
96           uint16_t offset, uint64_t dst, uint32_t length,
97           uint32_t flags)
98 {
99         uint32_t opcode = 0, val;
100         int ret = -EINVAL;
101         unsigned int start_pc = program->current_pc;
102
103         if (flags & SEQ)
104                 opcode = CMD_SEQ_STORE;
105         else
106                 opcode = CMD_STORE;
107
108         /* parameters check */
109         if ((flags & IMMED) && (flags & SGF)) {
110                 pr_err("STORE: Invalid flag. SEC PC: %d; Instr: %d\n",
111                        program->current_pc, program->current_instruction);
112                 goto err;
113         }
114         if ((flags & IMMED) && (offset != 0)) {
115                 pr_err("STORE: Invalid flag. SEC PC: %d; Instr: %d\n",
116                        program->current_pc, program->current_instruction);
117                 goto err;
118         }
119
120         if ((flags & SEQ) && ((src == JOBDESCBUF) || (src == SHAREDESCBUF) ||
121                               (src == JOBDESCBUF_EFF) ||
122                               (src == SHAREDESCBUF_EFF))) {
123                 pr_err("STORE: Invalid SRC type. SEC PC: %d; Instr: %d\n",
124                        program->current_pc, program->current_instruction);
125                 goto err;
126         }
127
128         if (flags & IMMED)
129                 opcode |= LDST_IMM;
130
131         if ((flags & SGF) || (flags & VLF))
132                 opcode |= LDST_VLF;
133
134         /*
135          * source for data to be stored can be specified as:
136          *    - register location; set in src field[9-15];
137          *    - if IMMED flag is set, data is set in value field [0-31];
138          *      user can give this value as actual value or pointer to data
139          */
140         if (!(flags & IMMED)) {
141                 ret = __rta_map_opcode((uint32_t)src, store_src_table,
142                                        store_src_table_sz[rta_sec_era], &val);
143                 if (ret < 0) {
144                         pr_err("STORE: Invalid source. SEC PC: %d; Instr: %d\n",
145                                program->current_pc,
146                                program->current_instruction);
147                         goto err;
148                 }
149                 opcode |= val;
150         }
151
152         /* DESC BUFFER: length / offset values are specified in 4-byte words */
153         if ((src == DESCBUF) || (src == JOBDESCBUF) || (src == SHAREDESCBUF) ||
154             (src == JOBDESCBUF_EFF) || (src == SHAREDESCBUF_EFF)) {
155                 opcode |= (length >> 2);
156                 opcode |= (uint32_t)((offset >> 2) << LDST_OFFSET_SHIFT);
157         } else {
158                 opcode |= length;
159                 opcode |= (uint32_t)(offset << LDST_OFFSET_SHIFT);
160         }
161
162         __rta_out32(program, opcode);
163         program->current_instruction++;
164
165         if ((src == JOBDESCBUF) || (src == SHAREDESCBUF) ||
166             (src == JOBDESCBUF_EFF) || (src == SHAREDESCBUF_EFF))
167                 return (int)start_pc;
168
169         /* for STORE, a pointer to where the data will be stored if needed */
170         if (!(flags & SEQ))
171                 __rta_out64(program, program->ps, dst);
172
173         /* for IMMED data, place the data here */
174         if (flags & IMMED)
175                 __rta_inline_data(program, src, flags & __COPY_MASK, length);
176
177         return (int)start_pc;
178
179  err:
180         program->first_error_pc = start_pc;
181         program->current_instruction++;
182         return ret;
183 }
184
185 #endif /* __RTA_STORE_CMD_H__ */