1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
6 #include <linux/sort.h>
7 #include <linux/string.h>
11 #include "cxgb4_cudbg.h"
13 #include "cudbg_lib_common.h"
14 #include "cudbg_entity.h"
15 #include "cudbg_lib.h"
16 #include "cudbg_zlib.h"
17 #include "cxgb4_tc_mqprio.h"
19 static const u32 t6_tp_pio_array[][IREG_NUM_ELEM] = {
20 {0x7e40, 0x7e44, 0x020, 28}, /* t6_tp_pio_regs_20_to_3b */
21 {0x7e40, 0x7e44, 0x040, 10}, /* t6_tp_pio_regs_40_to_49 */
22 {0x7e40, 0x7e44, 0x050, 10}, /* t6_tp_pio_regs_50_to_59 */
23 {0x7e40, 0x7e44, 0x060, 14}, /* t6_tp_pio_regs_60_to_6d */
24 {0x7e40, 0x7e44, 0x06F, 1}, /* t6_tp_pio_regs_6f */
25 {0x7e40, 0x7e44, 0x070, 6}, /* t6_tp_pio_regs_70_to_75 */
26 {0x7e40, 0x7e44, 0x130, 18}, /* t6_tp_pio_regs_130_to_141 */
27 {0x7e40, 0x7e44, 0x145, 19}, /* t6_tp_pio_regs_145_to_157 */
28 {0x7e40, 0x7e44, 0x160, 1}, /* t6_tp_pio_regs_160 */
29 {0x7e40, 0x7e44, 0x230, 25}, /* t6_tp_pio_regs_230_to_248 */
30 {0x7e40, 0x7e44, 0x24a, 3}, /* t6_tp_pio_regs_24c */
31 {0x7e40, 0x7e44, 0x8C0, 1} /* t6_tp_pio_regs_8c0 */
34 static const u32 t5_tp_pio_array[][IREG_NUM_ELEM] = {
35 {0x7e40, 0x7e44, 0x020, 28}, /* t5_tp_pio_regs_20_to_3b */
36 {0x7e40, 0x7e44, 0x040, 19}, /* t5_tp_pio_regs_40_to_52 */
37 {0x7e40, 0x7e44, 0x054, 2}, /* t5_tp_pio_regs_54_to_55 */
38 {0x7e40, 0x7e44, 0x060, 13}, /* t5_tp_pio_regs_60_to_6c */
39 {0x7e40, 0x7e44, 0x06F, 1}, /* t5_tp_pio_regs_6f */
40 {0x7e40, 0x7e44, 0x120, 4}, /* t5_tp_pio_regs_120_to_123 */
41 {0x7e40, 0x7e44, 0x12b, 2}, /* t5_tp_pio_regs_12b_to_12c */
42 {0x7e40, 0x7e44, 0x12f, 21}, /* t5_tp_pio_regs_12f_to_143 */
43 {0x7e40, 0x7e44, 0x145, 19}, /* t5_tp_pio_regs_145_to_157 */
44 {0x7e40, 0x7e44, 0x230, 25}, /* t5_tp_pio_regs_230_to_248 */
45 {0x7e40, 0x7e44, 0x8C0, 1} /* t5_tp_pio_regs_8c0 */
48 static const u32 t6_tp_tm_pio_array[][IREG_NUM_ELEM] = {
49 {0x7e18, 0x7e1c, 0x0, 12}
52 static const u32 t5_tp_tm_pio_array[][IREG_NUM_ELEM] = {
53 {0x7e18, 0x7e1c, 0x0, 12}
56 static const u32 t6_tp_mib_index_array[6][IREG_NUM_ELEM] = {
57 {0x7e50, 0x7e54, 0x0, 13},
58 {0x7e50, 0x7e54, 0x10, 6},
59 {0x7e50, 0x7e54, 0x18, 21},
60 {0x7e50, 0x7e54, 0x30, 32},
61 {0x7e50, 0x7e54, 0x50, 22},
62 {0x7e50, 0x7e54, 0x68, 12}
65 static const u32 t5_tp_mib_index_array[9][IREG_NUM_ELEM] = {
66 {0x7e50, 0x7e54, 0x0, 13},
67 {0x7e50, 0x7e54, 0x10, 6},
68 {0x7e50, 0x7e54, 0x18, 8},
69 {0x7e50, 0x7e54, 0x20, 13},
70 {0x7e50, 0x7e54, 0x30, 16},
71 {0x7e50, 0x7e54, 0x40, 16},
72 {0x7e50, 0x7e54, 0x50, 16},
73 {0x7e50, 0x7e54, 0x60, 6},
74 {0x7e50, 0x7e54, 0x68, 4}
77 static const u32 t5_sge_dbg_index_array[2][IREG_NUM_ELEM] = {
78 {0x10cc, 0x10d0, 0x0, 16},
79 {0x10cc, 0x10d4, 0x0, 16},
82 static const u32 t6_sge_qbase_index_array[] = {
83 /* 1 addr reg SGE_QBASE_INDEX and 4 data reg SGE_QBASE_MAP[0-3] */
84 0x1250, 0x1240, 0x1244, 0x1248, 0x124c,
87 static const u32 t5_pcie_pdbg_array[][IREG_NUM_ELEM] = {
88 {0x5a04, 0x5a0c, 0x00, 0x20}, /* t5_pcie_pdbg_regs_00_to_20 */
89 {0x5a04, 0x5a0c, 0x21, 0x20}, /* t5_pcie_pdbg_regs_21_to_40 */
90 {0x5a04, 0x5a0c, 0x41, 0x10}, /* t5_pcie_pdbg_regs_41_to_50 */
93 static const u32 t5_pcie_cdbg_array[][IREG_NUM_ELEM] = {
94 {0x5a10, 0x5a18, 0x00, 0x20}, /* t5_pcie_cdbg_regs_00_to_20 */
95 {0x5a10, 0x5a18, 0x21, 0x18}, /* t5_pcie_cdbg_regs_21_to_37 */
98 static const u32 t5_pm_rx_array[][IREG_NUM_ELEM] = {
99 {0x8FD0, 0x8FD4, 0x10000, 0x20}, /* t5_pm_rx_regs_10000_to_10020 */
100 {0x8FD0, 0x8FD4, 0x10021, 0x0D}, /* t5_pm_rx_regs_10021_to_1002c */
103 static const u32 t5_pm_tx_array[][IREG_NUM_ELEM] = {
104 {0x8FF0, 0x8FF4, 0x10000, 0x20}, /* t5_pm_tx_regs_10000_to_10020 */
105 {0x8FF0, 0x8FF4, 0x10021, 0x1D}, /* t5_pm_tx_regs_10021_to_1003c */
108 static const u32 t5_pcie_config_array[][2] = {
125 static const u32 t6_ma_ireg_array[][IREG_NUM_ELEM] = {
126 {0x78f8, 0x78fc, 0xa000, 23}, /* t6_ma_regs_a000_to_a016 */
127 {0x78f8, 0x78fc, 0xa400, 30}, /* t6_ma_regs_a400_to_a41e */
128 {0x78f8, 0x78fc, 0xa800, 20} /* t6_ma_regs_a800_to_a813 */
131 static const u32 t6_ma_ireg_array2[][IREG_NUM_ELEM] = {
132 {0x78f8, 0x78fc, 0xe400, 17}, /* t6_ma_regs_e400_to_e600 */
133 {0x78f8, 0x78fc, 0xe640, 13} /* t6_ma_regs_e640_to_e7c0 */
136 static const u32 t6_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
137 {0x7b50, 0x7b54, 0x2000, 0x20, 0}, /* up_cim_2000_to_207c */
138 {0x7b50, 0x7b54, 0x2080, 0x1d, 0}, /* up_cim_2080_to_20fc */
139 {0x7b50, 0x7b54, 0x00, 0x20, 0}, /* up_cim_00_to_7c */
140 {0x7b50, 0x7b54, 0x80, 0x20, 0}, /* up_cim_80_to_fc */
141 {0x7b50, 0x7b54, 0x100, 0x11, 0}, /* up_cim_100_to_14c */
142 {0x7b50, 0x7b54, 0x200, 0x10, 0}, /* up_cim_200_to_23c */
143 {0x7b50, 0x7b54, 0x240, 0x2, 0}, /* up_cim_240_to_244 */
144 {0x7b50, 0x7b54, 0x250, 0x2, 0}, /* up_cim_250_to_254 */
145 {0x7b50, 0x7b54, 0x260, 0x2, 0}, /* up_cim_260_to_264 */
146 {0x7b50, 0x7b54, 0x270, 0x2, 0}, /* up_cim_270_to_274 */
147 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
148 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
149 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
150 {0x7b50, 0x7b54, 0x4900, 0x4, 0x4}, /* up_cim_4900_to_4c60 */
151 {0x7b50, 0x7b54, 0x4904, 0x4, 0x4}, /* up_cim_4904_to_4c64 */
152 {0x7b50, 0x7b54, 0x4908, 0x4, 0x4}, /* up_cim_4908_to_4c68 */
153 {0x7b50, 0x7b54, 0x4910, 0x4, 0x4}, /* up_cim_4910_to_4c70 */
154 {0x7b50, 0x7b54, 0x4914, 0x4, 0x4}, /* up_cim_4914_to_4c74 */
155 {0x7b50, 0x7b54, 0x4920, 0x10, 0x10}, /* up_cim_4920_to_4a10 */
156 {0x7b50, 0x7b54, 0x4924, 0x10, 0x10}, /* up_cim_4924_to_4a14 */
157 {0x7b50, 0x7b54, 0x4928, 0x10, 0x10}, /* up_cim_4928_to_4a18 */
158 {0x7b50, 0x7b54, 0x492c, 0x10, 0x10}, /* up_cim_492c_to_4a1c */
161 static const u32 t5_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
162 {0x7b50, 0x7b54, 0x2000, 0x20, 0}, /* up_cim_2000_to_207c */
163 {0x7b50, 0x7b54, 0x2080, 0x19, 0}, /* up_cim_2080_to_20ec */
164 {0x7b50, 0x7b54, 0x00, 0x20, 0}, /* up_cim_00_to_7c */
165 {0x7b50, 0x7b54, 0x80, 0x20, 0}, /* up_cim_80_to_fc */
166 {0x7b50, 0x7b54, 0x100, 0x11, 0}, /* up_cim_100_to_14c */
167 {0x7b50, 0x7b54, 0x200, 0x10, 0}, /* up_cim_200_to_23c */
168 {0x7b50, 0x7b54, 0x240, 0x2, 0}, /* up_cim_240_to_244 */
169 {0x7b50, 0x7b54, 0x250, 0x2, 0}, /* up_cim_250_to_254 */
170 {0x7b50, 0x7b54, 0x260, 0x2, 0}, /* up_cim_260_to_264 */
171 {0x7b50, 0x7b54, 0x270, 0x2, 0}, /* up_cim_270_to_274 */
172 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
173 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
174 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
177 static const u32 t6_hma_ireg_array[][IREG_NUM_ELEM] = {
178 {0x51320, 0x51324, 0xa000, 32} /* t6_hma_regs_a000_to_a01f */
181 u32 cudbg_get_entity_length(struct adapter *adap, u32 entity)
183 struct cudbg_tcam tcam_region = { 0 };
184 u32 value, n = 0, len = 0;
188 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
190 len = T4_REGMAP_SIZE;
194 len = T5_REGMAP_SIZE;
201 len = adap->params.devlog.size;
204 if (is_t6(adap->params.chip)) {
205 len = adap->params.cim_la_size / 10 + 1;
206 len *= 10 * sizeof(u32);
208 len = adap->params.cim_la_size / 8;
209 len *= 8 * sizeof(u32);
211 len += sizeof(u32); /* for reading CIM LA configuration */
213 case CUDBG_CIM_MA_LA:
214 len = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
217 len = sizeof(struct cudbg_cim_qcfg);
219 case CUDBG_CIM_IBQ_TP0:
220 case CUDBG_CIM_IBQ_TP1:
221 case CUDBG_CIM_IBQ_ULP:
222 case CUDBG_CIM_IBQ_SGE0:
223 case CUDBG_CIM_IBQ_SGE1:
224 case CUDBG_CIM_IBQ_NCSI:
225 len = CIM_IBQ_SIZE * 4 * sizeof(u32);
227 case CUDBG_CIM_OBQ_ULP0:
228 len = cudbg_cim_obq_size(adap, 0);
230 case CUDBG_CIM_OBQ_ULP1:
231 len = cudbg_cim_obq_size(adap, 1);
233 case CUDBG_CIM_OBQ_ULP2:
234 len = cudbg_cim_obq_size(adap, 2);
236 case CUDBG_CIM_OBQ_ULP3:
237 len = cudbg_cim_obq_size(adap, 3);
239 case CUDBG_CIM_OBQ_SGE:
240 len = cudbg_cim_obq_size(adap, 4);
242 case CUDBG_CIM_OBQ_NCSI:
243 len = cudbg_cim_obq_size(adap, 5);
245 case CUDBG_CIM_OBQ_RXQ0:
246 len = cudbg_cim_obq_size(adap, 6);
248 case CUDBG_CIM_OBQ_RXQ1:
249 len = cudbg_cim_obq_size(adap, 7);
252 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
253 if (value & EDRAM0_ENABLE_F) {
254 value = t4_read_reg(adap, MA_EDRAM0_BAR_A);
255 len = EDRAM0_SIZE_G(value);
257 len = cudbg_mbytes_to_bytes(len);
260 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
261 if (value & EDRAM1_ENABLE_F) {
262 value = t4_read_reg(adap, MA_EDRAM1_BAR_A);
263 len = EDRAM1_SIZE_G(value);
265 len = cudbg_mbytes_to_bytes(len);
268 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
269 if (value & EXT_MEM0_ENABLE_F) {
270 value = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
271 len = EXT_MEM0_SIZE_G(value);
273 len = cudbg_mbytes_to_bytes(len);
276 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
277 if (value & EXT_MEM1_ENABLE_F) {
278 value = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
279 len = EXT_MEM1_SIZE_G(value);
281 len = cudbg_mbytes_to_bytes(len);
284 len = t4_chip_rss_size(adap) * sizeof(u16);
286 case CUDBG_RSS_VF_CONF:
287 len = adap->params.arch.vfcount *
288 sizeof(struct cudbg_rss_vf_conf);
291 len = NMTUS * sizeof(u16);
294 len = sizeof(struct cudbg_pm_stats);
297 len = sizeof(struct cudbg_hw_sched);
299 case CUDBG_TP_INDIRECT:
300 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
302 n = sizeof(t5_tp_pio_array) +
303 sizeof(t5_tp_tm_pio_array) +
304 sizeof(t5_tp_mib_index_array);
307 n = sizeof(t6_tp_pio_array) +
308 sizeof(t6_tp_tm_pio_array) +
309 sizeof(t6_tp_mib_index_array);
314 n = n / (IREG_NUM_ELEM * sizeof(u32));
315 len = sizeof(struct ireg_buf) * n;
317 case CUDBG_SGE_INDIRECT:
318 len = sizeof(struct ireg_buf) * 2 +
319 sizeof(struct sge_qbase_reg_field);
322 len = sizeof(struct cudbg_ulprx_la);
325 len = sizeof(struct cudbg_tp_la) + TPLA_SIZE * sizeof(u64);
328 len = sizeof(struct cudbg_ver_hdr) +
329 sizeof(struct cudbg_meminfo);
331 case CUDBG_CIM_PIF_LA:
332 len = sizeof(struct cudbg_cim_pif_la);
333 len += 2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
336 len = sizeof(struct cudbg_clk_info);
338 case CUDBG_PCIE_INDIRECT:
339 n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
340 len = sizeof(struct ireg_buf) * n * 2;
342 case CUDBG_PM_INDIRECT:
343 n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
344 len = sizeof(struct ireg_buf) * n * 2;
347 len = sizeof(struct cudbg_tid_info_region_rev1);
349 case CUDBG_PCIE_CONFIG:
350 len = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
352 case CUDBG_DUMP_CONTEXT:
353 len = cudbg_dump_context_size(adap);
356 len = sizeof(struct cudbg_mps_tcam) *
357 adap->params.arch.mps_tcam_size;
360 len = sizeof(struct cudbg_vpd_data);
363 cudbg_fill_le_tcam_info(adap, &tcam_region);
364 len = sizeof(struct cudbg_tcam) +
365 sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
368 len = sizeof(u16) * NMTUS * NCCTRL_WIN;
370 case CUDBG_MA_INDIRECT:
371 if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
372 n = sizeof(t6_ma_ireg_array) /
373 (IREG_NUM_ELEM * sizeof(u32));
374 len = sizeof(struct ireg_buf) * n * 2;
378 len = sizeof(struct cudbg_ver_hdr) +
379 sizeof(struct cudbg_ulptx_la);
381 case CUDBG_UP_CIM_INDIRECT:
383 if (is_t5(adap->params.chip))
384 n = sizeof(t5_up_cim_reg_array) /
385 ((IREG_NUM_ELEM + 1) * sizeof(u32));
386 else if (is_t6(adap->params.chip))
387 n = sizeof(t6_up_cim_reg_array) /
388 ((IREG_NUM_ELEM + 1) * sizeof(u32));
389 len = sizeof(struct ireg_buf) * n;
391 case CUDBG_PBT_TABLE:
392 len = sizeof(struct cudbg_pbt_tables);
395 len = sizeof(struct cudbg_mbox_log) * adap->mbox_log->size;
397 case CUDBG_HMA_INDIRECT:
398 if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
399 n = sizeof(t6_hma_ireg_array) /
400 (IREG_NUM_ELEM * sizeof(u32));
401 len = sizeof(struct ireg_buf) * n;
405 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
406 if (value & HMA_MUX_F) {
407 /* In T6, there's no MC1. So, HMA shares MC1
410 value = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
411 len = EXT_MEM1_SIZE_G(value);
413 len = cudbg_mbytes_to_bytes(len);
416 cudbg_fill_qdesc_num_and_size(adap, NULL, &len);
425 static int cudbg_do_compression(struct cudbg_init *pdbg_init,
426 struct cudbg_buffer *pin_buff,
427 struct cudbg_buffer *dbg_buff)
429 struct cudbg_buffer temp_in_buff = { 0 };
430 int bytes_left, bytes_read, bytes;
431 u32 offset = dbg_buff->offset;
434 temp_in_buff.offset = pin_buff->offset;
435 temp_in_buff.data = pin_buff->data;
436 temp_in_buff.size = pin_buff->size;
438 bytes_left = pin_buff->size;
440 while (bytes_left > 0) {
441 /* Do compression in smaller chunks */
442 bytes = min_t(unsigned long, bytes_left,
443 (unsigned long)CUDBG_CHUNK_SIZE);
444 temp_in_buff.data = (char *)pin_buff->data + bytes_read;
445 temp_in_buff.size = bytes;
446 rc = cudbg_compress_buff(pdbg_init, &temp_in_buff, dbg_buff);
453 pin_buff->size = dbg_buff->offset - offset;
457 static int cudbg_write_and_release_buff(struct cudbg_init *pdbg_init,
458 struct cudbg_buffer *pin_buff,
459 struct cudbg_buffer *dbg_buff)
463 if (pdbg_init->compress_type == CUDBG_COMPRESSION_NONE) {
464 cudbg_update_buff(pin_buff, dbg_buff);
466 rc = cudbg_do_compression(pdbg_init, pin_buff, dbg_buff);
472 cudbg_put_buff(pdbg_init, pin_buff);
476 static int is_fw_attached(struct cudbg_init *pdbg_init)
478 struct adapter *padap = pdbg_init->adap;
480 if (!(padap->flags & CXGB4_FW_OK) || padap->use_bd)
486 /* This function will add additional padding bytes into debug_buffer to make it
489 void cudbg_align_debug_buffer(struct cudbg_buffer *dbg_buff,
490 struct cudbg_entity_hdr *entity_hdr)
492 u8 zero_buf[4] = {0};
495 remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
496 padding = 4 - remain;
498 memcpy(((u8 *)dbg_buff->data) + dbg_buff->offset, &zero_buf,
500 dbg_buff->offset += padding;
501 entity_hdr->num_pad = padding;
503 entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
506 struct cudbg_entity_hdr *cudbg_get_entity_hdr(void *outbuf, int i)
508 struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
510 return (struct cudbg_entity_hdr *)
511 ((char *)outbuf + cudbg_hdr->hdr_len +
512 (sizeof(struct cudbg_entity_hdr) * (i - 1)));
515 static int cudbg_read_vpd_reg(struct adapter *padap, u32 addr, u32 len,
520 vaddr = t4_eeprom_ptov(addr, padap->pf, EEPROMPFSIZE);
524 rc = pci_read_vpd(padap->pdev, vaddr, len, dest);
531 static int cudbg_mem_desc_cmp(const void *a, const void *b)
533 return ((const struct cudbg_mem_desc *)a)->base -
534 ((const struct cudbg_mem_desc *)b)->base;
537 int cudbg_fill_meminfo(struct adapter *padap,
538 struct cudbg_meminfo *meminfo_buff)
540 struct cudbg_mem_desc *md;
541 u32 lo, hi, used, alloc;
544 memset(meminfo_buff->avail, 0,
545 ARRAY_SIZE(meminfo_buff->avail) *
546 sizeof(struct cudbg_mem_desc));
547 memset(meminfo_buff->mem, 0,
548 (ARRAY_SIZE(cudbg_region) + 3) * sizeof(struct cudbg_mem_desc));
549 md = meminfo_buff->mem;
551 for (i = 0; i < ARRAY_SIZE(meminfo_buff->mem); i++) {
552 meminfo_buff->mem[i].limit = 0;
553 meminfo_buff->mem[i].idx = i;
556 /* Find and sort the populated memory ranges */
558 lo = t4_read_reg(padap, MA_TARGET_MEM_ENABLE_A);
559 if (lo & EDRAM0_ENABLE_F) {
560 hi = t4_read_reg(padap, MA_EDRAM0_BAR_A);
561 meminfo_buff->avail[i].base =
562 cudbg_mbytes_to_bytes(EDRAM0_BASE_G(hi));
563 meminfo_buff->avail[i].limit =
564 meminfo_buff->avail[i].base +
565 cudbg_mbytes_to_bytes(EDRAM0_SIZE_G(hi));
566 meminfo_buff->avail[i].idx = 0;
570 if (lo & EDRAM1_ENABLE_F) {
571 hi = t4_read_reg(padap, MA_EDRAM1_BAR_A);
572 meminfo_buff->avail[i].base =
573 cudbg_mbytes_to_bytes(EDRAM1_BASE_G(hi));
574 meminfo_buff->avail[i].limit =
575 meminfo_buff->avail[i].base +
576 cudbg_mbytes_to_bytes(EDRAM1_SIZE_G(hi));
577 meminfo_buff->avail[i].idx = 1;
581 if (is_t5(padap->params.chip)) {
582 if (lo & EXT_MEM0_ENABLE_F) {
583 hi = t4_read_reg(padap, MA_EXT_MEMORY0_BAR_A);
584 meminfo_buff->avail[i].base =
585 cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
586 meminfo_buff->avail[i].limit =
587 meminfo_buff->avail[i].base +
588 cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
589 meminfo_buff->avail[i].idx = 3;
593 if (lo & EXT_MEM1_ENABLE_F) {
594 hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
595 meminfo_buff->avail[i].base =
596 cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
597 meminfo_buff->avail[i].limit =
598 meminfo_buff->avail[i].base +
599 cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
600 meminfo_buff->avail[i].idx = 4;
604 if (lo & EXT_MEM_ENABLE_F) {
605 hi = t4_read_reg(padap, MA_EXT_MEMORY_BAR_A);
606 meminfo_buff->avail[i].base =
607 cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
608 meminfo_buff->avail[i].limit =
609 meminfo_buff->avail[i].base +
610 cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
611 meminfo_buff->avail[i].idx = 2;
615 if (lo & HMA_MUX_F) {
616 hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
617 meminfo_buff->avail[i].base =
618 cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
619 meminfo_buff->avail[i].limit =
620 meminfo_buff->avail[i].base +
621 cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
622 meminfo_buff->avail[i].idx = 5;
627 if (!i) /* no memory available */
628 return CUDBG_STATUS_ENTITY_NOT_FOUND;
630 meminfo_buff->avail_c = i;
631 sort(meminfo_buff->avail, i, sizeof(struct cudbg_mem_desc),
632 cudbg_mem_desc_cmp, NULL);
633 (md++)->base = t4_read_reg(padap, SGE_DBQ_CTXT_BADDR_A);
634 (md++)->base = t4_read_reg(padap, SGE_IMSG_CTXT_BADDR_A);
635 (md++)->base = t4_read_reg(padap, SGE_FLM_CACHE_BADDR_A);
636 (md++)->base = t4_read_reg(padap, TP_CMM_TCB_BASE_A);
637 (md++)->base = t4_read_reg(padap, TP_CMM_MM_BASE_A);
638 (md++)->base = t4_read_reg(padap, TP_CMM_TIMER_BASE_A);
639 (md++)->base = t4_read_reg(padap, TP_CMM_MM_RX_FLST_BASE_A);
640 (md++)->base = t4_read_reg(padap, TP_CMM_MM_TX_FLST_BASE_A);
641 (md++)->base = t4_read_reg(padap, TP_CMM_MM_PS_FLST_BASE_A);
643 /* the next few have explicit upper bounds */
644 md->base = t4_read_reg(padap, TP_PMM_TX_BASE_A);
645 md->limit = md->base - 1 +
646 t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A) *
647 PMTXMAXPAGE_G(t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A));
650 md->base = t4_read_reg(padap, TP_PMM_RX_BASE_A);
651 md->limit = md->base - 1 +
652 t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) *
653 PMRXMAXPAGE_G(t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A));
656 if (t4_read_reg(padap, LE_DB_CONFIG_A) & HASHEN_F) {
657 if (CHELSIO_CHIP_VERSION(padap->params.chip) <= CHELSIO_T5) {
658 hi = t4_read_reg(padap, LE_DB_TID_HASHBASE_A) / 4;
659 md->base = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
661 hi = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
662 md->base = t4_read_reg(padap,
663 LE_DB_HASH_TBL_BASE_ADDR_A);
668 md->idx = ARRAY_SIZE(cudbg_region); /* hide it */
672 #define ulp_region(reg) do { \
673 md->base = t4_read_reg(padap, ULP_ ## reg ## _LLIMIT_A);\
674 (md++)->limit = t4_read_reg(padap, ULP_ ## reg ## _ULIMIT_A);\
677 ulp_region(RX_ISCSI);
682 ulp_region(RX_RQUDP);
687 md->idx = ARRAY_SIZE(cudbg_region);
688 if (!is_t4(padap->params.chip)) {
689 u32 fifo_size = t4_read_reg(padap, SGE_DBVFIFO_SIZE_A);
690 u32 sge_ctrl = t4_read_reg(padap, SGE_CONTROL2_A);
693 if (is_t5(padap->params.chip)) {
694 if (sge_ctrl & VFIFO_ENABLE_F)
695 size = DBVFIFO_SIZE_G(fifo_size);
697 size = T6_DBVFIFO_SIZE_G(fifo_size);
701 md->base = BASEADDR_G(t4_read_reg(padap,
702 SGE_DBVFIFO_BADDR_A));
703 md->limit = md->base + (size << 2) - 1;
709 md->base = t4_read_reg(padap, ULP_RX_CTX_BASE_A);
712 md->base = t4_read_reg(padap, ULP_TX_ERR_TABLE_BASE_A);
716 md->base = padap->vres.ocq.start;
717 if (padap->vres.ocq.size)
718 md->limit = md->base + padap->vres.ocq.size - 1;
720 md->idx = ARRAY_SIZE(cudbg_region); /* hide it */
723 /* add any address-space holes, there can be up to 3 */
724 for (n = 0; n < i - 1; n++)
725 if (meminfo_buff->avail[n].limit <
726 meminfo_buff->avail[n + 1].base)
727 (md++)->base = meminfo_buff->avail[n].limit;
729 if (meminfo_buff->avail[n].limit)
730 (md++)->base = meminfo_buff->avail[n].limit;
732 n = md - meminfo_buff->mem;
733 meminfo_buff->mem_c = n;
735 sort(meminfo_buff->mem, n, sizeof(struct cudbg_mem_desc),
736 cudbg_mem_desc_cmp, NULL);
738 lo = t4_read_reg(padap, CIM_SDRAM_BASE_ADDR_A);
739 hi = t4_read_reg(padap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
740 meminfo_buff->up_ram_lo = lo;
741 meminfo_buff->up_ram_hi = hi;
743 lo = t4_read_reg(padap, CIM_EXTMEM2_BASE_ADDR_A);
744 hi = t4_read_reg(padap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
745 meminfo_buff->up_extmem2_lo = lo;
746 meminfo_buff->up_extmem2_hi = hi;
748 lo = t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A);
749 for (i = 0, meminfo_buff->free_rx_cnt = 0; i < 2; i++)
750 meminfo_buff->free_rx_cnt +=
751 FREERXPAGECOUNT_G(t4_read_reg(padap,
752 TP_FLM_FREE_RX_CNT_A));
754 meminfo_buff->rx_pages_data[0] = PMRXMAXPAGE_G(lo);
755 meminfo_buff->rx_pages_data[1] =
756 t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) >> 10;
757 meminfo_buff->rx_pages_data[2] = (lo & PMRXNUMCHN_F) ? 2 : 1;
759 lo = t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A);
760 hi = t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A);
761 for (i = 0, meminfo_buff->free_tx_cnt = 0; i < 4; i++)
762 meminfo_buff->free_tx_cnt +=
763 FREETXPAGECOUNT_G(t4_read_reg(padap,
764 TP_FLM_FREE_TX_CNT_A));
766 meminfo_buff->tx_pages_data[0] = PMTXMAXPAGE_G(lo);
767 meminfo_buff->tx_pages_data[1] =
768 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10);
769 meminfo_buff->tx_pages_data[2] =
770 hi >= (1 << 20) ? 'M' : 'K';
771 meminfo_buff->tx_pages_data[3] = 1 << PMTXNUMCHN_G(lo);
773 meminfo_buff->p_structs = t4_read_reg(padap, TP_CMM_MM_MAX_PSTRUCT_A);
774 meminfo_buff->p_structs_free_cnt =
775 FREEPSTRUCTCOUNT_G(t4_read_reg(padap, TP_FLM_FREE_PS_CNT_A));
777 for (i = 0; i < 4; i++) {
778 if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
779 lo = t4_read_reg(padap,
780 MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
782 lo = t4_read_reg(padap, MPS_RX_PG_RSV0_A + i * 4);
783 if (is_t5(padap->params.chip)) {
784 used = T5_USED_G(lo);
785 alloc = T5_ALLOC_G(lo);
790 meminfo_buff->port_used[i] = used;
791 meminfo_buff->port_alloc[i] = alloc;
794 for (i = 0; i < padap->params.arch.nchan; i++) {
795 if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
796 lo = t4_read_reg(padap,
797 MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
799 lo = t4_read_reg(padap, MPS_RX_PG_RSV4_A + i * 4);
800 if (is_t5(padap->params.chip)) {
801 used = T5_USED_G(lo);
802 alloc = T5_ALLOC_G(lo);
807 meminfo_buff->loopback_used[i] = used;
808 meminfo_buff->loopback_alloc[i] = alloc;
814 int cudbg_collect_reg_dump(struct cudbg_init *pdbg_init,
815 struct cudbg_buffer *dbg_buff,
816 struct cudbg_error *cudbg_err)
818 struct adapter *padap = pdbg_init->adap;
819 struct cudbg_buffer temp_buff = { 0 };
823 if (is_t4(padap->params.chip))
824 buf_size = T4_REGMAP_SIZE;
825 else if (is_t5(padap->params.chip) || is_t6(padap->params.chip))
826 buf_size = T5_REGMAP_SIZE;
828 rc = cudbg_get_buff(pdbg_init, dbg_buff, buf_size, &temp_buff);
831 t4_get_regs(padap, (void *)temp_buff.data, temp_buff.size);
832 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
835 int cudbg_collect_fw_devlog(struct cudbg_init *pdbg_init,
836 struct cudbg_buffer *dbg_buff,
837 struct cudbg_error *cudbg_err)
839 struct adapter *padap = pdbg_init->adap;
840 struct cudbg_buffer temp_buff = { 0 };
841 struct devlog_params *dparams;
844 rc = t4_init_devlog_params(padap);
846 cudbg_err->sys_err = rc;
850 dparams = &padap->params.devlog;
851 rc = cudbg_get_buff(pdbg_init, dbg_buff, dparams->size, &temp_buff);
855 /* Collect FW devlog */
856 if (dparams->start != 0) {
857 spin_lock(&padap->win0_lock);
858 rc = t4_memory_rw(padap, padap->params.drv_memwin,
859 dparams->memtype, dparams->start,
861 (__be32 *)(char *)temp_buff.data,
863 spin_unlock(&padap->win0_lock);
865 cudbg_err->sys_err = rc;
866 cudbg_put_buff(pdbg_init, &temp_buff);
870 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
873 int cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
874 struct cudbg_buffer *dbg_buff,
875 struct cudbg_error *cudbg_err)
877 struct adapter *padap = pdbg_init->adap;
878 struct cudbg_buffer temp_buff = { 0 };
882 if (is_t6(padap->params.chip)) {
883 size = padap->params.cim_la_size / 10 + 1;
884 size *= 10 * sizeof(u32);
886 size = padap->params.cim_la_size / 8;
887 size *= 8 * sizeof(u32);
891 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
895 rc = t4_cim_read(padap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
897 cudbg_err->sys_err = rc;
898 cudbg_put_buff(pdbg_init, &temp_buff);
902 memcpy((char *)temp_buff.data, &cfg, sizeof(cfg));
903 rc = t4_cim_read_la(padap,
904 (u32 *)((char *)temp_buff.data + sizeof(cfg)),
907 cudbg_err->sys_err = rc;
908 cudbg_put_buff(pdbg_init, &temp_buff);
911 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
914 int cudbg_collect_cim_ma_la(struct cudbg_init *pdbg_init,
915 struct cudbg_buffer *dbg_buff,
916 struct cudbg_error *cudbg_err)
918 struct adapter *padap = pdbg_init->adap;
919 struct cudbg_buffer temp_buff = { 0 };
922 size = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
923 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
927 t4_cim_read_ma_la(padap,
928 (u32 *)temp_buff.data,
929 (u32 *)((char *)temp_buff.data +
931 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
934 int cudbg_collect_cim_qcfg(struct cudbg_init *pdbg_init,
935 struct cudbg_buffer *dbg_buff,
936 struct cudbg_error *cudbg_err)
938 struct adapter *padap = pdbg_init->adap;
939 struct cudbg_buffer temp_buff = { 0 };
940 struct cudbg_cim_qcfg *cim_qcfg_data;
943 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_cim_qcfg),
948 cim_qcfg_data = (struct cudbg_cim_qcfg *)temp_buff.data;
949 cim_qcfg_data->chip = padap->params.chip;
950 rc = t4_cim_read(padap, UP_IBQ_0_RDADDR_A,
951 ARRAY_SIZE(cim_qcfg_data->stat), cim_qcfg_data->stat);
953 cudbg_err->sys_err = rc;
954 cudbg_put_buff(pdbg_init, &temp_buff);
958 rc = t4_cim_read(padap, UP_OBQ_0_REALADDR_A,
959 ARRAY_SIZE(cim_qcfg_data->obq_wr),
960 cim_qcfg_data->obq_wr);
962 cudbg_err->sys_err = rc;
963 cudbg_put_buff(pdbg_init, &temp_buff);
967 t4_read_cimq_cfg(padap, cim_qcfg_data->base, cim_qcfg_data->size,
968 cim_qcfg_data->thres);
969 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
972 static int cudbg_read_cim_ibq(struct cudbg_init *pdbg_init,
973 struct cudbg_buffer *dbg_buff,
974 struct cudbg_error *cudbg_err, int qid)
976 struct adapter *padap = pdbg_init->adap;
977 struct cudbg_buffer temp_buff = { 0 };
978 int no_of_read_words, rc = 0;
981 /* collect CIM IBQ */
982 qsize = CIM_IBQ_SIZE * 4 * sizeof(u32);
983 rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
987 /* t4_read_cim_ibq will return no. of read words or error */
988 no_of_read_words = t4_read_cim_ibq(padap, qid,
989 (u32 *)temp_buff.data, qsize);
990 /* no_of_read_words is less than or equal to 0 means error */
991 if (no_of_read_words <= 0) {
992 if (!no_of_read_words)
993 rc = CUDBG_SYSTEM_ERROR;
995 rc = no_of_read_words;
996 cudbg_err->sys_err = rc;
997 cudbg_put_buff(pdbg_init, &temp_buff);
1000 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1003 int cudbg_collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
1004 struct cudbg_buffer *dbg_buff,
1005 struct cudbg_error *cudbg_err)
1007 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 0);
1010 int cudbg_collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
1011 struct cudbg_buffer *dbg_buff,
1012 struct cudbg_error *cudbg_err)
1014 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 1);
1017 int cudbg_collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
1018 struct cudbg_buffer *dbg_buff,
1019 struct cudbg_error *cudbg_err)
1021 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 2);
1024 int cudbg_collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
1025 struct cudbg_buffer *dbg_buff,
1026 struct cudbg_error *cudbg_err)
1028 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 3);
1031 int cudbg_collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
1032 struct cudbg_buffer *dbg_buff,
1033 struct cudbg_error *cudbg_err)
1035 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 4);
1038 int cudbg_collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
1039 struct cudbg_buffer *dbg_buff,
1040 struct cudbg_error *cudbg_err)
1042 return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 5);
1045 u32 cudbg_cim_obq_size(struct adapter *padap, int qid)
1049 t4_write_reg(padap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
1050 QUENUMSELECT_V(qid));
1051 value = t4_read_reg(padap, CIM_QUEUE_CONFIG_CTRL_A);
1052 value = CIMQSIZE_G(value) * 64; /* size in number of words */
1053 return value * sizeof(u32);
1056 static int cudbg_read_cim_obq(struct cudbg_init *pdbg_init,
1057 struct cudbg_buffer *dbg_buff,
1058 struct cudbg_error *cudbg_err, int qid)
1060 struct adapter *padap = pdbg_init->adap;
1061 struct cudbg_buffer temp_buff = { 0 };
1062 int no_of_read_words, rc = 0;
1065 /* collect CIM OBQ */
1066 qsize = cudbg_cim_obq_size(padap, qid);
1067 rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
1071 /* t4_read_cim_obq will return no. of read words or error */
1072 no_of_read_words = t4_read_cim_obq(padap, qid,
1073 (u32 *)temp_buff.data, qsize);
1074 /* no_of_read_words is less than or equal to 0 means error */
1075 if (no_of_read_words <= 0) {
1076 if (!no_of_read_words)
1077 rc = CUDBG_SYSTEM_ERROR;
1079 rc = no_of_read_words;
1080 cudbg_err->sys_err = rc;
1081 cudbg_put_buff(pdbg_init, &temp_buff);
1084 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1087 int cudbg_collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
1088 struct cudbg_buffer *dbg_buff,
1089 struct cudbg_error *cudbg_err)
1091 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 0);
1094 int cudbg_collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
1095 struct cudbg_buffer *dbg_buff,
1096 struct cudbg_error *cudbg_err)
1098 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 1);
1101 int cudbg_collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
1102 struct cudbg_buffer *dbg_buff,
1103 struct cudbg_error *cudbg_err)
1105 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 2);
1108 int cudbg_collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
1109 struct cudbg_buffer *dbg_buff,
1110 struct cudbg_error *cudbg_err)
1112 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 3);
1115 int cudbg_collect_cim_obq_sge(struct cudbg_init *pdbg_init,
1116 struct cudbg_buffer *dbg_buff,
1117 struct cudbg_error *cudbg_err)
1119 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 4);
1122 int cudbg_collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
1123 struct cudbg_buffer *dbg_buff,
1124 struct cudbg_error *cudbg_err)
1126 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 5);
1129 int cudbg_collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
1130 struct cudbg_buffer *dbg_buff,
1131 struct cudbg_error *cudbg_err)
1133 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 6);
1136 int cudbg_collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
1137 struct cudbg_buffer *dbg_buff,
1138 struct cudbg_error *cudbg_err)
1140 return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 7);
1143 static int cudbg_meminfo_get_mem_index(struct adapter *padap,
1144 struct cudbg_meminfo *mem_info,
1145 u8 mem_type, u8 *idx)
1157 /* Some T5 cards have both MC0 and MC1. */
1158 flag = is_t5(padap->params.chip) ? MC0_FLAG : MC_FLAG;
1167 return CUDBG_STATUS_ENTITY_NOT_FOUND;
1170 for (i = 0; i < mem_info->avail_c; i++) {
1171 if (mem_info->avail[i].idx == flag) {
1177 return CUDBG_STATUS_ENTITY_NOT_FOUND;
1180 /* Fetch the @region_name's start and end from @meminfo. */
1181 static int cudbg_get_mem_region(struct adapter *padap,
1182 struct cudbg_meminfo *meminfo,
1183 u8 mem_type, const char *region_name,
1184 struct cudbg_mem_desc *mem_desc)
1190 rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc);
1194 i = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
1199 for (i = 0; i < meminfo->mem_c; i++) {
1200 if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
1201 continue; /* Skip holes */
1203 if (!(meminfo->mem[i].limit))
1204 meminfo->mem[i].limit =
1205 i < meminfo->mem_c - 1 ?
1206 meminfo->mem[i + 1].base - 1 : ~0;
1208 if (meminfo->mem[i].idx == idx) {
1209 /* Check if the region exists in @mem_type memory */
1210 if (meminfo->mem[i].base < meminfo->avail[mc].base &&
1211 meminfo->mem[i].limit < meminfo->avail[mc].base)
1214 if (meminfo->mem[i].base > meminfo->avail[mc].limit)
1217 memcpy(mem_desc, &meminfo->mem[i],
1218 sizeof(struct cudbg_mem_desc));
1229 /* Fetch and update the start and end of the requested memory region w.r.t 0
1230 * in the corresponding EDC/MC/HMA.
1232 static int cudbg_get_mem_relative(struct adapter *padap,
1233 struct cudbg_meminfo *meminfo,
1234 u8 mem_type, u32 *out_base, u32 *out_end)
1239 rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc_idx);
1243 if (*out_base < meminfo->avail[mc_idx].base)
1246 *out_base -= meminfo->avail[mc_idx].base;
1248 if (*out_end > meminfo->avail[mc_idx].limit)
1249 *out_end = meminfo->avail[mc_idx].limit;
1251 *out_end -= meminfo->avail[mc_idx].base;
1256 /* Get TX and RX Payload region */
1257 static int cudbg_get_payload_range(struct adapter *padap, u8 mem_type,
1258 const char *region_name,
1259 struct cudbg_region_info *payload)
1261 struct cudbg_mem_desc mem_desc = { 0 };
1262 struct cudbg_meminfo meminfo;
1265 rc = cudbg_fill_meminfo(padap, &meminfo);
1269 rc = cudbg_get_mem_region(padap, &meminfo, mem_type, region_name,
1272 payload->exist = false;
1276 payload->exist = true;
1277 payload->start = mem_desc.base;
1278 payload->end = mem_desc.limit;
1280 return cudbg_get_mem_relative(padap, &meminfo, mem_type,
1281 &payload->start, &payload->end);
1284 static int cudbg_memory_read(struct cudbg_init *pdbg_init, int win,
1285 int mtype, u32 addr, u32 len, void *hbuf)
1287 u32 win_pf, memoffset, mem_aperture, mem_base;
1288 struct adapter *adap = pdbg_init->adap;
1289 u32 pos, offset, resid;
1294 /* Argument sanity checks ...
1296 if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
1301 /* Try to do 64-bit reads. Residual will be handled later. */
1305 ret = t4_memory_rw_init(adap, win, mtype, &memoffset, &mem_base,
1310 addr = addr + memoffset;
1311 win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
1313 pos = addr & ~(mem_aperture - 1);
1314 offset = addr - pos;
1316 /* Set up initial PCI-E Memory Window to cover the start of our
1319 t4_memory_update_win(adap, win, pos | win_pf);
1321 /* Transfer data from the adapter */
1323 *buf++ = le64_to_cpu((__force __le64)
1324 t4_read_reg64(adap, mem_base + offset));
1325 offset += sizeof(u64);
1328 /* If we've reached the end of our current window aperture,
1329 * move the PCI-E Memory Window on to the next.
1331 if (offset == mem_aperture) {
1332 pos += mem_aperture;
1334 t4_memory_update_win(adap, win, pos | win_pf);
1338 res_buf = (u32 *)buf;
1339 /* Read residual in 32-bit multiples */
1340 while (resid > sizeof(u32)) {
1341 *res_buf++ = le32_to_cpu((__force __le32)
1342 t4_read_reg(adap, mem_base + offset));
1343 offset += sizeof(u32);
1344 resid -= sizeof(u32);
1346 /* If we've reached the end of our current window aperture,
1347 * move the PCI-E Memory Window on to the next.
1349 if (offset == mem_aperture) {
1350 pos += mem_aperture;
1352 t4_memory_update_win(adap, win, pos | win_pf);
1356 /* Transfer residual < 32-bits */
1358 t4_memory_rw_residual(adap, resid, mem_base + offset,
1359 (u8 *)res_buf, T4_MEMORY_READ);
1364 #define CUDBG_YIELD_ITERATION 256
1366 static int cudbg_read_fw_mem(struct cudbg_init *pdbg_init,
1367 struct cudbg_buffer *dbg_buff, u8 mem_type,
1368 unsigned long tot_len,
1369 struct cudbg_error *cudbg_err)
1371 static const char * const region_name[] = { "Tx payload:",
1373 unsigned long bytes, bytes_left, bytes_read = 0;
1374 struct adapter *padap = pdbg_init->adap;
1375 struct cudbg_buffer temp_buff = { 0 };
1376 struct cudbg_region_info payload[2];
1377 u32 yield_count = 0;
1381 /* Get TX/RX Payload region range if they exist */
1382 memset(payload, 0, sizeof(payload));
1383 for (i = 0; i < ARRAY_SIZE(region_name); i++) {
1384 rc = cudbg_get_payload_range(padap, mem_type, region_name[i],
1389 if (payload[i].exist) {
1390 /* Align start and end to avoid wrap around */
1391 payload[i].start = roundup(payload[i].start,
1393 payload[i].end = rounddown(payload[i].end,
1398 bytes_left = tot_len;
1399 while (bytes_left > 0) {
1400 /* As MC size is huge and read through PIO access, this
1401 * loop will hold cpu for a longer time. OS may think that
1402 * the process is hanged and will generate CPU stall traces.
1403 * So yield the cpu regularly.
1406 if (!(yield_count % CUDBG_YIELD_ITERATION))
1409 bytes = min_t(unsigned long, bytes_left,
1410 (unsigned long)CUDBG_CHUNK_SIZE);
1411 rc = cudbg_get_buff(pdbg_init, dbg_buff, bytes, &temp_buff);
1415 for (i = 0; i < ARRAY_SIZE(payload); i++)
1416 if (payload[i].exist &&
1417 bytes_read >= payload[i].start &&
1418 bytes_read + bytes <= payload[i].end)
1419 /* TX and RX Payload regions can't overlap */
1422 spin_lock(&padap->win0_lock);
1423 rc = cudbg_memory_read(pdbg_init, MEMWIN_NIC, mem_type,
1424 bytes_read, bytes, temp_buff.data);
1425 spin_unlock(&padap->win0_lock);
1427 cudbg_err->sys_err = rc;
1428 cudbg_put_buff(pdbg_init, &temp_buff);
1433 bytes_left -= bytes;
1434 bytes_read += bytes;
1435 rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
1438 cudbg_put_buff(pdbg_init, &temp_buff);
1445 static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
1446 struct cudbg_error *cudbg_err)
1448 struct adapter *padap = pdbg_init->adap;
1451 if (is_fw_attached(pdbg_init)) {
1452 /* Flush uP dcache before reading edcX/mcX */
1453 rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
1455 cudbg_err->sys_warn = rc;
1459 static int cudbg_mem_region_size(struct cudbg_init *pdbg_init,
1460 struct cudbg_error *cudbg_err,
1461 u8 mem_type, unsigned long *region_size)
1463 struct adapter *padap = pdbg_init->adap;
1464 struct cudbg_meminfo mem_info;
1468 memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
1469 rc = cudbg_fill_meminfo(padap, &mem_info);
1471 cudbg_err->sys_err = rc;
1475 cudbg_t4_fwcache(pdbg_init, cudbg_err);
1476 rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
1478 cudbg_err->sys_err = rc;
1483 *region_size = mem_info.avail[mc_idx].limit -
1484 mem_info.avail[mc_idx].base;
1489 static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
1490 struct cudbg_buffer *dbg_buff,
1491 struct cudbg_error *cudbg_err,
1494 unsigned long size = 0;
1497 rc = cudbg_mem_region_size(pdbg_init, cudbg_err, mem_type, &size);
1501 return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
1505 int cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
1506 struct cudbg_buffer *dbg_buff,
1507 struct cudbg_error *cudbg_err)
1509 return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
1513 int cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
1514 struct cudbg_buffer *dbg_buff,
1515 struct cudbg_error *cudbg_err)
1517 return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
1521 int cudbg_collect_mc0_meminfo(struct cudbg_init *pdbg_init,
1522 struct cudbg_buffer *dbg_buff,
1523 struct cudbg_error *cudbg_err)
1525 return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
1529 int cudbg_collect_mc1_meminfo(struct cudbg_init *pdbg_init,
1530 struct cudbg_buffer *dbg_buff,
1531 struct cudbg_error *cudbg_err)
1533 return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
1537 int cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,
1538 struct cudbg_buffer *dbg_buff,
1539 struct cudbg_error *cudbg_err)
1541 return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
1545 int cudbg_collect_rss(struct cudbg_init *pdbg_init,
1546 struct cudbg_buffer *dbg_buff,
1547 struct cudbg_error *cudbg_err)
1549 struct adapter *padap = pdbg_init->adap;
1550 struct cudbg_buffer temp_buff = { 0 };
1553 nentries = t4_chip_rss_size(padap);
1554 rc = cudbg_get_buff(pdbg_init, dbg_buff, nentries * sizeof(u16),
1559 rc = t4_read_rss(padap, (u16 *)temp_buff.data);
1561 cudbg_err->sys_err = rc;
1562 cudbg_put_buff(pdbg_init, &temp_buff);
1565 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1568 int cudbg_collect_rss_vf_config(struct cudbg_init *pdbg_init,
1569 struct cudbg_buffer *dbg_buff,
1570 struct cudbg_error *cudbg_err)
1572 struct adapter *padap = pdbg_init->adap;
1573 struct cudbg_buffer temp_buff = { 0 };
1574 struct cudbg_rss_vf_conf *vfconf;
1575 int vf, rc, vf_count;
1577 vf_count = padap->params.arch.vfcount;
1578 rc = cudbg_get_buff(pdbg_init, dbg_buff,
1579 vf_count * sizeof(struct cudbg_rss_vf_conf),
1584 vfconf = (struct cudbg_rss_vf_conf *)temp_buff.data;
1585 for (vf = 0; vf < vf_count; vf++)
1586 t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
1587 &vfconf[vf].rss_vf_vfh, true);
1588 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1591 int cudbg_collect_path_mtu(struct cudbg_init *pdbg_init,
1592 struct cudbg_buffer *dbg_buff,
1593 struct cudbg_error *cudbg_err)
1595 struct adapter *padap = pdbg_init->adap;
1596 struct cudbg_buffer temp_buff = { 0 };
1599 rc = cudbg_get_buff(pdbg_init, dbg_buff, NMTUS * sizeof(u16),
1604 t4_read_mtu_tbl(padap, (u16 *)temp_buff.data, NULL);
1605 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1608 int cudbg_collect_pm_stats(struct cudbg_init *pdbg_init,
1609 struct cudbg_buffer *dbg_buff,
1610 struct cudbg_error *cudbg_err)
1612 struct adapter *padap = pdbg_init->adap;
1613 struct cudbg_buffer temp_buff = { 0 };
1614 struct cudbg_pm_stats *pm_stats_buff;
1617 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_pm_stats),
1622 pm_stats_buff = (struct cudbg_pm_stats *)temp_buff.data;
1623 t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
1624 t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
1625 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1628 int cudbg_collect_hw_sched(struct cudbg_init *pdbg_init,
1629 struct cudbg_buffer *dbg_buff,
1630 struct cudbg_error *cudbg_err)
1632 struct adapter *padap = pdbg_init->adap;
1633 struct cudbg_buffer temp_buff = { 0 };
1634 struct cudbg_hw_sched *hw_sched_buff;
1637 if (!padap->params.vpd.cclk)
1638 return CUDBG_STATUS_CCLK_NOT_DEFINED;
1640 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_hw_sched),
1646 hw_sched_buff = (struct cudbg_hw_sched *)temp_buff.data;
1647 hw_sched_buff->map = t4_read_reg(padap, TP_TX_MOD_QUEUE_REQ_MAP_A);
1648 hw_sched_buff->mode = TIMERMODE_G(t4_read_reg(padap, TP_MOD_CONFIG_A));
1649 t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
1650 for (i = 0; i < NTX_SCHED; ++i)
1651 t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
1652 &hw_sched_buff->ipg[i], true);
1653 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1656 int cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
1657 struct cudbg_buffer *dbg_buff,
1658 struct cudbg_error *cudbg_err)
1660 struct adapter *padap = pdbg_init->adap;
1661 struct cudbg_buffer temp_buff = { 0 };
1662 struct ireg_buf *ch_tp_pio;
1666 if (is_t5(padap->params.chip))
1667 n = sizeof(t5_tp_pio_array) +
1668 sizeof(t5_tp_tm_pio_array) +
1669 sizeof(t5_tp_mib_index_array);
1671 n = sizeof(t6_tp_pio_array) +
1672 sizeof(t6_tp_tm_pio_array) +
1673 sizeof(t6_tp_mib_index_array);
1675 n = n / (IREG_NUM_ELEM * sizeof(u32));
1676 size = sizeof(struct ireg_buf) * n;
1677 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
1681 ch_tp_pio = (struct ireg_buf *)temp_buff.data;
1684 if (is_t5(padap->params.chip))
1685 n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
1686 else if (is_t6(padap->params.chip))
1687 n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
1689 for (i = 0; i < n; i++) {
1690 struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
1691 u32 *buff = ch_tp_pio->outbuf;
1693 if (is_t5(padap->params.chip)) {
1694 tp_pio->ireg_addr = t5_tp_pio_array[i][0];
1695 tp_pio->ireg_data = t5_tp_pio_array[i][1];
1696 tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
1697 tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
1698 } else if (is_t6(padap->params.chip)) {
1699 tp_pio->ireg_addr = t6_tp_pio_array[i][0];
1700 tp_pio->ireg_data = t6_tp_pio_array[i][1];
1701 tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
1702 tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
1704 t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
1705 tp_pio->ireg_local_offset, true);
1710 if (is_t5(padap->params.chip))
1711 n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
1712 else if (is_t6(padap->params.chip))
1713 n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
1715 for (i = 0; i < n; i++) {
1716 struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
1717 u32 *buff = ch_tp_pio->outbuf;
1719 if (is_t5(padap->params.chip)) {
1720 tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
1721 tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
1722 tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
1723 tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
1724 } else if (is_t6(padap->params.chip)) {
1725 tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
1726 tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
1727 tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
1728 tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
1730 t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
1731 tp_pio->ireg_local_offset, true);
1736 if (is_t5(padap->params.chip))
1737 n = sizeof(t5_tp_mib_index_array) /
1738 (IREG_NUM_ELEM * sizeof(u32));
1739 else if (is_t6(padap->params.chip))
1740 n = sizeof(t6_tp_mib_index_array) /
1741 (IREG_NUM_ELEM * sizeof(u32));
1743 for (i = 0; i < n ; i++) {
1744 struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
1745 u32 *buff = ch_tp_pio->outbuf;
1747 if (is_t5(padap->params.chip)) {
1748 tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
1749 tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
1750 tp_pio->ireg_local_offset =
1751 t5_tp_mib_index_array[i][2];
1752 tp_pio->ireg_offset_range =
1753 t5_tp_mib_index_array[i][3];
1754 } else if (is_t6(padap->params.chip)) {
1755 tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
1756 tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
1757 tp_pio->ireg_local_offset =
1758 t6_tp_mib_index_array[i][2];
1759 tp_pio->ireg_offset_range =
1760 t6_tp_mib_index_array[i][3];
1762 t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
1763 tp_pio->ireg_local_offset, true);
1766 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1769 static void cudbg_read_sge_qbase_indirect_reg(struct adapter *padap,
1770 struct sge_qbase_reg_field *qbase,
1771 u32 func, bool is_pf)
1776 buff = qbase->pf_data_value[func];
1778 buff = qbase->vf_data_value[func];
1779 /* In SGE_QBASE_INDEX,
1780 * Entries 0->7 are PF0->7, Entries 8->263 are VFID0->256.
1785 t4_write_reg(padap, qbase->reg_addr, func);
1786 for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++, buff++)
1787 *buff = t4_read_reg(padap, qbase->reg_data[i]);
1790 int cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
1791 struct cudbg_buffer *dbg_buff,
1792 struct cudbg_error *cudbg_err)
1794 struct adapter *padap = pdbg_init->adap;
1795 struct cudbg_buffer temp_buff = { 0 };
1796 struct sge_qbase_reg_field *sge_qbase;
1797 struct ireg_buf *ch_sge_dbg;
1798 u8 padap_running = 0;
1802 /* Accessing SGE_QBASE_MAP[0-3] and SGE_QBASE_INDEX regs can
1803 * lead to SGE missing doorbells under heavy traffic. So, only
1804 * collect them when adapter is idle.
1806 for_each_port(padap, i) {
1807 padap_running = netif_running(padap->port[i]);
1812 size = sizeof(*ch_sge_dbg) * 2;
1814 size += sizeof(*sge_qbase);
1816 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
1820 ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
1821 for (i = 0; i < 2; i++) {
1822 struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
1823 u32 *buff = ch_sge_dbg->outbuf;
1825 sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
1826 sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
1827 sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
1828 sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
1829 t4_read_indirect(padap,
1833 sge_pio->ireg_offset_range,
1834 sge_pio->ireg_local_offset);
1838 if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5 &&
1840 sge_qbase = (struct sge_qbase_reg_field *)ch_sge_dbg;
1841 /* 1 addr reg SGE_QBASE_INDEX and 4 data reg
1842 * SGE_QBASE_MAP[0-3]
1844 sge_qbase->reg_addr = t6_sge_qbase_index_array[0];
1845 for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++)
1846 sge_qbase->reg_data[i] =
1847 t6_sge_qbase_index_array[i + 1];
1849 for (i = 0; i <= PCIE_FW_MASTER_M; i++)
1850 cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
1853 for (i = 0; i < padap->params.arch.vfcount; i++)
1854 cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
1857 sge_qbase->vfcount = padap->params.arch.vfcount;
1860 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1863 int cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
1864 struct cudbg_buffer *dbg_buff,
1865 struct cudbg_error *cudbg_err)
1867 struct adapter *padap = pdbg_init->adap;
1868 struct cudbg_buffer temp_buff = { 0 };
1869 struct cudbg_ulprx_la *ulprx_la_buff;
1872 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_ulprx_la),
1877 ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
1878 t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
1879 ulprx_la_buff->size = ULPRX_LA_SIZE;
1880 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1883 int cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
1884 struct cudbg_buffer *dbg_buff,
1885 struct cudbg_error *cudbg_err)
1887 struct adapter *padap = pdbg_init->adap;
1888 struct cudbg_buffer temp_buff = { 0 };
1889 struct cudbg_tp_la *tp_la_buff;
1892 size = sizeof(struct cudbg_tp_la) + TPLA_SIZE * sizeof(u64);
1893 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
1897 tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
1898 tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
1899 t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
1900 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1903 int cudbg_collect_meminfo(struct cudbg_init *pdbg_init,
1904 struct cudbg_buffer *dbg_buff,
1905 struct cudbg_error *cudbg_err)
1907 struct adapter *padap = pdbg_init->adap;
1908 struct cudbg_buffer temp_buff = { 0 };
1909 struct cudbg_meminfo *meminfo_buff;
1910 struct cudbg_ver_hdr *ver_hdr;
1913 rc = cudbg_get_buff(pdbg_init, dbg_buff,
1914 sizeof(struct cudbg_ver_hdr) +
1915 sizeof(struct cudbg_meminfo),
1920 ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
1921 ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
1922 ver_hdr->revision = CUDBG_MEMINFO_REV;
1923 ver_hdr->size = sizeof(struct cudbg_meminfo);
1925 meminfo_buff = (struct cudbg_meminfo *)(temp_buff.data +
1927 rc = cudbg_fill_meminfo(padap, meminfo_buff);
1929 cudbg_err->sys_err = rc;
1930 cudbg_put_buff(pdbg_init, &temp_buff);
1934 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1937 int cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
1938 struct cudbg_buffer *dbg_buff,
1939 struct cudbg_error *cudbg_err)
1941 struct cudbg_cim_pif_la *cim_pif_la_buff;
1942 struct adapter *padap = pdbg_init->adap;
1943 struct cudbg_buffer temp_buff = { 0 };
1946 size = sizeof(struct cudbg_cim_pif_la) +
1947 2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
1948 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
1952 cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
1953 cim_pif_la_buff->size = CIM_PIFLA_SIZE;
1954 t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
1955 (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
1957 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
1960 int cudbg_collect_clk_info(struct cudbg_init *pdbg_init,
1961 struct cudbg_buffer *dbg_buff,
1962 struct cudbg_error *cudbg_err)
1964 struct adapter *padap = pdbg_init->adap;
1965 struct cudbg_buffer temp_buff = { 0 };
1966 struct cudbg_clk_info *clk_info_buff;
1970 if (!padap->params.vpd.cclk)
1971 return CUDBG_STATUS_CCLK_NOT_DEFINED;
1973 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_clk_info),
1978 clk_info_buff = (struct cudbg_clk_info *)temp_buff.data;
1979 clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk; /* psec */
1980 clk_info_buff->res = t4_read_reg(padap, TP_TIMER_RESOLUTION_A);
1981 clk_info_buff->tre = TIMERRESOLUTION_G(clk_info_buff->res);
1982 clk_info_buff->dack_re = DELAYEDACKRESOLUTION_G(clk_info_buff->res);
1983 tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
1985 clk_info_buff->dack_timer =
1986 (clk_info_buff->cclk_ps << clk_info_buff->dack_re) / 1000000 *
1987 t4_read_reg(padap, TP_DACK_TIMER_A);
1988 clk_info_buff->retransmit_min =
1989 tp_tick_us * t4_read_reg(padap, TP_RXT_MIN_A);
1990 clk_info_buff->retransmit_max =
1991 tp_tick_us * t4_read_reg(padap, TP_RXT_MAX_A);
1992 clk_info_buff->persist_timer_min =
1993 tp_tick_us * t4_read_reg(padap, TP_PERS_MIN_A);
1994 clk_info_buff->persist_timer_max =
1995 tp_tick_us * t4_read_reg(padap, TP_PERS_MAX_A);
1996 clk_info_buff->keepalive_idle_timer =
1997 tp_tick_us * t4_read_reg(padap, TP_KEEP_IDLE_A);
1998 clk_info_buff->keepalive_interval =
1999 tp_tick_us * t4_read_reg(padap, TP_KEEP_INTVL_A);
2000 clk_info_buff->initial_srtt =
2001 tp_tick_us * INITSRTT_G(t4_read_reg(padap, TP_INIT_SRTT_A));
2002 clk_info_buff->finwait2_timer =
2003 tp_tick_us * t4_read_reg(padap, TP_FINWAIT2_TIMER_A);
2005 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2008 int cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
2009 struct cudbg_buffer *dbg_buff,
2010 struct cudbg_error *cudbg_err)
2012 struct adapter *padap = pdbg_init->adap;
2013 struct cudbg_buffer temp_buff = { 0 };
2014 struct ireg_buf *ch_pcie;
2018 n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
2019 size = sizeof(struct ireg_buf) * n * 2;
2020 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2024 ch_pcie = (struct ireg_buf *)temp_buff.data;
2026 for (i = 0; i < n; i++) {
2027 struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
2028 u32 *buff = ch_pcie->outbuf;
2030 pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
2031 pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
2032 pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
2033 pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
2034 t4_read_indirect(padap,
2035 pcie_pio->ireg_addr,
2036 pcie_pio->ireg_data,
2038 pcie_pio->ireg_offset_range,
2039 pcie_pio->ireg_local_offset);
2044 n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
2045 for (i = 0; i < n; i++) {
2046 struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
2047 u32 *buff = ch_pcie->outbuf;
2049 pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
2050 pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
2051 pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
2052 pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
2053 t4_read_indirect(padap,
2054 pcie_pio->ireg_addr,
2055 pcie_pio->ireg_data,
2057 pcie_pio->ireg_offset_range,
2058 pcie_pio->ireg_local_offset);
2061 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2064 int cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
2065 struct cudbg_buffer *dbg_buff,
2066 struct cudbg_error *cudbg_err)
2068 struct adapter *padap = pdbg_init->adap;
2069 struct cudbg_buffer temp_buff = { 0 };
2070 struct ireg_buf *ch_pm;
2074 n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
2075 size = sizeof(struct ireg_buf) * n * 2;
2076 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2080 ch_pm = (struct ireg_buf *)temp_buff.data;
2082 for (i = 0; i < n; i++) {
2083 struct ireg_field *pm_pio = &ch_pm->tp_pio;
2084 u32 *buff = ch_pm->outbuf;
2086 pm_pio->ireg_addr = t5_pm_rx_array[i][0];
2087 pm_pio->ireg_data = t5_pm_rx_array[i][1];
2088 pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
2089 pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
2090 t4_read_indirect(padap,
2094 pm_pio->ireg_offset_range,
2095 pm_pio->ireg_local_offset);
2100 n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
2101 for (i = 0; i < n; i++) {
2102 struct ireg_field *pm_pio = &ch_pm->tp_pio;
2103 u32 *buff = ch_pm->outbuf;
2105 pm_pio->ireg_addr = t5_pm_tx_array[i][0];
2106 pm_pio->ireg_data = t5_pm_tx_array[i][1];
2107 pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
2108 pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
2109 t4_read_indirect(padap,
2113 pm_pio->ireg_offset_range,
2114 pm_pio->ireg_local_offset);
2117 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2120 int cudbg_collect_tid(struct cudbg_init *pdbg_init,
2121 struct cudbg_buffer *dbg_buff,
2122 struct cudbg_error *cudbg_err)
2124 struct adapter *padap = pdbg_init->adap;
2125 struct cudbg_tid_info_region_rev1 *tid1;
2126 struct cudbg_buffer temp_buff = { 0 };
2127 struct cudbg_tid_info_region *tid;
2128 u32 para[2], val[2];
2131 rc = cudbg_get_buff(pdbg_init, dbg_buff,
2132 sizeof(struct cudbg_tid_info_region_rev1),
2137 tid1 = (struct cudbg_tid_info_region_rev1 *)temp_buff.data;
2139 tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
2140 tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
2141 tid1->ver_hdr.size = sizeof(struct cudbg_tid_info_region_rev1) -
2142 sizeof(struct cudbg_ver_hdr);
2144 /* If firmware is not attached/alive, use backdoor register
2145 * access to collect dump.
2147 if (!is_fw_attached(pdbg_init))
2150 #define FW_PARAM_PFVF_A(param) \
2151 (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
2152 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param) | \
2153 FW_PARAMS_PARAM_Y_V(0) | \
2154 FW_PARAMS_PARAM_Z_V(0))
2156 para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
2157 para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
2158 rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2, para, val);
2160 cudbg_err->sys_err = rc;
2161 cudbg_put_buff(pdbg_init, &temp_buff);
2164 tid->uotid_base = val[0];
2165 tid->nuotids = val[1] - val[0] + 1;
2167 if (is_t5(padap->params.chip)) {
2168 tid->sb = t4_read_reg(padap, LE_DB_SERVER_INDEX_A) / 4;
2169 } else if (is_t6(padap->params.chip)) {
2171 t4_read_reg(padap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
2172 tid->sb = t4_read_reg(padap, LE_DB_SRVR_START_INDEX_A);
2174 para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
2175 para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
2176 rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2,
2179 cudbg_err->sys_err = rc;
2180 cudbg_put_buff(pdbg_init, &temp_buff);
2183 tid->hpftid_base = val[0];
2184 tid->nhpftids = val[1] - val[0] + 1;
2187 #undef FW_PARAM_PFVF_A
2190 tid->ntids = padap->tids.ntids;
2191 tid->nstids = padap->tids.nstids;
2192 tid->stid_base = padap->tids.stid_base;
2193 tid->hash_base = padap->tids.hash_base;
2195 tid->natids = padap->tids.natids;
2196 tid->nftids = padap->tids.nftids;
2197 tid->ftid_base = padap->tids.ftid_base;
2198 tid->aftid_base = padap->tids.aftid_base;
2199 tid->aftid_end = padap->tids.aftid_end;
2201 tid->sftid_base = padap->tids.sftid_base;
2202 tid->nsftids = padap->tids.nsftids;
2204 tid->flags = padap->flags;
2205 tid->le_db_conf = t4_read_reg(padap, LE_DB_CONFIG_A);
2206 tid->ip_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV4_A);
2207 tid->ipv6_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV6_A);
2209 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2212 int cudbg_collect_pcie_config(struct cudbg_init *pdbg_init,
2213 struct cudbg_buffer *dbg_buff,
2214 struct cudbg_error *cudbg_err)
2216 struct adapter *padap = pdbg_init->adap;
2217 struct cudbg_buffer temp_buff = { 0 };
2218 u32 size, *value, j;
2221 size = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
2222 n = sizeof(t5_pcie_config_array) / (2 * sizeof(u32));
2223 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2227 value = (u32 *)temp_buff.data;
2228 for (i = 0; i < n; i++) {
2229 for (j = t5_pcie_config_array[i][0];
2230 j <= t5_pcie_config_array[i][1]; j += 4) {
2231 t4_hw_pci_read_cfg4(padap, j, value);
2235 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2238 static int cudbg_sge_ctxt_check_valid(u32 *buf, int type)
2240 int index, bit, bit_pos = 0;
2253 index = bit_pos / 32;
2255 return buf[index] & (1U << bit);
2258 static int cudbg_get_ctxt_region_info(struct adapter *padap,
2259 struct cudbg_region_info *ctx_info,
2262 struct cudbg_mem_desc mem_desc;
2263 struct cudbg_meminfo meminfo;
2264 u32 i, j, value, found;
2268 rc = cudbg_fill_meminfo(padap, &meminfo);
2272 /* Get EGRESS and INGRESS context region size */
2273 for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
2275 memset(&mem_desc, 0, sizeof(struct cudbg_mem_desc));
2276 for (j = 0; j < ARRAY_SIZE(meminfo.avail); j++) {
2277 rc = cudbg_get_mem_region(padap, &meminfo, j,
2282 rc = cudbg_get_mem_relative(padap, &meminfo, j,
2286 ctx_info[i].exist = false;
2289 ctx_info[i].exist = true;
2290 ctx_info[i].start = mem_desc.base;
2291 ctx_info[i].end = mem_desc.limit;
2297 ctx_info[i].exist = false;
2300 /* Get FLM and CNM max qid. */
2301 value = t4_read_reg(padap, SGE_FLM_CFG_A);
2303 /* Get number of data freelist queues */
2304 flq = HDRSTARTFLQ_G(value);
2305 ctx_info[CTXT_FLM].exist = true;
2306 ctx_info[CTXT_FLM].end = (CUDBG_MAX_FL_QIDS >> flq) * SGE_CTXT_SIZE;
2308 /* The number of CONM contexts are same as number of freelist
2311 ctx_info[CTXT_CNM].exist = true;
2312 ctx_info[CTXT_CNM].end = ctx_info[CTXT_FLM].end;
2317 int cudbg_dump_context_size(struct adapter *padap)
2319 struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
2320 u8 mem_type[CTXT_INGRESS + 1] = { 0 };
2324 /* Get max valid qid for each type of queue */
2325 rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
2329 for (i = 0; i < CTXT_CNM; i++) {
2330 if (!region_info[i].exist) {
2331 if (i == CTXT_EGRESS || i == CTXT_INGRESS)
2332 size += CUDBG_LOWMEM_MAX_CTXT_QIDS *
2337 size += (region_info[i].end - region_info[i].start + 1) /
2340 return size * sizeof(struct cudbg_ch_cntxt);
2343 static void cudbg_read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
2344 enum ctxt_type ctype, u32 *data)
2346 struct adapter *padap = pdbg_init->adap;
2349 /* Under heavy traffic, the SGE Queue contexts registers will be
2350 * frequently accessed by firmware.
2352 * To avoid conflicts with firmware, always ask firmware to fetch
2353 * the SGE Queue contexts via mailbox. On failure, fallback to
2354 * accessing hardware registers directly.
2356 if (is_fw_attached(pdbg_init))
2357 rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype, data);
2359 t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
2362 static void cudbg_get_sge_ctxt_fw(struct cudbg_init *pdbg_init, u32 max_qid,
2364 struct cudbg_ch_cntxt **out_buff)
2366 struct cudbg_ch_cntxt *buff = *out_buff;
2370 for (j = 0; j < max_qid; j++) {
2371 cudbg_read_sge_ctxt(pdbg_init, j, ctxt_type, buff->data);
2372 rc = cudbg_sge_ctxt_check_valid(buff->data, ctxt_type);
2376 buff->cntxt_type = ctxt_type;
2379 if (ctxt_type == CTXT_FLM) {
2380 cudbg_read_sge_ctxt(pdbg_init, j, CTXT_CNM, buff->data);
2381 buff->cntxt_type = CTXT_CNM;
2390 int cudbg_collect_dump_context(struct cudbg_init *pdbg_init,
2391 struct cudbg_buffer *dbg_buff,
2392 struct cudbg_error *cudbg_err)
2394 struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
2395 struct adapter *padap = pdbg_init->adap;
2396 u32 j, size, max_ctx_size, max_ctx_qid;
2397 u8 mem_type[CTXT_INGRESS + 1] = { 0 };
2398 struct cudbg_buffer temp_buff = { 0 };
2399 struct cudbg_ch_cntxt *buff;
2404 /* Get max valid qid for each type of queue */
2405 rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
2409 rc = cudbg_dump_context_size(padap);
2411 return CUDBG_STATUS_ENTITY_NOT_FOUND;
2414 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2418 /* Get buffer with enough space to read the biggest context
2421 max_ctx_size = max(region_info[CTXT_EGRESS].end -
2422 region_info[CTXT_EGRESS].start + 1,
2423 region_info[CTXT_INGRESS].end -
2424 region_info[CTXT_INGRESS].start + 1);
2426 ctx_buf = kvzalloc(max_ctx_size, GFP_KERNEL);
2428 cudbg_put_buff(pdbg_init, &temp_buff);
2432 buff = (struct cudbg_ch_cntxt *)temp_buff.data;
2434 /* Collect EGRESS and INGRESS context data.
2435 * In case of failures, fallback to collecting via FW or
2438 for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
2439 if (!region_info[i].exist) {
2440 max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
2441 cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
2446 max_ctx_size = region_info[i].end - region_info[i].start + 1;
2447 max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
2449 /* If firmware is not attached/alive, use backdoor register
2450 * access to collect dump.
2452 if (is_fw_attached(pdbg_init)) {
2453 t4_sge_ctxt_flush(padap, padap->mbox, i);
2455 rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type[i],
2456 region_info[i].start, max_ctx_size,
2457 (__be32 *)ctx_buf, 1);
2460 if (rc || !is_fw_attached(pdbg_init)) {
2461 max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
2462 cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
2467 for (j = 0; j < max_ctx_qid; j++) {
2471 src_off = (u64 *)(ctx_buf + j * SGE_CTXT_SIZE);
2472 dst_off = (__be64 *)buff->data;
2474 /* The data is stored in 64-bit cpu order. Convert it
2475 * to big endian before parsing.
2477 for (k = 0; k < SGE_CTXT_SIZE / sizeof(u64); k++)
2478 dst_off[k] = cpu_to_be64(src_off[k]);
2480 rc = cudbg_sge_ctxt_check_valid(buff->data, i);
2484 buff->cntxt_type = i;
2492 /* Collect FREELIST and CONGESTION MANAGER contexts */
2493 max_ctx_size = region_info[CTXT_FLM].end -
2494 region_info[CTXT_FLM].start + 1;
2495 max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
2496 /* Since FLM and CONM are 1-to-1 mapped, the below function
2497 * will fetch both FLM and CONM contexts.
2499 cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, CTXT_FLM, &buff);
2501 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2504 static inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
2507 y = (__force u64)cpu_to_be64(y);
2508 memcpy(addr, (char *)&y + 2, ETH_ALEN);
2511 static void cudbg_mps_rpl_backdoor(struct adapter *padap,
2512 struct fw_ldst_mps_rplc *mps_rplc)
2514 if (is_t5(padap->params.chip)) {
2515 mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
2516 MPS_VF_RPLCT_MAP3_A));
2517 mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
2518 MPS_VF_RPLCT_MAP2_A));
2519 mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
2520 MPS_VF_RPLCT_MAP1_A));
2521 mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
2522 MPS_VF_RPLCT_MAP0_A));
2524 mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
2525 MPS_VF_RPLCT_MAP7_A));
2526 mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
2527 MPS_VF_RPLCT_MAP6_A));
2528 mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
2529 MPS_VF_RPLCT_MAP5_A));
2530 mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
2531 MPS_VF_RPLCT_MAP4_A));
2533 mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP3_A));
2534 mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP2_A));
2535 mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP1_A));
2536 mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP0_A));
2539 static int cudbg_collect_tcam_index(struct cudbg_init *pdbg_init,
2540 struct cudbg_mps_tcam *tcam, u32 idx)
2542 struct adapter *padap = pdbg_init->adap;
2543 u64 tcamy, tcamx, val;
2547 if (CHELSIO_CHIP_VERSION(padap->params.chip) >= CHELSIO_T6) {
2548 /* CtlReqID - 1: use Host Driver Requester ID
2549 * CtlCmdType - 0: Read, 1: Write
2550 * CtlTcamSel - 0: TCAM0, 1: TCAM1
2551 * CtlXYBitSel- 0: Y bit, 1: X bit
2555 ctl = CTLREQID_V(1) | CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
2557 ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
2559 ctl |= CTLTCAMINDEX_V(idx - 256) | CTLTCAMSEL_V(1);
2561 t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
2562 val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
2563 tcamy = DMACH_G(val) << 32;
2564 tcamy |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
2565 data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
2566 tcam->lookup_type = DATALKPTYPE_G(data2);
2568 /* 0 - Outer header, 1 - Inner header
2569 * [71:48] bit locations are overloaded for
2570 * outer vs. inner lookup types.
2572 if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
2573 /* Inner header VNI */
2574 tcam->vniy = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
2575 tcam->vniy = (tcam->vniy << 16) | VIDL_G(val);
2576 tcam->dip_hit = data2 & DATADIPHIT_F;
2578 tcam->vlan_vld = data2 & DATAVIDH2_F;
2579 tcam->ivlan = VIDL_G(val);
2582 tcam->port_num = DATAPORTNUM_G(data2);
2584 /* Read tcamx. Change the control param */
2585 ctl |= CTLXYBITSEL_V(1);
2586 t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
2587 val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
2588 tcamx = DMACH_G(val) << 32;
2589 tcamx |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
2590 data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
2591 if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
2592 /* Inner header VNI mask */
2593 tcam->vnix = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
2594 tcam->vnix = (tcam->vnix << 16) | VIDL_G(val);
2597 tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(idx));
2598 tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(idx));
2601 /* If no entry, return */
2605 tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(idx));
2606 tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(idx));
2608 if (is_t5(padap->params.chip))
2609 tcam->repli = (tcam->cls_lo & REPLICATE_F);
2610 else if (is_t6(padap->params.chip))
2611 tcam->repli = (tcam->cls_lo & T6_REPLICATE_F);
2614 struct fw_ldst_cmd ldst_cmd;
2615 struct fw_ldst_mps_rplc mps_rplc;
2617 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
2618 ldst_cmd.op_to_addrspace =
2619 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
2620 FW_CMD_REQUEST_F | FW_CMD_READ_F |
2621 FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS));
2622 ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
2623 ldst_cmd.u.mps.rplc.fid_idx =
2624 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
2625 FW_LDST_CMD_IDX_V(idx));
2627 /* If firmware is not attached/alive, use backdoor register
2628 * access to collect dump.
2630 if (is_fw_attached(pdbg_init))
2631 rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd,
2632 sizeof(ldst_cmd), &ldst_cmd);
2634 if (rc || !is_fw_attached(pdbg_init)) {
2635 cudbg_mps_rpl_backdoor(padap, &mps_rplc);
2636 /* Ignore error since we collected directly from
2637 * reading registers.
2641 mps_rplc = ldst_cmd.u.mps.rplc;
2644 tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
2645 tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
2646 tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
2647 tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
2648 if (padap->params.arch.mps_rplc_size > CUDBG_MAX_RPLC_SIZE) {
2649 tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
2650 tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
2651 tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
2652 tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
2655 cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
2657 tcam->rplc_size = padap->params.arch.mps_rplc_size;
2661 int cudbg_collect_mps_tcam(struct cudbg_init *pdbg_init,
2662 struct cudbg_buffer *dbg_buff,
2663 struct cudbg_error *cudbg_err)
2665 struct adapter *padap = pdbg_init->adap;
2666 struct cudbg_buffer temp_buff = { 0 };
2667 u32 size = 0, i, n, total_size = 0;
2668 struct cudbg_mps_tcam *tcam;
2671 n = padap->params.arch.mps_tcam_size;
2672 size = sizeof(struct cudbg_mps_tcam) * n;
2673 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2677 tcam = (struct cudbg_mps_tcam *)temp_buff.data;
2678 for (i = 0; i < n; i++) {
2679 rc = cudbg_collect_tcam_index(pdbg_init, tcam, i);
2681 cudbg_err->sys_err = rc;
2682 cudbg_put_buff(pdbg_init, &temp_buff);
2685 total_size += sizeof(struct cudbg_mps_tcam);
2690 rc = CUDBG_SYSTEM_ERROR;
2691 cudbg_err->sys_err = rc;
2692 cudbg_put_buff(pdbg_init, &temp_buff);
2695 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2698 int cudbg_collect_vpd_data(struct cudbg_init *pdbg_init,
2699 struct cudbg_buffer *dbg_buff,
2700 struct cudbg_error *cudbg_err)
2702 struct adapter *padap = pdbg_init->adap;
2703 struct cudbg_buffer temp_buff = { 0 };
2704 char vpd_str[CUDBG_VPD_VER_LEN + 1];
2705 struct cudbg_vpd_data *vpd_data;
2706 struct vpd_params vpd = { 0 };
2707 u32 vpd_vers, fw_vers;
2710 rc = t4_get_raw_vpd_params(padap, &vpd);
2714 rc = t4_get_fw_version(padap, &fw_vers);
2718 rc = cudbg_read_vpd_reg(padap, CUDBG_VPD_VER_ADDR, CUDBG_VPD_VER_LEN,
2723 vpd_str[CUDBG_VPD_VER_LEN] = '\0';
2724 rc = kstrtouint(vpd_str, 0, &vpd_vers);
2728 rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_vpd_data),
2733 vpd_data = (struct cudbg_vpd_data *)temp_buff.data;
2734 memcpy(vpd_data->sn, vpd.sn, SERNUM_LEN + 1);
2735 memcpy(vpd_data->bn, vpd.pn, PN_LEN + 1);
2736 memcpy(vpd_data->na, vpd.na, MACADDR_LEN + 1);
2737 memcpy(vpd_data->mn, vpd.id, ID_LEN + 1);
2738 vpd_data->scfg_vers = t4_read_reg(padap, PCIE_STATIC_SPARE2_A);
2739 vpd_data->vpd_vers = vpd_vers;
2740 vpd_data->fw_major = FW_HDR_FW_VER_MAJOR_G(fw_vers);
2741 vpd_data->fw_minor = FW_HDR_FW_VER_MINOR_G(fw_vers);
2742 vpd_data->fw_micro = FW_HDR_FW_VER_MICRO_G(fw_vers);
2743 vpd_data->fw_build = FW_HDR_FW_VER_BUILD_G(fw_vers);
2744 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2747 static int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
2748 struct cudbg_tid_data *tid_data)
2750 struct adapter *padap = pdbg_init->adap;
2751 int i, cmd_retry = 8;
2754 /* Fill REQ_DATA regs with 0's */
2755 for (i = 0; i < NUM_LE_DB_DBGI_REQ_DATA_INSTANCES; i++)
2756 t4_write_reg(padap, LE_DB_DBGI_REQ_DATA_A + (i << 2), 0);
2758 /* Write DBIG command */
2759 val = DBGICMD_V(4) | DBGITID_V(tid);
2760 t4_write_reg(padap, LE_DB_DBGI_REQ_TCAM_CMD_A, val);
2761 tid_data->dbig_cmd = val;
2763 val = DBGICMDSTRT_F | DBGICMDMODE_V(1); /* LE mode */
2764 t4_write_reg(padap, LE_DB_DBGI_CONFIG_A, val);
2765 tid_data->dbig_conf = val;
2767 /* Poll the DBGICMDBUSY bit */
2770 val = t4_read_reg(padap, LE_DB_DBGI_CONFIG_A);
2771 val = val & DBGICMDBUSY_F;
2774 return CUDBG_SYSTEM_ERROR;
2777 /* Check RESP status */
2778 val = t4_read_reg(padap, LE_DB_DBGI_RSP_STATUS_A);
2779 tid_data->dbig_rsp_stat = val;
2781 return CUDBG_SYSTEM_ERROR;
2783 /* Read RESP data */
2784 for (i = 0; i < NUM_LE_DB_DBGI_RSP_DATA_INSTANCES; i++)
2785 tid_data->data[i] = t4_read_reg(padap,
2786 LE_DB_DBGI_RSP_DATA_A +
2788 tid_data->tid = tid;
2792 static int cudbg_get_le_type(u32 tid, struct cudbg_tcam tcam_region)
2794 int type = LE_ET_UNKNOWN;
2796 if (tid < tcam_region.server_start)
2797 type = LE_ET_TCAM_CON;
2798 else if (tid < tcam_region.filter_start)
2799 type = LE_ET_TCAM_SERVER;
2800 else if (tid < tcam_region.clip_start)
2801 type = LE_ET_TCAM_FILTER;
2802 else if (tid < tcam_region.routing_start)
2803 type = LE_ET_TCAM_CLIP;
2804 else if (tid < tcam_region.tid_hash_base)
2805 type = LE_ET_TCAM_ROUTING;
2806 else if (tid < tcam_region.max_tid)
2807 type = LE_ET_HASH_CON;
2809 type = LE_ET_INVALID_TID;
2814 static int cudbg_is_ipv6_entry(struct cudbg_tid_data *tid_data,
2815 struct cudbg_tcam tcam_region)
2820 le_type = cudbg_get_le_type(tid_data->tid, tcam_region);
2821 if (tid_data->tid & 1)
2824 if (le_type == LE_ET_HASH_CON) {
2825 ipv6 = tid_data->data[16] & 0x8000;
2826 } else if (le_type == LE_ET_TCAM_CON) {
2827 ipv6 = tid_data->data[16] & 0x8000;
2829 ipv6 = tid_data->data[9] == 0x00C00000;
2836 void cudbg_fill_le_tcam_info(struct adapter *padap,
2837 struct cudbg_tcam *tcam_region)
2841 /* Get the LE regions */
2842 value = t4_read_reg(padap, LE_DB_TID_HASHBASE_A); /* hash base index */
2843 tcam_region->tid_hash_base = value;
2845 /* Get routing table index */
2846 value = t4_read_reg(padap, LE_DB_ROUTING_TABLE_INDEX_A);
2847 tcam_region->routing_start = value;
2849 /* Get clip table index. For T6 there is separate CLIP TCAM */
2850 if (is_t6(padap->params.chip))
2851 value = t4_read_reg(padap, LE_DB_CLCAM_TID_BASE_A);
2853 value = t4_read_reg(padap, LE_DB_CLIP_TABLE_INDEX_A);
2854 tcam_region->clip_start = value;
2856 /* Get filter table index */
2857 value = t4_read_reg(padap, LE_DB_FILTER_TABLE_INDEX_A);
2858 tcam_region->filter_start = value;
2860 /* Get server table index */
2861 value = t4_read_reg(padap, LE_DB_SERVER_INDEX_A);
2862 tcam_region->server_start = value;
2864 /* Check whether hash is enabled and calculate the max tids */
2865 value = t4_read_reg(padap, LE_DB_CONFIG_A);
2866 if ((value >> HASHEN_S) & 1) {
2867 value = t4_read_reg(padap, LE_DB_HASH_CONFIG_A);
2868 if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
2869 tcam_region->max_tid = (value & 0xFFFFF) +
2870 tcam_region->tid_hash_base;
2872 value = HASHTIDSIZE_G(value);
2874 tcam_region->max_tid = value +
2875 tcam_region->tid_hash_base;
2877 } else { /* hash not enabled */
2878 if (is_t6(padap->params.chip))
2879 tcam_region->max_tid = (value & ASLIPCOMPEN_F) ?
2880 CUDBG_MAX_TID_COMP_EN :
2881 CUDBG_MAX_TID_COMP_DIS;
2883 tcam_region->max_tid = CUDBG_MAX_TCAM_TID;
2886 if (is_t6(padap->params.chip))
2887 tcam_region->max_tid += CUDBG_T6_CLIP;
2890 int cudbg_collect_le_tcam(struct cudbg_init *pdbg_init,
2891 struct cudbg_buffer *dbg_buff,
2892 struct cudbg_error *cudbg_err)
2894 struct adapter *padap = pdbg_init->adap;
2895 struct cudbg_buffer temp_buff = { 0 };
2896 struct cudbg_tcam tcam_region = { 0 };
2897 struct cudbg_tid_data *tid_data;
2902 cudbg_fill_le_tcam_info(padap, &tcam_region);
2904 size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
2905 size += sizeof(struct cudbg_tcam);
2906 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2910 memcpy(temp_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
2911 bytes = sizeof(struct cudbg_tcam);
2912 tid_data = (struct cudbg_tid_data *)(temp_buff.data + bytes);
2914 for (i = 0; i < tcam_region.max_tid; ) {
2915 rc = cudbg_read_tid(pdbg_init, i, tid_data);
2917 cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
2918 /* Update tcam header and exit */
2919 tcam_region.max_tid = i;
2920 memcpy(temp_buff.data, &tcam_region,
2921 sizeof(struct cudbg_tcam));
2925 if (cudbg_is_ipv6_entry(tid_data, tcam_region)) {
2926 /* T6 CLIP TCAM: ipv6 takes 4 entries */
2927 if (is_t6(padap->params.chip) &&
2928 i >= tcam_region.clip_start &&
2929 i < tcam_region.clip_start + CUDBG_T6_CLIP)
2931 else /* Main TCAM: ipv6 takes two tids */
2938 bytes += sizeof(struct cudbg_tid_data);
2942 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2945 int cudbg_collect_cctrl(struct cudbg_init *pdbg_init,
2946 struct cudbg_buffer *dbg_buff,
2947 struct cudbg_error *cudbg_err)
2949 struct adapter *padap = pdbg_init->adap;
2950 struct cudbg_buffer temp_buff = { 0 };
2954 size = sizeof(u16) * NMTUS * NCCTRL_WIN;
2955 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2959 t4_read_cong_tbl(padap, (void *)temp_buff.data);
2960 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
2963 int cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
2964 struct cudbg_buffer *dbg_buff,
2965 struct cudbg_error *cudbg_err)
2967 struct adapter *padap = pdbg_init->adap;
2968 struct cudbg_buffer temp_buff = { 0 };
2969 struct ireg_buf *ma_indr;
2973 if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
2974 return CUDBG_STATUS_ENTITY_NOT_FOUND;
2976 n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
2977 size = sizeof(struct ireg_buf) * n * 2;
2978 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
2982 ma_indr = (struct ireg_buf *)temp_buff.data;
2983 for (i = 0; i < n; i++) {
2984 struct ireg_field *ma_fli = &ma_indr->tp_pio;
2985 u32 *buff = ma_indr->outbuf;
2987 ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
2988 ma_fli->ireg_data = t6_ma_ireg_array[i][1];
2989 ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
2990 ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
2991 t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
2992 buff, ma_fli->ireg_offset_range,
2993 ma_fli->ireg_local_offset);
2997 n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
2998 for (i = 0; i < n; i++) {
2999 struct ireg_field *ma_fli = &ma_indr->tp_pio;
3000 u32 *buff = ma_indr->outbuf;
3002 ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
3003 ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
3004 ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
3005 for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
3006 t4_read_indirect(padap, ma_fli->ireg_addr,
3007 ma_fli->ireg_data, buff, 1,
3008 ma_fli->ireg_local_offset);
3010 ma_fli->ireg_local_offset += 0x20;
3014 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3017 int cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
3018 struct cudbg_buffer *dbg_buff,
3019 struct cudbg_error *cudbg_err)
3021 struct adapter *padap = pdbg_init->adap;
3022 struct cudbg_buffer temp_buff = { 0 };
3023 struct cudbg_ulptx_la *ulptx_la_buff;
3024 struct cudbg_ver_hdr *ver_hdr;
3028 rc = cudbg_get_buff(pdbg_init, dbg_buff,
3029 sizeof(struct cudbg_ver_hdr) +
3030 sizeof(struct cudbg_ulptx_la),
3035 ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
3036 ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
3037 ver_hdr->revision = CUDBG_ULPTX_LA_REV;
3038 ver_hdr->size = sizeof(struct cudbg_ulptx_la);
3040 ulptx_la_buff = (struct cudbg_ulptx_la *)(temp_buff.data +
3042 for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
3043 ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
3044 ULP_TX_LA_RDPTR_0_A +
3046 ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
3047 ULP_TX_LA_WRPTR_0_A +
3049 ulptx_la_buff->rddata[i] = t4_read_reg(padap,
3050 ULP_TX_LA_RDDATA_0_A +
3052 for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
3053 ulptx_la_buff->rd_data[i][j] =
3055 ULP_TX_LA_RDDATA_0_A + 0x10 * i);
3058 for (i = 0; i < CUDBG_NUM_ULPTX_ASIC_READ; i++) {
3059 t4_write_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A, 0x1);
3060 ulptx_la_buff->rdptr_asic[i] =
3061 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A);
3062 ulptx_la_buff->rddata_asic[i][0] =
3063 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_0_A);
3064 ulptx_la_buff->rddata_asic[i][1] =
3065 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_1_A);
3066 ulptx_la_buff->rddata_asic[i][2] =
3067 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_2_A);
3068 ulptx_la_buff->rddata_asic[i][3] =
3069 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_3_A);
3070 ulptx_la_buff->rddata_asic[i][4] =
3071 t4_read_reg(padap, ULP_TX_ASIC_DEBUG_4_A);
3072 ulptx_la_buff->rddata_asic[i][5] =
3073 t4_read_reg(padap, PM_RX_BASE_ADDR);
3076 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3079 int cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
3080 struct cudbg_buffer *dbg_buff,
3081 struct cudbg_error *cudbg_err)
3083 struct adapter *padap = pdbg_init->adap;
3084 struct cudbg_buffer temp_buff = { 0 };
3085 u32 local_offset, local_range;
3086 struct ireg_buf *up_cim;
3091 if (is_t5(padap->params.chip))
3092 n = sizeof(t5_up_cim_reg_array) /
3093 ((IREG_NUM_ELEM + 1) * sizeof(u32));
3094 else if (is_t6(padap->params.chip))
3095 n = sizeof(t6_up_cim_reg_array) /
3096 ((IREG_NUM_ELEM + 1) * sizeof(u32));
3098 return CUDBG_STATUS_NOT_IMPLEMENTED;
3100 size = sizeof(struct ireg_buf) * n;
3101 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
3105 up_cim = (struct ireg_buf *)temp_buff.data;
3106 for (i = 0; i < n; i++) {
3107 struct ireg_field *up_cim_reg = &up_cim->tp_pio;
3108 u32 *buff = up_cim->outbuf;
3110 if (is_t5(padap->params.chip)) {
3111 up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
3112 up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
3113 up_cim_reg->ireg_local_offset =
3114 t5_up_cim_reg_array[i][2];
3115 up_cim_reg->ireg_offset_range =
3116 t5_up_cim_reg_array[i][3];
3117 instance = t5_up_cim_reg_array[i][4];
3118 } else if (is_t6(padap->params.chip)) {
3119 up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
3120 up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
3121 up_cim_reg->ireg_local_offset =
3122 t6_up_cim_reg_array[i][2];
3123 up_cim_reg->ireg_offset_range =
3124 t6_up_cim_reg_array[i][3];
3125 instance = t6_up_cim_reg_array[i][4];
3129 case NUM_CIM_CTL_TSCH_CHANNEL_INSTANCES:
3130 iter = up_cim_reg->ireg_offset_range;
3131 local_offset = 0x120;
3134 case NUM_CIM_CTL_TSCH_CHANNEL_TSCH_CLASS_INSTANCES:
3135 iter = up_cim_reg->ireg_offset_range;
3136 local_offset = 0x10;
3142 local_range = up_cim_reg->ireg_offset_range;
3146 for (j = 0; j < iter; j++, buff++) {
3147 rc = t4_cim_read(padap,
3148 up_cim_reg->ireg_local_offset +
3149 (j * local_offset), local_range, buff);
3151 cudbg_put_buff(pdbg_init, &temp_buff);
3157 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3160 int cudbg_collect_pbt_tables(struct cudbg_init *pdbg_init,
3161 struct cudbg_buffer *dbg_buff,
3162 struct cudbg_error *cudbg_err)
3164 struct adapter *padap = pdbg_init->adap;
3165 struct cudbg_buffer temp_buff = { 0 };
3166 struct cudbg_pbt_tables *pbt;
3170 rc = cudbg_get_buff(pdbg_init, dbg_buff,
3171 sizeof(struct cudbg_pbt_tables),
3176 pbt = (struct cudbg_pbt_tables *)temp_buff.data;
3177 /* PBT dynamic entries */
3178 addr = CUDBG_CHAC_PBT_ADDR;
3179 for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
3180 rc = t4_cim_read(padap, addr + (i * 4), 1,
3181 &pbt->pbt_dynamic[i]);
3183 cudbg_err->sys_err = rc;
3184 cudbg_put_buff(pdbg_init, &temp_buff);
3189 /* PBT static entries */
3190 /* static entries start when bit 6 is set */
3191 addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
3192 for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
3193 rc = t4_cim_read(padap, addr + (i * 4), 1,
3194 &pbt->pbt_static[i]);
3196 cudbg_err->sys_err = rc;
3197 cudbg_put_buff(pdbg_init, &temp_buff);
3203 addr = CUDBG_CHAC_PBT_LRF;
3204 for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
3205 rc = t4_cim_read(padap, addr + (i * 4), 1,
3206 &pbt->lrf_table[i]);
3208 cudbg_err->sys_err = rc;
3209 cudbg_put_buff(pdbg_init, &temp_buff);
3214 /* PBT data entries */
3215 addr = CUDBG_CHAC_PBT_DATA;
3216 for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
3217 rc = t4_cim_read(padap, addr + (i * 4), 1,
3220 cudbg_err->sys_err = rc;
3221 cudbg_put_buff(pdbg_init, &temp_buff);
3225 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3228 int cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
3229 struct cudbg_buffer *dbg_buff,
3230 struct cudbg_error *cudbg_err)
3232 struct adapter *padap = pdbg_init->adap;
3233 struct cudbg_mbox_log *mboxlog = NULL;
3234 struct cudbg_buffer temp_buff = { 0 };
3235 struct mbox_cmd_log *log = NULL;
3236 struct mbox_cmd *entry;
3237 unsigned int entry_idx;
3243 log = padap->mbox_log;
3244 mbox_cmds = padap->mbox_log->size;
3245 size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
3246 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
3250 mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
3251 for (k = 0; k < mbox_cmds; k++) {
3252 entry_idx = log->cursor + k;
3253 if (entry_idx >= log->size)
3254 entry_idx -= log->size;
3256 entry = mbox_cmd_log_entry(log, entry_idx);
3257 /* skip over unused entries */
3258 if (entry->timestamp == 0)
3261 memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
3262 for (i = 0; i < MBOX_LEN / 8; i++) {
3263 flit = entry->cmd[i];
3264 mboxlog->hi[i] = (u32)(flit >> 32);
3265 mboxlog->lo[i] = (u32)flit;
3269 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3272 int cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
3273 struct cudbg_buffer *dbg_buff,
3274 struct cudbg_error *cudbg_err)
3276 struct adapter *padap = pdbg_init->adap;
3277 struct cudbg_buffer temp_buff = { 0 };
3278 struct ireg_buf *hma_indr;
3282 if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
3283 return CUDBG_STATUS_ENTITY_NOT_FOUND;
3285 n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
3286 size = sizeof(struct ireg_buf) * n;
3287 rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
3291 hma_indr = (struct ireg_buf *)temp_buff.data;
3292 for (i = 0; i < n; i++) {
3293 struct ireg_field *hma_fli = &hma_indr->tp_pio;
3294 u32 *buff = hma_indr->outbuf;
3296 hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
3297 hma_fli->ireg_data = t6_hma_ireg_array[i][1];
3298 hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
3299 hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
3300 t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
3301 buff, hma_fli->ireg_offset_range,
3302 hma_fli->ireg_local_offset);
3305 return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
3308 void cudbg_fill_qdesc_num_and_size(const struct adapter *padap,
3309 u32 *num, u32 *size)
3311 u32 tot_entries = 0, tot_size = 0;
3313 /* NIC TXQ, RXQ, FLQ, and CTRLQ */
3314 tot_entries += MAX_ETH_QSETS * 3;
3315 tot_entries += MAX_CTRL_QUEUES;
3317 tot_size += MAX_ETH_QSETS * MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
3318 tot_size += MAX_ETH_QSETS * MAX_RSPQ_ENTRIES * MAX_RXQ_DESC_SIZE;
3319 tot_size += MAX_ETH_QSETS * MAX_RX_BUFFERS * MAX_FL_DESC_SIZE;
3320 tot_size += MAX_CTRL_QUEUES * MAX_CTRL_TXQ_ENTRIES *
3321 MAX_CTRL_TXQ_DESC_SIZE;
3323 /* FW_EVTQ and INTRQ */
3324 tot_entries += INGQ_EXTRAS;
3325 tot_size += INGQ_EXTRAS * MAX_RSPQ_ENTRIES * MAX_RXQ_DESC_SIZE;
3329 tot_size += MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
3331 /* ULD TXQ, RXQ, and FLQ */
3332 tot_entries += CXGB4_TX_MAX * MAX_OFLD_QSETS;
3333 tot_entries += CXGB4_ULD_MAX * MAX_ULD_QSETS * 2;
3335 tot_size += CXGB4_TX_MAX * MAX_OFLD_QSETS * MAX_TXQ_ENTRIES *
3337 tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * MAX_RSPQ_ENTRIES *
3339 tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * MAX_RX_BUFFERS *
3343 tot_entries += CXGB4_ULD_MAX * MAX_ULD_QSETS;
3344 tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * SGE_MAX_IQ_SIZE *
3347 /* ETHOFLD TXQ, RXQ, and FLQ */
3348 tot_entries += MAX_OFLD_QSETS * 3;
3349 tot_size += MAX_OFLD_QSETS * MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
3351 tot_size += sizeof(struct cudbg_ver_hdr) +
3352 sizeof(struct cudbg_qdesc_info) +
3353 sizeof(struct cudbg_qdesc_entry) * tot_entries;
3362 int cudbg_collect_qdesc(struct cudbg_init *pdbg_init,
3363 struct cudbg_buffer *dbg_buff,
3364 struct cudbg_error *cudbg_err)
3366 u32 num_queues = 0, tot_entries = 0, size = 0;
3367 struct adapter *padap = pdbg_init->adap;
3368 struct cudbg_buffer temp_buff = { 0 };
3369 struct cudbg_qdesc_entry *qdesc_entry;
3370 struct cudbg_qdesc_info *qdesc_info;
3371 struct cudbg_ver_hdr *ver_hdr;
3372 struct sge *s = &padap->sge;
3373 u32 i, j, cur_off, tot_len;
3377 cudbg_fill_qdesc_num_and_size(padap, &tot_entries, &size);
3378 size = min_t(u32, size, CUDBG_DUMP_BUFF_SIZE);
3380 data = kvzalloc(size, GFP_KERNEL);
3384 ver_hdr = (struct cudbg_ver_hdr *)data;
3385 ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
3386 ver_hdr->revision = CUDBG_QDESC_REV;
3387 ver_hdr->size = sizeof(struct cudbg_qdesc_info);
3388 size -= sizeof(*ver_hdr);
3390 qdesc_info = (struct cudbg_qdesc_info *)(data +
3392 size -= sizeof(*qdesc_info);
3393 qdesc_entry = (struct cudbg_qdesc_entry *)qdesc_info->data;
3395 #define QDESC_GET(q, desc, type, label) do { \
3400 cudbg_fill_qdesc_##q(q, type, qdesc_entry); \
3401 size -= sizeof(*qdesc_entry) + qdesc_entry->data_size; \
3403 qdesc_entry = cudbg_next_qdesc(qdesc_entry); \
3407 #define QDESC_GET_TXQ(q, type, label) do { \
3408 struct sge_txq *txq = (struct sge_txq *)q; \
3409 QDESC_GET(txq, txq->desc, type, label); \
3412 #define QDESC_GET_RXQ(q, type, label) do { \
3413 struct sge_rspq *rxq = (struct sge_rspq *)q; \
3414 QDESC_GET(rxq, rxq->desc, type, label); \
3417 #define QDESC_GET_FLQ(q, type, label) do { \
3418 struct sge_fl *flq = (struct sge_fl *)q; \
3419 QDESC_GET(flq, flq->desc, type, label); \
3423 for (i = 0; i < s->ethqsets; i++)
3424 QDESC_GET_TXQ(&s->ethtxq[i].q, CUDBG_QTYPE_NIC_TXQ, out);
3427 for (i = 0; i < s->ethqsets; i++)
3428 QDESC_GET_RXQ(&s->ethrxq[i].rspq, CUDBG_QTYPE_NIC_RXQ, out);
3431 for (i = 0; i < s->ethqsets; i++)
3432 QDESC_GET_FLQ(&s->ethrxq[i].fl, CUDBG_QTYPE_NIC_FLQ, out);
3435 for (i = 0; i < padap->params.nports; i++)
3436 QDESC_GET_TXQ(&s->ctrlq[i].q, CUDBG_QTYPE_CTRLQ, out);
3439 QDESC_GET_RXQ(&s->fw_evtq, CUDBG_QTYPE_FWEVTQ, out);
3442 QDESC_GET_RXQ(&s->intrq, CUDBG_QTYPE_INTRQ, out);
3445 QDESC_GET_TXQ(&s->ptptxq.q, CUDBG_QTYPE_PTP_TXQ, out);
3448 mutex_lock(&uld_mutex);
3450 if (s->uld_txq_info) {
3451 struct sge_uld_txq_info *utxq;
3454 for (j = 0; j < CXGB4_TX_MAX; j++) {
3455 if (!s->uld_txq_info[j])
3458 utxq = s->uld_txq_info[j];
3459 for (i = 0; i < utxq->ntxq; i++)
3460 QDESC_GET_TXQ(&utxq->uldtxq[i].q,
3461 cudbg_uld_txq_to_qtype(j),
3466 if (s->uld_rxq_info) {
3467 struct sge_uld_rxq_info *urxq;
3471 for (j = 0; j < CXGB4_ULD_MAX; j++) {
3472 if (!s->uld_rxq_info[j])
3475 urxq = s->uld_rxq_info[j];
3476 for (i = 0; i < urxq->nrxq; i++)
3477 QDESC_GET_RXQ(&urxq->uldrxq[i].rspq,
3478 cudbg_uld_rxq_to_qtype(j),
3483 for (j = 0; j < CXGB4_ULD_MAX; j++) {
3484 if (!s->uld_rxq_info[j])
3487 urxq = s->uld_rxq_info[j];
3488 for (i = 0; i < urxq->nrxq; i++)
3489 QDESC_GET_FLQ(&urxq->uldrxq[i].fl,
3490 cudbg_uld_flq_to_qtype(j),
3495 for (j = 0; j < CXGB4_ULD_MAX; j++) {
3496 if (!s->uld_rxq_info[j])
3499 urxq = s->uld_rxq_info[j];
3501 for (i = 0; i < urxq->nciq; i++)
3502 QDESC_GET_RXQ(&urxq->uldrxq[base + i].rspq,
3503 cudbg_uld_ciq_to_qtype(j),
3507 mutex_unlock(&uld_mutex);
3509 if (!padap->tc_mqprio)
3512 mutex_lock(&padap->tc_mqprio->mqprio_mutex);
3515 for (i = 0; i < s->eoqsets; i++)
3516 QDESC_GET_TXQ(&s->eohw_txq[i].q,
3517 CUDBG_QTYPE_ETHOFLD_TXQ, out_unlock_mqprio);
3519 /* ETHOFLD RXQ and FLQ */
3521 for (i = 0; i < s->eoqsets; i++)
3522 QDESC_GET_RXQ(&s->eohw_rxq[i].rspq,
3523 CUDBG_QTYPE_ETHOFLD_RXQ, out_unlock_mqprio);
3525 for (i = 0; i < s->eoqsets; i++)
3526 QDESC_GET_FLQ(&s->eohw_rxq[i].fl,
3527 CUDBG_QTYPE_ETHOFLD_FLQ, out_unlock_mqprio);
3531 mutex_unlock(&padap->tc_mqprio->mqprio_mutex);
3534 qdesc_info->qdesc_entry_size = sizeof(*qdesc_entry);
3535 qdesc_info->num_queues = num_queues;
3538 u32 chunk_size = min_t(u32, tot_len, CUDBG_CHUNK_SIZE);
3540 rc = cudbg_get_buff(pdbg_init, dbg_buff, chunk_size,
3543 cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
3547 memcpy(temp_buff.data, data + cur_off, chunk_size);
3548 tot_len -= chunk_size;
3549 cur_off += chunk_size;
3550 rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
3553 cudbg_put_buff(pdbg_init, &temp_buff);
3554 cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
3562 #undef QDESC_GET_FLQ
3563 #undef QDESC_GET_RXQ
3564 #undef QDESC_GET_TXQ
3570 mutex_unlock(&uld_mutex);
3574 int cudbg_collect_flash(struct cudbg_init *pdbg_init,
3575 struct cudbg_buffer *dbg_buff,
3576 struct cudbg_error *cudbg_err)
3578 struct adapter *padap = pdbg_init->adap;
3579 u32 count = padap->params.sf_size, n;
3580 struct cudbg_buffer temp_buff = {0};
3584 addr = FLASH_EXP_ROM_START;
3586 for (i = 0; i < count; i += SF_PAGE_SIZE) {
3587 n = min_t(u32, count - i, SF_PAGE_SIZE);
3589 rc = cudbg_get_buff(pdbg_init, dbg_buff, n, &temp_buff);
3591 cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
3594 rc = t4_read_flash(padap, addr, n, (u32 *)temp_buff.data, 0);
3599 rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
3602 cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;