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