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 : : #define ICE_BST_TCAM_TABLE_SIZE 256
9 : :
10 : 0 : static void _bst_np_kb_dump(struct ice_hw *hw, struct ice_np_keybuilder *kb)
11 : : {
12 [ # # ]: 0 : ice_info(hw, "next proto key builder:\n");
13 [ # # ]: 0 : ice_info(hw, "\tops = %d\n", kb->ops);
14 [ # # ]: 0 : ice_info(hw, "\tstart_or_reg0 = %d\n", kb->start_or_reg0);
15 [ # # ]: 0 : ice_info(hw, "\tlen_or_reg1 = %d\n", kb->len_or_reg1);
16 : 0 : }
17 : :
18 : 0 : static void _bst_pg_kb_dump(struct ice_hw *hw, struct ice_pg_keybuilder *kb)
19 : : {
20 [ # # ]: 0 : ice_info(hw, "parse graph key builder:\n");
21 [ # # ]: 0 : ice_info(hw, "\tflag0_ena = %d\n", kb->flag0_ena);
22 [ # # ]: 0 : ice_info(hw, "\tflag1_ena = %d\n", kb->flag1_ena);
23 [ # # ]: 0 : ice_info(hw, "\tflag2_ena = %d\n", kb->flag2_ena);
24 [ # # ]: 0 : ice_info(hw, "\tflag3_ena = %d\n", kb->flag3_ena);
25 [ # # ]: 0 : ice_info(hw, "\tflag0_idx = %d\n", kb->flag0_idx);
26 [ # # ]: 0 : ice_info(hw, "\tflag1_idx = %d\n", kb->flag1_idx);
27 [ # # ]: 0 : ice_info(hw, "\tflag2_idx = %d\n", kb->flag2_idx);
28 [ # # ]: 0 : ice_info(hw, "\tflag3_idx = %d\n", kb->flag3_idx);
29 [ # # ]: 0 : ice_info(hw, "\talu_reg_idx = %d\n", kb->alu_reg_idx);
30 : 0 : }
31 : :
32 : 0 : static void _bst_alu_dump(struct ice_hw *hw, struct ice_alu *alu, int index)
33 : : {
34 [ # # ]: 0 : ice_info(hw, "alu%d:\n", index);
35 [ # # ]: 0 : ice_info(hw, "\topc = %d\n", alu->opc);
36 [ # # ]: 0 : ice_info(hw, "\tsrc_start = %d\n", alu->src_start);
37 [ # # ]: 0 : ice_info(hw, "\tsrc_len = %d\n", alu->src_len);
38 [ # # ]: 0 : ice_info(hw, "\tshift_xlate_select = %d\n", alu->shift_xlate_select);
39 [ # # ]: 0 : ice_info(hw, "\tshift_xlate_key = %d\n", alu->shift_xlate_key);
40 [ # # ]: 0 : ice_info(hw, "\tsrc_reg_id = %d\n", alu->src_reg_id);
41 [ # # ]: 0 : ice_info(hw, "\tdst_reg_id = %d\n", alu->dst_reg_id);
42 [ # # ]: 0 : ice_info(hw, "\tinc0 = %d\n", alu->inc0);
43 [ # # ]: 0 : ice_info(hw, "\tinc1 = %d\n", alu->inc1);
44 [ # # ]: 0 : ice_info(hw, "\tproto_offset_opc = %d\n", alu->proto_offset_opc);
45 [ # # ]: 0 : ice_info(hw, "\tproto_offset = %d\n", alu->proto_offset);
46 [ # # ]: 0 : ice_info(hw, "\tbranch_addr = %d\n", alu->branch_addr);
47 [ # # ]: 0 : ice_info(hw, "\timm = %d\n", alu->imm);
48 [ # # ]: 0 : ice_info(hw, "\tdst_start = %d\n", alu->dst_start);
49 [ # # ]: 0 : ice_info(hw, "\tdst_len = %d\n", alu->dst_len);
50 [ # # ]: 0 : ice_info(hw, "\tflags_extr_imm = %d\n", alu->flags_extr_imm);
51 [ # # ]: 0 : ice_info(hw, "\tflags_start_imm= %d\n", alu->flags_start_imm);
52 : 0 : }
53 : :
54 : : /**
55 : : * ice_bst_tcam_dump - dump a boost tcam info
56 : : * @hw: pointer to the hardware structure
57 : : * @item: boost tcam to dump
58 : : */
59 : 0 : void ice_bst_tcam_dump(struct ice_hw *hw, struct ice_bst_tcam_item *item)
60 : : {
61 : : int i;
62 : :
63 [ # # ]: 0 : ice_info(hw, "address = %d\n", item->address);
64 [ # # ]: 0 : ice_info(hw, "key :");
65 [ # # ]: 0 : for (i = 0; i < 20; i++)
66 [ # # ]: 0 : ice_info(hw, "%02x ", item->key[i]);
67 [ # # ]: 0 : ice_info(hw, "\n");
68 [ # # ]: 0 : ice_info(hw, "key_inv:");
69 [ # # ]: 0 : for (i = 0; i < 20; i++)
70 [ # # ]: 0 : ice_info(hw, "%02x ", item->key_inv[i]);
71 [ # # ]: 0 : ice_info(hw, "\n");
72 [ # # ]: 0 : ice_info(hw, "hit_idx_grp = %d\n", item->hit_idx_grp);
73 [ # # ]: 0 : ice_info(hw, "pg_pri = %d\n", item->pg_pri);
74 : 0 : _bst_np_kb_dump(hw, &item->np_kb);
75 : 0 : _bst_pg_kb_dump(hw, &item->pg_kb);
76 : 0 : _bst_alu_dump(hw, &item->alu0, 0);
77 : 0 : _bst_alu_dump(hw, &item->alu1, 1);
78 : 0 : _bst_alu_dump(hw, &item->alu2, 2);
79 : 0 : }
80 : :
81 : : /** The function parses a 96 bits ALU entry with below format:
82 : : * BIT 0-5: Opcode (alu->opc)
83 : : * BIT 6-13: Source Start (alu->src_start)
84 : : * BIT 14-18: Source Length (alu->src_len)
85 : : * BIT 19: Shift/Xlate Select (alu->shift_xlate_select)
86 : : * BIT 20-23: Shift/Xlate Key (alu->shift_xlate_key)
87 : : * BIT 24-30: Source Register ID (alu->src_reg_id)
88 : : * BIT 31-37: Dest. Register ID (alu->dst_reg_id)
89 : : * BIT 38: Inc0 (alu->inc0)
90 : : * BIT 39: Inc1:(alu->inc1)
91 : : * BIT 40:41 Protocol Offset Opcode (alu->proto_offset_opc)
92 : : * BIT 42:49 Protocol Offset (alu->proto_offset)
93 : : * BIT 50:57 Branch Address (alu->branch_addr)
94 : : * BIT 58:73 Immediate (alu->imm)
95 : : * BIT 74 Dedicated Flags Enable (alu->dedicate_flags_ena)
96 : : * BIT 75:80 Dest. Start (alu->dst_start)
97 : : * BIT 81:86 Dest. Length (alu->dst_len)
98 : : * BIT 87 Flags Extract Imm. (alu->flags_extr_imm)
99 : : * BIT 88:95 Flags Start/Immediate (alu->flags_start_imm)
100 : : *
101 : : * NOTE: the first 7 bits are skipped as the start bit is not
102 : : * byte aligned.
103 : : */
104 : 0 : static void _bst_alu_init(struct ice_alu *alu, u8 *data)
105 : : {
106 : 0 : u64 d64 = *(u64 *)data >> 7;
107 : :
108 : 0 : alu->opc = (enum ice_alu_opcode)(d64 & 0x3f);
109 : 0 : alu->src_start = (u8)((d64 >> 6) & 0xff);
110 : 0 : alu->src_len = (u8)((d64 >> 14) & 0x1f);
111 : 0 : alu->shift_xlate_select = ((d64 >> 19) & 0x1) != 0;
112 : 0 : alu->shift_xlate_key = (u8)((d64 >> 20) & 0xf);
113 : 0 : alu->src_reg_id = (u8)((d64 >> 24) & 0x7f);
114 : 0 : alu->dst_reg_id = (u8)((d64 >> 31) & 0x7f);
115 : 0 : alu->inc0 = ((d64 >> 38) & 0x1) != 0;
116 : 0 : alu->inc1 = ((d64 >> 39) & 0x1) != 0;
117 : 0 : alu->proto_offset_opc = (u8)((d64 >> 40) & 0x3);
118 : 0 : alu->proto_offset = (u8)((d64 >> 42) & 0xff);
119 : :
120 : 0 : d64 = *(u64 *)(&data[6]) >> 9;
121 : :
122 : 0 : alu->branch_addr = (u8)(d64 & 0xff);
123 : 0 : alu->imm = (u16)((d64 >> 8) & 0xffff);
124 : 0 : alu->dedicate_flags_ena = ((d64 >> 24) & 0x1) != 0;
125 : 0 : alu->dst_start = (u8)((d64 >> 25) & 0x3f);
126 : 0 : alu->dst_len = (u8)((d64 >> 31) & 0x3f);
127 : 0 : alu->flags_extr_imm = ((d64 >> 37) & 0x1) != 0;
128 : 0 : alu->flags_start_imm = (u8)((d64 >> 38) & 0xff);
129 : 0 : }
130 : :
131 : : /** The function parses a 35 bits Parse Graph Key Build with below format:
132 : : * BIT 0: Flag 0 Enable (kb->flag0_ena)
133 : : * BIT 1-6: Flag 0 Index (kb->flag0_idx)
134 : : * BIT 7: Flag 1 Enable (kb->flag1_ena)
135 : : * BIT 8-13: Flag 1 Index (kb->flag1_idx)
136 : : * BIT 14: Flag 2 Enable (kb->flag2_ena)
137 : : * BIT 15-20: Flag 2 Index (kb->flag2_idx)
138 : : * BIT 21: Flag 3 Enable (kb->flag3_ena)
139 : : * BIT 22-27: Flag 3 Index (kb->flag3_idx)
140 : : * BIT 28-34: ALU Register Index (kb->alu_reg_idx)
141 : : */
142 : 0 : static void _bst_pgkb_init(struct ice_pg_keybuilder *kb, u64 data)
143 : : {
144 : 0 : kb->flag0_ena = (data & 0x1) != 0;
145 : 0 : kb->flag0_idx = (u8)((data >> 1) & 0x3f);
146 : 0 : kb->flag1_ena = ((data >> 7) & 0x1) != 0;
147 : 0 : kb->flag1_idx = (u8)((data >> 8) & 0x3f);
148 : 0 : kb->flag2_ena = ((data >> 14) & 0x1) != 0;
149 : 0 : kb->flag2_idx = (u8)((data >> 15) & 0x3f);
150 : 0 : kb->flag3_ena = ((data >> 21) & 0x1) != 0;
151 : 0 : kb->flag3_idx = (u8)((data >> 22) & 0x3f);
152 : 0 : kb->alu_reg_idx = (u8)((data >> 28) & 0x7f);
153 : 0 : }
154 : :
155 : : /** The function parses a 18 bits Next Protocol Key Build with below format:
156 : : * BIT 0-1: Opcode kb->ops
157 : : * BIT 2-9: Start / Reg 0 (kb->start_or_reg0)
158 : : * BIT 10-17: Length / Reg 1 (kb->len_or_reg1)
159 : : */
160 : : static void _bst_npkb_init(struct ice_np_keybuilder *kb, u32 data)
161 : : {
162 : 0 : kb->ops = (u8)(data & 0x3);
163 : 0 : kb->start_or_reg0 = (u8)((data >> 2) & 0xff);
164 : 0 : kb->len_or_reg1 = (u8)((data >> 10) & 0xff);
165 : : }
166 : :
167 : : /** The function parses a 704 bits Boost TCAM entry with below format:
168 : : * BIT 0-15: Address (ti->address)
169 : : * BIT 16-31: reserved
170 : : * BIT 32-191: Key (ti->key)
171 : : * BIT 192-351:Key Invert (ti->key_inv)
172 : : * BIT 352-359:Boost Hit Index Group (ti->hit_idx_grp)
173 : : * BIT 360-361:PG Priority (ti->pg_pri)
174 : : * BIT 362-379:Next Proto Key Build (ti->np_kb)
175 : : * BIT 380-414:PG Key Build (ti->pg_kb)
176 : : * BIT 415-510:ALU 0 (ti->alu0)
177 : : * BIT 511-606:ALU 1 (ti->alu1)
178 : : * BIT 607-702:ALU 2 (ti->alu2)
179 : : * BIT 703: reserved
180 : : */
181 : 0 : static void _bst_parse_item(struct ice_hw *hw, u16 idx, void *item,
182 : : void *data, int size)
183 : : {
184 : : struct ice_bst_tcam_item *ti = (struct ice_bst_tcam_item *)item;
185 : : u8 *buf = (u8 *)data;
186 : : int i;
187 : :
188 : 0 : ti->address = *(u16 *)buf;
189 : :
190 [ # # ]: 0 : for (i = 0; i < 20; i++)
191 : 0 : ti->key[i] = buf[4 + i];
192 [ # # ]: 0 : for (i = 0; i < 20; i++)
193 : 0 : ti->key_inv[i] = buf[24 + i];
194 : 0 : ti->hit_idx_grp = buf[44];
195 : 0 : ti->pg_pri = buf[45] & 0x3;
196 : 0 : _bst_npkb_init(&ti->np_kb, *(u32 *)&buf[45] >> 2);
197 : 0 : _bst_pgkb_init(&ti->pg_kb, *(u64 *)&buf[47] >> 4);
198 : 0 : _bst_alu_init(&ti->alu0, &buf[51]);
199 : 0 : _bst_alu_init(&ti->alu1, &buf[63]);
200 : 0 : _bst_alu_init(&ti->alu2, &buf[75]);
201 : :
202 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
203 : 0 : ice_bst_tcam_dump(hw, ti);
204 : 0 : }
205 : :
206 : : /**
207 : : * ice_bst_tcam_table_get - create a boost tcam table
208 : : * @hw: pointer to the hardware structure
209 : : */
210 : 0 : struct ice_bst_tcam_item *ice_bst_tcam_table_get(struct ice_hw *hw)
211 : : {
212 : 0 : return (struct ice_bst_tcam_item *)
213 : 0 : ice_parser_create_table(hw, ICE_SID_RXPARSER_BOOST_TCAM,
214 : : sizeof(struct ice_bst_tcam_item),
215 : : ICE_BST_TCAM_TABLE_SIZE,
216 : : ice_parser_sect_item_get,
217 : : _bst_parse_item, true);
218 : : }
219 : :
220 : 0 : static void _parse_lbl_item(struct ice_hw *hw, u16 idx, void *item,
221 : : void *data, int size)
222 : : {
223 : 0 : ice_parse_item_dflt(hw, idx, item, data, size);
224 : :
225 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
226 : 0 : ice_lbl_dump(hw, (struct ice_lbl_item *)item);
227 : 0 : }
228 : :
229 : : /**
230 : : * ice_bst_lbl_table_get - create a boost label table
231 : : * @hw: pointer to the hardware structure
232 : : */
233 : 0 : struct ice_lbl_item *ice_bst_lbl_table_get(struct ice_hw *hw)
234 : : {
235 : 0 : return (struct ice_lbl_item *)
236 : 0 : ice_parser_create_table(hw, ICE_SID_LBL_RXPARSER_TMEM,
237 : : sizeof(struct ice_lbl_item),
238 : : ICE_BST_TCAM_TABLE_SIZE,
239 : : ice_parser_sect_item_get,
240 : : _parse_lbl_item, true);
241 : : }
242 : :
243 : : /**
244 : : * ice_bst_tcam_match - match a pattern on the boost tcam table
245 : : * @tcam_table: boost tcam table to search
246 : : * @pat: pattern to match
247 : : */
248 : : struct ice_bst_tcam_item *
249 : 0 : ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat)
250 : : {
251 : : int i;
252 : :
253 [ # # ]: 0 : for (i = 0; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
254 : 0 : struct ice_bst_tcam_item *item = &tcam_table[i];
255 : :
256 [ # # ]: 0 : if (item->hit_idx_grp == 0)
257 : 0 : continue;
258 [ # # ]: 0 : if (ice_ternary_match(item->key, item->key_inv, pat, 20))
259 : 0 : return item;
260 : : }
261 : :
262 : : return NULL;
263 : : }
264 : :
265 : 0 : static bool _start_with(const char *prefix, const char *string)
266 : : {
267 : 0 : int len1 = strlen(prefix);
268 : 0 : int len2 = strlen(string);
269 : :
270 [ # # ]: 0 : if (len2 < len1)
271 : : return false;
272 : :
273 : 0 : return !memcmp(prefix, string, len1);
274 : : }
275 : :
276 : : struct ice_bst_tcam_item *
277 : 0 : ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table,
278 : : struct ice_lbl_item *lbl_table,
279 : : const char *prefix, u16 *start)
280 : : {
281 : 0 : u16 i = *start;
282 : :
283 [ # # ]: 0 : for (; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
284 [ # # ]: 0 : if (_start_with(prefix, lbl_table[i].label)) {
285 : 0 : *start = i;
286 : 0 : return &tcam_table[lbl_table[i].idx];
287 : : }
288 : : }
289 : :
290 : : return NULL;
291 : : }
|