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.
7 * Copyright 2008-2016 Freescale Semiconductor Inc.
8 * Copyright (c) 2016 NXP.
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.
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
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.
41 #ifndef __RTA_NFIFO_CMD_H__
42 #define __RTA_NFIFO_CMD_H__
44 extern enum rta_sec_era rta_sec_era;
46 static const uint32_t nfifo_src[][2] = {
47 /*1*/ { IFIFO, NFIFOENTRY_STYPE_DFIFO },
48 { OFIFO, NFIFOENTRY_STYPE_OFIFO },
49 { PAD, NFIFOENTRY_STYPE_PAD },
50 /*4*/ { MSGOUTSNOOP, NFIFOENTRY_STYPE_SNOOP | NFIFOENTRY_DEST_BOTH },
51 /*5*/ { ALTSOURCE, NFIFOENTRY_STYPE_ALTSOURCE },
52 { OFIFO_SYNC, NFIFOENTRY_STYPE_OFIFO_SYNC },
53 /*7*/ { MSGOUTSNOOP_ALT, NFIFOENTRY_STYPE_SNOOP_ALT | NFIFOENTRY_DEST_BOTH }
57 * Allowed NFIFO LOAD sources for each SEC Era.
58 * Values represent the number of entries from nfifo_src[] that are supported.
60 static const unsigned int nfifo_src_sz[] = {4, 5, 5, 5, 5, 5, 5, 7};
62 static const uint32_t nfifo_data[][2] = {
63 { MSG, NFIFOENTRY_DTYPE_MSG },
64 { MSG1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_MSG },
65 { MSG2, NFIFOENTRY_DEST_CLASS2 | NFIFOENTRY_DTYPE_MSG },
66 { IV1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_IV },
67 { IV2, NFIFOENTRY_DEST_CLASS2 | NFIFOENTRY_DTYPE_IV },
68 { ICV1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_ICV },
69 { ICV2, NFIFOENTRY_DEST_CLASS2 | NFIFOENTRY_DTYPE_ICV },
70 { SAD1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_SAD },
71 { AAD1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_AAD },
72 { AAD2, NFIFOENTRY_DEST_CLASS2 | NFIFOENTRY_DTYPE_AAD },
73 { AFHA_SBOX, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_SBOX },
74 { SKIP, NFIFOENTRY_DTYPE_SKIP },
75 { PKE, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_E },
76 { PKN, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_N },
77 { PKA, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_A },
78 { PKA0, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_A0 },
79 { PKA1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_A1 },
80 { PKA2, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_A2 },
81 { PKA3, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_A3 },
82 { PKB, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_B },
83 { PKB0, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_B0 },
84 { PKB1, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_B1 },
85 { PKB2, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_B2 },
86 { PKB3, NFIFOENTRY_DEST_CLASS1 | NFIFOENTRY_DTYPE_PK_B3 },
87 { AB1, NFIFOENTRY_DEST_CLASS1 },
88 { AB2, NFIFOENTRY_DEST_CLASS2 },
89 { ABD, NFIFOENTRY_DEST_DECO }
92 static const uint32_t nfifo_flags[][2] = {
93 /*1*/ { LAST1, NFIFOENTRY_LC1 },
94 { LAST2, NFIFOENTRY_LC2 },
95 { FLUSH1, NFIFOENTRY_FC1 },
96 { BP, NFIFOENTRY_BND },
97 { PAD_ZERO, NFIFOENTRY_PTYPE_ZEROS },
98 { PAD_NONZERO, NFIFOENTRY_PTYPE_RND_NOZEROS },
99 { PAD_INCREMENT, NFIFOENTRY_PTYPE_INCREMENT },
100 { PAD_RANDOM, NFIFOENTRY_PTYPE_RND },
101 { PAD_ZERO_N1, NFIFOENTRY_PTYPE_ZEROS_NZ },
102 { PAD_NONZERO_0, NFIFOENTRY_PTYPE_RND_NZ_LZ },
103 { PAD_N1, NFIFOENTRY_PTYPE_N },
104 /*12*/ { PAD_NONZERO_N, NFIFOENTRY_PTYPE_RND_NZ_N },
105 { FLUSH2, NFIFOENTRY_FC2 },
106 { OC, NFIFOENTRY_OC }
110 * Allowed NFIFO LOAD flags for each SEC Era.
111 * Values represent the number of entries from nfifo_flags[] that are supported.
113 static const unsigned int nfifo_flags_sz[] = {12, 14, 14, 14, 14, 14, 14, 14};
115 static const uint32_t nfifo_pad_flags[][2] = {
116 { BM, NFIFOENTRY_BM },
117 { PS, NFIFOENTRY_PS },
118 { PR, NFIFOENTRY_PR }
122 * Allowed NFIFO LOAD pad flags for each SEC Era.
123 * Values represent the number of entries from nfifo_pad_flags[] that are
126 static const unsigned int nfifo_pad_flags_sz[] = {2, 2, 2, 2, 3, 3, 3, 3};
129 rta_nfifo_load(struct program *program, uint32_t src,
130 uint32_t data, uint32_t length, uint32_t flags)
132 uint32_t opcode = 0, val;
134 uint32_t load_cmd = CMD_LOAD | LDST_IMM | LDST_CLASS_IND_CCB |
135 LDST_SRCDST_WORD_INFO_FIFO;
136 unsigned int start_pc = program->current_pc;
138 if ((data == AFHA_SBOX) && (rta_sec_era == RTA_SEC_ERA_7)) {
139 pr_err("NFIFO: AFHA S-box not supported by SEC Era %d\n",
140 USER_SEC_ERA(rta_sec_era));
144 /* write source field */
145 ret = __rta_map_opcode(src, nfifo_src, nfifo_src_sz[rta_sec_era], &val);
147 pr_err("NFIFO: Invalid SRC. SEC PC: %d; Instr: %d\n",
148 program->current_pc, program->current_instruction);
153 /* write type field */
154 ret = __rta_map_opcode(data, nfifo_data, ARRAY_SIZE(nfifo_data), &val);
156 pr_err("NFIFO: Invalid data. SEC PC: %d; Instr: %d\n",
157 program->current_pc, program->current_instruction);
163 if (!(flags & EXT)) {
164 opcode |= length & NFIFOENTRY_DLEN_MASK;
171 __rta_map_flags(flags, nfifo_flags, nfifo_flags_sz[rta_sec_era],
174 /* in case of padding, check the destination */
176 __rta_map_flags(flags, nfifo_pad_flags,
177 nfifo_pad_flags_sz[rta_sec_era], &opcode);
179 /* write LOAD command first */
180 __rta_out32(program, load_cmd);
181 __rta_out32(program, opcode);
184 __rta_out32(program, length & NFIFOENTRY_DLEN_MASK);
186 program->current_instruction++;
188 return (int)start_pc;
191 program->first_error_pc = start_pc;
192 program->current_instruction++;
196 #endif /* __RTA_NFIFO_CMD_H__ */