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