New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / dpaa2 / mc / fsl_dpkg.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 2013-2015 Freescale Semiconductor Inc.
8  * Copyright 2016-2017 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 #ifndef __FSL_DPKG_H_
41 #define __FSL_DPKG_H_
42
43 #include <fsl_net.h>
44
45 /* Data Path Key Generator API
46  * Contains initialization APIs and runtime APIs for the Key Generator
47  */
48
49 /** Key Generator properties */
50
51 /**
52  * Number of masks per key extraction
53  */
54 #define DPKG_NUM_OF_MASKS               4
55 /**
56  * Number of extractions per key profile
57  */
58 #define DPKG_MAX_NUM_OF_EXTRACTS        10
59
60 /**
61  * enum dpkg_extract_from_hdr_type - Selecting extraction by header types
62  * @DPKG_FROM_HDR: Extract selected bytes from header, by offset
63  * @DPKG_FROM_FIELD: Extract selected bytes from header, by offset from field
64  * @DPKG_FULL_FIELD: Extract a full field
65  */
66 enum dpkg_extract_from_hdr_type {
67         DPKG_FROM_HDR = 0,
68         DPKG_FROM_FIELD = 1,
69         DPKG_FULL_FIELD = 2
70 };
71
72 /**
73  * enum dpkg_extract_type - Enumeration for selecting extraction type
74  * @DPKG_EXTRACT_FROM_HDR: Extract from the header
75  * @DPKG_EXTRACT_FROM_DATA: Extract from data not in specific header
76  * @DPKG_EXTRACT_FROM_PARSE: Extract from parser-result;
77  *      e.g. can be used to extract header existence;
78  *      please refer to 'Parse Result definition' section in the parser BG
79  */
80 enum dpkg_extract_type {
81         DPKG_EXTRACT_FROM_HDR = 0,
82         DPKG_EXTRACT_FROM_DATA = 1,
83         DPKG_EXTRACT_FROM_PARSE = 3
84 };
85
86 /**
87  * struct dpkg_mask - A structure for defining a single extraction mask
88  * @mask: Byte mask for the extracted content
89  * @offset: Offset within the extracted content
90  */
91 struct dpkg_mask {
92         uint8_t mask;
93         uint8_t offset;
94 };
95
96 /* Macros for accessing command fields smaller than 1byte */
97 #define DPKG_MASK(field)        \
98         GENMASK(DPKG_##field##_SHIFT + DPKG_##field##_SIZE - 1, \
99                 DPKG_##field##_SHIFT)
100 #define dpkg_set_field(var, field, val) \
101         ((var) |= (((val) << DPKG_##field##_SHIFT) & DPKG_MASK(field)))
102 #define dpkg_get_field(var, field)      \
103         (((var) & DPKG_MASK(field)) >> DPKG_##field##_SHIFT)
104
105 /**
106  * struct dpkg_extract - A structure for defining a single extraction
107  * @type: Determines how the union below is interpreted:
108  *              DPKG_EXTRACT_FROM_HDR: selects 'from_hdr';
109  *              DPKG_EXTRACT_FROM_DATA: selects 'from_data';
110  *              DPKG_EXTRACT_FROM_PARSE: selects 'from_parse'
111  * @extract: Selects extraction method
112  * @num_of_byte_masks: Defines the number of valid entries in the array below;
113  *              This is also the number of bytes to be used as masks
114  * @masks: Masks parameters
115  */
116 struct dpkg_extract {
117         enum dpkg_extract_type type;
118         /**
119          * union extract - Selects extraction method
120          * @from_hdr - Used when 'type = DPKG_EXTRACT_FROM_HDR'
121          * @from_data - Used when 'type = DPKG_EXTRACT_FROM_DATA'
122          * @from_parse - Used when 'type = DPKG_EXTRACT_FROM_PARSE'
123          */
124         union {
125                 /**
126                  * struct from_hdr - Used when 'type = DPKG_EXTRACT_FROM_HDR'
127                  * @prot: Any of the supported headers
128                  * @type: Defines the type of header extraction:
129                  *      DPKG_FROM_HDR: use size & offset below;
130                  *      DPKG_FROM_FIELD: use field, size and offset below;
131                  *      DPKG_FULL_FIELD: use field below
132                  * @field: One of the supported fields (NH_FLD_)
133                  *
134                  * @size: Size in bytes
135                  * @offset: Byte offset
136                  * @hdr_index: Clear for cases not listed below;
137                  *      Used for protocols that may have more than a single
138                  *      header, 0 indicates an outer header;
139                  *      Supported protocols (possible values):
140                  *      NET_PROT_VLAN (0, HDR_INDEX_LAST);
141                  *      NET_PROT_MPLS (0, 1, HDR_INDEX_LAST);
142                  *      NET_PROT_IP(0, HDR_INDEX_LAST);
143                  *      NET_PROT_IPv4(0, HDR_INDEX_LAST);
144                  *      NET_PROT_IPv6(0, HDR_INDEX_LAST);
145                  */
146
147                 struct {
148                         enum net_prot prot;
149                         enum dpkg_extract_from_hdr_type type;
150                         uint32_t field;
151                         uint8_t size;
152                         uint8_t offset;
153                         uint8_t hdr_index;
154                 } from_hdr;
155                 /**
156                  * struct from_data
157                  *      Used when 'type = DPKG_EXTRACT_FROM_DATA'
158                  * @size: Size in bytes
159                  * @offset: Byte offset
160                  */
161                 struct {
162                         uint8_t size;
163                         uint8_t offset;
164                 } from_data;
165
166                 /**
167                  * struct from_parse
168                  *      Used when 'type = DPKG_EXTRACT_FROM_PARSE'
169                  * @size: Size in bytes
170                  * @offset: Byte offset
171                  */
172                 struct {
173                         uint8_t size;
174                         uint8_t offset;
175                 } from_parse;
176         } extract;
177
178         uint8_t num_of_byte_masks;
179         struct dpkg_mask masks[DPKG_NUM_OF_MASKS];
180 };
181
182 /**
183  * struct dpkg_profile_cfg - A structure for defining a full Key Generation
184  *                              profile (rule)
185  * @num_extracts: Defines the number of valid entries in the array below
186  * @extracts: Array of required extractions
187  */
188 struct dpkg_profile_cfg {
189         uint8_t num_extracts;
190         struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
191 };
192
193 /* dpni_set_rx_tc_dist extension (structure of the DMA-able memory at
194  * key_cfg_iova)
195  */
196 struct dpni_mask_cfg {
197         uint8_t mask;
198         uint8_t offset;
199 };
200
201 #define DPKG_EFH_TYPE_SHIFT             0
202 #define DPKG_EFH_TYPE_SIZE              4
203 #define DPKG_EXTRACT_TYPE_SHIFT         0
204 #define DPKG_EXTRACT_TYPE_SIZE          4
205
206 struct dpni_dist_extract {
207         /* word 0 */
208         uint8_t prot;
209         /* EFH type stored in the 4 least significant bits */
210         uint8_t efh_type;
211         uint8_t size;
212         uint8_t offset;
213         uint32_t field;
214         /* word 1 */
215         uint8_t hdr_index;
216         uint8_t constant;
217         uint8_t num_of_repeats;
218         uint8_t num_of_byte_masks;
219         /* Extraction type is stored in the 4 LSBs */
220         uint8_t extract_type;
221         uint8_t pad[3];
222         /* word 2 */
223         struct dpni_mask_cfg masks[4];
224 };
225
226 struct dpni_ext_set_rx_tc_dist {
227         /* extension word 0 */
228         uint8_t num_extracts;
229         uint8_t pad[7];
230         /* words 1..25 */
231         struct dpni_dist_extract extracts[10];
232 };
233
234 int dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
235                          uint8_t *key_cfg_buf);
236
237 #endif /* __FSL_DPKG_H_ */