Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2022 Intel Corporation
3 : : */
4 : :
5 : : #include <stdlib.h>
6 : : #include <unistd.h>
7 : : #include <sys/stat.h>
8 : :
9 : : #include <eal_export.h>
10 : : #include <rte_string_fns.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_tailq.h>
13 : :
14 : : #include "ice_ethdev.h"
15 : : #include "ice_rxtx.h"
16 : : #include "rte_pmd_ice.h"
17 : :
18 : : #define ICE_BLK_MAX_COUNT 512
19 : : #define ICE_BUFF_SEG_HEADER_FLAG 0x1
20 : : #define ICE_PKG_HDR_HEADR_PART1 1
21 : : #define ICE_PKG_HDR_HEADR_PART2 2
22 : : #define ICE_PKG_HDR_GM_SEG_OFFSET 16
23 : : #define ICE_PKG_HDR_ICE_SEG_OFFSET 100
24 : : #define ICE_PKG_GM_SEG_TYPE 1
25 : : #define ICE_PKG_MAJOR_VERSION 1
26 : : #define ICE_PKG_GM_SEG_SIZE 84
27 : : #define ICE_PKG_ICE_SEG_TYPE 0x10
28 : : #define ICE_PKG_ICE_SEG_SIZE_BASE 56
29 : : #define SPACE_CHAR 0x20
30 : :
31 : : #define ICE_PKG_COPY_STRING(dst, src) \
32 : : do {\
33 : : char *_dst = (dst); \
34 : : const char *_src = (src); \
35 : : memset(_dst, SPACE_CHAR, ICE_PKG_NAME_SIZE); \
36 : : strlcpy(_dst, _src, strlen(_dst)); \
37 : : } while (0)
38 : :
39 : : /* Package header */
40 : : struct ice_package_header {
41 : : struct __hdr {
42 : : uint32_t h1; /* header part 1 */
43 : : uint32_t h2; /* header part 2 */
44 : : } header;
45 : : uint32_t gm_seg_offset; /* Global Metadata segment: 16 */
46 : : uint32_t ice_seg_offset; /* ICE segment: 100 */
47 : : struct ice_global_metadata_seg gm_seg;
48 : : struct __ice_seg {
49 : : struct ice_generic_seg_hdr hdr;
50 : : uint32_t devid_count;
51 : : struct ice_pkg_ver nvm_ver;
52 : : } ice_seg;
53 : :
54 : : uint32_t buff_count;
55 : : };
56 : :
57 : : struct ice_buff_seg_header {
58 : : __le16 flag;
59 : : __le16 length;
60 : : __le16 type;
61 : : __le16 reserve; /* 0 */
62 : : __le16 header_len; /* 0x0C */
63 : : __le16 data_size; /* length - header_len */
64 : : };
65 : :
66 : : struct ice_buff_seg_simple {
67 : : struct ice_buff_seg_header header;
68 : : __le16 seg_end;
69 : : };
70 : :
71 : : struct ice_buff_seg_simple_data {
72 : : __le16 type;
73 : : __le32 addr;
74 : : __le16 len;
75 : : __le16 seg_end;
76 : : };
77 : :
78 : : struct ice_buff_seg_series {
79 : : struct ice_buff_seg_header header;
80 : : uint16_t offset_delta;
81 : : uint16_t offset[2];
82 : : };
83 : :
84 : : struct ice_buff_seg_series_data {
85 : : __le16 type;
86 : : __le32 begin_addr;
87 : : __le16 len;
88 : : __le32 end_addr;
89 : : __le16 last_len;
90 : : __le16 offset_delta;
91 : : __le16 seg_end;
92 : : uint8_t padding;
93 : : };
94 : :
95 : : struct ice_buff_seg_series_with_sub {
96 : : struct ice_buff_seg_header header;
97 : : uint16_t sub_block_num;
98 : : };
99 : :
100 : : struct ice_buff_seg_series_with_sub_data {
101 : : __le16 type;
102 : : __le32 begin_addr;
103 : : __le16 len;
104 : : __le32 end_addr;
105 : : __le16 last_len;
106 : : __le16 sblk_size;
107 : : };
108 : :
109 : :
110 : : static const
111 : : uint16_t ice_buff_seg_header_size = sizeof(struct ice_buff_seg_header);
112 : :
113 : : static void
114 : 0 : write_buffer_simple(uint8_t **buff)
115 : : {
116 : : uint16_t i;
117 : : /* ICE ddp package simple segment template */
118 : 0 : const struct ice_buff_seg_simple_data buff_data[] = {
119 : : {0x0001, 0x00000, 0x0030, 0x0000},
120 : : {0x000a, 0x01000, 0x0810, 0x0800},
121 : : {0x000b, 0x02000, 0x00d8, 0x0000},
122 : : {0x000d, 0x06000, 0x0810, 0x0400},
123 : : {0x000f, 0x09000, 0x0110, 0x0100},
124 : : {0x0011, 0x17000, 0x001d, 0x0000},
125 : : {0x0012, 0x18000, 0x0014, 0x0000},
126 : : {0x0014, 0x19000, 0x0810, 0x0800},
127 : : {0x0015, 0x1a000, 0x00d8, 0x0000},
128 : : {0x0017, 0x1e000, 0x0810, 0x0400},
129 : : {0x0019, 0x21000, 0x0090, 0x0080},
130 : : {0x001b, 0x27000, 0x001d, 0x0000},
131 : : {0x001c, 0x28000, 0x0014, 0x0000},
132 : : {0x001e, 0x29000, 0x0810, 0x0800},
133 : : {0x001f, 0x2a000, 0x00d8, 0x0000},
134 : : {0x0021, 0x2e000, 0x0810, 0x0400},
135 : : {0x0023, 0x31000, 0x0090, 0x0080},
136 : : {0x0025, 0x36000, 0x001d, 0x0000},
137 : : {0x0026, 0x37000, 0x0014, 0x0000},
138 : : {0x0028, 0x38000, 0x0810, 0x0800},
139 : : {0x0029, 0x39000, 0x00d8, 0x0000},
140 : : {0x002b, 0x3d000, 0x0810, 0x0400},
141 : : {0x002d, 0x40000, 0x0090, 0x0080},
142 : : {0x002f, 0x45000, 0x001d, 0x0000},
143 : : {0x0030, 0x46000, 0x0014, 0x0000},
144 : : {0x0035, 0x57000, 0x0010, 0x0000},
145 : : {0x003a, 0x67000, 0x0190, 0x0010},
146 : : {0x003b, 0x68000, 0x0810, 0x0800},
147 : : {0x003f, 0x79000, 0x0010, 0x0000},
148 : : {0x0044, 0x89000, 0x0190, 0x0010},
149 : : {0x0045, 0x8a000, 0x0810, 0x0800},
150 : : {0x0046, 0x8b000, 0x001c, 0x0000},
151 : : {0x0047, 0x8c000, 0x001c, 0x0000},
152 : : {0x0048, 0x8d000, 0x0410, 0x0080},
153 : : {0x0049, 0x8e000, 0x0410, 0x0080},
154 : : {0x004a, 0x8f000, 0x0028, 0x0006},
155 : : {0x004b, 0x90000, 0x0028, 0x0006},
156 : : {0x004c, 0x91000, 0x0890, 0x0080},
157 : : {0x004d, 0x92000, 0x0890, 0x0080},
158 : : {0x004e, 0x93000, 0x0350, 0x0040},
159 : : {0x004f, 0x94000, 0x0350, 0x0040},
160 : : {0x0050, 0x95000, 0x0810, 0x0800},
161 : : {0x0051, 0x96000, 0x00d8, 0x0000},
162 : : {0x0053, 0x9a000, 0x0810, 0x0400},
163 : : {0x0055, 0x9c000, 0x0030, 0x0020},
164 : : {0x0057, 0x9f000, 0x001d, 0x0000},
165 : : {0x0058, 0xa0000, 0x0014, 0x0000},
166 : : {0x005a, 0xa1000, 0x0024, 0x0000},
167 : : {0x005b, 0xa2000, 0x0024, 0x0000},
168 : : {0x005d, 0xa4000, 0x0810, 0x0100},
169 : : {0x020d, 0xa8000, 0x0414, 0x0400},
170 : : {0x020e, 0xa9000, 0x0214, 0x0200},
171 : : {0x020f, 0xaa000, 0x0114, 0x0100},
172 : : {0x0210, 0xab000, 0x0114, 0x0100},
173 : : {0x0217, 0xaf000, 0x0414, 0x0400},
174 : : {0x0218, 0xb0000, 0x0214, 0x0200},
175 : : {0x0219, 0xb1000, 0x0094, 0x0080},
176 : : {0x021a, 0xb2000, 0x0094, 0x0080},
177 : : {0x0221, 0xb6000, 0x0414, 0x0400},
178 : : {0x0222, 0xb7000, 0x0214, 0x0200},
179 : : {0x0223, 0xb8000, 0x0094, 0x0080},
180 : : {0x0224, 0xb9000, 0x0094, 0x0080},
181 : : {0x022b, 0xbd000, 0x0414, 0x0400},
182 : : {0x022c, 0xbe000, 0x0214, 0x0200},
183 : : {0x022d, 0xbf000, 0x0094, 0x0080},
184 : : {0x022e, 0xc0000, 0x0094, 0x0080},
185 : : {0x0238, 0xc1000, 0x0114, 0x0100},
186 : : {0x0253, 0xc5000, 0x0414, 0x0400},
187 : : {0x0254, 0xc6000, 0x0054, 0x0040},
188 : : {0x0255, 0xc7000, 0x0034, 0x0020},
189 : : {0x0256, 0xc8000, 0x0034, 0x0020},
190 : : };
191 : :
192 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
193 : 0 : const struct ice_buff_seg_simple_data *seg = &buff_data[i];
194 : : struct ice_buff_seg_simple buff_seg;
195 : 0 : uint8_t *buffer = &(*buff)[seg->addr];
196 : :
197 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
198 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
199 : 0 : buff_seg.header.length = seg->len;
200 : 0 : buff_seg.header.type = seg->type;
201 : 0 : buff_seg.header.reserve = 0x0;
202 : 0 : buff_seg.header.header_len =
203 : : sizeof(struct ice_buff_seg_header);
204 : 0 : buff_seg.header.data_size =
205 : 0 : buff_seg.header.length - buff_seg.header.header_len;
206 : 0 : buff_seg.seg_end = seg->seg_end;
207 : :
208 : 0 : memset(buffer, 0x00, buff_seg.header.length);
209 : : memcpy(buffer, &buff_seg, sizeof(struct ice_buff_seg_simple));
210 : : }
211 : 0 : }
212 : :
213 : : static void
214 : 0 : write_buffer_block(uint8_t **buff)
215 : : {
216 : : uint16_t i;
217 : : /* ICE ddp package multiple segments template 1 */
218 : 0 : const struct ice_buff_seg_series_data buff_data[] = {
219 : : {0x000c, 0x03000, 0x1000, 0x05000, 0x0030, 0x0ff0, 0x0020, 0},
220 : : {0x0010, 0x0a000, 0x0fd0, 0x16000, 0x0310, 0x0015, 0x0004, 0},
221 : : {0x0016, 0x1b000, 0x1000, 0x1d000, 0x0030, 0x0ff0, 0x0020, 0},
222 : : {0x001a, 0x22000, 0x0f90, 0x26000, 0x0210, 0x001f, 0x0004, 0},
223 : : {0x0020, 0x2b000, 0x1000, 0x2d000, 0x0030, 0x0ff0, 0x0020, 0},
224 : : {0x0024, 0x32000, 0x0fd0, 0x35000, 0x00d0, 0x002a, 0x0002, 0},
225 : : {0x002a, 0x3a000, 0x1000, 0x3c000, 0x0030, 0x0ff0, 0x0020, 0},
226 : : {0x002e, 0x41000, 0x0fd0, 0x44000, 0x00d0, 0x002a, 0x0002, 0},
227 : : {0x0032, 0x47000, 0x1000, 0x4f000, 0x0090, 0x00ff, 0x0008, 0},
228 : : {0x0033, 0x50000, 0x1000, 0x53000, 0x0040, 0x0154, 0x0004, 0},
229 : : {0x0034, 0x54000, 0x1000, 0x56000, 0x0430, 0x0055, 0x0016, 0},
230 : : {0x0039, 0x65000, 0x1000, 0x66000, 0x0220, 0x00aa, 0x0016, 0},
231 : : {0x003c, 0x69000, 0x1000, 0x71000, 0x0090, 0x00ff, 0x0008, 0},
232 : : {0x003d, 0x72000, 0x1000, 0x75000, 0x0040, 0x0154, 0x0004, 0},
233 : : {0x003e, 0x76000, 0x1000, 0x78000, 0x0430, 0x0055, 0x0016, 0},
234 : : {0x0043, 0x87000, 0x1000, 0x88000, 0x0220, 0x00aa, 0x0016, 0},
235 : : {0x0052, 0x97000, 0x1000, 0x99000, 0x0030, 0x0ff0, 0x0020, 0},
236 : : {0x0056, 0x9d000, 0x0f90, 0x9e000, 0x0090, 0x001f, 0x0001, 0},
237 : : {0x020c, 0xa5000, 0x1000, 0xa7000, 0x003c, 0x0fec, 0x0028, 1},
238 : : {0x0216, 0xac000, 0x1000, 0xae000, 0x003c, 0x0fec, 0x0028, 1},
239 : : {0x0220, 0xb3000, 0x1000, 0xb5000, 0x003c, 0x0fec, 0x0028, 1},
240 : : {0x022a, 0xba000, 0x1000, 0xbc000, 0x003c, 0x0fec, 0x0028, 1},
241 : : {0x0252, 0xc2000, 0x1000, 0xc4000, 0x003c, 0x0fec, 0x0028, 1},
242 : : };
243 : :
244 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
245 : 0 : const struct ice_buff_seg_series_data *seg = &buff_data[i];
246 : : struct ice_buff_seg_series buff_seg;
247 : : const uint16_t buff_seg_size =
248 : : sizeof(struct ice_buff_seg_series);
249 : 0 : uint32_t addr = seg->begin_addr;
250 : : __le16 last_offset = 0;
251 : :
252 [ # # ]: 0 : for (; addr <= seg->end_addr; addr += ICE_PKG_BUF_SIZE) {
253 [ # # ]: 0 : uint8_t *buffer = &(*buff)[addr];
254 : :
255 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
256 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
257 [ # # ]: 0 : buff_seg.header.length = addr == seg->end_addr ?
258 : : seg->last_len : seg->len;
259 : 0 : buff_seg.header.type = seg->type;
260 : 0 : buff_seg.header.reserve = 0x0;
261 : 0 : buff_seg.header.header_len = ice_buff_seg_header_size;
262 : 0 : buff_seg.header.data_size = buff_seg.header.length -
263 : : buff_seg.header.header_len;
264 [ # # ]: 0 : buff_seg.offset_delta = addr < seg->end_addr ?
265 : : seg->offset_delta : seg->seg_end;
266 : 0 : buff_seg.offset[!seg->padding] = 0x0;
267 : 0 : buff_seg.offset[seg->padding] = last_offset;
268 : :
269 : 0 : memset(buffer, 0x00, buff_seg.header.length);
270 : : memcpy(buffer, &buff_seg, buff_seg_size);
271 : :
272 : 0 : last_offset += seg->offset_delta;
273 : : }
274 : : }
275 : 0 : }
276 : :
277 : : static void
278 : 0 : write_buffer_block2(uint8_t **buff)
279 : : {
280 : : uint16_t i;
281 : : /* ICE ddp package multiple segments template 2 */
282 : 0 : struct ice_buff_seg_series_with_sub_data buff_data[] = {
283 : : {0x000e, 0x07000, 0x1000, 0x08000, 0x0a1c, 13},
284 : : {0x0018, 0x1f000, 0x1000, 0x20000, 0x0a1c, 13},
285 : : {0x0022, 0x2f000, 0x1000, 0x30000, 0x0a1c, 13},
286 : : {0x002c, 0x3e000, 0x1000, 0x3f000, 0x0a1c, 13},
287 : : {0x0037, 0x58000, 0x1000, 0x5e000, 0x0070, 24},
288 : : {0x0038, 0x5f000, 0x0fe0, 0x64000, 0x0900, 88},
289 : : {0x0041, 0x7a000, 0x1000, 0x80000, 0x0070, 24},
290 : : {0x0042, 0x81000, 0x0fe0, 0x86000, 0x0900, 88},
291 : : {0x0054, 0x9b000, 0x034e, 0x9b000, 0x034e, 13},
292 : : {0x005c, 0xa3000, 0x0a10, 0xa3000, 0x0a10, 40},
293 : : };
294 : :
295 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
296 : 0 : struct ice_buff_seg_series_with_sub_data *seg = &buff_data[i];
297 : : struct ice_buff_seg_series_with_sub buff_seg;
298 : : const uint16_t buff_seg_size =
299 : : sizeof(struct ice_buff_seg_series_with_sub);
300 : : uint32_t addr;
301 : : uint16_t last_idx = 0;
302 : :
303 : 0 : for (addr = seg->begin_addr;
304 [ # # ]: 0 : addr <= seg->end_addr; addr += ICE_PKG_BUF_SIZE) {
305 [ # # ]: 0 : uint8_t *buffer = &(*buff)[addr];
306 : : uint16_t total_sblk_size;
307 : : uint16_t idx = 0;
308 : : uint32_t pos = buff_seg_size;
309 : :
310 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
311 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
312 : 0 : buff_seg.header.length =
313 [ # # ]: 0 : addr == seg->end_addr ?
314 : : seg->last_len : seg->len;
315 : 0 : buff_seg.header.type = seg->type;
316 : 0 : buff_seg.header.reserve = 0x0;
317 : 0 : buff_seg.header.header_len = ice_buff_seg_header_size;
318 : 0 : buff_seg.header.data_size = buff_seg.header.length -
319 : : buff_seg.header.header_len;
320 : :
321 : 0 : total_sblk_size = buff_seg.header.data_size
322 : : - sizeof(buff_seg.sub_block_num);
323 : 0 : buff_seg.sub_block_num =
324 : 0 : total_sblk_size / seg->sblk_size;
325 : :
326 [ # # ]: 0 : memset(buffer, 0x00, buff_seg.header.length);
327 : : memcpy(buffer, &buff_seg, buff_seg_size);
328 : :
329 : : /* padding if needed */
330 [ # # ]: 0 : if (total_sblk_size % seg->sblk_size)
331 : : pos += sizeof(uint16_t);
332 : :
333 : 0 : for (idx = last_idx;
334 [ # # ]: 0 : idx < last_idx + buff_seg.sub_block_num; idx++) {
335 : 0 : memcpy(buffer + pos, &idx, sizeof(uint16_t));
336 : 0 : pos += seg->sblk_size;
337 : : }
338 : :
339 : : last_idx = idx;
340 : : }
341 : : }
342 : 0 : }
343 : :
344 : : static int
345 : 0 : ice_dump_pkg(struct rte_eth_dev *dev, uint8_t **buff, uint32_t *size)
346 : : {
347 : : struct ice_hw *hw;
348 : : struct ice_buf pkg_buff;
349 : : uint8_t *next_buff;
350 : : uint16_t i = 0;
351 : : uint16_t count;
352 : : struct ice_package_header *cache;
353 : : uint32_t cache_size;
354 : :
355 : 0 : write_buffer_simple(buff);
356 : 0 : write_buffer_block(buff);
357 : 0 : write_buffer_block2(buff);
358 : :
359 : 0 : hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
360 : :
361 [ # # ]: 0 : if (*size % ICE_PKG_BUF_SIZE)
362 : : return -EINVAL;
363 : :
364 : 0 : count = *size / ICE_PKG_BUF_SIZE;
365 [ # # ]: 0 : for (i = 0; i < count; i++) {
366 : 0 : next_buff = (uint8_t *)(*buff) + i * ICE_PKG_BUF_SIZE;
367 : : memcpy(pkg_buff.buf, next_buff, ICE_PKG_BUF_SIZE);
368 [ # # ]: 0 : if (ice_aq_upload_section(hw,
369 : : (struct ice_buf_hdr *)&pkg_buff.buf[0],
370 : : ICE_PKG_BUF_SIZE,
371 : : NULL))
372 : : return -EINVAL;
373 : : memcpy(next_buff, pkg_buff.buf, ICE_PKG_BUF_SIZE);
374 : : }
375 : :
376 : 0 : cache_size = sizeof(struct ice_package_header) + *size;
377 : 0 : cache = (struct ice_package_header *)malloc(cache_size);
378 [ # # ]: 0 : if (!cache)
379 : : return -ENOSPC;
380 : :
381 : 0 : cache->header.h1 = ICE_PKG_HDR_HEADR_PART1;
382 : 0 : cache->header.h2 = ICE_PKG_HDR_HEADR_PART2;
383 : 0 : cache->gm_seg_offset = ICE_PKG_HDR_GM_SEG_OFFSET;
384 : 0 : cache->ice_seg_offset = ICE_PKG_HDR_ICE_SEG_OFFSET;
385 : 0 : cache->gm_seg.hdr.seg_type = ICE_PKG_GM_SEG_TYPE;
386 : 0 : cache->gm_seg.hdr.seg_format_ver.major = ICE_PKG_MAJOR_VERSION;
387 : 0 : cache->gm_seg.hdr.seg_size = ICE_PKG_GM_SEG_SIZE;
388 : 0 : ICE_PKG_COPY_STRING(cache->gm_seg.hdr.seg_id, "Global Metadata");
389 : :
390 : 0 : cache->gm_seg.pkg_ver.major = ICE_PKG_MAJOR_VERSION;
391 : 0 : cache->gm_seg.rsvd = 1;
392 : 0 : ICE_PKG_COPY_STRING(cache->gm_seg.pkg_name, "DEFAULT");
393 : :
394 : 0 : cache->ice_seg.hdr.seg_type = ICE_PKG_ICE_SEG_TYPE;
395 : 0 : cache->ice_seg.hdr.seg_format_ver.major = ICE_PKG_MAJOR_VERSION;
396 : 0 : cache->ice_seg.hdr.seg_size = ICE_PKG_ICE_SEG_SIZE_BASE + *size;
397 : 0 : cache->ice_seg.devid_count = 0;
398 : 0 : cache->ice_seg.nvm_ver.major = 0;
399 : 0 : ICE_PKG_COPY_STRING(cache->ice_seg.hdr.seg_id, "CPK Configuration Data");
400 : :
401 : 0 : cache->buff_count = count;
402 : :
403 : : next_buff = (uint8_t *)cache;
404 : 0 : next_buff += sizeof(struct ice_package_header);
405 : 0 : memcpy(next_buff, *buff, *size);
406 : :
407 : 0 : free(*buff);
408 : 0 : *buff = (uint8_t *)cache;
409 : 0 : *size = cache_size;
410 : :
411 : 0 : return 0;
412 : : }
413 : :
414 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_ice_dump_package, 19.11)
415 : 0 : int rte_pmd_ice_dump_package(uint16_t port, uint8_t **buff, uint32_t *size)
416 : : {
417 : : struct rte_eth_dev *dev;
418 : :
419 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
420 : :
421 : 0 : dev = &rte_eth_devices[port];
422 [ # # ]: 0 : if (!is_ice_supported(dev))
423 : : return -ENOTSUP;
424 : :
425 : 0 : return ice_dump_pkg(dev, buff, size);
426 : : }
427 : :
428 : : static uint16_t
429 : 0 : covert_byte_to_hex(uint8_t **outbuf, const uint8_t *inbuf, uint32_t inbuf_size)
430 : : {
431 : : uint32_t i;
432 : 0 : uint8_t *buffer = *outbuf;
433 [ # # ]: 0 : for (i = 0; i < inbuf_size; ++i)
434 : 0 : sprintf((char *)(buffer + i * 2), "%02X", inbuf[i]);
435 : :
436 : 0 : return inbuf_size * 2;
437 : : }
438 : :
439 : : static int
440 : 0 : ice_dump_switch(struct rte_eth_dev *dev, uint8_t **buff2, uint32_t *size)
441 : : {
442 : : struct ice_hw *hw;
443 : : struct ice_sq_cd *cd = NULL;
444 : : int i = 0;
445 : 0 : uint16_t tbl_id = 0;
446 : 0 : uint16_t tbl_idx = 0;
447 : 0 : uint8_t *buffer = *buff2;
448 : :
449 : 0 : hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
450 : :
451 : : /* table index string format: "0000:" */
452 : : #define TBL_IDX_STR_SIZE 7
453 [ # # ]: 0 : for (i = 0; i < ICE_BLK_MAX_COUNT; i++) {
454 : : int res;
455 : : uint16_t buff_size;
456 : : uint8_t *buff;
457 : : uint32_t offset = 0;
458 : :
459 : 0 : buff = malloc(ICE_PKG_BUF_SIZE);
460 [ # # ]: 0 : if (!buff)
461 : 0 : return ICE_ERR_NO_MEMORY;
462 : :
463 [ # # ]: 0 : if (tbl_idx == 0) {
464 : : char tbl_idx_str[TBL_IDX_STR_SIZE];
465 : : memset(tbl_idx_str, 0, sizeof(tbl_idx_str));
466 : 0 : sprintf(tbl_idx_str, "%d:", tbl_id);
467 : 0 : memcpy(buffer, tbl_idx_str, strlen(tbl_idx_str));
468 : 0 : offset = strlen(tbl_idx_str);
469 : 0 : buffer += offset;
470 : : }
471 : :
472 : 0 : res = ice_aq_get_internal_data(hw,
473 : : ICE_AQC_DBG_DUMP_CLUSTER_ID_SW_E810,
474 : : tbl_id, tbl_idx, buff,
475 : : ICE_PKG_BUF_SIZE,
476 : : &buff_size, &tbl_id, &tbl_idx, NULL, cd);
477 : :
478 [ # # ]: 0 : if (res) {
479 : 0 : free(buff);
480 : 0 : return res;
481 : : }
482 : :
483 : 0 : offset = covert_byte_to_hex(&buffer, buff, buff_size);
484 : 0 : buffer += offset;
485 : :
486 : 0 : free(buff);
487 : :
488 [ # # ]: 0 : if (tbl_idx == 0xffff) {
489 : 0 : tbl_idx = 0;
490 : : memset(buffer, '\n', sizeof(char));
491 : 0 : buffer++;
492 : : offset = 0;
493 : : }
494 : :
495 [ # # ]: 0 : if (tbl_id == 0xff)
496 : : break;
497 : : }
498 : :
499 : 0 : *size = buffer - *buff2;
500 : 0 : return 0;
501 : : }
502 : :
503 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_ice_dump_switch, 22.11)
504 : 0 : int rte_pmd_ice_dump_switch(uint16_t port, uint8_t **buff, uint32_t *size)
505 : : {
506 : : struct rte_eth_dev *dev;
507 : :
508 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
509 : :
510 : 0 : dev = &rte_eth_devices[port];
511 [ # # ]: 0 : if (!is_ice_supported(dev))
512 : : return -ENOTSUP;
513 : :
514 : 0 : return ice_dump_switch(dev, buff, size);
515 : : }
516 : :
517 : 0 : static void print_rl_profile(const struct ice_aqc_rl_profile_elem *prof,
518 : : FILE *stream)
519 : : {
520 : : fprintf(stream, "\t\t\t\t\t<td>\n");
521 : : fprintf(stream, "\t\t\t\t\t\t<table>\n");
522 : :
523 : : fprintf(stream, "\t\t\t\t\t\t\t<tr>\n");
524 : : fprintf(stream, "\t\t\t\t\t\t\t\t<td>id</td>\n");
525 : 0 : fprintf(stream, "\t\t\t\t\t\t\t\t<td>%d</td>\n", prof->profile_id);
526 : : fprintf(stream, "\t\t\t\t\t\t\t</tr>\n");
527 : :
528 : : fprintf(stream, "\t\t\t\t\t\t\t<tr>\n");
529 : : fprintf(stream, "\t\t\t\t\t\t\t\t<td>max burst size</td>\n");
530 : 0 : fprintf(stream, "\t\t\t\t\t\t\t\t<td>%d</td>\n", prof->max_burst_size);
531 : : fprintf(stream, "\t\t\t\t\t\t\t</tr>\n");
532 : :
533 : : fprintf(stream, "\t\t\t\t\t\t\t<tr>\n");
534 : : fprintf(stream, "\t\t\t\t\t\t\t\t<td>rate limit multiply</td>\n");
535 : 0 : fprintf(stream, "\t\t\t\t\t\t\t\t<td>%d</td>\n", prof->rl_multiply);
536 : : fprintf(stream, "\t\t\t\t\t\t\t</tr>\n");
537 : :
538 : : fprintf(stream, "\t\t\t\t\t\t\t<tr>\n");
539 : : fprintf(stream, "\t\t\t\t\t\t\t\t<td>wake up calculation</td>\n");
540 : 0 : fprintf(stream, "\t\t\t\t\t\t\t\t<td>%d</td>\n", prof->wake_up_calc);
541 : : fprintf(stream, "\t\t\t\t\t\t\t</tr>\n");
542 : :
543 : : fprintf(stream, "\t\t\t\t\t\t\t<tr>\n");
544 : : fprintf(stream, "\t\t\t\t\t\t\t\t<td>rate limit encode</td>\n");
545 : 0 : fprintf(stream, "\t\t\t\t\t\t\t\t<td>%d</td>\n", prof->rl_encode);
546 : : fprintf(stream, "\t\t\t\t\t\t\t</tr>\n");
547 : :
548 : : fprintf(stream, "\t\t\t\t\t\t</table>\n");
549 : : fprintf(stream, "\t\t\t\t\t</td>\n");
550 : 0 : }
551 : :
552 : : static const char *
553 : : get_elem_type(u8 type)
554 : : {
555 : : static const char * const ice_sched_node_types[] = {
556 : : "Undefined", "Root", "TC", "SE Generic", "SW Entry", "Leaf"
557 : : };
558 : 0 : if (type < RTE_DIM(ice_sched_node_types))
559 : 0 : return ice_sched_node_types[type];
560 : : return "*UNKNOWN*";
561 : : }
562 : :
563 : : static
564 : 0 : void print_valid_sections(FILE *stream, u8 vs)
565 : : {
566 [ # # ]: 0 : if ((vs & 0x1) != 0)
567 : : fprintf(stream, "generic ");
568 [ # # ]: 0 : if ((vs & 0x2) != 0)
569 : : fprintf(stream, "cir ");
570 [ # # ]: 0 : if ((vs & 0x4) != 0)
571 : : fprintf(stream, "eir ");
572 [ # # ]: 0 : if ((vs & 0x8) != 0)
573 : : fprintf(stream, "shared ");
574 : 0 : }
575 : :
576 : : static
577 : 0 : void print_scheduling_mode(FILE *stream, bool flag)
578 : : {
579 [ # # ]: 0 : if (flag)
580 : : fprintf(stream, "pps");
581 : : else
582 : : fprintf(stream, "bps");
583 : 0 : }
584 : :
585 : : static
586 : 0 : void print_priority_mode(FILE *stream, bool flag)
587 : : {
588 [ # # ]: 0 : if (flag)
589 : : fprintf(stream, "single priority node");
590 : : else
591 : : fprintf(stream, "wfq");
592 : 0 : }
593 : :
594 : : static
595 : 0 : void print_node(const struct rte_eth_dev_data *ethdata,
596 : : const struct ice_aqc_txsched_elem_data *data,
597 : : const struct ice_aqc_rl_profile_elem *cir_prof,
598 : : const struct ice_aqc_rl_profile_elem *eir_prof,
599 : : const struct ice_aqc_rl_profile_elem *shared_prof,
600 : : bool detail, FILE *stream)
601 : : {
602 : 0 : fprintf(stream, "\tNODE_%d [\n", data->node_teid);
603 : : fprintf(stream, "\t\tlabel=<\n");
604 : :
605 : : fprintf(stream, "\t\t\t<table>\n");
606 : :
607 : 0 : fprintf(stream, "\t\t\t\t<tr><td>teid</td><td>%d</td></tr>\n", data->node_teid);
608 : 0 : fprintf(stream, "\t\t\t\t<tr><td>type</td><td>%s</td></tr>\n",
609 [ # # ]: 0 : get_elem_type(data->data.elem_type));
610 [ # # ]: 0 : if (data->data.elem_type == ICE_AQC_ELEM_TYPE_LEAF) {
611 [ # # ]: 0 : for (uint16_t i = 0; i < ethdata->nb_tx_queues; i++) {
612 : 0 : struct ci_tx_queue *q = ethdata->tx_queues[i];
613 [ # # ]: 0 : if (q->q_teid == data->node_teid) {
614 : 0 : fprintf(stream, "\t\t\t\t<tr><td>TXQ</td><td>%u</td></tr>\n", i);
615 : : break;
616 : : }
617 : : }
618 : : }
619 : :
620 [ # # ]: 0 : if (!detail)
621 : 0 : goto brief;
622 : :
623 : : fprintf(stream, "\t\t\t\t<tr>\n");
624 : : fprintf(stream, "\t\t\t\t\t<td> valid sections </td>\n");
625 : : fprintf(stream, "\t\t\t\t\t<td>");
626 : 0 : print_valid_sections(stream, data->data.valid_sections);
627 : : fprintf(stream, "</td>\n");
628 : : fprintf(stream, "\t\t\t\t</tr>\n");
629 : :
630 : : fprintf(stream, "\t\t\t\t<tr>\n");
631 : : fprintf(stream, "\t\t\t\t\t<td> scheduling mode </td>\n");
632 : : fprintf(stream, "\t\t\t\t\t<td>");
633 : 0 : print_scheduling_mode(stream, (data->data.generic & 0x1) != 0);
634 : : fprintf(stream, "</td>\n");
635 : : fprintf(stream, "\t\t\t\t</tr>\n");
636 : :
637 : : fprintf(stream, "\t\t\t\t<tr>\n");
638 : : fprintf(stream, "\t\t\t\t\t<td> priority </td>\n");
639 : 0 : fprintf(stream, "\t\t\t\t\t<td> %d </td>\n", (data->data.generic >> 1) & 0x7);
640 : : fprintf(stream, "\t\t\t\t</tr>\n");
641 : :
642 : : fprintf(stream, "\t\t\t\t<tr>\n");
643 : : fprintf(stream, "\t\t\t\t\t<td> priority mode</td>\n");
644 : : fprintf(stream, "\t\t\t\t\t<td>");
645 : 0 : print_priority_mode(stream, ((data->data.generic >> 4) & 0x1) == 0);
646 : : fprintf(stream, "</td>\n");
647 : : fprintf(stream, "\t\t\t\t</tr>\n");
648 : :
649 : : fprintf(stream, "\t\t\t\t<tr>\n");
650 : : fprintf(stream, "\t\t\t\t\t<td> adjustment value </td>\n");
651 : 0 : fprintf(stream, "\t\t\t\t\t<td> %d </td>\n", (data->data.generic >> 5) & 0x3);
652 : : fprintf(stream, "\t\t\t\t</tr>\n");
653 : :
654 : : fprintf(stream, "\t\t\t\t<tr>\n");
655 : : fprintf(stream, "\t\t\t\t\t<td> suspended </td>\n");
656 : 0 : fprintf(stream, "\t\t\t\t\t<td> %d </td>\n", data->data.flags & 0x1);
657 : : fprintf(stream, "\t\t\t\t</tr>\n");
658 : :
659 : : fprintf(stream, "\t\t\t\t<tr>\n");
660 : : fprintf(stream, "\t\t\t\t\t<td> cir bw profile </td>\n");
661 [ # # ]: 0 : if (cir_prof == NULL)
662 : : fprintf(stream, "\t\t\t\t\t<td> default </td>\n");
663 : : else
664 : 0 : print_rl_profile(cir_prof, stream);
665 : : fprintf(stream, "\t\t\t\t</tr>\n");
666 : :
667 : : fprintf(stream, "\t\t\t\t<tr>\n");
668 : : fprintf(stream, "\t\t\t\t\t<td> cir bw weight </td>\n");
669 : 0 : fprintf(stream, "\t\t\t\t\t<td> %d </td>\n", data->data.cir_bw.bw_alloc);
670 : : fprintf(stream, "\t\t\t\t</tr>\n");
671 : :
672 : : fprintf(stream, "\t\t\t\t<tr>\n");
673 : : fprintf(stream, "\t\t\t\t\t<td> eir bw profile </td>\n");
674 [ # # ]: 0 : if (eir_prof == NULL)
675 : : fprintf(stream, "\t\t\t\t\t<td> default </td>\n");
676 : : else
677 : 0 : print_rl_profile(eir_prof, stream);
678 : : fprintf(stream, "\t\t\t\t</tr>\n");
679 : :
680 : : fprintf(stream, "\t\t\t\t<tr>\n");
681 : : fprintf(stream, "\t\t\t\t\t<td> eir bw weight </td>\n");
682 : 0 : fprintf(stream, "\t\t\t\t\t<td> %d </td>\n", data->data.eir_bw.bw_alloc);
683 : : fprintf(stream, "\t\t\t\t</tr>\n");
684 : :
685 : : fprintf(stream, "\t\t\t\t<tr>\n");
686 : : fprintf(stream, "\t\t\t\t\t<td> shared rl profile </td>\n");
687 [ # # ]: 0 : if (shared_prof == NULL)
688 : : fprintf(stream, "\t\t\t\t\t<td> default </td>\n");
689 : : else
690 : 0 : print_rl_profile(shared_prof, stream);
691 : : fprintf(stream, "\t\t\t\t</tr>\n");
692 : :
693 : 0 : brief:
694 : : fprintf(stream, "\t\t\t</table>\n");
695 : :
696 : : fprintf(stream, "\t\t>\n");
697 : : fprintf(stream, "\t\tshape=plain\n");
698 : : fprintf(stream, "\t]\n");
699 : :
700 : 0 : }
701 : :
702 : : static
703 : 0 : int query_rl_profile(struct ice_hw *hw,
704 : : uint8_t level, uint8_t flags, uint16_t profile_id,
705 : : struct ice_aqc_rl_profile_elem *data)
706 : : {
707 : : int ice_status;
708 : :
709 : 0 : data->level = level;
710 : 0 : data->flags = flags;
711 : 0 : data->profile_id = profile_id;
712 : :
713 : 0 : ice_status = ice_aq_query_rl_profile(hw, 1, data,
714 : : sizeof(struct ice_aqc_rl_profile_elem), NULL);
715 : :
716 [ # # ]: 0 : if (ice_status != ICE_SUCCESS) {
717 : 0 : PMD_DRV_LOG(ERR, "Failed to query rl profile.");
718 : 0 : return -EINVAL;
719 : : }
720 : :
721 : : return 0;
722 : : }
723 : :
724 : : static int
725 : 0 : query_node(struct ice_hw *hw, struct rte_eth_dev_data *ethdata,
726 : : struct ice_sched_node *node, bool detail, FILE *stream)
727 : : {
728 : 0 : struct ice_aqc_txsched_elem_data *data = &node->info;
729 : : struct ice_aqc_rl_profile_elem cir_prof;
730 : : struct ice_aqc_rl_profile_elem eir_prof;
731 : : struct ice_aqc_rl_profile_elem shared_prof;
732 : : struct ice_aqc_rl_profile_elem *cp = NULL;
733 : : struct ice_aqc_rl_profile_elem *ep = NULL;
734 : : struct ice_aqc_rl_profile_elem *sp = NULL;
735 : 0 : u8 level = node->tx_sched_layer;
736 : : int ret;
737 : :
738 [ # # ]: 0 : if (data->data.cir_bw.bw_profile_idx != 0) {
739 : 0 : ret = query_rl_profile(hw, level, 0, data->data.cir_bw.bw_profile_idx, &cir_prof);
740 : :
741 [ # # ]: 0 : if (ret)
742 : : return ret;
743 : : cp = &cir_prof;
744 : : }
745 : :
746 [ # # ]: 0 : if (data->data.eir_bw.bw_profile_idx != 0) {
747 : 0 : ret = query_rl_profile(hw, level, 1, data->data.eir_bw.bw_profile_idx, &eir_prof);
748 : :
749 [ # # ]: 0 : if (ret)
750 : : return ret;
751 : : ep = &eir_prof;
752 : : }
753 : :
754 [ # # ]: 0 : if (data->data.srl_id != 0) {
755 : 0 : ret = query_rl_profile(hw, level, 2, data->data.srl_id, &shared_prof);
756 : :
757 [ # # ]: 0 : if (ret)
758 : : return ret;
759 : : sp = &shared_prof;
760 : : }
761 : :
762 : 0 : print_node(ethdata, data, cp, ep, sp, detail, stream);
763 : :
764 : 0 : return 0;
765 : : }
766 : :
767 : : static int
768 : 0 : query_node_recursive(struct ice_hw *hw, struct rte_eth_dev_data *ethdata,
769 : : struct ice_sched_node *node, bool detail, FILE *stream)
770 : : {
771 : : bool close = false;
772 [ # # # # ]: 0 : if (node->parent != NULL && node->vsi_handle != node->parent->vsi_handle) {
773 : 0 : fprintf(stream, "subgraph cluster_%u {\n", node->vsi_handle);
774 : 0 : fprintf(stream, "\tlabel = \"VSI %u\";\n", node->vsi_handle);
775 : : close = true;
776 : : }
777 : :
778 : 0 : int ret = query_node(hw, ethdata, node, detail, stream);
779 [ # # ]: 0 : if (ret != 0)
780 : : return ret;
781 : :
782 [ # # ]: 0 : for (uint16_t i = 0; i < node->num_children; i++) {
783 : 0 : ret = query_node_recursive(hw, ethdata, node->children[i], detail, stream);
784 [ # # ]: 0 : if (ret != 0)
785 : 0 : return ret;
786 : : /* if we have a lot of nodes, skip a bunch in the middle */
787 [ # # # # ]: 0 : if (node->num_children > 16 && i == 2) {
788 : 0 : uint16_t inc = node->num_children - 5;
789 : 0 : fprintf(stream, "\tn%d_children [label=\"... +%d child nodes ...\"];\n",
790 : : node->info.node_teid, inc);
791 : 0 : fprintf(stream, "\tNODE_%d -> n%d_children;\n",
792 : : node->info.node_teid, node->info.node_teid);
793 : 0 : i += inc;
794 : : }
795 : : }
796 [ # # ]: 0 : if (close)
797 : : fprintf(stream, "}\n");
798 [ # # ]: 0 : if (node->info.parent_teid != 0xFFFFFFFF)
799 : 0 : fprintf(stream, "\tNODE_%d -> NODE_%d\n",
800 : : node->info.parent_teid, node->info.node_teid);
801 : :
802 : : return 0;
803 : : }
804 : :
805 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_ice_dump_txsched, 24.03)
806 : : int
807 : 0 : rte_pmd_ice_dump_txsched(uint16_t port, bool detail, FILE *stream)
808 : : {
809 : : struct rte_eth_dev *dev;
810 : : struct ice_hw *hw;
811 : :
812 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
813 : :
814 : 0 : dev = &rte_eth_devices[port];
815 [ # # ]: 0 : if (!is_ice_supported(dev))
816 : : return -ENOTSUP;
817 : :
818 : : dev = &rte_eth_devices[port];
819 : 0 : hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
820 : :
821 : : fprintf(stream, "digraph tx_sched {\n");
822 : 0 : query_node_recursive(hw, dev->data, hw->port_info->root, detail, stream);
823 : : fprintf(stream, "}\n");
824 : :
825 : 0 : return 0;
826 : : }
|