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