Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2023 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _CPFL_RULES_API_H_
6 : : #define _CPFL_RULES_API_H_
7 : :
8 : : #include <base/idpf_controlq_api.h>
9 : : #include "cpfl_actions.h"
10 : : #include "cpfl_controlq.h"
11 : :
12 : : /* Common Bit Mask Macros */
13 : : #define CPFL_BIT(b) (1 << (b))
14 : :
15 : : #define MAKE_MASK(type, mask, shift) ((u##type) (mask) << (shift))
16 : : #define SHIFT_VAL_LT(type, val, field) \
17 : : (((u##type)(val) << field##_S) & field##_M)
18 : : #define SHIFT_VAL_RT(type, val, field) \
19 : : (((u##type)(val) & field##_M) >> field##_S)
20 : :
21 : : #define MAKE_MASK_VAL(type, bit_len) (((u##type)0x01 << (bit_len)) - 1)
22 : : #define MAKE_MASK_VAL16(bit_len) MAKE_MASK_VAL(16, bit_len)
23 : : #define MAKE_MASK_VAL64(bit_len) MAKE_MASK_VAL(64, bit_len)
24 : :
25 : : #define MAKE_MASK64(mask, shift) MAKE_MASK(64, mask, shift)
26 : : #define MAKE_MASK16(mask, shift) MAKE_MASK(16, mask, shift)
27 : : #define MAKE_MASK32(mask, shift) MAKE_MASK(32, mask, shift)
28 : :
29 : : /* Make masks with bit length and left-shifting count */
30 : : #define MAKE_SMASK(type, bits, shift) \
31 : : ((((u##type)1 << (bits)) - 1) << (shift))
32 : : #define MAKE_SMASK64(bits, shift) MAKE_SMASK(64, bits, shift)
33 : : #define MAKE_SMASK32(bits, shift) MAKE_SMASK(32, bits, shift)
34 : : #define MAKE_SMASK16(bits, shift) MAKE_SMASK(16, bits, shift)
35 : :
36 : : #define SHIFT_VAL64(val, field) SHIFT_VAL_LT(64, val, field)
37 : : #define SHIFT_VAL32(val, field) SHIFT_VAL_LT(32, val, field)
38 : : #define SHIFT_VAL16(val, field) SHIFT_VAL_LT(16, val, field)
39 : :
40 : : /* Rule Config queue opcodes */
41 : : enum cpfl_ctlq_rule_cfg_opc {
42 : : cpfl_ctlq_sem_add_rule = 0x1303,
43 : : cpfl_ctlq_sem_update_rule = 0x1304,
44 : : cpfl_ctlq_sem_del_rule = 0x1305,
45 : : cpfl_ctlq_sem_query_rule = 0x1306,
46 : : cpfl_ctlq_sem_query_rule_hash_addr = 0x1307,
47 : : cpfl_ctlq_sem_query_del_rule_hash_addr = 0x1308,
48 : :
49 : : cpfl_ctlq_lem_add_update_rule = 0x1343,
50 : : cpfl_ctlq_lem_del_rule = 0x1345,
51 : : cpfl_ctlq_lem_query_rule = 0x1346,
52 : : cpfl_ctlq_lem_query_rule_hash_addr = 0x1347,
53 : : cpfl_ctlq_lem_query_del_rule_hash_addr = 0x1348,
54 : :
55 : : cpfl_ctlq_mod_add_update_rule = 0x1360,
56 : : cpfl_ctlq_mod_query_rule = 0x1361,
57 : : };
58 : :
59 : : enum cpfl_cfg_pkt_error_code {
60 : : CPFL_CFG_PKT_ERR_OK = 0,
61 : : CPFL_CFG_PKT_ERR_ESRCH = 1, /* Bad opcode */
62 : : CPFL_CFG_PKT_ERR_EEXIST = 2, /* Entry Already exists */
63 : : CPFL_CFG_PKT_ERR_ENOSPC = 4, /* No space left in the table*/
64 : : CPFL_CFG_PKT_ERR_ERANGE = 5, /* Parameter out of range */
65 : : CPFL_CFG_PKT_ERR_ESBCOMP = 6, /* Completion Error */
66 : : CPFL_CFG_PKT_ERR_ENOPIN = 7, /* Entry cannot be pinned in cache */
67 : : CPFL_CFG_PKT_ERR_ENOTFND = 8, /* Entry Not exists */
68 : : CPFL_CFG_PKT_ERR_EMAXCOL = 9 /* Max Hash Collision */
69 : : };
70 : :
71 : : static const char * const cpfl_cfg_pkt_errormsg[] = {
72 : : [CPFL_CFG_PKT_ERR_ESRCH] = "Bad opcode",
73 : : [CPFL_CFG_PKT_ERR_EEXIST] = "The rule conflicts with already existed one",
74 : : [CPFL_CFG_PKT_ERR_ENOSPC] = "No space left in the table",
75 : : [CPFL_CFG_PKT_ERR_ERANGE] = "Parameter out of range",
76 : : [CPFL_CFG_PKT_ERR_ESBCOMP] = "Completion error",
77 : : [CPFL_CFG_PKT_ERR_ENOPIN] = "Entry cannot be pinned in cache",
78 : : [CPFL_CFG_PKT_ERR_ENOTFND] = "Entry does not exist",
79 : : [CPFL_CFG_PKT_ERR_EMAXCOL] = "Maximum Hash Collisions reached",
80 : : };
81 : :
82 : : /* macros for creating context for rule descriptor */
83 : : #define MEV_RULE_VSI_ID_S 0
84 : : #define MEV_RULE_VSI_ID_M \
85 : : MAKE_MASK64(0x7FF, MEV_RULE_VSI_ID_S)
86 : :
87 : : #define MEV_RULE_TIME_SEL_S 13
88 : : #define MEV_RULE_TIME_SEL_M \
89 : : MAKE_MASK64(0x3, MEV_RULE_TIME_SEL_S)
90 : :
91 : : #define MEV_RULE_TIME_SEL_VAL_S 15
92 : : #define MEV_RULE_TIME_SEL_VAL_M \
93 : : MAKE_MASK64(0x1, MEV_RULE_TIME_SEL_VAL_S)
94 : :
95 : : #define MEV_RULE_PORT_NUM_S 16
96 : : #define MEV_RULE_HOST_ID_S 18
97 : : #define MEV_RULE_PORT_NUM_M \
98 : : MAKE_MASK64(0x3, MEV_RULE_PORT_NUM_S)
99 : : #define MEV_RULE_HOST_ID_M \
100 : : MAKE_MASK64(0x7, MEV_RULE_HOST_ID_S)
101 : :
102 : : #define MEV_RULE_CACHE_WR_THRU_S 21
103 : : #define MEV_RULE_CACHE_WR_THRU_M \
104 : : MAKE_MASK64(0x1, MEV_RULE_CACHE_WR_THRU_S)
105 : :
106 : : #define MEV_RULE_RESP_REQ_S 22
107 : : #define MEV_RULE_RESP_REQ_M \
108 : : MAKE_MASK64(0x3, MEV_RULE_RESP_REQ_S)
109 : : #define MEV_RULE_OBJ_ADDR_S 24
110 : : #define MEV_RULE_OBJ_ADDR_M \
111 : : MAKE_MASK64(0x7FFFFFF, MEV_RULE_OBJ_ADDR_S)
112 : : #define MEV_RULE_OBJ_ID_S 59
113 : : #define MEV_RULE_OBJ_ID_M \
114 : : MAKE_MASK64((uint64_t)0x3, MEV_RULE_OBJ_ID_S)
115 : :
116 : : /* macros for creating CFG_CTRL for sem/lem rule blob */
117 : : #define MEV_RULE_CFG_CTRL_PROF_ID_S 0
118 : : #define MEV_RULE_CFG_CTRL_PROF_ID_M \
119 : : MAKE_MASK16(0x7FF, MEV_RULE_CFG_CTRL_PROF_ID_S)
120 : :
121 : : #define MEV_RULE_CFG_CTRL_SUB_PROF_ID_S 11
122 : : #define MEV_RULE_CFG_CTRL_SUB_PROF_ID_M \
123 : : MAKE_MASK16(0x3, MEV_RULE_CFG_CTRL_SUB_PROF_ID_S)
124 : : #define MEV_RULE_CFG_CTRL_PIN_CACHE_S 13
125 : : #define MEV_RULE_CFG_CTRL_PIN_CACHE_M \
126 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_PIN_CACHE_S)
127 : : #define MEV_RULE_CFG_CTRL_CLEAR_MIRROR_S 14
128 : : #define MEV_RULE_CFG_CTRL_CLEAR_MIRROR_M \
129 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_CLEAR_MIRROR_S)
130 : : #define MEV_RULE_CFG_CTRL_FIXED_FETCH_S 15
131 : : #define MEV_RULE_CFG_CTRL_FIXED_FETCH_M \
132 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_FIXED_FETCH_S)
133 : :
134 : : /**
135 : : * macro to build the CFG_CTRL for rule packet data, which is one of
136 : : * cpfl_prep_sem_rule_blob()'s input parameter.
137 : : */
138 : : /* build SEM CFG_CTRL*/
139 : : #define CPFL_GET_MEV_SEM_RULE_CFG_CTRL(prof_id, sub_prof_id, \
140 : : pin_to_cache, fixed_fetch) \
141 : : (SHIFT_VAL16((prof_id), MEV_RULE_CFG_CTRL_PROF_ID) | \
142 : : SHIFT_VAL16((sub_prof_id), MEV_RULE_CFG_CTRL_SUB_PROF_ID) | \
143 : : SHIFT_VAL16((pin_to_cache), MEV_RULE_CFG_CTRL_PIN_CACHE) | \
144 : : SHIFT_VAL16((fixed_fetch), MEV_RULE_CFG_CTRL_FIXED_FETCH))
145 : :
146 : : /* build LEM CFG_CTRL*/
147 : : #define CPFL_GET_MEV_LEM_RULE_CFG_CTRL(prof_id, pin_to_cache, clear_mirror) \
148 : : (SHIFT_VAL16(prof_id, MEV_RULE_CFG_CTRL_PROF_ID) | \
149 : : SHIFT_VAL16(pin_to_cache, MEV_RULE_CFG_CTRL_PIN_CACHE) | \
150 : : SHIFT_VAL16(clear_mirror, MEV_RULE_CFG_CTRL_CLEAR_MIRROR))
151 : :
152 : : /* macros for creating mod content config packets */
153 : : #define MEV_RULE_MOD_INDEX_S 24
154 : : #define MEV_RULE_MOD_INDEX_M \
155 : : MAKE_MASK64(0xFFFFFFFF, MEV_RULE_MOD_INDEX_S)
156 : :
157 : : #define MEV_RULE_PIN_MOD_CONTENT_S 62
158 : : #define MEV_RULE_PIN_MOD_CONTENT_M \
159 : : MAKE_MASK64((uint64_t)0x1, MEV_RULE_PIN_MOD_CONTENT_S)
160 : : #define MEV_RULE_MOD_OBJ_SIZE_S 63
161 : : #define MEV_RULE_MOD_OBJ_SIZE_M \
162 : : MAKE_MASK64((uint64_t)0x1, MEV_RULE_MOD_OBJ_SIZE_S)
163 : :
164 : : /**
165 : : * struct cpfl_sem_rule_cfg_pkt - Describes rule information for SEM
166 : : * note: The key may be in mixed big/little endian format, the rest of members
167 : : * are in little endian
168 : : */
169 : : struct cpfl_sem_rule_cfg_pkt {
170 : : #define MEV_SEM_RULE_KEY_SIZE 128
171 : : uint8_t key[MEV_SEM_RULE_KEY_SIZE];
172 : :
173 : : #define MEV_SEM_RULE_ACT_SIZE 72
174 : : uint8_t actions[MEV_SEM_RULE_ACT_SIZE];
175 : :
176 : : /* Bit(s):
177 : : * 10:0 : PROFILE_ID
178 : : * 12:11: SUB_PROF_ID (used for SEM only)
179 : : * 13 : pin the SEM key content into the cache
180 : : * 14 : Reserved
181 : : * 15 : Fixed_fetch
182 : : */
183 : : uint8_t cfg_ctrl[2];
184 : :
185 : : /* Bit(s):
186 : : * 0: valid
187 : : * 15:1: Hints
188 : : * 26:16: PROFILE_ID, the profile associated with the entry
189 : : * 31:27: PF
190 : : * 55:32: FLOW ID (assigned by HW)
191 : : * 63:56: EPOCH
192 : : */
193 : : uint8_t ctrl_word[8];
194 : : uint8_t padding[46];
195 : : };
196 : :
197 : : /**
198 : : * struct cpfl_lem_rule_cfg_pkt - Describes rule information for LEM
199 : : * note: The key may be in mixed big/little endian format, the rest of members
200 : : * are in little endian
201 : : */
202 : : struct cpfl_lem_rule_cfg_pkt {
203 : : #define MEV_LEM_RULE_KEY_SIZE 128
204 : : uint8_t key[MEV_LEM_RULE_KEY_SIZE];
205 : :
206 : : #define MEV_LEM_RULE_ACT_SIZE 48
207 : : uint8_t actions[MEV_LEM_RULE_ACT_SIZE];
208 : : /* Bit(s):
209 : : * 10:0 : PROFILE_ID
210 : : * 12:11: Reserved
211 : : * 13 : pin the LEM key content into the cache
212 : : * 14 : if set, clear mirror first state for first index in actions
213 : : * 15 : Reserved.
214 : : */
215 : : uint8_t cfg_ctrl[2];
216 : : /* Bit(s):
217 : : * 0: valid
218 : : * 15:1: Hints
219 : : * 26:16: PROFILE_ID, the profile associated with the entry
220 : : * 31:27: PF
221 : : * 55:32: FLOW ID (assigned by HW)
222 : : * 63:56: EPOCH
223 : : */
224 : : uint8_t ctrl_word[8];
225 : : uint8_t padding[70];
226 : : };
227 : :
228 : : /**
229 : : * union cpfl_rule_cfg_pkt_record - Describes rule data blob
230 : : */
231 : : union cpfl_rule_cfg_pkt_record {
232 : : struct cpfl_sem_rule_cfg_pkt sem_rule;
233 : : struct cpfl_lem_rule_cfg_pkt lem_rule;
234 : : uint8_t pkt_data[256];
235 : : uint8_t mod_blob[256];
236 : : };
237 : :
238 : : /**
239 : : * cpfl_rule_query_addr - LEM/SEM Rule Query Address structure
240 : : */
241 : : struct cpfl_rule_query_addr {
242 : : uint8_t obj_id;
243 : : uint32_t obj_addr;
244 : : };
245 : :
246 : : /**
247 : : * cpfl_rule_query_del_addr - Rule Query and Delete Address
248 : : */
249 : : struct cpfl_rule_query_del_addr {
250 : : uint8_t obj_id;
251 : : uint32_t obj_addr;
252 : : };
253 : :
254 : : /**
255 : : * cpfl_rule_mod_content - MOD Rule Content
256 : : */
257 : : struct cpfl_rule_mod_content {
258 : : uint8_t obj_size;
259 : : uint8_t pin_content;
260 : : uint32_t index;
261 : : };
262 : :
263 : : /**
264 : : * cpfl_rule_cfg_data_common - data struct for all rule opcodes
265 : : *note: some rules may only require part of structure
266 : : */
267 : : struct cpfl_rule_cfg_data_common {
268 : : enum cpfl_ctlq_rule_cfg_opc opc;
269 : : uint64_t cookie;
270 : : uint16_t vsi_id;
271 : : uint8_t port_num;
272 : : uint8_t host_id;
273 : : uint8_t time_sel;
274 : : uint8_t time_sel_val;
275 : : uint8_t cache_wr_thru;
276 : : uint8_t resp_req;
277 : : uint32_t ret_val;
278 : : uint16_t buf_len;
279 : : struct idpf_dma_mem *payload;
280 : : };
281 : :
282 : : /**
283 : : * cpfl_rule_cfg_data - rule config data
284 : : * note: Before sending rule to HW, caller needs to fill
285 : : * in this struct then call cpfl_prep_rule_desc().
286 : : */
287 : : struct cpfl_rule_cfg_data {
288 : : struct cpfl_rule_cfg_data_common common;
289 : : union {
290 : : struct cpfl_rule_query_addr query_addr;
291 : : struct cpfl_rule_query_del_addr query_del_addr;
292 : : struct cpfl_rule_mod_content mod_content;
293 : : } ext;
294 : : };
295 : :
296 : : /**
297 : : * cpfl_fill_rule_mod_content - fill info for mod content
298 : : */
299 : : static inline void
300 : : cpfl_fill_rule_mod_content(uint8_t mod_obj_size,
301 : : uint8_t pin_mod_content,
302 : : uint32_t mod_index,
303 : : struct cpfl_rule_mod_content *mod_content)
304 : : {
305 : 0 : mod_content->obj_size = mod_obj_size;
306 : 0 : mod_content->pin_content = pin_mod_content;
307 : 0 : mod_content->index = mod_index;
308 : : }
309 : :
310 : : /**
311 : : * cpfl_fill_rule_cfg_data_common - fill in rule config data for all opcodes
312 : : * note: call this function before calls cpfl_prep_rule_desc()
313 : : */
314 : : static inline void
315 : : cpfl_fill_rule_cfg_data_common(enum cpfl_ctlq_rule_cfg_opc opc,
316 : : uint64_t cookie,
317 : : uint16_t vsi_id,
318 : : uint8_t port_num,
319 : : uint8_t host_id,
320 : : uint8_t time_sel,
321 : : uint8_t time_sel_val,
322 : : uint8_t cache_wr_thru,
323 : : uint8_t resp_req,
324 : : uint16_t payload_len,
325 : : struct idpf_dma_mem *payload,
326 : : struct cpfl_rule_cfg_data_common *cfg_cmn)
327 : : {
328 : 0 : cfg_cmn->opc = opc;
329 : 0 : cfg_cmn->cookie = cookie;
330 : 0 : cfg_cmn->vsi_id = vsi_id;
331 : 0 : cfg_cmn->port_num = port_num;
332 : 0 : cfg_cmn->resp_req = resp_req;
333 : 0 : cfg_cmn->ret_val = 0;
334 : 0 : cfg_cmn->host_id = host_id;
335 : 0 : cfg_cmn->time_sel = time_sel;
336 : 0 : cfg_cmn->time_sel_val = time_sel_val;
337 : 0 : cfg_cmn->cache_wr_thru = cache_wr_thru;
338 : :
339 : 0 : cfg_cmn->buf_len = payload_len;
340 : 0 : cfg_cmn->payload = payload;
341 : : }
342 : :
343 : : void
344 : : cpfl_prep_rule_desc(struct cpfl_rule_cfg_data *cfg_data,
345 : : struct idpf_ctlq_msg *ctlq_msg);
346 : :
347 : : void
348 : : cpfl_prep_sem_rule_blob(const uint8_t *key,
349 : : uint8_t key_byte_len,
350 : : const uint8_t *act_bytes,
351 : : uint8_t act_byte_len,
352 : : uint16_t cfg_ctrl,
353 : : union cpfl_rule_cfg_pkt_record *rule_blob);
354 : : void
355 : : cpfl_prep_lem_rule_blob(uint8_t *key,
356 : : uint8_t key_byte_len,
357 : : uint8_t *act_bytes,
358 : : uint8_t act_byte_len,
359 : : uint16_t cfg_ctrl,
360 : : union cpfl_rule_cfg_pkt_record *rule_blob);
361 : : #endif /* _CPFL_RULES_API_H_ */
|