162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/sort.h>
762306a36Sopenharmony_ci#include <linux/string.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "t4_regs.h"
1062306a36Sopenharmony_ci#include "cxgb4.h"
1162306a36Sopenharmony_ci#include "cxgb4_cudbg.h"
1262306a36Sopenharmony_ci#include "cudbg_if.h"
1362306a36Sopenharmony_ci#include "cudbg_lib_common.h"
1462306a36Sopenharmony_ci#include "cudbg_entity.h"
1562306a36Sopenharmony_ci#include "cudbg_lib.h"
1662306a36Sopenharmony_ci#include "cudbg_zlib.h"
1762306a36Sopenharmony_ci#include "cxgb4_tc_mqprio.h"
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistatic const u32 t6_tp_pio_array[][IREG_NUM_ELEM] = {
2062306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x020, 28}, /* t6_tp_pio_regs_20_to_3b */
2162306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x040, 10}, /* t6_tp_pio_regs_40_to_49 */
2262306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x050, 10}, /* t6_tp_pio_regs_50_to_59 */
2362306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x060, 14}, /* t6_tp_pio_regs_60_to_6d */
2462306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x06F, 1}, /* t6_tp_pio_regs_6f */
2562306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x070, 6}, /* t6_tp_pio_regs_70_to_75 */
2662306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x130, 18}, /* t6_tp_pio_regs_130_to_141 */
2762306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x145, 19}, /* t6_tp_pio_regs_145_to_157 */
2862306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x160, 1}, /* t6_tp_pio_regs_160 */
2962306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x230, 25}, /* t6_tp_pio_regs_230_to_248 */
3062306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x24a, 3}, /* t6_tp_pio_regs_24c */
3162306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x8C0, 1} /* t6_tp_pio_regs_8c0 */
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistatic const u32 t5_tp_pio_array[][IREG_NUM_ELEM] = {
3562306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x020, 28}, /* t5_tp_pio_regs_20_to_3b */
3662306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x040, 19}, /* t5_tp_pio_regs_40_to_52 */
3762306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x054, 2}, /* t5_tp_pio_regs_54_to_55 */
3862306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x060, 13}, /* t5_tp_pio_regs_60_to_6c */
3962306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x06F, 1}, /* t5_tp_pio_regs_6f */
4062306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x120, 4}, /* t5_tp_pio_regs_120_to_123 */
4162306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x12b, 2}, /* t5_tp_pio_regs_12b_to_12c */
4262306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x12f, 21}, /* t5_tp_pio_regs_12f_to_143 */
4362306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x145, 19}, /* t5_tp_pio_regs_145_to_157 */
4462306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x230, 25}, /* t5_tp_pio_regs_230_to_248 */
4562306a36Sopenharmony_ci	{0x7e40, 0x7e44, 0x8C0, 1} /* t5_tp_pio_regs_8c0 */
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistatic const u32 t6_tp_tm_pio_array[][IREG_NUM_ELEM] = {
4962306a36Sopenharmony_ci	{0x7e18, 0x7e1c, 0x0, 12}
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistatic const u32 t5_tp_tm_pio_array[][IREG_NUM_ELEM] = {
5362306a36Sopenharmony_ci	{0x7e18, 0x7e1c, 0x0, 12}
5462306a36Sopenharmony_ci};
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistatic const u32 t6_tp_mib_index_array[6][IREG_NUM_ELEM] = {
5762306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x0, 13},
5862306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x10, 6},
5962306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x18, 21},
6062306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x30, 32},
6162306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x50, 22},
6262306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x68, 12}
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic const u32 t5_tp_mib_index_array[9][IREG_NUM_ELEM] = {
6662306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x0, 13},
6762306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x10, 6},
6862306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x18, 8},
6962306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x20, 13},
7062306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x30, 16},
7162306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x40, 16},
7262306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x50, 16},
7362306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x60, 6},
7462306a36Sopenharmony_ci	{0x7e50, 0x7e54, 0x68, 4}
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistatic const u32 t5_sge_dbg_index_array[2][IREG_NUM_ELEM] = {
7862306a36Sopenharmony_ci	{0x10cc, 0x10d0, 0x0, 16},
7962306a36Sopenharmony_ci	{0x10cc, 0x10d4, 0x0, 16},
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistatic const u32 t6_sge_qbase_index_array[] = {
8362306a36Sopenharmony_ci	/* 1 addr reg SGE_QBASE_INDEX and 4 data reg SGE_QBASE_MAP[0-3] */
8462306a36Sopenharmony_ci	0x1250, 0x1240, 0x1244, 0x1248, 0x124c,
8562306a36Sopenharmony_ci};
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cistatic const u32 t5_pcie_pdbg_array[][IREG_NUM_ELEM] = {
8862306a36Sopenharmony_ci	{0x5a04, 0x5a0c, 0x00, 0x20}, /* t5_pcie_pdbg_regs_00_to_20 */
8962306a36Sopenharmony_ci	{0x5a04, 0x5a0c, 0x21, 0x20}, /* t5_pcie_pdbg_regs_21_to_40 */
9062306a36Sopenharmony_ci	{0x5a04, 0x5a0c, 0x41, 0x10}, /* t5_pcie_pdbg_regs_41_to_50 */
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistatic const u32 t5_pcie_cdbg_array[][IREG_NUM_ELEM] = {
9462306a36Sopenharmony_ci	{0x5a10, 0x5a18, 0x00, 0x20}, /* t5_pcie_cdbg_regs_00_to_20 */
9562306a36Sopenharmony_ci	{0x5a10, 0x5a18, 0x21, 0x18}, /* t5_pcie_cdbg_regs_21_to_37 */
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_cistatic const u32 t5_pm_rx_array[][IREG_NUM_ELEM] = {
9962306a36Sopenharmony_ci	{0x8FD0, 0x8FD4, 0x10000, 0x20}, /* t5_pm_rx_regs_10000_to_10020 */
10062306a36Sopenharmony_ci	{0x8FD0, 0x8FD4, 0x10021, 0x0D}, /* t5_pm_rx_regs_10021_to_1002c */
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_cistatic const u32 t5_pm_tx_array[][IREG_NUM_ELEM] = {
10462306a36Sopenharmony_ci	{0x8FF0, 0x8FF4, 0x10000, 0x20}, /* t5_pm_tx_regs_10000_to_10020 */
10562306a36Sopenharmony_ci	{0x8FF0, 0x8FF4, 0x10021, 0x1D}, /* t5_pm_tx_regs_10021_to_1003c */
10662306a36Sopenharmony_ci};
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cistatic const u32 t5_pcie_config_array[][2] = {
10962306a36Sopenharmony_ci	{0x0, 0x34},
11062306a36Sopenharmony_ci	{0x3c, 0x40},
11162306a36Sopenharmony_ci	{0x50, 0x64},
11262306a36Sopenharmony_ci	{0x70, 0x80},
11362306a36Sopenharmony_ci	{0x94, 0xa0},
11462306a36Sopenharmony_ci	{0xb0, 0xb8},
11562306a36Sopenharmony_ci	{0xd0, 0xd4},
11662306a36Sopenharmony_ci	{0x100, 0x128},
11762306a36Sopenharmony_ci	{0x140, 0x148},
11862306a36Sopenharmony_ci	{0x150, 0x164},
11962306a36Sopenharmony_ci	{0x170, 0x178},
12062306a36Sopenharmony_ci	{0x180, 0x194},
12162306a36Sopenharmony_ci	{0x1a0, 0x1b8},
12262306a36Sopenharmony_ci	{0x1c0, 0x208},
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistatic const u32 t6_ma_ireg_array[][IREG_NUM_ELEM] = {
12662306a36Sopenharmony_ci	{0x78f8, 0x78fc, 0xa000, 23}, /* t6_ma_regs_a000_to_a016 */
12762306a36Sopenharmony_ci	{0x78f8, 0x78fc, 0xa400, 30}, /* t6_ma_regs_a400_to_a41e */
12862306a36Sopenharmony_ci	{0x78f8, 0x78fc, 0xa800, 20} /* t6_ma_regs_a800_to_a813 */
12962306a36Sopenharmony_ci};
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cistatic const u32 t6_ma_ireg_array2[][IREG_NUM_ELEM] = {
13262306a36Sopenharmony_ci	{0x78f8, 0x78fc, 0xe400, 17}, /* t6_ma_regs_e400_to_e600 */
13362306a36Sopenharmony_ci	{0x78f8, 0x78fc, 0xe640, 13} /* t6_ma_regs_e640_to_e7c0 */
13462306a36Sopenharmony_ci};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cistatic const u32 t6_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
13762306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x2000, 0x20, 0}, /* up_cim_2000_to_207c */
13862306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x2080, 0x1d, 0}, /* up_cim_2080_to_20fc */
13962306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x00, 0x20, 0}, /* up_cim_00_to_7c */
14062306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x80, 0x20, 0}, /* up_cim_80_to_fc */
14162306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x100, 0x11, 0}, /* up_cim_100_to_14c */
14262306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x200, 0x10, 0}, /* up_cim_200_to_23c */
14362306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x240, 0x2, 0}, /* up_cim_240_to_244 */
14462306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x250, 0x2, 0}, /* up_cim_250_to_254 */
14562306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x260, 0x2, 0}, /* up_cim_260_to_264 */
14662306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x270, 0x2, 0}, /* up_cim_270_to_274 */
14762306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
14862306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
14962306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
15062306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4900, 0x4, 0x4}, /* up_cim_4900_to_4c60 */
15162306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4904, 0x4, 0x4}, /* up_cim_4904_to_4c64 */
15262306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4908, 0x4, 0x4}, /* up_cim_4908_to_4c68 */
15362306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4910, 0x4, 0x4}, /* up_cim_4910_to_4c70 */
15462306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4914, 0x4, 0x4}, /* up_cim_4914_to_4c74 */
15562306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4920, 0x10, 0x10}, /* up_cim_4920_to_4a10 */
15662306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4924, 0x10, 0x10}, /* up_cim_4924_to_4a14 */
15762306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x4928, 0x10, 0x10}, /* up_cim_4928_to_4a18 */
15862306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x492c, 0x10, 0x10}, /* up_cim_492c_to_4a1c */
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistatic const u32 t5_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
16262306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x2000, 0x20, 0}, /* up_cim_2000_to_207c */
16362306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x2080, 0x19, 0}, /* up_cim_2080_to_20ec */
16462306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x00, 0x20, 0}, /* up_cim_00_to_7c */
16562306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x80, 0x20, 0}, /* up_cim_80_to_fc */
16662306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x100, 0x11, 0}, /* up_cim_100_to_14c */
16762306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x200, 0x10, 0}, /* up_cim_200_to_23c */
16862306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x240, 0x2, 0}, /* up_cim_240_to_244 */
16962306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x250, 0x2, 0}, /* up_cim_250_to_254 */
17062306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x260, 0x2, 0}, /* up_cim_260_to_264 */
17162306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x270, 0x2, 0}, /* up_cim_270_to_274 */
17262306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
17362306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
17462306a36Sopenharmony_ci	{0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
17562306a36Sopenharmony_ci};
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cistatic const u32 t6_hma_ireg_array[][IREG_NUM_ELEM] = {
17862306a36Sopenharmony_ci	{0x51320, 0x51324, 0xa000, 32} /* t6_hma_regs_a000_to_a01f */
17962306a36Sopenharmony_ci};
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ciu32 cudbg_get_entity_length(struct adapter *adap, u32 entity)
18262306a36Sopenharmony_ci{
18362306a36Sopenharmony_ci	struct cudbg_tcam tcam_region = { 0 };
18462306a36Sopenharmony_ci	u32 value, n = 0, len = 0;
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci	switch (entity) {
18762306a36Sopenharmony_ci	case CUDBG_REG_DUMP:
18862306a36Sopenharmony_ci		switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
18962306a36Sopenharmony_ci		case CHELSIO_T4:
19062306a36Sopenharmony_ci			len = T4_REGMAP_SIZE;
19162306a36Sopenharmony_ci			break;
19262306a36Sopenharmony_ci		case CHELSIO_T5:
19362306a36Sopenharmony_ci		case CHELSIO_T6:
19462306a36Sopenharmony_ci			len = T5_REGMAP_SIZE;
19562306a36Sopenharmony_ci			break;
19662306a36Sopenharmony_ci		default:
19762306a36Sopenharmony_ci			break;
19862306a36Sopenharmony_ci		}
19962306a36Sopenharmony_ci		break;
20062306a36Sopenharmony_ci	case CUDBG_DEV_LOG:
20162306a36Sopenharmony_ci		len = adap->params.devlog.size;
20262306a36Sopenharmony_ci		break;
20362306a36Sopenharmony_ci	case CUDBG_CIM_LA:
20462306a36Sopenharmony_ci		if (is_t6(adap->params.chip)) {
20562306a36Sopenharmony_ci			len = adap->params.cim_la_size / 10 + 1;
20662306a36Sopenharmony_ci			len *= 10 * sizeof(u32);
20762306a36Sopenharmony_ci		} else {
20862306a36Sopenharmony_ci			len = adap->params.cim_la_size / 8;
20962306a36Sopenharmony_ci			len *= 8 * sizeof(u32);
21062306a36Sopenharmony_ci		}
21162306a36Sopenharmony_ci		len += sizeof(u32); /* for reading CIM LA configuration */
21262306a36Sopenharmony_ci		break;
21362306a36Sopenharmony_ci	case CUDBG_CIM_MA_LA:
21462306a36Sopenharmony_ci		len = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
21562306a36Sopenharmony_ci		break;
21662306a36Sopenharmony_ci	case CUDBG_CIM_QCFG:
21762306a36Sopenharmony_ci		len = sizeof(struct cudbg_cim_qcfg);
21862306a36Sopenharmony_ci		break;
21962306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_TP0:
22062306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_TP1:
22162306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_ULP:
22262306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_SGE0:
22362306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_SGE1:
22462306a36Sopenharmony_ci	case CUDBG_CIM_IBQ_NCSI:
22562306a36Sopenharmony_ci		len = CIM_IBQ_SIZE * 4 * sizeof(u32);
22662306a36Sopenharmony_ci		break;
22762306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_ULP0:
22862306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 0);
22962306a36Sopenharmony_ci		break;
23062306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_ULP1:
23162306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 1);
23262306a36Sopenharmony_ci		break;
23362306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_ULP2:
23462306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 2);
23562306a36Sopenharmony_ci		break;
23662306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_ULP3:
23762306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 3);
23862306a36Sopenharmony_ci		break;
23962306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_SGE:
24062306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 4);
24162306a36Sopenharmony_ci		break;
24262306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_NCSI:
24362306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 5);
24462306a36Sopenharmony_ci		break;
24562306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_RXQ0:
24662306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 6);
24762306a36Sopenharmony_ci		break;
24862306a36Sopenharmony_ci	case CUDBG_CIM_OBQ_RXQ1:
24962306a36Sopenharmony_ci		len = cudbg_cim_obq_size(adap, 7);
25062306a36Sopenharmony_ci		break;
25162306a36Sopenharmony_ci	case CUDBG_EDC0:
25262306a36Sopenharmony_ci		value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
25362306a36Sopenharmony_ci		if (value & EDRAM0_ENABLE_F) {
25462306a36Sopenharmony_ci			value = t4_read_reg(adap, MA_EDRAM0_BAR_A);
25562306a36Sopenharmony_ci			len = EDRAM0_SIZE_G(value);
25662306a36Sopenharmony_ci		}
25762306a36Sopenharmony_ci		len = cudbg_mbytes_to_bytes(len);
25862306a36Sopenharmony_ci		break;
25962306a36Sopenharmony_ci	case CUDBG_EDC1:
26062306a36Sopenharmony_ci		value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
26162306a36Sopenharmony_ci		if (value & EDRAM1_ENABLE_F) {
26262306a36Sopenharmony_ci			value = t4_read_reg(adap, MA_EDRAM1_BAR_A);
26362306a36Sopenharmony_ci			len = EDRAM1_SIZE_G(value);
26462306a36Sopenharmony_ci		}
26562306a36Sopenharmony_ci		len = cudbg_mbytes_to_bytes(len);
26662306a36Sopenharmony_ci		break;
26762306a36Sopenharmony_ci	case CUDBG_MC0:
26862306a36Sopenharmony_ci		value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
26962306a36Sopenharmony_ci		if (value & EXT_MEM0_ENABLE_F) {
27062306a36Sopenharmony_ci			value = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
27162306a36Sopenharmony_ci			len = EXT_MEM0_SIZE_G(value);
27262306a36Sopenharmony_ci		}
27362306a36Sopenharmony_ci		len = cudbg_mbytes_to_bytes(len);
27462306a36Sopenharmony_ci		break;
27562306a36Sopenharmony_ci	case CUDBG_MC1:
27662306a36Sopenharmony_ci		value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
27762306a36Sopenharmony_ci		if (value & EXT_MEM1_ENABLE_F) {
27862306a36Sopenharmony_ci			value = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
27962306a36Sopenharmony_ci			len = EXT_MEM1_SIZE_G(value);
28062306a36Sopenharmony_ci		}
28162306a36Sopenharmony_ci		len = cudbg_mbytes_to_bytes(len);
28262306a36Sopenharmony_ci		break;
28362306a36Sopenharmony_ci	case CUDBG_RSS:
28462306a36Sopenharmony_ci		len = t4_chip_rss_size(adap) * sizeof(u16);
28562306a36Sopenharmony_ci		break;
28662306a36Sopenharmony_ci	case CUDBG_RSS_VF_CONF:
28762306a36Sopenharmony_ci		len = adap->params.arch.vfcount *
28862306a36Sopenharmony_ci		      sizeof(struct cudbg_rss_vf_conf);
28962306a36Sopenharmony_ci		break;
29062306a36Sopenharmony_ci	case CUDBG_PATH_MTU:
29162306a36Sopenharmony_ci		len = NMTUS * sizeof(u16);
29262306a36Sopenharmony_ci		break;
29362306a36Sopenharmony_ci	case CUDBG_PM_STATS:
29462306a36Sopenharmony_ci		len = sizeof(struct cudbg_pm_stats);
29562306a36Sopenharmony_ci		break;
29662306a36Sopenharmony_ci	case CUDBG_HW_SCHED:
29762306a36Sopenharmony_ci		len = sizeof(struct cudbg_hw_sched);
29862306a36Sopenharmony_ci		break;
29962306a36Sopenharmony_ci	case CUDBG_TP_INDIRECT:
30062306a36Sopenharmony_ci		switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
30162306a36Sopenharmony_ci		case CHELSIO_T5:
30262306a36Sopenharmony_ci			n = sizeof(t5_tp_pio_array) +
30362306a36Sopenharmony_ci			    sizeof(t5_tp_tm_pio_array) +
30462306a36Sopenharmony_ci			    sizeof(t5_tp_mib_index_array);
30562306a36Sopenharmony_ci			break;
30662306a36Sopenharmony_ci		case CHELSIO_T6:
30762306a36Sopenharmony_ci			n = sizeof(t6_tp_pio_array) +
30862306a36Sopenharmony_ci			    sizeof(t6_tp_tm_pio_array) +
30962306a36Sopenharmony_ci			    sizeof(t6_tp_mib_index_array);
31062306a36Sopenharmony_ci			break;
31162306a36Sopenharmony_ci		default:
31262306a36Sopenharmony_ci			break;
31362306a36Sopenharmony_ci		}
31462306a36Sopenharmony_ci		n = n / (IREG_NUM_ELEM * sizeof(u32));
31562306a36Sopenharmony_ci		len = sizeof(struct ireg_buf) * n;
31662306a36Sopenharmony_ci		break;
31762306a36Sopenharmony_ci	case CUDBG_SGE_INDIRECT:
31862306a36Sopenharmony_ci		len = sizeof(struct ireg_buf) * 2 +
31962306a36Sopenharmony_ci		      sizeof(struct sge_qbase_reg_field);
32062306a36Sopenharmony_ci		break;
32162306a36Sopenharmony_ci	case CUDBG_ULPRX_LA:
32262306a36Sopenharmony_ci		len = sizeof(struct cudbg_ulprx_la);
32362306a36Sopenharmony_ci		break;
32462306a36Sopenharmony_ci	case CUDBG_TP_LA:
32562306a36Sopenharmony_ci		len = sizeof(struct cudbg_tp_la) + TPLA_SIZE * sizeof(u64);
32662306a36Sopenharmony_ci		break;
32762306a36Sopenharmony_ci	case CUDBG_MEMINFO:
32862306a36Sopenharmony_ci		len = sizeof(struct cudbg_ver_hdr) +
32962306a36Sopenharmony_ci		      sizeof(struct cudbg_meminfo);
33062306a36Sopenharmony_ci		break;
33162306a36Sopenharmony_ci	case CUDBG_CIM_PIF_LA:
33262306a36Sopenharmony_ci		len = sizeof(struct cudbg_cim_pif_la);
33362306a36Sopenharmony_ci		len += 2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
33462306a36Sopenharmony_ci		break;
33562306a36Sopenharmony_ci	case CUDBG_CLK:
33662306a36Sopenharmony_ci		len = sizeof(struct cudbg_clk_info);
33762306a36Sopenharmony_ci		break;
33862306a36Sopenharmony_ci	case CUDBG_PCIE_INDIRECT:
33962306a36Sopenharmony_ci		n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
34062306a36Sopenharmony_ci		len = sizeof(struct ireg_buf) * n * 2;
34162306a36Sopenharmony_ci		break;
34262306a36Sopenharmony_ci	case CUDBG_PM_INDIRECT:
34362306a36Sopenharmony_ci		n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
34462306a36Sopenharmony_ci		len = sizeof(struct ireg_buf) * n * 2;
34562306a36Sopenharmony_ci		break;
34662306a36Sopenharmony_ci	case CUDBG_TID_INFO:
34762306a36Sopenharmony_ci		len = sizeof(struct cudbg_tid_info_region_rev1);
34862306a36Sopenharmony_ci		break;
34962306a36Sopenharmony_ci	case CUDBG_PCIE_CONFIG:
35062306a36Sopenharmony_ci		len = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
35162306a36Sopenharmony_ci		break;
35262306a36Sopenharmony_ci	case CUDBG_DUMP_CONTEXT:
35362306a36Sopenharmony_ci		len = cudbg_dump_context_size(adap);
35462306a36Sopenharmony_ci		break;
35562306a36Sopenharmony_ci	case CUDBG_MPS_TCAM:
35662306a36Sopenharmony_ci		len = sizeof(struct cudbg_mps_tcam) *
35762306a36Sopenharmony_ci		      adap->params.arch.mps_tcam_size;
35862306a36Sopenharmony_ci		break;
35962306a36Sopenharmony_ci	case CUDBG_VPD_DATA:
36062306a36Sopenharmony_ci		len = sizeof(struct cudbg_vpd_data);
36162306a36Sopenharmony_ci		break;
36262306a36Sopenharmony_ci	case CUDBG_LE_TCAM:
36362306a36Sopenharmony_ci		cudbg_fill_le_tcam_info(adap, &tcam_region);
36462306a36Sopenharmony_ci		len = sizeof(struct cudbg_tcam) +
36562306a36Sopenharmony_ci		      sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
36662306a36Sopenharmony_ci		break;
36762306a36Sopenharmony_ci	case CUDBG_CCTRL:
36862306a36Sopenharmony_ci		len = sizeof(u16) * NMTUS * NCCTRL_WIN;
36962306a36Sopenharmony_ci		break;
37062306a36Sopenharmony_ci	case CUDBG_MA_INDIRECT:
37162306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
37262306a36Sopenharmony_ci			n = sizeof(t6_ma_ireg_array) /
37362306a36Sopenharmony_ci			    (IREG_NUM_ELEM * sizeof(u32));
37462306a36Sopenharmony_ci			len = sizeof(struct ireg_buf) * n * 2;
37562306a36Sopenharmony_ci		}
37662306a36Sopenharmony_ci		break;
37762306a36Sopenharmony_ci	case CUDBG_ULPTX_LA:
37862306a36Sopenharmony_ci		len = sizeof(struct cudbg_ver_hdr) +
37962306a36Sopenharmony_ci		      sizeof(struct cudbg_ulptx_la);
38062306a36Sopenharmony_ci		break;
38162306a36Sopenharmony_ci	case CUDBG_UP_CIM_INDIRECT:
38262306a36Sopenharmony_ci		n = 0;
38362306a36Sopenharmony_ci		if (is_t5(adap->params.chip))
38462306a36Sopenharmony_ci			n = sizeof(t5_up_cim_reg_array) /
38562306a36Sopenharmony_ci			    ((IREG_NUM_ELEM + 1) * sizeof(u32));
38662306a36Sopenharmony_ci		else if (is_t6(adap->params.chip))
38762306a36Sopenharmony_ci			n = sizeof(t6_up_cim_reg_array) /
38862306a36Sopenharmony_ci			    ((IREG_NUM_ELEM + 1) * sizeof(u32));
38962306a36Sopenharmony_ci		len = sizeof(struct ireg_buf) * n;
39062306a36Sopenharmony_ci		break;
39162306a36Sopenharmony_ci	case CUDBG_PBT_TABLE:
39262306a36Sopenharmony_ci		len = sizeof(struct cudbg_pbt_tables);
39362306a36Sopenharmony_ci		break;
39462306a36Sopenharmony_ci	case CUDBG_MBOX_LOG:
39562306a36Sopenharmony_ci		len = sizeof(struct cudbg_mbox_log) * adap->mbox_log->size;
39662306a36Sopenharmony_ci		break;
39762306a36Sopenharmony_ci	case CUDBG_HMA_INDIRECT:
39862306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
39962306a36Sopenharmony_ci			n = sizeof(t6_hma_ireg_array) /
40062306a36Sopenharmony_ci			    (IREG_NUM_ELEM * sizeof(u32));
40162306a36Sopenharmony_ci			len = sizeof(struct ireg_buf) * n;
40262306a36Sopenharmony_ci		}
40362306a36Sopenharmony_ci		break;
40462306a36Sopenharmony_ci	case CUDBG_HMA:
40562306a36Sopenharmony_ci		value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
40662306a36Sopenharmony_ci		if (value & HMA_MUX_F) {
40762306a36Sopenharmony_ci			/* In T6, there's no MC1.  So, HMA shares MC1
40862306a36Sopenharmony_ci			 * address space.
40962306a36Sopenharmony_ci			 */
41062306a36Sopenharmony_ci			value = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
41162306a36Sopenharmony_ci			len = EXT_MEM1_SIZE_G(value);
41262306a36Sopenharmony_ci		}
41362306a36Sopenharmony_ci		len = cudbg_mbytes_to_bytes(len);
41462306a36Sopenharmony_ci		break;
41562306a36Sopenharmony_ci	case CUDBG_QDESC:
41662306a36Sopenharmony_ci		cudbg_fill_qdesc_num_and_size(adap, NULL, &len);
41762306a36Sopenharmony_ci		break;
41862306a36Sopenharmony_ci	default:
41962306a36Sopenharmony_ci		break;
42062306a36Sopenharmony_ci	}
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci	return len;
42362306a36Sopenharmony_ci}
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_cistatic int cudbg_do_compression(struct cudbg_init *pdbg_init,
42662306a36Sopenharmony_ci				struct cudbg_buffer *pin_buff,
42762306a36Sopenharmony_ci				struct cudbg_buffer *dbg_buff)
42862306a36Sopenharmony_ci{
42962306a36Sopenharmony_ci	struct cudbg_buffer temp_in_buff = { 0 };
43062306a36Sopenharmony_ci	int bytes_left, bytes_read, bytes;
43162306a36Sopenharmony_ci	u32 offset = dbg_buff->offset;
43262306a36Sopenharmony_ci	int rc;
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci	temp_in_buff.offset = pin_buff->offset;
43562306a36Sopenharmony_ci	temp_in_buff.data = pin_buff->data;
43662306a36Sopenharmony_ci	temp_in_buff.size = pin_buff->size;
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci	bytes_left = pin_buff->size;
43962306a36Sopenharmony_ci	bytes_read = 0;
44062306a36Sopenharmony_ci	while (bytes_left > 0) {
44162306a36Sopenharmony_ci		/* Do compression in smaller chunks */
44262306a36Sopenharmony_ci		bytes = min_t(unsigned long, bytes_left,
44362306a36Sopenharmony_ci			      (unsigned long)CUDBG_CHUNK_SIZE);
44462306a36Sopenharmony_ci		temp_in_buff.data = (char *)pin_buff->data + bytes_read;
44562306a36Sopenharmony_ci		temp_in_buff.size = bytes;
44662306a36Sopenharmony_ci		rc = cudbg_compress_buff(pdbg_init, &temp_in_buff, dbg_buff);
44762306a36Sopenharmony_ci		if (rc)
44862306a36Sopenharmony_ci			return rc;
44962306a36Sopenharmony_ci		bytes_left -= bytes;
45062306a36Sopenharmony_ci		bytes_read += bytes;
45162306a36Sopenharmony_ci	}
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci	pin_buff->size = dbg_buff->offset - offset;
45462306a36Sopenharmony_ci	return 0;
45562306a36Sopenharmony_ci}
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_cistatic int cudbg_write_and_release_buff(struct cudbg_init *pdbg_init,
45862306a36Sopenharmony_ci					struct cudbg_buffer *pin_buff,
45962306a36Sopenharmony_ci					struct cudbg_buffer *dbg_buff)
46062306a36Sopenharmony_ci{
46162306a36Sopenharmony_ci	int rc = 0;
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci	if (pdbg_init->compress_type == CUDBG_COMPRESSION_NONE) {
46462306a36Sopenharmony_ci		cudbg_update_buff(pin_buff, dbg_buff);
46562306a36Sopenharmony_ci	} else {
46662306a36Sopenharmony_ci		rc = cudbg_do_compression(pdbg_init, pin_buff, dbg_buff);
46762306a36Sopenharmony_ci		if (rc)
46862306a36Sopenharmony_ci			goto out;
46962306a36Sopenharmony_ci	}
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ciout:
47262306a36Sopenharmony_ci	cudbg_put_buff(pdbg_init, pin_buff);
47362306a36Sopenharmony_ci	return rc;
47462306a36Sopenharmony_ci}
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_cistatic int is_fw_attached(struct cudbg_init *pdbg_init)
47762306a36Sopenharmony_ci{
47862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci	if (!(padap->flags & CXGB4_FW_OK) || padap->use_bd)
48162306a36Sopenharmony_ci		return 0;
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci	return 1;
48462306a36Sopenharmony_ci}
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci/* This function will add additional padding bytes into debug_buffer to make it
48762306a36Sopenharmony_ci * 4 byte aligned.
48862306a36Sopenharmony_ci */
48962306a36Sopenharmony_civoid cudbg_align_debug_buffer(struct cudbg_buffer *dbg_buff,
49062306a36Sopenharmony_ci			      struct cudbg_entity_hdr *entity_hdr)
49162306a36Sopenharmony_ci{
49262306a36Sopenharmony_ci	u8 zero_buf[4] = {0};
49362306a36Sopenharmony_ci	u8 padding, remain;
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ci	remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
49662306a36Sopenharmony_ci	padding = 4 - remain;
49762306a36Sopenharmony_ci	if (remain) {
49862306a36Sopenharmony_ci		memcpy(((u8 *)dbg_buff->data) + dbg_buff->offset, &zero_buf,
49962306a36Sopenharmony_ci		       padding);
50062306a36Sopenharmony_ci		dbg_buff->offset += padding;
50162306a36Sopenharmony_ci		entity_hdr->num_pad = padding;
50262306a36Sopenharmony_ci	}
50362306a36Sopenharmony_ci	entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
50462306a36Sopenharmony_ci}
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_cistruct cudbg_entity_hdr *cudbg_get_entity_hdr(void *outbuf, int i)
50762306a36Sopenharmony_ci{
50862306a36Sopenharmony_ci	struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
50962306a36Sopenharmony_ci
51062306a36Sopenharmony_ci	return (struct cudbg_entity_hdr *)
51162306a36Sopenharmony_ci	       ((char *)outbuf + cudbg_hdr->hdr_len +
51262306a36Sopenharmony_ci		(sizeof(struct cudbg_entity_hdr) * (i - 1)));
51362306a36Sopenharmony_ci}
51462306a36Sopenharmony_ci
51562306a36Sopenharmony_cistatic int cudbg_read_vpd_reg(struct adapter *padap, u32 addr, u32 len,
51662306a36Sopenharmony_ci			      void *dest)
51762306a36Sopenharmony_ci{
51862306a36Sopenharmony_ci	int vaddr, rc;
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci	vaddr = t4_eeprom_ptov(addr, padap->pf, EEPROMPFSIZE);
52162306a36Sopenharmony_ci	if (vaddr < 0)
52262306a36Sopenharmony_ci		return vaddr;
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ci	rc = pci_read_vpd(padap->pdev, vaddr, len, dest);
52562306a36Sopenharmony_ci	if (rc < 0)
52662306a36Sopenharmony_ci		return rc;
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_ci	return 0;
52962306a36Sopenharmony_ci}
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_cistatic int cudbg_mem_desc_cmp(const void *a, const void *b)
53262306a36Sopenharmony_ci{
53362306a36Sopenharmony_ci	return ((const struct cudbg_mem_desc *)a)->base -
53462306a36Sopenharmony_ci	       ((const struct cudbg_mem_desc *)b)->base;
53562306a36Sopenharmony_ci}
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ciint cudbg_fill_meminfo(struct adapter *padap,
53862306a36Sopenharmony_ci		       struct cudbg_meminfo *meminfo_buff)
53962306a36Sopenharmony_ci{
54062306a36Sopenharmony_ci	struct cudbg_mem_desc *md;
54162306a36Sopenharmony_ci	u32 lo, hi, used, alloc;
54262306a36Sopenharmony_ci	int n, i;
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_ci	memset(meminfo_buff->avail, 0,
54562306a36Sopenharmony_ci	       ARRAY_SIZE(meminfo_buff->avail) *
54662306a36Sopenharmony_ci	       sizeof(struct cudbg_mem_desc));
54762306a36Sopenharmony_ci	memset(meminfo_buff->mem, 0,
54862306a36Sopenharmony_ci	       (ARRAY_SIZE(cudbg_region) + 3) * sizeof(struct cudbg_mem_desc));
54962306a36Sopenharmony_ci	md  = meminfo_buff->mem;
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(meminfo_buff->mem); i++) {
55262306a36Sopenharmony_ci		meminfo_buff->mem[i].limit = 0;
55362306a36Sopenharmony_ci		meminfo_buff->mem[i].idx = i;
55462306a36Sopenharmony_ci	}
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_ci	/* Find and sort the populated memory ranges */
55762306a36Sopenharmony_ci	i = 0;
55862306a36Sopenharmony_ci	lo = t4_read_reg(padap, MA_TARGET_MEM_ENABLE_A);
55962306a36Sopenharmony_ci	if (lo & EDRAM0_ENABLE_F) {
56062306a36Sopenharmony_ci		hi = t4_read_reg(padap, MA_EDRAM0_BAR_A);
56162306a36Sopenharmony_ci		meminfo_buff->avail[i].base =
56262306a36Sopenharmony_ci			cudbg_mbytes_to_bytes(EDRAM0_BASE_G(hi));
56362306a36Sopenharmony_ci		meminfo_buff->avail[i].limit =
56462306a36Sopenharmony_ci			meminfo_buff->avail[i].base +
56562306a36Sopenharmony_ci			cudbg_mbytes_to_bytes(EDRAM0_SIZE_G(hi));
56662306a36Sopenharmony_ci		meminfo_buff->avail[i].idx = 0;
56762306a36Sopenharmony_ci		i++;
56862306a36Sopenharmony_ci	}
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci	if (lo & EDRAM1_ENABLE_F) {
57162306a36Sopenharmony_ci		hi =  t4_read_reg(padap, MA_EDRAM1_BAR_A);
57262306a36Sopenharmony_ci		meminfo_buff->avail[i].base =
57362306a36Sopenharmony_ci			cudbg_mbytes_to_bytes(EDRAM1_BASE_G(hi));
57462306a36Sopenharmony_ci		meminfo_buff->avail[i].limit =
57562306a36Sopenharmony_ci			meminfo_buff->avail[i].base +
57662306a36Sopenharmony_ci			cudbg_mbytes_to_bytes(EDRAM1_SIZE_G(hi));
57762306a36Sopenharmony_ci		meminfo_buff->avail[i].idx = 1;
57862306a36Sopenharmony_ci		i++;
57962306a36Sopenharmony_ci	}
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci	if (is_t5(padap->params.chip)) {
58262306a36Sopenharmony_ci		if (lo & EXT_MEM0_ENABLE_F) {
58362306a36Sopenharmony_ci			hi = t4_read_reg(padap, MA_EXT_MEMORY0_BAR_A);
58462306a36Sopenharmony_ci			meminfo_buff->avail[i].base =
58562306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
58662306a36Sopenharmony_ci			meminfo_buff->avail[i].limit =
58762306a36Sopenharmony_ci				meminfo_buff->avail[i].base +
58862306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
58962306a36Sopenharmony_ci			meminfo_buff->avail[i].idx = 3;
59062306a36Sopenharmony_ci			i++;
59162306a36Sopenharmony_ci		}
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_ci		if (lo & EXT_MEM1_ENABLE_F) {
59462306a36Sopenharmony_ci			hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
59562306a36Sopenharmony_ci			meminfo_buff->avail[i].base =
59662306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
59762306a36Sopenharmony_ci			meminfo_buff->avail[i].limit =
59862306a36Sopenharmony_ci				meminfo_buff->avail[i].base +
59962306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
60062306a36Sopenharmony_ci			meminfo_buff->avail[i].idx = 4;
60162306a36Sopenharmony_ci			i++;
60262306a36Sopenharmony_ci		}
60362306a36Sopenharmony_ci	} else {
60462306a36Sopenharmony_ci		if (lo & EXT_MEM_ENABLE_F) {
60562306a36Sopenharmony_ci			hi = t4_read_reg(padap, MA_EXT_MEMORY_BAR_A);
60662306a36Sopenharmony_ci			meminfo_buff->avail[i].base =
60762306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
60862306a36Sopenharmony_ci			meminfo_buff->avail[i].limit =
60962306a36Sopenharmony_ci				meminfo_buff->avail[i].base +
61062306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
61162306a36Sopenharmony_ci			meminfo_buff->avail[i].idx = 2;
61262306a36Sopenharmony_ci			i++;
61362306a36Sopenharmony_ci		}
61462306a36Sopenharmony_ci
61562306a36Sopenharmony_ci		if (lo & HMA_MUX_F) {
61662306a36Sopenharmony_ci			hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
61762306a36Sopenharmony_ci			meminfo_buff->avail[i].base =
61862306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
61962306a36Sopenharmony_ci			meminfo_buff->avail[i].limit =
62062306a36Sopenharmony_ci				meminfo_buff->avail[i].base +
62162306a36Sopenharmony_ci				cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
62262306a36Sopenharmony_ci			meminfo_buff->avail[i].idx = 5;
62362306a36Sopenharmony_ci			i++;
62462306a36Sopenharmony_ci		}
62562306a36Sopenharmony_ci	}
62662306a36Sopenharmony_ci
62762306a36Sopenharmony_ci	if (!i) /* no memory available */
62862306a36Sopenharmony_ci		return CUDBG_STATUS_ENTITY_NOT_FOUND;
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci	meminfo_buff->avail_c = i;
63162306a36Sopenharmony_ci	sort(meminfo_buff->avail, i, sizeof(struct cudbg_mem_desc),
63262306a36Sopenharmony_ci	     cudbg_mem_desc_cmp, NULL);
63362306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, SGE_DBQ_CTXT_BADDR_A);
63462306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, SGE_IMSG_CTXT_BADDR_A);
63562306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, SGE_FLM_CACHE_BADDR_A);
63662306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_TCB_BASE_A);
63762306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_MM_BASE_A);
63862306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_TIMER_BASE_A);
63962306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_MM_RX_FLST_BASE_A);
64062306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_MM_TX_FLST_BASE_A);
64162306a36Sopenharmony_ci	(md++)->base = t4_read_reg(padap, TP_CMM_MM_PS_FLST_BASE_A);
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_ci	/* the next few have explicit upper bounds */
64462306a36Sopenharmony_ci	md->base = t4_read_reg(padap, TP_PMM_TX_BASE_A);
64562306a36Sopenharmony_ci	md->limit = md->base - 1 +
64662306a36Sopenharmony_ci		    t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A) *
64762306a36Sopenharmony_ci		    PMTXMAXPAGE_G(t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A));
64862306a36Sopenharmony_ci	md++;
64962306a36Sopenharmony_ci
65062306a36Sopenharmony_ci	md->base = t4_read_reg(padap, TP_PMM_RX_BASE_A);
65162306a36Sopenharmony_ci	md->limit = md->base - 1 +
65262306a36Sopenharmony_ci		    t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) *
65362306a36Sopenharmony_ci		    PMRXMAXPAGE_G(t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A));
65462306a36Sopenharmony_ci	md++;
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ci	if (t4_read_reg(padap, LE_DB_CONFIG_A) & HASHEN_F) {
65762306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(padap->params.chip) <= CHELSIO_T5) {
65862306a36Sopenharmony_ci			hi = t4_read_reg(padap, LE_DB_TID_HASHBASE_A) / 4;
65962306a36Sopenharmony_ci			md->base = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
66062306a36Sopenharmony_ci		} else {
66162306a36Sopenharmony_ci			hi = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
66262306a36Sopenharmony_ci			md->base = t4_read_reg(padap,
66362306a36Sopenharmony_ci					       LE_DB_HASH_TBL_BASE_ADDR_A);
66462306a36Sopenharmony_ci		}
66562306a36Sopenharmony_ci		md->limit = 0;
66662306a36Sopenharmony_ci	} else {
66762306a36Sopenharmony_ci		md->base = 0;
66862306a36Sopenharmony_ci		md->idx = ARRAY_SIZE(cudbg_region);  /* hide it */
66962306a36Sopenharmony_ci	}
67062306a36Sopenharmony_ci	md++;
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci#define ulp_region(reg) do { \
67362306a36Sopenharmony_ci	md->base = t4_read_reg(padap, ULP_ ## reg ## _LLIMIT_A);\
67462306a36Sopenharmony_ci	(md++)->limit = t4_read_reg(padap, ULP_ ## reg ## _ULIMIT_A);\
67562306a36Sopenharmony_ci} while (0)
67662306a36Sopenharmony_ci
67762306a36Sopenharmony_ci	ulp_region(RX_ISCSI);
67862306a36Sopenharmony_ci	ulp_region(RX_TDDP);
67962306a36Sopenharmony_ci	ulp_region(TX_TPT);
68062306a36Sopenharmony_ci	ulp_region(RX_STAG);
68162306a36Sopenharmony_ci	ulp_region(RX_RQ);
68262306a36Sopenharmony_ci	ulp_region(RX_RQUDP);
68362306a36Sopenharmony_ci	ulp_region(RX_PBL);
68462306a36Sopenharmony_ci	ulp_region(TX_PBL);
68562306a36Sopenharmony_ci#undef ulp_region
68662306a36Sopenharmony_ci	md->base = 0;
68762306a36Sopenharmony_ci	md->idx = ARRAY_SIZE(cudbg_region);
68862306a36Sopenharmony_ci	if (!is_t4(padap->params.chip)) {
68962306a36Sopenharmony_ci		u32 fifo_size = t4_read_reg(padap, SGE_DBVFIFO_SIZE_A);
69062306a36Sopenharmony_ci		u32 sge_ctrl = t4_read_reg(padap, SGE_CONTROL2_A);
69162306a36Sopenharmony_ci		u32 size = 0;
69262306a36Sopenharmony_ci
69362306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
69462306a36Sopenharmony_ci			if (sge_ctrl & VFIFO_ENABLE_F)
69562306a36Sopenharmony_ci				size = DBVFIFO_SIZE_G(fifo_size);
69662306a36Sopenharmony_ci		} else {
69762306a36Sopenharmony_ci			size = T6_DBVFIFO_SIZE_G(fifo_size);
69862306a36Sopenharmony_ci		}
69962306a36Sopenharmony_ci
70062306a36Sopenharmony_ci		if (size) {
70162306a36Sopenharmony_ci			md->base = BASEADDR_G(t4_read_reg(padap,
70262306a36Sopenharmony_ci							  SGE_DBVFIFO_BADDR_A));
70362306a36Sopenharmony_ci			md->limit = md->base + (size << 2) - 1;
70462306a36Sopenharmony_ci		}
70562306a36Sopenharmony_ci	}
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci	md++;
70862306a36Sopenharmony_ci
70962306a36Sopenharmony_ci	md->base = t4_read_reg(padap, ULP_RX_CTX_BASE_A);
71062306a36Sopenharmony_ci	md->limit = 0;
71162306a36Sopenharmony_ci	md++;
71262306a36Sopenharmony_ci	md->base = t4_read_reg(padap, ULP_TX_ERR_TABLE_BASE_A);
71362306a36Sopenharmony_ci	md->limit = 0;
71462306a36Sopenharmony_ci	md++;
71562306a36Sopenharmony_ci
71662306a36Sopenharmony_ci	md->base = padap->vres.ocq.start;
71762306a36Sopenharmony_ci	if (padap->vres.ocq.size)
71862306a36Sopenharmony_ci		md->limit = md->base + padap->vres.ocq.size - 1;
71962306a36Sopenharmony_ci	else
72062306a36Sopenharmony_ci		md->idx = ARRAY_SIZE(cudbg_region);  /* hide it */
72162306a36Sopenharmony_ci	md++;
72262306a36Sopenharmony_ci
72362306a36Sopenharmony_ci	/* add any address-space holes, there can be up to 3 */
72462306a36Sopenharmony_ci	for (n = 0; n < i - 1; n++)
72562306a36Sopenharmony_ci		if (meminfo_buff->avail[n].limit <
72662306a36Sopenharmony_ci		    meminfo_buff->avail[n + 1].base)
72762306a36Sopenharmony_ci			(md++)->base = meminfo_buff->avail[n].limit;
72862306a36Sopenharmony_ci
72962306a36Sopenharmony_ci	if (meminfo_buff->avail[n].limit)
73062306a36Sopenharmony_ci		(md++)->base = meminfo_buff->avail[n].limit;
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci	n = md - meminfo_buff->mem;
73362306a36Sopenharmony_ci	meminfo_buff->mem_c = n;
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_ci	sort(meminfo_buff->mem, n, sizeof(struct cudbg_mem_desc),
73662306a36Sopenharmony_ci	     cudbg_mem_desc_cmp, NULL);
73762306a36Sopenharmony_ci
73862306a36Sopenharmony_ci	lo = t4_read_reg(padap, CIM_SDRAM_BASE_ADDR_A);
73962306a36Sopenharmony_ci	hi = t4_read_reg(padap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
74062306a36Sopenharmony_ci	meminfo_buff->up_ram_lo = lo;
74162306a36Sopenharmony_ci	meminfo_buff->up_ram_hi = hi;
74262306a36Sopenharmony_ci
74362306a36Sopenharmony_ci	lo = t4_read_reg(padap, CIM_EXTMEM2_BASE_ADDR_A);
74462306a36Sopenharmony_ci	hi = t4_read_reg(padap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
74562306a36Sopenharmony_ci	meminfo_buff->up_extmem2_lo = lo;
74662306a36Sopenharmony_ci	meminfo_buff->up_extmem2_hi = hi;
74762306a36Sopenharmony_ci
74862306a36Sopenharmony_ci	lo = t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A);
74962306a36Sopenharmony_ci	for (i = 0, meminfo_buff->free_rx_cnt = 0; i < 2; i++)
75062306a36Sopenharmony_ci		meminfo_buff->free_rx_cnt +=
75162306a36Sopenharmony_ci			FREERXPAGECOUNT_G(t4_read_reg(padap,
75262306a36Sopenharmony_ci						      TP_FLM_FREE_RX_CNT_A));
75362306a36Sopenharmony_ci
75462306a36Sopenharmony_ci	meminfo_buff->rx_pages_data[0] =  PMRXMAXPAGE_G(lo);
75562306a36Sopenharmony_ci	meminfo_buff->rx_pages_data[1] =
75662306a36Sopenharmony_ci		t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) >> 10;
75762306a36Sopenharmony_ci	meminfo_buff->rx_pages_data[2] = (lo & PMRXNUMCHN_F) ? 2 : 1;
75862306a36Sopenharmony_ci
75962306a36Sopenharmony_ci	lo = t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A);
76062306a36Sopenharmony_ci	hi = t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A);
76162306a36Sopenharmony_ci	for (i = 0, meminfo_buff->free_tx_cnt = 0; i < 4; i++)
76262306a36Sopenharmony_ci		meminfo_buff->free_tx_cnt +=
76362306a36Sopenharmony_ci			FREETXPAGECOUNT_G(t4_read_reg(padap,
76462306a36Sopenharmony_ci						      TP_FLM_FREE_TX_CNT_A));
76562306a36Sopenharmony_ci
76662306a36Sopenharmony_ci	meminfo_buff->tx_pages_data[0] = PMTXMAXPAGE_G(lo);
76762306a36Sopenharmony_ci	meminfo_buff->tx_pages_data[1] =
76862306a36Sopenharmony_ci		hi >= (1 << 20) ? (hi >> 20) : (hi >> 10);
76962306a36Sopenharmony_ci	meminfo_buff->tx_pages_data[2] =
77062306a36Sopenharmony_ci		hi >= (1 << 20) ? 'M' : 'K';
77162306a36Sopenharmony_ci	meminfo_buff->tx_pages_data[3] = 1 << PMTXNUMCHN_G(lo);
77262306a36Sopenharmony_ci
77362306a36Sopenharmony_ci	meminfo_buff->p_structs = t4_read_reg(padap, TP_CMM_MM_MAX_PSTRUCT_A);
77462306a36Sopenharmony_ci	meminfo_buff->p_structs_free_cnt =
77562306a36Sopenharmony_ci		FREEPSTRUCTCOUNT_G(t4_read_reg(padap, TP_FLM_FREE_PS_CNT_A));
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_ci	for (i = 0; i < 4; i++) {
77862306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
77962306a36Sopenharmony_ci			lo = t4_read_reg(padap,
78062306a36Sopenharmony_ci					 MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
78162306a36Sopenharmony_ci		else
78262306a36Sopenharmony_ci			lo = t4_read_reg(padap, MPS_RX_PG_RSV0_A + i * 4);
78362306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
78462306a36Sopenharmony_ci			used = T5_USED_G(lo);
78562306a36Sopenharmony_ci			alloc = T5_ALLOC_G(lo);
78662306a36Sopenharmony_ci		} else {
78762306a36Sopenharmony_ci			used = USED_G(lo);
78862306a36Sopenharmony_ci			alloc = ALLOC_G(lo);
78962306a36Sopenharmony_ci		}
79062306a36Sopenharmony_ci		meminfo_buff->port_used[i] = used;
79162306a36Sopenharmony_ci		meminfo_buff->port_alloc[i] = alloc;
79262306a36Sopenharmony_ci	}
79362306a36Sopenharmony_ci
79462306a36Sopenharmony_ci	for (i = 0; i < padap->params.arch.nchan; i++) {
79562306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
79662306a36Sopenharmony_ci			lo = t4_read_reg(padap,
79762306a36Sopenharmony_ci					 MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
79862306a36Sopenharmony_ci		else
79962306a36Sopenharmony_ci			lo = t4_read_reg(padap, MPS_RX_PG_RSV4_A + i * 4);
80062306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
80162306a36Sopenharmony_ci			used = T5_USED_G(lo);
80262306a36Sopenharmony_ci			alloc = T5_ALLOC_G(lo);
80362306a36Sopenharmony_ci		} else {
80462306a36Sopenharmony_ci			used = USED_G(lo);
80562306a36Sopenharmony_ci			alloc = ALLOC_G(lo);
80662306a36Sopenharmony_ci		}
80762306a36Sopenharmony_ci		meminfo_buff->loopback_used[i] = used;
80862306a36Sopenharmony_ci		meminfo_buff->loopback_alloc[i] = alloc;
80962306a36Sopenharmony_ci	}
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ci	return 0;
81262306a36Sopenharmony_ci}
81362306a36Sopenharmony_ci
81462306a36Sopenharmony_ciint cudbg_collect_reg_dump(struct cudbg_init *pdbg_init,
81562306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
81662306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
81762306a36Sopenharmony_ci{
81862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
81962306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
82062306a36Sopenharmony_ci	u32 buf_size = 0;
82162306a36Sopenharmony_ci	int rc = 0;
82262306a36Sopenharmony_ci
82362306a36Sopenharmony_ci	if (is_t4(padap->params.chip))
82462306a36Sopenharmony_ci		buf_size = T4_REGMAP_SIZE;
82562306a36Sopenharmony_ci	else if (is_t5(padap->params.chip) || is_t6(padap->params.chip))
82662306a36Sopenharmony_ci		buf_size = T5_REGMAP_SIZE;
82762306a36Sopenharmony_ci
82862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, buf_size, &temp_buff);
82962306a36Sopenharmony_ci	if (rc)
83062306a36Sopenharmony_ci		return rc;
83162306a36Sopenharmony_ci	t4_get_regs(padap, (void *)temp_buff.data, temp_buff.size);
83262306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
83362306a36Sopenharmony_ci}
83462306a36Sopenharmony_ci
83562306a36Sopenharmony_ciint cudbg_collect_fw_devlog(struct cudbg_init *pdbg_init,
83662306a36Sopenharmony_ci			    struct cudbg_buffer *dbg_buff,
83762306a36Sopenharmony_ci			    struct cudbg_error *cudbg_err)
83862306a36Sopenharmony_ci{
83962306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
84062306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
84162306a36Sopenharmony_ci	struct devlog_params *dparams;
84262306a36Sopenharmony_ci	int rc = 0;
84362306a36Sopenharmony_ci
84462306a36Sopenharmony_ci	rc = t4_init_devlog_params(padap);
84562306a36Sopenharmony_ci	if (rc < 0) {
84662306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
84762306a36Sopenharmony_ci		return rc;
84862306a36Sopenharmony_ci	}
84962306a36Sopenharmony_ci
85062306a36Sopenharmony_ci	dparams = &padap->params.devlog;
85162306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, dparams->size, &temp_buff);
85262306a36Sopenharmony_ci	if (rc)
85362306a36Sopenharmony_ci		return rc;
85462306a36Sopenharmony_ci
85562306a36Sopenharmony_ci	/* Collect FW devlog */
85662306a36Sopenharmony_ci	if (dparams->start != 0) {
85762306a36Sopenharmony_ci		spin_lock(&padap->win0_lock);
85862306a36Sopenharmony_ci		rc = t4_memory_rw(padap, padap->params.drv_memwin,
85962306a36Sopenharmony_ci				  dparams->memtype, dparams->start,
86062306a36Sopenharmony_ci				  dparams->size,
86162306a36Sopenharmony_ci				  (__be32 *)(char *)temp_buff.data,
86262306a36Sopenharmony_ci				  1);
86362306a36Sopenharmony_ci		spin_unlock(&padap->win0_lock);
86462306a36Sopenharmony_ci		if (rc) {
86562306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
86662306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
86762306a36Sopenharmony_ci			return rc;
86862306a36Sopenharmony_ci		}
86962306a36Sopenharmony_ci	}
87062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
87162306a36Sopenharmony_ci}
87262306a36Sopenharmony_ci
87362306a36Sopenharmony_ciint cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
87462306a36Sopenharmony_ci			 struct cudbg_buffer *dbg_buff,
87562306a36Sopenharmony_ci			 struct cudbg_error *cudbg_err)
87662306a36Sopenharmony_ci{
87762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
87862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
87962306a36Sopenharmony_ci	int size, rc;
88062306a36Sopenharmony_ci	u32 cfg = 0;
88162306a36Sopenharmony_ci
88262306a36Sopenharmony_ci	if (is_t6(padap->params.chip)) {
88362306a36Sopenharmony_ci		size = padap->params.cim_la_size / 10 + 1;
88462306a36Sopenharmony_ci		size *= 10 * sizeof(u32);
88562306a36Sopenharmony_ci	} else {
88662306a36Sopenharmony_ci		size = padap->params.cim_la_size / 8;
88762306a36Sopenharmony_ci		size *= 8 * sizeof(u32);
88862306a36Sopenharmony_ci	}
88962306a36Sopenharmony_ci
89062306a36Sopenharmony_ci	size += sizeof(cfg);
89162306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
89262306a36Sopenharmony_ci	if (rc)
89362306a36Sopenharmony_ci		return rc;
89462306a36Sopenharmony_ci
89562306a36Sopenharmony_ci	rc = t4_cim_read(padap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
89662306a36Sopenharmony_ci	if (rc) {
89762306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
89862306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
89962306a36Sopenharmony_ci		return rc;
90062306a36Sopenharmony_ci	}
90162306a36Sopenharmony_ci
90262306a36Sopenharmony_ci	memcpy((char *)temp_buff.data, &cfg, sizeof(cfg));
90362306a36Sopenharmony_ci	rc = t4_cim_read_la(padap,
90462306a36Sopenharmony_ci			    (u32 *)((char *)temp_buff.data + sizeof(cfg)),
90562306a36Sopenharmony_ci			    NULL);
90662306a36Sopenharmony_ci	if (rc < 0) {
90762306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
90862306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
90962306a36Sopenharmony_ci		return rc;
91062306a36Sopenharmony_ci	}
91162306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
91262306a36Sopenharmony_ci}
91362306a36Sopenharmony_ci
91462306a36Sopenharmony_ciint cudbg_collect_cim_ma_la(struct cudbg_init *pdbg_init,
91562306a36Sopenharmony_ci			    struct cudbg_buffer *dbg_buff,
91662306a36Sopenharmony_ci			    struct cudbg_error *cudbg_err)
91762306a36Sopenharmony_ci{
91862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
91962306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
92062306a36Sopenharmony_ci	int size, rc;
92162306a36Sopenharmony_ci
92262306a36Sopenharmony_ci	size = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
92362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
92462306a36Sopenharmony_ci	if (rc)
92562306a36Sopenharmony_ci		return rc;
92662306a36Sopenharmony_ci
92762306a36Sopenharmony_ci	t4_cim_read_ma_la(padap,
92862306a36Sopenharmony_ci			  (u32 *)temp_buff.data,
92962306a36Sopenharmony_ci			  (u32 *)((char *)temp_buff.data +
93062306a36Sopenharmony_ci				  5 * CIM_MALA_SIZE));
93162306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
93262306a36Sopenharmony_ci}
93362306a36Sopenharmony_ci
93462306a36Sopenharmony_ciint cudbg_collect_cim_qcfg(struct cudbg_init *pdbg_init,
93562306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
93662306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
93762306a36Sopenharmony_ci{
93862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
93962306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
94062306a36Sopenharmony_ci	struct cudbg_cim_qcfg *cim_qcfg_data;
94162306a36Sopenharmony_ci	int rc;
94262306a36Sopenharmony_ci
94362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_cim_qcfg),
94462306a36Sopenharmony_ci			    &temp_buff);
94562306a36Sopenharmony_ci	if (rc)
94662306a36Sopenharmony_ci		return rc;
94762306a36Sopenharmony_ci
94862306a36Sopenharmony_ci	cim_qcfg_data = (struct cudbg_cim_qcfg *)temp_buff.data;
94962306a36Sopenharmony_ci	cim_qcfg_data->chip = padap->params.chip;
95062306a36Sopenharmony_ci	rc = t4_cim_read(padap, UP_IBQ_0_RDADDR_A,
95162306a36Sopenharmony_ci			 ARRAY_SIZE(cim_qcfg_data->stat), cim_qcfg_data->stat);
95262306a36Sopenharmony_ci	if (rc) {
95362306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
95462306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
95562306a36Sopenharmony_ci		return rc;
95662306a36Sopenharmony_ci	}
95762306a36Sopenharmony_ci
95862306a36Sopenharmony_ci	rc = t4_cim_read(padap, UP_OBQ_0_REALADDR_A,
95962306a36Sopenharmony_ci			 ARRAY_SIZE(cim_qcfg_data->obq_wr),
96062306a36Sopenharmony_ci			 cim_qcfg_data->obq_wr);
96162306a36Sopenharmony_ci	if (rc) {
96262306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
96362306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
96462306a36Sopenharmony_ci		return rc;
96562306a36Sopenharmony_ci	}
96662306a36Sopenharmony_ci
96762306a36Sopenharmony_ci	t4_read_cimq_cfg(padap, cim_qcfg_data->base, cim_qcfg_data->size,
96862306a36Sopenharmony_ci			 cim_qcfg_data->thres);
96962306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
97062306a36Sopenharmony_ci}
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_cistatic int cudbg_read_cim_ibq(struct cudbg_init *pdbg_init,
97362306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
97462306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err, int qid)
97562306a36Sopenharmony_ci{
97662306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
97762306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
97862306a36Sopenharmony_ci	int no_of_read_words, rc = 0;
97962306a36Sopenharmony_ci	u32 qsize;
98062306a36Sopenharmony_ci
98162306a36Sopenharmony_ci	/* collect CIM IBQ */
98262306a36Sopenharmony_ci	qsize = CIM_IBQ_SIZE * 4 * sizeof(u32);
98362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
98462306a36Sopenharmony_ci	if (rc)
98562306a36Sopenharmony_ci		return rc;
98662306a36Sopenharmony_ci
98762306a36Sopenharmony_ci	/* t4_read_cim_ibq will return no. of read words or error */
98862306a36Sopenharmony_ci	no_of_read_words = t4_read_cim_ibq(padap, qid,
98962306a36Sopenharmony_ci					   (u32 *)temp_buff.data, qsize);
99062306a36Sopenharmony_ci	/* no_of_read_words is less than or equal to 0 means error */
99162306a36Sopenharmony_ci	if (no_of_read_words <= 0) {
99262306a36Sopenharmony_ci		if (!no_of_read_words)
99362306a36Sopenharmony_ci			rc = CUDBG_SYSTEM_ERROR;
99462306a36Sopenharmony_ci		else
99562306a36Sopenharmony_ci			rc = no_of_read_words;
99662306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
99762306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
99862306a36Sopenharmony_ci		return rc;
99962306a36Sopenharmony_ci	}
100062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
100162306a36Sopenharmony_ci}
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_ciint cudbg_collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
100462306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
100562306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
100662306a36Sopenharmony_ci{
100762306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 0);
100862306a36Sopenharmony_ci}
100962306a36Sopenharmony_ci
101062306a36Sopenharmony_ciint cudbg_collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
101162306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
101262306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
101362306a36Sopenharmony_ci{
101462306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 1);
101562306a36Sopenharmony_ci}
101662306a36Sopenharmony_ci
101762306a36Sopenharmony_ciint cudbg_collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
101862306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
101962306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
102062306a36Sopenharmony_ci{
102162306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 2);
102262306a36Sopenharmony_ci}
102362306a36Sopenharmony_ci
102462306a36Sopenharmony_ciint cudbg_collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
102562306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
102662306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
102762306a36Sopenharmony_ci{
102862306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 3);
102962306a36Sopenharmony_ci}
103062306a36Sopenharmony_ci
103162306a36Sopenharmony_ciint cudbg_collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
103262306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
103362306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
103462306a36Sopenharmony_ci{
103562306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 4);
103662306a36Sopenharmony_ci}
103762306a36Sopenharmony_ci
103862306a36Sopenharmony_ciint cudbg_collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
103962306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
104062306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
104162306a36Sopenharmony_ci{
104262306a36Sopenharmony_ci	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 5);
104362306a36Sopenharmony_ci}
104462306a36Sopenharmony_ci
104562306a36Sopenharmony_ciu32 cudbg_cim_obq_size(struct adapter *padap, int qid)
104662306a36Sopenharmony_ci{
104762306a36Sopenharmony_ci	u32 value;
104862306a36Sopenharmony_ci
104962306a36Sopenharmony_ci	t4_write_reg(padap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
105062306a36Sopenharmony_ci		     QUENUMSELECT_V(qid));
105162306a36Sopenharmony_ci	value = t4_read_reg(padap, CIM_QUEUE_CONFIG_CTRL_A);
105262306a36Sopenharmony_ci	value = CIMQSIZE_G(value) * 64; /* size in number of words */
105362306a36Sopenharmony_ci	return value * sizeof(u32);
105462306a36Sopenharmony_ci}
105562306a36Sopenharmony_ci
105662306a36Sopenharmony_cistatic int cudbg_read_cim_obq(struct cudbg_init *pdbg_init,
105762306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
105862306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err, int qid)
105962306a36Sopenharmony_ci{
106062306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
106162306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
106262306a36Sopenharmony_ci	int no_of_read_words, rc = 0;
106362306a36Sopenharmony_ci	u32 qsize;
106462306a36Sopenharmony_ci
106562306a36Sopenharmony_ci	/* collect CIM OBQ */
106662306a36Sopenharmony_ci	qsize =  cudbg_cim_obq_size(padap, qid);
106762306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
106862306a36Sopenharmony_ci	if (rc)
106962306a36Sopenharmony_ci		return rc;
107062306a36Sopenharmony_ci
107162306a36Sopenharmony_ci	/* t4_read_cim_obq will return no. of read words or error */
107262306a36Sopenharmony_ci	no_of_read_words = t4_read_cim_obq(padap, qid,
107362306a36Sopenharmony_ci					   (u32 *)temp_buff.data, qsize);
107462306a36Sopenharmony_ci	/* no_of_read_words is less than or equal to 0 means error */
107562306a36Sopenharmony_ci	if (no_of_read_words <= 0) {
107662306a36Sopenharmony_ci		if (!no_of_read_words)
107762306a36Sopenharmony_ci			rc = CUDBG_SYSTEM_ERROR;
107862306a36Sopenharmony_ci		else
107962306a36Sopenharmony_ci			rc = no_of_read_words;
108062306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
108162306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
108262306a36Sopenharmony_ci		return rc;
108362306a36Sopenharmony_ci	}
108462306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
108562306a36Sopenharmony_ci}
108662306a36Sopenharmony_ci
108762306a36Sopenharmony_ciint cudbg_collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
108862306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
108962306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
109062306a36Sopenharmony_ci{
109162306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 0);
109262306a36Sopenharmony_ci}
109362306a36Sopenharmony_ci
109462306a36Sopenharmony_ciint cudbg_collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
109562306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
109662306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
109762306a36Sopenharmony_ci{
109862306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 1);
109962306a36Sopenharmony_ci}
110062306a36Sopenharmony_ci
110162306a36Sopenharmony_ciint cudbg_collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
110262306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
110362306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
110462306a36Sopenharmony_ci{
110562306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 2);
110662306a36Sopenharmony_ci}
110762306a36Sopenharmony_ci
110862306a36Sopenharmony_ciint cudbg_collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
110962306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
111062306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
111162306a36Sopenharmony_ci{
111262306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 3);
111362306a36Sopenharmony_ci}
111462306a36Sopenharmony_ci
111562306a36Sopenharmony_ciint cudbg_collect_cim_obq_sge(struct cudbg_init *pdbg_init,
111662306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
111762306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
111862306a36Sopenharmony_ci{
111962306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 4);
112062306a36Sopenharmony_ci}
112162306a36Sopenharmony_ci
112262306a36Sopenharmony_ciint cudbg_collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
112362306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
112462306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
112562306a36Sopenharmony_ci{
112662306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 5);
112762306a36Sopenharmony_ci}
112862306a36Sopenharmony_ci
112962306a36Sopenharmony_ciint cudbg_collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
113062306a36Sopenharmony_ci				struct cudbg_buffer *dbg_buff,
113162306a36Sopenharmony_ci				struct cudbg_error *cudbg_err)
113262306a36Sopenharmony_ci{
113362306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 6);
113462306a36Sopenharmony_ci}
113562306a36Sopenharmony_ci
113662306a36Sopenharmony_ciint cudbg_collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
113762306a36Sopenharmony_ci				struct cudbg_buffer *dbg_buff,
113862306a36Sopenharmony_ci				struct cudbg_error *cudbg_err)
113962306a36Sopenharmony_ci{
114062306a36Sopenharmony_ci	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 7);
114162306a36Sopenharmony_ci}
114262306a36Sopenharmony_ci
114362306a36Sopenharmony_cistatic int cudbg_meminfo_get_mem_index(struct adapter *padap,
114462306a36Sopenharmony_ci				       struct cudbg_meminfo *mem_info,
114562306a36Sopenharmony_ci				       u8 mem_type, u8 *idx)
114662306a36Sopenharmony_ci{
114762306a36Sopenharmony_ci	u8 i, flag;
114862306a36Sopenharmony_ci
114962306a36Sopenharmony_ci	switch (mem_type) {
115062306a36Sopenharmony_ci	case MEM_EDC0:
115162306a36Sopenharmony_ci		flag = EDC0_FLAG;
115262306a36Sopenharmony_ci		break;
115362306a36Sopenharmony_ci	case MEM_EDC1:
115462306a36Sopenharmony_ci		flag = EDC1_FLAG;
115562306a36Sopenharmony_ci		break;
115662306a36Sopenharmony_ci	case MEM_MC0:
115762306a36Sopenharmony_ci		/* Some T5 cards have both MC0 and MC1. */
115862306a36Sopenharmony_ci		flag = is_t5(padap->params.chip) ? MC0_FLAG : MC_FLAG;
115962306a36Sopenharmony_ci		break;
116062306a36Sopenharmony_ci	case MEM_MC1:
116162306a36Sopenharmony_ci		flag = MC1_FLAG;
116262306a36Sopenharmony_ci		break;
116362306a36Sopenharmony_ci	case MEM_HMA:
116462306a36Sopenharmony_ci		flag = HMA_FLAG;
116562306a36Sopenharmony_ci		break;
116662306a36Sopenharmony_ci	default:
116762306a36Sopenharmony_ci		return CUDBG_STATUS_ENTITY_NOT_FOUND;
116862306a36Sopenharmony_ci	}
116962306a36Sopenharmony_ci
117062306a36Sopenharmony_ci	for (i = 0; i < mem_info->avail_c; i++) {
117162306a36Sopenharmony_ci		if (mem_info->avail[i].idx == flag) {
117262306a36Sopenharmony_ci			*idx = i;
117362306a36Sopenharmony_ci			return 0;
117462306a36Sopenharmony_ci		}
117562306a36Sopenharmony_ci	}
117662306a36Sopenharmony_ci
117762306a36Sopenharmony_ci	return CUDBG_STATUS_ENTITY_NOT_FOUND;
117862306a36Sopenharmony_ci}
117962306a36Sopenharmony_ci
118062306a36Sopenharmony_ci/* Fetch the @region_name's start and end from @meminfo. */
118162306a36Sopenharmony_cistatic int cudbg_get_mem_region(struct adapter *padap,
118262306a36Sopenharmony_ci				struct cudbg_meminfo *meminfo,
118362306a36Sopenharmony_ci				u8 mem_type, const char *region_name,
118462306a36Sopenharmony_ci				struct cudbg_mem_desc *mem_desc)
118562306a36Sopenharmony_ci{
118662306a36Sopenharmony_ci	u8 mc, found = 0;
118762306a36Sopenharmony_ci	u32 idx = 0;
118862306a36Sopenharmony_ci	int rc, i;
118962306a36Sopenharmony_ci
119062306a36Sopenharmony_ci	rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc);
119162306a36Sopenharmony_ci	if (rc)
119262306a36Sopenharmony_ci		return rc;
119362306a36Sopenharmony_ci
119462306a36Sopenharmony_ci	i = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
119562306a36Sopenharmony_ci	if (i < 0)
119662306a36Sopenharmony_ci		return -EINVAL;
119762306a36Sopenharmony_ci
119862306a36Sopenharmony_ci	idx = i;
119962306a36Sopenharmony_ci	for (i = 0; i < meminfo->mem_c; i++) {
120062306a36Sopenharmony_ci		if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
120162306a36Sopenharmony_ci			continue; /* Skip holes */
120262306a36Sopenharmony_ci
120362306a36Sopenharmony_ci		if (!(meminfo->mem[i].limit))
120462306a36Sopenharmony_ci			meminfo->mem[i].limit =
120562306a36Sopenharmony_ci				i < meminfo->mem_c - 1 ?
120662306a36Sopenharmony_ci				meminfo->mem[i + 1].base - 1 : ~0;
120762306a36Sopenharmony_ci
120862306a36Sopenharmony_ci		if (meminfo->mem[i].idx == idx) {
120962306a36Sopenharmony_ci			/* Check if the region exists in @mem_type memory */
121062306a36Sopenharmony_ci			if (meminfo->mem[i].base < meminfo->avail[mc].base &&
121162306a36Sopenharmony_ci			    meminfo->mem[i].limit < meminfo->avail[mc].base)
121262306a36Sopenharmony_ci				return -EINVAL;
121362306a36Sopenharmony_ci
121462306a36Sopenharmony_ci			if (meminfo->mem[i].base > meminfo->avail[mc].limit)
121562306a36Sopenharmony_ci				return -EINVAL;
121662306a36Sopenharmony_ci
121762306a36Sopenharmony_ci			memcpy(mem_desc, &meminfo->mem[i],
121862306a36Sopenharmony_ci			       sizeof(struct cudbg_mem_desc));
121962306a36Sopenharmony_ci			found = 1;
122062306a36Sopenharmony_ci			break;
122162306a36Sopenharmony_ci		}
122262306a36Sopenharmony_ci	}
122362306a36Sopenharmony_ci	if (!found)
122462306a36Sopenharmony_ci		return -EINVAL;
122562306a36Sopenharmony_ci
122662306a36Sopenharmony_ci	return 0;
122762306a36Sopenharmony_ci}
122862306a36Sopenharmony_ci
122962306a36Sopenharmony_ci/* Fetch and update the start and end of the requested memory region w.r.t 0
123062306a36Sopenharmony_ci * in the corresponding EDC/MC/HMA.
123162306a36Sopenharmony_ci */
123262306a36Sopenharmony_cistatic int cudbg_get_mem_relative(struct adapter *padap,
123362306a36Sopenharmony_ci				  struct cudbg_meminfo *meminfo,
123462306a36Sopenharmony_ci				  u8 mem_type, u32 *out_base, u32 *out_end)
123562306a36Sopenharmony_ci{
123662306a36Sopenharmony_ci	u8 mc_idx;
123762306a36Sopenharmony_ci	int rc;
123862306a36Sopenharmony_ci
123962306a36Sopenharmony_ci	rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc_idx);
124062306a36Sopenharmony_ci	if (rc)
124162306a36Sopenharmony_ci		return rc;
124262306a36Sopenharmony_ci
124362306a36Sopenharmony_ci	if (*out_base < meminfo->avail[mc_idx].base)
124462306a36Sopenharmony_ci		*out_base = 0;
124562306a36Sopenharmony_ci	else
124662306a36Sopenharmony_ci		*out_base -= meminfo->avail[mc_idx].base;
124762306a36Sopenharmony_ci
124862306a36Sopenharmony_ci	if (*out_end > meminfo->avail[mc_idx].limit)
124962306a36Sopenharmony_ci		*out_end = meminfo->avail[mc_idx].limit;
125062306a36Sopenharmony_ci	else
125162306a36Sopenharmony_ci		*out_end -= meminfo->avail[mc_idx].base;
125262306a36Sopenharmony_ci
125362306a36Sopenharmony_ci	return 0;
125462306a36Sopenharmony_ci}
125562306a36Sopenharmony_ci
125662306a36Sopenharmony_ci/* Get TX and RX Payload region */
125762306a36Sopenharmony_cistatic int cudbg_get_payload_range(struct adapter *padap, u8 mem_type,
125862306a36Sopenharmony_ci				   const char *region_name,
125962306a36Sopenharmony_ci				   struct cudbg_region_info *payload)
126062306a36Sopenharmony_ci{
126162306a36Sopenharmony_ci	struct cudbg_mem_desc mem_desc = { 0 };
126262306a36Sopenharmony_ci	struct cudbg_meminfo meminfo;
126362306a36Sopenharmony_ci	int rc;
126462306a36Sopenharmony_ci
126562306a36Sopenharmony_ci	rc = cudbg_fill_meminfo(padap, &meminfo);
126662306a36Sopenharmony_ci	if (rc)
126762306a36Sopenharmony_ci		return rc;
126862306a36Sopenharmony_ci
126962306a36Sopenharmony_ci	rc = cudbg_get_mem_region(padap, &meminfo, mem_type, region_name,
127062306a36Sopenharmony_ci				  &mem_desc);
127162306a36Sopenharmony_ci	if (rc) {
127262306a36Sopenharmony_ci		payload->exist = false;
127362306a36Sopenharmony_ci		return 0;
127462306a36Sopenharmony_ci	}
127562306a36Sopenharmony_ci
127662306a36Sopenharmony_ci	payload->exist = true;
127762306a36Sopenharmony_ci	payload->start = mem_desc.base;
127862306a36Sopenharmony_ci	payload->end = mem_desc.limit;
127962306a36Sopenharmony_ci
128062306a36Sopenharmony_ci	return cudbg_get_mem_relative(padap, &meminfo, mem_type,
128162306a36Sopenharmony_ci				      &payload->start, &payload->end);
128262306a36Sopenharmony_ci}
128362306a36Sopenharmony_ci
128462306a36Sopenharmony_cistatic int cudbg_memory_read(struct cudbg_init *pdbg_init, int win,
128562306a36Sopenharmony_ci			     int mtype, u32 addr, u32 len, void *hbuf)
128662306a36Sopenharmony_ci{
128762306a36Sopenharmony_ci	u32 win_pf, memoffset, mem_aperture, mem_base;
128862306a36Sopenharmony_ci	struct adapter *adap = pdbg_init->adap;
128962306a36Sopenharmony_ci	u32 pos, offset, resid;
129062306a36Sopenharmony_ci	u32 *res_buf;
129162306a36Sopenharmony_ci	u64 *buf;
129262306a36Sopenharmony_ci	int ret;
129362306a36Sopenharmony_ci
129462306a36Sopenharmony_ci	/* Argument sanity checks ...
129562306a36Sopenharmony_ci	 */
129662306a36Sopenharmony_ci	if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
129762306a36Sopenharmony_ci		return -EINVAL;
129862306a36Sopenharmony_ci
129962306a36Sopenharmony_ci	buf = (u64 *)hbuf;
130062306a36Sopenharmony_ci
130162306a36Sopenharmony_ci	/* Try to do 64-bit reads.  Residual will be handled later. */
130262306a36Sopenharmony_ci	resid = len & 0x7;
130362306a36Sopenharmony_ci	len -= resid;
130462306a36Sopenharmony_ci
130562306a36Sopenharmony_ci	ret = t4_memory_rw_init(adap, win, mtype, &memoffset, &mem_base,
130662306a36Sopenharmony_ci				&mem_aperture);
130762306a36Sopenharmony_ci	if (ret)
130862306a36Sopenharmony_ci		return ret;
130962306a36Sopenharmony_ci
131062306a36Sopenharmony_ci	addr = addr + memoffset;
131162306a36Sopenharmony_ci	win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
131262306a36Sopenharmony_ci
131362306a36Sopenharmony_ci	pos = addr & ~(mem_aperture - 1);
131462306a36Sopenharmony_ci	offset = addr - pos;
131562306a36Sopenharmony_ci
131662306a36Sopenharmony_ci	/* Set up initial PCI-E Memory Window to cover the start of our
131762306a36Sopenharmony_ci	 * transfer.
131862306a36Sopenharmony_ci	 */
131962306a36Sopenharmony_ci	t4_memory_update_win(adap, win, pos | win_pf);
132062306a36Sopenharmony_ci
132162306a36Sopenharmony_ci	/* Transfer data from the adapter */
132262306a36Sopenharmony_ci	while (len > 0) {
132362306a36Sopenharmony_ci		*buf++ = le64_to_cpu((__force __le64)
132462306a36Sopenharmony_ci				     t4_read_reg64(adap, mem_base + offset));
132562306a36Sopenharmony_ci		offset += sizeof(u64);
132662306a36Sopenharmony_ci		len -= sizeof(u64);
132762306a36Sopenharmony_ci
132862306a36Sopenharmony_ci		/* If we've reached the end of our current window aperture,
132962306a36Sopenharmony_ci		 * move the PCI-E Memory Window on to the next.
133062306a36Sopenharmony_ci		 */
133162306a36Sopenharmony_ci		if (offset == mem_aperture) {
133262306a36Sopenharmony_ci			pos += mem_aperture;
133362306a36Sopenharmony_ci			offset = 0;
133462306a36Sopenharmony_ci			t4_memory_update_win(adap, win, pos | win_pf);
133562306a36Sopenharmony_ci		}
133662306a36Sopenharmony_ci	}
133762306a36Sopenharmony_ci
133862306a36Sopenharmony_ci	res_buf = (u32 *)buf;
133962306a36Sopenharmony_ci	/* Read residual in 32-bit multiples */
134062306a36Sopenharmony_ci	while (resid > sizeof(u32)) {
134162306a36Sopenharmony_ci		*res_buf++ = le32_to_cpu((__force __le32)
134262306a36Sopenharmony_ci					 t4_read_reg(adap, mem_base + offset));
134362306a36Sopenharmony_ci		offset += sizeof(u32);
134462306a36Sopenharmony_ci		resid -= sizeof(u32);
134562306a36Sopenharmony_ci
134662306a36Sopenharmony_ci		/* If we've reached the end of our current window aperture,
134762306a36Sopenharmony_ci		 * move the PCI-E Memory Window on to the next.
134862306a36Sopenharmony_ci		 */
134962306a36Sopenharmony_ci		if (offset == mem_aperture) {
135062306a36Sopenharmony_ci			pos += mem_aperture;
135162306a36Sopenharmony_ci			offset = 0;
135262306a36Sopenharmony_ci			t4_memory_update_win(adap, win, pos | win_pf);
135362306a36Sopenharmony_ci		}
135462306a36Sopenharmony_ci	}
135562306a36Sopenharmony_ci
135662306a36Sopenharmony_ci	/* Transfer residual < 32-bits */
135762306a36Sopenharmony_ci	if (resid)
135862306a36Sopenharmony_ci		t4_memory_rw_residual(adap, resid, mem_base + offset,
135962306a36Sopenharmony_ci				      (u8 *)res_buf, T4_MEMORY_READ);
136062306a36Sopenharmony_ci
136162306a36Sopenharmony_ci	return 0;
136262306a36Sopenharmony_ci}
136362306a36Sopenharmony_ci
136462306a36Sopenharmony_ci#define CUDBG_YIELD_ITERATION 256
136562306a36Sopenharmony_ci
136662306a36Sopenharmony_cistatic int cudbg_read_fw_mem(struct cudbg_init *pdbg_init,
136762306a36Sopenharmony_ci			     struct cudbg_buffer *dbg_buff, u8 mem_type,
136862306a36Sopenharmony_ci			     unsigned long tot_len,
136962306a36Sopenharmony_ci			     struct cudbg_error *cudbg_err)
137062306a36Sopenharmony_ci{
137162306a36Sopenharmony_ci	static const char * const region_name[] = { "Tx payload:",
137262306a36Sopenharmony_ci						    "Rx payload:" };
137362306a36Sopenharmony_ci	unsigned long bytes, bytes_left, bytes_read = 0;
137462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
137562306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
137662306a36Sopenharmony_ci	struct cudbg_region_info payload[2];
137762306a36Sopenharmony_ci	u32 yield_count = 0;
137862306a36Sopenharmony_ci	int rc = 0;
137962306a36Sopenharmony_ci	u8 i;
138062306a36Sopenharmony_ci
138162306a36Sopenharmony_ci	/* Get TX/RX Payload region range if they exist */
138262306a36Sopenharmony_ci	memset(payload, 0, sizeof(payload));
138362306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(region_name); i++) {
138462306a36Sopenharmony_ci		rc = cudbg_get_payload_range(padap, mem_type, region_name[i],
138562306a36Sopenharmony_ci					     &payload[i]);
138662306a36Sopenharmony_ci		if (rc)
138762306a36Sopenharmony_ci			return rc;
138862306a36Sopenharmony_ci
138962306a36Sopenharmony_ci		if (payload[i].exist) {
139062306a36Sopenharmony_ci			/* Align start and end to avoid wrap around */
139162306a36Sopenharmony_ci			payload[i].start = roundup(payload[i].start,
139262306a36Sopenharmony_ci						   CUDBG_CHUNK_SIZE);
139362306a36Sopenharmony_ci			payload[i].end = rounddown(payload[i].end,
139462306a36Sopenharmony_ci						   CUDBG_CHUNK_SIZE);
139562306a36Sopenharmony_ci		}
139662306a36Sopenharmony_ci	}
139762306a36Sopenharmony_ci
139862306a36Sopenharmony_ci	bytes_left = tot_len;
139962306a36Sopenharmony_ci	while (bytes_left > 0) {
140062306a36Sopenharmony_ci		/* As MC size is huge and read through PIO access, this
140162306a36Sopenharmony_ci		 * loop will hold cpu for a longer time. OS may think that
140262306a36Sopenharmony_ci		 * the process is hanged and will generate CPU stall traces.
140362306a36Sopenharmony_ci		 * So yield the cpu regularly.
140462306a36Sopenharmony_ci		 */
140562306a36Sopenharmony_ci		yield_count++;
140662306a36Sopenharmony_ci		if (!(yield_count % CUDBG_YIELD_ITERATION))
140762306a36Sopenharmony_ci			schedule();
140862306a36Sopenharmony_ci
140962306a36Sopenharmony_ci		bytes = min_t(unsigned long, bytes_left,
141062306a36Sopenharmony_ci			      (unsigned long)CUDBG_CHUNK_SIZE);
141162306a36Sopenharmony_ci		rc = cudbg_get_buff(pdbg_init, dbg_buff, bytes, &temp_buff);
141262306a36Sopenharmony_ci		if (rc)
141362306a36Sopenharmony_ci			return rc;
141462306a36Sopenharmony_ci
141562306a36Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(payload); i++)
141662306a36Sopenharmony_ci			if (payload[i].exist &&
141762306a36Sopenharmony_ci			    bytes_read >= payload[i].start &&
141862306a36Sopenharmony_ci			    bytes_read + bytes <= payload[i].end)
141962306a36Sopenharmony_ci				/* TX and RX Payload regions can't overlap */
142062306a36Sopenharmony_ci				goto skip_read;
142162306a36Sopenharmony_ci
142262306a36Sopenharmony_ci		spin_lock(&padap->win0_lock);
142362306a36Sopenharmony_ci		rc = cudbg_memory_read(pdbg_init, MEMWIN_NIC, mem_type,
142462306a36Sopenharmony_ci				       bytes_read, bytes, temp_buff.data);
142562306a36Sopenharmony_ci		spin_unlock(&padap->win0_lock);
142662306a36Sopenharmony_ci		if (rc) {
142762306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
142862306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
142962306a36Sopenharmony_ci			return rc;
143062306a36Sopenharmony_ci		}
143162306a36Sopenharmony_ci
143262306a36Sopenharmony_ciskip_read:
143362306a36Sopenharmony_ci		bytes_left -= bytes;
143462306a36Sopenharmony_ci		bytes_read += bytes;
143562306a36Sopenharmony_ci		rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
143662306a36Sopenharmony_ci						  dbg_buff);
143762306a36Sopenharmony_ci		if (rc) {
143862306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
143962306a36Sopenharmony_ci			return rc;
144062306a36Sopenharmony_ci		}
144162306a36Sopenharmony_ci	}
144262306a36Sopenharmony_ci	return rc;
144362306a36Sopenharmony_ci}
144462306a36Sopenharmony_ci
144562306a36Sopenharmony_cistatic void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
144662306a36Sopenharmony_ci			     struct cudbg_error *cudbg_err)
144762306a36Sopenharmony_ci{
144862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
144962306a36Sopenharmony_ci	int rc;
145062306a36Sopenharmony_ci
145162306a36Sopenharmony_ci	if (is_fw_attached(pdbg_init)) {
145262306a36Sopenharmony_ci		/* Flush uP dcache before reading edcX/mcX  */
145362306a36Sopenharmony_ci		rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
145462306a36Sopenharmony_ci		if (rc)
145562306a36Sopenharmony_ci			cudbg_err->sys_warn = rc;
145662306a36Sopenharmony_ci	}
145762306a36Sopenharmony_ci}
145862306a36Sopenharmony_ci
145962306a36Sopenharmony_cistatic int cudbg_mem_region_size(struct cudbg_init *pdbg_init,
146062306a36Sopenharmony_ci				 struct cudbg_error *cudbg_err,
146162306a36Sopenharmony_ci				 u8 mem_type, unsigned long *region_size)
146262306a36Sopenharmony_ci{
146362306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
146462306a36Sopenharmony_ci	struct cudbg_meminfo mem_info;
146562306a36Sopenharmony_ci	u8 mc_idx;
146662306a36Sopenharmony_ci	int rc;
146762306a36Sopenharmony_ci
146862306a36Sopenharmony_ci	memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
146962306a36Sopenharmony_ci	rc = cudbg_fill_meminfo(padap, &mem_info);
147062306a36Sopenharmony_ci	if (rc) {
147162306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
147262306a36Sopenharmony_ci		return rc;
147362306a36Sopenharmony_ci	}
147462306a36Sopenharmony_ci
147562306a36Sopenharmony_ci	cudbg_t4_fwcache(pdbg_init, cudbg_err);
147662306a36Sopenharmony_ci	rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
147762306a36Sopenharmony_ci	if (rc) {
147862306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
147962306a36Sopenharmony_ci		return rc;
148062306a36Sopenharmony_ci	}
148162306a36Sopenharmony_ci
148262306a36Sopenharmony_ci	if (region_size)
148362306a36Sopenharmony_ci		*region_size = mem_info.avail[mc_idx].limit -
148462306a36Sopenharmony_ci			       mem_info.avail[mc_idx].base;
148562306a36Sopenharmony_ci
148662306a36Sopenharmony_ci	return 0;
148762306a36Sopenharmony_ci}
148862306a36Sopenharmony_ci
148962306a36Sopenharmony_cistatic int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
149062306a36Sopenharmony_ci				    struct cudbg_buffer *dbg_buff,
149162306a36Sopenharmony_ci				    struct cudbg_error *cudbg_err,
149262306a36Sopenharmony_ci				    u8 mem_type)
149362306a36Sopenharmony_ci{
149462306a36Sopenharmony_ci	unsigned long size = 0;
149562306a36Sopenharmony_ci	int rc;
149662306a36Sopenharmony_ci
149762306a36Sopenharmony_ci	rc = cudbg_mem_region_size(pdbg_init, cudbg_err, mem_type, &size);
149862306a36Sopenharmony_ci	if (rc)
149962306a36Sopenharmony_ci		return rc;
150062306a36Sopenharmony_ci
150162306a36Sopenharmony_ci	return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
150262306a36Sopenharmony_ci				 cudbg_err);
150362306a36Sopenharmony_ci}
150462306a36Sopenharmony_ci
150562306a36Sopenharmony_ciint cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
150662306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
150762306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
150862306a36Sopenharmony_ci{
150962306a36Sopenharmony_ci	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
151062306a36Sopenharmony_ci					MEM_EDC0);
151162306a36Sopenharmony_ci}
151262306a36Sopenharmony_ci
151362306a36Sopenharmony_ciint cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
151462306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
151562306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
151662306a36Sopenharmony_ci{
151762306a36Sopenharmony_ci	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
151862306a36Sopenharmony_ci					MEM_EDC1);
151962306a36Sopenharmony_ci}
152062306a36Sopenharmony_ci
152162306a36Sopenharmony_ciint cudbg_collect_mc0_meminfo(struct cudbg_init *pdbg_init,
152262306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
152362306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
152462306a36Sopenharmony_ci{
152562306a36Sopenharmony_ci	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
152662306a36Sopenharmony_ci					MEM_MC0);
152762306a36Sopenharmony_ci}
152862306a36Sopenharmony_ci
152962306a36Sopenharmony_ciint cudbg_collect_mc1_meminfo(struct cudbg_init *pdbg_init,
153062306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
153162306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
153262306a36Sopenharmony_ci{
153362306a36Sopenharmony_ci	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
153462306a36Sopenharmony_ci					MEM_MC1);
153562306a36Sopenharmony_ci}
153662306a36Sopenharmony_ci
153762306a36Sopenharmony_ciint cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,
153862306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
153962306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
154062306a36Sopenharmony_ci{
154162306a36Sopenharmony_ci	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
154262306a36Sopenharmony_ci					MEM_HMA);
154362306a36Sopenharmony_ci}
154462306a36Sopenharmony_ci
154562306a36Sopenharmony_ciint cudbg_collect_rss(struct cudbg_init *pdbg_init,
154662306a36Sopenharmony_ci		      struct cudbg_buffer *dbg_buff,
154762306a36Sopenharmony_ci		      struct cudbg_error *cudbg_err)
154862306a36Sopenharmony_ci{
154962306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
155062306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
155162306a36Sopenharmony_ci	int rc, nentries;
155262306a36Sopenharmony_ci
155362306a36Sopenharmony_ci	nentries = t4_chip_rss_size(padap);
155462306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, nentries * sizeof(u16),
155562306a36Sopenharmony_ci			    &temp_buff);
155662306a36Sopenharmony_ci	if (rc)
155762306a36Sopenharmony_ci		return rc;
155862306a36Sopenharmony_ci
155962306a36Sopenharmony_ci	rc = t4_read_rss(padap, (u16 *)temp_buff.data);
156062306a36Sopenharmony_ci	if (rc) {
156162306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
156262306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
156362306a36Sopenharmony_ci		return rc;
156462306a36Sopenharmony_ci	}
156562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
156662306a36Sopenharmony_ci}
156762306a36Sopenharmony_ci
156862306a36Sopenharmony_ciint cudbg_collect_rss_vf_config(struct cudbg_init *pdbg_init,
156962306a36Sopenharmony_ci				struct cudbg_buffer *dbg_buff,
157062306a36Sopenharmony_ci				struct cudbg_error *cudbg_err)
157162306a36Sopenharmony_ci{
157262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
157362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
157462306a36Sopenharmony_ci	struct cudbg_rss_vf_conf *vfconf;
157562306a36Sopenharmony_ci	int vf, rc, vf_count;
157662306a36Sopenharmony_ci
157762306a36Sopenharmony_ci	vf_count = padap->params.arch.vfcount;
157862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff,
157962306a36Sopenharmony_ci			    vf_count * sizeof(struct cudbg_rss_vf_conf),
158062306a36Sopenharmony_ci			    &temp_buff);
158162306a36Sopenharmony_ci	if (rc)
158262306a36Sopenharmony_ci		return rc;
158362306a36Sopenharmony_ci
158462306a36Sopenharmony_ci	vfconf = (struct cudbg_rss_vf_conf *)temp_buff.data;
158562306a36Sopenharmony_ci	for (vf = 0; vf < vf_count; vf++)
158662306a36Sopenharmony_ci		t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
158762306a36Sopenharmony_ci				      &vfconf[vf].rss_vf_vfh, true);
158862306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
158962306a36Sopenharmony_ci}
159062306a36Sopenharmony_ci
159162306a36Sopenharmony_ciint cudbg_collect_path_mtu(struct cudbg_init *pdbg_init,
159262306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
159362306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
159462306a36Sopenharmony_ci{
159562306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
159662306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
159762306a36Sopenharmony_ci	int rc;
159862306a36Sopenharmony_ci
159962306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, NMTUS * sizeof(u16),
160062306a36Sopenharmony_ci			    &temp_buff);
160162306a36Sopenharmony_ci	if (rc)
160262306a36Sopenharmony_ci		return rc;
160362306a36Sopenharmony_ci
160462306a36Sopenharmony_ci	t4_read_mtu_tbl(padap, (u16 *)temp_buff.data, NULL);
160562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
160662306a36Sopenharmony_ci}
160762306a36Sopenharmony_ci
160862306a36Sopenharmony_ciint cudbg_collect_pm_stats(struct cudbg_init *pdbg_init,
160962306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
161062306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
161162306a36Sopenharmony_ci{
161262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
161362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
161462306a36Sopenharmony_ci	struct cudbg_pm_stats *pm_stats_buff;
161562306a36Sopenharmony_ci	int rc;
161662306a36Sopenharmony_ci
161762306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_pm_stats),
161862306a36Sopenharmony_ci			    &temp_buff);
161962306a36Sopenharmony_ci	if (rc)
162062306a36Sopenharmony_ci		return rc;
162162306a36Sopenharmony_ci
162262306a36Sopenharmony_ci	pm_stats_buff = (struct cudbg_pm_stats *)temp_buff.data;
162362306a36Sopenharmony_ci	t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
162462306a36Sopenharmony_ci	t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
162562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
162662306a36Sopenharmony_ci}
162762306a36Sopenharmony_ci
162862306a36Sopenharmony_ciint cudbg_collect_hw_sched(struct cudbg_init *pdbg_init,
162962306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
163062306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
163162306a36Sopenharmony_ci{
163262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
163362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
163462306a36Sopenharmony_ci	struct cudbg_hw_sched *hw_sched_buff;
163562306a36Sopenharmony_ci	int i, rc = 0;
163662306a36Sopenharmony_ci
163762306a36Sopenharmony_ci	if (!padap->params.vpd.cclk)
163862306a36Sopenharmony_ci		return CUDBG_STATUS_CCLK_NOT_DEFINED;
163962306a36Sopenharmony_ci
164062306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_hw_sched),
164162306a36Sopenharmony_ci			    &temp_buff);
164262306a36Sopenharmony_ci
164362306a36Sopenharmony_ci	if (rc)
164462306a36Sopenharmony_ci		return rc;
164562306a36Sopenharmony_ci
164662306a36Sopenharmony_ci	hw_sched_buff = (struct cudbg_hw_sched *)temp_buff.data;
164762306a36Sopenharmony_ci	hw_sched_buff->map = t4_read_reg(padap, TP_TX_MOD_QUEUE_REQ_MAP_A);
164862306a36Sopenharmony_ci	hw_sched_buff->mode = TIMERMODE_G(t4_read_reg(padap, TP_MOD_CONFIG_A));
164962306a36Sopenharmony_ci	t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
165062306a36Sopenharmony_ci	for (i = 0; i < NTX_SCHED; ++i)
165162306a36Sopenharmony_ci		t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
165262306a36Sopenharmony_ci				&hw_sched_buff->ipg[i], true);
165362306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
165462306a36Sopenharmony_ci}
165562306a36Sopenharmony_ci
165662306a36Sopenharmony_ciint cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
165762306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
165862306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
165962306a36Sopenharmony_ci{
166062306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
166162306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
166262306a36Sopenharmony_ci	struct ireg_buf *ch_tp_pio;
166362306a36Sopenharmony_ci	int i, rc, n = 0;
166462306a36Sopenharmony_ci	u32 size;
166562306a36Sopenharmony_ci
166662306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
166762306a36Sopenharmony_ci		n = sizeof(t5_tp_pio_array) +
166862306a36Sopenharmony_ci		    sizeof(t5_tp_tm_pio_array) +
166962306a36Sopenharmony_ci		    sizeof(t5_tp_mib_index_array);
167062306a36Sopenharmony_ci	else
167162306a36Sopenharmony_ci		n = sizeof(t6_tp_pio_array) +
167262306a36Sopenharmony_ci		    sizeof(t6_tp_tm_pio_array) +
167362306a36Sopenharmony_ci		    sizeof(t6_tp_mib_index_array);
167462306a36Sopenharmony_ci
167562306a36Sopenharmony_ci	n = n / (IREG_NUM_ELEM * sizeof(u32));
167662306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n;
167762306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
167862306a36Sopenharmony_ci	if (rc)
167962306a36Sopenharmony_ci		return rc;
168062306a36Sopenharmony_ci
168162306a36Sopenharmony_ci	ch_tp_pio = (struct ireg_buf *)temp_buff.data;
168262306a36Sopenharmony_ci
168362306a36Sopenharmony_ci	/* TP_PIO */
168462306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
168562306a36Sopenharmony_ci		n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
168662306a36Sopenharmony_ci	else if (is_t6(padap->params.chip))
168762306a36Sopenharmony_ci		n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
168862306a36Sopenharmony_ci
168962306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
169062306a36Sopenharmony_ci		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
169162306a36Sopenharmony_ci		u32 *buff = ch_tp_pio->outbuf;
169262306a36Sopenharmony_ci
169362306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
169462306a36Sopenharmony_ci			tp_pio->ireg_addr = t5_tp_pio_array[i][0];
169562306a36Sopenharmony_ci			tp_pio->ireg_data = t5_tp_pio_array[i][1];
169662306a36Sopenharmony_ci			tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
169762306a36Sopenharmony_ci			tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
169862306a36Sopenharmony_ci		} else if (is_t6(padap->params.chip)) {
169962306a36Sopenharmony_ci			tp_pio->ireg_addr = t6_tp_pio_array[i][0];
170062306a36Sopenharmony_ci			tp_pio->ireg_data = t6_tp_pio_array[i][1];
170162306a36Sopenharmony_ci			tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
170262306a36Sopenharmony_ci			tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
170362306a36Sopenharmony_ci		}
170462306a36Sopenharmony_ci		t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
170562306a36Sopenharmony_ci			       tp_pio->ireg_local_offset, true);
170662306a36Sopenharmony_ci		ch_tp_pio++;
170762306a36Sopenharmony_ci	}
170862306a36Sopenharmony_ci
170962306a36Sopenharmony_ci	/* TP_TM_PIO */
171062306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
171162306a36Sopenharmony_ci		n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
171262306a36Sopenharmony_ci	else if (is_t6(padap->params.chip))
171362306a36Sopenharmony_ci		n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
171462306a36Sopenharmony_ci
171562306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
171662306a36Sopenharmony_ci		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
171762306a36Sopenharmony_ci		u32 *buff = ch_tp_pio->outbuf;
171862306a36Sopenharmony_ci
171962306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
172062306a36Sopenharmony_ci			tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
172162306a36Sopenharmony_ci			tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
172262306a36Sopenharmony_ci			tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
172362306a36Sopenharmony_ci			tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
172462306a36Sopenharmony_ci		} else if (is_t6(padap->params.chip)) {
172562306a36Sopenharmony_ci			tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
172662306a36Sopenharmony_ci			tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
172762306a36Sopenharmony_ci			tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
172862306a36Sopenharmony_ci			tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
172962306a36Sopenharmony_ci		}
173062306a36Sopenharmony_ci		t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
173162306a36Sopenharmony_ci				  tp_pio->ireg_local_offset, true);
173262306a36Sopenharmony_ci		ch_tp_pio++;
173362306a36Sopenharmony_ci	}
173462306a36Sopenharmony_ci
173562306a36Sopenharmony_ci	/* TP_MIB_INDEX */
173662306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
173762306a36Sopenharmony_ci		n = sizeof(t5_tp_mib_index_array) /
173862306a36Sopenharmony_ci		    (IREG_NUM_ELEM * sizeof(u32));
173962306a36Sopenharmony_ci	else if (is_t6(padap->params.chip))
174062306a36Sopenharmony_ci		n = sizeof(t6_tp_mib_index_array) /
174162306a36Sopenharmony_ci		    (IREG_NUM_ELEM * sizeof(u32));
174262306a36Sopenharmony_ci
174362306a36Sopenharmony_ci	for (i = 0; i < n ; i++) {
174462306a36Sopenharmony_ci		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
174562306a36Sopenharmony_ci		u32 *buff = ch_tp_pio->outbuf;
174662306a36Sopenharmony_ci
174762306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
174862306a36Sopenharmony_ci			tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
174962306a36Sopenharmony_ci			tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
175062306a36Sopenharmony_ci			tp_pio->ireg_local_offset =
175162306a36Sopenharmony_ci				t5_tp_mib_index_array[i][2];
175262306a36Sopenharmony_ci			tp_pio->ireg_offset_range =
175362306a36Sopenharmony_ci				t5_tp_mib_index_array[i][3];
175462306a36Sopenharmony_ci		} else if (is_t6(padap->params.chip)) {
175562306a36Sopenharmony_ci			tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
175662306a36Sopenharmony_ci			tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
175762306a36Sopenharmony_ci			tp_pio->ireg_local_offset =
175862306a36Sopenharmony_ci				t6_tp_mib_index_array[i][2];
175962306a36Sopenharmony_ci			tp_pio->ireg_offset_range =
176062306a36Sopenharmony_ci				t6_tp_mib_index_array[i][3];
176162306a36Sopenharmony_ci		}
176262306a36Sopenharmony_ci		t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
176362306a36Sopenharmony_ci			       tp_pio->ireg_local_offset, true);
176462306a36Sopenharmony_ci		ch_tp_pio++;
176562306a36Sopenharmony_ci	}
176662306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
176762306a36Sopenharmony_ci}
176862306a36Sopenharmony_ci
176962306a36Sopenharmony_cistatic void cudbg_read_sge_qbase_indirect_reg(struct adapter *padap,
177062306a36Sopenharmony_ci					      struct sge_qbase_reg_field *qbase,
177162306a36Sopenharmony_ci					      u32 func, bool is_pf)
177262306a36Sopenharmony_ci{
177362306a36Sopenharmony_ci	u32 *buff, i;
177462306a36Sopenharmony_ci
177562306a36Sopenharmony_ci	if (is_pf) {
177662306a36Sopenharmony_ci		buff = qbase->pf_data_value[func];
177762306a36Sopenharmony_ci	} else {
177862306a36Sopenharmony_ci		buff = qbase->vf_data_value[func];
177962306a36Sopenharmony_ci		/* In SGE_QBASE_INDEX,
178062306a36Sopenharmony_ci		 * Entries 0->7 are PF0->7, Entries 8->263 are VFID0->256.
178162306a36Sopenharmony_ci		 */
178262306a36Sopenharmony_ci		func += 8;
178362306a36Sopenharmony_ci	}
178462306a36Sopenharmony_ci
178562306a36Sopenharmony_ci	t4_write_reg(padap, qbase->reg_addr, func);
178662306a36Sopenharmony_ci	for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++, buff++)
178762306a36Sopenharmony_ci		*buff = t4_read_reg(padap, qbase->reg_data[i]);
178862306a36Sopenharmony_ci}
178962306a36Sopenharmony_ci
179062306a36Sopenharmony_ciint cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
179162306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
179262306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
179362306a36Sopenharmony_ci{
179462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
179562306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
179662306a36Sopenharmony_ci	struct sge_qbase_reg_field *sge_qbase;
179762306a36Sopenharmony_ci	struct ireg_buf *ch_sge_dbg;
179862306a36Sopenharmony_ci	u8 padap_running = 0;
179962306a36Sopenharmony_ci	int i, rc;
180062306a36Sopenharmony_ci	u32 size;
180162306a36Sopenharmony_ci
180262306a36Sopenharmony_ci	/* Accessing SGE_QBASE_MAP[0-3] and SGE_QBASE_INDEX regs can
180362306a36Sopenharmony_ci	 * lead to SGE missing doorbells under heavy traffic. So, only
180462306a36Sopenharmony_ci	 * collect them when adapter is idle.
180562306a36Sopenharmony_ci	 */
180662306a36Sopenharmony_ci	for_each_port(padap, i) {
180762306a36Sopenharmony_ci		padap_running = netif_running(padap->port[i]);
180862306a36Sopenharmony_ci		if (padap_running)
180962306a36Sopenharmony_ci			break;
181062306a36Sopenharmony_ci	}
181162306a36Sopenharmony_ci
181262306a36Sopenharmony_ci	size = sizeof(*ch_sge_dbg) * 2;
181362306a36Sopenharmony_ci	if (!padap_running)
181462306a36Sopenharmony_ci		size += sizeof(*sge_qbase);
181562306a36Sopenharmony_ci
181662306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
181762306a36Sopenharmony_ci	if (rc)
181862306a36Sopenharmony_ci		return rc;
181962306a36Sopenharmony_ci
182062306a36Sopenharmony_ci	ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
182162306a36Sopenharmony_ci	for (i = 0; i < 2; i++) {
182262306a36Sopenharmony_ci		struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
182362306a36Sopenharmony_ci		u32 *buff = ch_sge_dbg->outbuf;
182462306a36Sopenharmony_ci
182562306a36Sopenharmony_ci		sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
182662306a36Sopenharmony_ci		sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
182762306a36Sopenharmony_ci		sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
182862306a36Sopenharmony_ci		sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
182962306a36Sopenharmony_ci		t4_read_indirect(padap,
183062306a36Sopenharmony_ci				 sge_pio->ireg_addr,
183162306a36Sopenharmony_ci				 sge_pio->ireg_data,
183262306a36Sopenharmony_ci				 buff,
183362306a36Sopenharmony_ci				 sge_pio->ireg_offset_range,
183462306a36Sopenharmony_ci				 sge_pio->ireg_local_offset);
183562306a36Sopenharmony_ci		ch_sge_dbg++;
183662306a36Sopenharmony_ci	}
183762306a36Sopenharmony_ci
183862306a36Sopenharmony_ci	if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5 &&
183962306a36Sopenharmony_ci	    !padap_running) {
184062306a36Sopenharmony_ci		sge_qbase = (struct sge_qbase_reg_field *)ch_sge_dbg;
184162306a36Sopenharmony_ci		/* 1 addr reg SGE_QBASE_INDEX and 4 data reg
184262306a36Sopenharmony_ci		 * SGE_QBASE_MAP[0-3]
184362306a36Sopenharmony_ci		 */
184462306a36Sopenharmony_ci		sge_qbase->reg_addr = t6_sge_qbase_index_array[0];
184562306a36Sopenharmony_ci		for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++)
184662306a36Sopenharmony_ci			sge_qbase->reg_data[i] =
184762306a36Sopenharmony_ci				t6_sge_qbase_index_array[i + 1];
184862306a36Sopenharmony_ci
184962306a36Sopenharmony_ci		for (i = 0; i <= PCIE_FW_MASTER_M; i++)
185062306a36Sopenharmony_ci			cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
185162306a36Sopenharmony_ci							  i, true);
185262306a36Sopenharmony_ci
185362306a36Sopenharmony_ci		for (i = 0; i < padap->params.arch.vfcount; i++)
185462306a36Sopenharmony_ci			cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
185562306a36Sopenharmony_ci							  i, false);
185662306a36Sopenharmony_ci
185762306a36Sopenharmony_ci		sge_qbase->vfcount = padap->params.arch.vfcount;
185862306a36Sopenharmony_ci	}
185962306a36Sopenharmony_ci
186062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
186162306a36Sopenharmony_ci}
186262306a36Sopenharmony_ci
186362306a36Sopenharmony_ciint cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
186462306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
186562306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
186662306a36Sopenharmony_ci{
186762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
186862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
186962306a36Sopenharmony_ci	struct cudbg_ulprx_la *ulprx_la_buff;
187062306a36Sopenharmony_ci	int rc;
187162306a36Sopenharmony_ci
187262306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_ulprx_la),
187362306a36Sopenharmony_ci			    &temp_buff);
187462306a36Sopenharmony_ci	if (rc)
187562306a36Sopenharmony_ci		return rc;
187662306a36Sopenharmony_ci
187762306a36Sopenharmony_ci	ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
187862306a36Sopenharmony_ci	t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
187962306a36Sopenharmony_ci	ulprx_la_buff->size = ULPRX_LA_SIZE;
188062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
188162306a36Sopenharmony_ci}
188262306a36Sopenharmony_ci
188362306a36Sopenharmony_ciint cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
188462306a36Sopenharmony_ci			struct cudbg_buffer *dbg_buff,
188562306a36Sopenharmony_ci			struct cudbg_error *cudbg_err)
188662306a36Sopenharmony_ci{
188762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
188862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
188962306a36Sopenharmony_ci	struct cudbg_tp_la *tp_la_buff;
189062306a36Sopenharmony_ci	int size, rc;
189162306a36Sopenharmony_ci
189262306a36Sopenharmony_ci	size = sizeof(struct cudbg_tp_la) + TPLA_SIZE *  sizeof(u64);
189362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
189462306a36Sopenharmony_ci	if (rc)
189562306a36Sopenharmony_ci		return rc;
189662306a36Sopenharmony_ci
189762306a36Sopenharmony_ci	tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
189862306a36Sopenharmony_ci	tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
189962306a36Sopenharmony_ci	t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
190062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
190162306a36Sopenharmony_ci}
190262306a36Sopenharmony_ci
190362306a36Sopenharmony_ciint cudbg_collect_meminfo(struct cudbg_init *pdbg_init,
190462306a36Sopenharmony_ci			  struct cudbg_buffer *dbg_buff,
190562306a36Sopenharmony_ci			  struct cudbg_error *cudbg_err)
190662306a36Sopenharmony_ci{
190762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
190862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
190962306a36Sopenharmony_ci	struct cudbg_meminfo *meminfo_buff;
191062306a36Sopenharmony_ci	struct cudbg_ver_hdr *ver_hdr;
191162306a36Sopenharmony_ci	int rc;
191262306a36Sopenharmony_ci
191362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff,
191462306a36Sopenharmony_ci			    sizeof(struct cudbg_ver_hdr) +
191562306a36Sopenharmony_ci			    sizeof(struct cudbg_meminfo),
191662306a36Sopenharmony_ci			    &temp_buff);
191762306a36Sopenharmony_ci	if (rc)
191862306a36Sopenharmony_ci		return rc;
191962306a36Sopenharmony_ci
192062306a36Sopenharmony_ci	ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
192162306a36Sopenharmony_ci	ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
192262306a36Sopenharmony_ci	ver_hdr->revision = CUDBG_MEMINFO_REV;
192362306a36Sopenharmony_ci	ver_hdr->size = sizeof(struct cudbg_meminfo);
192462306a36Sopenharmony_ci
192562306a36Sopenharmony_ci	meminfo_buff = (struct cudbg_meminfo *)(temp_buff.data +
192662306a36Sopenharmony_ci						sizeof(*ver_hdr));
192762306a36Sopenharmony_ci	rc = cudbg_fill_meminfo(padap, meminfo_buff);
192862306a36Sopenharmony_ci	if (rc) {
192962306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
193062306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
193162306a36Sopenharmony_ci		return rc;
193262306a36Sopenharmony_ci	}
193362306a36Sopenharmony_ci
193462306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
193562306a36Sopenharmony_ci}
193662306a36Sopenharmony_ci
193762306a36Sopenharmony_ciint cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
193862306a36Sopenharmony_ci			     struct cudbg_buffer *dbg_buff,
193962306a36Sopenharmony_ci			     struct cudbg_error *cudbg_err)
194062306a36Sopenharmony_ci{
194162306a36Sopenharmony_ci	struct cudbg_cim_pif_la *cim_pif_la_buff;
194262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
194362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
194462306a36Sopenharmony_ci	int size, rc;
194562306a36Sopenharmony_ci
194662306a36Sopenharmony_ci	size = sizeof(struct cudbg_cim_pif_la) +
194762306a36Sopenharmony_ci	       2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
194862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
194962306a36Sopenharmony_ci	if (rc)
195062306a36Sopenharmony_ci		return rc;
195162306a36Sopenharmony_ci
195262306a36Sopenharmony_ci	cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
195362306a36Sopenharmony_ci	cim_pif_la_buff->size = CIM_PIFLA_SIZE;
195462306a36Sopenharmony_ci	t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
195562306a36Sopenharmony_ci			   (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
195662306a36Sopenharmony_ci			   NULL, NULL);
195762306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
195862306a36Sopenharmony_ci}
195962306a36Sopenharmony_ci
196062306a36Sopenharmony_ciint cudbg_collect_clk_info(struct cudbg_init *pdbg_init,
196162306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
196262306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
196362306a36Sopenharmony_ci{
196462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
196562306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
196662306a36Sopenharmony_ci	struct cudbg_clk_info *clk_info_buff;
196762306a36Sopenharmony_ci	u64 tp_tick_us;
196862306a36Sopenharmony_ci	int rc;
196962306a36Sopenharmony_ci
197062306a36Sopenharmony_ci	if (!padap->params.vpd.cclk)
197162306a36Sopenharmony_ci		return CUDBG_STATUS_CCLK_NOT_DEFINED;
197262306a36Sopenharmony_ci
197362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_clk_info),
197462306a36Sopenharmony_ci			    &temp_buff);
197562306a36Sopenharmony_ci	if (rc)
197662306a36Sopenharmony_ci		return rc;
197762306a36Sopenharmony_ci
197862306a36Sopenharmony_ci	clk_info_buff = (struct cudbg_clk_info *)temp_buff.data;
197962306a36Sopenharmony_ci	clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk; /* psec */
198062306a36Sopenharmony_ci	clk_info_buff->res = t4_read_reg(padap, TP_TIMER_RESOLUTION_A);
198162306a36Sopenharmony_ci	clk_info_buff->tre = TIMERRESOLUTION_G(clk_info_buff->res);
198262306a36Sopenharmony_ci	clk_info_buff->dack_re = DELAYEDACKRESOLUTION_G(clk_info_buff->res);
198362306a36Sopenharmony_ci	tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
198462306a36Sopenharmony_ci
198562306a36Sopenharmony_ci	clk_info_buff->dack_timer =
198662306a36Sopenharmony_ci		(clk_info_buff->cclk_ps << clk_info_buff->dack_re) / 1000000 *
198762306a36Sopenharmony_ci		t4_read_reg(padap, TP_DACK_TIMER_A);
198862306a36Sopenharmony_ci	clk_info_buff->retransmit_min =
198962306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_RXT_MIN_A);
199062306a36Sopenharmony_ci	clk_info_buff->retransmit_max =
199162306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_RXT_MAX_A);
199262306a36Sopenharmony_ci	clk_info_buff->persist_timer_min =
199362306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_PERS_MIN_A);
199462306a36Sopenharmony_ci	clk_info_buff->persist_timer_max =
199562306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_PERS_MAX_A);
199662306a36Sopenharmony_ci	clk_info_buff->keepalive_idle_timer =
199762306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_KEEP_IDLE_A);
199862306a36Sopenharmony_ci	clk_info_buff->keepalive_interval =
199962306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_KEEP_INTVL_A);
200062306a36Sopenharmony_ci	clk_info_buff->initial_srtt =
200162306a36Sopenharmony_ci		tp_tick_us * INITSRTT_G(t4_read_reg(padap, TP_INIT_SRTT_A));
200262306a36Sopenharmony_ci	clk_info_buff->finwait2_timer =
200362306a36Sopenharmony_ci		tp_tick_us * t4_read_reg(padap, TP_FINWAIT2_TIMER_A);
200462306a36Sopenharmony_ci
200562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
200662306a36Sopenharmony_ci}
200762306a36Sopenharmony_ci
200862306a36Sopenharmony_ciint cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
200962306a36Sopenharmony_ci				struct cudbg_buffer *dbg_buff,
201062306a36Sopenharmony_ci				struct cudbg_error *cudbg_err)
201162306a36Sopenharmony_ci{
201262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
201362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
201462306a36Sopenharmony_ci	struct ireg_buf *ch_pcie;
201562306a36Sopenharmony_ci	int i, rc, n;
201662306a36Sopenharmony_ci	u32 size;
201762306a36Sopenharmony_ci
201862306a36Sopenharmony_ci	n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
201962306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n * 2;
202062306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
202162306a36Sopenharmony_ci	if (rc)
202262306a36Sopenharmony_ci		return rc;
202362306a36Sopenharmony_ci
202462306a36Sopenharmony_ci	ch_pcie = (struct ireg_buf *)temp_buff.data;
202562306a36Sopenharmony_ci	/* PCIE_PDBG */
202662306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
202762306a36Sopenharmony_ci		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
202862306a36Sopenharmony_ci		u32 *buff = ch_pcie->outbuf;
202962306a36Sopenharmony_ci
203062306a36Sopenharmony_ci		pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
203162306a36Sopenharmony_ci		pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
203262306a36Sopenharmony_ci		pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
203362306a36Sopenharmony_ci		pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
203462306a36Sopenharmony_ci		t4_read_indirect(padap,
203562306a36Sopenharmony_ci				 pcie_pio->ireg_addr,
203662306a36Sopenharmony_ci				 pcie_pio->ireg_data,
203762306a36Sopenharmony_ci				 buff,
203862306a36Sopenharmony_ci				 pcie_pio->ireg_offset_range,
203962306a36Sopenharmony_ci				 pcie_pio->ireg_local_offset);
204062306a36Sopenharmony_ci		ch_pcie++;
204162306a36Sopenharmony_ci	}
204262306a36Sopenharmony_ci
204362306a36Sopenharmony_ci	/* PCIE_CDBG */
204462306a36Sopenharmony_ci	n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
204562306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
204662306a36Sopenharmony_ci		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
204762306a36Sopenharmony_ci		u32 *buff = ch_pcie->outbuf;
204862306a36Sopenharmony_ci
204962306a36Sopenharmony_ci		pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
205062306a36Sopenharmony_ci		pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
205162306a36Sopenharmony_ci		pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
205262306a36Sopenharmony_ci		pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
205362306a36Sopenharmony_ci		t4_read_indirect(padap,
205462306a36Sopenharmony_ci				 pcie_pio->ireg_addr,
205562306a36Sopenharmony_ci				 pcie_pio->ireg_data,
205662306a36Sopenharmony_ci				 buff,
205762306a36Sopenharmony_ci				 pcie_pio->ireg_offset_range,
205862306a36Sopenharmony_ci				 pcie_pio->ireg_local_offset);
205962306a36Sopenharmony_ci		ch_pcie++;
206062306a36Sopenharmony_ci	}
206162306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
206262306a36Sopenharmony_ci}
206362306a36Sopenharmony_ci
206462306a36Sopenharmony_ciint cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
206562306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
206662306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
206762306a36Sopenharmony_ci{
206862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
206962306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
207062306a36Sopenharmony_ci	struct ireg_buf *ch_pm;
207162306a36Sopenharmony_ci	int i, rc, n;
207262306a36Sopenharmony_ci	u32 size;
207362306a36Sopenharmony_ci
207462306a36Sopenharmony_ci	n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
207562306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n * 2;
207662306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
207762306a36Sopenharmony_ci	if (rc)
207862306a36Sopenharmony_ci		return rc;
207962306a36Sopenharmony_ci
208062306a36Sopenharmony_ci	ch_pm = (struct ireg_buf *)temp_buff.data;
208162306a36Sopenharmony_ci	/* PM_RX */
208262306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
208362306a36Sopenharmony_ci		struct ireg_field *pm_pio = &ch_pm->tp_pio;
208462306a36Sopenharmony_ci		u32 *buff = ch_pm->outbuf;
208562306a36Sopenharmony_ci
208662306a36Sopenharmony_ci		pm_pio->ireg_addr = t5_pm_rx_array[i][0];
208762306a36Sopenharmony_ci		pm_pio->ireg_data = t5_pm_rx_array[i][1];
208862306a36Sopenharmony_ci		pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
208962306a36Sopenharmony_ci		pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
209062306a36Sopenharmony_ci		t4_read_indirect(padap,
209162306a36Sopenharmony_ci				 pm_pio->ireg_addr,
209262306a36Sopenharmony_ci				 pm_pio->ireg_data,
209362306a36Sopenharmony_ci				 buff,
209462306a36Sopenharmony_ci				 pm_pio->ireg_offset_range,
209562306a36Sopenharmony_ci				 pm_pio->ireg_local_offset);
209662306a36Sopenharmony_ci		ch_pm++;
209762306a36Sopenharmony_ci	}
209862306a36Sopenharmony_ci
209962306a36Sopenharmony_ci	/* PM_TX */
210062306a36Sopenharmony_ci	n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
210162306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
210262306a36Sopenharmony_ci		struct ireg_field *pm_pio = &ch_pm->tp_pio;
210362306a36Sopenharmony_ci		u32 *buff = ch_pm->outbuf;
210462306a36Sopenharmony_ci
210562306a36Sopenharmony_ci		pm_pio->ireg_addr = t5_pm_tx_array[i][0];
210662306a36Sopenharmony_ci		pm_pio->ireg_data = t5_pm_tx_array[i][1];
210762306a36Sopenharmony_ci		pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
210862306a36Sopenharmony_ci		pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
210962306a36Sopenharmony_ci		t4_read_indirect(padap,
211062306a36Sopenharmony_ci				 pm_pio->ireg_addr,
211162306a36Sopenharmony_ci				 pm_pio->ireg_data,
211262306a36Sopenharmony_ci				 buff,
211362306a36Sopenharmony_ci				 pm_pio->ireg_offset_range,
211462306a36Sopenharmony_ci				 pm_pio->ireg_local_offset);
211562306a36Sopenharmony_ci		ch_pm++;
211662306a36Sopenharmony_ci	}
211762306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
211862306a36Sopenharmony_ci}
211962306a36Sopenharmony_ci
212062306a36Sopenharmony_ciint cudbg_collect_tid(struct cudbg_init *pdbg_init,
212162306a36Sopenharmony_ci		      struct cudbg_buffer *dbg_buff,
212262306a36Sopenharmony_ci		      struct cudbg_error *cudbg_err)
212362306a36Sopenharmony_ci{
212462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
212562306a36Sopenharmony_ci	struct cudbg_tid_info_region_rev1 *tid1;
212662306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
212762306a36Sopenharmony_ci	struct cudbg_tid_info_region *tid;
212862306a36Sopenharmony_ci	u32 para[2], val[2];
212962306a36Sopenharmony_ci	int rc;
213062306a36Sopenharmony_ci
213162306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff,
213262306a36Sopenharmony_ci			    sizeof(struct cudbg_tid_info_region_rev1),
213362306a36Sopenharmony_ci			    &temp_buff);
213462306a36Sopenharmony_ci	if (rc)
213562306a36Sopenharmony_ci		return rc;
213662306a36Sopenharmony_ci
213762306a36Sopenharmony_ci	tid1 = (struct cudbg_tid_info_region_rev1 *)temp_buff.data;
213862306a36Sopenharmony_ci	tid = &tid1->tid;
213962306a36Sopenharmony_ci	tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
214062306a36Sopenharmony_ci	tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
214162306a36Sopenharmony_ci	tid1->ver_hdr.size = sizeof(struct cudbg_tid_info_region_rev1) -
214262306a36Sopenharmony_ci			     sizeof(struct cudbg_ver_hdr);
214362306a36Sopenharmony_ci
214462306a36Sopenharmony_ci	/* If firmware is not attached/alive, use backdoor register
214562306a36Sopenharmony_ci	 * access to collect dump.
214662306a36Sopenharmony_ci	 */
214762306a36Sopenharmony_ci	if (!is_fw_attached(pdbg_init))
214862306a36Sopenharmony_ci		goto fill_tid;
214962306a36Sopenharmony_ci
215062306a36Sopenharmony_ci#define FW_PARAM_PFVF_A(param) \
215162306a36Sopenharmony_ci	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
215262306a36Sopenharmony_ci	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param) | \
215362306a36Sopenharmony_ci	 FW_PARAMS_PARAM_Y_V(0) | \
215462306a36Sopenharmony_ci	 FW_PARAMS_PARAM_Z_V(0))
215562306a36Sopenharmony_ci
215662306a36Sopenharmony_ci	para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
215762306a36Sopenharmony_ci	para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
215862306a36Sopenharmony_ci	rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2, para, val);
215962306a36Sopenharmony_ci	if (rc <  0) {
216062306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
216162306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
216262306a36Sopenharmony_ci		return rc;
216362306a36Sopenharmony_ci	}
216462306a36Sopenharmony_ci	tid->uotid_base = val[0];
216562306a36Sopenharmony_ci	tid->nuotids = val[1] - val[0] + 1;
216662306a36Sopenharmony_ci
216762306a36Sopenharmony_ci	if (is_t5(padap->params.chip)) {
216862306a36Sopenharmony_ci		tid->sb = t4_read_reg(padap, LE_DB_SERVER_INDEX_A) / 4;
216962306a36Sopenharmony_ci	} else if (is_t6(padap->params.chip)) {
217062306a36Sopenharmony_ci		tid1->tid_start =
217162306a36Sopenharmony_ci			t4_read_reg(padap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
217262306a36Sopenharmony_ci		tid->sb = t4_read_reg(padap, LE_DB_SRVR_START_INDEX_A);
217362306a36Sopenharmony_ci
217462306a36Sopenharmony_ci		para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
217562306a36Sopenharmony_ci		para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
217662306a36Sopenharmony_ci		rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2,
217762306a36Sopenharmony_ci				     para, val);
217862306a36Sopenharmony_ci		if (rc < 0) {
217962306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
218062306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
218162306a36Sopenharmony_ci			return rc;
218262306a36Sopenharmony_ci		}
218362306a36Sopenharmony_ci		tid->hpftid_base = val[0];
218462306a36Sopenharmony_ci		tid->nhpftids = val[1] - val[0] + 1;
218562306a36Sopenharmony_ci	}
218662306a36Sopenharmony_ci
218762306a36Sopenharmony_ci#undef FW_PARAM_PFVF_A
218862306a36Sopenharmony_ci
218962306a36Sopenharmony_cifill_tid:
219062306a36Sopenharmony_ci	tid->ntids = padap->tids.ntids;
219162306a36Sopenharmony_ci	tid->nstids = padap->tids.nstids;
219262306a36Sopenharmony_ci	tid->stid_base = padap->tids.stid_base;
219362306a36Sopenharmony_ci	tid->hash_base = padap->tids.hash_base;
219462306a36Sopenharmony_ci
219562306a36Sopenharmony_ci	tid->natids = padap->tids.natids;
219662306a36Sopenharmony_ci	tid->nftids = padap->tids.nftids;
219762306a36Sopenharmony_ci	tid->ftid_base = padap->tids.ftid_base;
219862306a36Sopenharmony_ci	tid->aftid_base = padap->tids.aftid_base;
219962306a36Sopenharmony_ci	tid->aftid_end = padap->tids.aftid_end;
220062306a36Sopenharmony_ci
220162306a36Sopenharmony_ci	tid->sftid_base = padap->tids.sftid_base;
220262306a36Sopenharmony_ci	tid->nsftids = padap->tids.nsftids;
220362306a36Sopenharmony_ci
220462306a36Sopenharmony_ci	tid->flags = padap->flags;
220562306a36Sopenharmony_ci	tid->le_db_conf = t4_read_reg(padap, LE_DB_CONFIG_A);
220662306a36Sopenharmony_ci	tid->ip_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV4_A);
220762306a36Sopenharmony_ci	tid->ipv6_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV6_A);
220862306a36Sopenharmony_ci
220962306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
221062306a36Sopenharmony_ci}
221162306a36Sopenharmony_ci
221262306a36Sopenharmony_ciint cudbg_collect_pcie_config(struct cudbg_init *pdbg_init,
221362306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
221462306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
221562306a36Sopenharmony_ci{
221662306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
221762306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
221862306a36Sopenharmony_ci	u32 size, *value, j;
221962306a36Sopenharmony_ci	int i, rc, n;
222062306a36Sopenharmony_ci
222162306a36Sopenharmony_ci	size = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
222262306a36Sopenharmony_ci	n = sizeof(t5_pcie_config_array) / (2 * sizeof(u32));
222362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
222462306a36Sopenharmony_ci	if (rc)
222562306a36Sopenharmony_ci		return rc;
222662306a36Sopenharmony_ci
222762306a36Sopenharmony_ci	value = (u32 *)temp_buff.data;
222862306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
222962306a36Sopenharmony_ci		for (j = t5_pcie_config_array[i][0];
223062306a36Sopenharmony_ci		     j <= t5_pcie_config_array[i][1]; j += 4) {
223162306a36Sopenharmony_ci			t4_hw_pci_read_cfg4(padap, j, value);
223262306a36Sopenharmony_ci			value++;
223362306a36Sopenharmony_ci		}
223462306a36Sopenharmony_ci	}
223562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
223662306a36Sopenharmony_ci}
223762306a36Sopenharmony_ci
223862306a36Sopenharmony_cistatic int cudbg_sge_ctxt_check_valid(u32 *buf, int type)
223962306a36Sopenharmony_ci{
224062306a36Sopenharmony_ci	int index, bit, bit_pos = 0;
224162306a36Sopenharmony_ci
224262306a36Sopenharmony_ci	switch (type) {
224362306a36Sopenharmony_ci	case CTXT_EGRESS:
224462306a36Sopenharmony_ci		bit_pos = 176;
224562306a36Sopenharmony_ci		break;
224662306a36Sopenharmony_ci	case CTXT_INGRESS:
224762306a36Sopenharmony_ci		bit_pos = 141;
224862306a36Sopenharmony_ci		break;
224962306a36Sopenharmony_ci	case CTXT_FLM:
225062306a36Sopenharmony_ci		bit_pos = 89;
225162306a36Sopenharmony_ci		break;
225262306a36Sopenharmony_ci	}
225362306a36Sopenharmony_ci	index = bit_pos / 32;
225462306a36Sopenharmony_ci	bit =  bit_pos % 32;
225562306a36Sopenharmony_ci	return buf[index] & (1U << bit);
225662306a36Sopenharmony_ci}
225762306a36Sopenharmony_ci
225862306a36Sopenharmony_cistatic int cudbg_get_ctxt_region_info(struct adapter *padap,
225962306a36Sopenharmony_ci				      struct cudbg_region_info *ctx_info,
226062306a36Sopenharmony_ci				      u8 *mem_type)
226162306a36Sopenharmony_ci{
226262306a36Sopenharmony_ci	struct cudbg_mem_desc mem_desc;
226362306a36Sopenharmony_ci	struct cudbg_meminfo meminfo;
226462306a36Sopenharmony_ci	u32 i, j, value, found;
226562306a36Sopenharmony_ci	u8 flq;
226662306a36Sopenharmony_ci	int rc;
226762306a36Sopenharmony_ci
226862306a36Sopenharmony_ci	rc = cudbg_fill_meminfo(padap, &meminfo);
226962306a36Sopenharmony_ci	if (rc)
227062306a36Sopenharmony_ci		return rc;
227162306a36Sopenharmony_ci
227262306a36Sopenharmony_ci	/* Get EGRESS and INGRESS context region size */
227362306a36Sopenharmony_ci	for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
227462306a36Sopenharmony_ci		found = 0;
227562306a36Sopenharmony_ci		memset(&mem_desc, 0, sizeof(struct cudbg_mem_desc));
227662306a36Sopenharmony_ci		for (j = 0; j < ARRAY_SIZE(meminfo.avail); j++) {
227762306a36Sopenharmony_ci			rc = cudbg_get_mem_region(padap, &meminfo, j,
227862306a36Sopenharmony_ci						  cudbg_region[i],
227962306a36Sopenharmony_ci						  &mem_desc);
228062306a36Sopenharmony_ci			if (!rc) {
228162306a36Sopenharmony_ci				found = 1;
228262306a36Sopenharmony_ci				rc = cudbg_get_mem_relative(padap, &meminfo, j,
228362306a36Sopenharmony_ci							    &mem_desc.base,
228462306a36Sopenharmony_ci							    &mem_desc.limit);
228562306a36Sopenharmony_ci				if (rc) {
228662306a36Sopenharmony_ci					ctx_info[i].exist = false;
228762306a36Sopenharmony_ci					break;
228862306a36Sopenharmony_ci				}
228962306a36Sopenharmony_ci				ctx_info[i].exist = true;
229062306a36Sopenharmony_ci				ctx_info[i].start = mem_desc.base;
229162306a36Sopenharmony_ci				ctx_info[i].end = mem_desc.limit;
229262306a36Sopenharmony_ci				mem_type[i] = j;
229362306a36Sopenharmony_ci				break;
229462306a36Sopenharmony_ci			}
229562306a36Sopenharmony_ci		}
229662306a36Sopenharmony_ci		if (!found)
229762306a36Sopenharmony_ci			ctx_info[i].exist = false;
229862306a36Sopenharmony_ci	}
229962306a36Sopenharmony_ci
230062306a36Sopenharmony_ci	/* Get FLM and CNM max qid. */
230162306a36Sopenharmony_ci	value = t4_read_reg(padap, SGE_FLM_CFG_A);
230262306a36Sopenharmony_ci
230362306a36Sopenharmony_ci	/* Get number of data freelist queues */
230462306a36Sopenharmony_ci	flq = HDRSTARTFLQ_G(value);
230562306a36Sopenharmony_ci	ctx_info[CTXT_FLM].exist = true;
230662306a36Sopenharmony_ci	ctx_info[CTXT_FLM].end = (CUDBG_MAX_FL_QIDS >> flq) * SGE_CTXT_SIZE;
230762306a36Sopenharmony_ci
230862306a36Sopenharmony_ci	/* The number of CONM contexts are same as number of freelist
230962306a36Sopenharmony_ci	 * queues.
231062306a36Sopenharmony_ci	 */
231162306a36Sopenharmony_ci	ctx_info[CTXT_CNM].exist = true;
231262306a36Sopenharmony_ci	ctx_info[CTXT_CNM].end = ctx_info[CTXT_FLM].end;
231362306a36Sopenharmony_ci
231462306a36Sopenharmony_ci	return 0;
231562306a36Sopenharmony_ci}
231662306a36Sopenharmony_ci
231762306a36Sopenharmony_ciint cudbg_dump_context_size(struct adapter *padap)
231862306a36Sopenharmony_ci{
231962306a36Sopenharmony_ci	struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
232062306a36Sopenharmony_ci	u8 mem_type[CTXT_INGRESS + 1] = { 0 };
232162306a36Sopenharmony_ci	u32 i, size = 0;
232262306a36Sopenharmony_ci	int rc;
232362306a36Sopenharmony_ci
232462306a36Sopenharmony_ci	/* Get max valid qid for each type of queue */
232562306a36Sopenharmony_ci	rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
232662306a36Sopenharmony_ci	if (rc)
232762306a36Sopenharmony_ci		return rc;
232862306a36Sopenharmony_ci
232962306a36Sopenharmony_ci	for (i = 0; i < CTXT_CNM; i++) {
233062306a36Sopenharmony_ci		if (!region_info[i].exist) {
233162306a36Sopenharmony_ci			if (i == CTXT_EGRESS || i == CTXT_INGRESS)
233262306a36Sopenharmony_ci				size += CUDBG_LOWMEM_MAX_CTXT_QIDS *
233362306a36Sopenharmony_ci					SGE_CTXT_SIZE;
233462306a36Sopenharmony_ci			continue;
233562306a36Sopenharmony_ci		}
233662306a36Sopenharmony_ci
233762306a36Sopenharmony_ci		size += (region_info[i].end - region_info[i].start + 1) /
233862306a36Sopenharmony_ci			SGE_CTXT_SIZE;
233962306a36Sopenharmony_ci	}
234062306a36Sopenharmony_ci	return size * sizeof(struct cudbg_ch_cntxt);
234162306a36Sopenharmony_ci}
234262306a36Sopenharmony_ci
234362306a36Sopenharmony_cistatic void cudbg_read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
234462306a36Sopenharmony_ci				enum ctxt_type ctype, u32 *data)
234562306a36Sopenharmony_ci{
234662306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
234762306a36Sopenharmony_ci	int rc = -1;
234862306a36Sopenharmony_ci
234962306a36Sopenharmony_ci	/* Under heavy traffic, the SGE Queue contexts registers will be
235062306a36Sopenharmony_ci	 * frequently accessed by firmware.
235162306a36Sopenharmony_ci	 *
235262306a36Sopenharmony_ci	 * To avoid conflicts with firmware, always ask firmware to fetch
235362306a36Sopenharmony_ci	 * the SGE Queue contexts via mailbox. On failure, fallback to
235462306a36Sopenharmony_ci	 * accessing hardware registers directly.
235562306a36Sopenharmony_ci	 */
235662306a36Sopenharmony_ci	if (is_fw_attached(pdbg_init))
235762306a36Sopenharmony_ci		rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype, data);
235862306a36Sopenharmony_ci	if (rc)
235962306a36Sopenharmony_ci		t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
236062306a36Sopenharmony_ci}
236162306a36Sopenharmony_ci
236262306a36Sopenharmony_cistatic void cudbg_get_sge_ctxt_fw(struct cudbg_init *pdbg_init, u32 max_qid,
236362306a36Sopenharmony_ci				  u8 ctxt_type,
236462306a36Sopenharmony_ci				  struct cudbg_ch_cntxt **out_buff)
236562306a36Sopenharmony_ci{
236662306a36Sopenharmony_ci	struct cudbg_ch_cntxt *buff = *out_buff;
236762306a36Sopenharmony_ci	int rc;
236862306a36Sopenharmony_ci	u32 j;
236962306a36Sopenharmony_ci
237062306a36Sopenharmony_ci	for (j = 0; j < max_qid; j++) {
237162306a36Sopenharmony_ci		cudbg_read_sge_ctxt(pdbg_init, j, ctxt_type, buff->data);
237262306a36Sopenharmony_ci		rc = cudbg_sge_ctxt_check_valid(buff->data, ctxt_type);
237362306a36Sopenharmony_ci		if (!rc)
237462306a36Sopenharmony_ci			continue;
237562306a36Sopenharmony_ci
237662306a36Sopenharmony_ci		buff->cntxt_type = ctxt_type;
237762306a36Sopenharmony_ci		buff->cntxt_id = j;
237862306a36Sopenharmony_ci		buff++;
237962306a36Sopenharmony_ci		if (ctxt_type == CTXT_FLM) {
238062306a36Sopenharmony_ci			cudbg_read_sge_ctxt(pdbg_init, j, CTXT_CNM, buff->data);
238162306a36Sopenharmony_ci			buff->cntxt_type = CTXT_CNM;
238262306a36Sopenharmony_ci			buff->cntxt_id = j;
238362306a36Sopenharmony_ci			buff++;
238462306a36Sopenharmony_ci		}
238562306a36Sopenharmony_ci	}
238662306a36Sopenharmony_ci
238762306a36Sopenharmony_ci	*out_buff = buff;
238862306a36Sopenharmony_ci}
238962306a36Sopenharmony_ci
239062306a36Sopenharmony_ciint cudbg_collect_dump_context(struct cudbg_init *pdbg_init,
239162306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
239262306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
239362306a36Sopenharmony_ci{
239462306a36Sopenharmony_ci	struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
239562306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
239662306a36Sopenharmony_ci	u32 j, size, max_ctx_size, max_ctx_qid;
239762306a36Sopenharmony_ci	u8 mem_type[CTXT_INGRESS + 1] = { 0 };
239862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
239962306a36Sopenharmony_ci	struct cudbg_ch_cntxt *buff;
240062306a36Sopenharmony_ci	u8 *ctx_buf;
240162306a36Sopenharmony_ci	u8 i, k;
240262306a36Sopenharmony_ci	int rc;
240362306a36Sopenharmony_ci
240462306a36Sopenharmony_ci	/* Get max valid qid for each type of queue */
240562306a36Sopenharmony_ci	rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
240662306a36Sopenharmony_ci	if (rc)
240762306a36Sopenharmony_ci		return rc;
240862306a36Sopenharmony_ci
240962306a36Sopenharmony_ci	rc = cudbg_dump_context_size(padap);
241062306a36Sopenharmony_ci	if (rc <= 0)
241162306a36Sopenharmony_ci		return CUDBG_STATUS_ENTITY_NOT_FOUND;
241262306a36Sopenharmony_ci
241362306a36Sopenharmony_ci	size = rc;
241462306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
241562306a36Sopenharmony_ci	if (rc)
241662306a36Sopenharmony_ci		return rc;
241762306a36Sopenharmony_ci
241862306a36Sopenharmony_ci	/* Get buffer with enough space to read the biggest context
241962306a36Sopenharmony_ci	 * region in memory.
242062306a36Sopenharmony_ci	 */
242162306a36Sopenharmony_ci	max_ctx_size = max(region_info[CTXT_EGRESS].end -
242262306a36Sopenharmony_ci			   region_info[CTXT_EGRESS].start + 1,
242362306a36Sopenharmony_ci			   region_info[CTXT_INGRESS].end -
242462306a36Sopenharmony_ci			   region_info[CTXT_INGRESS].start + 1);
242562306a36Sopenharmony_ci
242662306a36Sopenharmony_ci	ctx_buf = kvzalloc(max_ctx_size, GFP_KERNEL);
242762306a36Sopenharmony_ci	if (!ctx_buf) {
242862306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
242962306a36Sopenharmony_ci		return -ENOMEM;
243062306a36Sopenharmony_ci	}
243162306a36Sopenharmony_ci
243262306a36Sopenharmony_ci	buff = (struct cudbg_ch_cntxt *)temp_buff.data;
243362306a36Sopenharmony_ci
243462306a36Sopenharmony_ci	/* Collect EGRESS and INGRESS context data.
243562306a36Sopenharmony_ci	 * In case of failures, fallback to collecting via FW or
243662306a36Sopenharmony_ci	 * backdoor access.
243762306a36Sopenharmony_ci	 */
243862306a36Sopenharmony_ci	for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
243962306a36Sopenharmony_ci		if (!region_info[i].exist) {
244062306a36Sopenharmony_ci			max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
244162306a36Sopenharmony_ci			cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
244262306a36Sopenharmony_ci					      &buff);
244362306a36Sopenharmony_ci			continue;
244462306a36Sopenharmony_ci		}
244562306a36Sopenharmony_ci
244662306a36Sopenharmony_ci		max_ctx_size = region_info[i].end - region_info[i].start + 1;
244762306a36Sopenharmony_ci		max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
244862306a36Sopenharmony_ci
244962306a36Sopenharmony_ci		/* If firmware is not attached/alive, use backdoor register
245062306a36Sopenharmony_ci		 * access to collect dump.
245162306a36Sopenharmony_ci		 */
245262306a36Sopenharmony_ci		if (is_fw_attached(pdbg_init)) {
245362306a36Sopenharmony_ci			t4_sge_ctxt_flush(padap, padap->mbox, i);
245462306a36Sopenharmony_ci
245562306a36Sopenharmony_ci			rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type[i],
245662306a36Sopenharmony_ci					  region_info[i].start, max_ctx_size,
245762306a36Sopenharmony_ci					  (__be32 *)ctx_buf, 1);
245862306a36Sopenharmony_ci		}
245962306a36Sopenharmony_ci
246062306a36Sopenharmony_ci		if (rc || !is_fw_attached(pdbg_init)) {
246162306a36Sopenharmony_ci			max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
246262306a36Sopenharmony_ci			cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
246362306a36Sopenharmony_ci					      &buff);
246462306a36Sopenharmony_ci			continue;
246562306a36Sopenharmony_ci		}
246662306a36Sopenharmony_ci
246762306a36Sopenharmony_ci		for (j = 0; j < max_ctx_qid; j++) {
246862306a36Sopenharmony_ci			__be64 *dst_off;
246962306a36Sopenharmony_ci			u64 *src_off;
247062306a36Sopenharmony_ci
247162306a36Sopenharmony_ci			src_off = (u64 *)(ctx_buf + j * SGE_CTXT_SIZE);
247262306a36Sopenharmony_ci			dst_off = (__be64 *)buff->data;
247362306a36Sopenharmony_ci
247462306a36Sopenharmony_ci			/* The data is stored in 64-bit cpu order.  Convert it
247562306a36Sopenharmony_ci			 * to big endian before parsing.
247662306a36Sopenharmony_ci			 */
247762306a36Sopenharmony_ci			for (k = 0; k < SGE_CTXT_SIZE / sizeof(u64); k++)
247862306a36Sopenharmony_ci				dst_off[k] = cpu_to_be64(src_off[k]);
247962306a36Sopenharmony_ci
248062306a36Sopenharmony_ci			rc = cudbg_sge_ctxt_check_valid(buff->data, i);
248162306a36Sopenharmony_ci			if (!rc)
248262306a36Sopenharmony_ci				continue;
248362306a36Sopenharmony_ci
248462306a36Sopenharmony_ci			buff->cntxt_type = i;
248562306a36Sopenharmony_ci			buff->cntxt_id = j;
248662306a36Sopenharmony_ci			buff++;
248762306a36Sopenharmony_ci		}
248862306a36Sopenharmony_ci	}
248962306a36Sopenharmony_ci
249062306a36Sopenharmony_ci	kvfree(ctx_buf);
249162306a36Sopenharmony_ci
249262306a36Sopenharmony_ci	/* Collect FREELIST and CONGESTION MANAGER contexts */
249362306a36Sopenharmony_ci	max_ctx_size = region_info[CTXT_FLM].end -
249462306a36Sopenharmony_ci		       region_info[CTXT_FLM].start + 1;
249562306a36Sopenharmony_ci	max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
249662306a36Sopenharmony_ci	/* Since FLM and CONM are 1-to-1 mapped, the below function
249762306a36Sopenharmony_ci	 * will fetch both FLM and CONM contexts.
249862306a36Sopenharmony_ci	 */
249962306a36Sopenharmony_ci	cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, CTXT_FLM, &buff);
250062306a36Sopenharmony_ci
250162306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
250262306a36Sopenharmony_ci}
250362306a36Sopenharmony_ci
250462306a36Sopenharmony_cistatic inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
250562306a36Sopenharmony_ci{
250662306a36Sopenharmony_ci	*mask = x | y;
250762306a36Sopenharmony_ci	y = (__force u64)cpu_to_be64(y);
250862306a36Sopenharmony_ci	memcpy(addr, (char *)&y + 2, ETH_ALEN);
250962306a36Sopenharmony_ci}
251062306a36Sopenharmony_ci
251162306a36Sopenharmony_cistatic void cudbg_mps_rpl_backdoor(struct adapter *padap,
251262306a36Sopenharmony_ci				   struct fw_ldst_mps_rplc *mps_rplc)
251362306a36Sopenharmony_ci{
251462306a36Sopenharmony_ci	if (is_t5(padap->params.chip)) {
251562306a36Sopenharmony_ci		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
251662306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP3_A));
251762306a36Sopenharmony_ci		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
251862306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP2_A));
251962306a36Sopenharmony_ci		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
252062306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP1_A));
252162306a36Sopenharmony_ci		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
252262306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP0_A));
252362306a36Sopenharmony_ci	} else {
252462306a36Sopenharmony_ci		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
252562306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP7_A));
252662306a36Sopenharmony_ci		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
252762306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP6_A));
252862306a36Sopenharmony_ci		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
252962306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP5_A));
253062306a36Sopenharmony_ci		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
253162306a36Sopenharmony_ci							  MPS_VF_RPLCT_MAP4_A));
253262306a36Sopenharmony_ci	}
253362306a36Sopenharmony_ci	mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP3_A));
253462306a36Sopenharmony_ci	mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP2_A));
253562306a36Sopenharmony_ci	mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP1_A));
253662306a36Sopenharmony_ci	mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP0_A));
253762306a36Sopenharmony_ci}
253862306a36Sopenharmony_ci
253962306a36Sopenharmony_cistatic int cudbg_collect_tcam_index(struct cudbg_init *pdbg_init,
254062306a36Sopenharmony_ci				    struct cudbg_mps_tcam *tcam, u32 idx)
254162306a36Sopenharmony_ci{
254262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
254362306a36Sopenharmony_ci	u64 tcamy, tcamx, val;
254462306a36Sopenharmony_ci	u32 ctl, data2;
254562306a36Sopenharmony_ci	int rc = 0;
254662306a36Sopenharmony_ci
254762306a36Sopenharmony_ci	if (CHELSIO_CHIP_VERSION(padap->params.chip) >= CHELSIO_T6) {
254862306a36Sopenharmony_ci		/* CtlReqID   - 1: use Host Driver Requester ID
254962306a36Sopenharmony_ci		 * CtlCmdType - 0: Read, 1: Write
255062306a36Sopenharmony_ci		 * CtlTcamSel - 0: TCAM0, 1: TCAM1
255162306a36Sopenharmony_ci		 * CtlXYBitSel- 0: Y bit, 1: X bit
255262306a36Sopenharmony_ci		 */
255362306a36Sopenharmony_ci
255462306a36Sopenharmony_ci		/* Read tcamy */
255562306a36Sopenharmony_ci		ctl = CTLREQID_V(1) | CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
255662306a36Sopenharmony_ci		if (idx < 256)
255762306a36Sopenharmony_ci			ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
255862306a36Sopenharmony_ci		else
255962306a36Sopenharmony_ci			ctl |= CTLTCAMINDEX_V(idx - 256) | CTLTCAMSEL_V(1);
256062306a36Sopenharmony_ci
256162306a36Sopenharmony_ci		t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
256262306a36Sopenharmony_ci		val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
256362306a36Sopenharmony_ci		tcamy = DMACH_G(val) << 32;
256462306a36Sopenharmony_ci		tcamy |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
256562306a36Sopenharmony_ci		data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
256662306a36Sopenharmony_ci		tcam->lookup_type = DATALKPTYPE_G(data2);
256762306a36Sopenharmony_ci
256862306a36Sopenharmony_ci		/* 0 - Outer header, 1 - Inner header
256962306a36Sopenharmony_ci		 * [71:48] bit locations are overloaded for
257062306a36Sopenharmony_ci		 * outer vs. inner lookup types.
257162306a36Sopenharmony_ci		 */
257262306a36Sopenharmony_ci		if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
257362306a36Sopenharmony_ci			/* Inner header VNI */
257462306a36Sopenharmony_ci			tcam->vniy = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
257562306a36Sopenharmony_ci			tcam->vniy = (tcam->vniy << 16) | VIDL_G(val);
257662306a36Sopenharmony_ci			tcam->dip_hit = data2 & DATADIPHIT_F;
257762306a36Sopenharmony_ci		} else {
257862306a36Sopenharmony_ci			tcam->vlan_vld = data2 & DATAVIDH2_F;
257962306a36Sopenharmony_ci			tcam->ivlan = VIDL_G(val);
258062306a36Sopenharmony_ci		}
258162306a36Sopenharmony_ci
258262306a36Sopenharmony_ci		tcam->port_num = DATAPORTNUM_G(data2);
258362306a36Sopenharmony_ci
258462306a36Sopenharmony_ci		/* Read tcamx. Change the control param */
258562306a36Sopenharmony_ci		ctl |= CTLXYBITSEL_V(1);
258662306a36Sopenharmony_ci		t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
258762306a36Sopenharmony_ci		val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
258862306a36Sopenharmony_ci		tcamx = DMACH_G(val) << 32;
258962306a36Sopenharmony_ci		tcamx |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
259062306a36Sopenharmony_ci		data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
259162306a36Sopenharmony_ci		if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
259262306a36Sopenharmony_ci			/* Inner header VNI mask */
259362306a36Sopenharmony_ci			tcam->vnix = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
259462306a36Sopenharmony_ci			tcam->vnix = (tcam->vnix << 16) | VIDL_G(val);
259562306a36Sopenharmony_ci		}
259662306a36Sopenharmony_ci	} else {
259762306a36Sopenharmony_ci		tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(idx));
259862306a36Sopenharmony_ci		tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(idx));
259962306a36Sopenharmony_ci	}
260062306a36Sopenharmony_ci
260162306a36Sopenharmony_ci	/* If no entry, return */
260262306a36Sopenharmony_ci	if (tcamx & tcamy)
260362306a36Sopenharmony_ci		return rc;
260462306a36Sopenharmony_ci
260562306a36Sopenharmony_ci	tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(idx));
260662306a36Sopenharmony_ci	tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(idx));
260762306a36Sopenharmony_ci
260862306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
260962306a36Sopenharmony_ci		tcam->repli = (tcam->cls_lo & REPLICATE_F);
261062306a36Sopenharmony_ci	else if (is_t6(padap->params.chip))
261162306a36Sopenharmony_ci		tcam->repli = (tcam->cls_lo & T6_REPLICATE_F);
261262306a36Sopenharmony_ci
261362306a36Sopenharmony_ci	if (tcam->repli) {
261462306a36Sopenharmony_ci		struct fw_ldst_cmd ldst_cmd;
261562306a36Sopenharmony_ci		struct fw_ldst_mps_rplc mps_rplc;
261662306a36Sopenharmony_ci
261762306a36Sopenharmony_ci		memset(&ldst_cmd, 0, sizeof(ldst_cmd));
261862306a36Sopenharmony_ci		ldst_cmd.op_to_addrspace =
261962306a36Sopenharmony_ci			htonl(FW_CMD_OP_V(FW_LDST_CMD) |
262062306a36Sopenharmony_ci			      FW_CMD_REQUEST_F | FW_CMD_READ_F |
262162306a36Sopenharmony_ci			      FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS));
262262306a36Sopenharmony_ci		ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
262362306a36Sopenharmony_ci		ldst_cmd.u.mps.rplc.fid_idx =
262462306a36Sopenharmony_ci			htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
262562306a36Sopenharmony_ci			      FW_LDST_CMD_IDX_V(idx));
262662306a36Sopenharmony_ci
262762306a36Sopenharmony_ci		/* If firmware is not attached/alive, use backdoor register
262862306a36Sopenharmony_ci		 * access to collect dump.
262962306a36Sopenharmony_ci		 */
263062306a36Sopenharmony_ci		if (is_fw_attached(pdbg_init))
263162306a36Sopenharmony_ci			rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd,
263262306a36Sopenharmony_ci					sizeof(ldst_cmd), &ldst_cmd);
263362306a36Sopenharmony_ci
263462306a36Sopenharmony_ci		if (rc || !is_fw_attached(pdbg_init)) {
263562306a36Sopenharmony_ci			cudbg_mps_rpl_backdoor(padap, &mps_rplc);
263662306a36Sopenharmony_ci			/* Ignore error since we collected directly from
263762306a36Sopenharmony_ci			 * reading registers.
263862306a36Sopenharmony_ci			 */
263962306a36Sopenharmony_ci			rc = 0;
264062306a36Sopenharmony_ci		} else {
264162306a36Sopenharmony_ci			mps_rplc = ldst_cmd.u.mps.rplc;
264262306a36Sopenharmony_ci		}
264362306a36Sopenharmony_ci
264462306a36Sopenharmony_ci		tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
264562306a36Sopenharmony_ci		tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
264662306a36Sopenharmony_ci		tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
264762306a36Sopenharmony_ci		tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
264862306a36Sopenharmony_ci		if (padap->params.arch.mps_rplc_size > CUDBG_MAX_RPLC_SIZE) {
264962306a36Sopenharmony_ci			tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
265062306a36Sopenharmony_ci			tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
265162306a36Sopenharmony_ci			tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
265262306a36Sopenharmony_ci			tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
265362306a36Sopenharmony_ci		}
265462306a36Sopenharmony_ci	}
265562306a36Sopenharmony_ci	cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
265662306a36Sopenharmony_ci	tcam->idx = idx;
265762306a36Sopenharmony_ci	tcam->rplc_size = padap->params.arch.mps_rplc_size;
265862306a36Sopenharmony_ci	return rc;
265962306a36Sopenharmony_ci}
266062306a36Sopenharmony_ci
266162306a36Sopenharmony_ciint cudbg_collect_mps_tcam(struct cudbg_init *pdbg_init,
266262306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
266362306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
266462306a36Sopenharmony_ci{
266562306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
266662306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
266762306a36Sopenharmony_ci	u32 size = 0, i, n, total_size = 0;
266862306a36Sopenharmony_ci	struct cudbg_mps_tcam *tcam;
266962306a36Sopenharmony_ci	int rc;
267062306a36Sopenharmony_ci
267162306a36Sopenharmony_ci	n = padap->params.arch.mps_tcam_size;
267262306a36Sopenharmony_ci	size = sizeof(struct cudbg_mps_tcam) * n;
267362306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
267462306a36Sopenharmony_ci	if (rc)
267562306a36Sopenharmony_ci		return rc;
267662306a36Sopenharmony_ci
267762306a36Sopenharmony_ci	tcam = (struct cudbg_mps_tcam *)temp_buff.data;
267862306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
267962306a36Sopenharmony_ci		rc = cudbg_collect_tcam_index(pdbg_init, tcam, i);
268062306a36Sopenharmony_ci		if (rc) {
268162306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
268262306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
268362306a36Sopenharmony_ci			return rc;
268462306a36Sopenharmony_ci		}
268562306a36Sopenharmony_ci		total_size += sizeof(struct cudbg_mps_tcam);
268662306a36Sopenharmony_ci		tcam++;
268762306a36Sopenharmony_ci	}
268862306a36Sopenharmony_ci
268962306a36Sopenharmony_ci	if (!total_size) {
269062306a36Sopenharmony_ci		rc = CUDBG_SYSTEM_ERROR;
269162306a36Sopenharmony_ci		cudbg_err->sys_err = rc;
269262306a36Sopenharmony_ci		cudbg_put_buff(pdbg_init, &temp_buff);
269362306a36Sopenharmony_ci		return rc;
269462306a36Sopenharmony_ci	}
269562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
269662306a36Sopenharmony_ci}
269762306a36Sopenharmony_ci
269862306a36Sopenharmony_ciint cudbg_collect_vpd_data(struct cudbg_init *pdbg_init,
269962306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
270062306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
270162306a36Sopenharmony_ci{
270262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
270362306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
270462306a36Sopenharmony_ci	char vpd_str[CUDBG_VPD_VER_LEN + 1];
270562306a36Sopenharmony_ci	struct cudbg_vpd_data *vpd_data;
270662306a36Sopenharmony_ci	struct vpd_params vpd = { 0 };
270762306a36Sopenharmony_ci	u32 vpd_vers, fw_vers;
270862306a36Sopenharmony_ci	int rc;
270962306a36Sopenharmony_ci
271062306a36Sopenharmony_ci	rc = t4_get_raw_vpd_params(padap, &vpd);
271162306a36Sopenharmony_ci	if (rc)
271262306a36Sopenharmony_ci		return rc;
271362306a36Sopenharmony_ci
271462306a36Sopenharmony_ci	rc = t4_get_fw_version(padap, &fw_vers);
271562306a36Sopenharmony_ci	if (rc)
271662306a36Sopenharmony_ci		return rc;
271762306a36Sopenharmony_ci
271862306a36Sopenharmony_ci	rc = cudbg_read_vpd_reg(padap, CUDBG_VPD_VER_ADDR, CUDBG_VPD_VER_LEN,
271962306a36Sopenharmony_ci				vpd_str);
272062306a36Sopenharmony_ci	if (rc)
272162306a36Sopenharmony_ci		return rc;
272262306a36Sopenharmony_ci
272362306a36Sopenharmony_ci	vpd_str[CUDBG_VPD_VER_LEN] = '\0';
272462306a36Sopenharmony_ci	rc = kstrtouint(vpd_str, 0, &vpd_vers);
272562306a36Sopenharmony_ci	if (rc)
272662306a36Sopenharmony_ci		return rc;
272762306a36Sopenharmony_ci
272862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_vpd_data),
272962306a36Sopenharmony_ci			    &temp_buff);
273062306a36Sopenharmony_ci	if (rc)
273162306a36Sopenharmony_ci		return rc;
273262306a36Sopenharmony_ci
273362306a36Sopenharmony_ci	vpd_data = (struct cudbg_vpd_data *)temp_buff.data;
273462306a36Sopenharmony_ci	memcpy(vpd_data->sn, vpd.sn, SERNUM_LEN + 1);
273562306a36Sopenharmony_ci	memcpy(vpd_data->bn, vpd.pn, PN_LEN + 1);
273662306a36Sopenharmony_ci	memcpy(vpd_data->na, vpd.na, MACADDR_LEN + 1);
273762306a36Sopenharmony_ci	memcpy(vpd_data->mn, vpd.id, ID_LEN + 1);
273862306a36Sopenharmony_ci	vpd_data->scfg_vers = t4_read_reg(padap, PCIE_STATIC_SPARE2_A);
273962306a36Sopenharmony_ci	vpd_data->vpd_vers = vpd_vers;
274062306a36Sopenharmony_ci	vpd_data->fw_major = FW_HDR_FW_VER_MAJOR_G(fw_vers);
274162306a36Sopenharmony_ci	vpd_data->fw_minor = FW_HDR_FW_VER_MINOR_G(fw_vers);
274262306a36Sopenharmony_ci	vpd_data->fw_micro = FW_HDR_FW_VER_MICRO_G(fw_vers);
274362306a36Sopenharmony_ci	vpd_data->fw_build = FW_HDR_FW_VER_BUILD_G(fw_vers);
274462306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
274562306a36Sopenharmony_ci}
274662306a36Sopenharmony_ci
274762306a36Sopenharmony_cistatic int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
274862306a36Sopenharmony_ci			  struct cudbg_tid_data *tid_data)
274962306a36Sopenharmony_ci{
275062306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
275162306a36Sopenharmony_ci	int i, cmd_retry = 8;
275262306a36Sopenharmony_ci	u32 val;
275362306a36Sopenharmony_ci
275462306a36Sopenharmony_ci	/* Fill REQ_DATA regs with 0's */
275562306a36Sopenharmony_ci	for (i = 0; i < NUM_LE_DB_DBGI_REQ_DATA_INSTANCES; i++)
275662306a36Sopenharmony_ci		t4_write_reg(padap, LE_DB_DBGI_REQ_DATA_A + (i << 2), 0);
275762306a36Sopenharmony_ci
275862306a36Sopenharmony_ci	/* Write DBIG command */
275962306a36Sopenharmony_ci	val = DBGICMD_V(4) | DBGITID_V(tid);
276062306a36Sopenharmony_ci	t4_write_reg(padap, LE_DB_DBGI_REQ_TCAM_CMD_A, val);
276162306a36Sopenharmony_ci	tid_data->dbig_cmd = val;
276262306a36Sopenharmony_ci
276362306a36Sopenharmony_ci	val = DBGICMDSTRT_F | DBGICMDMODE_V(1); /* LE mode */
276462306a36Sopenharmony_ci	t4_write_reg(padap, LE_DB_DBGI_CONFIG_A, val);
276562306a36Sopenharmony_ci	tid_data->dbig_conf = val;
276662306a36Sopenharmony_ci
276762306a36Sopenharmony_ci	/* Poll the DBGICMDBUSY bit */
276862306a36Sopenharmony_ci	val = 1;
276962306a36Sopenharmony_ci	while (val) {
277062306a36Sopenharmony_ci		val = t4_read_reg(padap, LE_DB_DBGI_CONFIG_A);
277162306a36Sopenharmony_ci		val = val & DBGICMDBUSY_F;
277262306a36Sopenharmony_ci		cmd_retry--;
277362306a36Sopenharmony_ci		if (!cmd_retry)
277462306a36Sopenharmony_ci			return CUDBG_SYSTEM_ERROR;
277562306a36Sopenharmony_ci	}
277662306a36Sopenharmony_ci
277762306a36Sopenharmony_ci	/* Check RESP status */
277862306a36Sopenharmony_ci	val = t4_read_reg(padap, LE_DB_DBGI_RSP_STATUS_A);
277962306a36Sopenharmony_ci	tid_data->dbig_rsp_stat = val;
278062306a36Sopenharmony_ci	if (!(val & 1))
278162306a36Sopenharmony_ci		return CUDBG_SYSTEM_ERROR;
278262306a36Sopenharmony_ci
278362306a36Sopenharmony_ci	/* Read RESP data */
278462306a36Sopenharmony_ci	for (i = 0; i < NUM_LE_DB_DBGI_RSP_DATA_INSTANCES; i++)
278562306a36Sopenharmony_ci		tid_data->data[i] = t4_read_reg(padap,
278662306a36Sopenharmony_ci						LE_DB_DBGI_RSP_DATA_A +
278762306a36Sopenharmony_ci						(i << 2));
278862306a36Sopenharmony_ci	tid_data->tid = tid;
278962306a36Sopenharmony_ci	return 0;
279062306a36Sopenharmony_ci}
279162306a36Sopenharmony_ci
279262306a36Sopenharmony_cistatic int cudbg_get_le_type(u32 tid, struct cudbg_tcam tcam_region)
279362306a36Sopenharmony_ci{
279462306a36Sopenharmony_ci	int type = LE_ET_UNKNOWN;
279562306a36Sopenharmony_ci
279662306a36Sopenharmony_ci	if (tid < tcam_region.server_start)
279762306a36Sopenharmony_ci		type = LE_ET_TCAM_CON;
279862306a36Sopenharmony_ci	else if (tid < tcam_region.filter_start)
279962306a36Sopenharmony_ci		type = LE_ET_TCAM_SERVER;
280062306a36Sopenharmony_ci	else if (tid < tcam_region.clip_start)
280162306a36Sopenharmony_ci		type = LE_ET_TCAM_FILTER;
280262306a36Sopenharmony_ci	else if (tid < tcam_region.routing_start)
280362306a36Sopenharmony_ci		type = LE_ET_TCAM_CLIP;
280462306a36Sopenharmony_ci	else if (tid < tcam_region.tid_hash_base)
280562306a36Sopenharmony_ci		type = LE_ET_TCAM_ROUTING;
280662306a36Sopenharmony_ci	else if (tid < tcam_region.max_tid)
280762306a36Sopenharmony_ci		type = LE_ET_HASH_CON;
280862306a36Sopenharmony_ci	else
280962306a36Sopenharmony_ci		type = LE_ET_INVALID_TID;
281062306a36Sopenharmony_ci
281162306a36Sopenharmony_ci	return type;
281262306a36Sopenharmony_ci}
281362306a36Sopenharmony_ci
281462306a36Sopenharmony_cistatic int cudbg_is_ipv6_entry(struct cudbg_tid_data *tid_data,
281562306a36Sopenharmony_ci			       struct cudbg_tcam tcam_region)
281662306a36Sopenharmony_ci{
281762306a36Sopenharmony_ci	int ipv6 = 0;
281862306a36Sopenharmony_ci	int le_type;
281962306a36Sopenharmony_ci
282062306a36Sopenharmony_ci	le_type = cudbg_get_le_type(tid_data->tid, tcam_region);
282162306a36Sopenharmony_ci	if (tid_data->tid & 1)
282262306a36Sopenharmony_ci		return 0;
282362306a36Sopenharmony_ci
282462306a36Sopenharmony_ci	if (le_type == LE_ET_HASH_CON) {
282562306a36Sopenharmony_ci		ipv6 = tid_data->data[16] & 0x8000;
282662306a36Sopenharmony_ci	} else if (le_type == LE_ET_TCAM_CON) {
282762306a36Sopenharmony_ci		ipv6 = tid_data->data[16] & 0x8000;
282862306a36Sopenharmony_ci		if (ipv6)
282962306a36Sopenharmony_ci			ipv6 = tid_data->data[9] == 0x00C00000;
283062306a36Sopenharmony_ci	} else {
283162306a36Sopenharmony_ci		ipv6 = 0;
283262306a36Sopenharmony_ci	}
283362306a36Sopenharmony_ci	return ipv6;
283462306a36Sopenharmony_ci}
283562306a36Sopenharmony_ci
283662306a36Sopenharmony_civoid cudbg_fill_le_tcam_info(struct adapter *padap,
283762306a36Sopenharmony_ci			     struct cudbg_tcam *tcam_region)
283862306a36Sopenharmony_ci{
283962306a36Sopenharmony_ci	u32 value;
284062306a36Sopenharmony_ci
284162306a36Sopenharmony_ci	/* Get the LE regions */
284262306a36Sopenharmony_ci	value = t4_read_reg(padap, LE_DB_TID_HASHBASE_A); /* hash base index */
284362306a36Sopenharmony_ci	tcam_region->tid_hash_base = value;
284462306a36Sopenharmony_ci
284562306a36Sopenharmony_ci	/* Get routing table index */
284662306a36Sopenharmony_ci	value = t4_read_reg(padap, LE_DB_ROUTING_TABLE_INDEX_A);
284762306a36Sopenharmony_ci	tcam_region->routing_start = value;
284862306a36Sopenharmony_ci
284962306a36Sopenharmony_ci	/* Get clip table index. For T6 there is separate CLIP TCAM */
285062306a36Sopenharmony_ci	if (is_t6(padap->params.chip))
285162306a36Sopenharmony_ci		value = t4_read_reg(padap, LE_DB_CLCAM_TID_BASE_A);
285262306a36Sopenharmony_ci	else
285362306a36Sopenharmony_ci		value = t4_read_reg(padap, LE_DB_CLIP_TABLE_INDEX_A);
285462306a36Sopenharmony_ci	tcam_region->clip_start = value;
285562306a36Sopenharmony_ci
285662306a36Sopenharmony_ci	/* Get filter table index */
285762306a36Sopenharmony_ci	value = t4_read_reg(padap, LE_DB_FILTER_TABLE_INDEX_A);
285862306a36Sopenharmony_ci	tcam_region->filter_start = value;
285962306a36Sopenharmony_ci
286062306a36Sopenharmony_ci	/* Get server table index */
286162306a36Sopenharmony_ci	value = t4_read_reg(padap, LE_DB_SERVER_INDEX_A);
286262306a36Sopenharmony_ci	tcam_region->server_start = value;
286362306a36Sopenharmony_ci
286462306a36Sopenharmony_ci	/* Check whether hash is enabled and calculate the max tids */
286562306a36Sopenharmony_ci	value = t4_read_reg(padap, LE_DB_CONFIG_A);
286662306a36Sopenharmony_ci	if ((value >> HASHEN_S) & 1) {
286762306a36Sopenharmony_ci		value = t4_read_reg(padap, LE_DB_HASH_CONFIG_A);
286862306a36Sopenharmony_ci		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
286962306a36Sopenharmony_ci			tcam_region->max_tid = (value & 0xFFFFF) +
287062306a36Sopenharmony_ci					       tcam_region->tid_hash_base;
287162306a36Sopenharmony_ci		} else {
287262306a36Sopenharmony_ci			value = HASHTIDSIZE_G(value);
287362306a36Sopenharmony_ci			value = 1 << value;
287462306a36Sopenharmony_ci			tcam_region->max_tid = value +
287562306a36Sopenharmony_ci					       tcam_region->tid_hash_base;
287662306a36Sopenharmony_ci		}
287762306a36Sopenharmony_ci	} else { /* hash not enabled */
287862306a36Sopenharmony_ci		if (is_t6(padap->params.chip))
287962306a36Sopenharmony_ci			tcam_region->max_tid = (value & ASLIPCOMPEN_F) ?
288062306a36Sopenharmony_ci					       CUDBG_MAX_TID_COMP_EN :
288162306a36Sopenharmony_ci					       CUDBG_MAX_TID_COMP_DIS;
288262306a36Sopenharmony_ci		else
288362306a36Sopenharmony_ci			tcam_region->max_tid = CUDBG_MAX_TCAM_TID;
288462306a36Sopenharmony_ci	}
288562306a36Sopenharmony_ci
288662306a36Sopenharmony_ci	if (is_t6(padap->params.chip))
288762306a36Sopenharmony_ci		tcam_region->max_tid += CUDBG_T6_CLIP;
288862306a36Sopenharmony_ci}
288962306a36Sopenharmony_ci
289062306a36Sopenharmony_ciint cudbg_collect_le_tcam(struct cudbg_init *pdbg_init,
289162306a36Sopenharmony_ci			  struct cudbg_buffer *dbg_buff,
289262306a36Sopenharmony_ci			  struct cudbg_error *cudbg_err)
289362306a36Sopenharmony_ci{
289462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
289562306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
289662306a36Sopenharmony_ci	struct cudbg_tcam tcam_region = { 0 };
289762306a36Sopenharmony_ci	struct cudbg_tid_data *tid_data;
289862306a36Sopenharmony_ci	u32 bytes = 0;
289962306a36Sopenharmony_ci	int rc, size;
290062306a36Sopenharmony_ci	u32 i;
290162306a36Sopenharmony_ci
290262306a36Sopenharmony_ci	cudbg_fill_le_tcam_info(padap, &tcam_region);
290362306a36Sopenharmony_ci
290462306a36Sopenharmony_ci	size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
290562306a36Sopenharmony_ci	size += sizeof(struct cudbg_tcam);
290662306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
290762306a36Sopenharmony_ci	if (rc)
290862306a36Sopenharmony_ci		return rc;
290962306a36Sopenharmony_ci
291062306a36Sopenharmony_ci	memcpy(temp_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
291162306a36Sopenharmony_ci	bytes = sizeof(struct cudbg_tcam);
291262306a36Sopenharmony_ci	tid_data = (struct cudbg_tid_data *)(temp_buff.data + bytes);
291362306a36Sopenharmony_ci	/* read all tid */
291462306a36Sopenharmony_ci	for (i = 0; i < tcam_region.max_tid; ) {
291562306a36Sopenharmony_ci		rc = cudbg_read_tid(pdbg_init, i, tid_data);
291662306a36Sopenharmony_ci		if (rc) {
291762306a36Sopenharmony_ci			cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
291862306a36Sopenharmony_ci			/* Update tcam header and exit */
291962306a36Sopenharmony_ci			tcam_region.max_tid = i;
292062306a36Sopenharmony_ci			memcpy(temp_buff.data, &tcam_region,
292162306a36Sopenharmony_ci			       sizeof(struct cudbg_tcam));
292262306a36Sopenharmony_ci			goto out;
292362306a36Sopenharmony_ci		}
292462306a36Sopenharmony_ci
292562306a36Sopenharmony_ci		if (cudbg_is_ipv6_entry(tid_data, tcam_region)) {
292662306a36Sopenharmony_ci			/* T6 CLIP TCAM: ipv6 takes 4 entries */
292762306a36Sopenharmony_ci			if (is_t6(padap->params.chip) &&
292862306a36Sopenharmony_ci			    i >= tcam_region.clip_start &&
292962306a36Sopenharmony_ci			    i < tcam_region.clip_start + CUDBG_T6_CLIP)
293062306a36Sopenharmony_ci				i += 4;
293162306a36Sopenharmony_ci			else /* Main TCAM: ipv6 takes two tids */
293262306a36Sopenharmony_ci				i += 2;
293362306a36Sopenharmony_ci		} else {
293462306a36Sopenharmony_ci			i++;
293562306a36Sopenharmony_ci		}
293662306a36Sopenharmony_ci
293762306a36Sopenharmony_ci		tid_data++;
293862306a36Sopenharmony_ci		bytes += sizeof(struct cudbg_tid_data);
293962306a36Sopenharmony_ci	}
294062306a36Sopenharmony_ci
294162306a36Sopenharmony_ciout:
294262306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
294362306a36Sopenharmony_ci}
294462306a36Sopenharmony_ci
294562306a36Sopenharmony_ciint cudbg_collect_cctrl(struct cudbg_init *pdbg_init,
294662306a36Sopenharmony_ci			struct cudbg_buffer *dbg_buff,
294762306a36Sopenharmony_ci			struct cudbg_error *cudbg_err)
294862306a36Sopenharmony_ci{
294962306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
295062306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
295162306a36Sopenharmony_ci	u32 size;
295262306a36Sopenharmony_ci	int rc;
295362306a36Sopenharmony_ci
295462306a36Sopenharmony_ci	size = sizeof(u16) * NMTUS * NCCTRL_WIN;
295562306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
295662306a36Sopenharmony_ci	if (rc)
295762306a36Sopenharmony_ci		return rc;
295862306a36Sopenharmony_ci
295962306a36Sopenharmony_ci	t4_read_cong_tbl(padap, (void *)temp_buff.data);
296062306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
296162306a36Sopenharmony_ci}
296262306a36Sopenharmony_ci
296362306a36Sopenharmony_ciint cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
296462306a36Sopenharmony_ci			      struct cudbg_buffer *dbg_buff,
296562306a36Sopenharmony_ci			      struct cudbg_error *cudbg_err)
296662306a36Sopenharmony_ci{
296762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
296862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
296962306a36Sopenharmony_ci	struct ireg_buf *ma_indr;
297062306a36Sopenharmony_ci	int i, rc, n;
297162306a36Sopenharmony_ci	u32 size, j;
297262306a36Sopenharmony_ci
297362306a36Sopenharmony_ci	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
297462306a36Sopenharmony_ci		return CUDBG_STATUS_ENTITY_NOT_FOUND;
297562306a36Sopenharmony_ci
297662306a36Sopenharmony_ci	n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
297762306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n * 2;
297862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
297962306a36Sopenharmony_ci	if (rc)
298062306a36Sopenharmony_ci		return rc;
298162306a36Sopenharmony_ci
298262306a36Sopenharmony_ci	ma_indr = (struct ireg_buf *)temp_buff.data;
298362306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
298462306a36Sopenharmony_ci		struct ireg_field *ma_fli = &ma_indr->tp_pio;
298562306a36Sopenharmony_ci		u32 *buff = ma_indr->outbuf;
298662306a36Sopenharmony_ci
298762306a36Sopenharmony_ci		ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
298862306a36Sopenharmony_ci		ma_fli->ireg_data = t6_ma_ireg_array[i][1];
298962306a36Sopenharmony_ci		ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
299062306a36Sopenharmony_ci		ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
299162306a36Sopenharmony_ci		t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
299262306a36Sopenharmony_ci				 buff, ma_fli->ireg_offset_range,
299362306a36Sopenharmony_ci				 ma_fli->ireg_local_offset);
299462306a36Sopenharmony_ci		ma_indr++;
299562306a36Sopenharmony_ci	}
299662306a36Sopenharmony_ci
299762306a36Sopenharmony_ci	n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
299862306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
299962306a36Sopenharmony_ci		struct ireg_field *ma_fli = &ma_indr->tp_pio;
300062306a36Sopenharmony_ci		u32 *buff = ma_indr->outbuf;
300162306a36Sopenharmony_ci
300262306a36Sopenharmony_ci		ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
300362306a36Sopenharmony_ci		ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
300462306a36Sopenharmony_ci		ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
300562306a36Sopenharmony_ci		for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
300662306a36Sopenharmony_ci			t4_read_indirect(padap, ma_fli->ireg_addr,
300762306a36Sopenharmony_ci					 ma_fli->ireg_data, buff, 1,
300862306a36Sopenharmony_ci					 ma_fli->ireg_local_offset);
300962306a36Sopenharmony_ci			buff++;
301062306a36Sopenharmony_ci			ma_fli->ireg_local_offset += 0x20;
301162306a36Sopenharmony_ci		}
301262306a36Sopenharmony_ci		ma_indr++;
301362306a36Sopenharmony_ci	}
301462306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
301562306a36Sopenharmony_ci}
301662306a36Sopenharmony_ci
301762306a36Sopenharmony_ciint cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
301862306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
301962306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
302062306a36Sopenharmony_ci{
302162306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
302262306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
302362306a36Sopenharmony_ci	struct cudbg_ulptx_la *ulptx_la_buff;
302462306a36Sopenharmony_ci	struct cudbg_ver_hdr *ver_hdr;
302562306a36Sopenharmony_ci	u32 i, j;
302662306a36Sopenharmony_ci	int rc;
302762306a36Sopenharmony_ci
302862306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff,
302962306a36Sopenharmony_ci			    sizeof(struct cudbg_ver_hdr) +
303062306a36Sopenharmony_ci			    sizeof(struct cudbg_ulptx_la),
303162306a36Sopenharmony_ci			    &temp_buff);
303262306a36Sopenharmony_ci	if (rc)
303362306a36Sopenharmony_ci		return rc;
303462306a36Sopenharmony_ci
303562306a36Sopenharmony_ci	ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
303662306a36Sopenharmony_ci	ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
303762306a36Sopenharmony_ci	ver_hdr->revision = CUDBG_ULPTX_LA_REV;
303862306a36Sopenharmony_ci	ver_hdr->size = sizeof(struct cudbg_ulptx_la);
303962306a36Sopenharmony_ci
304062306a36Sopenharmony_ci	ulptx_la_buff = (struct cudbg_ulptx_la *)(temp_buff.data +
304162306a36Sopenharmony_ci						  sizeof(*ver_hdr));
304262306a36Sopenharmony_ci	for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
304362306a36Sopenharmony_ci		ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
304462306a36Sopenharmony_ci						      ULP_TX_LA_RDPTR_0_A +
304562306a36Sopenharmony_ci						      0x10 * i);
304662306a36Sopenharmony_ci		ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
304762306a36Sopenharmony_ci						      ULP_TX_LA_WRPTR_0_A +
304862306a36Sopenharmony_ci						      0x10 * i);
304962306a36Sopenharmony_ci		ulptx_la_buff->rddata[i] = t4_read_reg(padap,
305062306a36Sopenharmony_ci						       ULP_TX_LA_RDDATA_0_A +
305162306a36Sopenharmony_ci						       0x10 * i);
305262306a36Sopenharmony_ci		for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
305362306a36Sopenharmony_ci			ulptx_la_buff->rd_data[i][j] =
305462306a36Sopenharmony_ci				t4_read_reg(padap,
305562306a36Sopenharmony_ci					    ULP_TX_LA_RDDATA_0_A + 0x10 * i);
305662306a36Sopenharmony_ci	}
305762306a36Sopenharmony_ci
305862306a36Sopenharmony_ci	for (i = 0; i < CUDBG_NUM_ULPTX_ASIC_READ; i++) {
305962306a36Sopenharmony_ci		t4_write_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A, 0x1);
306062306a36Sopenharmony_ci		ulptx_la_buff->rdptr_asic[i] =
306162306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A);
306262306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][0] =
306362306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_0_A);
306462306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][1] =
306562306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_1_A);
306662306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][2] =
306762306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_2_A);
306862306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][3] =
306962306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_3_A);
307062306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][4] =
307162306a36Sopenharmony_ci				t4_read_reg(padap, ULP_TX_ASIC_DEBUG_4_A);
307262306a36Sopenharmony_ci		ulptx_la_buff->rddata_asic[i][5] =
307362306a36Sopenharmony_ci				t4_read_reg(padap, PM_RX_BASE_ADDR);
307462306a36Sopenharmony_ci	}
307562306a36Sopenharmony_ci
307662306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
307762306a36Sopenharmony_ci}
307862306a36Sopenharmony_ci
307962306a36Sopenharmony_ciint cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
308062306a36Sopenharmony_ci				  struct cudbg_buffer *dbg_buff,
308162306a36Sopenharmony_ci				  struct cudbg_error *cudbg_err)
308262306a36Sopenharmony_ci{
308362306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
308462306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
308562306a36Sopenharmony_ci	u32 local_offset, local_range;
308662306a36Sopenharmony_ci	struct ireg_buf *up_cim;
308762306a36Sopenharmony_ci	u32 size, j, iter;
308862306a36Sopenharmony_ci	u32 instance = 0;
308962306a36Sopenharmony_ci	int i, rc, n;
309062306a36Sopenharmony_ci
309162306a36Sopenharmony_ci	if (is_t5(padap->params.chip))
309262306a36Sopenharmony_ci		n = sizeof(t5_up_cim_reg_array) /
309362306a36Sopenharmony_ci		    ((IREG_NUM_ELEM + 1) * sizeof(u32));
309462306a36Sopenharmony_ci	else if (is_t6(padap->params.chip))
309562306a36Sopenharmony_ci		n = sizeof(t6_up_cim_reg_array) /
309662306a36Sopenharmony_ci		    ((IREG_NUM_ELEM + 1) * sizeof(u32));
309762306a36Sopenharmony_ci	else
309862306a36Sopenharmony_ci		return CUDBG_STATUS_NOT_IMPLEMENTED;
309962306a36Sopenharmony_ci
310062306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n;
310162306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
310262306a36Sopenharmony_ci	if (rc)
310362306a36Sopenharmony_ci		return rc;
310462306a36Sopenharmony_ci
310562306a36Sopenharmony_ci	up_cim = (struct ireg_buf *)temp_buff.data;
310662306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
310762306a36Sopenharmony_ci		struct ireg_field *up_cim_reg = &up_cim->tp_pio;
310862306a36Sopenharmony_ci		u32 *buff = up_cim->outbuf;
310962306a36Sopenharmony_ci
311062306a36Sopenharmony_ci		if (is_t5(padap->params.chip)) {
311162306a36Sopenharmony_ci			up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
311262306a36Sopenharmony_ci			up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
311362306a36Sopenharmony_ci			up_cim_reg->ireg_local_offset =
311462306a36Sopenharmony_ci						t5_up_cim_reg_array[i][2];
311562306a36Sopenharmony_ci			up_cim_reg->ireg_offset_range =
311662306a36Sopenharmony_ci						t5_up_cim_reg_array[i][3];
311762306a36Sopenharmony_ci			instance = t5_up_cim_reg_array[i][4];
311862306a36Sopenharmony_ci		} else if (is_t6(padap->params.chip)) {
311962306a36Sopenharmony_ci			up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
312062306a36Sopenharmony_ci			up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
312162306a36Sopenharmony_ci			up_cim_reg->ireg_local_offset =
312262306a36Sopenharmony_ci						t6_up_cim_reg_array[i][2];
312362306a36Sopenharmony_ci			up_cim_reg->ireg_offset_range =
312462306a36Sopenharmony_ci						t6_up_cim_reg_array[i][3];
312562306a36Sopenharmony_ci			instance = t6_up_cim_reg_array[i][4];
312662306a36Sopenharmony_ci		}
312762306a36Sopenharmony_ci
312862306a36Sopenharmony_ci		switch (instance) {
312962306a36Sopenharmony_ci		case NUM_CIM_CTL_TSCH_CHANNEL_INSTANCES:
313062306a36Sopenharmony_ci			iter = up_cim_reg->ireg_offset_range;
313162306a36Sopenharmony_ci			local_offset = 0x120;
313262306a36Sopenharmony_ci			local_range = 1;
313362306a36Sopenharmony_ci			break;
313462306a36Sopenharmony_ci		case NUM_CIM_CTL_TSCH_CHANNEL_TSCH_CLASS_INSTANCES:
313562306a36Sopenharmony_ci			iter = up_cim_reg->ireg_offset_range;
313662306a36Sopenharmony_ci			local_offset = 0x10;
313762306a36Sopenharmony_ci			local_range = 1;
313862306a36Sopenharmony_ci			break;
313962306a36Sopenharmony_ci		default:
314062306a36Sopenharmony_ci			iter = 1;
314162306a36Sopenharmony_ci			local_offset = 0;
314262306a36Sopenharmony_ci			local_range = up_cim_reg->ireg_offset_range;
314362306a36Sopenharmony_ci			break;
314462306a36Sopenharmony_ci		}
314562306a36Sopenharmony_ci
314662306a36Sopenharmony_ci		for (j = 0; j < iter; j++, buff++) {
314762306a36Sopenharmony_ci			rc = t4_cim_read(padap,
314862306a36Sopenharmony_ci					 up_cim_reg->ireg_local_offset +
314962306a36Sopenharmony_ci					 (j * local_offset), local_range, buff);
315062306a36Sopenharmony_ci			if (rc) {
315162306a36Sopenharmony_ci				cudbg_put_buff(pdbg_init, &temp_buff);
315262306a36Sopenharmony_ci				return rc;
315362306a36Sopenharmony_ci			}
315462306a36Sopenharmony_ci		}
315562306a36Sopenharmony_ci		up_cim++;
315662306a36Sopenharmony_ci	}
315762306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
315862306a36Sopenharmony_ci}
315962306a36Sopenharmony_ci
316062306a36Sopenharmony_ciint cudbg_collect_pbt_tables(struct cudbg_init *pdbg_init,
316162306a36Sopenharmony_ci			     struct cudbg_buffer *dbg_buff,
316262306a36Sopenharmony_ci			     struct cudbg_error *cudbg_err)
316362306a36Sopenharmony_ci{
316462306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
316562306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
316662306a36Sopenharmony_ci	struct cudbg_pbt_tables *pbt;
316762306a36Sopenharmony_ci	int i, rc;
316862306a36Sopenharmony_ci	u32 addr;
316962306a36Sopenharmony_ci
317062306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff,
317162306a36Sopenharmony_ci			    sizeof(struct cudbg_pbt_tables),
317262306a36Sopenharmony_ci			    &temp_buff);
317362306a36Sopenharmony_ci	if (rc)
317462306a36Sopenharmony_ci		return rc;
317562306a36Sopenharmony_ci
317662306a36Sopenharmony_ci	pbt = (struct cudbg_pbt_tables *)temp_buff.data;
317762306a36Sopenharmony_ci	/* PBT dynamic entries */
317862306a36Sopenharmony_ci	addr = CUDBG_CHAC_PBT_ADDR;
317962306a36Sopenharmony_ci	for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
318062306a36Sopenharmony_ci		rc = t4_cim_read(padap, addr + (i * 4), 1,
318162306a36Sopenharmony_ci				 &pbt->pbt_dynamic[i]);
318262306a36Sopenharmony_ci		if (rc) {
318362306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
318462306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
318562306a36Sopenharmony_ci			return rc;
318662306a36Sopenharmony_ci		}
318762306a36Sopenharmony_ci	}
318862306a36Sopenharmony_ci
318962306a36Sopenharmony_ci	/* PBT static entries */
319062306a36Sopenharmony_ci	/* static entries start when bit 6 is set */
319162306a36Sopenharmony_ci	addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
319262306a36Sopenharmony_ci	for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
319362306a36Sopenharmony_ci		rc = t4_cim_read(padap, addr + (i * 4), 1,
319462306a36Sopenharmony_ci				 &pbt->pbt_static[i]);
319562306a36Sopenharmony_ci		if (rc) {
319662306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
319762306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
319862306a36Sopenharmony_ci			return rc;
319962306a36Sopenharmony_ci		}
320062306a36Sopenharmony_ci	}
320162306a36Sopenharmony_ci
320262306a36Sopenharmony_ci	/* LRF entries */
320362306a36Sopenharmony_ci	addr = CUDBG_CHAC_PBT_LRF;
320462306a36Sopenharmony_ci	for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
320562306a36Sopenharmony_ci		rc = t4_cim_read(padap, addr + (i * 4), 1,
320662306a36Sopenharmony_ci				 &pbt->lrf_table[i]);
320762306a36Sopenharmony_ci		if (rc) {
320862306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
320962306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
321062306a36Sopenharmony_ci			return rc;
321162306a36Sopenharmony_ci		}
321262306a36Sopenharmony_ci	}
321362306a36Sopenharmony_ci
321462306a36Sopenharmony_ci	/* PBT data entries */
321562306a36Sopenharmony_ci	addr = CUDBG_CHAC_PBT_DATA;
321662306a36Sopenharmony_ci	for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
321762306a36Sopenharmony_ci		rc = t4_cim_read(padap, addr + (i * 4), 1,
321862306a36Sopenharmony_ci				 &pbt->pbt_data[i]);
321962306a36Sopenharmony_ci		if (rc) {
322062306a36Sopenharmony_ci			cudbg_err->sys_err = rc;
322162306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
322262306a36Sopenharmony_ci			return rc;
322362306a36Sopenharmony_ci		}
322462306a36Sopenharmony_ci	}
322562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
322662306a36Sopenharmony_ci}
322762306a36Sopenharmony_ci
322862306a36Sopenharmony_ciint cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
322962306a36Sopenharmony_ci			   struct cudbg_buffer *dbg_buff,
323062306a36Sopenharmony_ci			   struct cudbg_error *cudbg_err)
323162306a36Sopenharmony_ci{
323262306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
323362306a36Sopenharmony_ci	struct cudbg_mbox_log *mboxlog = NULL;
323462306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
323562306a36Sopenharmony_ci	struct mbox_cmd_log *log = NULL;
323662306a36Sopenharmony_ci	struct mbox_cmd *entry;
323762306a36Sopenharmony_ci	unsigned int entry_idx;
323862306a36Sopenharmony_ci	u16 mbox_cmds;
323962306a36Sopenharmony_ci	int i, k, rc;
324062306a36Sopenharmony_ci	u64 flit;
324162306a36Sopenharmony_ci	u32 size;
324262306a36Sopenharmony_ci
324362306a36Sopenharmony_ci	log = padap->mbox_log;
324462306a36Sopenharmony_ci	mbox_cmds = padap->mbox_log->size;
324562306a36Sopenharmony_ci	size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
324662306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
324762306a36Sopenharmony_ci	if (rc)
324862306a36Sopenharmony_ci		return rc;
324962306a36Sopenharmony_ci
325062306a36Sopenharmony_ci	mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
325162306a36Sopenharmony_ci	for (k = 0; k < mbox_cmds; k++) {
325262306a36Sopenharmony_ci		entry_idx = log->cursor + k;
325362306a36Sopenharmony_ci		if (entry_idx >= log->size)
325462306a36Sopenharmony_ci			entry_idx -= log->size;
325562306a36Sopenharmony_ci
325662306a36Sopenharmony_ci		entry = mbox_cmd_log_entry(log, entry_idx);
325762306a36Sopenharmony_ci		/* skip over unused entries */
325862306a36Sopenharmony_ci		if (entry->timestamp == 0)
325962306a36Sopenharmony_ci			continue;
326062306a36Sopenharmony_ci
326162306a36Sopenharmony_ci		memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
326262306a36Sopenharmony_ci		for (i = 0; i < MBOX_LEN / 8; i++) {
326362306a36Sopenharmony_ci			flit = entry->cmd[i];
326462306a36Sopenharmony_ci			mboxlog->hi[i] = (u32)(flit >> 32);
326562306a36Sopenharmony_ci			mboxlog->lo[i] = (u32)flit;
326662306a36Sopenharmony_ci		}
326762306a36Sopenharmony_ci		mboxlog++;
326862306a36Sopenharmony_ci	}
326962306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
327062306a36Sopenharmony_ci}
327162306a36Sopenharmony_ci
327262306a36Sopenharmony_ciint cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
327362306a36Sopenharmony_ci			       struct cudbg_buffer *dbg_buff,
327462306a36Sopenharmony_ci			       struct cudbg_error *cudbg_err)
327562306a36Sopenharmony_ci{
327662306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
327762306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
327862306a36Sopenharmony_ci	struct ireg_buf *hma_indr;
327962306a36Sopenharmony_ci	int i, rc, n;
328062306a36Sopenharmony_ci	u32 size;
328162306a36Sopenharmony_ci
328262306a36Sopenharmony_ci	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
328362306a36Sopenharmony_ci		return CUDBG_STATUS_ENTITY_NOT_FOUND;
328462306a36Sopenharmony_ci
328562306a36Sopenharmony_ci	n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
328662306a36Sopenharmony_ci	size = sizeof(struct ireg_buf) * n;
328762306a36Sopenharmony_ci	rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
328862306a36Sopenharmony_ci	if (rc)
328962306a36Sopenharmony_ci		return rc;
329062306a36Sopenharmony_ci
329162306a36Sopenharmony_ci	hma_indr = (struct ireg_buf *)temp_buff.data;
329262306a36Sopenharmony_ci	for (i = 0; i < n; i++) {
329362306a36Sopenharmony_ci		struct ireg_field *hma_fli = &hma_indr->tp_pio;
329462306a36Sopenharmony_ci		u32 *buff = hma_indr->outbuf;
329562306a36Sopenharmony_ci
329662306a36Sopenharmony_ci		hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
329762306a36Sopenharmony_ci		hma_fli->ireg_data = t6_hma_ireg_array[i][1];
329862306a36Sopenharmony_ci		hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
329962306a36Sopenharmony_ci		hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
330062306a36Sopenharmony_ci		t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
330162306a36Sopenharmony_ci				 buff, hma_fli->ireg_offset_range,
330262306a36Sopenharmony_ci				 hma_fli->ireg_local_offset);
330362306a36Sopenharmony_ci		hma_indr++;
330462306a36Sopenharmony_ci	}
330562306a36Sopenharmony_ci	return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
330662306a36Sopenharmony_ci}
330762306a36Sopenharmony_ci
330862306a36Sopenharmony_civoid cudbg_fill_qdesc_num_and_size(const struct adapter *padap,
330962306a36Sopenharmony_ci				   u32 *num, u32 *size)
331062306a36Sopenharmony_ci{
331162306a36Sopenharmony_ci	u32 tot_entries = 0, tot_size = 0;
331262306a36Sopenharmony_ci
331362306a36Sopenharmony_ci	/* NIC TXQ, RXQ, FLQ, and CTRLQ */
331462306a36Sopenharmony_ci	tot_entries += MAX_ETH_QSETS * 3;
331562306a36Sopenharmony_ci	tot_entries += MAX_CTRL_QUEUES;
331662306a36Sopenharmony_ci
331762306a36Sopenharmony_ci	tot_size += MAX_ETH_QSETS * MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
331862306a36Sopenharmony_ci	tot_size += MAX_ETH_QSETS * MAX_RSPQ_ENTRIES * MAX_RXQ_DESC_SIZE;
331962306a36Sopenharmony_ci	tot_size += MAX_ETH_QSETS * MAX_RX_BUFFERS * MAX_FL_DESC_SIZE;
332062306a36Sopenharmony_ci	tot_size += MAX_CTRL_QUEUES * MAX_CTRL_TXQ_ENTRIES *
332162306a36Sopenharmony_ci		    MAX_CTRL_TXQ_DESC_SIZE;
332262306a36Sopenharmony_ci
332362306a36Sopenharmony_ci	/* FW_EVTQ and INTRQ */
332462306a36Sopenharmony_ci	tot_entries += INGQ_EXTRAS;
332562306a36Sopenharmony_ci	tot_size += INGQ_EXTRAS * MAX_RSPQ_ENTRIES * MAX_RXQ_DESC_SIZE;
332662306a36Sopenharmony_ci
332762306a36Sopenharmony_ci	/* PTP_TXQ */
332862306a36Sopenharmony_ci	tot_entries += 1;
332962306a36Sopenharmony_ci	tot_size += MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
333062306a36Sopenharmony_ci
333162306a36Sopenharmony_ci	/* ULD TXQ, RXQ, and FLQ */
333262306a36Sopenharmony_ci	tot_entries += CXGB4_TX_MAX * MAX_OFLD_QSETS;
333362306a36Sopenharmony_ci	tot_entries += CXGB4_ULD_MAX * MAX_ULD_QSETS * 2;
333462306a36Sopenharmony_ci
333562306a36Sopenharmony_ci	tot_size += CXGB4_TX_MAX * MAX_OFLD_QSETS * MAX_TXQ_ENTRIES *
333662306a36Sopenharmony_ci		    MAX_TXQ_DESC_SIZE;
333762306a36Sopenharmony_ci	tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * MAX_RSPQ_ENTRIES *
333862306a36Sopenharmony_ci		    MAX_RXQ_DESC_SIZE;
333962306a36Sopenharmony_ci	tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * MAX_RX_BUFFERS *
334062306a36Sopenharmony_ci		    MAX_FL_DESC_SIZE;
334162306a36Sopenharmony_ci
334262306a36Sopenharmony_ci	/* ULD CIQ */
334362306a36Sopenharmony_ci	tot_entries += CXGB4_ULD_MAX * MAX_ULD_QSETS;
334462306a36Sopenharmony_ci	tot_size += CXGB4_ULD_MAX * MAX_ULD_QSETS * SGE_MAX_IQ_SIZE *
334562306a36Sopenharmony_ci		    MAX_RXQ_DESC_SIZE;
334662306a36Sopenharmony_ci
334762306a36Sopenharmony_ci	/* ETHOFLD TXQ, RXQ, and FLQ */
334862306a36Sopenharmony_ci	tot_entries += MAX_OFLD_QSETS * 3;
334962306a36Sopenharmony_ci	tot_size += MAX_OFLD_QSETS * MAX_TXQ_ENTRIES * MAX_TXQ_DESC_SIZE;
335062306a36Sopenharmony_ci
335162306a36Sopenharmony_ci	tot_size += sizeof(struct cudbg_ver_hdr) +
335262306a36Sopenharmony_ci		    sizeof(struct cudbg_qdesc_info) +
335362306a36Sopenharmony_ci		    sizeof(struct cudbg_qdesc_entry) * tot_entries;
335462306a36Sopenharmony_ci
335562306a36Sopenharmony_ci	if (num)
335662306a36Sopenharmony_ci		*num = tot_entries;
335762306a36Sopenharmony_ci
335862306a36Sopenharmony_ci	if (size)
335962306a36Sopenharmony_ci		*size = tot_size;
336062306a36Sopenharmony_ci}
336162306a36Sopenharmony_ci
336262306a36Sopenharmony_ciint cudbg_collect_qdesc(struct cudbg_init *pdbg_init,
336362306a36Sopenharmony_ci			struct cudbg_buffer *dbg_buff,
336462306a36Sopenharmony_ci			struct cudbg_error *cudbg_err)
336562306a36Sopenharmony_ci{
336662306a36Sopenharmony_ci	u32 num_queues = 0, tot_entries = 0, size = 0;
336762306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
336862306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = { 0 };
336962306a36Sopenharmony_ci	struct cudbg_qdesc_entry *qdesc_entry;
337062306a36Sopenharmony_ci	struct cudbg_qdesc_info *qdesc_info;
337162306a36Sopenharmony_ci	struct cudbg_ver_hdr *ver_hdr;
337262306a36Sopenharmony_ci	struct sge *s = &padap->sge;
337362306a36Sopenharmony_ci	u32 i, j, cur_off, tot_len;
337462306a36Sopenharmony_ci	u8 *data;
337562306a36Sopenharmony_ci	int rc;
337662306a36Sopenharmony_ci
337762306a36Sopenharmony_ci	cudbg_fill_qdesc_num_and_size(padap, &tot_entries, &size);
337862306a36Sopenharmony_ci	size = min_t(u32, size, CUDBG_DUMP_BUFF_SIZE);
337962306a36Sopenharmony_ci	tot_len = size;
338062306a36Sopenharmony_ci	data = kvzalloc(size, GFP_KERNEL);
338162306a36Sopenharmony_ci	if (!data)
338262306a36Sopenharmony_ci		return -ENOMEM;
338362306a36Sopenharmony_ci
338462306a36Sopenharmony_ci	ver_hdr = (struct cudbg_ver_hdr *)data;
338562306a36Sopenharmony_ci	ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
338662306a36Sopenharmony_ci	ver_hdr->revision = CUDBG_QDESC_REV;
338762306a36Sopenharmony_ci	ver_hdr->size = sizeof(struct cudbg_qdesc_info);
338862306a36Sopenharmony_ci	size -= sizeof(*ver_hdr);
338962306a36Sopenharmony_ci
339062306a36Sopenharmony_ci	qdesc_info = (struct cudbg_qdesc_info *)(data +
339162306a36Sopenharmony_ci						 sizeof(*ver_hdr));
339262306a36Sopenharmony_ci	size -= sizeof(*qdesc_info);
339362306a36Sopenharmony_ci	qdesc_entry = (struct cudbg_qdesc_entry *)qdesc_info->data;
339462306a36Sopenharmony_ci
339562306a36Sopenharmony_ci#define QDESC_GET(q, desc, type, label) do { \
339662306a36Sopenharmony_ci	if (size <= 0) { \
339762306a36Sopenharmony_ci		goto label; \
339862306a36Sopenharmony_ci	} \
339962306a36Sopenharmony_ci	if (desc) { \
340062306a36Sopenharmony_ci		cudbg_fill_qdesc_##q(q, type, qdesc_entry); \
340162306a36Sopenharmony_ci		size -= sizeof(*qdesc_entry) + qdesc_entry->data_size; \
340262306a36Sopenharmony_ci		num_queues++; \
340362306a36Sopenharmony_ci		qdesc_entry = cudbg_next_qdesc(qdesc_entry); \
340462306a36Sopenharmony_ci	} \
340562306a36Sopenharmony_ci} while (0)
340662306a36Sopenharmony_ci
340762306a36Sopenharmony_ci#define QDESC_GET_TXQ(q, type, label) do { \
340862306a36Sopenharmony_ci	struct sge_txq *txq = (struct sge_txq *)q; \
340962306a36Sopenharmony_ci	QDESC_GET(txq, txq->desc, type, label); \
341062306a36Sopenharmony_ci} while (0)
341162306a36Sopenharmony_ci
341262306a36Sopenharmony_ci#define QDESC_GET_RXQ(q, type, label) do { \
341362306a36Sopenharmony_ci	struct sge_rspq *rxq = (struct sge_rspq *)q; \
341462306a36Sopenharmony_ci	QDESC_GET(rxq, rxq->desc, type, label); \
341562306a36Sopenharmony_ci} while (0)
341662306a36Sopenharmony_ci
341762306a36Sopenharmony_ci#define QDESC_GET_FLQ(q, type, label) do { \
341862306a36Sopenharmony_ci	struct sge_fl *flq = (struct sge_fl *)q; \
341962306a36Sopenharmony_ci	QDESC_GET(flq, flq->desc, type, label); \
342062306a36Sopenharmony_ci} while (0)
342162306a36Sopenharmony_ci
342262306a36Sopenharmony_ci	/* NIC TXQ */
342362306a36Sopenharmony_ci	for (i = 0; i < s->ethqsets; i++)
342462306a36Sopenharmony_ci		QDESC_GET_TXQ(&s->ethtxq[i].q, CUDBG_QTYPE_NIC_TXQ, out);
342562306a36Sopenharmony_ci
342662306a36Sopenharmony_ci	/* NIC RXQ */
342762306a36Sopenharmony_ci	for (i = 0; i < s->ethqsets; i++)
342862306a36Sopenharmony_ci		QDESC_GET_RXQ(&s->ethrxq[i].rspq, CUDBG_QTYPE_NIC_RXQ, out);
342962306a36Sopenharmony_ci
343062306a36Sopenharmony_ci	/* NIC FLQ */
343162306a36Sopenharmony_ci	for (i = 0; i < s->ethqsets; i++)
343262306a36Sopenharmony_ci		QDESC_GET_FLQ(&s->ethrxq[i].fl, CUDBG_QTYPE_NIC_FLQ, out);
343362306a36Sopenharmony_ci
343462306a36Sopenharmony_ci	/* NIC CTRLQ */
343562306a36Sopenharmony_ci	for (i = 0; i < padap->params.nports; i++)
343662306a36Sopenharmony_ci		QDESC_GET_TXQ(&s->ctrlq[i].q, CUDBG_QTYPE_CTRLQ, out);
343762306a36Sopenharmony_ci
343862306a36Sopenharmony_ci	/* FW_EVTQ */
343962306a36Sopenharmony_ci	QDESC_GET_RXQ(&s->fw_evtq, CUDBG_QTYPE_FWEVTQ, out);
344062306a36Sopenharmony_ci
344162306a36Sopenharmony_ci	/* INTRQ */
344262306a36Sopenharmony_ci	QDESC_GET_RXQ(&s->intrq, CUDBG_QTYPE_INTRQ, out);
344362306a36Sopenharmony_ci
344462306a36Sopenharmony_ci	/* PTP_TXQ */
344562306a36Sopenharmony_ci	QDESC_GET_TXQ(&s->ptptxq.q, CUDBG_QTYPE_PTP_TXQ, out);
344662306a36Sopenharmony_ci
344762306a36Sopenharmony_ci	/* ULD Queues */
344862306a36Sopenharmony_ci	mutex_lock(&uld_mutex);
344962306a36Sopenharmony_ci
345062306a36Sopenharmony_ci	if (s->uld_txq_info) {
345162306a36Sopenharmony_ci		struct sge_uld_txq_info *utxq;
345262306a36Sopenharmony_ci
345362306a36Sopenharmony_ci		/* ULD TXQ */
345462306a36Sopenharmony_ci		for (j = 0; j < CXGB4_TX_MAX; j++) {
345562306a36Sopenharmony_ci			if (!s->uld_txq_info[j])
345662306a36Sopenharmony_ci				continue;
345762306a36Sopenharmony_ci
345862306a36Sopenharmony_ci			utxq = s->uld_txq_info[j];
345962306a36Sopenharmony_ci			for (i = 0; i < utxq->ntxq; i++)
346062306a36Sopenharmony_ci				QDESC_GET_TXQ(&utxq->uldtxq[i].q,
346162306a36Sopenharmony_ci					      cudbg_uld_txq_to_qtype(j),
346262306a36Sopenharmony_ci					      out_unlock_uld);
346362306a36Sopenharmony_ci		}
346462306a36Sopenharmony_ci	}
346562306a36Sopenharmony_ci
346662306a36Sopenharmony_ci	if (s->uld_rxq_info) {
346762306a36Sopenharmony_ci		struct sge_uld_rxq_info *urxq;
346862306a36Sopenharmony_ci		u32 base;
346962306a36Sopenharmony_ci
347062306a36Sopenharmony_ci		/* ULD RXQ */
347162306a36Sopenharmony_ci		for (j = 0; j < CXGB4_ULD_MAX; j++) {
347262306a36Sopenharmony_ci			if (!s->uld_rxq_info[j])
347362306a36Sopenharmony_ci				continue;
347462306a36Sopenharmony_ci
347562306a36Sopenharmony_ci			urxq = s->uld_rxq_info[j];
347662306a36Sopenharmony_ci			for (i = 0; i < urxq->nrxq; i++)
347762306a36Sopenharmony_ci				QDESC_GET_RXQ(&urxq->uldrxq[i].rspq,
347862306a36Sopenharmony_ci					      cudbg_uld_rxq_to_qtype(j),
347962306a36Sopenharmony_ci					      out_unlock_uld);
348062306a36Sopenharmony_ci		}
348162306a36Sopenharmony_ci
348262306a36Sopenharmony_ci		/* ULD FLQ */
348362306a36Sopenharmony_ci		for (j = 0; j < CXGB4_ULD_MAX; j++) {
348462306a36Sopenharmony_ci			if (!s->uld_rxq_info[j])
348562306a36Sopenharmony_ci				continue;
348662306a36Sopenharmony_ci
348762306a36Sopenharmony_ci			urxq = s->uld_rxq_info[j];
348862306a36Sopenharmony_ci			for (i = 0; i < urxq->nrxq; i++)
348962306a36Sopenharmony_ci				QDESC_GET_FLQ(&urxq->uldrxq[i].fl,
349062306a36Sopenharmony_ci					      cudbg_uld_flq_to_qtype(j),
349162306a36Sopenharmony_ci					      out_unlock_uld);
349262306a36Sopenharmony_ci		}
349362306a36Sopenharmony_ci
349462306a36Sopenharmony_ci		/* ULD CIQ */
349562306a36Sopenharmony_ci		for (j = 0; j < CXGB4_ULD_MAX; j++) {
349662306a36Sopenharmony_ci			if (!s->uld_rxq_info[j])
349762306a36Sopenharmony_ci				continue;
349862306a36Sopenharmony_ci
349962306a36Sopenharmony_ci			urxq = s->uld_rxq_info[j];
350062306a36Sopenharmony_ci			base = urxq->nrxq;
350162306a36Sopenharmony_ci			for (i = 0; i < urxq->nciq; i++)
350262306a36Sopenharmony_ci				QDESC_GET_RXQ(&urxq->uldrxq[base + i].rspq,
350362306a36Sopenharmony_ci					      cudbg_uld_ciq_to_qtype(j),
350462306a36Sopenharmony_ci					      out_unlock_uld);
350562306a36Sopenharmony_ci		}
350662306a36Sopenharmony_ci	}
350762306a36Sopenharmony_ci	mutex_unlock(&uld_mutex);
350862306a36Sopenharmony_ci
350962306a36Sopenharmony_ci	if (!padap->tc_mqprio)
351062306a36Sopenharmony_ci		goto out;
351162306a36Sopenharmony_ci
351262306a36Sopenharmony_ci	mutex_lock(&padap->tc_mqprio->mqprio_mutex);
351362306a36Sopenharmony_ci	/* ETHOFLD TXQ */
351462306a36Sopenharmony_ci	if (s->eohw_txq)
351562306a36Sopenharmony_ci		for (i = 0; i < s->eoqsets; i++)
351662306a36Sopenharmony_ci			QDESC_GET_TXQ(&s->eohw_txq[i].q,
351762306a36Sopenharmony_ci				      CUDBG_QTYPE_ETHOFLD_TXQ, out_unlock_mqprio);
351862306a36Sopenharmony_ci
351962306a36Sopenharmony_ci	/* ETHOFLD RXQ and FLQ */
352062306a36Sopenharmony_ci	if (s->eohw_rxq) {
352162306a36Sopenharmony_ci		for (i = 0; i < s->eoqsets; i++)
352262306a36Sopenharmony_ci			QDESC_GET_RXQ(&s->eohw_rxq[i].rspq,
352362306a36Sopenharmony_ci				      CUDBG_QTYPE_ETHOFLD_RXQ, out_unlock_mqprio);
352462306a36Sopenharmony_ci
352562306a36Sopenharmony_ci		for (i = 0; i < s->eoqsets; i++)
352662306a36Sopenharmony_ci			QDESC_GET_FLQ(&s->eohw_rxq[i].fl,
352762306a36Sopenharmony_ci				      CUDBG_QTYPE_ETHOFLD_FLQ, out_unlock_mqprio);
352862306a36Sopenharmony_ci	}
352962306a36Sopenharmony_ci
353062306a36Sopenharmony_ciout_unlock_mqprio:
353162306a36Sopenharmony_ci	mutex_unlock(&padap->tc_mqprio->mqprio_mutex);
353262306a36Sopenharmony_ci
353362306a36Sopenharmony_ciout:
353462306a36Sopenharmony_ci	qdesc_info->qdesc_entry_size = sizeof(*qdesc_entry);
353562306a36Sopenharmony_ci	qdesc_info->num_queues = num_queues;
353662306a36Sopenharmony_ci	cur_off = 0;
353762306a36Sopenharmony_ci	while (tot_len) {
353862306a36Sopenharmony_ci		u32 chunk_size = min_t(u32, tot_len, CUDBG_CHUNK_SIZE);
353962306a36Sopenharmony_ci
354062306a36Sopenharmony_ci		rc = cudbg_get_buff(pdbg_init, dbg_buff, chunk_size,
354162306a36Sopenharmony_ci				    &temp_buff);
354262306a36Sopenharmony_ci		if (rc) {
354362306a36Sopenharmony_ci			cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
354462306a36Sopenharmony_ci			goto out_free;
354562306a36Sopenharmony_ci		}
354662306a36Sopenharmony_ci
354762306a36Sopenharmony_ci		memcpy(temp_buff.data, data + cur_off, chunk_size);
354862306a36Sopenharmony_ci		tot_len -= chunk_size;
354962306a36Sopenharmony_ci		cur_off += chunk_size;
355062306a36Sopenharmony_ci		rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
355162306a36Sopenharmony_ci						  dbg_buff);
355262306a36Sopenharmony_ci		if (rc) {
355362306a36Sopenharmony_ci			cudbg_put_buff(pdbg_init, &temp_buff);
355462306a36Sopenharmony_ci			cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
355562306a36Sopenharmony_ci			goto out_free;
355662306a36Sopenharmony_ci		}
355762306a36Sopenharmony_ci	}
355862306a36Sopenharmony_ci
355962306a36Sopenharmony_ciout_free:
356062306a36Sopenharmony_ci	kvfree(data);
356162306a36Sopenharmony_ci
356262306a36Sopenharmony_ci#undef QDESC_GET_FLQ
356362306a36Sopenharmony_ci#undef QDESC_GET_RXQ
356462306a36Sopenharmony_ci#undef QDESC_GET_TXQ
356562306a36Sopenharmony_ci#undef QDESC_GET
356662306a36Sopenharmony_ci
356762306a36Sopenharmony_ci	return rc;
356862306a36Sopenharmony_ci
356962306a36Sopenharmony_ciout_unlock_uld:
357062306a36Sopenharmony_ci	mutex_unlock(&uld_mutex);
357162306a36Sopenharmony_ci	goto out;
357262306a36Sopenharmony_ci}
357362306a36Sopenharmony_ci
357462306a36Sopenharmony_ciint cudbg_collect_flash(struct cudbg_init *pdbg_init,
357562306a36Sopenharmony_ci			struct cudbg_buffer *dbg_buff,
357662306a36Sopenharmony_ci			struct cudbg_error *cudbg_err)
357762306a36Sopenharmony_ci{
357862306a36Sopenharmony_ci	struct adapter *padap = pdbg_init->adap;
357962306a36Sopenharmony_ci	u32 count = padap->params.sf_size, n;
358062306a36Sopenharmony_ci	struct cudbg_buffer temp_buff = {0};
358162306a36Sopenharmony_ci	u32 addr, i;
358262306a36Sopenharmony_ci	int rc;
358362306a36Sopenharmony_ci
358462306a36Sopenharmony_ci	addr = FLASH_EXP_ROM_START;
358562306a36Sopenharmony_ci
358662306a36Sopenharmony_ci	for (i = 0; i < count; i += SF_PAGE_SIZE) {
358762306a36Sopenharmony_ci		n = min_t(u32, count - i, SF_PAGE_SIZE);
358862306a36Sopenharmony_ci
358962306a36Sopenharmony_ci		rc = cudbg_get_buff(pdbg_init, dbg_buff, n, &temp_buff);
359062306a36Sopenharmony_ci		if (rc) {
359162306a36Sopenharmony_ci			cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
359262306a36Sopenharmony_ci			goto out;
359362306a36Sopenharmony_ci		}
359462306a36Sopenharmony_ci		rc = t4_read_flash(padap, addr, n, (u32 *)temp_buff.data, 0);
359562306a36Sopenharmony_ci		if (rc)
359662306a36Sopenharmony_ci			goto out;
359762306a36Sopenharmony_ci
359862306a36Sopenharmony_ci		addr += (n * 4);
359962306a36Sopenharmony_ci		rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
360062306a36Sopenharmony_ci						  dbg_buff);
360162306a36Sopenharmony_ci		if (rc) {
360262306a36Sopenharmony_ci			cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
360362306a36Sopenharmony_ci			goto out;
360462306a36Sopenharmony_ci		}
360562306a36Sopenharmony_ci	}
360662306a36Sopenharmony_ci
360762306a36Sopenharmony_ciout:
360862306a36Sopenharmony_ci	return rc;
360962306a36Sopenharmony_ci}
3610