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 <rte_string_fns.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_tailq.h>
12 : :
13 : : #include "ice_ethdev.h"
14 : :
15 : : #define ICE_BLK_MAX_COUNT 512
16 : : #define ICE_BUFF_SEG_HEADER_FLAG 0x1
17 : : #define ICE_PKG_HDR_HEADR_PART1 1
18 : : #define ICE_PKG_HDR_HEADR_PART2 2
19 : : #define ICE_PKG_HDR_GM_SEG_OFFSET 16
20 : : #define ICE_PKG_HDR_ICE_SEG_OFFSET 100
21 : : #define ICE_PKG_GM_SEG_TYPE 1
22 : : #define ICE_PKG_MAJOR_VERSION 1
23 : : #define ICE_PKG_GM_SEG_SIZE 84
24 : : #define ICE_PKG_ICE_SEG_TYPE 0x10
25 : : #define ICE_PKG_ICE_SEG_SIZE_BASE 56
26 : : #define SPACE_CHAR 0x20
27 : :
28 : : #define ICE_PKG_COPY_STRING(dst, src) \
29 : : do {\
30 : : char *_dst = (dst); \
31 : : const char *_src = (src); \
32 : : memset(_dst, SPACE_CHAR, ICE_PKG_NAME_SIZE); \
33 : : strlcpy(_dst, _src, strlen(_dst)); \
34 : : } while (0)
35 : :
36 : : /* Package header */
37 : : struct ice_package_header {
38 : : struct __hdr {
39 : : uint32_t h1; /* header part 1 */
40 : : uint32_t h2; /* header part 2 */
41 : : } header;
42 : : uint32_t gm_seg_offset; /* Global Metadata segment: 16 */
43 : : uint32_t ice_seg_offset; /* ICE segment: 100 */
44 : : struct ice_global_metadata_seg gm_seg;
45 : : struct __ice_seg {
46 : : struct ice_generic_seg_hdr hdr;
47 : : uint32_t devid_count;
48 : : struct ice_pkg_ver nvm_ver;
49 : : } ice_seg;
50 : :
51 : : uint32_t buff_count;
52 : : };
53 : :
54 : : struct ice_buff_seg_header {
55 : : __le16 flag;
56 : : __le16 length;
57 : : __le16 type;
58 : : __le16 reserve; /* 0 */
59 : : __le16 header_len; /* 0x0C */
60 : : __le16 data_size; /* length - header_len */
61 : : };
62 : :
63 : : struct ice_buff_seg_simple {
64 : : struct ice_buff_seg_header header;
65 : : __le16 seg_end;
66 : : };
67 : :
68 : : struct ice_buff_seg_simple_data {
69 : : __le16 type;
70 : : __le32 addr;
71 : : __le16 len;
72 : : __le16 seg_end;
73 : : };
74 : :
75 : : struct ice_buff_seg_series {
76 : : struct ice_buff_seg_header header;
77 : : uint16_t offset_delta;
78 : : uint16_t offset[2];
79 : : };
80 : :
81 : : struct ice_buff_seg_series_data {
82 : : __le16 type;
83 : : __le32 begin_addr;
84 : : __le16 len;
85 : : __le32 end_addr;
86 : : __le16 last_len;
87 : : __le16 offset_delta;
88 : : __le16 seg_end;
89 : : uint8_t padding;
90 : : };
91 : :
92 : : struct ice_buff_seg_series_with_sub {
93 : : struct ice_buff_seg_header header;
94 : : uint16_t sub_block_num;
95 : : };
96 : :
97 : : struct ice_buff_seg_series_with_sub_data {
98 : : __le16 type;
99 : : __le32 begin_addr;
100 : : __le16 len;
101 : : __le32 end_addr;
102 : : __le16 last_len;
103 : : __le16 sblk_size;
104 : : };
105 : :
106 : :
107 : : static const
108 : : uint16_t ice_buff_seg_header_size = sizeof(struct ice_buff_seg_header);
109 : :
110 : : static void
111 : 0 : write_buffer_simple(uint8_t **buff)
112 : : {
113 : : uint16_t i;
114 : : /* ICE ddp package simple segment template */
115 : 0 : const struct ice_buff_seg_simple_data buff_data[] = {
116 : : {0x0001, 0x00000, 0x0030, 0x0000},
117 : : {0x000a, 0x01000, 0x0810, 0x0800},
118 : : {0x000b, 0x02000, 0x00d8, 0x0000},
119 : : {0x000d, 0x06000, 0x0810, 0x0400},
120 : : {0x000f, 0x09000, 0x0110, 0x0100},
121 : : {0x0011, 0x17000, 0x001d, 0x0000},
122 : : {0x0012, 0x18000, 0x0014, 0x0000},
123 : : {0x0014, 0x19000, 0x0810, 0x0800},
124 : : {0x0015, 0x1a000, 0x00d8, 0x0000},
125 : : {0x0017, 0x1e000, 0x0810, 0x0400},
126 : : {0x0019, 0x21000, 0x0090, 0x0080},
127 : : {0x001b, 0x27000, 0x001d, 0x0000},
128 : : {0x001c, 0x28000, 0x0014, 0x0000},
129 : : {0x001e, 0x29000, 0x0810, 0x0800},
130 : : {0x001f, 0x2a000, 0x00d8, 0x0000},
131 : : {0x0021, 0x2e000, 0x0810, 0x0400},
132 : : {0x0023, 0x31000, 0x0090, 0x0080},
133 : : {0x0025, 0x36000, 0x001d, 0x0000},
134 : : {0x0026, 0x37000, 0x0014, 0x0000},
135 : : {0x0028, 0x38000, 0x0810, 0x0800},
136 : : {0x0029, 0x39000, 0x00d8, 0x0000},
137 : : {0x002b, 0x3d000, 0x0810, 0x0400},
138 : : {0x002d, 0x40000, 0x0090, 0x0080},
139 : : {0x002f, 0x45000, 0x001d, 0x0000},
140 : : {0x0030, 0x46000, 0x0014, 0x0000},
141 : : {0x0035, 0x57000, 0x0010, 0x0000},
142 : : {0x003a, 0x67000, 0x0190, 0x0010},
143 : : {0x003b, 0x68000, 0x0810, 0x0800},
144 : : {0x003f, 0x79000, 0x0010, 0x0000},
145 : : {0x0044, 0x89000, 0x0190, 0x0010},
146 : : {0x0045, 0x8a000, 0x0810, 0x0800},
147 : : {0x0046, 0x8b000, 0x001c, 0x0000},
148 : : {0x0047, 0x8c000, 0x001c, 0x0000},
149 : : {0x0048, 0x8d000, 0x0410, 0x0080},
150 : : {0x0049, 0x8e000, 0x0410, 0x0080},
151 : : {0x004a, 0x8f000, 0x0028, 0x0006},
152 : : {0x004b, 0x90000, 0x0028, 0x0006},
153 : : {0x004c, 0x91000, 0x0890, 0x0080},
154 : : {0x004d, 0x92000, 0x0890, 0x0080},
155 : : {0x004e, 0x93000, 0x0350, 0x0040},
156 : : {0x004f, 0x94000, 0x0350, 0x0040},
157 : : {0x0050, 0x95000, 0x0810, 0x0800},
158 : : {0x0051, 0x96000, 0x00d8, 0x0000},
159 : : {0x0053, 0x9a000, 0x0810, 0x0400},
160 : : {0x0055, 0x9c000, 0x0030, 0x0020},
161 : : {0x0057, 0x9f000, 0x001d, 0x0000},
162 : : {0x0058, 0xa0000, 0x0014, 0x0000},
163 : : {0x005a, 0xa1000, 0x0024, 0x0000},
164 : : {0x005b, 0xa2000, 0x0024, 0x0000},
165 : : {0x005d, 0xa4000, 0x0810, 0x0100},
166 : : {0x020d, 0xa8000, 0x0414, 0x0400},
167 : : {0x020e, 0xa9000, 0x0214, 0x0200},
168 : : {0x020f, 0xaa000, 0x0114, 0x0100},
169 : : {0x0210, 0xab000, 0x0114, 0x0100},
170 : : {0x0217, 0xaf000, 0x0414, 0x0400},
171 : : {0x0218, 0xb0000, 0x0214, 0x0200},
172 : : {0x0219, 0xb1000, 0x0094, 0x0080},
173 : : {0x021a, 0xb2000, 0x0094, 0x0080},
174 : : {0x0221, 0xb6000, 0x0414, 0x0400},
175 : : {0x0222, 0xb7000, 0x0214, 0x0200},
176 : : {0x0223, 0xb8000, 0x0094, 0x0080},
177 : : {0x0224, 0xb9000, 0x0094, 0x0080},
178 : : {0x022b, 0xbd000, 0x0414, 0x0400},
179 : : {0x022c, 0xbe000, 0x0214, 0x0200},
180 : : {0x022d, 0xbf000, 0x0094, 0x0080},
181 : : {0x022e, 0xc0000, 0x0094, 0x0080},
182 : : {0x0238, 0xc1000, 0x0114, 0x0100},
183 : : {0x0253, 0xc5000, 0x0414, 0x0400},
184 : : {0x0254, 0xc6000, 0x0054, 0x0040},
185 : : {0x0255, 0xc7000, 0x0034, 0x0020},
186 : : {0x0256, 0xc8000, 0x0034, 0x0020},
187 : : };
188 : :
189 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
190 : 0 : const struct ice_buff_seg_simple_data *seg = &buff_data[i];
191 : : struct ice_buff_seg_simple buff_seg;
192 : 0 : uint8_t *buffer = &(*buff)[seg->addr];
193 : :
194 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
195 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
196 : 0 : buff_seg.header.length = seg->len;
197 : 0 : buff_seg.header.type = seg->type;
198 : 0 : buff_seg.header.reserve = 0x0;
199 : 0 : buff_seg.header.header_len =
200 : : sizeof(struct ice_buff_seg_header);
201 : 0 : buff_seg.header.data_size =
202 : 0 : buff_seg.header.length - buff_seg.header.header_len;
203 : 0 : buff_seg.seg_end = seg->seg_end;
204 : :
205 : 0 : memset(buffer, 0x00, buff_seg.header.length);
206 : : memcpy(buffer, &buff_seg, sizeof(struct ice_buff_seg_simple));
207 : : }
208 : 0 : }
209 : :
210 : : static void
211 : 0 : write_buffer_block(uint8_t **buff)
212 : : {
213 : : uint16_t i;
214 : : /* ICE ddp package multiple segments template 1 */
215 : 0 : const struct ice_buff_seg_series_data buff_data[] = {
216 : : {0x000c, 0x03000, 0x1000, 0x05000, 0x0030, 0x0ff0, 0x0020, 0},
217 : : {0x0010, 0x0a000, 0x0fd0, 0x16000, 0x0310, 0x0015, 0x0004, 0},
218 : : {0x0016, 0x1b000, 0x1000, 0x1d000, 0x0030, 0x0ff0, 0x0020, 0},
219 : : {0x001a, 0x22000, 0x0f90, 0x26000, 0x0210, 0x001f, 0x0004, 0},
220 : : {0x0020, 0x2b000, 0x1000, 0x2d000, 0x0030, 0x0ff0, 0x0020, 0},
221 : : {0x0024, 0x32000, 0x0fd0, 0x35000, 0x00d0, 0x002a, 0x0002, 0},
222 : : {0x002a, 0x3a000, 0x1000, 0x3c000, 0x0030, 0x0ff0, 0x0020, 0},
223 : : {0x002e, 0x41000, 0x0fd0, 0x44000, 0x00d0, 0x002a, 0x0002, 0},
224 : : {0x0032, 0x47000, 0x1000, 0x4f000, 0x0090, 0x00ff, 0x0008, 0},
225 : : {0x0033, 0x50000, 0x1000, 0x53000, 0x0040, 0x0154, 0x0004, 0},
226 : : {0x0034, 0x54000, 0x1000, 0x56000, 0x0430, 0x0055, 0x0016, 0},
227 : : {0x0039, 0x65000, 0x1000, 0x66000, 0x0220, 0x00aa, 0x0016, 0},
228 : : {0x003c, 0x69000, 0x1000, 0x71000, 0x0090, 0x00ff, 0x0008, 0},
229 : : {0x003d, 0x72000, 0x1000, 0x75000, 0x0040, 0x0154, 0x0004, 0},
230 : : {0x003e, 0x76000, 0x1000, 0x78000, 0x0430, 0x0055, 0x0016, 0},
231 : : {0x0043, 0x87000, 0x1000, 0x88000, 0x0220, 0x00aa, 0x0016, 0},
232 : : {0x0052, 0x97000, 0x1000, 0x99000, 0x0030, 0x0ff0, 0x0020, 0},
233 : : {0x0056, 0x9d000, 0x0f90, 0x9e000, 0x0090, 0x001f, 0x0001, 0},
234 : : {0x020c, 0xa5000, 0x1000, 0xa7000, 0x003c, 0x0fec, 0x0028, 1},
235 : : {0x0216, 0xac000, 0x1000, 0xae000, 0x003c, 0x0fec, 0x0028, 1},
236 : : {0x0220, 0xb3000, 0x1000, 0xb5000, 0x003c, 0x0fec, 0x0028, 1},
237 : : {0x022a, 0xba000, 0x1000, 0xbc000, 0x003c, 0x0fec, 0x0028, 1},
238 : : {0x0252, 0xc2000, 0x1000, 0xc4000, 0x003c, 0x0fec, 0x0028, 1},
239 : : };
240 : :
241 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
242 : 0 : const struct ice_buff_seg_series_data *seg = &buff_data[i];
243 : : struct ice_buff_seg_series buff_seg;
244 : : const uint16_t buff_seg_size =
245 : : sizeof(struct ice_buff_seg_series);
246 : 0 : uint32_t addr = seg->begin_addr;
247 : : __le16 last_offset = 0;
248 : :
249 [ # # ]: 0 : for (; addr <= seg->end_addr; addr += ICE_PKG_BUF_SIZE) {
250 [ # # ]: 0 : uint8_t *buffer = &(*buff)[addr];
251 : :
252 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
253 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
254 [ # # ]: 0 : buff_seg.header.length = addr == seg->end_addr ?
255 : : seg->last_len : seg->len;
256 : 0 : buff_seg.header.type = seg->type;
257 : 0 : buff_seg.header.reserve = 0x0;
258 : 0 : buff_seg.header.header_len = ice_buff_seg_header_size;
259 : 0 : buff_seg.header.data_size = buff_seg.header.length -
260 : : buff_seg.header.header_len;
261 [ # # ]: 0 : buff_seg.offset_delta = addr < seg->end_addr ?
262 : : seg->offset_delta : seg->seg_end;
263 : 0 : buff_seg.offset[!seg->padding] = 0x0;
264 : 0 : buff_seg.offset[seg->padding] = last_offset;
265 : :
266 : 0 : memset(buffer, 0x00, buff_seg.header.length);
267 : : memcpy(buffer, &buff_seg, buff_seg_size);
268 : :
269 : 0 : last_offset += seg->offset_delta;
270 : : }
271 : : }
272 : 0 : }
273 : :
274 : : static void
275 : 0 : write_buffer_block2(uint8_t **buff)
276 : : {
277 : : uint16_t i;
278 : : /* ICE ddp package multiple segments template 2 */
279 : 0 : struct ice_buff_seg_series_with_sub_data buff_data[] = {
280 : : {0x000e, 0x07000, 0x1000, 0x08000, 0x0a1c, 13},
281 : : {0x0018, 0x1f000, 0x1000, 0x20000, 0x0a1c, 13},
282 : : {0x0022, 0x2f000, 0x1000, 0x30000, 0x0a1c, 13},
283 : : {0x002c, 0x3e000, 0x1000, 0x3f000, 0x0a1c, 13},
284 : : {0x0037, 0x58000, 0x1000, 0x5e000, 0x0070, 24},
285 : : {0x0038, 0x5f000, 0x0fe0, 0x64000, 0x0900, 88},
286 : : {0x0041, 0x7a000, 0x1000, 0x80000, 0x0070, 24},
287 : : {0x0042, 0x81000, 0x0fe0, 0x86000, 0x0900, 88},
288 : : {0x0054, 0x9b000, 0x034e, 0x9b000, 0x034e, 13},
289 : : {0x005c, 0xa3000, 0x0a10, 0xa3000, 0x0a10, 40},
290 : : };
291 : :
292 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(buff_data); i++) {
293 : 0 : struct ice_buff_seg_series_with_sub_data *seg = &buff_data[i];
294 : : struct ice_buff_seg_series_with_sub buff_seg;
295 : : const uint16_t buff_seg_size =
296 : : sizeof(struct ice_buff_seg_series_with_sub);
297 : : uint32_t addr;
298 : : uint16_t last_idx = 0;
299 : :
300 : 0 : for (addr = seg->begin_addr;
301 [ # # ]: 0 : addr <= seg->end_addr; addr += ICE_PKG_BUF_SIZE) {
302 [ # # ]: 0 : uint8_t *buffer = &(*buff)[addr];
303 : : uint16_t total_sblk_size;
304 : : uint16_t idx = 0;
305 : : uint32_t pos = buff_seg_size;
306 : :
307 : : memset(buffer, 0xFF, ICE_PKG_BUF_SIZE);
308 : 0 : buff_seg.header.flag = ICE_BUFF_SEG_HEADER_FLAG;
309 : 0 : buff_seg.header.length =
310 [ # # ]: 0 : addr == seg->end_addr ?
311 : : seg->last_len : seg->len;
312 : 0 : buff_seg.header.type = seg->type;
313 : 0 : buff_seg.header.reserve = 0x0;
314 : 0 : buff_seg.header.header_len = ice_buff_seg_header_size;
315 : 0 : buff_seg.header.data_size = buff_seg.header.length -
316 : : buff_seg.header.header_len;
317 : :
318 : 0 : total_sblk_size = buff_seg.header.data_size
319 : : - sizeof(buff_seg.sub_block_num);
320 : 0 : buff_seg.sub_block_num =
321 : 0 : total_sblk_size / seg->sblk_size;
322 : :
323 [ # # ]: 0 : memset(buffer, 0x00, buff_seg.header.length);
324 : : memcpy(buffer, &buff_seg, buff_seg_size);
325 : :
326 : : /* padding if needed */
327 [ # # ]: 0 : if (total_sblk_size % seg->sblk_size)
328 : : pos += sizeof(uint16_t);
329 : :
330 : 0 : for (idx = last_idx;
331 [ # # ]: 0 : idx < last_idx + buff_seg.sub_block_num; idx++) {
332 : 0 : memcpy(buffer + pos, &idx, sizeof(uint16_t));
333 : 0 : pos += seg->sblk_size;
334 : : }
335 : :
336 : : last_idx = idx;
337 : : }
338 : : }
339 : 0 : }
340 : :
341 : : static int
342 : 0 : ice_dump_pkg(struct rte_eth_dev *dev, uint8_t **buff, uint32_t *size)
343 : : {
344 : : struct ice_hw *hw;
345 : : struct ice_buf pkg_buff;
346 : : uint8_t *next_buff;
347 : : uint16_t i = 0;
348 : : uint16_t count;
349 : : struct ice_package_header *cache;
350 : : uint32_t cache_size;
351 : :
352 : 0 : write_buffer_simple(buff);
353 : 0 : write_buffer_block(buff);
354 : 0 : write_buffer_block2(buff);
355 : :
356 : 0 : hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
357 : :
358 [ # # ]: 0 : if (*size % ICE_PKG_BUF_SIZE)
359 : : return -EINVAL;
360 : :
361 : 0 : count = *size / ICE_PKG_BUF_SIZE;
362 [ # # ]: 0 : for (i = 0; i < count; i++) {
363 [ # # ]: 0 : next_buff = (uint8_t *)(*buff) + i * ICE_PKG_BUF_SIZE;
364 : : rte_memcpy(pkg_buff.buf, next_buff, ICE_PKG_BUF_SIZE);
365 [ # # ]: 0 : if (ice_aq_upload_section(hw,
366 : : (struct ice_buf_hdr *)&pkg_buff.buf[0],
367 : : ICE_PKG_BUF_SIZE,
368 : : NULL))
369 : : return -EINVAL;
370 : : rte_memcpy(next_buff, pkg_buff.buf, ICE_PKG_BUF_SIZE);
371 : : }
372 : :
373 : 0 : cache_size = sizeof(struct ice_package_header) + *size;
374 : 0 : cache = (struct ice_package_header *)malloc(cache_size);
375 [ # # ]: 0 : if (!cache)
376 : : return -ENOSPC;
377 : :
378 : 0 : cache->header.h1 = ICE_PKG_HDR_HEADR_PART1;
379 : 0 : cache->header.h2 = ICE_PKG_HDR_HEADR_PART2;
380 : 0 : cache->gm_seg_offset = ICE_PKG_HDR_GM_SEG_OFFSET;
381 : 0 : cache->ice_seg_offset = ICE_PKG_HDR_ICE_SEG_OFFSET;
382 : 0 : cache->gm_seg.hdr.seg_type = ICE_PKG_GM_SEG_TYPE;
383 : 0 : cache->gm_seg.hdr.seg_format_ver.major = ICE_PKG_MAJOR_VERSION;
384 : 0 : cache->gm_seg.hdr.seg_size = ICE_PKG_GM_SEG_SIZE;
385 : 0 : ICE_PKG_COPY_STRING(cache->gm_seg.hdr.seg_id, "Global Metadata");
386 : :
387 : 0 : cache->gm_seg.pkg_ver.major = ICE_PKG_MAJOR_VERSION;
388 : 0 : cache->gm_seg.rsvd = 1;
389 : 0 : ICE_PKG_COPY_STRING(cache->gm_seg.pkg_name, "DEFAULT");
390 : :
391 : 0 : cache->ice_seg.hdr.seg_type = ICE_PKG_ICE_SEG_TYPE;
392 : 0 : cache->ice_seg.hdr.seg_format_ver.major = ICE_PKG_MAJOR_VERSION;
393 : 0 : cache->ice_seg.hdr.seg_size = ICE_PKG_ICE_SEG_SIZE_BASE + *size;
394 : 0 : cache->ice_seg.devid_count = 0;
395 : 0 : cache->ice_seg.nvm_ver.major = 0;
396 : 0 : ICE_PKG_COPY_STRING(cache->ice_seg.hdr.seg_id, "CPK Configuration Data");
397 : :
398 : 0 : cache->buff_count = count;
399 : :
400 : : next_buff = (uint8_t *)cache;
401 : 0 : next_buff += sizeof(struct ice_package_header);
402 : 0 : memcpy(next_buff, *buff, *size);
403 : :
404 : 0 : free(*buff);
405 : 0 : *buff = (uint8_t *)cache;
406 : 0 : *size = cache_size;
407 : :
408 : 0 : return 0;
409 : : }
410 : :
411 : 0 : int rte_pmd_ice_dump_package(uint16_t port, uint8_t **buff, uint32_t *size)
412 : : {
413 : : struct rte_eth_dev *dev;
414 : :
415 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
416 : :
417 : 0 : dev = &rte_eth_devices[port];
418 [ # # ]: 0 : if (!is_ice_supported(dev))
419 : : return -ENOTSUP;
420 : :
421 : 0 : return ice_dump_pkg(dev, buff, size);
422 : : }
423 : :
424 : : static uint16_t
425 : 0 : covert_byte_to_hex(uint8_t **outbuf, const uint8_t *inbuf, uint32_t inbuf_size)
426 : : {
427 : : uint32_t i;
428 : 0 : uint8_t *buffer = *outbuf;
429 [ # # ]: 0 : for (i = 0; i < inbuf_size; ++i)
430 : 0 : sprintf((char *)(buffer + i * 2), "%02X", inbuf[i]);
431 : :
432 : 0 : return inbuf_size * 2;
433 : : }
434 : :
435 : : static int
436 : 0 : ice_dump_switch(struct rte_eth_dev *dev, uint8_t **buff2, uint32_t *size)
437 : : {
438 : : struct ice_hw *hw;
439 : : int i = 0;
440 : 0 : uint16_t tbl_id = 0;
441 : 0 : uint32_t tbl_idx = 0;
442 : 0 : uint8_t *buffer = *buff2;
443 : :
444 : 0 : hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
445 : :
446 : : /* table index string format: "0000:" */
447 : : #define TBL_IDX_STR_SIZE 7
448 [ # # ]: 0 : for (i = 0; i < ICE_BLK_MAX_COUNT; i++) {
449 : : int res;
450 : : uint16_t buff_size;
451 : : uint8_t *buff;
452 : : uint32_t offset = 0;
453 : :
454 : 0 : buff = malloc(ICE_PKG_BUF_SIZE);
455 [ # # ]: 0 : if (!buff)
456 : 0 : return ICE_ERR_NO_MEMORY;
457 : :
458 [ # # ]: 0 : if (tbl_idx == 0) {
459 : : char tbl_idx_str[TBL_IDX_STR_SIZE];
460 : : memset(tbl_idx_str, 0, sizeof(tbl_idx_str));
461 : 0 : sprintf(tbl_idx_str, "%d:", tbl_id);
462 : 0 : memcpy(buffer, tbl_idx_str, strlen(tbl_idx_str));
463 : 0 : offset = strlen(tbl_idx_str);
464 : 0 : buffer += offset;
465 : : }
466 : :
467 : 0 : res = ice_aq_get_internal_data(hw,
468 : : ICE_AQC_DBG_DUMP_CLUSTER_ID_SW,
469 : : tbl_id, tbl_idx, buff,
470 : : ICE_PKG_BUF_SIZE,
471 : : &buff_size, &tbl_id, &tbl_idx, NULL);
472 : :
473 [ # # ]: 0 : if (res) {
474 : 0 : free(buff);
475 : 0 : return res;
476 : : }
477 : :
478 : 0 : offset = covert_byte_to_hex(&buffer, buff, buff_size);
479 : 0 : buffer += offset;
480 : :
481 : 0 : free(buff);
482 : :
483 [ # # ]: 0 : if (tbl_idx == 0xffffffff) {
484 : 0 : tbl_idx = 0;
485 : : memset(buffer, '\n', sizeof(char));
486 : 0 : buffer++;
487 : : offset = 0;
488 : : }
489 : :
490 [ # # ]: 0 : if (tbl_id == 0xff)
491 : : break;
492 : : }
493 : :
494 : 0 : *size = buffer - *buff2;
495 : 0 : return 0;
496 : : }
497 : :
498 : 0 : int rte_pmd_ice_dump_switch(uint16_t port, uint8_t **buff, uint32_t *size)
499 : : {
500 : : struct rte_eth_dev *dev;
501 : :
502 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
503 : :
504 : 0 : dev = &rte_eth_devices[port];
505 [ # # ]: 0 : if (!is_ice_supported(dev))
506 : : return -ENOTSUP;
507 : :
508 : 0 : return ice_dump_switch(dev, buff, size);
509 : : }
|