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 
18b33af022SRahul Lakkireddy #include "t4_regs.h"
19a7975a2fSRahul Lakkireddy #include "cxgb4.h"
20a7975a2fSRahul Lakkireddy #include "cudbg_if.h"
21a7975a2fSRahul Lakkireddy #include "cudbg_lib_common.h"
22a7975a2fSRahul Lakkireddy #include "cudbg_lib.h"
23b33af022SRahul Lakkireddy #include "cudbg_entity.h"
24a7975a2fSRahul Lakkireddy 
25a7975a2fSRahul Lakkireddy static void cudbg_write_and_release_buff(struct cudbg_buffer *pin_buff,
26a7975a2fSRahul Lakkireddy 					 struct cudbg_buffer *dbg_buff)
27a7975a2fSRahul Lakkireddy {
28a7975a2fSRahul Lakkireddy 	cudbg_update_buff(pin_buff, dbg_buff);
29a7975a2fSRahul Lakkireddy 	cudbg_put_buff(pin_buff, dbg_buff);
30a7975a2fSRahul Lakkireddy }
31a7975a2fSRahul Lakkireddy 
32b33af022SRahul Lakkireddy static int is_fw_attached(struct cudbg_init *pdbg_init)
33b33af022SRahul Lakkireddy {
34b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
35b33af022SRahul Lakkireddy 
36b33af022SRahul Lakkireddy 	if (!(padap->flags & FW_OK) || padap->use_bd)
37b33af022SRahul Lakkireddy 		return 0;
38b33af022SRahul Lakkireddy 
39b33af022SRahul Lakkireddy 	return 1;
40b33af022SRahul Lakkireddy }
41b33af022SRahul Lakkireddy 
42a7975a2fSRahul Lakkireddy /* This function will add additional padding bytes into debug_buffer to make it
43a7975a2fSRahul Lakkireddy  * 4 byte aligned.
44a7975a2fSRahul Lakkireddy  */
45a7975a2fSRahul Lakkireddy void cudbg_align_debug_buffer(struct cudbg_buffer *dbg_buff,
46a7975a2fSRahul Lakkireddy 			      struct cudbg_entity_hdr *entity_hdr)
47a7975a2fSRahul Lakkireddy {
48a7975a2fSRahul Lakkireddy 	u8 zero_buf[4] = {0};
49a7975a2fSRahul Lakkireddy 	u8 padding, remain;
50a7975a2fSRahul Lakkireddy 
51a7975a2fSRahul Lakkireddy 	remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
52a7975a2fSRahul Lakkireddy 	padding = 4 - remain;
53a7975a2fSRahul Lakkireddy 	if (remain) {
54a7975a2fSRahul Lakkireddy 		memcpy(((u8 *)dbg_buff->data) + dbg_buff->offset, &zero_buf,
55a7975a2fSRahul Lakkireddy 		       padding);
56a7975a2fSRahul Lakkireddy 		dbg_buff->offset += padding;
57a7975a2fSRahul Lakkireddy 		entity_hdr->num_pad = padding;
58a7975a2fSRahul Lakkireddy 	}
59a7975a2fSRahul Lakkireddy 	entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
60a7975a2fSRahul Lakkireddy }
61a7975a2fSRahul Lakkireddy 
62a7975a2fSRahul Lakkireddy struct cudbg_entity_hdr *cudbg_get_entity_hdr(void *outbuf, int i)
63a7975a2fSRahul Lakkireddy {
64a7975a2fSRahul Lakkireddy 	struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
65a7975a2fSRahul Lakkireddy 
66a7975a2fSRahul Lakkireddy 	return (struct cudbg_entity_hdr *)
67a7975a2fSRahul Lakkireddy 	       ((char *)outbuf + cudbg_hdr->hdr_len +
68a7975a2fSRahul Lakkireddy 		(sizeof(struct cudbg_entity_hdr) * (i - 1)));
69a7975a2fSRahul Lakkireddy }
70a7975a2fSRahul Lakkireddy 
71a7975a2fSRahul Lakkireddy int cudbg_collect_reg_dump(struct cudbg_init *pdbg_init,
72a7975a2fSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
73a7975a2fSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
74a7975a2fSRahul Lakkireddy {
75a7975a2fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
76a7975a2fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
77a7975a2fSRahul Lakkireddy 	u32 buf_size = 0;
78a7975a2fSRahul Lakkireddy 	int rc = 0;
79a7975a2fSRahul Lakkireddy 
80a7975a2fSRahul Lakkireddy 	if (is_t4(padap->params.chip))
81a7975a2fSRahul Lakkireddy 		buf_size = T4_REGMAP_SIZE;
82a7975a2fSRahul Lakkireddy 	else if (is_t5(padap->params.chip) || is_t6(padap->params.chip))
83a7975a2fSRahul Lakkireddy 		buf_size = T5_REGMAP_SIZE;
84a7975a2fSRahul Lakkireddy 
85a7975a2fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, buf_size, &temp_buff);
86a7975a2fSRahul Lakkireddy 	if (rc)
87a7975a2fSRahul Lakkireddy 		return rc;
88a7975a2fSRahul Lakkireddy 	t4_get_regs(padap, (void *)temp_buff.data, temp_buff.size);
89a7975a2fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
90a7975a2fSRahul Lakkireddy 	return rc;
91a7975a2fSRahul Lakkireddy }
92b33af022SRahul Lakkireddy 
93844d1b6fSRahul Lakkireddy int cudbg_collect_fw_devlog(struct cudbg_init *pdbg_init,
94844d1b6fSRahul Lakkireddy 			    struct cudbg_buffer *dbg_buff,
95844d1b6fSRahul Lakkireddy 			    struct cudbg_error *cudbg_err)
96844d1b6fSRahul Lakkireddy {
97844d1b6fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
98844d1b6fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
99844d1b6fSRahul Lakkireddy 	struct devlog_params *dparams;
100844d1b6fSRahul Lakkireddy 	int rc = 0;
101844d1b6fSRahul Lakkireddy 
102844d1b6fSRahul Lakkireddy 	rc = t4_init_devlog_params(padap);
103844d1b6fSRahul Lakkireddy 	if (rc < 0) {
104844d1b6fSRahul Lakkireddy 		cudbg_err->sys_err = rc;
105844d1b6fSRahul Lakkireddy 		return rc;
106844d1b6fSRahul Lakkireddy 	}
107844d1b6fSRahul Lakkireddy 
108844d1b6fSRahul Lakkireddy 	dparams = &padap->params.devlog;
109844d1b6fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, dparams->size, &temp_buff);
110844d1b6fSRahul Lakkireddy 	if (rc)
111844d1b6fSRahul Lakkireddy 		return rc;
112844d1b6fSRahul Lakkireddy 
113844d1b6fSRahul Lakkireddy 	/* Collect FW devlog */
114844d1b6fSRahul Lakkireddy 	if (dparams->start != 0) {
115844d1b6fSRahul Lakkireddy 		spin_lock(&padap->win0_lock);
116844d1b6fSRahul Lakkireddy 		rc = t4_memory_rw(padap, padap->params.drv_memwin,
117844d1b6fSRahul Lakkireddy 				  dparams->memtype, dparams->start,
118844d1b6fSRahul Lakkireddy 				  dparams->size,
119844d1b6fSRahul Lakkireddy 				  (__be32 *)(char *)temp_buff.data,
120844d1b6fSRahul Lakkireddy 				  1);
121844d1b6fSRahul Lakkireddy 		spin_unlock(&padap->win0_lock);
122844d1b6fSRahul Lakkireddy 		if (rc) {
123844d1b6fSRahul Lakkireddy 			cudbg_err->sys_err = rc;
124844d1b6fSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
125844d1b6fSRahul Lakkireddy 			return rc;
126844d1b6fSRahul Lakkireddy 		}
127844d1b6fSRahul Lakkireddy 	}
128844d1b6fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
129844d1b6fSRahul Lakkireddy 	return rc;
130844d1b6fSRahul Lakkireddy }
131844d1b6fSRahul Lakkireddy 
13227887bc7SRahul Lakkireddy int cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
13327887bc7SRahul Lakkireddy 			 struct cudbg_buffer *dbg_buff,
13427887bc7SRahul Lakkireddy 			 struct cudbg_error *cudbg_err)
13527887bc7SRahul Lakkireddy {
13627887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
13727887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
13827887bc7SRahul Lakkireddy 	int size, rc;
13927887bc7SRahul Lakkireddy 	u32 cfg = 0;
14027887bc7SRahul Lakkireddy 
14127887bc7SRahul Lakkireddy 	if (is_t6(padap->params.chip)) {
14227887bc7SRahul Lakkireddy 		size = padap->params.cim_la_size / 10 + 1;
14327887bc7SRahul Lakkireddy 		size *= 11 * sizeof(u32);
14427887bc7SRahul Lakkireddy 	} else {
14527887bc7SRahul Lakkireddy 		size = padap->params.cim_la_size / 8;
14627887bc7SRahul Lakkireddy 		size *= 8 * sizeof(u32);
14727887bc7SRahul Lakkireddy 	}
14827887bc7SRahul Lakkireddy 
14927887bc7SRahul Lakkireddy 	size += sizeof(cfg);
15027887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
15127887bc7SRahul Lakkireddy 	if (rc)
15227887bc7SRahul Lakkireddy 		return rc;
15327887bc7SRahul Lakkireddy 
15427887bc7SRahul Lakkireddy 	rc = t4_cim_read(padap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
15527887bc7SRahul Lakkireddy 	if (rc) {
15627887bc7SRahul Lakkireddy 		cudbg_err->sys_err = rc;
15727887bc7SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
15827887bc7SRahul Lakkireddy 		return rc;
15927887bc7SRahul Lakkireddy 	}
16027887bc7SRahul Lakkireddy 
16127887bc7SRahul Lakkireddy 	memcpy((char *)temp_buff.data, &cfg, sizeof(cfg));
16227887bc7SRahul Lakkireddy 	rc = t4_cim_read_la(padap,
16327887bc7SRahul Lakkireddy 			    (u32 *)((char *)temp_buff.data + sizeof(cfg)),
16427887bc7SRahul Lakkireddy 			    NULL);
16527887bc7SRahul Lakkireddy 	if (rc < 0) {
16627887bc7SRahul Lakkireddy 		cudbg_err->sys_err = rc;
16727887bc7SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
16827887bc7SRahul Lakkireddy 		return rc;
16927887bc7SRahul Lakkireddy 	}
17027887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
17127887bc7SRahul Lakkireddy 	return rc;
17227887bc7SRahul Lakkireddy }
17327887bc7SRahul Lakkireddy 
17427887bc7SRahul Lakkireddy int cudbg_collect_cim_ma_la(struct cudbg_init *pdbg_init,
17527887bc7SRahul Lakkireddy 			    struct cudbg_buffer *dbg_buff,
17627887bc7SRahul Lakkireddy 			    struct cudbg_error *cudbg_err)
17727887bc7SRahul Lakkireddy {
17827887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
17927887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
18027887bc7SRahul Lakkireddy 	int size, rc;
18127887bc7SRahul Lakkireddy 
18227887bc7SRahul Lakkireddy 	size = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
18327887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
18427887bc7SRahul Lakkireddy 	if (rc)
18527887bc7SRahul Lakkireddy 		return rc;
18627887bc7SRahul Lakkireddy 
18727887bc7SRahul Lakkireddy 	t4_cim_read_ma_la(padap,
18827887bc7SRahul Lakkireddy 			  (u32 *)temp_buff.data,
18927887bc7SRahul Lakkireddy 			  (u32 *)((char *)temp_buff.data +
19027887bc7SRahul Lakkireddy 				  5 * CIM_MALA_SIZE));
19127887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
19227887bc7SRahul Lakkireddy 	return rc;
19327887bc7SRahul Lakkireddy }
19427887bc7SRahul Lakkireddy 
1957c075ce2SRahul Lakkireddy static int cudbg_read_cim_ibq(struct cudbg_init *pdbg_init,
1967c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
1977c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err, int qid)
1987c075ce2SRahul Lakkireddy {
1997c075ce2SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2007c075ce2SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2017c075ce2SRahul Lakkireddy 	int no_of_read_words, rc = 0;
2027c075ce2SRahul Lakkireddy 	u32 qsize;
2037c075ce2SRahul Lakkireddy 
2047c075ce2SRahul Lakkireddy 	/* collect CIM IBQ */
2057c075ce2SRahul Lakkireddy 	qsize = CIM_IBQ_SIZE * 4 * sizeof(u32);
2067c075ce2SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, qsize, &temp_buff);
2077c075ce2SRahul Lakkireddy 	if (rc)
2087c075ce2SRahul Lakkireddy 		return rc;
2097c075ce2SRahul Lakkireddy 
2107c075ce2SRahul Lakkireddy 	/* t4_read_cim_ibq will return no. of read words or error */
2117c075ce2SRahul Lakkireddy 	no_of_read_words = t4_read_cim_ibq(padap, qid,
212acfdf7eaSRahul Lakkireddy 					   (u32 *)temp_buff.data, qsize);
2137c075ce2SRahul Lakkireddy 	/* no_of_read_words is less than or equal to 0 means error */
2147c075ce2SRahul Lakkireddy 	if (no_of_read_words <= 0) {
2157c075ce2SRahul Lakkireddy 		if (!no_of_read_words)
2167c075ce2SRahul Lakkireddy 			rc = CUDBG_SYSTEM_ERROR;
2177c075ce2SRahul Lakkireddy 		else
2187c075ce2SRahul Lakkireddy 			rc = no_of_read_words;
2197c075ce2SRahul Lakkireddy 		cudbg_err->sys_err = rc;
2207c075ce2SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
2217c075ce2SRahul Lakkireddy 		return rc;
2227c075ce2SRahul Lakkireddy 	}
2237c075ce2SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
2247c075ce2SRahul Lakkireddy 	return rc;
2257c075ce2SRahul Lakkireddy }
2267c075ce2SRahul Lakkireddy 
2277c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
2287c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
2297c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
2307c075ce2SRahul Lakkireddy {
2317c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 0);
2327c075ce2SRahul Lakkireddy }
2337c075ce2SRahul Lakkireddy 
2347c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
2357c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
2367c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
2377c075ce2SRahul Lakkireddy {
2387c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 1);
2397c075ce2SRahul Lakkireddy }
2407c075ce2SRahul Lakkireddy 
2417c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
2427c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
2437c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
2447c075ce2SRahul Lakkireddy {
2457c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 2);
2467c075ce2SRahul Lakkireddy }
2477c075ce2SRahul Lakkireddy 
2487c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
2497c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
2507c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
2517c075ce2SRahul Lakkireddy {
2527c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 3);
2537c075ce2SRahul Lakkireddy }
2547c075ce2SRahul Lakkireddy 
2557c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
2567c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
2577c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
2587c075ce2SRahul Lakkireddy {
2597c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 4);
2607c075ce2SRahul Lakkireddy }
2617c075ce2SRahul Lakkireddy 
2627c075ce2SRahul Lakkireddy int cudbg_collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
2637c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
2647c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
2657c075ce2SRahul Lakkireddy {
2667c075ce2SRahul Lakkireddy 	return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 5);
2677c075ce2SRahul Lakkireddy }
2687c075ce2SRahul Lakkireddy 
269acfdf7eaSRahul Lakkireddy u32 cudbg_cim_obq_size(struct adapter *padap, int qid)
270acfdf7eaSRahul Lakkireddy {
271acfdf7eaSRahul Lakkireddy 	u32 value;
272acfdf7eaSRahul Lakkireddy 
273acfdf7eaSRahul Lakkireddy 	t4_write_reg(padap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
274acfdf7eaSRahul Lakkireddy 		     QUENUMSELECT_V(qid));
275acfdf7eaSRahul Lakkireddy 	value = t4_read_reg(padap, CIM_QUEUE_CONFIG_CTRL_A);
276acfdf7eaSRahul Lakkireddy 	value = CIMQSIZE_G(value) * 64; /* size in number of words */
277acfdf7eaSRahul Lakkireddy 	return value * sizeof(u32);
278acfdf7eaSRahul Lakkireddy }
279acfdf7eaSRahul Lakkireddy 
2807c075ce2SRahul Lakkireddy static int cudbg_read_cim_obq(struct cudbg_init *pdbg_init,
2817c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
2827c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err, int qid)
2837c075ce2SRahul Lakkireddy {
2847c075ce2SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
2857c075ce2SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
2867c075ce2SRahul Lakkireddy 	int no_of_read_words, rc = 0;
2877c075ce2SRahul Lakkireddy 	u32 qsize;
2887c075ce2SRahul Lakkireddy 
2897c075ce2SRahul Lakkireddy 	/* collect CIM OBQ */
290acfdf7eaSRahul Lakkireddy 	qsize =  cudbg_cim_obq_size(padap, qid);
2917c075ce2SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, qsize, &temp_buff);
2927c075ce2SRahul Lakkireddy 	if (rc)
2937c075ce2SRahul Lakkireddy 		return rc;
2947c075ce2SRahul Lakkireddy 
2957c075ce2SRahul Lakkireddy 	/* t4_read_cim_obq will return no. of read words or error */
2967c075ce2SRahul Lakkireddy 	no_of_read_words = t4_read_cim_obq(padap, qid,
297acfdf7eaSRahul Lakkireddy 					   (u32 *)temp_buff.data, qsize);
2987c075ce2SRahul Lakkireddy 	/* no_of_read_words is less than or equal to 0 means error */
2997c075ce2SRahul Lakkireddy 	if (no_of_read_words <= 0) {
3007c075ce2SRahul Lakkireddy 		if (!no_of_read_words)
3017c075ce2SRahul Lakkireddy 			rc = CUDBG_SYSTEM_ERROR;
3027c075ce2SRahul Lakkireddy 		else
3037c075ce2SRahul Lakkireddy 			rc = no_of_read_words;
3047c075ce2SRahul Lakkireddy 		cudbg_err->sys_err = rc;
3057c075ce2SRahul Lakkireddy 		cudbg_put_buff(&temp_buff, dbg_buff);
3067c075ce2SRahul Lakkireddy 		return rc;
3077c075ce2SRahul Lakkireddy 	}
3087c075ce2SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
3097c075ce2SRahul Lakkireddy 	return rc;
3107c075ce2SRahul Lakkireddy }
3117c075ce2SRahul Lakkireddy 
3127c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
3137c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
3147c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
3157c075ce2SRahul Lakkireddy {
3167c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 0);
3177c075ce2SRahul Lakkireddy }
3187c075ce2SRahul Lakkireddy 
3197c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
3207c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
3217c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
3227c075ce2SRahul Lakkireddy {
3237c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 1);
3247c075ce2SRahul Lakkireddy }
3257c075ce2SRahul Lakkireddy 
3267c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
3277c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
3287c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
3297c075ce2SRahul Lakkireddy {
3307c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 2);
3317c075ce2SRahul Lakkireddy }
3327c075ce2SRahul Lakkireddy 
3337c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
3347c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
3357c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
3367c075ce2SRahul Lakkireddy {
3377c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 3);
3387c075ce2SRahul Lakkireddy }
3397c075ce2SRahul Lakkireddy 
3407c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_sge(struct cudbg_init *pdbg_init,
3417c075ce2SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
3427c075ce2SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
3437c075ce2SRahul Lakkireddy {
3447c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 4);
3457c075ce2SRahul Lakkireddy }
3467c075ce2SRahul Lakkireddy 
3477c075ce2SRahul Lakkireddy int cudbg_collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
3487c075ce2SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
3497c075ce2SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
3507c075ce2SRahul Lakkireddy {
3517c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 5);
3527c075ce2SRahul Lakkireddy }
3537c075ce2SRahul Lakkireddy 
3547c075ce2SRahul Lakkireddy int cudbg_collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
3557c075ce2SRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
3567c075ce2SRahul Lakkireddy 				struct cudbg_error *cudbg_err)
3577c075ce2SRahul Lakkireddy {
3587c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 6);
3597c075ce2SRahul Lakkireddy }
3607c075ce2SRahul Lakkireddy 
3617c075ce2SRahul Lakkireddy int cudbg_collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
3627c075ce2SRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
3637c075ce2SRahul Lakkireddy 				struct cudbg_error *cudbg_err)
3647c075ce2SRahul Lakkireddy {
3657c075ce2SRahul Lakkireddy 	return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 7);
3667c075ce2SRahul Lakkireddy }
3677c075ce2SRahul Lakkireddy 
368b33af022SRahul Lakkireddy static int cudbg_read_fw_mem(struct cudbg_init *pdbg_init,
369b33af022SRahul Lakkireddy 			     struct cudbg_buffer *dbg_buff, u8 mem_type,
370b33af022SRahul Lakkireddy 			     unsigned long tot_len,
371b33af022SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
372b33af022SRahul Lakkireddy {
373b33af022SRahul Lakkireddy 	unsigned long bytes, bytes_left, bytes_read = 0;
374b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
375b33af022SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
376b33af022SRahul Lakkireddy 	int rc = 0;
377b33af022SRahul Lakkireddy 
378b33af022SRahul Lakkireddy 	bytes_left = tot_len;
379b33af022SRahul Lakkireddy 	while (bytes_left > 0) {
380b33af022SRahul Lakkireddy 		bytes = min_t(unsigned long, bytes_left,
381b33af022SRahul Lakkireddy 			      (unsigned long)CUDBG_CHUNK_SIZE);
382b33af022SRahul Lakkireddy 		rc = cudbg_get_buff(dbg_buff, bytes, &temp_buff);
383b33af022SRahul Lakkireddy 		if (rc)
384b33af022SRahul Lakkireddy 			return rc;
385b33af022SRahul Lakkireddy 		spin_lock(&padap->win0_lock);
386b33af022SRahul Lakkireddy 		rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type,
387b33af022SRahul Lakkireddy 				  bytes_read, bytes,
388b33af022SRahul Lakkireddy 				  (__be32 *)temp_buff.data,
389b33af022SRahul Lakkireddy 				  1);
390b33af022SRahul Lakkireddy 		spin_unlock(&padap->win0_lock);
391b33af022SRahul Lakkireddy 		if (rc) {
392b33af022SRahul Lakkireddy 			cudbg_err->sys_err = rc;
393b33af022SRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
394b33af022SRahul Lakkireddy 			return rc;
395b33af022SRahul Lakkireddy 		}
396b33af022SRahul Lakkireddy 		bytes_left -= bytes;
397b33af022SRahul Lakkireddy 		bytes_read += bytes;
398b33af022SRahul Lakkireddy 		cudbg_write_and_release_buff(&temp_buff, dbg_buff);
399b33af022SRahul Lakkireddy 	}
400b33af022SRahul Lakkireddy 	return rc;
401b33af022SRahul Lakkireddy }
402b33af022SRahul Lakkireddy 
403b33af022SRahul Lakkireddy static void cudbg_collect_mem_info(struct cudbg_init *pdbg_init,
404b33af022SRahul Lakkireddy 				   struct card_mem *mem_info)
405b33af022SRahul Lakkireddy {
406b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
407b33af022SRahul Lakkireddy 	u32 value;
408b33af022SRahul Lakkireddy 
409b33af022SRahul Lakkireddy 	value = t4_read_reg(padap, MA_EDRAM0_BAR_A);
410b33af022SRahul Lakkireddy 	value = EDRAM0_SIZE_G(value);
411b33af022SRahul Lakkireddy 	mem_info->size_edc0 = (u16)value;
412b33af022SRahul Lakkireddy 
413b33af022SRahul Lakkireddy 	value = t4_read_reg(padap, MA_EDRAM1_BAR_A);
414b33af022SRahul Lakkireddy 	value = EDRAM1_SIZE_G(value);
415b33af022SRahul Lakkireddy 	mem_info->size_edc1 = (u16)value;
416b33af022SRahul Lakkireddy 
417b33af022SRahul Lakkireddy 	value = t4_read_reg(padap, MA_TARGET_MEM_ENABLE_A);
418b33af022SRahul Lakkireddy 	if (value & EDRAM0_ENABLE_F)
419b33af022SRahul Lakkireddy 		mem_info->mem_flag |= (1 << EDC0_FLAG);
420b33af022SRahul Lakkireddy 	if (value & EDRAM1_ENABLE_F)
421b33af022SRahul Lakkireddy 		mem_info->mem_flag |= (1 << EDC1_FLAG);
422b33af022SRahul Lakkireddy }
423b33af022SRahul Lakkireddy 
424b33af022SRahul Lakkireddy static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
425b33af022SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
426b33af022SRahul Lakkireddy {
427b33af022SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
428b33af022SRahul Lakkireddy 	int rc;
429b33af022SRahul Lakkireddy 
430b33af022SRahul Lakkireddy 	if (is_fw_attached(pdbg_init)) {
431b33af022SRahul Lakkireddy 		/* Flush uP dcache before reading edcX/mcX  */
432b33af022SRahul Lakkireddy 		rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
433b33af022SRahul Lakkireddy 		if (rc)
434b33af022SRahul Lakkireddy 			cudbg_err->sys_warn = rc;
435b33af022SRahul Lakkireddy 	}
436b33af022SRahul Lakkireddy }
437b33af022SRahul Lakkireddy 
438b33af022SRahul Lakkireddy static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
439b33af022SRahul Lakkireddy 				    struct cudbg_buffer *dbg_buff,
440b33af022SRahul Lakkireddy 				    struct cudbg_error *cudbg_err,
441b33af022SRahul Lakkireddy 				    u8 mem_type)
442b33af022SRahul Lakkireddy {
443b33af022SRahul Lakkireddy 	struct card_mem mem_info = {0};
444b33af022SRahul Lakkireddy 	unsigned long flag, size;
445b33af022SRahul Lakkireddy 	int rc;
446b33af022SRahul Lakkireddy 
447b33af022SRahul Lakkireddy 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
448b33af022SRahul Lakkireddy 	cudbg_collect_mem_info(pdbg_init, &mem_info);
449b33af022SRahul Lakkireddy 	switch (mem_type) {
450b33af022SRahul Lakkireddy 	case MEM_EDC0:
451b33af022SRahul Lakkireddy 		flag = (1 << EDC0_FLAG);
452b33af022SRahul Lakkireddy 		size = cudbg_mbytes_to_bytes(mem_info.size_edc0);
453b33af022SRahul Lakkireddy 		break;
454b33af022SRahul Lakkireddy 	case MEM_EDC1:
455b33af022SRahul Lakkireddy 		flag = (1 << EDC1_FLAG);
456b33af022SRahul Lakkireddy 		size = cudbg_mbytes_to_bytes(mem_info.size_edc1);
457b33af022SRahul Lakkireddy 		break;
458b33af022SRahul Lakkireddy 	default:
459b33af022SRahul Lakkireddy 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
460b33af022SRahul Lakkireddy 		goto err;
461b33af022SRahul Lakkireddy 	}
462b33af022SRahul Lakkireddy 
463b33af022SRahul Lakkireddy 	if (mem_info.mem_flag & flag) {
464b33af022SRahul Lakkireddy 		rc = cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type,
465b33af022SRahul Lakkireddy 				       size, cudbg_err);
466b33af022SRahul Lakkireddy 		if (rc)
467b33af022SRahul Lakkireddy 			goto err;
468b33af022SRahul Lakkireddy 	} else {
469b33af022SRahul Lakkireddy 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
470b33af022SRahul Lakkireddy 		goto err;
471b33af022SRahul Lakkireddy 	}
472b33af022SRahul Lakkireddy err:
473b33af022SRahul Lakkireddy 	return rc;
474b33af022SRahul Lakkireddy }
475b33af022SRahul Lakkireddy 
476b33af022SRahul Lakkireddy int cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
477b33af022SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
478b33af022SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
479b33af022SRahul Lakkireddy {
480b33af022SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
481b33af022SRahul Lakkireddy 					MEM_EDC0);
482b33af022SRahul Lakkireddy }
483b33af022SRahul Lakkireddy 
484b33af022SRahul Lakkireddy int cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
485b33af022SRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
486b33af022SRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
487b33af022SRahul Lakkireddy {
488b33af022SRahul Lakkireddy 	return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
489b33af022SRahul Lakkireddy 					MEM_EDC1);
490b33af022SRahul Lakkireddy }
491844d1b6fSRahul Lakkireddy 
4924359cf33SRahul Lakkireddy int cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
4934359cf33SRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
4944359cf33SRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
4954359cf33SRahul Lakkireddy {
4964359cf33SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
4974359cf33SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
4984359cf33SRahul Lakkireddy 	struct ireg_buf *ch_tp_pio;
4994359cf33SRahul Lakkireddy 	int i, rc, n = 0;
5004359cf33SRahul Lakkireddy 	u32 size;
5014359cf33SRahul Lakkireddy 
5024359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
5034359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_pio_array) +
5044359cf33SRahul Lakkireddy 		    sizeof(t5_tp_tm_pio_array) +
5054359cf33SRahul Lakkireddy 		    sizeof(t5_tp_mib_index_array);
5064359cf33SRahul Lakkireddy 	else
5074359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_pio_array) +
5084359cf33SRahul Lakkireddy 		    sizeof(t6_tp_tm_pio_array) +
5094359cf33SRahul Lakkireddy 		    sizeof(t6_tp_mib_index_array);
5104359cf33SRahul Lakkireddy 
5114359cf33SRahul Lakkireddy 	n = n / (IREG_NUM_ELEM * sizeof(u32));
5124359cf33SRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
5134359cf33SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
5144359cf33SRahul Lakkireddy 	if (rc)
5154359cf33SRahul Lakkireddy 		return rc;
5164359cf33SRahul Lakkireddy 
5174359cf33SRahul Lakkireddy 	ch_tp_pio = (struct ireg_buf *)temp_buff.data;
5184359cf33SRahul Lakkireddy 
5194359cf33SRahul Lakkireddy 	/* TP_PIO */
5204359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
5214359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
5224359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
5234359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
5244359cf33SRahul Lakkireddy 
5254359cf33SRahul Lakkireddy 	for (i = 0; i < n; i++) {
5264359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
5274359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
5284359cf33SRahul Lakkireddy 
5294359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
5304359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_pio_array[i][0];
5314359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_pio_array[i][1];
5324359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
5334359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
5344359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
5354359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_pio_array[i][0];
5364359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_pio_array[i][1];
5374359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
5384359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
5394359cf33SRahul Lakkireddy 		}
5404359cf33SRahul Lakkireddy 		t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
5414359cf33SRahul Lakkireddy 			       tp_pio->ireg_local_offset, true);
5424359cf33SRahul Lakkireddy 		ch_tp_pio++;
5434359cf33SRahul Lakkireddy 	}
5444359cf33SRahul Lakkireddy 
5454359cf33SRahul Lakkireddy 	/* TP_TM_PIO */
5464359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
5474359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
5484359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
5494359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
5504359cf33SRahul Lakkireddy 
5514359cf33SRahul Lakkireddy 	for (i = 0; i < n; i++) {
5524359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
5534359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
5544359cf33SRahul Lakkireddy 
5554359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
5564359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
5574359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
5584359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
5594359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
5604359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
5614359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
5624359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
5634359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
5644359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
5654359cf33SRahul Lakkireddy 		}
5664359cf33SRahul Lakkireddy 		t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
5674359cf33SRahul Lakkireddy 				  tp_pio->ireg_local_offset, true);
5684359cf33SRahul Lakkireddy 		ch_tp_pio++;
5694359cf33SRahul Lakkireddy 	}
5704359cf33SRahul Lakkireddy 
5714359cf33SRahul Lakkireddy 	/* TP_MIB_INDEX */
5724359cf33SRahul Lakkireddy 	if (is_t5(padap->params.chip))
5734359cf33SRahul Lakkireddy 		n = sizeof(t5_tp_mib_index_array) /
5744359cf33SRahul Lakkireddy 		    (IREG_NUM_ELEM * sizeof(u32));
5754359cf33SRahul Lakkireddy 	else if (is_t6(padap->params.chip))
5764359cf33SRahul Lakkireddy 		n = sizeof(t6_tp_mib_index_array) /
5774359cf33SRahul Lakkireddy 		    (IREG_NUM_ELEM * sizeof(u32));
5784359cf33SRahul Lakkireddy 
5794359cf33SRahul Lakkireddy 	for (i = 0; i < n ; i++) {
5804359cf33SRahul Lakkireddy 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
5814359cf33SRahul Lakkireddy 		u32 *buff = ch_tp_pio->outbuf;
5824359cf33SRahul Lakkireddy 
5834359cf33SRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
5844359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
5854359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
5864359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset =
5874359cf33SRahul Lakkireddy 				t5_tp_mib_index_array[i][2];
5884359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range =
5894359cf33SRahul Lakkireddy 				t5_tp_mib_index_array[i][3];
5904359cf33SRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
5914359cf33SRahul Lakkireddy 			tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
5924359cf33SRahul Lakkireddy 			tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
5934359cf33SRahul Lakkireddy 			tp_pio->ireg_local_offset =
5944359cf33SRahul Lakkireddy 				t6_tp_mib_index_array[i][2];
5954359cf33SRahul Lakkireddy 			tp_pio->ireg_offset_range =
5964359cf33SRahul Lakkireddy 				t6_tp_mib_index_array[i][3];
5974359cf33SRahul Lakkireddy 		}
5984359cf33SRahul Lakkireddy 		t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
5994359cf33SRahul Lakkireddy 			       tp_pio->ireg_local_offset, true);
6004359cf33SRahul Lakkireddy 		ch_tp_pio++;
6014359cf33SRahul Lakkireddy 	}
6024359cf33SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
6034359cf33SRahul Lakkireddy 	return rc;
6044359cf33SRahul Lakkireddy }
6054359cf33SRahul Lakkireddy 
606270d39bfSRahul Lakkireddy int cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
607270d39bfSRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
608270d39bfSRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
609270d39bfSRahul Lakkireddy {
610270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
611270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
612270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_sge_dbg;
613270d39bfSRahul Lakkireddy 	int i, rc;
614270d39bfSRahul Lakkireddy 
615270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(*ch_sge_dbg) * 2, &temp_buff);
616270d39bfSRahul Lakkireddy 	if (rc)
617270d39bfSRahul Lakkireddy 		return rc;
618270d39bfSRahul Lakkireddy 
619270d39bfSRahul Lakkireddy 	ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
620270d39bfSRahul Lakkireddy 	for (i = 0; i < 2; i++) {
621270d39bfSRahul Lakkireddy 		struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
622270d39bfSRahul Lakkireddy 		u32 *buff = ch_sge_dbg->outbuf;
623270d39bfSRahul Lakkireddy 
624270d39bfSRahul Lakkireddy 		sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
625270d39bfSRahul Lakkireddy 		sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
626270d39bfSRahul Lakkireddy 		sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
627270d39bfSRahul Lakkireddy 		sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
628270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
629270d39bfSRahul Lakkireddy 				 sge_pio->ireg_addr,
630270d39bfSRahul Lakkireddy 				 sge_pio->ireg_data,
631270d39bfSRahul Lakkireddy 				 buff,
632270d39bfSRahul Lakkireddy 				 sge_pio->ireg_offset_range,
633270d39bfSRahul Lakkireddy 				 sge_pio->ireg_local_offset);
634270d39bfSRahul Lakkireddy 		ch_sge_dbg++;
635270d39bfSRahul Lakkireddy 	}
636270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
637270d39bfSRahul Lakkireddy 	return rc;
638270d39bfSRahul Lakkireddy }
639270d39bfSRahul Lakkireddy 
64027887bc7SRahul Lakkireddy int cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
64127887bc7SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
64227887bc7SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
64327887bc7SRahul Lakkireddy {
64427887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
64527887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
64627887bc7SRahul Lakkireddy 	struct cudbg_ulprx_la *ulprx_la_buff;
64727887bc7SRahul Lakkireddy 	int rc;
64827887bc7SRahul Lakkireddy 
64927887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_ulprx_la),
65027887bc7SRahul Lakkireddy 			    &temp_buff);
65127887bc7SRahul Lakkireddy 	if (rc)
65227887bc7SRahul Lakkireddy 		return rc;
65327887bc7SRahul Lakkireddy 
65427887bc7SRahul Lakkireddy 	ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
65527887bc7SRahul Lakkireddy 	t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
65627887bc7SRahul Lakkireddy 	ulprx_la_buff->size = ULPRX_LA_SIZE;
65727887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
65827887bc7SRahul Lakkireddy 	return rc;
65927887bc7SRahul Lakkireddy }
66027887bc7SRahul Lakkireddy 
66127887bc7SRahul Lakkireddy int cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
66227887bc7SRahul Lakkireddy 			struct cudbg_buffer *dbg_buff,
66327887bc7SRahul Lakkireddy 			struct cudbg_error *cudbg_err)
66427887bc7SRahul Lakkireddy {
66527887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
66627887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
66727887bc7SRahul Lakkireddy 	struct cudbg_tp_la *tp_la_buff;
66827887bc7SRahul Lakkireddy 	int size, rc;
66927887bc7SRahul Lakkireddy 
67027887bc7SRahul Lakkireddy 	size = sizeof(struct cudbg_tp_la) + TPLA_SIZE *  sizeof(u64);
67127887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
67227887bc7SRahul Lakkireddy 	if (rc)
67327887bc7SRahul Lakkireddy 		return rc;
67427887bc7SRahul Lakkireddy 
67527887bc7SRahul Lakkireddy 	tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
67627887bc7SRahul Lakkireddy 	tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
67727887bc7SRahul Lakkireddy 	t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
67827887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
67927887bc7SRahul Lakkireddy 	return rc;
68027887bc7SRahul Lakkireddy }
68127887bc7SRahul Lakkireddy 
68227887bc7SRahul Lakkireddy int cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
68327887bc7SRahul Lakkireddy 			     struct cudbg_buffer *dbg_buff,
68427887bc7SRahul Lakkireddy 			     struct cudbg_error *cudbg_err)
68527887bc7SRahul Lakkireddy {
68627887bc7SRahul Lakkireddy 	struct cudbg_cim_pif_la *cim_pif_la_buff;
68727887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
68827887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
68927887bc7SRahul Lakkireddy 	int size, rc;
69027887bc7SRahul Lakkireddy 
69127887bc7SRahul Lakkireddy 	size = sizeof(struct cudbg_cim_pif_la) +
69227887bc7SRahul Lakkireddy 	       2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
69327887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
69427887bc7SRahul Lakkireddy 	if (rc)
69527887bc7SRahul Lakkireddy 		return rc;
69627887bc7SRahul Lakkireddy 
69727887bc7SRahul Lakkireddy 	cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
69827887bc7SRahul Lakkireddy 	cim_pif_la_buff->size = CIM_PIFLA_SIZE;
69927887bc7SRahul Lakkireddy 	t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
70027887bc7SRahul Lakkireddy 			   (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
70127887bc7SRahul Lakkireddy 			   NULL, NULL);
70227887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
70327887bc7SRahul Lakkireddy 	return rc;
70427887bc7SRahul Lakkireddy }
70527887bc7SRahul Lakkireddy 
706270d39bfSRahul Lakkireddy int cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
707270d39bfSRahul Lakkireddy 				struct cudbg_buffer *dbg_buff,
708270d39bfSRahul Lakkireddy 				struct cudbg_error *cudbg_err)
709270d39bfSRahul Lakkireddy {
710270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
711270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
712270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_pcie;
713270d39bfSRahul Lakkireddy 	int i, rc, n;
714270d39bfSRahul Lakkireddy 	u32 size;
715270d39bfSRahul Lakkireddy 
716270d39bfSRahul Lakkireddy 	n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
717270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
718270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
719270d39bfSRahul Lakkireddy 	if (rc)
720270d39bfSRahul Lakkireddy 		return rc;
721270d39bfSRahul Lakkireddy 
722270d39bfSRahul Lakkireddy 	ch_pcie = (struct ireg_buf *)temp_buff.data;
723270d39bfSRahul Lakkireddy 	/* PCIE_PDBG */
724270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
725270d39bfSRahul Lakkireddy 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
726270d39bfSRahul Lakkireddy 		u32 *buff = ch_pcie->outbuf;
727270d39bfSRahul Lakkireddy 
728270d39bfSRahul Lakkireddy 		pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
729270d39bfSRahul Lakkireddy 		pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
730270d39bfSRahul Lakkireddy 		pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
731270d39bfSRahul Lakkireddy 		pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
732270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
733270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_addr,
734270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_data,
735270d39bfSRahul Lakkireddy 				 buff,
736270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_offset_range,
737270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_local_offset);
738270d39bfSRahul Lakkireddy 		ch_pcie++;
739270d39bfSRahul Lakkireddy 	}
740270d39bfSRahul Lakkireddy 
741270d39bfSRahul Lakkireddy 	/* PCIE_CDBG */
742270d39bfSRahul Lakkireddy 	n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
743270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
744270d39bfSRahul Lakkireddy 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
745270d39bfSRahul Lakkireddy 		u32 *buff = ch_pcie->outbuf;
746270d39bfSRahul Lakkireddy 
747270d39bfSRahul Lakkireddy 		pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
748270d39bfSRahul Lakkireddy 		pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
749270d39bfSRahul Lakkireddy 		pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
750270d39bfSRahul Lakkireddy 		pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
751270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
752270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_addr,
753270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_data,
754270d39bfSRahul Lakkireddy 				 buff,
755270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_offset_range,
756270d39bfSRahul Lakkireddy 				 pcie_pio->ireg_local_offset);
757270d39bfSRahul Lakkireddy 		ch_pcie++;
758270d39bfSRahul Lakkireddy 	}
759270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
760270d39bfSRahul Lakkireddy 	return rc;
761270d39bfSRahul Lakkireddy }
762270d39bfSRahul Lakkireddy 
763270d39bfSRahul Lakkireddy int cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
764270d39bfSRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
765270d39bfSRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
766270d39bfSRahul Lakkireddy {
767270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
768270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
769270d39bfSRahul Lakkireddy 	struct ireg_buf *ch_pm;
770270d39bfSRahul Lakkireddy 	int i, rc, n;
771270d39bfSRahul Lakkireddy 	u32 size;
772270d39bfSRahul Lakkireddy 
773270d39bfSRahul Lakkireddy 	n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
774270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
775270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
776270d39bfSRahul Lakkireddy 	if (rc)
777270d39bfSRahul Lakkireddy 		return rc;
778270d39bfSRahul Lakkireddy 
779270d39bfSRahul Lakkireddy 	ch_pm = (struct ireg_buf *)temp_buff.data;
780270d39bfSRahul Lakkireddy 	/* PM_RX */
781270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
782270d39bfSRahul Lakkireddy 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
783270d39bfSRahul Lakkireddy 		u32 *buff = ch_pm->outbuf;
784270d39bfSRahul Lakkireddy 
785270d39bfSRahul Lakkireddy 		pm_pio->ireg_addr = t5_pm_rx_array[i][0];
786270d39bfSRahul Lakkireddy 		pm_pio->ireg_data = t5_pm_rx_array[i][1];
787270d39bfSRahul Lakkireddy 		pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
788270d39bfSRahul Lakkireddy 		pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
789270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
790270d39bfSRahul Lakkireddy 				 pm_pio->ireg_addr,
791270d39bfSRahul Lakkireddy 				 pm_pio->ireg_data,
792270d39bfSRahul Lakkireddy 				 buff,
793270d39bfSRahul Lakkireddy 				 pm_pio->ireg_offset_range,
794270d39bfSRahul Lakkireddy 				 pm_pio->ireg_local_offset);
795270d39bfSRahul Lakkireddy 		ch_pm++;
796270d39bfSRahul Lakkireddy 	}
797270d39bfSRahul Lakkireddy 
798270d39bfSRahul Lakkireddy 	/* PM_TX */
799270d39bfSRahul Lakkireddy 	n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
800270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
801270d39bfSRahul Lakkireddy 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
802270d39bfSRahul Lakkireddy 		u32 *buff = ch_pm->outbuf;
803270d39bfSRahul Lakkireddy 
804270d39bfSRahul Lakkireddy 		pm_pio->ireg_addr = t5_pm_tx_array[i][0];
805270d39bfSRahul Lakkireddy 		pm_pio->ireg_data = t5_pm_tx_array[i][1];
806270d39bfSRahul Lakkireddy 		pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
807270d39bfSRahul Lakkireddy 		pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
808270d39bfSRahul Lakkireddy 		t4_read_indirect(padap,
809270d39bfSRahul Lakkireddy 				 pm_pio->ireg_addr,
810270d39bfSRahul Lakkireddy 				 pm_pio->ireg_data,
811270d39bfSRahul Lakkireddy 				 buff,
812270d39bfSRahul Lakkireddy 				 pm_pio->ireg_offset_range,
813270d39bfSRahul Lakkireddy 				 pm_pio->ireg_local_offset);
814270d39bfSRahul Lakkireddy 		ch_pm++;
815270d39bfSRahul Lakkireddy 	}
816270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
817270d39bfSRahul Lakkireddy 	return rc;
818270d39bfSRahul Lakkireddy }
819270d39bfSRahul Lakkireddy 
820270d39bfSRahul Lakkireddy int cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
821270d39bfSRahul Lakkireddy 			      struct cudbg_buffer *dbg_buff,
822270d39bfSRahul Lakkireddy 			      struct cudbg_error *cudbg_err)
823270d39bfSRahul Lakkireddy {
824270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
825270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
826270d39bfSRahul Lakkireddy 	struct ireg_buf *ma_indr;
827270d39bfSRahul Lakkireddy 	int i, rc, n;
828270d39bfSRahul Lakkireddy 	u32 size, j;
829270d39bfSRahul Lakkireddy 
830270d39bfSRahul Lakkireddy 	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
831270d39bfSRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
832270d39bfSRahul Lakkireddy 
833270d39bfSRahul Lakkireddy 	n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
834270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n * 2;
835270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
836270d39bfSRahul Lakkireddy 	if (rc)
837270d39bfSRahul Lakkireddy 		return rc;
838270d39bfSRahul Lakkireddy 
839270d39bfSRahul Lakkireddy 	ma_indr = (struct ireg_buf *)temp_buff.data;
840270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
841270d39bfSRahul Lakkireddy 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
842270d39bfSRahul Lakkireddy 		u32 *buff = ma_indr->outbuf;
843270d39bfSRahul Lakkireddy 
844270d39bfSRahul Lakkireddy 		ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
845270d39bfSRahul Lakkireddy 		ma_fli->ireg_data = t6_ma_ireg_array[i][1];
846270d39bfSRahul Lakkireddy 		ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
847270d39bfSRahul Lakkireddy 		ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
848270d39bfSRahul Lakkireddy 		t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
849270d39bfSRahul Lakkireddy 				 buff, ma_fli->ireg_offset_range,
850270d39bfSRahul Lakkireddy 				 ma_fli->ireg_local_offset);
851270d39bfSRahul Lakkireddy 		ma_indr++;
852270d39bfSRahul Lakkireddy 	}
853270d39bfSRahul Lakkireddy 
854270d39bfSRahul Lakkireddy 	n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
855270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
856270d39bfSRahul Lakkireddy 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
857270d39bfSRahul Lakkireddy 		u32 *buff = ma_indr->outbuf;
858270d39bfSRahul Lakkireddy 
859270d39bfSRahul Lakkireddy 		ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
860270d39bfSRahul Lakkireddy 		ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
861270d39bfSRahul Lakkireddy 		ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
862270d39bfSRahul Lakkireddy 		for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
863270d39bfSRahul Lakkireddy 			t4_read_indirect(padap, ma_fli->ireg_addr,
864270d39bfSRahul Lakkireddy 					 ma_fli->ireg_data, buff, 1,
865270d39bfSRahul Lakkireddy 					 ma_fli->ireg_local_offset);
866270d39bfSRahul Lakkireddy 			buff++;
867270d39bfSRahul Lakkireddy 			ma_fli->ireg_local_offset += 0x20;
868270d39bfSRahul Lakkireddy 		}
869270d39bfSRahul Lakkireddy 		ma_indr++;
870270d39bfSRahul Lakkireddy 	}
871270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
872270d39bfSRahul Lakkireddy 	return rc;
873270d39bfSRahul Lakkireddy }
874270d39bfSRahul Lakkireddy 
87527887bc7SRahul Lakkireddy int cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
87627887bc7SRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
87727887bc7SRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
87827887bc7SRahul Lakkireddy {
87927887bc7SRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
88027887bc7SRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
88127887bc7SRahul Lakkireddy 	struct cudbg_ulptx_la *ulptx_la_buff;
88227887bc7SRahul Lakkireddy 	u32 i, j;
88327887bc7SRahul Lakkireddy 	int rc;
88427887bc7SRahul Lakkireddy 
88527887bc7SRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, sizeof(struct cudbg_ulptx_la),
88627887bc7SRahul Lakkireddy 			    &temp_buff);
88727887bc7SRahul Lakkireddy 	if (rc)
88827887bc7SRahul Lakkireddy 		return rc;
88927887bc7SRahul Lakkireddy 
89027887bc7SRahul Lakkireddy 	ulptx_la_buff = (struct cudbg_ulptx_la *)temp_buff.data;
89127887bc7SRahul Lakkireddy 	for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
89227887bc7SRahul Lakkireddy 		ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
89327887bc7SRahul Lakkireddy 						      ULP_TX_LA_RDPTR_0_A +
89427887bc7SRahul Lakkireddy 						      0x10 * i);
89527887bc7SRahul Lakkireddy 		ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
89627887bc7SRahul Lakkireddy 						      ULP_TX_LA_WRPTR_0_A +
89727887bc7SRahul Lakkireddy 						      0x10 * i);
89827887bc7SRahul Lakkireddy 		ulptx_la_buff->rddata[i] = t4_read_reg(padap,
89927887bc7SRahul Lakkireddy 						       ULP_TX_LA_RDDATA_0_A +
90027887bc7SRahul Lakkireddy 						       0x10 * i);
90127887bc7SRahul Lakkireddy 		for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
90227887bc7SRahul Lakkireddy 			ulptx_la_buff->rd_data[i][j] =
90327887bc7SRahul Lakkireddy 				t4_read_reg(padap,
90427887bc7SRahul Lakkireddy 					    ULP_TX_LA_RDDATA_0_A + 0x10 * i);
90527887bc7SRahul Lakkireddy 	}
90627887bc7SRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
90727887bc7SRahul Lakkireddy 	return rc;
90827887bc7SRahul Lakkireddy }
90927887bc7SRahul Lakkireddy 
910270d39bfSRahul Lakkireddy int cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
911270d39bfSRahul Lakkireddy 				  struct cudbg_buffer *dbg_buff,
912270d39bfSRahul Lakkireddy 				  struct cudbg_error *cudbg_err)
913270d39bfSRahul Lakkireddy {
914270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
915270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
916270d39bfSRahul Lakkireddy 	struct ireg_buf *up_cim;
917270d39bfSRahul Lakkireddy 	int i, rc, n;
918270d39bfSRahul Lakkireddy 	u32 size;
919270d39bfSRahul Lakkireddy 
920270d39bfSRahul Lakkireddy 	n = sizeof(t5_up_cim_reg_array) / (IREG_NUM_ELEM * sizeof(u32));
921270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
922270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
923270d39bfSRahul Lakkireddy 	if (rc)
924270d39bfSRahul Lakkireddy 		return rc;
925270d39bfSRahul Lakkireddy 
926270d39bfSRahul Lakkireddy 	up_cim = (struct ireg_buf *)temp_buff.data;
927270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
928270d39bfSRahul Lakkireddy 		struct ireg_field *up_cim_reg = &up_cim->tp_pio;
929270d39bfSRahul Lakkireddy 		u32 *buff = up_cim->outbuf;
930270d39bfSRahul Lakkireddy 
931270d39bfSRahul Lakkireddy 		if (is_t5(padap->params.chip)) {
932270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
933270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
934270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_local_offset =
935270d39bfSRahul Lakkireddy 						t5_up_cim_reg_array[i][2];
936270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_offset_range =
937270d39bfSRahul Lakkireddy 						t5_up_cim_reg_array[i][3];
938270d39bfSRahul Lakkireddy 		} else if (is_t6(padap->params.chip)) {
939270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
940270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
941270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_local_offset =
942270d39bfSRahul Lakkireddy 						t6_up_cim_reg_array[i][2];
943270d39bfSRahul Lakkireddy 			up_cim_reg->ireg_offset_range =
944270d39bfSRahul Lakkireddy 						t6_up_cim_reg_array[i][3];
945270d39bfSRahul Lakkireddy 		}
946270d39bfSRahul Lakkireddy 
947270d39bfSRahul Lakkireddy 		rc = t4_cim_read(padap, up_cim_reg->ireg_local_offset,
948270d39bfSRahul Lakkireddy 				 up_cim_reg->ireg_offset_range, buff);
949270d39bfSRahul Lakkireddy 		if (rc) {
950270d39bfSRahul Lakkireddy 			cudbg_put_buff(&temp_buff, dbg_buff);
951270d39bfSRahul Lakkireddy 			return rc;
952270d39bfSRahul Lakkireddy 		}
953270d39bfSRahul Lakkireddy 		up_cim++;
954270d39bfSRahul Lakkireddy 	}
955270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
956270d39bfSRahul Lakkireddy 	return rc;
957270d39bfSRahul Lakkireddy }
958270d39bfSRahul Lakkireddy 
959844d1b6fSRahul Lakkireddy int cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
960844d1b6fSRahul Lakkireddy 			   struct cudbg_buffer *dbg_buff,
961844d1b6fSRahul Lakkireddy 			   struct cudbg_error *cudbg_err)
962844d1b6fSRahul Lakkireddy {
963844d1b6fSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
964844d1b6fSRahul Lakkireddy 	struct cudbg_mbox_log *mboxlog = NULL;
965844d1b6fSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
966844d1b6fSRahul Lakkireddy 	struct mbox_cmd_log *log = NULL;
967844d1b6fSRahul Lakkireddy 	struct mbox_cmd *entry;
968844d1b6fSRahul Lakkireddy 	unsigned int entry_idx;
969844d1b6fSRahul Lakkireddy 	u16 mbox_cmds;
970844d1b6fSRahul Lakkireddy 	int i, k, rc;
971844d1b6fSRahul Lakkireddy 	u64 flit;
972844d1b6fSRahul Lakkireddy 	u32 size;
973844d1b6fSRahul Lakkireddy 
974844d1b6fSRahul Lakkireddy 	log = padap->mbox_log;
975844d1b6fSRahul Lakkireddy 	mbox_cmds = padap->mbox_log->size;
976844d1b6fSRahul Lakkireddy 	size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
977844d1b6fSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
978844d1b6fSRahul Lakkireddy 	if (rc)
979844d1b6fSRahul Lakkireddy 		return rc;
980844d1b6fSRahul Lakkireddy 
981844d1b6fSRahul Lakkireddy 	mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
982844d1b6fSRahul Lakkireddy 	for (k = 0; k < mbox_cmds; k++) {
983844d1b6fSRahul Lakkireddy 		entry_idx = log->cursor + k;
984844d1b6fSRahul Lakkireddy 		if (entry_idx >= log->size)
985844d1b6fSRahul Lakkireddy 			entry_idx -= log->size;
986844d1b6fSRahul Lakkireddy 
987844d1b6fSRahul Lakkireddy 		entry = mbox_cmd_log_entry(log, entry_idx);
988844d1b6fSRahul Lakkireddy 		/* skip over unused entries */
989844d1b6fSRahul Lakkireddy 		if (entry->timestamp == 0)
990844d1b6fSRahul Lakkireddy 			continue;
991844d1b6fSRahul Lakkireddy 
992844d1b6fSRahul Lakkireddy 		memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
993844d1b6fSRahul Lakkireddy 		for (i = 0; i < MBOX_LEN / 8; i++) {
994844d1b6fSRahul Lakkireddy 			flit = entry->cmd[i];
995844d1b6fSRahul Lakkireddy 			mboxlog->hi[i] = (u32)(flit >> 32);
996844d1b6fSRahul Lakkireddy 			mboxlog->lo[i] = (u32)flit;
997844d1b6fSRahul Lakkireddy 		}
998844d1b6fSRahul Lakkireddy 		mboxlog++;
999844d1b6fSRahul Lakkireddy 	}
1000844d1b6fSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1001844d1b6fSRahul Lakkireddy 	return rc;
1002844d1b6fSRahul Lakkireddy }
1003270d39bfSRahul Lakkireddy 
1004270d39bfSRahul Lakkireddy int cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
1005270d39bfSRahul Lakkireddy 			       struct cudbg_buffer *dbg_buff,
1006270d39bfSRahul Lakkireddy 			       struct cudbg_error *cudbg_err)
1007270d39bfSRahul Lakkireddy {
1008270d39bfSRahul Lakkireddy 	struct adapter *padap = pdbg_init->adap;
1009270d39bfSRahul Lakkireddy 	struct cudbg_buffer temp_buff = { 0 };
1010270d39bfSRahul Lakkireddy 	struct ireg_buf *hma_indr;
1011270d39bfSRahul Lakkireddy 	int i, rc, n;
1012270d39bfSRahul Lakkireddy 	u32 size;
1013270d39bfSRahul Lakkireddy 
1014270d39bfSRahul Lakkireddy 	if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
1015270d39bfSRahul Lakkireddy 		return CUDBG_STATUS_ENTITY_NOT_FOUND;
1016270d39bfSRahul Lakkireddy 
1017270d39bfSRahul Lakkireddy 	n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
1018270d39bfSRahul Lakkireddy 	size = sizeof(struct ireg_buf) * n;
1019270d39bfSRahul Lakkireddy 	rc = cudbg_get_buff(dbg_buff, size, &temp_buff);
1020270d39bfSRahul Lakkireddy 	if (rc)
1021270d39bfSRahul Lakkireddy 		return rc;
1022270d39bfSRahul Lakkireddy 
1023270d39bfSRahul Lakkireddy 	hma_indr = (struct ireg_buf *)temp_buff.data;
1024270d39bfSRahul Lakkireddy 	for (i = 0; i < n; i++) {
1025270d39bfSRahul Lakkireddy 		struct ireg_field *hma_fli = &hma_indr->tp_pio;
1026270d39bfSRahul Lakkireddy 		u32 *buff = hma_indr->outbuf;
1027270d39bfSRahul Lakkireddy 
1028270d39bfSRahul Lakkireddy 		hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
1029270d39bfSRahul Lakkireddy 		hma_fli->ireg_data = t6_hma_ireg_array[i][1];
1030270d39bfSRahul Lakkireddy 		hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
1031270d39bfSRahul Lakkireddy 		hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
1032270d39bfSRahul Lakkireddy 		t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
1033270d39bfSRahul Lakkireddy 				 buff, hma_fli->ireg_offset_range,
1034270d39bfSRahul Lakkireddy 				 hma_fli->ireg_local_offset);
1035270d39bfSRahul Lakkireddy 		hma_indr++;
1036270d39bfSRahul Lakkireddy 	}
1037270d39bfSRahul Lakkireddy 	cudbg_write_and_release_buff(&temp_buff, dbg_buff);
1038270d39bfSRahul Lakkireddy 	return rc;
1039270d39bfSRahul Lakkireddy }
1040