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_mod_add_update_rule = 0x1360,
50 : : cpfl_ctlq_mod_query_rule = 0x1361,
51 : : };
52 : :
53 : : enum cpfl_cfg_pkt_error_code {
54 : : CPFL_CFG_PKT_ERR_OK = 0,
55 : : CPFL_CFG_PKT_ERR_ESRCH = 1, /* Bad opcode */
56 : : CPFL_CFG_PKT_ERR_EEXIST = 2, /* Entry Already exists */
57 : : CPFL_CFG_PKT_ERR_ENOSPC = 4, /* No space left in the table*/
58 : : CPFL_CFG_PKT_ERR_ERANGE = 5, /* Parameter out of range */
59 : : CPFL_CFG_PKT_ERR_ESBCOMP = 6, /* Completion Error */
60 : : CPFL_CFG_PKT_ERR_ENOPIN = 7, /* Entry cannot be pinned in cache */
61 : : CPFL_CFG_PKT_ERR_ENOTFND = 8, /* Entry Not exists */
62 : : CPFL_CFG_PKT_ERR_EMAXCOL = 9 /* Max Hash Collision */
63 : : };
64 : :
65 : : static const char * const cpfl_cfg_pkt_errormsg[] = {
66 : : [CPFL_CFG_PKT_ERR_ESRCH] = "Bad opcode",
67 : : [CPFL_CFG_PKT_ERR_EEXIST] = "The rule conflicts with already existed one",
68 : : [CPFL_CFG_PKT_ERR_ENOSPC] = "No space left in the table",
69 : : [CPFL_CFG_PKT_ERR_ERANGE] = "Parameter out of range",
70 : : [CPFL_CFG_PKT_ERR_ESBCOMP] = "Completion error",
71 : : [CPFL_CFG_PKT_ERR_ENOPIN] = "Entry cannot be pinned in cache",
72 : : [CPFL_CFG_PKT_ERR_ENOTFND] = "Entry does not exist",
73 : : [CPFL_CFG_PKT_ERR_EMAXCOL] = "Maximum Hash Collisions reached",
74 : : };
75 : :
76 : : /* macros for creating context for rule descriptor */
77 : : #define MEV_RULE_VSI_ID_S 0
78 : : #define MEV_RULE_VSI_ID_M \
79 : : MAKE_MASK64(0x7FF, MEV_RULE_VSI_ID_S)
80 : :
81 : : #define MEV_RULE_TIME_SEL_S 13
82 : : #define MEV_RULE_TIME_SEL_M \
83 : : MAKE_MASK64(0x3, MEV_RULE_TIME_SEL_S)
84 : :
85 : : #define MEV_RULE_TIME_SEL_VAL_S 15
86 : : #define MEV_RULE_TIME_SEL_VAL_M \
87 : : MAKE_MASK64(0x1, MEV_RULE_TIME_SEL_VAL_S)
88 : :
89 : : #define MEV_RULE_PORT_NUM_S 16
90 : : #define MEV_RULE_HOST_ID_S 18
91 : : #define MEV_RULE_PORT_NUM_M \
92 : : MAKE_MASK64(0x3, MEV_RULE_PORT_NUM_S)
93 : : #define MEV_RULE_HOST_ID_M \
94 : : MAKE_MASK64(0x7, MEV_RULE_HOST_ID_S)
95 : :
96 : : #define MEV_RULE_CACHE_WR_THRU_S 21
97 : : #define MEV_RULE_CACHE_WR_THRU_M \
98 : : MAKE_MASK64(0x1, MEV_RULE_CACHE_WR_THRU_S)
99 : :
100 : : #define MEV_RULE_RESP_REQ_S 22
101 : : #define MEV_RULE_RESP_REQ_M \
102 : : MAKE_MASK64(0x3, MEV_RULE_RESP_REQ_S)
103 : : #define MEV_RULE_OBJ_ADDR_S 24
104 : : #define MEV_RULE_OBJ_ADDR_M \
105 : : MAKE_MASK64(0x7FFFFFF, MEV_RULE_OBJ_ADDR_S)
106 : : #define MEV_RULE_OBJ_ID_S 59
107 : : #define MEV_RULE_OBJ_ID_M \
108 : : MAKE_MASK64((uint64_t)0x3, MEV_RULE_OBJ_ID_S)
109 : :
110 : : /* macros for creating CFG_CTRL for sem/lem rule blob */
111 : : #define MEV_RULE_CFG_CTRL_PROF_ID_S 0
112 : : #define MEV_RULE_CFG_CTRL_PROF_ID_M \
113 : : MAKE_MASK16(0x7FF, MEV_RULE_CFG_CTRL_PROF_ID_S)
114 : :
115 : : #define MEV_RULE_CFG_CTRL_SUB_PROF_ID_S 11
116 : : #define MEV_RULE_CFG_CTRL_SUB_PROF_ID_M \
117 : : MAKE_MASK16(0x3, MEV_RULE_CFG_CTRL_SUB_PROF_ID_S)
118 : : #define MEV_RULE_CFG_CTRL_PIN_CACHE_S 13
119 : : #define MEV_RULE_CFG_CTRL_PIN_CACHE_M \
120 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_PIN_CACHE_S)
121 : : #define MEV_RULE_CFG_CTRL_CLEAR_MIRROR_S 14
122 : : #define MEV_RULE_CFG_CTRL_CLEAR_MIRROR_M \
123 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_CLEAR_MIRROR_S)
124 : : #define MEV_RULE_CFG_CTRL_FIXED_FETCH_S 15
125 : : #define MEV_RULE_CFG_CTRL_FIXED_FETCH_M \
126 : : MAKE_MASK16(0x1, MEV_RULE_CFG_CTRL_FIXED_FETCH_S)
127 : :
128 : : /**
129 : : * macro to build the CFG_CTRL for rule packet data, which is one of
130 : : * cpfl_prep_sem_rule_blob()'s input parameter.
131 : : */
132 : : /* build SEM CFG_CTRL*/
133 : : #define CPFL_GET_MEV_SEM_RULE_CFG_CTRL(prof_id, sub_prof_id, \
134 : : pin_to_cache, fixed_fetch) \
135 : : (SHIFT_VAL16((prof_id), MEV_RULE_CFG_CTRL_PROF_ID) | \
136 : : SHIFT_VAL16((sub_prof_id), MEV_RULE_CFG_CTRL_SUB_PROF_ID) | \
137 : : SHIFT_VAL16((pin_to_cache), MEV_RULE_CFG_CTRL_PIN_CACHE) | \
138 : : SHIFT_VAL16((fixed_fetch), MEV_RULE_CFG_CTRL_FIXED_FETCH))
139 : :
140 : : /* build LEM CFG_CTRL*/
141 : : #define CPFL_GET_MEV_LEM_RULE_CFG_CTRL(prof_id, pin_to_cache, clear_mirror) \
142 : : (SHIFT_VAL16(prof_id, MEV_RULE_CFG_CTRL_PROF_ID) | \
143 : : SHIFT_VAL16(pin_to_cache, MEV_RULE_CFG_CTRL_PIN_CACHE) | \
144 : : SHIFT_VAL16(clear_mirror, MEV_RULE_CFG_CTRL_CLEAR_MIRROR))
145 : :
146 : : /* macros for creating mod content config packets */
147 : : #define MEV_RULE_MOD_INDEX_S 24
148 : : #define MEV_RULE_MOD_INDEX_M \
149 : : MAKE_MASK64(0xFFFFFFFF, MEV_RULE_MOD_INDEX_S)
150 : :
151 : : #define MEV_RULE_PIN_MOD_CONTENT_S 62
152 : : #define MEV_RULE_PIN_MOD_CONTENT_M \
153 : : MAKE_MASK64((uint64_t)0x1, MEV_RULE_PIN_MOD_CONTENT_S)
154 : : #define MEV_RULE_MOD_OBJ_SIZE_S 63
155 : : #define MEV_RULE_MOD_OBJ_SIZE_M \
156 : : MAKE_MASK64((uint64_t)0x1, MEV_RULE_MOD_OBJ_SIZE_S)
157 : :
158 : : /**
159 : : * struct cpfl_sem_rule_cfg_pkt - Describes rule information for SEM
160 : : * note: The key may be in mixed big/little endian format, the rest of members
161 : : * are in little endian
162 : : */
163 : : struct cpfl_sem_rule_cfg_pkt {
164 : : #define MEV_SEM_RULE_KEY_SIZE 128
165 : : uint8_t key[MEV_SEM_RULE_KEY_SIZE];
166 : :
167 : : #define MEV_SEM_RULE_ACT_SIZE 72
168 : : uint8_t actions[MEV_SEM_RULE_ACT_SIZE];
169 : :
170 : : /* Bit(s):
171 : : * 10:0 : PROFILE_ID
172 : : * 12:11: SUB_PROF_ID (used for SEM only)
173 : : * 13 : pin the SEM key content into the cache
174 : : * 14 : Reserved
175 : : * 15 : Fixed_fetch
176 : : */
177 : : uint8_t cfg_ctrl[2];
178 : :
179 : : /* Bit(s):
180 : : * 0: valid
181 : : * 15:1: Hints
182 : : * 26:16: PROFILE_ID, the profile associated with the entry
183 : : * 31:27: PF
184 : : * 55:32: FLOW ID (assigned by HW)
185 : : * 63:56: EPOCH
186 : : */
187 : : uint8_t ctrl_word[8];
188 : : uint8_t padding[46];
189 : : };
190 : :
191 : : /**
192 : : * union cpfl_rule_cfg_pkt_record - Describes rule data blob
193 : : */
194 : : union cpfl_rule_cfg_pkt_record {
195 : : struct cpfl_sem_rule_cfg_pkt sem_rule;
196 : : uint8_t pkt_data[256];
197 : : uint8_t mod_blob[256];
198 : : };
199 : :
200 : : /**
201 : : * cpfl_rule_query_addr - LEM/SEM Rule Query Address structure
202 : : */
203 : : struct cpfl_rule_query_addr {
204 : : uint8_t obj_id;
205 : : uint32_t obj_addr;
206 : : };
207 : :
208 : : /**
209 : : * cpfl_rule_query_del_addr - Rule Query and Delete Address
210 : : */
211 : : struct cpfl_rule_query_del_addr {
212 : : uint8_t obj_id;
213 : : uint32_t obj_addr;
214 : : };
215 : :
216 : : /**
217 : : * cpfl_rule_mod_content - MOD Rule Content
218 : : */
219 : : struct cpfl_rule_mod_content {
220 : : uint8_t obj_size;
221 : : uint8_t pin_content;
222 : : uint32_t index;
223 : : };
224 : :
225 : : /**
226 : : * cpfl_rule_cfg_data_common - data struct for all rule opcodes
227 : : *note: some rules may only require part of structure
228 : : */
229 : : struct cpfl_rule_cfg_data_common {
230 : : enum cpfl_ctlq_rule_cfg_opc opc;
231 : : uint64_t cookie;
232 : : uint16_t vsi_id;
233 : : uint8_t port_num;
234 : : uint8_t host_id;
235 : : uint8_t time_sel;
236 : : uint8_t time_sel_val;
237 : : uint8_t cache_wr_thru;
238 : : uint8_t resp_req;
239 : : uint32_t ret_val;
240 : : uint16_t buf_len;
241 : : struct idpf_dma_mem *payload;
242 : : };
243 : :
244 : : /**
245 : : * cpfl_rule_cfg_data - rule config data
246 : : * note: Before sending rule to HW, caller needs to fill
247 : : * in this struct then call cpfl_prep_rule_desc().
248 : : */
249 : : struct cpfl_rule_cfg_data {
250 : : struct cpfl_rule_cfg_data_common common;
251 : : union {
252 : : struct cpfl_rule_query_addr query_addr;
253 : : struct cpfl_rule_query_del_addr query_del_addr;
254 : : struct cpfl_rule_mod_content mod_content;
255 : : } ext;
256 : : };
257 : :
258 : : /**
259 : : * cpfl_fill_rule_mod_content - fill info for mod content
260 : : */
261 : : static inline void
262 : : cpfl_fill_rule_mod_content(uint8_t mod_obj_size,
263 : : uint8_t pin_mod_content,
264 : : uint32_t mod_index,
265 : : struct cpfl_rule_mod_content *mod_content)
266 : : {
267 : 0 : mod_content->obj_size = mod_obj_size;
268 : 0 : mod_content->pin_content = pin_mod_content;
269 : 0 : mod_content->index = mod_index;
270 : : }
271 : :
272 : : /**
273 : : * cpfl_fill_rule_cfg_data_common - fill in rule config data for all opcodes
274 : : * note: call this function before calls cpfl_prep_rule_desc()
275 : : */
276 : : static inline void
277 : : cpfl_fill_rule_cfg_data_common(enum cpfl_ctlq_rule_cfg_opc opc,
278 : : uint64_t cookie,
279 : : uint16_t vsi_id,
280 : : uint8_t port_num,
281 : : uint8_t host_id,
282 : : uint8_t time_sel,
283 : : uint8_t time_sel_val,
284 : : uint8_t cache_wr_thru,
285 : : uint8_t resp_req,
286 : : uint16_t payload_len,
287 : : struct idpf_dma_mem *payload,
288 : : struct cpfl_rule_cfg_data_common *cfg_cmn)
289 : : {
290 : 0 : cfg_cmn->opc = opc;
291 : 0 : cfg_cmn->cookie = cookie;
292 : 0 : cfg_cmn->vsi_id = vsi_id;
293 : 0 : cfg_cmn->port_num = port_num;
294 : 0 : cfg_cmn->resp_req = resp_req;
295 : 0 : cfg_cmn->ret_val = 0;
296 : 0 : cfg_cmn->host_id = host_id;
297 : 0 : cfg_cmn->time_sel = time_sel;
298 : 0 : cfg_cmn->time_sel_val = time_sel_val;
299 : 0 : cfg_cmn->cache_wr_thru = cache_wr_thru;
300 : :
301 : 0 : cfg_cmn->buf_len = payload_len;
302 : 0 : cfg_cmn->payload = payload;
303 : : }
304 : :
305 : : void
306 : : cpfl_prep_rule_desc(struct cpfl_rule_cfg_data *cfg_data,
307 : : struct idpf_ctlq_msg *ctlq_msg);
308 : :
309 : : void
310 : : cpfl_prep_sem_rule_blob(const uint8_t *key,
311 : : uint8_t key_byte_len,
312 : : const uint8_t *act_bytes,
313 : : uint8_t act_byte_len,
314 : : uint16_t cfg_ctrl,
315 : : union cpfl_rule_cfg_pkt_record *rule_blob);
316 : :
317 : : #endif /* _CPFL_RULES_API_H_ */
|