Loading...
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2/* QLogic qed NIC Driver
3 * Copyright (c) 2015 QLogic Corporation
4 * Copyright (c) 2019-2021 Marvell International Ltd.
5 */
6
7#include <linux/module.h>
8#include <linux/vmalloc.h>
9#include <linux/crc32.h>
10#include "qed.h"
11#include "qed_cxt.h"
12#include "qed_hsi.h"
13#include "qed_dbg_hsi.h"
14#include "qed_hw.h"
15#include "qed_mcp.h"
16#include "qed_reg_addr.h"
17
18/* Memory groups enum */
19enum mem_groups {
20 MEM_GROUP_PXP_MEM,
21 MEM_GROUP_DMAE_MEM,
22 MEM_GROUP_CM_MEM,
23 MEM_GROUP_QM_MEM,
24 MEM_GROUP_DORQ_MEM,
25 MEM_GROUP_BRB_RAM,
26 MEM_GROUP_BRB_MEM,
27 MEM_GROUP_PRS_MEM,
28 MEM_GROUP_SDM_MEM,
29 MEM_GROUP_PBUF,
30 MEM_GROUP_IOR,
31 MEM_GROUP_RAM,
32 MEM_GROUP_BTB_RAM,
33 MEM_GROUP_RDIF_CTX,
34 MEM_GROUP_TDIF_CTX,
35 MEM_GROUP_CFC_MEM,
36 MEM_GROUP_CONN_CFC_MEM,
37 MEM_GROUP_CAU_PI,
38 MEM_GROUP_CAU_MEM,
39 MEM_GROUP_CAU_MEM_EXT,
40 MEM_GROUP_PXP_ILT,
41 MEM_GROUP_MULD_MEM,
42 MEM_GROUP_BTB_MEM,
43 MEM_GROUP_IGU_MEM,
44 MEM_GROUP_IGU_MSIX,
45 MEM_GROUP_CAU_SB,
46 MEM_GROUP_BMB_RAM,
47 MEM_GROUP_BMB_MEM,
48 MEM_GROUP_TM_MEM,
49 MEM_GROUP_TASK_CFC_MEM,
50 MEM_GROUPS_NUM
51};
52
53/* Memory groups names */
54static const char * const s_mem_group_names[] = {
55 "PXP_MEM",
56 "DMAE_MEM",
57 "CM_MEM",
58 "QM_MEM",
59 "DORQ_MEM",
60 "BRB_RAM",
61 "BRB_MEM",
62 "PRS_MEM",
63 "SDM_MEM",
64 "PBUF",
65 "IOR",
66 "RAM",
67 "BTB_RAM",
68 "RDIF_CTX",
69 "TDIF_CTX",
70 "CFC_MEM",
71 "CONN_CFC_MEM",
72 "CAU_PI",
73 "CAU_MEM",
74 "CAU_MEM_EXT",
75 "PXP_ILT",
76 "MULD_MEM",
77 "BTB_MEM",
78 "IGU_MEM",
79 "IGU_MSIX",
80 "CAU_SB",
81 "BMB_RAM",
82 "BMB_MEM",
83 "TM_MEM",
84 "TASK_CFC_MEM",
85};
86
87/* Idle check conditions */
88
89static u32 cond5(const u32 *r, const u32 *imm)
90{
91 return ((r[0] & imm[0]) != imm[1]) && ((r[1] & imm[2]) != imm[3]);
92}
93
94static u32 cond7(const u32 *r, const u32 *imm)
95{
96 return ((r[0] >> imm[0]) & imm[1]) != imm[2];
97}
98
99static u32 cond6(const u32 *r, const u32 *imm)
100{
101 return (r[0] & imm[0]) != imm[1];
102}
103
104static u32 cond9(const u32 *r, const u32 *imm)
105{
106 return ((r[0] & imm[0]) >> imm[1]) !=
107 (((r[0] & imm[2]) >> imm[3]) | ((r[1] & imm[4]) << imm[5]));
108}
109
110static u32 cond10(const u32 *r, const u32 *imm)
111{
112 return ((r[0] & imm[0]) >> imm[1]) != (r[0] & imm[2]);
113}
114
115static u32 cond4(const u32 *r, const u32 *imm)
116{
117 return (r[0] & ~imm[0]) != imm[1];
118}
119
120static u32 cond0(const u32 *r, const u32 *imm)
121{
122 return (r[0] & ~r[1]) != imm[0];
123}
124
125static u32 cond14(const u32 *r, const u32 *imm)
126{
127 return (r[0] | imm[0]) != imm[1];
128}
129
130static u32 cond1(const u32 *r, const u32 *imm)
131{
132 return r[0] != imm[0];
133}
134
135static u32 cond11(const u32 *r, const u32 *imm)
136{
137 return r[0] != r[1] && r[2] == imm[0];
138}
139
140static u32 cond12(const u32 *r, const u32 *imm)
141{
142 return r[0] != r[1] && r[2] > imm[0];
143}
144
145static u32 cond3(const u32 *r, const u32 *imm)
146{
147 return r[0] != r[1];
148}
149
150static u32 cond13(const u32 *r, const u32 *imm)
151{
152 return r[0] & imm[0];
153}
154
155static u32 cond8(const u32 *r, const u32 *imm)
156{
157 return r[0] < (r[1] - imm[0]);
158}
159
160static u32 cond2(const u32 *r, const u32 *imm)
161{
162 return r[0] > imm[0];
163}
164
165/* Array of Idle Check conditions */
166static u32(*cond_arr[]) (const u32 *r, const u32 *imm) = {
167 cond0,
168 cond1,
169 cond2,
170 cond3,
171 cond4,
172 cond5,
173 cond6,
174 cond7,
175 cond8,
176 cond9,
177 cond10,
178 cond11,
179 cond12,
180 cond13,
181 cond14,
182};
183
184#define NUM_PHYS_BLOCKS 84
185
186#define NUM_DBG_RESET_REGS 8
187
188/******************************* Data Types **********************************/
189
190enum hw_types {
191 HW_TYPE_ASIC,
192 PLATFORM_RESERVED,
193 PLATFORM_RESERVED2,
194 PLATFORM_RESERVED3,
195 PLATFORM_RESERVED4,
196 MAX_HW_TYPES
197};
198
199/* CM context types */
200enum cm_ctx_types {
201 CM_CTX_CONN_AG,
202 CM_CTX_CONN_ST,
203 CM_CTX_TASK_AG,
204 CM_CTX_TASK_ST,
205 NUM_CM_CTX_TYPES
206};
207
208/* Debug bus frame modes */
209enum dbg_bus_frame_modes {
210 DBG_BUS_FRAME_MODE_4ST = 0, /* 4 Storm dwords (no HW) */
211 DBG_BUS_FRAME_MODE_2ST_2HW = 1, /* 2 Storm dwords, 2 HW dwords */
212 DBG_BUS_FRAME_MODE_1ST_3HW = 2, /* 1 Storm dwords, 3 HW dwords */
213 DBG_BUS_FRAME_MODE_4HW = 3, /* 4 HW dwords (no Storms) */
214 DBG_BUS_FRAME_MODE_8HW = 4, /* 8 HW dwords (no Storms) */
215 DBG_BUS_NUM_FRAME_MODES
216};
217
218/* Debug bus SEMI frame modes */
219enum dbg_bus_semi_frame_modes {
220 DBG_BUS_SEMI_FRAME_MODE_4FAST = 0, /* 4 fast dw */
221 DBG_BUS_SEMI_FRAME_MODE_2FAST_2SLOW = 1, /* 2 fast dw, 2 slow dw */
222 DBG_BUS_SEMI_FRAME_MODE_1FAST_3SLOW = 2, /* 1 fast dw,3 slow dw */
223 DBG_BUS_SEMI_FRAME_MODE_4SLOW = 3, /* 4 slow dw */
224 DBG_BUS_SEMI_NUM_FRAME_MODES
225};
226
227/* Debug bus filter types */
228enum dbg_bus_filter_types {
229 DBG_BUS_FILTER_TYPE_OFF, /* Filter always off */
230 DBG_BUS_FILTER_TYPE_PRE, /* Filter before trigger only */
231 DBG_BUS_FILTER_TYPE_POST, /* Filter after trigger only */
232 DBG_BUS_FILTER_TYPE_ON /* Filter always on */
233};
234
235/* Debug bus pre-trigger recording types */
236enum dbg_bus_pre_trigger_types {
237 DBG_BUS_PRE_TRIGGER_FROM_ZERO, /* Record from time 0 */
238 DBG_BUS_PRE_TRIGGER_NUM_CHUNKS, /* Record some chunks before trigger */
239 DBG_BUS_PRE_TRIGGER_DROP /* Drop data before trigger */
240};
241
242/* Debug bus post-trigger recording types */
243enum dbg_bus_post_trigger_types {
244 DBG_BUS_POST_TRIGGER_RECORD, /* Start recording after trigger */
245 DBG_BUS_POST_TRIGGER_DROP /* Drop data after trigger */
246};
247
248/* Debug bus other engine mode */
249enum dbg_bus_other_engine_modes {
250 DBG_BUS_OTHER_ENGINE_MODE_NONE,
251 DBG_BUS_OTHER_ENGINE_MODE_DOUBLE_BW_TX,
252 DBG_BUS_OTHER_ENGINE_MODE_DOUBLE_BW_RX,
253 DBG_BUS_OTHER_ENGINE_MODE_CROSS_ENGINE_TX,
254 DBG_BUS_OTHER_ENGINE_MODE_CROSS_ENGINE_RX
255};
256
257/* DBG block Framing mode definitions */
258struct framing_mode_defs {
259 u8 id;
260 u8 blocks_dword_mask;
261 u8 storms_dword_mask;
262 u8 semi_framing_mode_id;
263 u8 full_buf_thr;
264};
265
266/* Chip constant definitions */
267struct chip_defs {
268 const char *name;
269 u8 dwords_per_cycle;
270 u8 num_framing_modes;
271 u32 num_ilt_pages;
272 struct framing_mode_defs *framing_modes;
273};
274
275/* HW type constant definitions */
276struct hw_type_defs {
277 const char *name;
278 u32 delay_factor;
279 u32 dmae_thresh;
280 u32 log_thresh;
281};
282
283/* RBC reset definitions */
284struct rbc_reset_defs {
285 u32 reset_reg_addr;
286 u32 reset_val[MAX_CHIP_IDS];
287};
288
289/* Storm constant definitions.
290 * Addresses are in bytes, sizes are in quad-regs.
291 */
292struct storm_defs {
293 char letter;
294 enum block_id sem_block_id;
295 enum dbg_bus_clients dbg_client_id[MAX_CHIP_IDS];
296 bool has_vfc;
297 u32 sem_fast_mem_addr;
298 u32 sem_frame_mode_addr;
299 u32 sem_slow_enable_addr;
300 u32 sem_slow_mode_addr;
301 u32 sem_slow_mode1_conf_addr;
302 u32 sem_sync_dbg_empty_addr;
303 u32 sem_gpre_vect_addr;
304 u32 cm_ctx_wr_addr;
305 u32 cm_ctx_rd_addr[NUM_CM_CTX_TYPES];
306 u32 cm_ctx_lid_sizes[MAX_CHIP_IDS][NUM_CM_CTX_TYPES];
307};
308
309/* Debug Bus Constraint operation constant definitions */
310struct dbg_bus_constraint_op_defs {
311 u8 hw_op_val;
312 bool is_cyclic;
313};
314
315/* Storm Mode definitions */
316struct storm_mode_defs {
317 const char *name;
318 bool is_fast_dbg;
319 u8 id_in_hw;
320 u32 src_disable_reg_addr;
321 u32 src_enable_val;
322 bool exists[MAX_CHIP_IDS];
323};
324
325struct grc_param_defs {
326 u32 default_val[MAX_CHIP_IDS];
327 u32 min;
328 u32 max;
329 bool is_preset;
330 bool is_persistent;
331 u32 exclude_all_preset_val;
332 u32 crash_preset_val[MAX_CHIP_IDS];
333};
334
335/* Address is in 128b units. Width is in bits. */
336struct rss_mem_defs {
337 const char *mem_name;
338 const char *type_name;
339 u32 addr;
340 u32 entry_width;
341 u32 num_entries[MAX_CHIP_IDS];
342};
343
344struct vfc_ram_defs {
345 const char *mem_name;
346 const char *type_name;
347 u32 base_row;
348 u32 num_rows;
349};
350
351struct big_ram_defs {
352 const char *instance_name;
353 enum mem_groups mem_group_id;
354 enum mem_groups ram_mem_group_id;
355 enum dbg_grc_params grc_param;
356 u32 addr_reg_addr;
357 u32 data_reg_addr;
358 u32 is_256b_reg_addr;
359 u32 is_256b_bit_offset[MAX_CHIP_IDS];
360 u32 ram_size[MAX_CHIP_IDS]; /* In dwords */
361};
362
363struct phy_defs {
364 const char *phy_name;
365
366 /* PHY base GRC address */
367 u32 base_addr;
368
369 /* Relative address of indirect TBUS address register (bits 0..7) */
370 u32 tbus_addr_lo_addr;
371
372 /* Relative address of indirect TBUS address register (bits 8..10) */
373 u32 tbus_addr_hi_addr;
374
375 /* Relative address of indirect TBUS data register (bits 0..7) */
376 u32 tbus_data_lo_addr;
377
378 /* Relative address of indirect TBUS data register (bits 8..11) */
379 u32 tbus_data_hi_addr;
380};
381
382/* Split type definitions */
383struct split_type_defs {
384 const char *name;
385};
386
387/******************************** Constants **********************************/
388
389#define BYTES_IN_DWORD sizeof(u32)
390/* In the macros below, size and offset are specified in bits */
391#define CEIL_DWORDS(size) DIV_ROUND_UP(size, 32)
392#define FIELD_BIT_OFFSET(type, field) type ## _ ## field ## _ ## OFFSET
393#define FIELD_BIT_SIZE(type, field) type ## _ ## field ## _ ## SIZE
394#define FIELD_DWORD_OFFSET(type, field) \
395 ((int)(FIELD_BIT_OFFSET(type, field) / 32))
396#define FIELD_DWORD_SHIFT(type, field) (FIELD_BIT_OFFSET(type, field) % 32)
397#define FIELD_BIT_MASK(type, field) \
398 (((1 << FIELD_BIT_SIZE(type, field)) - 1) << \
399 FIELD_DWORD_SHIFT(type, field))
400
401#define SET_VAR_FIELD(var, type, field, val) \
402 do { \
403 var[FIELD_DWORD_OFFSET(type, field)] &= \
404 (~FIELD_BIT_MASK(type, field)); \
405 var[FIELD_DWORD_OFFSET(type, field)] |= \
406 (val) << FIELD_DWORD_SHIFT(type, field); \
407 } while (0)
408
409#define ARR_REG_WR(dev, ptt, addr, arr, arr_size) \
410 do { \
411 for (i = 0; i < (arr_size); i++) \
412 qed_wr(dev, ptt, addr, (arr)[i]); \
413 } while (0)
414
415#define DWORDS_TO_BYTES(dwords) ((dwords) * BYTES_IN_DWORD)
416#define BYTES_TO_DWORDS(bytes) ((bytes) / BYTES_IN_DWORD)
417
418/* extra lines include a signature line + optional latency events line */
419#define NUM_EXTRA_DBG_LINES(block) \
420 (GET_FIELD((block)->flags, DBG_BLOCK_CHIP_HAS_LATENCY_EVENTS) ? 2 : 1)
421#define NUM_DBG_LINES(block) \
422 ((block)->num_of_dbg_bus_lines + NUM_EXTRA_DBG_LINES(block))
423
424#define USE_DMAE true
425#define PROTECT_WIDE_BUS true
426
427#define RAM_LINES_TO_DWORDS(lines) ((lines) * 2)
428#define RAM_LINES_TO_BYTES(lines) \
429 DWORDS_TO_BYTES(RAM_LINES_TO_DWORDS(lines))
430
431#define REG_DUMP_LEN_SHIFT 24
432#define MEM_DUMP_ENTRY_SIZE_DWORDS \
433 BYTES_TO_DWORDS(sizeof(struct dbg_dump_mem))
434
435#define IDLE_CHK_RULE_SIZE_DWORDS \
436 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_rule))
437
438#define IDLE_CHK_RESULT_HDR_DWORDS \
439 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_hdr))
440
441#define IDLE_CHK_RESULT_REG_HDR_DWORDS \
442 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_reg_hdr))
443
444#define PAGE_MEM_DESC_SIZE_DWORDS \
445 BYTES_TO_DWORDS(sizeof(struct phys_mem_desc))
446
447#define IDLE_CHK_MAX_ENTRIES_SIZE 32
448
449/* The sizes and offsets below are specified in bits */
450#define VFC_CAM_CMD_STRUCT_SIZE 64
451#define VFC_CAM_CMD_ROW_OFFSET 48
452#define VFC_CAM_CMD_ROW_SIZE 9
453#define VFC_CAM_ADDR_STRUCT_SIZE 16
454#define VFC_CAM_ADDR_OP_OFFSET 0
455#define VFC_CAM_ADDR_OP_SIZE 4
456#define VFC_CAM_RESP_STRUCT_SIZE 256
457#define VFC_RAM_ADDR_STRUCT_SIZE 16
458#define VFC_RAM_ADDR_OP_OFFSET 0
459#define VFC_RAM_ADDR_OP_SIZE 2
460#define VFC_RAM_ADDR_ROW_OFFSET 2
461#define VFC_RAM_ADDR_ROW_SIZE 10
462#define VFC_RAM_RESP_STRUCT_SIZE 256
463
464#define VFC_CAM_CMD_DWORDS CEIL_DWORDS(VFC_CAM_CMD_STRUCT_SIZE)
465#define VFC_CAM_ADDR_DWORDS CEIL_DWORDS(VFC_CAM_ADDR_STRUCT_SIZE)
466#define VFC_CAM_RESP_DWORDS CEIL_DWORDS(VFC_CAM_RESP_STRUCT_SIZE)
467#define VFC_RAM_CMD_DWORDS VFC_CAM_CMD_DWORDS
468#define VFC_RAM_ADDR_DWORDS CEIL_DWORDS(VFC_RAM_ADDR_STRUCT_SIZE)
469#define VFC_RAM_RESP_DWORDS CEIL_DWORDS(VFC_RAM_RESP_STRUCT_SIZE)
470
471#define NUM_VFC_RAM_TYPES 4
472
473#define VFC_CAM_NUM_ROWS 512
474
475#define VFC_OPCODE_CAM_RD 14
476#define VFC_OPCODE_RAM_RD 0
477
478#define NUM_RSS_MEM_TYPES 5
479
480#define NUM_BIG_RAM_TYPES 3
481#define BIG_RAM_NAME_LEN 3
482
483#define NUM_PHY_TBUS_ADDRESSES 2048
484#define PHY_DUMP_SIZE_DWORDS (NUM_PHY_TBUS_ADDRESSES / 2)
485
486#define RESET_REG_UNRESET_OFFSET 4
487
488#define STALL_DELAY_MS 500
489
490#define STATIC_DEBUG_LINE_DWORDS 9
491
492#define NUM_COMMON_GLOBAL_PARAMS 10
493
494#define MAX_RECURSION_DEPTH 10
495
496#define FW_IMG_KUKU 0
497#define FW_IMG_MAIN 1
498#define FW_IMG_L2B 2
499
500#define REG_FIFO_ELEMENT_DWORDS 2
501#define REG_FIFO_DEPTH_ELEMENTS 32
502#define REG_FIFO_DEPTH_DWORDS \
503 (REG_FIFO_ELEMENT_DWORDS * REG_FIFO_DEPTH_ELEMENTS)
504
505#define IGU_FIFO_ELEMENT_DWORDS 4
506#define IGU_FIFO_DEPTH_ELEMENTS 64
507#define IGU_FIFO_DEPTH_DWORDS \
508 (IGU_FIFO_ELEMENT_DWORDS * IGU_FIFO_DEPTH_ELEMENTS)
509
510#define PROTECTION_OVERRIDE_ELEMENT_DWORDS 2
511#define PROTECTION_OVERRIDE_DEPTH_ELEMENTS 20
512#define PROTECTION_OVERRIDE_DEPTH_DWORDS \
513 (PROTECTION_OVERRIDE_DEPTH_ELEMENTS * \
514 PROTECTION_OVERRIDE_ELEMENT_DWORDS)
515
516#define MCP_SPAD_TRACE_OFFSIZE_ADDR \
517 (MCP_REG_SCRATCH + \
518 offsetof(struct static_init, sections[SPAD_SECTION_TRACE]))
519
520#define MAX_SW_PLTAFORM_STR_SIZE 64
521
522#define EMPTY_FW_VERSION_STR "???_???_???_???"
523#define EMPTY_FW_IMAGE_STR "???????????????"
524
525/***************************** Constant Arrays *******************************/
526
527/* DBG block framing mode definitions, in descending preference order */
528static struct framing_mode_defs s_framing_mode_defs[4] = {
529 {DBG_BUS_FRAME_MODE_4ST, 0x0, 0xf,
530 DBG_BUS_SEMI_FRAME_MODE_4FAST,
531 10},
532 {DBG_BUS_FRAME_MODE_4HW, 0xf, 0x0, DBG_BUS_SEMI_FRAME_MODE_4SLOW,
533 10},
534 {DBG_BUS_FRAME_MODE_2ST_2HW, 0x3, 0xc,
535 DBG_BUS_SEMI_FRAME_MODE_2FAST_2SLOW, 10},
536 {DBG_BUS_FRAME_MODE_1ST_3HW, 0x7, 0x8,
537 DBG_BUS_SEMI_FRAME_MODE_1FAST_3SLOW, 10}
538};
539
540/* Chip constant definitions array */
541static struct chip_defs s_chip_defs[MAX_CHIP_IDS] = {
542 {"bb", 4, DBG_BUS_NUM_FRAME_MODES, PSWRQ2_REG_ILT_MEMORY_SIZE_BB / 2,
543 s_framing_mode_defs},
544 {"ah", 4, DBG_BUS_NUM_FRAME_MODES, PSWRQ2_REG_ILT_MEMORY_SIZE_K2 / 2,
545 s_framing_mode_defs}
546};
547
548/* Storm constant definitions array */
549static struct storm_defs s_storm_defs[] = {
550 /* Tstorm */
551 {'T', BLOCK_TSEM,
552 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
553 true,
554 TSEM_REG_FAST_MEMORY,
555 TSEM_REG_DBG_FRAME_MODE, TSEM_REG_SLOW_DBG_ACTIVE,
556 TSEM_REG_SLOW_DBG_MODE, TSEM_REG_DBG_MODE1_CFG,
557 TSEM_REG_SYNC_DBG_EMPTY, TSEM_REG_DBG_GPRE_VECT,
558 TCM_REG_CTX_RBC_ACCS,
559 {TCM_REG_AGG_CON_CTX, TCM_REG_SM_CON_CTX, TCM_REG_AGG_TASK_CTX,
560 TCM_REG_SM_TASK_CTX},
561 {{4, 16, 2, 4}, {4, 16, 2, 4}} /* {bb} {k2} */
562 },
563
564 /* Mstorm */
565 {'M', BLOCK_MSEM,
566 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM},
567 false,
568 MSEM_REG_FAST_MEMORY,
569 MSEM_REG_DBG_FRAME_MODE,
570 MSEM_REG_SLOW_DBG_ACTIVE,
571 MSEM_REG_SLOW_DBG_MODE,
572 MSEM_REG_DBG_MODE1_CFG,
573 MSEM_REG_SYNC_DBG_EMPTY,
574 MSEM_REG_DBG_GPRE_VECT,
575 MCM_REG_CTX_RBC_ACCS,
576 {MCM_REG_AGG_CON_CTX, MCM_REG_SM_CON_CTX, MCM_REG_AGG_TASK_CTX,
577 MCM_REG_SM_TASK_CTX },
578 {{1, 10, 2, 7}, {1, 10, 2, 7}} /* {bb} {k2}*/
579 },
580
581 /* Ustorm */
582 {'U', BLOCK_USEM,
583 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
584 false,
585 USEM_REG_FAST_MEMORY,
586 USEM_REG_DBG_FRAME_MODE,
587 USEM_REG_SLOW_DBG_ACTIVE,
588 USEM_REG_SLOW_DBG_MODE,
589 USEM_REG_DBG_MODE1_CFG,
590 USEM_REG_SYNC_DBG_EMPTY,
591 USEM_REG_DBG_GPRE_VECT,
592 UCM_REG_CTX_RBC_ACCS,
593 {UCM_REG_AGG_CON_CTX, UCM_REG_SM_CON_CTX, UCM_REG_AGG_TASK_CTX,
594 UCM_REG_SM_TASK_CTX},
595 {{2, 13, 3, 3}, {2, 13, 3, 3}} /* {bb} {k2} */
596 },
597
598 /* Xstorm */
599 {'X', BLOCK_XSEM,
600 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
601 false,
602 XSEM_REG_FAST_MEMORY,
603 XSEM_REG_DBG_FRAME_MODE,
604 XSEM_REG_SLOW_DBG_ACTIVE,
605 XSEM_REG_SLOW_DBG_MODE,
606 XSEM_REG_DBG_MODE1_CFG,
607 XSEM_REG_SYNC_DBG_EMPTY,
608 XSEM_REG_DBG_GPRE_VECT,
609 XCM_REG_CTX_RBC_ACCS,
610 {XCM_REG_AGG_CON_CTX, XCM_REG_SM_CON_CTX, 0, 0},
611 {{9, 15, 0, 0}, {9, 15, 0, 0}} /* {bb} {k2} */
612 },
613
614 /* Ystorm */
615 {'Y', BLOCK_YSEM,
616 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY},
617 false,
618 YSEM_REG_FAST_MEMORY,
619 YSEM_REG_DBG_FRAME_MODE,
620 YSEM_REG_SLOW_DBG_ACTIVE,
621 YSEM_REG_SLOW_DBG_MODE,
622 YSEM_REG_DBG_MODE1_CFG,
623 YSEM_REG_SYNC_DBG_EMPTY,
624 YSEM_REG_DBG_GPRE_VECT,
625 YCM_REG_CTX_RBC_ACCS,
626 {YCM_REG_AGG_CON_CTX, YCM_REG_SM_CON_CTX, YCM_REG_AGG_TASK_CTX,
627 YCM_REG_SM_TASK_CTX},
628 {{2, 3, 2, 12}, {2, 3, 2, 12}} /* {bb} {k2} */
629 },
630
631 /* Pstorm */
632 {'P', BLOCK_PSEM,
633 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
634 true,
635 PSEM_REG_FAST_MEMORY,
636 PSEM_REG_DBG_FRAME_MODE,
637 PSEM_REG_SLOW_DBG_ACTIVE,
638 PSEM_REG_SLOW_DBG_MODE,
639 PSEM_REG_DBG_MODE1_CFG,
640 PSEM_REG_SYNC_DBG_EMPTY,
641 PSEM_REG_DBG_GPRE_VECT,
642 PCM_REG_CTX_RBC_ACCS,
643 {0, PCM_REG_SM_CON_CTX, 0, 0},
644 {{0, 10, 0, 0}, {0, 10, 0, 0}} /* {bb} {k2} */
645 },
646};
647
648static struct hw_type_defs s_hw_type_defs[] = {
649 /* HW_TYPE_ASIC */
650 {"asic", 1, 256, 32768},
651 {"reserved", 0, 0, 0},
652 {"reserved2", 0, 0, 0},
653 {"reserved3", 0, 0, 0},
654 {"reserved4", 0, 0, 0}
655};
656
657static struct grc_param_defs s_grc_param_defs[] = {
658 /* DBG_GRC_PARAM_DUMP_TSTORM */
659 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
660
661 /* DBG_GRC_PARAM_DUMP_MSTORM */
662 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
663
664 /* DBG_GRC_PARAM_DUMP_USTORM */
665 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
666
667 /* DBG_GRC_PARAM_DUMP_XSTORM */
668 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
669
670 /* DBG_GRC_PARAM_DUMP_YSTORM */
671 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
672
673 /* DBG_GRC_PARAM_DUMP_PSTORM */
674 {{1, 1}, 0, 1, false, false, 1, {1, 1}},
675
676 /* DBG_GRC_PARAM_DUMP_REGS */
677 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
678
679 /* DBG_GRC_PARAM_DUMP_RAM */
680 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
681
682 /* DBG_GRC_PARAM_DUMP_PBUF */
683 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
684
685 /* DBG_GRC_PARAM_DUMP_IOR */
686 {{0, 0}, 0, 1, false, false, 0, {1, 1}},
687
688 /* DBG_GRC_PARAM_DUMP_VFC */
689 {{0, 0}, 0, 1, false, false, 0, {1, 1}},
690
691 /* DBG_GRC_PARAM_DUMP_CM_CTX */
692 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
693
694 /* DBG_GRC_PARAM_DUMP_ILT */
695 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
696
697 /* DBG_GRC_PARAM_DUMP_RSS */
698 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
699
700 /* DBG_GRC_PARAM_DUMP_CAU */
701 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
702
703 /* DBG_GRC_PARAM_DUMP_QM */
704 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
705
706 /* DBG_GRC_PARAM_DUMP_MCP */
707 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
708
709 /* DBG_GRC_PARAM_DUMP_DORQ */
710 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
711
712 /* DBG_GRC_PARAM_DUMP_CFC */
713 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
714
715 /* DBG_GRC_PARAM_DUMP_IGU */
716 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
717
718 /* DBG_GRC_PARAM_DUMP_BRB */
719 {{0, 0}, 0, 1, false, false, 0, {1, 1}},
720
721 /* DBG_GRC_PARAM_DUMP_BTB */
722 {{0, 0}, 0, 1, false, false, 0, {1, 1}},
723
724 /* DBG_GRC_PARAM_DUMP_BMB */
725 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
726
727 /* DBG_GRC_PARAM_RESERVED1 */
728 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
729
730 /* DBG_GRC_PARAM_DUMP_MULD */
731 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
732
733 /* DBG_GRC_PARAM_DUMP_PRS */
734 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
735
736 /* DBG_GRC_PARAM_DUMP_DMAE */
737 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
738
739 /* DBG_GRC_PARAM_DUMP_TM */
740 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
741
742 /* DBG_GRC_PARAM_DUMP_SDM */
743 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
744
745 /* DBG_GRC_PARAM_DUMP_DIF */
746 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
747
748 /* DBG_GRC_PARAM_DUMP_STATIC */
749 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
750
751 /* DBG_GRC_PARAM_UNSTALL */
752 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
753
754 /* DBG_GRC_PARAM_RESERVED2 */
755 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
756
757 /* DBG_GRC_PARAM_MCP_TRACE_META_SIZE */
758 {{0, 0}, 1, 0xffffffff, false, true, 0, {0, 0}},
759
760 /* DBG_GRC_PARAM_EXCLUDE_ALL */
761 {{0, 0}, 0, 1, true, false, 0, {0, 0}},
762
763 /* DBG_GRC_PARAM_CRASH */
764 {{0, 0}, 0, 1, true, false, 0, {0, 0}},
765
766 /* DBG_GRC_PARAM_PARITY_SAFE */
767 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
768
769 /* DBG_GRC_PARAM_DUMP_CM */
770 {{1, 1}, 0, 1, false, false, 0, {1, 1}},
771
772 /* DBG_GRC_PARAM_DUMP_PHY */
773 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
774
775 /* DBG_GRC_PARAM_NO_MCP */
776 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
777
778 /* DBG_GRC_PARAM_NO_FW_VER */
779 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
780
781 /* DBG_GRC_PARAM_RESERVED3 */
782 {{0, 0}, 0, 1, false, false, 0, {0, 0}},
783
784 /* DBG_GRC_PARAM_DUMP_MCP_HW_DUMP */
785 {{0, 1}, 0, 1, false, false, 0, {0, 1}},
786
787 /* DBG_GRC_PARAM_DUMP_ILT_CDUC */
788 {{1, 1}, 0, 1, false, false, 0, {0, 0}},
789
790 /* DBG_GRC_PARAM_DUMP_ILT_CDUT */
791 {{1, 1}, 0, 1, false, false, 0, {0, 0}},
792
793 /* DBG_GRC_PARAM_DUMP_CAU_EXT */
794 {{0, 0}, 0, 1, false, false, 0, {1, 1}}
795};
796
797static struct rss_mem_defs s_rss_mem_defs[] = {
798 {"rss_mem_cid", "rss_cid", 0, 32,
799 {256, 320}},
800
801 {"rss_mem_key_msb", "rss_key", 1024, 256,
802 {128, 208}},
803
804 {"rss_mem_key_lsb", "rss_key", 2048, 64,
805 {128, 208}},
806
807 {"rss_mem_info", "rss_info", 3072, 16,
808 {128, 208}},
809
810 {"rss_mem_ind", "rss_ind", 4096, 16,
811 {16384, 26624}}
812};
813
814static struct vfc_ram_defs s_vfc_ram_defs[] = {
815 {"vfc_ram_tt1", "vfc_ram", 0, 512},
816 {"vfc_ram_mtt2", "vfc_ram", 512, 128},
817 {"vfc_ram_stt2", "vfc_ram", 640, 32},
818 {"vfc_ram_ro_vect", "vfc_ram", 672, 32}
819};
820
821static struct big_ram_defs s_big_ram_defs[] = {
822 {"BRB", MEM_GROUP_BRB_MEM, MEM_GROUP_BRB_RAM, DBG_GRC_PARAM_DUMP_BRB,
823 BRB_REG_BIG_RAM_ADDRESS, BRB_REG_BIG_RAM_DATA,
824 MISC_REG_BLOCK_256B_EN, {0, 0},
825 {153600, 180224}},
826
827 {"BTB", MEM_GROUP_BTB_MEM, MEM_GROUP_BTB_RAM, DBG_GRC_PARAM_DUMP_BTB,
828 BTB_REG_BIG_RAM_ADDRESS, BTB_REG_BIG_RAM_DATA,
829 MISC_REG_BLOCK_256B_EN, {0, 1},
830 {92160, 117760}},
831
832 {"BMB", MEM_GROUP_BMB_MEM, MEM_GROUP_BMB_RAM, DBG_GRC_PARAM_DUMP_BMB,
833 BMB_REG_BIG_RAM_ADDRESS, BMB_REG_BIG_RAM_DATA,
834 MISCS_REG_BLOCK_256B_EN, {0, 0},
835 {36864, 36864}}
836};
837
838static struct rbc_reset_defs s_rbc_reset_defs[] = {
839 {MISCS_REG_RESET_PL_HV,
840 {0x0, 0x400}},
841 {MISC_REG_RESET_PL_PDA_VMAIN_1,
842 {0x4404040, 0x4404040}},
843 {MISC_REG_RESET_PL_PDA_VMAIN_2,
844 {0x7, 0x7c00007}},
845 {MISC_REG_RESET_PL_PDA_VAUX,
846 {0x2, 0x2}},
847};
848
849static struct phy_defs s_phy_defs[] = {
850 {"nw_phy", NWS_REG_NWS_CMU_K2,
851 PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_7_0_K2,
852 PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_15_8_K2,
853 PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_7_0_K2,
854 PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_11_8_K2},
855 {"sgmii_phy", MS_REG_MS_CMU_K2,
856 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X132_K2,
857 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X133_K2,
858 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X130_K2,
859 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X131_K2},
860 {"pcie_phy0", PHY_PCIE_REG_PHY0_K2,
861 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2,
862 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2,
863 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2,
864 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2},
865 {"pcie_phy1", PHY_PCIE_REG_PHY1_K2,
866 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2,
867 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2,
868 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2,
869 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2},
870};
871
872static struct split_type_defs s_split_type_defs[] = {
873 /* SPLIT_TYPE_NONE */
874 {"eng"},
875
876 /* SPLIT_TYPE_PORT */
877 {"port"},
878
879 /* SPLIT_TYPE_PF */
880 {"pf"},
881
882 /* SPLIT_TYPE_PORT_PF */
883 {"port"},
884
885 /* SPLIT_TYPE_VF */
886 {"vf"}
887};
888
889/******************************** Variables **********************************/
890
891/* The version of the calling app */
892static u32 s_app_ver;
893
894/**************************** Private Functions ******************************/
895
896static void qed_static_asserts(void)
897{
898}
899
900/* Reads and returns a single dword from the specified unaligned buffer */
901static u32 qed_read_unaligned_dword(u8 *buf)
902{
903 u32 dword;
904
905 memcpy((u8 *)&dword, buf, sizeof(dword));
906 return dword;
907}
908
909/* Sets the value of the specified GRC param */
910static void qed_grc_set_param(struct qed_hwfn *p_hwfn,
911 enum dbg_grc_params grc_param, u32 val)
912{
913 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
914
915 dev_data->grc.param_val[grc_param] = val;
916}
917
918/* Returns the value of the specified GRC param */
919static u32 qed_grc_get_param(struct qed_hwfn *p_hwfn,
920 enum dbg_grc_params grc_param)
921{
922 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
923
924 return dev_data->grc.param_val[grc_param];
925}
926
927/* Initializes the GRC parameters */
928static void qed_dbg_grc_init_params(struct qed_hwfn *p_hwfn)
929{
930 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
931
932 if (!dev_data->grc.params_initialized) {
933 qed_dbg_grc_set_params_default(p_hwfn);
934 dev_data->grc.params_initialized = 1;
935 }
936}
937
938/* Sets pointer and size for the specified binary buffer type */
939static void qed_set_dbg_bin_buf(struct qed_hwfn *p_hwfn,
940 enum bin_dbg_buffer_type buf_type,
941 const u32 *ptr, u32 size)
942{
943 struct virt_mem_desc *buf = &p_hwfn->dbg_arrays[buf_type];
944
945 buf->ptr = (void *)ptr;
946 buf->size = size;
947}
948
949/* Initializes debug data for the specified device */
950static enum dbg_status qed_dbg_dev_init(struct qed_hwfn *p_hwfn)
951{
952 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
953 u8 num_pfs = 0, max_pfs_per_port = 0;
954
955 if (dev_data->initialized)
956 return DBG_STATUS_OK;
957
958 if (!s_app_ver)
959 return DBG_STATUS_APP_VERSION_NOT_SET;
960
961 /* Set chip */
962 if (QED_IS_K2(p_hwfn->cdev)) {
963 dev_data->chip_id = CHIP_K2;
964 dev_data->mode_enable[MODE_K2] = 1;
965 dev_data->num_vfs = MAX_NUM_VFS_K2;
966 num_pfs = MAX_NUM_PFS_K2;
967 max_pfs_per_port = MAX_NUM_PFS_K2 / 2;
968 } else if (QED_IS_BB_B0(p_hwfn->cdev)) {
969 dev_data->chip_id = CHIP_BB;
970 dev_data->mode_enable[MODE_BB] = 1;
971 dev_data->num_vfs = MAX_NUM_VFS_BB;
972 num_pfs = MAX_NUM_PFS_BB;
973 max_pfs_per_port = MAX_NUM_PFS_BB;
974 } else {
975 return DBG_STATUS_UNKNOWN_CHIP;
976 }
977
978 /* Set HW type */
979 dev_data->hw_type = HW_TYPE_ASIC;
980 dev_data->mode_enable[MODE_ASIC] = 1;
981
982 /* Set port mode */
983 switch (p_hwfn->cdev->num_ports_in_engine) {
984 case 1:
985 dev_data->mode_enable[MODE_PORTS_PER_ENG_1] = 1;
986 break;
987 case 2:
988 dev_data->mode_enable[MODE_PORTS_PER_ENG_2] = 1;
989 break;
990 case 4:
991 dev_data->mode_enable[MODE_PORTS_PER_ENG_4] = 1;
992 break;
993 }
994
995 /* Set 100G mode */
996 if (QED_IS_CMT(p_hwfn->cdev))
997 dev_data->mode_enable[MODE_100G] = 1;
998
999 /* Set number of ports */
1000 if (dev_data->mode_enable[MODE_PORTS_PER_ENG_1] ||
1001 dev_data->mode_enable[MODE_100G])
1002 dev_data->num_ports = 1;
1003 else if (dev_data->mode_enable[MODE_PORTS_PER_ENG_2])
1004 dev_data->num_ports = 2;
1005 else if (dev_data->mode_enable[MODE_PORTS_PER_ENG_4])
1006 dev_data->num_ports = 4;
1007
1008 /* Set number of PFs per port */
1009 dev_data->num_pfs_per_port = min_t(u32,
1010 num_pfs / dev_data->num_ports,
1011 max_pfs_per_port);
1012
1013 /* Initializes the GRC parameters */
1014 qed_dbg_grc_init_params(p_hwfn);
1015
1016 dev_data->use_dmae = true;
1017 dev_data->initialized = 1;
1018
1019 return DBG_STATUS_OK;
1020}
1021
1022static const struct dbg_block *get_dbg_block(struct qed_hwfn *p_hwfn,
1023 enum block_id block_id)
1024{
1025 const struct dbg_block *dbg_block;
1026
1027 dbg_block = p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS].ptr;
1028 return dbg_block + block_id;
1029}
1030
1031static const struct dbg_block_chip *qed_get_dbg_block_per_chip(struct qed_hwfn
1032 *p_hwfn,
1033 enum block_id
1034 block_id)
1035{
1036 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1037
1038 return (const struct dbg_block_chip *)
1039 p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS_CHIP_DATA].ptr +
1040 block_id * MAX_CHIP_IDS + dev_data->chip_id;
1041}
1042
1043static const struct dbg_reset_reg *qed_get_dbg_reset_reg(struct qed_hwfn
1044 *p_hwfn,
1045 u8 reset_reg_id)
1046{
1047 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1048
1049 return (const struct dbg_reset_reg *)
1050 p_hwfn->dbg_arrays[BIN_BUF_DBG_RESET_REGS].ptr +
1051 reset_reg_id * MAX_CHIP_IDS + dev_data->chip_id;
1052}
1053
1054/* Reads the FW info structure for the specified Storm from the chip,
1055 * and writes it to the specified fw_info pointer.
1056 */
1057static void qed_read_storm_fw_info(struct qed_hwfn *p_hwfn,
1058 struct qed_ptt *p_ptt,
1059 u8 storm_id, struct fw_info *fw_info)
1060{
1061 struct storm_defs *storm = &s_storm_defs[storm_id];
1062 struct fw_info_location fw_info_location;
1063 u32 addr, i, size, *dest;
1064
1065 memset(&fw_info_location, 0, sizeof(fw_info_location));
1066 memset(fw_info, 0, sizeof(*fw_info));
1067
1068 /* Read first the address that points to fw_info location.
1069 * The address is located in the last line of the Storm RAM.
1070 */
1071 addr = storm->sem_fast_mem_addr + SEM_FAST_REG_INT_RAM +
1072 DWORDS_TO_BYTES(SEM_FAST_REG_INT_RAM_SIZE) -
1073 sizeof(fw_info_location);
1074
1075 dest = (u32 *)&fw_info_location;
1076 size = BYTES_TO_DWORDS(sizeof(fw_info_location));
1077
1078 for (i = 0; i < size; i++, addr += BYTES_IN_DWORD)
1079 dest[i] = qed_rd(p_hwfn, p_ptt, addr);
1080
1081 /* Read FW version info from Storm RAM */
1082 size = le32_to_cpu(fw_info_location.size);
1083 if (!size || size > sizeof(*fw_info))
1084 return;
1085
1086 addr = le32_to_cpu(fw_info_location.grc_addr);
1087 dest = (u32 *)fw_info;
1088 size = BYTES_TO_DWORDS(size);
1089
1090 for (i = 0; i < size; i++, addr += BYTES_IN_DWORD)
1091 dest[i] = qed_rd(p_hwfn, p_ptt, addr);
1092}
1093
1094/* Dumps the specified string to the specified buffer.
1095 * Returns the dumped size in bytes.
1096 */
1097static u32 qed_dump_str(char *dump_buf, bool dump, const char *str)
1098{
1099 if (dump)
1100 strcpy(dump_buf, str);
1101
1102 return (u32)strlen(str) + 1;
1103}
1104
1105/* Dumps zeros to align the specified buffer to dwords.
1106 * Returns the dumped size in bytes.
1107 */
1108static u32 qed_dump_align(char *dump_buf, bool dump, u32 byte_offset)
1109{
1110 u8 offset_in_dword, align_size;
1111
1112 offset_in_dword = (u8)(byte_offset & 0x3);
1113 align_size = offset_in_dword ? BYTES_IN_DWORD - offset_in_dword : 0;
1114
1115 if (dump && align_size)
1116 memset(dump_buf, 0, align_size);
1117
1118 return align_size;
1119}
1120
1121/* Writes the specified string param to the specified buffer.
1122 * Returns the dumped size in dwords.
1123 */
1124static u32 qed_dump_str_param(u32 *dump_buf,
1125 bool dump,
1126 const char *param_name, const char *param_val)
1127{
1128 char *char_buf = (char *)dump_buf;
1129 u32 offset = 0;
1130
1131 /* Dump param name */
1132 offset += qed_dump_str(char_buf + offset, dump, param_name);
1133
1134 /* Indicate a string param value */
1135 if (dump)
1136 *(char_buf + offset) = 1;
1137 offset++;
1138
1139 /* Dump param value */
1140 offset += qed_dump_str(char_buf + offset, dump, param_val);
1141
1142 /* Align buffer to next dword */
1143 offset += qed_dump_align(char_buf + offset, dump, offset);
1144
1145 return BYTES_TO_DWORDS(offset);
1146}
1147
1148/* Writes the specified numeric param to the specified buffer.
1149 * Returns the dumped size in dwords.
1150 */
1151static u32 qed_dump_num_param(u32 *dump_buf,
1152 bool dump, const char *param_name, u32 param_val)
1153{
1154 char *char_buf = (char *)dump_buf;
1155 u32 offset = 0;
1156
1157 /* Dump param name */
1158 offset += qed_dump_str(char_buf + offset, dump, param_name);
1159
1160 /* Indicate a numeric param value */
1161 if (dump)
1162 *(char_buf + offset) = 0;
1163 offset++;
1164
1165 /* Align buffer to next dword */
1166 offset += qed_dump_align(char_buf + offset, dump, offset);
1167
1168 /* Dump param value (and change offset from bytes to dwords) */
1169 offset = BYTES_TO_DWORDS(offset);
1170 if (dump)
1171 *(dump_buf + offset) = param_val;
1172 offset++;
1173
1174 return offset;
1175}
1176
1177/* Reads the FW version and writes it as a param to the specified buffer.
1178 * Returns the dumped size in dwords.
1179 */
1180static u32 qed_dump_fw_ver_param(struct qed_hwfn *p_hwfn,
1181 struct qed_ptt *p_ptt,
1182 u32 *dump_buf, bool dump)
1183{
1184 char fw_ver_str[16] = EMPTY_FW_VERSION_STR;
1185 char fw_img_str[16] = EMPTY_FW_IMAGE_STR;
1186 struct fw_info fw_info = { {0}, {0} };
1187 u32 offset = 0;
1188
1189 if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
1190 /* Read FW info from chip */
1191 qed_read_fw_info(p_hwfn, p_ptt, &fw_info);
1192
1193 /* Create FW version/image strings */
1194 if (snprintf(fw_ver_str, sizeof(fw_ver_str),
1195 "%d_%d_%d_%d", fw_info.ver.num.major,
1196 fw_info.ver.num.minor, fw_info.ver.num.rev,
1197 fw_info.ver.num.eng) < 0)
1198 DP_NOTICE(p_hwfn,
1199 "Unexpected debug error: invalid FW version string\n");
1200 switch (fw_info.ver.image_id) {
1201 case FW_IMG_KUKU:
1202 strcpy(fw_img_str, "kuku");
1203 break;
1204 case FW_IMG_MAIN:
1205 strcpy(fw_img_str, "main");
1206 break;
1207 case FW_IMG_L2B:
1208 strcpy(fw_img_str, "l2b");
1209 break;
1210 default:
1211 strcpy(fw_img_str, "unknown");
1212 break;
1213 }
1214 }
1215
1216 /* Dump FW version, image and timestamp */
1217 offset += qed_dump_str_param(dump_buf + offset,
1218 dump, "fw-version", fw_ver_str);
1219 offset += qed_dump_str_param(dump_buf + offset,
1220 dump, "fw-image", fw_img_str);
1221 offset += qed_dump_num_param(dump_buf + offset, dump, "fw-timestamp",
1222 le32_to_cpu(fw_info.ver.timestamp));
1223
1224 return offset;
1225}
1226
1227/* Reads the MFW version and writes it as a param to the specified buffer.
1228 * Returns the dumped size in dwords.
1229 */
1230static u32 qed_dump_mfw_ver_param(struct qed_hwfn *p_hwfn,
1231 struct qed_ptt *p_ptt,
1232 u32 *dump_buf, bool dump)
1233{
1234 char mfw_ver_str[16] = EMPTY_FW_VERSION_STR;
1235
1236 if (dump &&
1237 !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
1238 u32 global_section_offsize, global_section_addr, mfw_ver;
1239 u32 public_data_addr, global_section_offsize_addr;
1240
1241 /* Find MCP public data GRC address. Needs to be ORed with
1242 * MCP_REG_SCRATCH due to a HW bug.
1243 */
1244 public_data_addr = qed_rd(p_hwfn,
1245 p_ptt,
1246 MISC_REG_SHARED_MEM_ADDR) |
1247 MCP_REG_SCRATCH;
1248
1249 /* Find MCP public global section offset */
1250 global_section_offsize_addr = public_data_addr +
1251 offsetof(struct mcp_public_data,
1252 sections) +
1253 sizeof(offsize_t) * PUBLIC_GLOBAL;
1254 global_section_offsize = qed_rd(p_hwfn, p_ptt,
1255 global_section_offsize_addr);
1256 global_section_addr =
1257 MCP_REG_SCRATCH +
1258 (global_section_offsize & OFFSIZE_OFFSET_MASK) * 4;
1259
1260 /* Read MFW version from MCP public global section */
1261 mfw_ver = qed_rd(p_hwfn, p_ptt,
1262 global_section_addr +
1263 offsetof(struct public_global, mfw_ver));
1264
1265 /* Dump MFW version param */
1266 if (snprintf(mfw_ver_str, sizeof(mfw_ver_str), "%d_%d_%d_%d",
1267 (u8)(mfw_ver >> 24), (u8)(mfw_ver >> 16),
1268 (u8)(mfw_ver >> 8), (u8)mfw_ver) < 0)
1269 DP_NOTICE(p_hwfn,
1270 "Unexpected debug error: invalid MFW version string\n");
1271 }
1272
1273 return qed_dump_str_param(dump_buf, dump, "mfw-version", mfw_ver_str);
1274}
1275
1276/* Reads the chip revision from the chip and writes it as a param to the
1277 * specified buffer. Returns the dumped size in dwords.
1278 */
1279static u32 qed_dump_chip_revision_param(struct qed_hwfn *p_hwfn,
1280 struct qed_ptt *p_ptt,
1281 u32 *dump_buf, bool dump)
1282{
1283 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1284 char param_str[3] = "??";
1285
1286 if (dev_data->hw_type == HW_TYPE_ASIC) {
1287 u32 chip_rev, chip_metal;
1288
1289 chip_rev = qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
1290 chip_metal = qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
1291
1292 param_str[0] = 'a' + (u8)chip_rev;
1293 param_str[1] = '0' + (u8)chip_metal;
1294 }
1295
1296 return qed_dump_str_param(dump_buf, dump, "chip-revision", param_str);
1297}
1298
1299/* Writes a section header to the specified buffer.
1300 * Returns the dumped size in dwords.
1301 */
1302static u32 qed_dump_section_hdr(u32 *dump_buf,
1303 bool dump, const char *name, u32 num_params)
1304{
1305 return qed_dump_num_param(dump_buf, dump, name, num_params);
1306}
1307
1308/* Writes the common global params to the specified buffer.
1309 * Returns the dumped size in dwords.
1310 */
1311static u32 qed_dump_common_global_params(struct qed_hwfn *p_hwfn,
1312 struct qed_ptt *p_ptt,
1313 u32 *dump_buf,
1314 bool dump,
1315 u8 num_specific_global_params)
1316{
1317 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1318 u32 offset = 0;
1319 u8 num_params;
1320
1321 /* Dump global params section header */
1322 num_params = NUM_COMMON_GLOBAL_PARAMS + num_specific_global_params +
1323 (dev_data->chip_id == CHIP_BB ? 1 : 0);
1324 offset += qed_dump_section_hdr(dump_buf + offset,
1325 dump, "global_params", num_params);
1326
1327 /* Store params */
1328 offset += qed_dump_fw_ver_param(p_hwfn, p_ptt, dump_buf + offset, dump);
1329 offset += qed_dump_mfw_ver_param(p_hwfn,
1330 p_ptt, dump_buf + offset, dump);
1331 offset += qed_dump_chip_revision_param(p_hwfn,
1332 p_ptt, dump_buf + offset, dump);
1333 offset += qed_dump_num_param(dump_buf + offset,
1334 dump, "tools-version", TOOLS_VERSION);
1335 offset += qed_dump_str_param(dump_buf + offset,
1336 dump,
1337 "chip",
1338 s_chip_defs[dev_data->chip_id].name);
1339 offset += qed_dump_str_param(dump_buf + offset,
1340 dump,
1341 "platform",
1342 s_hw_type_defs[dev_data->hw_type].name);
1343 offset += qed_dump_num_param(dump_buf + offset,
1344 dump, "pci-func", p_hwfn->abs_pf_id);
1345 offset += qed_dump_num_param(dump_buf + offset,
1346 dump, "epoch", qed_get_epoch_time());
1347 if (dev_data->chip_id == CHIP_BB)
1348 offset += qed_dump_num_param(dump_buf + offset,
1349 dump, "path", QED_PATH_ID(p_hwfn));
1350
1351 return offset;
1352}
1353
1354/* Writes the "last" section (including CRC) to the specified buffer at the
1355 * given offset. Returns the dumped size in dwords.
1356 */
1357static u32 qed_dump_last_section(u32 *dump_buf, u32 offset, bool dump)
1358{
1359 u32 start_offset = offset;
1360
1361 /* Dump CRC section header */
1362 offset += qed_dump_section_hdr(dump_buf + offset, dump, "last", 0);
1363
1364 /* Calculate CRC32 and add it to the dword after the "last" section */
1365 if (dump)
1366 *(dump_buf + offset) = ~crc32(0xffffffff,
1367 (u8 *)dump_buf,
1368 DWORDS_TO_BYTES(offset));
1369
1370 offset++;
1371
1372 return offset - start_offset;
1373}
1374
1375/* Update blocks reset state */
1376static void qed_update_blocks_reset_state(struct qed_hwfn *p_hwfn,
1377 struct qed_ptt *p_ptt)
1378{
1379 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1380 u32 reg_val[NUM_DBG_RESET_REGS] = { 0 };
1381 u8 rst_reg_id;
1382 u32 blk_id;
1383
1384 /* Read reset registers */
1385 for (rst_reg_id = 0; rst_reg_id < NUM_DBG_RESET_REGS; rst_reg_id++) {
1386 const struct dbg_reset_reg *rst_reg;
1387 bool rst_reg_removed;
1388 u32 rst_reg_addr;
1389
1390 rst_reg = qed_get_dbg_reset_reg(p_hwfn, rst_reg_id);
1391 rst_reg_removed = GET_FIELD(rst_reg->data,
1392 DBG_RESET_REG_IS_REMOVED);
1393 rst_reg_addr = DWORDS_TO_BYTES(GET_FIELD(rst_reg->data,
1394 DBG_RESET_REG_ADDR));
1395
1396 if (!rst_reg_removed)
1397 reg_val[rst_reg_id] = qed_rd(p_hwfn, p_ptt,
1398 rst_reg_addr);
1399 }
1400
1401 /* Check if blocks are in reset */
1402 for (blk_id = 0; blk_id < NUM_PHYS_BLOCKS; blk_id++) {
1403 const struct dbg_block_chip *blk;
1404 bool has_rst_reg;
1405 bool is_removed;
1406
1407 blk = qed_get_dbg_block_per_chip(p_hwfn, (enum block_id)blk_id);
1408 is_removed = GET_FIELD(blk->flags, DBG_BLOCK_CHIP_IS_REMOVED);
1409 has_rst_reg = GET_FIELD(blk->flags,
1410 DBG_BLOCK_CHIP_HAS_RESET_REG);
1411
1412 if (!is_removed && has_rst_reg)
1413 dev_data->block_in_reset[blk_id] =
1414 !(reg_val[blk->reset_reg_id] &
1415 BIT(blk->reset_reg_bit_offset));
1416 }
1417}
1418
1419/* is_mode_match recursive function */
1420static bool qed_is_mode_match_rec(struct qed_hwfn *p_hwfn,
1421 u16 *modes_buf_offset, u8 rec_depth)
1422{
1423 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1424 u8 *dbg_array;
1425 bool arg1, arg2;
1426 u8 tree_val;
1427
1428 if (rec_depth > MAX_RECURSION_DEPTH) {
1429 DP_NOTICE(p_hwfn,
1430 "Unexpected error: is_mode_match_rec exceeded the max recursion depth. This is probably due to a corrupt init/debug buffer.\n");
1431 return false;
1432 }
1433
1434 /* Get next element from modes tree buffer */
1435 dbg_array = p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr;
1436 tree_val = dbg_array[(*modes_buf_offset)++];
1437
1438 switch (tree_val) {
1439 case INIT_MODE_OP_NOT:
1440 return !qed_is_mode_match_rec(p_hwfn,
1441 modes_buf_offset, rec_depth + 1);
1442 case INIT_MODE_OP_OR:
1443 case INIT_MODE_OP_AND:
1444 arg1 = qed_is_mode_match_rec(p_hwfn,
1445 modes_buf_offset, rec_depth + 1);
1446 arg2 = qed_is_mode_match_rec(p_hwfn,
1447 modes_buf_offset, rec_depth + 1);
1448 return (tree_val == INIT_MODE_OP_OR) ? (arg1 ||
1449 arg2) : (arg1 && arg2);
1450 default:
1451 return dev_data->mode_enable[tree_val - MAX_INIT_MODE_OPS] > 0;
1452 }
1453}
1454
1455/* Returns true if the mode (specified using modes_buf_offset) is enabled */
1456static bool qed_is_mode_match(struct qed_hwfn *p_hwfn, u16 *modes_buf_offset)
1457{
1458 return qed_is_mode_match_rec(p_hwfn, modes_buf_offset, 0);
1459}
1460
1461/* Enable / disable the Debug block */
1462static void qed_bus_enable_dbg_block(struct qed_hwfn *p_hwfn,
1463 struct qed_ptt *p_ptt, bool enable)
1464{
1465 qed_wr(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON, enable ? 1 : 0);
1466}
1467
1468/* Resets the Debug block */
1469static void qed_bus_reset_dbg_block(struct qed_hwfn *p_hwfn,
1470 struct qed_ptt *p_ptt)
1471{
1472 u32 reset_reg_addr, old_reset_reg_val, new_reset_reg_val;
1473 const struct dbg_reset_reg *reset_reg;
1474 const struct dbg_block_chip *block;
1475
1476 block = qed_get_dbg_block_per_chip(p_hwfn, BLOCK_DBG);
1477 reset_reg = qed_get_dbg_reset_reg(p_hwfn, block->reset_reg_id);
1478 reset_reg_addr =
1479 DWORDS_TO_BYTES(GET_FIELD(reset_reg->data, DBG_RESET_REG_ADDR));
1480
1481 old_reset_reg_val = qed_rd(p_hwfn, p_ptt, reset_reg_addr);
1482 new_reset_reg_val =
1483 old_reset_reg_val & ~BIT(block->reset_reg_bit_offset);
1484
1485 qed_wr(p_hwfn, p_ptt, reset_reg_addr, new_reset_reg_val);
1486 qed_wr(p_hwfn, p_ptt, reset_reg_addr, old_reset_reg_val);
1487}
1488
1489/* Enable / disable Debug Bus clients according to the specified mask
1490 * (1 = enable, 0 = disable).
1491 */
1492static void qed_bus_enable_clients(struct qed_hwfn *p_hwfn,
1493 struct qed_ptt *p_ptt, u32 client_mask)
1494{
1495 qed_wr(p_hwfn, p_ptt, DBG_REG_CLIENT_ENABLE, client_mask);
1496}
1497
1498static void qed_bus_config_dbg_line(struct qed_hwfn *p_hwfn,
1499 struct qed_ptt *p_ptt,
1500 enum block_id block_id,
1501 u8 line_id,
1502 u8 enable_mask,
1503 u8 right_shift,
1504 u8 force_valid_mask, u8 force_frame_mask)
1505{
1506 const struct dbg_block_chip *block =
1507 qed_get_dbg_block_per_chip(p_hwfn, block_id);
1508
1509 qed_wr(p_hwfn, p_ptt, DWORDS_TO_BYTES(block->dbg_select_reg_addr),
1510 line_id);
1511 qed_wr(p_hwfn, p_ptt, DWORDS_TO_BYTES(block->dbg_dword_enable_reg_addr),
1512 enable_mask);
1513 qed_wr(p_hwfn, p_ptt, DWORDS_TO_BYTES(block->dbg_shift_reg_addr),
1514 right_shift);
1515 qed_wr(p_hwfn, p_ptt, DWORDS_TO_BYTES(block->dbg_force_valid_reg_addr),
1516 force_valid_mask);
1517 qed_wr(p_hwfn, p_ptt, DWORDS_TO_BYTES(block->dbg_force_frame_reg_addr),
1518 force_frame_mask);
1519}
1520
1521/* Disable debug bus in all blocks */
1522static void qed_bus_disable_blocks(struct qed_hwfn *p_hwfn,
1523 struct qed_ptt *p_ptt)
1524{
1525 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1526 u32 block_id;
1527
1528 /* Disable all blocks */
1529 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
1530 const struct dbg_block_chip *block_per_chip =
1531 qed_get_dbg_block_per_chip(p_hwfn,
1532 (enum block_id)block_id);
1533
1534 if (GET_FIELD(block_per_chip->flags,
1535 DBG_BLOCK_CHIP_IS_REMOVED) ||
1536 dev_data->block_in_reset[block_id])
1537 continue;
1538
1539 /* Disable debug bus */
1540 if (GET_FIELD(block_per_chip->flags,
1541 DBG_BLOCK_CHIP_HAS_DBG_BUS)) {
1542 u32 dbg_en_addr =
1543 block_per_chip->dbg_dword_enable_reg_addr;
1544 u16 modes_buf_offset =
1545 GET_FIELD(block_per_chip->dbg_bus_mode.data,
1546 DBG_MODE_HDR_MODES_BUF_OFFSET);
1547 bool eval_mode =
1548 GET_FIELD(block_per_chip->dbg_bus_mode.data,
1549 DBG_MODE_HDR_EVAL_MODE) > 0;
1550
1551 if (!eval_mode ||
1552 qed_is_mode_match(p_hwfn, &modes_buf_offset))
1553 qed_wr(p_hwfn, p_ptt,
1554 DWORDS_TO_BYTES(dbg_en_addr),
1555 0);
1556 }
1557 }
1558}
1559
1560/* Returns true if the specified entity (indicated by GRC param) should be
1561 * included in the dump, false otherwise.
1562 */
1563static bool qed_grc_is_included(struct qed_hwfn *p_hwfn,
1564 enum dbg_grc_params grc_param)
1565{
1566 return qed_grc_get_param(p_hwfn, grc_param) > 0;
1567}
1568
1569/* Returns the storm_id that matches the specified Storm letter,
1570 * or MAX_DBG_STORMS if invalid storm letter.
1571 */
1572static enum dbg_storms qed_get_id_from_letter(char storm_letter)
1573{
1574 u8 storm_id;
1575
1576 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++)
1577 if (s_storm_defs[storm_id].letter == storm_letter)
1578 return (enum dbg_storms)storm_id;
1579
1580 return MAX_DBG_STORMS;
1581}
1582
1583/* Returns true of the specified Storm should be included in the dump, false
1584 * otherwise.
1585 */
1586static bool qed_grc_is_storm_included(struct qed_hwfn *p_hwfn,
1587 enum dbg_storms storm)
1588{
1589 return qed_grc_get_param(p_hwfn, (enum dbg_grc_params)storm) > 0;
1590}
1591
1592/* Returns true if the specified memory should be included in the dump, false
1593 * otherwise.
1594 */
1595static bool qed_grc_is_mem_included(struct qed_hwfn *p_hwfn,
1596 enum block_id block_id, u8 mem_group_id)
1597{
1598 const struct dbg_block *block;
1599 u8 i;
1600
1601 block = get_dbg_block(p_hwfn, block_id);
1602
1603 /* If the block is associated with a Storm, check Storm match */
1604 if (block->associated_storm_letter) {
1605 enum dbg_storms associated_storm_id =
1606 qed_get_id_from_letter(block->associated_storm_letter);
1607
1608 if (associated_storm_id == MAX_DBG_STORMS ||
1609 !qed_grc_is_storm_included(p_hwfn, associated_storm_id))
1610 return false;
1611 }
1612
1613 for (i = 0; i < NUM_BIG_RAM_TYPES; i++) {
1614 struct big_ram_defs *big_ram = &s_big_ram_defs[i];
1615
1616 if (mem_group_id == big_ram->mem_group_id ||
1617 mem_group_id == big_ram->ram_mem_group_id)
1618 return qed_grc_is_included(p_hwfn, big_ram->grc_param);
1619 }
1620
1621 switch (mem_group_id) {
1622 case MEM_GROUP_PXP_ILT:
1623 case MEM_GROUP_PXP_MEM:
1624 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PXP);
1625 case MEM_GROUP_RAM:
1626 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RAM);
1627 case MEM_GROUP_PBUF:
1628 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PBUF);
1629 case MEM_GROUP_CAU_MEM:
1630 case MEM_GROUP_CAU_SB:
1631 case MEM_GROUP_CAU_PI:
1632 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CAU);
1633 case MEM_GROUP_CAU_MEM_EXT:
1634 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CAU_EXT);
1635 case MEM_GROUP_QM_MEM:
1636 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_QM);
1637 case MEM_GROUP_CFC_MEM:
1638 case MEM_GROUP_CONN_CFC_MEM:
1639 case MEM_GROUP_TASK_CFC_MEM:
1640 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CFC) ||
1641 qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX);
1642 case MEM_GROUP_DORQ_MEM:
1643 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DORQ);
1644 case MEM_GROUP_IGU_MEM:
1645 case MEM_GROUP_IGU_MSIX:
1646 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IGU);
1647 case MEM_GROUP_MULD_MEM:
1648 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MULD);
1649 case MEM_GROUP_PRS_MEM:
1650 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PRS);
1651 case MEM_GROUP_DMAE_MEM:
1652 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DMAE);
1653 case MEM_GROUP_TM_MEM:
1654 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_TM);
1655 case MEM_GROUP_SDM_MEM:
1656 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_SDM);
1657 case MEM_GROUP_TDIF_CTX:
1658 case MEM_GROUP_RDIF_CTX:
1659 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DIF);
1660 case MEM_GROUP_CM_MEM:
1661 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM);
1662 case MEM_GROUP_IOR:
1663 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IOR);
1664 default:
1665 return true;
1666 }
1667}
1668
1669/* Stalls all Storms */
1670static void qed_grc_stall_storms(struct qed_hwfn *p_hwfn,
1671 struct qed_ptt *p_ptt, bool stall)
1672{
1673 u32 reg_addr;
1674 u8 storm_id;
1675
1676 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
1677 if (!qed_grc_is_storm_included(p_hwfn,
1678 (enum dbg_storms)storm_id))
1679 continue;
1680
1681 reg_addr = s_storm_defs[storm_id].sem_fast_mem_addr +
1682 SEM_FAST_REG_STALL_0;
1683 qed_wr(p_hwfn, p_ptt, reg_addr, stall ? 1 : 0);
1684 }
1685
1686 msleep(STALL_DELAY_MS);
1687}
1688
1689/* Takes all blocks out of reset. If rbc_only is true, only RBC clients are
1690 * taken out of reset.
1691 */
1692static void qed_grc_unreset_blocks(struct qed_hwfn *p_hwfn,
1693 struct qed_ptt *p_ptt, bool rbc_only)
1694{
1695 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1696 u8 chip_id = dev_data->chip_id;
1697 u32 i;
1698
1699 /* Take RBCs out of reset */
1700 for (i = 0; i < ARRAY_SIZE(s_rbc_reset_defs); i++)
1701 if (s_rbc_reset_defs[i].reset_val[dev_data->chip_id])
1702 qed_wr(p_hwfn,
1703 p_ptt,
1704 s_rbc_reset_defs[i].reset_reg_addr +
1705 RESET_REG_UNRESET_OFFSET,
1706 s_rbc_reset_defs[i].reset_val[chip_id]);
1707
1708 if (!rbc_only) {
1709 u32 reg_val[NUM_DBG_RESET_REGS] = { 0 };
1710 u8 reset_reg_id;
1711 u32 block_id;
1712
1713 /* Fill reset regs values */
1714 for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
1715 bool is_removed, has_reset_reg, unreset_before_dump;
1716 const struct dbg_block_chip *block;
1717
1718 block = qed_get_dbg_block_per_chip(p_hwfn,
1719 (enum block_id)
1720 block_id);
1721 is_removed =
1722 GET_FIELD(block->flags, DBG_BLOCK_CHIP_IS_REMOVED);
1723 has_reset_reg =
1724 GET_FIELD(block->flags,
1725 DBG_BLOCK_CHIP_HAS_RESET_REG);
1726 unreset_before_dump =
1727 GET_FIELD(block->flags,
1728 DBG_BLOCK_CHIP_UNRESET_BEFORE_DUMP);
1729
1730 if (!is_removed && has_reset_reg && unreset_before_dump)
1731 reg_val[block->reset_reg_id] |=
1732 BIT(block->reset_reg_bit_offset);
1733 }
1734
1735 /* Write reset registers */
1736 for (reset_reg_id = 0; reset_reg_id < NUM_DBG_RESET_REGS;
1737 reset_reg_id++) {
1738 const struct dbg_reset_reg *reset_reg;
1739 u32 reset_reg_addr;
1740
1741 reset_reg = qed_get_dbg_reset_reg(p_hwfn, reset_reg_id);
1742
1743 if (GET_FIELD
1744 (reset_reg->data, DBG_RESET_REG_IS_REMOVED))
1745 continue;
1746
1747 if (reg_val[reset_reg_id]) {
1748 reset_reg_addr =
1749 GET_FIELD(reset_reg->data,
1750 DBG_RESET_REG_ADDR);
1751 qed_wr(p_hwfn,
1752 p_ptt,
1753 DWORDS_TO_BYTES(reset_reg_addr) +
1754 RESET_REG_UNRESET_OFFSET,
1755 reg_val[reset_reg_id]);
1756 }
1757 }
1758 }
1759}
1760
1761/* Returns the attention block data of the specified block */
1762static const struct dbg_attn_block_type_data *
1763qed_get_block_attn_data(struct qed_hwfn *p_hwfn,
1764 enum block_id block_id, enum dbg_attn_type attn_type)
1765{
1766 const struct dbg_attn_block *base_attn_block_arr =
1767 (const struct dbg_attn_block *)
1768 p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr;
1769
1770 return &base_attn_block_arr[block_id].per_type_data[attn_type];
1771}
1772
1773/* Returns the attention registers of the specified block */
1774static const struct dbg_attn_reg *
1775qed_get_block_attn_regs(struct qed_hwfn *p_hwfn,
1776 enum block_id block_id, enum dbg_attn_type attn_type,
1777 u8 *num_attn_regs)
1778{
1779 const struct dbg_attn_block_type_data *block_type_data =
1780 qed_get_block_attn_data(p_hwfn, block_id, attn_type);
1781
1782 *num_attn_regs = block_type_data->num_regs;
1783
1784 return (const struct dbg_attn_reg *)
1785 p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr +
1786 block_type_data->regs_offset;
1787}
1788
1789/* For each block, clear the status of all parities */
1790static void qed_grc_clear_all_prty(struct qed_hwfn *p_hwfn,
1791 struct qed_ptt *p_ptt)
1792{
1793 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1794 const struct dbg_attn_reg *attn_reg_arr;
1795 u32 block_id, sts_clr_address;
1796 u8 reg_idx, num_attn_regs;
1797
1798 for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
1799 if (dev_data->block_in_reset[block_id])
1800 continue;
1801
1802 attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
1803 (enum block_id)block_id,
1804 ATTN_TYPE_PARITY,
1805 &num_attn_regs);
1806
1807 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
1808 const struct dbg_attn_reg *reg_data =
1809 &attn_reg_arr[reg_idx];
1810 u16 modes_buf_offset;
1811 bool eval_mode;
1812
1813 /* Check mode */
1814 eval_mode = GET_FIELD(reg_data->mode.data,
1815 DBG_MODE_HDR_EVAL_MODE) > 0;
1816 modes_buf_offset =
1817 GET_FIELD(reg_data->mode.data,
1818 DBG_MODE_HDR_MODES_BUF_OFFSET);
1819
1820 sts_clr_address = reg_data->sts_clr_address;
1821 /* If Mode match: clear parity status */
1822 if (!eval_mode ||
1823 qed_is_mode_match(p_hwfn, &modes_buf_offset))
1824 qed_rd(p_hwfn, p_ptt,
1825 DWORDS_TO_BYTES(sts_clr_address));
1826 }
1827 }
1828}
1829
1830/* Finds the meta data image in NVRAM */
1831static enum dbg_status qed_find_nvram_image(struct qed_hwfn *p_hwfn,
1832 struct qed_ptt *p_ptt,
1833 u32 image_type,
1834 u32 *nvram_offset_bytes,
1835 u32 *nvram_size_bytes,
1836 bool b_can_sleep)
1837{
1838 u32 ret_mcp_resp, ret_mcp_param, ret_txn_size;
1839 struct mcp_file_att file_att;
1840 int nvm_result;
1841
1842 /* Call NVRAM get file command */
1843 nvm_result = qed_mcp_nvm_rd_cmd(p_hwfn,
1844 p_ptt,
1845 DRV_MSG_CODE_NVM_GET_FILE_ATT,
1846 image_type,
1847 &ret_mcp_resp,
1848 &ret_mcp_param,
1849 &ret_txn_size,
1850 (u32 *)&file_att,
1851 b_can_sleep);
1852
1853 /* Check response */
1854 if (nvm_result || (ret_mcp_resp & FW_MSG_CODE_MASK) !=
1855 FW_MSG_CODE_NVM_OK)
1856 return DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
1857
1858 /* Update return values */
1859 *nvram_offset_bytes = file_att.nvm_start_addr;
1860 *nvram_size_bytes = file_att.len;
1861
1862 DP_VERBOSE(p_hwfn,
1863 QED_MSG_DEBUG,
1864 "find_nvram_image: found NVRAM image of type %d in NVRAM offset %d bytes with size %d bytes\n",
1865 image_type, *nvram_offset_bytes, *nvram_size_bytes);
1866
1867 /* Check alignment */
1868 if (*nvram_size_bytes & 0x3)
1869 return DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE;
1870
1871 return DBG_STATUS_OK;
1872}
1873
1874/* Reads data from NVRAM */
1875static enum dbg_status qed_nvram_read(struct qed_hwfn *p_hwfn,
1876 struct qed_ptt *p_ptt,
1877 u32 nvram_offset_bytes,
1878 u32 nvram_size_bytes,
1879 u32 *ret_buf,
1880 bool b_can_sleep)
1881{
1882 u32 ret_mcp_resp, ret_mcp_param, ret_read_size, bytes_to_copy;
1883 s32 bytes_left = nvram_size_bytes;
1884 u32 read_offset = 0, param = 0;
1885
1886 DP_VERBOSE(p_hwfn,
1887 QED_MSG_DEBUG,
1888 "nvram_read: reading image of size %d bytes from NVRAM\n",
1889 nvram_size_bytes);
1890
1891 do {
1892 bytes_to_copy =
1893 (bytes_left >
1894 MCP_DRV_NVM_BUF_LEN) ? MCP_DRV_NVM_BUF_LEN : bytes_left;
1895
1896 /* Call NVRAM read command */
1897 SET_MFW_FIELD(param,
1898 DRV_MB_PARAM_NVM_OFFSET,
1899 nvram_offset_bytes + read_offset);
1900 SET_MFW_FIELD(param, DRV_MB_PARAM_NVM_LEN, bytes_to_copy);
1901 if (qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
1902 DRV_MSG_CODE_NVM_READ_NVRAM, param,
1903 &ret_mcp_resp,
1904 &ret_mcp_param, &ret_read_size,
1905 (u32 *)((u8 *)ret_buf + read_offset),
1906 b_can_sleep))
1907 return DBG_STATUS_NVRAM_READ_FAILED;
1908
1909 /* Check response */
1910 if ((ret_mcp_resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
1911 return DBG_STATUS_NVRAM_READ_FAILED;
1912
1913 /* Update read offset */
1914 read_offset += ret_read_size;
1915 bytes_left -= ret_read_size;
1916 } while (bytes_left > 0);
1917
1918 return DBG_STATUS_OK;
1919}
1920
1921/* Dumps GRC registers section header. Returns the dumped size in dwords.
1922 * the following parameters are dumped:
1923 * - count: no. of dumped entries
1924 * - split_type: split type
1925 * - split_id: split ID (dumped only if split_id != SPLIT_TYPE_NONE)
1926 * - reg_type_name: register type name (dumped only if reg_type_name != NULL)
1927 */
1928static u32 qed_grc_dump_regs_hdr(u32 *dump_buf,
1929 bool dump,
1930 u32 num_reg_entries,
1931 enum init_split_types split_type,
1932 u8 split_id, const char *reg_type_name)
1933{
1934 u8 num_params = 2 +
1935 (split_type != SPLIT_TYPE_NONE ? 1 : 0) + (reg_type_name ? 1 : 0);
1936 u32 offset = 0;
1937
1938 offset += qed_dump_section_hdr(dump_buf + offset,
1939 dump, "grc_regs", num_params);
1940 offset += qed_dump_num_param(dump_buf + offset,
1941 dump, "count", num_reg_entries);
1942 offset += qed_dump_str_param(dump_buf + offset,
1943 dump, "split",
1944 s_split_type_defs[split_type].name);
1945 if (split_type != SPLIT_TYPE_NONE)
1946 offset += qed_dump_num_param(dump_buf + offset,
1947 dump, "id", split_id);
1948 if (reg_type_name)
1949 offset += qed_dump_str_param(dump_buf + offset,
1950 dump, "type", reg_type_name);
1951
1952 return offset;
1953}
1954
1955/* Reads the specified registers into the specified buffer.
1956 * The addr and len arguments are specified in dwords.
1957 */
1958void qed_read_regs(struct qed_hwfn *p_hwfn,
1959 struct qed_ptt *p_ptt, u32 *buf, u32 addr, u32 len)
1960{
1961 u32 i;
1962
1963 for (i = 0; i < len; i++)
1964 buf[i] = qed_rd(p_hwfn, p_ptt, DWORDS_TO_BYTES(addr + i));
1965}
1966
1967/* Dumps the GRC registers in the specified address range.
1968 * Returns the dumped size in dwords.
1969 * The addr and len arguments are specified in dwords.
1970 */
1971static u32 qed_grc_dump_addr_range(struct qed_hwfn *p_hwfn,
1972 struct qed_ptt *p_ptt,
1973 u32 *dump_buf,
1974 bool dump, u32 addr, u32 len, bool wide_bus,
1975 enum init_split_types split_type,
1976 u8 split_id)
1977{
1978 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1979 u8 port_id = 0, pf_id = 0, vf_id = 0;
1980 bool read_using_dmae = false;
1981 u32 thresh;
1982 u16 fid;
1983
1984 if (!dump)
1985 return len;
1986
1987 switch (split_type) {
1988 case SPLIT_TYPE_PORT:
1989 port_id = split_id;
1990 break;
1991 case SPLIT_TYPE_PF:
1992 pf_id = split_id;
1993 break;
1994 case SPLIT_TYPE_PORT_PF:
1995 port_id = split_id / dev_data->num_pfs_per_port;
1996 pf_id = port_id + dev_data->num_ports *
1997 (split_id % dev_data->num_pfs_per_port);
1998 break;
1999 case SPLIT_TYPE_VF:
2000 vf_id = split_id;
2001 break;
2002 default:
2003 break;
2004 }
2005
2006 /* Try reading using DMAE */
2007 if (dev_data->use_dmae && split_type != SPLIT_TYPE_VF &&
2008 (len >= s_hw_type_defs[dev_data->hw_type].dmae_thresh ||
2009 (PROTECT_WIDE_BUS && wide_bus))) {
2010 struct qed_dmae_params dmae_params;
2011
2012 /* Set DMAE params */
2013 memset(&dmae_params, 0, sizeof(dmae_params));
2014 SET_FIELD(dmae_params.flags, QED_DMAE_PARAMS_COMPLETION_DST, 1);
2015 switch (split_type) {
2016 case SPLIT_TYPE_PORT:
2017 SET_FIELD(dmae_params.flags, QED_DMAE_PARAMS_PORT_VALID,
2018 1);
2019 dmae_params.port_id = port_id;
2020 break;
2021 case SPLIT_TYPE_PF:
2022 SET_FIELD(dmae_params.flags,
2023 QED_DMAE_PARAMS_SRC_PF_VALID, 1);
2024 dmae_params.src_pfid = pf_id;
2025 break;
2026 case SPLIT_TYPE_PORT_PF:
2027 SET_FIELD(dmae_params.flags, QED_DMAE_PARAMS_PORT_VALID,
2028 1);
2029 SET_FIELD(dmae_params.flags,
2030 QED_DMAE_PARAMS_SRC_PF_VALID, 1);
2031 dmae_params.port_id = port_id;
2032 dmae_params.src_pfid = pf_id;
2033 break;
2034 default:
2035 break;
2036 }
2037
2038 /* Execute DMAE command */
2039 read_using_dmae = !qed_dmae_grc2host(p_hwfn,
2040 p_ptt,
2041 DWORDS_TO_BYTES(addr),
2042 (u64)(uintptr_t)(dump_buf),
2043 len, &dmae_params);
2044 if (!read_using_dmae) {
2045 dev_data->use_dmae = 0;
2046 DP_VERBOSE(p_hwfn,
2047 QED_MSG_DEBUG,
2048 "Failed reading from chip using DMAE, using GRC instead\n");
2049 }
2050 }
2051
2052 if (read_using_dmae)
2053 goto print_log;
2054
2055 /* If not read using DMAE, read using GRC */
2056
2057 /* Set pretend */
2058 if (split_type != dev_data->pretend.split_type ||
2059 split_id != dev_data->pretend.split_id) {
2060 switch (split_type) {
2061 case SPLIT_TYPE_PORT:
2062 qed_port_pretend(p_hwfn, p_ptt, port_id);
2063 break;
2064 case SPLIT_TYPE_PF:
2065 fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
2066 pf_id);
2067 qed_fid_pretend(p_hwfn, p_ptt, fid);
2068 break;
2069 case SPLIT_TYPE_PORT_PF:
2070 fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
2071 pf_id);
2072 qed_port_fid_pretend(p_hwfn, p_ptt, port_id, fid);
2073 break;
2074 case SPLIT_TYPE_VF:
2075 fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_VFVALID, 1)
2076 | FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_VFID,
2077 vf_id);
2078 qed_fid_pretend(p_hwfn, p_ptt, fid);
2079 break;
2080 default:
2081 break;
2082 }
2083
2084 dev_data->pretend.split_type = (u8)split_type;
2085 dev_data->pretend.split_id = split_id;
2086 }
2087
2088 /* Read registers using GRC */
2089 qed_read_regs(p_hwfn, p_ptt, dump_buf, addr, len);
2090
2091print_log:
2092 /* Print log */
2093 dev_data->num_regs_read += len;
2094 thresh = s_hw_type_defs[dev_data->hw_type].log_thresh;
2095 if ((dev_data->num_regs_read / thresh) >
2096 ((dev_data->num_regs_read - len) / thresh))
2097 DP_VERBOSE(p_hwfn,
2098 QED_MSG_DEBUG,
2099 "Dumped %d registers...\n", dev_data->num_regs_read);
2100
2101 return len;
2102}
2103
2104/* Dumps GRC registers sequence header. Returns the dumped size in dwords.
2105 * The addr and len arguments are specified in dwords.
2106 */
2107static u32 qed_grc_dump_reg_entry_hdr(u32 *dump_buf,
2108 bool dump, u32 addr, u32 len)
2109{
2110 if (dump)
2111 *dump_buf = addr | (len << REG_DUMP_LEN_SHIFT);
2112
2113 return 1;
2114}
2115
2116/* Dumps GRC registers sequence. Returns the dumped size in dwords.
2117 * The addr and len arguments are specified in dwords.
2118 */
2119static u32 qed_grc_dump_reg_entry(struct qed_hwfn *p_hwfn,
2120 struct qed_ptt *p_ptt,
2121 u32 *dump_buf,
2122 bool dump, u32 addr, u32 len, bool wide_bus,
2123 enum init_split_types split_type, u8 split_id)
2124{
2125 u32 offset = 0;
2126
2127 offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, len);
2128 offset += qed_grc_dump_addr_range(p_hwfn,
2129 p_ptt,
2130 dump_buf + offset,
2131 dump, addr, len, wide_bus,
2132 split_type, split_id);
2133
2134 return offset;
2135}
2136
2137/* Dumps GRC registers sequence with skip cycle.
2138 * Returns the dumped size in dwords.
2139 * - addr: start GRC address in dwords
2140 * - total_len: total no. of dwords to dump
2141 * - read_len: no. consecutive dwords to read
2142 * - skip_len: no. of dwords to skip (and fill with zeros)
2143 */
2144static u32 qed_grc_dump_reg_entry_skip(struct qed_hwfn *p_hwfn,
2145 struct qed_ptt *p_ptt,
2146 u32 *dump_buf,
2147 bool dump,
2148 u32 addr,
2149 u32 total_len,
2150 u32 read_len, u32 skip_len)
2151{
2152 u32 offset = 0, reg_offset = 0;
2153
2154 offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, total_len);
2155
2156 if (!dump)
2157 return offset + total_len;
2158
2159 while (reg_offset < total_len) {
2160 u32 curr_len = min_t(u32, read_len, total_len - reg_offset);
2161
2162 offset += qed_grc_dump_addr_range(p_hwfn,
2163 p_ptt,
2164 dump_buf + offset,
2165 dump, addr, curr_len, false,
2166 SPLIT_TYPE_NONE, 0);
2167 reg_offset += curr_len;
2168 addr += curr_len;
2169
2170 if (reg_offset < total_len) {
2171 curr_len = min_t(u32, skip_len, total_len - skip_len);
2172 memset(dump_buf + offset, 0, DWORDS_TO_BYTES(curr_len));
2173 offset += curr_len;
2174 reg_offset += curr_len;
2175 addr += curr_len;
2176 }
2177 }
2178
2179 return offset;
2180}
2181
2182/* Dumps GRC registers entries. Returns the dumped size in dwords. */
2183static u32 qed_grc_dump_regs_entries(struct qed_hwfn *p_hwfn,
2184 struct qed_ptt *p_ptt,
2185 struct virt_mem_desc input_regs_arr,
2186 u32 *dump_buf,
2187 bool dump,
2188 enum init_split_types split_type,
2189 u8 split_id,
2190 bool block_enable[MAX_BLOCK_ID],
2191 u32 *num_dumped_reg_entries)
2192{
2193 u32 i, offset = 0, input_offset = 0;
2194 bool mode_match = true;
2195
2196 *num_dumped_reg_entries = 0;
2197
2198 while (input_offset < BYTES_TO_DWORDS(input_regs_arr.size)) {
2199 const struct dbg_dump_cond_hdr *cond_hdr =
2200 (const struct dbg_dump_cond_hdr *)
2201 input_regs_arr.ptr + input_offset++;
2202 u16 modes_buf_offset;
2203 bool eval_mode;
2204
2205 /* Check mode/block */
2206 eval_mode = GET_FIELD(cond_hdr->mode.data,
2207 DBG_MODE_HDR_EVAL_MODE) > 0;
2208 if (eval_mode) {
2209 modes_buf_offset =
2210 GET_FIELD(cond_hdr->mode.data,
2211 DBG_MODE_HDR_MODES_BUF_OFFSET);
2212 mode_match = qed_is_mode_match(p_hwfn,
2213 &modes_buf_offset);
2214 }
2215
2216 if (!mode_match || !block_enable[cond_hdr->block_id]) {
2217 input_offset += cond_hdr->data_size;
2218 continue;
2219 }
2220
2221 for (i = 0; i < cond_hdr->data_size; i++, input_offset++) {
2222 const struct dbg_dump_reg *reg =
2223 (const struct dbg_dump_reg *)
2224 input_regs_arr.ptr + input_offset;
2225 u32 addr, len;
2226 bool wide_bus;
2227
2228 addr = GET_FIELD(reg->data, DBG_DUMP_REG_ADDRESS);
2229 len = GET_FIELD(reg->data, DBG_DUMP_REG_LENGTH);
2230 wide_bus = GET_FIELD(reg->data, DBG_DUMP_REG_WIDE_BUS);
2231 offset += qed_grc_dump_reg_entry(p_hwfn,
2232 p_ptt,
2233 dump_buf + offset,
2234 dump,
2235 addr,
2236 len,
2237 wide_bus,
2238 split_type, split_id);
2239 (*num_dumped_reg_entries)++;
2240 }
2241 }
2242
2243 return offset;
2244}
2245
2246/* Dumps GRC registers entries. Returns the dumped size in dwords. */
2247static u32 qed_grc_dump_split_data(struct qed_hwfn *p_hwfn,
2248 struct qed_ptt *p_ptt,
2249 struct virt_mem_desc input_regs_arr,
2250 u32 *dump_buf,
2251 bool dump,
2252 bool block_enable[MAX_BLOCK_ID],
2253 enum init_split_types split_type,
2254 u8 split_id, const char *reg_type_name)
2255{
2256 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2257 enum init_split_types hdr_split_type = split_type;
2258 u32 num_dumped_reg_entries, offset;
2259 u8 hdr_split_id = split_id;
2260
2261 /* In PORT_PF split type, print a port split header */
2262 if (split_type == SPLIT_TYPE_PORT_PF) {
2263 hdr_split_type = SPLIT_TYPE_PORT;
2264 hdr_split_id = split_id / dev_data->num_pfs_per_port;
2265 }
2266
2267 /* Calculate register dump header size (and skip it for now) */
2268 offset = qed_grc_dump_regs_hdr(dump_buf,
2269 false,
2270 0,
2271 hdr_split_type,
2272 hdr_split_id, reg_type_name);
2273
2274 /* Dump registers */
2275 offset += qed_grc_dump_regs_entries(p_hwfn,
2276 p_ptt,
2277 input_regs_arr,
2278 dump_buf + offset,
2279 dump,
2280 split_type,
2281 split_id,
2282 block_enable,
2283 &num_dumped_reg_entries);
2284
2285 /* Write register dump header */
2286 if (dump && num_dumped_reg_entries > 0)
2287 qed_grc_dump_regs_hdr(dump_buf,
2288 dump,
2289 num_dumped_reg_entries,
2290 hdr_split_type,
2291 hdr_split_id, reg_type_name);
2292
2293 return num_dumped_reg_entries > 0 ? offset : 0;
2294}
2295
2296/* Dumps registers according to the input registers array. Returns the dumped
2297 * size in dwords.
2298 */
2299static u32 qed_grc_dump_registers(struct qed_hwfn *p_hwfn,
2300 struct qed_ptt *p_ptt,
2301 u32 *dump_buf,
2302 bool dump,
2303 bool block_enable[MAX_BLOCK_ID],
2304 const char *reg_type_name)
2305{
2306 struct virt_mem_desc *dbg_buf =
2307 &p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG];
2308 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2309 u32 offset = 0, input_offset = 0;
2310
2311 while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
2312 const struct dbg_dump_split_hdr *split_hdr;
2313 struct virt_mem_desc curr_input_regs_arr;
2314 enum init_split_types split_type;
2315 u16 split_count = 0;
2316 u32 split_data_size;
2317 u8 split_id;
2318
2319 split_hdr =
2320 (const struct dbg_dump_split_hdr *)
2321 dbg_buf->ptr + input_offset++;
2322 split_type =
2323 GET_FIELD(split_hdr->hdr,
2324 DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
2325 split_data_size = GET_FIELD(split_hdr->hdr,
2326 DBG_DUMP_SPLIT_HDR_DATA_SIZE);
2327 curr_input_regs_arr.ptr =
2328 (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr +
2329 input_offset;
2330 curr_input_regs_arr.size = DWORDS_TO_BYTES(split_data_size);
2331
2332 switch (split_type) {
2333 case SPLIT_TYPE_NONE:
2334 split_count = 1;
2335 break;
2336 case SPLIT_TYPE_PORT:
2337 split_count = dev_data->num_ports;
2338 break;
2339 case SPLIT_TYPE_PF:
2340 case SPLIT_TYPE_PORT_PF:
2341 split_count = dev_data->num_ports *
2342 dev_data->num_pfs_per_port;
2343 break;
2344 case SPLIT_TYPE_VF:
2345 split_count = dev_data->num_vfs;
2346 break;
2347 default:
2348 return 0;
2349 }
2350
2351 for (split_id = 0; split_id < split_count; split_id++)
2352 offset += qed_grc_dump_split_data(p_hwfn, p_ptt,
2353 curr_input_regs_arr,
2354 dump_buf + offset,
2355 dump, block_enable,
2356 split_type,
2357 split_id,
2358 reg_type_name);
2359
2360 input_offset += split_data_size;
2361 }
2362
2363 /* Cancel pretends (pretend to original PF) */
2364 if (dump) {
2365 qed_fid_pretend(p_hwfn, p_ptt,
2366 FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
2367 p_hwfn->rel_pf_id));
2368 dev_data->pretend.split_type = SPLIT_TYPE_NONE;
2369 dev_data->pretend.split_id = 0;
2370 }
2371
2372 return offset;
2373}
2374
2375/* Dump reset registers. Returns the dumped size in dwords. */
2376static u32 qed_grc_dump_reset_regs(struct qed_hwfn *p_hwfn,
2377 struct qed_ptt *p_ptt,
2378 u32 *dump_buf, bool dump)
2379{
2380 u32 offset = 0, num_regs = 0;
2381 u8 reset_reg_id;
2382
2383 /* Calculate header size */
2384 offset += qed_grc_dump_regs_hdr(dump_buf,
2385 false,
2386 0, SPLIT_TYPE_NONE, 0, "RESET_REGS");
2387
2388 /* Write reset registers */
2389 for (reset_reg_id = 0; reset_reg_id < NUM_DBG_RESET_REGS;
2390 reset_reg_id++) {
2391 const struct dbg_reset_reg *reset_reg;
2392 u32 reset_reg_addr;
2393
2394 reset_reg = qed_get_dbg_reset_reg(p_hwfn, reset_reg_id);
2395
2396 if (GET_FIELD(reset_reg->data, DBG_RESET_REG_IS_REMOVED))
2397 continue;
2398
2399 reset_reg_addr = GET_FIELD(reset_reg->data, DBG_RESET_REG_ADDR);
2400 offset += qed_grc_dump_reg_entry(p_hwfn,
2401 p_ptt,
2402 dump_buf + offset,
2403 dump,
2404 reset_reg_addr,
2405 1, false, SPLIT_TYPE_NONE, 0);
2406 num_regs++;
2407 }
2408
2409 /* Write header */
2410 if (dump)
2411 qed_grc_dump_regs_hdr(dump_buf,
2412 true, num_regs, SPLIT_TYPE_NONE,
2413 0, "RESET_REGS");
2414
2415 return offset;
2416}
2417
2418/* Dump registers that are modified during GRC Dump and therefore must be
2419 * dumped first. Returns the dumped size in dwords.
2420 */
2421static u32 qed_grc_dump_modified_regs(struct qed_hwfn *p_hwfn,
2422 struct qed_ptt *p_ptt,
2423 u32 *dump_buf, bool dump)
2424{
2425 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2426 u32 block_id, offset = 0, stall_regs_offset;
2427 const struct dbg_attn_reg *attn_reg_arr;
2428 u8 storm_id, reg_idx, num_attn_regs;
2429 u32 num_reg_entries = 0;
2430
2431 /* Write empty header for attention registers */
2432 offset += qed_grc_dump_regs_hdr(dump_buf,
2433 false,
2434 0, SPLIT_TYPE_NONE, 0, "ATTN_REGS");
2435
2436 /* Write parity registers */
2437 for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
2438 if (dev_data->block_in_reset[block_id] && dump)
2439 continue;
2440
2441 attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
2442 (enum block_id)block_id,
2443 ATTN_TYPE_PARITY,
2444 &num_attn_regs);
2445
2446 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
2447 const struct dbg_attn_reg *reg_data =
2448 &attn_reg_arr[reg_idx];
2449 u16 modes_buf_offset;
2450 bool eval_mode;
2451 u32 addr;
2452
2453 /* Check mode */
2454 eval_mode = GET_FIELD(reg_data->mode.data,
2455 DBG_MODE_HDR_EVAL_MODE) > 0;
2456 modes_buf_offset =
2457 GET_FIELD(reg_data->mode.data,
2458 DBG_MODE_HDR_MODES_BUF_OFFSET);
2459 if (eval_mode &&
2460 !qed_is_mode_match(p_hwfn, &modes_buf_offset))
2461 continue;
2462
2463 /* Mode match: read & dump registers */
2464 addr = reg_data->mask_address;
2465 offset += qed_grc_dump_reg_entry(p_hwfn,
2466 p_ptt,
2467 dump_buf + offset,
2468 dump,
2469 addr,
2470 1, false,
2471 SPLIT_TYPE_NONE, 0);
2472 addr = GET_FIELD(reg_data->data,
2473 DBG_ATTN_REG_STS_ADDRESS);
2474 offset += qed_grc_dump_reg_entry(p_hwfn,
2475 p_ptt,
2476 dump_buf + offset,
2477 dump,
2478 addr,
2479 1, false,
2480 SPLIT_TYPE_NONE, 0);
2481 num_reg_entries += 2;
2482 }
2483 }
2484
2485 /* Overwrite header for attention registers */
2486 if (dump)
2487 qed_grc_dump_regs_hdr(dump_buf,
2488 true,
2489 num_reg_entries,
2490 SPLIT_TYPE_NONE, 0, "ATTN_REGS");
2491
2492 /* Write empty header for stall registers */
2493 stall_regs_offset = offset;
2494 offset += qed_grc_dump_regs_hdr(dump_buf,
2495 false, 0, SPLIT_TYPE_NONE, 0, "REGS");
2496
2497 /* Write Storm stall status registers */
2498 for (storm_id = 0, num_reg_entries = 0; storm_id < MAX_DBG_STORMS;
2499 storm_id++) {
2500 struct storm_defs *storm = &s_storm_defs[storm_id];
2501 u32 addr;
2502
2503 if (dev_data->block_in_reset[storm->sem_block_id] && dump)
2504 continue;
2505
2506 addr =
2507 BYTES_TO_DWORDS(storm->sem_fast_mem_addr +
2508 SEM_FAST_REG_STALLED);
2509 offset += qed_grc_dump_reg_entry(p_hwfn,
2510 p_ptt,
2511 dump_buf + offset,
2512 dump,
2513 addr,
2514 1,
2515 false, SPLIT_TYPE_NONE, 0);
2516 num_reg_entries++;
2517 }
2518
2519 /* Overwrite header for stall registers */
2520 if (dump)
2521 qed_grc_dump_regs_hdr(dump_buf + stall_regs_offset,
2522 true,
2523 num_reg_entries,
2524 SPLIT_TYPE_NONE, 0, "REGS");
2525
2526 return offset;
2527}
2528
2529/* Dumps registers that can't be represented in the debug arrays */
2530static u32 qed_grc_dump_special_regs(struct qed_hwfn *p_hwfn,
2531 struct qed_ptt *p_ptt,
2532 u32 *dump_buf, bool dump)
2533{
2534 u32 offset = 0, addr;
2535
2536 offset += qed_grc_dump_regs_hdr(dump_buf,
2537 dump, 2, SPLIT_TYPE_NONE, 0, "REGS");
2538
2539 /* Dump R/TDIF_REG_DEBUG_ERROR_INFO_SIZE (every 8'th register should be
2540 * skipped).
2541 */
2542 addr = BYTES_TO_DWORDS(RDIF_REG_DEBUG_ERROR_INFO);
2543 offset += qed_grc_dump_reg_entry_skip(p_hwfn,
2544 p_ptt,
2545 dump_buf + offset,
2546 dump,
2547 addr,
2548 RDIF_REG_DEBUG_ERROR_INFO_SIZE,
2549 7,
2550 1);
2551 addr = BYTES_TO_DWORDS(TDIF_REG_DEBUG_ERROR_INFO);
2552 offset +=
2553 qed_grc_dump_reg_entry_skip(p_hwfn,
2554 p_ptt,
2555 dump_buf + offset,
2556 dump,
2557 addr,
2558 TDIF_REG_DEBUG_ERROR_INFO_SIZE,
2559 7,
2560 1);
2561
2562 return offset;
2563}
2564
2565/* Dumps a GRC memory header (section and params). Returns the dumped size in
2566 * dwords. The following parameters are dumped:
2567 * - name: dumped only if it's not NULL.
2568 * - addr: in dwords, dumped only if name is NULL.
2569 * - len: in dwords, always dumped.
2570 * - width: dumped if it's not zero.
2571 * - packed: dumped only if it's not false.
2572 * - mem_group: always dumped.
2573 * - is_storm: true only if the memory is related to a Storm.
2574 * - storm_letter: valid only if is_storm is true.
2575 *
2576 */
2577static u32 qed_grc_dump_mem_hdr(struct qed_hwfn *p_hwfn,
2578 u32 *dump_buf,
2579 bool dump,
2580 const char *name,
2581 u32 addr,
2582 u32 len,
2583 u32 bit_width,
2584 bool packed,
2585 const char *mem_group, char storm_letter)
2586{
2587 u8 num_params = 3;
2588 u32 offset = 0;
2589 char buf[64];
2590
2591 if (!len)
2592 DP_NOTICE(p_hwfn,
2593 "Unexpected GRC Dump error: dumped memory size must be non-zero\n");
2594
2595 if (bit_width)
2596 num_params++;
2597 if (packed)
2598 num_params++;
2599
2600 /* Dump section header */
2601 offset += qed_dump_section_hdr(dump_buf + offset,
2602 dump, "grc_mem", num_params);
2603
2604 if (name) {
2605 /* Dump name */
2606 if (storm_letter) {
2607 strcpy(buf, "?STORM_");
2608 buf[0] = storm_letter;
2609 strcpy(buf + strlen(buf), name);
2610 } else {
2611 strcpy(buf, name);
2612 }
2613
2614 offset += qed_dump_str_param(dump_buf + offset,
2615 dump, "name", buf);
2616 } else {
2617 /* Dump address */
2618 u32 addr_in_bytes = DWORDS_TO_BYTES(addr);
2619
2620 offset += qed_dump_num_param(dump_buf + offset,
2621 dump, "addr", addr_in_bytes);
2622 }
2623
2624 /* Dump len */
2625 offset += qed_dump_num_param(dump_buf + offset, dump, "len", len);
2626
2627 /* Dump bit width */
2628 if (bit_width)
2629 offset += qed_dump_num_param(dump_buf + offset,
2630 dump, "width", bit_width);
2631
2632 /* Dump packed */
2633 if (packed)
2634 offset += qed_dump_num_param(dump_buf + offset,
2635 dump, "packed", 1);
2636
2637 /* Dump reg type */
2638 if (storm_letter) {
2639 strcpy(buf, "?STORM_");
2640 buf[0] = storm_letter;
2641 strcpy(buf + strlen(buf), mem_group);
2642 } else {
2643 strcpy(buf, mem_group);
2644 }
2645
2646 offset += qed_dump_str_param(dump_buf + offset, dump, "type", buf);
2647
2648 return offset;
2649}
2650
2651/* Dumps a single GRC memory. If name is NULL, the memory is stored by address.
2652 * Returns the dumped size in dwords.
2653 * The addr and len arguments are specified in dwords.
2654 */
2655static u32 qed_grc_dump_mem(struct qed_hwfn *p_hwfn,
2656 struct qed_ptt *p_ptt,
2657 u32 *dump_buf,
2658 bool dump,
2659 const char *name,
2660 u32 addr,
2661 u32 len,
2662 bool wide_bus,
2663 u32 bit_width,
2664 bool packed,
2665 const char *mem_group, char storm_letter)
2666{
2667 u32 offset = 0;
2668
2669 offset += qed_grc_dump_mem_hdr(p_hwfn,
2670 dump_buf + offset,
2671 dump,
2672 name,
2673 addr,
2674 len,
2675 bit_width,
2676 packed, mem_group, storm_letter);
2677 offset += qed_grc_dump_addr_range(p_hwfn,
2678 p_ptt,
2679 dump_buf + offset,
2680 dump, addr, len, wide_bus,
2681 SPLIT_TYPE_NONE, 0);
2682
2683 return offset;
2684}
2685
2686/* Dumps GRC memories entries. Returns the dumped size in dwords. */
2687static u32 qed_grc_dump_mem_entries(struct qed_hwfn *p_hwfn,
2688 struct qed_ptt *p_ptt,
2689 struct virt_mem_desc input_mems_arr,
2690 u32 *dump_buf, bool dump)
2691{
2692 u32 i, offset = 0, input_offset = 0;
2693 bool mode_match = true;
2694
2695 while (input_offset < BYTES_TO_DWORDS(input_mems_arr.size)) {
2696 const struct dbg_dump_cond_hdr *cond_hdr;
2697 u16 modes_buf_offset;
2698 u32 num_entries;
2699 bool eval_mode;
2700
2701 cond_hdr =
2702 (const struct dbg_dump_cond_hdr *)input_mems_arr.ptr +
2703 input_offset++;
2704 num_entries = cond_hdr->data_size / MEM_DUMP_ENTRY_SIZE_DWORDS;
2705
2706 /* Check required mode */
2707 eval_mode = GET_FIELD(cond_hdr->mode.data,
2708 DBG_MODE_HDR_EVAL_MODE) > 0;
2709 if (eval_mode) {
2710 modes_buf_offset =
2711 GET_FIELD(cond_hdr->mode.data,
2712 DBG_MODE_HDR_MODES_BUF_OFFSET);
2713 mode_match = qed_is_mode_match(p_hwfn,
2714 &modes_buf_offset);
2715 }
2716
2717 if (!mode_match) {
2718 input_offset += cond_hdr->data_size;
2719 continue;
2720 }
2721
2722 for (i = 0; i < num_entries;
2723 i++, input_offset += MEM_DUMP_ENTRY_SIZE_DWORDS) {
2724 const struct dbg_dump_mem *mem =
2725 (const struct dbg_dump_mem *)((u32 *)
2726 input_mems_arr.ptr
2727 + input_offset);
2728 const struct dbg_block *block;
2729 char storm_letter = 0;
2730 u32 mem_addr, mem_len;
2731 bool mem_wide_bus;
2732 u8 mem_group_id;
2733
2734 mem_group_id = GET_FIELD(mem->dword0,
2735 DBG_DUMP_MEM_MEM_GROUP_ID);
2736 if (mem_group_id >= MEM_GROUPS_NUM) {
2737 DP_NOTICE(p_hwfn, "Invalid mem_group_id\n");
2738 return 0;
2739 }
2740
2741 if (!qed_grc_is_mem_included(p_hwfn,
2742 (enum block_id)
2743 cond_hdr->block_id,
2744 mem_group_id))
2745 continue;
2746
2747 mem_addr = GET_FIELD(mem->dword0, DBG_DUMP_MEM_ADDRESS);
2748 mem_len = GET_FIELD(mem->dword1, DBG_DUMP_MEM_LENGTH);
2749 mem_wide_bus = GET_FIELD(mem->dword1,
2750 DBG_DUMP_MEM_WIDE_BUS);
2751
2752 block = get_dbg_block(p_hwfn,
2753 cond_hdr->block_id);
2754
2755 /* If memory is associated with Storm,
2756 * update storm details
2757 */
2758 if (block->associated_storm_letter)
2759 storm_letter = block->associated_storm_letter;
2760
2761 /* Dump memory */
2762 offset += qed_grc_dump_mem(p_hwfn,
2763 p_ptt,
2764 dump_buf + offset,
2765 dump,
2766 NULL,
2767 mem_addr,
2768 mem_len,
2769 mem_wide_bus,
2770 0,
2771 false,
2772 s_mem_group_names[mem_group_id],
2773 storm_letter);
2774 }
2775 }
2776
2777 return offset;
2778}
2779
2780/* Dumps GRC memories according to the input array dump_mem.
2781 * Returns the dumped size in dwords.
2782 */
2783static u32 qed_grc_dump_memories(struct qed_hwfn *p_hwfn,
2784 struct qed_ptt *p_ptt,
2785 u32 *dump_buf, bool dump)
2786{
2787 struct virt_mem_desc *dbg_buf =
2788 &p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_MEM];
2789 u32 offset = 0, input_offset = 0;
2790
2791 while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
2792 const struct dbg_dump_split_hdr *split_hdr;
2793 struct virt_mem_desc curr_input_mems_arr;
2794 enum init_split_types split_type;
2795 u32 split_data_size;
2796
2797 split_hdr =
2798 (const struct dbg_dump_split_hdr *)dbg_buf->ptr +
2799 input_offset++;
2800 split_type = GET_FIELD(split_hdr->hdr,
2801 DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
2802 split_data_size = GET_FIELD(split_hdr->hdr,
2803 DBG_DUMP_SPLIT_HDR_DATA_SIZE);
2804 curr_input_mems_arr.ptr = (u32 *)dbg_buf->ptr + input_offset;
2805 curr_input_mems_arr.size = DWORDS_TO_BYTES(split_data_size);
2806
2807 if (split_type == SPLIT_TYPE_NONE)
2808 offset += qed_grc_dump_mem_entries(p_hwfn,
2809 p_ptt,
2810 curr_input_mems_arr,
2811 dump_buf + offset,
2812 dump);
2813 else
2814 DP_NOTICE(p_hwfn,
2815 "Dumping split memories is currently not supported\n");
2816
2817 input_offset += split_data_size;
2818 }
2819
2820 return offset;
2821}
2822
2823/* Dumps GRC context data for the specified Storm.
2824 * Returns the dumped size in dwords.
2825 * The lid_size argument is specified in quad-regs.
2826 */
2827static u32 qed_grc_dump_ctx_data(struct qed_hwfn *p_hwfn,
2828 struct qed_ptt *p_ptt,
2829 u32 *dump_buf,
2830 bool dump,
2831 const char *name,
2832 u32 num_lids,
2833 enum cm_ctx_types ctx_type, u8 storm_id)
2834{
2835 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2836 struct storm_defs *storm = &s_storm_defs[storm_id];
2837 u32 i, lid, lid_size, total_size;
2838 u32 rd_reg_addr, offset = 0;
2839
2840 /* Convert quad-regs to dwords */
2841 lid_size = storm->cm_ctx_lid_sizes[dev_data->chip_id][ctx_type] * 4;
2842
2843 if (!lid_size)
2844 return 0;
2845
2846 total_size = num_lids * lid_size;
2847
2848 offset += qed_grc_dump_mem_hdr(p_hwfn,
2849 dump_buf + offset,
2850 dump,
2851 name,
2852 0,
2853 total_size,
2854 lid_size * 32,
2855 false, name, storm->letter);
2856
2857 if (!dump)
2858 return offset + total_size;
2859
2860 rd_reg_addr = BYTES_TO_DWORDS(storm->cm_ctx_rd_addr[ctx_type]);
2861
2862 /* Dump context data */
2863 for (lid = 0; lid < num_lids; lid++) {
2864 for (i = 0; i < lid_size; i++) {
2865 qed_wr(p_hwfn,
2866 p_ptt, storm->cm_ctx_wr_addr, (i << 9) | lid);
2867 offset += qed_grc_dump_addr_range(p_hwfn,
2868 p_ptt,
2869 dump_buf + offset,
2870 dump,
2871 rd_reg_addr,
2872 1,
2873 false,
2874 SPLIT_TYPE_NONE, 0);
2875 }
2876 cond_resched();
2877 }
2878
2879 return offset;
2880}
2881
2882/* Dumps GRC contexts. Returns the dumped size in dwords. */
2883static u32 qed_grc_dump_ctx(struct qed_hwfn *p_hwfn,
2884 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
2885{
2886 u32 offset = 0;
2887 u8 storm_id;
2888
2889 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
2890 if (!qed_grc_is_storm_included(p_hwfn,
2891 (enum dbg_storms)storm_id))
2892 continue;
2893
2894 /* Dump Conn AG context size */
2895 offset += qed_grc_dump_ctx_data(p_hwfn,
2896 p_ptt,
2897 dump_buf + offset,
2898 dump,
2899 "CONN_AG_CTX",
2900 NUM_OF_LCIDS,
2901 CM_CTX_CONN_AG, storm_id);
2902
2903 /* Dump Conn ST context size */
2904 offset += qed_grc_dump_ctx_data(p_hwfn,
2905 p_ptt,
2906 dump_buf + offset,
2907 dump,
2908 "CONN_ST_CTX",
2909 NUM_OF_LCIDS,
2910 CM_CTX_CONN_ST, storm_id);
2911
2912 /* Dump Task AG context size */
2913 offset += qed_grc_dump_ctx_data(p_hwfn,
2914 p_ptt,
2915 dump_buf + offset,
2916 dump,
2917 "TASK_AG_CTX",
2918 NUM_OF_LTIDS,
2919 CM_CTX_TASK_AG, storm_id);
2920
2921 /* Dump Task ST context size */
2922 offset += qed_grc_dump_ctx_data(p_hwfn,
2923 p_ptt,
2924 dump_buf + offset,
2925 dump,
2926 "TASK_ST_CTX",
2927 NUM_OF_LTIDS,
2928 CM_CTX_TASK_ST, storm_id);
2929 }
2930
2931 return offset;
2932}
2933
2934#define VFC_STATUS_RESP_READY_BIT 0
2935#define VFC_STATUS_BUSY_BIT 1
2936#define VFC_STATUS_SENDING_CMD_BIT 2
2937
2938#define VFC_POLLING_DELAY_MS 1
2939#define VFC_POLLING_COUNT 20
2940
2941/* Reads data from VFC. Returns the number of dwords read (0 on error).
2942 * Sizes are specified in dwords.
2943 */
2944static u32 qed_grc_dump_read_from_vfc(struct qed_hwfn *p_hwfn,
2945 struct qed_ptt *p_ptt,
2946 struct storm_defs *storm,
2947 u32 *cmd_data,
2948 u32 cmd_size,
2949 u32 *addr_data,
2950 u32 addr_size,
2951 u32 resp_size, u32 *dump_buf)
2952{
2953 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2954 u32 vfc_status, polling_ms, polling_count = 0, i;
2955 u32 reg_addr, sem_base;
2956 bool is_ready = false;
2957
2958 sem_base = storm->sem_fast_mem_addr;
2959 polling_ms = VFC_POLLING_DELAY_MS *
2960 s_hw_type_defs[dev_data->hw_type].delay_factor;
2961
2962 /* Write VFC command */
2963 ARR_REG_WR(p_hwfn,
2964 p_ptt,
2965 sem_base + SEM_FAST_REG_VFC_DATA_WR,
2966 cmd_data, cmd_size);
2967
2968 /* Write VFC address */
2969 ARR_REG_WR(p_hwfn,
2970 p_ptt,
2971 sem_base + SEM_FAST_REG_VFC_ADDR,
2972 addr_data, addr_size);
2973
2974 /* Read response */
2975 for (i = 0; i < resp_size; i++) {
2976 /* Poll until ready */
2977 do {
2978 reg_addr = sem_base + SEM_FAST_REG_VFC_STATUS;
2979 qed_grc_dump_addr_range(p_hwfn,
2980 p_ptt,
2981 &vfc_status,
2982 true,
2983 BYTES_TO_DWORDS(reg_addr),
2984 1,
2985 false, SPLIT_TYPE_NONE, 0);
2986 is_ready = vfc_status & BIT(VFC_STATUS_RESP_READY_BIT);
2987
2988 if (!is_ready) {
2989 if (polling_count++ == VFC_POLLING_COUNT)
2990 return 0;
2991
2992 msleep(polling_ms);
2993 }
2994 } while (!is_ready);
2995
2996 reg_addr = sem_base + SEM_FAST_REG_VFC_DATA_RD;
2997 qed_grc_dump_addr_range(p_hwfn,
2998 p_ptt,
2999 dump_buf + i,
3000 true,
3001 BYTES_TO_DWORDS(reg_addr),
3002 1, false, SPLIT_TYPE_NONE, 0);
3003 }
3004
3005 return resp_size;
3006}
3007
3008/* Dump VFC CAM. Returns the dumped size in dwords. */
3009static u32 qed_grc_dump_vfc_cam(struct qed_hwfn *p_hwfn,
3010 struct qed_ptt *p_ptt,
3011 u32 *dump_buf, bool dump, u8 storm_id)
3012{
3013 u32 total_size = VFC_CAM_NUM_ROWS * VFC_CAM_RESP_DWORDS;
3014 struct storm_defs *storm = &s_storm_defs[storm_id];
3015 u32 cam_addr[VFC_CAM_ADDR_DWORDS] = { 0 };
3016 u32 cam_cmd[VFC_CAM_CMD_DWORDS] = { 0 };
3017 u32 row, offset = 0;
3018
3019 offset += qed_grc_dump_mem_hdr(p_hwfn,
3020 dump_buf + offset,
3021 dump,
3022 "vfc_cam",
3023 0,
3024 total_size,
3025 256,
3026 false, "vfc_cam", storm->letter);
3027
3028 if (!dump)
3029 return offset + total_size;
3030
3031 /* Prepare CAM address */
3032 SET_VAR_FIELD(cam_addr, VFC_CAM_ADDR, OP, VFC_OPCODE_CAM_RD);
3033
3034 /* Read VFC CAM data */
3035 for (row = 0; row < VFC_CAM_NUM_ROWS; row++) {
3036 SET_VAR_FIELD(cam_cmd, VFC_CAM_CMD, ROW, row);
3037 offset += qed_grc_dump_read_from_vfc(p_hwfn,
3038 p_ptt,
3039 storm,
3040 cam_cmd,
3041 VFC_CAM_CMD_DWORDS,
3042 cam_addr,
3043 VFC_CAM_ADDR_DWORDS,
3044 VFC_CAM_RESP_DWORDS,
3045 dump_buf + offset);
3046 }
3047
3048 return offset;
3049}
3050
3051/* Dump VFC RAM. Returns the dumped size in dwords. */
3052static u32 qed_grc_dump_vfc_ram(struct qed_hwfn *p_hwfn,
3053 struct qed_ptt *p_ptt,
3054 u32 *dump_buf,
3055 bool dump,
3056 u8 storm_id, struct vfc_ram_defs *ram_defs)
3057{
3058 u32 total_size = ram_defs->num_rows * VFC_RAM_RESP_DWORDS;
3059 struct storm_defs *storm = &s_storm_defs[storm_id];
3060 u32 ram_addr[VFC_RAM_ADDR_DWORDS] = { 0 };
3061 u32 ram_cmd[VFC_RAM_CMD_DWORDS] = { 0 };
3062 u32 row, offset = 0;
3063
3064 offset += qed_grc_dump_mem_hdr(p_hwfn,
3065 dump_buf + offset,
3066 dump,
3067 ram_defs->mem_name,
3068 0,
3069 total_size,
3070 256,
3071 false,
3072 ram_defs->type_name,
3073 storm->letter);
3074
3075 if (!dump)
3076 return offset + total_size;
3077
3078 /* Prepare RAM address */
3079 SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, OP, VFC_OPCODE_RAM_RD);
3080
3081 /* Read VFC RAM data */
3082 for (row = ram_defs->base_row;
3083 row < ram_defs->base_row + ram_defs->num_rows; row++) {
3084 SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, ROW, row);
3085 offset += qed_grc_dump_read_from_vfc(p_hwfn,
3086 p_ptt,
3087 storm,
3088 ram_cmd,
3089 VFC_RAM_CMD_DWORDS,
3090 ram_addr,
3091 VFC_RAM_ADDR_DWORDS,
3092 VFC_RAM_RESP_DWORDS,
3093 dump_buf + offset);
3094 }
3095
3096 return offset;
3097}
3098
3099/* Dumps GRC VFC data. Returns the dumped size in dwords. */
3100static u32 qed_grc_dump_vfc(struct qed_hwfn *p_hwfn,
3101 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3102{
3103 u8 storm_id, i;
3104 u32 offset = 0;
3105
3106 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
3107 if (!qed_grc_is_storm_included(p_hwfn,
3108 (enum dbg_storms)storm_id) ||
3109 !s_storm_defs[storm_id].has_vfc)
3110 continue;
3111
3112 /* Read CAM */
3113 offset += qed_grc_dump_vfc_cam(p_hwfn,
3114 p_ptt,
3115 dump_buf + offset,
3116 dump, storm_id);
3117
3118 /* Read RAM */
3119 for (i = 0; i < NUM_VFC_RAM_TYPES; i++)
3120 offset += qed_grc_dump_vfc_ram(p_hwfn,
3121 p_ptt,
3122 dump_buf + offset,
3123 dump,
3124 storm_id,
3125 &s_vfc_ram_defs[i]);
3126 }
3127
3128 return offset;
3129}
3130
3131/* Dumps GRC RSS data. Returns the dumped size in dwords. */
3132static u32 qed_grc_dump_rss(struct qed_hwfn *p_hwfn,
3133 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3134{
3135 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3136 u32 offset = 0;
3137 u8 rss_mem_id;
3138
3139 for (rss_mem_id = 0; rss_mem_id < NUM_RSS_MEM_TYPES; rss_mem_id++) {
3140 u32 rss_addr, num_entries, total_dwords;
3141 struct rss_mem_defs *rss_defs;
3142 u32 addr, num_dwords_to_read;
3143 bool packed;
3144
3145 rss_defs = &s_rss_mem_defs[rss_mem_id];
3146 rss_addr = rss_defs->addr;
3147 num_entries = rss_defs->num_entries[dev_data->chip_id];
3148 total_dwords = (num_entries * rss_defs->entry_width) / 32;
3149 packed = (rss_defs->entry_width == 16);
3150
3151 offset += qed_grc_dump_mem_hdr(p_hwfn,
3152 dump_buf + offset,
3153 dump,
3154 rss_defs->mem_name,
3155 0,
3156 total_dwords,
3157 rss_defs->entry_width,
3158 packed,
3159 rss_defs->type_name, 0);
3160
3161 /* Dump RSS data */
3162 if (!dump) {
3163 offset += total_dwords;
3164 continue;
3165 }
3166
3167 addr = BYTES_TO_DWORDS(RSS_REG_RSS_RAM_DATA);
3168 while (total_dwords) {
3169 num_dwords_to_read = min_t(u32,
3170 RSS_REG_RSS_RAM_DATA_SIZE,
3171 total_dwords);
3172 qed_wr(p_hwfn, p_ptt, RSS_REG_RSS_RAM_ADDR, rss_addr);
3173 offset += qed_grc_dump_addr_range(p_hwfn,
3174 p_ptt,
3175 dump_buf + offset,
3176 dump,
3177 addr,
3178 num_dwords_to_read,
3179 false,
3180 SPLIT_TYPE_NONE, 0);
3181 total_dwords -= num_dwords_to_read;
3182 rss_addr++;
3183 }
3184 }
3185
3186 return offset;
3187}
3188
3189/* Dumps GRC Big RAM. Returns the dumped size in dwords. */
3190static u32 qed_grc_dump_big_ram(struct qed_hwfn *p_hwfn,
3191 struct qed_ptt *p_ptt,
3192 u32 *dump_buf, bool dump, u8 big_ram_id)
3193{
3194 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3195 u32 block_size, ram_size, offset = 0, reg_val, i;
3196 char mem_name[12] = "???_BIG_RAM";
3197 char type_name[8] = "???_RAM";
3198 struct big_ram_defs *big_ram;
3199
3200 big_ram = &s_big_ram_defs[big_ram_id];
3201 ram_size = big_ram->ram_size[dev_data->chip_id];
3202
3203 reg_val = qed_rd(p_hwfn, p_ptt, big_ram->is_256b_reg_addr);
3204 block_size = reg_val &
3205 BIT(big_ram->is_256b_bit_offset[dev_data->chip_id]) ? 256
3206 : 128;
3207
3208 memcpy(type_name, big_ram->instance_name, BIG_RAM_NAME_LEN);
3209 memcpy(mem_name, big_ram->instance_name, BIG_RAM_NAME_LEN);
3210
3211 /* Dump memory header */
3212 offset += qed_grc_dump_mem_hdr(p_hwfn,
3213 dump_buf + offset,
3214 dump,
3215 mem_name,
3216 0,
3217 ram_size,
3218 block_size * 8,
3219 false, type_name, 0);
3220
3221 /* Read and dump Big RAM data */
3222 if (!dump)
3223 return offset + ram_size;
3224
3225 /* Dump Big RAM */
3226 for (i = 0; i < DIV_ROUND_UP(ram_size, BRB_REG_BIG_RAM_DATA_SIZE);
3227 i++) {
3228 u32 addr, len;
3229
3230 qed_wr(p_hwfn, p_ptt, big_ram->addr_reg_addr, i);
3231 addr = BYTES_TO_DWORDS(big_ram->data_reg_addr);
3232 len = BRB_REG_BIG_RAM_DATA_SIZE;
3233 offset += qed_grc_dump_addr_range(p_hwfn,
3234 p_ptt,
3235 dump_buf + offset,
3236 dump,
3237 addr,
3238 len,
3239 false, SPLIT_TYPE_NONE, 0);
3240 }
3241
3242 return offset;
3243}
3244
3245/* Dumps MCP scratchpad. Returns the dumped size in dwords. */
3246static u32 qed_grc_dump_mcp(struct qed_hwfn *p_hwfn,
3247 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3248{
3249 bool block_enable[MAX_BLOCK_ID] = { 0 };
3250 u32 offset = 0, addr;
3251 bool halted = false;
3252
3253 /* Halt MCP */
3254 if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
3255 halted = !qed_mcp_halt(p_hwfn, p_ptt);
3256 if (!halted)
3257 DP_NOTICE(p_hwfn, "MCP halt failed!\n");
3258 }
3259
3260 /* Dump MCP scratchpad */
3261 offset += qed_grc_dump_mem(p_hwfn,
3262 p_ptt,
3263 dump_buf + offset,
3264 dump,
3265 NULL,
3266 BYTES_TO_DWORDS(MCP_REG_SCRATCH),
3267 MCP_REG_SCRATCH_SIZE,
3268 false, 0, false, "MCP", 0);
3269
3270 /* Dump MCP cpu_reg_file */
3271 offset += qed_grc_dump_mem(p_hwfn,
3272 p_ptt,
3273 dump_buf + offset,
3274 dump,
3275 NULL,
3276 BYTES_TO_DWORDS(MCP_REG_CPU_REG_FILE),
3277 MCP_REG_CPU_REG_FILE_SIZE,
3278 false, 0, false, "MCP", 0);
3279
3280 /* Dump MCP registers */
3281 block_enable[BLOCK_MCP] = true;
3282 offset += qed_grc_dump_registers(p_hwfn,
3283 p_ptt,
3284 dump_buf + offset,
3285 dump, block_enable, "MCP");
3286
3287 /* Dump required non-MCP registers */
3288 offset += qed_grc_dump_regs_hdr(dump_buf + offset,
3289 dump, 1, SPLIT_TYPE_NONE, 0,
3290 "MCP");
3291 addr = BYTES_TO_DWORDS(MISC_REG_SHARED_MEM_ADDR);
3292 offset += qed_grc_dump_reg_entry(p_hwfn,
3293 p_ptt,
3294 dump_buf + offset,
3295 dump,
3296 addr,
3297 1,
3298 false, SPLIT_TYPE_NONE, 0);
3299
3300 /* Release MCP */
3301 if (halted && qed_mcp_resume(p_hwfn, p_ptt))
3302 DP_NOTICE(p_hwfn, "Failed to resume MCP after halt!\n");
3303
3304 return offset;
3305}
3306
3307/* Dumps the tbus indirect memory for all PHYs.
3308 * Returns the dumped size in dwords.
3309 */
3310static u32 qed_grc_dump_phy(struct qed_hwfn *p_hwfn,
3311 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3312{
3313 u32 offset = 0, tbus_lo_offset, tbus_hi_offset;
3314 char mem_name[32];
3315 u8 phy_id;
3316
3317 for (phy_id = 0; phy_id < ARRAY_SIZE(s_phy_defs); phy_id++) {
3318 u32 addr_lo_addr, addr_hi_addr, data_lo_addr, data_hi_addr;
3319 struct phy_defs *phy_defs;
3320 u8 *bytes_buf;
3321
3322 phy_defs = &s_phy_defs[phy_id];
3323 addr_lo_addr = phy_defs->base_addr +
3324 phy_defs->tbus_addr_lo_addr;
3325 addr_hi_addr = phy_defs->base_addr +
3326 phy_defs->tbus_addr_hi_addr;
3327 data_lo_addr = phy_defs->base_addr +
3328 phy_defs->tbus_data_lo_addr;
3329 data_hi_addr = phy_defs->base_addr +
3330 phy_defs->tbus_data_hi_addr;
3331
3332 if (snprintf(mem_name, sizeof(mem_name), "tbus_%s",
3333 phy_defs->phy_name) < 0)
3334 DP_NOTICE(p_hwfn,
3335 "Unexpected debug error: invalid PHY memory name\n");
3336
3337 offset += qed_grc_dump_mem_hdr(p_hwfn,
3338 dump_buf + offset,
3339 dump,
3340 mem_name,
3341 0,
3342 PHY_DUMP_SIZE_DWORDS,
3343 16, true, mem_name, 0);
3344
3345 if (!dump) {
3346 offset += PHY_DUMP_SIZE_DWORDS;
3347 continue;
3348 }
3349
3350 bytes_buf = (u8 *)(dump_buf + offset);
3351 for (tbus_hi_offset = 0;
3352 tbus_hi_offset < (NUM_PHY_TBUS_ADDRESSES >> 8);
3353 tbus_hi_offset++) {
3354 qed_wr(p_hwfn, p_ptt, addr_hi_addr, tbus_hi_offset);
3355 for (tbus_lo_offset = 0; tbus_lo_offset < 256;
3356 tbus_lo_offset++) {
3357 qed_wr(p_hwfn,
3358 p_ptt, addr_lo_addr, tbus_lo_offset);
3359 *(bytes_buf++) = (u8)qed_rd(p_hwfn,
3360 p_ptt,
3361 data_lo_addr);
3362 *(bytes_buf++) = (u8)qed_rd(p_hwfn,
3363 p_ptt,
3364 data_hi_addr);
3365 }
3366 }
3367
3368 offset += PHY_DUMP_SIZE_DWORDS;
3369 }
3370
3371 return offset;
3372}
3373
3374/* Dumps the MCP HW dump from NVRAM. Returns the dumped size in dwords. */
3375static u32 qed_grc_dump_mcp_hw_dump(struct qed_hwfn *p_hwfn,
3376 struct qed_ptt *p_ptt,
3377 u32 *dump_buf, bool dump)
3378{
3379 u32 hw_dump_offset_bytes = 0, hw_dump_size_bytes = 0;
3380 u32 hw_dump_size_dwords = 0, offset = 0;
3381 enum dbg_status status;
3382
3383 /* Read HW dump image from NVRAM */
3384 status = qed_find_nvram_image(p_hwfn,
3385 p_ptt,
3386 NVM_TYPE_HW_DUMP_OUT,
3387 &hw_dump_offset_bytes,
3388 &hw_dump_size_bytes,
3389 false);
3390 if (status != DBG_STATUS_OK)
3391 return 0;
3392
3393 hw_dump_size_dwords = BYTES_TO_DWORDS(hw_dump_size_bytes);
3394
3395 /* Dump HW dump image section */
3396 offset += qed_dump_section_hdr(dump_buf + offset,
3397 dump, "mcp_hw_dump", 1);
3398 offset += qed_dump_num_param(dump_buf + offset,
3399 dump, "size", hw_dump_size_dwords);
3400
3401 /* Read MCP HW dump image into dump buffer */
3402 if (dump && hw_dump_size_dwords) {
3403 status = qed_nvram_read(p_hwfn,
3404 p_ptt,
3405 hw_dump_offset_bytes,
3406 hw_dump_size_bytes,
3407 dump_buf + offset,
3408 false);
3409 if (status != DBG_STATUS_OK) {
3410 DP_NOTICE(p_hwfn,
3411 "Failed to read MCP HW Dump image from NVRAM\n");
3412 return 0;
3413 }
3414 }
3415 offset += hw_dump_size_dwords;
3416
3417 return offset;
3418}
3419
3420/* Dumps Static Debug data. Returns the dumped size in dwords. */
3421static u32 qed_grc_dump_static_debug(struct qed_hwfn *p_hwfn,
3422 struct qed_ptt *p_ptt,
3423 u32 *dump_buf, bool dump)
3424{
3425 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3426 u32 block_id, line_id, offset = 0, addr, len;
3427
3428 /* Don't dump static debug if a debug bus recording is in progress */
3429 if (dump && qed_rd(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON))
3430 return 0;
3431
3432 if (dump) {
3433 /* Disable debug bus in all blocks */
3434 qed_bus_disable_blocks(p_hwfn, p_ptt);
3435
3436 qed_bus_reset_dbg_block(p_hwfn, p_ptt);
3437 qed_wr(p_hwfn,
3438 p_ptt, DBG_REG_FRAMING_MODE, DBG_BUS_FRAME_MODE_8HW);
3439 qed_wr(p_hwfn,
3440 p_ptt, DBG_REG_DEBUG_TARGET, DBG_BUS_TARGET_ID_INT_BUF);
3441 qed_wr(p_hwfn, p_ptt, DBG_REG_FULL_MODE, 1);
3442 qed_bus_enable_dbg_block(p_hwfn, p_ptt, true);
3443 }
3444
3445 /* Dump all static debug lines for each relevant block */
3446 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
3447 const struct dbg_block_chip *block_per_chip;
3448 const struct dbg_block *block;
3449 bool is_removed, has_dbg_bus;
3450 u16 modes_buf_offset;
3451 u32 block_dwords;
3452
3453 block_per_chip =
3454 qed_get_dbg_block_per_chip(p_hwfn, (enum block_id)block_id);
3455 is_removed = GET_FIELD(block_per_chip->flags,
3456 DBG_BLOCK_CHIP_IS_REMOVED);
3457 has_dbg_bus = GET_FIELD(block_per_chip->flags,
3458 DBG_BLOCK_CHIP_HAS_DBG_BUS);
3459
3460 if (!is_removed && has_dbg_bus &&
3461 GET_FIELD(block_per_chip->dbg_bus_mode.data,
3462 DBG_MODE_HDR_EVAL_MODE) > 0) {
3463 modes_buf_offset =
3464 GET_FIELD(block_per_chip->dbg_bus_mode.data,
3465 DBG_MODE_HDR_MODES_BUF_OFFSET);
3466 if (!qed_is_mode_match(p_hwfn, &modes_buf_offset))
3467 has_dbg_bus = false;
3468 }
3469
3470 if (is_removed || !has_dbg_bus)
3471 continue;
3472
3473 block_dwords = NUM_DBG_LINES(block_per_chip) *
3474 STATIC_DEBUG_LINE_DWORDS;
3475
3476 /* Dump static section params */
3477 block = get_dbg_block(p_hwfn, (enum block_id)block_id);
3478 offset += qed_grc_dump_mem_hdr(p_hwfn,
3479 dump_buf + offset,
3480 dump,
3481 block->name,
3482 0,
3483 block_dwords,
3484 32, false, "STATIC", 0);
3485
3486 if (!dump) {
3487 offset += block_dwords;
3488 continue;
3489 }
3490
3491 /* If all lines are invalid - dump zeros */
3492 if (dev_data->block_in_reset[block_id]) {
3493 memset(dump_buf + offset, 0,
3494 DWORDS_TO_BYTES(block_dwords));
3495 offset += block_dwords;
3496 continue;
3497 }
3498
3499 /* Enable block's client */
3500 qed_bus_enable_clients(p_hwfn,
3501 p_ptt,
3502 BIT(block_per_chip->dbg_client_id));
3503
3504 addr = BYTES_TO_DWORDS(DBG_REG_CALENDAR_OUT_DATA);
3505 len = STATIC_DEBUG_LINE_DWORDS;
3506 for (line_id = 0; line_id < (u32)NUM_DBG_LINES(block_per_chip);
3507 line_id++) {
3508 /* Configure debug line ID */
3509 qed_bus_config_dbg_line(p_hwfn,
3510 p_ptt,
3511 (enum block_id)block_id,
3512 (u8)line_id, 0xf, 0, 0, 0);
3513
3514 /* Read debug line info */
3515 offset += qed_grc_dump_addr_range(p_hwfn,
3516 p_ptt,
3517 dump_buf + offset,
3518 dump,
3519 addr,
3520 len,
3521 true, SPLIT_TYPE_NONE,
3522 0);
3523 }
3524
3525 /* Disable block's client and debug output */
3526 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
3527 qed_bus_config_dbg_line(p_hwfn, p_ptt,
3528 (enum block_id)block_id, 0, 0, 0, 0, 0);
3529 }
3530
3531 if (dump) {
3532 qed_bus_enable_dbg_block(p_hwfn, p_ptt, false);
3533 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
3534 }
3535
3536 return offset;
3537}
3538
3539/* Performs GRC Dump to the specified buffer.
3540 * Returns the dumped size in dwords.
3541 */
3542static enum dbg_status qed_grc_dump(struct qed_hwfn *p_hwfn,
3543 struct qed_ptt *p_ptt,
3544 u32 *dump_buf,
3545 bool dump, u32 *num_dumped_dwords)
3546{
3547 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3548 bool parities_masked = false;
3549 u32 dwords_read, offset = 0;
3550 u8 i;
3551
3552 *num_dumped_dwords = 0;
3553 dev_data->num_regs_read = 0;
3554
3555 /* Update reset state */
3556 if (dump)
3557 qed_update_blocks_reset_state(p_hwfn, p_ptt);
3558
3559 /* Dump global params */
3560 offset += qed_dump_common_global_params(p_hwfn,
3561 p_ptt,
3562 dump_buf + offset, dump, 4);
3563 offset += qed_dump_str_param(dump_buf + offset,
3564 dump, "dump-type", "grc-dump");
3565 offset += qed_dump_num_param(dump_buf + offset,
3566 dump,
3567 "num-lcids",
3568 NUM_OF_LCIDS);
3569 offset += qed_dump_num_param(dump_buf + offset,
3570 dump,
3571 "num-ltids",
3572 NUM_OF_LTIDS);
3573 offset += qed_dump_num_param(dump_buf + offset,
3574 dump, "num-ports", dev_data->num_ports);
3575
3576 /* Dump reset registers (dumped before taking blocks out of reset ) */
3577 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
3578 offset += qed_grc_dump_reset_regs(p_hwfn,
3579 p_ptt,
3580 dump_buf + offset, dump);
3581
3582 /* Take all blocks out of reset (using reset registers) */
3583 if (dump) {
3584 qed_grc_unreset_blocks(p_hwfn, p_ptt, false);
3585 qed_update_blocks_reset_state(p_hwfn, p_ptt);
3586 }
3587
3588 /* Disable all parities using MFW command */
3589 if (dump &&
3590 !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
3591 parities_masked = !qed_mcp_mask_parities(p_hwfn, p_ptt, 1);
3592 if (!parities_masked) {
3593 DP_NOTICE(p_hwfn,
3594 "Failed to mask parities using MFW\n");
3595 if (qed_grc_get_param
3596 (p_hwfn, DBG_GRC_PARAM_PARITY_SAFE))
3597 return DBG_STATUS_MCP_COULD_NOT_MASK_PRTY;
3598 }
3599 }
3600
3601 /* Dump modified registers (dumped before modifying them) */
3602 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
3603 offset += qed_grc_dump_modified_regs(p_hwfn,
3604 p_ptt,
3605 dump_buf + offset, dump);
3606
3607 /* Stall storms */
3608 if (dump &&
3609 (qed_grc_is_included(p_hwfn,
3610 DBG_GRC_PARAM_DUMP_IOR) ||
3611 qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC)))
3612 qed_grc_stall_storms(p_hwfn, p_ptt, true);
3613
3614 /* Dump all regs */
3615 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS)) {
3616 bool block_enable[MAX_BLOCK_ID];
3617
3618 /* Dump all blocks except MCP */
3619 for (i = 0; i < MAX_BLOCK_ID; i++)
3620 block_enable[i] = true;
3621 block_enable[BLOCK_MCP] = false;
3622 offset += qed_grc_dump_registers(p_hwfn,
3623 p_ptt,
3624 dump_buf +
3625 offset,
3626 dump,
3627 block_enable, NULL);
3628
3629 /* Dump special registers */
3630 offset += qed_grc_dump_special_regs(p_hwfn,
3631 p_ptt,
3632 dump_buf + offset, dump);
3633 }
3634
3635 /* Dump memories */
3636 offset += qed_grc_dump_memories(p_hwfn, p_ptt, dump_buf + offset, dump);
3637
3638 /* Dump MCP */
3639 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MCP))
3640 offset += qed_grc_dump_mcp(p_hwfn,
3641 p_ptt, dump_buf + offset, dump);
3642
3643 /* Dump context */
3644 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX))
3645 offset += qed_grc_dump_ctx(p_hwfn,
3646 p_ptt, dump_buf + offset, dump);
3647
3648 /* Dump RSS memories */
3649 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RSS))
3650 offset += qed_grc_dump_rss(p_hwfn,
3651 p_ptt, dump_buf + offset, dump);
3652
3653 /* Dump Big RAM */
3654 for (i = 0; i < NUM_BIG_RAM_TYPES; i++)
3655 if (qed_grc_is_included(p_hwfn, s_big_ram_defs[i].grc_param))
3656 offset += qed_grc_dump_big_ram(p_hwfn,
3657 p_ptt,
3658 dump_buf + offset,
3659 dump, i);
3660
3661 /* Dump VFC */
3662 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC)) {
3663 dwords_read = qed_grc_dump_vfc(p_hwfn,
3664 p_ptt, dump_buf + offset, dump);
3665 offset += dwords_read;
3666 if (!dwords_read)
3667 return DBG_STATUS_VFC_READ_ERROR;
3668 }
3669
3670 /* Dump PHY tbus */
3671 if (qed_grc_is_included(p_hwfn,
3672 DBG_GRC_PARAM_DUMP_PHY) && dev_data->chip_id ==
3673 CHIP_K2 && dev_data->hw_type == HW_TYPE_ASIC)
3674 offset += qed_grc_dump_phy(p_hwfn,
3675 p_ptt, dump_buf + offset, dump);
3676
3677 /* Dump MCP HW Dump */
3678 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MCP_HW_DUMP) &&
3679 !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP) && 1)
3680 offset += qed_grc_dump_mcp_hw_dump(p_hwfn,
3681 p_ptt,
3682 dump_buf + offset, dump);
3683
3684 /* Dump static debug data (only if not during debug bus recording) */
3685 if (qed_grc_is_included(p_hwfn,
3686 DBG_GRC_PARAM_DUMP_STATIC) &&
3687 (!dump || dev_data->bus.state == DBG_BUS_STATE_IDLE))
3688 offset += qed_grc_dump_static_debug(p_hwfn,
3689 p_ptt,
3690 dump_buf + offset, dump);
3691
3692 /* Dump last section */
3693 offset += qed_dump_last_section(dump_buf, offset, dump);
3694
3695 if (dump) {
3696 /* Unstall storms */
3697 if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_UNSTALL))
3698 qed_grc_stall_storms(p_hwfn, p_ptt, false);
3699
3700 /* Clear parity status */
3701 qed_grc_clear_all_prty(p_hwfn, p_ptt);
3702
3703 /* Enable all parities using MFW command */
3704 if (parities_masked)
3705 qed_mcp_mask_parities(p_hwfn, p_ptt, 0);
3706 }
3707
3708 *num_dumped_dwords = offset;
3709
3710 return DBG_STATUS_OK;
3711}
3712
3713/* Writes the specified failing Idle Check rule to the specified buffer.
3714 * Returns the dumped size in dwords.
3715 */
3716static u32 qed_idle_chk_dump_failure(struct qed_hwfn *p_hwfn,
3717 struct qed_ptt *p_ptt,
3718 u32 *dump_buf,
3719 bool dump,
3720 u16 rule_id,
3721 const struct dbg_idle_chk_rule *rule,
3722 u16 fail_entry_id, u32 *cond_reg_values)
3723{
3724 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3725 const struct dbg_idle_chk_cond_reg *cond_regs;
3726 const struct dbg_idle_chk_info_reg *info_regs;
3727 u32 i, next_reg_offset = 0, offset = 0;
3728 struct dbg_idle_chk_result_hdr *hdr;
3729 const union dbg_idle_chk_reg *regs;
3730 u8 reg_id;
3731
3732 hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
3733 regs = (const union dbg_idle_chk_reg *)
3734 p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr +
3735 rule->reg_offset;
3736 cond_regs = ®s[0].cond_reg;
3737 info_regs = ®s[rule->num_cond_regs].info_reg;
3738
3739 /* Dump rule data */
3740 if (dump) {
3741 memset(hdr, 0, sizeof(*hdr));
3742 hdr->rule_id = rule_id;
3743 hdr->mem_entry_id = fail_entry_id;
3744 hdr->severity = rule->severity;
3745 hdr->num_dumped_cond_regs = rule->num_cond_regs;
3746 }
3747
3748 offset += IDLE_CHK_RESULT_HDR_DWORDS;
3749
3750 /* Dump condition register values */
3751 for (reg_id = 0; reg_id < rule->num_cond_regs; reg_id++) {
3752 const struct dbg_idle_chk_cond_reg *reg = &cond_regs[reg_id];
3753 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
3754
3755 reg_hdr =
3756 (struct dbg_idle_chk_result_reg_hdr *)(dump_buf + offset);
3757
3758 /* Write register header */
3759 if (!dump) {
3760 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS +
3761 reg->entry_size;
3762 continue;
3763 }
3764
3765 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
3766 memset(reg_hdr, 0, sizeof(*reg_hdr));
3767 reg_hdr->start_entry = reg->start_entry;
3768 reg_hdr->size = reg->entry_size;
3769 SET_FIELD(reg_hdr->data,
3770 DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM,
3771 reg->num_entries > 1 || reg->start_entry > 0 ? 1 : 0);
3772 SET_FIELD(reg_hdr->data,
3773 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID, reg_id);
3774
3775 /* Write register values */
3776 for (i = 0; i < reg_hdr->size; i++, next_reg_offset++, offset++)
3777 dump_buf[offset] = cond_reg_values[next_reg_offset];
3778 }
3779
3780 /* Dump info register values */
3781 for (reg_id = 0; reg_id < rule->num_info_regs; reg_id++) {
3782 const struct dbg_idle_chk_info_reg *reg = &info_regs[reg_id];
3783 u32 block_id;
3784
3785 /* Check if register's block is in reset */
3786 if (!dump) {
3787 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS + reg->size;
3788 continue;
3789 }
3790
3791 block_id = GET_FIELD(reg->data, DBG_IDLE_CHK_INFO_REG_BLOCK_ID);
3792 if (block_id >= MAX_BLOCK_ID) {
3793 DP_NOTICE(p_hwfn, "Invalid block_id\n");
3794 return 0;
3795 }
3796
3797 if (!dev_data->block_in_reset[block_id]) {
3798 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
3799 bool wide_bus, eval_mode, mode_match = true;
3800 u16 modes_buf_offset;
3801 u32 addr;
3802
3803 reg_hdr = (struct dbg_idle_chk_result_reg_hdr *)
3804 (dump_buf + offset);
3805
3806 /* Check mode */
3807 eval_mode = GET_FIELD(reg->mode.data,
3808 DBG_MODE_HDR_EVAL_MODE) > 0;
3809 if (eval_mode) {
3810 modes_buf_offset =
3811 GET_FIELD(reg->mode.data,
3812 DBG_MODE_HDR_MODES_BUF_OFFSET);
3813 mode_match =
3814 qed_is_mode_match(p_hwfn,
3815 &modes_buf_offset);
3816 }
3817
3818 if (!mode_match)
3819 continue;
3820
3821 addr = GET_FIELD(reg->data,
3822 DBG_IDLE_CHK_INFO_REG_ADDRESS);
3823 wide_bus = GET_FIELD(reg->data,
3824 DBG_IDLE_CHK_INFO_REG_WIDE_BUS);
3825
3826 /* Write register header */
3827 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
3828 hdr->num_dumped_info_regs++;
3829 memset(reg_hdr, 0, sizeof(*reg_hdr));
3830 reg_hdr->size = reg->size;
3831 SET_FIELD(reg_hdr->data,
3832 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID,
3833 rule->num_cond_regs + reg_id);
3834
3835 /* Write register values */
3836 offset += qed_grc_dump_addr_range(p_hwfn,
3837 p_ptt,
3838 dump_buf + offset,
3839 dump,
3840 addr,
3841 reg->size, wide_bus,
3842 SPLIT_TYPE_NONE, 0);
3843 }
3844 }
3845
3846 return offset;
3847}
3848
3849/* Dumps idle check rule entries. Returns the dumped size in dwords. */
3850static u32
3851qed_idle_chk_dump_rule_entries(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3852 u32 *dump_buf, bool dump,
3853 const struct dbg_idle_chk_rule *input_rules,
3854 u32 num_input_rules, u32 *num_failing_rules)
3855{
3856 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3857 u32 cond_reg_values[IDLE_CHK_MAX_ENTRIES_SIZE];
3858 u32 i, offset = 0;
3859 u16 entry_id;
3860 u8 reg_id;
3861
3862 *num_failing_rules = 0;
3863
3864 for (i = 0; i < num_input_rules; i++) {
3865 const struct dbg_idle_chk_cond_reg *cond_regs;
3866 const struct dbg_idle_chk_rule *rule;
3867 const union dbg_idle_chk_reg *regs;
3868 u16 num_reg_entries = 1;
3869 bool check_rule = true;
3870 const u32 *imm_values;
3871
3872 rule = &input_rules[i];
3873 regs = (const union dbg_idle_chk_reg *)
3874 p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr +
3875 rule->reg_offset;
3876 cond_regs = ®s[0].cond_reg;
3877 imm_values =
3878 (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr +
3879 rule->imm_offset;
3880
3881 /* Check if all condition register blocks are out of reset, and
3882 * find maximal number of entries (all condition registers that
3883 * are memories must have the same size, which is > 1).
3884 */
3885 for (reg_id = 0; reg_id < rule->num_cond_regs && check_rule;
3886 reg_id++) {
3887 u32 block_id =
3888 GET_FIELD(cond_regs[reg_id].data,
3889 DBG_IDLE_CHK_COND_REG_BLOCK_ID);
3890
3891 if (block_id >= MAX_BLOCK_ID) {
3892 DP_NOTICE(p_hwfn, "Invalid block_id\n");
3893 return 0;
3894 }
3895
3896 check_rule = !dev_data->block_in_reset[block_id];
3897 if (cond_regs[reg_id].num_entries > num_reg_entries)
3898 num_reg_entries = cond_regs[reg_id].num_entries;
3899 }
3900
3901 if (!check_rule && dump)
3902 continue;
3903
3904 if (!dump) {
3905 u32 entry_dump_size =
3906 qed_idle_chk_dump_failure(p_hwfn,
3907 p_ptt,
3908 dump_buf + offset,
3909 false,
3910 rule->rule_id,
3911 rule,
3912 0,
3913 NULL);
3914
3915 offset += num_reg_entries * entry_dump_size;
3916 (*num_failing_rules) += num_reg_entries;
3917 continue;
3918 }
3919
3920 /* Go over all register entries (number of entries is the same
3921 * for all condition registers).
3922 */
3923 for (entry_id = 0; entry_id < num_reg_entries; entry_id++) {
3924 u32 next_reg_offset = 0;
3925
3926 /* Read current entry of all condition registers */
3927 for (reg_id = 0; reg_id < rule->num_cond_regs;
3928 reg_id++) {
3929 const struct dbg_idle_chk_cond_reg *reg =
3930 &cond_regs[reg_id];
3931 u32 padded_entry_size, addr;
3932 bool wide_bus;
3933
3934 /* Find GRC address (if it's a memory, the
3935 * address of the specific entry is calculated).
3936 */
3937 addr = GET_FIELD(reg->data,
3938 DBG_IDLE_CHK_COND_REG_ADDRESS);
3939 wide_bus =
3940 GET_FIELD(reg->data,
3941 DBG_IDLE_CHK_COND_REG_WIDE_BUS);
3942 if (reg->num_entries > 1 ||
3943 reg->start_entry > 0) {
3944 padded_entry_size =
3945 reg->entry_size > 1 ?
3946 roundup_pow_of_two(reg->entry_size) :
3947 1;
3948 addr += (reg->start_entry + entry_id) *
3949 padded_entry_size;
3950 }
3951
3952 /* Read registers */
3953 if (next_reg_offset + reg->entry_size >=
3954 IDLE_CHK_MAX_ENTRIES_SIZE) {
3955 DP_NOTICE(p_hwfn,
3956 "idle check registers entry is too large\n");
3957 return 0;
3958 }
3959
3960 next_reg_offset +=
3961 qed_grc_dump_addr_range(p_hwfn, p_ptt,
3962 cond_reg_values +
3963 next_reg_offset,
3964 dump, addr,
3965 reg->entry_size,
3966 wide_bus,
3967 SPLIT_TYPE_NONE, 0);
3968 }
3969
3970 /* Call rule condition function.
3971 * If returns true, it's a failure.
3972 */
3973 if ((*cond_arr[rule->cond_id]) (cond_reg_values,
3974 imm_values)) {
3975 offset += qed_idle_chk_dump_failure(p_hwfn,
3976 p_ptt,
3977 dump_buf + offset,
3978 dump,
3979 rule->rule_id,
3980 rule,
3981 entry_id,
3982 cond_reg_values);
3983 (*num_failing_rules)++;
3984 }
3985 }
3986 }
3987
3988 return offset;
3989}
3990
3991/* Performs Idle Check Dump to the specified buffer.
3992 * Returns the dumped size in dwords.
3993 */
3994static u32 qed_idle_chk_dump(struct qed_hwfn *p_hwfn,
3995 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3996{
3997 struct virt_mem_desc *dbg_buf =
3998 &p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES];
3999 u32 num_failing_rules_offset, offset = 0,
4000 input_offset = 0, num_failing_rules = 0;
4001
4002 /* Dump global params - 1 must match below amount of params */
4003 offset += qed_dump_common_global_params(p_hwfn,
4004 p_ptt,
4005 dump_buf + offset, dump, 1);
4006 offset += qed_dump_str_param(dump_buf + offset,
4007 dump, "dump-type", "idle-chk");
4008
4009 /* Dump idle check section header with a single parameter */
4010 offset += qed_dump_section_hdr(dump_buf + offset, dump, "idle_chk", 1);
4011 num_failing_rules_offset = offset;
4012 offset += qed_dump_num_param(dump_buf + offset, dump, "num_rules", 0);
4013
4014 while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
4015 const struct dbg_idle_chk_cond_hdr *cond_hdr =
4016 (const struct dbg_idle_chk_cond_hdr *)dbg_buf->ptr +
4017 input_offset++;
4018 bool eval_mode, mode_match = true;
4019 u32 curr_failing_rules;
4020 u16 modes_buf_offset;
4021
4022 /* Check mode */
4023 eval_mode = GET_FIELD(cond_hdr->mode.data,
4024 DBG_MODE_HDR_EVAL_MODE) > 0;
4025 if (eval_mode) {
4026 modes_buf_offset =
4027 GET_FIELD(cond_hdr->mode.data,
4028 DBG_MODE_HDR_MODES_BUF_OFFSET);
4029 mode_match = qed_is_mode_match(p_hwfn,
4030 &modes_buf_offset);
4031 }
4032
4033 if (mode_match) {
4034 const struct dbg_idle_chk_rule *rule =
4035 (const struct dbg_idle_chk_rule *)((u32 *)
4036 dbg_buf->ptr
4037 + input_offset);
4038 u32 num_input_rules =
4039 cond_hdr->data_size / IDLE_CHK_RULE_SIZE_DWORDS;
4040 offset +=
4041 qed_idle_chk_dump_rule_entries(p_hwfn,
4042 p_ptt,
4043 dump_buf +
4044 offset,
4045 dump,
4046 rule,
4047 num_input_rules,
4048 &curr_failing_rules);
4049 num_failing_rules += curr_failing_rules;
4050 }
4051
4052 input_offset += cond_hdr->data_size;
4053 }
4054
4055 /* Overwrite num_rules parameter */
4056 if (dump)
4057 qed_dump_num_param(dump_buf + num_failing_rules_offset,
4058 dump, "num_rules", num_failing_rules);
4059
4060 /* Dump last section */
4061 offset += qed_dump_last_section(dump_buf, offset, dump);
4062
4063 return offset;
4064}
4065
4066/* Get info on the MCP Trace data in the scratchpad:
4067 * - trace_data_grc_addr (OUT): trace data GRC address in bytes
4068 * - trace_data_size (OUT): trace data size in bytes (without the header)
4069 */
4070static enum dbg_status qed_mcp_trace_get_data_info(struct qed_hwfn *p_hwfn,
4071 struct qed_ptt *p_ptt,
4072 u32 *trace_data_grc_addr,
4073 u32 *trace_data_size)
4074{
4075 u32 spad_trace_offsize, signature;
4076
4077 /* Read trace section offsize structure from MCP scratchpad */
4078 spad_trace_offsize = qed_rd(p_hwfn, p_ptt, MCP_SPAD_TRACE_OFFSIZE_ADDR);
4079
4080 /* Extract trace section address from offsize (in scratchpad) */
4081 *trace_data_grc_addr =
4082 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize);
4083
4084 /* Read signature from MCP trace section */
4085 signature = qed_rd(p_hwfn, p_ptt,
4086 *trace_data_grc_addr +
4087 offsetof(struct mcp_trace, signature));
4088
4089 if (signature != MFW_TRACE_SIGNATURE)
4090 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4091
4092 /* Read trace size from MCP trace section */
4093 *trace_data_size = qed_rd(p_hwfn,
4094 p_ptt,
4095 *trace_data_grc_addr +
4096 offsetof(struct mcp_trace, size));
4097
4098 return DBG_STATUS_OK;
4099}
4100
4101/* Reads MCP trace meta data image from NVRAM
4102 * - running_bundle_id (OUT): running bundle ID (invalid when loaded from file)
4103 * - trace_meta_offset (OUT): trace meta offset in NVRAM in bytes (invalid when
4104 * loaded from file).
4105 * - trace_meta_size (OUT): size in bytes of the trace meta data.
4106 */
4107static enum dbg_status qed_mcp_trace_get_meta_info(struct qed_hwfn *p_hwfn,
4108 struct qed_ptt *p_ptt,
4109 u32 trace_data_size_bytes,
4110 u32 *running_bundle_id,
4111 u32 *trace_meta_offset,
4112 u32 *trace_meta_size)
4113{
4114 u32 spad_trace_offsize, nvram_image_type, running_mfw_addr;
4115
4116 /* Read MCP trace section offsize structure from MCP scratchpad */
4117 spad_trace_offsize = qed_rd(p_hwfn, p_ptt, MCP_SPAD_TRACE_OFFSIZE_ADDR);
4118
4119 /* Find running bundle ID */
4120 running_mfw_addr =
4121 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize) +
4122 QED_SECTION_SIZE(spad_trace_offsize) + trace_data_size_bytes;
4123 *running_bundle_id = qed_rd(p_hwfn, p_ptt, running_mfw_addr);
4124 if (*running_bundle_id > 1)
4125 return DBG_STATUS_INVALID_NVRAM_BUNDLE;
4126
4127 /* Find image in NVRAM */
4128 nvram_image_type =
4129 (*running_bundle_id ==
4130 DIR_ID_1) ? NVM_TYPE_MFW_TRACE1 : NVM_TYPE_MFW_TRACE2;
4131 return qed_find_nvram_image(p_hwfn,
4132 p_ptt,
4133 nvram_image_type,
4134 trace_meta_offset,
4135 trace_meta_size,
4136 true);
4137}
4138
4139/* Reads the MCP Trace meta data from NVRAM into the specified buffer */
4140static enum dbg_status qed_mcp_trace_read_meta(struct qed_hwfn *p_hwfn,
4141 struct qed_ptt *p_ptt,
4142 u32 nvram_offset_in_bytes,
4143 u32 size_in_bytes, u32 *buf)
4144{
4145 u8 modules_num, module_len, i, *byte_buf = (u8 *)buf;
4146 enum dbg_status status;
4147 u32 signature;
4148
4149 /* Read meta data from NVRAM */
4150 status = qed_nvram_read(p_hwfn,
4151 p_ptt,
4152 nvram_offset_in_bytes,
4153 size_in_bytes,
4154 buf,
4155 true);
4156 if (status != DBG_STATUS_OK)
4157 return status;
4158
4159 /* Extract and check first signature */
4160 signature = qed_read_unaligned_dword(byte_buf);
4161 byte_buf += sizeof(signature);
4162 if (signature != NVM_MAGIC_VALUE)
4163 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4164
4165 /* Extract number of modules */
4166 modules_num = *(byte_buf++);
4167
4168 /* Skip all modules */
4169 for (i = 0; i < modules_num; i++) {
4170 module_len = *(byte_buf++);
4171 byte_buf += module_len;
4172 }
4173
4174 /* Extract and check second signature */
4175 signature = qed_read_unaligned_dword(byte_buf);
4176 byte_buf += sizeof(signature);
4177 if (signature != NVM_MAGIC_VALUE)
4178 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4179
4180 return DBG_STATUS_OK;
4181}
4182
4183/* Dump MCP Trace */
4184static enum dbg_status qed_mcp_trace_dump(struct qed_hwfn *p_hwfn,
4185 struct qed_ptt *p_ptt,
4186 u32 *dump_buf,
4187 bool dump, u32 *num_dumped_dwords)
4188{
4189 u32 trace_data_grc_addr, trace_data_size_bytes, trace_data_size_dwords;
4190 u32 trace_meta_size_dwords = 0, running_bundle_id, offset = 0;
4191 u32 trace_meta_offset_bytes = 0, trace_meta_size_bytes = 0;
4192 enum dbg_status status;
4193 int halted = 0;
4194 bool use_mfw;
4195
4196 *num_dumped_dwords = 0;
4197
4198 use_mfw = !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP);
4199
4200 /* Get trace data info */
4201 status = qed_mcp_trace_get_data_info(p_hwfn,
4202 p_ptt,
4203 &trace_data_grc_addr,
4204 &trace_data_size_bytes);
4205 if (status != DBG_STATUS_OK)
4206 return status;
4207
4208 /* Dump global params */
4209 offset += qed_dump_common_global_params(p_hwfn,
4210 p_ptt,
4211 dump_buf + offset, dump, 1);
4212 offset += qed_dump_str_param(dump_buf + offset,
4213 dump, "dump-type", "mcp-trace");
4214
4215 /* Halt MCP while reading from scratchpad so the read data will be
4216 * consistent. if halt fails, MCP trace is taken anyway, with a small
4217 * risk that it may be corrupt.
4218 */
4219 if (dump && use_mfw) {
4220 halted = !qed_mcp_halt(p_hwfn, p_ptt);
4221 if (!halted)
4222 DP_NOTICE(p_hwfn, "MCP halt failed!\n");
4223 }
4224
4225 /* Find trace data size */
4226 trace_data_size_dwords =
4227 DIV_ROUND_UP(trace_data_size_bytes + sizeof(struct mcp_trace),
4228 BYTES_IN_DWORD);
4229
4230 /* Dump trace data section header and param */
4231 offset += qed_dump_section_hdr(dump_buf + offset,
4232 dump, "mcp_trace_data", 1);
4233 offset += qed_dump_num_param(dump_buf + offset,
4234 dump, "size", trace_data_size_dwords);
4235
4236 /* Read trace data from scratchpad into dump buffer */
4237 offset += qed_grc_dump_addr_range(p_hwfn,
4238 p_ptt,
4239 dump_buf + offset,
4240 dump,
4241 BYTES_TO_DWORDS(trace_data_grc_addr),
4242 trace_data_size_dwords, false,
4243 SPLIT_TYPE_NONE, 0);
4244
4245 /* Resume MCP (only if halt succeeded) */
4246 if (halted && qed_mcp_resume(p_hwfn, p_ptt))
4247 DP_NOTICE(p_hwfn, "Failed to resume MCP after halt!\n");
4248
4249 /* Dump trace meta section header */
4250 offset += qed_dump_section_hdr(dump_buf + offset,
4251 dump, "mcp_trace_meta", 1);
4252
4253 /* If MCP Trace meta size parameter was set, use it.
4254 * Otherwise, read trace meta.
4255 * trace_meta_size_bytes is dword-aligned.
4256 */
4257 trace_meta_size_bytes =
4258 qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_MCP_TRACE_META_SIZE);
4259 if ((!trace_meta_size_bytes || dump) && use_mfw)
4260 status = qed_mcp_trace_get_meta_info(p_hwfn,
4261 p_ptt,
4262 trace_data_size_bytes,
4263 &running_bundle_id,
4264 &trace_meta_offset_bytes,
4265 &trace_meta_size_bytes);
4266 if (status == DBG_STATUS_OK)
4267 trace_meta_size_dwords = BYTES_TO_DWORDS(trace_meta_size_bytes);
4268
4269 /* Dump trace meta size param */
4270 offset += qed_dump_num_param(dump_buf + offset,
4271 dump, "size", trace_meta_size_dwords);
4272
4273 /* Read trace meta image into dump buffer */
4274 if (dump && trace_meta_size_dwords)
4275 status = qed_mcp_trace_read_meta(p_hwfn,
4276 p_ptt,
4277 trace_meta_offset_bytes,
4278 trace_meta_size_bytes,
4279 dump_buf + offset);
4280 if (status == DBG_STATUS_OK)
4281 offset += trace_meta_size_dwords;
4282
4283 /* Dump last section */
4284 offset += qed_dump_last_section(dump_buf, offset, dump);
4285
4286 *num_dumped_dwords = offset;
4287
4288 /* If no mcp access, indicate that the dump doesn't contain the meta
4289 * data from NVRAM.
4290 */
4291 return use_mfw ? status : DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
4292}
4293
4294/* Dump GRC FIFO */
4295static enum dbg_status qed_reg_fifo_dump(struct qed_hwfn *p_hwfn,
4296 struct qed_ptt *p_ptt,
4297 u32 *dump_buf,
4298 bool dump, u32 *num_dumped_dwords)
4299{
4300 u32 dwords_read, size_param_offset, offset = 0, addr, len;
4301 bool fifo_has_data;
4302
4303 *num_dumped_dwords = 0;
4304
4305 /* Dump global params */
4306 offset += qed_dump_common_global_params(p_hwfn,
4307 p_ptt,
4308 dump_buf + offset, dump, 1);
4309 offset += qed_dump_str_param(dump_buf + offset,
4310 dump, "dump-type", "reg-fifo");
4311
4312 /* Dump fifo data section header and param. The size param is 0 for
4313 * now, and is overwritten after reading the FIFO.
4314 */
4315 offset += qed_dump_section_hdr(dump_buf + offset,
4316 dump, "reg_fifo_data", 1);
4317 size_param_offset = offset;
4318 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4319
4320 if (!dump) {
4321 /* FIFO max size is REG_FIFO_DEPTH_DWORDS. There is no way to
4322 * test how much data is available, except for reading it.
4323 */
4324 offset += REG_FIFO_DEPTH_DWORDS;
4325 goto out;
4326 }
4327
4328 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4329 GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
4330
4331 /* Pull available data from fifo. Use DMAE since this is widebus memory
4332 * and must be accessed atomically. Test for dwords_read not passing
4333 * buffer size since more entries could be added to the buffer as we are
4334 * emptying it.
4335 */
4336 addr = BYTES_TO_DWORDS(GRC_REG_TRACE_FIFO);
4337 len = REG_FIFO_ELEMENT_DWORDS;
4338 for (dwords_read = 0;
4339 fifo_has_data && dwords_read < REG_FIFO_DEPTH_DWORDS;
4340 dwords_read += REG_FIFO_ELEMENT_DWORDS) {
4341 offset += qed_grc_dump_addr_range(p_hwfn,
4342 p_ptt,
4343 dump_buf + offset,
4344 true,
4345 addr,
4346 len,
4347 true, SPLIT_TYPE_NONE,
4348 0);
4349 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4350 GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
4351 }
4352
4353 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4354 dwords_read);
4355out:
4356 /* Dump last section */
4357 offset += qed_dump_last_section(dump_buf, offset, dump);
4358
4359 *num_dumped_dwords = offset;
4360
4361 return DBG_STATUS_OK;
4362}
4363
4364/* Dump IGU FIFO */
4365static enum dbg_status qed_igu_fifo_dump(struct qed_hwfn *p_hwfn,
4366 struct qed_ptt *p_ptt,
4367 u32 *dump_buf,
4368 bool dump, u32 *num_dumped_dwords)
4369{
4370 u32 dwords_read, size_param_offset, offset = 0, addr, len;
4371 bool fifo_has_data;
4372
4373 *num_dumped_dwords = 0;
4374
4375 /* Dump global params */
4376 offset += qed_dump_common_global_params(p_hwfn,
4377 p_ptt,
4378 dump_buf + offset, dump, 1);
4379 offset += qed_dump_str_param(dump_buf + offset,
4380 dump, "dump-type", "igu-fifo");
4381
4382 /* Dump fifo data section header and param. The size param is 0 for
4383 * now, and is overwritten after reading the FIFO.
4384 */
4385 offset += qed_dump_section_hdr(dump_buf + offset,
4386 dump, "igu_fifo_data", 1);
4387 size_param_offset = offset;
4388 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4389
4390 if (!dump) {
4391 /* FIFO max size is IGU_FIFO_DEPTH_DWORDS. There is no way to
4392 * test how much data is available, except for reading it.
4393 */
4394 offset += IGU_FIFO_DEPTH_DWORDS;
4395 goto out;
4396 }
4397
4398 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4399 IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
4400
4401 /* Pull available data from fifo. Use DMAE since this is widebus memory
4402 * and must be accessed atomically. Test for dwords_read not passing
4403 * buffer size since more entries could be added to the buffer as we are
4404 * emptying it.
4405 */
4406 addr = BYTES_TO_DWORDS(IGU_REG_ERROR_HANDLING_MEMORY);
4407 len = IGU_FIFO_ELEMENT_DWORDS;
4408 for (dwords_read = 0;
4409 fifo_has_data && dwords_read < IGU_FIFO_DEPTH_DWORDS;
4410 dwords_read += IGU_FIFO_ELEMENT_DWORDS) {
4411 offset += qed_grc_dump_addr_range(p_hwfn,
4412 p_ptt,
4413 dump_buf + offset,
4414 true,
4415 addr,
4416 len,
4417 true, SPLIT_TYPE_NONE,
4418 0);
4419 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4420 IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
4421 }
4422
4423 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4424 dwords_read);
4425out:
4426 /* Dump last section */
4427 offset += qed_dump_last_section(dump_buf, offset, dump);
4428
4429 *num_dumped_dwords = offset;
4430
4431 return DBG_STATUS_OK;
4432}
4433
4434/* Protection Override dump */
4435static enum dbg_status qed_protection_override_dump(struct qed_hwfn *p_hwfn,
4436 struct qed_ptt *p_ptt,
4437 u32 *dump_buf,
4438 bool dump,
4439 u32 *num_dumped_dwords)
4440{
4441 u32 size_param_offset, override_window_dwords, offset = 0, addr;
4442
4443 *num_dumped_dwords = 0;
4444
4445 /* Dump global params */
4446 offset += qed_dump_common_global_params(p_hwfn,
4447 p_ptt,
4448 dump_buf + offset, dump, 1);
4449 offset += qed_dump_str_param(dump_buf + offset,
4450 dump, "dump-type", "protection-override");
4451
4452 /* Dump data section header and param. The size param is 0 for now,
4453 * and is overwritten after reading the data.
4454 */
4455 offset += qed_dump_section_hdr(dump_buf + offset,
4456 dump, "protection_override_data", 1);
4457 size_param_offset = offset;
4458 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4459
4460 if (!dump) {
4461 offset += PROTECTION_OVERRIDE_DEPTH_DWORDS;
4462 goto out;
4463 }
4464
4465 /* Add override window info to buffer */
4466 override_window_dwords =
4467 qed_rd(p_hwfn, p_ptt, GRC_REG_NUMBER_VALID_OVERRIDE_WINDOW) *
4468 PROTECTION_OVERRIDE_ELEMENT_DWORDS;
4469 if (override_window_dwords) {
4470 addr = BYTES_TO_DWORDS(GRC_REG_PROTECTION_OVERRIDE_WINDOW);
4471 offset += qed_grc_dump_addr_range(p_hwfn,
4472 p_ptt,
4473 dump_buf + offset,
4474 true,
4475 addr,
4476 override_window_dwords,
4477 true, SPLIT_TYPE_NONE, 0);
4478 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4479 override_window_dwords);
4480 }
4481out:
4482 /* Dump last section */
4483 offset += qed_dump_last_section(dump_buf, offset, dump);
4484
4485 *num_dumped_dwords = offset;
4486
4487 return DBG_STATUS_OK;
4488}
4489
4490/* Performs FW Asserts Dump to the specified buffer.
4491 * Returns the dumped size in dwords.
4492 */
4493static u32 qed_fw_asserts_dump(struct qed_hwfn *p_hwfn,
4494 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
4495{
4496 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
4497 struct fw_asserts_ram_section *asserts;
4498 char storm_letter_str[2] = "?";
4499 struct fw_info fw_info;
4500 u32 offset = 0;
4501 u8 storm_id;
4502
4503 /* Dump global params */
4504 offset += qed_dump_common_global_params(p_hwfn,
4505 p_ptt,
4506 dump_buf + offset, dump, 1);
4507 offset += qed_dump_str_param(dump_buf + offset,
4508 dump, "dump-type", "fw-asserts");
4509
4510 /* Find Storm dump size */
4511 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
4512 u32 fw_asserts_section_addr, next_list_idx_addr, next_list_idx;
4513 struct storm_defs *storm = &s_storm_defs[storm_id];
4514 u32 last_list_idx, addr;
4515
4516 if (dev_data->block_in_reset[storm->sem_block_id])
4517 continue;
4518
4519 /* Read FW info for the current Storm */
4520 qed_read_storm_fw_info(p_hwfn, p_ptt, storm_id, &fw_info);
4521
4522 asserts = &fw_info.fw_asserts_section;
4523
4524 /* Dump FW Asserts section header and params */
4525 storm_letter_str[0] = storm->letter;
4526 offset += qed_dump_section_hdr(dump_buf + offset,
4527 dump, "fw_asserts", 2);
4528 offset += qed_dump_str_param(dump_buf + offset,
4529 dump, "storm", storm_letter_str);
4530 offset += qed_dump_num_param(dump_buf + offset,
4531 dump,
4532 "size",
4533 asserts->list_element_dword_size);
4534
4535 /* Read and dump FW Asserts data */
4536 if (!dump) {
4537 offset += asserts->list_element_dword_size;
4538 continue;
4539 }
4540
4541 addr = le16_to_cpu(asserts->section_ram_line_offset);
4542 fw_asserts_section_addr = storm->sem_fast_mem_addr +
4543 SEM_FAST_REG_INT_RAM +
4544 RAM_LINES_TO_BYTES(addr);
4545
4546 next_list_idx_addr = fw_asserts_section_addr +
4547 DWORDS_TO_BYTES(asserts->list_next_index_dword_offset);
4548 next_list_idx = qed_rd(p_hwfn, p_ptt, next_list_idx_addr);
4549 last_list_idx = (next_list_idx > 0 ?
4550 next_list_idx :
4551 asserts->list_num_elements) - 1;
4552 addr = BYTES_TO_DWORDS(fw_asserts_section_addr) +
4553 asserts->list_dword_offset +
4554 last_list_idx * asserts->list_element_dword_size;
4555 offset +=
4556 qed_grc_dump_addr_range(p_hwfn, p_ptt,
4557 dump_buf + offset,
4558 dump, addr,
4559 asserts->list_element_dword_size,
4560 false, SPLIT_TYPE_NONE, 0);
4561 }
4562
4563 /* Dump last section */
4564 offset += qed_dump_last_section(dump_buf, offset, dump);
4565
4566 return offset;
4567}
4568
4569/* Dumps the specified ILT pages to the specified buffer.
4570 * Returns the dumped size in dwords.
4571 */
4572static u32 qed_ilt_dump_pages_range(u32 *dump_buf, u32 *given_offset,
4573 bool *dump, u32 start_page_id,
4574 u32 num_pages,
4575 struct phys_mem_desc *ilt_pages,
4576 bool dump_page_ids, u32 buf_size_in_dwords,
4577 u32 *given_actual_dump_size_in_dwords)
4578{
4579 u32 actual_dump_size_in_dwords = *given_actual_dump_size_in_dwords;
4580 u32 page_id, end_page_id, offset = *given_offset;
4581 struct phys_mem_desc *mem_desc = NULL;
4582 bool continue_dump = *dump;
4583 u32 partial_page_size = 0;
4584
4585 if (num_pages == 0)
4586 return offset;
4587
4588 end_page_id = start_page_id + num_pages - 1;
4589
4590 for (page_id = start_page_id; page_id <= end_page_id; page_id++) {
4591 mem_desc = &ilt_pages[page_id];
4592 if (!ilt_pages[page_id].virt_addr)
4593 continue;
4594
4595 if (dump_page_ids) {
4596 /* Copy page ID to dump buffer
4597 * (if dump is needed and buffer is not full)
4598 */
4599 if ((continue_dump) &&
4600 (offset + 1 > buf_size_in_dwords)) {
4601 continue_dump = false;
4602 actual_dump_size_in_dwords = offset;
4603 }
4604 if (continue_dump)
4605 *(dump_buf + offset) = page_id;
4606 offset++;
4607 } else {
4608 /* Copy page memory to dump buffer */
4609 if ((continue_dump) &&
4610 (offset + BYTES_TO_DWORDS(mem_desc->size) >
4611 buf_size_in_dwords)) {
4612 if (offset + BYTES_TO_DWORDS(mem_desc->size) >
4613 buf_size_in_dwords) {
4614 partial_page_size =
4615 buf_size_in_dwords - offset;
4616 memcpy(dump_buf + offset,
4617 mem_desc->virt_addr,
4618 partial_page_size);
4619 continue_dump = false;
4620 actual_dump_size_in_dwords =
4621 offset + partial_page_size;
4622 }
4623 }
4624
4625 if (continue_dump)
4626 memcpy(dump_buf + offset,
4627 mem_desc->virt_addr, mem_desc->size);
4628 offset += BYTES_TO_DWORDS(mem_desc->size);
4629 }
4630 }
4631
4632 *dump = continue_dump;
4633 *given_offset = offset;
4634 *given_actual_dump_size_in_dwords = actual_dump_size_in_dwords;
4635
4636 return offset;
4637}
4638
4639/* Dumps a section containing the dumped ILT pages.
4640 * Returns the dumped size in dwords.
4641 */
4642static u32 qed_ilt_dump_pages_section(struct qed_hwfn *p_hwfn,
4643 u32 *dump_buf,
4644 u32 *given_offset,
4645 bool *dump,
4646 u32 valid_conn_pf_pages,
4647 u32 valid_conn_vf_pages,
4648 struct phys_mem_desc *ilt_pages,
4649 bool dump_page_ids,
4650 u32 buf_size_in_dwords,
4651 u32 *given_actual_dump_size_in_dwords)
4652{
4653 struct qed_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients;
4654 u32 pf_start_line, start_page_id, offset = *given_offset;
4655 u32 cdut_pf_init_pages, cdut_vf_init_pages;
4656 u32 cdut_pf_work_pages, cdut_vf_work_pages;
4657 u32 base_data_offset, size_param_offset;
4658 u32 src_pages;
4659 u32 section_header_and_param_size;
4660 u32 cdut_pf_pages, cdut_vf_pages;
4661 u32 actual_dump_size_in_dwords;
4662 bool continue_dump = *dump;
4663 bool update_size = *dump;
4664 const char *section_name;
4665 u32 i;
4666
4667 actual_dump_size_in_dwords = *given_actual_dump_size_in_dwords;
4668 section_name = dump_page_ids ? "ilt_page_ids" : "ilt_page_mem";
4669 cdut_pf_init_pages = qed_get_cdut_num_pf_init_pages(p_hwfn);
4670 cdut_vf_init_pages = qed_get_cdut_num_vf_init_pages(p_hwfn);
4671 cdut_pf_work_pages = qed_get_cdut_num_pf_work_pages(p_hwfn);
4672 cdut_vf_work_pages = qed_get_cdut_num_vf_work_pages(p_hwfn);
4673 cdut_pf_pages = cdut_pf_init_pages + cdut_pf_work_pages;
4674 cdut_vf_pages = cdut_vf_init_pages + cdut_vf_work_pages;
4675 pf_start_line = p_hwfn->p_cxt_mngr->pf_start_line;
4676 section_header_and_param_size = qed_dump_section_hdr(NULL,
4677 false,
4678 section_name,
4679 1) +
4680 qed_dump_num_param(NULL, false, "size", 0);
4681
4682 if ((continue_dump) &&
4683 (offset + section_header_and_param_size > buf_size_in_dwords)) {
4684 continue_dump = false;
4685 update_size = false;
4686 actual_dump_size_in_dwords = offset;
4687 }
4688
4689 offset += qed_dump_section_hdr(dump_buf + offset,
4690 continue_dump, section_name, 1);
4691
4692 /* Dump size parameter (0 for now, overwritten with real size later) */
4693 size_param_offset = offset;
4694 offset += qed_dump_num_param(dump_buf + offset,
4695 continue_dump, "size", 0);
4696 base_data_offset = offset;
4697
4698 /* CDUC pages are ordered as follows:
4699 * - PF pages - valid section (included in PF connection type mapping)
4700 * - PF pages - invalid section (not dumped)
4701 * - For each VF in the PF:
4702 * - VF pages - valid section (included in VF connection type mapping)
4703 * - VF pages - invalid section (not dumped)
4704 */
4705 if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_DUMP_ILT_CDUC)) {
4706 /* Dump connection PF pages */
4707 start_page_id = clients[ILT_CLI_CDUC].first.val - pf_start_line;
4708 qed_ilt_dump_pages_range(dump_buf, &offset, &continue_dump,
4709 start_page_id, valid_conn_pf_pages,
4710 ilt_pages, dump_page_ids,
4711 buf_size_in_dwords,
4712 &actual_dump_size_in_dwords);
4713
4714 /* Dump connection VF pages */
4715 start_page_id += clients[ILT_CLI_CDUC].pf_total_lines;
4716 for (i = 0; i < p_hwfn->p_cxt_mngr->vf_count;
4717 i++, start_page_id += clients[ILT_CLI_CDUC].vf_total_lines)
4718 qed_ilt_dump_pages_range(dump_buf, &offset,
4719 &continue_dump, start_page_id,
4720 valid_conn_vf_pages,
4721 ilt_pages, dump_page_ids,
4722 buf_size_in_dwords,
4723 &actual_dump_size_in_dwords);
4724 }
4725
4726 /* CDUT pages are ordered as follows:
4727 * - PF init pages (not dumped)
4728 * - PF work pages
4729 * - For each VF in the PF:
4730 * - VF init pages (not dumped)
4731 * - VF work pages
4732 */
4733 if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_DUMP_ILT_CDUT)) {
4734 /* Dump task PF pages */
4735 start_page_id = clients[ILT_CLI_CDUT].first.val +
4736 cdut_pf_init_pages - pf_start_line;
4737 qed_ilt_dump_pages_range(dump_buf, &offset, &continue_dump,
4738 start_page_id, cdut_pf_work_pages,
4739 ilt_pages, dump_page_ids,
4740 buf_size_in_dwords,
4741 &actual_dump_size_in_dwords);
4742
4743 /* Dump task VF pages */
4744 start_page_id = clients[ILT_CLI_CDUT].first.val +
4745 cdut_pf_pages + cdut_vf_init_pages - pf_start_line;
4746 for (i = 0; i < p_hwfn->p_cxt_mngr->vf_count;
4747 i++, start_page_id += cdut_vf_pages)
4748 qed_ilt_dump_pages_range(dump_buf, &offset,
4749 &continue_dump, start_page_id,
4750 cdut_vf_work_pages, ilt_pages,
4751 dump_page_ids,
4752 buf_size_in_dwords,
4753 &actual_dump_size_in_dwords);
4754 }
4755
4756 /*Dump Searcher pages */
4757 if (clients[ILT_CLI_SRC].active) {
4758 start_page_id = clients[ILT_CLI_SRC].first.val - pf_start_line;
4759 src_pages = clients[ILT_CLI_SRC].last.val -
4760 clients[ILT_CLI_SRC].first.val + 1;
4761 qed_ilt_dump_pages_range(dump_buf, &offset, &continue_dump,
4762 start_page_id, src_pages, ilt_pages,
4763 dump_page_ids, buf_size_in_dwords,
4764 &actual_dump_size_in_dwords);
4765 }
4766
4767 /* Overwrite size param */
4768 if (update_size) {
4769 u32 section_size = (*dump == continue_dump) ?
4770 offset - base_data_offset :
4771 actual_dump_size_in_dwords - base_data_offset;
4772 if (section_size > 0)
4773 qed_dump_num_param(dump_buf + size_param_offset,
4774 *dump, "size", section_size);
4775 else if ((section_size == 0) && (*dump != continue_dump))
4776 actual_dump_size_in_dwords -=
4777 section_header_and_param_size;
4778 }
4779
4780 *dump = continue_dump;
4781 *given_offset = offset;
4782 *given_actual_dump_size_in_dwords = actual_dump_size_in_dwords;
4783
4784 return offset;
4785}
4786
4787/* Dumps a section containing the global parameters.
4788 * Part of ilt dump process
4789 * Returns the dumped size in dwords.
4790 */
4791static u32
4792qed_ilt_dump_dump_common_global_params(struct qed_hwfn *p_hwfn,
4793 struct qed_ptt *p_ptt,
4794 u32 *dump_buf,
4795 bool dump,
4796 u32 cduc_page_size,
4797 u32 conn_ctx_size,
4798 u32 cdut_page_size,
4799 u32 *full_dump_size_param_offset,
4800 u32 *actual_dump_size_param_offset)
4801{
4802 struct qed_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients;
4803 u32 offset = 0;
4804
4805 offset += qed_dump_common_global_params(p_hwfn, p_ptt,
4806 dump_buf + offset,
4807 dump, 30);
4808 offset += qed_dump_str_param(dump_buf + offset,
4809 dump,
4810 "dump-type", "ilt-dump");
4811 offset += qed_dump_num_param(dump_buf + offset,
4812 dump,
4813 "cduc-page-size",
4814 cduc_page_size);
4815 offset += qed_dump_num_param(dump_buf + offset,
4816 dump,
4817 "cduc-first-page-id",
4818 clients[ILT_CLI_CDUC].first.val);
4819 offset += qed_dump_num_param(dump_buf + offset,
4820 dump,
4821 "cduc-last-page-id",
4822 clients[ILT_CLI_CDUC].last.val);
4823 offset += qed_dump_num_param(dump_buf + offset,
4824 dump,
4825 "cduc-num-pf-pages",
4826 clients[ILT_CLI_CDUC].pf_total_lines);
4827 offset += qed_dump_num_param(dump_buf + offset,
4828 dump,
4829 "cduc-num-vf-pages",
4830 clients[ILT_CLI_CDUC].vf_total_lines);
4831 offset += qed_dump_num_param(dump_buf + offset,
4832 dump,
4833 "max-conn-ctx-size",
4834 conn_ctx_size);
4835 offset += qed_dump_num_param(dump_buf + offset,
4836 dump,
4837 "cdut-page-size",
4838 cdut_page_size);
4839 offset += qed_dump_num_param(dump_buf + offset,
4840 dump,
4841 "cdut-first-page-id",
4842 clients[ILT_CLI_CDUT].first.val);
4843 offset += qed_dump_num_param(dump_buf + offset,
4844 dump,
4845 "cdut-last-page-id",
4846 clients[ILT_CLI_CDUT].last.val);
4847 offset += qed_dump_num_param(dump_buf + offset,
4848 dump,
4849 "cdut-num-pf-init-pages",
4850 qed_get_cdut_num_pf_init_pages(p_hwfn));
4851 offset += qed_dump_num_param(dump_buf + offset,
4852 dump,
4853 "cdut-num-vf-init-pages",
4854 qed_get_cdut_num_vf_init_pages(p_hwfn));
4855 offset += qed_dump_num_param(dump_buf + offset,
4856 dump,
4857 "cdut-num-pf-work-pages",
4858 qed_get_cdut_num_pf_work_pages(p_hwfn));
4859 offset += qed_dump_num_param(dump_buf + offset,
4860 dump,
4861 "cdut-num-vf-work-pages",
4862 qed_get_cdut_num_vf_work_pages(p_hwfn));
4863 offset += qed_dump_num_param(dump_buf + offset,
4864 dump,
4865 "max-task-ctx-size",
4866 p_hwfn->p_cxt_mngr->task_ctx_size);
4867 offset += qed_dump_num_param(dump_buf + offset,
4868 dump,
4869 "first-vf-id-in-pf",
4870 p_hwfn->p_cxt_mngr->first_vf_in_pf);
4871 offset += qed_dump_num_param(dump_buf + offset,
4872 dump,
4873 "num-vfs-in-pf",
4874 p_hwfn->p_cxt_mngr->vf_count);
4875 offset += qed_dump_num_param(dump_buf + offset,
4876 dump,
4877 "ptr-size-bytes",
4878 sizeof(void *));
4879 offset += qed_dump_num_param(dump_buf + offset,
4880 dump,
4881 "pf-start-line",
4882 p_hwfn->p_cxt_mngr->pf_start_line);
4883 offset += qed_dump_num_param(dump_buf + offset,
4884 dump,
4885 "page-mem-desc-size-dwords",
4886 PAGE_MEM_DESC_SIZE_DWORDS);
4887 offset += qed_dump_num_param(dump_buf + offset,
4888 dump,
4889 "ilt-shadow-size",
4890 p_hwfn->p_cxt_mngr->ilt_shadow_size);
4891
4892 *full_dump_size_param_offset = offset;
4893
4894 offset += qed_dump_num_param(dump_buf + offset,
4895 dump, "dump-size-full", 0);
4896
4897 *actual_dump_size_param_offset = offset;
4898
4899 offset += qed_dump_num_param(dump_buf + offset,
4900 dump,
4901 "dump-size-actual", 0);
4902 offset += qed_dump_num_param(dump_buf + offset,
4903 dump,
4904 "iscsi_task_pages",
4905 p_hwfn->p_cxt_mngr->iscsi_task_pages);
4906 offset += qed_dump_num_param(dump_buf + offset,
4907 dump,
4908 "fcoe_task_pages",
4909 p_hwfn->p_cxt_mngr->fcoe_task_pages);
4910 offset += qed_dump_num_param(dump_buf + offset,
4911 dump,
4912 "roce_task_pages",
4913 p_hwfn->p_cxt_mngr->roce_task_pages);
4914 offset += qed_dump_num_param(dump_buf + offset,
4915 dump,
4916 "eth_task_pages",
4917 p_hwfn->p_cxt_mngr->eth_task_pages);
4918 offset += qed_dump_num_param(dump_buf + offset,
4919 dump,
4920 "src-first-page-id",
4921 clients[ILT_CLI_SRC].first.val);
4922 offset += qed_dump_num_param(dump_buf + offset,
4923 dump,
4924 "src-last-page-id",
4925 clients[ILT_CLI_SRC].last.val);
4926 offset += qed_dump_num_param(dump_buf + offset,
4927 dump,
4928 "src-is-active",
4929 clients[ILT_CLI_SRC].active);
4930
4931 /* Additional/Less parameters require matching of number in call to
4932 * dump_common_global_params()
4933 */
4934
4935 return offset;
4936}
4937
4938/* Dump section containing number of PF CIDs per connection type.
4939 * Part of ilt dump process.
4940 * Returns the dumped size in dwords.
4941 */
4942static u32 qed_ilt_dump_dump_num_pf_cids(struct qed_hwfn *p_hwfn,
4943 u32 *dump_buf,
4944 bool dump, u32 *valid_conn_pf_cids)
4945{
4946 u32 num_pf_cids = 0;
4947 u32 offset = 0;
4948 u8 conn_type;
4949
4950 offset += qed_dump_section_hdr(dump_buf + offset,
4951 dump, "num_pf_cids_per_conn_type", 1);
4952 offset += qed_dump_num_param(dump_buf + offset,
4953 dump, "size", NUM_OF_CONNECTION_TYPES);
4954 for (conn_type = 0, *valid_conn_pf_cids = 0;
4955 conn_type < NUM_OF_CONNECTION_TYPES; conn_type++, offset++) {
4956 num_pf_cids = p_hwfn->p_cxt_mngr->conn_cfg[conn_type].cid_count;
4957 if (dump)
4958 *(dump_buf + offset) = num_pf_cids;
4959 *valid_conn_pf_cids += num_pf_cids;
4960 }
4961
4962 return offset;
4963}
4964
4965/* Dump section containing number of VF CIDs per connection type
4966 * Part of ilt dump process.
4967 * Returns the dumped size in dwords.
4968 */
4969static u32 qed_ilt_dump_dump_num_vf_cids(struct qed_hwfn *p_hwfn,
4970 u32 *dump_buf,
4971 bool dump, u32 *valid_conn_vf_cids)
4972{
4973 u32 num_vf_cids = 0;
4974 u32 offset = 0;
4975 u8 conn_type;
4976
4977 offset += qed_dump_section_hdr(dump_buf + offset, dump,
4978 "num_vf_cids_per_conn_type", 1);
4979 offset += qed_dump_num_param(dump_buf + offset,
4980 dump, "size", NUM_OF_CONNECTION_TYPES);
4981 for (conn_type = 0, *valid_conn_vf_cids = 0;
4982 conn_type < NUM_OF_CONNECTION_TYPES; conn_type++, offset++) {
4983 num_vf_cids =
4984 p_hwfn->p_cxt_mngr->conn_cfg[conn_type].cids_per_vf;
4985 if (dump)
4986 *(dump_buf + offset) = num_vf_cids;
4987 *valid_conn_vf_cids += num_vf_cids;
4988 }
4989
4990 return offset;
4991}
4992
4993/* Performs ILT Dump to the specified buffer.
4994 * buf_size_in_dwords - The dumped buffer size.
4995 * Returns the dumped size in dwords.
4996 */
4997static u32 qed_ilt_dump(struct qed_hwfn *p_hwfn,
4998 struct qed_ptt *p_ptt,
4999 u32 *dump_buf, u32 buf_size_in_dwords, bool dump)
5000{
5001#if ((!defined VMWARE) && (!defined UEFI))
5002 struct qed_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients;
5003#endif
5004 u32 valid_conn_vf_cids = 0,
5005 valid_conn_vf_pages, offset = 0, real_dumped_size = 0;
5006 u32 valid_conn_pf_cids = 0, valid_conn_pf_pages, num_pages;
5007 u32 num_cids_per_page, conn_ctx_size;
5008 u32 cduc_page_size, cdut_page_size;
5009 u32 actual_dump_size_in_dwords = 0;
5010 struct phys_mem_desc *ilt_pages;
5011 u32 actul_dump_off = 0;
5012 u32 last_section_size;
5013 u32 full_dump_off = 0;
5014 u32 section_size = 0;
5015 bool continue_dump;
5016 u32 page_id;
5017
5018 last_section_size = qed_dump_last_section(NULL, 0, false);
5019 cduc_page_size = 1 <<
5020 (clients[ILT_CLI_CDUC].p_size.val + PXP_ILT_PAGE_SIZE_NUM_BITS_MIN);
5021 cdut_page_size = 1 <<
5022 (clients[ILT_CLI_CDUT].p_size.val + PXP_ILT_PAGE_SIZE_NUM_BITS_MIN);
5023 conn_ctx_size = p_hwfn->p_cxt_mngr->conn_ctx_size;
5024 num_cids_per_page = (int)(cduc_page_size / conn_ctx_size);
5025 ilt_pages = p_hwfn->p_cxt_mngr->ilt_shadow;
5026 continue_dump = dump;
5027
5028 /* if need to dump then save memory for the last section
5029 * (last section calculates CRC of dumped data)
5030 */
5031 if (dump) {
5032 if (buf_size_in_dwords >= last_section_size) {
5033 buf_size_in_dwords -= last_section_size;
5034 } else {
5035 continue_dump = false;
5036 actual_dump_size_in_dwords = offset;
5037 }
5038 }
5039
5040 /* Dump global params */
5041
5042 /* if need to dump then first check that there is enough memory
5043 * in dumped buffer for this section calculate the size of this
5044 * section without dumping. if there is not enough memory - then
5045 * stop the dumping.
5046 */
5047 if (continue_dump) {
5048 section_size =
5049 qed_ilt_dump_dump_common_global_params(p_hwfn,
5050 p_ptt,
5051 NULL,
5052 false,
5053 cduc_page_size,
5054 conn_ctx_size,
5055 cdut_page_size,
5056 &full_dump_off,
5057 &actul_dump_off);
5058 if (offset + section_size > buf_size_in_dwords) {
5059 continue_dump = false;
5060 actual_dump_size_in_dwords = offset;
5061 }
5062 }
5063
5064 offset += qed_ilt_dump_dump_common_global_params(p_hwfn,
5065 p_ptt,
5066 dump_buf + offset,
5067 continue_dump,
5068 cduc_page_size,
5069 conn_ctx_size,
5070 cdut_page_size,
5071 &full_dump_off,
5072 &actul_dump_off);
5073
5074 /* Dump section containing number of PF CIDs per connection type
5075 * If need to dump then first check that there is enough memory in
5076 * dumped buffer for this section.
5077 */
5078 if (continue_dump) {
5079 section_size =
5080 qed_ilt_dump_dump_num_pf_cids(p_hwfn,
5081 NULL,
5082 false,
5083 &valid_conn_pf_cids);
5084 if (offset + section_size > buf_size_in_dwords) {
5085 continue_dump = false;
5086 actual_dump_size_in_dwords = offset;
5087 }
5088 }
5089
5090 offset += qed_ilt_dump_dump_num_pf_cids(p_hwfn,
5091 dump_buf + offset,
5092 continue_dump,
5093 &valid_conn_pf_cids);
5094
5095 /* Dump section containing number of VF CIDs per connection type
5096 * If need to dump then first check that there is enough memory in
5097 * dumped buffer for this section.
5098 */
5099 if (continue_dump) {
5100 section_size =
5101 qed_ilt_dump_dump_num_vf_cids(p_hwfn,
5102 NULL,
5103 false,
5104 &valid_conn_vf_cids);
5105 if (offset + section_size > buf_size_in_dwords) {
5106 continue_dump = false;
5107 actual_dump_size_in_dwords = offset;
5108 }
5109 }
5110
5111 offset += qed_ilt_dump_dump_num_vf_cids(p_hwfn,
5112 dump_buf + offset,
5113 continue_dump,
5114 &valid_conn_vf_cids);
5115
5116 /* Dump section containing physical memory descriptors for each
5117 * ILT page.
5118 */
5119 num_pages = p_hwfn->p_cxt_mngr->ilt_shadow_size;
5120
5121 /* If need to dump then first check that there is enough memory
5122 * in dumped buffer for the section header.
5123 */
5124 if (continue_dump) {
5125 section_size = qed_dump_section_hdr(NULL,
5126 false,
5127 "ilt_page_desc",
5128 1) +
5129 qed_dump_num_param(NULL,
5130 false,
5131 "size",
5132 num_pages * PAGE_MEM_DESC_SIZE_DWORDS);
5133 if (offset + section_size > buf_size_in_dwords) {
5134 continue_dump = false;
5135 actual_dump_size_in_dwords = offset;
5136 }
5137 }
5138
5139 offset += qed_dump_section_hdr(dump_buf + offset,
5140 continue_dump, "ilt_page_desc", 1);
5141 offset += qed_dump_num_param(dump_buf + offset,
5142 continue_dump,
5143 "size",
5144 num_pages * PAGE_MEM_DESC_SIZE_DWORDS);
5145
5146 /* Copy memory descriptors to dump buffer
5147 * If need to dump then dump till the dump buffer size
5148 */
5149 if (continue_dump) {
5150 for (page_id = 0; page_id < num_pages;
5151 page_id++, offset += PAGE_MEM_DESC_SIZE_DWORDS) {
5152 if (continue_dump &&
5153 (offset + PAGE_MEM_DESC_SIZE_DWORDS <=
5154 buf_size_in_dwords)) {
5155 memcpy(dump_buf + offset,
5156 &ilt_pages[page_id],
5157 DWORDS_TO_BYTES
5158 (PAGE_MEM_DESC_SIZE_DWORDS));
5159 } else {
5160 if (continue_dump) {
5161 continue_dump = false;
5162 actual_dump_size_in_dwords = offset;
5163 }
5164 }
5165 }
5166 } else {
5167 offset += num_pages * PAGE_MEM_DESC_SIZE_DWORDS;
5168 }
5169
5170 valid_conn_pf_pages = DIV_ROUND_UP(valid_conn_pf_cids,
5171 num_cids_per_page);
5172 valid_conn_vf_pages = DIV_ROUND_UP(valid_conn_vf_cids,
5173 num_cids_per_page);
5174
5175 /* Dump ILT pages IDs */
5176 qed_ilt_dump_pages_section(p_hwfn, dump_buf, &offset, &continue_dump,
5177 valid_conn_pf_pages, valid_conn_vf_pages,
5178 ilt_pages, true, buf_size_in_dwords,
5179 &actual_dump_size_in_dwords);
5180
5181 /* Dump ILT pages memory */
5182 qed_ilt_dump_pages_section(p_hwfn, dump_buf, &offset, &continue_dump,
5183 valid_conn_pf_pages, valid_conn_vf_pages,
5184 ilt_pages, false, buf_size_in_dwords,
5185 &actual_dump_size_in_dwords);
5186
5187 real_dumped_size =
5188 (continue_dump == dump) ? offset : actual_dump_size_in_dwords;
5189 qed_dump_num_param(dump_buf + full_dump_off, dump,
5190 "full-dump-size", offset + last_section_size);
5191 qed_dump_num_param(dump_buf + actul_dump_off,
5192 dump,
5193 "actual-dump-size",
5194 real_dumped_size + last_section_size);
5195
5196 /* Dump last section */
5197 real_dumped_size += qed_dump_last_section(dump_buf,
5198 real_dumped_size, dump);
5199
5200 return real_dumped_size;
5201}
5202
5203/***************************** Public Functions *******************************/
5204
5205enum dbg_status qed_dbg_set_bin_ptr(struct qed_hwfn *p_hwfn,
5206 const u8 * const bin_ptr)
5207{
5208 struct bin_buffer_hdr *buf_hdrs = (struct bin_buffer_hdr *)bin_ptr;
5209 u8 buf_id;
5210
5211 /* Convert binary data to debug arrays */
5212 for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++)
5213 qed_set_dbg_bin_buf(p_hwfn,
5214 buf_id,
5215 (u32 *)(bin_ptr + buf_hdrs[buf_id].offset),
5216 buf_hdrs[buf_id].length);
5217
5218 return DBG_STATUS_OK;
5219}
5220
5221static enum dbg_status qed_dbg_set_app_ver(u32 ver)
5222{
5223 if (ver < TOOLS_VERSION)
5224 return DBG_STATUS_UNSUPPORTED_APP_VERSION;
5225
5226 s_app_ver = ver;
5227
5228 return DBG_STATUS_OK;
5229}
5230
5231bool qed_read_fw_info(struct qed_hwfn *p_hwfn,
5232 struct qed_ptt *p_ptt, struct fw_info *fw_info)
5233{
5234 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5235 u8 storm_id;
5236
5237 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
5238 struct storm_defs *storm = &s_storm_defs[storm_id];
5239
5240 /* Skip Storm if it's in reset */
5241 if (dev_data->block_in_reset[storm->sem_block_id])
5242 continue;
5243
5244 /* Read FW info for the current Storm */
5245 qed_read_storm_fw_info(p_hwfn, p_ptt, storm_id, fw_info);
5246
5247 return true;
5248 }
5249
5250 return false;
5251}
5252
5253enum dbg_status qed_dbg_grc_config(struct qed_hwfn *p_hwfn,
5254 enum dbg_grc_params grc_param, u32 val)
5255{
5256 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5257 enum dbg_status status;
5258 int i;
5259
5260 DP_VERBOSE(p_hwfn,
5261 QED_MSG_DEBUG,
5262 "dbg_grc_config: paramId = %d, val = %d\n", grc_param, val);
5263
5264 status = qed_dbg_dev_init(p_hwfn);
5265 if (status != DBG_STATUS_OK)
5266 return status;
5267
5268 /* Initializes the GRC parameters (if not initialized). Needed in order
5269 * to set the default parameter values for the first time.
5270 */
5271 qed_dbg_grc_init_params(p_hwfn);
5272
5273 if (grc_param >= MAX_DBG_GRC_PARAMS)
5274 return DBG_STATUS_INVALID_ARGS;
5275 if (val < s_grc_param_defs[grc_param].min ||
5276 val > s_grc_param_defs[grc_param].max)
5277 return DBG_STATUS_INVALID_ARGS;
5278
5279 if (s_grc_param_defs[grc_param].is_preset) {
5280 /* Preset param */
5281
5282 /* Disabling a preset is not allowed. Call
5283 * dbg_grc_set_params_default instead.
5284 */
5285 if (!val)
5286 return DBG_STATUS_INVALID_ARGS;
5287
5288 /* Update all params with the preset values */
5289 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++) {
5290 struct grc_param_defs *defs = &s_grc_param_defs[i];
5291 u32 preset_val;
5292 /* Skip persistent params */
5293 if (defs->is_persistent)
5294 continue;
5295
5296 /* Find preset value */
5297 if (grc_param == DBG_GRC_PARAM_EXCLUDE_ALL)
5298 preset_val =
5299 defs->exclude_all_preset_val;
5300 else if (grc_param == DBG_GRC_PARAM_CRASH)
5301 preset_val =
5302 defs->crash_preset_val[dev_data->chip_id];
5303 else
5304 return DBG_STATUS_INVALID_ARGS;
5305
5306 qed_grc_set_param(p_hwfn, i, preset_val);
5307 }
5308 } else {
5309 /* Regular param - set its value */
5310 qed_grc_set_param(p_hwfn, grc_param, val);
5311 }
5312
5313 return DBG_STATUS_OK;
5314}
5315
5316/* Assign default GRC param values */
5317void qed_dbg_grc_set_params_default(struct qed_hwfn *p_hwfn)
5318{
5319 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5320 u32 i;
5321
5322 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
5323 if (!s_grc_param_defs[i].is_persistent)
5324 dev_data->grc.param_val[i] =
5325 s_grc_param_defs[i].default_val[dev_data->chip_id];
5326}
5327
5328enum dbg_status qed_dbg_grc_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5329 struct qed_ptt *p_ptt,
5330 u32 *buf_size)
5331{
5332 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5333
5334 *buf_size = 0;
5335
5336 if (status != DBG_STATUS_OK)
5337 return status;
5338
5339 if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5340 !p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr ||
5341 !p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_MEM].ptr ||
5342 !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
5343 !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
5344 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5345
5346 return qed_grc_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5347}
5348
5349enum dbg_status qed_dbg_grc_dump(struct qed_hwfn *p_hwfn,
5350 struct qed_ptt *p_ptt,
5351 u32 *dump_buf,
5352 u32 buf_size_in_dwords,
5353 u32 *num_dumped_dwords)
5354{
5355 u32 needed_buf_size_in_dwords;
5356 enum dbg_status status;
5357
5358 *num_dumped_dwords = 0;
5359
5360 status = qed_dbg_grc_get_dump_buf_size(p_hwfn,
5361 p_ptt,
5362 &needed_buf_size_in_dwords);
5363 if (status != DBG_STATUS_OK)
5364 return status;
5365
5366 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5367 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5368
5369 /* Doesn't do anything, needed for compile time asserts */
5370 qed_static_asserts();
5371
5372 /* GRC Dump */
5373 status = qed_grc_dump(p_hwfn, p_ptt, dump_buf, true, num_dumped_dwords);
5374
5375 /* Revert GRC params to their default */
5376 qed_dbg_grc_set_params_default(p_hwfn);
5377
5378 return status;
5379}
5380
5381enum dbg_status qed_dbg_idle_chk_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5382 struct qed_ptt *p_ptt,
5383 u32 *buf_size)
5384{
5385 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5386 struct idle_chk_data *idle_chk = &dev_data->idle_chk;
5387 enum dbg_status status;
5388
5389 *buf_size = 0;
5390
5391 status = qed_dbg_dev_init(p_hwfn);
5392 if (status != DBG_STATUS_OK)
5393 return status;
5394
5395 if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5396 !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr ||
5397 !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr ||
5398 !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].ptr)
5399 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5400
5401 if (!idle_chk->buf_size_set) {
5402 idle_chk->buf_size = qed_idle_chk_dump(p_hwfn,
5403 p_ptt, NULL, false);
5404 idle_chk->buf_size_set = true;
5405 }
5406
5407 *buf_size = idle_chk->buf_size;
5408
5409 return DBG_STATUS_OK;
5410}
5411
5412enum dbg_status qed_dbg_idle_chk_dump(struct qed_hwfn *p_hwfn,
5413 struct qed_ptt *p_ptt,
5414 u32 *dump_buf,
5415 u32 buf_size_in_dwords,
5416 u32 *num_dumped_dwords)
5417{
5418 u32 needed_buf_size_in_dwords;
5419 enum dbg_status status;
5420
5421 *num_dumped_dwords = 0;
5422
5423 status = qed_dbg_idle_chk_get_dump_buf_size(p_hwfn,
5424 p_ptt,
5425 &needed_buf_size_in_dwords);
5426 if (status != DBG_STATUS_OK)
5427 return status;
5428
5429 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5430 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5431
5432 /* Update reset state */
5433 qed_grc_unreset_blocks(p_hwfn, p_ptt, true);
5434 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5435
5436 /* Idle Check Dump */
5437 *num_dumped_dwords = qed_idle_chk_dump(p_hwfn, p_ptt, dump_buf, true);
5438
5439 /* Revert GRC params to their default */
5440 qed_dbg_grc_set_params_default(p_hwfn);
5441
5442 return DBG_STATUS_OK;
5443}
5444
5445enum dbg_status qed_dbg_mcp_trace_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5446 struct qed_ptt *p_ptt,
5447 u32 *buf_size)
5448{
5449 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5450
5451 *buf_size = 0;
5452
5453 if (status != DBG_STATUS_OK)
5454 return status;
5455
5456 return qed_mcp_trace_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5457}
5458
5459enum dbg_status qed_dbg_mcp_trace_dump(struct qed_hwfn *p_hwfn,
5460 struct qed_ptt *p_ptt,
5461 u32 *dump_buf,
5462 u32 buf_size_in_dwords,
5463 u32 *num_dumped_dwords)
5464{
5465 u32 needed_buf_size_in_dwords;
5466 enum dbg_status status;
5467
5468 status =
5469 qed_dbg_mcp_trace_get_dump_buf_size(p_hwfn,
5470 p_ptt,
5471 &needed_buf_size_in_dwords);
5472 if (status != DBG_STATUS_OK && status !=
5473 DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
5474 return status;
5475
5476 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5477 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5478
5479 /* Update reset state */
5480 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5481
5482 /* Perform dump */
5483 status = qed_mcp_trace_dump(p_hwfn,
5484 p_ptt, dump_buf, true, num_dumped_dwords);
5485
5486 /* Revert GRC params to their default */
5487 qed_dbg_grc_set_params_default(p_hwfn);
5488
5489 return status;
5490}
5491
5492enum dbg_status qed_dbg_reg_fifo_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5493 struct qed_ptt *p_ptt,
5494 u32 *buf_size)
5495{
5496 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5497
5498 *buf_size = 0;
5499
5500 if (status != DBG_STATUS_OK)
5501 return status;
5502
5503 return qed_reg_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5504}
5505
5506enum dbg_status qed_dbg_reg_fifo_dump(struct qed_hwfn *p_hwfn,
5507 struct qed_ptt *p_ptt,
5508 u32 *dump_buf,
5509 u32 buf_size_in_dwords,
5510 u32 *num_dumped_dwords)
5511{
5512 u32 needed_buf_size_in_dwords;
5513 enum dbg_status status;
5514
5515 *num_dumped_dwords = 0;
5516
5517 status = qed_dbg_reg_fifo_get_dump_buf_size(p_hwfn,
5518 p_ptt,
5519 &needed_buf_size_in_dwords);
5520 if (status != DBG_STATUS_OK)
5521 return status;
5522
5523 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5524 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5525
5526 /* Update reset state */
5527 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5528
5529 status = qed_reg_fifo_dump(p_hwfn,
5530 p_ptt, dump_buf, true, num_dumped_dwords);
5531
5532 /* Revert GRC params to their default */
5533 qed_dbg_grc_set_params_default(p_hwfn);
5534
5535 return status;
5536}
5537
5538enum dbg_status qed_dbg_igu_fifo_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5539 struct qed_ptt *p_ptt,
5540 u32 *buf_size)
5541{
5542 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5543
5544 *buf_size = 0;
5545
5546 if (status != DBG_STATUS_OK)
5547 return status;
5548
5549 return qed_igu_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5550}
5551
5552enum dbg_status qed_dbg_igu_fifo_dump(struct qed_hwfn *p_hwfn,
5553 struct qed_ptt *p_ptt,
5554 u32 *dump_buf,
5555 u32 buf_size_in_dwords,
5556 u32 *num_dumped_dwords)
5557{
5558 u32 needed_buf_size_in_dwords;
5559 enum dbg_status status;
5560
5561 *num_dumped_dwords = 0;
5562
5563 status = qed_dbg_igu_fifo_get_dump_buf_size(p_hwfn,
5564 p_ptt,
5565 &needed_buf_size_in_dwords);
5566 if (status != DBG_STATUS_OK)
5567 return status;
5568
5569 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5570 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5571
5572 /* Update reset state */
5573 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5574
5575 status = qed_igu_fifo_dump(p_hwfn,
5576 p_ptt, dump_buf, true, num_dumped_dwords);
5577 /* Revert GRC params to their default */
5578 qed_dbg_grc_set_params_default(p_hwfn);
5579
5580 return status;
5581}
5582
5583enum dbg_status
5584qed_dbg_protection_override_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5585 struct qed_ptt *p_ptt,
5586 u32 *buf_size)
5587{
5588 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5589
5590 *buf_size = 0;
5591
5592 if (status != DBG_STATUS_OK)
5593 return status;
5594
5595 return qed_protection_override_dump(p_hwfn,
5596 p_ptt, NULL, false, buf_size);
5597}
5598
5599enum dbg_status qed_dbg_protection_override_dump(struct qed_hwfn *p_hwfn,
5600 struct qed_ptt *p_ptt,
5601 u32 *dump_buf,
5602 u32 buf_size_in_dwords,
5603 u32 *num_dumped_dwords)
5604{
5605 u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
5606 enum dbg_status status;
5607
5608 *num_dumped_dwords = 0;
5609
5610 status =
5611 qed_dbg_protection_override_get_dump_buf_size(p_hwfn,
5612 p_ptt,
5613 p_size);
5614 if (status != DBG_STATUS_OK)
5615 return status;
5616
5617 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5618 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5619
5620 /* Update reset state */
5621 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5622
5623 status = qed_protection_override_dump(p_hwfn,
5624 p_ptt,
5625 dump_buf,
5626 true, num_dumped_dwords);
5627
5628 /* Revert GRC params to their default */
5629 qed_dbg_grc_set_params_default(p_hwfn);
5630
5631 return status;
5632}
5633
5634enum dbg_status qed_dbg_fw_asserts_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5635 struct qed_ptt *p_ptt,
5636 u32 *buf_size)
5637{
5638 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5639
5640 *buf_size = 0;
5641
5642 if (status != DBG_STATUS_OK)
5643 return status;
5644
5645 /* Update reset state */
5646 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5647
5648 *buf_size = qed_fw_asserts_dump(p_hwfn, p_ptt, NULL, false);
5649
5650 return DBG_STATUS_OK;
5651}
5652
5653enum dbg_status qed_dbg_fw_asserts_dump(struct qed_hwfn *p_hwfn,
5654 struct qed_ptt *p_ptt,
5655 u32 *dump_buf,
5656 u32 buf_size_in_dwords,
5657 u32 *num_dumped_dwords)
5658{
5659 u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
5660 enum dbg_status status;
5661
5662 *num_dumped_dwords = 0;
5663
5664 status =
5665 qed_dbg_fw_asserts_get_dump_buf_size(p_hwfn,
5666 p_ptt,
5667 p_size);
5668 if (status != DBG_STATUS_OK)
5669 return status;
5670
5671 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5672 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5673
5674 *num_dumped_dwords = qed_fw_asserts_dump(p_hwfn, p_ptt, dump_buf, true);
5675
5676 /* Revert GRC params to their default */
5677 qed_dbg_grc_set_params_default(p_hwfn);
5678
5679 return DBG_STATUS_OK;
5680}
5681
5682static enum dbg_status qed_dbg_ilt_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5683 struct qed_ptt *p_ptt,
5684 u32 *buf_size)
5685{
5686 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5687
5688 *buf_size = 0;
5689
5690 if (status != DBG_STATUS_OK)
5691 return status;
5692
5693 *buf_size = qed_ilt_dump(p_hwfn, p_ptt, NULL, 0, false);
5694
5695 return DBG_STATUS_OK;
5696}
5697
5698static enum dbg_status qed_dbg_ilt_dump(struct qed_hwfn *p_hwfn,
5699 struct qed_ptt *p_ptt,
5700 u32 *dump_buf,
5701 u32 buf_size_in_dwords,
5702 u32 *num_dumped_dwords)
5703{
5704 *num_dumped_dwords = qed_ilt_dump(p_hwfn,
5705 p_ptt,
5706 dump_buf, buf_size_in_dwords, true);
5707
5708 /* Reveret GRC params to their default */
5709 qed_dbg_grc_set_params_default(p_hwfn);
5710
5711 return DBG_STATUS_OK;
5712}
5713
5714enum dbg_status qed_dbg_read_attn(struct qed_hwfn *p_hwfn,
5715 struct qed_ptt *p_ptt,
5716 enum block_id block_id,
5717 enum dbg_attn_type attn_type,
5718 bool clear_status,
5719 struct dbg_attn_block_result *results)
5720{
5721 enum dbg_status status = qed_dbg_dev_init(p_hwfn);
5722 u8 reg_idx, num_attn_regs, num_result_regs = 0;
5723 const struct dbg_attn_reg *attn_reg_arr;
5724
5725 if (status != DBG_STATUS_OK)
5726 return status;
5727
5728 if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5729 !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
5730 !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
5731 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5732
5733 attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
5734 block_id,
5735 attn_type, &num_attn_regs);
5736
5737 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
5738 const struct dbg_attn_reg *reg_data = &attn_reg_arr[reg_idx];
5739 struct dbg_attn_reg_result *reg_result;
5740 u32 sts_addr, sts_val;
5741 u16 modes_buf_offset;
5742 bool eval_mode;
5743
5744 /* Check mode */
5745 eval_mode = GET_FIELD(reg_data->mode.data,
5746 DBG_MODE_HDR_EVAL_MODE) > 0;
5747 modes_buf_offset = GET_FIELD(reg_data->mode.data,
5748 DBG_MODE_HDR_MODES_BUF_OFFSET);
5749 if (eval_mode && !qed_is_mode_match(p_hwfn, &modes_buf_offset))
5750 continue;
5751
5752 /* Mode match - read attention status register */
5753 sts_addr = DWORDS_TO_BYTES(clear_status ?
5754 reg_data->sts_clr_address :
5755 GET_FIELD(reg_data->data,
5756 DBG_ATTN_REG_STS_ADDRESS));
5757 sts_val = qed_rd(p_hwfn, p_ptt, sts_addr);
5758 if (!sts_val)
5759 continue;
5760
5761 /* Non-zero attention status - add to results */
5762 reg_result = &results->reg_results[num_result_regs];
5763 SET_FIELD(reg_result->data,
5764 DBG_ATTN_REG_RESULT_STS_ADDRESS, sts_addr);
5765 SET_FIELD(reg_result->data,
5766 DBG_ATTN_REG_RESULT_NUM_REG_ATTN,
5767 GET_FIELD(reg_data->data, DBG_ATTN_REG_NUM_REG_ATTN));
5768 reg_result->block_attn_offset = reg_data->block_attn_offset;
5769 reg_result->sts_val = sts_val;
5770 reg_result->mask_val = qed_rd(p_hwfn,
5771 p_ptt,
5772 DWORDS_TO_BYTES
5773 (reg_data->mask_address));
5774 num_result_regs++;
5775 }
5776
5777 results->block_id = (u8)block_id;
5778 results->names_offset =
5779 qed_get_block_attn_data(p_hwfn, block_id, attn_type)->names_offset;
5780 SET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_ATTN_TYPE, attn_type);
5781 SET_FIELD(results->data,
5782 DBG_ATTN_BLOCK_RESULT_NUM_REGS, num_result_regs);
5783
5784 return DBG_STATUS_OK;
5785}
5786
5787/******************************* Data Types **********************************/
5788
5789/* REG fifo element */
5790struct reg_fifo_element {
5791 u64 data;
5792#define REG_FIFO_ELEMENT_ADDRESS_SHIFT 0
5793#define REG_FIFO_ELEMENT_ADDRESS_MASK 0x7fffff
5794#define REG_FIFO_ELEMENT_ACCESS_SHIFT 23
5795#define REG_FIFO_ELEMENT_ACCESS_MASK 0x1
5796#define REG_FIFO_ELEMENT_PF_SHIFT 24
5797#define REG_FIFO_ELEMENT_PF_MASK 0xf
5798#define REG_FIFO_ELEMENT_VF_SHIFT 28
5799#define REG_FIFO_ELEMENT_VF_MASK 0xff
5800#define REG_FIFO_ELEMENT_PORT_SHIFT 36
5801#define REG_FIFO_ELEMENT_PORT_MASK 0x3
5802#define REG_FIFO_ELEMENT_PRIVILEGE_SHIFT 38
5803#define REG_FIFO_ELEMENT_PRIVILEGE_MASK 0x3
5804#define REG_FIFO_ELEMENT_PROTECTION_SHIFT 40
5805#define REG_FIFO_ELEMENT_PROTECTION_MASK 0x7
5806#define REG_FIFO_ELEMENT_MASTER_SHIFT 43
5807#define REG_FIFO_ELEMENT_MASTER_MASK 0xf
5808#define REG_FIFO_ELEMENT_ERROR_SHIFT 47
5809#define REG_FIFO_ELEMENT_ERROR_MASK 0x1f
5810};
5811
5812/* REG fifo error element */
5813struct reg_fifo_err {
5814 u32 err_code;
5815 const char *err_msg;
5816};
5817
5818/* IGU fifo element */
5819struct igu_fifo_element {
5820 u32 dword0;
5821#define IGU_FIFO_ELEMENT_DWORD0_FID_SHIFT 0
5822#define IGU_FIFO_ELEMENT_DWORD0_FID_MASK 0xff
5823#define IGU_FIFO_ELEMENT_DWORD0_IS_PF_SHIFT 8
5824#define IGU_FIFO_ELEMENT_DWORD0_IS_PF_MASK 0x1
5825#define IGU_FIFO_ELEMENT_DWORD0_SOURCE_SHIFT 9
5826#define IGU_FIFO_ELEMENT_DWORD0_SOURCE_MASK 0xf
5827#define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_SHIFT 13
5828#define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_MASK 0xf
5829#define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_SHIFT 17
5830#define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_MASK 0x7fff
5831 u32 dword1;
5832 u32 dword2;
5833#define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_SHIFT 0
5834#define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_MASK 0x1
5835#define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_SHIFT 1
5836#define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_MASK 0xffffffff
5837 u32 reserved;
5838};
5839
5840struct igu_fifo_wr_data {
5841 u32 data;
5842#define IGU_FIFO_WR_DATA_PROD_CONS_SHIFT 0
5843#define IGU_FIFO_WR_DATA_PROD_CONS_MASK 0xffffff
5844#define IGU_FIFO_WR_DATA_UPDATE_FLAG_SHIFT 24
5845#define IGU_FIFO_WR_DATA_UPDATE_FLAG_MASK 0x1
5846#define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_SHIFT 25
5847#define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_MASK 0x3
5848#define IGU_FIFO_WR_DATA_SEGMENT_SHIFT 27
5849#define IGU_FIFO_WR_DATA_SEGMENT_MASK 0x1
5850#define IGU_FIFO_WR_DATA_TIMER_MASK_SHIFT 28
5851#define IGU_FIFO_WR_DATA_TIMER_MASK_MASK 0x1
5852#define IGU_FIFO_WR_DATA_CMD_TYPE_SHIFT 31
5853#define IGU_FIFO_WR_DATA_CMD_TYPE_MASK 0x1
5854};
5855
5856struct igu_fifo_cleanup_wr_data {
5857 u32 data;
5858#define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_SHIFT 0
5859#define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_MASK 0x7ffffff
5860#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_SHIFT 27
5861#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_MASK 0x1
5862#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_SHIFT 28
5863#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_MASK 0x7
5864#define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_SHIFT 31
5865#define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_MASK 0x1
5866};
5867
5868/* Protection override element */
5869struct protection_override_element {
5870 u64 data;
5871#define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_SHIFT 0
5872#define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_MASK 0x7fffff
5873#define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_SHIFT 23
5874#define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_MASK 0xffffff
5875#define PROTECTION_OVERRIDE_ELEMENT_READ_SHIFT 47
5876#define PROTECTION_OVERRIDE_ELEMENT_READ_MASK 0x1
5877#define PROTECTION_OVERRIDE_ELEMENT_WRITE_SHIFT 48
5878#define PROTECTION_OVERRIDE_ELEMENT_WRITE_MASK 0x1
5879#define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_SHIFT 49
5880#define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_MASK 0x7
5881#define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_SHIFT 52
5882#define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_MASK 0x7
5883};
5884
5885enum igu_fifo_sources {
5886 IGU_SRC_PXP0,
5887 IGU_SRC_PXP1,
5888 IGU_SRC_PXP2,
5889 IGU_SRC_PXP3,
5890 IGU_SRC_PXP4,
5891 IGU_SRC_PXP5,
5892 IGU_SRC_PXP6,
5893 IGU_SRC_PXP7,
5894 IGU_SRC_CAU,
5895 IGU_SRC_ATTN,
5896 IGU_SRC_GRC
5897};
5898
5899enum igu_fifo_addr_types {
5900 IGU_ADDR_TYPE_MSIX_MEM,
5901 IGU_ADDR_TYPE_WRITE_PBA,
5902 IGU_ADDR_TYPE_WRITE_INT_ACK,
5903 IGU_ADDR_TYPE_WRITE_ATTN_BITS,
5904 IGU_ADDR_TYPE_READ_INT,
5905 IGU_ADDR_TYPE_WRITE_PROD_UPDATE,
5906 IGU_ADDR_TYPE_RESERVED
5907};
5908
5909struct igu_fifo_addr_data {
5910 u16 start_addr;
5911 u16 end_addr;
5912 char *desc;
5913 char *vf_desc;
5914 enum igu_fifo_addr_types type;
5915};
5916
5917/******************************** Constants **********************************/
5918
5919#define MAX_MSG_LEN 1024
5920
5921#define MCP_TRACE_MAX_MODULE_LEN 8
5922#define MCP_TRACE_FORMAT_MAX_PARAMS 3
5923#define MCP_TRACE_FORMAT_PARAM_WIDTH \
5924 (MCP_TRACE_FORMAT_P2_SIZE_OFFSET - MCP_TRACE_FORMAT_P1_SIZE_OFFSET)
5925
5926#define REG_FIFO_ELEMENT_ADDR_FACTOR 4
5927#define REG_FIFO_ELEMENT_IS_PF_VF_VAL 127
5928
5929#define PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR 4
5930
5931/***************************** Constant Arrays *******************************/
5932
5933/* Status string array */
5934static const char * const s_status_str[] = {
5935 /* DBG_STATUS_OK */
5936 "Operation completed successfully",
5937
5938 /* DBG_STATUS_APP_VERSION_NOT_SET */
5939 "Debug application version wasn't set",
5940
5941 /* DBG_STATUS_UNSUPPORTED_APP_VERSION */
5942 "Unsupported debug application version",
5943
5944 /* DBG_STATUS_DBG_BLOCK_NOT_RESET */
5945 "The debug block wasn't reset since the last recording",
5946
5947 /* DBG_STATUS_INVALID_ARGS */
5948 "Invalid arguments",
5949
5950 /* DBG_STATUS_OUTPUT_ALREADY_SET */
5951 "The debug output was already set",
5952
5953 /* DBG_STATUS_INVALID_PCI_BUF_SIZE */
5954 "Invalid PCI buffer size",
5955
5956 /* DBG_STATUS_PCI_BUF_ALLOC_FAILED */
5957 "PCI buffer allocation failed",
5958
5959 /* DBG_STATUS_PCI_BUF_NOT_ALLOCATED */
5960 "A PCI buffer wasn't allocated",
5961
5962 /* DBG_STATUS_INVALID_FILTER_TRIGGER_DWORDS */
5963 "The filter/trigger constraint dword offsets are not enabled for recording",
5964 /* DBG_STATUS_NO_MATCHING_FRAMING_MODE */
5965 "No matching framing mode",
5966
5967 /* DBG_STATUS_VFC_READ_ERROR */
5968 "Error reading from VFC",
5969
5970 /* DBG_STATUS_STORM_ALREADY_ENABLED */
5971 "The Storm was already enabled",
5972
5973 /* DBG_STATUS_STORM_NOT_ENABLED */
5974 "The specified Storm wasn't enabled",
5975
5976 /* DBG_STATUS_BLOCK_ALREADY_ENABLED */
5977 "The block was already enabled",
5978
5979 /* DBG_STATUS_BLOCK_NOT_ENABLED */
5980 "The specified block wasn't enabled",
5981
5982 /* DBG_STATUS_NO_INPUT_ENABLED */
5983 "No input was enabled for recording",
5984
5985 /* DBG_STATUS_NO_FILTER_TRIGGER_256B */
5986 "Filters and triggers are not allowed in E4 256-bit mode",
5987
5988 /* DBG_STATUS_FILTER_ALREADY_ENABLED */
5989 "The filter was already enabled",
5990
5991 /* DBG_STATUS_TRIGGER_ALREADY_ENABLED */
5992 "The trigger was already enabled",
5993
5994 /* DBG_STATUS_TRIGGER_NOT_ENABLED */
5995 "The trigger wasn't enabled",
5996
5997 /* DBG_STATUS_CANT_ADD_CONSTRAINT */
5998 "A constraint can be added only after a filter was enabled or a trigger state was added",
5999
6000 /* DBG_STATUS_TOO_MANY_TRIGGER_STATES */
6001 "Cannot add more than 3 trigger states",
6002
6003 /* DBG_STATUS_TOO_MANY_CONSTRAINTS */
6004 "Cannot add more than 4 constraints per filter or trigger state",
6005
6006 /* DBG_STATUS_RECORDING_NOT_STARTED */
6007 "The recording wasn't started",
6008
6009 /* DBG_STATUS_DATA_DIDNT_TRIGGER */
6010 "A trigger was configured, but it didn't trigger",
6011
6012 /* DBG_STATUS_NO_DATA_RECORDED */
6013 "No data was recorded",
6014
6015 /* DBG_STATUS_DUMP_BUF_TOO_SMALL */
6016 "Dump buffer is too small",
6017
6018 /* DBG_STATUS_DUMP_NOT_CHUNK_ALIGNED */
6019 "Dumped data is not aligned to chunks",
6020
6021 /* DBG_STATUS_UNKNOWN_CHIP */
6022 "Unknown chip",
6023
6024 /* DBG_STATUS_VIRT_MEM_ALLOC_FAILED */
6025 "Failed allocating virtual memory",
6026
6027 /* DBG_STATUS_BLOCK_IN_RESET */
6028 "The input block is in reset",
6029
6030 /* DBG_STATUS_INVALID_TRACE_SIGNATURE */
6031 "Invalid MCP trace signature found in NVRAM",
6032
6033 /* DBG_STATUS_INVALID_NVRAM_BUNDLE */
6034 "Invalid bundle ID found in NVRAM",
6035
6036 /* DBG_STATUS_NVRAM_GET_IMAGE_FAILED */
6037 "Failed getting NVRAM image",
6038
6039 /* DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE */
6040 "NVRAM image is not dword-aligned",
6041
6042 /* DBG_STATUS_NVRAM_READ_FAILED */
6043 "Failed reading from NVRAM",
6044
6045 /* DBG_STATUS_IDLE_CHK_PARSE_FAILED */
6046 "Idle check parsing failed",
6047
6048 /* DBG_STATUS_MCP_TRACE_BAD_DATA */
6049 "MCP Trace data is corrupt",
6050
6051 /* DBG_STATUS_MCP_TRACE_NO_META */
6052 "Dump doesn't contain meta data - it must be provided in image file",
6053
6054 /* DBG_STATUS_MCP_COULD_NOT_HALT */
6055 "Failed to halt MCP",
6056
6057 /* DBG_STATUS_MCP_COULD_NOT_RESUME */
6058 "Failed to resume MCP after halt",
6059
6060 /* DBG_STATUS_RESERVED0 */
6061 "",
6062
6063 /* DBG_STATUS_SEMI_FIFO_NOT_EMPTY */
6064 "Failed to empty SEMI sync FIFO",
6065
6066 /* DBG_STATUS_IGU_FIFO_BAD_DATA */
6067 "IGU FIFO data is corrupt",
6068
6069 /* DBG_STATUS_MCP_COULD_NOT_MASK_PRTY */
6070 "MCP failed to mask parities",
6071
6072 /* DBG_STATUS_FW_ASSERTS_PARSE_FAILED */
6073 "FW Asserts parsing failed",
6074
6075 /* DBG_STATUS_REG_FIFO_BAD_DATA */
6076 "GRC FIFO data is corrupt",
6077
6078 /* DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA */
6079 "Protection Override data is corrupt",
6080
6081 /* DBG_STATUS_DBG_ARRAY_NOT_SET */
6082 "Debug arrays were not set (when using binary files, dbg_set_bin_ptr must be called)",
6083
6084 /* DBG_STATUS_RESERVED1 */
6085 "",
6086
6087 /* DBG_STATUS_NON_MATCHING_LINES */
6088 "Non-matching debug lines - in E4, all lines must be of the same type (either 128b or 256b)",
6089
6090 /* DBG_STATUS_INSUFFICIENT_HW_IDS */
6091 "Insufficient HW IDs. Try to record less Storms/blocks",
6092
6093 /* DBG_STATUS_DBG_BUS_IN_USE */
6094 "The debug bus is in use",
6095
6096 /* DBG_STATUS_INVALID_STORM_DBG_MODE */
6097 "The storm debug mode is not supported in the current chip",
6098
6099 /* DBG_STATUS_OTHER_ENGINE_BB_ONLY */
6100 "Other engine is supported only in BB",
6101
6102 /* DBG_STATUS_FILTER_SINGLE_HW_ID */
6103 "The configured filter mode requires a single Storm/block input",
6104
6105 /* DBG_STATUS_TRIGGER_SINGLE_HW_ID */
6106 "The configured filter mode requires that all the constraints of a single trigger state will be defined on a single Storm/block input",
6107
6108 /* DBG_STATUS_MISSING_TRIGGER_STATE_STORM */
6109 "When triggering on Storm data, the Storm to trigger on must be specified",
6110
6111 /* DBG_STATUS_MDUMP2_FAILED_TO_REQUEST_OFFSIZE */
6112 "Failed to request MDUMP2 Offsize",
6113
6114 /* DBG_STATUS_MDUMP2_FAILED_VALIDATION_OF_DATA_CRC */
6115 "Expected CRC (part of the MDUMP2 data) is different than the calculated CRC over that data",
6116
6117 /* DBG_STATUS_MDUMP2_INVALID_SIGNATURE */
6118 "Invalid Signature found at start of MDUMP2",
6119
6120 /* DBG_STATUS_MDUMP2_INVALID_LOG_SIZE */
6121 "Invalid Log Size of MDUMP2",
6122
6123 /* DBG_STATUS_MDUMP2_INVALID_LOG_HDR */
6124 "Invalid Log Header of MDUMP2",
6125
6126 /* DBG_STATUS_MDUMP2_INVALID_LOG_DATA */
6127 "Invalid Log Data of MDUMP2",
6128
6129 /* DBG_STATUS_MDUMP2_ERROR_EXTRACTING_NUM_PORTS */
6130 "Could not extract number of ports from regval buf of MDUMP2",
6131
6132 /* DBG_STATUS_MDUMP2_ERROR_EXTRACTING_MFW_STATUS */
6133 "Could not extract MFW (link) status from regval buf of MDUMP2",
6134
6135 /* DBG_STATUS_MDUMP2_ERROR_DISPLAYING_LINKDUMP */
6136 "Could not display linkdump of MDUMP2",
6137
6138 /* DBG_STATUS_MDUMP2_ERROR_READING_PHY_CFG */
6139 "Could not read PHY CFG of MDUMP2",
6140
6141 /* DBG_STATUS_MDUMP2_ERROR_READING_PLL_MODE */
6142 "Could not read PLL Mode of MDUMP2",
6143
6144 /* DBG_STATUS_MDUMP2_ERROR_READING_LANE_REGS */
6145 "Could not read TSCF/TSCE Lane Regs of MDUMP2",
6146
6147 /* DBG_STATUS_MDUMP2_ERROR_ALLOCATING_BUF */
6148 "Could not allocate MDUMP2 reg-val internal buffer"
6149};
6150
6151/* Idle check severity names array */
6152static const char * const s_idle_chk_severity_str[] = {
6153 "Error",
6154 "Error if no traffic",
6155 "Warning"
6156};
6157
6158/* MCP Trace level names array */
6159static const char * const s_mcp_trace_level_str[] = {
6160 "ERROR",
6161 "TRACE",
6162 "DEBUG"
6163};
6164
6165/* Access type names array */
6166static const char * const s_access_strs[] = {
6167 "read",
6168 "write"
6169};
6170
6171/* Privilege type names array */
6172static const char * const s_privilege_strs[] = {
6173 "VF",
6174 "PDA",
6175 "HV",
6176 "UA"
6177};
6178
6179/* Protection type names array */
6180static const char * const s_protection_strs[] = {
6181 "(default)",
6182 "(default)",
6183 "(default)",
6184 "(default)",
6185 "override VF",
6186 "override PDA",
6187 "override HV",
6188 "override UA"
6189};
6190
6191/* Master type names array */
6192static const char * const s_master_strs[] = {
6193 "???",
6194 "pxp",
6195 "mcp",
6196 "msdm",
6197 "psdm",
6198 "ysdm",
6199 "usdm",
6200 "tsdm",
6201 "xsdm",
6202 "dbu",
6203 "dmae",
6204 "jdap",
6205 "???",
6206 "???",
6207 "???",
6208 "???"
6209};
6210
6211/* REG FIFO error messages array */
6212static struct reg_fifo_err s_reg_fifo_errors[] = {
6213 {1, "grc timeout"},
6214 {2, "address doesn't belong to any block"},
6215 {4, "reserved address in block or write to read-only address"},
6216 {8, "privilege/protection mismatch"},
6217 {16, "path isolation error"},
6218 {17, "RSL error"}
6219};
6220
6221/* IGU FIFO sources array */
6222static const char * const s_igu_fifo_source_strs[] = {
6223 "TSTORM",
6224 "MSTORM",
6225 "USTORM",
6226 "XSTORM",
6227 "YSTORM",
6228 "PSTORM",
6229 "PCIE",
6230 "NIG_QM_PBF",
6231 "CAU",
6232 "ATTN",
6233 "GRC",
6234};
6235
6236/* IGU FIFO error messages */
6237static const char * const s_igu_fifo_error_strs[] = {
6238 "no error",
6239 "length error",
6240 "function disabled",
6241 "VF sent command to attention address",
6242 "host sent prod update command",
6243 "read of during interrupt register while in MIMD mode",
6244 "access to PXP BAR reserved address",
6245 "producer update command to attention index",
6246 "unknown error",
6247 "SB index not valid",
6248 "SB relative index and FID not found",
6249 "FID not match",
6250 "command with error flag asserted (PCI error or CAU discard)",
6251 "VF sent cleanup and RF cleanup is disabled",
6252 "cleanup command on type bigger than 4"
6253};
6254
6255/* IGU FIFO address data */
6256static const struct igu_fifo_addr_data s_igu_fifo_addr_data[] = {
6257 {0x0, 0x101, "MSI-X Memory", NULL,
6258 IGU_ADDR_TYPE_MSIX_MEM},
6259 {0x102, 0x1ff, "reserved", NULL,
6260 IGU_ADDR_TYPE_RESERVED},
6261 {0x200, 0x200, "Write PBA[0:63]", NULL,
6262 IGU_ADDR_TYPE_WRITE_PBA},
6263 {0x201, 0x201, "Write PBA[64:127]", "reserved",
6264 IGU_ADDR_TYPE_WRITE_PBA},
6265 {0x202, 0x202, "Write PBA[128]", "reserved",
6266 IGU_ADDR_TYPE_WRITE_PBA},
6267 {0x203, 0x3ff, "reserved", NULL,
6268 IGU_ADDR_TYPE_RESERVED},
6269 {0x400, 0x5ef, "Write interrupt acknowledgment", NULL,
6270 IGU_ADDR_TYPE_WRITE_INT_ACK},
6271 {0x5f0, 0x5f0, "Attention bits update", NULL,
6272 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6273 {0x5f1, 0x5f1, "Attention bits set", NULL,
6274 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6275 {0x5f2, 0x5f2, "Attention bits clear", NULL,
6276 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6277 {0x5f3, 0x5f3, "Read interrupt 0:63 with mask", NULL,
6278 IGU_ADDR_TYPE_READ_INT},
6279 {0x5f4, 0x5f4, "Read interrupt 0:31 with mask", NULL,
6280 IGU_ADDR_TYPE_READ_INT},
6281 {0x5f5, 0x5f5, "Read interrupt 32:63 with mask", NULL,
6282 IGU_ADDR_TYPE_READ_INT},
6283 {0x5f6, 0x5f6, "Read interrupt 0:63 without mask", NULL,
6284 IGU_ADDR_TYPE_READ_INT},
6285 {0x5f7, 0x5ff, "reserved", NULL,
6286 IGU_ADDR_TYPE_RESERVED},
6287 {0x600, 0x7ff, "Producer update", NULL,
6288 IGU_ADDR_TYPE_WRITE_PROD_UPDATE}
6289};
6290
6291/******************************** Variables **********************************/
6292
6293/* Temporary buffer, used for print size calculations */
6294static char s_temp_buf[MAX_MSG_LEN];
6295
6296/**************************** Private Functions ******************************/
6297
6298static void qed_user_static_asserts(void)
6299{
6300}
6301
6302static u32 qed_cyclic_add(u32 a, u32 b, u32 size)
6303{
6304 return (a + b) % size;
6305}
6306
6307static u32 qed_cyclic_sub(u32 a, u32 b, u32 size)
6308{
6309 return (size + a - b) % size;
6310}
6311
6312/* Reads the specified number of bytes from the specified cyclic buffer (up to 4
6313 * bytes) and returns them as a dword value. the specified buffer offset is
6314 * updated.
6315 */
6316static u32 qed_read_from_cyclic_buf(void *buf,
6317 u32 *offset,
6318 u32 buf_size, u8 num_bytes_to_read)
6319{
6320 u8 i, *val_ptr, *bytes_buf = (u8 *)buf;
6321 u32 val = 0;
6322
6323 val_ptr = (u8 *)&val;
6324
6325 /* Assume running on a LITTLE ENDIAN and the buffer is network order
6326 * (BIG ENDIAN), as high order bytes are placed in lower memory address.
6327 */
6328 for (i = 0; i < num_bytes_to_read; i++) {
6329 val_ptr[i] = bytes_buf[*offset];
6330 *offset = qed_cyclic_add(*offset, 1, buf_size);
6331 }
6332
6333 return val;
6334}
6335
6336/* Reads and returns the next byte from the specified buffer.
6337 * The specified buffer offset is updated.
6338 */
6339static u8 qed_read_byte_from_buf(void *buf, u32 *offset)
6340{
6341 return ((u8 *)buf)[(*offset)++];
6342}
6343
6344/* Reads and returns the next dword from the specified buffer.
6345 * The specified buffer offset is updated.
6346 */
6347static u32 qed_read_dword_from_buf(void *buf, u32 *offset)
6348{
6349 u32 dword_val = *(u32 *)&((u8 *)buf)[*offset];
6350
6351 *offset += 4;
6352
6353 return dword_val;
6354}
6355
6356/* Reads the next string from the specified buffer, and copies it to the
6357 * specified pointer. The specified buffer offset is updated.
6358 */
6359static void qed_read_str_from_buf(void *buf, u32 *offset, u32 size, char *dest)
6360{
6361 const char *source_str = &((const char *)buf)[*offset];
6362
6363 strscpy(dest, source_str, size);
6364 *offset += size;
6365}
6366
6367/* Returns a pointer to the specified offset (in bytes) of the specified buffer.
6368 * If the specified buffer in NULL, a temporary buffer pointer is returned.
6369 */
6370static char *qed_get_buf_ptr(void *buf, u32 offset)
6371{
6372 return buf ? (char *)buf + offset : s_temp_buf;
6373}
6374
6375/* Reads a param from the specified buffer. Returns the number of dwords read.
6376 * If the returned str_param is NULL, the param is numeric and its value is
6377 * returned in num_param.
6378 * Otheriwise, the param is a string and its pointer is returned in str_param.
6379 */
6380static u32 qed_read_param(u32 *dump_buf,
6381 const char **param_name,
6382 const char **param_str_val, u32 *param_num_val)
6383{
6384 char *char_buf = (char *)dump_buf;
6385 size_t offset = 0;
6386
6387 /* Extract param name */
6388 *param_name = char_buf;
6389 offset += strlen(*param_name) + 1;
6390
6391 /* Check param type */
6392 if (*(char_buf + offset++)) {
6393 /* String param */
6394 *param_str_val = char_buf + offset;
6395 *param_num_val = 0;
6396 offset += strlen(*param_str_val) + 1;
6397 if (offset & 0x3)
6398 offset += (4 - (offset & 0x3));
6399 } else {
6400 /* Numeric param */
6401 *param_str_val = NULL;
6402 if (offset & 0x3)
6403 offset += (4 - (offset & 0x3));
6404 *param_num_val = *(u32 *)(char_buf + offset);
6405 offset += 4;
6406 }
6407
6408 return (u32)offset / 4;
6409}
6410
6411/* Reads a section header from the specified buffer.
6412 * Returns the number of dwords read.
6413 */
6414static u32 qed_read_section_hdr(u32 *dump_buf,
6415 const char **section_name,
6416 u32 *num_section_params)
6417{
6418 const char *param_str_val;
6419
6420 return qed_read_param(dump_buf,
6421 section_name, ¶m_str_val, num_section_params);
6422}
6423
6424/* Reads section params from the specified buffer and prints them to the results
6425 * buffer. Returns the number of dwords read.
6426 */
6427static u32 qed_print_section_params(u32 *dump_buf,
6428 u32 num_section_params,
6429 char *results_buf, u32 *num_chars_printed)
6430{
6431 u32 i, dump_offset = 0, results_offset = 0;
6432
6433 for (i = 0; i < num_section_params; i++) {
6434 const char *param_name, *param_str_val;
6435 u32 param_num_val = 0;
6436
6437 dump_offset += qed_read_param(dump_buf + dump_offset,
6438 ¶m_name,
6439 ¶m_str_val, ¶m_num_val);
6440
6441 if (param_str_val)
6442 results_offset +=
6443 sprintf(qed_get_buf_ptr(results_buf,
6444 results_offset),
6445 "%s: %s\n", param_name, param_str_val);
6446 else if (strcmp(param_name, "fw-timestamp"))
6447 results_offset +=
6448 sprintf(qed_get_buf_ptr(results_buf,
6449 results_offset),
6450 "%s: %d\n", param_name, param_num_val);
6451 }
6452
6453 results_offset += sprintf(qed_get_buf_ptr(results_buf, results_offset),
6454 "\n");
6455
6456 *num_chars_printed = results_offset;
6457
6458 return dump_offset;
6459}
6460
6461/* Returns the block name that matches the specified block ID,
6462 * or NULL if not found.
6463 */
6464static const char *qed_dbg_get_block_name(struct qed_hwfn *p_hwfn,
6465 enum block_id block_id)
6466{
6467 const struct dbg_block_user *block =
6468 (const struct dbg_block_user *)
6469 p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS_USER_DATA].ptr + block_id;
6470
6471 return (const char *)block->name;
6472}
6473
6474static struct dbg_tools_user_data *qed_dbg_get_user_data(struct qed_hwfn
6475 *p_hwfn)
6476{
6477 return (struct dbg_tools_user_data *)p_hwfn->dbg_user_info;
6478}
6479
6480/* Parses the idle check rules and returns the number of characters printed.
6481 * In case of parsing error, returns 0.
6482 */
6483static u32 qed_parse_idle_chk_dump_rules(struct qed_hwfn *p_hwfn,
6484 u32 *dump_buf,
6485 u32 *dump_buf_end,
6486 u32 num_rules,
6487 bool print_fw_idle_chk,
6488 char *results_buf,
6489 u32 *num_errors, u32 *num_warnings)
6490{
6491 /* Offset in results_buf in bytes */
6492 u32 results_offset = 0;
6493
6494 u32 rule_idx;
6495 u16 i, j;
6496
6497 *num_errors = 0;
6498 *num_warnings = 0;
6499
6500 /* Go over dumped results */
6501 for (rule_idx = 0; rule_idx < num_rules && dump_buf < dump_buf_end;
6502 rule_idx++) {
6503 const struct dbg_idle_chk_rule_parsing_data *rule_parsing_data;
6504 struct dbg_idle_chk_result_hdr *hdr;
6505 const char *parsing_str, *lsi_msg;
6506 u32 parsing_str_offset;
6507 bool has_fw_msg;
6508 u8 curr_reg_id;
6509
6510 hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
6511 rule_parsing_data =
6512 (const struct dbg_idle_chk_rule_parsing_data *)
6513 p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].ptr +
6514 hdr->rule_id;
6515 parsing_str_offset =
6516 GET_FIELD(rule_parsing_data->data,
6517 DBG_IDLE_CHK_RULE_PARSING_DATA_STR_OFFSET);
6518 has_fw_msg =
6519 GET_FIELD(rule_parsing_data->data,
6520 DBG_IDLE_CHK_RULE_PARSING_DATA_HAS_FW_MSG) > 0;
6521 parsing_str = (const char *)
6522 p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr +
6523 parsing_str_offset;
6524 lsi_msg = parsing_str;
6525 curr_reg_id = 0;
6526
6527 if (hdr->severity >= MAX_DBG_IDLE_CHK_SEVERITY_TYPES)
6528 return 0;
6529
6530 /* Skip rule header */
6531 dump_buf += BYTES_TO_DWORDS(sizeof(*hdr));
6532
6533 /* Update errors/warnings count */
6534 if (hdr->severity == IDLE_CHK_SEVERITY_ERROR ||
6535 hdr->severity == IDLE_CHK_SEVERITY_ERROR_NO_TRAFFIC)
6536 (*num_errors)++;
6537 else
6538 (*num_warnings)++;
6539
6540 /* Print rule severity */
6541 results_offset +=
6542 sprintf(qed_get_buf_ptr(results_buf,
6543 results_offset), "%s: ",
6544 s_idle_chk_severity_str[hdr->severity]);
6545
6546 /* Print rule message */
6547 if (has_fw_msg)
6548 parsing_str += strlen(parsing_str) + 1;
6549 results_offset +=
6550 sprintf(qed_get_buf_ptr(results_buf,
6551 results_offset), "%s.",
6552 has_fw_msg &&
6553 print_fw_idle_chk ? parsing_str : lsi_msg);
6554 parsing_str += strlen(parsing_str) + 1;
6555
6556 /* Print register values */
6557 results_offset +=
6558 sprintf(qed_get_buf_ptr(results_buf,
6559 results_offset), " Registers:");
6560 for (i = 0;
6561 i < hdr->num_dumped_cond_regs + hdr->num_dumped_info_regs;
6562 i++) {
6563 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
6564 bool is_mem;
6565 u8 reg_id;
6566
6567 reg_hdr =
6568 (struct dbg_idle_chk_result_reg_hdr *)dump_buf;
6569 is_mem = GET_FIELD(reg_hdr->data,
6570 DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM);
6571 reg_id = GET_FIELD(reg_hdr->data,
6572 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID);
6573
6574 /* Skip reg header */
6575 dump_buf += BYTES_TO_DWORDS(sizeof(*reg_hdr));
6576
6577 /* Skip register names until the required reg_id is
6578 * reached.
6579 */
6580 for (; reg_id > curr_reg_id; curr_reg_id++)
6581 parsing_str += strlen(parsing_str) + 1;
6582
6583 results_offset +=
6584 sprintf(qed_get_buf_ptr(results_buf,
6585 results_offset), " %s",
6586 parsing_str);
6587 if (i < hdr->num_dumped_cond_regs && is_mem)
6588 results_offset +=
6589 sprintf(qed_get_buf_ptr(results_buf,
6590 results_offset),
6591 "[%d]", hdr->mem_entry_id +
6592 reg_hdr->start_entry);
6593 results_offset +=
6594 sprintf(qed_get_buf_ptr(results_buf,
6595 results_offset), "=");
6596 for (j = 0; j < reg_hdr->size; j++, dump_buf++) {
6597 results_offset +=
6598 sprintf(qed_get_buf_ptr(results_buf,
6599 results_offset),
6600 "0x%x", *dump_buf);
6601 if (j < reg_hdr->size - 1)
6602 results_offset +=
6603 sprintf(qed_get_buf_ptr
6604 (results_buf,
6605 results_offset), ",");
6606 }
6607 }
6608
6609 results_offset +=
6610 sprintf(qed_get_buf_ptr(results_buf, results_offset), "\n");
6611 }
6612
6613 /* Check if end of dump buffer was exceeded */
6614 if (dump_buf > dump_buf_end)
6615 return 0;
6616
6617 return results_offset;
6618}
6619
6620/* Parses an idle check dump buffer.
6621 * If result_buf is not NULL, the idle check results are printed to it.
6622 * In any case, the required results buffer size is assigned to
6623 * parsed_results_bytes.
6624 * The parsing status is returned.
6625 */
6626static enum dbg_status qed_parse_idle_chk_dump(struct qed_hwfn *p_hwfn,
6627 u32 *dump_buf,
6628 u32 num_dumped_dwords,
6629 char *results_buf,
6630 u32 *parsed_results_bytes,
6631 u32 *num_errors,
6632 u32 *num_warnings)
6633{
6634 u32 num_section_params = 0, num_rules, num_rules_not_dumped;
6635 const char *section_name, *param_name, *param_str_val;
6636 u32 *dump_buf_end = dump_buf + num_dumped_dwords;
6637
6638 /* Offset in results_buf in bytes */
6639 u32 results_offset = 0;
6640
6641 *parsed_results_bytes = 0;
6642 *num_errors = 0;
6643 *num_warnings = 0;
6644
6645 if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr ||
6646 !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].ptr)
6647 return DBG_STATUS_DBG_ARRAY_NOT_SET;
6648
6649 /* Read global_params section */
6650 dump_buf += qed_read_section_hdr(dump_buf,
6651 §ion_name, &num_section_params);
6652 if (strcmp(section_name, "global_params"))
6653 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6654
6655 /* Print global params */
6656 dump_buf += qed_print_section_params(dump_buf,
6657 num_section_params,
6658 results_buf, &results_offset);
6659
6660 /* Read idle_chk section
6661 * There may be 1 or 2 idle_chk section parameters:
6662 * - 1st is "num_rules"
6663 * - 2nd is "num_rules_not_dumped" (optional)
6664 */
6665
6666 dump_buf += qed_read_section_hdr(dump_buf,
6667 §ion_name, &num_section_params);
6668 if (strcmp(section_name, "idle_chk") ||
6669 (num_section_params != 2 && num_section_params != 1))
6670 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6671 dump_buf += qed_read_param(dump_buf,
6672 ¶m_name, ¶m_str_val, &num_rules);
6673 if (strcmp(param_name, "num_rules"))
6674 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6675 if (num_section_params > 1) {
6676 dump_buf += qed_read_param(dump_buf,
6677 ¶m_name,
6678 ¶m_str_val,
6679 &num_rules_not_dumped);
6680 if (strcmp(param_name, "num_rules_not_dumped"))
6681 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6682 } else {
6683 num_rules_not_dumped = 0;
6684 }
6685
6686 if (num_rules) {
6687 u32 rules_print_size;
6688
6689 /* Print FW output */
6690 results_offset +=
6691 sprintf(qed_get_buf_ptr(results_buf,
6692 results_offset),
6693 "FW_IDLE_CHECK:\n");
6694 rules_print_size =
6695 qed_parse_idle_chk_dump_rules(p_hwfn,
6696 dump_buf,
6697 dump_buf_end,
6698 num_rules,
6699 true,
6700 results_buf ?
6701 results_buf +
6702 results_offset :
6703 NULL,
6704 num_errors,
6705 num_warnings);
6706 results_offset += rules_print_size;
6707 if (!rules_print_size)
6708 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6709
6710 /* Print LSI output */
6711 results_offset +=
6712 sprintf(qed_get_buf_ptr(results_buf,
6713 results_offset),
6714 "\nLSI_IDLE_CHECK:\n");
6715 rules_print_size =
6716 qed_parse_idle_chk_dump_rules(p_hwfn,
6717 dump_buf,
6718 dump_buf_end,
6719 num_rules,
6720 false,
6721 results_buf ?
6722 results_buf +
6723 results_offset :
6724 NULL,
6725 num_errors,
6726 num_warnings);
6727 results_offset += rules_print_size;
6728 if (!rules_print_size)
6729 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6730 }
6731
6732 /* Print errors/warnings count */
6733 if (*num_errors)
6734 results_offset +=
6735 sprintf(qed_get_buf_ptr(results_buf,
6736 results_offset),
6737 "\nIdle Check failed!!! (with %d errors and %d warnings)\n",
6738 *num_errors, *num_warnings);
6739 else if (*num_warnings)
6740 results_offset +=
6741 sprintf(qed_get_buf_ptr(results_buf,
6742 results_offset),
6743 "\nIdle Check completed successfully (with %d warnings)\n",
6744 *num_warnings);
6745 else
6746 results_offset +=
6747 sprintf(qed_get_buf_ptr(results_buf,
6748 results_offset),
6749 "\nIdle Check completed successfully\n");
6750
6751 if (num_rules_not_dumped)
6752 results_offset +=
6753 sprintf(qed_get_buf_ptr(results_buf,
6754 results_offset),
6755 "\nIdle Check Partially dumped : num_rules_not_dumped = %d\n",
6756 num_rules_not_dumped);
6757
6758 /* Add 1 for string NULL termination */
6759 *parsed_results_bytes = results_offset + 1;
6760
6761 return DBG_STATUS_OK;
6762}
6763
6764/* Allocates and fills MCP Trace meta data based on the specified meta data
6765 * dump buffer.
6766 * Returns debug status code.
6767 */
6768static enum dbg_status
6769qed_mcp_trace_alloc_meta_data(struct qed_hwfn *p_hwfn,
6770 const u32 *meta_buf)
6771{
6772 struct dbg_tools_user_data *dev_user_data;
6773 u32 offset = 0, signature, i;
6774 struct mcp_trace_meta *meta;
6775 u8 *meta_buf_bytes;
6776
6777 dev_user_data = qed_dbg_get_user_data(p_hwfn);
6778 meta = &dev_user_data->mcp_trace_meta;
6779 meta_buf_bytes = (u8 *)meta_buf;
6780
6781 /* Free the previous meta before loading a new one. */
6782 if (meta->is_allocated)
6783 qed_mcp_trace_free_meta_data(p_hwfn);
6784
6785 memset(meta, 0, sizeof(*meta));
6786
6787 /* Read first signature */
6788 signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6789 if (signature != NVM_MAGIC_VALUE)
6790 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
6791
6792 /* Read no. of modules and allocate memory for their pointers */
6793 meta->modules_num = qed_read_byte_from_buf(meta_buf_bytes, &offset);
6794 meta->modules = kcalloc(meta->modules_num, sizeof(char *),
6795 GFP_KERNEL);
6796 if (!meta->modules)
6797 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6798
6799 /* Allocate and read all module strings */
6800 for (i = 0; i < meta->modules_num; i++) {
6801 u8 module_len = qed_read_byte_from_buf(meta_buf_bytes, &offset);
6802
6803 *(meta->modules + i) = kzalloc(module_len, GFP_KERNEL);
6804 if (!(*(meta->modules + i))) {
6805 /* Update number of modules to be released */
6806 meta->modules_num = i ? i - 1 : 0;
6807 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6808 }
6809
6810 qed_read_str_from_buf(meta_buf_bytes, &offset, module_len,
6811 *(meta->modules + i));
6812 if (module_len > MCP_TRACE_MAX_MODULE_LEN)
6813 (*(meta->modules + i))[MCP_TRACE_MAX_MODULE_LEN] = '\0';
6814 }
6815
6816 /* Read second signature */
6817 signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6818 if (signature != NVM_MAGIC_VALUE)
6819 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
6820
6821 /* Read number of formats and allocate memory for all formats */
6822 meta->formats_num = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6823 meta->formats = kcalloc(meta->formats_num,
6824 sizeof(struct mcp_trace_format),
6825 GFP_KERNEL);
6826 if (!meta->formats)
6827 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6828
6829 /* Allocate and read all strings */
6830 for (i = 0; i < meta->formats_num; i++) {
6831 struct mcp_trace_format *format_ptr = &meta->formats[i];
6832 u8 format_len;
6833
6834 format_ptr->data = qed_read_dword_from_buf(meta_buf_bytes,
6835 &offset);
6836 format_len = GET_MFW_FIELD(format_ptr->data,
6837 MCP_TRACE_FORMAT_LEN);
6838 format_ptr->format_str = kzalloc(format_len, GFP_KERNEL);
6839 if (!format_ptr->format_str) {
6840 /* Update number of modules to be released */
6841 meta->formats_num = i ? i - 1 : 0;
6842 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6843 }
6844
6845 qed_read_str_from_buf(meta_buf_bytes,
6846 &offset,
6847 format_len, format_ptr->format_str);
6848 }
6849
6850 meta->is_allocated = true;
6851 return DBG_STATUS_OK;
6852}
6853
6854/* Parses an MCP trace buffer. If result_buf is not NULL, the MCP Trace results
6855 * are printed to it. The parsing status is returned.
6856 * Arguments:
6857 * trace_buf - MCP trace cyclic buffer
6858 * trace_buf_size - MCP trace cyclic buffer size in bytes
6859 * data_offset - offset in bytes of the data to parse in the MCP trace cyclic
6860 * buffer.
6861 * data_size - size in bytes of data to parse.
6862 * parsed_buf - destination buffer for parsed data.
6863 * parsed_results_bytes - size of parsed data in bytes.
6864 */
6865static enum dbg_status qed_parse_mcp_trace_buf(struct qed_hwfn *p_hwfn,
6866 u8 *trace_buf,
6867 u32 trace_buf_size,
6868 u32 data_offset,
6869 u32 data_size,
6870 char *parsed_buf,
6871 u32 *parsed_results_bytes)
6872{
6873 struct dbg_tools_user_data *dev_user_data;
6874 struct mcp_trace_meta *meta;
6875 u32 param_mask, param_shift;
6876 enum dbg_status status;
6877
6878 dev_user_data = qed_dbg_get_user_data(p_hwfn);
6879 meta = &dev_user_data->mcp_trace_meta;
6880 *parsed_results_bytes = 0;
6881
6882 if (!meta->is_allocated)
6883 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6884
6885 status = DBG_STATUS_OK;
6886
6887 while (data_size) {
6888 struct mcp_trace_format *format_ptr;
6889 u8 format_level, format_module;
6890 u32 params[3] = { 0, 0, 0 };
6891 u32 header, format_idx, i;
6892
6893 if (data_size < MFW_TRACE_ENTRY_SIZE)
6894 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6895
6896 header = qed_read_from_cyclic_buf(trace_buf,
6897 &data_offset,
6898 trace_buf_size,
6899 MFW_TRACE_ENTRY_SIZE);
6900 data_size -= MFW_TRACE_ENTRY_SIZE;
6901 format_idx = header & MFW_TRACE_EVENTID_MASK;
6902
6903 /* Skip message if its index doesn't exist in the meta data */
6904 if (format_idx >= meta->formats_num) {
6905 u8 format_size = (u8)GET_MFW_FIELD(header,
6906 MFW_TRACE_PRM_SIZE);
6907
6908 if (data_size < format_size)
6909 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6910
6911 data_offset = qed_cyclic_add(data_offset,
6912 format_size,
6913 trace_buf_size);
6914 data_size -= format_size;
6915 continue;
6916 }
6917
6918 format_ptr = &meta->formats[format_idx];
6919
6920 for (i = 0,
6921 param_mask = MCP_TRACE_FORMAT_P1_SIZE_MASK, param_shift =
6922 MCP_TRACE_FORMAT_P1_SIZE_OFFSET;
6923 i < MCP_TRACE_FORMAT_MAX_PARAMS;
6924 i++, param_mask <<= MCP_TRACE_FORMAT_PARAM_WIDTH,
6925 param_shift += MCP_TRACE_FORMAT_PARAM_WIDTH) {
6926 /* Extract param size (0..3) */
6927 u8 param_size = (u8)((format_ptr->data & param_mask) >>
6928 param_shift);
6929
6930 /* If the param size is zero, there are no other
6931 * parameters.
6932 */
6933 if (!param_size)
6934 break;
6935
6936 /* Size is encoded using 2 bits, where 3 is used to
6937 * encode 4.
6938 */
6939 if (param_size == 3)
6940 param_size = 4;
6941
6942 if (data_size < param_size)
6943 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6944
6945 params[i] = qed_read_from_cyclic_buf(trace_buf,
6946 &data_offset,
6947 trace_buf_size,
6948 param_size);
6949 data_size -= param_size;
6950 }
6951
6952 format_level = (u8)GET_MFW_FIELD(format_ptr->data,
6953 MCP_TRACE_FORMAT_LEVEL);
6954 format_module = (u8)GET_MFW_FIELD(format_ptr->data,
6955 MCP_TRACE_FORMAT_MODULE);
6956 if (format_level >= ARRAY_SIZE(s_mcp_trace_level_str))
6957 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6958
6959 /* Print current message to results buffer */
6960 *parsed_results_bytes +=
6961 sprintf(qed_get_buf_ptr(parsed_buf,
6962 *parsed_results_bytes),
6963 "%s %-8s: ",
6964 s_mcp_trace_level_str[format_level],
6965 meta->modules[format_module]);
6966 *parsed_results_bytes +=
6967 sprintf(qed_get_buf_ptr(parsed_buf, *parsed_results_bytes),
6968 format_ptr->format_str,
6969 params[0], params[1], params[2]);
6970 }
6971
6972 /* Add string NULL terminator */
6973 (*parsed_results_bytes)++;
6974
6975 return status;
6976}
6977
6978/* Parses an MCP Trace dump buffer.
6979 * If result_buf is not NULL, the MCP Trace results are printed to it.
6980 * In any case, the required results buffer size is assigned to
6981 * parsed_results_bytes.
6982 * The parsing status is returned.
6983 */
6984static enum dbg_status qed_parse_mcp_trace_dump(struct qed_hwfn *p_hwfn,
6985 u32 *dump_buf,
6986 char *results_buf,
6987 u32 *parsed_results_bytes,
6988 bool free_meta_data)
6989{
6990 const char *section_name, *param_name, *param_str_val;
6991 u32 data_size, trace_data_dwords, trace_meta_dwords;
6992 u32 offset, results_offset, results_buf_bytes;
6993 u32 param_num_val, num_section_params;
6994 struct mcp_trace *trace;
6995 enum dbg_status status;
6996 const u32 *meta_buf;
6997 u8 *trace_buf;
6998
6999 *parsed_results_bytes = 0;
7000
7001 /* Read global_params section */
7002 dump_buf += qed_read_section_hdr(dump_buf,
7003 §ion_name, &num_section_params);
7004 if (strcmp(section_name, "global_params"))
7005 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7006
7007 /* Print global params */
7008 dump_buf += qed_print_section_params(dump_buf,
7009 num_section_params,
7010 results_buf, &results_offset);
7011
7012 /* Read trace_data section */
7013 dump_buf += qed_read_section_hdr(dump_buf,
7014 §ion_name, &num_section_params);
7015 if (strcmp(section_name, "mcp_trace_data") || num_section_params != 1)
7016 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7017 dump_buf += qed_read_param(dump_buf,
7018 ¶m_name, ¶m_str_val, ¶m_num_val);
7019 if (strcmp(param_name, "size"))
7020 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7021 trace_data_dwords = param_num_val;
7022
7023 /* Prepare trace info */
7024 trace = (struct mcp_trace *)dump_buf;
7025 if (trace->signature != MFW_TRACE_SIGNATURE || !trace->size)
7026 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7027
7028 trace_buf = (u8 *)dump_buf + sizeof(*trace);
7029 offset = trace->trace_oldest;
7030 data_size = qed_cyclic_sub(trace->trace_prod, offset, trace->size);
7031 dump_buf += trace_data_dwords;
7032
7033 /* Read meta_data section */
7034 dump_buf += qed_read_section_hdr(dump_buf,
7035 §ion_name, &num_section_params);
7036 if (strcmp(section_name, "mcp_trace_meta"))
7037 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7038 dump_buf += qed_read_param(dump_buf,
7039 ¶m_name, ¶m_str_val, ¶m_num_val);
7040 if (strcmp(param_name, "size"))
7041 return DBG_STATUS_MCP_TRACE_BAD_DATA;
7042 trace_meta_dwords = param_num_val;
7043
7044 /* Choose meta data buffer */
7045 if (!trace_meta_dwords) {
7046 /* Dump doesn't include meta data */
7047 struct dbg_tools_user_data *dev_user_data =
7048 qed_dbg_get_user_data(p_hwfn);
7049
7050 if (!dev_user_data->mcp_trace_user_meta_buf)
7051 return DBG_STATUS_MCP_TRACE_NO_META;
7052
7053 meta_buf = dev_user_data->mcp_trace_user_meta_buf;
7054 } else {
7055 /* Dump includes meta data */
7056 meta_buf = dump_buf;
7057 }
7058
7059 /* Allocate meta data memory */
7060 status = qed_mcp_trace_alloc_meta_data(p_hwfn, meta_buf);
7061 if (status != DBG_STATUS_OK)
7062 return status;
7063
7064 status = qed_parse_mcp_trace_buf(p_hwfn,
7065 trace_buf,
7066 trace->size,
7067 offset,
7068 data_size,
7069 results_buf ?
7070 results_buf + results_offset :
7071 NULL,
7072 &results_buf_bytes);
7073 if (status != DBG_STATUS_OK)
7074 return status;
7075
7076 if (free_meta_data)
7077 qed_mcp_trace_free_meta_data(p_hwfn);
7078
7079 *parsed_results_bytes = results_offset + results_buf_bytes;
7080
7081 return DBG_STATUS_OK;
7082}
7083
7084/* Parses a Reg FIFO dump buffer.
7085 * If result_buf is not NULL, the Reg FIFO results are printed to it.
7086 * In any case, the required results buffer size is assigned to
7087 * parsed_results_bytes.
7088 * The parsing status is returned.
7089 */
7090static enum dbg_status qed_parse_reg_fifo_dump(u32 *dump_buf,
7091 char *results_buf,
7092 u32 *parsed_results_bytes)
7093{
7094 const char *section_name, *param_name, *param_str_val;
7095 u32 param_num_val, num_section_params, num_elements;
7096 struct reg_fifo_element *elements;
7097 u8 i, j, err_code, vf_val;
7098 u32 results_offset = 0;
7099 char vf_str[4];
7100
7101 /* Read global_params section */
7102 dump_buf += qed_read_section_hdr(dump_buf,
7103 §ion_name, &num_section_params);
7104 if (strcmp(section_name, "global_params"))
7105 return DBG_STATUS_REG_FIFO_BAD_DATA;
7106
7107 /* Print global params */
7108 dump_buf += qed_print_section_params(dump_buf,
7109 num_section_params,
7110 results_buf, &results_offset);
7111
7112 /* Read reg_fifo_data section */
7113 dump_buf += qed_read_section_hdr(dump_buf,
7114 §ion_name, &num_section_params);
7115 if (strcmp(section_name, "reg_fifo_data"))
7116 return DBG_STATUS_REG_FIFO_BAD_DATA;
7117 dump_buf += qed_read_param(dump_buf,
7118 ¶m_name, ¶m_str_val, ¶m_num_val);
7119 if (strcmp(param_name, "size"))
7120 return DBG_STATUS_REG_FIFO_BAD_DATA;
7121 if (param_num_val % REG_FIFO_ELEMENT_DWORDS)
7122 return DBG_STATUS_REG_FIFO_BAD_DATA;
7123 num_elements = param_num_val / REG_FIFO_ELEMENT_DWORDS;
7124 elements = (struct reg_fifo_element *)dump_buf;
7125
7126 /* Decode elements */
7127 for (i = 0; i < num_elements; i++) {
7128 const char *err_msg = NULL;
7129
7130 /* Discover if element belongs to a VF or a PF */
7131 vf_val = GET_FIELD(elements[i].data, REG_FIFO_ELEMENT_VF);
7132 if (vf_val == REG_FIFO_ELEMENT_IS_PF_VF_VAL)
7133 sprintf(vf_str, "%s", "N/A");
7134 else
7135 sprintf(vf_str, "%d", vf_val);
7136
7137 /* Find error message */
7138 err_code = GET_FIELD(elements[i].data, REG_FIFO_ELEMENT_ERROR);
7139 for (j = 0; j < ARRAY_SIZE(s_reg_fifo_errors) && !err_msg; j++)
7140 if (err_code == s_reg_fifo_errors[j].err_code)
7141 err_msg = s_reg_fifo_errors[j].err_msg;
7142
7143 /* Add parsed element to parsed buffer */
7144 results_offset +=
7145 sprintf(qed_get_buf_ptr(results_buf,
7146 results_offset),
7147 "raw: 0x%016llx, address: 0x%07x, access: %-5s, pf: %2d, vf: %s, port: %d, privilege: %-3s, protection: %-12s, master: %-4s, error: %s\n",
7148 elements[i].data,
7149 (u32)GET_FIELD(elements[i].data,
7150 REG_FIFO_ELEMENT_ADDRESS) *
7151 REG_FIFO_ELEMENT_ADDR_FACTOR,
7152 s_access_strs[GET_FIELD(elements[i].data,
7153 REG_FIFO_ELEMENT_ACCESS)],
7154 (u32)GET_FIELD(elements[i].data,
7155 REG_FIFO_ELEMENT_PF),
7156 vf_str,
7157 (u32)GET_FIELD(elements[i].data,
7158 REG_FIFO_ELEMENT_PORT),
7159 s_privilege_strs[GET_FIELD(elements[i].data,
7160 REG_FIFO_ELEMENT_PRIVILEGE)],
7161 s_protection_strs[GET_FIELD(elements[i].data,
7162 REG_FIFO_ELEMENT_PROTECTION)],
7163 s_master_strs[GET_FIELD(elements[i].data,
7164 REG_FIFO_ELEMENT_MASTER)],
7165 err_msg ? err_msg : "unknown error code");
7166 }
7167
7168 results_offset += sprintf(qed_get_buf_ptr(results_buf,
7169 results_offset),
7170 "fifo contained %d elements", num_elements);
7171
7172 /* Add 1 for string NULL termination */
7173 *parsed_results_bytes = results_offset + 1;
7174
7175 return DBG_STATUS_OK;
7176}
7177
7178static enum dbg_status qed_parse_igu_fifo_element(struct igu_fifo_element
7179 *element, char
7180 *results_buf,
7181 u32 *results_offset)
7182{
7183 const struct igu_fifo_addr_data *found_addr = NULL;
7184 u8 source, err_type, i, is_cleanup;
7185 char parsed_addr_data[32];
7186 char parsed_wr_data[256];
7187 u32 wr_data, prod_cons;
7188 bool is_wr_cmd, is_pf;
7189 u16 cmd_addr;
7190 u64 dword12;
7191
7192 /* Dword12 (dword index 1 and 2) contains bits 32..95 of the
7193 * FIFO element.
7194 */
7195 dword12 = ((u64)element->dword2 << 32) | element->dword1;
7196 is_wr_cmd = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD);
7197 is_pf = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_IS_PF);
7198 cmd_addr = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR);
7199 source = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_SOURCE);
7200 err_type = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE);
7201
7202 if (source >= ARRAY_SIZE(s_igu_fifo_source_strs))
7203 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7204 if (err_type >= ARRAY_SIZE(s_igu_fifo_error_strs))
7205 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7206
7207 /* Find address data */
7208 for (i = 0; i < ARRAY_SIZE(s_igu_fifo_addr_data) && !found_addr; i++) {
7209 const struct igu_fifo_addr_data *curr_addr =
7210 &s_igu_fifo_addr_data[i];
7211
7212 if (cmd_addr >= curr_addr->start_addr && cmd_addr <=
7213 curr_addr->end_addr)
7214 found_addr = curr_addr;
7215 }
7216
7217 if (!found_addr)
7218 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7219
7220 /* Prepare parsed address data */
7221 switch (found_addr->type) {
7222 case IGU_ADDR_TYPE_MSIX_MEM:
7223 sprintf(parsed_addr_data, " vector_num = 0x%x", cmd_addr / 2);
7224 break;
7225 case IGU_ADDR_TYPE_WRITE_INT_ACK:
7226 case IGU_ADDR_TYPE_WRITE_PROD_UPDATE:
7227 sprintf(parsed_addr_data,
7228 " SB = 0x%x", cmd_addr - found_addr->start_addr);
7229 break;
7230 default:
7231 parsed_addr_data[0] = '\0';
7232 }
7233
7234 if (!is_wr_cmd) {
7235 parsed_wr_data[0] = '\0';
7236 goto out;
7237 }
7238
7239 /* Prepare parsed write data */
7240 wr_data = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_WR_DATA);
7241 prod_cons = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_PROD_CONS);
7242 is_cleanup = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_CMD_TYPE);
7243
7244 if (source == IGU_SRC_ATTN) {
7245 sprintf(parsed_wr_data, "prod: 0x%x, ", prod_cons);
7246 } else {
7247 if (is_cleanup) {
7248 u8 cleanup_val, cleanup_type;
7249
7250 cleanup_val =
7251 GET_FIELD(wr_data,
7252 IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL);
7253 cleanup_type =
7254 GET_FIELD(wr_data,
7255 IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE);
7256
7257 sprintf(parsed_wr_data,
7258 "cmd_type: cleanup, cleanup_val: %s, cleanup_type : %d, ",
7259 cleanup_val ? "set" : "clear",
7260 cleanup_type);
7261 } else {
7262 u8 update_flag, en_dis_int_for_sb, segment;
7263 u8 timer_mask;
7264
7265 update_flag = GET_FIELD(wr_data,
7266 IGU_FIFO_WR_DATA_UPDATE_FLAG);
7267 en_dis_int_for_sb =
7268 GET_FIELD(wr_data,
7269 IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB);
7270 segment = GET_FIELD(wr_data,
7271 IGU_FIFO_WR_DATA_SEGMENT);
7272 timer_mask = GET_FIELD(wr_data,
7273 IGU_FIFO_WR_DATA_TIMER_MASK);
7274
7275 sprintf(parsed_wr_data,
7276 "cmd_type: prod/cons update, prod/cons: 0x%x, update_flag: %s, en_dis_int_for_sb : %s, segment : %s, timer_mask = %d, ",
7277 prod_cons,
7278 update_flag ? "update" : "nop",
7279 en_dis_int_for_sb ?
7280 (en_dis_int_for_sb == 1 ? "disable" : "nop") :
7281 "enable",
7282 segment ? "attn" : "regular",
7283 timer_mask);
7284 }
7285 }
7286out:
7287 /* Add parsed element to parsed buffer */
7288 *results_offset += sprintf(qed_get_buf_ptr(results_buf,
7289 *results_offset),
7290 "raw: 0x%01x%08x%08x, %s: %d, source : %s, type : %s, cmd_addr : 0x%x(%s%s), %serror: %s\n",
7291 element->dword2, element->dword1,
7292 element->dword0,
7293 is_pf ? "pf" : "vf",
7294 GET_FIELD(element->dword0,
7295 IGU_FIFO_ELEMENT_DWORD0_FID),
7296 s_igu_fifo_source_strs[source],
7297 is_wr_cmd ? "wr" : "rd",
7298 cmd_addr,
7299 (!is_pf && found_addr->vf_desc)
7300 ? found_addr->vf_desc
7301 : found_addr->desc,
7302 parsed_addr_data,
7303 parsed_wr_data,
7304 s_igu_fifo_error_strs[err_type]);
7305
7306 return DBG_STATUS_OK;
7307}
7308
7309/* Parses an IGU FIFO dump buffer.
7310 * If result_buf is not NULL, the IGU FIFO results are printed to it.
7311 * In any case, the required results buffer size is assigned to
7312 * parsed_results_bytes.
7313 * The parsing status is returned.
7314 */
7315static enum dbg_status qed_parse_igu_fifo_dump(u32 *dump_buf,
7316 char *results_buf,
7317 u32 *parsed_results_bytes)
7318{
7319 const char *section_name, *param_name, *param_str_val;
7320 u32 param_num_val, num_section_params, num_elements;
7321 struct igu_fifo_element *elements;
7322 enum dbg_status status;
7323 u32 results_offset = 0;
7324 u8 i;
7325
7326 /* Read global_params section */
7327 dump_buf += qed_read_section_hdr(dump_buf,
7328 §ion_name, &num_section_params);
7329 if (strcmp(section_name, "global_params"))
7330 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7331
7332 /* Print global params */
7333 dump_buf += qed_print_section_params(dump_buf,
7334 num_section_params,
7335 results_buf, &results_offset);
7336
7337 /* Read igu_fifo_data section */
7338 dump_buf += qed_read_section_hdr(dump_buf,
7339 §ion_name, &num_section_params);
7340 if (strcmp(section_name, "igu_fifo_data"))
7341 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7342 dump_buf += qed_read_param(dump_buf,
7343 ¶m_name, ¶m_str_val, ¶m_num_val);
7344 if (strcmp(param_name, "size"))
7345 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7346 if (param_num_val % IGU_FIFO_ELEMENT_DWORDS)
7347 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7348 num_elements = param_num_val / IGU_FIFO_ELEMENT_DWORDS;
7349 elements = (struct igu_fifo_element *)dump_buf;
7350
7351 /* Decode elements */
7352 for (i = 0; i < num_elements; i++) {
7353 status = qed_parse_igu_fifo_element(&elements[i],
7354 results_buf,
7355 &results_offset);
7356 if (status != DBG_STATUS_OK)
7357 return status;
7358 }
7359
7360 results_offset += sprintf(qed_get_buf_ptr(results_buf,
7361 results_offset),
7362 "fifo contained %d elements", num_elements);
7363
7364 /* Add 1 for string NULL termination */
7365 *parsed_results_bytes = results_offset + 1;
7366
7367 return DBG_STATUS_OK;
7368}
7369
7370static enum dbg_status
7371qed_parse_protection_override_dump(u32 *dump_buf,
7372 char *results_buf,
7373 u32 *parsed_results_bytes)
7374{
7375 const char *section_name, *param_name, *param_str_val;
7376 u32 param_num_val, num_section_params, num_elements;
7377 struct protection_override_element *elements;
7378 u32 results_offset = 0;
7379 u8 i;
7380
7381 /* Read global_params section */
7382 dump_buf += qed_read_section_hdr(dump_buf,
7383 §ion_name, &num_section_params);
7384 if (strcmp(section_name, "global_params"))
7385 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7386
7387 /* Print global params */
7388 dump_buf += qed_print_section_params(dump_buf,
7389 num_section_params,
7390 results_buf, &results_offset);
7391
7392 /* Read protection_override_data section */
7393 dump_buf += qed_read_section_hdr(dump_buf,
7394 §ion_name, &num_section_params);
7395 if (strcmp(section_name, "protection_override_data"))
7396 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7397 dump_buf += qed_read_param(dump_buf,
7398 ¶m_name, ¶m_str_val, ¶m_num_val);
7399 if (strcmp(param_name, "size"))
7400 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7401 if (param_num_val % PROTECTION_OVERRIDE_ELEMENT_DWORDS)
7402 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7403 num_elements = param_num_val / PROTECTION_OVERRIDE_ELEMENT_DWORDS;
7404 elements = (struct protection_override_element *)dump_buf;
7405
7406 /* Decode elements */
7407 for (i = 0; i < num_elements; i++) {
7408 u32 address = GET_FIELD(elements[i].data,
7409 PROTECTION_OVERRIDE_ELEMENT_ADDRESS) *
7410 PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR;
7411
7412 results_offset +=
7413 sprintf(qed_get_buf_ptr(results_buf,
7414 results_offset),
7415 "window %2d, address: 0x%07x, size: %7d regs, read: %d, write: %d, read protection: %-12s, write protection: %-12s\n",
7416 i, address,
7417 (u32)GET_FIELD(elements[i].data,
7418 PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE),
7419 (u32)GET_FIELD(elements[i].data,
7420 PROTECTION_OVERRIDE_ELEMENT_READ),
7421 (u32)GET_FIELD(elements[i].data,
7422 PROTECTION_OVERRIDE_ELEMENT_WRITE),
7423 s_protection_strs[GET_FIELD(elements[i].data,
7424 PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION)],
7425 s_protection_strs[GET_FIELD(elements[i].data,
7426 PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION)]);
7427 }
7428
7429 results_offset += sprintf(qed_get_buf_ptr(results_buf,
7430 results_offset),
7431 "protection override contained %d elements",
7432 num_elements);
7433
7434 /* Add 1 for string NULL termination */
7435 *parsed_results_bytes = results_offset + 1;
7436
7437 return DBG_STATUS_OK;
7438}
7439
7440/* Parses a FW Asserts dump buffer.
7441 * If result_buf is not NULL, the FW Asserts results are printed to it.
7442 * In any case, the required results buffer size is assigned to
7443 * parsed_results_bytes.
7444 * The parsing status is returned.
7445 */
7446static enum dbg_status qed_parse_fw_asserts_dump(u32 *dump_buf,
7447 char *results_buf,
7448 u32 *parsed_results_bytes)
7449{
7450 u32 num_section_params, param_num_val, i, results_offset = 0;
7451 const char *param_name, *param_str_val, *section_name;
7452 bool last_section_found = false;
7453
7454 *parsed_results_bytes = 0;
7455
7456 /* Read global_params section */
7457 dump_buf += qed_read_section_hdr(dump_buf,
7458 §ion_name, &num_section_params);
7459 if (strcmp(section_name, "global_params"))
7460 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7461
7462 /* Print global params */
7463 dump_buf += qed_print_section_params(dump_buf,
7464 num_section_params,
7465 results_buf, &results_offset);
7466
7467 while (!last_section_found) {
7468 dump_buf += qed_read_section_hdr(dump_buf,
7469 §ion_name,
7470 &num_section_params);
7471 if (!strcmp(section_name, "fw_asserts")) {
7472 /* Extract params */
7473 const char *storm_letter = NULL;
7474 u32 storm_dump_size = 0;
7475
7476 for (i = 0; i < num_section_params; i++) {
7477 dump_buf += qed_read_param(dump_buf,
7478 ¶m_name,
7479 ¶m_str_val,
7480 ¶m_num_val);
7481 if (!strcmp(param_name, "storm"))
7482 storm_letter = param_str_val;
7483 else if (!strcmp(param_name, "size"))
7484 storm_dump_size = param_num_val;
7485 else
7486 return
7487 DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7488 }
7489
7490 if (!storm_letter || !storm_dump_size)
7491 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7492
7493 /* Print data */
7494 results_offset +=
7495 sprintf(qed_get_buf_ptr(results_buf,
7496 results_offset),
7497 "\n%sSTORM_ASSERT: size=%d\n",
7498 storm_letter, storm_dump_size);
7499 for (i = 0; i < storm_dump_size; i++, dump_buf++)
7500 results_offset +=
7501 sprintf(qed_get_buf_ptr(results_buf,
7502 results_offset),
7503 "%08x\n", *dump_buf);
7504 } else if (!strcmp(section_name, "last")) {
7505 last_section_found = true;
7506 } else {
7507 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7508 }
7509 }
7510
7511 /* Add 1 for string NULL termination */
7512 *parsed_results_bytes = results_offset + 1;
7513
7514 return DBG_STATUS_OK;
7515}
7516
7517/***************************** Public Functions *******************************/
7518
7519enum dbg_status qed_dbg_user_set_bin_ptr(struct qed_hwfn *p_hwfn,
7520 const u8 * const bin_ptr)
7521{
7522 struct bin_buffer_hdr *buf_hdrs = (struct bin_buffer_hdr *)bin_ptr;
7523 u8 buf_id;
7524
7525 /* Convert binary data to debug arrays */
7526 for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++)
7527 qed_set_dbg_bin_buf(p_hwfn,
7528 (enum bin_dbg_buffer_type)buf_id,
7529 (u32 *)(bin_ptr + buf_hdrs[buf_id].offset),
7530 buf_hdrs[buf_id].length);
7531
7532 return DBG_STATUS_OK;
7533}
7534
7535enum dbg_status qed_dbg_alloc_user_data(struct qed_hwfn *p_hwfn,
7536 void **user_data_ptr)
7537{
7538 *user_data_ptr = kzalloc(sizeof(struct dbg_tools_user_data),
7539 GFP_KERNEL);
7540 if (!(*user_data_ptr))
7541 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
7542
7543 return DBG_STATUS_OK;
7544}
7545
7546const char *qed_dbg_get_status_str(enum dbg_status status)
7547{
7548 return (status <
7549 MAX_DBG_STATUS) ? s_status_str[status] : "Invalid debug status";
7550}
7551
7552enum dbg_status qed_get_idle_chk_results_buf_size(struct qed_hwfn *p_hwfn,
7553 u32 *dump_buf,
7554 u32 num_dumped_dwords,
7555 u32 *results_buf_size)
7556{
7557 u32 num_errors, num_warnings;
7558
7559 return qed_parse_idle_chk_dump(p_hwfn,
7560 dump_buf,
7561 num_dumped_dwords,
7562 NULL,
7563 results_buf_size,
7564 &num_errors, &num_warnings);
7565}
7566
7567enum dbg_status qed_print_idle_chk_results(struct qed_hwfn *p_hwfn,
7568 u32 *dump_buf,
7569 u32 num_dumped_dwords,
7570 char *results_buf,
7571 u32 *num_errors,
7572 u32 *num_warnings)
7573{
7574 u32 parsed_buf_size;
7575
7576 return qed_parse_idle_chk_dump(p_hwfn,
7577 dump_buf,
7578 num_dumped_dwords,
7579 results_buf,
7580 &parsed_buf_size,
7581 num_errors, num_warnings);
7582}
7583
7584void qed_dbg_mcp_trace_set_meta_data(struct qed_hwfn *p_hwfn,
7585 const u32 *meta_buf)
7586{
7587 struct dbg_tools_user_data *dev_user_data =
7588 qed_dbg_get_user_data(p_hwfn);
7589
7590 dev_user_data->mcp_trace_user_meta_buf = meta_buf;
7591}
7592
7593enum dbg_status qed_get_mcp_trace_results_buf_size(struct qed_hwfn *p_hwfn,
7594 u32 *dump_buf,
7595 u32 num_dumped_dwords,
7596 u32 *results_buf_size)
7597{
7598 return qed_parse_mcp_trace_dump(p_hwfn,
7599 dump_buf, NULL, results_buf_size, true);
7600}
7601
7602enum dbg_status qed_print_mcp_trace_results(struct qed_hwfn *p_hwfn,
7603 u32 *dump_buf,
7604 u32 num_dumped_dwords,
7605 char *results_buf)
7606{
7607 u32 parsed_buf_size;
7608
7609 /* Doesn't do anything, needed for compile time asserts */
7610 qed_user_static_asserts();
7611
7612 return qed_parse_mcp_trace_dump(p_hwfn,
7613 dump_buf,
7614 results_buf, &parsed_buf_size, true);
7615}
7616
7617enum dbg_status qed_print_mcp_trace_results_cont(struct qed_hwfn *p_hwfn,
7618 u32 *dump_buf,
7619 char *results_buf)
7620{
7621 u32 parsed_buf_size;
7622
7623 return qed_parse_mcp_trace_dump(p_hwfn, dump_buf, results_buf,
7624 &parsed_buf_size, false);
7625}
7626
7627enum dbg_status qed_print_mcp_trace_line(struct qed_hwfn *p_hwfn,
7628 u8 *dump_buf,
7629 u32 num_dumped_bytes,
7630 char *results_buf)
7631{
7632 u32 parsed_results_bytes;
7633
7634 return qed_parse_mcp_trace_buf(p_hwfn,
7635 dump_buf,
7636 num_dumped_bytes,
7637 0,
7638 num_dumped_bytes,
7639 results_buf, &parsed_results_bytes);
7640}
7641
7642/* Frees the specified MCP Trace meta data */
7643void qed_mcp_trace_free_meta_data(struct qed_hwfn *p_hwfn)
7644{
7645 struct dbg_tools_user_data *dev_user_data;
7646 struct mcp_trace_meta *meta;
7647 u32 i;
7648
7649 dev_user_data = qed_dbg_get_user_data(p_hwfn);
7650 meta = &dev_user_data->mcp_trace_meta;
7651 if (!meta->is_allocated)
7652 return;
7653
7654 /* Release modules */
7655 if (meta->modules) {
7656 for (i = 0; i < meta->modules_num; i++)
7657 kfree(meta->modules[i]);
7658 kfree(meta->modules);
7659 }
7660
7661 /* Release formats */
7662 if (meta->formats) {
7663 for (i = 0; i < meta->formats_num; i++)
7664 kfree(meta->formats[i].format_str);
7665 kfree(meta->formats);
7666 }
7667
7668 meta->is_allocated = false;
7669}
7670
7671enum dbg_status qed_get_reg_fifo_results_buf_size(struct qed_hwfn *p_hwfn,
7672 u32 *dump_buf,
7673 u32 num_dumped_dwords,
7674 u32 *results_buf_size)
7675{
7676 return qed_parse_reg_fifo_dump(dump_buf, NULL, results_buf_size);
7677}
7678
7679enum dbg_status qed_print_reg_fifo_results(struct qed_hwfn *p_hwfn,
7680 u32 *dump_buf,
7681 u32 num_dumped_dwords,
7682 char *results_buf)
7683{
7684 u32 parsed_buf_size;
7685
7686 return qed_parse_reg_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
7687}
7688
7689enum dbg_status qed_get_igu_fifo_results_buf_size(struct qed_hwfn *p_hwfn,
7690 u32 *dump_buf,
7691 u32 num_dumped_dwords,
7692 u32 *results_buf_size)
7693{
7694 return qed_parse_igu_fifo_dump(dump_buf, NULL, results_buf_size);
7695}
7696
7697enum dbg_status qed_print_igu_fifo_results(struct qed_hwfn *p_hwfn,
7698 u32 *dump_buf,
7699 u32 num_dumped_dwords,
7700 char *results_buf)
7701{
7702 u32 parsed_buf_size;
7703
7704 return qed_parse_igu_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
7705}
7706
7707enum dbg_status
7708qed_get_protection_override_results_buf_size(struct qed_hwfn *p_hwfn,
7709 u32 *dump_buf,
7710 u32 num_dumped_dwords,
7711 u32 *results_buf_size)
7712{
7713 return qed_parse_protection_override_dump(dump_buf,
7714 NULL, results_buf_size);
7715}
7716
7717enum dbg_status qed_print_protection_override_results(struct qed_hwfn *p_hwfn,
7718 u32 *dump_buf,
7719 u32 num_dumped_dwords,
7720 char *results_buf)
7721{
7722 u32 parsed_buf_size;
7723
7724 return qed_parse_protection_override_dump(dump_buf,
7725 results_buf,
7726 &parsed_buf_size);
7727}
7728
7729enum dbg_status qed_get_fw_asserts_results_buf_size(struct qed_hwfn *p_hwfn,
7730 u32 *dump_buf,
7731 u32 num_dumped_dwords,
7732 u32 *results_buf_size)
7733{
7734 return qed_parse_fw_asserts_dump(dump_buf, NULL, results_buf_size);
7735}
7736
7737enum dbg_status qed_print_fw_asserts_results(struct qed_hwfn *p_hwfn,
7738 u32 *dump_buf,
7739 u32 num_dumped_dwords,
7740 char *results_buf)
7741{
7742 u32 parsed_buf_size;
7743
7744 return qed_parse_fw_asserts_dump(dump_buf,
7745 results_buf, &parsed_buf_size);
7746}
7747
7748enum dbg_status qed_dbg_parse_attn(struct qed_hwfn *p_hwfn,
7749 struct dbg_attn_block_result *results)
7750{
7751 const u32 *block_attn_name_offsets;
7752 const char *attn_name_base;
7753 const char *block_name;
7754 enum dbg_attn_type attn_type;
7755 u8 num_regs, i, j;
7756
7757 num_regs = GET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_NUM_REGS);
7758 attn_type = GET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_ATTN_TYPE);
7759 block_name = qed_dbg_get_block_name(p_hwfn, results->block_id);
7760 if (!block_name)
7761 return DBG_STATUS_INVALID_ARGS;
7762
7763 if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES].ptr ||
7764 !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS].ptr ||
7765 !p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr)
7766 return DBG_STATUS_DBG_ARRAY_NOT_SET;
7767
7768 block_attn_name_offsets =
7769 (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS].ptr +
7770 results->names_offset;
7771
7772 attn_name_base = p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr;
7773
7774 /* Go over registers with a non-zero attention status */
7775 for (i = 0; i < num_regs; i++) {
7776 struct dbg_attn_bit_mapping *bit_mapping;
7777 struct dbg_attn_reg_result *reg_result;
7778 u8 num_reg_attn, bit_idx = 0;
7779
7780 reg_result = &results->reg_results[i];
7781 num_reg_attn = GET_FIELD(reg_result->data,
7782 DBG_ATTN_REG_RESULT_NUM_REG_ATTN);
7783 bit_mapping = (struct dbg_attn_bit_mapping *)
7784 p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES].ptr +
7785 reg_result->block_attn_offset;
7786
7787 /* Go over attention status bits */
7788 for (j = 0; j < num_reg_attn; j++) {
7789 u16 attn_idx_val = GET_FIELD(bit_mapping[j].data,
7790 DBG_ATTN_BIT_MAPPING_VAL);
7791 const char *attn_name, *attn_type_str, *masked_str;
7792 u32 attn_name_offset;
7793 u32 sts_addr;
7794
7795 /* Check if bit mask should be advanced (due to unused
7796 * bits).
7797 */
7798 if (GET_FIELD(bit_mapping[j].data,
7799 DBG_ATTN_BIT_MAPPING_IS_UNUSED_BIT_CNT)) {
7800 bit_idx += (u8)attn_idx_val;
7801 continue;
7802 }
7803
7804 /* Check current bit index */
7805 if (reg_result->sts_val & BIT(bit_idx)) {
7806 /* An attention bit with value=1 was found
7807 * Find attention name
7808 */
7809 attn_name_offset =
7810 block_attn_name_offsets[attn_idx_val];
7811 attn_name = attn_name_base + attn_name_offset;
7812 attn_type_str =
7813 (attn_type ==
7814 ATTN_TYPE_INTERRUPT ? "Interrupt" :
7815 "Parity");
7816 masked_str = reg_result->mask_val &
7817 BIT(bit_idx) ?
7818 " [masked]" : "";
7819 sts_addr =
7820 GET_FIELD(reg_result->data,
7821 DBG_ATTN_REG_RESULT_STS_ADDRESS);
7822 DP_NOTICE(p_hwfn,
7823 "%s (%s) : %s [address 0x%08x, bit %d]%s\n",
7824 block_name, attn_type_str, attn_name,
7825 sts_addr * 4, bit_idx, masked_str);
7826 }
7827
7828 bit_idx++;
7829 }
7830 }
7831
7832 return DBG_STATUS_OK;
7833}
7834
7835/* Wrapper for unifying the idle_chk and mcp_trace api */
7836static enum dbg_status
7837qed_print_idle_chk_results_wrapper(struct qed_hwfn *p_hwfn,
7838 u32 *dump_buf,
7839 u32 num_dumped_dwords,
7840 char *results_buf)
7841{
7842 u32 num_errors, num_warnnings;
7843
7844 return qed_print_idle_chk_results(p_hwfn, dump_buf, num_dumped_dwords,
7845 results_buf, &num_errors,
7846 &num_warnnings);
7847}
7848
7849static DEFINE_MUTEX(qed_dbg_lock);
7850
7851#define MAX_PHY_RESULT_BUFFER 9000
7852
7853/******************************** Feature Meta data section ******************/
7854
7855#define GRC_NUM_STR_FUNCS 2
7856#define IDLE_CHK_NUM_STR_FUNCS 1
7857#define MCP_TRACE_NUM_STR_FUNCS 1
7858#define REG_FIFO_NUM_STR_FUNCS 1
7859#define IGU_FIFO_NUM_STR_FUNCS 1
7860#define PROTECTION_OVERRIDE_NUM_STR_FUNCS 1
7861#define FW_ASSERTS_NUM_STR_FUNCS 1
7862#define ILT_NUM_STR_FUNCS 1
7863#define PHY_NUM_STR_FUNCS 20
7864
7865/* Feature meta data lookup table */
7866static struct {
7867 char *name;
7868 u32 num_funcs;
7869 enum dbg_status (*get_size)(struct qed_hwfn *p_hwfn,
7870 struct qed_ptt *p_ptt, u32 *size);
7871 enum dbg_status (*perform_dump)(struct qed_hwfn *p_hwfn,
7872 struct qed_ptt *p_ptt, u32 *dump_buf,
7873 u32 buf_size, u32 *dumped_dwords);
7874 enum dbg_status (*print_results)(struct qed_hwfn *p_hwfn,
7875 u32 *dump_buf, u32 num_dumped_dwords,
7876 char *results_buf);
7877 enum dbg_status (*results_buf_size)(struct qed_hwfn *p_hwfn,
7878 u32 *dump_buf,
7879 u32 num_dumped_dwords,
7880 u32 *results_buf_size);
7881 const struct qed_func_lookup *hsi_func_lookup;
7882} qed_features_lookup[] = {
7883 {
7884 "grc", GRC_NUM_STR_FUNCS, qed_dbg_grc_get_dump_buf_size,
7885 qed_dbg_grc_dump, NULL, NULL, NULL}, {
7886 "idle_chk", IDLE_CHK_NUM_STR_FUNCS,
7887 qed_dbg_idle_chk_get_dump_buf_size,
7888 qed_dbg_idle_chk_dump,
7889 qed_print_idle_chk_results_wrapper,
7890 qed_get_idle_chk_results_buf_size,
7891 NULL}, {
7892 "mcp_trace", MCP_TRACE_NUM_STR_FUNCS,
7893 qed_dbg_mcp_trace_get_dump_buf_size,
7894 qed_dbg_mcp_trace_dump, qed_print_mcp_trace_results,
7895 qed_get_mcp_trace_results_buf_size,
7896 NULL}, {
7897 "reg_fifo", REG_FIFO_NUM_STR_FUNCS,
7898 qed_dbg_reg_fifo_get_dump_buf_size,
7899 qed_dbg_reg_fifo_dump, qed_print_reg_fifo_results,
7900 qed_get_reg_fifo_results_buf_size,
7901 NULL}, {
7902 "igu_fifo", IGU_FIFO_NUM_STR_FUNCS,
7903 qed_dbg_igu_fifo_get_dump_buf_size,
7904 qed_dbg_igu_fifo_dump, qed_print_igu_fifo_results,
7905 qed_get_igu_fifo_results_buf_size,
7906 NULL}, {
7907 "protection_override", PROTECTION_OVERRIDE_NUM_STR_FUNCS,
7908 qed_dbg_protection_override_get_dump_buf_size,
7909 qed_dbg_protection_override_dump,
7910 qed_print_protection_override_results,
7911 qed_get_protection_override_results_buf_size,
7912 NULL}, {
7913 "fw_asserts", FW_ASSERTS_NUM_STR_FUNCS,
7914 qed_dbg_fw_asserts_get_dump_buf_size,
7915 qed_dbg_fw_asserts_dump,
7916 qed_print_fw_asserts_results,
7917 qed_get_fw_asserts_results_buf_size,
7918 NULL}, {
7919 "ilt", ILT_NUM_STR_FUNCS, qed_dbg_ilt_get_dump_buf_size,
7920 qed_dbg_ilt_dump, NULL, NULL, NULL},};
7921
7922static void qed_dbg_print_feature(u8 *p_text_buf, u32 text_size)
7923{
7924 u32 i, precision = 80;
7925
7926 if (!p_text_buf)
7927 return;
7928
7929 pr_notice("\n%.*s", precision, p_text_buf);
7930 for (i = precision; i < text_size; i += precision)
7931 pr_cont("%.*s", precision, p_text_buf + i);
7932 pr_cont("\n");
7933}
7934
7935#define QED_RESULTS_BUF_MIN_SIZE 16
7936/* Generic function for decoding debug feature info */
7937static enum dbg_status format_feature(struct qed_hwfn *p_hwfn,
7938 enum qed_dbg_features feature_idx)
7939{
7940 struct qed_dbg_feature *feature =
7941 &p_hwfn->cdev->dbg_features[feature_idx];
7942 u32 txt_size_bytes, null_char_pos, i;
7943 u32 *dbuf, dwords;
7944 enum dbg_status rc;
7945 char *text_buf;
7946
7947 /* Check if feature supports formatting capability */
7948 if (!qed_features_lookup[feature_idx].results_buf_size)
7949 return DBG_STATUS_OK;
7950
7951 dbuf = (u32 *)feature->dump_buf;
7952 dwords = feature->dumped_dwords;
7953
7954 /* Obtain size of formatted output */
7955 rc = qed_features_lookup[feature_idx].results_buf_size(p_hwfn,
7956 dbuf,
7957 dwords,
7958 &txt_size_bytes);
7959 if (rc != DBG_STATUS_OK)
7960 return rc;
7961
7962 /* Make sure that the allocated size is a multiple of dword
7963 * (4 bytes).
7964 */
7965 null_char_pos = txt_size_bytes - 1;
7966 txt_size_bytes = (txt_size_bytes + 3) & ~0x3;
7967
7968 if (txt_size_bytes < QED_RESULTS_BUF_MIN_SIZE) {
7969 DP_NOTICE(p_hwfn->cdev,
7970 "formatted size of feature was too small %d. Aborting\n",
7971 txt_size_bytes);
7972 return DBG_STATUS_INVALID_ARGS;
7973 }
7974
7975 /* allocate temp text buf */
7976 text_buf = vzalloc(txt_size_bytes);
7977 if (!text_buf) {
7978 DP_NOTICE(p_hwfn->cdev,
7979 "failed to allocate text buffer. Aborting\n");
7980 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
7981 }
7982
7983 /* Decode feature opcodes to string on temp buf */
7984 rc = qed_features_lookup[feature_idx].print_results(p_hwfn,
7985 dbuf,
7986 dwords,
7987 text_buf);
7988 if (rc != DBG_STATUS_OK) {
7989 vfree(text_buf);
7990 return rc;
7991 }
7992
7993 /* Replace the original null character with a '\n' character.
7994 * The bytes that were added as a result of the dword alignment are also
7995 * padded with '\n' characters.
7996 */
7997 for (i = null_char_pos; i < txt_size_bytes; i++)
7998 text_buf[i] = '\n';
7999
8000 /* Dump printable feature to log */
8001 if (p_hwfn->cdev->print_dbg_data)
8002 qed_dbg_print_feature(text_buf, txt_size_bytes);
8003
8004 /* Dump binary data as is to the output file */
8005 if (p_hwfn->cdev->dbg_bin_dump) {
8006 vfree(text_buf);
8007 return rc;
8008 }
8009
8010 /* Free the old dump_buf and point the dump_buf to the newly allocated
8011 * and formatted text buffer.
8012 */
8013 vfree(feature->dump_buf);
8014 feature->dump_buf = text_buf;
8015 feature->buf_size = txt_size_bytes;
8016 feature->dumped_dwords = txt_size_bytes / 4;
8017
8018 return rc;
8019}
8020
8021#define MAX_DBG_FEATURE_SIZE_DWORDS 0x3FFFFFFF
8022
8023/* Generic function for performing the dump of a debug feature. */
8024static enum dbg_status qed_dbg_dump(struct qed_hwfn *p_hwfn,
8025 struct qed_ptt *p_ptt,
8026 enum qed_dbg_features feature_idx)
8027{
8028 struct qed_dbg_feature *feature =
8029 &p_hwfn->cdev->dbg_features[feature_idx];
8030 u32 buf_size_dwords, *dbuf, *dwords;
8031 enum dbg_status rc;
8032
8033 DP_NOTICE(p_hwfn->cdev, "Collecting a debug feature [\"%s\"]\n",
8034 qed_features_lookup[feature_idx].name);
8035
8036 /* Dump_buf was already allocated need to free (this can happen if dump
8037 * was called but file was never read).
8038 * We can't use the buffer as is since size may have changed.
8039 */
8040 if (feature->dump_buf) {
8041 vfree(feature->dump_buf);
8042 feature->dump_buf = NULL;
8043 }
8044
8045 /* Get buffer size from hsi, allocate accordingly, and perform the
8046 * dump.
8047 */
8048 rc = qed_features_lookup[feature_idx].get_size(p_hwfn, p_ptt,
8049 &buf_size_dwords);
8050 if (rc != DBG_STATUS_OK && rc != DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
8051 return rc;
8052
8053 if (buf_size_dwords > MAX_DBG_FEATURE_SIZE_DWORDS) {
8054 feature->buf_size = 0;
8055 DP_NOTICE(p_hwfn->cdev,
8056 "Debug feature [\"%s\"] size (0x%x dwords) exceeds maximum size (0x%x dwords)\n",
8057 qed_features_lookup[feature_idx].name,
8058 buf_size_dwords, MAX_DBG_FEATURE_SIZE_DWORDS);
8059
8060 return DBG_STATUS_OK;
8061 }
8062
8063 feature->buf_size = buf_size_dwords * sizeof(u32);
8064 feature->dump_buf = vmalloc(feature->buf_size);
8065 if (!feature->dump_buf)
8066 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
8067
8068 dbuf = (u32 *)feature->dump_buf;
8069 dwords = &feature->dumped_dwords;
8070 rc = qed_features_lookup[feature_idx].perform_dump(p_hwfn, p_ptt,
8071 dbuf,
8072 feature->buf_size /
8073 sizeof(u32),
8074 dwords);
8075
8076 /* If mcp is stuck we get DBG_STATUS_NVRAM_GET_IMAGE_FAILED error.
8077 * In this case the buffer holds valid binary data, but we won't able
8078 * to parse it (since parsing relies on data in NVRAM which is only
8079 * accessible when MFW is responsive). skip the formatting but return
8080 * success so that binary data is provided.
8081 */
8082 if (rc == DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
8083 return DBG_STATUS_OK;
8084
8085 if (rc != DBG_STATUS_OK)
8086 return rc;
8087
8088 /* Format output */
8089 rc = format_feature(p_hwfn, feature_idx);
8090 return rc;
8091}
8092
8093int qed_dbg_grc(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
8094{
8095 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_GRC, num_dumped_bytes);
8096}
8097
8098int qed_dbg_grc_size(struct qed_dev *cdev)
8099{
8100 return qed_dbg_feature_size(cdev, DBG_FEATURE_GRC);
8101}
8102
8103int qed_dbg_idle_chk(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
8104{
8105 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_IDLE_CHK,
8106 num_dumped_bytes);
8107}
8108
8109int qed_dbg_idle_chk_size(struct qed_dev *cdev)
8110{
8111 return qed_dbg_feature_size(cdev, DBG_FEATURE_IDLE_CHK);
8112}
8113
8114int qed_dbg_reg_fifo(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
8115{
8116 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_REG_FIFO,
8117 num_dumped_bytes);
8118}
8119
8120int qed_dbg_reg_fifo_size(struct qed_dev *cdev)
8121{
8122 return qed_dbg_feature_size(cdev, DBG_FEATURE_REG_FIFO);
8123}
8124
8125int qed_dbg_igu_fifo(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
8126{
8127 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_IGU_FIFO,
8128 num_dumped_bytes);
8129}
8130
8131int qed_dbg_igu_fifo_size(struct qed_dev *cdev)
8132{
8133 return qed_dbg_feature_size(cdev, DBG_FEATURE_IGU_FIFO);
8134}
8135
8136static int qed_dbg_nvm_image_length(struct qed_hwfn *p_hwfn,
8137 enum qed_nvm_images image_id, u32 *length)
8138{
8139 struct qed_nvm_image_att image_att;
8140 int rc;
8141
8142 *length = 0;
8143 rc = qed_mcp_get_nvm_image_att(p_hwfn, image_id, &image_att);
8144 if (rc)
8145 return rc;
8146
8147 *length = image_att.length;
8148
8149 return rc;
8150}
8151
8152static int qed_dbg_nvm_image(struct qed_dev *cdev, void *buffer,
8153 u32 *num_dumped_bytes,
8154 enum qed_nvm_images image_id)
8155{
8156 struct qed_hwfn *p_hwfn =
8157 &cdev->hwfns[cdev->engine_for_debug];
8158 u32 len_rounded;
8159 int rc;
8160
8161 *num_dumped_bytes = 0;
8162 rc = qed_dbg_nvm_image_length(p_hwfn, image_id, &len_rounded);
8163 if (rc)
8164 return rc;
8165
8166 DP_NOTICE(p_hwfn->cdev,
8167 "Collecting a debug feature [\"nvram image %d\"]\n",
8168 image_id);
8169
8170 len_rounded = roundup(len_rounded, sizeof(u32));
8171 rc = qed_mcp_get_nvm_image(p_hwfn, image_id, buffer, len_rounded);
8172 if (rc)
8173 return rc;
8174
8175 /* QED_NVM_IMAGE_NVM_META image is not swapped like other images */
8176 if (image_id != QED_NVM_IMAGE_NVM_META)
8177 cpu_to_be32_array((__force __be32 *)buffer,
8178 (const u32 *)buffer,
8179 len_rounded / sizeof(u32));
8180
8181 *num_dumped_bytes = len_rounded;
8182
8183 return rc;
8184}
8185
8186int qed_dbg_protection_override(struct qed_dev *cdev, void *buffer,
8187 u32 *num_dumped_bytes)
8188{
8189 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_PROTECTION_OVERRIDE,
8190 num_dumped_bytes);
8191}
8192
8193int qed_dbg_protection_override_size(struct qed_dev *cdev)
8194{
8195 return qed_dbg_feature_size(cdev, DBG_FEATURE_PROTECTION_OVERRIDE);
8196}
8197
8198int qed_dbg_fw_asserts(struct qed_dev *cdev, void *buffer,
8199 u32 *num_dumped_bytes)
8200{
8201 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_FW_ASSERTS,
8202 num_dumped_bytes);
8203}
8204
8205int qed_dbg_fw_asserts_size(struct qed_dev *cdev)
8206{
8207 return qed_dbg_feature_size(cdev, DBG_FEATURE_FW_ASSERTS);
8208}
8209
8210int qed_dbg_ilt(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
8211{
8212 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_ILT, num_dumped_bytes);
8213}
8214
8215int qed_dbg_ilt_size(struct qed_dev *cdev)
8216{
8217 return qed_dbg_feature_size(cdev, DBG_FEATURE_ILT);
8218}
8219
8220int qed_dbg_mcp_trace(struct qed_dev *cdev, void *buffer,
8221 u32 *num_dumped_bytes)
8222{
8223 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_MCP_TRACE,
8224 num_dumped_bytes);
8225}
8226
8227int qed_dbg_mcp_trace_size(struct qed_dev *cdev)
8228{
8229 return qed_dbg_feature_size(cdev, DBG_FEATURE_MCP_TRACE);
8230}
8231
8232/* Defines the amount of bytes allocated for recording the length of debugfs
8233 * feature buffer.
8234 */
8235#define REGDUMP_HEADER_SIZE sizeof(u32)
8236#define REGDUMP_HEADER_SIZE_SHIFT 0
8237#define REGDUMP_HEADER_SIZE_MASK 0xffffff
8238#define REGDUMP_HEADER_FEATURE_SHIFT 24
8239#define REGDUMP_HEADER_FEATURE_MASK 0x1f
8240#define REGDUMP_HEADER_BIN_DUMP_SHIFT 29
8241#define REGDUMP_HEADER_BIN_DUMP_MASK 0x1
8242#define REGDUMP_HEADER_OMIT_ENGINE_SHIFT 30
8243#define REGDUMP_HEADER_OMIT_ENGINE_MASK 0x1
8244#define REGDUMP_HEADER_ENGINE_SHIFT 31
8245#define REGDUMP_HEADER_ENGINE_MASK 0x1
8246#define REGDUMP_MAX_SIZE 0x1000000
8247#define ILT_DUMP_MAX_SIZE (1024 * 1024 * 15)
8248
8249enum debug_print_features {
8250 OLD_MODE = 0,
8251 IDLE_CHK = 1,
8252 GRC_DUMP = 2,
8253 MCP_TRACE = 3,
8254 REG_FIFO = 4,
8255 PROTECTION_OVERRIDE = 5,
8256 IGU_FIFO = 6,
8257 PHY = 7,
8258 FW_ASSERTS = 8,
8259 NVM_CFG1 = 9,
8260 DEFAULT_CFG = 10,
8261 NVM_META = 11,
8262 MDUMP = 12,
8263 ILT_DUMP = 13,
8264};
8265
8266static u32 qed_calc_regdump_header(struct qed_dev *cdev,
8267 enum debug_print_features feature,
8268 int engine, u32 feature_size,
8269 u8 omit_engine, u8 dbg_bin_dump)
8270{
8271 u32 res = 0;
8272
8273 SET_FIELD(res, REGDUMP_HEADER_SIZE, feature_size);
8274 if (res != feature_size)
8275 DP_NOTICE(cdev,
8276 "Feature %d is too large (size 0x%x) and will corrupt the dump\n",
8277 feature, feature_size);
8278
8279 SET_FIELD(res, REGDUMP_HEADER_FEATURE, feature);
8280 SET_FIELD(res, REGDUMP_HEADER_BIN_DUMP, dbg_bin_dump);
8281 SET_FIELD(res, REGDUMP_HEADER_OMIT_ENGINE, omit_engine);
8282 SET_FIELD(res, REGDUMP_HEADER_ENGINE, engine);
8283
8284 return res;
8285}
8286
8287int qed_dbg_all_data(struct qed_dev *cdev, void *buffer)
8288{
8289 u8 cur_engine, omit_engine = 0, org_engine;
8290 struct qed_hwfn *p_hwfn = &cdev->hwfns[cdev->engine_for_debug];
8291 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
8292 int grc_params[MAX_DBG_GRC_PARAMS], rc, i;
8293 u32 offset = 0, feature_size;
8294
8295 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
8296 grc_params[i] = dev_data->grc.param_val[i];
8297
8298 if (!QED_IS_CMT(cdev))
8299 omit_engine = 1;
8300
8301 cdev->dbg_bin_dump = 1;
8302 mutex_lock(&qed_dbg_lock);
8303
8304 org_engine = qed_get_debug_engine(cdev);
8305 for (cur_engine = 0; cur_engine < cdev->num_hwfns; cur_engine++) {
8306 /* Collect idle_chks and grcDump for each hw function */
8307 DP_VERBOSE(cdev, QED_MSG_DEBUG,
8308 "obtaining idle_chk and grcdump for current engine\n");
8309 qed_set_debug_engine(cdev, cur_engine);
8310
8311 /* First idle_chk */
8312 rc = qed_dbg_idle_chk(cdev, (u8 *)buffer + offset +
8313 REGDUMP_HEADER_SIZE, &feature_size);
8314 if (!rc) {
8315 *(u32 *)((u8 *)buffer + offset) =
8316 qed_calc_regdump_header(cdev, IDLE_CHK,
8317 cur_engine,
8318 feature_size,
8319 omit_engine,
8320 cdev->dbg_bin_dump);
8321 offset += (feature_size + REGDUMP_HEADER_SIZE);
8322 } else {
8323 DP_ERR(cdev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
8324 }
8325
8326 /* Second idle_chk */
8327 rc = qed_dbg_idle_chk(cdev, (u8 *)buffer + offset +
8328 REGDUMP_HEADER_SIZE, &feature_size);
8329 if (!rc) {
8330 *(u32 *)((u8 *)buffer + offset) =
8331 qed_calc_regdump_header(cdev, IDLE_CHK,
8332 cur_engine,
8333 feature_size,
8334 omit_engine,
8335 cdev->dbg_bin_dump);
8336 offset += (feature_size + REGDUMP_HEADER_SIZE);
8337 } else {
8338 DP_ERR(cdev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
8339 }
8340
8341 /* reg_fifo dump */
8342 rc = qed_dbg_reg_fifo(cdev, (u8 *)buffer + offset +
8343 REGDUMP_HEADER_SIZE, &feature_size);
8344 if (!rc) {
8345 *(u32 *)((u8 *)buffer + offset) =
8346 qed_calc_regdump_header(cdev, REG_FIFO,
8347 cur_engine,
8348 feature_size,
8349 omit_engine,
8350 cdev->dbg_bin_dump);
8351 offset += (feature_size + REGDUMP_HEADER_SIZE);
8352 } else {
8353 DP_ERR(cdev, "qed_dbg_reg_fifo failed. rc = %d\n", rc);
8354 }
8355
8356 /* igu_fifo dump */
8357 rc = qed_dbg_igu_fifo(cdev, (u8 *)buffer + offset +
8358 REGDUMP_HEADER_SIZE, &feature_size);
8359 if (!rc) {
8360 *(u32 *)((u8 *)buffer + offset) =
8361 qed_calc_regdump_header(cdev, IGU_FIFO,
8362 cur_engine,
8363 feature_size,
8364 omit_engine,
8365 cdev->dbg_bin_dump);
8366 offset += (feature_size + REGDUMP_HEADER_SIZE);
8367 } else {
8368 DP_ERR(cdev, "qed_dbg_igu_fifo failed. rc = %d", rc);
8369 }
8370
8371 /* protection_override dump */
8372 rc = qed_dbg_protection_override(cdev, (u8 *)buffer + offset +
8373 REGDUMP_HEADER_SIZE,
8374 &feature_size);
8375 if (!rc) {
8376 *(u32 *)((u8 *)buffer + offset) =
8377 qed_calc_regdump_header(cdev,
8378 PROTECTION_OVERRIDE,
8379 cur_engine,
8380 feature_size,
8381 omit_engine,
8382 cdev->dbg_bin_dump);
8383 offset += (feature_size + REGDUMP_HEADER_SIZE);
8384 } else {
8385 DP_ERR(cdev,
8386 "qed_dbg_protection_override failed. rc = %d\n",
8387 rc);
8388 }
8389
8390 /* fw_asserts dump */
8391 rc = qed_dbg_fw_asserts(cdev, (u8 *)buffer + offset +
8392 REGDUMP_HEADER_SIZE, &feature_size);
8393 if (!rc) {
8394 *(u32 *)((u8 *)buffer + offset) =
8395 qed_calc_regdump_header(cdev, FW_ASSERTS,
8396 cur_engine,
8397 feature_size,
8398 omit_engine,
8399 cdev->dbg_bin_dump);
8400 offset += (feature_size + REGDUMP_HEADER_SIZE);
8401 } else {
8402 DP_ERR(cdev, "qed_dbg_fw_asserts failed. rc = %d\n",
8403 rc);
8404 }
8405
8406 feature_size = qed_dbg_ilt_size(cdev);
8407 if (!cdev->disable_ilt_dump && feature_size <
8408 ILT_DUMP_MAX_SIZE) {
8409 rc = qed_dbg_ilt(cdev, (u8 *)buffer + offset +
8410 REGDUMP_HEADER_SIZE, &feature_size);
8411 if (!rc) {
8412 *(u32 *)((u8 *)buffer + offset) =
8413 qed_calc_regdump_header(cdev, ILT_DUMP,
8414 cur_engine,
8415 feature_size,
8416 omit_engine,
8417 cdev->dbg_bin_dump);
8418 offset += (feature_size + REGDUMP_HEADER_SIZE);
8419 } else {
8420 DP_ERR(cdev, "qed_dbg_ilt failed. rc = %d\n",
8421 rc);
8422 }
8423 }
8424
8425 /* Grc dump - must be last because when mcp stuck it will
8426 * clutter idle_chk, reg_fifo, ...
8427 */
8428 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
8429 dev_data->grc.param_val[i] = grc_params[i];
8430
8431 rc = qed_dbg_grc(cdev, (u8 *)buffer + offset +
8432 REGDUMP_HEADER_SIZE, &feature_size);
8433 if (!rc) {
8434 *(u32 *)((u8 *)buffer + offset) =
8435 qed_calc_regdump_header(cdev, GRC_DUMP,
8436 cur_engine,
8437 feature_size,
8438 omit_engine,
8439 cdev->dbg_bin_dump);
8440 offset += (feature_size + REGDUMP_HEADER_SIZE);
8441 } else {
8442 DP_ERR(cdev, "qed_dbg_grc failed. rc = %d", rc);
8443 }
8444 }
8445
8446 qed_set_debug_engine(cdev, org_engine);
8447
8448 /* mcp_trace */
8449 rc = qed_dbg_mcp_trace(cdev, (u8 *)buffer + offset +
8450 REGDUMP_HEADER_SIZE, &feature_size);
8451 if (!rc) {
8452 *(u32 *)((u8 *)buffer + offset) =
8453 qed_calc_regdump_header(cdev, MCP_TRACE, cur_engine,
8454 feature_size, omit_engine,
8455 cdev->dbg_bin_dump);
8456 offset += (feature_size + REGDUMP_HEADER_SIZE);
8457 } else {
8458 DP_ERR(cdev, "qed_dbg_mcp_trace failed. rc = %d\n", rc);
8459 }
8460
8461 /* nvm cfg1 */
8462 rc = qed_dbg_nvm_image(cdev,
8463 (u8 *)buffer + offset +
8464 REGDUMP_HEADER_SIZE, &feature_size,
8465 QED_NVM_IMAGE_NVM_CFG1);
8466 if (!rc) {
8467 *(u32 *)((u8 *)buffer + offset) =
8468 qed_calc_regdump_header(cdev, NVM_CFG1, cur_engine,
8469 feature_size, omit_engine,
8470 cdev->dbg_bin_dump);
8471 offset += (feature_size + REGDUMP_HEADER_SIZE);
8472 } else if (rc != -ENOENT) {
8473 DP_ERR(cdev,
8474 "qed_dbg_nvm_image failed for image %d (%s), rc = %d\n",
8475 QED_NVM_IMAGE_NVM_CFG1, "QED_NVM_IMAGE_NVM_CFG1",
8476 rc);
8477 }
8478
8479 /* nvm default */
8480 rc = qed_dbg_nvm_image(cdev,
8481 (u8 *)buffer + offset +
8482 REGDUMP_HEADER_SIZE, &feature_size,
8483 QED_NVM_IMAGE_DEFAULT_CFG);
8484 if (!rc) {
8485 *(u32 *)((u8 *)buffer + offset) =
8486 qed_calc_regdump_header(cdev, DEFAULT_CFG,
8487 cur_engine, feature_size,
8488 omit_engine,
8489 cdev->dbg_bin_dump);
8490 offset += (feature_size + REGDUMP_HEADER_SIZE);
8491 } else if (rc != -ENOENT) {
8492 DP_ERR(cdev,
8493 "qed_dbg_nvm_image failed for image %d (%s), rc = %d\n",
8494 QED_NVM_IMAGE_DEFAULT_CFG,
8495 "QED_NVM_IMAGE_DEFAULT_CFG", rc);
8496 }
8497
8498 /* nvm meta */
8499 rc = qed_dbg_nvm_image(cdev,
8500 (u8 *)buffer + offset +
8501 REGDUMP_HEADER_SIZE, &feature_size,
8502 QED_NVM_IMAGE_NVM_META);
8503 if (!rc) {
8504 *(u32 *)((u8 *)buffer + offset) =
8505 qed_calc_regdump_header(cdev, NVM_META, cur_engine,
8506 feature_size, omit_engine,
8507 cdev->dbg_bin_dump);
8508 offset += (feature_size + REGDUMP_HEADER_SIZE);
8509 } else if (rc != -ENOENT) {
8510 DP_ERR(cdev,
8511 "qed_dbg_nvm_image failed for image %d (%s), rc = %d\n",
8512 QED_NVM_IMAGE_NVM_META, "QED_NVM_IMAGE_NVM_META",
8513 rc);
8514 }
8515
8516 /* nvm mdump */
8517 rc = qed_dbg_nvm_image(cdev, (u8 *)buffer + offset +
8518 REGDUMP_HEADER_SIZE, &feature_size,
8519 QED_NVM_IMAGE_MDUMP);
8520 if (!rc) {
8521 *(u32 *)((u8 *)buffer + offset) =
8522 qed_calc_regdump_header(cdev, MDUMP, cur_engine,
8523 feature_size, omit_engine,
8524 cdev->dbg_bin_dump);
8525 offset += (feature_size + REGDUMP_HEADER_SIZE);
8526 } else if (rc != -ENOENT) {
8527 DP_ERR(cdev,
8528 "qed_dbg_nvm_image failed for image %d (%s), rc = %d\n",
8529 QED_NVM_IMAGE_MDUMP, "QED_NVM_IMAGE_MDUMP", rc);
8530 }
8531
8532 mutex_unlock(&qed_dbg_lock);
8533 cdev->dbg_bin_dump = 0;
8534
8535 return 0;
8536}
8537
8538int qed_dbg_all_data_size(struct qed_dev *cdev)
8539{
8540 u32 regs_len = 0, image_len = 0, ilt_len = 0, total_ilt_len = 0;
8541 struct qed_hwfn *p_hwfn = &cdev->hwfns[cdev->engine_for_debug];
8542 u8 cur_engine, org_engine;
8543
8544 cdev->disable_ilt_dump = false;
8545 org_engine = qed_get_debug_engine(cdev);
8546 for (cur_engine = 0; cur_engine < cdev->num_hwfns; cur_engine++) {
8547 /* Engine specific */
8548 DP_VERBOSE(cdev, QED_MSG_DEBUG,
8549 "calculating idle_chk and grcdump register length for current engine\n");
8550 qed_set_debug_engine(cdev, cur_engine);
8551 regs_len += REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(cdev) +
8552 REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(cdev) +
8553 REGDUMP_HEADER_SIZE + qed_dbg_grc_size(cdev) +
8554 REGDUMP_HEADER_SIZE + qed_dbg_reg_fifo_size(cdev) +
8555 REGDUMP_HEADER_SIZE + qed_dbg_igu_fifo_size(cdev) +
8556 REGDUMP_HEADER_SIZE +
8557 qed_dbg_protection_override_size(cdev) +
8558 REGDUMP_HEADER_SIZE + qed_dbg_fw_asserts_size(cdev);
8559 ilt_len = REGDUMP_HEADER_SIZE + qed_dbg_ilt_size(cdev);
8560 if (ilt_len < ILT_DUMP_MAX_SIZE) {
8561 total_ilt_len += ilt_len;
8562 regs_len += ilt_len;
8563 }
8564 }
8565
8566 qed_set_debug_engine(cdev, org_engine);
8567
8568 /* Engine common */
8569 regs_len += REGDUMP_HEADER_SIZE + qed_dbg_mcp_trace_size(cdev) +
8570 REGDUMP_HEADER_SIZE + qed_dbg_phy_size(cdev);
8571 qed_dbg_nvm_image_length(p_hwfn, QED_NVM_IMAGE_NVM_CFG1, &image_len);
8572 if (image_len)
8573 regs_len += REGDUMP_HEADER_SIZE + image_len;
8574 qed_dbg_nvm_image_length(p_hwfn, QED_NVM_IMAGE_DEFAULT_CFG, &image_len);
8575 if (image_len)
8576 regs_len += REGDUMP_HEADER_SIZE + image_len;
8577 qed_dbg_nvm_image_length(p_hwfn, QED_NVM_IMAGE_NVM_META, &image_len);
8578 if (image_len)
8579 regs_len += REGDUMP_HEADER_SIZE + image_len;
8580 qed_dbg_nvm_image_length(p_hwfn, QED_NVM_IMAGE_MDUMP, &image_len);
8581 if (image_len)
8582 regs_len += REGDUMP_HEADER_SIZE + image_len;
8583
8584 if (regs_len > REGDUMP_MAX_SIZE) {
8585 DP_VERBOSE(cdev, QED_MSG_DEBUG,
8586 "Dump exceeds max size 0x%x, disable ILT dump\n",
8587 REGDUMP_MAX_SIZE);
8588 cdev->disable_ilt_dump = true;
8589 regs_len -= total_ilt_len;
8590 }
8591
8592 return regs_len;
8593}
8594
8595int qed_dbg_feature(struct qed_dev *cdev, void *buffer,
8596 enum qed_dbg_features feature, u32 *num_dumped_bytes)
8597{
8598 struct qed_dbg_feature *qed_feature = &cdev->dbg_features[feature];
8599 struct qed_hwfn *p_hwfn = &cdev->hwfns[cdev->engine_for_debug];
8600 enum dbg_status dbg_rc;
8601 struct qed_ptt *p_ptt;
8602 int rc = 0;
8603
8604 /* Acquire ptt */
8605 p_ptt = qed_ptt_acquire(p_hwfn);
8606 if (!p_ptt)
8607 return -EINVAL;
8608
8609 /* Get dump */
8610 dbg_rc = qed_dbg_dump(p_hwfn, p_ptt, feature);
8611 if (dbg_rc != DBG_STATUS_OK) {
8612 DP_VERBOSE(cdev, QED_MSG_DEBUG, "%s\n",
8613 qed_dbg_get_status_str(dbg_rc));
8614 *num_dumped_bytes = 0;
8615 rc = -EINVAL;
8616 goto out;
8617 }
8618
8619 DP_VERBOSE(cdev, QED_MSG_DEBUG,
8620 "copying debugfs feature to external buffer\n");
8621 memcpy(buffer, qed_feature->dump_buf, qed_feature->buf_size);
8622 *num_dumped_bytes = cdev->dbg_features[feature].dumped_dwords *
8623 4;
8624
8625out:
8626 qed_ptt_release(p_hwfn, p_ptt);
8627 return rc;
8628}
8629
8630int qed_dbg_feature_size(struct qed_dev *cdev, enum qed_dbg_features feature)
8631{
8632 struct qed_dbg_feature *qed_feature = &cdev->dbg_features[feature];
8633 struct qed_hwfn *p_hwfn = &cdev->hwfns[cdev->engine_for_debug];
8634 struct qed_ptt *p_ptt = qed_ptt_acquire(p_hwfn);
8635 u32 buf_size_dwords;
8636 enum dbg_status rc;
8637
8638 if (!p_ptt)
8639 return -EINVAL;
8640
8641 rc = qed_features_lookup[feature].get_size(p_hwfn, p_ptt,
8642 &buf_size_dwords);
8643 if (rc != DBG_STATUS_OK)
8644 buf_size_dwords = 0;
8645
8646 /* Feature will not be dumped if it exceeds maximum size */
8647 if (buf_size_dwords > MAX_DBG_FEATURE_SIZE_DWORDS)
8648 buf_size_dwords = 0;
8649
8650 qed_ptt_release(p_hwfn, p_ptt);
8651 qed_feature->buf_size = buf_size_dwords * sizeof(u32);
8652 return qed_feature->buf_size;
8653}
8654
8655int qed_dbg_phy_size(struct qed_dev *cdev)
8656{
8657 /* return max size of phy info and
8658 * phy mac_stat multiplied by the number of ports
8659 */
8660 return MAX_PHY_RESULT_BUFFER * (1 + qed_device_num_ports(cdev));
8661}
8662
8663u8 qed_get_debug_engine(struct qed_dev *cdev)
8664{
8665 return cdev->engine_for_debug;
8666}
8667
8668void qed_set_debug_engine(struct qed_dev *cdev, int engine_number)
8669{
8670 DP_VERBOSE(cdev, QED_MSG_DEBUG, "set debug engine to %d\n",
8671 engine_number);
8672 cdev->engine_for_debug = engine_number;
8673}
8674
8675void qed_dbg_pf_init(struct qed_dev *cdev)
8676{
8677 const u8 *dbg_values = NULL;
8678 int i;
8679
8680 /* Sync ver with debugbus qed code */
8681 qed_dbg_set_app_ver(TOOLS_VERSION);
8682
8683 /* Debug values are after init values.
8684 * The offset is the first dword of the file.
8685 */
8686 dbg_values = cdev->firmware->data + *(u32 *)cdev->firmware->data;
8687
8688 for_each_hwfn(cdev, i) {
8689 qed_dbg_set_bin_ptr(&cdev->hwfns[i], dbg_values);
8690 qed_dbg_user_set_bin_ptr(&cdev->hwfns[i], dbg_values);
8691 }
8692
8693 /* Set the hwfn to be 0 as default */
8694 cdev->engine_for_debug = 0;
8695}
8696
8697void qed_dbg_pf_exit(struct qed_dev *cdev)
8698{
8699 struct qed_dbg_feature *feature = NULL;
8700 enum qed_dbg_features feature_idx;
8701
8702 /* debug features' buffers may be allocated if debug feature was used
8703 * but dump wasn't called
8704 */
8705 for (feature_idx = 0; feature_idx < DBG_FEATURE_NUM; feature_idx++) {
8706 feature = &cdev->dbg_features[feature_idx];
8707 if (feature->dump_buf) {
8708 vfree(feature->dump_buf);
8709 feature->dump_buf = NULL;
8710 }
8711 }
8712}
1/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#include <linux/module.h>
10#include <linux/vmalloc.h>
11#include <linux/crc32.h>
12#include "qed.h"
13#include "qed_hsi.h"
14#include "qed_hw.h"
15#include "qed_mcp.h"
16#include "qed_reg_addr.h"
17
18/* Memory groups enum */
19enum mem_groups {
20 MEM_GROUP_PXP_MEM,
21 MEM_GROUP_DMAE_MEM,
22 MEM_GROUP_CM_MEM,
23 MEM_GROUP_QM_MEM,
24 MEM_GROUP_DORQ_MEM,
25 MEM_GROUP_BRB_RAM,
26 MEM_GROUP_BRB_MEM,
27 MEM_GROUP_PRS_MEM,
28 MEM_GROUP_IOR,
29 MEM_GROUP_BTB_RAM,
30 MEM_GROUP_CONN_CFC_MEM,
31 MEM_GROUP_TASK_CFC_MEM,
32 MEM_GROUP_CAU_PI,
33 MEM_GROUP_CAU_MEM,
34 MEM_GROUP_PXP_ILT,
35 MEM_GROUP_TM_MEM,
36 MEM_GROUP_SDM_MEM,
37 MEM_GROUP_PBUF,
38 MEM_GROUP_RAM,
39 MEM_GROUP_MULD_MEM,
40 MEM_GROUP_BTB_MEM,
41 MEM_GROUP_RDIF_CTX,
42 MEM_GROUP_TDIF_CTX,
43 MEM_GROUP_CFC_MEM,
44 MEM_GROUP_IGU_MEM,
45 MEM_GROUP_IGU_MSIX,
46 MEM_GROUP_CAU_SB,
47 MEM_GROUP_BMB_RAM,
48 MEM_GROUP_BMB_MEM,
49 MEM_GROUPS_NUM
50};
51
52/* Memory groups names */
53static const char * const s_mem_group_names[] = {
54 "PXP_MEM",
55 "DMAE_MEM",
56 "CM_MEM",
57 "QM_MEM",
58 "DORQ_MEM",
59 "BRB_RAM",
60 "BRB_MEM",
61 "PRS_MEM",
62 "IOR",
63 "BTB_RAM",
64 "CONN_CFC_MEM",
65 "TASK_CFC_MEM",
66 "CAU_PI",
67 "CAU_MEM",
68 "PXP_ILT",
69 "TM_MEM",
70 "SDM_MEM",
71 "PBUF",
72 "RAM",
73 "MULD_MEM",
74 "BTB_MEM",
75 "RDIF_CTX",
76 "TDIF_CTX",
77 "CFC_MEM",
78 "IGU_MEM",
79 "IGU_MSIX",
80 "CAU_SB",
81 "BMB_RAM",
82 "BMB_MEM",
83};
84
85/* Idle check conditions */
86
87static u32 cond5(const u32 *r, const u32 *imm)
88{
89 return ((r[0] & imm[0]) != imm[1]) && ((r[1] & imm[2]) != imm[3]);
90}
91
92static u32 cond7(const u32 *r, const u32 *imm)
93{
94 return ((r[0] >> imm[0]) & imm[1]) != imm[2];
95}
96
97static u32 cond6(const u32 *r, const u32 *imm)
98{
99 return (r[0] & imm[0]) != imm[1];
100}
101
102static u32 cond9(const u32 *r, const u32 *imm)
103{
104 return ((r[0] & imm[0]) >> imm[1]) !=
105 (((r[0] & imm[2]) >> imm[3]) | ((r[1] & imm[4]) << imm[5]));
106}
107
108static u32 cond10(const u32 *r, const u32 *imm)
109{
110 return ((r[0] & imm[0]) >> imm[1]) != (r[0] & imm[2]);
111}
112
113static u32 cond4(const u32 *r, const u32 *imm)
114{
115 return (r[0] & ~imm[0]) != imm[1];
116}
117
118static u32 cond0(const u32 *r, const u32 *imm)
119{
120 return (r[0] & ~r[1]) != imm[0];
121}
122
123static u32 cond1(const u32 *r, const u32 *imm)
124{
125 return r[0] != imm[0];
126}
127
128static u32 cond11(const u32 *r, const u32 *imm)
129{
130 return r[0] != r[1] && r[2] == imm[0];
131}
132
133static u32 cond12(const u32 *r, const u32 *imm)
134{
135 return r[0] != r[1] && r[2] > imm[0];
136}
137
138static u32 cond3(const u32 *r, const u32 *imm)
139{
140 return r[0] != r[1];
141}
142
143static u32 cond13(const u32 *r, const u32 *imm)
144{
145 return r[0] & imm[0];
146}
147
148static u32 cond8(const u32 *r, const u32 *imm)
149{
150 return r[0] < (r[1] - imm[0]);
151}
152
153static u32 cond2(const u32 *r, const u32 *imm)
154{
155 return r[0] > imm[0];
156}
157
158/* Array of Idle Check conditions */
159static u32(*cond_arr[]) (const u32 *r, const u32 *imm) = {
160 cond0,
161 cond1,
162 cond2,
163 cond3,
164 cond4,
165 cond5,
166 cond6,
167 cond7,
168 cond8,
169 cond9,
170 cond10,
171 cond11,
172 cond12,
173 cond13,
174};
175
176/******************************* Data Types **********************************/
177
178enum platform_ids {
179 PLATFORM_ASIC,
180 PLATFORM_RESERVED,
181 PLATFORM_RESERVED2,
182 PLATFORM_RESERVED3,
183 MAX_PLATFORM_IDS
184};
185
186struct chip_platform_defs {
187 u8 num_ports;
188 u8 num_pfs;
189 u8 num_vfs;
190};
191
192/* Chip constant definitions */
193struct chip_defs {
194 const char *name;
195 struct chip_platform_defs per_platform[MAX_PLATFORM_IDS];
196};
197
198/* Platform constant definitions */
199struct platform_defs {
200 const char *name;
201 u32 delay_factor;
202 u32 dmae_thresh;
203 u32 log_thresh;
204};
205
206/* Storm constant definitions.
207 * Addresses are in bytes, sizes are in quad-regs.
208 */
209struct storm_defs {
210 char letter;
211 enum block_id block_id;
212 enum dbg_bus_clients dbg_client_id[MAX_CHIP_IDS];
213 bool has_vfc;
214 u32 sem_fast_mem_addr;
215 u32 sem_frame_mode_addr;
216 u32 sem_slow_enable_addr;
217 u32 sem_slow_mode_addr;
218 u32 sem_slow_mode1_conf_addr;
219 u32 sem_sync_dbg_empty_addr;
220 u32 sem_slow_dbg_empty_addr;
221 u32 cm_ctx_wr_addr;
222 u32 cm_conn_ag_ctx_lid_size;
223 u32 cm_conn_ag_ctx_rd_addr;
224 u32 cm_conn_st_ctx_lid_size;
225 u32 cm_conn_st_ctx_rd_addr;
226 u32 cm_task_ag_ctx_lid_size;
227 u32 cm_task_ag_ctx_rd_addr;
228 u32 cm_task_st_ctx_lid_size;
229 u32 cm_task_st_ctx_rd_addr;
230};
231
232/* Block constant definitions */
233struct block_defs {
234 const char *name;
235 bool exists[MAX_CHIP_IDS];
236 bool associated_to_storm;
237
238 /* Valid only if associated_to_storm is true */
239 u32 storm_id;
240 enum dbg_bus_clients dbg_client_id[MAX_CHIP_IDS];
241 u32 dbg_select_addr;
242 u32 dbg_enable_addr;
243 u32 dbg_shift_addr;
244 u32 dbg_force_valid_addr;
245 u32 dbg_force_frame_addr;
246 bool has_reset_bit;
247
248 /* If true, block is taken out of reset before dump */
249 bool unreset;
250 enum dbg_reset_regs reset_reg;
251
252 /* Bit offset in reset register */
253 u8 reset_bit_offset;
254};
255
256/* Reset register definitions */
257struct reset_reg_defs {
258 u32 addr;
259 bool exists[MAX_CHIP_IDS];
260 u32 unreset_val[MAX_CHIP_IDS];
261};
262
263struct grc_param_defs {
264 u32 default_val[MAX_CHIP_IDS];
265 u32 min;
266 u32 max;
267 bool is_preset;
268 bool is_persistent;
269 u32 exclude_all_preset_val;
270 u32 crash_preset_val;
271};
272
273/* Address is in 128b units. Width is in bits. */
274struct rss_mem_defs {
275 const char *mem_name;
276 const char *type_name;
277 u32 addr;
278 u32 entry_width;
279 u32 num_entries[MAX_CHIP_IDS];
280};
281
282struct vfc_ram_defs {
283 const char *mem_name;
284 const char *type_name;
285 u32 base_row;
286 u32 num_rows;
287};
288
289struct big_ram_defs {
290 const char *instance_name;
291 enum mem_groups mem_group_id;
292 enum mem_groups ram_mem_group_id;
293 enum dbg_grc_params grc_param;
294 u32 addr_reg_addr;
295 u32 data_reg_addr;
296 u32 is_256b_reg_addr;
297 u32 is_256b_bit_offset[MAX_CHIP_IDS];
298 u32 ram_size[MAX_CHIP_IDS]; /* In dwords */
299};
300
301struct phy_defs {
302 const char *phy_name;
303
304 /* PHY base GRC address */
305 u32 base_addr;
306
307 /* Relative address of indirect TBUS address register (bits 0..7) */
308 u32 tbus_addr_lo_addr;
309
310 /* Relative address of indirect TBUS address register (bits 8..10) */
311 u32 tbus_addr_hi_addr;
312
313 /* Relative address of indirect TBUS data register (bits 0..7) */
314 u32 tbus_data_lo_addr;
315
316 /* Relative address of indirect TBUS data register (bits 8..11) */
317 u32 tbus_data_hi_addr;
318};
319
320/******************************** Constants **********************************/
321
322#define MAX_LCIDS 320
323#define MAX_LTIDS 320
324
325#define NUM_IOR_SETS 2
326#define IORS_PER_SET 176
327#define IOR_SET_OFFSET(set_id) ((set_id) * 256)
328
329#define BYTES_IN_DWORD sizeof(u32)
330
331/* In the macros below, size and offset are specified in bits */
332#define CEIL_DWORDS(size) DIV_ROUND_UP(size, 32)
333#define FIELD_BIT_OFFSET(type, field) type ## _ ## field ## _ ## OFFSET
334#define FIELD_BIT_SIZE(type, field) type ## _ ## field ## _ ## SIZE
335#define FIELD_DWORD_OFFSET(type, field) \
336 (int)(FIELD_BIT_OFFSET(type, field) / 32)
337#define FIELD_DWORD_SHIFT(type, field) (FIELD_BIT_OFFSET(type, field) % 32)
338#define FIELD_BIT_MASK(type, field) \
339 (((1 << FIELD_BIT_SIZE(type, field)) - 1) << \
340 FIELD_DWORD_SHIFT(type, field))
341
342#define SET_VAR_FIELD(var, type, field, val) \
343 do { \
344 var[FIELD_DWORD_OFFSET(type, field)] &= \
345 (~FIELD_BIT_MASK(type, field)); \
346 var[FIELD_DWORD_OFFSET(type, field)] |= \
347 (val) << FIELD_DWORD_SHIFT(type, field); \
348 } while (0)
349
350#define ARR_REG_WR(dev, ptt, addr, arr, arr_size) \
351 do { \
352 for (i = 0; i < (arr_size); i++) \
353 qed_wr(dev, ptt, addr, (arr)[i]); \
354 } while (0)
355
356#define ARR_REG_RD(dev, ptt, addr, arr, arr_size) \
357 do { \
358 for (i = 0; i < (arr_size); i++) \
359 (arr)[i] = qed_rd(dev, ptt, addr); \
360 } while (0)
361
362#define DWORDS_TO_BYTES(dwords) ((dwords) * BYTES_IN_DWORD)
363#define BYTES_TO_DWORDS(bytes) ((bytes) / BYTES_IN_DWORD)
364
365/* Extra lines include a signature line + optional latency events line */
366#define NUM_EXTRA_DBG_LINES(block_desc) \
367 (1 + ((block_desc)->has_latency_events ? 1 : 0))
368#define NUM_DBG_LINES(block_desc) \
369 ((block_desc)->num_of_lines + NUM_EXTRA_DBG_LINES(block_desc))
370
371#define RAM_LINES_TO_DWORDS(lines) ((lines) * 2)
372#define RAM_LINES_TO_BYTES(lines) \
373 DWORDS_TO_BYTES(RAM_LINES_TO_DWORDS(lines))
374
375#define REG_DUMP_LEN_SHIFT 24
376#define MEM_DUMP_ENTRY_SIZE_DWORDS \
377 BYTES_TO_DWORDS(sizeof(struct dbg_dump_mem))
378
379#define IDLE_CHK_RULE_SIZE_DWORDS \
380 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_rule))
381
382#define IDLE_CHK_RESULT_HDR_DWORDS \
383 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_hdr))
384
385#define IDLE_CHK_RESULT_REG_HDR_DWORDS \
386 BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_reg_hdr))
387
388#define IDLE_CHK_MAX_ENTRIES_SIZE 32
389
390/* The sizes and offsets below are specified in bits */
391#define VFC_CAM_CMD_STRUCT_SIZE 64
392#define VFC_CAM_CMD_ROW_OFFSET 48
393#define VFC_CAM_CMD_ROW_SIZE 9
394#define VFC_CAM_ADDR_STRUCT_SIZE 16
395#define VFC_CAM_ADDR_OP_OFFSET 0
396#define VFC_CAM_ADDR_OP_SIZE 4
397#define VFC_CAM_RESP_STRUCT_SIZE 256
398#define VFC_RAM_ADDR_STRUCT_SIZE 16
399#define VFC_RAM_ADDR_OP_OFFSET 0
400#define VFC_RAM_ADDR_OP_SIZE 2
401#define VFC_RAM_ADDR_ROW_OFFSET 2
402#define VFC_RAM_ADDR_ROW_SIZE 10
403#define VFC_RAM_RESP_STRUCT_SIZE 256
404
405#define VFC_CAM_CMD_DWORDS CEIL_DWORDS(VFC_CAM_CMD_STRUCT_SIZE)
406#define VFC_CAM_ADDR_DWORDS CEIL_DWORDS(VFC_CAM_ADDR_STRUCT_SIZE)
407#define VFC_CAM_RESP_DWORDS CEIL_DWORDS(VFC_CAM_RESP_STRUCT_SIZE)
408#define VFC_RAM_CMD_DWORDS VFC_CAM_CMD_DWORDS
409#define VFC_RAM_ADDR_DWORDS CEIL_DWORDS(VFC_RAM_ADDR_STRUCT_SIZE)
410#define VFC_RAM_RESP_DWORDS CEIL_DWORDS(VFC_RAM_RESP_STRUCT_SIZE)
411
412#define NUM_VFC_RAM_TYPES 4
413
414#define VFC_CAM_NUM_ROWS 512
415
416#define VFC_OPCODE_CAM_RD 14
417#define VFC_OPCODE_RAM_RD 0
418
419#define NUM_RSS_MEM_TYPES 5
420
421#define NUM_BIG_RAM_TYPES 3
422
423#define NUM_PHY_TBUS_ADDRESSES 2048
424#define PHY_DUMP_SIZE_DWORDS (NUM_PHY_TBUS_ADDRESSES / 2)
425
426#define RESET_REG_UNRESET_OFFSET 4
427
428#define STALL_DELAY_MS 500
429
430#define STATIC_DEBUG_LINE_DWORDS 9
431
432#define NUM_COMMON_GLOBAL_PARAMS 8
433
434#define FW_IMG_MAIN 1
435
436#define REG_FIFO_ELEMENT_DWORDS 2
437#define REG_FIFO_DEPTH_ELEMENTS 32
438#define REG_FIFO_DEPTH_DWORDS \
439 (REG_FIFO_ELEMENT_DWORDS * REG_FIFO_DEPTH_ELEMENTS)
440
441#define IGU_FIFO_ELEMENT_DWORDS 4
442#define IGU_FIFO_DEPTH_ELEMENTS 64
443#define IGU_FIFO_DEPTH_DWORDS \
444 (IGU_FIFO_ELEMENT_DWORDS * IGU_FIFO_DEPTH_ELEMENTS)
445
446#define PROTECTION_OVERRIDE_ELEMENT_DWORDS 2
447#define PROTECTION_OVERRIDE_DEPTH_ELEMENTS 20
448#define PROTECTION_OVERRIDE_DEPTH_DWORDS \
449 (PROTECTION_OVERRIDE_DEPTH_ELEMENTS * \
450 PROTECTION_OVERRIDE_ELEMENT_DWORDS)
451
452#define MCP_SPAD_TRACE_OFFSIZE_ADDR \
453 (MCP_REG_SCRATCH + \
454 offsetof(struct static_init, sections[SPAD_SECTION_TRACE]))
455
456#define EMPTY_FW_VERSION_STR "???_???_???_???"
457#define EMPTY_FW_IMAGE_STR "???????????????"
458
459/***************************** Constant Arrays *******************************/
460
461struct dbg_array {
462 const u32 *ptr;
463 u32 size_in_dwords;
464};
465
466/* Debug arrays */
467static struct dbg_array s_dbg_arrays[MAX_BIN_DBG_BUFFER_TYPE] = { {NULL} };
468
469/* Chip constant definitions array */
470static struct chip_defs s_chip_defs[MAX_CHIP_IDS] = {
471 { "bb",
472 {{MAX_NUM_PORTS_BB, MAX_NUM_PFS_BB, MAX_NUM_VFS_BB},
473 {0, 0, 0},
474 {0, 0, 0},
475 {0, 0, 0} } },
476 { "ah",
477 {{MAX_NUM_PORTS_K2, MAX_NUM_PFS_K2, MAX_NUM_VFS_K2},
478 {0, 0, 0},
479 {0, 0, 0},
480 {0, 0, 0} } },
481 { "reserved",
482 {{0, 0, 0},
483 {0, 0, 0},
484 {0, 0, 0},
485 {0, 0, 0} } }
486};
487
488/* Storm constant definitions array */
489static struct storm_defs s_storm_defs[] = {
490 /* Tstorm */
491 {'T', BLOCK_TSEM,
492 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT,
493 DBG_BUS_CLIENT_RBCT}, true,
494 TSEM_REG_FAST_MEMORY,
495 TSEM_REG_DBG_FRAME_MODE_BB_K2, TSEM_REG_SLOW_DBG_ACTIVE_BB_K2,
496 TSEM_REG_SLOW_DBG_MODE_BB_K2, TSEM_REG_DBG_MODE1_CFG_BB_K2,
497 TSEM_REG_SYNC_DBG_EMPTY, TSEM_REG_SLOW_DBG_EMPTY_BB_K2,
498 TCM_REG_CTX_RBC_ACCS,
499 4, TCM_REG_AGG_CON_CTX,
500 16, TCM_REG_SM_CON_CTX,
501 2, TCM_REG_AGG_TASK_CTX,
502 4, TCM_REG_SM_TASK_CTX},
503
504 /* Mstorm */
505 {'M', BLOCK_MSEM,
506 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM,
507 DBG_BUS_CLIENT_RBCM}, false,
508 MSEM_REG_FAST_MEMORY,
509 MSEM_REG_DBG_FRAME_MODE_BB_K2, MSEM_REG_SLOW_DBG_ACTIVE_BB_K2,
510 MSEM_REG_SLOW_DBG_MODE_BB_K2, MSEM_REG_DBG_MODE1_CFG_BB_K2,
511 MSEM_REG_SYNC_DBG_EMPTY, MSEM_REG_SLOW_DBG_EMPTY_BB_K2,
512 MCM_REG_CTX_RBC_ACCS,
513 1, MCM_REG_AGG_CON_CTX,
514 10, MCM_REG_SM_CON_CTX,
515 2, MCM_REG_AGG_TASK_CTX,
516 7, MCM_REG_SM_TASK_CTX},
517
518 /* Ustorm */
519 {'U', BLOCK_USEM,
520 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU,
521 DBG_BUS_CLIENT_RBCU}, false,
522 USEM_REG_FAST_MEMORY,
523 USEM_REG_DBG_FRAME_MODE_BB_K2, USEM_REG_SLOW_DBG_ACTIVE_BB_K2,
524 USEM_REG_SLOW_DBG_MODE_BB_K2, USEM_REG_DBG_MODE1_CFG_BB_K2,
525 USEM_REG_SYNC_DBG_EMPTY, USEM_REG_SLOW_DBG_EMPTY_BB_K2,
526 UCM_REG_CTX_RBC_ACCS,
527 2, UCM_REG_AGG_CON_CTX,
528 13, UCM_REG_SM_CON_CTX,
529 3, UCM_REG_AGG_TASK_CTX,
530 3, UCM_REG_SM_TASK_CTX},
531
532 /* Xstorm */
533 {'X', BLOCK_XSEM,
534 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX,
535 DBG_BUS_CLIENT_RBCX}, false,
536 XSEM_REG_FAST_MEMORY,
537 XSEM_REG_DBG_FRAME_MODE_BB_K2, XSEM_REG_SLOW_DBG_ACTIVE_BB_K2,
538 XSEM_REG_SLOW_DBG_MODE_BB_K2, XSEM_REG_DBG_MODE1_CFG_BB_K2,
539 XSEM_REG_SYNC_DBG_EMPTY, XSEM_REG_SLOW_DBG_EMPTY_BB_K2,
540 XCM_REG_CTX_RBC_ACCS,
541 9, XCM_REG_AGG_CON_CTX,
542 15, XCM_REG_SM_CON_CTX,
543 0, 0,
544 0, 0},
545
546 /* Ystorm */
547 {'Y', BLOCK_YSEM,
548 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY,
549 DBG_BUS_CLIENT_RBCY}, false,
550 YSEM_REG_FAST_MEMORY,
551 YSEM_REG_DBG_FRAME_MODE_BB_K2, YSEM_REG_SLOW_DBG_ACTIVE_BB_K2,
552 YSEM_REG_SLOW_DBG_MODE_BB_K2, YSEM_REG_DBG_MODE1_CFG_BB_K2,
553 YSEM_REG_SYNC_DBG_EMPTY, TSEM_REG_SLOW_DBG_EMPTY_BB_K2,
554 YCM_REG_CTX_RBC_ACCS,
555 2, YCM_REG_AGG_CON_CTX,
556 3, YCM_REG_SM_CON_CTX,
557 2, YCM_REG_AGG_TASK_CTX,
558 12, YCM_REG_SM_TASK_CTX},
559
560 /* Pstorm */
561 {'P', BLOCK_PSEM,
562 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS,
563 DBG_BUS_CLIENT_RBCS}, true,
564 PSEM_REG_FAST_MEMORY,
565 PSEM_REG_DBG_FRAME_MODE_BB_K2, PSEM_REG_SLOW_DBG_ACTIVE_BB_K2,
566 PSEM_REG_SLOW_DBG_MODE_BB_K2, PSEM_REG_DBG_MODE1_CFG_BB_K2,
567 PSEM_REG_SYNC_DBG_EMPTY, PSEM_REG_SLOW_DBG_EMPTY_BB_K2,
568 PCM_REG_CTX_RBC_ACCS,
569 0, 0,
570 10, PCM_REG_SM_CON_CTX,
571 0, 0,
572 0, 0}
573};
574
575/* Block definitions array */
576
577static struct block_defs block_grc_defs = {
578 "grc",
579 {true, true, true}, false, 0,
580 {DBG_BUS_CLIENT_RBCN, DBG_BUS_CLIENT_RBCN, DBG_BUS_CLIENT_RBCN},
581 GRC_REG_DBG_SELECT, GRC_REG_DBG_DWORD_ENABLE,
582 GRC_REG_DBG_SHIFT, GRC_REG_DBG_FORCE_VALID,
583 GRC_REG_DBG_FORCE_FRAME,
584 true, false, DBG_RESET_REG_MISC_PL_UA, 1
585};
586
587static struct block_defs block_miscs_defs = {
588 "miscs", {true, true, true}, false, 0,
589 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
590 0, 0, 0, 0, 0,
591 false, false, MAX_DBG_RESET_REGS, 0
592};
593
594static struct block_defs block_misc_defs = {
595 "misc", {true, true, true}, false, 0,
596 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
597 0, 0, 0, 0, 0,
598 false, false, MAX_DBG_RESET_REGS, 0
599};
600
601static struct block_defs block_dbu_defs = {
602 "dbu", {true, true, true}, false, 0,
603 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
604 0, 0, 0, 0, 0,
605 false, false, MAX_DBG_RESET_REGS, 0
606};
607
608static struct block_defs block_pglue_b_defs = {
609 "pglue_b",
610 {true, true, true}, false, 0,
611 {DBG_BUS_CLIENT_RBCH, DBG_BUS_CLIENT_RBCH, DBG_BUS_CLIENT_RBCH},
612 PGLUE_B_REG_DBG_SELECT, PGLUE_B_REG_DBG_DWORD_ENABLE,
613 PGLUE_B_REG_DBG_SHIFT, PGLUE_B_REG_DBG_FORCE_VALID,
614 PGLUE_B_REG_DBG_FORCE_FRAME,
615 true, false, DBG_RESET_REG_MISCS_PL_HV, 1
616};
617
618static struct block_defs block_cnig_defs = {
619 "cnig",
620 {true, true, true}, false, 0,
621 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCW,
622 DBG_BUS_CLIENT_RBCW},
623 CNIG_REG_DBG_SELECT_K2_E5, CNIG_REG_DBG_DWORD_ENABLE_K2_E5,
624 CNIG_REG_DBG_SHIFT_K2_E5, CNIG_REG_DBG_FORCE_VALID_K2_E5,
625 CNIG_REG_DBG_FORCE_FRAME_K2_E5,
626 true, false, DBG_RESET_REG_MISCS_PL_HV, 0
627};
628
629static struct block_defs block_cpmu_defs = {
630 "cpmu", {true, true, true}, false, 0,
631 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
632 0, 0, 0, 0, 0,
633 true, false, DBG_RESET_REG_MISCS_PL_HV, 8
634};
635
636static struct block_defs block_ncsi_defs = {
637 "ncsi",
638 {true, true, true}, false, 0,
639 {DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ},
640 NCSI_REG_DBG_SELECT, NCSI_REG_DBG_DWORD_ENABLE,
641 NCSI_REG_DBG_SHIFT, NCSI_REG_DBG_FORCE_VALID,
642 NCSI_REG_DBG_FORCE_FRAME,
643 true, false, DBG_RESET_REG_MISCS_PL_HV, 5
644};
645
646static struct block_defs block_opte_defs = {
647 "opte", {true, true, false}, false, 0,
648 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
649 0, 0, 0, 0, 0,
650 true, false, DBG_RESET_REG_MISCS_PL_HV, 4
651};
652
653static struct block_defs block_bmb_defs = {
654 "bmb",
655 {true, true, true}, false, 0,
656 {DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCB, DBG_BUS_CLIENT_RBCB},
657 BMB_REG_DBG_SELECT, BMB_REG_DBG_DWORD_ENABLE,
658 BMB_REG_DBG_SHIFT, BMB_REG_DBG_FORCE_VALID,
659 BMB_REG_DBG_FORCE_FRAME,
660 true, false, DBG_RESET_REG_MISCS_PL_UA, 7
661};
662
663static struct block_defs block_pcie_defs = {
664 "pcie",
665 {true, true, true}, false, 0,
666 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCH,
667 DBG_BUS_CLIENT_RBCH},
668 PCIE_REG_DBG_COMMON_SELECT_K2_E5,
669 PCIE_REG_DBG_COMMON_DWORD_ENABLE_K2_E5,
670 PCIE_REG_DBG_COMMON_SHIFT_K2_E5,
671 PCIE_REG_DBG_COMMON_FORCE_VALID_K2_E5,
672 PCIE_REG_DBG_COMMON_FORCE_FRAME_K2_E5,
673 false, false, MAX_DBG_RESET_REGS, 0
674};
675
676static struct block_defs block_mcp_defs = {
677 "mcp", {true, true, true}, false, 0,
678 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
679 0, 0, 0, 0, 0,
680 false, false, MAX_DBG_RESET_REGS, 0
681};
682
683static struct block_defs block_mcp2_defs = {
684 "mcp2",
685 {true, true, true}, false, 0,
686 {DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ},
687 MCP2_REG_DBG_SELECT, MCP2_REG_DBG_DWORD_ENABLE,
688 MCP2_REG_DBG_SHIFT, MCP2_REG_DBG_FORCE_VALID,
689 MCP2_REG_DBG_FORCE_FRAME,
690 false, false, MAX_DBG_RESET_REGS, 0
691};
692
693static struct block_defs block_pswhst_defs = {
694 "pswhst",
695 {true, true, true}, false, 0,
696 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
697 PSWHST_REG_DBG_SELECT, PSWHST_REG_DBG_DWORD_ENABLE,
698 PSWHST_REG_DBG_SHIFT, PSWHST_REG_DBG_FORCE_VALID,
699 PSWHST_REG_DBG_FORCE_FRAME,
700 true, false, DBG_RESET_REG_MISC_PL_HV, 0
701};
702
703static struct block_defs block_pswhst2_defs = {
704 "pswhst2",
705 {true, true, true}, false, 0,
706 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
707 PSWHST2_REG_DBG_SELECT, PSWHST2_REG_DBG_DWORD_ENABLE,
708 PSWHST2_REG_DBG_SHIFT, PSWHST2_REG_DBG_FORCE_VALID,
709 PSWHST2_REG_DBG_FORCE_FRAME,
710 true, false, DBG_RESET_REG_MISC_PL_HV, 0
711};
712
713static struct block_defs block_pswrd_defs = {
714 "pswrd",
715 {true, true, true}, false, 0,
716 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
717 PSWRD_REG_DBG_SELECT, PSWRD_REG_DBG_DWORD_ENABLE,
718 PSWRD_REG_DBG_SHIFT, PSWRD_REG_DBG_FORCE_VALID,
719 PSWRD_REG_DBG_FORCE_FRAME,
720 true, false, DBG_RESET_REG_MISC_PL_HV, 2
721};
722
723static struct block_defs block_pswrd2_defs = {
724 "pswrd2",
725 {true, true, true}, false, 0,
726 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
727 PSWRD2_REG_DBG_SELECT, PSWRD2_REG_DBG_DWORD_ENABLE,
728 PSWRD2_REG_DBG_SHIFT, PSWRD2_REG_DBG_FORCE_VALID,
729 PSWRD2_REG_DBG_FORCE_FRAME,
730 true, false, DBG_RESET_REG_MISC_PL_HV, 2
731};
732
733static struct block_defs block_pswwr_defs = {
734 "pswwr",
735 {true, true, true}, false, 0,
736 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
737 PSWWR_REG_DBG_SELECT, PSWWR_REG_DBG_DWORD_ENABLE,
738 PSWWR_REG_DBG_SHIFT, PSWWR_REG_DBG_FORCE_VALID,
739 PSWWR_REG_DBG_FORCE_FRAME,
740 true, false, DBG_RESET_REG_MISC_PL_HV, 3
741};
742
743static struct block_defs block_pswwr2_defs = {
744 "pswwr2", {true, true, true}, false, 0,
745 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
746 0, 0, 0, 0, 0,
747 true, false, DBG_RESET_REG_MISC_PL_HV, 3
748};
749
750static struct block_defs block_pswrq_defs = {
751 "pswrq",
752 {true, true, true}, false, 0,
753 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
754 PSWRQ_REG_DBG_SELECT, PSWRQ_REG_DBG_DWORD_ENABLE,
755 PSWRQ_REG_DBG_SHIFT, PSWRQ_REG_DBG_FORCE_VALID,
756 PSWRQ_REG_DBG_FORCE_FRAME,
757 true, false, DBG_RESET_REG_MISC_PL_HV, 1
758};
759
760static struct block_defs block_pswrq2_defs = {
761 "pswrq2",
762 {true, true, true}, false, 0,
763 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
764 PSWRQ2_REG_DBG_SELECT, PSWRQ2_REG_DBG_DWORD_ENABLE,
765 PSWRQ2_REG_DBG_SHIFT, PSWRQ2_REG_DBG_FORCE_VALID,
766 PSWRQ2_REG_DBG_FORCE_FRAME,
767 true, false, DBG_RESET_REG_MISC_PL_HV, 1
768};
769
770static struct block_defs block_pglcs_defs = {
771 "pglcs",
772 {true, true, true}, false, 0,
773 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCH,
774 DBG_BUS_CLIENT_RBCH},
775 PGLCS_REG_DBG_SELECT_K2_E5, PGLCS_REG_DBG_DWORD_ENABLE_K2_E5,
776 PGLCS_REG_DBG_SHIFT_K2_E5, PGLCS_REG_DBG_FORCE_VALID_K2_E5,
777 PGLCS_REG_DBG_FORCE_FRAME_K2_E5,
778 true, false, DBG_RESET_REG_MISCS_PL_HV, 2
779};
780
781static struct block_defs block_ptu_defs = {
782 "ptu",
783 {true, true, true}, false, 0,
784 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
785 PTU_REG_DBG_SELECT, PTU_REG_DBG_DWORD_ENABLE,
786 PTU_REG_DBG_SHIFT, PTU_REG_DBG_FORCE_VALID,
787 PTU_REG_DBG_FORCE_FRAME,
788 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 20
789};
790
791static struct block_defs block_dmae_defs = {
792 "dmae",
793 {true, true, true}, false, 0,
794 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
795 DMAE_REG_DBG_SELECT, DMAE_REG_DBG_DWORD_ENABLE,
796 DMAE_REG_DBG_SHIFT, DMAE_REG_DBG_FORCE_VALID,
797 DMAE_REG_DBG_FORCE_FRAME,
798 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 28
799};
800
801static struct block_defs block_tcm_defs = {
802 "tcm",
803 {true, true, true}, true, DBG_TSTORM_ID,
804 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
805 TCM_REG_DBG_SELECT, TCM_REG_DBG_DWORD_ENABLE,
806 TCM_REG_DBG_SHIFT, TCM_REG_DBG_FORCE_VALID,
807 TCM_REG_DBG_FORCE_FRAME,
808 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 5
809};
810
811static struct block_defs block_mcm_defs = {
812 "mcm",
813 {true, true, true}, true, DBG_MSTORM_ID,
814 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
815 MCM_REG_DBG_SELECT, MCM_REG_DBG_DWORD_ENABLE,
816 MCM_REG_DBG_SHIFT, MCM_REG_DBG_FORCE_VALID,
817 MCM_REG_DBG_FORCE_FRAME,
818 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 3
819};
820
821static struct block_defs block_ucm_defs = {
822 "ucm",
823 {true, true, true}, true, DBG_USTORM_ID,
824 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
825 UCM_REG_DBG_SELECT, UCM_REG_DBG_DWORD_ENABLE,
826 UCM_REG_DBG_SHIFT, UCM_REG_DBG_FORCE_VALID,
827 UCM_REG_DBG_FORCE_FRAME,
828 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 8
829};
830
831static struct block_defs block_xcm_defs = {
832 "xcm",
833 {true, true, true}, true, DBG_XSTORM_ID,
834 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
835 XCM_REG_DBG_SELECT, XCM_REG_DBG_DWORD_ENABLE,
836 XCM_REG_DBG_SHIFT, XCM_REG_DBG_FORCE_VALID,
837 XCM_REG_DBG_FORCE_FRAME,
838 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 19
839};
840
841static struct block_defs block_ycm_defs = {
842 "ycm",
843 {true, true, true}, true, DBG_YSTORM_ID,
844 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY, DBG_BUS_CLIENT_RBCY},
845 YCM_REG_DBG_SELECT, YCM_REG_DBG_DWORD_ENABLE,
846 YCM_REG_DBG_SHIFT, YCM_REG_DBG_FORCE_VALID,
847 YCM_REG_DBG_FORCE_FRAME,
848 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 5
849};
850
851static struct block_defs block_pcm_defs = {
852 "pcm",
853 {true, true, true}, true, DBG_PSTORM_ID,
854 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
855 PCM_REG_DBG_SELECT, PCM_REG_DBG_DWORD_ENABLE,
856 PCM_REG_DBG_SHIFT, PCM_REG_DBG_FORCE_VALID,
857 PCM_REG_DBG_FORCE_FRAME,
858 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 4
859};
860
861static struct block_defs block_qm_defs = {
862 "qm",
863 {true, true, true}, false, 0,
864 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCQ, DBG_BUS_CLIENT_RBCQ},
865 QM_REG_DBG_SELECT, QM_REG_DBG_DWORD_ENABLE,
866 QM_REG_DBG_SHIFT, QM_REG_DBG_FORCE_VALID,
867 QM_REG_DBG_FORCE_FRAME,
868 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 16
869};
870
871static struct block_defs block_tm_defs = {
872 "tm",
873 {true, true, true}, false, 0,
874 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
875 TM_REG_DBG_SELECT, TM_REG_DBG_DWORD_ENABLE,
876 TM_REG_DBG_SHIFT, TM_REG_DBG_FORCE_VALID,
877 TM_REG_DBG_FORCE_FRAME,
878 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 17
879};
880
881static struct block_defs block_dorq_defs = {
882 "dorq",
883 {true, true, true}, false, 0,
884 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY, DBG_BUS_CLIENT_RBCY},
885 DORQ_REG_DBG_SELECT, DORQ_REG_DBG_DWORD_ENABLE,
886 DORQ_REG_DBG_SHIFT, DORQ_REG_DBG_FORCE_VALID,
887 DORQ_REG_DBG_FORCE_FRAME,
888 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 18
889};
890
891static struct block_defs block_brb_defs = {
892 "brb",
893 {true, true, true}, false, 0,
894 {DBG_BUS_CLIENT_RBCR, DBG_BUS_CLIENT_RBCR, DBG_BUS_CLIENT_RBCR},
895 BRB_REG_DBG_SELECT, BRB_REG_DBG_DWORD_ENABLE,
896 BRB_REG_DBG_SHIFT, BRB_REG_DBG_FORCE_VALID,
897 BRB_REG_DBG_FORCE_FRAME,
898 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 0
899};
900
901static struct block_defs block_src_defs = {
902 "src",
903 {true, true, true}, false, 0,
904 {DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF},
905 SRC_REG_DBG_SELECT, SRC_REG_DBG_DWORD_ENABLE,
906 SRC_REG_DBG_SHIFT, SRC_REG_DBG_FORCE_VALID,
907 SRC_REG_DBG_FORCE_FRAME,
908 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 2
909};
910
911static struct block_defs block_prs_defs = {
912 "prs",
913 {true, true, true}, false, 0,
914 {DBG_BUS_CLIENT_RBCR, DBG_BUS_CLIENT_RBCR, DBG_BUS_CLIENT_RBCR},
915 PRS_REG_DBG_SELECT, PRS_REG_DBG_DWORD_ENABLE,
916 PRS_REG_DBG_SHIFT, PRS_REG_DBG_FORCE_VALID,
917 PRS_REG_DBG_FORCE_FRAME,
918 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 1
919};
920
921static struct block_defs block_tsdm_defs = {
922 "tsdm",
923 {true, true, true}, true, DBG_TSTORM_ID,
924 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
925 TSDM_REG_DBG_SELECT, TSDM_REG_DBG_DWORD_ENABLE,
926 TSDM_REG_DBG_SHIFT, TSDM_REG_DBG_FORCE_VALID,
927 TSDM_REG_DBG_FORCE_FRAME,
928 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 3
929};
930
931static struct block_defs block_msdm_defs = {
932 "msdm",
933 {true, true, true}, true, DBG_MSTORM_ID,
934 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
935 MSDM_REG_DBG_SELECT, MSDM_REG_DBG_DWORD_ENABLE,
936 MSDM_REG_DBG_SHIFT, MSDM_REG_DBG_FORCE_VALID,
937 MSDM_REG_DBG_FORCE_FRAME,
938 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 6
939};
940
941static struct block_defs block_usdm_defs = {
942 "usdm",
943 {true, true, true}, true, DBG_USTORM_ID,
944 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
945 USDM_REG_DBG_SELECT, USDM_REG_DBG_DWORD_ENABLE,
946 USDM_REG_DBG_SHIFT, USDM_REG_DBG_FORCE_VALID,
947 USDM_REG_DBG_FORCE_FRAME,
948 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 7
949};
950
951static struct block_defs block_xsdm_defs = {
952 "xsdm",
953 {true, true, true}, true, DBG_XSTORM_ID,
954 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
955 XSDM_REG_DBG_SELECT, XSDM_REG_DBG_DWORD_ENABLE,
956 XSDM_REG_DBG_SHIFT, XSDM_REG_DBG_FORCE_VALID,
957 XSDM_REG_DBG_FORCE_FRAME,
958 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 20
959};
960
961static struct block_defs block_ysdm_defs = {
962 "ysdm",
963 {true, true, true}, true, DBG_YSTORM_ID,
964 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY, DBG_BUS_CLIENT_RBCY},
965 YSDM_REG_DBG_SELECT, YSDM_REG_DBG_DWORD_ENABLE,
966 YSDM_REG_DBG_SHIFT, YSDM_REG_DBG_FORCE_VALID,
967 YSDM_REG_DBG_FORCE_FRAME,
968 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 8
969};
970
971static struct block_defs block_psdm_defs = {
972 "psdm",
973 {true, true, true}, true, DBG_PSTORM_ID,
974 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
975 PSDM_REG_DBG_SELECT, PSDM_REG_DBG_DWORD_ENABLE,
976 PSDM_REG_DBG_SHIFT, PSDM_REG_DBG_FORCE_VALID,
977 PSDM_REG_DBG_FORCE_FRAME,
978 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 7
979};
980
981static struct block_defs block_tsem_defs = {
982 "tsem",
983 {true, true, true}, true, DBG_TSTORM_ID,
984 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
985 TSEM_REG_DBG_SELECT, TSEM_REG_DBG_DWORD_ENABLE,
986 TSEM_REG_DBG_SHIFT, TSEM_REG_DBG_FORCE_VALID,
987 TSEM_REG_DBG_FORCE_FRAME,
988 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 4
989};
990
991static struct block_defs block_msem_defs = {
992 "msem",
993 {true, true, true}, true, DBG_MSTORM_ID,
994 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
995 MSEM_REG_DBG_SELECT, MSEM_REG_DBG_DWORD_ENABLE,
996 MSEM_REG_DBG_SHIFT, MSEM_REG_DBG_FORCE_VALID,
997 MSEM_REG_DBG_FORCE_FRAME,
998 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 9
999};
1000
1001static struct block_defs block_usem_defs = {
1002 "usem",
1003 {true, true, true}, true, DBG_USTORM_ID,
1004 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
1005 USEM_REG_DBG_SELECT, USEM_REG_DBG_DWORD_ENABLE,
1006 USEM_REG_DBG_SHIFT, USEM_REG_DBG_FORCE_VALID,
1007 USEM_REG_DBG_FORCE_FRAME,
1008 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 9
1009};
1010
1011static struct block_defs block_xsem_defs = {
1012 "xsem",
1013 {true, true, true}, true, DBG_XSTORM_ID,
1014 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
1015 XSEM_REG_DBG_SELECT, XSEM_REG_DBG_DWORD_ENABLE,
1016 XSEM_REG_DBG_SHIFT, XSEM_REG_DBG_FORCE_VALID,
1017 XSEM_REG_DBG_FORCE_FRAME,
1018 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 21
1019};
1020
1021static struct block_defs block_ysem_defs = {
1022 "ysem",
1023 {true, true, true}, true, DBG_YSTORM_ID,
1024 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY, DBG_BUS_CLIENT_RBCY},
1025 YSEM_REG_DBG_SELECT, YSEM_REG_DBG_DWORD_ENABLE,
1026 YSEM_REG_DBG_SHIFT, YSEM_REG_DBG_FORCE_VALID,
1027 YSEM_REG_DBG_FORCE_FRAME,
1028 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 11
1029};
1030
1031static struct block_defs block_psem_defs = {
1032 "psem",
1033 {true, true, true}, true, DBG_PSTORM_ID,
1034 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
1035 PSEM_REG_DBG_SELECT, PSEM_REG_DBG_DWORD_ENABLE,
1036 PSEM_REG_DBG_SHIFT, PSEM_REG_DBG_FORCE_VALID,
1037 PSEM_REG_DBG_FORCE_FRAME,
1038 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 10
1039};
1040
1041static struct block_defs block_rss_defs = {
1042 "rss",
1043 {true, true, true}, false, 0,
1044 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
1045 RSS_REG_DBG_SELECT, RSS_REG_DBG_DWORD_ENABLE,
1046 RSS_REG_DBG_SHIFT, RSS_REG_DBG_FORCE_VALID,
1047 RSS_REG_DBG_FORCE_FRAME,
1048 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 18
1049};
1050
1051static struct block_defs block_tmld_defs = {
1052 "tmld",
1053 {true, true, true}, false, 0,
1054 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
1055 TMLD_REG_DBG_SELECT, TMLD_REG_DBG_DWORD_ENABLE,
1056 TMLD_REG_DBG_SHIFT, TMLD_REG_DBG_FORCE_VALID,
1057 TMLD_REG_DBG_FORCE_FRAME,
1058 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 13
1059};
1060
1061static struct block_defs block_muld_defs = {
1062 "muld",
1063 {true, true, true}, false, 0,
1064 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
1065 MULD_REG_DBG_SELECT, MULD_REG_DBG_DWORD_ENABLE,
1066 MULD_REG_DBG_SHIFT, MULD_REG_DBG_FORCE_VALID,
1067 MULD_REG_DBG_FORCE_FRAME,
1068 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 14
1069};
1070
1071static struct block_defs block_yuld_defs = {
1072 "yuld",
1073 {true, true, false}, false, 0,
1074 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU,
1075 MAX_DBG_BUS_CLIENTS},
1076 YULD_REG_DBG_SELECT_BB_K2, YULD_REG_DBG_DWORD_ENABLE_BB_K2,
1077 YULD_REG_DBG_SHIFT_BB_K2, YULD_REG_DBG_FORCE_VALID_BB_K2,
1078 YULD_REG_DBG_FORCE_FRAME_BB_K2,
1079 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2,
1080 15
1081};
1082
1083static struct block_defs block_xyld_defs = {
1084 "xyld",
1085 {true, true, true}, false, 0,
1086 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
1087 XYLD_REG_DBG_SELECT, XYLD_REG_DBG_DWORD_ENABLE,
1088 XYLD_REG_DBG_SHIFT, XYLD_REG_DBG_FORCE_VALID,
1089 XYLD_REG_DBG_FORCE_FRAME,
1090 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 12
1091};
1092
1093static struct block_defs block_ptld_defs = {
1094 "ptld",
1095 {false, false, true}, false, 0,
1096 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCT},
1097 PTLD_REG_DBG_SELECT_E5, PTLD_REG_DBG_DWORD_ENABLE_E5,
1098 PTLD_REG_DBG_SHIFT_E5, PTLD_REG_DBG_FORCE_VALID_E5,
1099 PTLD_REG_DBG_FORCE_FRAME_E5,
1100 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2,
1101 28
1102};
1103
1104static struct block_defs block_ypld_defs = {
1105 "ypld",
1106 {false, false, true}, false, 0,
1107 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCS},
1108 YPLD_REG_DBG_SELECT_E5, YPLD_REG_DBG_DWORD_ENABLE_E5,
1109 YPLD_REG_DBG_SHIFT_E5, YPLD_REG_DBG_FORCE_VALID_E5,
1110 YPLD_REG_DBG_FORCE_FRAME_E5,
1111 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2,
1112 27
1113};
1114
1115static struct block_defs block_prm_defs = {
1116 "prm",
1117 {true, true, true}, false, 0,
1118 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
1119 PRM_REG_DBG_SELECT, PRM_REG_DBG_DWORD_ENABLE,
1120 PRM_REG_DBG_SHIFT, PRM_REG_DBG_FORCE_VALID,
1121 PRM_REG_DBG_FORCE_FRAME,
1122 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 21
1123};
1124
1125static struct block_defs block_pbf_pb1_defs = {
1126 "pbf_pb1",
1127 {true, true, true}, false, 0,
1128 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCV, DBG_BUS_CLIENT_RBCV},
1129 PBF_PB1_REG_DBG_SELECT, PBF_PB1_REG_DBG_DWORD_ENABLE,
1130 PBF_PB1_REG_DBG_SHIFT, PBF_PB1_REG_DBG_FORCE_VALID,
1131 PBF_PB1_REG_DBG_FORCE_FRAME,
1132 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1,
1133 11
1134};
1135
1136static struct block_defs block_pbf_pb2_defs = {
1137 "pbf_pb2",
1138 {true, true, true}, false, 0,
1139 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCV, DBG_BUS_CLIENT_RBCV},
1140 PBF_PB2_REG_DBG_SELECT, PBF_PB2_REG_DBG_DWORD_ENABLE,
1141 PBF_PB2_REG_DBG_SHIFT, PBF_PB2_REG_DBG_FORCE_VALID,
1142 PBF_PB2_REG_DBG_FORCE_FRAME,
1143 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1,
1144 12
1145};
1146
1147static struct block_defs block_rpb_defs = {
1148 "rpb",
1149 {true, true, true}, false, 0,
1150 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
1151 RPB_REG_DBG_SELECT, RPB_REG_DBG_DWORD_ENABLE,
1152 RPB_REG_DBG_SHIFT, RPB_REG_DBG_FORCE_VALID,
1153 RPB_REG_DBG_FORCE_FRAME,
1154 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 13
1155};
1156
1157static struct block_defs block_btb_defs = {
1158 "btb",
1159 {true, true, true}, false, 0,
1160 {DBG_BUS_CLIENT_RBCR, DBG_BUS_CLIENT_RBCV, DBG_BUS_CLIENT_RBCV},
1161 BTB_REG_DBG_SELECT, BTB_REG_DBG_DWORD_ENABLE,
1162 BTB_REG_DBG_SHIFT, BTB_REG_DBG_FORCE_VALID,
1163 BTB_REG_DBG_FORCE_FRAME,
1164 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 10
1165};
1166
1167static struct block_defs block_pbf_defs = {
1168 "pbf",
1169 {true, true, true}, false, 0,
1170 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCV, DBG_BUS_CLIENT_RBCV},
1171 PBF_REG_DBG_SELECT, PBF_REG_DBG_DWORD_ENABLE,
1172 PBF_REG_DBG_SHIFT, PBF_REG_DBG_FORCE_VALID,
1173 PBF_REG_DBG_FORCE_FRAME,
1174 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 15
1175};
1176
1177static struct block_defs block_rdif_defs = {
1178 "rdif",
1179 {true, true, true}, false, 0,
1180 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM, DBG_BUS_CLIENT_RBCM},
1181 RDIF_REG_DBG_SELECT, RDIF_REG_DBG_DWORD_ENABLE,
1182 RDIF_REG_DBG_SHIFT, RDIF_REG_DBG_FORCE_VALID,
1183 RDIF_REG_DBG_FORCE_FRAME,
1184 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 16
1185};
1186
1187static struct block_defs block_tdif_defs = {
1188 "tdif",
1189 {true, true, true}, false, 0,
1190 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
1191 TDIF_REG_DBG_SELECT, TDIF_REG_DBG_DWORD_ENABLE,
1192 TDIF_REG_DBG_SHIFT, TDIF_REG_DBG_FORCE_VALID,
1193 TDIF_REG_DBG_FORCE_FRAME,
1194 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 17
1195};
1196
1197static struct block_defs block_cdu_defs = {
1198 "cdu",
1199 {true, true, true}, false, 0,
1200 {DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF},
1201 CDU_REG_DBG_SELECT, CDU_REG_DBG_DWORD_ENABLE,
1202 CDU_REG_DBG_SHIFT, CDU_REG_DBG_FORCE_VALID,
1203 CDU_REG_DBG_FORCE_FRAME,
1204 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 23
1205};
1206
1207static struct block_defs block_ccfc_defs = {
1208 "ccfc",
1209 {true, true, true}, false, 0,
1210 {DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF},
1211 CCFC_REG_DBG_SELECT, CCFC_REG_DBG_DWORD_ENABLE,
1212 CCFC_REG_DBG_SHIFT, CCFC_REG_DBG_FORCE_VALID,
1213 CCFC_REG_DBG_FORCE_FRAME,
1214 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 24
1215};
1216
1217static struct block_defs block_tcfc_defs = {
1218 "tcfc",
1219 {true, true, true}, false, 0,
1220 {DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF, DBG_BUS_CLIENT_RBCF},
1221 TCFC_REG_DBG_SELECT, TCFC_REG_DBG_DWORD_ENABLE,
1222 TCFC_REG_DBG_SHIFT, TCFC_REG_DBG_FORCE_VALID,
1223 TCFC_REG_DBG_FORCE_FRAME,
1224 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 25
1225};
1226
1227static struct block_defs block_igu_defs = {
1228 "igu",
1229 {true, true, true}, false, 0,
1230 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
1231 IGU_REG_DBG_SELECT, IGU_REG_DBG_DWORD_ENABLE,
1232 IGU_REG_DBG_SHIFT, IGU_REG_DBG_FORCE_VALID,
1233 IGU_REG_DBG_FORCE_FRAME,
1234 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1, 27
1235};
1236
1237static struct block_defs block_cau_defs = {
1238 "cau",
1239 {true, true, true}, false, 0,
1240 {DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP, DBG_BUS_CLIENT_RBCP},
1241 CAU_REG_DBG_SELECT, CAU_REG_DBG_DWORD_ENABLE,
1242 CAU_REG_DBG_SHIFT, CAU_REG_DBG_FORCE_VALID,
1243 CAU_REG_DBG_FORCE_FRAME,
1244 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 19
1245};
1246
1247static struct block_defs block_rgfs_defs = {
1248 "rgfs", {false, false, true}, false, 0,
1249 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1250 0, 0, 0, 0, 0,
1251 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 29
1252};
1253
1254static struct block_defs block_rgsrc_defs = {
1255 "rgsrc",
1256 {false, false, true}, false, 0,
1257 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCH},
1258 RGSRC_REG_DBG_SELECT_E5, RGSRC_REG_DBG_DWORD_ENABLE_E5,
1259 RGSRC_REG_DBG_SHIFT_E5, RGSRC_REG_DBG_FORCE_VALID_E5,
1260 RGSRC_REG_DBG_FORCE_FRAME_E5,
1261 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1,
1262 30
1263};
1264
1265static struct block_defs block_tgfs_defs = {
1266 "tgfs", {false, false, true}, false, 0,
1267 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1268 0, 0, 0, 0, 0,
1269 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_2, 30
1270};
1271
1272static struct block_defs block_tgsrc_defs = {
1273 "tgsrc",
1274 {false, false, true}, false, 0,
1275 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCV},
1276 TGSRC_REG_DBG_SELECT_E5, TGSRC_REG_DBG_DWORD_ENABLE_E5,
1277 TGSRC_REG_DBG_SHIFT_E5, TGSRC_REG_DBG_FORCE_VALID_E5,
1278 TGSRC_REG_DBG_FORCE_FRAME_E5,
1279 true, true, DBG_RESET_REG_MISC_PL_PDA_VMAIN_1,
1280 31
1281};
1282
1283static struct block_defs block_umac_defs = {
1284 "umac",
1285 {true, true, true}, false, 0,
1286 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCZ,
1287 DBG_BUS_CLIENT_RBCZ},
1288 UMAC_REG_DBG_SELECT_K2_E5, UMAC_REG_DBG_DWORD_ENABLE_K2_E5,
1289 UMAC_REG_DBG_SHIFT_K2_E5, UMAC_REG_DBG_FORCE_VALID_K2_E5,
1290 UMAC_REG_DBG_FORCE_FRAME_K2_E5,
1291 true, false, DBG_RESET_REG_MISCS_PL_HV, 6
1292};
1293
1294static struct block_defs block_xmac_defs = {
1295 "xmac", {true, false, false}, false, 0,
1296 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1297 0, 0, 0, 0, 0,
1298 false, false, MAX_DBG_RESET_REGS, 0
1299};
1300
1301static struct block_defs block_dbg_defs = {
1302 "dbg", {true, true, true}, false, 0,
1303 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1304 0, 0, 0, 0, 0,
1305 true, true, DBG_RESET_REG_MISC_PL_PDA_VAUX, 3
1306};
1307
1308static struct block_defs block_nig_defs = {
1309 "nig",
1310 {true, true, true}, false, 0,
1311 {DBG_BUS_CLIENT_RBCN, DBG_BUS_CLIENT_RBCN, DBG_BUS_CLIENT_RBCN},
1312 NIG_REG_DBG_SELECT, NIG_REG_DBG_DWORD_ENABLE,
1313 NIG_REG_DBG_SHIFT, NIG_REG_DBG_FORCE_VALID,
1314 NIG_REG_DBG_FORCE_FRAME,
1315 true, true, DBG_RESET_REG_MISC_PL_PDA_VAUX, 0
1316};
1317
1318static struct block_defs block_wol_defs = {
1319 "wol",
1320 {false, true, true}, false, 0,
1321 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ},
1322 WOL_REG_DBG_SELECT_K2_E5, WOL_REG_DBG_DWORD_ENABLE_K2_E5,
1323 WOL_REG_DBG_SHIFT_K2_E5, WOL_REG_DBG_FORCE_VALID_K2_E5,
1324 WOL_REG_DBG_FORCE_FRAME_K2_E5,
1325 true, true, DBG_RESET_REG_MISC_PL_PDA_VAUX, 7
1326};
1327
1328static struct block_defs block_bmbn_defs = {
1329 "bmbn",
1330 {false, true, true}, false, 0,
1331 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCB,
1332 DBG_BUS_CLIENT_RBCB},
1333 BMBN_REG_DBG_SELECT_K2_E5, BMBN_REG_DBG_DWORD_ENABLE_K2_E5,
1334 BMBN_REG_DBG_SHIFT_K2_E5, BMBN_REG_DBG_FORCE_VALID_K2_E5,
1335 BMBN_REG_DBG_FORCE_FRAME_K2_E5,
1336 false, false, MAX_DBG_RESET_REGS, 0
1337};
1338
1339static struct block_defs block_ipc_defs = {
1340 "ipc", {true, true, true}, false, 0,
1341 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1342 0, 0, 0, 0, 0,
1343 true, false, DBG_RESET_REG_MISCS_PL_UA, 8
1344};
1345
1346static struct block_defs block_nwm_defs = {
1347 "nwm",
1348 {false, true, true}, false, 0,
1349 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCW, DBG_BUS_CLIENT_RBCW},
1350 NWM_REG_DBG_SELECT_K2_E5, NWM_REG_DBG_DWORD_ENABLE_K2_E5,
1351 NWM_REG_DBG_SHIFT_K2_E5, NWM_REG_DBG_FORCE_VALID_K2_E5,
1352 NWM_REG_DBG_FORCE_FRAME_K2_E5,
1353 true, false, DBG_RESET_REG_MISCS_PL_HV_2, 0
1354};
1355
1356static struct block_defs block_nws_defs = {
1357 "nws",
1358 {false, true, true}, false, 0,
1359 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCW, DBG_BUS_CLIENT_RBCW},
1360 NWS_REG_DBG_SELECT_K2_E5, NWS_REG_DBG_DWORD_ENABLE_K2_E5,
1361 NWS_REG_DBG_SHIFT_K2_E5, NWS_REG_DBG_FORCE_VALID_K2_E5,
1362 NWS_REG_DBG_FORCE_FRAME_K2_E5,
1363 true, false, DBG_RESET_REG_MISCS_PL_HV, 12
1364};
1365
1366static struct block_defs block_ms_defs = {
1367 "ms",
1368 {false, true, true}, false, 0,
1369 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCZ, DBG_BUS_CLIENT_RBCZ},
1370 MS_REG_DBG_SELECT_K2_E5, MS_REG_DBG_DWORD_ENABLE_K2_E5,
1371 MS_REG_DBG_SHIFT_K2_E5, MS_REG_DBG_FORCE_VALID_K2_E5,
1372 MS_REG_DBG_FORCE_FRAME_K2_E5,
1373 true, false, DBG_RESET_REG_MISCS_PL_HV, 13
1374};
1375
1376static struct block_defs block_phy_pcie_defs = {
1377 "phy_pcie",
1378 {false, true, true}, false, 0,
1379 {MAX_DBG_BUS_CLIENTS, DBG_BUS_CLIENT_RBCH,
1380 DBG_BUS_CLIENT_RBCH},
1381 PCIE_REG_DBG_COMMON_SELECT_K2_E5,
1382 PCIE_REG_DBG_COMMON_DWORD_ENABLE_K2_E5,
1383 PCIE_REG_DBG_COMMON_SHIFT_K2_E5,
1384 PCIE_REG_DBG_COMMON_FORCE_VALID_K2_E5,
1385 PCIE_REG_DBG_COMMON_FORCE_FRAME_K2_E5,
1386 false, false, MAX_DBG_RESET_REGS, 0
1387};
1388
1389static struct block_defs block_led_defs = {
1390 "led", {false, true, true}, false, 0,
1391 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1392 0, 0, 0, 0, 0,
1393 true, false, DBG_RESET_REG_MISCS_PL_HV, 14
1394};
1395
1396static struct block_defs block_avs_wrap_defs = {
1397 "avs_wrap", {false, true, false}, false, 0,
1398 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1399 0, 0, 0, 0, 0,
1400 true, false, DBG_RESET_REG_MISCS_PL_UA, 11
1401};
1402
1403static struct block_defs block_pxpreqbus_defs = {
1404 "pxpreqbus", {false, false, false}, false, 0,
1405 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1406 0, 0, 0, 0, 0,
1407 false, false, MAX_DBG_RESET_REGS, 0
1408};
1409
1410static struct block_defs block_misc_aeu_defs = {
1411 "misc_aeu", {true, true, true}, false, 0,
1412 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1413 0, 0, 0, 0, 0,
1414 false, false, MAX_DBG_RESET_REGS, 0
1415};
1416
1417static struct block_defs block_bar0_map_defs = {
1418 "bar0_map", {true, true, true}, false, 0,
1419 {MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS, MAX_DBG_BUS_CLIENTS},
1420 0, 0, 0, 0, 0,
1421 false, false, MAX_DBG_RESET_REGS, 0
1422};
1423
1424static struct block_defs *s_block_defs[MAX_BLOCK_ID] = {
1425 &block_grc_defs,
1426 &block_miscs_defs,
1427 &block_misc_defs,
1428 &block_dbu_defs,
1429 &block_pglue_b_defs,
1430 &block_cnig_defs,
1431 &block_cpmu_defs,
1432 &block_ncsi_defs,
1433 &block_opte_defs,
1434 &block_bmb_defs,
1435 &block_pcie_defs,
1436 &block_mcp_defs,
1437 &block_mcp2_defs,
1438 &block_pswhst_defs,
1439 &block_pswhst2_defs,
1440 &block_pswrd_defs,
1441 &block_pswrd2_defs,
1442 &block_pswwr_defs,
1443 &block_pswwr2_defs,
1444 &block_pswrq_defs,
1445 &block_pswrq2_defs,
1446 &block_pglcs_defs,
1447 &block_dmae_defs,
1448 &block_ptu_defs,
1449 &block_tcm_defs,
1450 &block_mcm_defs,
1451 &block_ucm_defs,
1452 &block_xcm_defs,
1453 &block_ycm_defs,
1454 &block_pcm_defs,
1455 &block_qm_defs,
1456 &block_tm_defs,
1457 &block_dorq_defs,
1458 &block_brb_defs,
1459 &block_src_defs,
1460 &block_prs_defs,
1461 &block_tsdm_defs,
1462 &block_msdm_defs,
1463 &block_usdm_defs,
1464 &block_xsdm_defs,
1465 &block_ysdm_defs,
1466 &block_psdm_defs,
1467 &block_tsem_defs,
1468 &block_msem_defs,
1469 &block_usem_defs,
1470 &block_xsem_defs,
1471 &block_ysem_defs,
1472 &block_psem_defs,
1473 &block_rss_defs,
1474 &block_tmld_defs,
1475 &block_muld_defs,
1476 &block_yuld_defs,
1477 &block_xyld_defs,
1478 &block_ptld_defs,
1479 &block_ypld_defs,
1480 &block_prm_defs,
1481 &block_pbf_pb1_defs,
1482 &block_pbf_pb2_defs,
1483 &block_rpb_defs,
1484 &block_btb_defs,
1485 &block_pbf_defs,
1486 &block_rdif_defs,
1487 &block_tdif_defs,
1488 &block_cdu_defs,
1489 &block_ccfc_defs,
1490 &block_tcfc_defs,
1491 &block_igu_defs,
1492 &block_cau_defs,
1493 &block_rgfs_defs,
1494 &block_rgsrc_defs,
1495 &block_tgfs_defs,
1496 &block_tgsrc_defs,
1497 &block_umac_defs,
1498 &block_xmac_defs,
1499 &block_dbg_defs,
1500 &block_nig_defs,
1501 &block_wol_defs,
1502 &block_bmbn_defs,
1503 &block_ipc_defs,
1504 &block_nwm_defs,
1505 &block_nws_defs,
1506 &block_ms_defs,
1507 &block_phy_pcie_defs,
1508 &block_led_defs,
1509 &block_avs_wrap_defs,
1510 &block_pxpreqbus_defs,
1511 &block_misc_aeu_defs,
1512 &block_bar0_map_defs,
1513};
1514
1515static struct platform_defs s_platform_defs[] = {
1516 {"asic", 1, 256, 32768},
1517 {"reserved", 0, 0, 0},
1518 {"reserved2", 0, 0, 0},
1519 {"reserved3", 0, 0, 0}
1520};
1521
1522static struct grc_param_defs s_grc_param_defs[] = {
1523 /* DBG_GRC_PARAM_DUMP_TSTORM */
1524 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1525
1526 /* DBG_GRC_PARAM_DUMP_MSTORM */
1527 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1528
1529 /* DBG_GRC_PARAM_DUMP_USTORM */
1530 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1531
1532 /* DBG_GRC_PARAM_DUMP_XSTORM */
1533 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1534
1535 /* DBG_GRC_PARAM_DUMP_YSTORM */
1536 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1537
1538 /* DBG_GRC_PARAM_DUMP_PSTORM */
1539 {{1, 1, 1}, 0, 1, false, false, 1, 1},
1540
1541 /* DBG_GRC_PARAM_DUMP_REGS */
1542 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1543
1544 /* DBG_GRC_PARAM_DUMP_RAM */
1545 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1546
1547 /* DBG_GRC_PARAM_DUMP_PBUF */
1548 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1549
1550 /* DBG_GRC_PARAM_DUMP_IOR */
1551 {{0, 0, 0}, 0, 1, false, false, 0, 1},
1552
1553 /* DBG_GRC_PARAM_DUMP_VFC */
1554 {{0, 0, 0}, 0, 1, false, false, 0, 1},
1555
1556 /* DBG_GRC_PARAM_DUMP_CM_CTX */
1557 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1558
1559 /* DBG_GRC_PARAM_DUMP_ILT */
1560 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1561
1562 /* DBG_GRC_PARAM_DUMP_RSS */
1563 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1564
1565 /* DBG_GRC_PARAM_DUMP_CAU */
1566 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1567
1568 /* DBG_GRC_PARAM_DUMP_QM */
1569 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1570
1571 /* DBG_GRC_PARAM_DUMP_MCP */
1572 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1573
1574 /* DBG_GRC_PARAM_MCP_TRACE_META_SIZE */
1575 {{1, 1, 1}, 1, 0xffffffff, false, true, 0, 1},
1576
1577 /* DBG_GRC_PARAM_DUMP_CFC */
1578 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1579
1580 /* DBG_GRC_PARAM_DUMP_IGU */
1581 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1582
1583 /* DBG_GRC_PARAM_DUMP_BRB */
1584 {{0, 0, 0}, 0, 1, false, false, 0, 1},
1585
1586 /* DBG_GRC_PARAM_DUMP_BTB */
1587 {{0, 0, 0}, 0, 1, false, false, 0, 1},
1588
1589 /* DBG_GRC_PARAM_DUMP_BMB */
1590 {{0, 0, 0}, 0, 1, false, false, 0, 1},
1591
1592 /* DBG_GRC_PARAM_DUMP_NIG */
1593 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1594
1595 /* DBG_GRC_PARAM_DUMP_MULD */
1596 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1597
1598 /* DBG_GRC_PARAM_DUMP_PRS */
1599 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1600
1601 /* DBG_GRC_PARAM_DUMP_DMAE */
1602 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1603
1604 /* DBG_GRC_PARAM_DUMP_TM */
1605 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1606
1607 /* DBG_GRC_PARAM_DUMP_SDM */
1608 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1609
1610 /* DBG_GRC_PARAM_DUMP_DIF */
1611 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1612
1613 /* DBG_GRC_PARAM_DUMP_STATIC */
1614 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1615
1616 /* DBG_GRC_PARAM_UNSTALL */
1617 {{0, 0, 0}, 0, 1, false, false, 0, 0},
1618
1619 /* DBG_GRC_PARAM_NUM_LCIDS */
1620 {{MAX_LCIDS, MAX_LCIDS, MAX_LCIDS}, 1, MAX_LCIDS, false, false,
1621 MAX_LCIDS, MAX_LCIDS},
1622
1623 /* DBG_GRC_PARAM_NUM_LTIDS */
1624 {{MAX_LTIDS, MAX_LTIDS, MAX_LTIDS}, 1, MAX_LTIDS, false, false,
1625 MAX_LTIDS, MAX_LTIDS},
1626
1627 /* DBG_GRC_PARAM_EXCLUDE_ALL */
1628 {{0, 0, 0}, 0, 1, true, false, 0, 0},
1629
1630 /* DBG_GRC_PARAM_CRASH */
1631 {{0, 0, 0}, 0, 1, true, false, 0, 0},
1632
1633 /* DBG_GRC_PARAM_PARITY_SAFE */
1634 {{0, 0, 0}, 0, 1, false, false, 1, 0},
1635
1636 /* DBG_GRC_PARAM_DUMP_CM */
1637 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1638
1639 /* DBG_GRC_PARAM_DUMP_PHY */
1640 {{1, 1, 1}, 0, 1, false, false, 0, 1},
1641
1642 /* DBG_GRC_PARAM_NO_MCP */
1643 {{0, 0, 0}, 0, 1, false, false, 0, 0},
1644
1645 /* DBG_GRC_PARAM_NO_FW_VER */
1646 {{0, 0, 0}, 0, 1, false, false, 0, 0}
1647};
1648
1649static struct rss_mem_defs s_rss_mem_defs[] = {
1650 { "rss_mem_cid", "rss_cid", 0, 32,
1651 {256, 320, 512} },
1652
1653 { "rss_mem_key_msb", "rss_key", 1024, 256,
1654 {128, 208, 257} },
1655
1656 { "rss_mem_key_lsb", "rss_key", 2048, 64,
1657 {128, 208, 257} },
1658
1659 { "rss_mem_info", "rss_info", 3072, 16,
1660 {128, 208, 256} },
1661
1662 { "rss_mem_ind", "rss_ind", 4096, 16,
1663 {16384, 26624, 32768} }
1664};
1665
1666static struct vfc_ram_defs s_vfc_ram_defs[] = {
1667 {"vfc_ram_tt1", "vfc_ram", 0, 512},
1668 {"vfc_ram_mtt2", "vfc_ram", 512, 128},
1669 {"vfc_ram_stt2", "vfc_ram", 640, 32},
1670 {"vfc_ram_ro_vect", "vfc_ram", 672, 32}
1671};
1672
1673static struct big_ram_defs s_big_ram_defs[] = {
1674 { "BRB", MEM_GROUP_BRB_MEM, MEM_GROUP_BRB_RAM, DBG_GRC_PARAM_DUMP_BRB,
1675 BRB_REG_BIG_RAM_ADDRESS, BRB_REG_BIG_RAM_DATA,
1676 MISC_REG_BLOCK_256B_EN, {0, 0, 0},
1677 {153600, 180224, 282624} },
1678
1679 { "BTB", MEM_GROUP_BTB_MEM, MEM_GROUP_BTB_RAM, DBG_GRC_PARAM_DUMP_BTB,
1680 BTB_REG_BIG_RAM_ADDRESS, BTB_REG_BIG_RAM_DATA,
1681 MISC_REG_BLOCK_256B_EN, {0, 1, 1},
1682 {92160, 117760, 168960} },
1683
1684 { "BMB", MEM_GROUP_BMB_MEM, MEM_GROUP_BMB_RAM, DBG_GRC_PARAM_DUMP_BMB,
1685 BMB_REG_BIG_RAM_ADDRESS, BMB_REG_BIG_RAM_DATA,
1686 MISCS_REG_BLOCK_256B_EN, {0, 0, 0},
1687 {36864, 36864, 36864} }
1688};
1689
1690static struct reset_reg_defs s_reset_regs_defs[] = {
1691 /* DBG_RESET_REG_MISCS_PL_UA */
1692 { MISCS_REG_RESET_PL_UA,
1693 {true, true, true}, {0x0, 0x0, 0x0} },
1694
1695 /* DBG_RESET_REG_MISCS_PL_HV */
1696 { MISCS_REG_RESET_PL_HV,
1697 {true, true, true}, {0x0, 0x400, 0x600} },
1698
1699 /* DBG_RESET_REG_MISCS_PL_HV_2 */
1700 { MISCS_REG_RESET_PL_HV_2_K2_E5,
1701 {false, true, true}, {0x0, 0x0, 0x0} },
1702
1703 /* DBG_RESET_REG_MISC_PL_UA */
1704 { MISC_REG_RESET_PL_UA,
1705 {true, true, true}, {0x0, 0x0, 0x0} },
1706
1707 /* DBG_RESET_REG_MISC_PL_HV */
1708 { MISC_REG_RESET_PL_HV,
1709 {true, true, true}, {0x0, 0x0, 0x0} },
1710
1711 /* DBG_RESET_REG_MISC_PL_PDA_VMAIN_1 */
1712 { MISC_REG_RESET_PL_PDA_VMAIN_1,
1713 {true, true, true}, {0x4404040, 0x4404040, 0x404040} },
1714
1715 /* DBG_RESET_REG_MISC_PL_PDA_VMAIN_2 */
1716 { MISC_REG_RESET_PL_PDA_VMAIN_2,
1717 {true, true, true}, {0x7, 0x7c00007, 0x5c08007} },
1718
1719 /* DBG_RESET_REG_MISC_PL_PDA_VAUX */
1720 { MISC_REG_RESET_PL_PDA_VAUX,
1721 {true, true, true}, {0x2, 0x2, 0x2} },
1722};
1723
1724static struct phy_defs s_phy_defs[] = {
1725 {"nw_phy", NWS_REG_NWS_CMU_K2,
1726 PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_7_0_K2_E5,
1727 PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_15_8_K2_E5,
1728 PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_7_0_K2_E5,
1729 PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_11_8_K2_E5},
1730 {"sgmii_phy", MS_REG_MS_CMU_K2_E5,
1731 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X132_K2_E5,
1732 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X133_K2_E5,
1733 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X130_K2_E5,
1734 PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X131_K2_E5},
1735 {"pcie_phy0", PHY_PCIE_REG_PHY0_K2_E5,
1736 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2_E5,
1737 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2_E5,
1738 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2_E5,
1739 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2_E5},
1740 {"pcie_phy1", PHY_PCIE_REG_PHY1_K2_E5,
1741 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2_E5,
1742 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2_E5,
1743 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2_E5,
1744 PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2_E5},
1745};
1746
1747/**************************** Private Functions ******************************/
1748
1749/* Reads and returns a single dword from the specified unaligned buffer */
1750static u32 qed_read_unaligned_dword(u8 *buf)
1751{
1752 u32 dword;
1753
1754 memcpy((u8 *)&dword, buf, sizeof(dword));
1755 return dword;
1756}
1757
1758/* Returns the value of the specified GRC param */
1759static u32 qed_grc_get_param(struct qed_hwfn *p_hwfn,
1760 enum dbg_grc_params grc_param)
1761{
1762 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1763
1764 return dev_data->grc.param_val[grc_param];
1765}
1766
1767/* Initializes the GRC parameters */
1768static void qed_dbg_grc_init_params(struct qed_hwfn *p_hwfn)
1769{
1770 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1771
1772 if (!dev_data->grc.params_initialized) {
1773 qed_dbg_grc_set_params_default(p_hwfn);
1774 dev_data->grc.params_initialized = 1;
1775 }
1776}
1777
1778/* Initializes debug data for the specified device */
1779static enum dbg_status qed_dbg_dev_init(struct qed_hwfn *p_hwfn,
1780 struct qed_ptt *p_ptt)
1781{
1782 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1783
1784 if (dev_data->initialized)
1785 return DBG_STATUS_OK;
1786
1787 if (QED_IS_K2(p_hwfn->cdev)) {
1788 dev_data->chip_id = CHIP_K2;
1789 dev_data->mode_enable[MODE_K2] = 1;
1790 } else if (QED_IS_BB_B0(p_hwfn->cdev)) {
1791 dev_data->chip_id = CHIP_BB;
1792 dev_data->mode_enable[MODE_BB] = 1;
1793 } else {
1794 return DBG_STATUS_UNKNOWN_CHIP;
1795 }
1796
1797 dev_data->platform_id = PLATFORM_ASIC;
1798 dev_data->mode_enable[MODE_ASIC] = 1;
1799
1800 /* Initializes the GRC parameters */
1801 qed_dbg_grc_init_params(p_hwfn);
1802
1803 dev_data->use_dmae = true;
1804 dev_data->num_regs_read = 0;
1805 dev_data->initialized = 1;
1806
1807 return DBG_STATUS_OK;
1808}
1809
1810static struct dbg_bus_block *get_dbg_bus_block_desc(struct qed_hwfn *p_hwfn,
1811 enum block_id block_id)
1812{
1813 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1814
1815 return (struct dbg_bus_block *)&dbg_bus_blocks[block_id *
1816 MAX_CHIP_IDS +
1817 dev_data->chip_id];
1818}
1819
1820/* Reads the FW info structure for the specified Storm from the chip,
1821 * and writes it to the specified fw_info pointer.
1822 */
1823static void qed_read_fw_info(struct qed_hwfn *p_hwfn,
1824 struct qed_ptt *p_ptt,
1825 u8 storm_id, struct fw_info *fw_info)
1826{
1827 struct storm_defs *storm = &s_storm_defs[storm_id];
1828 struct fw_info_location fw_info_location;
1829 u32 addr, i, *dest;
1830
1831 memset(&fw_info_location, 0, sizeof(fw_info_location));
1832 memset(fw_info, 0, sizeof(*fw_info));
1833
1834 /* Read first the address that points to fw_info location.
1835 * The address is located in the last line of the Storm RAM.
1836 */
1837 addr = storm->sem_fast_mem_addr + SEM_FAST_REG_INT_RAM +
1838 DWORDS_TO_BYTES(SEM_FAST_REG_INT_RAM_SIZE_BB_K2) -
1839 sizeof(fw_info_location);
1840 dest = (u32 *)&fw_info_location;
1841
1842 for (i = 0; i < BYTES_TO_DWORDS(sizeof(fw_info_location));
1843 i++, addr += BYTES_IN_DWORD)
1844 dest[i] = qed_rd(p_hwfn, p_ptt, addr);
1845
1846 /* Read FW version info from Storm RAM */
1847 if (fw_info_location.size > 0 && fw_info_location.size <=
1848 sizeof(*fw_info)) {
1849 addr = fw_info_location.grc_addr;
1850 dest = (u32 *)fw_info;
1851 for (i = 0; i < BYTES_TO_DWORDS(fw_info_location.size);
1852 i++, addr += BYTES_IN_DWORD)
1853 dest[i] = qed_rd(p_hwfn, p_ptt, addr);
1854 }
1855}
1856
1857/* Dumps the specified string to the specified buffer.
1858 * Returns the dumped size in bytes.
1859 */
1860static u32 qed_dump_str(char *dump_buf, bool dump, const char *str)
1861{
1862 if (dump)
1863 strcpy(dump_buf, str);
1864
1865 return (u32)strlen(str) + 1;
1866}
1867
1868/* Dumps zeros to align the specified buffer to dwords.
1869 * Returns the dumped size in bytes.
1870 */
1871static u32 qed_dump_align(char *dump_buf, bool dump, u32 byte_offset)
1872{
1873 u8 offset_in_dword, align_size;
1874
1875 offset_in_dword = (u8)(byte_offset & 0x3);
1876 align_size = offset_in_dword ? BYTES_IN_DWORD - offset_in_dword : 0;
1877
1878 if (dump && align_size)
1879 memset(dump_buf, 0, align_size);
1880
1881 return align_size;
1882}
1883
1884/* Writes the specified string param to the specified buffer.
1885 * Returns the dumped size in dwords.
1886 */
1887static u32 qed_dump_str_param(u32 *dump_buf,
1888 bool dump,
1889 const char *param_name, const char *param_val)
1890{
1891 char *char_buf = (char *)dump_buf;
1892 u32 offset = 0;
1893
1894 /* Dump param name */
1895 offset += qed_dump_str(char_buf + offset, dump, param_name);
1896
1897 /* Indicate a string param value */
1898 if (dump)
1899 *(char_buf + offset) = 1;
1900 offset++;
1901
1902 /* Dump param value */
1903 offset += qed_dump_str(char_buf + offset, dump, param_val);
1904
1905 /* Align buffer to next dword */
1906 offset += qed_dump_align(char_buf + offset, dump, offset);
1907
1908 return BYTES_TO_DWORDS(offset);
1909}
1910
1911/* Writes the specified numeric param to the specified buffer.
1912 * Returns the dumped size in dwords.
1913 */
1914static u32 qed_dump_num_param(u32 *dump_buf,
1915 bool dump, const char *param_name, u32 param_val)
1916{
1917 char *char_buf = (char *)dump_buf;
1918 u32 offset = 0;
1919
1920 /* Dump param name */
1921 offset += qed_dump_str(char_buf + offset, dump, param_name);
1922
1923 /* Indicate a numeric param value */
1924 if (dump)
1925 *(char_buf + offset) = 0;
1926 offset++;
1927
1928 /* Align buffer to next dword */
1929 offset += qed_dump_align(char_buf + offset, dump, offset);
1930
1931 /* Dump param value (and change offset from bytes to dwords) */
1932 offset = BYTES_TO_DWORDS(offset);
1933 if (dump)
1934 *(dump_buf + offset) = param_val;
1935 offset++;
1936
1937 return offset;
1938}
1939
1940/* Reads the FW version and writes it as a param to the specified buffer.
1941 * Returns the dumped size in dwords.
1942 */
1943static u32 qed_dump_fw_ver_param(struct qed_hwfn *p_hwfn,
1944 struct qed_ptt *p_ptt,
1945 u32 *dump_buf, bool dump)
1946{
1947 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
1948 char fw_ver_str[16] = EMPTY_FW_VERSION_STR;
1949 char fw_img_str[16] = EMPTY_FW_IMAGE_STR;
1950 struct fw_info fw_info = { {0}, {0} };
1951 u32 offset = 0;
1952
1953 if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
1954 /* Read FW image/version from PRAM in a non-reset SEMI */
1955 bool found = false;
1956 u8 storm_id;
1957
1958 for (storm_id = 0; storm_id < MAX_DBG_STORMS && !found;
1959 storm_id++) {
1960 struct storm_defs *storm = &s_storm_defs[storm_id];
1961
1962 /* Read FW version/image */
1963 if (dev_data->block_in_reset[storm->block_id])
1964 continue;
1965
1966 /* Read FW info for the current Storm */
1967 qed_read_fw_info(p_hwfn, p_ptt, storm_id, &fw_info);
1968
1969 /* Create FW version/image strings */
1970 if (snprintf(fw_ver_str, sizeof(fw_ver_str),
1971 "%d_%d_%d_%d", fw_info.ver.num.major,
1972 fw_info.ver.num.minor, fw_info.ver.num.rev,
1973 fw_info.ver.num.eng) < 0)
1974 DP_NOTICE(p_hwfn,
1975 "Unexpected debug error: invalid FW version string\n");
1976 switch (fw_info.ver.image_id) {
1977 case FW_IMG_MAIN:
1978 strcpy(fw_img_str, "main");
1979 break;
1980 default:
1981 strcpy(fw_img_str, "unknown");
1982 break;
1983 }
1984
1985 found = true;
1986 }
1987 }
1988
1989 /* Dump FW version, image and timestamp */
1990 offset += qed_dump_str_param(dump_buf + offset,
1991 dump, "fw-version", fw_ver_str);
1992 offset += qed_dump_str_param(dump_buf + offset,
1993 dump, "fw-image", fw_img_str);
1994 offset += qed_dump_num_param(dump_buf + offset,
1995 dump,
1996 "fw-timestamp", fw_info.ver.timestamp);
1997
1998 return offset;
1999}
2000
2001/* Reads the MFW version and writes it as a param to the specified buffer.
2002 * Returns the dumped size in dwords.
2003 */
2004static u32 qed_dump_mfw_ver_param(struct qed_hwfn *p_hwfn,
2005 struct qed_ptt *p_ptt,
2006 u32 *dump_buf, bool dump)
2007{
2008 char mfw_ver_str[16] = EMPTY_FW_VERSION_STR;
2009
2010 if (dump &&
2011 !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
2012 u32 global_section_offsize, global_section_addr, mfw_ver;
2013 u32 public_data_addr, global_section_offsize_addr;
2014
2015 /* Find MCP public data GRC address. Needs to be ORed with
2016 * MCP_REG_SCRATCH due to a HW bug.
2017 */
2018 public_data_addr = qed_rd(p_hwfn,
2019 p_ptt,
2020 MISC_REG_SHARED_MEM_ADDR) |
2021 MCP_REG_SCRATCH;
2022
2023 /* Find MCP public global section offset */
2024 global_section_offsize_addr = public_data_addr +
2025 offsetof(struct mcp_public_data,
2026 sections) +
2027 sizeof(offsize_t) * PUBLIC_GLOBAL;
2028 global_section_offsize = qed_rd(p_hwfn, p_ptt,
2029 global_section_offsize_addr);
2030 global_section_addr =
2031 MCP_REG_SCRATCH +
2032 (global_section_offsize & OFFSIZE_OFFSET_MASK) * 4;
2033
2034 /* Read MFW version from MCP public global section */
2035 mfw_ver = qed_rd(p_hwfn, p_ptt,
2036 global_section_addr +
2037 offsetof(struct public_global, mfw_ver));
2038
2039 /* Dump MFW version param */
2040 if (snprintf(mfw_ver_str, sizeof(mfw_ver_str), "%d_%d_%d_%d",
2041 (u8)(mfw_ver >> 24), (u8)(mfw_ver >> 16),
2042 (u8)(mfw_ver >> 8), (u8)mfw_ver) < 0)
2043 DP_NOTICE(p_hwfn,
2044 "Unexpected debug error: invalid MFW version string\n");
2045 }
2046
2047 return qed_dump_str_param(dump_buf, dump, "mfw-version", mfw_ver_str);
2048}
2049
2050/* Writes a section header to the specified buffer.
2051 * Returns the dumped size in dwords.
2052 */
2053static u32 qed_dump_section_hdr(u32 *dump_buf,
2054 bool dump, const char *name, u32 num_params)
2055{
2056 return qed_dump_num_param(dump_buf, dump, name, num_params);
2057}
2058
2059/* Writes the common global params to the specified buffer.
2060 * Returns the dumped size in dwords.
2061 */
2062static u32 qed_dump_common_global_params(struct qed_hwfn *p_hwfn,
2063 struct qed_ptt *p_ptt,
2064 u32 *dump_buf,
2065 bool dump,
2066 u8 num_specific_global_params)
2067{
2068 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2069 u32 offset = 0;
2070 u8 num_params;
2071
2072 /* Dump global params section header */
2073 num_params = NUM_COMMON_GLOBAL_PARAMS + num_specific_global_params;
2074 offset += qed_dump_section_hdr(dump_buf + offset,
2075 dump, "global_params", num_params);
2076
2077 /* Store params */
2078 offset += qed_dump_fw_ver_param(p_hwfn, p_ptt, dump_buf + offset, dump);
2079 offset += qed_dump_mfw_ver_param(p_hwfn,
2080 p_ptt, dump_buf + offset, dump);
2081 offset += qed_dump_num_param(dump_buf + offset,
2082 dump, "tools-version", TOOLS_VERSION);
2083 offset += qed_dump_str_param(dump_buf + offset,
2084 dump,
2085 "chip",
2086 s_chip_defs[dev_data->chip_id].name);
2087 offset += qed_dump_str_param(dump_buf + offset,
2088 dump,
2089 "platform",
2090 s_platform_defs[dev_data->platform_id].
2091 name);
2092 offset +=
2093 qed_dump_num_param(dump_buf + offset, dump, "pci-func",
2094 p_hwfn->abs_pf_id);
2095
2096 return offset;
2097}
2098
2099/* Writes the "last" section (including CRC) to the specified buffer at the
2100 * given offset. Returns the dumped size in dwords.
2101 */
2102static u32 qed_dump_last_section(u32 *dump_buf, u32 offset, bool dump)
2103{
2104 u32 start_offset = offset;
2105
2106 /* Dump CRC section header */
2107 offset += qed_dump_section_hdr(dump_buf + offset, dump, "last", 0);
2108
2109 /* Calculate CRC32 and add it to the dword after the "last" section */
2110 if (dump)
2111 *(dump_buf + offset) = ~crc32(0xffffffff,
2112 (u8 *)dump_buf,
2113 DWORDS_TO_BYTES(offset));
2114
2115 offset++;
2116
2117 return offset - start_offset;
2118}
2119
2120/* Update blocks reset state */
2121static void qed_update_blocks_reset_state(struct qed_hwfn *p_hwfn,
2122 struct qed_ptt *p_ptt)
2123{
2124 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2125 u32 reg_val[MAX_DBG_RESET_REGS] = { 0 };
2126 u32 i;
2127
2128 /* Read reset registers */
2129 for (i = 0; i < MAX_DBG_RESET_REGS; i++)
2130 if (s_reset_regs_defs[i].exists[dev_data->chip_id])
2131 reg_val[i] = qed_rd(p_hwfn,
2132 p_ptt, s_reset_regs_defs[i].addr);
2133
2134 /* Check if blocks are in reset */
2135 for (i = 0; i < MAX_BLOCK_ID; i++) {
2136 struct block_defs *block = s_block_defs[i];
2137
2138 dev_data->block_in_reset[i] = block->has_reset_bit &&
2139 !(reg_val[block->reset_reg] & BIT(block->reset_bit_offset));
2140 }
2141}
2142
2143/* Enable / disable the Debug block */
2144static void qed_bus_enable_dbg_block(struct qed_hwfn *p_hwfn,
2145 struct qed_ptt *p_ptt, bool enable)
2146{
2147 qed_wr(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON, enable ? 1 : 0);
2148}
2149
2150/* Resets the Debug block */
2151static void qed_bus_reset_dbg_block(struct qed_hwfn *p_hwfn,
2152 struct qed_ptt *p_ptt)
2153{
2154 u32 dbg_reset_reg_addr, old_reset_reg_val, new_reset_reg_val;
2155 struct block_defs *dbg_block = s_block_defs[BLOCK_DBG];
2156
2157 dbg_reset_reg_addr = s_reset_regs_defs[dbg_block->reset_reg].addr;
2158 old_reset_reg_val = qed_rd(p_hwfn, p_ptt, dbg_reset_reg_addr);
2159 new_reset_reg_val =
2160 old_reset_reg_val & ~BIT(dbg_block->reset_bit_offset);
2161
2162 qed_wr(p_hwfn, p_ptt, dbg_reset_reg_addr, new_reset_reg_val);
2163 qed_wr(p_hwfn, p_ptt, dbg_reset_reg_addr, old_reset_reg_val);
2164}
2165
2166static void qed_bus_set_framing_mode(struct qed_hwfn *p_hwfn,
2167 struct qed_ptt *p_ptt,
2168 enum dbg_bus_frame_modes mode)
2169{
2170 qed_wr(p_hwfn, p_ptt, DBG_REG_FRAMING_MODE, (u8)mode);
2171}
2172
2173/* Enable / disable Debug Bus clients according to the specified mask
2174 * (1 = enable, 0 = disable).
2175 */
2176static void qed_bus_enable_clients(struct qed_hwfn *p_hwfn,
2177 struct qed_ptt *p_ptt, u32 client_mask)
2178{
2179 qed_wr(p_hwfn, p_ptt, DBG_REG_CLIENT_ENABLE, client_mask);
2180}
2181
2182static bool qed_is_mode_match(struct qed_hwfn *p_hwfn, u16 *modes_buf_offset)
2183{
2184 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2185 bool arg1, arg2;
2186 const u32 *ptr;
2187 u8 tree_val;
2188
2189 /* Get next element from modes tree buffer */
2190 ptr = s_dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr;
2191 tree_val = ((u8 *)ptr)[(*modes_buf_offset)++];
2192
2193 switch (tree_val) {
2194 case INIT_MODE_OP_NOT:
2195 return !qed_is_mode_match(p_hwfn, modes_buf_offset);
2196 case INIT_MODE_OP_OR:
2197 case INIT_MODE_OP_AND:
2198 arg1 = qed_is_mode_match(p_hwfn, modes_buf_offset);
2199 arg2 = qed_is_mode_match(p_hwfn, modes_buf_offset);
2200 return (tree_val == INIT_MODE_OP_OR) ? (arg1 ||
2201 arg2) : (arg1 && arg2);
2202 default:
2203 return dev_data->mode_enable[tree_val - MAX_INIT_MODE_OPS] > 0;
2204 }
2205}
2206
2207/* Returns true if the specified entity (indicated by GRC param) should be
2208 * included in the dump, false otherwise.
2209 */
2210static bool qed_grc_is_included(struct qed_hwfn *p_hwfn,
2211 enum dbg_grc_params grc_param)
2212{
2213 return qed_grc_get_param(p_hwfn, grc_param) > 0;
2214}
2215
2216/* Returns true of the specified Storm should be included in the dump, false
2217 * otherwise.
2218 */
2219static bool qed_grc_is_storm_included(struct qed_hwfn *p_hwfn,
2220 enum dbg_storms storm)
2221{
2222 return qed_grc_get_param(p_hwfn, (enum dbg_grc_params)storm) > 0;
2223}
2224
2225/* Returns true if the specified memory should be included in the dump, false
2226 * otherwise.
2227 */
2228static bool qed_grc_is_mem_included(struct qed_hwfn *p_hwfn,
2229 enum block_id block_id, u8 mem_group_id)
2230{
2231 struct block_defs *block = s_block_defs[block_id];
2232 u8 i;
2233
2234 /* Check Storm match */
2235 if (block->associated_to_storm &&
2236 !qed_grc_is_storm_included(p_hwfn,
2237 (enum dbg_storms)block->storm_id))
2238 return false;
2239
2240 for (i = 0; i < NUM_BIG_RAM_TYPES; i++) {
2241 struct big_ram_defs *big_ram = &s_big_ram_defs[i];
2242
2243 if (mem_group_id == big_ram->mem_group_id ||
2244 mem_group_id == big_ram->ram_mem_group_id)
2245 return qed_grc_is_included(p_hwfn, big_ram->grc_param);
2246 }
2247
2248 switch (mem_group_id) {
2249 case MEM_GROUP_PXP_ILT:
2250 case MEM_GROUP_PXP_MEM:
2251 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PXP);
2252 case MEM_GROUP_RAM:
2253 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RAM);
2254 case MEM_GROUP_PBUF:
2255 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PBUF);
2256 case MEM_GROUP_CAU_MEM:
2257 case MEM_GROUP_CAU_SB:
2258 case MEM_GROUP_CAU_PI:
2259 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CAU);
2260 case MEM_GROUP_QM_MEM:
2261 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_QM);
2262 case MEM_GROUP_CFC_MEM:
2263 case MEM_GROUP_CONN_CFC_MEM:
2264 case MEM_GROUP_TASK_CFC_MEM:
2265 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CFC) ||
2266 qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX);
2267 case MEM_GROUP_IGU_MEM:
2268 case MEM_GROUP_IGU_MSIX:
2269 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IGU);
2270 case MEM_GROUP_MULD_MEM:
2271 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MULD);
2272 case MEM_GROUP_PRS_MEM:
2273 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PRS);
2274 case MEM_GROUP_DMAE_MEM:
2275 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DMAE);
2276 case MEM_GROUP_TM_MEM:
2277 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_TM);
2278 case MEM_GROUP_SDM_MEM:
2279 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_SDM);
2280 case MEM_GROUP_TDIF_CTX:
2281 case MEM_GROUP_RDIF_CTX:
2282 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DIF);
2283 case MEM_GROUP_CM_MEM:
2284 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM);
2285 case MEM_GROUP_IOR:
2286 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IOR);
2287 default:
2288 return true;
2289 }
2290}
2291
2292/* Stalls all Storms */
2293static void qed_grc_stall_storms(struct qed_hwfn *p_hwfn,
2294 struct qed_ptt *p_ptt, bool stall)
2295{
2296 u32 reg_addr;
2297 u8 storm_id;
2298
2299 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
2300 if (!qed_grc_is_storm_included(p_hwfn,
2301 (enum dbg_storms)storm_id))
2302 continue;
2303
2304 reg_addr = s_storm_defs[storm_id].sem_fast_mem_addr +
2305 SEM_FAST_REG_STALL_0_BB_K2;
2306 qed_wr(p_hwfn, p_ptt, reg_addr, stall ? 1 : 0);
2307 }
2308
2309 msleep(STALL_DELAY_MS);
2310}
2311
2312/* Takes all blocks out of reset */
2313static void qed_grc_unreset_blocks(struct qed_hwfn *p_hwfn,
2314 struct qed_ptt *p_ptt)
2315{
2316 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2317 u32 reg_val[MAX_DBG_RESET_REGS] = { 0 };
2318 u32 block_id, i;
2319
2320 /* Fill reset regs values */
2321 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
2322 struct block_defs *block = s_block_defs[block_id];
2323
2324 if (block->exists[dev_data->chip_id] && block->has_reset_bit &&
2325 block->unreset)
2326 reg_val[block->reset_reg] |=
2327 BIT(block->reset_bit_offset);
2328 }
2329
2330 /* Write reset registers */
2331 for (i = 0; i < MAX_DBG_RESET_REGS; i++) {
2332 if (!s_reset_regs_defs[i].exists[dev_data->chip_id])
2333 continue;
2334
2335 reg_val[i] |=
2336 s_reset_regs_defs[i].unreset_val[dev_data->chip_id];
2337
2338 if (reg_val[i])
2339 qed_wr(p_hwfn,
2340 p_ptt,
2341 s_reset_regs_defs[i].addr +
2342 RESET_REG_UNRESET_OFFSET, reg_val[i]);
2343 }
2344}
2345
2346/* Returns the attention block data of the specified block */
2347static const struct dbg_attn_block_type_data *
2348qed_get_block_attn_data(enum block_id block_id, enum dbg_attn_type attn_type)
2349{
2350 const struct dbg_attn_block *base_attn_block_arr =
2351 (const struct dbg_attn_block *)
2352 s_dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr;
2353
2354 return &base_attn_block_arr[block_id].per_type_data[attn_type];
2355}
2356
2357/* Returns the attention registers of the specified block */
2358static const struct dbg_attn_reg *
2359qed_get_block_attn_regs(enum block_id block_id, enum dbg_attn_type attn_type,
2360 u8 *num_attn_regs)
2361{
2362 const struct dbg_attn_block_type_data *block_type_data =
2363 qed_get_block_attn_data(block_id, attn_type);
2364
2365 *num_attn_regs = block_type_data->num_regs;
2366
2367 return &((const struct dbg_attn_reg *)
2368 s_dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)[block_type_data->
2369 regs_offset];
2370}
2371
2372/* For each block, clear the status of all parities */
2373static void qed_grc_clear_all_prty(struct qed_hwfn *p_hwfn,
2374 struct qed_ptt *p_ptt)
2375{
2376 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2377 const struct dbg_attn_reg *attn_reg_arr;
2378 u8 reg_idx, num_attn_regs;
2379 u32 block_id;
2380
2381 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
2382 if (dev_data->block_in_reset[block_id])
2383 continue;
2384
2385 attn_reg_arr = qed_get_block_attn_regs((enum block_id)block_id,
2386 ATTN_TYPE_PARITY,
2387 &num_attn_regs);
2388
2389 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
2390 const struct dbg_attn_reg *reg_data =
2391 &attn_reg_arr[reg_idx];
2392 u16 modes_buf_offset;
2393 bool eval_mode;
2394
2395 /* Check mode */
2396 eval_mode = GET_FIELD(reg_data->mode.data,
2397 DBG_MODE_HDR_EVAL_MODE) > 0;
2398 modes_buf_offset =
2399 GET_FIELD(reg_data->mode.data,
2400 DBG_MODE_HDR_MODES_BUF_OFFSET);
2401
2402 /* If Mode match: clear parity status */
2403 if (!eval_mode ||
2404 qed_is_mode_match(p_hwfn, &modes_buf_offset))
2405 qed_rd(p_hwfn, p_ptt,
2406 DWORDS_TO_BYTES(reg_data->
2407 sts_clr_address));
2408 }
2409 }
2410}
2411
2412/* Dumps GRC registers section header. Returns the dumped size in dwords.
2413 * The following parameters are dumped:
2414 * - count: no. of dumped entries
2415 * - split: split type
2416 * - id: split ID (dumped only if split_id >= 0)
2417 * - param_name: user parameter value (dumped only if param_name != NULL
2418 * and param_val != NULL).
2419 */
2420static u32 qed_grc_dump_regs_hdr(u32 *dump_buf,
2421 bool dump,
2422 u32 num_reg_entries,
2423 const char *split_type,
2424 int split_id,
2425 const char *param_name, const char *param_val)
2426{
2427 u8 num_params = 2 + (split_id >= 0 ? 1 : 0) + (param_name ? 1 : 0);
2428 u32 offset = 0;
2429
2430 offset += qed_dump_section_hdr(dump_buf + offset,
2431 dump, "grc_regs", num_params);
2432 offset += qed_dump_num_param(dump_buf + offset,
2433 dump, "count", num_reg_entries);
2434 offset += qed_dump_str_param(dump_buf + offset,
2435 dump, "split", split_type);
2436 if (split_id >= 0)
2437 offset += qed_dump_num_param(dump_buf + offset,
2438 dump, "id", split_id);
2439 if (param_name && param_val)
2440 offset += qed_dump_str_param(dump_buf + offset,
2441 dump, param_name, param_val);
2442
2443 return offset;
2444}
2445
2446/* Reads the specified registers into the specified buffer.
2447 * The addr and len arguments are specified in dwords.
2448 */
2449void qed_read_regs(struct qed_hwfn *p_hwfn,
2450 struct qed_ptt *p_ptt, u32 *buf, u32 addr, u32 len)
2451{
2452 u32 i;
2453
2454 for (i = 0; i < len; i++)
2455 buf[i] = qed_rd(p_hwfn, p_ptt, DWORDS_TO_BYTES(addr + i));
2456}
2457
2458/* Dumps the GRC registers in the specified address range.
2459 * Returns the dumped size in dwords.
2460 * The addr and len arguments are specified in dwords.
2461 */
2462static u32 qed_grc_dump_addr_range(struct qed_hwfn *p_hwfn,
2463 struct qed_ptt *p_ptt,
2464 u32 *dump_buf,
2465 bool dump, u32 addr, u32 len, bool wide_bus)
2466{
2467 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2468
2469 if (!dump)
2470 return len;
2471
2472 /* Print log if needed */
2473 dev_data->num_regs_read += len;
2474 if (dev_data->num_regs_read >=
2475 s_platform_defs[dev_data->platform_id].log_thresh) {
2476 DP_VERBOSE(p_hwfn,
2477 QED_MSG_DEBUG,
2478 "Dumping %d registers...\n",
2479 dev_data->num_regs_read);
2480 dev_data->num_regs_read = 0;
2481 }
2482
2483 /* Try reading using DMAE */
2484 if (dev_data->use_dmae &&
2485 (len >= s_platform_defs[dev_data->platform_id].dmae_thresh ||
2486 wide_bus)) {
2487 if (!qed_dmae_grc2host(p_hwfn, p_ptt, DWORDS_TO_BYTES(addr),
2488 (u64)(uintptr_t)(dump_buf), len, 0))
2489 return len;
2490 dev_data->use_dmae = 0;
2491 DP_VERBOSE(p_hwfn,
2492 QED_MSG_DEBUG,
2493 "Failed reading from chip using DMAE, using GRC instead\n");
2494 }
2495
2496 /* Read registers */
2497 qed_read_regs(p_hwfn, p_ptt, dump_buf, addr, len);
2498
2499 return len;
2500}
2501
2502/* Dumps GRC registers sequence header. Returns the dumped size in dwords.
2503 * The addr and len arguments are specified in dwords.
2504 */
2505static u32 qed_grc_dump_reg_entry_hdr(u32 *dump_buf,
2506 bool dump, u32 addr, u32 len)
2507{
2508 if (dump)
2509 *dump_buf = addr | (len << REG_DUMP_LEN_SHIFT);
2510
2511 return 1;
2512}
2513
2514/* Dumps GRC registers sequence. Returns the dumped size in dwords.
2515 * The addr and len arguments are specified in dwords.
2516 */
2517static u32 qed_grc_dump_reg_entry(struct qed_hwfn *p_hwfn,
2518 struct qed_ptt *p_ptt,
2519 u32 *dump_buf,
2520 bool dump, u32 addr, u32 len, bool wide_bus)
2521{
2522 u32 offset = 0;
2523
2524 offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, len);
2525 offset += qed_grc_dump_addr_range(p_hwfn,
2526 p_ptt,
2527 dump_buf + offset,
2528 dump, addr, len, wide_bus);
2529
2530 return offset;
2531}
2532
2533/* Dumps GRC registers sequence with skip cycle.
2534 * Returns the dumped size in dwords.
2535 * - addr: start GRC address in dwords
2536 * - total_len: total no. of dwords to dump
2537 * - read_len: no. consecutive dwords to read
2538 * - skip_len: no. of dwords to skip (and fill with zeros)
2539 */
2540static u32 qed_grc_dump_reg_entry_skip(struct qed_hwfn *p_hwfn,
2541 struct qed_ptt *p_ptt,
2542 u32 *dump_buf,
2543 bool dump,
2544 u32 addr,
2545 u32 total_len,
2546 u32 read_len, u32 skip_len)
2547{
2548 u32 offset = 0, reg_offset = 0;
2549
2550 offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, total_len);
2551
2552 if (!dump)
2553 return offset + total_len;
2554
2555 while (reg_offset < total_len) {
2556 u32 curr_len = min_t(u32, read_len, total_len - reg_offset);
2557
2558 offset += qed_grc_dump_addr_range(p_hwfn,
2559 p_ptt,
2560 dump_buf + offset,
2561 dump, addr, curr_len, false);
2562 reg_offset += curr_len;
2563 addr += curr_len;
2564
2565 if (reg_offset < total_len) {
2566 curr_len = min_t(u32, skip_len, total_len - skip_len);
2567 memset(dump_buf + offset, 0, DWORDS_TO_BYTES(curr_len));
2568 offset += curr_len;
2569 reg_offset += curr_len;
2570 addr += curr_len;
2571 }
2572 }
2573
2574 return offset;
2575}
2576
2577/* Dumps GRC registers entries. Returns the dumped size in dwords. */
2578static u32 qed_grc_dump_regs_entries(struct qed_hwfn *p_hwfn,
2579 struct qed_ptt *p_ptt,
2580 struct dbg_array input_regs_arr,
2581 u32 *dump_buf,
2582 bool dump,
2583 bool block_enable[MAX_BLOCK_ID],
2584 u32 *num_dumped_reg_entries)
2585{
2586 u32 i, offset = 0, input_offset = 0;
2587 bool mode_match = true;
2588
2589 *num_dumped_reg_entries = 0;
2590
2591 while (input_offset < input_regs_arr.size_in_dwords) {
2592 const struct dbg_dump_cond_hdr *cond_hdr =
2593 (const struct dbg_dump_cond_hdr *)
2594 &input_regs_arr.ptr[input_offset++];
2595 u16 modes_buf_offset;
2596 bool eval_mode;
2597
2598 /* Check mode/block */
2599 eval_mode = GET_FIELD(cond_hdr->mode.data,
2600 DBG_MODE_HDR_EVAL_MODE) > 0;
2601 if (eval_mode) {
2602 modes_buf_offset =
2603 GET_FIELD(cond_hdr->mode.data,
2604 DBG_MODE_HDR_MODES_BUF_OFFSET);
2605 mode_match = qed_is_mode_match(p_hwfn,
2606 &modes_buf_offset);
2607 }
2608
2609 if (!mode_match || !block_enable[cond_hdr->block_id]) {
2610 input_offset += cond_hdr->data_size;
2611 continue;
2612 }
2613
2614 for (i = 0; i < cond_hdr->data_size; i++, input_offset++) {
2615 const struct dbg_dump_reg *reg =
2616 (const struct dbg_dump_reg *)
2617 &input_regs_arr.ptr[input_offset];
2618 u32 addr, len;
2619 bool wide_bus;
2620
2621 addr = GET_FIELD(reg->data, DBG_DUMP_REG_ADDRESS);
2622 len = GET_FIELD(reg->data, DBG_DUMP_REG_LENGTH);
2623 wide_bus = GET_FIELD(reg->data, DBG_DUMP_REG_WIDE_BUS);
2624 offset += qed_grc_dump_reg_entry(p_hwfn,
2625 p_ptt,
2626 dump_buf + offset,
2627 dump,
2628 addr,
2629 len,
2630 wide_bus);
2631 (*num_dumped_reg_entries)++;
2632 }
2633 }
2634
2635 return offset;
2636}
2637
2638/* Dumps GRC registers entries. Returns the dumped size in dwords. */
2639static u32 qed_grc_dump_split_data(struct qed_hwfn *p_hwfn,
2640 struct qed_ptt *p_ptt,
2641 struct dbg_array input_regs_arr,
2642 u32 *dump_buf,
2643 bool dump,
2644 bool block_enable[MAX_BLOCK_ID],
2645 const char *split_type_name,
2646 u32 split_id,
2647 const char *param_name,
2648 const char *param_val)
2649{
2650 u32 num_dumped_reg_entries, offset;
2651
2652 /* Calculate register dump header size (and skip it for now) */
2653 offset = qed_grc_dump_regs_hdr(dump_buf,
2654 false,
2655 0,
2656 split_type_name,
2657 split_id, param_name, param_val);
2658
2659 /* Dump registers */
2660 offset += qed_grc_dump_regs_entries(p_hwfn,
2661 p_ptt,
2662 input_regs_arr,
2663 dump_buf + offset,
2664 dump,
2665 block_enable,
2666 &num_dumped_reg_entries);
2667
2668 /* Write register dump header */
2669 if (dump && num_dumped_reg_entries > 0)
2670 qed_grc_dump_regs_hdr(dump_buf,
2671 dump,
2672 num_dumped_reg_entries,
2673 split_type_name,
2674 split_id, param_name, param_val);
2675
2676 return num_dumped_reg_entries > 0 ? offset : 0;
2677}
2678
2679/* Dumps registers according to the input registers array. Returns the dumped
2680 * size in dwords.
2681 */
2682static u32 qed_grc_dump_registers(struct qed_hwfn *p_hwfn,
2683 struct qed_ptt *p_ptt,
2684 u32 *dump_buf,
2685 bool dump,
2686 bool block_enable[MAX_BLOCK_ID],
2687 const char *param_name, const char *param_val)
2688{
2689 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2690 struct chip_platform_defs *chip_platform;
2691 u32 offset = 0, input_offset = 0;
2692 struct chip_defs *chip;
2693 u8 port_id, pf_id, vf_id;
2694 u16 fid;
2695
2696 chip = &s_chip_defs[dev_data->chip_id];
2697 chip_platform = &chip->per_platform[dev_data->platform_id];
2698
2699 while (input_offset <
2700 s_dbg_arrays[BIN_BUF_DBG_DUMP_REG].size_in_dwords) {
2701 const struct dbg_dump_split_hdr *split_hdr;
2702 struct dbg_array curr_input_regs_arr;
2703 u32 split_data_size;
2704 u8 split_type_id;
2705
2706 split_hdr =
2707 (const struct dbg_dump_split_hdr *)
2708 &s_dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr[input_offset++];
2709 split_type_id =
2710 GET_FIELD(split_hdr->hdr,
2711 DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
2712 split_data_size =
2713 GET_FIELD(split_hdr->hdr,
2714 DBG_DUMP_SPLIT_HDR_DATA_SIZE);
2715 curr_input_regs_arr.ptr =
2716 &s_dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr[input_offset];
2717 curr_input_regs_arr.size_in_dwords = split_data_size;
2718
2719 switch (split_type_id) {
2720 case SPLIT_TYPE_NONE:
2721 offset += qed_grc_dump_split_data(p_hwfn,
2722 p_ptt,
2723 curr_input_regs_arr,
2724 dump_buf + offset,
2725 dump,
2726 block_enable,
2727 "eng",
2728 (u32)(-1),
2729 param_name,
2730 param_val);
2731 break;
2732
2733 case SPLIT_TYPE_PORT:
2734 for (port_id = 0; port_id < chip_platform->num_ports;
2735 port_id++) {
2736 if (dump)
2737 qed_port_pretend(p_hwfn, p_ptt,
2738 port_id);
2739 offset +=
2740 qed_grc_dump_split_data(p_hwfn, p_ptt,
2741 curr_input_regs_arr,
2742 dump_buf + offset,
2743 dump, block_enable,
2744 "port", port_id,
2745 param_name,
2746 param_val);
2747 }
2748 break;
2749
2750 case SPLIT_TYPE_PF:
2751 case SPLIT_TYPE_PORT_PF:
2752 for (pf_id = 0; pf_id < chip_platform->num_pfs;
2753 pf_id++) {
2754 u8 pfid_shift =
2755 PXP_PRETEND_CONCRETE_FID_PFID_SHIFT;
2756
2757 if (dump) {
2758 fid = pf_id << pfid_shift;
2759 qed_fid_pretend(p_hwfn, p_ptt, fid);
2760 }
2761
2762 offset +=
2763 qed_grc_dump_split_data(p_hwfn,
2764 p_ptt,
2765 curr_input_regs_arr,
2766 dump_buf + offset,
2767 dump,
2768 block_enable,
2769 "pf",
2770 pf_id,
2771 param_name,
2772 param_val);
2773 }
2774 break;
2775
2776 case SPLIT_TYPE_VF:
2777 for (vf_id = 0; vf_id < chip_platform->num_vfs;
2778 vf_id++) {
2779 u8 vfvalid_shift =
2780 PXP_PRETEND_CONCRETE_FID_VFVALID_SHIFT;
2781 u8 vfid_shift =
2782 PXP_PRETEND_CONCRETE_FID_VFID_SHIFT;
2783
2784 if (dump) {
2785 fid = BIT(vfvalid_shift) |
2786 (vf_id << vfid_shift);
2787 qed_fid_pretend(p_hwfn, p_ptt, fid);
2788 }
2789
2790 offset +=
2791 qed_grc_dump_split_data(p_hwfn, p_ptt,
2792 curr_input_regs_arr,
2793 dump_buf + offset,
2794 dump, block_enable,
2795 "vf", vf_id,
2796 param_name,
2797 param_val);
2798 }
2799 break;
2800
2801 default:
2802 break;
2803 }
2804
2805 input_offset += split_data_size;
2806 }
2807
2808 /* Pretend to original PF */
2809 if (dump) {
2810 fid = p_hwfn->rel_pf_id << PXP_PRETEND_CONCRETE_FID_PFID_SHIFT;
2811 qed_fid_pretend(p_hwfn, p_ptt, fid);
2812 }
2813
2814 return offset;
2815}
2816
2817/* Dump reset registers. Returns the dumped size in dwords. */
2818static u32 qed_grc_dump_reset_regs(struct qed_hwfn *p_hwfn,
2819 struct qed_ptt *p_ptt,
2820 u32 *dump_buf, bool dump)
2821{
2822 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2823 u32 i, offset = 0, num_regs = 0;
2824
2825 /* Calculate header size */
2826 offset += qed_grc_dump_regs_hdr(dump_buf,
2827 false, 0, "eng", -1, NULL, NULL);
2828
2829 /* Write reset registers */
2830 for (i = 0; i < MAX_DBG_RESET_REGS; i++) {
2831 if (!s_reset_regs_defs[i].exists[dev_data->chip_id])
2832 continue;
2833
2834 offset += qed_grc_dump_reg_entry(p_hwfn,
2835 p_ptt,
2836 dump_buf + offset,
2837 dump,
2838 BYTES_TO_DWORDS
2839 (s_reset_regs_defs[i].addr), 1,
2840 false);
2841 num_regs++;
2842 }
2843
2844 /* Write header */
2845 if (dump)
2846 qed_grc_dump_regs_hdr(dump_buf,
2847 true, num_regs, "eng", -1, NULL, NULL);
2848
2849 return offset;
2850}
2851
2852/* Dump registers that are modified during GRC Dump and therefore must be
2853 * dumped first. Returns the dumped size in dwords.
2854 */
2855static u32 qed_grc_dump_modified_regs(struct qed_hwfn *p_hwfn,
2856 struct qed_ptt *p_ptt,
2857 u32 *dump_buf, bool dump)
2858{
2859 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
2860 u32 block_id, offset = 0, num_reg_entries = 0;
2861 const struct dbg_attn_reg *attn_reg_arr;
2862 u8 storm_id, reg_idx, num_attn_regs;
2863
2864 /* Calculate header size */
2865 offset += qed_grc_dump_regs_hdr(dump_buf,
2866 false, 0, "eng", -1, NULL, NULL);
2867
2868 /* Write parity registers */
2869 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
2870 if (dev_data->block_in_reset[block_id] && dump)
2871 continue;
2872
2873 attn_reg_arr = qed_get_block_attn_regs((enum block_id)block_id,
2874 ATTN_TYPE_PARITY,
2875 &num_attn_regs);
2876
2877 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
2878 const struct dbg_attn_reg *reg_data =
2879 &attn_reg_arr[reg_idx];
2880 u16 modes_buf_offset;
2881 bool eval_mode;
2882 u32 addr;
2883
2884 /* Check mode */
2885 eval_mode = GET_FIELD(reg_data->mode.data,
2886 DBG_MODE_HDR_EVAL_MODE) > 0;
2887 modes_buf_offset =
2888 GET_FIELD(reg_data->mode.data,
2889 DBG_MODE_HDR_MODES_BUF_OFFSET);
2890 if (eval_mode &&
2891 !qed_is_mode_match(p_hwfn, &modes_buf_offset))
2892 continue;
2893
2894 /* Mode match: read & dump registers */
2895 addr = reg_data->mask_address;
2896 offset += qed_grc_dump_reg_entry(p_hwfn,
2897 p_ptt,
2898 dump_buf + offset,
2899 dump,
2900 addr,
2901 1, false);
2902 addr = GET_FIELD(reg_data->data,
2903 DBG_ATTN_REG_STS_ADDRESS);
2904 offset += qed_grc_dump_reg_entry(p_hwfn,
2905 p_ptt,
2906 dump_buf + offset,
2907 dump,
2908 addr,
2909 1, false);
2910 num_reg_entries += 2;
2911 }
2912 }
2913
2914 /* Write Storm stall status registers */
2915 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
2916 struct storm_defs *storm = &s_storm_defs[storm_id];
2917 u32 addr;
2918
2919 if (dev_data->block_in_reset[storm->block_id] && dump)
2920 continue;
2921
2922 addr =
2923 BYTES_TO_DWORDS(s_storm_defs[storm_id].sem_fast_mem_addr +
2924 SEM_FAST_REG_STALLED);
2925 offset += qed_grc_dump_reg_entry(p_hwfn,
2926 p_ptt,
2927 dump_buf + offset,
2928 dump,
2929 addr,
2930 1,
2931 false);
2932 num_reg_entries++;
2933 }
2934
2935 /* Write header */
2936 if (dump)
2937 qed_grc_dump_regs_hdr(dump_buf,
2938 true,
2939 num_reg_entries, "eng", -1, NULL, NULL);
2940
2941 return offset;
2942}
2943
2944/* Dumps registers that can't be represented in the debug arrays */
2945static u32 qed_grc_dump_special_regs(struct qed_hwfn *p_hwfn,
2946 struct qed_ptt *p_ptt,
2947 u32 *dump_buf, bool dump)
2948{
2949 u32 offset = 0, addr;
2950
2951 offset += qed_grc_dump_regs_hdr(dump_buf,
2952 dump, 2, "eng", -1, NULL, NULL);
2953
2954 /* Dump R/TDIF_REG_DEBUG_ERROR_INFO_SIZE (every 8'th register should be
2955 * skipped).
2956 */
2957 addr = BYTES_TO_DWORDS(RDIF_REG_DEBUG_ERROR_INFO);
2958 offset += qed_grc_dump_reg_entry_skip(p_hwfn,
2959 p_ptt,
2960 dump_buf + offset,
2961 dump,
2962 addr,
2963 RDIF_REG_DEBUG_ERROR_INFO_SIZE,
2964 7,
2965 1);
2966 addr = BYTES_TO_DWORDS(TDIF_REG_DEBUG_ERROR_INFO);
2967 offset +=
2968 qed_grc_dump_reg_entry_skip(p_hwfn,
2969 p_ptt,
2970 dump_buf + offset,
2971 dump,
2972 addr,
2973 TDIF_REG_DEBUG_ERROR_INFO_SIZE,
2974 7,
2975 1);
2976
2977 return offset;
2978}
2979
2980/* Dumps a GRC memory header (section and params). Returns the dumped size in
2981 * dwords. The following parameters are dumped:
2982 * - name: dumped only if it's not NULL.
2983 * - addr: in dwords, dumped only if name is NULL.
2984 * - len: in dwords, always dumped.
2985 * - width: dumped if it's not zero.
2986 * - packed: dumped only if it's not false.
2987 * - mem_group: always dumped.
2988 * - is_storm: true only if the memory is related to a Storm.
2989 * - storm_letter: valid only if is_storm is true.
2990 *
2991 */
2992static u32 qed_grc_dump_mem_hdr(struct qed_hwfn *p_hwfn,
2993 u32 *dump_buf,
2994 bool dump,
2995 const char *name,
2996 u32 addr,
2997 u32 len,
2998 u32 bit_width,
2999 bool packed,
3000 const char *mem_group,
3001 bool is_storm, char storm_letter)
3002{
3003 u8 num_params = 3;
3004 u32 offset = 0;
3005 char buf[64];
3006
3007 if (!len)
3008 DP_NOTICE(p_hwfn,
3009 "Unexpected GRC Dump error: dumped memory size must be non-zero\n");
3010
3011 if (bit_width)
3012 num_params++;
3013 if (packed)
3014 num_params++;
3015
3016 /* Dump section header */
3017 offset += qed_dump_section_hdr(dump_buf + offset,
3018 dump, "grc_mem", num_params);
3019
3020 if (name) {
3021 /* Dump name */
3022 if (is_storm) {
3023 strcpy(buf, "?STORM_");
3024 buf[0] = storm_letter;
3025 strcpy(buf + strlen(buf), name);
3026 } else {
3027 strcpy(buf, name);
3028 }
3029
3030 offset += qed_dump_str_param(dump_buf + offset,
3031 dump, "name", buf);
3032 } else {
3033 /* Dump address */
3034 u32 addr_in_bytes = DWORDS_TO_BYTES(addr);
3035
3036 offset += qed_dump_num_param(dump_buf + offset,
3037 dump, "addr", addr_in_bytes);
3038 }
3039
3040 /* Dump len */
3041 offset += qed_dump_num_param(dump_buf + offset, dump, "len", len);
3042
3043 /* Dump bit width */
3044 if (bit_width)
3045 offset += qed_dump_num_param(dump_buf + offset,
3046 dump, "width", bit_width);
3047
3048 /* Dump packed */
3049 if (packed)
3050 offset += qed_dump_num_param(dump_buf + offset,
3051 dump, "packed", 1);
3052
3053 /* Dump reg type */
3054 if (is_storm) {
3055 strcpy(buf, "?STORM_");
3056 buf[0] = storm_letter;
3057 strcpy(buf + strlen(buf), mem_group);
3058 } else {
3059 strcpy(buf, mem_group);
3060 }
3061
3062 offset += qed_dump_str_param(dump_buf + offset, dump, "type", buf);
3063
3064 return offset;
3065}
3066
3067/* Dumps a single GRC memory. If name is NULL, the memory is stored by address.
3068 * Returns the dumped size in dwords.
3069 * The addr and len arguments are specified in dwords.
3070 */
3071static u32 qed_grc_dump_mem(struct qed_hwfn *p_hwfn,
3072 struct qed_ptt *p_ptt,
3073 u32 *dump_buf,
3074 bool dump,
3075 const char *name,
3076 u32 addr,
3077 u32 len,
3078 bool wide_bus,
3079 u32 bit_width,
3080 bool packed,
3081 const char *mem_group,
3082 bool is_storm, char storm_letter)
3083{
3084 u32 offset = 0;
3085
3086 offset += qed_grc_dump_mem_hdr(p_hwfn,
3087 dump_buf + offset,
3088 dump,
3089 name,
3090 addr,
3091 len,
3092 bit_width,
3093 packed,
3094 mem_group, is_storm, storm_letter);
3095 offset += qed_grc_dump_addr_range(p_hwfn,
3096 p_ptt,
3097 dump_buf + offset,
3098 dump, addr, len, wide_bus);
3099
3100 return offset;
3101}
3102
3103/* Dumps GRC memories entries. Returns the dumped size in dwords. */
3104static u32 qed_grc_dump_mem_entries(struct qed_hwfn *p_hwfn,
3105 struct qed_ptt *p_ptt,
3106 struct dbg_array input_mems_arr,
3107 u32 *dump_buf, bool dump)
3108{
3109 u32 i, offset = 0, input_offset = 0;
3110 bool mode_match = true;
3111
3112 while (input_offset < input_mems_arr.size_in_dwords) {
3113 const struct dbg_dump_cond_hdr *cond_hdr;
3114 u16 modes_buf_offset;
3115 u32 num_entries;
3116 bool eval_mode;
3117
3118 cond_hdr = (const struct dbg_dump_cond_hdr *)
3119 &input_mems_arr.ptr[input_offset++];
3120 num_entries = cond_hdr->data_size / MEM_DUMP_ENTRY_SIZE_DWORDS;
3121
3122 /* Check required mode */
3123 eval_mode = GET_FIELD(cond_hdr->mode.data,
3124 DBG_MODE_HDR_EVAL_MODE) > 0;
3125 if (eval_mode) {
3126 modes_buf_offset =
3127 GET_FIELD(cond_hdr->mode.data,
3128 DBG_MODE_HDR_MODES_BUF_OFFSET);
3129 mode_match = qed_is_mode_match(p_hwfn,
3130 &modes_buf_offset);
3131 }
3132
3133 if (!mode_match) {
3134 input_offset += cond_hdr->data_size;
3135 continue;
3136 }
3137
3138 for (i = 0; i < num_entries;
3139 i++, input_offset += MEM_DUMP_ENTRY_SIZE_DWORDS) {
3140 const struct dbg_dump_mem *mem =
3141 (const struct dbg_dump_mem *)
3142 &input_mems_arr.ptr[input_offset];
3143 u8 mem_group_id = GET_FIELD(mem->dword0,
3144 DBG_DUMP_MEM_MEM_GROUP_ID);
3145 bool is_storm = false, mem_wide_bus;
3146 enum dbg_grc_params grc_param;
3147 char storm_letter = 'a';
3148 enum block_id block_id;
3149 u32 mem_addr, mem_len;
3150
3151 if (mem_group_id >= MEM_GROUPS_NUM) {
3152 DP_NOTICE(p_hwfn, "Invalid mem_group_id\n");
3153 return 0;
3154 }
3155
3156 block_id = (enum block_id)cond_hdr->block_id;
3157 if (!qed_grc_is_mem_included(p_hwfn,
3158 block_id,
3159 mem_group_id))
3160 continue;
3161
3162 mem_addr = GET_FIELD(mem->dword0, DBG_DUMP_MEM_ADDRESS);
3163 mem_len = GET_FIELD(mem->dword1, DBG_DUMP_MEM_LENGTH);
3164 mem_wide_bus = GET_FIELD(mem->dword1,
3165 DBG_DUMP_MEM_WIDE_BUS);
3166
3167 /* Update memory length for CCFC/TCFC memories
3168 * according to number of LCIDs/LTIDs.
3169 */
3170 if (mem_group_id == MEM_GROUP_CONN_CFC_MEM) {
3171 if (mem_len % MAX_LCIDS) {
3172 DP_NOTICE(p_hwfn,
3173 "Invalid CCFC connection memory size\n");
3174 return 0;
3175 }
3176
3177 grc_param = DBG_GRC_PARAM_NUM_LCIDS;
3178 mem_len = qed_grc_get_param(p_hwfn, grc_param) *
3179 (mem_len / MAX_LCIDS);
3180 } else if (mem_group_id == MEM_GROUP_TASK_CFC_MEM) {
3181 if (mem_len % MAX_LTIDS) {
3182 DP_NOTICE(p_hwfn,
3183 "Invalid TCFC task memory size\n");
3184 return 0;
3185 }
3186
3187 grc_param = DBG_GRC_PARAM_NUM_LTIDS;
3188 mem_len = qed_grc_get_param(p_hwfn, grc_param) *
3189 (mem_len / MAX_LTIDS);
3190 }
3191
3192 /* If memory is associated with Storm, update Storm
3193 * details.
3194 */
3195 if (s_block_defs
3196 [cond_hdr->block_id]->associated_to_storm) {
3197 is_storm = true;
3198 storm_letter =
3199 s_storm_defs[s_block_defs
3200 [cond_hdr->block_id]->
3201 storm_id].letter;
3202 }
3203
3204 /* Dump memory */
3205 offset += qed_grc_dump_mem(p_hwfn,
3206 p_ptt,
3207 dump_buf + offset,
3208 dump,
3209 NULL,
3210 mem_addr,
3211 mem_len,
3212 mem_wide_bus,
3213 0,
3214 false,
3215 s_mem_group_names[mem_group_id],
3216 is_storm,
3217 storm_letter);
3218 }
3219 }
3220
3221 return offset;
3222}
3223
3224/* Dumps GRC memories according to the input array dump_mem.
3225 * Returns the dumped size in dwords.
3226 */
3227static u32 qed_grc_dump_memories(struct qed_hwfn *p_hwfn,
3228 struct qed_ptt *p_ptt,
3229 u32 *dump_buf, bool dump)
3230{
3231 u32 offset = 0, input_offset = 0;
3232
3233 while (input_offset <
3234 s_dbg_arrays[BIN_BUF_DBG_DUMP_MEM].size_in_dwords) {
3235 const struct dbg_dump_split_hdr *split_hdr;
3236 struct dbg_array curr_input_mems_arr;
3237 u32 split_data_size;
3238 u8 split_type_id;
3239
3240 split_hdr = (const struct dbg_dump_split_hdr *)
3241 &s_dbg_arrays[BIN_BUF_DBG_DUMP_MEM].ptr[input_offset++];
3242 split_type_id =
3243 GET_FIELD(split_hdr->hdr,
3244 DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
3245 split_data_size =
3246 GET_FIELD(split_hdr->hdr,
3247 DBG_DUMP_SPLIT_HDR_DATA_SIZE);
3248 curr_input_mems_arr.ptr =
3249 &s_dbg_arrays[BIN_BUF_DBG_DUMP_MEM].ptr[input_offset];
3250 curr_input_mems_arr.size_in_dwords = split_data_size;
3251
3252 switch (split_type_id) {
3253 case SPLIT_TYPE_NONE:
3254 offset += qed_grc_dump_mem_entries(p_hwfn,
3255 p_ptt,
3256 curr_input_mems_arr,
3257 dump_buf + offset,
3258 dump);
3259 break;
3260
3261 default:
3262 DP_NOTICE(p_hwfn,
3263 "Dumping split memories is currently not supported\n");
3264 break;
3265 }
3266
3267 input_offset += split_data_size;
3268 }
3269
3270 return offset;
3271}
3272
3273/* Dumps GRC context data for the specified Storm.
3274 * Returns the dumped size in dwords.
3275 * The lid_size argument is specified in quad-regs.
3276 */
3277static u32 qed_grc_dump_ctx_data(struct qed_hwfn *p_hwfn,
3278 struct qed_ptt *p_ptt,
3279 u32 *dump_buf,
3280 bool dump,
3281 const char *name,
3282 u32 num_lids,
3283 u32 lid_size,
3284 u32 rd_reg_addr,
3285 u8 storm_id)
3286{
3287 struct storm_defs *storm = &s_storm_defs[storm_id];
3288 u32 i, lid, total_size, offset = 0;
3289
3290 if (!lid_size)
3291 return 0;
3292
3293 lid_size *= BYTES_IN_DWORD;
3294 total_size = num_lids * lid_size;
3295
3296 offset += qed_grc_dump_mem_hdr(p_hwfn,
3297 dump_buf + offset,
3298 dump,
3299 name,
3300 0,
3301 total_size,
3302 lid_size * 32,
3303 false, name, true, storm->letter);
3304
3305 if (!dump)
3306 return offset + total_size;
3307
3308 /* Dump context data */
3309 for (lid = 0; lid < num_lids; lid++) {
3310 for (i = 0; i < lid_size; i++, offset++) {
3311 qed_wr(p_hwfn,
3312 p_ptt, storm->cm_ctx_wr_addr, (i << 9) | lid);
3313 *(dump_buf + offset) = qed_rd(p_hwfn,
3314 p_ptt, rd_reg_addr);
3315 }
3316 }
3317
3318 return offset;
3319}
3320
3321/* Dumps GRC contexts. Returns the dumped size in dwords. */
3322static u32 qed_grc_dump_ctx(struct qed_hwfn *p_hwfn,
3323 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3324{
3325 enum dbg_grc_params grc_param;
3326 u32 offset = 0;
3327 u8 storm_id;
3328
3329 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
3330 struct storm_defs *storm = &s_storm_defs[storm_id];
3331
3332 if (!qed_grc_is_storm_included(p_hwfn,
3333 (enum dbg_storms)storm_id))
3334 continue;
3335
3336 /* Dump Conn AG context size */
3337 grc_param = DBG_GRC_PARAM_NUM_LCIDS;
3338 offset +=
3339 qed_grc_dump_ctx_data(p_hwfn,
3340 p_ptt,
3341 dump_buf + offset,
3342 dump,
3343 "CONN_AG_CTX",
3344 qed_grc_get_param(p_hwfn,
3345 grc_param),
3346 storm->cm_conn_ag_ctx_lid_size,
3347 storm->cm_conn_ag_ctx_rd_addr,
3348 storm_id);
3349
3350 /* Dump Conn ST context size */
3351 grc_param = DBG_GRC_PARAM_NUM_LCIDS;
3352 offset +=
3353 qed_grc_dump_ctx_data(p_hwfn,
3354 p_ptt,
3355 dump_buf + offset,
3356 dump,
3357 "CONN_ST_CTX",
3358 qed_grc_get_param(p_hwfn,
3359 grc_param),
3360 storm->cm_conn_st_ctx_lid_size,
3361 storm->cm_conn_st_ctx_rd_addr,
3362 storm_id);
3363
3364 /* Dump Task AG context size */
3365 grc_param = DBG_GRC_PARAM_NUM_LTIDS;
3366 offset +=
3367 qed_grc_dump_ctx_data(p_hwfn,
3368 p_ptt,
3369 dump_buf + offset,
3370 dump,
3371 "TASK_AG_CTX",
3372 qed_grc_get_param(p_hwfn,
3373 grc_param),
3374 storm->cm_task_ag_ctx_lid_size,
3375 storm->cm_task_ag_ctx_rd_addr,
3376 storm_id);
3377
3378 /* Dump Task ST context size */
3379 grc_param = DBG_GRC_PARAM_NUM_LTIDS;
3380 offset +=
3381 qed_grc_dump_ctx_data(p_hwfn,
3382 p_ptt,
3383 dump_buf + offset,
3384 dump,
3385 "TASK_ST_CTX",
3386 qed_grc_get_param(p_hwfn,
3387 grc_param),
3388 storm->cm_task_st_ctx_lid_size,
3389 storm->cm_task_st_ctx_rd_addr,
3390 storm_id);
3391 }
3392
3393 return offset;
3394}
3395
3396/* Dumps GRC IORs data. Returns the dumped size in dwords. */
3397static u32 qed_grc_dump_iors(struct qed_hwfn *p_hwfn,
3398 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3399{
3400 char buf[10] = "IOR_SET_?";
3401 u32 addr, offset = 0;
3402 u8 storm_id, set_id;
3403
3404 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
3405 struct storm_defs *storm = &s_storm_defs[storm_id];
3406
3407 if (!qed_grc_is_storm_included(p_hwfn,
3408 (enum dbg_storms)storm_id))
3409 continue;
3410
3411 for (set_id = 0; set_id < NUM_IOR_SETS; set_id++) {
3412 addr = BYTES_TO_DWORDS(storm->sem_fast_mem_addr +
3413 SEM_FAST_REG_STORM_REG_FILE) +
3414 IOR_SET_OFFSET(set_id);
3415 buf[strlen(buf) - 1] = '0' + set_id;
3416 offset += qed_grc_dump_mem(p_hwfn,
3417 p_ptt,
3418 dump_buf + offset,
3419 dump,
3420 buf,
3421 addr,
3422 IORS_PER_SET,
3423 false,
3424 32,
3425 false,
3426 "ior",
3427 true,
3428 storm->letter);
3429 }
3430 }
3431
3432 return offset;
3433}
3434
3435/* Dump VFC CAM. Returns the dumped size in dwords. */
3436static u32 qed_grc_dump_vfc_cam(struct qed_hwfn *p_hwfn,
3437 struct qed_ptt *p_ptt,
3438 u32 *dump_buf, bool dump, u8 storm_id)
3439{
3440 u32 total_size = VFC_CAM_NUM_ROWS * VFC_CAM_RESP_DWORDS;
3441 struct storm_defs *storm = &s_storm_defs[storm_id];
3442 u32 cam_addr[VFC_CAM_ADDR_DWORDS] = { 0 };
3443 u32 cam_cmd[VFC_CAM_CMD_DWORDS] = { 0 };
3444 u32 row, i, offset = 0;
3445
3446 offset += qed_grc_dump_mem_hdr(p_hwfn,
3447 dump_buf + offset,
3448 dump,
3449 "vfc_cam",
3450 0,
3451 total_size,
3452 256,
3453 false, "vfc_cam", true, storm->letter);
3454
3455 if (!dump)
3456 return offset + total_size;
3457
3458 /* Prepare CAM address */
3459 SET_VAR_FIELD(cam_addr, VFC_CAM_ADDR, OP, VFC_OPCODE_CAM_RD);
3460
3461 for (row = 0; row < VFC_CAM_NUM_ROWS;
3462 row++, offset += VFC_CAM_RESP_DWORDS) {
3463 /* Write VFC CAM command */
3464 SET_VAR_FIELD(cam_cmd, VFC_CAM_CMD, ROW, row);
3465 ARR_REG_WR(p_hwfn,
3466 p_ptt,
3467 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_DATA_WR,
3468 cam_cmd, VFC_CAM_CMD_DWORDS);
3469
3470 /* Write VFC CAM address */
3471 ARR_REG_WR(p_hwfn,
3472 p_ptt,
3473 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_ADDR,
3474 cam_addr, VFC_CAM_ADDR_DWORDS);
3475
3476 /* Read VFC CAM read response */
3477 ARR_REG_RD(p_hwfn,
3478 p_ptt,
3479 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_DATA_RD,
3480 dump_buf + offset, VFC_CAM_RESP_DWORDS);
3481 }
3482
3483 return offset;
3484}
3485
3486/* Dump VFC RAM. Returns the dumped size in dwords. */
3487static u32 qed_grc_dump_vfc_ram(struct qed_hwfn *p_hwfn,
3488 struct qed_ptt *p_ptt,
3489 u32 *dump_buf,
3490 bool dump,
3491 u8 storm_id, struct vfc_ram_defs *ram_defs)
3492{
3493 u32 total_size = ram_defs->num_rows * VFC_RAM_RESP_DWORDS;
3494 struct storm_defs *storm = &s_storm_defs[storm_id];
3495 u32 ram_addr[VFC_RAM_ADDR_DWORDS] = { 0 };
3496 u32 ram_cmd[VFC_RAM_CMD_DWORDS] = { 0 };
3497 u32 row, i, offset = 0;
3498
3499 offset += qed_grc_dump_mem_hdr(p_hwfn,
3500 dump_buf + offset,
3501 dump,
3502 ram_defs->mem_name,
3503 0,
3504 total_size,
3505 256,
3506 false,
3507 ram_defs->type_name,
3508 true, storm->letter);
3509
3510 /* Prepare RAM address */
3511 SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, OP, VFC_OPCODE_RAM_RD);
3512
3513 if (!dump)
3514 return offset + total_size;
3515
3516 for (row = ram_defs->base_row;
3517 row < ram_defs->base_row + ram_defs->num_rows;
3518 row++, offset += VFC_RAM_RESP_DWORDS) {
3519 /* Write VFC RAM command */
3520 ARR_REG_WR(p_hwfn,
3521 p_ptt,
3522 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_DATA_WR,
3523 ram_cmd, VFC_RAM_CMD_DWORDS);
3524
3525 /* Write VFC RAM address */
3526 SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, ROW, row);
3527 ARR_REG_WR(p_hwfn,
3528 p_ptt,
3529 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_ADDR,
3530 ram_addr, VFC_RAM_ADDR_DWORDS);
3531
3532 /* Read VFC RAM read response */
3533 ARR_REG_RD(p_hwfn,
3534 p_ptt,
3535 storm->sem_fast_mem_addr + SEM_FAST_REG_VFC_DATA_RD,
3536 dump_buf + offset, VFC_RAM_RESP_DWORDS);
3537 }
3538
3539 return offset;
3540}
3541
3542/* Dumps GRC VFC data. Returns the dumped size in dwords. */
3543static u32 qed_grc_dump_vfc(struct qed_hwfn *p_hwfn,
3544 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3545{
3546 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3547 u8 storm_id, i;
3548 u32 offset = 0;
3549
3550 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
3551 if (!qed_grc_is_storm_included(p_hwfn,
3552 (enum dbg_storms)storm_id) ||
3553 !s_storm_defs[storm_id].has_vfc ||
3554 (storm_id == DBG_PSTORM_ID && dev_data->platform_id !=
3555 PLATFORM_ASIC))
3556 continue;
3557
3558 /* Read CAM */
3559 offset += qed_grc_dump_vfc_cam(p_hwfn,
3560 p_ptt,
3561 dump_buf + offset,
3562 dump, storm_id);
3563
3564 /* Read RAM */
3565 for (i = 0; i < NUM_VFC_RAM_TYPES; i++)
3566 offset += qed_grc_dump_vfc_ram(p_hwfn,
3567 p_ptt,
3568 dump_buf + offset,
3569 dump,
3570 storm_id,
3571 &s_vfc_ram_defs[i]);
3572 }
3573
3574 return offset;
3575}
3576
3577/* Dumps GRC RSS data. Returns the dumped size in dwords. */
3578static u32 qed_grc_dump_rss(struct qed_hwfn *p_hwfn,
3579 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3580{
3581 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3582 u32 offset = 0;
3583 u8 rss_mem_id;
3584
3585 for (rss_mem_id = 0; rss_mem_id < NUM_RSS_MEM_TYPES; rss_mem_id++) {
3586 u32 rss_addr, num_entries, total_dwords;
3587 struct rss_mem_defs *rss_defs;
3588 u32 addr, num_dwords_to_read;
3589 bool packed;
3590
3591 rss_defs = &s_rss_mem_defs[rss_mem_id];
3592 rss_addr = rss_defs->addr;
3593 num_entries = rss_defs->num_entries[dev_data->chip_id];
3594 total_dwords = (num_entries * rss_defs->entry_width) / 32;
3595 packed = (rss_defs->entry_width == 16);
3596
3597 offset += qed_grc_dump_mem_hdr(p_hwfn,
3598 dump_buf + offset,
3599 dump,
3600 rss_defs->mem_name,
3601 0,
3602 total_dwords,
3603 rss_defs->entry_width,
3604 packed,
3605 rss_defs->type_name, false, 0);
3606
3607 /* Dump RSS data */
3608 if (!dump) {
3609 offset += total_dwords;
3610 continue;
3611 }
3612
3613 addr = BYTES_TO_DWORDS(RSS_REG_RSS_RAM_DATA);
3614 while (total_dwords) {
3615 num_dwords_to_read = min_t(u32,
3616 RSS_REG_RSS_RAM_DATA_SIZE,
3617 total_dwords);
3618 qed_wr(p_hwfn, p_ptt, RSS_REG_RSS_RAM_ADDR, rss_addr);
3619 offset += qed_grc_dump_addr_range(p_hwfn,
3620 p_ptt,
3621 dump_buf + offset,
3622 dump,
3623 addr,
3624 num_dwords_to_read,
3625 false);
3626 total_dwords -= num_dwords_to_read;
3627 rss_addr++;
3628 }
3629 }
3630
3631 return offset;
3632}
3633
3634/* Dumps GRC Big RAM. Returns the dumped size in dwords. */
3635static u32 qed_grc_dump_big_ram(struct qed_hwfn *p_hwfn,
3636 struct qed_ptt *p_ptt,
3637 u32 *dump_buf, bool dump, u8 big_ram_id)
3638{
3639 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3640 u32 block_size, ram_size, offset = 0, reg_val, i;
3641 char mem_name[12] = "???_BIG_RAM";
3642 char type_name[8] = "???_RAM";
3643 struct big_ram_defs *big_ram;
3644
3645 big_ram = &s_big_ram_defs[big_ram_id];
3646 ram_size = big_ram->ram_size[dev_data->chip_id];
3647
3648 reg_val = qed_rd(p_hwfn, p_ptt, big_ram->is_256b_reg_addr);
3649 block_size = reg_val &
3650 BIT(big_ram->is_256b_bit_offset[dev_data->chip_id]) ? 256
3651 : 128;
3652
3653 strscpy(type_name, big_ram->instance_name, sizeof(type_name));
3654 strscpy(mem_name, big_ram->instance_name, sizeof(mem_name));
3655
3656 /* Dump memory header */
3657 offset += qed_grc_dump_mem_hdr(p_hwfn,
3658 dump_buf + offset,
3659 dump,
3660 mem_name,
3661 0,
3662 ram_size,
3663 block_size * 8,
3664 false, type_name, false, 0);
3665
3666 /* Read and dump Big RAM data */
3667 if (!dump)
3668 return offset + ram_size;
3669
3670 /* Dump Big RAM */
3671 for (i = 0; i < DIV_ROUND_UP(ram_size, BRB_REG_BIG_RAM_DATA_SIZE);
3672 i++) {
3673 u32 addr, len;
3674
3675 qed_wr(p_hwfn, p_ptt, big_ram->addr_reg_addr, i);
3676 addr = BYTES_TO_DWORDS(big_ram->data_reg_addr);
3677 len = BRB_REG_BIG_RAM_DATA_SIZE;
3678 offset += qed_grc_dump_addr_range(p_hwfn,
3679 p_ptt,
3680 dump_buf + offset,
3681 dump,
3682 addr,
3683 len,
3684 false);
3685 }
3686
3687 return offset;
3688}
3689
3690static u32 qed_grc_dump_mcp(struct qed_hwfn *p_hwfn,
3691 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3692{
3693 bool block_enable[MAX_BLOCK_ID] = { 0 };
3694 u32 offset = 0, addr;
3695 bool halted = false;
3696
3697 /* Halt MCP */
3698 if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
3699 halted = !qed_mcp_halt(p_hwfn, p_ptt);
3700 if (!halted)
3701 DP_NOTICE(p_hwfn, "MCP halt failed!\n");
3702 }
3703
3704 /* Dump MCP scratchpad */
3705 offset += qed_grc_dump_mem(p_hwfn,
3706 p_ptt,
3707 dump_buf + offset,
3708 dump,
3709 NULL,
3710 BYTES_TO_DWORDS(MCP_REG_SCRATCH),
3711 MCP_REG_SCRATCH_SIZE_BB_K2,
3712 false, 0, false, "MCP", false, 0);
3713
3714 /* Dump MCP cpu_reg_file */
3715 offset += qed_grc_dump_mem(p_hwfn,
3716 p_ptt,
3717 dump_buf + offset,
3718 dump,
3719 NULL,
3720 BYTES_TO_DWORDS(MCP_REG_CPU_REG_FILE),
3721 MCP_REG_CPU_REG_FILE_SIZE,
3722 false, 0, false, "MCP", false, 0);
3723
3724 /* Dump MCP registers */
3725 block_enable[BLOCK_MCP] = true;
3726 offset += qed_grc_dump_registers(p_hwfn,
3727 p_ptt,
3728 dump_buf + offset,
3729 dump, block_enable, "block", "MCP");
3730
3731 /* Dump required non-MCP registers */
3732 offset += qed_grc_dump_regs_hdr(dump_buf + offset,
3733 dump, 1, "eng", -1, "block", "MCP");
3734 addr = BYTES_TO_DWORDS(MISC_REG_SHARED_MEM_ADDR);
3735 offset += qed_grc_dump_reg_entry(p_hwfn,
3736 p_ptt,
3737 dump_buf + offset,
3738 dump,
3739 addr,
3740 1,
3741 false);
3742
3743 /* Release MCP */
3744 if (halted && qed_mcp_resume(p_hwfn, p_ptt))
3745 DP_NOTICE(p_hwfn, "Failed to resume MCP after halt!\n");
3746
3747 return offset;
3748}
3749
3750/* Dumps the tbus indirect memory for all PHYs. */
3751static u32 qed_grc_dump_phy(struct qed_hwfn *p_hwfn,
3752 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
3753{
3754 u32 offset = 0, tbus_lo_offset, tbus_hi_offset;
3755 char mem_name[32];
3756 u8 phy_id;
3757
3758 for (phy_id = 0; phy_id < ARRAY_SIZE(s_phy_defs); phy_id++) {
3759 u32 addr_lo_addr, addr_hi_addr, data_lo_addr, data_hi_addr;
3760 struct phy_defs *phy_defs;
3761 u8 *bytes_buf;
3762
3763 phy_defs = &s_phy_defs[phy_id];
3764 addr_lo_addr = phy_defs->base_addr +
3765 phy_defs->tbus_addr_lo_addr;
3766 addr_hi_addr = phy_defs->base_addr +
3767 phy_defs->tbus_addr_hi_addr;
3768 data_lo_addr = phy_defs->base_addr +
3769 phy_defs->tbus_data_lo_addr;
3770 data_hi_addr = phy_defs->base_addr +
3771 phy_defs->tbus_data_hi_addr;
3772
3773 if (snprintf(mem_name, sizeof(mem_name), "tbus_%s",
3774 phy_defs->phy_name) < 0)
3775 DP_NOTICE(p_hwfn,
3776 "Unexpected debug error: invalid PHY memory name\n");
3777
3778 offset += qed_grc_dump_mem_hdr(p_hwfn,
3779 dump_buf + offset,
3780 dump,
3781 mem_name,
3782 0,
3783 PHY_DUMP_SIZE_DWORDS,
3784 16, true, mem_name, false, 0);
3785
3786 if (!dump) {
3787 offset += PHY_DUMP_SIZE_DWORDS;
3788 continue;
3789 }
3790
3791 bytes_buf = (u8 *)(dump_buf + offset);
3792 for (tbus_hi_offset = 0;
3793 tbus_hi_offset < (NUM_PHY_TBUS_ADDRESSES >> 8);
3794 tbus_hi_offset++) {
3795 qed_wr(p_hwfn, p_ptt, addr_hi_addr, tbus_hi_offset);
3796 for (tbus_lo_offset = 0; tbus_lo_offset < 256;
3797 tbus_lo_offset++) {
3798 qed_wr(p_hwfn,
3799 p_ptt, addr_lo_addr, tbus_lo_offset);
3800 *(bytes_buf++) = (u8)qed_rd(p_hwfn,
3801 p_ptt,
3802 data_lo_addr);
3803 *(bytes_buf++) = (u8)qed_rd(p_hwfn,
3804 p_ptt,
3805 data_hi_addr);
3806 }
3807 }
3808
3809 offset += PHY_DUMP_SIZE_DWORDS;
3810 }
3811
3812 return offset;
3813}
3814
3815static void qed_config_dbg_line(struct qed_hwfn *p_hwfn,
3816 struct qed_ptt *p_ptt,
3817 enum block_id block_id,
3818 u8 line_id,
3819 u8 enable_mask,
3820 u8 right_shift,
3821 u8 force_valid_mask, u8 force_frame_mask)
3822{
3823 struct block_defs *block = s_block_defs[block_id];
3824
3825 qed_wr(p_hwfn, p_ptt, block->dbg_select_addr, line_id);
3826 qed_wr(p_hwfn, p_ptt, block->dbg_enable_addr, enable_mask);
3827 qed_wr(p_hwfn, p_ptt, block->dbg_shift_addr, right_shift);
3828 qed_wr(p_hwfn, p_ptt, block->dbg_force_valid_addr, force_valid_mask);
3829 qed_wr(p_hwfn, p_ptt, block->dbg_force_frame_addr, force_frame_mask);
3830}
3831
3832/* Dumps Static Debug data. Returns the dumped size in dwords. */
3833static u32 qed_grc_dump_static_debug(struct qed_hwfn *p_hwfn,
3834 struct qed_ptt *p_ptt,
3835 u32 *dump_buf, bool dump)
3836{
3837 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3838 u32 block_id, line_id, offset = 0;
3839
3840 /* Don't dump static debug if a debug bus recording is in progress */
3841 if (dump && qed_rd(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON))
3842 return 0;
3843
3844 if (dump) {
3845 /* Disable all blocks debug output */
3846 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
3847 struct block_defs *block = s_block_defs[block_id];
3848
3849 if (block->dbg_client_id[dev_data->chip_id] !=
3850 MAX_DBG_BUS_CLIENTS)
3851 qed_wr(p_hwfn, p_ptt, block->dbg_enable_addr,
3852 0);
3853 }
3854
3855 qed_bus_reset_dbg_block(p_hwfn, p_ptt);
3856 qed_bus_set_framing_mode(p_hwfn,
3857 p_ptt, DBG_BUS_FRAME_MODE_8HW_0ST);
3858 qed_wr(p_hwfn,
3859 p_ptt, DBG_REG_DEBUG_TARGET, DBG_BUS_TARGET_ID_INT_BUF);
3860 qed_wr(p_hwfn, p_ptt, DBG_REG_FULL_MODE, 1);
3861 qed_bus_enable_dbg_block(p_hwfn, p_ptt, true);
3862 }
3863
3864 /* Dump all static debug lines for each relevant block */
3865 for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
3866 struct block_defs *block = s_block_defs[block_id];
3867 struct dbg_bus_block *block_desc;
3868 u32 block_dwords, addr, len;
3869 u8 dbg_client_id;
3870
3871 if (block->dbg_client_id[dev_data->chip_id] ==
3872 MAX_DBG_BUS_CLIENTS)
3873 continue;
3874
3875 block_desc = get_dbg_bus_block_desc(p_hwfn,
3876 (enum block_id)block_id);
3877 block_dwords = NUM_DBG_LINES(block_desc) *
3878 STATIC_DEBUG_LINE_DWORDS;
3879
3880 /* Dump static section params */
3881 offset += qed_grc_dump_mem_hdr(p_hwfn,
3882 dump_buf + offset,
3883 dump,
3884 block->name,
3885 0,
3886 block_dwords,
3887 32, false, "STATIC", false, 0);
3888
3889 if (!dump) {
3890 offset += block_dwords;
3891 continue;
3892 }
3893
3894 /* If all lines are invalid - dump zeros */
3895 if (dev_data->block_in_reset[block_id]) {
3896 memset(dump_buf + offset, 0,
3897 DWORDS_TO_BYTES(block_dwords));
3898 offset += block_dwords;
3899 continue;
3900 }
3901
3902 /* Enable block's client */
3903 dbg_client_id = block->dbg_client_id[dev_data->chip_id];
3904 qed_bus_enable_clients(p_hwfn,
3905 p_ptt,
3906 BIT(dbg_client_id));
3907
3908 addr = BYTES_TO_DWORDS(DBG_REG_CALENDAR_OUT_DATA);
3909 len = STATIC_DEBUG_LINE_DWORDS;
3910 for (line_id = 0; line_id < (u32)NUM_DBG_LINES(block_desc);
3911 line_id++) {
3912 /* Configure debug line ID */
3913 qed_config_dbg_line(p_hwfn,
3914 p_ptt,
3915 (enum block_id)block_id,
3916 (u8)line_id, 0xf, 0, 0, 0);
3917
3918 /* Read debug line info */
3919 offset += qed_grc_dump_addr_range(p_hwfn,
3920 p_ptt,
3921 dump_buf + offset,
3922 dump,
3923 addr,
3924 len,
3925 true);
3926 }
3927
3928 /* Disable block's client and debug output */
3929 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
3930 qed_wr(p_hwfn, p_ptt, block->dbg_enable_addr, 0);
3931 }
3932
3933 if (dump) {
3934 qed_bus_enable_dbg_block(p_hwfn, p_ptt, false);
3935 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
3936 }
3937
3938 return offset;
3939}
3940
3941/* Performs GRC Dump to the specified buffer.
3942 * Returns the dumped size in dwords.
3943 */
3944static enum dbg_status qed_grc_dump(struct qed_hwfn *p_hwfn,
3945 struct qed_ptt *p_ptt,
3946 u32 *dump_buf,
3947 bool dump, u32 *num_dumped_dwords)
3948{
3949 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
3950 bool parities_masked = false;
3951 u8 i, port_mode = 0;
3952 u32 offset = 0;
3953
3954 *num_dumped_dwords = 0;
3955
3956 if (dump) {
3957 /* Find port mode */
3958 switch (qed_rd(p_hwfn, p_ptt, MISC_REG_PORT_MODE)) {
3959 case 0:
3960 port_mode = 1;
3961 break;
3962 case 1:
3963 port_mode = 2;
3964 break;
3965 case 2:
3966 port_mode = 4;
3967 break;
3968 }
3969
3970 /* Update reset state */
3971 qed_update_blocks_reset_state(p_hwfn, p_ptt);
3972 }
3973
3974 /* Dump global params */
3975 offset += qed_dump_common_global_params(p_hwfn,
3976 p_ptt,
3977 dump_buf + offset, dump, 4);
3978 offset += qed_dump_str_param(dump_buf + offset,
3979 dump, "dump-type", "grc-dump");
3980 offset += qed_dump_num_param(dump_buf + offset,
3981 dump,
3982 "num-lcids",
3983 qed_grc_get_param(p_hwfn,
3984 DBG_GRC_PARAM_NUM_LCIDS));
3985 offset += qed_dump_num_param(dump_buf + offset,
3986 dump,
3987 "num-ltids",
3988 qed_grc_get_param(p_hwfn,
3989 DBG_GRC_PARAM_NUM_LTIDS));
3990 offset += qed_dump_num_param(dump_buf + offset,
3991 dump, "num-ports", port_mode);
3992
3993 /* Dump reset registers (dumped before taking blocks out of reset ) */
3994 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
3995 offset += qed_grc_dump_reset_regs(p_hwfn,
3996 p_ptt,
3997 dump_buf + offset, dump);
3998
3999 /* Take all blocks out of reset (using reset registers) */
4000 if (dump) {
4001 qed_grc_unreset_blocks(p_hwfn, p_ptt);
4002 qed_update_blocks_reset_state(p_hwfn, p_ptt);
4003 }
4004
4005 /* Disable all parities using MFW command */
4006 if (dump &&
4007 !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
4008 parities_masked = !qed_mcp_mask_parities(p_hwfn, p_ptt, 1);
4009 if (!parities_masked) {
4010 DP_NOTICE(p_hwfn,
4011 "Failed to mask parities using MFW\n");
4012 if (qed_grc_get_param
4013 (p_hwfn, DBG_GRC_PARAM_PARITY_SAFE))
4014 return DBG_STATUS_MCP_COULD_NOT_MASK_PRTY;
4015 }
4016 }
4017
4018 /* Dump modified registers (dumped before modifying them) */
4019 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
4020 offset += qed_grc_dump_modified_regs(p_hwfn,
4021 p_ptt,
4022 dump_buf + offset, dump);
4023
4024 /* Stall storms */
4025 if (dump &&
4026 (qed_grc_is_included(p_hwfn,
4027 DBG_GRC_PARAM_DUMP_IOR) ||
4028 qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC)))
4029 qed_grc_stall_storms(p_hwfn, p_ptt, true);
4030
4031 /* Dump all regs */
4032 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS)) {
4033 bool block_enable[MAX_BLOCK_ID];
4034
4035 /* Dump all blocks except MCP */
4036 for (i = 0; i < MAX_BLOCK_ID; i++)
4037 block_enable[i] = true;
4038 block_enable[BLOCK_MCP] = false;
4039 offset += qed_grc_dump_registers(p_hwfn,
4040 p_ptt,
4041 dump_buf +
4042 offset,
4043 dump,
4044 block_enable, NULL, NULL);
4045
4046 /* Dump special registers */
4047 offset += qed_grc_dump_special_regs(p_hwfn,
4048 p_ptt,
4049 dump_buf + offset, dump);
4050 }
4051
4052 /* Dump memories */
4053 offset += qed_grc_dump_memories(p_hwfn, p_ptt, dump_buf + offset, dump);
4054
4055 /* Dump MCP */
4056 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MCP))
4057 offset += qed_grc_dump_mcp(p_hwfn,
4058 p_ptt, dump_buf + offset, dump);
4059
4060 /* Dump context */
4061 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX))
4062 offset += qed_grc_dump_ctx(p_hwfn,
4063 p_ptt, dump_buf + offset, dump);
4064
4065 /* Dump RSS memories */
4066 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RSS))
4067 offset += qed_grc_dump_rss(p_hwfn,
4068 p_ptt, dump_buf + offset, dump);
4069
4070 /* Dump Big RAM */
4071 for (i = 0; i < NUM_BIG_RAM_TYPES; i++)
4072 if (qed_grc_is_included(p_hwfn, s_big_ram_defs[i].grc_param))
4073 offset += qed_grc_dump_big_ram(p_hwfn,
4074 p_ptt,
4075 dump_buf + offset,
4076 dump, i);
4077
4078 /* Dump IORs */
4079 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IOR))
4080 offset += qed_grc_dump_iors(p_hwfn,
4081 p_ptt, dump_buf + offset, dump);
4082
4083 /* Dump VFC */
4084 if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC))
4085 offset += qed_grc_dump_vfc(p_hwfn,
4086 p_ptt, dump_buf + offset, dump);
4087
4088 /* Dump PHY tbus */
4089 if (qed_grc_is_included(p_hwfn,
4090 DBG_GRC_PARAM_DUMP_PHY) && dev_data->chip_id ==
4091 CHIP_K2 && dev_data->platform_id == PLATFORM_ASIC)
4092 offset += qed_grc_dump_phy(p_hwfn,
4093 p_ptt, dump_buf + offset, dump);
4094
4095 /* Dump static debug data */
4096 if (qed_grc_is_included(p_hwfn,
4097 DBG_GRC_PARAM_DUMP_STATIC) &&
4098 dev_data->bus.state == DBG_BUS_STATE_IDLE)
4099 offset += qed_grc_dump_static_debug(p_hwfn,
4100 p_ptt,
4101 dump_buf + offset, dump);
4102
4103 /* Dump last section */
4104 offset += qed_dump_last_section(dump_buf, offset, dump);
4105
4106 if (dump) {
4107 /* Unstall storms */
4108 if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_UNSTALL))
4109 qed_grc_stall_storms(p_hwfn, p_ptt, false);
4110
4111 /* Clear parity status */
4112 qed_grc_clear_all_prty(p_hwfn, p_ptt);
4113
4114 /* Enable all parities using MFW command */
4115 if (parities_masked)
4116 qed_mcp_mask_parities(p_hwfn, p_ptt, 0);
4117 }
4118
4119 *num_dumped_dwords = offset;
4120
4121 return DBG_STATUS_OK;
4122}
4123
4124/* Writes the specified failing Idle Check rule to the specified buffer.
4125 * Returns the dumped size in dwords.
4126 */
4127static u32 qed_idle_chk_dump_failure(struct qed_hwfn *p_hwfn,
4128 struct qed_ptt *p_ptt,
4129 u32 *
4130 dump_buf,
4131 bool dump,
4132 u16 rule_id,
4133 const struct dbg_idle_chk_rule *rule,
4134 u16 fail_entry_id, u32 *cond_reg_values)
4135{
4136 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
4137 const struct dbg_idle_chk_cond_reg *cond_regs;
4138 const struct dbg_idle_chk_info_reg *info_regs;
4139 u32 i, next_reg_offset = 0, offset = 0;
4140 struct dbg_idle_chk_result_hdr *hdr;
4141 const union dbg_idle_chk_reg *regs;
4142 u8 reg_id;
4143
4144 hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
4145 regs = &((const union dbg_idle_chk_reg *)
4146 s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr)[rule->reg_offset];
4147 cond_regs = ®s[0].cond_reg;
4148 info_regs = ®s[rule->num_cond_regs].info_reg;
4149
4150 /* Dump rule data */
4151 if (dump) {
4152 memset(hdr, 0, sizeof(*hdr));
4153 hdr->rule_id = rule_id;
4154 hdr->mem_entry_id = fail_entry_id;
4155 hdr->severity = rule->severity;
4156 hdr->num_dumped_cond_regs = rule->num_cond_regs;
4157 }
4158
4159 offset += IDLE_CHK_RESULT_HDR_DWORDS;
4160
4161 /* Dump condition register values */
4162 for (reg_id = 0; reg_id < rule->num_cond_regs; reg_id++) {
4163 const struct dbg_idle_chk_cond_reg *reg = &cond_regs[reg_id];
4164 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
4165
4166 reg_hdr = (struct dbg_idle_chk_result_reg_hdr *)
4167 (dump_buf + offset);
4168
4169 /* Write register header */
4170 if (!dump) {
4171 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS +
4172 reg->entry_size;
4173 continue;
4174 }
4175
4176 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
4177 memset(reg_hdr, 0, sizeof(*reg_hdr));
4178 reg_hdr->start_entry = reg->start_entry;
4179 reg_hdr->size = reg->entry_size;
4180 SET_FIELD(reg_hdr->data,
4181 DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM,
4182 reg->num_entries > 1 || reg->start_entry > 0 ? 1 : 0);
4183 SET_FIELD(reg_hdr->data,
4184 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID, reg_id);
4185
4186 /* Write register values */
4187 for (i = 0; i < reg_hdr->size; i++, next_reg_offset++, offset++)
4188 dump_buf[offset] = cond_reg_values[next_reg_offset];
4189 }
4190
4191 /* Dump info register values */
4192 for (reg_id = 0; reg_id < rule->num_info_regs; reg_id++) {
4193 const struct dbg_idle_chk_info_reg *reg = &info_regs[reg_id];
4194 u32 block_id;
4195
4196 /* Check if register's block is in reset */
4197 if (!dump) {
4198 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS + reg->size;
4199 continue;
4200 }
4201
4202 block_id = GET_FIELD(reg->data, DBG_IDLE_CHK_INFO_REG_BLOCK_ID);
4203 if (block_id >= MAX_BLOCK_ID) {
4204 DP_NOTICE(p_hwfn, "Invalid block_id\n");
4205 return 0;
4206 }
4207
4208 if (!dev_data->block_in_reset[block_id]) {
4209 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
4210 bool wide_bus, eval_mode, mode_match = true;
4211 u16 modes_buf_offset;
4212 u32 addr;
4213
4214 reg_hdr = (struct dbg_idle_chk_result_reg_hdr *)
4215 (dump_buf + offset);
4216
4217 /* Check mode */
4218 eval_mode = GET_FIELD(reg->mode.data,
4219 DBG_MODE_HDR_EVAL_MODE) > 0;
4220 if (eval_mode) {
4221 modes_buf_offset =
4222 GET_FIELD(reg->mode.data,
4223 DBG_MODE_HDR_MODES_BUF_OFFSET);
4224 mode_match =
4225 qed_is_mode_match(p_hwfn,
4226 &modes_buf_offset);
4227 }
4228
4229 if (!mode_match)
4230 continue;
4231
4232 addr = GET_FIELD(reg->data,
4233 DBG_IDLE_CHK_INFO_REG_ADDRESS);
4234 wide_bus = GET_FIELD(reg->data,
4235 DBG_IDLE_CHK_INFO_REG_WIDE_BUS);
4236
4237 /* Write register header */
4238 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
4239 hdr->num_dumped_info_regs++;
4240 memset(reg_hdr, 0, sizeof(*reg_hdr));
4241 reg_hdr->size = reg->size;
4242 SET_FIELD(reg_hdr->data,
4243 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID,
4244 rule->num_cond_regs + reg_id);
4245
4246 /* Write register values */
4247 offset += qed_grc_dump_addr_range(p_hwfn,
4248 p_ptt,
4249 dump_buf + offset,
4250 dump,
4251 addr,
4252 reg->size, wide_bus);
4253 }
4254 }
4255
4256 return offset;
4257}
4258
4259/* Dumps idle check rule entries. Returns the dumped size in dwords. */
4260static u32
4261qed_idle_chk_dump_rule_entries(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
4262 u32 *dump_buf, bool dump,
4263 const struct dbg_idle_chk_rule *input_rules,
4264 u32 num_input_rules, u32 *num_failing_rules)
4265{
4266 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
4267 u32 cond_reg_values[IDLE_CHK_MAX_ENTRIES_SIZE];
4268 u32 i, offset = 0;
4269 u16 entry_id;
4270 u8 reg_id;
4271
4272 *num_failing_rules = 0;
4273
4274 for (i = 0; i < num_input_rules; i++) {
4275 const struct dbg_idle_chk_cond_reg *cond_regs;
4276 const struct dbg_idle_chk_rule *rule;
4277 const union dbg_idle_chk_reg *regs;
4278 u16 num_reg_entries = 1;
4279 bool check_rule = true;
4280 const u32 *imm_values;
4281
4282 rule = &input_rules[i];
4283 regs = &((const union dbg_idle_chk_reg *)
4284 s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr)
4285 [rule->reg_offset];
4286 cond_regs = ®s[0].cond_reg;
4287 imm_values = &s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr
4288 [rule->imm_offset];
4289
4290 /* Check if all condition register blocks are out of reset, and
4291 * find maximal number of entries (all condition registers that
4292 * are memories must have the same size, which is > 1).
4293 */
4294 for (reg_id = 0; reg_id < rule->num_cond_regs && check_rule;
4295 reg_id++) {
4296 u32 block_id =
4297 GET_FIELD(cond_regs[reg_id].data,
4298 DBG_IDLE_CHK_COND_REG_BLOCK_ID);
4299
4300 if (block_id >= MAX_BLOCK_ID) {
4301 DP_NOTICE(p_hwfn, "Invalid block_id\n");
4302 return 0;
4303 }
4304
4305 check_rule = !dev_data->block_in_reset[block_id];
4306 if (cond_regs[reg_id].num_entries > num_reg_entries)
4307 num_reg_entries = cond_regs[reg_id].num_entries;
4308 }
4309
4310 if (!check_rule && dump)
4311 continue;
4312
4313 if (!dump) {
4314 u32 entry_dump_size =
4315 qed_idle_chk_dump_failure(p_hwfn,
4316 p_ptt,
4317 dump_buf + offset,
4318 false,
4319 rule->rule_id,
4320 rule,
4321 0,
4322 NULL);
4323
4324 offset += num_reg_entries * entry_dump_size;
4325 (*num_failing_rules) += num_reg_entries;
4326 continue;
4327 }
4328
4329 /* Go over all register entries (number of entries is the same
4330 * for all condition registers).
4331 */
4332 for (entry_id = 0; entry_id < num_reg_entries; entry_id++) {
4333 u32 next_reg_offset = 0;
4334
4335 /* Read current entry of all condition registers */
4336 for (reg_id = 0; reg_id < rule->num_cond_regs;
4337 reg_id++) {
4338 const struct dbg_idle_chk_cond_reg *reg =
4339 &cond_regs[reg_id];
4340 u32 padded_entry_size, addr;
4341 bool wide_bus;
4342
4343 /* Find GRC address (if it's a memory, the
4344 * address of the specific entry is calculated).
4345 */
4346 addr = GET_FIELD(reg->data,
4347 DBG_IDLE_CHK_COND_REG_ADDRESS);
4348 wide_bus =
4349 GET_FIELD(reg->data,
4350 DBG_IDLE_CHK_COND_REG_WIDE_BUS);
4351 if (reg->num_entries > 1 ||
4352 reg->start_entry > 0) {
4353 padded_entry_size =
4354 reg->entry_size > 1 ?
4355 roundup_pow_of_two(reg->entry_size) :
4356 1;
4357 addr += (reg->start_entry + entry_id) *
4358 padded_entry_size;
4359 }
4360
4361 /* Read registers */
4362 if (next_reg_offset + reg->entry_size >=
4363 IDLE_CHK_MAX_ENTRIES_SIZE) {
4364 DP_NOTICE(p_hwfn,
4365 "idle check registers entry is too large\n");
4366 return 0;
4367 }
4368
4369 next_reg_offset +=
4370 qed_grc_dump_addr_range(p_hwfn, p_ptt,
4371 cond_reg_values +
4372 next_reg_offset,
4373 dump, addr,
4374 reg->entry_size,
4375 wide_bus);
4376 }
4377
4378 /* Call rule condition function.
4379 * If returns true, it's a failure.
4380 */
4381 if ((*cond_arr[rule->cond_id]) (cond_reg_values,
4382 imm_values)) {
4383 offset += qed_idle_chk_dump_failure(p_hwfn,
4384 p_ptt,
4385 dump_buf + offset,
4386 dump,
4387 rule->rule_id,
4388 rule,
4389 entry_id,
4390 cond_reg_values);
4391 (*num_failing_rules)++;
4392 }
4393 }
4394 }
4395
4396 return offset;
4397}
4398
4399/* Performs Idle Check Dump to the specified buffer.
4400 * Returns the dumped size in dwords.
4401 */
4402static u32 qed_idle_chk_dump(struct qed_hwfn *p_hwfn,
4403 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
4404{
4405 u32 num_failing_rules_offset, offset = 0, input_offset = 0;
4406 u32 num_failing_rules = 0;
4407
4408 /* Dump global params */
4409 offset += qed_dump_common_global_params(p_hwfn,
4410 p_ptt,
4411 dump_buf + offset, dump, 1);
4412 offset += qed_dump_str_param(dump_buf + offset,
4413 dump, "dump-type", "idle-chk");
4414
4415 /* Dump idle check section header with a single parameter */
4416 offset += qed_dump_section_hdr(dump_buf + offset, dump, "idle_chk", 1);
4417 num_failing_rules_offset = offset;
4418 offset += qed_dump_num_param(dump_buf + offset, dump, "num_rules", 0);
4419
4420 while (input_offset <
4421 s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].size_in_dwords) {
4422 const struct dbg_idle_chk_cond_hdr *cond_hdr =
4423 (const struct dbg_idle_chk_cond_hdr *)
4424 &s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].ptr
4425 [input_offset++];
4426 bool eval_mode, mode_match = true;
4427 u32 curr_failing_rules;
4428 u16 modes_buf_offset;
4429
4430 /* Check mode */
4431 eval_mode = GET_FIELD(cond_hdr->mode.data,
4432 DBG_MODE_HDR_EVAL_MODE) > 0;
4433 if (eval_mode) {
4434 modes_buf_offset =
4435 GET_FIELD(cond_hdr->mode.data,
4436 DBG_MODE_HDR_MODES_BUF_OFFSET);
4437 mode_match = qed_is_mode_match(p_hwfn,
4438 &modes_buf_offset);
4439 }
4440
4441 if (mode_match) {
4442 offset +=
4443 qed_idle_chk_dump_rule_entries(p_hwfn,
4444 p_ptt,
4445 dump_buf + offset,
4446 dump,
4447 (const struct dbg_idle_chk_rule *)
4448 &s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].
4449 ptr[input_offset],
4450 cond_hdr->data_size / IDLE_CHK_RULE_SIZE_DWORDS,
4451 &curr_failing_rules);
4452 num_failing_rules += curr_failing_rules;
4453 }
4454
4455 input_offset += cond_hdr->data_size;
4456 }
4457
4458 /* Overwrite num_rules parameter */
4459 if (dump)
4460 qed_dump_num_param(dump_buf + num_failing_rules_offset,
4461 dump, "num_rules", num_failing_rules);
4462
4463 /* Dump last section */
4464 offset += qed_dump_last_section(dump_buf, offset, dump);
4465
4466 return offset;
4467}
4468
4469/* Finds the meta data image in NVRAM */
4470static enum dbg_status qed_find_nvram_image(struct qed_hwfn *p_hwfn,
4471 struct qed_ptt *p_ptt,
4472 u32 image_type,
4473 u32 *nvram_offset_bytes,
4474 u32 *nvram_size_bytes)
4475{
4476 u32 ret_mcp_resp, ret_mcp_param, ret_txn_size;
4477 struct mcp_file_att file_att;
4478 int nvm_result;
4479
4480 /* Call NVRAM get file command */
4481 nvm_result = qed_mcp_nvm_rd_cmd(p_hwfn,
4482 p_ptt,
4483 DRV_MSG_CODE_NVM_GET_FILE_ATT,
4484 image_type,
4485 &ret_mcp_resp,
4486 &ret_mcp_param,
4487 &ret_txn_size, (u32 *)&file_att);
4488
4489 /* Check response */
4490 if (nvm_result ||
4491 (ret_mcp_resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
4492 return DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
4493
4494 /* Update return values */
4495 *nvram_offset_bytes = file_att.nvm_start_addr;
4496 *nvram_size_bytes = file_att.len;
4497
4498 DP_VERBOSE(p_hwfn,
4499 QED_MSG_DEBUG,
4500 "find_nvram_image: found NVRAM image of type %d in NVRAM offset %d bytes with size %d bytes\n",
4501 image_type, *nvram_offset_bytes, *nvram_size_bytes);
4502
4503 /* Check alignment */
4504 if (*nvram_size_bytes & 0x3)
4505 return DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE;
4506
4507 return DBG_STATUS_OK;
4508}
4509
4510/* Reads data from NVRAM */
4511static enum dbg_status qed_nvram_read(struct qed_hwfn *p_hwfn,
4512 struct qed_ptt *p_ptt,
4513 u32 nvram_offset_bytes,
4514 u32 nvram_size_bytes, u32 *ret_buf)
4515{
4516 u32 ret_mcp_resp, ret_mcp_param, ret_read_size, bytes_to_copy;
4517 s32 bytes_left = nvram_size_bytes;
4518 u32 read_offset = 0;
4519
4520 DP_VERBOSE(p_hwfn,
4521 QED_MSG_DEBUG,
4522 "nvram_read: reading image of size %d bytes from NVRAM\n",
4523 nvram_size_bytes);
4524
4525 do {
4526 bytes_to_copy =
4527 (bytes_left >
4528 MCP_DRV_NVM_BUF_LEN) ? MCP_DRV_NVM_BUF_LEN : bytes_left;
4529
4530 /* Call NVRAM read command */
4531 if (qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
4532 DRV_MSG_CODE_NVM_READ_NVRAM,
4533 (nvram_offset_bytes +
4534 read_offset) |
4535 (bytes_to_copy <<
4536 DRV_MB_PARAM_NVM_LEN_OFFSET),
4537 &ret_mcp_resp, &ret_mcp_param,
4538 &ret_read_size,
4539 (u32 *)((u8 *)ret_buf + read_offset)))
4540 return DBG_STATUS_NVRAM_READ_FAILED;
4541
4542 /* Check response */
4543 if ((ret_mcp_resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
4544 return DBG_STATUS_NVRAM_READ_FAILED;
4545
4546 /* Update read offset */
4547 read_offset += ret_read_size;
4548 bytes_left -= ret_read_size;
4549 } while (bytes_left > 0);
4550
4551 return DBG_STATUS_OK;
4552}
4553
4554/* Get info on the MCP Trace data in the scratchpad:
4555 * - trace_data_grc_addr (OUT): trace data GRC address in bytes
4556 * - trace_data_size (OUT): trace data size in bytes (without the header)
4557 */
4558static enum dbg_status qed_mcp_trace_get_data_info(struct qed_hwfn *p_hwfn,
4559 struct qed_ptt *p_ptt,
4560 u32 *trace_data_grc_addr,
4561 u32 *trace_data_size)
4562{
4563 u32 spad_trace_offsize, signature;
4564
4565 /* Read trace section offsize structure from MCP scratchpad */
4566 spad_trace_offsize = qed_rd(p_hwfn, p_ptt, MCP_SPAD_TRACE_OFFSIZE_ADDR);
4567
4568 /* Extract trace section address from offsize (in scratchpad) */
4569 *trace_data_grc_addr =
4570 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize);
4571
4572 /* Read signature from MCP trace section */
4573 signature = qed_rd(p_hwfn, p_ptt,
4574 *trace_data_grc_addr +
4575 offsetof(struct mcp_trace, signature));
4576
4577 if (signature != MFW_TRACE_SIGNATURE)
4578 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4579
4580 /* Read trace size from MCP trace section */
4581 *trace_data_size = qed_rd(p_hwfn,
4582 p_ptt,
4583 *trace_data_grc_addr +
4584 offsetof(struct mcp_trace, size));
4585
4586 return DBG_STATUS_OK;
4587}
4588
4589/* Reads MCP trace meta data image from NVRAM
4590 * - running_bundle_id (OUT): running bundle ID (invalid when loaded from file)
4591 * - trace_meta_offset (OUT): trace meta offset in NVRAM in bytes (invalid when
4592 * loaded from file).
4593 * - trace_meta_size (OUT): size in bytes of the trace meta data.
4594 */
4595static enum dbg_status qed_mcp_trace_get_meta_info(struct qed_hwfn *p_hwfn,
4596 struct qed_ptt *p_ptt,
4597 u32 trace_data_size_bytes,
4598 u32 *running_bundle_id,
4599 u32 *trace_meta_offset,
4600 u32 *trace_meta_size)
4601{
4602 u32 spad_trace_offsize, nvram_image_type, running_mfw_addr;
4603
4604 /* Read MCP trace section offsize structure from MCP scratchpad */
4605 spad_trace_offsize = qed_rd(p_hwfn, p_ptt, MCP_SPAD_TRACE_OFFSIZE_ADDR);
4606
4607 /* Find running bundle ID */
4608 running_mfw_addr =
4609 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize) +
4610 QED_SECTION_SIZE(spad_trace_offsize) + trace_data_size_bytes;
4611 *running_bundle_id = qed_rd(p_hwfn, p_ptt, running_mfw_addr);
4612 if (*running_bundle_id > 1)
4613 return DBG_STATUS_INVALID_NVRAM_BUNDLE;
4614
4615 /* Find image in NVRAM */
4616 nvram_image_type =
4617 (*running_bundle_id ==
4618 DIR_ID_1) ? NVM_TYPE_MFW_TRACE1 : NVM_TYPE_MFW_TRACE2;
4619 return qed_find_nvram_image(p_hwfn,
4620 p_ptt,
4621 nvram_image_type,
4622 trace_meta_offset, trace_meta_size);
4623}
4624
4625/* Reads the MCP Trace meta data from NVRAM into the specified buffer */
4626static enum dbg_status qed_mcp_trace_read_meta(struct qed_hwfn *p_hwfn,
4627 struct qed_ptt *p_ptt,
4628 u32 nvram_offset_in_bytes,
4629 u32 size_in_bytes, u32 *buf)
4630{
4631 u8 modules_num, module_len, i, *byte_buf = (u8 *)buf;
4632 enum dbg_status status;
4633 u32 signature;
4634
4635 /* Read meta data from NVRAM */
4636 status = qed_nvram_read(p_hwfn,
4637 p_ptt,
4638 nvram_offset_in_bytes, size_in_bytes, buf);
4639 if (status != DBG_STATUS_OK)
4640 return status;
4641
4642 /* Extract and check first signature */
4643 signature = qed_read_unaligned_dword(byte_buf);
4644 byte_buf += sizeof(signature);
4645 if (signature != NVM_MAGIC_VALUE)
4646 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4647
4648 /* Extract number of modules */
4649 modules_num = *(byte_buf++);
4650
4651 /* Skip all modules */
4652 for (i = 0; i < modules_num; i++) {
4653 module_len = *(byte_buf++);
4654 byte_buf += module_len;
4655 }
4656
4657 /* Extract and check second signature */
4658 signature = qed_read_unaligned_dword(byte_buf);
4659 byte_buf += sizeof(signature);
4660 if (signature != NVM_MAGIC_VALUE)
4661 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
4662
4663 return DBG_STATUS_OK;
4664}
4665
4666/* Dump MCP Trace */
4667static enum dbg_status qed_mcp_trace_dump(struct qed_hwfn *p_hwfn,
4668 struct qed_ptt *p_ptt,
4669 u32 *dump_buf,
4670 bool dump, u32 *num_dumped_dwords)
4671{
4672 u32 trace_data_grc_addr, trace_data_size_bytes, trace_data_size_dwords;
4673 u32 trace_meta_size_dwords = 0, running_bundle_id, offset = 0;
4674 u32 trace_meta_offset_bytes = 0, trace_meta_size_bytes = 0;
4675 enum dbg_status status;
4676 bool mcp_access;
4677 int halted = 0;
4678
4679 *num_dumped_dwords = 0;
4680
4681 mcp_access = !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP);
4682
4683 /* Get trace data info */
4684 status = qed_mcp_trace_get_data_info(p_hwfn,
4685 p_ptt,
4686 &trace_data_grc_addr,
4687 &trace_data_size_bytes);
4688 if (status != DBG_STATUS_OK)
4689 return status;
4690
4691 /* Dump global params */
4692 offset += qed_dump_common_global_params(p_hwfn,
4693 p_ptt,
4694 dump_buf + offset, dump, 1);
4695 offset += qed_dump_str_param(dump_buf + offset,
4696 dump, "dump-type", "mcp-trace");
4697
4698 /* Halt MCP while reading from scratchpad so the read data will be
4699 * consistent. if halt fails, MCP trace is taken anyway, with a small
4700 * risk that it may be corrupt.
4701 */
4702 if (dump && mcp_access) {
4703 halted = !qed_mcp_halt(p_hwfn, p_ptt);
4704 if (!halted)
4705 DP_NOTICE(p_hwfn, "MCP halt failed!\n");
4706 }
4707
4708 /* Find trace data size */
4709 trace_data_size_dwords =
4710 DIV_ROUND_UP(trace_data_size_bytes + sizeof(struct mcp_trace),
4711 BYTES_IN_DWORD);
4712
4713 /* Dump trace data section header and param */
4714 offset += qed_dump_section_hdr(dump_buf + offset,
4715 dump, "mcp_trace_data", 1);
4716 offset += qed_dump_num_param(dump_buf + offset,
4717 dump, "size", trace_data_size_dwords);
4718
4719 /* Read trace data from scratchpad into dump buffer */
4720 offset += qed_grc_dump_addr_range(p_hwfn,
4721 p_ptt,
4722 dump_buf + offset,
4723 dump,
4724 BYTES_TO_DWORDS(trace_data_grc_addr),
4725 trace_data_size_dwords, false);
4726
4727 /* Resume MCP (only if halt succeeded) */
4728 if (halted && qed_mcp_resume(p_hwfn, p_ptt))
4729 DP_NOTICE(p_hwfn, "Failed to resume MCP after halt!\n");
4730
4731 /* Dump trace meta section header */
4732 offset += qed_dump_section_hdr(dump_buf + offset,
4733 dump, "mcp_trace_meta", 1);
4734
4735 /* If MCP Trace meta size parameter was set, use it.
4736 * Otherwise, read trace meta.
4737 * trace_meta_size_bytes is dword-aligned.
4738 */
4739 trace_meta_size_bytes =
4740 qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_MCP_TRACE_META_SIZE);
4741 if ((!trace_meta_size_bytes || dump) && mcp_access) {
4742 status = qed_mcp_trace_get_meta_info(p_hwfn,
4743 p_ptt,
4744 trace_data_size_bytes,
4745 &running_bundle_id,
4746 &trace_meta_offset_bytes,
4747 &trace_meta_size_bytes);
4748 if (status == DBG_STATUS_OK)
4749 trace_meta_size_dwords =
4750 BYTES_TO_DWORDS(trace_meta_size_bytes);
4751 }
4752
4753 /* Dump trace meta size param */
4754 offset += qed_dump_num_param(dump_buf + offset,
4755 dump, "size", trace_meta_size_dwords);
4756
4757 /* Read trace meta image into dump buffer */
4758 if (dump && trace_meta_size_dwords)
4759 status = qed_mcp_trace_read_meta(p_hwfn,
4760 p_ptt,
4761 trace_meta_offset_bytes,
4762 trace_meta_size_bytes,
4763 dump_buf + offset);
4764 if (status == DBG_STATUS_OK)
4765 offset += trace_meta_size_dwords;
4766
4767 /* Dump last section */
4768 offset += qed_dump_last_section(dump_buf, offset, dump);
4769
4770 *num_dumped_dwords = offset;
4771
4772 /* If no mcp access, indicate that the dump doesn't contain the meta
4773 * data from NVRAM.
4774 */
4775 return mcp_access ? status : DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
4776}
4777
4778/* Dump GRC FIFO */
4779static enum dbg_status qed_reg_fifo_dump(struct qed_hwfn *p_hwfn,
4780 struct qed_ptt *p_ptt,
4781 u32 *dump_buf,
4782 bool dump, u32 *num_dumped_dwords)
4783{
4784 u32 dwords_read, size_param_offset, offset = 0, addr, len;
4785 bool fifo_has_data;
4786
4787 *num_dumped_dwords = 0;
4788
4789 /* Dump global params */
4790 offset += qed_dump_common_global_params(p_hwfn,
4791 p_ptt,
4792 dump_buf + offset, dump, 1);
4793 offset += qed_dump_str_param(dump_buf + offset,
4794 dump, "dump-type", "reg-fifo");
4795
4796 /* Dump fifo data section header and param. The size param is 0 for
4797 * now, and is overwritten after reading the FIFO.
4798 */
4799 offset += qed_dump_section_hdr(dump_buf + offset,
4800 dump, "reg_fifo_data", 1);
4801 size_param_offset = offset;
4802 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4803
4804 if (!dump) {
4805 /* FIFO max size is REG_FIFO_DEPTH_DWORDS. There is no way to
4806 * test how much data is available, except for reading it.
4807 */
4808 offset += REG_FIFO_DEPTH_DWORDS;
4809 goto out;
4810 }
4811
4812 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4813 GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
4814
4815 /* Pull available data from fifo. Use DMAE since this is widebus memory
4816 * and must be accessed atomically. Test for dwords_read not passing
4817 * buffer size since more entries could be added to the buffer as we are
4818 * emptying it.
4819 */
4820 addr = BYTES_TO_DWORDS(GRC_REG_TRACE_FIFO);
4821 len = REG_FIFO_ELEMENT_DWORDS;
4822 for (dwords_read = 0;
4823 fifo_has_data && dwords_read < REG_FIFO_DEPTH_DWORDS;
4824 dwords_read += REG_FIFO_ELEMENT_DWORDS) {
4825 offset += qed_grc_dump_addr_range(p_hwfn,
4826 p_ptt,
4827 dump_buf + offset,
4828 true,
4829 addr,
4830 len,
4831 true);
4832 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4833 GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
4834 }
4835
4836 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4837 dwords_read);
4838out:
4839 /* Dump last section */
4840 offset += qed_dump_last_section(dump_buf, offset, dump);
4841
4842 *num_dumped_dwords = offset;
4843
4844 return DBG_STATUS_OK;
4845}
4846
4847/* Dump IGU FIFO */
4848static enum dbg_status qed_igu_fifo_dump(struct qed_hwfn *p_hwfn,
4849 struct qed_ptt *p_ptt,
4850 u32 *dump_buf,
4851 bool dump, u32 *num_dumped_dwords)
4852{
4853 u32 dwords_read, size_param_offset, offset = 0, addr, len;
4854 bool fifo_has_data;
4855
4856 *num_dumped_dwords = 0;
4857
4858 /* Dump global params */
4859 offset += qed_dump_common_global_params(p_hwfn,
4860 p_ptt,
4861 dump_buf + offset, dump, 1);
4862 offset += qed_dump_str_param(dump_buf + offset,
4863 dump, "dump-type", "igu-fifo");
4864
4865 /* Dump fifo data section header and param. The size param is 0 for
4866 * now, and is overwritten after reading the FIFO.
4867 */
4868 offset += qed_dump_section_hdr(dump_buf + offset,
4869 dump, "igu_fifo_data", 1);
4870 size_param_offset = offset;
4871 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4872
4873 if (!dump) {
4874 /* FIFO max size is IGU_FIFO_DEPTH_DWORDS. There is no way to
4875 * test how much data is available, except for reading it.
4876 */
4877 offset += IGU_FIFO_DEPTH_DWORDS;
4878 goto out;
4879 }
4880
4881 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4882 IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
4883
4884 /* Pull available data from fifo. Use DMAE since this is widebus memory
4885 * and must be accessed atomically. Test for dwords_read not passing
4886 * buffer size since more entries could be added to the buffer as we are
4887 * emptying it.
4888 */
4889 addr = BYTES_TO_DWORDS(IGU_REG_ERROR_HANDLING_MEMORY);
4890 len = IGU_FIFO_ELEMENT_DWORDS;
4891 for (dwords_read = 0;
4892 fifo_has_data && dwords_read < IGU_FIFO_DEPTH_DWORDS;
4893 dwords_read += IGU_FIFO_ELEMENT_DWORDS) {
4894 offset += qed_grc_dump_addr_range(p_hwfn,
4895 p_ptt,
4896 dump_buf + offset,
4897 true,
4898 addr,
4899 len,
4900 true);
4901 fifo_has_data = qed_rd(p_hwfn, p_ptt,
4902 IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
4903 }
4904
4905 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4906 dwords_read);
4907out:
4908 /* Dump last section */
4909 offset += qed_dump_last_section(dump_buf, offset, dump);
4910
4911 *num_dumped_dwords = offset;
4912
4913 return DBG_STATUS_OK;
4914}
4915
4916/* Protection Override dump */
4917static enum dbg_status qed_protection_override_dump(struct qed_hwfn *p_hwfn,
4918 struct qed_ptt *p_ptt,
4919 u32 *dump_buf,
4920 bool dump,
4921 u32 *num_dumped_dwords)
4922{
4923 u32 size_param_offset, override_window_dwords, offset = 0, addr;
4924
4925 *num_dumped_dwords = 0;
4926
4927 /* Dump global params */
4928 offset += qed_dump_common_global_params(p_hwfn,
4929 p_ptt,
4930 dump_buf + offset, dump, 1);
4931 offset += qed_dump_str_param(dump_buf + offset,
4932 dump, "dump-type", "protection-override");
4933
4934 /* Dump data section header and param. The size param is 0 for now,
4935 * and is overwritten after reading the data.
4936 */
4937 offset += qed_dump_section_hdr(dump_buf + offset,
4938 dump, "protection_override_data", 1);
4939 size_param_offset = offset;
4940 offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
4941
4942 if (!dump) {
4943 offset += PROTECTION_OVERRIDE_DEPTH_DWORDS;
4944 goto out;
4945 }
4946
4947 /* Add override window info to buffer */
4948 override_window_dwords =
4949 qed_rd(p_hwfn, p_ptt, GRC_REG_NUMBER_VALID_OVERRIDE_WINDOW) *
4950 PROTECTION_OVERRIDE_ELEMENT_DWORDS;
4951 addr = BYTES_TO_DWORDS(GRC_REG_PROTECTION_OVERRIDE_WINDOW);
4952 offset += qed_grc_dump_addr_range(p_hwfn,
4953 p_ptt,
4954 dump_buf + offset,
4955 true,
4956 addr,
4957 override_window_dwords,
4958 true);
4959 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
4960 override_window_dwords);
4961out:
4962 /* Dump last section */
4963 offset += qed_dump_last_section(dump_buf, offset, dump);
4964
4965 *num_dumped_dwords = offset;
4966
4967 return DBG_STATUS_OK;
4968}
4969
4970/* Performs FW Asserts Dump to the specified buffer.
4971 * Returns the dumped size in dwords.
4972 */
4973static u32 qed_fw_asserts_dump(struct qed_hwfn *p_hwfn,
4974 struct qed_ptt *p_ptt, u32 *dump_buf, bool dump)
4975{
4976 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
4977 struct fw_asserts_ram_section *asserts;
4978 char storm_letter_str[2] = "?";
4979 struct fw_info fw_info;
4980 u32 offset = 0;
4981 u8 storm_id;
4982
4983 /* Dump global params */
4984 offset += qed_dump_common_global_params(p_hwfn,
4985 p_ptt,
4986 dump_buf + offset, dump, 1);
4987 offset += qed_dump_str_param(dump_buf + offset,
4988 dump, "dump-type", "fw-asserts");
4989
4990 /* Find Storm dump size */
4991 for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
4992 u32 fw_asserts_section_addr, next_list_idx_addr, next_list_idx;
4993 struct storm_defs *storm = &s_storm_defs[storm_id];
4994 u32 last_list_idx, addr;
4995
4996 if (dev_data->block_in_reset[storm->block_id])
4997 continue;
4998
4999 /* Read FW info for the current Storm */
5000 qed_read_fw_info(p_hwfn, p_ptt, storm_id, &fw_info);
5001
5002 asserts = &fw_info.fw_asserts_section;
5003
5004 /* Dump FW Asserts section header and params */
5005 storm_letter_str[0] = storm->letter;
5006 offset += qed_dump_section_hdr(dump_buf + offset,
5007 dump, "fw_asserts", 2);
5008 offset += qed_dump_str_param(dump_buf + offset,
5009 dump, "storm", storm_letter_str);
5010 offset += qed_dump_num_param(dump_buf + offset,
5011 dump,
5012 "size",
5013 asserts->list_element_dword_size);
5014
5015 /* Read and dump FW Asserts data */
5016 if (!dump) {
5017 offset += asserts->list_element_dword_size;
5018 continue;
5019 }
5020
5021 fw_asserts_section_addr = storm->sem_fast_mem_addr +
5022 SEM_FAST_REG_INT_RAM +
5023 RAM_LINES_TO_BYTES(asserts->section_ram_line_offset);
5024 next_list_idx_addr = fw_asserts_section_addr +
5025 DWORDS_TO_BYTES(asserts->list_next_index_dword_offset);
5026 next_list_idx = qed_rd(p_hwfn, p_ptt, next_list_idx_addr);
5027 last_list_idx = (next_list_idx > 0 ?
5028 next_list_idx :
5029 asserts->list_num_elements) - 1;
5030 addr = BYTES_TO_DWORDS(fw_asserts_section_addr) +
5031 asserts->list_dword_offset +
5032 last_list_idx * asserts->list_element_dword_size;
5033 offset +=
5034 qed_grc_dump_addr_range(p_hwfn, p_ptt,
5035 dump_buf + offset,
5036 dump, addr,
5037 asserts->list_element_dword_size,
5038 false);
5039 }
5040
5041 /* Dump last section */
5042 offset += qed_dump_last_section(dump_buf, offset, dump);
5043
5044 return offset;
5045}
5046
5047/***************************** Public Functions *******************************/
5048
5049enum dbg_status qed_dbg_set_bin_ptr(const u8 * const bin_ptr)
5050{
5051 struct bin_buffer_hdr *buf_array = (struct bin_buffer_hdr *)bin_ptr;
5052 u8 buf_id;
5053
5054 /* convert binary data to debug arrays */
5055 for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++) {
5056 s_dbg_arrays[buf_id].ptr =
5057 (u32 *)(bin_ptr + buf_array[buf_id].offset);
5058 s_dbg_arrays[buf_id].size_in_dwords =
5059 BYTES_TO_DWORDS(buf_array[buf_id].length);
5060 }
5061
5062 return DBG_STATUS_OK;
5063}
5064
5065/* Assign default GRC param values */
5066void qed_dbg_grc_set_params_default(struct qed_hwfn *p_hwfn)
5067{
5068 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5069 u32 i;
5070
5071 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
5072 if (!s_grc_param_defs[i].is_persistent)
5073 dev_data->grc.param_val[i] =
5074 s_grc_param_defs[i].default_val[dev_data->chip_id];
5075}
5076
5077enum dbg_status qed_dbg_grc_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5078 struct qed_ptt *p_ptt,
5079 u32 *buf_size)
5080{
5081 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5082
5083 *buf_size = 0;
5084
5085 if (status != DBG_STATUS_OK)
5086 return status;
5087
5088 if (!s_dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5089 !s_dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr ||
5090 !s_dbg_arrays[BIN_BUF_DBG_DUMP_MEM].ptr ||
5091 !s_dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
5092 !s_dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
5093 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5094
5095 return qed_grc_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5096}
5097
5098enum dbg_status qed_dbg_grc_dump(struct qed_hwfn *p_hwfn,
5099 struct qed_ptt *p_ptt,
5100 u32 *dump_buf,
5101 u32 buf_size_in_dwords,
5102 u32 *num_dumped_dwords)
5103{
5104 u32 needed_buf_size_in_dwords;
5105 enum dbg_status status;
5106
5107 *num_dumped_dwords = 0;
5108
5109 status = qed_dbg_grc_get_dump_buf_size(p_hwfn,
5110 p_ptt,
5111 &needed_buf_size_in_dwords);
5112 if (status != DBG_STATUS_OK)
5113 return status;
5114
5115 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5116 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5117
5118 /* GRC Dump */
5119 status = qed_grc_dump(p_hwfn, p_ptt, dump_buf, true, num_dumped_dwords);
5120
5121 /* Revert GRC params to their default */
5122 qed_dbg_grc_set_params_default(p_hwfn);
5123
5124 return status;
5125}
5126
5127enum dbg_status qed_dbg_idle_chk_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5128 struct qed_ptt *p_ptt,
5129 u32 *buf_size)
5130{
5131 struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
5132 struct idle_chk_data *idle_chk;
5133 enum dbg_status status;
5134
5135 idle_chk = &dev_data->idle_chk;
5136 *buf_size = 0;
5137
5138 status = qed_dbg_dev_init(p_hwfn, p_ptt);
5139 if (status != DBG_STATUS_OK)
5140 return status;
5141
5142 if (!s_dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5143 !s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr ||
5144 !s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr ||
5145 !s_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].ptr)
5146 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5147
5148 if (!idle_chk->buf_size_set) {
5149 idle_chk->buf_size = qed_idle_chk_dump(p_hwfn,
5150 p_ptt, NULL, false);
5151 idle_chk->buf_size_set = true;
5152 }
5153
5154 *buf_size = idle_chk->buf_size;
5155
5156 return DBG_STATUS_OK;
5157}
5158
5159enum dbg_status qed_dbg_idle_chk_dump(struct qed_hwfn *p_hwfn,
5160 struct qed_ptt *p_ptt,
5161 u32 *dump_buf,
5162 u32 buf_size_in_dwords,
5163 u32 *num_dumped_dwords)
5164{
5165 u32 needed_buf_size_in_dwords;
5166 enum dbg_status status;
5167
5168 *num_dumped_dwords = 0;
5169
5170 status = qed_dbg_idle_chk_get_dump_buf_size(p_hwfn,
5171 p_ptt,
5172 &needed_buf_size_in_dwords);
5173 if (status != DBG_STATUS_OK)
5174 return status;
5175
5176 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5177 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5178
5179 /* Update reset state */
5180 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5181
5182 /* Idle Check Dump */
5183 *num_dumped_dwords = qed_idle_chk_dump(p_hwfn, p_ptt, dump_buf, true);
5184
5185 /* Revert GRC params to their default */
5186 qed_dbg_grc_set_params_default(p_hwfn);
5187
5188 return DBG_STATUS_OK;
5189}
5190
5191enum dbg_status qed_dbg_mcp_trace_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5192 struct qed_ptt *p_ptt,
5193 u32 *buf_size)
5194{
5195 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5196
5197 *buf_size = 0;
5198
5199 if (status != DBG_STATUS_OK)
5200 return status;
5201
5202 return qed_mcp_trace_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5203}
5204
5205enum dbg_status qed_dbg_mcp_trace_dump(struct qed_hwfn *p_hwfn,
5206 struct qed_ptt *p_ptt,
5207 u32 *dump_buf,
5208 u32 buf_size_in_dwords,
5209 u32 *num_dumped_dwords)
5210{
5211 u32 needed_buf_size_in_dwords;
5212 enum dbg_status status;
5213
5214 status =
5215 qed_dbg_mcp_trace_get_dump_buf_size(p_hwfn,
5216 p_ptt,
5217 &needed_buf_size_in_dwords);
5218 if (status != DBG_STATUS_OK && status !=
5219 DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
5220 return status;
5221
5222 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5223 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5224
5225 /* Update reset state */
5226 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5227
5228 /* Perform dump */
5229 status = qed_mcp_trace_dump(p_hwfn,
5230 p_ptt, dump_buf, true, num_dumped_dwords);
5231
5232 /* Revert GRC params to their default */
5233 qed_dbg_grc_set_params_default(p_hwfn);
5234
5235 return status;
5236}
5237
5238enum dbg_status qed_dbg_reg_fifo_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5239 struct qed_ptt *p_ptt,
5240 u32 *buf_size)
5241{
5242 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5243
5244 *buf_size = 0;
5245
5246 if (status != DBG_STATUS_OK)
5247 return status;
5248
5249 return qed_reg_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5250}
5251
5252enum dbg_status qed_dbg_reg_fifo_dump(struct qed_hwfn *p_hwfn,
5253 struct qed_ptt *p_ptt,
5254 u32 *dump_buf,
5255 u32 buf_size_in_dwords,
5256 u32 *num_dumped_dwords)
5257{
5258 u32 needed_buf_size_in_dwords;
5259 enum dbg_status status;
5260
5261 *num_dumped_dwords = 0;
5262
5263 status = qed_dbg_reg_fifo_get_dump_buf_size(p_hwfn,
5264 p_ptt,
5265 &needed_buf_size_in_dwords);
5266 if (status != DBG_STATUS_OK)
5267 return status;
5268
5269 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5270 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5271
5272 /* Update reset state */
5273 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5274
5275 status = qed_reg_fifo_dump(p_hwfn,
5276 p_ptt, dump_buf, true, num_dumped_dwords);
5277
5278 /* Revert GRC params to their default */
5279 qed_dbg_grc_set_params_default(p_hwfn);
5280
5281 return status;
5282}
5283
5284enum dbg_status qed_dbg_igu_fifo_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5285 struct qed_ptt *p_ptt,
5286 u32 *buf_size)
5287{
5288 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5289
5290 *buf_size = 0;
5291
5292 if (status != DBG_STATUS_OK)
5293 return status;
5294
5295 return qed_igu_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
5296}
5297
5298enum dbg_status qed_dbg_igu_fifo_dump(struct qed_hwfn *p_hwfn,
5299 struct qed_ptt *p_ptt,
5300 u32 *dump_buf,
5301 u32 buf_size_in_dwords,
5302 u32 *num_dumped_dwords)
5303{
5304 u32 needed_buf_size_in_dwords;
5305 enum dbg_status status;
5306
5307 *num_dumped_dwords = 0;
5308
5309 status = qed_dbg_igu_fifo_get_dump_buf_size(p_hwfn,
5310 p_ptt,
5311 &needed_buf_size_in_dwords);
5312 if (status != DBG_STATUS_OK)
5313 return status;
5314
5315 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5316 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5317
5318 /* Update reset state */
5319 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5320
5321 status = qed_igu_fifo_dump(p_hwfn,
5322 p_ptt, dump_buf, true, num_dumped_dwords);
5323 /* Revert GRC params to their default */
5324 qed_dbg_grc_set_params_default(p_hwfn);
5325
5326 return status;
5327}
5328
5329enum dbg_status
5330qed_dbg_protection_override_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5331 struct qed_ptt *p_ptt,
5332 u32 *buf_size)
5333{
5334 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5335
5336 *buf_size = 0;
5337
5338 if (status != DBG_STATUS_OK)
5339 return status;
5340
5341 return qed_protection_override_dump(p_hwfn,
5342 p_ptt, NULL, false, buf_size);
5343}
5344
5345enum dbg_status qed_dbg_protection_override_dump(struct qed_hwfn *p_hwfn,
5346 struct qed_ptt *p_ptt,
5347 u32 *dump_buf,
5348 u32 buf_size_in_dwords,
5349 u32 *num_dumped_dwords)
5350{
5351 u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
5352 enum dbg_status status;
5353
5354 *num_dumped_dwords = 0;
5355
5356 status =
5357 qed_dbg_protection_override_get_dump_buf_size(p_hwfn,
5358 p_ptt,
5359 p_size);
5360 if (status != DBG_STATUS_OK)
5361 return status;
5362
5363 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5364 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5365
5366 /* Update reset state */
5367 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5368
5369 status = qed_protection_override_dump(p_hwfn,
5370 p_ptt,
5371 dump_buf,
5372 true, num_dumped_dwords);
5373
5374 /* Revert GRC params to their default */
5375 qed_dbg_grc_set_params_default(p_hwfn);
5376
5377 return status;
5378}
5379
5380enum dbg_status qed_dbg_fw_asserts_get_dump_buf_size(struct qed_hwfn *p_hwfn,
5381 struct qed_ptt *p_ptt,
5382 u32 *buf_size)
5383{
5384 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5385
5386 *buf_size = 0;
5387
5388 if (status != DBG_STATUS_OK)
5389 return status;
5390
5391 /* Update reset state */
5392 qed_update_blocks_reset_state(p_hwfn, p_ptt);
5393
5394 *buf_size = qed_fw_asserts_dump(p_hwfn, p_ptt, NULL, false);
5395
5396 return DBG_STATUS_OK;
5397}
5398
5399enum dbg_status qed_dbg_fw_asserts_dump(struct qed_hwfn *p_hwfn,
5400 struct qed_ptt *p_ptt,
5401 u32 *dump_buf,
5402 u32 buf_size_in_dwords,
5403 u32 *num_dumped_dwords)
5404{
5405 u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
5406 enum dbg_status status;
5407
5408 *num_dumped_dwords = 0;
5409
5410 status =
5411 qed_dbg_fw_asserts_get_dump_buf_size(p_hwfn,
5412 p_ptt,
5413 p_size);
5414 if (status != DBG_STATUS_OK)
5415 return status;
5416
5417 if (buf_size_in_dwords < needed_buf_size_in_dwords)
5418 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
5419
5420 *num_dumped_dwords = qed_fw_asserts_dump(p_hwfn, p_ptt, dump_buf, true);
5421
5422 /* Revert GRC params to their default */
5423 qed_dbg_grc_set_params_default(p_hwfn);
5424
5425 return DBG_STATUS_OK;
5426}
5427
5428enum dbg_status qed_dbg_read_attn(struct qed_hwfn *p_hwfn,
5429 struct qed_ptt *p_ptt,
5430 enum block_id block_id,
5431 enum dbg_attn_type attn_type,
5432 bool clear_status,
5433 struct dbg_attn_block_result *results)
5434{
5435 enum dbg_status status = qed_dbg_dev_init(p_hwfn, p_ptt);
5436 u8 reg_idx, num_attn_regs, num_result_regs = 0;
5437 const struct dbg_attn_reg *attn_reg_arr;
5438
5439 if (status != DBG_STATUS_OK)
5440 return status;
5441
5442 if (!s_dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
5443 !s_dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
5444 !s_dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
5445 return DBG_STATUS_DBG_ARRAY_NOT_SET;
5446
5447 attn_reg_arr = qed_get_block_attn_regs(block_id,
5448 attn_type, &num_attn_regs);
5449
5450 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
5451 const struct dbg_attn_reg *reg_data = &attn_reg_arr[reg_idx];
5452 struct dbg_attn_reg_result *reg_result;
5453 u32 sts_addr, sts_val;
5454 u16 modes_buf_offset;
5455 bool eval_mode;
5456
5457 /* Check mode */
5458 eval_mode = GET_FIELD(reg_data->mode.data,
5459 DBG_MODE_HDR_EVAL_MODE) > 0;
5460 modes_buf_offset = GET_FIELD(reg_data->mode.data,
5461 DBG_MODE_HDR_MODES_BUF_OFFSET);
5462 if (eval_mode && !qed_is_mode_match(p_hwfn, &modes_buf_offset))
5463 continue;
5464
5465 /* Mode match - read attention status register */
5466 sts_addr = DWORDS_TO_BYTES(clear_status ?
5467 reg_data->sts_clr_address :
5468 GET_FIELD(reg_data->data,
5469 DBG_ATTN_REG_STS_ADDRESS));
5470 sts_val = qed_rd(p_hwfn, p_ptt, sts_addr);
5471 if (!sts_val)
5472 continue;
5473
5474 /* Non-zero attention status - add to results */
5475 reg_result = &results->reg_results[num_result_regs];
5476 SET_FIELD(reg_result->data,
5477 DBG_ATTN_REG_RESULT_STS_ADDRESS, sts_addr);
5478 SET_FIELD(reg_result->data,
5479 DBG_ATTN_REG_RESULT_NUM_REG_ATTN,
5480 GET_FIELD(reg_data->data, DBG_ATTN_REG_NUM_REG_ATTN));
5481 reg_result->block_attn_offset = reg_data->block_attn_offset;
5482 reg_result->sts_val = sts_val;
5483 reg_result->mask_val = qed_rd(p_hwfn,
5484 p_ptt,
5485 DWORDS_TO_BYTES
5486 (reg_data->mask_address));
5487 num_result_regs++;
5488 }
5489
5490 results->block_id = (u8)block_id;
5491 results->names_offset =
5492 qed_get_block_attn_data(block_id, attn_type)->names_offset;
5493 SET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_ATTN_TYPE, attn_type);
5494 SET_FIELD(results->data,
5495 DBG_ATTN_BLOCK_RESULT_NUM_REGS, num_result_regs);
5496
5497 return DBG_STATUS_OK;
5498}
5499
5500/******************************* Data Types **********************************/
5501
5502struct block_info {
5503 const char *name;
5504 enum block_id id;
5505};
5506
5507struct mcp_trace_format {
5508 u32 data;
5509#define MCP_TRACE_FORMAT_MODULE_MASK 0x0000ffff
5510#define MCP_TRACE_FORMAT_MODULE_SHIFT 0
5511#define MCP_TRACE_FORMAT_LEVEL_MASK 0x00030000
5512#define MCP_TRACE_FORMAT_LEVEL_SHIFT 16
5513#define MCP_TRACE_FORMAT_P1_SIZE_MASK 0x000c0000
5514#define MCP_TRACE_FORMAT_P1_SIZE_SHIFT 18
5515#define MCP_TRACE_FORMAT_P2_SIZE_MASK 0x00300000
5516#define MCP_TRACE_FORMAT_P2_SIZE_SHIFT 20
5517#define MCP_TRACE_FORMAT_P3_SIZE_MASK 0x00c00000
5518#define MCP_TRACE_FORMAT_P3_SIZE_SHIFT 22
5519#define MCP_TRACE_FORMAT_LEN_MASK 0xff000000
5520#define MCP_TRACE_FORMAT_LEN_SHIFT 24
5521
5522 char *format_str;
5523};
5524
5525/* Meta data structure, generated by a perl script during MFW build. therefore,
5526 * the structs mcp_trace_meta and mcp_trace_format are duplicated in the perl
5527 * script.
5528 */
5529struct mcp_trace_meta {
5530 u32 modules_num;
5531 char **modules;
5532 u32 formats_num;
5533 struct mcp_trace_format *formats;
5534};
5535
5536/* REG fifo element */
5537struct reg_fifo_element {
5538 u64 data;
5539#define REG_FIFO_ELEMENT_ADDRESS_SHIFT 0
5540#define REG_FIFO_ELEMENT_ADDRESS_MASK 0x7fffff
5541#define REG_FIFO_ELEMENT_ACCESS_SHIFT 23
5542#define REG_FIFO_ELEMENT_ACCESS_MASK 0x1
5543#define REG_FIFO_ELEMENT_PF_SHIFT 24
5544#define REG_FIFO_ELEMENT_PF_MASK 0xf
5545#define REG_FIFO_ELEMENT_VF_SHIFT 28
5546#define REG_FIFO_ELEMENT_VF_MASK 0xff
5547#define REG_FIFO_ELEMENT_PORT_SHIFT 36
5548#define REG_FIFO_ELEMENT_PORT_MASK 0x3
5549#define REG_FIFO_ELEMENT_PRIVILEGE_SHIFT 38
5550#define REG_FIFO_ELEMENT_PRIVILEGE_MASK 0x3
5551#define REG_FIFO_ELEMENT_PROTECTION_SHIFT 40
5552#define REG_FIFO_ELEMENT_PROTECTION_MASK 0x7
5553#define REG_FIFO_ELEMENT_MASTER_SHIFT 43
5554#define REG_FIFO_ELEMENT_MASTER_MASK 0xf
5555#define REG_FIFO_ELEMENT_ERROR_SHIFT 47
5556#define REG_FIFO_ELEMENT_ERROR_MASK 0x1f
5557};
5558
5559/* IGU fifo element */
5560struct igu_fifo_element {
5561 u32 dword0;
5562#define IGU_FIFO_ELEMENT_DWORD0_FID_SHIFT 0
5563#define IGU_FIFO_ELEMENT_DWORD0_FID_MASK 0xff
5564#define IGU_FIFO_ELEMENT_DWORD0_IS_PF_SHIFT 8
5565#define IGU_FIFO_ELEMENT_DWORD0_IS_PF_MASK 0x1
5566#define IGU_FIFO_ELEMENT_DWORD0_SOURCE_SHIFT 9
5567#define IGU_FIFO_ELEMENT_DWORD0_SOURCE_MASK 0xf
5568#define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_SHIFT 13
5569#define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_MASK 0xf
5570#define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_SHIFT 17
5571#define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_MASK 0x7fff
5572 u32 dword1;
5573 u32 dword2;
5574#define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_SHIFT 0
5575#define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_MASK 0x1
5576#define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_SHIFT 1
5577#define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_MASK 0xffffffff
5578 u32 reserved;
5579};
5580
5581struct igu_fifo_wr_data {
5582 u32 data;
5583#define IGU_FIFO_WR_DATA_PROD_CONS_SHIFT 0
5584#define IGU_FIFO_WR_DATA_PROD_CONS_MASK 0xffffff
5585#define IGU_FIFO_WR_DATA_UPDATE_FLAG_SHIFT 24
5586#define IGU_FIFO_WR_DATA_UPDATE_FLAG_MASK 0x1
5587#define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_SHIFT 25
5588#define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_MASK 0x3
5589#define IGU_FIFO_WR_DATA_SEGMENT_SHIFT 27
5590#define IGU_FIFO_WR_DATA_SEGMENT_MASK 0x1
5591#define IGU_FIFO_WR_DATA_TIMER_MASK_SHIFT 28
5592#define IGU_FIFO_WR_DATA_TIMER_MASK_MASK 0x1
5593#define IGU_FIFO_WR_DATA_CMD_TYPE_SHIFT 31
5594#define IGU_FIFO_WR_DATA_CMD_TYPE_MASK 0x1
5595};
5596
5597struct igu_fifo_cleanup_wr_data {
5598 u32 data;
5599#define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_SHIFT 0
5600#define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_MASK 0x7ffffff
5601#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_SHIFT 27
5602#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_MASK 0x1
5603#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_SHIFT 28
5604#define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_MASK 0x7
5605#define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_SHIFT 31
5606#define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_MASK 0x1
5607};
5608
5609/* Protection override element */
5610struct protection_override_element {
5611 u64 data;
5612#define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_SHIFT 0
5613#define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_MASK 0x7fffff
5614#define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_SHIFT 23
5615#define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_MASK 0xffffff
5616#define PROTECTION_OVERRIDE_ELEMENT_READ_SHIFT 47
5617#define PROTECTION_OVERRIDE_ELEMENT_READ_MASK 0x1
5618#define PROTECTION_OVERRIDE_ELEMENT_WRITE_SHIFT 48
5619#define PROTECTION_OVERRIDE_ELEMENT_WRITE_MASK 0x1
5620#define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_SHIFT 49
5621#define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_MASK 0x7
5622#define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_SHIFT 52
5623#define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_MASK 0x7
5624};
5625
5626enum igu_fifo_sources {
5627 IGU_SRC_PXP0,
5628 IGU_SRC_PXP1,
5629 IGU_SRC_PXP2,
5630 IGU_SRC_PXP3,
5631 IGU_SRC_PXP4,
5632 IGU_SRC_PXP5,
5633 IGU_SRC_PXP6,
5634 IGU_SRC_PXP7,
5635 IGU_SRC_CAU,
5636 IGU_SRC_ATTN,
5637 IGU_SRC_GRC
5638};
5639
5640enum igu_fifo_addr_types {
5641 IGU_ADDR_TYPE_MSIX_MEM,
5642 IGU_ADDR_TYPE_WRITE_PBA,
5643 IGU_ADDR_TYPE_WRITE_INT_ACK,
5644 IGU_ADDR_TYPE_WRITE_ATTN_BITS,
5645 IGU_ADDR_TYPE_READ_INT,
5646 IGU_ADDR_TYPE_WRITE_PROD_UPDATE,
5647 IGU_ADDR_TYPE_RESERVED
5648};
5649
5650struct igu_fifo_addr_data {
5651 u16 start_addr;
5652 u16 end_addr;
5653 char *desc;
5654 char *vf_desc;
5655 enum igu_fifo_addr_types type;
5656};
5657
5658/******************************** Constants **********************************/
5659
5660#define MAX_MSG_LEN 1024
5661
5662#define MCP_TRACE_MAX_MODULE_LEN 8
5663#define MCP_TRACE_FORMAT_MAX_PARAMS 3
5664#define MCP_TRACE_FORMAT_PARAM_WIDTH \
5665 (MCP_TRACE_FORMAT_P2_SIZE_SHIFT - MCP_TRACE_FORMAT_P1_SIZE_SHIFT)
5666
5667#define REG_FIFO_ELEMENT_ADDR_FACTOR 4
5668#define REG_FIFO_ELEMENT_IS_PF_VF_VAL 127
5669
5670#define PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR 4
5671
5672/***************************** Constant Arrays *******************************/
5673
5674struct user_dbg_array {
5675 const u32 *ptr;
5676 u32 size_in_dwords;
5677};
5678
5679/* Debug arrays */
5680static struct user_dbg_array
5681s_user_dbg_arrays[MAX_BIN_DBG_BUFFER_TYPE] = { {NULL} };
5682
5683/* Block names array */
5684static struct block_info s_block_info_arr[] = {
5685 {"grc", BLOCK_GRC},
5686 {"miscs", BLOCK_MISCS},
5687 {"misc", BLOCK_MISC},
5688 {"dbu", BLOCK_DBU},
5689 {"pglue_b", BLOCK_PGLUE_B},
5690 {"cnig", BLOCK_CNIG},
5691 {"cpmu", BLOCK_CPMU},
5692 {"ncsi", BLOCK_NCSI},
5693 {"opte", BLOCK_OPTE},
5694 {"bmb", BLOCK_BMB},
5695 {"pcie", BLOCK_PCIE},
5696 {"mcp", BLOCK_MCP},
5697 {"mcp2", BLOCK_MCP2},
5698 {"pswhst", BLOCK_PSWHST},
5699 {"pswhst2", BLOCK_PSWHST2},
5700 {"pswrd", BLOCK_PSWRD},
5701 {"pswrd2", BLOCK_PSWRD2},
5702 {"pswwr", BLOCK_PSWWR},
5703 {"pswwr2", BLOCK_PSWWR2},
5704 {"pswrq", BLOCK_PSWRQ},
5705 {"pswrq2", BLOCK_PSWRQ2},
5706 {"pglcs", BLOCK_PGLCS},
5707 {"ptu", BLOCK_PTU},
5708 {"dmae", BLOCK_DMAE},
5709 {"tcm", BLOCK_TCM},
5710 {"mcm", BLOCK_MCM},
5711 {"ucm", BLOCK_UCM},
5712 {"xcm", BLOCK_XCM},
5713 {"ycm", BLOCK_YCM},
5714 {"pcm", BLOCK_PCM},
5715 {"qm", BLOCK_QM},
5716 {"tm", BLOCK_TM},
5717 {"dorq", BLOCK_DORQ},
5718 {"brb", BLOCK_BRB},
5719 {"src", BLOCK_SRC},
5720 {"prs", BLOCK_PRS},
5721 {"tsdm", BLOCK_TSDM},
5722 {"msdm", BLOCK_MSDM},
5723 {"usdm", BLOCK_USDM},
5724 {"xsdm", BLOCK_XSDM},
5725 {"ysdm", BLOCK_YSDM},
5726 {"psdm", BLOCK_PSDM},
5727 {"tsem", BLOCK_TSEM},
5728 {"msem", BLOCK_MSEM},
5729 {"usem", BLOCK_USEM},
5730 {"xsem", BLOCK_XSEM},
5731 {"ysem", BLOCK_YSEM},
5732 {"psem", BLOCK_PSEM},
5733 {"rss", BLOCK_RSS},
5734 {"tmld", BLOCK_TMLD},
5735 {"muld", BLOCK_MULD},
5736 {"yuld", BLOCK_YULD},
5737 {"xyld", BLOCK_XYLD},
5738 {"ptld", BLOCK_PTLD},
5739 {"ypld", BLOCK_YPLD},
5740 {"prm", BLOCK_PRM},
5741 {"pbf_pb1", BLOCK_PBF_PB1},
5742 {"pbf_pb2", BLOCK_PBF_PB2},
5743 {"rpb", BLOCK_RPB},
5744 {"btb", BLOCK_BTB},
5745 {"pbf", BLOCK_PBF},
5746 {"rdif", BLOCK_RDIF},
5747 {"tdif", BLOCK_TDIF},
5748 {"cdu", BLOCK_CDU},
5749 {"ccfc", BLOCK_CCFC},
5750 {"tcfc", BLOCK_TCFC},
5751 {"igu", BLOCK_IGU},
5752 {"cau", BLOCK_CAU},
5753 {"rgfs", BLOCK_RGFS},
5754 {"rgsrc", BLOCK_RGSRC},
5755 {"tgfs", BLOCK_TGFS},
5756 {"tgsrc", BLOCK_TGSRC},
5757 {"umac", BLOCK_UMAC},
5758 {"xmac", BLOCK_XMAC},
5759 {"dbg", BLOCK_DBG},
5760 {"nig", BLOCK_NIG},
5761 {"wol", BLOCK_WOL},
5762 {"bmbn", BLOCK_BMBN},
5763 {"ipc", BLOCK_IPC},
5764 {"nwm", BLOCK_NWM},
5765 {"nws", BLOCK_NWS},
5766 {"ms", BLOCK_MS},
5767 {"phy_pcie", BLOCK_PHY_PCIE},
5768 {"led", BLOCK_LED},
5769 {"avs_wrap", BLOCK_AVS_WRAP},
5770 {"pxpreqbus", BLOCK_PXPREQBUS},
5771 {"misc_aeu", BLOCK_MISC_AEU},
5772 {"bar0_map", BLOCK_BAR0_MAP}
5773};
5774
5775/* Status string array */
5776static const char * const s_status_str[] = {
5777 /* DBG_STATUS_OK */
5778 "Operation completed successfully",
5779
5780 /* DBG_STATUS_APP_VERSION_NOT_SET */
5781 "Debug application version wasn't set",
5782
5783 /* DBG_STATUS_UNSUPPORTED_APP_VERSION */
5784 "Unsupported debug application version",
5785
5786 /* DBG_STATUS_DBG_BLOCK_NOT_RESET */
5787 "The debug block wasn't reset since the last recording",
5788
5789 /* DBG_STATUS_INVALID_ARGS */
5790 "Invalid arguments",
5791
5792 /* DBG_STATUS_OUTPUT_ALREADY_SET */
5793 "The debug output was already set",
5794
5795 /* DBG_STATUS_INVALID_PCI_BUF_SIZE */
5796 "Invalid PCI buffer size",
5797
5798 /* DBG_STATUS_PCI_BUF_ALLOC_FAILED */
5799 "PCI buffer allocation failed",
5800
5801 /* DBG_STATUS_PCI_BUF_NOT_ALLOCATED */
5802 "A PCI buffer wasn't allocated",
5803
5804 /* DBG_STATUS_TOO_MANY_INPUTS */
5805 "Too many inputs were enabled. Enabled less inputs, or set 'unifyInputs' to true",
5806
5807 /* DBG_STATUS_INPUT_OVERLAP */
5808 "Overlapping debug bus inputs",
5809
5810 /* DBG_STATUS_HW_ONLY_RECORDING */
5811 "Cannot record Storm data since the entire recording cycle is used by HW",
5812
5813 /* DBG_STATUS_STORM_ALREADY_ENABLED */
5814 "The Storm was already enabled",
5815
5816 /* DBG_STATUS_STORM_NOT_ENABLED */
5817 "The specified Storm wasn't enabled",
5818
5819 /* DBG_STATUS_BLOCK_ALREADY_ENABLED */
5820 "The block was already enabled",
5821
5822 /* DBG_STATUS_BLOCK_NOT_ENABLED */
5823 "The specified block wasn't enabled",
5824
5825 /* DBG_STATUS_NO_INPUT_ENABLED */
5826 "No input was enabled for recording",
5827
5828 /* DBG_STATUS_NO_FILTER_TRIGGER_64B */
5829 "Filters and triggers are not allowed when recording in 64b units",
5830
5831 /* DBG_STATUS_FILTER_ALREADY_ENABLED */
5832 "The filter was already enabled",
5833
5834 /* DBG_STATUS_TRIGGER_ALREADY_ENABLED */
5835 "The trigger was already enabled",
5836
5837 /* DBG_STATUS_TRIGGER_NOT_ENABLED */
5838 "The trigger wasn't enabled",
5839
5840 /* DBG_STATUS_CANT_ADD_CONSTRAINT */
5841 "A constraint can be added only after a filter was enabled or a trigger state was added",
5842
5843 /* DBG_STATUS_TOO_MANY_TRIGGER_STATES */
5844 "Cannot add more than 3 trigger states",
5845
5846 /* DBG_STATUS_TOO_MANY_CONSTRAINTS */
5847 "Cannot add more than 4 constraints per filter or trigger state",
5848
5849 /* DBG_STATUS_RECORDING_NOT_STARTED */
5850 "The recording wasn't started",
5851
5852 /* DBG_STATUS_DATA_DIDNT_TRIGGER */
5853 "A trigger was configured, but it didn't trigger",
5854
5855 /* DBG_STATUS_NO_DATA_RECORDED */
5856 "No data was recorded",
5857
5858 /* DBG_STATUS_DUMP_BUF_TOO_SMALL */
5859 "Dump buffer is too small",
5860
5861 /* DBG_STATUS_DUMP_NOT_CHUNK_ALIGNED */
5862 "Dumped data is not aligned to chunks",
5863
5864 /* DBG_STATUS_UNKNOWN_CHIP */
5865 "Unknown chip",
5866
5867 /* DBG_STATUS_VIRT_MEM_ALLOC_FAILED */
5868 "Failed allocating virtual memory",
5869
5870 /* DBG_STATUS_BLOCK_IN_RESET */
5871 "The input block is in reset",
5872
5873 /* DBG_STATUS_INVALID_TRACE_SIGNATURE */
5874 "Invalid MCP trace signature found in NVRAM",
5875
5876 /* DBG_STATUS_INVALID_NVRAM_BUNDLE */
5877 "Invalid bundle ID found in NVRAM",
5878
5879 /* DBG_STATUS_NVRAM_GET_IMAGE_FAILED */
5880 "Failed getting NVRAM image",
5881
5882 /* DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE */
5883 "NVRAM image is not dword-aligned",
5884
5885 /* DBG_STATUS_NVRAM_READ_FAILED */
5886 "Failed reading from NVRAM",
5887
5888 /* DBG_STATUS_IDLE_CHK_PARSE_FAILED */
5889 "Idle check parsing failed",
5890
5891 /* DBG_STATUS_MCP_TRACE_BAD_DATA */
5892 "MCP Trace data is corrupt",
5893
5894 /* DBG_STATUS_MCP_TRACE_NO_META */
5895 "Dump doesn't contain meta data - it must be provided in image file",
5896
5897 /* DBG_STATUS_MCP_COULD_NOT_HALT */
5898 "Failed to halt MCP",
5899
5900 /* DBG_STATUS_MCP_COULD_NOT_RESUME */
5901 "Failed to resume MCP after halt",
5902
5903 /* DBG_STATUS_RESERVED2 */
5904 "Reserved debug status - shouldn't be returned",
5905
5906 /* DBG_STATUS_SEMI_FIFO_NOT_EMPTY */
5907 "Failed to empty SEMI sync FIFO",
5908
5909 /* DBG_STATUS_IGU_FIFO_BAD_DATA */
5910 "IGU FIFO data is corrupt",
5911
5912 /* DBG_STATUS_MCP_COULD_NOT_MASK_PRTY */
5913 "MCP failed to mask parities",
5914
5915 /* DBG_STATUS_FW_ASSERTS_PARSE_FAILED */
5916 "FW Asserts parsing failed",
5917
5918 /* DBG_STATUS_REG_FIFO_BAD_DATA */
5919 "GRC FIFO data is corrupt",
5920
5921 /* DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA */
5922 "Protection Override data is corrupt",
5923
5924 /* DBG_STATUS_DBG_ARRAY_NOT_SET */
5925 "Debug arrays were not set (when using binary files, dbg_set_bin_ptr must be called)",
5926
5927 /* DBG_STATUS_FILTER_BUG */
5928 "Debug Bus filtering requires the -unifyInputs option (due to a HW bug)",
5929
5930 /* DBG_STATUS_NON_MATCHING_LINES */
5931 "Non-matching debug lines - all lines must be of the same type (either 128b or 256b)",
5932
5933 /* DBG_STATUS_INVALID_TRIGGER_DWORD_OFFSET */
5934 "The selected trigger dword offset wasn't enabled in the recorded HW block",
5935
5936 /* DBG_STATUS_DBG_BUS_IN_USE */
5937 "The debug bus is in use"
5938};
5939
5940/* Idle check severity names array */
5941static const char * const s_idle_chk_severity_str[] = {
5942 "Error",
5943 "Error if no traffic",
5944 "Warning"
5945};
5946
5947/* MCP Trace level names array */
5948static const char * const s_mcp_trace_level_str[] = {
5949 "ERROR",
5950 "TRACE",
5951 "DEBUG"
5952};
5953
5954/* Access type names array */
5955static const char * const s_access_strs[] = {
5956 "read",
5957 "write"
5958};
5959
5960/* Privilege type names array */
5961static const char * const s_privilege_strs[] = {
5962 "VF",
5963 "PDA",
5964 "HV",
5965 "UA"
5966};
5967
5968/* Protection type names array */
5969static const char * const s_protection_strs[] = {
5970 "(default)",
5971 "(default)",
5972 "(default)",
5973 "(default)",
5974 "override VF",
5975 "override PDA",
5976 "override HV",
5977 "override UA"
5978};
5979
5980/* Master type names array */
5981static const char * const s_master_strs[] = {
5982 "???",
5983 "pxp",
5984 "mcp",
5985 "msdm",
5986 "psdm",
5987 "ysdm",
5988 "usdm",
5989 "tsdm",
5990 "xsdm",
5991 "dbu",
5992 "dmae",
5993 "???",
5994 "???",
5995 "???",
5996 "???",
5997 "???"
5998};
5999
6000/* REG FIFO error messages array */
6001static const char * const s_reg_fifo_error_strs[] = {
6002 "grc timeout",
6003 "address doesn't belong to any block",
6004 "reserved address in block or write to read-only address",
6005 "privilege/protection mismatch",
6006 "path isolation error"
6007};
6008
6009/* IGU FIFO sources array */
6010static const char * const s_igu_fifo_source_strs[] = {
6011 "TSTORM",
6012 "MSTORM",
6013 "USTORM",
6014 "XSTORM",
6015 "YSTORM",
6016 "PSTORM",
6017 "PCIE",
6018 "NIG_QM_PBF",
6019 "CAU",
6020 "ATTN",
6021 "GRC",
6022};
6023
6024/* IGU FIFO error messages */
6025static const char * const s_igu_fifo_error_strs[] = {
6026 "no error",
6027 "length error",
6028 "function disabled",
6029 "VF sent command to attnetion address",
6030 "host sent prod update command",
6031 "read of during interrupt register while in MIMD mode",
6032 "access to PXP BAR reserved address",
6033 "producer update command to attention index",
6034 "unknown error",
6035 "SB index not valid",
6036 "SB relative index and FID not found",
6037 "FID not match",
6038 "command with error flag asserted (PCI error or CAU discard)",
6039 "VF sent cleanup and RF cleanup is disabled",
6040 "cleanup command on type bigger than 4"
6041};
6042
6043/* IGU FIFO address data */
6044static const struct igu_fifo_addr_data s_igu_fifo_addr_data[] = {
6045 {0x0, 0x101, "MSI-X Memory", NULL,
6046 IGU_ADDR_TYPE_MSIX_MEM},
6047 {0x102, 0x1ff, "reserved", NULL,
6048 IGU_ADDR_TYPE_RESERVED},
6049 {0x200, 0x200, "Write PBA[0:63]", NULL,
6050 IGU_ADDR_TYPE_WRITE_PBA},
6051 {0x201, 0x201, "Write PBA[64:127]", "reserved",
6052 IGU_ADDR_TYPE_WRITE_PBA},
6053 {0x202, 0x202, "Write PBA[128]", "reserved",
6054 IGU_ADDR_TYPE_WRITE_PBA},
6055 {0x203, 0x3ff, "reserved", NULL,
6056 IGU_ADDR_TYPE_RESERVED},
6057 {0x400, 0x5ef, "Write interrupt acknowledgment", NULL,
6058 IGU_ADDR_TYPE_WRITE_INT_ACK},
6059 {0x5f0, 0x5f0, "Attention bits update", NULL,
6060 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6061 {0x5f1, 0x5f1, "Attention bits set", NULL,
6062 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6063 {0x5f2, 0x5f2, "Attention bits clear", NULL,
6064 IGU_ADDR_TYPE_WRITE_ATTN_BITS},
6065 {0x5f3, 0x5f3, "Read interrupt 0:63 with mask", NULL,
6066 IGU_ADDR_TYPE_READ_INT},
6067 {0x5f4, 0x5f4, "Read interrupt 0:31 with mask", NULL,
6068 IGU_ADDR_TYPE_READ_INT},
6069 {0x5f5, 0x5f5, "Read interrupt 32:63 with mask", NULL,
6070 IGU_ADDR_TYPE_READ_INT},
6071 {0x5f6, 0x5f6, "Read interrupt 0:63 without mask", NULL,
6072 IGU_ADDR_TYPE_READ_INT},
6073 {0x5f7, 0x5ff, "reserved", NULL,
6074 IGU_ADDR_TYPE_RESERVED},
6075 {0x600, 0x7ff, "Producer update", NULL,
6076 IGU_ADDR_TYPE_WRITE_PROD_UPDATE}
6077};
6078
6079/******************************** Variables **********************************/
6080
6081/* MCP Trace meta data array - used in case the dump doesn't contain the
6082 * meta data (e.g. due to no NVRAM access).
6083 */
6084static struct user_dbg_array s_mcp_trace_meta_arr = { NULL, 0 };
6085
6086/* Parsed MCP Trace meta data info, based on MCP trace meta array */
6087static struct mcp_trace_meta s_mcp_trace_meta;
6088static bool s_mcp_trace_meta_valid;
6089
6090/* Temporary buffer, used for print size calculations */
6091static char s_temp_buf[MAX_MSG_LEN];
6092
6093/**************************** Private Functions ******************************/
6094
6095static u32 qed_cyclic_add(u32 a, u32 b, u32 size)
6096{
6097 return (a + b) % size;
6098}
6099
6100static u32 qed_cyclic_sub(u32 a, u32 b, u32 size)
6101{
6102 return (size + a - b) % size;
6103}
6104
6105/* Reads the specified number of bytes from the specified cyclic buffer (up to 4
6106 * bytes) and returns them as a dword value. the specified buffer offset is
6107 * updated.
6108 */
6109static u32 qed_read_from_cyclic_buf(void *buf,
6110 u32 *offset,
6111 u32 buf_size, u8 num_bytes_to_read)
6112{
6113 u8 i, *val_ptr, *bytes_buf = (u8 *)buf;
6114 u32 val = 0;
6115
6116 val_ptr = (u8 *)&val;
6117
6118 /* Assume running on a LITTLE ENDIAN and the buffer is network order
6119 * (BIG ENDIAN), as high order bytes are placed in lower memory address.
6120 */
6121 for (i = 0; i < num_bytes_to_read; i++) {
6122 val_ptr[i] = bytes_buf[*offset];
6123 *offset = qed_cyclic_add(*offset, 1, buf_size);
6124 }
6125
6126 return val;
6127}
6128
6129/* Reads and returns the next byte from the specified buffer.
6130 * The specified buffer offset is updated.
6131 */
6132static u8 qed_read_byte_from_buf(void *buf, u32 *offset)
6133{
6134 return ((u8 *)buf)[(*offset)++];
6135}
6136
6137/* Reads and returns the next dword from the specified buffer.
6138 * The specified buffer offset is updated.
6139 */
6140static u32 qed_read_dword_from_buf(void *buf, u32 *offset)
6141{
6142 u32 dword_val = *(u32 *)&((u8 *)buf)[*offset];
6143
6144 *offset += 4;
6145
6146 return dword_val;
6147}
6148
6149/* Reads the next string from the specified buffer, and copies it to the
6150 * specified pointer. The specified buffer offset is updated.
6151 */
6152static void qed_read_str_from_buf(void *buf, u32 *offset, u32 size, char *dest)
6153{
6154 const char *source_str = &((const char *)buf)[*offset];
6155
6156 strncpy(dest, source_str, size);
6157 dest[size - 1] = '\0';
6158 *offset += size;
6159}
6160
6161/* Returns a pointer to the specified offset (in bytes) of the specified buffer.
6162 * If the specified buffer in NULL, a temporary buffer pointer is returned.
6163 */
6164static char *qed_get_buf_ptr(void *buf, u32 offset)
6165{
6166 return buf ? (char *)buf + offset : s_temp_buf;
6167}
6168
6169/* Reads a param from the specified buffer. Returns the number of dwords read.
6170 * If the returned str_param is NULL, the param is numeric and its value is
6171 * returned in num_param.
6172 * Otheriwise, the param is a string and its pointer is returned in str_param.
6173 */
6174static u32 qed_read_param(u32 *dump_buf,
6175 const char **param_name,
6176 const char **param_str_val, u32 *param_num_val)
6177{
6178 char *char_buf = (char *)dump_buf;
6179 size_t offset = 0;
6180
6181 /* Extract param name */
6182 *param_name = char_buf;
6183 offset += strlen(*param_name) + 1;
6184
6185 /* Check param type */
6186 if (*(char_buf + offset++)) {
6187 /* String param */
6188 *param_str_val = char_buf + offset;
6189 *param_num_val = 0;
6190 offset += strlen(*param_str_val) + 1;
6191 if (offset & 0x3)
6192 offset += (4 - (offset & 0x3));
6193 } else {
6194 /* Numeric param */
6195 *param_str_val = NULL;
6196 if (offset & 0x3)
6197 offset += (4 - (offset & 0x3));
6198 *param_num_val = *(u32 *)(char_buf + offset);
6199 offset += 4;
6200 }
6201
6202 return (u32)offset / 4;
6203}
6204
6205/* Reads a section header from the specified buffer.
6206 * Returns the number of dwords read.
6207 */
6208static u32 qed_read_section_hdr(u32 *dump_buf,
6209 const char **section_name,
6210 u32 *num_section_params)
6211{
6212 const char *param_str_val;
6213
6214 return qed_read_param(dump_buf,
6215 section_name, ¶m_str_val, num_section_params);
6216}
6217
6218/* Reads section params from the specified buffer and prints them to the results
6219 * buffer. Returns the number of dwords read.
6220 */
6221static u32 qed_print_section_params(u32 *dump_buf,
6222 u32 num_section_params,
6223 char *results_buf, u32 *num_chars_printed)
6224{
6225 u32 i, dump_offset = 0, results_offset = 0;
6226
6227 for (i = 0; i < num_section_params; i++) {
6228 const char *param_name, *param_str_val;
6229 u32 param_num_val = 0;
6230
6231 dump_offset += qed_read_param(dump_buf + dump_offset,
6232 ¶m_name,
6233 ¶m_str_val, ¶m_num_val);
6234
6235 if (param_str_val)
6236 results_offset +=
6237 sprintf(qed_get_buf_ptr(results_buf,
6238 results_offset),
6239 "%s: %s\n", param_name, param_str_val);
6240 else if (strcmp(param_name, "fw-timestamp"))
6241 results_offset +=
6242 sprintf(qed_get_buf_ptr(results_buf,
6243 results_offset),
6244 "%s: %d\n", param_name, param_num_val);
6245 }
6246
6247 results_offset += sprintf(qed_get_buf_ptr(results_buf, results_offset),
6248 "\n");
6249
6250 *num_chars_printed = results_offset;
6251
6252 return dump_offset;
6253}
6254
6255/* Parses the idle check rules and returns the number of characters printed.
6256 * In case of parsing error, returns 0.
6257 */
6258static u32 qed_parse_idle_chk_dump_rules(u32 *dump_buf,
6259 u32 *dump_buf_end,
6260 u32 num_rules,
6261 bool print_fw_idle_chk,
6262 char *results_buf,
6263 u32 *num_errors, u32 *num_warnings)
6264{
6265 /* Offset in results_buf in bytes */
6266 u32 results_offset = 0;
6267
6268 u32 rule_idx;
6269 u16 i, j;
6270
6271 *num_errors = 0;
6272 *num_warnings = 0;
6273
6274 /* Go over dumped results */
6275 for (rule_idx = 0; rule_idx < num_rules && dump_buf < dump_buf_end;
6276 rule_idx++) {
6277 const struct dbg_idle_chk_rule_parsing_data *rule_parsing_data;
6278 struct dbg_idle_chk_result_hdr *hdr;
6279 const char *parsing_str, *lsi_msg;
6280 u32 parsing_str_offset;
6281 bool has_fw_msg;
6282 u8 curr_reg_id;
6283
6284 hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
6285 rule_parsing_data =
6286 (const struct dbg_idle_chk_rule_parsing_data *)
6287 &s_user_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].
6288 ptr[hdr->rule_id];
6289 parsing_str_offset =
6290 GET_FIELD(rule_parsing_data->data,
6291 DBG_IDLE_CHK_RULE_PARSING_DATA_STR_OFFSET);
6292 has_fw_msg =
6293 GET_FIELD(rule_parsing_data->data,
6294 DBG_IDLE_CHK_RULE_PARSING_DATA_HAS_FW_MSG) > 0;
6295 parsing_str =
6296 &((const char *)
6297 s_user_dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr)
6298 [parsing_str_offset];
6299 lsi_msg = parsing_str;
6300 curr_reg_id = 0;
6301
6302 if (hdr->severity >= MAX_DBG_IDLE_CHK_SEVERITY_TYPES)
6303 return 0;
6304
6305 /* Skip rule header */
6306 dump_buf += BYTES_TO_DWORDS(sizeof(*hdr));
6307
6308 /* Update errors/warnings count */
6309 if (hdr->severity == IDLE_CHK_SEVERITY_ERROR ||
6310 hdr->severity == IDLE_CHK_SEVERITY_ERROR_NO_TRAFFIC)
6311 (*num_errors)++;
6312 else
6313 (*num_warnings)++;
6314
6315 /* Print rule severity */
6316 results_offset +=
6317 sprintf(qed_get_buf_ptr(results_buf,
6318 results_offset), "%s: ",
6319 s_idle_chk_severity_str[hdr->severity]);
6320
6321 /* Print rule message */
6322 if (has_fw_msg)
6323 parsing_str += strlen(parsing_str) + 1;
6324 results_offset +=
6325 sprintf(qed_get_buf_ptr(results_buf,
6326 results_offset), "%s.",
6327 has_fw_msg &&
6328 print_fw_idle_chk ? parsing_str : lsi_msg);
6329 parsing_str += strlen(parsing_str) + 1;
6330
6331 /* Print register values */
6332 results_offset +=
6333 sprintf(qed_get_buf_ptr(results_buf,
6334 results_offset), " Registers:");
6335 for (i = 0;
6336 i < hdr->num_dumped_cond_regs + hdr->num_dumped_info_regs;
6337 i++) {
6338 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
6339 bool is_mem;
6340 u8 reg_id;
6341
6342 reg_hdr =
6343 (struct dbg_idle_chk_result_reg_hdr *)dump_buf;
6344 is_mem = GET_FIELD(reg_hdr->data,
6345 DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM);
6346 reg_id = GET_FIELD(reg_hdr->data,
6347 DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID);
6348
6349 /* Skip reg header */
6350 dump_buf += BYTES_TO_DWORDS(sizeof(*reg_hdr));
6351
6352 /* Skip register names until the required reg_id is
6353 * reached.
6354 */
6355 for (; reg_id > curr_reg_id;
6356 curr_reg_id++,
6357 parsing_str += strlen(parsing_str) + 1);
6358
6359 results_offset +=
6360 sprintf(qed_get_buf_ptr(results_buf,
6361 results_offset), " %s",
6362 parsing_str);
6363 if (i < hdr->num_dumped_cond_regs && is_mem)
6364 results_offset +=
6365 sprintf(qed_get_buf_ptr(results_buf,
6366 results_offset),
6367 "[%d]", hdr->mem_entry_id +
6368 reg_hdr->start_entry);
6369 results_offset +=
6370 sprintf(qed_get_buf_ptr(results_buf,
6371 results_offset), "=");
6372 for (j = 0; j < reg_hdr->size; j++, dump_buf++) {
6373 results_offset +=
6374 sprintf(qed_get_buf_ptr(results_buf,
6375 results_offset),
6376 "0x%x", *dump_buf);
6377 if (j < reg_hdr->size - 1)
6378 results_offset +=
6379 sprintf(qed_get_buf_ptr
6380 (results_buf,
6381 results_offset), ",");
6382 }
6383 }
6384
6385 results_offset +=
6386 sprintf(qed_get_buf_ptr(results_buf, results_offset), "\n");
6387 }
6388
6389 /* Check if end of dump buffer was exceeded */
6390 if (dump_buf > dump_buf_end)
6391 return 0;
6392
6393 return results_offset;
6394}
6395
6396/* Parses an idle check dump buffer.
6397 * If result_buf is not NULL, the idle check results are printed to it.
6398 * In any case, the required results buffer size is assigned to
6399 * parsed_results_bytes.
6400 * The parsing status is returned.
6401 */
6402static enum dbg_status qed_parse_idle_chk_dump(u32 *dump_buf,
6403 u32 num_dumped_dwords,
6404 char *results_buf,
6405 u32 *parsed_results_bytes,
6406 u32 *num_errors,
6407 u32 *num_warnings)
6408{
6409 const char *section_name, *param_name, *param_str_val;
6410 u32 *dump_buf_end = dump_buf + num_dumped_dwords;
6411 u32 num_section_params = 0, num_rules;
6412
6413 /* Offset in results_buf in bytes */
6414 u32 results_offset = 0;
6415
6416 *parsed_results_bytes = 0;
6417 *num_errors = 0;
6418 *num_warnings = 0;
6419
6420 if (!s_user_dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr ||
6421 !s_user_dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].ptr)
6422 return DBG_STATUS_DBG_ARRAY_NOT_SET;
6423
6424 /* Read global_params section */
6425 dump_buf += qed_read_section_hdr(dump_buf,
6426 §ion_name, &num_section_params);
6427 if (strcmp(section_name, "global_params"))
6428 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6429
6430 /* Print global params */
6431 dump_buf += qed_print_section_params(dump_buf,
6432 num_section_params,
6433 results_buf, &results_offset);
6434
6435 /* Read idle_chk section */
6436 dump_buf += qed_read_section_hdr(dump_buf,
6437 §ion_name, &num_section_params);
6438 if (strcmp(section_name, "idle_chk") || num_section_params != 1)
6439 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6440 dump_buf += qed_read_param(dump_buf,
6441 ¶m_name, ¶m_str_val, &num_rules);
6442 if (strcmp(param_name, "num_rules"))
6443 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6444
6445 if (num_rules) {
6446 u32 rules_print_size;
6447
6448 /* Print FW output */
6449 results_offset +=
6450 sprintf(qed_get_buf_ptr(results_buf,
6451 results_offset),
6452 "FW_IDLE_CHECK:\n");
6453 rules_print_size =
6454 qed_parse_idle_chk_dump_rules(dump_buf,
6455 dump_buf_end,
6456 num_rules,
6457 true,
6458 results_buf ?
6459 results_buf +
6460 results_offset :
6461 NULL,
6462 num_errors,
6463 num_warnings);
6464 results_offset += rules_print_size;
6465 if (!rules_print_size)
6466 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6467
6468 /* Print LSI output */
6469 results_offset +=
6470 sprintf(qed_get_buf_ptr(results_buf,
6471 results_offset),
6472 "\nLSI_IDLE_CHECK:\n");
6473 rules_print_size =
6474 qed_parse_idle_chk_dump_rules(dump_buf,
6475 dump_buf_end,
6476 num_rules,
6477 false,
6478 results_buf ?
6479 results_buf +
6480 results_offset :
6481 NULL,
6482 num_errors,
6483 num_warnings);
6484 results_offset += rules_print_size;
6485 if (!rules_print_size)
6486 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
6487 }
6488
6489 /* Print errors/warnings count */
6490 if (*num_errors)
6491 results_offset +=
6492 sprintf(qed_get_buf_ptr(results_buf,
6493 results_offset),
6494 "\nIdle Check failed!!! (with %d errors and %d warnings)\n",
6495 *num_errors, *num_warnings);
6496 else if (*num_warnings)
6497 results_offset +=
6498 sprintf(qed_get_buf_ptr(results_buf,
6499 results_offset),
6500 "\nIdle Check completed successfully (with %d warnings)\n",
6501 *num_warnings);
6502 else
6503 results_offset +=
6504 sprintf(qed_get_buf_ptr(results_buf,
6505 results_offset),
6506 "\nIdle Check completed successfully\n");
6507
6508 /* Add 1 for string NULL termination */
6509 *parsed_results_bytes = results_offset + 1;
6510
6511 return DBG_STATUS_OK;
6512}
6513
6514/* Frees the specified MCP Trace meta data */
6515static void qed_mcp_trace_free_meta(struct qed_hwfn *p_hwfn,
6516 struct mcp_trace_meta *meta)
6517{
6518 u32 i;
6519
6520 s_mcp_trace_meta_valid = false;
6521
6522 /* Release modules */
6523 if (meta->modules) {
6524 for (i = 0; i < meta->modules_num; i++)
6525 kfree(meta->modules[i]);
6526 kfree(meta->modules);
6527 }
6528
6529 /* Release formats */
6530 if (meta->formats) {
6531 for (i = 0; i < meta->formats_num; i++)
6532 kfree(meta->formats[i].format_str);
6533 kfree(meta->formats);
6534 }
6535}
6536
6537/* Allocates and fills MCP Trace meta data based on the specified meta data
6538 * dump buffer.
6539 * Returns debug status code.
6540 */
6541static enum dbg_status qed_mcp_trace_alloc_meta(struct qed_hwfn *p_hwfn,
6542 const u32 *meta_buf,
6543 struct mcp_trace_meta *meta)
6544{
6545 u8 *meta_buf_bytes = (u8 *)meta_buf;
6546 u32 offset = 0, signature, i;
6547
6548 /* Free the previous meta before loading a new one. */
6549 if (s_mcp_trace_meta_valid)
6550 qed_mcp_trace_free_meta(p_hwfn, meta);
6551
6552 memset(meta, 0, sizeof(*meta));
6553
6554 /* Read first signature */
6555 signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6556 if (signature != NVM_MAGIC_VALUE)
6557 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
6558
6559 /* Read no. of modules and allocate memory for their pointers */
6560 meta->modules_num = qed_read_byte_from_buf(meta_buf_bytes, &offset);
6561 meta->modules = kzalloc(meta->modules_num * sizeof(char *), GFP_KERNEL);
6562 if (!meta->modules)
6563 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6564
6565 /* Allocate and read all module strings */
6566 for (i = 0; i < meta->modules_num; i++) {
6567 u8 module_len = qed_read_byte_from_buf(meta_buf_bytes, &offset);
6568
6569 *(meta->modules + i) = kzalloc(module_len, GFP_KERNEL);
6570 if (!(*(meta->modules + i))) {
6571 /* Update number of modules to be released */
6572 meta->modules_num = i ? i - 1 : 0;
6573 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6574 }
6575
6576 qed_read_str_from_buf(meta_buf_bytes, &offset, module_len,
6577 *(meta->modules + i));
6578 if (module_len > MCP_TRACE_MAX_MODULE_LEN)
6579 (*(meta->modules + i))[MCP_TRACE_MAX_MODULE_LEN] = '\0';
6580 }
6581
6582 /* Read second signature */
6583 signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6584 if (signature != NVM_MAGIC_VALUE)
6585 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
6586
6587 /* Read number of formats and allocate memory for all formats */
6588 meta->formats_num = qed_read_dword_from_buf(meta_buf_bytes, &offset);
6589 meta->formats = kzalloc(meta->formats_num *
6590 sizeof(struct mcp_trace_format),
6591 GFP_KERNEL);
6592 if (!meta->formats)
6593 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6594
6595 /* Allocate and read all strings */
6596 for (i = 0; i < meta->formats_num; i++) {
6597 struct mcp_trace_format *format_ptr = &meta->formats[i];
6598 u8 format_len;
6599
6600 format_ptr->data = qed_read_dword_from_buf(meta_buf_bytes,
6601 &offset);
6602 format_len =
6603 (format_ptr->data &
6604 MCP_TRACE_FORMAT_LEN_MASK) >> MCP_TRACE_FORMAT_LEN_SHIFT;
6605 format_ptr->format_str = kzalloc(format_len, GFP_KERNEL);
6606 if (!format_ptr->format_str) {
6607 /* Update number of modules to be released */
6608 meta->formats_num = i ? i - 1 : 0;
6609 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
6610 }
6611
6612 qed_read_str_from_buf(meta_buf_bytes,
6613 &offset,
6614 format_len, format_ptr->format_str);
6615 }
6616
6617 s_mcp_trace_meta_valid = true;
6618 return DBG_STATUS_OK;
6619}
6620
6621/* Parses an MCP trace buffer. If result_buf is not NULL, the MCP Trace results
6622 * are printed to it. The parsing status is returned.
6623 * Arguments:
6624 * trace_buf - MCP trace cyclic buffer
6625 * trace_buf_size - MCP trace cyclic buffer size in bytes
6626 * data_offset - offset in bytes of the data to parse in the MCP trace cyclic
6627 * buffer.
6628 * data_size - size in bytes of data to parse.
6629 * parsed_buf - destination buffer for parsed data.
6630 * parsed_bytes - size of parsed data in bytes.
6631 */
6632static enum dbg_status qed_parse_mcp_trace_buf(u8 *trace_buf,
6633 u32 trace_buf_size,
6634 u32 data_offset,
6635 u32 data_size,
6636 char *parsed_buf,
6637 u32 *parsed_bytes)
6638{
6639 u32 param_mask, param_shift;
6640 enum dbg_status status;
6641
6642 *parsed_bytes = 0;
6643
6644 if (!s_mcp_trace_meta_valid)
6645 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6646
6647 status = DBG_STATUS_OK;
6648
6649 while (data_size) {
6650 struct mcp_trace_format *format_ptr;
6651 u8 format_level, format_module;
6652 u32 params[3] = { 0, 0, 0 };
6653 u32 header, format_idx, i;
6654
6655 if (data_size < MFW_TRACE_ENTRY_SIZE)
6656 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6657
6658 header = qed_read_from_cyclic_buf(trace_buf,
6659 &data_offset,
6660 trace_buf_size,
6661 MFW_TRACE_ENTRY_SIZE);
6662 data_size -= MFW_TRACE_ENTRY_SIZE;
6663 format_idx = header & MFW_TRACE_EVENTID_MASK;
6664
6665 /* Skip message if its index doesn't exist in the meta data */
6666 if (format_idx > s_mcp_trace_meta.formats_num) {
6667 u8 format_size =
6668 (u8)((header & MFW_TRACE_PRM_SIZE_MASK) >>
6669 MFW_TRACE_PRM_SIZE_SHIFT);
6670
6671 if (data_size < format_size)
6672 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6673
6674 data_offset = qed_cyclic_add(data_offset,
6675 format_size,
6676 trace_buf_size);
6677 data_size -= format_size;
6678 continue;
6679 }
6680
6681 format_ptr = &s_mcp_trace_meta.formats[format_idx];
6682
6683 for (i = 0,
6684 param_mask = MCP_TRACE_FORMAT_P1_SIZE_MASK,
6685 param_shift = MCP_TRACE_FORMAT_P1_SIZE_SHIFT;
6686 i < MCP_TRACE_FORMAT_MAX_PARAMS;
6687 i++,
6688 param_mask <<= MCP_TRACE_FORMAT_PARAM_WIDTH,
6689 param_shift += MCP_TRACE_FORMAT_PARAM_WIDTH) {
6690 /* Extract param size (0..3) */
6691 u8 param_size = (u8)((format_ptr->data & param_mask) >>
6692 param_shift);
6693
6694 /* If the param size is zero, there are no other
6695 * parameters.
6696 */
6697 if (!param_size)
6698 break;
6699
6700 /* Size is encoded using 2 bits, where 3 is used to
6701 * encode 4.
6702 */
6703 if (param_size == 3)
6704 param_size = 4;
6705
6706 if (data_size < param_size)
6707 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6708
6709 params[i] = qed_read_from_cyclic_buf(trace_buf,
6710 &data_offset,
6711 trace_buf_size,
6712 param_size);
6713 data_size -= param_size;
6714 }
6715
6716 format_level = (u8)((format_ptr->data &
6717 MCP_TRACE_FORMAT_LEVEL_MASK) >>
6718 MCP_TRACE_FORMAT_LEVEL_SHIFT);
6719 format_module = (u8)((format_ptr->data &
6720 MCP_TRACE_FORMAT_MODULE_MASK) >>
6721 MCP_TRACE_FORMAT_MODULE_SHIFT);
6722 if (format_level >= ARRAY_SIZE(s_mcp_trace_level_str))
6723 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6724
6725 /* Print current message to results buffer */
6726 *parsed_bytes +=
6727 sprintf(qed_get_buf_ptr(parsed_buf, *parsed_bytes),
6728 "%s %-8s: ",
6729 s_mcp_trace_level_str[format_level],
6730 s_mcp_trace_meta.modules[format_module]);
6731 *parsed_bytes +=
6732 sprintf(qed_get_buf_ptr(parsed_buf, *parsed_bytes),
6733 format_ptr->format_str,
6734 params[0], params[1], params[2]);
6735 }
6736
6737 /* Add string NULL terminator */
6738 (*parsed_bytes)++;
6739
6740 return status;
6741}
6742
6743/* Parses an MCP Trace dump buffer.
6744 * If result_buf is not NULL, the MCP Trace results are printed to it.
6745 * In any case, the required results buffer size is assigned to
6746 * parsed_bytes.
6747 * The parsing status is returned.
6748 */
6749static enum dbg_status qed_parse_mcp_trace_dump(struct qed_hwfn *p_hwfn,
6750 u32 *dump_buf,
6751 char *parsed_buf,
6752 u32 *parsed_bytes)
6753{
6754 const char *section_name, *param_name, *param_str_val;
6755 u32 data_size, trace_data_dwords, trace_meta_dwords;
6756 u32 offset, results_offset, parsed_buf_bytes;
6757 u32 param_num_val, num_section_params;
6758 struct mcp_trace *trace;
6759 enum dbg_status status;
6760 const u32 *meta_buf;
6761 u8 *trace_buf;
6762
6763 *parsed_bytes = 0;
6764
6765 /* Read global_params section */
6766 dump_buf += qed_read_section_hdr(dump_buf,
6767 §ion_name, &num_section_params);
6768 if (strcmp(section_name, "global_params"))
6769 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6770
6771 /* Print global params */
6772 dump_buf += qed_print_section_params(dump_buf,
6773 num_section_params,
6774 parsed_buf, &results_offset);
6775
6776 /* Read trace_data section */
6777 dump_buf += qed_read_section_hdr(dump_buf,
6778 §ion_name, &num_section_params);
6779 if (strcmp(section_name, "mcp_trace_data") || num_section_params != 1)
6780 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6781 dump_buf += qed_read_param(dump_buf,
6782 ¶m_name, ¶m_str_val, ¶m_num_val);
6783 if (strcmp(param_name, "size"))
6784 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6785 trace_data_dwords = param_num_val;
6786
6787 /* Prepare trace info */
6788 trace = (struct mcp_trace *)dump_buf;
6789 trace_buf = (u8 *)dump_buf + sizeof(*trace);
6790 offset = trace->trace_oldest;
6791 data_size = qed_cyclic_sub(trace->trace_prod, offset, trace->size);
6792 dump_buf += trace_data_dwords;
6793
6794 /* Read meta_data section */
6795 dump_buf += qed_read_section_hdr(dump_buf,
6796 §ion_name, &num_section_params);
6797 if (strcmp(section_name, "mcp_trace_meta"))
6798 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6799 dump_buf += qed_read_param(dump_buf,
6800 ¶m_name, ¶m_str_val, ¶m_num_val);
6801 if (strcmp(param_name, "size"))
6802 return DBG_STATUS_MCP_TRACE_BAD_DATA;
6803 trace_meta_dwords = param_num_val;
6804
6805 /* Choose meta data buffer */
6806 if (!trace_meta_dwords) {
6807 /* Dump doesn't include meta data */
6808 if (!s_mcp_trace_meta_arr.ptr)
6809 return DBG_STATUS_MCP_TRACE_NO_META;
6810 meta_buf = s_mcp_trace_meta_arr.ptr;
6811 } else {
6812 /* Dump includes meta data */
6813 meta_buf = dump_buf;
6814 }
6815
6816 /* Allocate meta data memory */
6817 status = qed_mcp_trace_alloc_meta(p_hwfn, meta_buf, &s_mcp_trace_meta);
6818 if (status != DBG_STATUS_OK)
6819 return status;
6820
6821 status = qed_parse_mcp_trace_buf(trace_buf,
6822 trace->size,
6823 offset,
6824 data_size,
6825 parsed_buf ?
6826 parsed_buf + results_offset :
6827 NULL,
6828 &parsed_buf_bytes);
6829 if (status != DBG_STATUS_OK)
6830 return status;
6831
6832 *parsed_bytes = results_offset + parsed_buf_bytes;
6833
6834 return DBG_STATUS_OK;
6835}
6836
6837/* Parses a Reg FIFO dump buffer.
6838 * If result_buf is not NULL, the Reg FIFO results are printed to it.
6839 * In any case, the required results buffer size is assigned to
6840 * parsed_results_bytes.
6841 * The parsing status is returned.
6842 */
6843static enum dbg_status qed_parse_reg_fifo_dump(u32 *dump_buf,
6844 char *results_buf,
6845 u32 *parsed_results_bytes)
6846{
6847 const char *section_name, *param_name, *param_str_val;
6848 u32 param_num_val, num_section_params, num_elements;
6849 struct reg_fifo_element *elements;
6850 u8 i, j, err_val, vf_val;
6851 u32 results_offset = 0;
6852 char vf_str[4];
6853
6854 /* Read global_params section */
6855 dump_buf += qed_read_section_hdr(dump_buf,
6856 §ion_name, &num_section_params);
6857 if (strcmp(section_name, "global_params"))
6858 return DBG_STATUS_REG_FIFO_BAD_DATA;
6859
6860 /* Print global params */
6861 dump_buf += qed_print_section_params(dump_buf,
6862 num_section_params,
6863 results_buf, &results_offset);
6864
6865 /* Read reg_fifo_data section */
6866 dump_buf += qed_read_section_hdr(dump_buf,
6867 §ion_name, &num_section_params);
6868 if (strcmp(section_name, "reg_fifo_data"))
6869 return DBG_STATUS_REG_FIFO_BAD_DATA;
6870 dump_buf += qed_read_param(dump_buf,
6871 ¶m_name, ¶m_str_val, ¶m_num_val);
6872 if (strcmp(param_name, "size"))
6873 return DBG_STATUS_REG_FIFO_BAD_DATA;
6874 if (param_num_val % REG_FIFO_ELEMENT_DWORDS)
6875 return DBG_STATUS_REG_FIFO_BAD_DATA;
6876 num_elements = param_num_val / REG_FIFO_ELEMENT_DWORDS;
6877 elements = (struct reg_fifo_element *)dump_buf;
6878
6879 /* Decode elements */
6880 for (i = 0; i < num_elements; i++) {
6881 bool err_printed = false;
6882
6883 /* Discover if element belongs to a VF or a PF */
6884 vf_val = GET_FIELD(elements[i].data, REG_FIFO_ELEMENT_VF);
6885 if (vf_val == REG_FIFO_ELEMENT_IS_PF_VF_VAL)
6886 sprintf(vf_str, "%s", "N/A");
6887 else
6888 sprintf(vf_str, "%d", vf_val);
6889
6890 /* Add parsed element to parsed buffer */
6891 results_offset +=
6892 sprintf(qed_get_buf_ptr(results_buf,
6893 results_offset),
6894 "raw: 0x%016llx, address: 0x%07x, access: %-5s, pf: %2d, vf: %s, port: %d, privilege: %-3s, protection: %-12s, master: %-4s, errors: ",
6895 elements[i].data,
6896 (u32)GET_FIELD(elements[i].data,
6897 REG_FIFO_ELEMENT_ADDRESS) *
6898 REG_FIFO_ELEMENT_ADDR_FACTOR,
6899 s_access_strs[GET_FIELD(elements[i].data,
6900 REG_FIFO_ELEMENT_ACCESS)],
6901 (u32)GET_FIELD(elements[i].data,
6902 REG_FIFO_ELEMENT_PF),
6903 vf_str,
6904 (u32)GET_FIELD(elements[i].data,
6905 REG_FIFO_ELEMENT_PORT),
6906 s_privilege_strs[GET_FIELD(elements[i].data,
6907 REG_FIFO_ELEMENT_PRIVILEGE)],
6908 s_protection_strs[GET_FIELD(elements[i].data,
6909 REG_FIFO_ELEMENT_PROTECTION)],
6910 s_master_strs[GET_FIELD(elements[i].data,
6911 REG_FIFO_ELEMENT_MASTER)]);
6912
6913 /* Print errors */
6914 for (j = 0,
6915 err_val = GET_FIELD(elements[i].data,
6916 REG_FIFO_ELEMENT_ERROR);
6917 j < ARRAY_SIZE(s_reg_fifo_error_strs);
6918 j++, err_val >>= 1) {
6919 if (err_val & 0x1) {
6920 if (err_printed)
6921 results_offset +=
6922 sprintf(qed_get_buf_ptr
6923 (results_buf,
6924 results_offset), ", ");
6925 results_offset +=
6926 sprintf(qed_get_buf_ptr
6927 (results_buf, results_offset), "%s",
6928 s_reg_fifo_error_strs[j]);
6929 err_printed = true;
6930 }
6931 }
6932
6933 results_offset +=
6934 sprintf(qed_get_buf_ptr(results_buf, results_offset), "\n");
6935 }
6936
6937 results_offset += sprintf(qed_get_buf_ptr(results_buf,
6938 results_offset),
6939 "fifo contained %d elements", num_elements);
6940
6941 /* Add 1 for string NULL termination */
6942 *parsed_results_bytes = results_offset + 1;
6943
6944 return DBG_STATUS_OK;
6945}
6946
6947static enum dbg_status qed_parse_igu_fifo_element(struct igu_fifo_element
6948 *element, char
6949 *results_buf,
6950 u32 *results_offset)
6951{
6952 const struct igu_fifo_addr_data *found_addr = NULL;
6953 u8 source, err_type, i, is_cleanup;
6954 char parsed_addr_data[32];
6955 char parsed_wr_data[256];
6956 u32 wr_data, prod_cons;
6957 bool is_wr_cmd, is_pf;
6958 u16 cmd_addr;
6959 u64 dword12;
6960
6961 /* Dword12 (dword index 1 and 2) contains bits 32..95 of the
6962 * FIFO element.
6963 */
6964 dword12 = ((u64)element->dword2 << 32) | element->dword1;
6965 is_wr_cmd = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD);
6966 is_pf = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_IS_PF);
6967 cmd_addr = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR);
6968 source = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_SOURCE);
6969 err_type = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE);
6970
6971 if (source >= ARRAY_SIZE(s_igu_fifo_source_strs))
6972 return DBG_STATUS_IGU_FIFO_BAD_DATA;
6973 if (err_type >= ARRAY_SIZE(s_igu_fifo_error_strs))
6974 return DBG_STATUS_IGU_FIFO_BAD_DATA;
6975
6976 /* Find address data */
6977 for (i = 0; i < ARRAY_SIZE(s_igu_fifo_addr_data) && !found_addr; i++) {
6978 const struct igu_fifo_addr_data *curr_addr =
6979 &s_igu_fifo_addr_data[i];
6980
6981 if (cmd_addr >= curr_addr->start_addr && cmd_addr <=
6982 curr_addr->end_addr)
6983 found_addr = curr_addr;
6984 }
6985
6986 if (!found_addr)
6987 return DBG_STATUS_IGU_FIFO_BAD_DATA;
6988
6989 /* Prepare parsed address data */
6990 switch (found_addr->type) {
6991 case IGU_ADDR_TYPE_MSIX_MEM:
6992 sprintf(parsed_addr_data, " vector_num = 0x%x", cmd_addr / 2);
6993 break;
6994 case IGU_ADDR_TYPE_WRITE_INT_ACK:
6995 case IGU_ADDR_TYPE_WRITE_PROD_UPDATE:
6996 sprintf(parsed_addr_data,
6997 " SB = 0x%x", cmd_addr - found_addr->start_addr);
6998 break;
6999 default:
7000 parsed_addr_data[0] = '\0';
7001 }
7002
7003 if (!is_wr_cmd) {
7004 parsed_wr_data[0] = '\0';
7005 goto out;
7006 }
7007
7008 /* Prepare parsed write data */
7009 wr_data = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_WR_DATA);
7010 prod_cons = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_PROD_CONS);
7011 is_cleanup = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_CMD_TYPE);
7012
7013 if (source == IGU_SRC_ATTN) {
7014 sprintf(parsed_wr_data, "prod: 0x%x, ", prod_cons);
7015 } else {
7016 if (is_cleanup) {
7017 u8 cleanup_val, cleanup_type;
7018
7019 cleanup_val =
7020 GET_FIELD(wr_data,
7021 IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL);
7022 cleanup_type =
7023 GET_FIELD(wr_data,
7024 IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE);
7025
7026 sprintf(parsed_wr_data,
7027 "cmd_type: cleanup, cleanup_val: %s, cleanup_type : %d, ",
7028 cleanup_val ? "set" : "clear",
7029 cleanup_type);
7030 } else {
7031 u8 update_flag, en_dis_int_for_sb, segment;
7032 u8 timer_mask;
7033
7034 update_flag = GET_FIELD(wr_data,
7035 IGU_FIFO_WR_DATA_UPDATE_FLAG);
7036 en_dis_int_for_sb =
7037 GET_FIELD(wr_data,
7038 IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB);
7039 segment = GET_FIELD(wr_data,
7040 IGU_FIFO_WR_DATA_SEGMENT);
7041 timer_mask = GET_FIELD(wr_data,
7042 IGU_FIFO_WR_DATA_TIMER_MASK);
7043
7044 sprintf(parsed_wr_data,
7045 "cmd_type: prod/cons update, prod/cons: 0x%x, update_flag: %s, en_dis_int_for_sb : %s, segment : %s, timer_mask = %d, ",
7046 prod_cons,
7047 update_flag ? "update" : "nop",
7048 en_dis_int_for_sb ?
7049 (en_dis_int_for_sb == 1 ? "disable" : "nop") :
7050 "enable",
7051 segment ? "attn" : "regular",
7052 timer_mask);
7053 }
7054 }
7055out:
7056 /* Add parsed element to parsed buffer */
7057 *results_offset += sprintf(qed_get_buf_ptr(results_buf,
7058 *results_offset),
7059 "raw: 0x%01x%08x%08x, %s: %d, source : %s, type : %s, cmd_addr : 0x%x(%s%s), %serror: %s\n",
7060 element->dword2, element->dword1,
7061 element->dword0,
7062 is_pf ? "pf" : "vf",
7063 GET_FIELD(element->dword0,
7064 IGU_FIFO_ELEMENT_DWORD0_FID),
7065 s_igu_fifo_source_strs[source],
7066 is_wr_cmd ? "wr" : "rd",
7067 cmd_addr,
7068 (!is_pf && found_addr->vf_desc)
7069 ? found_addr->vf_desc
7070 : found_addr->desc,
7071 parsed_addr_data,
7072 parsed_wr_data,
7073 s_igu_fifo_error_strs[err_type]);
7074
7075 return DBG_STATUS_OK;
7076}
7077
7078/* Parses an IGU FIFO dump buffer.
7079 * If result_buf is not NULL, the IGU FIFO results are printed to it.
7080 * In any case, the required results buffer size is assigned to
7081 * parsed_results_bytes.
7082 * The parsing status is returned.
7083 */
7084static enum dbg_status qed_parse_igu_fifo_dump(u32 *dump_buf,
7085 char *results_buf,
7086 u32 *parsed_results_bytes)
7087{
7088 const char *section_name, *param_name, *param_str_val;
7089 u32 param_num_val, num_section_params, num_elements;
7090 struct igu_fifo_element *elements;
7091 enum dbg_status status;
7092 u32 results_offset = 0;
7093 u8 i;
7094
7095 /* Read global_params section */
7096 dump_buf += qed_read_section_hdr(dump_buf,
7097 §ion_name, &num_section_params);
7098 if (strcmp(section_name, "global_params"))
7099 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7100
7101 /* Print global params */
7102 dump_buf += qed_print_section_params(dump_buf,
7103 num_section_params,
7104 results_buf, &results_offset);
7105
7106 /* Read igu_fifo_data section */
7107 dump_buf += qed_read_section_hdr(dump_buf,
7108 §ion_name, &num_section_params);
7109 if (strcmp(section_name, "igu_fifo_data"))
7110 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7111 dump_buf += qed_read_param(dump_buf,
7112 ¶m_name, ¶m_str_val, ¶m_num_val);
7113 if (strcmp(param_name, "size"))
7114 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7115 if (param_num_val % IGU_FIFO_ELEMENT_DWORDS)
7116 return DBG_STATUS_IGU_FIFO_BAD_DATA;
7117 num_elements = param_num_val / IGU_FIFO_ELEMENT_DWORDS;
7118 elements = (struct igu_fifo_element *)dump_buf;
7119
7120 /* Decode elements */
7121 for (i = 0; i < num_elements; i++) {
7122 status = qed_parse_igu_fifo_element(&elements[i],
7123 results_buf,
7124 &results_offset);
7125 if (status != DBG_STATUS_OK)
7126 return status;
7127 }
7128
7129 results_offset += sprintf(qed_get_buf_ptr(results_buf,
7130 results_offset),
7131 "fifo contained %d elements", num_elements);
7132
7133 /* Add 1 for string NULL termination */
7134 *parsed_results_bytes = results_offset + 1;
7135
7136 return DBG_STATUS_OK;
7137}
7138
7139static enum dbg_status
7140qed_parse_protection_override_dump(u32 *dump_buf,
7141 char *results_buf,
7142 u32 *parsed_results_bytes)
7143{
7144 const char *section_name, *param_name, *param_str_val;
7145 u32 param_num_val, num_section_params, num_elements;
7146 struct protection_override_element *elements;
7147 u32 results_offset = 0;
7148 u8 i;
7149
7150 /* Read global_params section */
7151 dump_buf += qed_read_section_hdr(dump_buf,
7152 §ion_name, &num_section_params);
7153 if (strcmp(section_name, "global_params"))
7154 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7155
7156 /* Print global params */
7157 dump_buf += qed_print_section_params(dump_buf,
7158 num_section_params,
7159 results_buf, &results_offset);
7160
7161 /* Read protection_override_data section */
7162 dump_buf += qed_read_section_hdr(dump_buf,
7163 §ion_name, &num_section_params);
7164 if (strcmp(section_name, "protection_override_data"))
7165 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7166 dump_buf += qed_read_param(dump_buf,
7167 ¶m_name, ¶m_str_val, ¶m_num_val);
7168 if (strcmp(param_name, "size"))
7169 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7170 if (param_num_val % PROTECTION_OVERRIDE_ELEMENT_DWORDS)
7171 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
7172 num_elements = param_num_val / PROTECTION_OVERRIDE_ELEMENT_DWORDS;
7173 elements = (struct protection_override_element *)dump_buf;
7174
7175 /* Decode elements */
7176 for (i = 0; i < num_elements; i++) {
7177 u32 address = GET_FIELD(elements[i].data,
7178 PROTECTION_OVERRIDE_ELEMENT_ADDRESS) *
7179 PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR;
7180
7181 results_offset +=
7182 sprintf(qed_get_buf_ptr(results_buf,
7183 results_offset),
7184 "window %2d, address: 0x%07x, size: %7d regs, read: %d, write: %d, read protection: %-12s, write protection: %-12s\n",
7185 i, address,
7186 (u32)GET_FIELD(elements[i].data,
7187 PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE),
7188 (u32)GET_FIELD(elements[i].data,
7189 PROTECTION_OVERRIDE_ELEMENT_READ),
7190 (u32)GET_FIELD(elements[i].data,
7191 PROTECTION_OVERRIDE_ELEMENT_WRITE),
7192 s_protection_strs[GET_FIELD(elements[i].data,
7193 PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION)],
7194 s_protection_strs[GET_FIELD(elements[i].data,
7195 PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION)]);
7196 }
7197
7198 results_offset += sprintf(qed_get_buf_ptr(results_buf,
7199 results_offset),
7200 "protection override contained %d elements",
7201 num_elements);
7202
7203 /* Add 1 for string NULL termination */
7204 *parsed_results_bytes = results_offset + 1;
7205
7206 return DBG_STATUS_OK;
7207}
7208
7209/* Parses a FW Asserts dump buffer.
7210 * If result_buf is not NULL, the FW Asserts results are printed to it.
7211 * In any case, the required results buffer size is assigned to
7212 * parsed_results_bytes.
7213 * The parsing status is returned.
7214 */
7215static enum dbg_status qed_parse_fw_asserts_dump(u32 *dump_buf,
7216 char *results_buf,
7217 u32 *parsed_results_bytes)
7218{
7219 u32 num_section_params, param_num_val, i, results_offset = 0;
7220 const char *param_name, *param_str_val, *section_name;
7221 bool last_section_found = false;
7222
7223 *parsed_results_bytes = 0;
7224
7225 /* Read global_params section */
7226 dump_buf += qed_read_section_hdr(dump_buf,
7227 §ion_name, &num_section_params);
7228 if (strcmp(section_name, "global_params"))
7229 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7230
7231 /* Print global params */
7232 dump_buf += qed_print_section_params(dump_buf,
7233 num_section_params,
7234 results_buf, &results_offset);
7235
7236 while (!last_section_found) {
7237 dump_buf += qed_read_section_hdr(dump_buf,
7238 §ion_name,
7239 &num_section_params);
7240 if (!strcmp(section_name, "fw_asserts")) {
7241 /* Extract params */
7242 const char *storm_letter = NULL;
7243 u32 storm_dump_size = 0;
7244
7245 for (i = 0; i < num_section_params; i++) {
7246 dump_buf += qed_read_param(dump_buf,
7247 ¶m_name,
7248 ¶m_str_val,
7249 ¶m_num_val);
7250 if (!strcmp(param_name, "storm"))
7251 storm_letter = param_str_val;
7252 else if (!strcmp(param_name, "size"))
7253 storm_dump_size = param_num_val;
7254 else
7255 return
7256 DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7257 }
7258
7259 if (!storm_letter || !storm_dump_size)
7260 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7261
7262 /* Print data */
7263 results_offset +=
7264 sprintf(qed_get_buf_ptr(results_buf,
7265 results_offset),
7266 "\n%sSTORM_ASSERT: size=%d\n",
7267 storm_letter, storm_dump_size);
7268 for (i = 0; i < storm_dump_size; i++, dump_buf++)
7269 results_offset +=
7270 sprintf(qed_get_buf_ptr(results_buf,
7271 results_offset),
7272 "%08x\n", *dump_buf);
7273 } else if (!strcmp(section_name, "last")) {
7274 last_section_found = true;
7275 } else {
7276 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
7277 }
7278 }
7279
7280 /* Add 1 for string NULL termination */
7281 *parsed_results_bytes = results_offset + 1;
7282
7283 return DBG_STATUS_OK;
7284}
7285
7286/***************************** Public Functions *******************************/
7287
7288enum dbg_status qed_dbg_user_set_bin_ptr(const u8 * const bin_ptr)
7289{
7290 struct bin_buffer_hdr *buf_array = (struct bin_buffer_hdr *)bin_ptr;
7291 u8 buf_id;
7292
7293 /* Convert binary data to debug arrays */
7294 for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++) {
7295 s_user_dbg_arrays[buf_id].ptr =
7296 (u32 *)(bin_ptr + buf_array[buf_id].offset);
7297 s_user_dbg_arrays[buf_id].size_in_dwords =
7298 BYTES_TO_DWORDS(buf_array[buf_id].length);
7299 }
7300
7301 return DBG_STATUS_OK;
7302}
7303
7304const char *qed_dbg_get_status_str(enum dbg_status status)
7305{
7306 return (status <
7307 MAX_DBG_STATUS) ? s_status_str[status] : "Invalid debug status";
7308}
7309
7310enum dbg_status qed_get_idle_chk_results_buf_size(struct qed_hwfn *p_hwfn,
7311 u32 *dump_buf,
7312 u32 num_dumped_dwords,
7313 u32 *results_buf_size)
7314{
7315 u32 num_errors, num_warnings;
7316
7317 return qed_parse_idle_chk_dump(dump_buf,
7318 num_dumped_dwords,
7319 NULL,
7320 results_buf_size,
7321 &num_errors, &num_warnings);
7322}
7323
7324enum dbg_status qed_print_idle_chk_results(struct qed_hwfn *p_hwfn,
7325 u32 *dump_buf,
7326 u32 num_dumped_dwords,
7327 char *results_buf,
7328 u32 *num_errors,
7329 u32 *num_warnings)
7330{
7331 u32 parsed_buf_size;
7332
7333 return qed_parse_idle_chk_dump(dump_buf,
7334 num_dumped_dwords,
7335 results_buf,
7336 &parsed_buf_size,
7337 num_errors, num_warnings);
7338}
7339
7340void qed_dbg_mcp_trace_set_meta_data(u32 *data, u32 size)
7341{
7342 s_mcp_trace_meta_arr.ptr = data;
7343 s_mcp_trace_meta_arr.size_in_dwords = size;
7344}
7345
7346enum dbg_status qed_get_mcp_trace_results_buf_size(struct qed_hwfn *p_hwfn,
7347 u32 *dump_buf,
7348 u32 num_dumped_dwords,
7349 u32 *results_buf_size)
7350{
7351 return qed_parse_mcp_trace_dump(p_hwfn,
7352 dump_buf, NULL, results_buf_size);
7353}
7354
7355enum dbg_status qed_print_mcp_trace_results(struct qed_hwfn *p_hwfn,
7356 u32 *dump_buf,
7357 u32 num_dumped_dwords,
7358 char *results_buf)
7359{
7360 u32 parsed_buf_size;
7361
7362 return qed_parse_mcp_trace_dump(p_hwfn,
7363 dump_buf,
7364 results_buf, &parsed_buf_size);
7365}
7366
7367enum dbg_status qed_print_mcp_trace_line(u8 *dump_buf,
7368 u32 num_dumped_bytes,
7369 char *results_buf)
7370{
7371 u32 parsed_bytes;
7372
7373 return qed_parse_mcp_trace_buf(dump_buf,
7374 num_dumped_bytes,
7375 0,
7376 num_dumped_bytes,
7377 results_buf, &parsed_bytes);
7378}
7379
7380enum dbg_status qed_get_reg_fifo_results_buf_size(struct qed_hwfn *p_hwfn,
7381 u32 *dump_buf,
7382 u32 num_dumped_dwords,
7383 u32 *results_buf_size)
7384{
7385 return qed_parse_reg_fifo_dump(dump_buf, NULL, results_buf_size);
7386}
7387
7388enum dbg_status qed_print_reg_fifo_results(struct qed_hwfn *p_hwfn,
7389 u32 *dump_buf,
7390 u32 num_dumped_dwords,
7391 char *results_buf)
7392{
7393 u32 parsed_buf_size;
7394
7395 return qed_parse_reg_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
7396}
7397
7398enum dbg_status qed_get_igu_fifo_results_buf_size(struct qed_hwfn *p_hwfn,
7399 u32 *dump_buf,
7400 u32 num_dumped_dwords,
7401 u32 *results_buf_size)
7402{
7403 return qed_parse_igu_fifo_dump(dump_buf, NULL, results_buf_size);
7404}
7405
7406enum dbg_status qed_print_igu_fifo_results(struct qed_hwfn *p_hwfn,
7407 u32 *dump_buf,
7408 u32 num_dumped_dwords,
7409 char *results_buf)
7410{
7411 u32 parsed_buf_size;
7412
7413 return qed_parse_igu_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
7414}
7415
7416enum dbg_status
7417qed_get_protection_override_results_buf_size(struct qed_hwfn *p_hwfn,
7418 u32 *dump_buf,
7419 u32 num_dumped_dwords,
7420 u32 *results_buf_size)
7421{
7422 return qed_parse_protection_override_dump(dump_buf,
7423 NULL, results_buf_size);
7424}
7425
7426enum dbg_status qed_print_protection_override_results(struct qed_hwfn *p_hwfn,
7427 u32 *dump_buf,
7428 u32 num_dumped_dwords,
7429 char *results_buf)
7430{
7431 u32 parsed_buf_size;
7432
7433 return qed_parse_protection_override_dump(dump_buf,
7434 results_buf,
7435 &parsed_buf_size);
7436}
7437
7438enum dbg_status qed_get_fw_asserts_results_buf_size(struct qed_hwfn *p_hwfn,
7439 u32 *dump_buf,
7440 u32 num_dumped_dwords,
7441 u32 *results_buf_size)
7442{
7443 return qed_parse_fw_asserts_dump(dump_buf, NULL, results_buf_size);
7444}
7445
7446enum dbg_status qed_print_fw_asserts_results(struct qed_hwfn *p_hwfn,
7447 u32 *dump_buf,
7448 u32 num_dumped_dwords,
7449 char *results_buf)
7450{
7451 u32 parsed_buf_size;
7452
7453 return qed_parse_fw_asserts_dump(dump_buf,
7454 results_buf, &parsed_buf_size);
7455}
7456
7457enum dbg_status qed_dbg_parse_attn(struct qed_hwfn *p_hwfn,
7458 struct dbg_attn_block_result *results)
7459{
7460 struct user_dbg_array *block_attn, *pstrings;
7461 const u32 *block_attn_name_offsets;
7462 enum dbg_attn_type attn_type;
7463 const char *block_name;
7464 u8 num_regs, i, j;
7465
7466 num_regs = GET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_NUM_REGS);
7467 attn_type = (enum dbg_attn_type)
7468 GET_FIELD(results->data,
7469 DBG_ATTN_BLOCK_RESULT_ATTN_TYPE);
7470 block_name = s_block_info_arr[results->block_id].name;
7471
7472 if (!s_user_dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES].ptr ||
7473 !s_user_dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS].ptr ||
7474 !s_user_dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr)
7475 return DBG_STATUS_DBG_ARRAY_NOT_SET;
7476
7477 block_attn = &s_user_dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS];
7478 block_attn_name_offsets = &block_attn->ptr[results->names_offset];
7479
7480 /* Go over registers with a non-zero attention status */
7481 for (i = 0; i < num_regs; i++) {
7482 struct dbg_attn_bit_mapping *bit_mapping;
7483 struct dbg_attn_reg_result *reg_result;
7484 u8 num_reg_attn, bit_idx = 0;
7485
7486 reg_result = &results->reg_results[i];
7487 num_reg_attn = GET_FIELD(reg_result->data,
7488 DBG_ATTN_REG_RESULT_NUM_REG_ATTN);
7489 block_attn = &s_user_dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES];
7490 bit_mapping = &((struct dbg_attn_bit_mapping *)
7491 block_attn->ptr)[reg_result->block_attn_offset];
7492
7493 pstrings = &s_user_dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS];
7494
7495 /* Go over attention status bits */
7496 for (j = 0; j < num_reg_attn; j++) {
7497 u16 attn_idx_val = GET_FIELD(bit_mapping[j].data,
7498 DBG_ATTN_BIT_MAPPING_VAL);
7499 const char *attn_name, *attn_type_str, *masked_str;
7500 u32 attn_name_offset, sts_addr;
7501
7502 /* Check if bit mask should be advanced (due to unused
7503 * bits).
7504 */
7505 if (GET_FIELD(bit_mapping[j].data,
7506 DBG_ATTN_BIT_MAPPING_IS_UNUSED_BIT_CNT)) {
7507 bit_idx += (u8)attn_idx_val;
7508 continue;
7509 }
7510
7511 /* Check current bit index */
7512 if (!(reg_result->sts_val & BIT(bit_idx))) {
7513 bit_idx++;
7514 continue;
7515 }
7516
7517 /* Find attention name */
7518 attn_name_offset =
7519 block_attn_name_offsets[attn_idx_val];
7520 attn_name = &((const char *)
7521 pstrings->ptr)[attn_name_offset];
7522 attn_type_str = attn_type == ATTN_TYPE_INTERRUPT ?
7523 "Interrupt" : "Parity";
7524 masked_str = reg_result->mask_val & BIT(bit_idx) ?
7525 " [masked]" : "";
7526 sts_addr = GET_FIELD(reg_result->data,
7527 DBG_ATTN_REG_RESULT_STS_ADDRESS);
7528 DP_NOTICE(p_hwfn,
7529 "%s (%s) : %s [address 0x%08x, bit %d]%s\n",
7530 block_name, attn_type_str, attn_name,
7531 sts_addr, bit_idx, masked_str);
7532
7533 bit_idx++;
7534 }
7535 }
7536
7537 return DBG_STATUS_OK;
7538}
7539
7540/* Wrapper for unifying the idle_chk and mcp_trace api */
7541static enum dbg_status
7542qed_print_idle_chk_results_wrapper(struct qed_hwfn *p_hwfn,
7543 u32 *dump_buf,
7544 u32 num_dumped_dwords,
7545 char *results_buf)
7546{
7547 u32 num_errors, num_warnnings;
7548
7549 return qed_print_idle_chk_results(p_hwfn, dump_buf, num_dumped_dwords,
7550 results_buf, &num_errors,
7551 &num_warnnings);
7552}
7553
7554/* Feature meta data lookup table */
7555static struct {
7556 char *name;
7557 enum dbg_status (*get_size)(struct qed_hwfn *p_hwfn,
7558 struct qed_ptt *p_ptt, u32 *size);
7559 enum dbg_status (*perform_dump)(struct qed_hwfn *p_hwfn,
7560 struct qed_ptt *p_ptt, u32 *dump_buf,
7561 u32 buf_size, u32 *dumped_dwords);
7562 enum dbg_status (*print_results)(struct qed_hwfn *p_hwfn,
7563 u32 *dump_buf, u32 num_dumped_dwords,
7564 char *results_buf);
7565 enum dbg_status (*results_buf_size)(struct qed_hwfn *p_hwfn,
7566 u32 *dump_buf,
7567 u32 num_dumped_dwords,
7568 u32 *results_buf_size);
7569} qed_features_lookup[] = {
7570 {
7571 "grc", qed_dbg_grc_get_dump_buf_size,
7572 qed_dbg_grc_dump, NULL, NULL}, {
7573 "idle_chk",
7574 qed_dbg_idle_chk_get_dump_buf_size,
7575 qed_dbg_idle_chk_dump,
7576 qed_print_idle_chk_results_wrapper,
7577 qed_get_idle_chk_results_buf_size}, {
7578 "mcp_trace",
7579 qed_dbg_mcp_trace_get_dump_buf_size,
7580 qed_dbg_mcp_trace_dump, qed_print_mcp_trace_results,
7581 qed_get_mcp_trace_results_buf_size}, {
7582 "reg_fifo",
7583 qed_dbg_reg_fifo_get_dump_buf_size,
7584 qed_dbg_reg_fifo_dump, qed_print_reg_fifo_results,
7585 qed_get_reg_fifo_results_buf_size}, {
7586 "igu_fifo",
7587 qed_dbg_igu_fifo_get_dump_buf_size,
7588 qed_dbg_igu_fifo_dump, qed_print_igu_fifo_results,
7589 qed_get_igu_fifo_results_buf_size}, {
7590 "protection_override",
7591 qed_dbg_protection_override_get_dump_buf_size,
7592 qed_dbg_protection_override_dump,
7593 qed_print_protection_override_results,
7594 qed_get_protection_override_results_buf_size}, {
7595 "fw_asserts",
7596 qed_dbg_fw_asserts_get_dump_buf_size,
7597 qed_dbg_fw_asserts_dump,
7598 qed_print_fw_asserts_results,
7599 qed_get_fw_asserts_results_buf_size},};
7600
7601static void qed_dbg_print_feature(u8 *p_text_buf, u32 text_size)
7602{
7603 u32 i, precision = 80;
7604
7605 if (!p_text_buf)
7606 return;
7607
7608 pr_notice("\n%.*s", precision, p_text_buf);
7609 for (i = precision; i < text_size; i += precision)
7610 pr_cont("%.*s", precision, p_text_buf + i);
7611 pr_cont("\n");
7612}
7613
7614#define QED_RESULTS_BUF_MIN_SIZE 16
7615/* Generic function for decoding debug feature info */
7616static enum dbg_status format_feature(struct qed_hwfn *p_hwfn,
7617 enum qed_dbg_features feature_idx)
7618{
7619 struct qed_dbg_feature *feature =
7620 &p_hwfn->cdev->dbg_params.features[feature_idx];
7621 u32 text_size_bytes, null_char_pos, i;
7622 enum dbg_status rc;
7623 char *text_buf;
7624
7625 /* Check if feature supports formatting capability */
7626 if (!qed_features_lookup[feature_idx].results_buf_size)
7627 return DBG_STATUS_OK;
7628
7629 /* Obtain size of formatted output */
7630 rc = qed_features_lookup[feature_idx].
7631 results_buf_size(p_hwfn, (u32 *)feature->dump_buf,
7632 feature->dumped_dwords, &text_size_bytes);
7633 if (rc != DBG_STATUS_OK)
7634 return rc;
7635
7636 /* Make sure that the allocated size is a multiple of dword (4 bytes) */
7637 null_char_pos = text_size_bytes - 1;
7638 text_size_bytes = (text_size_bytes + 3) & ~0x3;
7639
7640 if (text_size_bytes < QED_RESULTS_BUF_MIN_SIZE) {
7641 DP_NOTICE(p_hwfn->cdev,
7642 "formatted size of feature was too small %d. Aborting\n",
7643 text_size_bytes);
7644 return DBG_STATUS_INVALID_ARGS;
7645 }
7646
7647 /* Allocate temp text buf */
7648 text_buf = vzalloc(text_size_bytes);
7649 if (!text_buf)
7650 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
7651
7652 /* Decode feature opcodes to string on temp buf */
7653 rc = qed_features_lookup[feature_idx].
7654 print_results(p_hwfn, (u32 *)feature->dump_buf,
7655 feature->dumped_dwords, text_buf);
7656 if (rc != DBG_STATUS_OK) {
7657 vfree(text_buf);
7658 return rc;
7659 }
7660
7661 /* Replace the original null character with a '\n' character.
7662 * The bytes that were added as a result of the dword alignment are also
7663 * padded with '\n' characters.
7664 */
7665 for (i = null_char_pos; i < text_size_bytes; i++)
7666 text_buf[i] = '\n';
7667
7668 /* Dump printable feature to log */
7669 if (p_hwfn->cdev->dbg_params.print_data)
7670 qed_dbg_print_feature(text_buf, text_size_bytes);
7671
7672 /* Free the old dump_buf and point the dump_buf to the newly allocagted
7673 * and formatted text buffer.
7674 */
7675 vfree(feature->dump_buf);
7676 feature->dump_buf = text_buf;
7677 feature->buf_size = text_size_bytes;
7678 feature->dumped_dwords = text_size_bytes / 4;
7679 return rc;
7680}
7681
7682/* Generic function for performing the dump of a debug feature. */
7683static enum dbg_status qed_dbg_dump(struct qed_hwfn *p_hwfn,
7684 struct qed_ptt *p_ptt,
7685 enum qed_dbg_features feature_idx)
7686{
7687 struct qed_dbg_feature *feature =
7688 &p_hwfn->cdev->dbg_params.features[feature_idx];
7689 u32 buf_size_dwords;
7690 enum dbg_status rc;
7691
7692 DP_NOTICE(p_hwfn->cdev, "Collecting a debug feature [\"%s\"]\n",
7693 qed_features_lookup[feature_idx].name);
7694
7695 /* Dump_buf was already allocated need to free (this can happen if dump
7696 * was called but file was never read).
7697 * We can't use the buffer as is since size may have changed.
7698 */
7699 if (feature->dump_buf) {
7700 vfree(feature->dump_buf);
7701 feature->dump_buf = NULL;
7702 }
7703
7704 /* Get buffer size from hsi, allocate accordingly, and perform the
7705 * dump.
7706 */
7707 rc = qed_features_lookup[feature_idx].get_size(p_hwfn, p_ptt,
7708 &buf_size_dwords);
7709 if (rc != DBG_STATUS_OK && rc != DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
7710 return rc;
7711 feature->buf_size = buf_size_dwords * sizeof(u32);
7712 feature->dump_buf = vmalloc(feature->buf_size);
7713 if (!feature->dump_buf)
7714 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
7715
7716 rc = qed_features_lookup[feature_idx].
7717 perform_dump(p_hwfn, p_ptt, (u32 *)feature->dump_buf,
7718 feature->buf_size / sizeof(u32),
7719 &feature->dumped_dwords);
7720
7721 /* If mcp is stuck we get DBG_STATUS_NVRAM_GET_IMAGE_FAILED error.
7722 * In this case the buffer holds valid binary data, but we wont able
7723 * to parse it (since parsing relies on data in NVRAM which is only
7724 * accessible when MFW is responsive). skip the formatting but return
7725 * success so that binary data is provided.
7726 */
7727 if (rc == DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
7728 return DBG_STATUS_OK;
7729
7730 if (rc != DBG_STATUS_OK)
7731 return rc;
7732
7733 /* Format output */
7734 rc = format_feature(p_hwfn, feature_idx);
7735 return rc;
7736}
7737
7738int qed_dbg_grc(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
7739{
7740 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_GRC, num_dumped_bytes);
7741}
7742
7743int qed_dbg_grc_size(struct qed_dev *cdev)
7744{
7745 return qed_dbg_feature_size(cdev, DBG_FEATURE_GRC);
7746}
7747
7748int qed_dbg_idle_chk(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
7749{
7750 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_IDLE_CHK,
7751 num_dumped_bytes);
7752}
7753
7754int qed_dbg_idle_chk_size(struct qed_dev *cdev)
7755{
7756 return qed_dbg_feature_size(cdev, DBG_FEATURE_IDLE_CHK);
7757}
7758
7759int qed_dbg_reg_fifo(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
7760{
7761 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_REG_FIFO,
7762 num_dumped_bytes);
7763}
7764
7765int qed_dbg_reg_fifo_size(struct qed_dev *cdev)
7766{
7767 return qed_dbg_feature_size(cdev, DBG_FEATURE_REG_FIFO);
7768}
7769
7770int qed_dbg_igu_fifo(struct qed_dev *cdev, void *buffer, u32 *num_dumped_bytes)
7771{
7772 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_IGU_FIFO,
7773 num_dumped_bytes);
7774}
7775
7776int qed_dbg_igu_fifo_size(struct qed_dev *cdev)
7777{
7778 return qed_dbg_feature_size(cdev, DBG_FEATURE_IGU_FIFO);
7779}
7780
7781int qed_dbg_protection_override(struct qed_dev *cdev, void *buffer,
7782 u32 *num_dumped_bytes)
7783{
7784 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_PROTECTION_OVERRIDE,
7785 num_dumped_bytes);
7786}
7787
7788int qed_dbg_protection_override_size(struct qed_dev *cdev)
7789{
7790 return qed_dbg_feature_size(cdev, DBG_FEATURE_PROTECTION_OVERRIDE);
7791}
7792
7793int qed_dbg_fw_asserts(struct qed_dev *cdev, void *buffer,
7794 u32 *num_dumped_bytes)
7795{
7796 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_FW_ASSERTS,
7797 num_dumped_bytes);
7798}
7799
7800int qed_dbg_fw_asserts_size(struct qed_dev *cdev)
7801{
7802 return qed_dbg_feature_size(cdev, DBG_FEATURE_FW_ASSERTS);
7803}
7804
7805int qed_dbg_mcp_trace(struct qed_dev *cdev, void *buffer,
7806 u32 *num_dumped_bytes)
7807{
7808 return qed_dbg_feature(cdev, buffer, DBG_FEATURE_MCP_TRACE,
7809 num_dumped_bytes);
7810}
7811
7812int qed_dbg_mcp_trace_size(struct qed_dev *cdev)
7813{
7814 return qed_dbg_feature_size(cdev, DBG_FEATURE_MCP_TRACE);
7815}
7816
7817/* Defines the amount of bytes allocated for recording the length of debugfs
7818 * feature buffer.
7819 */
7820#define REGDUMP_HEADER_SIZE sizeof(u32)
7821#define REGDUMP_HEADER_FEATURE_SHIFT 24
7822#define REGDUMP_HEADER_ENGINE_SHIFT 31
7823#define REGDUMP_HEADER_OMIT_ENGINE_SHIFT 30
7824enum debug_print_features {
7825 OLD_MODE = 0,
7826 IDLE_CHK = 1,
7827 GRC_DUMP = 2,
7828 MCP_TRACE = 3,
7829 REG_FIFO = 4,
7830 PROTECTION_OVERRIDE = 5,
7831 IGU_FIFO = 6,
7832 PHY = 7,
7833 FW_ASSERTS = 8,
7834};
7835
7836static u32 qed_calc_regdump_header(enum debug_print_features feature,
7837 int engine, u32 feature_size, u8 omit_engine)
7838{
7839 /* Insert the engine, feature and mode inside the header and combine it
7840 * with feature size.
7841 */
7842 return feature_size | (feature << REGDUMP_HEADER_FEATURE_SHIFT) |
7843 (omit_engine << REGDUMP_HEADER_OMIT_ENGINE_SHIFT) |
7844 (engine << REGDUMP_HEADER_ENGINE_SHIFT);
7845}
7846
7847int qed_dbg_all_data(struct qed_dev *cdev, void *buffer)
7848{
7849 u8 cur_engine, omit_engine = 0, org_engine;
7850 u32 offset = 0, feature_size;
7851 int rc;
7852
7853 if (cdev->num_hwfns == 1)
7854 omit_engine = 1;
7855
7856 org_engine = qed_get_debug_engine(cdev);
7857 for (cur_engine = 0; cur_engine < cdev->num_hwfns; cur_engine++) {
7858 /* Collect idle_chks and grcDump for each hw function */
7859 DP_VERBOSE(cdev, QED_MSG_DEBUG,
7860 "obtaining idle_chk and grcdump for current engine\n");
7861 qed_set_debug_engine(cdev, cur_engine);
7862
7863 /* First idle_chk */
7864 rc = qed_dbg_idle_chk(cdev, (u8 *)buffer + offset +
7865 REGDUMP_HEADER_SIZE, &feature_size);
7866 if (!rc) {
7867 *(u32 *)((u8 *)buffer + offset) =
7868 qed_calc_regdump_header(IDLE_CHK, cur_engine,
7869 feature_size, omit_engine);
7870 offset += (feature_size + REGDUMP_HEADER_SIZE);
7871 } else {
7872 DP_ERR(cdev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
7873 }
7874
7875 /* Second idle_chk */
7876 rc = qed_dbg_idle_chk(cdev, (u8 *)buffer + offset +
7877 REGDUMP_HEADER_SIZE, &feature_size);
7878 if (!rc) {
7879 *(u32 *)((u8 *)buffer + offset) =
7880 qed_calc_regdump_header(IDLE_CHK, cur_engine,
7881 feature_size, omit_engine);
7882 offset += (feature_size + REGDUMP_HEADER_SIZE);
7883 } else {
7884 DP_ERR(cdev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
7885 }
7886
7887 /* reg_fifo dump */
7888 rc = qed_dbg_reg_fifo(cdev, (u8 *)buffer + offset +
7889 REGDUMP_HEADER_SIZE, &feature_size);
7890 if (!rc) {
7891 *(u32 *)((u8 *)buffer + offset) =
7892 qed_calc_regdump_header(REG_FIFO, cur_engine,
7893 feature_size, omit_engine);
7894 offset += (feature_size + REGDUMP_HEADER_SIZE);
7895 } else {
7896 DP_ERR(cdev, "qed_dbg_reg_fifo failed. rc = %d\n", rc);
7897 }
7898
7899 /* igu_fifo dump */
7900 rc = qed_dbg_igu_fifo(cdev, (u8 *)buffer + offset +
7901 REGDUMP_HEADER_SIZE, &feature_size);
7902 if (!rc) {
7903 *(u32 *)((u8 *)buffer + offset) =
7904 qed_calc_regdump_header(IGU_FIFO, cur_engine,
7905 feature_size, omit_engine);
7906 offset += (feature_size + REGDUMP_HEADER_SIZE);
7907 } else {
7908 DP_ERR(cdev, "qed_dbg_igu_fifo failed. rc = %d", rc);
7909 }
7910
7911 /* protection_override dump */
7912 rc = qed_dbg_protection_override(cdev, (u8 *)buffer + offset +
7913 REGDUMP_HEADER_SIZE,
7914 &feature_size);
7915 if (!rc) {
7916 *(u32 *)((u8 *)buffer + offset) =
7917 qed_calc_regdump_header(PROTECTION_OVERRIDE,
7918 cur_engine,
7919 feature_size, omit_engine);
7920 offset += (feature_size + REGDUMP_HEADER_SIZE);
7921 } else {
7922 DP_ERR(cdev,
7923 "qed_dbg_protection_override failed. rc = %d\n",
7924 rc);
7925 }
7926
7927 /* fw_asserts dump */
7928 rc = qed_dbg_fw_asserts(cdev, (u8 *)buffer + offset +
7929 REGDUMP_HEADER_SIZE, &feature_size);
7930 if (!rc) {
7931 *(u32 *)((u8 *)buffer + offset) =
7932 qed_calc_regdump_header(FW_ASSERTS, cur_engine,
7933 feature_size, omit_engine);
7934 offset += (feature_size + REGDUMP_HEADER_SIZE);
7935 } else {
7936 DP_ERR(cdev, "qed_dbg_fw_asserts failed. rc = %d\n",
7937 rc);
7938 }
7939
7940 /* GRC dump - must be last because when mcp stuck it will
7941 * clutter idle_chk, reg_fifo, ...
7942 */
7943 rc = qed_dbg_grc(cdev, (u8 *)buffer + offset +
7944 REGDUMP_HEADER_SIZE, &feature_size);
7945 if (!rc) {
7946 *(u32 *)((u8 *)buffer + offset) =
7947 qed_calc_regdump_header(GRC_DUMP, cur_engine,
7948 feature_size, omit_engine);
7949 offset += (feature_size + REGDUMP_HEADER_SIZE);
7950 } else {
7951 DP_ERR(cdev, "qed_dbg_grc failed. rc = %d", rc);
7952 }
7953 }
7954
7955 qed_set_debug_engine(cdev, org_engine);
7956 /* mcp_trace */
7957 rc = qed_dbg_mcp_trace(cdev, (u8 *)buffer + offset +
7958 REGDUMP_HEADER_SIZE, &feature_size);
7959 if (!rc) {
7960 *(u32 *)((u8 *)buffer + offset) =
7961 qed_calc_regdump_header(MCP_TRACE, cur_engine,
7962 feature_size, omit_engine);
7963 offset += (feature_size + REGDUMP_HEADER_SIZE);
7964 } else {
7965 DP_ERR(cdev, "qed_dbg_mcp_trace failed. rc = %d\n", rc);
7966 }
7967
7968 return 0;
7969}
7970
7971int qed_dbg_all_data_size(struct qed_dev *cdev)
7972{
7973 u8 cur_engine, org_engine;
7974 u32 regs_len = 0;
7975
7976 org_engine = qed_get_debug_engine(cdev);
7977 for (cur_engine = 0; cur_engine < cdev->num_hwfns; cur_engine++) {
7978 /* Engine specific */
7979 DP_VERBOSE(cdev, QED_MSG_DEBUG,
7980 "calculating idle_chk and grcdump register length for current engine\n");
7981 qed_set_debug_engine(cdev, cur_engine);
7982 regs_len += REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(cdev) +
7983 REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(cdev) +
7984 REGDUMP_HEADER_SIZE + qed_dbg_grc_size(cdev) +
7985 REGDUMP_HEADER_SIZE + qed_dbg_reg_fifo_size(cdev) +
7986 REGDUMP_HEADER_SIZE + qed_dbg_igu_fifo_size(cdev) +
7987 REGDUMP_HEADER_SIZE +
7988 qed_dbg_protection_override_size(cdev) +
7989 REGDUMP_HEADER_SIZE + qed_dbg_fw_asserts_size(cdev);
7990 }
7991
7992 qed_set_debug_engine(cdev, org_engine);
7993
7994 /* Engine common */
7995 regs_len += REGDUMP_HEADER_SIZE + qed_dbg_mcp_trace_size(cdev);
7996
7997 return regs_len;
7998}
7999
8000int qed_dbg_feature(struct qed_dev *cdev, void *buffer,
8001 enum qed_dbg_features feature, u32 *num_dumped_bytes)
8002{
8003 struct qed_hwfn *p_hwfn =
8004 &cdev->hwfns[cdev->dbg_params.engine_for_debug];
8005 struct qed_dbg_feature *qed_feature =
8006 &cdev->dbg_params.features[feature];
8007 enum dbg_status dbg_rc;
8008 struct qed_ptt *p_ptt;
8009 int rc = 0;
8010
8011 /* Acquire ptt */
8012 p_ptt = qed_ptt_acquire(p_hwfn);
8013 if (!p_ptt)
8014 return -EINVAL;
8015
8016 /* Get dump */
8017 dbg_rc = qed_dbg_dump(p_hwfn, p_ptt, feature);
8018 if (dbg_rc != DBG_STATUS_OK) {
8019 DP_VERBOSE(cdev, QED_MSG_DEBUG, "%s\n",
8020 qed_dbg_get_status_str(dbg_rc));
8021 *num_dumped_bytes = 0;
8022 rc = -EINVAL;
8023 goto out;
8024 }
8025
8026 DP_VERBOSE(cdev, QED_MSG_DEBUG,
8027 "copying debugfs feature to external buffer\n");
8028 memcpy(buffer, qed_feature->dump_buf, qed_feature->buf_size);
8029 *num_dumped_bytes = cdev->dbg_params.features[feature].dumped_dwords *
8030 4;
8031
8032out:
8033 qed_ptt_release(p_hwfn, p_ptt);
8034 return rc;
8035}
8036
8037int qed_dbg_feature_size(struct qed_dev *cdev, enum qed_dbg_features feature)
8038{
8039 struct qed_hwfn *p_hwfn =
8040 &cdev->hwfns[cdev->dbg_params.engine_for_debug];
8041 struct qed_ptt *p_ptt = qed_ptt_acquire(p_hwfn);
8042 struct qed_dbg_feature *qed_feature =
8043 &cdev->dbg_params.features[feature];
8044 u32 buf_size_dwords;
8045 enum dbg_status rc;
8046
8047 if (!p_ptt)
8048 return -EINVAL;
8049
8050 rc = qed_features_lookup[feature].get_size(p_hwfn, p_ptt,
8051 &buf_size_dwords);
8052 if (rc != DBG_STATUS_OK)
8053 buf_size_dwords = 0;
8054
8055 qed_ptt_release(p_hwfn, p_ptt);
8056 qed_feature->buf_size = buf_size_dwords * sizeof(u32);
8057 return qed_feature->buf_size;
8058}
8059
8060u8 qed_get_debug_engine(struct qed_dev *cdev)
8061{
8062 return cdev->dbg_params.engine_for_debug;
8063}
8064
8065void qed_set_debug_engine(struct qed_dev *cdev, int engine_number)
8066{
8067 DP_VERBOSE(cdev, QED_MSG_DEBUG, "set debug engine to %d\n",
8068 engine_number);
8069 cdev->dbg_params.engine_for_debug = engine_number;
8070}
8071
8072void qed_dbg_pf_init(struct qed_dev *cdev)
8073{
8074 const u8 *dbg_values;
8075
8076 /* Debug values are after init values.
8077 * The offset is the first dword of the file.
8078 */
8079 dbg_values = cdev->firmware->data + *(u32 *)cdev->firmware->data;
8080 qed_dbg_set_bin_ptr((u8 *)dbg_values);
8081 qed_dbg_user_set_bin_ptr((u8 *)dbg_values);
8082}
8083
8084void qed_dbg_pf_exit(struct qed_dev *cdev)
8085{
8086 struct qed_dbg_feature *feature = NULL;
8087 enum qed_dbg_features feature_idx;
8088
8089 /* Debug features' buffers may be allocated if debug feature was used
8090 * but dump wasn't called.
8091 */
8092 for (feature_idx = 0; feature_idx < DBG_FEATURE_NUM; feature_idx++) {
8093 feature = &cdev->dbg_params.features[feature_idx];
8094 if (feature->dump_buf) {
8095 vfree(feature->dump_buf);
8096 feature->dump_buf = NULL;
8097 }
8098 }
8099}