1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
8 static void _pg_cam_key_dump(struct ice_hw *hw, struct ice_pg_cam_key *key)
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);
22 static void _pg_nm_cam_key_dump(struct ice_hw *hw,
23 struct ice_pg_nm_cam_key *key)
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);
36 static void _pg_cam_action_dump(struct ice_hw *hw,
37 struct ice_pg_cam_action *action)
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);
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
56 void ice_pg_cam_dump(struct ice_hw *hw, struct ice_pg_cam_item *item)
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);
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
68 void ice_pg_nm_cam_dump(struct ice_hw *hw, struct ice_pg_nm_cam_item *item)
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);
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)
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)
88 static void _pg_cam_action_init(struct ice_pg_cam_action *action, u64 data)
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);
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)
112 static void _pg_nm_cam_key_init(struct ice_pg_nm_cam_key *key, u64 data)
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);
124 key->alu_reg = (u16)((data >> 25) & 0xffff);
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)
139 static void _pg_cam_key_init(struct ice_pg_cam_key *key, u8 *data)
141 u64 d64 = *(u64 *)data;
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);
153 key->alu_reg = (u16)((d64 >> 25) & 0xffff);
155 key->next_proto = (*(u32 *)&data[5] >> 1);
156 key->next_proto |= ((u32)(data[9] & 0x1) << 31);
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)
163 static void _pg_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
164 void *data, int size)
166 struct ice_pg_cam_item *ci = (struct ice_pg_cam_item *)item;
167 u8 *buf = (u8 *)data;
171 d64 = (*(u64 *)&buf[9] >> 1);
172 _pg_cam_key_init(&ci->key, buf);
173 _pg_cam_action_init(&ci->action, d64);
175 if (hw->debug_mask & ICE_DBG_PARSER)
176 ice_pg_cam_dump(hw, ci);
179 /** The function parses a 136 bits Parse Graph Spill CAM Entry with below
181 * BIT 0-55: Action (ci->key)
182 * BIT 56-135: Key (ci->action)
184 static void _pg_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
185 void *data, int size)
187 struct ice_pg_cam_item *ci = (struct ice_pg_cam_item *)item;
188 u8 *buf = (u8 *)data;
193 _pg_cam_action_init(&ci->action, d64);
194 _pg_cam_key_init(&ci->key, &buf[7]);
196 if (hw->debug_mask & ICE_DBG_PARSER)
197 ice_pg_cam_dump(hw, ci);
200 /** The function parses a 96 bits Parse Graph NoMatch CAM Entry with below
202 * BIT 0-40: Key (ci->key)
203 * BIT 41-95: Action (ci->action)
205 static void _pg_nm_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
206 void *data, int size)
208 struct ice_pg_nm_cam_item *ci = (struct ice_pg_nm_cam_item *)item;
209 u8 *buf = (u8 *)data;
214 _pg_nm_cam_key_init(&ci->key, d64);
215 d64 = (*(u64 *)&buf[5] >> 1);
216 _pg_cam_action_init(&ci->action, d64);
218 if (hw->debug_mask & ICE_DBG_PARSER)
219 ice_pg_nm_cam_dump(hw, ci);
222 /** The function parses a 104 bits Parse Graph NoMatch Spill CAM Entry with
224 * BIT 0-55: Key (ci->key)
225 * BIT 56-103: Action (ci->action)
227 static void _pg_nm_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
228 void *data, int size)
230 struct ice_pg_nm_cam_item *ci = (struct ice_pg_nm_cam_item *)item;
231 u8 *buf = (u8 *)data;
236 _pg_cam_action_init(&ci->action, d64);
237 d64 = *(u64 *)&buf[7];
238 _pg_nm_cam_key_init(&ci->key, d64);
240 if (hw->debug_mask & ICE_DBG_PARSER)
241 ice_pg_nm_cam_dump(hw, ci);
245 * ice_pg_cam_table_get - create a parse graph cam table
246 * @ice_hw: pointer to the hardware structure
248 struct ice_pg_cam_item *ice_pg_cam_table_get(struct ice_hw *hw)
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);
259 * ice_pg_sp_cam_table_get - create a parse graph spill cam table
260 * @ice_hw: pointer to the hardware structure
262 struct ice_pg_cam_item *ice_pg_sp_cam_table_get(struct ice_hw *hw)
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);
273 * ice_pg_nm_cam_table_get - create a parse graph no match cam table
274 * @ice_hw: pointer to the hardware structure
276 struct ice_pg_nm_cam_item *ice_pg_nm_cam_table_get(struct ice_hw *hw)
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);
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
290 struct ice_pg_nm_cam_item *ice_pg_nm_sp_cam_table_get(struct ice_hw *hw)
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);