1a7975a2fSRahul Lakkireddy /*
2a7975a2fSRahul Lakkireddy  *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
3a7975a2fSRahul Lakkireddy  *
4a7975a2fSRahul Lakkireddy  *  This program is free software; you can redistribute it and/or modify it
5a7975a2fSRahul Lakkireddy  *  under the terms and conditions of the GNU General Public License,
6a7975a2fSRahul Lakkireddy  *  version 2, as published by the Free Software Foundation.
7a7975a2fSRahul Lakkireddy  *
8a7975a2fSRahul Lakkireddy  *  This program is distributed in the hope it will be useful, but WITHOUT
9a7975a2fSRahul Lakkireddy  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10a7975a2fSRahul Lakkireddy  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11a7975a2fSRahul Lakkireddy  *  more details.
12a7975a2fSRahul Lakkireddy  *
13a7975a2fSRahul Lakkireddy  *  The full GNU General Public License is included in this distribution in
14a7975a2fSRahul Lakkireddy  *  the file called "COPYING".
15a7975a2fSRahul Lakkireddy  *
16a7975a2fSRahul Lakkireddy  */
17a7975a2fSRahul Lakkireddy 
18123e25c4SRahul Lakkireddy #include <linux/sort.h>
19123e25c4SRahul Lakkireddy 
20b33af022SRahul Lakkireddy #include "t4_regs.h"
21a7975a2fSRahul Lakkireddy #include "cxgb4.h"
22a7975a2fSRahul Lakkireddy #include "cudbg_if.h"
23a7975a2fSRahul Lakkireddy #include "cudbg_lib_common.h"
24b33af022SRahul Lakkireddy #include "cudbg_entity.h"
25123e25c4SRahul Lakkireddy #include "cudbg_lib.h"
26a7975a2fSRahul Lakkireddy 
27a7975a2fSRahul Lakkireddy static void cudbg_write_and_release_buff(struct cudbg_buffer *pin_buff,
28a7975a2fSRahul Lakkireddy 					 struct cudbg_buffer *dbg_buff)
29a7975a2fSRahul Lakkireddy {
30a7975a2fSRahul Lakkireddy 	cudbg_update_buff(pin_buff, dbg_buff);
31a7975a2fSRahul Lakkireddy 	cudbg_put_buff(pin_buff, dbg_buff);
32a7975a2fSRahul Lakkireddy }
33a7975a2fSRahul Lakkireddy 
34b33af022SRahul Lakkireddy static int is_fw_attached(struct cudbg_init *pdbg_init)
35b33af022SRahul Lakkireddy {
36b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
37b33af022SRahul Lakkireddy 
38b33af022SRahul Lakkireddy 	if (!(padap->flags & FW_OK) || padap->use_bd)
39b33af022SRahul Lakkireddy 		return 0;
40b33af022SRahul Lakkireddy 
41b33af022SRahul Lakkireddy 	return 1;
42b33af022SRahul Lakkireddy }
43b33af022SRahul Lakkireddy 
44a7975a2fSRahul Lakkireddy /* This function will add additional padding bytes into debug_buffer to make it
45a7975a2fSRahul Lakkireddy  * 4 byte aligned.
46a7975a2fSRahul Lakkireddy  */
47a7975a2fSRahul Lakkireddy void cudbg_align_debug_buffer(struct cudbg_buffer *dbg_buff,
48a7975a2fSRahul Lakkireddy 			      struct cudbg_entity_hdr *entity_hdr)
49a7975a2fSRahul Lakkireddy {
50a7975a2fSRahul Lakkireddy 	u8 zero_buf[4] = {0};
51a7975a2fSRahul Lakkireddy 	u8 padding, remain;
52a7975a2fSRahul Lakkireddy 
53a7975a2fSRahul Lakkireddy 	remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
54a7975a2fSRahul Lakkireddy 	padding = 4 - remain;
55a7975a2fSRahul Lakkireddy 	if (remain) {
56a7975a2fSRahul Lakkireddy 		memcpy(((u8 *)dbg_buff->data) + dbg_buff->offset, &zero_buf,
57a7975a2fSRahul Lakkireddy 		       padding);
58a7975a2fSRahul Lakkireddy 		dbg_buff->offset += padding;
59a7975a2fSRahul Lakkireddy 		entity_hdr->num_pad = padding;
60a7975a2fSRahul Lakkireddy 	}
61a7975a2fSRahul Lakkireddy 	entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
62a7975a2fSRahul Lakkireddy }
63a7975a2fSRahul Lakkireddy 
64a7975a2fSRahul Lakkireddy struct cudbg_entity_hdr *cudbg_get_entity_hdr(void *outbuf, int i)
65a7975a2fSRahul Lakkireddy {
66a7975a2fSRahul Lakkireddy 	struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
67a7975a2fSRahul Lakkireddy 
68a7975a2fSRahul Lakkireddy 	return (struct cudbg_entity_hdr *)
69a7975a2fSRahul Lakkireddy 	       ((char *)outbuf + cudbg_hdr->hdr_len +
70a7975a2fSRahul Lakkireddy 		(sizeof(struct cudbg_entity_hdr) * (i - 1)));
71a7975a2fSRahul Lakkireddy }
72a7975a2fSRahul Lakkireddy 
73940c9c45SRahul Lakkireddy static int cudbg_read_vpd_reg(struct adapter *padap, u32 addr, u32 len,
74940c9c45SRahul Lakkireddy 			      void *dest)
75940c9c45SRahul Lakkireddy {
76940c9c45SRahul Lakkireddy 	int vaddr, rc;
77940c9c45SRahul Lakkireddy 
78940c9c45SRahul Lakkireddy 	vaddr = t4_eeprom_ptov(addr, padap->pf, EEPROMPFSIZE);
79940c9c45SRahul Lakkireddy 	if (vaddr < 0)
80940c9c45SRahul Lakkireddy 		return vaddr;
81940c9c45SRahul Lakkireddy 
82940c9c45SRahul Lakkireddy 	rc = pci_read_vpd(padap->pdev, vaddr, len, dest);
83940c9c45SRahul Lakkireddy 	if (rc < 0)
84940c9c45SRahul Lakkireddy 		return rc;
85940c9c45SRahul Lakkireddy 
86940c9c45SRahul Lakkireddy 	return 0;
87940c9c45SRahul Lakkireddy }
88940c9c45SRahul Lakkireddy 
89123e25c4SRahul Lakkireddy static int cudbg_mem_desc_cmp(const void *a, const void *b)
90123e25c4SRahul Lakkireddy {
91123e25c4SRahul Lakkireddy 	return ((const struct cudbg_mem_desc *)a)->base -
92123e25c4SRahul Lakkireddy 	       ((const struct cudbg_mem_desc *)b)->base;
93123e25c4SRahul Lakkireddy }
94123e25c4SRahul Lakkireddy 
95123e25c4SRahul Lakkireddy int cudbg_fill_meminfo(struct adapter *padap,
96123e25c4SRahul Lakkireddy 		       struct cudbg_meminfo *meminfo_buff)
97123e25c4SRahul Lakkireddy {
98123e25c4SRahul Lakkireddy 	struct cudbg_mem_desc *md;
99123e25c4SRahul Lakkireddy 	u32 lo, hi, used, alloc;
100123e25c4SRahul Lakkireddy 	int n, i;
101123e25c4SRahul Lakkireddy 
102123e25c4SRahul Lakkireddy 	memset(meminfo_buff->avail, 0,
103123e25c4SRahul Lakkireddy 	       ARRAY_SIZE(meminfo_buff->avail) *
104123e25c4SRahul Lakkireddy 	       sizeof(struct cudbg_mem_desc));
105123e25c4SRahul Lakkireddy 	memset(meminfo_buff->mem, 0,
106123e25c4SRahul Lakkireddy 	       (ARRAY_SIZE(cudbg_region) + 3) * sizeof(struct cudbg_mem_desc));
107123e25c4SRahul Lakkireddy 	md  = meminfo_buff->mem;
108123e25c4SRahul Lakkireddy 
109123e25c4SRahul Lakkireddy 	for (i = 0; i < ARRAY_SIZE(meminfo_buff->mem); i++) {
110123e25c4SRahul Lakkireddy 		meminfo_buff->mem[i].limit = 0;
111123e25c4SRahul Lakkireddy 		meminfo_buff->mem[i].idx = i;
112123e25c4SRahul Lakkireddy 	}
113123e25c4SRahul Lakkireddy 
114123e25c4SRahul Lakkireddy 	/* Find and sort the populated memory ranges */
115123e25c4SRahul Lakkireddy 	i = 0;
116123e25c4SRahul Lakkireddy 	lo = t4_read_reg(padap, MA_TARGET_MEM_ENABLE_A);
117123e25c4SRahul Lakkireddy 	if (lo & EDRAM0_ENABLE_F) {
118123e25c4SRahul Lakkireddy 		hi = t4_read_reg(padap, MA_EDRAM0_BAR_A);
119123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].base =
120123e25c4SRahul Lakkireddy 			cudbg_mbytes_to_bytes(EDRAM0_BASE_G(hi));
121123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].limit =
122123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].base +
123123e25c4SRahul Lakkireddy 			cudbg_mbytes_to_bytes(EDRAM0_SIZE_G(hi));
124123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].idx = 0;
125123e25c4SRahul Lakkireddy 		i++;
126123e25c4SRahul Lakkireddy 	}
127123e25c4SRahul Lakkireddy 
128123e25c4SRahul Lakkireddy 	if (lo & EDRAM1_ENABLE_F) {
129123e25c4SRahul Lakkireddy 		hi =  t4_read_reg(padap, MA_EDRAM1_BAR_A);
130123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].base =
131123e25c4SRahul Lakkireddy 			cudbg_mbytes_to_bytes(EDRAM1_BASE_G(hi));
132123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].limit =
133123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].base +
134123e25c4SRahul Lakkireddy 			cudbg_mbytes_to_bytes(EDRAM1_SIZE_G(hi));
135123e25c4SRahul Lakkireddy 		meminfo_buff->avail[i].idx = 1;
136123e25c4SRahul Lakkireddy 		i++;
137123e25c4SRahul Lakkireddy 	}
138123e25c4SRahul Lakkireddy 
139123e25c4SRahul Lakkireddy 	if (is_t5(padap->params.chip)) {
140123e25c4SRahul Lakkireddy 		if (lo & EXT_MEM0_ENABLE_F) {
141123e25c4SRahul Lakkireddy 			hi = t4_read_reg(padap, MA_EXT_MEMORY0_BAR_A);
142123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].base =
143123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
144123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].limit =
145123e25c4SRahul Lakkireddy 				meminfo_buff->avail[i].base +
146123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
147123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].idx = 3;
148123e25c4SRahul Lakkireddy 			i++;
149123e25c4SRahul Lakkireddy 		}
150123e25c4SRahul Lakkireddy 
151123e25c4SRahul Lakkireddy 		if (lo & EXT_MEM1_ENABLE_F) {
152123e25c4SRahul Lakkireddy 			hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
153123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].base =
154123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
155123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].limit =
156123e25c4SRahul Lakkireddy 				meminfo_buff->avail[i].base +
157123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
158123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].idx = 4;
159123e25c4SRahul Lakkireddy 			i++;
160123e25c4SRahul Lakkireddy 		}
161123e25c4SRahul Lakkireddy 	} else {
162123e25c4SRahul Lakkireddy 		if (lo & EXT_MEM_ENABLE_F) {
163123e25c4SRahul Lakkireddy 			hi = t4_read_reg(padap, MA_EXT_MEMORY_BAR_A);
164123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].base =
165123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
166123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].limit =
167123e25c4SRahul Lakkireddy 				meminfo_buff->avail[i].base +
168123e25c4SRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
169123e25c4SRahul Lakkireddy 			meminfo_buff->avail[i].idx = 2;
170123e25c4SRahul Lakkireddy 			i++;
171123e25c4SRahul Lakkireddy 		}
1724db0401fSRahul Lakkireddy 
1734db0401fSRahul Lakkireddy 		if (lo & HMA_MUX_F) {
1744db0401fSRahul Lakkireddy 			hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
1754db0401fSRahul Lakkireddy 			meminfo_buff->avail[i].base =
1764db0401fSRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
1774db0401fSRahul Lakkireddy 			meminfo_buff->avail[i].limit =
1784db0401fSRahul Lakkireddy 				meminfo_buff->avail[i].base +
1794db0401fSRahul Lakkireddy 				cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
1804db0401fSRahul Lakkireddy 			meminfo_buff->avail[i].idx = 5;
1814db0401fSRahul Lakkireddy 			i++;
1824db0401fSRahul Lakkireddy 		}
183123e25c4SRahul Lakkireddy 	}
184123e25c4SRahul Lakkireddy 
185123e25c4SRahul Lakkireddy 	if (!i) /* no memory available */
186123e25c4SRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
187123e25c4SRahul Lakkireddy 
188123e25c4SRahul Lakkireddy 	meminfo_buff->avail_c = i;
189123e25c4SRahul Lakkireddy 	sort(meminfo_buff->avail, i, sizeof(struct cudbg_mem_desc),
190123e25c4SRahul Lakkireddy 	     cudbg_mem_desc_cmp, NULL);
191123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, SGE_DBQ_CTXT_BADDR_A);
192123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, SGE_IMSG_CTXT_BADDR_A);
193123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, SGE_FLM_CACHE_BADDR_A);
194123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_TCB_BASE_A);
195123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_MM_BASE_A);
196123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_TIMER_BASE_A);
197123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_MM_RX_FLST_BASE_A);
198123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_MM_TX_FLST_BASE_A);
199123e25c4SRahul Lakkireddy 	(md++)->base = t4_read_reg(padap, TP_CMM_MM_PS_FLST_BASE_A);
200123e25c4SRahul Lakkireddy 
201123e25c4SRahul Lakkireddy 	/* the next few have explicit upper bounds */
202123e25c4SRahul Lakkireddy 	md->base = t4_read_reg(padap, TP_PMM_TX_BASE_A);
203123e25c4SRahul Lakkireddy 	md->limit = md->base - 1 +
204123e25c4SRahul Lakkireddy 		    t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A) *
205123e25c4SRahul Lakkireddy 		    PMTXMAXPAGE_G(t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A));
206123e25c4SRahul Lakkireddy 	md++;
207123e25c4SRahul Lakkireddy 
208123e25c4SRahul Lakkireddy 	md->base = t4_read_reg(padap, TP_PMM_RX_BASE_A);
209123e25c4SRahul Lakkireddy 	md->limit = md->base - 1 +
210123e25c4SRahul Lakkireddy 		    t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) *
211123e25c4SRahul Lakkireddy 		    PMRXMAXPAGE_G(t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A));
212123e25c4SRahul Lakkireddy 	md++;
213123e25c4SRahul Lakkireddy 
214123e25c4SRahul Lakkireddy 	if (t4_read_reg(padap, LE_DB_CONFIG_A) & HASHEN_F) {
215123e25c4SRahul Lakkireddy 		if (CHELSIO_CHIP_VERSION(padap->params.chip) <= CHELSIO_T5) {
216123e25c4SRahul Lakkireddy 			hi = t4_read_reg(padap, LE_DB_TID_HASHBASE_A) / 4;
217123e25c4SRahul Lakkireddy 			md->base = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
218123e25c4SRahul Lakkireddy 		} else {
219123e25c4SRahul Lakkireddy 			hi = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
220123e25c4SRahul Lakkireddy 			md->base = t4_read_reg(padap,
221123e25c4SRahul Lakkireddy 					       LE_DB_HASH_TBL_BASE_ADDR_A);
222123e25c4SRahul Lakkireddy 		}
223123e25c4SRahul Lakkireddy 		md->limit = 0;
224123e25c4SRahul Lakkireddy 	} else {
225123e25c4SRahul Lakkireddy 		md->base = 0;
226123e25c4SRahul Lakkireddy 		md->idx = ARRAY_SIZE(cudbg_region);  /* hide it */
227123e25c4SRahul Lakkireddy 	}
228123e25c4SRahul Lakkireddy 	md++;
229123e25c4SRahul Lakkireddy 
230123e25c4SRahul Lakkireddy #define ulp_region(reg) do { \
231123e25c4SRahul Lakkireddy 	md->base = t4_read_reg(padap, ULP_ ## reg ## _LLIMIT_A);\
232123e25c4SRahul Lakkireddy 	(md++)->limit = t4_read_reg(padap, ULP_ ## reg ## _ULIMIT_A);\
233123e25c4SRahul Lakkireddy } while (0)
234123e25c4SRahul Lakkireddy 
235123e25c4SRahul Lakkireddy 	ulp_region(RX_ISCSI);
236123e25c4SRahul Lakkireddy 	ulp_region(RX_TDDP);
237123e25c4SRahul Lakkireddy 	ulp_region(TX_TPT);
238123e25c4SRahul Lakkireddy 	ulp_region(RX_STAG);
239123e25c4SRahul Lakkireddy 	ulp_region(RX_RQ);
240123e25c4SRahul Lakkireddy 	ulp_region(RX_RQUDP);
241123e25c4SRahul Lakkireddy 	ulp_region(RX_PBL);
242123e25c4SRahul Lakkireddy 	ulp_region(TX_PBL);
243123e25c4SRahul Lakkireddy #undef ulp_region
244123e25c4SRahul Lakkireddy 	md->base = 0;
245123e25c4SRahul Lakkireddy 	md->idx = ARRAY_SIZE(cudbg_region);
246123e25c4SRahul Lakkireddy 	if (!is_t4(padap->params.chip)) {
247123e25c4SRahul Lakkireddy 		u32 fifo_size = t4_read_reg(padap, SGE_DBVFIFO_SIZE_A);
248123e25c4SRahul Lakkireddy 		u32 sge_ctrl = t4_read_reg(padap, SGE_CONTROL2_A);
249123e25c4SRahul Lakkireddy 		u32 size = 0;
250123e25c4SRahul Lakkireddy 
251123e25c4SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
252123e25c4SRahul Lakkireddy 			if (sge_ctrl & VFIFO_ENABLE_F)
253123e25c4SRahul Lakkireddy 				size = DBVFIFO_SIZE_G(fifo_size);
254123e25c4SRahul Lakkireddy 		} else {
255123e25c4SRahul Lakkireddy 			size = T6_DBVFIFO_SIZE_G(fifo_size);
256123e25c4SRahul Lakkireddy 		}
257123e25c4SRahul Lakkireddy 
258123e25c4SRahul Lakkireddy 		if (size) {
259123e25c4SRahul Lakkireddy 			md->base = BASEADDR_G(t4_read_reg(padap,
260123e25c4SRahul Lakkireddy 							  SGE_DBVFIFO_BADDR_A));
261123e25c4SRahul Lakkireddy 			md->limit = md->base + (size << 2) - 1;
262123e25c4SRahul Lakkireddy 		}
263123e25c4SRahul Lakkireddy 	}
264123e25c4SRahul Lakkireddy 
265123e25c4SRahul Lakkireddy 	md++;
266123e25c4SRahul Lakkireddy 
267123e25c4SRahul Lakkireddy 	md->base = t4_read_reg(padap, ULP_RX_CTX_BASE_A);
268123e25c4SRahul Lakkireddy 	md->limit = 0;
269123e25c4SRahul Lakkireddy 	md++;
270123e25c4SRahul Lakkireddy 	md->base = t4_read_reg(padap, ULP_TX_ERR_TABLE_BASE_A);
271123e25c4SRahul Lakkireddy 	md->limit = 0;
272123e25c4SRahul Lakkireddy 	md++;
273123e25c4SRahul Lakkireddy 
274123e25c4SRahul Lakkireddy 	md->base = padap->vres.ocq.start;
275123e25c4SRahul Lakkireddy 	if (padap->vres.ocq.size)
276123e25c4SRahul Lakkireddy 		md->limit = md->base + padap->vres.ocq.size - 1;
277123e25c4SRahul Lakkireddy 	else
278123e25c4SRahul Lakkireddy 		md->idx = ARRAY_SIZE(cudbg_region);  /* hide it */
279123e25c4SRahul Lakkireddy 	md++;
280123e25c4SRahul Lakkireddy 
281123e25c4SRahul Lakkireddy 	/* add any address-space holes, there can be up to 3 */
282123e25c4SRahul Lakkireddy 	for (n = 0; n < i - 1; n++)
283123e25c4SRahul Lakkireddy 		if (meminfo_buff->avail[n].limit <
284123e25c4SRahul Lakkireddy 		    meminfo_buff->avail[n + 1].base)
285123e25c4SRahul Lakkireddy 			(md++)->base = meminfo_buff->avail[n].limit;
286123e25c4SRahul Lakkireddy 
287123e25c4SRahul Lakkireddy 	if (meminfo_buff->avail[n].limit)
288123e25c4SRahul Lakkireddy 		(md++)->base = meminfo_buff->avail[n].limit;
289123e25c4SRahul Lakkireddy 
290123e25c4SRahul Lakkireddy 	n = md - meminfo_buff->mem;
291123e25c4SRahul Lakkireddy 	meminfo_buff->mem_c = n;
292123e25c4SRahul Lakkireddy 
293123e25c4SRahul Lakkireddy 	sort(meminfo_buff->mem, n, sizeof(struct cudbg_mem_desc),
294123e25c4SRahul Lakkireddy 	     cudbg_mem_desc_cmp, NULL);
295123e25c4SRahul Lakkireddy 
296123e25c4SRahul Lakkireddy 	lo = t4_read_reg(padap, CIM_SDRAM_BASE_ADDR_A);
297123e25c4SRahul Lakkireddy 	hi = t4_read_reg(padap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
298123e25c4SRahul Lakkireddy 	meminfo_buff->up_ram_lo = lo;
299123e25c4SRahul Lakkireddy 	meminfo_buff->up_ram_hi = hi;
300123e25c4SRahul Lakkireddy 
301123e25c4SRahul Lakkireddy 	lo = t4_read_reg(padap, CIM_EXTMEM2_BASE_ADDR_A);
302123e25c4SRahul Lakkireddy 	hi = t4_read_reg(padap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
303123e25c4SRahul Lakkireddy 	meminfo_buff->up_extmem2_lo = lo;
304123e25c4SRahul Lakkireddy 	meminfo_buff->up_extmem2_hi = hi;
305123e25c4SRahul Lakkireddy 
306123e25c4SRahul Lakkireddy 	lo = t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A);
307123e25c4SRahul Lakkireddy 	meminfo_buff->rx_pages_data[0] =  PMRXMAXPAGE_G(lo);
308123e25c4SRahul Lakkireddy 	meminfo_buff->rx_pages_data[1] =
309123e25c4SRahul Lakkireddy 		t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) >> 10;
310123e25c4SRahul Lakkireddy 	meminfo_buff->rx_pages_data[2] = (lo & PMRXNUMCHN_F) ? 2 : 1;
311123e25c4SRahul Lakkireddy 
312123e25c4SRahul Lakkireddy 	lo = t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A);
313123e25c4SRahul Lakkireddy 	hi = t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A);
314123e25c4SRahul Lakkireddy 	meminfo_buff->tx_pages_data[0] = PMTXMAXPAGE_G(lo);
315123e25c4SRahul Lakkireddy 	meminfo_buff->tx_pages_data[1] =
316123e25c4SRahul Lakkireddy 		hi >= (1 << 20) ? (hi >> 20) : (hi >> 10);
317123e25c4SRahul Lakkireddy 	meminfo_buff->tx_pages_data[2] =
318123e25c4SRahul Lakkireddy 		hi >= (1 << 20) ? 'M' : 'K';
319123e25c4SRahul Lakkireddy 	meminfo_buff->tx_pages_data[3] = 1 << PMTXNUMCHN_G(lo);
320123e25c4SRahul Lakkireddy 
321123e25c4SRahul Lakkireddy 	meminfo_buff->p_structs = t4_read_reg(padap, TP_CMM_MM_MAX_PSTRUCT_A);
322123e25c4SRahul Lakkireddy 
323123e25c4SRahul Lakkireddy 	for (i = 0; i < 4; i++) {
324123e25c4SRahul Lakkireddy 		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
325123e25c4SRahul Lakkireddy 			lo = t4_read_reg(padap,
326123e25c4SRahul Lakkireddy 					 MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
327123e25c4SRahul Lakkireddy 		else
328123e25c4SRahul Lakkireddy 			lo = t4_read_reg(padap, MPS_RX_PG_RSV0_A + i * 4);
329123e25c4SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
330123e25c4SRahul Lakkireddy 			used = T5_USED_G(lo);
331123e25c4SRahul Lakkireddy 			alloc = T5_ALLOC_G(lo);
332123e25c4SRahul Lakkireddy 		} else {
333123e25c4SRahul Lakkireddy 			used = USED_G(lo);
334123e25c4SRahul Lakkireddy 			alloc = ALLOC_G(lo);
335123e25c4SRahul Lakkireddy 		}
336123e25c4SRahul Lakkireddy 		meminfo_buff->port_used[i] = used;
337123e25c4SRahul Lakkireddy 		meminfo_buff->port_alloc[i] = alloc;
338123e25c4SRahul Lakkireddy 	}
339123e25c4SRahul Lakkireddy 
340123e25c4SRahul Lakkireddy 	for (i = 0; i < padap->params.arch.nchan; i++) {
341123e25c4SRahul Lakkireddy 		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
342123e25c4SRahul Lakkireddy 			lo = t4_read_reg(padap,
343123e25c4SRahul Lakkireddy 					 MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
344123e25c4SRahul Lakkireddy 		else
345123e25c4SRahul Lakkireddy 			lo = t4_read_reg(padap, MPS_RX_PG_RSV4_A + i * 4);
346123e25c4SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
347123e25c4SRahul Lakkireddy 			used = T5_USED_G(lo);
348123e25c4SRahul Lakkireddy 			alloc = T5_ALLOC_G(lo);
349123e25c4SRahul Lakkireddy 		} else {
350123e25c4SRahul Lakkireddy 			used = USED_G(lo);
351123e25c4SRahul Lakkireddy 			alloc = ALLOC_G(lo);
352123e25c4SRahul Lakkireddy 		}
353123e25c4SRahul Lakkireddy 		meminfo_buff->loopback_used[i] = used;
354123e25c4SRahul Lakkireddy 		meminfo_buff->loopback_alloc[i] = alloc;
355123e25c4SRahul Lakkireddy 	}
356123e25c4SRahul Lakkireddy 
357123e25c4SRahul Lakkireddy 	return 0;
358123e25c4SRahul Lakkireddy }
359123e25c4SRahul Lakkireddy 
360a7975a2fSRahul Lakkireddy int cudbg_collect_reg_dump(struct cudbg_init *pdbg_init,
361a7975a2fSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
362a7975a2fSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
363a7975a2fSRahul Lakkireddy {
364a7975a2fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
365a7975a2fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
366a7975a2fSRahul Lakkireddy 	u32 buf_size = 0;
367a7975a2fSRahul Lakkireddy 	int rc = 0;
368a7975a2fSRahul Lakkireddy 
369a7975a2fSRahul Lakkireddy 	if (is_t4(padap->params.chip))
370a7975a2fSRahul Lakkireddy 		buf_size = T4_REGMAP_SIZE;
371a7975a2fSRahul Lakkireddy 	else if (is_t5(padap->params.chip) || is_t6(padap->params.chip))
372a7975a2fSRahul Lakkireddy 		buf_size = T5_REGMAP_SIZE;
373a7975a2fSRahul Lakkireddy 
374a7975a2fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, buf_size, &temp_buff);
375a7975a2fSRahul Lakkireddy 	if (rc)
376a7975a2fSRahul Lakkireddy 		return rc;
377a7975a2fSRahul Lakkireddy 	t4_get_regs(padap, (void *)temp_buff.data, temp_buff.size);
378a7975a2fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
379a7975a2fSRahul Lakkireddy 	return rc;
380a7975a2fSRahul Lakkireddy }
381b33af022SRahul Lakkireddy 
382844d1b6fSRahul Lakkireddy int cudbg_collect_fw_devlog(struct cudbg_init *pdbg_init,
383844d1b6fSRahul Lakkireddy 			    struct cudbg_buffer *dbg_buff,
384844d1b6fSRahul Lakkireddy 			    struct cudbg_error *cudbg_err)
385844d1b6fSRahul Lakkireddy {
386844d1b6fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
387844d1b6fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
388844d1b6fSRahul Lakkireddy 	struct devlog_params *dparams;
389844d1b6fSRahul Lakkireddy 	int rc = 0;
390844d1b6fSRahul Lakkireddy 
391844d1b6fSRahul Lakkireddy 	rc = t4_init_devlog_params(padap);
392844d1b6fSRahul Lakkireddy 	if (rc < 0) {
393844d1b6fSRahul Lakkireddy 		cudbg_err->sys_err = rc;
394844d1b6fSRahul Lakkireddy 		return rc;
395844d1b6fSRahul Lakkireddy 	}
396844d1b6fSRahul Lakkireddy 
397844d1b6fSRahul Lakkireddy 	dparams = &padap->params.devlog;
398844d1b6fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, dparams->size, &temp_buff);
399844d1b6fSRahul Lakkireddy 	if (rc)
400844d1b6fSRahul Lakkireddy 		return rc;
401844d1b6fSRahul Lakkireddy 
402844d1b6fSRahul Lakkireddy 	/* Collect FW devlog */
403844d1b6fSRahul Lakkireddy 	if (dparams->start != 0) {
404844d1b6fSRahul Lakkireddy 		spin_lock(&padap->win0_lock);
405844d1b6fSRahul Lakkireddy 		rc = t4_memory_rw(padap, padap->params.drv_memwin,
406844d1b6fSRahul Lakkireddy 				  dparams->memtype, dparams->start,
407844d1b6fSRahul Lakkireddy 				  dparams->size,
408844d1b6fSRahul Lakkireddy 				  (__be32 *)(char *)temp_buff.data,
409844d1b6fSRahul Lakkireddy 				  1);
410844d1b6fSRahul Lakkireddy 		spin_unlock(&padap->win0_lock);
411844d1b6fSRahul Lakkireddy 		if (rc) {
412844d1b6fSRahul Lakkireddy 			cudbg_err->sys_err = rc;
413844d1b6fSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
414844d1b6fSRahul Lakkireddy 			return rc;
415844d1b6fSRahul Lakkireddy 		}
416844d1b6fSRahul Lakkireddy 	}
417844d1b6fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
418844d1b6fSRahul Lakkireddy 	return rc;
419844d1b6fSRahul Lakkireddy }
420844d1b6fSRahul Lakkireddy 
42127887bc7SRahul Lakkireddy int cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
42227887bc7SRahul Lakkireddy 			 struct cudbg_buffer *dbg_buff,
42327887bc7SRahul Lakkireddy 			 struct cudbg_error *cudbg_err)
42427887bc7SRahul Lakkireddy {
42527887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
42627887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
42727887bc7SRahul Lakkireddy 	int size, rc;
42827887bc7SRahul Lakkireddy 	u32 cfg = 0;
42927887bc7SRahul Lakkireddy 
43027887bc7SRahul Lakkireddy 	if (is_t6(padap->params.chip)) {
43127887bc7SRahul Lakkireddy 		size = padap->params.cim_la_size / 10 + 1;
43227887bc7SRahul Lakkireddy 		size *= 11 * sizeof(u32);
43327887bc7SRahul Lakkireddy 	} else {
43427887bc7SRahul Lakkireddy 		size = padap->params.cim_la_size / 8;
43527887bc7SRahul Lakkireddy 		size *= 8 * sizeof(u32);
43627887bc7SRahul Lakkireddy 	}
43727887bc7SRahul Lakkireddy 
43827887bc7SRahul Lakkireddy 	size += sizeof(cfg);
43927887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
44027887bc7SRahul Lakkireddy 	if (rc)
44127887bc7SRahul Lakkireddy 		return rc;
44227887bc7SRahul Lakkireddy 
44327887bc7SRahul Lakkireddy 	rc = t4_cim_read(padap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
44427887bc7SRahul Lakkireddy 	if (rc) {
44527887bc7SRahul Lakkireddy 		cudbg_err->sys_err = rc;
44627887bc7SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
44727887bc7SRahul Lakkireddy 		return rc;
44827887bc7SRahul Lakkireddy 	}
44927887bc7SRahul Lakkireddy 
45027887bc7SRahul Lakkireddy 	memcpy((char *)temp_buff.data, &cfg, sizeof(cfg));
45127887bc7SRahul Lakkireddy 	rc = t4_cim_read_la(padap,
45227887bc7SRahul Lakkireddy 			    (u32 *)((char *)temp_buff.data + sizeof(cfg)),
45327887bc7SRahul Lakkireddy 			    NULL);
45427887bc7SRahul Lakkireddy 	if (rc < 0) {
45527887bc7SRahul Lakkireddy 		cudbg_err->sys_err = rc;
45627887bc7SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
45727887bc7SRahul Lakkireddy 		return rc;
45827887bc7SRahul Lakkireddy 	}
45927887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
46027887bc7SRahul Lakkireddy 	return rc;
46127887bc7SRahul Lakkireddy }
46227887bc7SRahul Lakkireddy 
46327887bc7SRahul Lakkireddy int cudbg_collect_cim_ma_la(struct cudbg_init *pdbg_init,
46427887bc7SRahul Lakkireddy 			    struct cudbg_buffer *dbg_buff,
46527887bc7SRahul Lakkireddy 			    struct cudbg_error *cudbg_err)
46627887bc7SRahul Lakkireddy {
46727887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
46827887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
46927887bc7SRahul Lakkireddy 	int size, rc;
47027887bc7SRahul Lakkireddy 
47127887bc7SRahul Lakkireddy 	size = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
47227887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
47327887bc7SRahul Lakkireddy 	if (rc)
47427887bc7SRahul Lakkireddy 		return rc;
47527887bc7SRahul Lakkireddy 
47627887bc7SRahul Lakkireddy 	t4_cim_read_ma_la(padap,
47727887bc7SRahul Lakkireddy 			  (u32 *)temp_buff.data,
47827887bc7SRahul Lakkireddy 			  (u32 *)((char *)temp_buff.data +
47927887bc7SRahul Lakkireddy 				  5 * CIM_MALA_SIZE));
48027887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
48127887bc7SRahul Lakkireddy 	return rc;
48227887bc7SRahul Lakkireddy }
48327887bc7SRahul Lakkireddy 
4843044d0fbSRahul Lakkireddy int cudbg_collect_cim_qcfg(struct cudbg_init *pdbg_init,
4853044d0fbSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
4863044d0fbSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
4873044d0fbSRahul Lakkireddy {
4883044d0fbSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
4893044d0fbSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
4903044d0fbSRahul Lakkireddy 	struct cudbg_cim_qcfg *cim_qcfg_data;
4913044d0fbSRahul Lakkireddy 	int rc;
4923044d0fbSRahul Lakkireddy 
4933044d0fbSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_cim_qcfg),
4943044d0fbSRahul Lakkireddy 			    &temp_buff);
4953044d0fbSRahul Lakkireddy 	if (rc)
4963044d0fbSRahul Lakkireddy 		return rc;
4973044d0fbSRahul Lakkireddy 
4983044d0fbSRahul Lakkireddy 	cim_qcfg_data = (struct cudbg_cim_qcfg *)temp_buff.data;
4993044d0fbSRahul Lakkireddy 	cim_qcfg_data->chip = padap->params.chip;
5003044d0fbSRahul Lakkireddy 	rc = t4_cim_read(padap, UP_IBQ_0_RDADDR_A,
5013044d0fbSRahul Lakkireddy 			 ARRAY_SIZE(cim_qcfg_data->stat), cim_qcfg_data->stat);
5023044d0fbSRahul Lakkireddy 	if (rc) {
5033044d0fbSRahul Lakkireddy 		cudbg_err->sys_err = rc;
5043044d0fbSRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
5053044d0fbSRahul Lakkireddy 		return rc;
5063044d0fbSRahul Lakkireddy 	}
5073044d0fbSRahul Lakkireddy 
5083044d0fbSRahul Lakkireddy 	rc = t4_cim_read(padap, UP_OBQ_0_REALADDR_A,
5093044d0fbSRahul Lakkireddy 			 ARRAY_SIZE(cim_qcfg_data->obq_wr),
5103044d0fbSRahul Lakkireddy 			 cim_qcfg_data->obq_wr);
5113044d0fbSRahul Lakkireddy 	if (rc) {
5123044d0fbSRahul Lakkireddy 		cudbg_err->sys_err = rc;
5133044d0fbSRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
5143044d0fbSRahul Lakkireddy 		return rc;
5153044d0fbSRahul Lakkireddy 	}
5163044d0fbSRahul Lakkireddy 
5173044d0fbSRahul Lakkireddy 	t4_read_cimq_cfg(padap, cim_qcfg_data->base, cim_qcfg_data->size,
5183044d0fbSRahul Lakkireddy 			 cim_qcfg_data->thres);
5193044d0fbSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
5203044d0fbSRahul Lakkireddy 	return rc;
5213044d0fbSRahul Lakkireddy }
5223044d0fbSRahul Lakkireddy 
5237c075ce2SRahul Lakkireddy static int cudbg_read_cim_ibq(struct cudbg_init *pdbg_init,
5247c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
5257c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err, int qid)
5267c075ce2SRahul Lakkireddy {
5277c075ce2SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
5287c075ce2SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
5297c075ce2SRahul Lakkireddy 	int no_of_read_words, rc = 0;
5307c075ce2SRahul Lakkireddy 	u32 qsize;
5317c075ce2SRahul Lakkireddy 
5327c075ce2SRahul Lakkireddy 	/* collect CIM IBQ */
5337c075ce2SRahul Lakkireddy 	qsize = CIM_IBQ_SIZE * 4 * sizeof(u32);
5347c075ce2SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, qsize, &temp_buff);
5357c075ce2SRahul Lakkireddy 	if (rc)
5367c075ce2SRahul Lakkireddy 		return rc;
5377c075ce2SRahul Lakkireddy 
5387c075ce2SRahul Lakkireddy 	/* t4_read_cim_ibq will return no. of read words or error */
5397c075ce2SRahul Lakkireddy 	no_of_read_words = t4_read_cim_ibq(padap, qid,
540acfdf7eaSRahul Lakkireddy 					   (u32 *)temp_buff.data, qsize);
5417c075ce2SRahul Lakkireddy 	/* no_of_read_words is less than or equal to 0 means error */
5427c075ce2SRahul Lakkireddy 	if (no_of_read_words <= 0) {
5437c075ce2SRahul Lakkireddy 		if (!no_of_read_words)
5447c075ce2SRahul Lakkireddy 			rc = CUDBG_SYSTEM_ERROR;
5457c075ce2SRahul Lakkireddy 		else
5467c075ce2SRahul Lakkireddy 			rc = no_of_read_words;
5477c075ce2SRahul Lakkireddy 		cudbg_err->sys_err = rc;
5487c075ce2SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
5497c075ce2SRahul Lakkireddy 		return rc;
5507c075ce2SRahul Lakkireddy 	}
5517c075ce2SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
5527c075ce2SRahul Lakkireddy 	return rc;
5537c075ce2SRahul Lakkireddy }
5547c075ce2SRahul Lakkireddy 
5557c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
5567c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
5577c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
5587c075ce2SRahul Lakkireddy {
5597c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 0);
5607c075ce2SRahul Lakkireddy }
5617c075ce2SRahul Lakkireddy 
5627c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
5637c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
5647c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
5657c075ce2SRahul Lakkireddy {
5667c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 1);
5677c075ce2SRahul Lakkireddy }
5687c075ce2SRahul Lakkireddy 
5697c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
5707c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
5717c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
5727c075ce2SRahul Lakkireddy {
5737c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 2);
5747c075ce2SRahul Lakkireddy }
5757c075ce2SRahul Lakkireddy 
5767c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
5777c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
5787c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
5797c075ce2SRahul Lakkireddy {
5807c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 3);
5817c075ce2SRahul Lakkireddy }
5827c075ce2SRahul Lakkireddy 
5837c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
5847c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
5857c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
5867c075ce2SRahul Lakkireddy {
5877c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 4);
5887c075ce2SRahul Lakkireddy }
5897c075ce2SRahul Lakkireddy 
5907c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
5917c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
5927c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
5937c075ce2SRahul Lakkireddy {
5947c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 5);
5957c075ce2SRahul Lakkireddy }
5967c075ce2SRahul Lakkireddy 
597acfdf7eaSRahul Lakkireddy u32 cudbg_cim_obq_size(struct adapter *padap, int qid)
598acfdf7eaSRahul Lakkireddy {
599acfdf7eaSRahul Lakkireddy 	u32 value;
600acfdf7eaSRahul Lakkireddy 
601acfdf7eaSRahul Lakkireddy 	t4_write_reg(padap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
602acfdf7eaSRahul Lakkireddy 		     QUENUMSELECT_V(qid));
603acfdf7eaSRahul Lakkireddy 	value = t4_read_reg(padap, CIM_QUEUE_CONFIG_CTRL_A);
604acfdf7eaSRahul Lakkireddy 	value = CIMQSIZE_G(value) * 64; /* size in number of words */
605acfdf7eaSRahul Lakkireddy 	return value * sizeof(u32);
606acfdf7eaSRahul Lakkireddy }
607acfdf7eaSRahul Lakkireddy 
6087c075ce2SRahul Lakkireddy static int cudbg_read_cim_obq(struct cudbg_init *pdbg_init,
6097c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
6107c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err, int qid)
6117c075ce2SRahul Lakkireddy {
6127c075ce2SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
6137c075ce2SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
6147c075ce2SRahul Lakkireddy 	int no_of_read_words, rc = 0;
6157c075ce2SRahul Lakkireddy 	u32 qsize;
6167c075ce2SRahul Lakkireddy 
6177c075ce2SRahul Lakkireddy 	/* collect CIM OBQ */
618acfdf7eaSRahul Lakkireddy 	qsize =  cudbg_cim_obq_size(padap, qid);
6197c075ce2SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, qsize, &temp_buff);
6207c075ce2SRahul Lakkireddy 	if (rc)
6217c075ce2SRahul Lakkireddy 		return rc;
6227c075ce2SRahul Lakkireddy 
6237c075ce2SRahul Lakkireddy 	/* t4_read_cim_obq will return no. of read words or error */
6247c075ce2SRahul Lakkireddy 	no_of_read_words = t4_read_cim_obq(padap, qid,
625acfdf7eaSRahul Lakkireddy 					   (u32 *)temp_buff.data, qsize);
6267c075ce2SRahul Lakkireddy 	/* no_of_read_words is less than or equal to 0 means error */
6277c075ce2SRahul Lakkireddy 	if (no_of_read_words <= 0) {
6287c075ce2SRahul Lakkireddy 		if (!no_of_read_words)
6297c075ce2SRahul Lakkireddy 			rc = CUDBG_SYSTEM_ERROR;
6307c075ce2SRahul Lakkireddy 		else
6317c075ce2SRahul Lakkireddy 			rc = no_of_read_words;
6327c075ce2SRahul Lakkireddy 		cudbg_err->sys_err = rc;
6337c075ce2SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
6347c075ce2SRahul Lakkireddy 		return rc;
6357c075ce2SRahul Lakkireddy 	}
6367c075ce2SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
6377c075ce2SRahul Lakkireddy 	return rc;
6387c075ce2SRahul Lakkireddy }
6397c075ce2SRahul Lakkireddy 
6407c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
6417c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
6427c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
6437c075ce2SRahul Lakkireddy {
6447c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 0);
6457c075ce2SRahul Lakkireddy }
6467c075ce2SRahul Lakkireddy 
6477c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
6487c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
6497c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
6507c075ce2SRahul Lakkireddy {
6517c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 1);
6527c075ce2SRahul Lakkireddy }
6537c075ce2SRahul Lakkireddy 
6547c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
6557c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
6567c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
6577c075ce2SRahul Lakkireddy {
6587c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 2);
6597c075ce2SRahul Lakkireddy }
6607c075ce2SRahul Lakkireddy 
6617c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
6627c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
6637c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
6647c075ce2SRahul Lakkireddy {
6657c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 3);
6667c075ce2SRahul Lakkireddy }
6677c075ce2SRahul Lakkireddy 
6687c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_sge(struct cudbg_init *pdbg_init,
6697c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
6707c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
6717c075ce2SRahul Lakkireddy {
6727c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 4);
6737c075ce2SRahul Lakkireddy }
6747c075ce2SRahul Lakkireddy 
6757c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
6767c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
6777c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
6787c075ce2SRahul Lakkireddy {
6797c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 5);
6807c075ce2SRahul Lakkireddy }
6817c075ce2SRahul Lakkireddy 
6827c075ce2SRahul Lakkireddy int cudbg_collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
6837c075ce2SRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
6847c075ce2SRahul Lakkireddy 				struct cudbg_error *cudbg_err)
6857c075ce2SRahul Lakkireddy {
6867c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 6);
6877c075ce2SRahul Lakkireddy }
6887c075ce2SRahul Lakkireddy 
6897c075ce2SRahul Lakkireddy int cudbg_collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
6907c075ce2SRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
6917c075ce2SRahul Lakkireddy 				struct cudbg_error *cudbg_err)
6927c075ce2SRahul Lakkireddy {
6937c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 7);
6947c075ce2SRahul Lakkireddy }
6957c075ce2SRahul Lakkireddy 
696a1c69520SRahul Lakkireddy static int cudbg_meminfo_get_mem_index(struct adapter *padap,
697a1c69520SRahul Lakkireddy 				       struct cudbg_meminfo *mem_info,
698a1c69520SRahul Lakkireddy 				       u8 mem_type, u8 *idx)
699a1c69520SRahul Lakkireddy {
700a1c69520SRahul Lakkireddy 	u8 i, flag;
701a1c69520SRahul Lakkireddy 
702a1c69520SRahul Lakkireddy 	switch (mem_type) {
703a1c69520SRahul Lakkireddy 	case MEM_EDC0:
704a1c69520SRahul Lakkireddy 		flag = EDC0_FLAG;
705a1c69520SRahul Lakkireddy 		break;
706a1c69520SRahul Lakkireddy 	case MEM_EDC1:
707a1c69520SRahul Lakkireddy 		flag = EDC1_FLAG;
708a1c69520SRahul Lakkireddy 		break;
709a1c69520SRahul Lakkireddy 	case MEM_MC0:
710a1c69520SRahul Lakkireddy 		/* Some T5 cards have both MC0 and MC1. */
711a1c69520SRahul Lakkireddy 		flag = is_t5(padap->params.chip) ? MC0_FLAG : MC_FLAG;
712a1c69520SRahul Lakkireddy 		break;
713a1c69520SRahul Lakkireddy 	case MEM_MC1:
714a1c69520SRahul Lakkireddy 		flag = MC1_FLAG;
715a1c69520SRahul Lakkireddy 		break;
7164db0401fSRahul Lakkireddy 	case MEM_HMA:
7174db0401fSRahul Lakkireddy 		flag = HMA_FLAG;
7184db0401fSRahul Lakkireddy 		break;
719a1c69520SRahul Lakkireddy 	default:
720a1c69520SRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
721a1c69520SRahul Lakkireddy 	}
722a1c69520SRahul Lakkireddy 
723a1c69520SRahul Lakkireddy 	for (i = 0; i < mem_info->avail_c; i++) {
724a1c69520SRahul Lakkireddy 		if (mem_info->avail[i].idx == flag) {
725a1c69520SRahul Lakkireddy 			*idx = i;
726a1c69520SRahul Lakkireddy 			return 0;
727a1c69520SRahul Lakkireddy 		}
728a1c69520SRahul Lakkireddy 	}
729a1c69520SRahul Lakkireddy 
730a1c69520SRahul Lakkireddy 	return CUDBG_STATUS_ENTITY_NOT_FOUND;
731a1c69520SRahul Lakkireddy }
732a1c69520SRahul Lakkireddy 
733a1c69520SRahul Lakkireddy #define CUDBG_YIELD_ITERATION 256
734a1c69520SRahul Lakkireddy 
735b33af022SRahul Lakkireddy static int cudbg_read_fw_mem(struct cudbg_init *pdbg_init,
736b33af022SRahul Lakkireddy 			     struct cudbg_buffer *dbg_buff, u8 mem_type,
737b33af022SRahul Lakkireddy 			     unsigned long tot_len,
738b33af022SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
739b33af022SRahul Lakkireddy {
740b33af022SRahul Lakkireddy 	unsigned long bytes, bytes_left, bytes_read = 0;
741b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
742b33af022SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
743a1c69520SRahul Lakkireddy 	u32 yield_count = 0;
744b33af022SRahul Lakkireddy 	int rc = 0;
745b33af022SRahul Lakkireddy 
746b33af022SRahul Lakkireddy 	bytes_left = tot_len;
747b33af022SRahul Lakkireddy 	while (bytes_left > 0) {
748a1c69520SRahul Lakkireddy 		/* As MC size is huge and read through PIO access, this
749a1c69520SRahul Lakkireddy 		 * loop will hold cpu for a longer time. OS may think that
750a1c69520SRahul Lakkireddy 		 * the process is hanged and will generate CPU stall traces.
751a1c69520SRahul Lakkireddy 		 * So yield the cpu regularly.
752a1c69520SRahul Lakkireddy 		 */
753a1c69520SRahul Lakkireddy 		yield_count++;
754a1c69520SRahul Lakkireddy 		if (!(yield_count % CUDBG_YIELD_ITERATION))
755a1c69520SRahul Lakkireddy 			schedule();
756a1c69520SRahul Lakkireddy 
757b33af022SRahul Lakkireddy 		bytes = min_t(unsigned long, bytes_left,
758b33af022SRahul Lakkireddy 			      (unsigned long)CUDBG_CHUNK_SIZE);
759b33af022SRahul Lakkireddy 		rc = cudbg_get_buff(dbg_buff, bytes, &temp_buff);
760b33af022SRahul Lakkireddy 		if (rc)
761b33af022SRahul Lakkireddy 			return rc;
762b33af022SRahul Lakkireddy 		spin_lock(&padap->win0_lock);
763b33af022SRahul Lakkireddy 		rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type,
764b33af022SRahul Lakkireddy 				  bytes_read, bytes,
765b33af022SRahul Lakkireddy 				  (__be32 *)temp_buff.data,
766b33af022SRahul Lakkireddy 				  1);
767b33af022SRahul Lakkireddy 		spin_unlock(&padap->win0_lock);
768b33af022SRahul Lakkireddy 		if (rc) {
769b33af022SRahul Lakkireddy 			cudbg_err->sys_err = rc;
770b33af022SRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
771b33af022SRahul Lakkireddy 			return rc;
772b33af022SRahul Lakkireddy 		}
773b33af022SRahul Lakkireddy 		bytes_left -= bytes;
774b33af022SRahul Lakkireddy 		bytes_read += bytes;
775b33af022SRahul Lakkireddy 		cudbg_write_and_release_buff(&temp_buff, dbg_buff);
776b33af022SRahul Lakkireddy 	}
777b33af022SRahul Lakkireddy 	return rc;
778b33af022SRahul Lakkireddy }
779b33af022SRahul Lakkireddy 
780b33af022SRahul Lakkireddy static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
781b33af022SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
782b33af022SRahul Lakkireddy {
783b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
784b33af022SRahul Lakkireddy 	int rc;
785b33af022SRahul Lakkireddy 
786b33af022SRahul Lakkireddy 	if (is_fw_attached(pdbg_init)) {
787b33af022SRahul Lakkireddy 		/* Flush uP dcache before reading edcX/mcX  */
788b33af022SRahul Lakkireddy 		rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
789b33af022SRahul Lakkireddy 		if (rc)
790b33af022SRahul Lakkireddy 			cudbg_err->sys_warn = rc;
791b33af022SRahul Lakkireddy 	}
792b33af022SRahul Lakkireddy }
793b33af022SRahul Lakkireddy 
794b33af022SRahul Lakkireddy static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
795b33af022SRahul Lakkireddy 				    struct cudbg_buffer *dbg_buff,
796b33af022SRahul Lakkireddy 				    struct cudbg_error *cudbg_err,
797b33af022SRahul Lakkireddy 				    u8 mem_type)
798b33af022SRahul Lakkireddy {
799a1c69520SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
800a1c69520SRahul Lakkireddy 	struct cudbg_meminfo mem_info;
801a1c69520SRahul Lakkireddy 	unsigned long size;
802a1c69520SRahul Lakkireddy 	u8 mc_idx;
803b33af022SRahul Lakkireddy 	int rc;
804b33af022SRahul Lakkireddy 
805a1c69520SRahul Lakkireddy 	memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
806a1c69520SRahul Lakkireddy 	rc = cudbg_fill_meminfo(padap, &mem_info);
807b33af022SRahul Lakkireddy 	if (rc)
808b33af022SRahul Lakkireddy 		return rc;
809a1c69520SRahul Lakkireddy 
810a1c69520SRahul Lakkireddy 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
811a1c69520SRahul Lakkireddy 	rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
812a1c69520SRahul Lakkireddy 	if (rc)
813a1c69520SRahul Lakkireddy 		return rc;
814a1c69520SRahul Lakkireddy 
815a1c69520SRahul Lakkireddy 	size = mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base;
816a1c69520SRahul Lakkireddy 	return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
817a1c69520SRahul Lakkireddy 				 cudbg_err);
818b33af022SRahul Lakkireddy }
819b33af022SRahul Lakkireddy 
820b33af022SRahul Lakkireddy int cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
821b33af022SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
822b33af022SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
823b33af022SRahul Lakkireddy {
824b33af022SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
825b33af022SRahul Lakkireddy 					MEM_EDC0);
826b33af022SRahul Lakkireddy }
827b33af022SRahul Lakkireddy 
828b33af022SRahul Lakkireddy int cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
829b33af022SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
830b33af022SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
831b33af022SRahul Lakkireddy {
832b33af022SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
833b33af022SRahul Lakkireddy 					MEM_EDC1);
834b33af022SRahul Lakkireddy }
835844d1b6fSRahul Lakkireddy 
836a1c69520SRahul Lakkireddy int cudbg_collect_mc0_meminfo(struct cudbg_init *pdbg_init,
837a1c69520SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
838a1c69520SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
839a1c69520SRahul Lakkireddy {
840a1c69520SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
841a1c69520SRahul Lakkireddy 					MEM_MC0);
842a1c69520SRahul Lakkireddy }
843a1c69520SRahul Lakkireddy 
844a1c69520SRahul Lakkireddy int cudbg_collect_mc1_meminfo(struct cudbg_init *pdbg_init,
845a1c69520SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
846a1c69520SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
847a1c69520SRahul Lakkireddy {
848a1c69520SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
849a1c69520SRahul Lakkireddy 					MEM_MC1);
850a1c69520SRahul Lakkireddy }
851a1c69520SRahul Lakkireddy 
8524db0401fSRahul Lakkireddy int cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,
8534db0401fSRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
8544db0401fSRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
8554db0401fSRahul Lakkireddy {
8564db0401fSRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
8574db0401fSRahul Lakkireddy 					MEM_HMA);
8584db0401fSRahul Lakkireddy }
8594db0401fSRahul Lakkireddy 
86028b44556SRahul Lakkireddy int cudbg_collect_rss(struct cudbg_init *pdbg_init,
86128b44556SRahul Lakkireddy 		      struct cudbg_buffer *dbg_buff,
86228b44556SRahul Lakkireddy 		      struct cudbg_error *cudbg_err)
86328b44556SRahul Lakkireddy {
86428b44556SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
86528b44556SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
86628b44556SRahul Lakkireddy 	int rc;
86728b44556SRahul Lakkireddy 
86828b44556SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, RSS_NENTRIES * sizeof(u16), &temp_buff);
86928b44556SRahul Lakkireddy 	if (rc)
87028b44556SRahul Lakkireddy 		return rc;
87128b44556SRahul Lakkireddy 
87228b44556SRahul Lakkireddy 	rc = t4_read_rss(padap, (u16 *)temp_buff.data);
87328b44556SRahul Lakkireddy 	if (rc) {
87428b44556SRahul Lakkireddy 		cudbg_err->sys_err = rc;
87528b44556SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
87628b44556SRahul Lakkireddy 		return rc;
87728b44556SRahul Lakkireddy 	}
87828b44556SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
87928b44556SRahul Lakkireddy 	return rc;
88028b44556SRahul Lakkireddy }
88128b44556SRahul Lakkireddy 
88228b44556SRahul Lakkireddy int cudbg_collect_rss_vf_config(struct cudbg_init *pdbg_init,
88328b44556SRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
88428b44556SRahul Lakkireddy 				struct cudbg_error *cudbg_err)
88528b44556SRahul Lakkireddy {
88628b44556SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
88728b44556SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
88828b44556SRahul Lakkireddy 	struct cudbg_rss_vf_conf *vfconf;
88928b44556SRahul Lakkireddy 	int vf, rc, vf_count;
89028b44556SRahul Lakkireddy 
89128b44556SRahul Lakkireddy 	vf_count = padap->params.arch.vfcount;
89228b44556SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff,
89328b44556SRahul Lakkireddy 			    vf_count * sizeof(struct cudbg_rss_vf_conf),
89428b44556SRahul Lakkireddy 			    &temp_buff);
89528b44556SRahul Lakkireddy 	if (rc)
89628b44556SRahul Lakkireddy 		return rc;
89728b44556SRahul Lakkireddy 
89828b44556SRahul Lakkireddy 	vfconf = (struct cudbg_rss_vf_conf *)temp_buff.data;
89928b44556SRahul Lakkireddy 	for (vf = 0; vf < vf_count; vf++)
90028b44556SRahul Lakkireddy 		t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
90128b44556SRahul Lakkireddy 				      &vfconf[vf].rss_vf_vfh, true);
90228b44556SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
90328b44556SRahul Lakkireddy 	return rc;
90428b44556SRahul Lakkireddy }
90528b44556SRahul Lakkireddy 
9066f92a654SRahul Lakkireddy int cudbg_collect_path_mtu(struct cudbg_init *pdbg_init,
9076f92a654SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
9086f92a654SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
9096f92a654SRahul Lakkireddy {
9106f92a654SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
9116f92a654SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
9126f92a654SRahul Lakkireddy 	int rc;
9136f92a654SRahul Lakkireddy 
9146f92a654SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, NMTUS * sizeof(u16), &temp_buff);
9156f92a654SRahul Lakkireddy 	if (rc)
9166f92a654SRahul Lakkireddy 		return rc;
9176f92a654SRahul Lakkireddy 
9186f92a654SRahul Lakkireddy 	t4_read_mtu_tbl(padap, (u16 *)temp_buff.data, NULL);
9196f92a654SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
9206f92a654SRahul Lakkireddy 	return rc;
9216f92a654SRahul Lakkireddy }
9226f92a654SRahul Lakkireddy 
9236f92a654SRahul Lakkireddy int cudbg_collect_pm_stats(struct cudbg_init *pdbg_init,
9246f92a654SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
9256f92a654SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
9266f92a654SRahul Lakkireddy {
9276f92a654SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
9286f92a654SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
9296f92a654SRahul Lakkireddy 	struct cudbg_pm_stats *pm_stats_buff;
9306f92a654SRahul Lakkireddy 	int rc;
9316f92a654SRahul Lakkireddy 
9326f92a654SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_pm_stats),
9336f92a654SRahul Lakkireddy 			    &temp_buff);
9346f92a654SRahul Lakkireddy 	if (rc)
9356f92a654SRahul Lakkireddy 		return rc;
9366f92a654SRahul Lakkireddy 
9376f92a654SRahul Lakkireddy 	pm_stats_buff = (struct cudbg_pm_stats *)temp_buff.data;
9386f92a654SRahul Lakkireddy 	t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
9396f92a654SRahul Lakkireddy 	t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
9406f92a654SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
9416f92a654SRahul Lakkireddy 	return rc;
9426f92a654SRahul Lakkireddy }
9436f92a654SRahul Lakkireddy 
94408c4901bSRahul Lakkireddy int cudbg_collect_hw_sched(struct cudbg_init *pdbg_init,
94508c4901bSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
94608c4901bSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
94708c4901bSRahul Lakkireddy {
94808c4901bSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
94908c4901bSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
95008c4901bSRahul Lakkireddy 	struct cudbg_hw_sched *hw_sched_buff;
95108c4901bSRahul Lakkireddy 	int i, rc = 0;
95208c4901bSRahul Lakkireddy 
95308c4901bSRahul Lakkireddy 	if (!padap->params.vpd.cclk)
95408c4901bSRahul Lakkireddy 		return CUDBG_STATUS_CCLK_NOT_DEFINED;
95508c4901bSRahul Lakkireddy 
95608c4901bSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_hw_sched),
95708c4901bSRahul Lakkireddy 			    &temp_buff);
95808c4901bSRahul Lakkireddy 	hw_sched_buff = (struct cudbg_hw_sched *)temp_buff.data;
95908c4901bSRahul Lakkireddy 	hw_sched_buff->map = t4_read_reg(padap, TP_TX_MOD_QUEUE_REQ_MAP_A);
96008c4901bSRahul Lakkireddy 	hw_sched_buff->mode = TIMERMODE_G(t4_read_reg(padap, TP_MOD_CONFIG_A));
96108c4901bSRahul Lakkireddy 	t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
96208c4901bSRahul Lakkireddy 	for (i = 0; i < NTX_SCHED; ++i)
96308c4901bSRahul Lakkireddy 		t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
96408c4901bSRahul Lakkireddy 				&hw_sched_buff->ipg[i], true);
96508c4901bSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
96608c4901bSRahul Lakkireddy 	return rc;
96708c4901bSRahul Lakkireddy }
96808c4901bSRahul Lakkireddy 
9694359cf33SRahul Lakkireddy int cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
9704359cf33SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
9714359cf33SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
9724359cf33SRahul Lakkireddy {
9734359cf33SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
9744359cf33SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
9754359cf33SRahul Lakkireddy 	struct ireg_buf *ch_tp_pio;
9764359cf33SRahul Lakkireddy 	int i, rc, n = 0;
9774359cf33SRahul Lakkireddy 	u32 size;
9784359cf33SRahul Lakkireddy 
9794359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
9804359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_pio_array) +
9814359cf33SRahul Lakkireddy 		    sizeof(t5_tp_tm_pio_array) +
9824359cf33SRahul Lakkireddy 		    sizeof(t5_tp_mib_index_array);
9834359cf33SRahul Lakkireddy 	else
9844359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_pio_array) +
9854359cf33SRahul Lakkireddy 		    sizeof(t6_tp_tm_pio_array) +
9864359cf33SRahul Lakkireddy 		    sizeof(t6_tp_mib_index_array);
9874359cf33SRahul Lakkireddy 
9884359cf33SRahul Lakkireddy 	n = n / (IREG_NUM_ELEM * sizeof(u32));
9894359cf33SRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
9904359cf33SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
9914359cf33SRahul Lakkireddy 	if (rc)
9924359cf33SRahul Lakkireddy 		return rc;
9934359cf33SRahul Lakkireddy 
9944359cf33SRahul Lakkireddy 	ch_tp_pio = (struct ireg_buf *)temp_buff.data;
9954359cf33SRahul Lakkireddy 
9964359cf33SRahul Lakkireddy 	/* TP_PIO */
9974359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
9984359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
9994359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
10004359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
10014359cf33SRahul Lakkireddy 
10024359cf33SRahul Lakkireddy 	for (i = 0; i < n; i++) {
10034359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
10044359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
10054359cf33SRahul Lakkireddy 
10064359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
10074359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_pio_array[i][0];
10084359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_pio_array[i][1];
10094359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
10104359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
10114359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
10124359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_pio_array[i][0];
10134359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_pio_array[i][1];
10144359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
10154359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
10164359cf33SRahul Lakkireddy 		}
10174359cf33SRahul Lakkireddy 		t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
10184359cf33SRahul Lakkireddy 			       tp_pio->ireg_local_offset, true);
10194359cf33SRahul Lakkireddy 		ch_tp_pio++;
10204359cf33SRahul Lakkireddy 	}
10214359cf33SRahul Lakkireddy 
10224359cf33SRahul Lakkireddy 	/* TP_TM_PIO */
10234359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
10244359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
10254359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
10264359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
10274359cf33SRahul Lakkireddy 
10284359cf33SRahul Lakkireddy 	for (i = 0; i < n; i++) {
10294359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
10304359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
10314359cf33SRahul Lakkireddy 
10324359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
10334359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
10344359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
10354359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
10364359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
10374359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
10384359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
10394359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
10404359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
10414359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
10424359cf33SRahul Lakkireddy 		}
10434359cf33SRahul Lakkireddy 		t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
10444359cf33SRahul Lakkireddy 				  tp_pio->ireg_local_offset, true);
10454359cf33SRahul Lakkireddy 		ch_tp_pio++;
10464359cf33SRahul Lakkireddy 	}
10474359cf33SRahul Lakkireddy 
10484359cf33SRahul Lakkireddy 	/* TP_MIB_INDEX */
10494359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
10504359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_mib_index_array) /
10514359cf33SRahul Lakkireddy 		    (IREG_NUM_ELEM * sizeof(u32));
10524359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
10534359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_mib_index_array) /
10544359cf33SRahul Lakkireddy 		    (IREG_NUM_ELEM * sizeof(u32));
10554359cf33SRahul Lakkireddy 
10564359cf33SRahul Lakkireddy 	for (i = 0; i < n ; i++) {
10574359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
10584359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
10594359cf33SRahul Lakkireddy 
10604359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
10614359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
10624359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
10634359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset =
10644359cf33SRahul Lakkireddy 				t5_tp_mib_index_array[i][2];
10654359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range =
10664359cf33SRahul Lakkireddy 				t5_tp_mib_index_array[i][3];
10674359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
10684359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
10694359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
10704359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset =
10714359cf33SRahul Lakkireddy 				t6_tp_mib_index_array[i][2];
10724359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range =
10734359cf33SRahul Lakkireddy 				t6_tp_mib_index_array[i][3];
10744359cf33SRahul Lakkireddy 		}
10754359cf33SRahul Lakkireddy 		t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
10764359cf33SRahul Lakkireddy 			       tp_pio->ireg_local_offset, true);
10774359cf33SRahul Lakkireddy 		ch_tp_pio++;
10784359cf33SRahul Lakkireddy 	}
10794359cf33SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
10804359cf33SRahul Lakkireddy 	return rc;
10814359cf33SRahul Lakkireddy }
10824359cf33SRahul Lakkireddy 
1083270d39bfSRahul Lakkireddy int cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
1084270d39bfSRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
1085270d39bfSRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
1086270d39bfSRahul Lakkireddy {
1087270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1088270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1089270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_sge_dbg;
1090270d39bfSRahul Lakkireddy 	int i, rc;
1091270d39bfSRahul Lakkireddy 
1092270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(*ch_sge_dbg) * 2, &temp_buff);
1093270d39bfSRahul Lakkireddy 	if (rc)
1094270d39bfSRahul Lakkireddy 		return rc;
1095270d39bfSRahul Lakkireddy 
1096270d39bfSRahul Lakkireddy 	ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
1097270d39bfSRahul Lakkireddy 	for (i = 0; i < 2; i++) {
1098270d39bfSRahul Lakkireddy 		struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
1099270d39bfSRahul Lakkireddy 		u32 *buff = ch_sge_dbg->outbuf;
1100270d39bfSRahul Lakkireddy 
1101270d39bfSRahul Lakkireddy 		sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
1102270d39bfSRahul Lakkireddy 		sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
1103270d39bfSRahul Lakkireddy 		sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
1104270d39bfSRahul Lakkireddy 		sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
1105270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
1106270d39bfSRahul Lakkireddy 				 sge_pio->ireg_addr,
1107270d39bfSRahul Lakkireddy 				 sge_pio->ireg_data,
1108270d39bfSRahul Lakkireddy 				 buff,
1109270d39bfSRahul Lakkireddy 				 sge_pio->ireg_offset_range,
1110270d39bfSRahul Lakkireddy 				 sge_pio->ireg_local_offset);
1111270d39bfSRahul Lakkireddy 		ch_sge_dbg++;
1112270d39bfSRahul Lakkireddy 	}
1113270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1114270d39bfSRahul Lakkireddy 	return rc;
1115270d39bfSRahul Lakkireddy }
1116270d39bfSRahul Lakkireddy 
111727887bc7SRahul Lakkireddy int cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
111827887bc7SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
111927887bc7SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
112027887bc7SRahul Lakkireddy {
112127887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
112227887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
112327887bc7SRahul Lakkireddy 	struct cudbg_ulprx_la *ulprx_la_buff;
112427887bc7SRahul Lakkireddy 	int rc;
112527887bc7SRahul Lakkireddy 
112627887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_ulprx_la),
112727887bc7SRahul Lakkireddy 			    &temp_buff);
112827887bc7SRahul Lakkireddy 	if (rc)
112927887bc7SRahul Lakkireddy 		return rc;
113027887bc7SRahul Lakkireddy 
113127887bc7SRahul Lakkireddy 	ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
113227887bc7SRahul Lakkireddy 	t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
113327887bc7SRahul Lakkireddy 	ulprx_la_buff->size = ULPRX_LA_SIZE;
113427887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
113527887bc7SRahul Lakkireddy 	return rc;
113627887bc7SRahul Lakkireddy }
113727887bc7SRahul Lakkireddy 
113827887bc7SRahul Lakkireddy int cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
113927887bc7SRahul Lakkireddy 			struct cudbg_buffer *dbg_buff,
114027887bc7SRahul Lakkireddy 			struct cudbg_error *cudbg_err)
114127887bc7SRahul Lakkireddy {
114227887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
114327887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
114427887bc7SRahul Lakkireddy 	struct cudbg_tp_la *tp_la_buff;
114527887bc7SRahul Lakkireddy 	int size, rc;
114627887bc7SRahul Lakkireddy 
114727887bc7SRahul Lakkireddy 	size = sizeof(struct cudbg_tp_la) + TPLA_SIZE *  sizeof(u64);
114827887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
114927887bc7SRahul Lakkireddy 	if (rc)
115027887bc7SRahul Lakkireddy 		return rc;
115127887bc7SRahul Lakkireddy 
115227887bc7SRahul Lakkireddy 	tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
115327887bc7SRahul Lakkireddy 	tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
115427887bc7SRahul Lakkireddy 	t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
115527887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
115627887bc7SRahul Lakkireddy 	return rc;
115727887bc7SRahul Lakkireddy }
115827887bc7SRahul Lakkireddy 
1159123e25c4SRahul Lakkireddy int cudbg_collect_meminfo(struct cudbg_init *pdbg_init,
1160123e25c4SRahul Lakkireddy 			  struct cudbg_buffer *dbg_buff,
1161123e25c4SRahul Lakkireddy 			  struct cudbg_error *cudbg_err)
1162123e25c4SRahul Lakkireddy {
1163123e25c4SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1164123e25c4SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1165123e25c4SRahul Lakkireddy 	struct cudbg_meminfo *meminfo_buff;
1166123e25c4SRahul Lakkireddy 	int rc;
1167123e25c4SRahul Lakkireddy 
1168123e25c4SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_meminfo), &temp_buff);
1169123e25c4SRahul Lakkireddy 	if (rc)
1170123e25c4SRahul Lakkireddy 		return rc;
1171123e25c4SRahul Lakkireddy 
1172123e25c4SRahul Lakkireddy 	meminfo_buff = (struct cudbg_meminfo *)temp_buff.data;
1173123e25c4SRahul Lakkireddy 	rc = cudbg_fill_meminfo(padap, meminfo_buff);
1174123e25c4SRahul Lakkireddy 	if (rc) {
1175123e25c4SRahul Lakkireddy 		cudbg_err->sys_err = rc;
1176123e25c4SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
1177123e25c4SRahul Lakkireddy 		return rc;
1178123e25c4SRahul Lakkireddy 	}
1179123e25c4SRahul Lakkireddy 
1180123e25c4SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1181123e25c4SRahul Lakkireddy 	return rc;
1182123e25c4SRahul Lakkireddy }
1183123e25c4SRahul Lakkireddy 
118427887bc7SRahul Lakkireddy int cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
118527887bc7SRahul Lakkireddy 			     struct cudbg_buffer *dbg_buff,
118627887bc7SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
118727887bc7SRahul Lakkireddy {
118827887bc7SRahul Lakkireddy 	struct cudbg_cim_pif_la *cim_pif_la_buff;
118927887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
119027887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
119127887bc7SRahul Lakkireddy 	int size, rc;
119227887bc7SRahul Lakkireddy 
119327887bc7SRahul Lakkireddy 	size = sizeof(struct cudbg_cim_pif_la) +
119427887bc7SRahul Lakkireddy 	       2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
119527887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
119627887bc7SRahul Lakkireddy 	if (rc)
119727887bc7SRahul Lakkireddy 		return rc;
119827887bc7SRahul Lakkireddy 
119927887bc7SRahul Lakkireddy 	cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
120027887bc7SRahul Lakkireddy 	cim_pif_la_buff->size = CIM_PIFLA_SIZE;
120127887bc7SRahul Lakkireddy 	t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
120227887bc7SRahul Lakkireddy 			   (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
120327887bc7SRahul Lakkireddy 			   NULL, NULL);
120427887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
120527887bc7SRahul Lakkireddy 	return rc;
120627887bc7SRahul Lakkireddy }
120727887bc7SRahul Lakkireddy 
12086f92a654SRahul Lakkireddy int cudbg_collect_clk_info(struct cudbg_init *pdbg_init,
12096f92a654SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
12106f92a654SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
12116f92a654SRahul Lakkireddy {
12126f92a654SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
12136f92a654SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
12146f92a654SRahul Lakkireddy 	struct cudbg_clk_info *clk_info_buff;
12156f92a654SRahul Lakkireddy 	u64 tp_tick_us;
12166f92a654SRahul Lakkireddy 	int rc;
12176f92a654SRahul Lakkireddy 
12186f92a654SRahul Lakkireddy 	if (!padap->params.vpd.cclk)
12196f92a654SRahul Lakkireddy 		return CUDBG_STATUS_CCLK_NOT_DEFINED;
12206f92a654SRahul Lakkireddy 
12216f92a654SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_clk_info),
12226f92a654SRahul Lakkireddy 			    &temp_buff);
12236f92a654SRahul Lakkireddy 	if (rc)
12246f92a654SRahul Lakkireddy 		return rc;
12256f92a654SRahul Lakkireddy 
12266f92a654SRahul Lakkireddy 	clk_info_buff = (struct cudbg_clk_info *)temp_buff.data;
12276f92a654SRahul Lakkireddy 	clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk; /* psec */
12286f92a654SRahul Lakkireddy 	clk_info_buff->res = t4_read_reg(padap, TP_TIMER_RESOLUTION_A);
12296f92a654SRahul Lakkireddy 	clk_info_buff->tre = TIMERRESOLUTION_G(clk_info_buff->res);
12306f92a654SRahul Lakkireddy 	clk_info_buff->dack_re = DELAYEDACKRESOLUTION_G(clk_info_buff->res);
12316f92a654SRahul Lakkireddy 	tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
12326f92a654SRahul Lakkireddy 
12336f92a654SRahul Lakkireddy 	clk_info_buff->dack_timer =
12346f92a654SRahul Lakkireddy 		(clk_info_buff->cclk_ps << clk_info_buff->dack_re) / 1000000 *
12356f92a654SRahul Lakkireddy 		t4_read_reg(padap, TP_DACK_TIMER_A);
12366f92a654SRahul Lakkireddy 	clk_info_buff->retransmit_min =
12376f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_RXT_MIN_A);
12386f92a654SRahul Lakkireddy 	clk_info_buff->retransmit_max =
12396f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_RXT_MAX_A);
12406f92a654SRahul Lakkireddy 	clk_info_buff->persist_timer_min =
12416f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_PERS_MIN_A);
12426f92a654SRahul Lakkireddy 	clk_info_buff->persist_timer_max =
12436f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_PERS_MAX_A);
12446f92a654SRahul Lakkireddy 	clk_info_buff->keepalive_idle_timer =
12456f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_KEEP_IDLE_A);
12466f92a654SRahul Lakkireddy 	clk_info_buff->keepalive_interval =
12476f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_KEEP_INTVL_A);
12486f92a654SRahul Lakkireddy 	clk_info_buff->initial_srtt =
12496f92a654SRahul Lakkireddy 		tp_tick_us * INITSRTT_G(t4_read_reg(padap, TP_INIT_SRTT_A));
12506f92a654SRahul Lakkireddy 	clk_info_buff->finwait2_timer =
12516f92a654SRahul Lakkireddy 		tp_tick_us * t4_read_reg(padap, TP_FINWAIT2_TIMER_A);
12526f92a654SRahul Lakkireddy 
12536f92a654SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
12546f92a654SRahul Lakkireddy 	return rc;
12556f92a654SRahul Lakkireddy }
12566f92a654SRahul Lakkireddy 
1257270d39bfSRahul Lakkireddy int cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
1258270d39bfSRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
1259270d39bfSRahul Lakkireddy 				struct cudbg_error *cudbg_err)
1260270d39bfSRahul Lakkireddy {
1261270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1262270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1263270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_pcie;
1264270d39bfSRahul Lakkireddy 	int i, rc, n;
1265270d39bfSRahul Lakkireddy 	u32 size;
1266270d39bfSRahul Lakkireddy 
1267270d39bfSRahul Lakkireddy 	n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
1268270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
1269270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
1270270d39bfSRahul Lakkireddy 	if (rc)
1271270d39bfSRahul Lakkireddy 		return rc;
1272270d39bfSRahul Lakkireddy 
1273270d39bfSRahul Lakkireddy 	ch_pcie = (struct ireg_buf *)temp_buff.data;
1274270d39bfSRahul Lakkireddy 	/* PCIE_PDBG */
1275270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1276270d39bfSRahul Lakkireddy 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
1277270d39bfSRahul Lakkireddy 		u32 *buff = ch_pcie->outbuf;
1278270d39bfSRahul Lakkireddy 
1279270d39bfSRahul Lakkireddy 		pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
1280270d39bfSRahul Lakkireddy 		pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
1281270d39bfSRahul Lakkireddy 		pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
1282270d39bfSRahul Lakkireddy 		pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
1283270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
1284270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_addr,
1285270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_data,
1286270d39bfSRahul Lakkireddy 				 buff,
1287270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_offset_range,
1288270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_local_offset);
1289270d39bfSRahul Lakkireddy 		ch_pcie++;
1290270d39bfSRahul Lakkireddy 	}
1291270d39bfSRahul Lakkireddy 
1292270d39bfSRahul Lakkireddy 	/* PCIE_CDBG */
1293270d39bfSRahul Lakkireddy 	n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
1294270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1295270d39bfSRahul Lakkireddy 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
1296270d39bfSRahul Lakkireddy 		u32 *buff = ch_pcie->outbuf;
1297270d39bfSRahul Lakkireddy 
1298270d39bfSRahul Lakkireddy 		pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
1299270d39bfSRahul Lakkireddy 		pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
1300270d39bfSRahul Lakkireddy 		pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
1301270d39bfSRahul Lakkireddy 		pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
1302270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
1303270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_addr,
1304270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_data,
1305270d39bfSRahul Lakkireddy 				 buff,
1306270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_offset_range,
1307270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_local_offset);
1308270d39bfSRahul Lakkireddy 		ch_pcie++;
1309270d39bfSRahul Lakkireddy 	}
1310270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1311270d39bfSRahul Lakkireddy 	return rc;
1312270d39bfSRahul Lakkireddy }
1313270d39bfSRahul Lakkireddy 
1314270d39bfSRahul Lakkireddy int cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
1315270d39bfSRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
1316270d39bfSRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
1317270d39bfSRahul Lakkireddy {
1318270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1319270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1320270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_pm;
1321270d39bfSRahul Lakkireddy 	int i, rc, n;
1322270d39bfSRahul Lakkireddy 	u32 size;
1323270d39bfSRahul Lakkireddy 
1324270d39bfSRahul Lakkireddy 	n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
1325270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
1326270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
1327270d39bfSRahul Lakkireddy 	if (rc)
1328270d39bfSRahul Lakkireddy 		return rc;
1329270d39bfSRahul Lakkireddy 
1330270d39bfSRahul Lakkireddy 	ch_pm = (struct ireg_buf *)temp_buff.data;
1331270d39bfSRahul Lakkireddy 	/* PM_RX */
1332270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1333270d39bfSRahul Lakkireddy 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
1334270d39bfSRahul Lakkireddy 		u32 *buff = ch_pm->outbuf;
1335270d39bfSRahul Lakkireddy 
1336270d39bfSRahul Lakkireddy 		pm_pio->ireg_addr = t5_pm_rx_array[i][0];
1337270d39bfSRahul Lakkireddy 		pm_pio->ireg_data = t5_pm_rx_array[i][1];
1338270d39bfSRahul Lakkireddy 		pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
1339270d39bfSRahul Lakkireddy 		pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
1340270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
1341270d39bfSRahul Lakkireddy 				 pm_pio->ireg_addr,
1342270d39bfSRahul Lakkireddy 				 pm_pio->ireg_data,
1343270d39bfSRahul Lakkireddy 				 buff,
1344270d39bfSRahul Lakkireddy 				 pm_pio->ireg_offset_range,
1345270d39bfSRahul Lakkireddy 				 pm_pio->ireg_local_offset);
1346270d39bfSRahul Lakkireddy 		ch_pm++;
1347270d39bfSRahul Lakkireddy 	}
1348270d39bfSRahul Lakkireddy 
1349270d39bfSRahul Lakkireddy 	/* PM_TX */
1350270d39bfSRahul Lakkireddy 	n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
1351270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1352270d39bfSRahul Lakkireddy 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
1353270d39bfSRahul Lakkireddy 		u32 *buff = ch_pm->outbuf;
1354270d39bfSRahul Lakkireddy 
1355270d39bfSRahul Lakkireddy 		pm_pio->ireg_addr = t5_pm_tx_array[i][0];
1356270d39bfSRahul Lakkireddy 		pm_pio->ireg_data = t5_pm_tx_array[i][1];
1357270d39bfSRahul Lakkireddy 		pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
1358270d39bfSRahul Lakkireddy 		pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
1359270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
1360270d39bfSRahul Lakkireddy 				 pm_pio->ireg_addr,
1361270d39bfSRahul Lakkireddy 				 pm_pio->ireg_data,
1362270d39bfSRahul Lakkireddy 				 buff,
1363270d39bfSRahul Lakkireddy 				 pm_pio->ireg_offset_range,
1364270d39bfSRahul Lakkireddy 				 pm_pio->ireg_local_offset);
1365270d39bfSRahul Lakkireddy 		ch_pm++;
1366270d39bfSRahul Lakkireddy 	}
1367270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1368270d39bfSRahul Lakkireddy 	return rc;
1369270d39bfSRahul Lakkireddy }
1370270d39bfSRahul Lakkireddy 
13719030e498SRahul Lakkireddy int cudbg_collect_tid(struct cudbg_init *pdbg_init,
13729030e498SRahul Lakkireddy 		      struct cudbg_buffer *dbg_buff,
13739030e498SRahul Lakkireddy 		      struct cudbg_error *cudbg_err)
13749030e498SRahul Lakkireddy {
13759030e498SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
13769030e498SRahul Lakkireddy 	struct cudbg_tid_info_region_rev1 *tid1;
13779030e498SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
13789030e498SRahul Lakkireddy 	struct cudbg_tid_info_region *tid;
13799030e498SRahul Lakkireddy 	u32 para[2], val[2];
13809030e498SRahul Lakkireddy 	int rc;
13819030e498SRahul Lakkireddy 
13829030e498SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_tid_info_region_rev1),
13839030e498SRahul Lakkireddy 			    &temp_buff);
13849030e498SRahul Lakkireddy 	if (rc)
13859030e498SRahul Lakkireddy 		return rc;
13869030e498SRahul Lakkireddy 
13879030e498SRahul Lakkireddy 	tid1 = (struct cudbg_tid_info_region_rev1 *)temp_buff.data;
13889030e498SRahul Lakkireddy 	tid = &tid1->tid;
13899030e498SRahul Lakkireddy 	tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
13909030e498SRahul Lakkireddy 	tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
13919030e498SRahul Lakkireddy 	tid1->ver_hdr.size = sizeof(struct cudbg_tid_info_region_rev1) -
13929030e498SRahul Lakkireddy 			     sizeof(struct cudbg_ver_hdr);
13939030e498SRahul Lakkireddy 
13949030e498SRahul Lakkireddy #define FW_PARAM_PFVF_A(param) \
13959030e498SRahul Lakkireddy 	(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
13969030e498SRahul Lakkireddy 	 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param) | \
13979030e498SRahul Lakkireddy 	 FW_PARAMS_PARAM_Y_V(0) | \
13989030e498SRahul Lakkireddy 	 FW_PARAMS_PARAM_Z_V(0))
13999030e498SRahul Lakkireddy 
14009030e498SRahul Lakkireddy 	para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
14019030e498SRahul Lakkireddy 	para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
14029030e498SRahul Lakkireddy 	rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2, para, val);
14039030e498SRahul Lakkireddy 	if (rc <  0) {
14049030e498SRahul Lakkireddy 		cudbg_err->sys_err = rc;
14059030e498SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
14069030e498SRahul Lakkireddy 		return rc;
14079030e498SRahul Lakkireddy 	}
14089030e498SRahul Lakkireddy 	tid->uotid_base = val[0];
14099030e498SRahul Lakkireddy 	tid->nuotids = val[1] - val[0] + 1;
14109030e498SRahul Lakkireddy 
14119030e498SRahul Lakkireddy 	if (is_t5(padap->params.chip)) {
14129030e498SRahul Lakkireddy 		tid->sb = t4_read_reg(padap, LE_DB_SERVER_INDEX_A) / 4;
14139030e498SRahul Lakkireddy 	} else if (is_t6(padap->params.chip)) {
14149030e498SRahul Lakkireddy 		tid1->tid_start =
14159030e498SRahul Lakkireddy 			t4_read_reg(padap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
14169030e498SRahul Lakkireddy 		tid->sb = t4_read_reg(padap, LE_DB_SRVR_START_INDEX_A);
14179030e498SRahul Lakkireddy 
14189030e498SRahul Lakkireddy 		para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
14199030e498SRahul Lakkireddy 		para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
14209030e498SRahul Lakkireddy 		rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2,
14219030e498SRahul Lakkireddy 				     para, val);
14229030e498SRahul Lakkireddy 		if (rc < 0) {
14239030e498SRahul Lakkireddy 			cudbg_err->sys_err = rc;
14249030e498SRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
14259030e498SRahul Lakkireddy 			return rc;
14269030e498SRahul Lakkireddy 		}
14279030e498SRahul Lakkireddy 		tid->hpftid_base = val[0];
14289030e498SRahul Lakkireddy 		tid->nhpftids = val[1] - val[0] + 1;
14299030e498SRahul Lakkireddy 	}
14309030e498SRahul Lakkireddy 
14319030e498SRahul Lakkireddy 	tid->ntids = padap->tids.ntids;
14329030e498SRahul Lakkireddy 	tid->nstids = padap->tids.nstids;
14339030e498SRahul Lakkireddy 	tid->stid_base = padap->tids.stid_base;
14349030e498SRahul Lakkireddy 	tid->hash_base = padap->tids.hash_base;
14359030e498SRahul Lakkireddy 
14369030e498SRahul Lakkireddy 	tid->natids = padap->tids.natids;
14379030e498SRahul Lakkireddy 	tid->nftids = padap->tids.nftids;
14389030e498SRahul Lakkireddy 	tid->ftid_base = padap->tids.ftid_base;
14399030e498SRahul Lakkireddy 	tid->aftid_base = padap->tids.aftid_base;
14409030e498SRahul Lakkireddy 	tid->aftid_end = padap->tids.aftid_end;
14419030e498SRahul Lakkireddy 
14429030e498SRahul Lakkireddy 	tid->sftid_base = padap->tids.sftid_base;
14439030e498SRahul Lakkireddy 	tid->nsftids = padap->tids.nsftids;
14449030e498SRahul Lakkireddy 
14459030e498SRahul Lakkireddy 	tid->flags = padap->flags;
14469030e498SRahul Lakkireddy 	tid->le_db_conf = t4_read_reg(padap, LE_DB_CONFIG_A);
14479030e498SRahul Lakkireddy 	tid->ip_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV4_A);
14489030e498SRahul Lakkireddy 	tid->ipv6_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV6_A);
14499030e498SRahul Lakkireddy 
14509030e498SRahul Lakkireddy #undef FW_PARAM_PFVF_A
14519030e498SRahul Lakkireddy 
14529030e498SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
14539030e498SRahul Lakkireddy 	return rc;
14549030e498SRahul Lakkireddy }
14559030e498SRahul Lakkireddy 
14569e5c598cSRahul Lakkireddy int cudbg_dump_context_size(struct adapter *padap)
14579e5c598cSRahul Lakkireddy {
14589e5c598cSRahul Lakkireddy 	u32 value, size;
14599e5c598cSRahul Lakkireddy 	u8 flq;
14609e5c598cSRahul Lakkireddy 
14619e5c598cSRahul Lakkireddy 	value = t4_read_reg(padap, SGE_FLM_CFG_A);
14629e5c598cSRahul Lakkireddy 
14639e5c598cSRahul Lakkireddy 	/* Get number of data freelist queues */
14649e5c598cSRahul Lakkireddy 	flq = HDRSTARTFLQ_G(value);
14659e5c598cSRahul Lakkireddy 	size = CUDBG_MAX_FL_QIDS >> flq;
14669e5c598cSRahul Lakkireddy 
14679e5c598cSRahul Lakkireddy 	/* Add extra space for congestion manager contexts.
14689e5c598cSRahul Lakkireddy 	 * The number of CONM contexts are same as number of freelist
14699e5c598cSRahul Lakkireddy 	 * queues.
14709e5c598cSRahul Lakkireddy 	 */
14719e5c598cSRahul Lakkireddy 	size += size;
14729e5c598cSRahul Lakkireddy 	return size * sizeof(struct cudbg_ch_cntxt);
14739e5c598cSRahul Lakkireddy }
14749e5c598cSRahul Lakkireddy 
14759e5c598cSRahul Lakkireddy static void cudbg_read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
14769e5c598cSRahul Lakkireddy 				enum ctxt_type ctype, u32 *data)
14779e5c598cSRahul Lakkireddy {
14789e5c598cSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
14799e5c598cSRahul Lakkireddy 	int rc = -1;
14809e5c598cSRahul Lakkireddy 
14819e5c598cSRahul Lakkireddy 	/* Under heavy traffic, the SGE Queue contexts registers will be
14829e5c598cSRahul Lakkireddy 	 * frequently accessed by firmware.
14839e5c598cSRahul Lakkireddy 	 *
14849e5c598cSRahul Lakkireddy 	 * To avoid conflicts with firmware, always ask firmware to fetch
14859e5c598cSRahul Lakkireddy 	 * the SGE Queue contexts via mailbox. On failure, fallback to
14869e5c598cSRahul Lakkireddy 	 * accessing hardware registers directly.
14879e5c598cSRahul Lakkireddy 	 */
14889e5c598cSRahul Lakkireddy 	if (is_fw_attached(pdbg_init))
14899e5c598cSRahul Lakkireddy 		rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype, data);
14909e5c598cSRahul Lakkireddy 	if (rc)
14919e5c598cSRahul Lakkireddy 		t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
14929e5c598cSRahul Lakkireddy }
14939e5c598cSRahul Lakkireddy 
14949e5c598cSRahul Lakkireddy int cudbg_collect_dump_context(struct cudbg_init *pdbg_init,
14959e5c598cSRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
14969e5c598cSRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
14979e5c598cSRahul Lakkireddy {
14989e5c598cSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
14999e5c598cSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
15009e5c598cSRahul Lakkireddy 	struct cudbg_ch_cntxt *buff;
15019e5c598cSRahul Lakkireddy 	u32 size, i = 0;
15029e5c598cSRahul Lakkireddy 	int rc;
15039e5c598cSRahul Lakkireddy 
15049e5c598cSRahul Lakkireddy 	rc = cudbg_dump_context_size(padap);
15059e5c598cSRahul Lakkireddy 	if (rc <= 0)
15069e5c598cSRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
15079e5c598cSRahul Lakkireddy 
15089e5c598cSRahul Lakkireddy 	size = rc;
15099e5c598cSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
15109e5c598cSRahul Lakkireddy 	if (rc)
15119e5c598cSRahul Lakkireddy 		return rc;
15129e5c598cSRahul Lakkireddy 
15139e5c598cSRahul Lakkireddy 	buff = (struct cudbg_ch_cntxt *)temp_buff.data;
15149e5c598cSRahul Lakkireddy 	while (size > 0) {
15159e5c598cSRahul Lakkireddy 		buff->cntxt_type = CTXT_FLM;
15169e5c598cSRahul Lakkireddy 		buff->cntxt_id = i;
15179e5c598cSRahul Lakkireddy 		cudbg_read_sge_ctxt(pdbg_init, i, CTXT_FLM, buff->data);
15189e5c598cSRahul Lakkireddy 		buff++;
15199e5c598cSRahul Lakkireddy 		size -= sizeof(struct cudbg_ch_cntxt);
15209e5c598cSRahul Lakkireddy 
15219e5c598cSRahul Lakkireddy 		buff->cntxt_type = CTXT_CNM;
15229e5c598cSRahul Lakkireddy 		buff->cntxt_id = i;
15239e5c598cSRahul Lakkireddy 		cudbg_read_sge_ctxt(pdbg_init, i, CTXT_CNM, buff->data);
15249e5c598cSRahul Lakkireddy 		buff++;
15259e5c598cSRahul Lakkireddy 		size -= sizeof(struct cudbg_ch_cntxt);
15269e5c598cSRahul Lakkireddy 
15279e5c598cSRahul Lakkireddy 		i++;
15289e5c598cSRahul Lakkireddy 	}
15299e5c598cSRahul Lakkireddy 
15309e5c598cSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
15319e5c598cSRahul Lakkireddy 	return rc;
15329e5c598cSRahul Lakkireddy }
15339e5c598cSRahul Lakkireddy 
1534b289593eSRahul Lakkireddy static inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1535b289593eSRahul Lakkireddy {
1536b289593eSRahul Lakkireddy 	*mask = x | y;
1537b289593eSRahul Lakkireddy 	y = (__force u64)cpu_to_be64(y);
1538b289593eSRahul Lakkireddy 	memcpy(addr, (char *)&y + 2, ETH_ALEN);
1539b289593eSRahul Lakkireddy }
1540b289593eSRahul Lakkireddy 
1541b289593eSRahul Lakkireddy static void cudbg_mps_rpl_backdoor(struct adapter *padap,
1542b289593eSRahul Lakkireddy 				   struct fw_ldst_mps_rplc *mps_rplc)
1543b289593eSRahul Lakkireddy {
1544b289593eSRahul Lakkireddy 	if (is_t5(padap->params.chip)) {
1545b289593eSRahul Lakkireddy 		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
1546b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP3_A));
1547b289593eSRahul Lakkireddy 		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
1548b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP2_A));
1549b289593eSRahul Lakkireddy 		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
1550b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP1_A));
1551b289593eSRahul Lakkireddy 		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
1552b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP0_A));
1553b289593eSRahul Lakkireddy 	} else {
1554b289593eSRahul Lakkireddy 		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
1555b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP7_A));
1556b289593eSRahul Lakkireddy 		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
1557b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP6_A));
1558b289593eSRahul Lakkireddy 		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
1559b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP5_A));
1560b289593eSRahul Lakkireddy 		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
1561b289593eSRahul Lakkireddy 							  MPS_VF_RPLCT_MAP4_A));
1562b289593eSRahul Lakkireddy 	}
1563b289593eSRahul Lakkireddy 	mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP3_A));
1564b289593eSRahul Lakkireddy 	mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP2_A));
1565b289593eSRahul Lakkireddy 	mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP1_A));
1566b289593eSRahul Lakkireddy 	mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP0_A));
1567b289593eSRahul Lakkireddy }
1568b289593eSRahul Lakkireddy 
1569b289593eSRahul Lakkireddy static int cudbg_collect_tcam_index(struct adapter *padap,
1570b289593eSRahul Lakkireddy 				    struct cudbg_mps_tcam *tcam, u32 idx)
1571b289593eSRahul Lakkireddy {
1572b289593eSRahul Lakkireddy 	u64 tcamy, tcamx, val;
1573b289593eSRahul Lakkireddy 	u32 ctl, data2;
1574b289593eSRahul Lakkireddy 	int rc = 0;
1575b289593eSRahul Lakkireddy 
1576b289593eSRahul Lakkireddy 	if (CHELSIO_CHIP_VERSION(padap->params.chip) >= CHELSIO_T6) {
1577b289593eSRahul Lakkireddy 		/* CtlReqID   - 1: use Host Driver Requester ID
1578b289593eSRahul Lakkireddy 		 * CtlCmdType - 0: Read, 1: Write
1579b289593eSRahul Lakkireddy 		 * CtlTcamSel - 0: TCAM0, 1: TCAM1
1580b289593eSRahul Lakkireddy 		 * CtlXYBitSel- 0: Y bit, 1: X bit
1581b289593eSRahul Lakkireddy 		 */
1582b289593eSRahul Lakkireddy 
1583b289593eSRahul Lakkireddy 		/* Read tcamy */
1584b289593eSRahul Lakkireddy 		ctl = CTLREQID_V(1) | CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
1585b289593eSRahul Lakkireddy 		if (idx < 256)
1586b289593eSRahul Lakkireddy 			ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
1587b289593eSRahul Lakkireddy 		else
1588b289593eSRahul Lakkireddy 			ctl |= CTLTCAMINDEX_V(idx - 256) | CTLTCAMSEL_V(1);
1589b289593eSRahul Lakkireddy 
1590b289593eSRahul Lakkireddy 		t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1591b289593eSRahul Lakkireddy 		val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
1592b289593eSRahul Lakkireddy 		tcamy = DMACH_G(val) << 32;
1593b289593eSRahul Lakkireddy 		tcamy |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
1594b289593eSRahul Lakkireddy 		data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
1595b289593eSRahul Lakkireddy 		tcam->lookup_type = DATALKPTYPE_G(data2);
1596b289593eSRahul Lakkireddy 
1597b289593eSRahul Lakkireddy 		/* 0 - Outer header, 1 - Inner header
1598b289593eSRahul Lakkireddy 		 * [71:48] bit locations are overloaded for
1599b289593eSRahul Lakkireddy 		 * outer vs. inner lookup types.
1600b289593eSRahul Lakkireddy 		 */
1601b289593eSRahul Lakkireddy 		if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
1602b289593eSRahul Lakkireddy 			/* Inner header VNI */
1603b289593eSRahul Lakkireddy 			tcam->vniy = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
1604b289593eSRahul Lakkireddy 			tcam->vniy = (tcam->vniy << 16) | VIDL_G(val);
1605b289593eSRahul Lakkireddy 			tcam->dip_hit = data2 & DATADIPHIT_F;
1606b289593eSRahul Lakkireddy 		} else {
1607b289593eSRahul Lakkireddy 			tcam->vlan_vld = data2 & DATAVIDH2_F;
1608b289593eSRahul Lakkireddy 			tcam->ivlan = VIDL_G(val);
1609b289593eSRahul Lakkireddy 		}
1610b289593eSRahul Lakkireddy 
1611b289593eSRahul Lakkireddy 		tcam->port_num = DATAPORTNUM_G(data2);
1612b289593eSRahul Lakkireddy 
1613b289593eSRahul Lakkireddy 		/* Read tcamx. Change the control param */
1614b289593eSRahul Lakkireddy 		ctl |= CTLXYBITSEL_V(1);
1615b289593eSRahul Lakkireddy 		t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1616b289593eSRahul Lakkireddy 		val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
1617b289593eSRahul Lakkireddy 		tcamx = DMACH_G(val) << 32;
1618b289593eSRahul Lakkireddy 		tcamx |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
1619b289593eSRahul Lakkireddy 		data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
1620b289593eSRahul Lakkireddy 		if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
1621b289593eSRahul Lakkireddy 			/* Inner header VNI mask */
1622b289593eSRahul Lakkireddy 			tcam->vnix = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
1623b289593eSRahul Lakkireddy 			tcam->vnix = (tcam->vnix << 16) | VIDL_G(val);
1624b289593eSRahul Lakkireddy 		}
1625b289593eSRahul Lakkireddy 	} else {
1626b289593eSRahul Lakkireddy 		tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(idx));
1627b289593eSRahul Lakkireddy 		tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(idx));
1628b289593eSRahul Lakkireddy 	}
1629b289593eSRahul Lakkireddy 
1630b289593eSRahul Lakkireddy 	/* If no entry, return */
1631b289593eSRahul Lakkireddy 	if (tcamx & tcamy)
1632b289593eSRahul Lakkireddy 		return rc;
1633b289593eSRahul Lakkireddy 
1634b289593eSRahul Lakkireddy 	tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(idx));
1635b289593eSRahul Lakkireddy 	tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(idx));
1636b289593eSRahul Lakkireddy 
1637b289593eSRahul Lakkireddy 	if (is_t5(padap->params.chip))
1638b289593eSRahul Lakkireddy 		tcam->repli = (tcam->cls_lo & REPLICATE_F);
1639b289593eSRahul Lakkireddy 	else if (is_t6(padap->params.chip))
1640b289593eSRahul Lakkireddy 		tcam->repli = (tcam->cls_lo & T6_REPLICATE_F);
1641b289593eSRahul Lakkireddy 
1642b289593eSRahul Lakkireddy 	if (tcam->repli) {
1643b289593eSRahul Lakkireddy 		struct fw_ldst_cmd ldst_cmd;
1644b289593eSRahul Lakkireddy 		struct fw_ldst_mps_rplc mps_rplc;
1645b289593eSRahul Lakkireddy 
1646b289593eSRahul Lakkireddy 		memset(&ldst_cmd, 0, sizeof(ldst_cmd));
1647b289593eSRahul Lakkireddy 		ldst_cmd.op_to_addrspace =
1648b289593eSRahul Lakkireddy 			htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1649b289593eSRahul Lakkireddy 			      FW_CMD_REQUEST_F | FW_CMD_READ_F |
1650b289593eSRahul Lakkireddy 			      FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS));
1651b289593eSRahul Lakkireddy 		ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
1652b289593eSRahul Lakkireddy 		ldst_cmd.u.mps.rplc.fid_idx =
1653b289593eSRahul Lakkireddy 			htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
1654b289593eSRahul Lakkireddy 			      FW_LDST_CMD_IDX_V(idx));
1655b289593eSRahul Lakkireddy 
1656b289593eSRahul Lakkireddy 		rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd, sizeof(ldst_cmd),
1657b289593eSRahul Lakkireddy 				&ldst_cmd);
1658b289593eSRahul Lakkireddy 		if (rc)
1659b289593eSRahul Lakkireddy 			cudbg_mps_rpl_backdoor(padap, &mps_rplc);
1660b289593eSRahul Lakkireddy 		else
1661b289593eSRahul Lakkireddy 			mps_rplc = ldst_cmd.u.mps.rplc;
1662b289593eSRahul Lakkireddy 
1663b289593eSRahul Lakkireddy 		tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
1664b289593eSRahul Lakkireddy 		tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
1665b289593eSRahul Lakkireddy 		tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
1666b289593eSRahul Lakkireddy 		tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
1667b289593eSRahul Lakkireddy 		if (padap->params.arch.mps_rplc_size > CUDBG_MAX_RPLC_SIZE) {
1668b289593eSRahul Lakkireddy 			tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
1669b289593eSRahul Lakkireddy 			tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
1670b289593eSRahul Lakkireddy 			tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
1671b289593eSRahul Lakkireddy 			tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
1672b289593eSRahul Lakkireddy 		}
1673b289593eSRahul Lakkireddy 	}
1674b289593eSRahul Lakkireddy 	cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
1675b289593eSRahul Lakkireddy 	tcam->idx = idx;
1676b289593eSRahul Lakkireddy 	tcam->rplc_size = padap->params.arch.mps_rplc_size;
1677b289593eSRahul Lakkireddy 	return rc;
1678b289593eSRahul Lakkireddy }
1679b289593eSRahul Lakkireddy 
1680b289593eSRahul Lakkireddy int cudbg_collect_mps_tcam(struct cudbg_init *pdbg_init,
1681b289593eSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
1682b289593eSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
1683b289593eSRahul Lakkireddy {
1684b289593eSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1685b289593eSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1686b289593eSRahul Lakkireddy 	u32 size = 0, i, n, total_size = 0;
1687b289593eSRahul Lakkireddy 	struct cudbg_mps_tcam *tcam;
1688b289593eSRahul Lakkireddy 	int rc;
1689b289593eSRahul Lakkireddy 
1690b289593eSRahul Lakkireddy 	n = padap->params.arch.mps_tcam_size;
1691b289593eSRahul Lakkireddy 	size = sizeof(struct cudbg_mps_tcam) * n;
1692b289593eSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
1693b289593eSRahul Lakkireddy 	if (rc)
1694b289593eSRahul Lakkireddy 		return rc;
1695b289593eSRahul Lakkireddy 
1696b289593eSRahul Lakkireddy 	tcam = (struct cudbg_mps_tcam *)temp_buff.data;
1697b289593eSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1698b289593eSRahul Lakkireddy 		rc = cudbg_collect_tcam_index(padap, tcam, i);
1699b289593eSRahul Lakkireddy 		if (rc) {
1700b289593eSRahul Lakkireddy 			cudbg_err->sys_err = rc;
1701b289593eSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
1702b289593eSRahul Lakkireddy 			return rc;
1703b289593eSRahul Lakkireddy 		}
1704b289593eSRahul Lakkireddy 		total_size += sizeof(struct cudbg_mps_tcam);
1705b289593eSRahul Lakkireddy 		tcam++;
1706b289593eSRahul Lakkireddy 	}
1707b289593eSRahul Lakkireddy 
1708b289593eSRahul Lakkireddy 	if (!total_size) {
1709b289593eSRahul Lakkireddy 		rc = CUDBG_SYSTEM_ERROR;
1710b289593eSRahul Lakkireddy 		cudbg_err->sys_err = rc;
1711b289593eSRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
1712b289593eSRahul Lakkireddy 		return rc;
1713b289593eSRahul Lakkireddy 	}
1714b289593eSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1715b289593eSRahul Lakkireddy 	return rc;
1716b289593eSRahul Lakkireddy }
1717b289593eSRahul Lakkireddy 
17186f92a654SRahul Lakkireddy int cudbg_collect_vpd_data(struct cudbg_init *pdbg_init,
17196f92a654SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
17206f92a654SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
17216f92a654SRahul Lakkireddy {
17226f92a654SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
17236f92a654SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1724940c9c45SRahul Lakkireddy 	char vpd_str[CUDBG_VPD_VER_LEN + 1];
1725940c9c45SRahul Lakkireddy 	u32 scfg_vers, vpd_vers, fw_vers;
17266f92a654SRahul Lakkireddy 	struct cudbg_vpd_data *vpd_data;
1727940c9c45SRahul Lakkireddy 	struct vpd_params vpd = { 0 };
1728940c9c45SRahul Lakkireddy 	int rc, ret;
1729940c9c45SRahul Lakkireddy 
1730940c9c45SRahul Lakkireddy 	rc = t4_get_raw_vpd_params(padap, &vpd);
1731940c9c45SRahul Lakkireddy 	if (rc)
1732940c9c45SRahul Lakkireddy 		return rc;
1733940c9c45SRahul Lakkireddy 
1734940c9c45SRahul Lakkireddy 	rc = t4_get_fw_version(padap, &fw_vers);
1735940c9c45SRahul Lakkireddy 	if (rc)
1736940c9c45SRahul Lakkireddy 		return rc;
1737940c9c45SRahul Lakkireddy 
1738940c9c45SRahul Lakkireddy 	/* Serial Configuration Version is located beyond the PF's vpd size.
1739940c9c45SRahul Lakkireddy 	 * Temporarily give access to entire EEPROM to get it.
1740940c9c45SRahul Lakkireddy 	 */
1741940c9c45SRahul Lakkireddy 	rc = pci_set_vpd_size(padap->pdev, EEPROMVSIZE);
1742940c9c45SRahul Lakkireddy 	if (rc < 0)
1743940c9c45SRahul Lakkireddy 		return rc;
1744940c9c45SRahul Lakkireddy 
1745940c9c45SRahul Lakkireddy 	ret = cudbg_read_vpd_reg(padap, CUDBG_SCFG_VER_ADDR, CUDBG_SCFG_VER_LEN,
1746940c9c45SRahul Lakkireddy 				 &scfg_vers);
1747940c9c45SRahul Lakkireddy 
1748940c9c45SRahul Lakkireddy 	/* Restore back to original PF's vpd size */
1749940c9c45SRahul Lakkireddy 	rc = pci_set_vpd_size(padap->pdev, CUDBG_VPD_PF_SIZE);
1750940c9c45SRahul Lakkireddy 	if (rc < 0)
1751940c9c45SRahul Lakkireddy 		return rc;
1752940c9c45SRahul Lakkireddy 
1753940c9c45SRahul Lakkireddy 	if (ret)
1754940c9c45SRahul Lakkireddy 		return ret;
1755940c9c45SRahul Lakkireddy 
1756940c9c45SRahul Lakkireddy 	rc = cudbg_read_vpd_reg(padap, CUDBG_VPD_VER_ADDR, CUDBG_VPD_VER_LEN,
1757940c9c45SRahul Lakkireddy 				vpd_str);
1758940c9c45SRahul Lakkireddy 	if (rc)
1759940c9c45SRahul Lakkireddy 		return rc;
1760940c9c45SRahul Lakkireddy 
1761940c9c45SRahul Lakkireddy 	vpd_str[CUDBG_VPD_VER_LEN] = '\0';
1762940c9c45SRahul Lakkireddy 	rc = kstrtouint(vpd_str, 0, &vpd_vers);
1763940c9c45SRahul Lakkireddy 	if (rc)
1764940c9c45SRahul Lakkireddy 		return rc;
17656f92a654SRahul Lakkireddy 
17666f92a654SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_vpd_data),
17676f92a654SRahul Lakkireddy 			    &temp_buff);
17686f92a654SRahul Lakkireddy 	if (rc)
17696f92a654SRahul Lakkireddy 		return rc;
17706f92a654SRahul Lakkireddy 
17716f92a654SRahul Lakkireddy 	vpd_data = (struct cudbg_vpd_data *)temp_buff.data;
1772940c9c45SRahul Lakkireddy 	memcpy(vpd_data->sn, vpd.sn, SERNUM_LEN + 1);
1773940c9c45SRahul Lakkireddy 	memcpy(vpd_data->bn, vpd.pn, PN_LEN + 1);
1774940c9c45SRahul Lakkireddy 	memcpy(vpd_data->na, vpd.na, MACADDR_LEN + 1);
1775940c9c45SRahul Lakkireddy 	memcpy(vpd_data->mn, vpd.id, ID_LEN + 1);
1776940c9c45SRahul Lakkireddy 	vpd_data->scfg_vers = scfg_vers;
1777940c9c45SRahul Lakkireddy 	vpd_data->vpd_vers = vpd_vers;
1778940c9c45SRahul Lakkireddy 	vpd_data->fw_major = FW_HDR_FW_VER_MAJOR_G(fw_vers);
1779940c9c45SRahul Lakkireddy 	vpd_data->fw_minor = FW_HDR_FW_VER_MINOR_G(fw_vers);
1780940c9c45SRahul Lakkireddy 	vpd_data->fw_micro = FW_HDR_FW_VER_MICRO_G(fw_vers);
1781940c9c45SRahul Lakkireddy 	vpd_data->fw_build = FW_HDR_FW_VER_BUILD_G(fw_vers);
17826f92a654SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
17836f92a654SRahul Lakkireddy 	return rc;
17846f92a654SRahul Lakkireddy }
17856f92a654SRahul Lakkireddy 
178603e98b91SRahul Lakkireddy static int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
178703e98b91SRahul Lakkireddy 			  struct cudbg_tid_data *tid_data)
178803e98b91SRahul Lakkireddy {
178903e98b91SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
179003e98b91SRahul Lakkireddy 	int i, cmd_retry = 8;
179103e98b91SRahul Lakkireddy 	u32 val;
179203e98b91SRahul Lakkireddy 
179303e98b91SRahul Lakkireddy 	/* Fill REQ_DATA regs with 0's */
179403e98b91SRahul Lakkireddy 	for (i = 0; i < NUM_LE_DB_DBGI_REQ_DATA_INSTANCES; i++)
179503e98b91SRahul Lakkireddy 		t4_write_reg(padap, LE_DB_DBGI_REQ_DATA_A + (i << 2), 0);
179603e98b91SRahul Lakkireddy 
179703e98b91SRahul Lakkireddy 	/* Write DBIG command */
179803e98b91SRahul Lakkireddy 	val = DBGICMD_V(4) | DBGITID_V(tid);
179903e98b91SRahul Lakkireddy 	t4_write_reg(padap, LE_DB_DBGI_REQ_TCAM_CMD_A, val);
180003e98b91SRahul Lakkireddy 	tid_data->dbig_cmd = val;
180103e98b91SRahul Lakkireddy 
180203e98b91SRahul Lakkireddy 	val = DBGICMDSTRT_F | DBGICMDMODE_V(1); /* LE mode */
180303e98b91SRahul Lakkireddy 	t4_write_reg(padap, LE_DB_DBGI_CONFIG_A, val);
180403e98b91SRahul Lakkireddy 	tid_data->dbig_conf = val;
180503e98b91SRahul Lakkireddy 
180603e98b91SRahul Lakkireddy 	/* Poll the DBGICMDBUSY bit */
180703e98b91SRahul Lakkireddy 	val = 1;
180803e98b91SRahul Lakkireddy 	while (val) {
180903e98b91SRahul Lakkireddy 		val = t4_read_reg(padap, LE_DB_DBGI_CONFIG_A);
181003e98b91SRahul Lakkireddy 		val = val & DBGICMDBUSY_F;
181103e98b91SRahul Lakkireddy 		cmd_retry--;
181203e98b91SRahul Lakkireddy 		if (!cmd_retry)
181303e98b91SRahul Lakkireddy 			return CUDBG_SYSTEM_ERROR;
181403e98b91SRahul Lakkireddy 	}
181503e98b91SRahul Lakkireddy 
181603e98b91SRahul Lakkireddy 	/* Check RESP status */
181703e98b91SRahul Lakkireddy 	val = t4_read_reg(padap, LE_DB_DBGI_RSP_STATUS_A);
181803e98b91SRahul Lakkireddy 	tid_data->dbig_rsp_stat = val;
181903e98b91SRahul Lakkireddy 	if (!(val & 1))
182003e98b91SRahul Lakkireddy 		return CUDBG_SYSTEM_ERROR;
182103e98b91SRahul Lakkireddy 
182203e98b91SRahul Lakkireddy 	/* Read RESP data */
182303e98b91SRahul Lakkireddy 	for (i = 0; i < NUM_LE_DB_DBGI_RSP_DATA_INSTANCES; i++)
182403e98b91SRahul Lakkireddy 		tid_data->data[i] = t4_read_reg(padap,
182503e98b91SRahul Lakkireddy 						LE_DB_DBGI_RSP_DATA_A +
182603e98b91SRahul Lakkireddy 						(i << 2));
182703e98b91SRahul Lakkireddy 	tid_data->tid = tid;
182803e98b91SRahul Lakkireddy 	return 0;
182903e98b91SRahul Lakkireddy }
183003e98b91SRahul Lakkireddy 
183103e98b91SRahul Lakkireddy static int cudbg_get_le_type(u32 tid, struct cudbg_tcam tcam_region)
183203e98b91SRahul Lakkireddy {
183303e98b91SRahul Lakkireddy 	int type = LE_ET_UNKNOWN;
183403e98b91SRahul Lakkireddy 
183503e98b91SRahul Lakkireddy 	if (tid < tcam_region.server_start)
183603e98b91SRahul Lakkireddy 		type = LE_ET_TCAM_CON;
183703e98b91SRahul Lakkireddy 	else if (tid < tcam_region.filter_start)
183803e98b91SRahul Lakkireddy 		type = LE_ET_TCAM_SERVER;
183903e98b91SRahul Lakkireddy 	else if (tid < tcam_region.clip_start)
184003e98b91SRahul Lakkireddy 		type = LE_ET_TCAM_FILTER;
184103e98b91SRahul Lakkireddy 	else if (tid < tcam_region.routing_start)
184203e98b91SRahul Lakkireddy 		type = LE_ET_TCAM_CLIP;
184303e98b91SRahul Lakkireddy 	else if (tid < tcam_region.tid_hash_base)
184403e98b91SRahul Lakkireddy 		type = LE_ET_TCAM_ROUTING;
184503e98b91SRahul Lakkireddy 	else if (tid < tcam_region.max_tid)
184603e98b91SRahul Lakkireddy 		type = LE_ET_HASH_CON;
184703e98b91SRahul Lakkireddy 	else
184803e98b91SRahul Lakkireddy 		type = LE_ET_INVALID_TID;
184903e98b91SRahul Lakkireddy 
185003e98b91SRahul Lakkireddy 	return type;
185103e98b91SRahul Lakkireddy }
185203e98b91SRahul Lakkireddy 
185303e98b91SRahul Lakkireddy static int cudbg_is_ipv6_entry(struct cudbg_tid_data *tid_data,
185403e98b91SRahul Lakkireddy 			       struct cudbg_tcam tcam_region)
185503e98b91SRahul Lakkireddy {
185603e98b91SRahul Lakkireddy 	int ipv6 = 0;
185703e98b91SRahul Lakkireddy 	int le_type;
185803e98b91SRahul Lakkireddy 
185903e98b91SRahul Lakkireddy 	le_type = cudbg_get_le_type(tid_data->tid, tcam_region);
186003e98b91SRahul Lakkireddy 	if (tid_data->tid & 1)
186103e98b91SRahul Lakkireddy 		return 0;
186203e98b91SRahul Lakkireddy 
186303e98b91SRahul Lakkireddy 	if (le_type == LE_ET_HASH_CON) {
186403e98b91SRahul Lakkireddy 		ipv6 = tid_data->data[16] & 0x8000;
186503e98b91SRahul Lakkireddy 	} else if (le_type == LE_ET_TCAM_CON) {
186603e98b91SRahul Lakkireddy 		ipv6 = tid_data->data[16] & 0x8000;
186703e98b91SRahul Lakkireddy 		if (ipv6)
186803e98b91SRahul Lakkireddy 			ipv6 = tid_data->data[9] == 0x00C00000;
186903e98b91SRahul Lakkireddy 	} else {
187003e98b91SRahul Lakkireddy 		ipv6 = 0;
187103e98b91SRahul Lakkireddy 	}
187203e98b91SRahul Lakkireddy 	return ipv6;
187303e98b91SRahul Lakkireddy }
187403e98b91SRahul Lakkireddy 
187503e98b91SRahul Lakkireddy void cudbg_fill_le_tcam_info(struct adapter *padap,
187603e98b91SRahul Lakkireddy 			     struct cudbg_tcam *tcam_region)
187703e98b91SRahul Lakkireddy {
187803e98b91SRahul Lakkireddy 	u32 value;
187903e98b91SRahul Lakkireddy 
188003e98b91SRahul Lakkireddy 	/* Get the LE regions */
188103e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_TID_HASHBASE_A); /* hash base index */
188203e98b91SRahul Lakkireddy 	tcam_region->tid_hash_base = value;
188303e98b91SRahul Lakkireddy 
188403e98b91SRahul Lakkireddy 	/* Get routing table index */
188503e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_ROUTING_TABLE_INDEX_A);
188603e98b91SRahul Lakkireddy 	tcam_region->routing_start = value;
188703e98b91SRahul Lakkireddy 
188803e98b91SRahul Lakkireddy 	/*Get clip table index */
188903e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_CLIP_TABLE_INDEX_A);
189003e98b91SRahul Lakkireddy 	tcam_region->clip_start = value;
189103e98b91SRahul Lakkireddy 
189203e98b91SRahul Lakkireddy 	/* Get filter table index */
189303e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_FILTER_TABLE_INDEX_A);
189403e98b91SRahul Lakkireddy 	tcam_region->filter_start = value;
189503e98b91SRahul Lakkireddy 
189603e98b91SRahul Lakkireddy 	/* Get server table index */
189703e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_SERVER_INDEX_A);
189803e98b91SRahul Lakkireddy 	tcam_region->server_start = value;
189903e98b91SRahul Lakkireddy 
190003e98b91SRahul Lakkireddy 	/* Check whether hash is enabled and calculate the max tids */
190103e98b91SRahul Lakkireddy 	value = t4_read_reg(padap, LE_DB_CONFIG_A);
190203e98b91SRahul Lakkireddy 	if ((value >> HASHEN_S) & 1) {
190303e98b91SRahul Lakkireddy 		value = t4_read_reg(padap, LE_DB_HASH_CONFIG_A);
190403e98b91SRahul Lakkireddy 		if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
190503e98b91SRahul Lakkireddy 			tcam_region->max_tid = (value & 0xFFFFF) +
190603e98b91SRahul Lakkireddy 					       tcam_region->tid_hash_base;
190703e98b91SRahul Lakkireddy 		} else {
190803e98b91SRahul Lakkireddy 			value = HASHTIDSIZE_G(value);
190903e98b91SRahul Lakkireddy 			value = 1 << value;
191003e98b91SRahul Lakkireddy 			tcam_region->max_tid = value +
191103e98b91SRahul Lakkireddy 					       tcam_region->tid_hash_base;
191203e98b91SRahul Lakkireddy 		}
191303e98b91SRahul Lakkireddy 	} else { /* hash not enabled */
191403e98b91SRahul Lakkireddy 		tcam_region->max_tid = CUDBG_MAX_TCAM_TID;
191503e98b91SRahul Lakkireddy 	}
191603e98b91SRahul Lakkireddy }
191703e98b91SRahul Lakkireddy 
191803e98b91SRahul Lakkireddy int cudbg_collect_le_tcam(struct cudbg_init *pdbg_init,
191903e98b91SRahul Lakkireddy 			  struct cudbg_buffer *dbg_buff,
192003e98b91SRahul Lakkireddy 			  struct cudbg_error *cudbg_err)
192103e98b91SRahul Lakkireddy {
192203e98b91SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
192303e98b91SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
192403e98b91SRahul Lakkireddy 	struct cudbg_tcam tcam_region = { 0 };
192503e98b91SRahul Lakkireddy 	struct cudbg_tid_data *tid_data;
192603e98b91SRahul Lakkireddy 	u32 bytes = 0;
192703e98b91SRahul Lakkireddy 	int rc, size;
192803e98b91SRahul Lakkireddy 	u32 i;
192903e98b91SRahul Lakkireddy 
193003e98b91SRahul Lakkireddy 	cudbg_fill_le_tcam_info(padap, &tcam_region);
193103e98b91SRahul Lakkireddy 
193203e98b91SRahul Lakkireddy 	size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
193303e98b91SRahul Lakkireddy 	size += sizeof(struct cudbg_tcam);
193403e98b91SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
193503e98b91SRahul Lakkireddy 	if (rc)
193603e98b91SRahul Lakkireddy 		return rc;
193703e98b91SRahul Lakkireddy 
193803e98b91SRahul Lakkireddy 	memcpy(temp_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
193903e98b91SRahul Lakkireddy 	bytes = sizeof(struct cudbg_tcam);
194003e98b91SRahul Lakkireddy 	tid_data = (struct cudbg_tid_data *)(temp_buff.data + bytes);
194103e98b91SRahul Lakkireddy 	/* read all tid */
194203e98b91SRahul Lakkireddy 	for (i = 0; i < tcam_region.max_tid; ) {
194303e98b91SRahul Lakkireddy 		rc = cudbg_read_tid(pdbg_init, i, tid_data);
194403e98b91SRahul Lakkireddy 		if (rc) {
194503e98b91SRahul Lakkireddy 			cudbg_err->sys_err = rc;
194603e98b91SRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
194703e98b91SRahul Lakkireddy 			return rc;
194803e98b91SRahul Lakkireddy 		}
194903e98b91SRahul Lakkireddy 
195003e98b91SRahul Lakkireddy 		/* ipv6 takes two tids */
195103e98b91SRahul Lakkireddy 		cudbg_is_ipv6_entry(tid_data, tcam_region) ? i += 2 : i++;
195203e98b91SRahul Lakkireddy 
195303e98b91SRahul Lakkireddy 		tid_data++;
195403e98b91SRahul Lakkireddy 		bytes += sizeof(struct cudbg_tid_data);
195503e98b91SRahul Lakkireddy 	}
195603e98b91SRahul Lakkireddy 
195703e98b91SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
195803e98b91SRahul Lakkireddy 	return rc;
195903e98b91SRahul Lakkireddy }
196003e98b91SRahul Lakkireddy 
19616f92a654SRahul Lakkireddy int cudbg_collect_cctrl(struct cudbg_init *pdbg_init,
19626f92a654SRahul Lakkireddy 			struct cudbg_buffer *dbg_buff,
19636f92a654SRahul Lakkireddy 			struct cudbg_error *cudbg_err)
19646f92a654SRahul Lakkireddy {
19656f92a654SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
19666f92a654SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
19676f92a654SRahul Lakkireddy 	u32 size;
19686f92a654SRahul Lakkireddy 	int rc;
19696f92a654SRahul Lakkireddy 
19706f92a654SRahul Lakkireddy 	size = sizeof(u16) * NMTUS * NCCTRL_WIN;
19716f92a654SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
19726f92a654SRahul Lakkireddy 	if (rc)
19736f92a654SRahul Lakkireddy 		return rc;
19746f92a654SRahul Lakkireddy 
19756f92a654SRahul Lakkireddy 	t4_read_cong_tbl(padap, (void *)temp_buff.data);
19766f92a654SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
19776f92a654SRahul Lakkireddy 	return rc;
19786f92a654SRahul Lakkireddy }
19796f92a654SRahul Lakkireddy 
1980270d39bfSRahul Lakkireddy int cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
1981270d39bfSRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
1982270d39bfSRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
1983270d39bfSRahul Lakkireddy {
1984270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1985270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1986270d39bfSRahul Lakkireddy 	struct ireg_buf *ma_indr;
1987270d39bfSRahul Lakkireddy 	int i, rc, n;
1988270d39bfSRahul Lakkireddy 	u32 size, j;
1989270d39bfSRahul Lakkireddy 
1990270d39bfSRahul Lakkireddy 	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
1991270d39bfSRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
1992270d39bfSRahul Lakkireddy 
1993270d39bfSRahul Lakkireddy 	n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
1994270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
1995270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
1996270d39bfSRahul Lakkireddy 	if (rc)
1997270d39bfSRahul Lakkireddy 		return rc;
1998270d39bfSRahul Lakkireddy 
1999270d39bfSRahul Lakkireddy 	ma_indr = (struct ireg_buf *)temp_buff.data;
2000270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
2001270d39bfSRahul Lakkireddy 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
2002270d39bfSRahul Lakkireddy 		u32 *buff = ma_indr->outbuf;
2003270d39bfSRahul Lakkireddy 
2004270d39bfSRahul Lakkireddy 		ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
2005270d39bfSRahul Lakkireddy 		ma_fli->ireg_data = t6_ma_ireg_array[i][1];
2006270d39bfSRahul Lakkireddy 		ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
2007270d39bfSRahul Lakkireddy 		ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
2008270d39bfSRahul Lakkireddy 		t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
2009270d39bfSRahul Lakkireddy 				 buff, ma_fli->ireg_offset_range,
2010270d39bfSRahul Lakkireddy 				 ma_fli->ireg_local_offset);
2011270d39bfSRahul Lakkireddy 		ma_indr++;
2012270d39bfSRahul Lakkireddy 	}
2013270d39bfSRahul Lakkireddy 
2014270d39bfSRahul Lakkireddy 	n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
2015270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
2016270d39bfSRahul Lakkireddy 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
2017270d39bfSRahul Lakkireddy 		u32 *buff = ma_indr->outbuf;
2018270d39bfSRahul Lakkireddy 
2019270d39bfSRahul Lakkireddy 		ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
2020270d39bfSRahul Lakkireddy 		ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
2021270d39bfSRahul Lakkireddy 		ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
2022270d39bfSRahul Lakkireddy 		for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
2023270d39bfSRahul Lakkireddy 			t4_read_indirect(padap, ma_fli->ireg_addr,
2024270d39bfSRahul Lakkireddy 					 ma_fli->ireg_data, buff, 1,
2025270d39bfSRahul Lakkireddy 					 ma_fli->ireg_local_offset);
2026270d39bfSRahul Lakkireddy 			buff++;
2027270d39bfSRahul Lakkireddy 			ma_fli->ireg_local_offset += 0x20;
2028270d39bfSRahul Lakkireddy 		}
2029270d39bfSRahul Lakkireddy 		ma_indr++;
2030270d39bfSRahul Lakkireddy 	}
2031270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2032270d39bfSRahul Lakkireddy 	return rc;
2033270d39bfSRahul Lakkireddy }
2034270d39bfSRahul Lakkireddy 
203527887bc7SRahul Lakkireddy int cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
203627887bc7SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
203727887bc7SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
203827887bc7SRahul Lakkireddy {
203927887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
204027887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
204127887bc7SRahul Lakkireddy 	struct cudbg_ulptx_la *ulptx_la_buff;
204227887bc7SRahul Lakkireddy 	u32 i, j;
204327887bc7SRahul Lakkireddy 	int rc;
204427887bc7SRahul Lakkireddy 
204527887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_ulptx_la),
204627887bc7SRahul Lakkireddy 			    &temp_buff);
204727887bc7SRahul Lakkireddy 	if (rc)
204827887bc7SRahul Lakkireddy 		return rc;
204927887bc7SRahul Lakkireddy 
205027887bc7SRahul Lakkireddy 	ulptx_la_buff = (struct cudbg_ulptx_la *)temp_buff.data;
205127887bc7SRahul Lakkireddy 	for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
205227887bc7SRahul Lakkireddy 		ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
205327887bc7SRahul Lakkireddy 						      ULP_TX_LA_RDPTR_0_A +
205427887bc7SRahul Lakkireddy 						      0x10 * i);
205527887bc7SRahul Lakkireddy 		ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
205627887bc7SRahul Lakkireddy 						      ULP_TX_LA_WRPTR_0_A +
205727887bc7SRahul Lakkireddy 						      0x10 * i);
205827887bc7SRahul Lakkireddy 		ulptx_la_buff->rddata[i] = t4_read_reg(padap,
205927887bc7SRahul Lakkireddy 						       ULP_TX_LA_RDDATA_0_A +
206027887bc7SRahul Lakkireddy 						       0x10 * i);
206127887bc7SRahul Lakkireddy 		for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
206227887bc7SRahul Lakkireddy 			ulptx_la_buff->rd_data[i][j] =
206327887bc7SRahul Lakkireddy 				t4_read_reg(padap,
206427887bc7SRahul Lakkireddy 					    ULP_TX_LA_RDDATA_0_A + 0x10 * i);
206527887bc7SRahul Lakkireddy 	}
206627887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
206727887bc7SRahul Lakkireddy 	return rc;
206827887bc7SRahul Lakkireddy }
206927887bc7SRahul Lakkireddy 
2070270d39bfSRahul Lakkireddy int cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
2071270d39bfSRahul Lakkireddy 				  struct cudbg_buffer *dbg_buff,
2072270d39bfSRahul Lakkireddy 				  struct cudbg_error *cudbg_err)
2073270d39bfSRahul Lakkireddy {
2074270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2075270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2076270d39bfSRahul Lakkireddy 	struct ireg_buf *up_cim;
2077270d39bfSRahul Lakkireddy 	int i, rc, n;
2078270d39bfSRahul Lakkireddy 	u32 size;
2079270d39bfSRahul Lakkireddy 
2080270d39bfSRahul Lakkireddy 	n = sizeof(t5_up_cim_reg_array) / (IREG_NUM_ELEM * sizeof(u32));
2081270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
2082270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
2083270d39bfSRahul Lakkireddy 	if (rc)
2084270d39bfSRahul Lakkireddy 		return rc;
2085270d39bfSRahul Lakkireddy 
2086270d39bfSRahul Lakkireddy 	up_cim = (struct ireg_buf *)temp_buff.data;
2087270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
2088270d39bfSRahul Lakkireddy 		struct ireg_field *up_cim_reg = &up_cim->tp_pio;
2089270d39bfSRahul Lakkireddy 		u32 *buff = up_cim->outbuf;
2090270d39bfSRahul Lakkireddy 
2091270d39bfSRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
2092270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
2093270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
2094270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_local_offset =
2095270d39bfSRahul Lakkireddy 						t5_up_cim_reg_array[i][2];
2096270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_offset_range =
2097270d39bfSRahul Lakkireddy 						t5_up_cim_reg_array[i][3];
2098270d39bfSRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
2099270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
2100270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
2101270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_local_offset =
2102270d39bfSRahul Lakkireddy 						t6_up_cim_reg_array[i][2];
2103270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_offset_range =
2104270d39bfSRahul Lakkireddy 						t6_up_cim_reg_array[i][3];
2105270d39bfSRahul Lakkireddy 		}
2106270d39bfSRahul Lakkireddy 
2107270d39bfSRahul Lakkireddy 		rc = t4_cim_read(padap, up_cim_reg->ireg_local_offset,
2108270d39bfSRahul Lakkireddy 				 up_cim_reg->ireg_offset_range, buff);
2109270d39bfSRahul Lakkireddy 		if (rc) {
2110270d39bfSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
2111270d39bfSRahul Lakkireddy 			return rc;
2112270d39bfSRahul Lakkireddy 		}
2113270d39bfSRahul Lakkireddy 		up_cim++;
2114270d39bfSRahul Lakkireddy 	}
2115270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2116270d39bfSRahul Lakkireddy 	return rc;
2117270d39bfSRahul Lakkireddy }
2118270d39bfSRahul Lakkireddy 
2119db8cd7ceSRahul Lakkireddy int cudbg_collect_pbt_tables(struct cudbg_init *pdbg_init,
2120db8cd7ceSRahul Lakkireddy 			     struct cudbg_buffer *dbg_buff,
2121db8cd7ceSRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
2122db8cd7ceSRahul Lakkireddy {
2123db8cd7ceSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2124db8cd7ceSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2125db8cd7ceSRahul Lakkireddy 	struct cudbg_pbt_tables *pbt;
2126db8cd7ceSRahul Lakkireddy 	int i, rc;
2127db8cd7ceSRahul Lakkireddy 	u32 addr;
2128db8cd7ceSRahul Lakkireddy 
2129db8cd7ceSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_pbt_tables),
2130db8cd7ceSRahul Lakkireddy 			    &temp_buff);
2131db8cd7ceSRahul Lakkireddy 	if (rc)
2132db8cd7ceSRahul Lakkireddy 		return rc;
2133db8cd7ceSRahul Lakkireddy 
2134db8cd7ceSRahul Lakkireddy 	pbt = (struct cudbg_pbt_tables *)temp_buff.data;
2135db8cd7ceSRahul Lakkireddy 	/* PBT dynamic entries */
2136db8cd7ceSRahul Lakkireddy 	addr = CUDBG_CHAC_PBT_ADDR;
2137db8cd7ceSRahul Lakkireddy 	for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
2138db8cd7ceSRahul Lakkireddy 		rc = t4_cim_read(padap, addr + (i * 4), 1,
2139db8cd7ceSRahul Lakkireddy 				 &pbt->pbt_dynamic[i]);
2140db8cd7ceSRahul Lakkireddy 		if (rc) {
2141db8cd7ceSRahul Lakkireddy 			cudbg_err->sys_err = rc;
2142db8cd7ceSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
2143db8cd7ceSRahul Lakkireddy 			return rc;
2144db8cd7ceSRahul Lakkireddy 		}
2145db8cd7ceSRahul Lakkireddy 	}
2146db8cd7ceSRahul Lakkireddy 
2147db8cd7ceSRahul Lakkireddy 	/* PBT static entries */
2148db8cd7ceSRahul Lakkireddy 	/* static entries start when bit 6 is set */
2149db8cd7ceSRahul Lakkireddy 	addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
2150db8cd7ceSRahul Lakkireddy 	for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
2151db8cd7ceSRahul Lakkireddy 		rc = t4_cim_read(padap, addr + (i * 4), 1,
2152db8cd7ceSRahul Lakkireddy 				 &pbt->pbt_static[i]);
2153db8cd7ceSRahul Lakkireddy 		if (rc) {
2154db8cd7ceSRahul Lakkireddy 			cudbg_err->sys_err = rc;
2155db8cd7ceSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
2156db8cd7ceSRahul Lakkireddy 			return rc;
2157db8cd7ceSRahul Lakkireddy 		}
2158db8cd7ceSRahul Lakkireddy 	}
2159db8cd7ceSRahul Lakkireddy 
2160db8cd7ceSRahul Lakkireddy 	/* LRF entries */
2161db8cd7ceSRahul Lakkireddy 	addr = CUDBG_CHAC_PBT_LRF;
2162db8cd7ceSRahul Lakkireddy 	for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
2163db8cd7ceSRahul Lakkireddy 		rc = t4_cim_read(padap, addr + (i * 4), 1,
2164db8cd7ceSRahul Lakkireddy 				 &pbt->lrf_table[i]);
2165db8cd7ceSRahul Lakkireddy 		if (rc) {
2166db8cd7ceSRahul Lakkireddy 			cudbg_err->sys_err = rc;
2167db8cd7ceSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
2168db8cd7ceSRahul Lakkireddy 			return rc;
2169db8cd7ceSRahul Lakkireddy 		}
2170db8cd7ceSRahul Lakkireddy 	}
2171db8cd7ceSRahul Lakkireddy 
2172db8cd7ceSRahul Lakkireddy 	/* PBT data entries */
2173db8cd7ceSRahul Lakkireddy 	addr = CUDBG_CHAC_PBT_DATA;
2174db8cd7ceSRahul Lakkireddy 	for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
2175db8cd7ceSRahul Lakkireddy 		rc = t4_cim_read(padap, addr + (i * 4), 1,
2176db8cd7ceSRahul Lakkireddy 				 &pbt->pbt_data[i]);
2177db8cd7ceSRahul Lakkireddy 		if (rc) {
2178db8cd7ceSRahul Lakkireddy 			cudbg_err->sys_err = rc;
2179db8cd7ceSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
2180db8cd7ceSRahul Lakkireddy 			return rc;
2181db8cd7ceSRahul Lakkireddy 		}
2182db8cd7ceSRahul Lakkireddy 	}
2183db8cd7ceSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2184db8cd7ceSRahul Lakkireddy 	return rc;
2185db8cd7ceSRahul Lakkireddy }
2186db8cd7ceSRahul Lakkireddy 
2187844d1b6fSRahul Lakkireddy int cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
2188844d1b6fSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
2189844d1b6fSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
2190844d1b6fSRahul Lakkireddy {
2191844d1b6fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2192844d1b6fSRahul Lakkireddy 	struct cudbg_mbox_log *mboxlog = NULL;
2193844d1b6fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2194844d1b6fSRahul Lakkireddy 	struct mbox_cmd_log *log = NULL;
2195844d1b6fSRahul Lakkireddy 	struct mbox_cmd *entry;
2196844d1b6fSRahul Lakkireddy 	unsigned int entry_idx;
2197844d1b6fSRahul Lakkireddy 	u16 mbox_cmds;
2198844d1b6fSRahul Lakkireddy 	int i, k, rc;
2199844d1b6fSRahul Lakkireddy 	u64 flit;
2200844d1b6fSRahul Lakkireddy 	u32 size;
2201844d1b6fSRahul Lakkireddy 
2202844d1b6fSRahul Lakkireddy 	log = padap->mbox_log;
2203844d1b6fSRahul Lakkireddy 	mbox_cmds = padap->mbox_log->size;
2204844d1b6fSRahul Lakkireddy 	size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
2205844d1b6fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
2206844d1b6fSRahul Lakkireddy 	if (rc)
2207844d1b6fSRahul Lakkireddy 		return rc;
2208844d1b6fSRahul Lakkireddy 
2209844d1b6fSRahul Lakkireddy 	mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
2210844d1b6fSRahul Lakkireddy 	for (k = 0; k < mbox_cmds; k++) {
2211844d1b6fSRahul Lakkireddy 		entry_idx = log->cursor + k;
2212844d1b6fSRahul Lakkireddy 		if (entry_idx >= log->size)
2213844d1b6fSRahul Lakkireddy 			entry_idx -= log->size;
2214844d1b6fSRahul Lakkireddy 
2215844d1b6fSRahul Lakkireddy 		entry = mbox_cmd_log_entry(log, entry_idx);
2216844d1b6fSRahul Lakkireddy 		/* skip over unused entries */
2217844d1b6fSRahul Lakkireddy 		if (entry->timestamp == 0)
2218844d1b6fSRahul Lakkireddy 			continue;
2219844d1b6fSRahul Lakkireddy 
2220844d1b6fSRahul Lakkireddy 		memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
2221844d1b6fSRahul Lakkireddy 		for (i = 0; i < MBOX_LEN / 8; i++) {
2222844d1b6fSRahul Lakkireddy 			flit = entry->cmd[i];
2223844d1b6fSRahul Lakkireddy 			mboxlog->hi[i] = (u32)(flit >> 32);
2224844d1b6fSRahul Lakkireddy 			mboxlog->lo[i] = (u32)flit;
2225844d1b6fSRahul Lakkireddy 		}
2226844d1b6fSRahul Lakkireddy 		mboxlog++;
2227844d1b6fSRahul Lakkireddy 	}
2228844d1b6fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2229844d1b6fSRahul Lakkireddy 	return rc;
2230844d1b6fSRahul Lakkireddy }
2231270d39bfSRahul Lakkireddy 
2232270d39bfSRahul Lakkireddy int cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
2233270d39bfSRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
2234270d39bfSRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
2235270d39bfSRahul Lakkireddy {
2236270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2237270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2238270d39bfSRahul Lakkireddy 	struct ireg_buf *hma_indr;
2239270d39bfSRahul Lakkireddy 	int i, rc, n;
2240270d39bfSRahul Lakkireddy 	u32 size;
2241270d39bfSRahul Lakkireddy 
2242270d39bfSRahul Lakkireddy 	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
2243270d39bfSRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
2244270d39bfSRahul Lakkireddy 
2245270d39bfSRahul Lakkireddy 	n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
2246270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
2247270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
2248270d39bfSRahul Lakkireddy 	if (rc)
2249270d39bfSRahul Lakkireddy 		return rc;
2250270d39bfSRahul Lakkireddy 
2251270d39bfSRahul Lakkireddy 	hma_indr = (struct ireg_buf *)temp_buff.data;
2252270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
2253270d39bfSRahul Lakkireddy 		struct ireg_field *hma_fli = &hma_indr->tp_pio;
2254270d39bfSRahul Lakkireddy 		u32 *buff = hma_indr->outbuf;
2255270d39bfSRahul Lakkireddy 
2256270d39bfSRahul Lakkireddy 		hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
2257270d39bfSRahul Lakkireddy 		hma_fli->ireg_data = t6_hma_ireg_array[i][1];
2258270d39bfSRahul Lakkireddy 		hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
2259270d39bfSRahul Lakkireddy 		hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
2260270d39bfSRahul Lakkireddy 		t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
2261270d39bfSRahul Lakkireddy 				 buff, hma_fli->ireg_offset_range,
2262270d39bfSRahul Lakkireddy 				 hma_fli->ireg_local_offset);
2263270d39bfSRahul Lakkireddy 		hma_indr++;
2264270d39bfSRahul Lakkireddy 	}
2265270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2266270d39bfSRahul Lakkireddy 	return rc;
2267270d39bfSRahul Lakkireddy }
2268