net/ice: track DCF state of PF
[dpdk.git] / drivers / net / ice / base / ice_pg_cam.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
7
8 static void _pg_cam_key_dump(struct ice_hw *hw, struct ice_pg_cam_key *key)
9 {
10         ice_info(hw, "key:\n");
11         ice_info(hw, "\tvalid = %d\n", key->valid);
12         ice_info(hw, "\tnode_id = %d\n", key->node_id);
13         ice_info(hw, "\tflag0 = %d\n", key->flag0);
14         ice_info(hw, "\tflag1 = %d\n", key->flag1);
15         ice_info(hw, "\tflag2 = %d\n", key->flag2);
16         ice_info(hw, "\tflag3 = %d\n", key->flag3);
17         ice_info(hw, "\tboost_idx = %d\n", key->boost_idx);
18         ice_info(hw, "\talu_reg = 0x%04x\n", key->alu_reg);
19         ice_info(hw, "\tnext_proto = 0x%08x\n", key->next_proto);
20 }
21
22 static void _pg_nm_cam_key_dump(struct ice_hw *hw,
23                                 struct ice_pg_nm_cam_key *key)
24 {
25         ice_info(hw, "key:\n");
26         ice_info(hw, "\tvalid = %d\n", key->valid);
27         ice_info(hw, "\tnode_id = %d\n", key->node_id);
28         ice_info(hw, "\tflag0 = %d\n", key->flag0);
29         ice_info(hw, "\tflag1 = %d\n", key->flag1);
30         ice_info(hw, "\tflag2 = %d\n", key->flag2);
31         ice_info(hw, "\tflag3 = %d\n", key->flag3);
32         ice_info(hw, "\tboost_idx = %d\n", key->boost_idx);
33         ice_info(hw, "\talu_reg = 0x%04x\n", key->alu_reg);
34 }
35
36 static void _pg_cam_action_dump(struct ice_hw *hw,
37                                 struct ice_pg_cam_action *action)
38 {
39         ice_info(hw, "action:\n");
40         ice_info(hw, "\tnext_node = %d\n", action->next_node);
41         ice_info(hw, "\tnext_pc = %d\n", action->next_pc);
42         ice_info(hw, "\tis_pg = %d\n", action->is_pg);
43         ice_info(hw, "\tproto_id = %d\n", action->proto_id);
44         ice_info(hw, "\tis_mg = %d\n", action->is_mg);
45         ice_info(hw, "\tmarker_id = %d\n", action->marker_id);
46         ice_info(hw, "\tis_last_round = %d\n", action->is_last_round);
47         ice_info(hw, "\tho_polarity = %d\n", action->ho_polarity);
48         ice_info(hw, "\tho_inc = %d\n", action->ho_inc);
49 }
50
51 /**
52  * ice_pg_cam_dump - dump an parse graph cam info
53  * @ice_hw: pointer to the hardware structure
54  * @item: parse graph cam to dump
55  */
56 void ice_pg_cam_dump(struct ice_hw *hw, struct ice_pg_cam_item *item)
57 {
58         ice_info(hw, "index = %d\n", item->idx);
59         _pg_cam_key_dump(hw, &item->key);
60         _pg_cam_action_dump(hw, &item->action);
61 }
62
63 /**
64  * ice_pg_nm_cam_dump - dump an parse graph no match cam info
65  * @ice_hw: pointer to the hardware structure
66  * @item: parse graph no match cam to dump
67  */
68 void ice_pg_nm_cam_dump(struct ice_hw *hw, struct ice_pg_nm_cam_item *item)
69 {
70         ice_info(hw, "index = %d\n", item->idx);
71         _pg_nm_cam_key_dump(hw, &item->key);
72         _pg_cam_action_dump(hw, &item->action);
73 }
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 static void _pg_cam_action_init(struct ice_pg_cam_action *action, u64 data)
89 {
90         action->next_node = (u16)(data & 0x7ff);
91         action->next_pc = (u8)((data >> 11) & 0xff);
92         action->is_pg = ((data >> 19) & 0x1) != 0;
93         action->proto_id = ((data >> 23) & 0xff);
94         action->is_mg = ((data >> 31) & 0x1) != 0;
95         action->marker_id = ((data >> 32) & 0xff);
96         action->is_last_round = ((data >> 40) & 0x1) != 0;
97         action->ho_polarity = ((data >> 41) & 0x1) != 0;
98         action->ho_inc = ((data >> 42) & 0x1ff);
99 }
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 static void _pg_nm_cam_key_init(struct ice_pg_nm_cam_key *key, u64 data)
113 {
114         key->valid = (data & 0x1) != 0;
115         key->node_id = (u16)((data >> 1) & 0x7ff);
116         key->flag0 = ((data >> 12) & 0x1) != 0;
117         key->flag1 = ((data >> 13) & 0x1) != 0;
118         key->flag2 = ((data >> 14) & 0x1) != 0;
119         key->flag3 = ((data >> 15) & 0x1) != 0;
120         if ((data >> 16) & 0x1)
121                 key->boost_idx = (u8)((data >> 17) & 0xff);
122         else
123                 key->boost_idx = 0;
124         key->alu_reg = (u16)((data >> 25) & 0xffff);
125 }
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 static void _pg_cam_key_init(struct ice_pg_cam_key *key, u8 *data)
140 {
141         u64 d64 = *(u64 *)data;
142
143         key->valid = (d64 & 0x1) != 0;
144         key->node_id = (u16)((d64 >> 1) & 0x7ff);
145         key->flag0 = ((d64 >> 12) & 0x1) != 0;
146         key->flag1 = ((d64 >> 13) & 0x1) != 0;
147         key->flag2 = ((d64 >> 14) & 0x1) != 0;
148         key->flag3 = ((d64 >> 15) & 0x1) != 0;
149         if ((d64 >> 16) & 0x1)
150                 key->boost_idx = (u8)((d64 >> 17) & 0xff);
151         else
152                 key->boost_idx = 0;
153         key->alu_reg = (u16)((d64 >> 25) & 0xffff);
154
155         key->next_proto = (*(u32 *)&data[5] >> 1);
156         key->next_proto |= ((u32)(data[9] & 0x1) << 31);
157 }
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 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         ci->idx = idx;
171         d64 = (*(u64 *)&buf[9] >> 1);
172         _pg_cam_key_init(&ci->key, buf);
173         _pg_cam_action_init(&ci->action, d64);
174
175         if (hw->debug_mask & ICE_DBG_PARSER)
176                 ice_pg_cam_dump(hw, ci);
177 }
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 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         ci->idx = idx;
192         d64 = *(u64 *)buf;
193         _pg_cam_action_init(&ci->action, d64);
194         _pg_cam_key_init(&ci->key, &buf[7]);
195
196         if (hw->debug_mask & ICE_DBG_PARSER)
197                 ice_pg_cam_dump(hw, ci);
198 }
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 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         ci->idx = idx;
213         d64 = *(u64 *)buf;
214         _pg_nm_cam_key_init(&ci->key, d64);
215         d64 = (*(u64 *)&buf[5] >> 1);
216         _pg_cam_action_init(&ci->action, d64);
217
218         if (hw->debug_mask & ICE_DBG_PARSER)
219                 ice_pg_nm_cam_dump(hw, ci);
220 }
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 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         ci->idx = idx;
235         d64 = *(u64 *)buf;
236         _pg_cam_action_init(&ci->action, d64);
237         d64 = *(u64 *)&buf[7];
238         _pg_nm_cam_key_init(&ci->key, d64);
239
240         if (hw->debug_mask & ICE_DBG_PARSER)
241                 ice_pg_nm_cam_dump(hw, ci);
242 }
243
244 /**
245  * ice_pg_cam_table_get - create a parse graph cam table
246  * @ice_hw: pointer to the hardware structure
247  */
248 struct ice_pg_cam_item *ice_pg_cam_table_get(struct ice_hw *hw)
249 {
250         return (struct ice_pg_cam_item *)
251                 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  * @ice_hw: pointer to the hardware structure
261  */
262 struct ice_pg_cam_item *ice_pg_sp_cam_table_get(struct ice_hw *hw)
263 {
264         return (struct ice_pg_cam_item *)
265                 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  * @ice_hw: pointer to the hardware structure
275  */
276 struct ice_pg_nm_cam_item *ice_pg_nm_cam_table_get(struct ice_hw *hw)
277 {
278         return (struct ice_pg_nm_cam_item *)
279                 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  * @ice_hw: pointer to the hardware structure
289  */
290 struct ice_pg_nm_cam_item *ice_pg_nm_sp_cam_table_get(struct ice_hw *hw)
291 {
292         return (struct ice_pg_nm_cam_item *)
293                 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         if (!item->key.valid ||
304             item->key.node_id != key->node_id ||
305             item->key.flag0 != key->flag0 ||
306             item->key.flag1 != key->flag1 ||
307             item->key.flag2 != key->flag2 ||
308             item->key.flag3 != key->flag3 ||
309             item->key.boost_idx != key->boost_idx ||
310             item->key.alu_reg != key->alu_reg ||
311             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         if (!item->key.valid ||
321             item->key.node_id != key->node_id ||
322             item->key.flag0 != key->flag0 ||
323             item->key.flag1 != key->flag1 ||
324             item->key.flag2 != key->flag2 ||
325             item->key.flag3 != key->flag3 ||
326             item->key.boost_idx != key->boost_idx ||
327             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 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         for (i = 0; i < size; i++) {
345                 struct ice_pg_cam_item *item = &table[i];
346
347                 if (_pg_cam_match(item, key))
348                         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 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         for (i = 0; i < size; i++) {
367                 struct ice_pg_nm_cam_item *item = &table[i];
368
369                 if (_pg_nm_cam_match(item, key))
370                         return item;
371         }
372
373         return NULL;
374 }