xref: /dpdk/drivers/net/dpaa2/mc/fsl_dpkg.h (revision 591200ef6f32b56adc367ebe3647cc3dbe9362db)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  * Copyright 2013-2015 Freescale Semiconductor Inc.
3  * Copyright 2016-2023 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	20
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  * @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
105  */
106 struct dpkg_extract {
107 	enum dpkg_extract_type type;
108 	union {
109 		struct {
110 			enum net_prot prot;
111 			enum dpkg_extract_from_hdr_type type;
112 			uint32_t field;
113 			uint8_t size;
114 			uint8_t offset;
115 			uint8_t hdr_index;
116 		} from_hdr;
117 		struct {
118 			uint8_t size;
119 			uint8_t offset;
120 		} from_data;
121 		struct {
122 			uint8_t size;
123 			uint8_t offset;
124 		} from_parse;
125 	} extract;
126 
127 	uint8_t num_of_byte_masks;
128 	struct dpkg_mask masks[DPKG_NUM_OF_MASKS];
129 };
130 
131 /**
132  * struct dpkg_profile_cfg - A structure for defining a full Key Generation
133  *				profile (rule)
134  * @num_extracts: Defines the number of valid entries in the array below
135  * @extracts: Array of required extractions
136  */
137 struct dpkg_profile_cfg {
138 	uint8_t num_extracts;
139 	struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
140 };
141 
142 /* dpni_set_rx_tc_dist extension (structure of the DMA-able memory at
143  * key_cfg_iova)
144  */
145 struct dpni_mask_cfg {
146 	uint8_t mask;
147 	uint8_t offset;
148 };
149 
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
154 
155 struct dpni_dist_extract {
156 	/* word 0 */
157 	uint8_t prot;
158 	/* EFH type stored in the 4 least significant bits */
159 	uint8_t efh_type;
160 	uint8_t size;
161 	uint8_t offset;
162 	uint32_t field;
163 	/* word 1 */
164 	uint8_t hdr_index;
165 	uint8_t constant;
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;
170 	uint8_t pad[3];
171 	/* word 2 */
172 	struct dpni_mask_cfg masks[4];
173 };
174 
175 struct dpni_ext_set_rx_tc_dist {
176 	/* extension word 0 */
177 	uint8_t num_extracts;
178 	uint8_t pad[7];
179 	/* words 1..25 */
180 	struct dpni_dist_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
181 };
182 
183 int
184 dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
185 	void *key_cfg_buf);
186 
187 #endif /* __FSL_DPKG_H_ */
188