1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright 2013-2015 Freescale Semiconductor Inc.
3 * Copyright 2016-2017 NXP
11 /* Data Path Key Generator API
12 * Contains initialization APIs and runtime APIs for the Key Generator
15 /** Key Generator properties */
18 * Number of masks per key extraction
20 #define DPKG_NUM_OF_MASKS 4
22 * Number of extractions per key profile
24 #define DPKG_MAX_NUM_OF_EXTRACTS 10
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
32 enum dpkg_extract_from_hdr_type {
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
46 enum dpkg_extract_type {
47 DPKG_EXTRACT_FROM_HDR = 0,
48 DPKG_EXTRACT_FROM_DATA = 1,
49 DPKG_EXTRACT_FROM_PARSE = 3
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
62 /* Macros for accessing command fields smaller than 1byte */
63 #define DPKG_MASK(field) \
64 GENMASK(DPKG_##field##_SHIFT + DPKG_##field##_SIZE - 1, \
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)
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 * @extract.from_hdr: Used when 'type = DPKG_EXTRACT_FROM_HDR'
79 * @extract.from_data: Used when 'type = DPKG_EXTRACT_FROM_DATA'
80 * @extract.from_parse: Used when 'type = DPKG_EXTRACT_FROM_PARSE'
81 * @extract.from_hdr.prot: Any of the supported headers
82 * @extract.from_hdr.type: Defines the type of header extraction:
83 * DPKG_FROM_HDR: use size & offset below;
84 * DPKG_FROM_FIELD: use field, size and offset below;
85 * DPKG_FULL_FIELD: use field below
86 * @extract.from_hdr.field: One of the supported fields (NH_FLD_)
87 * @extract.from_hdr.size: Size in bytes
88 * @extract.from_hdr.offset: Byte offset
89 * @extract.from_hdr.hdr_index: Clear for cases not listed below;
90 * Used for protocols that may have more than a single
91 * header, 0 indicates an outer header;
92 * Supported protocols (possible values):
93 * NET_PROT_VLAN (0, HDR_INDEX_LAST);
94 * NET_PROT_MPLS (0, 1, HDR_INDEX_LAST);
95 * NET_PROT_IP(0, HDR_INDEX_LAST);
96 * NET_PROT_IPv4(0, HDR_INDEX_LAST);
97 * NET_PROT_IPv6(0, HDR_INDEX_LAST);
98 * @extract.from_data.size: Size in bytes
99 * @extract.from_data.offset: Byte offset
100 * @extract.from_parse.size: Size in bytes
101 * @extract.from_parse.offset: Byte offset
102 * @num_of_byte_masks: Defines the number of valid entries in the array below;
103 * This is also the number of bytes to be used as masks
104 * @masks: Masks parameters
106 struct dpkg_extract {
107 enum dpkg_extract_type type;
111 enum dpkg_extract_from_hdr_type type;
127 uint8_t num_of_byte_masks;
128 struct dpkg_mask masks[DPKG_NUM_OF_MASKS];
132 * struct dpkg_profile_cfg - A structure for defining a full Key Generation
134 * @num_extracts: Defines the number of valid entries in the array below
135 * @extracts: Array of required extractions
137 struct dpkg_profile_cfg {
138 uint8_t num_extracts;
139 struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
142 /* dpni_set_rx_tc_dist extension (structure of the DMA-able memory at
145 struct dpni_mask_cfg {
150 #define DPKG_EFH_TYPE_SHIFT 0
151 #define DPKG_EFH_TYPE_SIZE 4
152 #define DPKG_EXTRACT_TYPE_SHIFT 0
153 #define DPKG_EXTRACT_TYPE_SIZE 4
155 struct dpni_dist_extract {
158 /* EFH type stored in the 4 least significant bits */
166 uint8_t num_of_repeats;
167 uint8_t num_of_byte_masks;
168 /* Extraction type is stored in the 4 LSBs */
169 uint8_t extract_type;
172 struct dpni_mask_cfg masks[4];
175 struct dpni_ext_set_rx_tc_dist {
176 /* extension word 0 */
177 uint8_t num_extracts;
180 struct dpni_dist_extract extracts[10];
183 int dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
184 uint8_t *key_cfg_buf);
186 #endif /* __FSL_DPKG_H_ */