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 : :
7 : : #define ICE_XLT_KB_TBL_OFF 12
8 : : #define ICE_XLT_KB_TBL_ENTRY_SIZE 24
9 : :
10 : 0 : static void _xlt_kb_entry_dump(struct ice_hw *hw,
11 : : struct ice_xlt_kb_entry *entry, int idx)
12 : : {
13 : : int i;
14 : :
15 [ # # ]: 0 : ice_info(hw, "key builder entry %d\n", idx);
16 [ # # ]: 0 : ice_info(hw, "\txlt1_ad_sel = %d\n", entry->xlt1_ad_sel);
17 [ # # ]: 0 : ice_info(hw, "\txlt2_ad_sel = %d\n", entry->xlt2_ad_sel);
18 : :
19 [ # # ]: 0 : for (i = 0; i < ICE_XLT_KB_FLAG0_14_CNT; i++)
20 [ # # ]: 0 : ice_info(hw, "\tflg%d_sel = %d\n", i, entry->flg0_14_sel[i]);
21 : :
22 [ # # ]: 0 : ice_info(hw, "\txlt1_md_sel = %d\n", entry->xlt1_md_sel);
23 [ # # ]: 0 : ice_info(hw, "\txlt2_md_sel = %d\n", entry->xlt2_md_sel);
24 : 0 : }
25 : :
26 : : /**
27 : : * ice_imem_dump - dump a xlt key build info
28 : : * @hw: pointer to the hardware structure
29 : : * @kb: key build to dump
30 : : */
31 : 0 : void ice_xlt_kb_dump(struct ice_hw *hw, struct ice_xlt_kb *kb)
32 : : {
33 : : int i;
34 : :
35 [ # # ]: 0 : ice_info(hw, "xlt1_pm = %d\n", kb->xlt1_pm);
36 [ # # ]: 0 : ice_info(hw, "xlt2_pm = %d\n", kb->xlt2_pm);
37 [ # # ]: 0 : ice_info(hw, "prof_id_pm = %d\n", kb->prof_id_pm);
38 [ # # ]: 0 : ice_info(hw, "flag15 low = 0x%08x\n", (u32)kb->flag15);
39 [ # # ]: 0 : ice_info(hw, "flag15 high = 0x%08x\n", (u32)(kb->flag15 >> 32));
40 : :
41 [ # # ]: 0 : for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
42 : 0 : _xlt_kb_entry_dump(hw, &kb->entries[i], i);
43 : 0 : }
44 : :
45 : : /** The function parses a 192 bits XLT Key Build entry with below format:
46 : : * BIT 0-31: reserved
47 : : * BIT 32-34: XLT1 AdSel (entry->xlt1_ad_sel)
48 : : * BIT 35-37: XLT2 AdSel (entry->xlt2_ad_sel)
49 : : * BIT 38-46: Flag 0 Select (entry->flg0_14_sel[0])
50 : : * BIT 47-55: Flag 1 Select (entry->flg0_14_sel[1])
51 : : * BIT 56-64: Flag 2 Select (entry->flg0_14_sel[2])
52 : : * BIT 65-73: Flag 3 Select (entry->flg0_14_sel[3])
53 : : * BIT 74-82: Flag 4 Select (entry->flg0_14_sel[4])
54 : : * BIT 83-91: Flag 5 Select (entry->flg0_14_sel[5])
55 : : * BIT 92-100: Flag 6 Select (entry->flg0_14_sel[6])
56 : : * BIT 101-109:Flag 7 Select (entry->flg0_14_sel[7])
57 : : * BIT 110-118:Flag 8 Select (entry->flg0_14_sel[8])
58 : : * BIT 119-127:Flag 9 Select (entry->flg0_14_sel[9])
59 : : * BIT 128-136:Flag 10 Select (entry->flg0_14_sel[10])
60 : : * BIT 137-145:Flag 11 Select (entry->flg0_14_sel[11])
61 : : * BIT 146-154:Flag 12 Select (entry->flg0_14_sel[12])
62 : : * BIT 155-163:Flag 13 Select (entry->flg0_14_sel[13])
63 : : * BIT 164-172:Flag 14 Select (entry->flg0_14_sel[14])
64 : : * BIT 173-181:reserved
65 : : * BIT 182-186:XLT1 MdSel (entry->xlt1_md_sel)
66 : : * BIT 187-191:XLT2 MdSel (entry->xlt2_md_sel)
67 : : */
68 : 0 : static void _kb_entry_init(struct ice_xlt_kb_entry *entry, u8 *data)
69 : : {
70 : 0 : u64 d64 = *(u64 *)&data[4];
71 : :
72 : 0 : entry->xlt1_ad_sel = (u8)(d64 & 0x7);
73 : 0 : entry->xlt2_ad_sel = (u8)((d64 >> 3) & 0x7);
74 : 0 : entry->flg0_14_sel[0] = (u16)((d64 >> 6) & 0x1ff);
75 : 0 : entry->flg0_14_sel[1] = (u16)((d64 >> 15) & 0x1ff);
76 : 0 : entry->flg0_14_sel[2] = (u16)((d64 >> 24) & 0x1ff);
77 : 0 : entry->flg0_14_sel[3] = (u16)((d64 >> 33) & 0x1ff);
78 : 0 : entry->flg0_14_sel[4] = (u16)((d64 >> 42) & 0x1ff);
79 : 0 : entry->flg0_14_sel[5] = (u16)((d64 >> 51) & 0x1ff);
80 : :
81 : 0 : d64 = (*(u64 *)&data[11] >> 4);
82 : 0 : entry->flg0_14_sel[6] = (u16)(d64 & 0x1ff);
83 : 0 : entry->flg0_14_sel[7] = (u16)((d64 >> 9) & 0x1ff);
84 : 0 : entry->flg0_14_sel[8] = (u16)((d64 >> 18) & 0x1ff);
85 : 0 : entry->flg0_14_sel[9] = (u16)((d64 >> 27) & 0x1ff);
86 : 0 : entry->flg0_14_sel[10] = (u16)((d64 >> 36) & 0x1ff);
87 : 0 : entry->flg0_14_sel[11] = (u16)((d64 >> 45) & 0x1ff);
88 : :
89 : 0 : d64 = (*(u64 *)&data[18] >> 2);
90 : 0 : entry->flg0_14_sel[12] = (u16)(d64 & 0x1ff);
91 : 0 : entry->flg0_14_sel[13] = (u16)((d64 >> 9) & 0x1ff);
92 : 0 : entry->flg0_14_sel[14] = (u16)((d64 >> 18) & 0x1ff);
93 : :
94 : 0 : entry->xlt1_md_sel = (u8)((d64 >> 36) & 0x1f);
95 : 0 : entry->xlt2_md_sel = (u8)((d64 >> 41) & 0x1f);
96 : 0 : }
97 : :
98 : : /** The function parses a 204 bytes XLT Key Build Table with below format:
99 : : * byte 0: XLT1 Partition Mode (kb->xlt1_pm)
100 : : * byte 1: XLT2 Partition Mode (kb->xlt2_pm)
101 : : * byte 2: Profile ID Partition Mode (kb->prof_id_pm)
102 : : * byte 3: reserved
103 : : * byte 4-11: Flag15 Mask (kb->flag15)
104 : : * byte 12-203:8 Key Build entries (kb->entries)
105 : : */
106 : 0 : static void _parse_kb_data(struct ice_hw *hw, struct ice_xlt_kb *kb, void *data)
107 : : {
108 : : u8 *buf = (u8 *)data;
109 : : int i;
110 : :
111 : 0 : kb->xlt1_pm = buf[0];
112 : 0 : kb->xlt2_pm = buf[1];
113 : 0 : kb->prof_id_pm = buf[2];
114 : :
115 : 0 : kb->flag15 = *(u64 *)&buf[4];
116 [ # # ]: 0 : for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
117 : 0 : _kb_entry_init(&kb->entries[i],
118 : 0 : &buf[ICE_XLT_KB_TBL_OFF +
119 : 0 : i * ICE_XLT_KB_TBL_ENTRY_SIZE]);
120 : :
121 [ # # ]: 0 : if (hw->debug_mask & ICE_DBG_PARSER)
122 : 0 : ice_xlt_kb_dump(hw, kb);
123 : 0 : }
124 : :
125 : 0 : static struct ice_xlt_kb *_xlt_kb_get(struct ice_hw *hw, u32 sect_type)
126 : : {
127 : 0 : struct ice_seg *seg = hw->seg;
128 : : struct ice_pkg_enum state;
129 : : struct ice_xlt_kb *kb;
130 : : void *data;
131 : :
132 [ # # ]: 0 : if (!seg)
133 : : return NULL;
134 : :
135 : 0 : kb = (struct ice_xlt_kb *)ice_malloc(hw, sizeof(*kb));
136 [ # # ]: 0 : if (!kb) {
137 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for xlt key builder type %d.\n",
138 : : sect_type);
139 : 0 : return NULL;
140 : : }
141 : :
142 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
143 : 0 : data = ice_pkg_enum_section(seg, &state, sect_type);
144 [ # # ]: 0 : if (!data) {
145 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PARSER, "failed to find section type %d.\n",
146 : : sect_type);
147 : 0 : return NULL;
148 : : }
149 : :
150 : 0 : _parse_kb_data(hw, kb, data);
151 : :
152 : 0 : return kb;
153 : : }
154 : :
155 : : /**
156 : : * ice_xlt_kb_get_sw - create switch xlt key build
157 : : * @hw: pointer to the hardware structure
158 : : */
159 : 0 : struct ice_xlt_kb *ice_xlt_kb_get_sw(struct ice_hw *hw)
160 : : {
161 : 0 : return _xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_SW);
162 : : }
163 : :
164 : : /**
165 : : * ice_xlt_kb_get_acl - create acl xlt key build
166 : : * @hw: pointer to the hardware structure
167 : : */
168 : 0 : struct ice_xlt_kb *ice_xlt_kb_get_acl(struct ice_hw *hw)
169 : : {
170 : 0 : return _xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_ACL);
171 : : }
172 : :
173 : : /**
174 : : * ice_xlt_kb_get_fd - create fdir xlt key build
175 : : * @hw: pointer to the hardware structure
176 : : */
177 : 0 : struct ice_xlt_kb *ice_xlt_kb_get_fd(struct ice_hw *hw)
178 : : {
179 : 0 : return _xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_FD);
180 : : }
181 : :
182 : : /**
183 : : * ice_xlt_kb_get_fd - create rss xlt key build
184 : : * @hw: pointer to the hardware structure
185 : : */
186 : 0 : struct ice_xlt_kb *ice_xlt_kb_get_rss(struct ice_hw *hw)
187 : : {
188 : 0 : return _xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_RSS);
189 : : }
190 : :
191 : : /**
192 : : * ice_xlt_kb_flag_get - aggregate 64 bits packet flag into 16 bits xlt flag
193 : : * @kb: xlt key build
194 : : * @pkt_flag: 64 bits packet flag
195 : : */
196 : 0 : u16 ice_xlt_kb_flag_get(struct ice_xlt_kb *kb, u64 pkt_flag)
197 : : {
198 : : struct ice_xlt_kb_entry *entry = &kb->entries[0];
199 : : u16 flg = 0;
200 : : int i;
201 : :
202 : : /* check flag 15 */
203 [ # # ]: 0 : if (kb->flag15 & pkt_flag)
204 : : flg = (u16)(1u << 15);
205 : :
206 : : /* check flag 0 - 14 */
207 [ # # ]: 0 : for (i = 0; i < 15; i++) {
208 : : /* only check first entry */
209 : 0 : u16 idx = (u16)(entry->flg0_14_sel[i] & 0x3f);
210 : :
211 [ # # ]: 0 : if (pkt_flag & (1ul << idx))
212 : 0 : flg |= (u16)(1u << i);
213 : : }
214 : :
215 : 0 : return flg;
216 : : }
|