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 2013-2015 Freescale Semiconductor Inc.
8 * Copyright 2016-2017 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.
45 /* Data Path Key Generator API
46 * Contains initialization APIs and runtime APIs for the Key Generator
49 /** Key Generator properties */
52 * Number of masks per key extraction
54 #define DPKG_NUM_OF_MASKS 4
56 * Number of extractions per key profile
58 #define DPKG_MAX_NUM_OF_EXTRACTS 10
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
66 enum dpkg_extract_from_hdr_type {
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
80 enum dpkg_extract_type {
81 DPKG_EXTRACT_FROM_HDR = 0,
82 DPKG_EXTRACT_FROM_DATA = 1,
83 DPKG_EXTRACT_FROM_PARSE = 3
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
96 /* Macros for accessing command fields smaller than 1byte */
97 #define DPKG_MASK(field) \
98 GENMASK(DPKG_##field##_SHIFT + DPKG_##field##_SIZE - 1, \
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)
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
116 struct dpkg_extract {
117 enum dpkg_extract_type type;
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'
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_)
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);
149 enum dpkg_extract_from_hdr_type type;
157 * Used when 'type = DPKG_EXTRACT_FROM_DATA'
158 * @size: Size in bytes
159 * @offset: Byte offset
168 * Used when 'type = DPKG_EXTRACT_FROM_PARSE'
169 * @size: Size in bytes
170 * @offset: Byte offset
178 uint8_t num_of_byte_masks;
179 struct dpkg_mask masks[DPKG_NUM_OF_MASKS];
183 * struct dpkg_profile_cfg - A structure for defining a full Key Generation
185 * @num_extracts: Defines the number of valid entries in the array below
186 * @extracts: Array of required extractions
188 struct dpkg_profile_cfg {
189 uint8_t num_extracts;
190 struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
193 /* dpni_set_rx_tc_dist extension (structure of the DMA-able memory at
196 struct dpni_mask_cfg {
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
206 struct dpni_dist_extract {
209 /* EFH type stored in the 4 least significant bits */
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;
223 struct dpni_mask_cfg masks[4];
226 struct dpni_ext_set_rx_tc_dist {
227 /* extension word 0 */
228 uint8_t num_extracts;
231 struct dpni_dist_extract extracts[10];
234 int dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
235 uint8_t *key_cfg_buf);
237 #endif /* __FSL_DPKG_H_ */