Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2023 Intel Corporation
3 : : */
4 : :
5 : : #include "ice_common.h"
6 : : #include "ice_parser_util.h"
7 : :
8 : 0 : static void _pg_cam_key_dump(struct ice_hw *hw, struct ice_pg_cam_key *key)
9 : : {
10 [ # # ]: 0 : ice_info(hw, "key:\n");
11 [ # # ]: 0 : ice_info(hw, "\tvalid = %d\n", key->valid);
12 [ # # ]: 0 : ice_info(hw, "\tnode_id = %d\n", key->node_id);
13 [ # # ]: 0 : ice_info(hw, "\tflag0 = %d\n", key->flag0);
14 [ # # ]: 0 : ice_info(hw, "\tflag1 = %d\n", key->flag1);
15 [ # # ]: 0 : ice_info(hw, "\tflag2 = %d\n", key->flag2);
16 [ # # ]: 0 : ice_info(hw, "\tflag3 = %d\n", key->flag3);
17 [ # # ]: 0 : ice_info(hw, "\tboost_idx = %d\n", key->boost_idx);
18 [ # # ]: 0 : ice_info(hw, "\talu_reg = 0x%04x\n", key->alu_reg);
19 [ # # ]: 0 : ice_info(hw, "\tnext_proto = 0x%08x\n", key->next_proto);
20 : 0 : }
21 : :
22 : 0 : static void _pg_nm_cam_key_dump(struct ice_hw *hw,
23 : : struct ice_pg_nm_cam_key *key)
24 : : {
25 [ # # ]: 0 : ice_info(hw, "key:\n");
26 [ # # ]: 0 : ice_info(hw, "\tvalid = %d\n", key->valid);
27 [ # # ]: 0 : ice_info(hw, "\tnode_id = %d\n", key->node_id);
28 [ # # ]: 0 : ice_info(hw, "\tflag0 = %d\n", key->flag0);
29 [ # # ]: 0 : ice_info(hw, "\tflag1 = %d\n", key->flag1);
30 [ # # ]: 0 : ice_info(hw, "\tflag2 = %d\n", key->flag2);
31 [ # # ]: 0 : ice_info(hw, "\tflag3 = %d\n", key->flag3);
32 [ # # ]: 0 : ice_info(hw, "\tboost_idx = %d\n", key->boost_idx);
33 [ # # ]: 0 : ice_info(hw, "\talu_reg = 0x%04x\n", key->alu_reg);
34 : 0 : }
35 : :
36 : 0 : static void _pg_cam_action_dump(struct ice_hw *hw,
37 : : struct ice_pg_cam_action *action)
38 : : {
39 [ # # ]: 0 : ice_info(hw, "action:\n");
40 [ # # ]: 0 : ice_info(hw, "\tnext_node = %d\n", action->next_node);
41 [ # # ]: 0 : ice_info(hw, "\tnext_pc = %d\n", action->next_pc);
42 [ # # ]: 0 : ice_info(hw, "\tis_pg = %d\n", action->is_pg);
43 [ # # ]: 0 : ice_info(hw, "\tproto_id = %d\n", action->proto_id);
44 [ # # ]: 0 : ice_info(hw, "\tis_mg = %d\n", action->is_mg);
45 [ # # ]: 0 : ice_info(hw, "\tmarker_id = %d\n", action->marker_id);
46 [ # # ]: 0 : ice_info(hw, "\tis_last_round = %d\n", action->is_last_round);
47 [ # # ]: 0 : ice_info(hw, "\tho_polarity = %d\n", action->ho_polarity);
48 [ # # ]: 0 : ice_info(hw, "\tho_inc = %d\n", action->ho_inc);
49 : 0 : }
50 : :
51 : : /**
52 : : * ice_pg_cam_dump - dump an parse graph cam info
53 : : * @hw: pointer to the hardware structure
54 : : * @item: parse graph cam to dump
55 : : */
56 : 0 : void ice_pg_cam_dump(struct ice_hw *hw, struct ice_pg_cam_item *item)
57 : : {
58 [ # # ]: 0 : ice_info(hw, "index = %d\n", item->idx);
59 : 0 : _pg_cam_key_dump(hw, &item->key);
60 : 0 : _pg_cam_action_dump(hw, &item->action);
61 : 0 : }
62 : :
63 : : /**
64 : : * ice_pg_nm_cam_dump - dump an parse graph no match cam info
65 : : * @hw: pointer to the hardware structure
66 : : * @item: parse graph no match cam to dump
67 : : */
68 : 0 : void ice_pg_nm_cam_dump(struct ice_hw *hw, struct ice_pg_nm_cam_item *item)
69 : : {
70 [ # # ]: 0 : ice_info(hw, "index = %d\n", item->idx);
71 : 0 : _pg_nm_cam_key_dump(hw, &item->key);
72 : 0 : _pg_cam_action_dump(hw, &item->action);
73 : 0 : }
74 : :
75 : : /** The function parses a 55 bits Parse Graph CAM Action with below format:
76 : : * BIT 0-11: Next Node ID (action->next_node)
77 : : * BIT 12-19: Next PC (action->next_pc)
78 : : * BIT 20: Is Protocol Group (action->is_pg)
79 : : * BIT 21-23: reserved
80 : : * BIT 24-31: Protocol ID (action->proto_id)
81 : : * BIT 32: Is Marker Group (action->is_mg)
82 : : * BIT 33-40: Marker ID (action->marker_id)
83 : : * BIT 41: Is Last Round (action->is_last_round)
84 : : * BIT 42: Header Offset Polarity (action->ho_poloarity)
85 : : * BIT 43-51: Header Offset Inc (action->ho_inc)
86 : : * BIT 52-54: reserved
87 : : */
88 : 0 : static void _pg_cam_action_init(struct ice_pg_cam_action *action, u64 data)
89 : : {
90 : 0 : action->next_node = (u16)(data & 0x7ff);
91 : 0 : action->next_pc = (u8)((data >> 11) & 0xff);
92 : 0 : action->is_pg = ((data >> 19) & 0x1) != 0;
93 : 0 : action->proto_id = ((data >> 23) & 0xff);
94 : 0 : action->is_mg = ((data >> 31) & 0x1) != 0;
95 : 0 : action->marker_id = ((data >> 32) & 0xff);
96 : 0 : action->is_last_round = ((data >> 40) & 0x1) != 0;
97 : 0 : action->ho_polarity = ((data >> 41) & 0x1) != 0;
98 : 0 : action->ho_inc = ((data >> 42) & 0x1ff);
99 : 0 : }
100 : :
101 : : /** The function parses a 41 bits Parse Graph NoMatch CAM Key with below format:
102 : : * BIT 0: Valid (key->valid)
103 : : * BIT 1-11: Node ID (key->node_id)
104 : : * BIT 12: Flag 0 (key->flag0)
105 : : * BIT 13: Flag 1 (key->flag1)
106 : : * BIT 14: Flag 2 (key->flag2)
107 : : * BIT 15: Flag 3 (key->flag3)
108 : : * BIT 16: Boost Hit (key->boost_idx to 0 if it is 0)
109 : : * BIT 17-24: Boost Index (key->boost_idx only if Boost Hit is not 0)
110 : : * BIT 25-40: ALU Reg (key->alu_reg)
111 : : */
112 : 0 : static void _pg_nm_cam_key_init(struct ice_pg_nm_cam_key *key, u64 data)
113 : : {
114 : 0 : key->valid = (data & 0x1) != 0;
115 : 0 : key->node_id = (u16)((data >> 1) & 0x7ff);
116 : 0 : key->flag0 = ((data >> 12) & 0x1) != 0;
117 : 0 : key->flag1 = ((data >> 13) & 0x1) != 0;
118 : 0 : key->flag2 = ((data >> 14) & 0x1) != 0;
119 : 0 : key->flag3 = ((data >> 15) & 0x1) != 0;
120 [ # # ]: 0 : if ((data >> 16) & 0x1)
121 : 0 : key->boost_idx = (u8)((data >> 17) & 0xff);
122 : : else
123 : 0 : key->boost_idx = 0;
124 : 0 : key->alu_reg = (u16)((data >> 25) & 0xffff);
125 : 0 : }
126 : :
127 : : /** The function parses a 73 bits Parse Graph CAM Key with below format:
128 : : * BIT 0: Valid (key->valid)
129 : : * BIT 1-11: Node ID (key->node_id)
130 : : * BIT 12: Flag 0 (key->flag0)
131 : : * BIT 13: Flag 1 (key->flag1)
132 : : * BIT 14: Flag 2 (key->flag2)
133 : : * BIT 15: Flag 3 (key->flag3)
134 : : * BIT 16: Boost Hit (key->boost_idx to 0 if it is 0)
135 : : * BIT 17-24: Boost Index (key->boost_idx only if Boost Hit is not 0)
136 : : * BIT 25-40: ALU Reg (key->alu_reg)
137 : : * BIT 41-72: Next Proto Key (key->next_proto)
138 : : */
139 : 0 : static void _pg_cam_key_init(struct ice_pg_cam_key *key, u8 *data)
140 : : {
141 : 0 : u64 d64 = *(u64 *)data;
142 : :
143 : 0 : key->valid = (d64 & 0x1) != 0;
144 : 0 : key->node_id = (u16)((d64 >> 1) & 0x7ff);
145 : 0 : key->flag0 = ((d64 >> 12) & 0x1) != 0;
146 : 0 : key->flag1 = ((d64 >> 13) & 0x1) != 0;
147 : 0 : key->flag2 = ((d64 >> 14) & 0x1) != 0;
148 : 0 : key->flag3 = ((d64 >> 15) & 0x1) != 0;
149 [ # # ]: 0 : if ((d64 >> 16) & 0x1)
150 : 0 : key->boost_idx = (u8)((d64 >> 17) & 0xff);
151 : : else
152 : 0 : key->boost_idx = 0;
153 : 0 : key->alu_reg = (u16)((d64 >> 25) & 0xffff);
154 : :
155 : 0 : key->next_proto = (*(u32 *)&data[5] >> 1);
156 : 0 : key->next_proto |= ((u32)(data[9] & 0x1) << 31);
157 : 0 : }
158 : :
159 : : /** The function parses a 128 bits Parse Graph CAM Entry with below format:
160 : : * BIT 0-72: Key (ci->key)
161 : : * BIT 73-127: Action (ci->action)
162 : : */
163 : 0 : static void _pg_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
164 : : void *data, int size)
165 : : {
166 : : struct ice_pg_cam_item *ci = (struct ice_pg_cam_item *)item;
167 : : u8 *buf = (u8 *)data;
168 : : u64 d64;
169 : :
170 : 0 : ci->idx = idx;
171 : 0 : d64 = (*(u64 *)&buf[9] >> 1);
172 : 0 : _pg_cam_key_init(&ci->key, buf);
173 : 0 : _pg_cam_action_init(&ci->action, d64);
174 : :
175 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
176 : 0 : ice_pg_cam_dump(hw, ci);
177 : 0 : }
178 : :
179 : : /** The function parses a 136 bits Parse Graph Spill CAM Entry with below
180 : : * format:
181 : : * BIT 0-55: Action (ci->key)
182 : : * BIT 56-135: Key (ci->action)
183 : : */
184 : 0 : static void _pg_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
185 : : void *data, int size)
186 : : {
187 : : struct ice_pg_cam_item *ci = (struct ice_pg_cam_item *)item;
188 : : u8 *buf = (u8 *)data;
189 : : u64 d64;
190 : :
191 : 0 : ci->idx = idx;
192 : 0 : d64 = *(u64 *)buf;
193 : 0 : _pg_cam_action_init(&ci->action, d64);
194 : 0 : _pg_cam_key_init(&ci->key, &buf[7]);
195 : :
196 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
197 : 0 : ice_pg_cam_dump(hw, ci);
198 : 0 : }
199 : :
200 : : /** The function parses a 96 bits Parse Graph NoMatch CAM Entry with below
201 : : * format:
202 : : * BIT 0-40: Key (ci->key)
203 : : * BIT 41-95: Action (ci->action)
204 : : */
205 : 0 : static void _pg_nm_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
206 : : void *data, int size)
207 : : {
208 : : struct ice_pg_nm_cam_item *ci = (struct ice_pg_nm_cam_item *)item;
209 : : u8 *buf = (u8 *)data;
210 : : u64 d64;
211 : :
212 : 0 : ci->idx = idx;
213 : 0 : d64 = *(u64 *)buf;
214 : 0 : _pg_nm_cam_key_init(&ci->key, d64);
215 : 0 : d64 = (*(u64 *)&buf[5] >> 1);
216 : 0 : _pg_cam_action_init(&ci->action, d64);
217 : :
218 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
219 : 0 : ice_pg_nm_cam_dump(hw, ci);
220 : 0 : }
221 : :
222 : : /** The function parses a 104 bits Parse Graph NoMatch Spill CAM Entry with
223 : : * below format:
224 : : * BIT 0-55: Key (ci->key)
225 : : * BIT 56-103: Action (ci->action)
226 : : */
227 : 0 : static void _pg_nm_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
228 : : void *data, int size)
229 : : {
230 : : struct ice_pg_nm_cam_item *ci = (struct ice_pg_nm_cam_item *)item;
231 : : u8 *buf = (u8 *)data;
232 : : u64 d64;
233 : :
234 : 0 : ci->idx = idx;
235 : 0 : d64 = *(u64 *)buf;
236 : 0 : _pg_cam_action_init(&ci->action, d64);
237 : 0 : d64 = *(u64 *)&buf[7];
238 : 0 : _pg_nm_cam_key_init(&ci->key, d64);
239 : :
240 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
241 : 0 : ice_pg_nm_cam_dump(hw, ci);
242 : 0 : }
243 : :
244 : : /**
245 : : * ice_pg_cam_table_get - create a parse graph cam table
246 : : * @hw: pointer to the hardware structure
247 : : */
248 : 0 : struct ice_pg_cam_item *ice_pg_cam_table_get(struct ice_hw *hw)
249 : : {
250 : 0 : return (struct ice_pg_cam_item *)
251 : 0 : ice_parser_create_table(hw, ICE_SID_RXPARSER_CAM,
252 : : sizeof(struct ice_pg_cam_item),
253 : : ICE_PG_CAM_TABLE_SIZE,
254 : : ice_parser_sect_item_get,
255 : : _pg_cam_parse_item, false);
256 : : }
257 : :
258 : : /**
259 : : * ice_pg_sp_cam_table_get - create a parse graph spill cam table
260 : : * @hw: pointer to the hardware structure
261 : : */
262 : 0 : struct ice_pg_cam_item *ice_pg_sp_cam_table_get(struct ice_hw *hw)
263 : : {
264 : 0 : return (struct ice_pg_cam_item *)
265 : 0 : ice_parser_create_table(hw, ICE_SID_RXPARSER_PG_SPILL,
266 : : sizeof(struct ice_pg_cam_item),
267 : : ICE_PG_SP_CAM_TABLE_SIZE,
268 : : ice_parser_sect_item_get,
269 : : _pg_sp_cam_parse_item, false);
270 : : }
271 : :
272 : : /**
273 : : * ice_pg_nm_cam_table_get - create a parse graph no match cam table
274 : : * @hw: pointer to the hardware structure
275 : : */
276 : 0 : struct ice_pg_nm_cam_item *ice_pg_nm_cam_table_get(struct ice_hw *hw)
277 : : {
278 : 0 : return (struct ice_pg_nm_cam_item *)
279 : 0 : ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_CAM,
280 : : sizeof(struct ice_pg_nm_cam_item),
281 : : ICE_PG_NM_CAM_TABLE_SIZE,
282 : : ice_parser_sect_item_get,
283 : : _pg_nm_cam_parse_item, false);
284 : : }
285 : :
286 : : /**
287 : : * ice_pg_nm_sp_cam_table_get - create a parse graph no match spill cam table
288 : : * @hw: pointer to the hardware structure
289 : : */
290 : 0 : struct ice_pg_nm_cam_item *ice_pg_nm_sp_cam_table_get(struct ice_hw *hw)
291 : : {
292 : 0 : return (struct ice_pg_nm_cam_item *)
293 : 0 : ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_SPILL,
294 : : sizeof(struct ice_pg_nm_cam_item),
295 : : ICE_PG_NM_SP_CAM_TABLE_SIZE,
296 : : ice_parser_sect_item_get,
297 : : _pg_nm_sp_cam_parse_item, false);
298 : : }
299 : :
300 : : static bool _pg_cam_match(struct ice_pg_cam_item *item,
301 : : struct ice_pg_cam_key *key)
302 : : {
303 : 0 : if (!item->key.valid ||
304 [ # # ]: 0 : item->key.node_id != key->node_id ||
305 : : item->key.flag0 != key->flag0 ||
306 : : item->key.flag1 != key->flag1 ||
307 [ # # ]: 0 : item->key.flag2 != key->flag2 ||
308 : : item->key.flag3 != key->flag3 ||
309 [ # # ]: 0 : item->key.boost_idx != key->boost_idx ||
310 : 0 : item->key.alu_reg != key->alu_reg ||
311 [ # # ]: 0 : item->key.next_proto != key->next_proto)
312 : : return false;
313 : :
314 : : return true;
315 : : }
316 : :
317 : : static bool _pg_nm_cam_match(struct ice_pg_nm_cam_item *item,
318 : : struct ice_pg_cam_key *key)
319 : : {
320 : 0 : if (!item->key.valid ||
321 [ # # ]: 0 : item->key.node_id != key->node_id ||
322 [ # # ]: 0 : item->key.flag0 != key->flag0 ||
323 : : item->key.flag1 != key->flag1 ||
324 [ # # ]: 0 : item->key.flag2 != key->flag2 ||
325 : 0 : item->key.flag3 != key->flag3 ||
326 [ # # ]: 0 : item->key.boost_idx != key->boost_idx ||
327 [ # # ]: 0 : item->key.alu_reg != key->alu_reg)
328 : : return false;
329 : :
330 : : return true;
331 : : }
332 : :
333 : : /**
334 : : * ice_pg_cam_match - search parse graph cam table by key
335 : : * @table: parse graph cam table to search
336 : : * @size: cam table size
337 : : * @key: search key
338 : : */
339 : 0 : struct ice_pg_cam_item *ice_pg_cam_match(struct ice_pg_cam_item *table,
340 : : int size, struct ice_pg_cam_key *key)
341 : : {
342 : : int i;
343 : :
344 [ # # ]: 0 : for (i = 0; i < size; i++) {
345 [ # # ]: 0 : struct ice_pg_cam_item *item = &table[i];
346 : :
347 : : if (_pg_cam_match(item, key))
348 : 0 : return item;
349 : : }
350 : :
351 : : return NULL;
352 : : }
353 : :
354 : : /**
355 : : * ice_pg_nm_cam_match - search parse graph no match cam table by key
356 : : * @table: parse graph no match cam table to search
357 : : * @size: cam table size
358 : : * @key: search key
359 : : */
360 : : struct ice_pg_nm_cam_item *
361 : 0 : ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *table, int size,
362 : : struct ice_pg_cam_key *key)
363 : : {
364 : : int i;
365 : :
366 [ # # ]: 0 : for (i = 0; i < size; i++) {
367 [ # # ]: 0 : struct ice_pg_nm_cam_item *item = &table[i];
368 : :
369 : : if (_pg_nm_cam_match(item, key))
370 : 0 : return item;
371 : : }
372 : :
373 : : return NULL;
374 : : }
|