xref: /freebsd/sys/dev/cxgbe/cudbg/cudbg_lib.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1f856f099SNavdeep Parhar /*-
2f856f099SNavdeep Parhar  * Copyright (c) 2017 Chelsio Communications, Inc.
3f856f099SNavdeep Parhar  * All rights reserved.
4f856f099SNavdeep Parhar  *
5f856f099SNavdeep Parhar  * Redistribution and use in source and binary forms, with or without
6f856f099SNavdeep Parhar  * modification, are permitted provided that the following conditions
7f856f099SNavdeep Parhar  * are met:
8f856f099SNavdeep Parhar  * 1. Redistributions of source code must retain the above copyright
9f856f099SNavdeep Parhar  *    notice, this list of conditions and the following disclaimer.
10f856f099SNavdeep Parhar  * 2. Redistributions in binary form must reproduce the above copyright
11f856f099SNavdeep Parhar  *    notice, this list of conditions and the following disclaimer in the
12f856f099SNavdeep Parhar  *    documentation and/or other materials provided with the distribution.
13f856f099SNavdeep Parhar  *
14f856f099SNavdeep Parhar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15f856f099SNavdeep Parhar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16f856f099SNavdeep Parhar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17f856f099SNavdeep Parhar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18f856f099SNavdeep Parhar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19f856f099SNavdeep Parhar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20f856f099SNavdeep Parhar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21f856f099SNavdeep Parhar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22f856f099SNavdeep Parhar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23f856f099SNavdeep Parhar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24f856f099SNavdeep Parhar  * SUCH DAMAGE.
25f856f099SNavdeep Parhar  */
26f856f099SNavdeep Parhar 
27f856f099SNavdeep Parhar #include <sys/types.h>
28f856f099SNavdeep Parhar #include <sys/param.h>
29f856f099SNavdeep Parhar 
30f856f099SNavdeep Parhar #include "common/common.h"
31f856f099SNavdeep Parhar #include "common/t4_regs.h"
32f856f099SNavdeep Parhar #include "cudbg.h"
33f856f099SNavdeep Parhar #include "cudbg_lib_common.h"
34f856f099SNavdeep Parhar #include "cudbg_lib.h"
35f856f099SNavdeep Parhar #include "cudbg_entity.h"
36f856f099SNavdeep Parhar #define  BUFFER_WARN_LIMIT 10000000
37f856f099SNavdeep Parhar 
38f856f099SNavdeep Parhar struct large_entity large_entity_list[] = {
39f856f099SNavdeep Parhar 	{CUDBG_EDC0, 0, 0},
40f856f099SNavdeep Parhar 	{CUDBG_EDC1, 0 , 0},
41f856f099SNavdeep Parhar 	{CUDBG_MC0, 0, 0},
42f856f099SNavdeep Parhar 	{CUDBG_MC1, 0, 0}
43f856f099SNavdeep Parhar };
44f856f099SNavdeep Parhar 
is_fw_attached(struct cudbg_init * pdbg_init)45f856f099SNavdeep Parhar static int is_fw_attached(struct cudbg_init *pdbg_init)
46f856f099SNavdeep Parhar {
47f856f099SNavdeep Parhar 
48f856f099SNavdeep Parhar 	return (pdbg_init->adap->flags & FW_OK);
49f856f099SNavdeep Parhar }
50f856f099SNavdeep Parhar 
51f856f099SNavdeep Parhar /* This function will add additional padding bytes into debug_buffer to make it
52f856f099SNavdeep Parhar  * 4 byte aligned.*/
align_debug_buffer(struct cudbg_buffer * dbg_buff,struct cudbg_entity_hdr * entity_hdr)53f856f099SNavdeep Parhar static void align_debug_buffer(struct cudbg_buffer *dbg_buff,
54f856f099SNavdeep Parhar 			struct cudbg_entity_hdr *entity_hdr)
55f856f099SNavdeep Parhar {
56f856f099SNavdeep Parhar 	u8 zero_buf[4] = {0};
57f856f099SNavdeep Parhar 	u8 padding, remain;
58f856f099SNavdeep Parhar 
59f856f099SNavdeep Parhar 	remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
60f856f099SNavdeep Parhar 	padding = 4 - remain;
61f856f099SNavdeep Parhar 	if (remain) {
62f856f099SNavdeep Parhar 		memcpy(((u8 *) dbg_buff->data) + dbg_buff->offset, &zero_buf,
63f856f099SNavdeep Parhar 		       padding);
64f856f099SNavdeep Parhar 		dbg_buff->offset += padding;
65f856f099SNavdeep Parhar 		entity_hdr->num_pad = padding;
66f856f099SNavdeep Parhar 	}
67f856f099SNavdeep Parhar 
68f856f099SNavdeep Parhar 	entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
69f856f099SNavdeep Parhar }
70f856f099SNavdeep Parhar 
read_sge_ctxt(struct cudbg_init * pdbg_init,u32 cid,enum ctxt_type ctype,u32 * data)71f856f099SNavdeep Parhar static void read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
72f856f099SNavdeep Parhar 			  enum ctxt_type ctype, u32 *data)
73f856f099SNavdeep Parhar {
74f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
75f856f099SNavdeep Parhar 	int rc = -1;
76f856f099SNavdeep Parhar 
778ee789e9SNavdeep Parhar 	if (is_fw_attached(pdbg_init)) {
788ee789e9SNavdeep Parhar 		rc = begin_synchronized_op(padap, NULL, SLEEP_OK | INTR_OK,
798ee789e9SNavdeep Parhar 		    "t4cudf");
808ee789e9SNavdeep Parhar 		if (rc != 0)
818ee789e9SNavdeep Parhar 			goto out;
82f856f099SNavdeep Parhar 		rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype,
83f856f099SNavdeep Parhar 				    data);
848ee789e9SNavdeep Parhar 		end_synchronized_op(padap, 0);
858ee789e9SNavdeep Parhar 	}
86f856f099SNavdeep Parhar 
878ee789e9SNavdeep Parhar out:
88f856f099SNavdeep Parhar 	if (rc)
89f856f099SNavdeep Parhar 		t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
90f856f099SNavdeep Parhar }
91f856f099SNavdeep Parhar 
get_next_ext_entity_hdr(void * outbuf,u32 * ext_size,struct cudbg_buffer * dbg_buff,struct cudbg_entity_hdr ** entity_hdr)92f856f099SNavdeep Parhar static int get_next_ext_entity_hdr(void *outbuf, u32 *ext_size,
93f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
94f856f099SNavdeep Parhar 			    struct cudbg_entity_hdr **entity_hdr)
95f856f099SNavdeep Parhar {
96f856f099SNavdeep Parhar 	struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
97f856f099SNavdeep Parhar 	int rc = 0;
98f856f099SNavdeep Parhar 	u32 ext_offset = cudbg_hdr->data_len;
99f856f099SNavdeep Parhar 	*ext_size = 0;
100f856f099SNavdeep Parhar 
101f856f099SNavdeep Parhar 	if (dbg_buff->size - dbg_buff->offset <=
102f856f099SNavdeep Parhar 		 sizeof(struct cudbg_entity_hdr)) {
103f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_BUFFER_SHORT;
104f856f099SNavdeep Parhar 		goto err;
105f856f099SNavdeep Parhar 	}
106f856f099SNavdeep Parhar 
107f856f099SNavdeep Parhar 	*entity_hdr = (struct cudbg_entity_hdr *)
108f856f099SNavdeep Parhar 		       ((char *)outbuf + cudbg_hdr->data_len);
109f856f099SNavdeep Parhar 
110f856f099SNavdeep Parhar 	/* Find the last extended entity header */
111f856f099SNavdeep Parhar 	while ((*entity_hdr)->size) {
112f856f099SNavdeep Parhar 
113f856f099SNavdeep Parhar 		ext_offset += sizeof(struct cudbg_entity_hdr) +
114f856f099SNavdeep Parhar 				     (*entity_hdr)->size;
115f856f099SNavdeep Parhar 
116f856f099SNavdeep Parhar 		*ext_size += (*entity_hdr)->size +
117f856f099SNavdeep Parhar 			      sizeof(struct cudbg_entity_hdr);
118f856f099SNavdeep Parhar 
119f856f099SNavdeep Parhar 		if (dbg_buff->size - dbg_buff->offset + *ext_size  <=
120f856f099SNavdeep Parhar 			sizeof(struct cudbg_entity_hdr)) {
121f856f099SNavdeep Parhar 			rc = CUDBG_STATUS_BUFFER_SHORT;
122f856f099SNavdeep Parhar 			goto err;
123f856f099SNavdeep Parhar 		}
124f856f099SNavdeep Parhar 
125f856f099SNavdeep Parhar 		if (ext_offset != (*entity_hdr)->next_ext_offset) {
126f856f099SNavdeep Parhar 			ext_offset -= sizeof(struct cudbg_entity_hdr) +
127f856f099SNavdeep Parhar 				     (*entity_hdr)->size;
128f856f099SNavdeep Parhar 			break;
129f856f099SNavdeep Parhar 		}
130f856f099SNavdeep Parhar 
131f856f099SNavdeep Parhar 		(*entity_hdr)->next_ext_offset = *ext_size;
132f856f099SNavdeep Parhar 
133f856f099SNavdeep Parhar 		*entity_hdr = (struct cudbg_entity_hdr *)
134f856f099SNavdeep Parhar 					   ((char *)outbuf +
135f856f099SNavdeep Parhar 					   ext_offset);
136f856f099SNavdeep Parhar 	}
137f856f099SNavdeep Parhar 
138f856f099SNavdeep Parhar 	/* update the data offset */
139f856f099SNavdeep Parhar 	dbg_buff->offset = ext_offset;
140f856f099SNavdeep Parhar err:
141f856f099SNavdeep Parhar 	return rc;
142f856f099SNavdeep Parhar }
143f856f099SNavdeep Parhar 
wr_entity_to_flash(void * handle,struct cudbg_buffer * dbg_buff,u32 cur_entity_data_offset,u32 cur_entity_size,int entity_nu,u32 ext_size)144f856f099SNavdeep Parhar static int wr_entity_to_flash(void *handle, struct cudbg_buffer *dbg_buff,
145f856f099SNavdeep Parhar 		       u32 cur_entity_data_offset,
146f856f099SNavdeep Parhar 		       u32 cur_entity_size,
147f856f099SNavdeep Parhar 		       int entity_nu, u32 ext_size)
148f856f099SNavdeep Parhar {
149f856f099SNavdeep Parhar 	struct cudbg_private *priv = handle;
150f856f099SNavdeep Parhar 	struct cudbg_init *cudbg_init = &priv->dbg_init;
151f856f099SNavdeep Parhar 	struct cudbg_flash_sec_info *sec_info = &priv->sec_info;
152f856f099SNavdeep Parhar 	u64 timestamp;
153f856f099SNavdeep Parhar 	u32 cur_entity_hdr_offset = sizeof(struct cudbg_hdr);
154f856f099SNavdeep Parhar 	u32 remain_flash_size;
155f856f099SNavdeep Parhar 	u32 flash_data_offset;
156f856f099SNavdeep Parhar 	u32 data_hdr_size;
157f856f099SNavdeep Parhar 	int rc = -1;
158f856f099SNavdeep Parhar 
159f856f099SNavdeep Parhar 	data_hdr_size = CUDBG_MAX_ENTITY * sizeof(struct cudbg_entity_hdr) +
160f856f099SNavdeep Parhar 			sizeof(struct cudbg_hdr);
161f856f099SNavdeep Parhar 
162f856f099SNavdeep Parhar 	flash_data_offset = (FLASH_CUDBG_NSECS *
163f856f099SNavdeep Parhar 			     (sizeof(struct cudbg_flash_hdr) +
164f856f099SNavdeep Parhar 			      data_hdr_size)) +
165f856f099SNavdeep Parhar 			    (cur_entity_data_offset - data_hdr_size);
166f856f099SNavdeep Parhar 
167f856f099SNavdeep Parhar 	if (flash_data_offset > CUDBG_FLASH_SIZE) {
168f856f099SNavdeep Parhar 		update_skip_size(sec_info, cur_entity_size);
169f856f099SNavdeep Parhar 		if (cudbg_init->verbose)
170f856f099SNavdeep Parhar 			cudbg_init->print("Large entity skipping...\n");
171f856f099SNavdeep Parhar 		return rc;
172f856f099SNavdeep Parhar 	}
173f856f099SNavdeep Parhar 
174f856f099SNavdeep Parhar 	remain_flash_size = CUDBG_FLASH_SIZE - flash_data_offset;
175f856f099SNavdeep Parhar 
176f856f099SNavdeep Parhar 	if (cur_entity_size > remain_flash_size) {
177f856f099SNavdeep Parhar 		update_skip_size(sec_info, cur_entity_size);
178f856f099SNavdeep Parhar 		if (cudbg_init->verbose)
179f856f099SNavdeep Parhar 			cudbg_init->print("Large entity skipping...\n");
180f856f099SNavdeep Parhar 	} else {
181f856f099SNavdeep Parhar 		timestamp = 0;
182f856f099SNavdeep Parhar 
183f856f099SNavdeep Parhar 		cur_entity_hdr_offset +=
184f856f099SNavdeep Parhar 			(sizeof(struct cudbg_entity_hdr) *
185f856f099SNavdeep Parhar 			(entity_nu - 1));
186f856f099SNavdeep Parhar 
187f856f099SNavdeep Parhar 		rc = cudbg_write_flash(handle, timestamp, dbg_buff,
188f856f099SNavdeep Parhar 				       cur_entity_data_offset,
189f856f099SNavdeep Parhar 				       cur_entity_hdr_offset,
190f856f099SNavdeep Parhar 				       cur_entity_size,
191f856f099SNavdeep Parhar 				       ext_size);
192f856f099SNavdeep Parhar 		if (rc == CUDBG_STATUS_FLASH_FULL && cudbg_init->verbose)
193f856f099SNavdeep Parhar 			cudbg_init->print("\n\tFLASH is full... "
194f856f099SNavdeep Parhar 				"can not write in flash more\n\n");
195f856f099SNavdeep Parhar 	}
196f856f099SNavdeep Parhar 
197f856f099SNavdeep Parhar 	return rc;
198f856f099SNavdeep Parhar }
199f856f099SNavdeep Parhar 
cudbg_collect(void * handle,void * outbuf,u32 * outbuf_size)200f856f099SNavdeep Parhar int cudbg_collect(void *handle, void *outbuf, u32 *outbuf_size)
201f856f099SNavdeep Parhar {
202f856f099SNavdeep Parhar 	struct cudbg_entity_hdr *entity_hdr = NULL;
203f856f099SNavdeep Parhar 	struct cudbg_entity_hdr *ext_entity_hdr = NULL;
204f856f099SNavdeep Parhar 	struct cudbg_hdr *cudbg_hdr;
205f856f099SNavdeep Parhar 	struct cudbg_buffer dbg_buff;
206f856f099SNavdeep Parhar 	struct cudbg_error cudbg_err = {0};
207f856f099SNavdeep Parhar 	int large_entity_code;
208f856f099SNavdeep Parhar 
209f856f099SNavdeep Parhar 	u8 *dbg_bitmap = ((struct cudbg_private *)handle)->dbg_init.dbg_bitmap;
210f856f099SNavdeep Parhar 	struct cudbg_init *cudbg_init =
211f856f099SNavdeep Parhar 		&(((struct cudbg_private *)handle)->dbg_init);
212f856f099SNavdeep Parhar 	struct adapter *padap = cudbg_init->adap;
213f856f099SNavdeep Parhar 	u32 total_size, remaining_buf_size;
214f856f099SNavdeep Parhar 	u32 ext_size = 0;
215f856f099SNavdeep Parhar 	int index, bit, i, rc = -1;
216f856f099SNavdeep Parhar 	int all;
217f856f099SNavdeep Parhar 	bool flag_ext = 0;
218f856f099SNavdeep Parhar 
219f856f099SNavdeep Parhar 	reset_skip_entity();
220f856f099SNavdeep Parhar 
221f856f099SNavdeep Parhar 	dbg_buff.data = outbuf;
222f856f099SNavdeep Parhar 	dbg_buff.size = *outbuf_size;
223f856f099SNavdeep Parhar 	dbg_buff.offset = 0;
224f856f099SNavdeep Parhar 
225f856f099SNavdeep Parhar 	cudbg_hdr = (struct cudbg_hdr *)dbg_buff.data;
226f856f099SNavdeep Parhar 	cudbg_hdr->signature = CUDBG_SIGNATURE;
227f856f099SNavdeep Parhar 	cudbg_hdr->hdr_len = sizeof(struct cudbg_hdr);
228f856f099SNavdeep Parhar 	cudbg_hdr->major_ver = CUDBG_MAJOR_VERSION;
229f856f099SNavdeep Parhar 	cudbg_hdr->minor_ver = CUDBG_MINOR_VERSION;
230f856f099SNavdeep Parhar 	cudbg_hdr->max_entities = CUDBG_MAX_ENTITY;
231f856f099SNavdeep Parhar 	cudbg_hdr->chip_ver = padap->params.chipid;
232f856f099SNavdeep Parhar 
233f856f099SNavdeep Parhar 	if (cudbg_hdr->data_len)
234f856f099SNavdeep Parhar 		flag_ext = 1;
235f856f099SNavdeep Parhar 
236f856f099SNavdeep Parhar 	if (cudbg_init->use_flash) {
237f856f099SNavdeep Parhar #ifndef notyet
238f856f099SNavdeep Parhar 		rc = t4_get_flash_params(padap);
239f856f099SNavdeep Parhar 		if (rc) {
240f856f099SNavdeep Parhar 			if (cudbg_init->verbose)
241f856f099SNavdeep Parhar 				cudbg_init->print("\nGet flash params failed.\n\n");
242f856f099SNavdeep Parhar 			cudbg_init->use_flash = 0;
243f856f099SNavdeep Parhar 		}
244f856f099SNavdeep Parhar #endif
245f856f099SNavdeep Parhar 
246f856f099SNavdeep Parhar #ifdef notyet
247f856f099SNavdeep Parhar 		/* Timestamp is mandatory. If it is not passed then disable
248f856f099SNavdeep Parhar 		 * flash support
249f856f099SNavdeep Parhar 		 */
250f856f099SNavdeep Parhar 		if (!cudbg_init->dbg_params[CUDBG_TIMESTAMP_PARAM].u.time) {
251f856f099SNavdeep Parhar 			if (cudbg_init->verbose)
252f856f099SNavdeep Parhar 				cudbg_init->print("\nTimestamp param missing,"
253f856f099SNavdeep Parhar 					  "so ignoring flash write request\n\n");
254f856f099SNavdeep Parhar 			cudbg_init->use_flash = 0;
255f856f099SNavdeep Parhar 		}
256f856f099SNavdeep Parhar #endif
257f856f099SNavdeep Parhar 	}
258f856f099SNavdeep Parhar 
259f856f099SNavdeep Parhar 	if (sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY >
260f856f099SNavdeep Parhar 	    dbg_buff.size) {
261f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_SMALL_BUFF;
262f856f099SNavdeep Parhar 		total_size = cudbg_hdr->hdr_len;
263f856f099SNavdeep Parhar 		goto err;
264f856f099SNavdeep Parhar 	}
265f856f099SNavdeep Parhar 
266f856f099SNavdeep Parhar 	/* If ext flag is set then move the offset to the end of the buf
267f856f099SNavdeep Parhar 	 * so that we can add ext entities
268f856f099SNavdeep Parhar 	 */
269f856f099SNavdeep Parhar 	if (flag_ext) {
270f856f099SNavdeep Parhar 		ext_entity_hdr = (struct cudbg_entity_hdr *)
271f856f099SNavdeep Parhar 			      ((char *)outbuf + cudbg_hdr->hdr_len +
272f856f099SNavdeep Parhar 			      (sizeof(struct cudbg_entity_hdr) *
273f856f099SNavdeep Parhar 			      (CUDBG_EXT_ENTITY - 1)));
274f856f099SNavdeep Parhar 		ext_entity_hdr->start_offset = cudbg_hdr->data_len;
275f856f099SNavdeep Parhar 		ext_entity_hdr->entity_type = CUDBG_EXT_ENTITY;
276f856f099SNavdeep Parhar 		ext_entity_hdr->size = 0;
277f856f099SNavdeep Parhar 		dbg_buff.offset = cudbg_hdr->data_len;
278f856f099SNavdeep Parhar 	} else {
279f856f099SNavdeep Parhar 		dbg_buff.offset += cudbg_hdr->hdr_len; /* move 24 bytes*/
280f856f099SNavdeep Parhar 		dbg_buff.offset += CUDBG_MAX_ENTITY *
281f856f099SNavdeep Parhar 					sizeof(struct cudbg_entity_hdr);
282f856f099SNavdeep Parhar 	}
283f856f099SNavdeep Parhar 
284f856f099SNavdeep Parhar 	total_size = dbg_buff.offset;
285f856f099SNavdeep Parhar 	all = dbg_bitmap[0] & (1 << CUDBG_ALL);
286f856f099SNavdeep Parhar 
287f856f099SNavdeep Parhar 	/*sort(large_entity_list);*/
288f856f099SNavdeep Parhar 
289f856f099SNavdeep Parhar 	for (i = 1; i < CUDBG_MAX_ENTITY; i++) {
290f856f099SNavdeep Parhar 		index = i / 8;
291f856f099SNavdeep Parhar 		bit = i % 8;
292f856f099SNavdeep Parhar 
293f856f099SNavdeep Parhar 		if (entity_list[i].bit == CUDBG_EXT_ENTITY)
294f856f099SNavdeep Parhar 			continue;
295f856f099SNavdeep Parhar 
296f856f099SNavdeep Parhar 		if (all || (dbg_bitmap[index] & (1 << bit))) {
297f856f099SNavdeep Parhar 
298f856f099SNavdeep Parhar 			if (!flag_ext) {
299f856f099SNavdeep Parhar 				rc = get_entity_hdr(outbuf, i, dbg_buff.size,
300f856f099SNavdeep Parhar 						    &entity_hdr);
301f856f099SNavdeep Parhar 				if (rc)
302f856f099SNavdeep Parhar 					cudbg_hdr->hdr_flags = rc;
303f856f099SNavdeep Parhar 			} else {
304f856f099SNavdeep Parhar 				rc = get_next_ext_entity_hdr(outbuf, &ext_size,
305f856f099SNavdeep Parhar 							     &dbg_buff,
306f856f099SNavdeep Parhar 							     &entity_hdr);
307f856f099SNavdeep Parhar 				if (rc)
308f856f099SNavdeep Parhar 					goto err;
309f856f099SNavdeep Parhar 
310f856f099SNavdeep Parhar 				/* move the offset after the ext header */
311f856f099SNavdeep Parhar 				dbg_buff.offset +=
312f856f099SNavdeep Parhar 					sizeof(struct cudbg_entity_hdr);
313f856f099SNavdeep Parhar 			}
314f856f099SNavdeep Parhar 
315f856f099SNavdeep Parhar 			entity_hdr->entity_type = i;
316f856f099SNavdeep Parhar 			entity_hdr->start_offset = dbg_buff.offset;
317f856f099SNavdeep Parhar 			/* process each entity by calling process_entity fp */
318f856f099SNavdeep Parhar 			remaining_buf_size = dbg_buff.size - dbg_buff.offset;
319f856f099SNavdeep Parhar 
320f856f099SNavdeep Parhar 			if ((remaining_buf_size <= BUFFER_WARN_LIMIT) &&
321f856f099SNavdeep Parhar 			    is_large_entity(i)) {
322f856f099SNavdeep Parhar 				if (cudbg_init->verbose)
323f856f099SNavdeep Parhar 					cudbg_init->print("Skipping %s\n",
324f856f099SNavdeep Parhar 					    entity_list[i].name);
325f856f099SNavdeep Parhar 				skip_entity(i);
326f856f099SNavdeep Parhar 				continue;
327f856f099SNavdeep Parhar 			} else {
328f856f099SNavdeep Parhar 
329f856f099SNavdeep Parhar 				/* If fw_attach is 0, then skip entities which
330f856f099SNavdeep Parhar 				 * communicates with firmware
331f856f099SNavdeep Parhar 				 */
332f856f099SNavdeep Parhar 
333f856f099SNavdeep Parhar 				if (!is_fw_attached(cudbg_init) &&
334f856f099SNavdeep Parhar 				    (entity_list[i].flag &
335f856f099SNavdeep Parhar 				    (1 << ENTITY_FLAG_FW_NO_ATTACH))) {
336f856f099SNavdeep Parhar 					if (cudbg_init->verbose)
337f856f099SNavdeep Parhar 						cudbg_init->print("Skipping %s entity,"\
338f856f099SNavdeep Parhar 							  "because fw_attach "\
339f856f099SNavdeep Parhar 							  "is 0\n",
340f856f099SNavdeep Parhar 							  entity_list[i].name);
341f856f099SNavdeep Parhar 					continue;
342f856f099SNavdeep Parhar 				}
343f856f099SNavdeep Parhar 
344f856f099SNavdeep Parhar 				if (cudbg_init->verbose)
345f856f099SNavdeep Parhar 					cudbg_init->print("collecting debug entity: "\
346f856f099SNavdeep Parhar 						  "%s\n", entity_list[i].name);
347f856f099SNavdeep Parhar 				memset(&cudbg_err, 0,
348f856f099SNavdeep Parhar 				       sizeof(struct cudbg_error));
349f856f099SNavdeep Parhar 				rc = process_entity[i-1](cudbg_init, &dbg_buff,
350f856f099SNavdeep Parhar 							 &cudbg_err);
351f856f099SNavdeep Parhar 			}
352f856f099SNavdeep Parhar 
353f856f099SNavdeep Parhar 			if (rc) {
354f856f099SNavdeep Parhar 				entity_hdr->size = 0;
355f856f099SNavdeep Parhar 				dbg_buff.offset = entity_hdr->start_offset;
356f856f099SNavdeep Parhar 			} else
357f856f099SNavdeep Parhar 				align_debug_buffer(&dbg_buff, entity_hdr);
358f856f099SNavdeep Parhar 
359f856f099SNavdeep Parhar 			if (cudbg_err.sys_err)
360f856f099SNavdeep Parhar 				rc = CUDBG_SYSTEM_ERROR;
361f856f099SNavdeep Parhar 
362f856f099SNavdeep Parhar 			entity_hdr->hdr_flags =  rc;
363f856f099SNavdeep Parhar 			entity_hdr->sys_err = cudbg_err.sys_err;
364f856f099SNavdeep Parhar 			entity_hdr->sys_warn =	cudbg_err.sys_warn;
365f856f099SNavdeep Parhar 
366f856f099SNavdeep Parhar 			/* We don't want to include ext entity size in global
367f856f099SNavdeep Parhar 			 * header
368f856f099SNavdeep Parhar 			 */
369f856f099SNavdeep Parhar 			if (!flag_ext)
370f856f099SNavdeep Parhar 				total_size += entity_hdr->size;
371f856f099SNavdeep Parhar 
372f856f099SNavdeep Parhar 			cudbg_hdr->data_len = total_size;
373f856f099SNavdeep Parhar 			*outbuf_size = total_size;
374f856f099SNavdeep Parhar 
375f856f099SNavdeep Parhar 			/* consider the size of the ext entity header and data
376f856f099SNavdeep Parhar 			 * also
377f856f099SNavdeep Parhar 			 */
378f856f099SNavdeep Parhar 			if (flag_ext) {
379f856f099SNavdeep Parhar 				ext_size += (sizeof(struct cudbg_entity_hdr) +
380f856f099SNavdeep Parhar 					     entity_hdr->size);
381f856f099SNavdeep Parhar 				entity_hdr->start_offset -= cudbg_hdr->data_len;
382f856f099SNavdeep Parhar 				ext_entity_hdr->size = ext_size;
383f856f099SNavdeep Parhar 				entity_hdr->next_ext_offset = ext_size;
384f856f099SNavdeep Parhar 				entity_hdr->flag |= CUDBG_EXT_DATA_VALID;
385f856f099SNavdeep Parhar 			}
386f856f099SNavdeep Parhar 
387f856f099SNavdeep Parhar 			if (cudbg_init->use_flash) {
388f856f099SNavdeep Parhar 				if (flag_ext) {
389f856f099SNavdeep Parhar 					wr_entity_to_flash(handle,
390f856f099SNavdeep Parhar 							   &dbg_buff,
391f856f099SNavdeep Parhar 							   ext_entity_hdr->
392f856f099SNavdeep Parhar 							   start_offset,
393f856f099SNavdeep Parhar 							   entity_hdr->
394f856f099SNavdeep Parhar 							   size,
395f856f099SNavdeep Parhar 							   CUDBG_EXT_ENTITY,
396f856f099SNavdeep Parhar 							   ext_size);
397f856f099SNavdeep Parhar 				}
398f856f099SNavdeep Parhar 				else
399f856f099SNavdeep Parhar 					wr_entity_to_flash(handle,
400f856f099SNavdeep Parhar 							   &dbg_buff,
401f856f099SNavdeep Parhar 							   entity_hdr->\
402f856f099SNavdeep Parhar 							   start_offset,
403f856f099SNavdeep Parhar 							   entity_hdr->size,
404f856f099SNavdeep Parhar 							   i, ext_size);
405f856f099SNavdeep Parhar 			}
406f856f099SNavdeep Parhar 		}
407f856f099SNavdeep Parhar 	}
408f856f099SNavdeep Parhar 
409f856f099SNavdeep Parhar 	for (i = 0; i < sizeof(large_entity_list) / sizeof(struct large_entity);
410f856f099SNavdeep Parhar 	     i++) {
411f856f099SNavdeep Parhar 		large_entity_code = large_entity_list[i].entity_code;
412f856f099SNavdeep Parhar 		if (large_entity_list[i].skip_flag) {
413f856f099SNavdeep Parhar 			if (!flag_ext) {
414f856f099SNavdeep Parhar 				rc = get_entity_hdr(outbuf, large_entity_code,
415f856f099SNavdeep Parhar 						    dbg_buff.size, &entity_hdr);
416f856f099SNavdeep Parhar 				if (rc)
417f856f099SNavdeep Parhar 					cudbg_hdr->hdr_flags = rc;
418f856f099SNavdeep Parhar 			} else {
419f856f099SNavdeep Parhar 				rc = get_next_ext_entity_hdr(outbuf, &ext_size,
420f856f099SNavdeep Parhar 							     &dbg_buff,
421f856f099SNavdeep Parhar 							     &entity_hdr);
422f856f099SNavdeep Parhar 				if (rc)
423f856f099SNavdeep Parhar 					goto err;
424f856f099SNavdeep Parhar 
425f856f099SNavdeep Parhar 				dbg_buff.offset +=
426f856f099SNavdeep Parhar 					sizeof(struct cudbg_entity_hdr);
427f856f099SNavdeep Parhar 			}
428f856f099SNavdeep Parhar 
429f856f099SNavdeep Parhar 			/* If fw_attach is 0, then skip entities which
430f856f099SNavdeep Parhar 			 * communicates with firmware
431f856f099SNavdeep Parhar 			 */
432f856f099SNavdeep Parhar 			if (!is_fw_attached(cudbg_init) &&
433f856f099SNavdeep Parhar 			    (entity_list[large_entity_code].flag &
434f856f099SNavdeep Parhar 			    (1 << ENTITY_FLAG_FW_NO_ATTACH))) {
435f856f099SNavdeep Parhar 				if (cudbg_init->verbose)
436f856f099SNavdeep Parhar 					cudbg_init->print("Skipping %s entity,"\
437f856f099SNavdeep Parhar 						  "because fw_attach "\
438f856f099SNavdeep Parhar 						  "is 0\n",
439f856f099SNavdeep Parhar 						  entity_list[large_entity_code]
440f856f099SNavdeep Parhar 						  .name);
441f856f099SNavdeep Parhar 				continue;
442f856f099SNavdeep Parhar 			}
443f856f099SNavdeep Parhar 
444f856f099SNavdeep Parhar 			entity_hdr->entity_type = large_entity_code;
445f856f099SNavdeep Parhar 			entity_hdr->start_offset = dbg_buff.offset;
446f856f099SNavdeep Parhar 			if (cudbg_init->verbose)
447f856f099SNavdeep Parhar 				cudbg_init->print("Re-trying debug entity: %s\n",
448f856f099SNavdeep Parhar 					  entity_list[large_entity_code].name);
449f856f099SNavdeep Parhar 
450f856f099SNavdeep Parhar 			memset(&cudbg_err, 0, sizeof(struct cudbg_error));
451f856f099SNavdeep Parhar 			rc = process_entity[large_entity_code - 1](cudbg_init,
452f856f099SNavdeep Parhar 								   &dbg_buff,
453f856f099SNavdeep Parhar 								   &cudbg_err);
454f856f099SNavdeep Parhar 			if (rc) {
455f856f099SNavdeep Parhar 				entity_hdr->size = 0;
456f856f099SNavdeep Parhar 				dbg_buff.offset = entity_hdr->start_offset;
457f856f099SNavdeep Parhar 			} else
458f856f099SNavdeep Parhar 				align_debug_buffer(&dbg_buff, entity_hdr);
459f856f099SNavdeep Parhar 
460f856f099SNavdeep Parhar 			if (cudbg_err.sys_err)
461f856f099SNavdeep Parhar 				rc = CUDBG_SYSTEM_ERROR;
462f856f099SNavdeep Parhar 
463f856f099SNavdeep Parhar 			entity_hdr->hdr_flags = rc;
464f856f099SNavdeep Parhar 			entity_hdr->sys_err = cudbg_err.sys_err;
465f856f099SNavdeep Parhar 			entity_hdr->sys_warn =	cudbg_err.sys_warn;
466f856f099SNavdeep Parhar 
467f856f099SNavdeep Parhar 			/* We don't want to include ext entity size in global
468f856f099SNavdeep Parhar 			 * header
469f856f099SNavdeep Parhar 			 */
470f856f099SNavdeep Parhar 			if (!flag_ext)
471f856f099SNavdeep Parhar 				total_size += entity_hdr->size;
472f856f099SNavdeep Parhar 
473f856f099SNavdeep Parhar 			cudbg_hdr->data_len = total_size;
474f856f099SNavdeep Parhar 			*outbuf_size = total_size;
475f856f099SNavdeep Parhar 
476f856f099SNavdeep Parhar 			/* consider the size of the ext entity header and
477f856f099SNavdeep Parhar 			 * data also
478f856f099SNavdeep Parhar 			 */
479f856f099SNavdeep Parhar 			if (flag_ext) {
480f856f099SNavdeep Parhar 				ext_size += (sizeof(struct cudbg_entity_hdr) +
481f856f099SNavdeep Parhar 						   entity_hdr->size);
482f856f099SNavdeep Parhar 				entity_hdr->start_offset -=
483f856f099SNavdeep Parhar 							cudbg_hdr->data_len;
484f856f099SNavdeep Parhar 				ext_entity_hdr->size = ext_size;
485f856f099SNavdeep Parhar 				entity_hdr->flag |= CUDBG_EXT_DATA_VALID;
486f856f099SNavdeep Parhar 			}
487f856f099SNavdeep Parhar 
488f856f099SNavdeep Parhar 			if (cudbg_init->use_flash) {
489f856f099SNavdeep Parhar 				if (flag_ext)
490f856f099SNavdeep Parhar 					wr_entity_to_flash(handle,
491f856f099SNavdeep Parhar 							   &dbg_buff,
492f856f099SNavdeep Parhar 							   ext_entity_hdr->
493f856f099SNavdeep Parhar 							   start_offset,
494f856f099SNavdeep Parhar 							   entity_hdr->size,
495f856f099SNavdeep Parhar 							   CUDBG_EXT_ENTITY,
496f856f099SNavdeep Parhar 							   ext_size);
497f856f099SNavdeep Parhar 				else
498f856f099SNavdeep Parhar 					wr_entity_to_flash(handle,
499f856f099SNavdeep Parhar 							   &dbg_buff,
500f856f099SNavdeep Parhar 							   entity_hdr->
501f856f099SNavdeep Parhar 							   start_offset,
502f856f099SNavdeep Parhar 							   entity_hdr->
503f856f099SNavdeep Parhar 							   size,
504f856f099SNavdeep Parhar 							   large_entity_list[i].
505f856f099SNavdeep Parhar 							   entity_code,
506f856f099SNavdeep Parhar 							   ext_size);
507f856f099SNavdeep Parhar 			}
508f856f099SNavdeep Parhar 		}
509f856f099SNavdeep Parhar 	}
510f856f099SNavdeep Parhar 
511f856f099SNavdeep Parhar 	cudbg_hdr->data_len = total_size;
512f856f099SNavdeep Parhar 	*outbuf_size = total_size;
513f856f099SNavdeep Parhar 
514f856f099SNavdeep Parhar 	if (flag_ext)
515f856f099SNavdeep Parhar 		*outbuf_size += ext_size;
516f856f099SNavdeep Parhar 
517f856f099SNavdeep Parhar 	return 0;
518f856f099SNavdeep Parhar err:
519f856f099SNavdeep Parhar 	return rc;
520f856f099SNavdeep Parhar }
521f856f099SNavdeep Parhar 
reset_skip_entity(void)522f856f099SNavdeep Parhar void reset_skip_entity(void)
523f856f099SNavdeep Parhar {
524f856f099SNavdeep Parhar 	int i;
525f856f099SNavdeep Parhar 
526f856f099SNavdeep Parhar 	for (i = 0; i < ARRAY_SIZE(large_entity_list); i++)
527f856f099SNavdeep Parhar 		large_entity_list[i].skip_flag = 0;
528f856f099SNavdeep Parhar }
529f856f099SNavdeep Parhar 
skip_entity(int entity_code)530f856f099SNavdeep Parhar void skip_entity(int entity_code)
531f856f099SNavdeep Parhar {
532f856f099SNavdeep Parhar 	int i;
533f856f099SNavdeep Parhar 	for (i = 0; i < sizeof(large_entity_list) / sizeof(struct large_entity);
534f856f099SNavdeep Parhar 	     i++) {
535f856f099SNavdeep Parhar 		if (large_entity_list[i].entity_code == entity_code)
536f856f099SNavdeep Parhar 			large_entity_list[i].skip_flag = 1;
537f856f099SNavdeep Parhar 	}
538f856f099SNavdeep Parhar }
539f856f099SNavdeep Parhar 
is_large_entity(int entity_code)540f856f099SNavdeep Parhar int is_large_entity(int entity_code)
541f856f099SNavdeep Parhar {
542f856f099SNavdeep Parhar 	int i;
543f856f099SNavdeep Parhar 
544f856f099SNavdeep Parhar 	for (i = 0; i < sizeof(large_entity_list) / sizeof(struct large_entity);
545f856f099SNavdeep Parhar 	     i++) {
546f856f099SNavdeep Parhar 		if (large_entity_list[i].entity_code == entity_code)
547f856f099SNavdeep Parhar 			return 1;
548f856f099SNavdeep Parhar 	}
549f856f099SNavdeep Parhar 	return 0;
550f856f099SNavdeep Parhar }
551f856f099SNavdeep Parhar 
get_entity_hdr(void * outbuf,int i,u32 size,struct cudbg_entity_hdr ** entity_hdr)552f856f099SNavdeep Parhar int get_entity_hdr(void *outbuf, int i, u32 size,
553f856f099SNavdeep Parhar 		   struct cudbg_entity_hdr **entity_hdr)
554f856f099SNavdeep Parhar {
555f856f099SNavdeep Parhar 	int rc = 0;
556f856f099SNavdeep Parhar 	struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
557f856f099SNavdeep Parhar 
558f856f099SNavdeep Parhar 	if (cudbg_hdr->hdr_len + (sizeof(struct cudbg_entity_hdr)*i) > size)
559f856f099SNavdeep Parhar 		return CUDBG_STATUS_SMALL_BUFF;
560f856f099SNavdeep Parhar 
561f856f099SNavdeep Parhar 	*entity_hdr = (struct cudbg_entity_hdr *)
562f856f099SNavdeep Parhar 		      ((char *)outbuf+cudbg_hdr->hdr_len +
563f856f099SNavdeep Parhar 		       (sizeof(struct cudbg_entity_hdr)*(i-1)));
564f856f099SNavdeep Parhar 	return rc;
565f856f099SNavdeep Parhar }
566f856f099SNavdeep Parhar 
collect_rss(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)567f856f099SNavdeep Parhar static int collect_rss(struct cudbg_init *pdbg_init,
568f856f099SNavdeep Parhar 		       struct cudbg_buffer *dbg_buff,
569f856f099SNavdeep Parhar 		       struct cudbg_error *cudbg_err)
570f856f099SNavdeep Parhar {
571f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
572f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
573f856f099SNavdeep Parhar 	u32 size;
574f856f099SNavdeep Parhar 	int rc = 0;
575f856f099SNavdeep Parhar 
576a2e160c5SNavdeep Parhar 	size = padap->chip_params->rss_nentries * sizeof(u16);
577f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
578f856f099SNavdeep Parhar 	if (rc)
579f856f099SNavdeep Parhar 		goto err;
580f856f099SNavdeep Parhar 
581f856f099SNavdeep Parhar 	rc = t4_read_rss(padap, (u16 *)scratch_buff.data);
582f856f099SNavdeep Parhar 	if (rc) {
583f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
584f856f099SNavdeep Parhar 			pdbg_init->print("%s(), t4_read_rss failed!, rc: %d\n",
585f856f099SNavdeep Parhar 				 __func__, rc);
586f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
587f856f099SNavdeep Parhar 		goto err1;
588f856f099SNavdeep Parhar 	}
589f856f099SNavdeep Parhar 
590f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
591f856f099SNavdeep Parhar 	if (rc)
592f856f099SNavdeep Parhar 		goto err1;
593f856f099SNavdeep Parhar 
594f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
595f856f099SNavdeep Parhar 
596f856f099SNavdeep Parhar err1:
597f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
598f856f099SNavdeep Parhar err:
599f856f099SNavdeep Parhar 	return rc;
600f856f099SNavdeep Parhar }
601f856f099SNavdeep Parhar 
collect_sw_state(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)602f856f099SNavdeep Parhar static int collect_sw_state(struct cudbg_init *pdbg_init,
603f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
604f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
605f856f099SNavdeep Parhar {
606f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
607f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
608f856f099SNavdeep Parhar 	struct sw_state *swstate;
609f856f099SNavdeep Parhar 	u32 size;
610f856f099SNavdeep Parhar 	int rc = 0;
611f856f099SNavdeep Parhar 
612f856f099SNavdeep Parhar 	size = sizeof(struct sw_state);
613f856f099SNavdeep Parhar 
614f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
615f856f099SNavdeep Parhar 	if (rc)
616f856f099SNavdeep Parhar 		goto err;
617f856f099SNavdeep Parhar 
618f856f099SNavdeep Parhar 	swstate = (struct sw_state *) scratch_buff.data;
619f856f099SNavdeep Parhar 
620f856f099SNavdeep Parhar 	swstate->fw_state = t4_read_reg(padap, A_PCIE_FW);
621f856f099SNavdeep Parhar 	snprintf(swstate->caller_string, sizeof(swstate->caller_string), "%s",
622f856f099SNavdeep Parhar 	    "FreeBSD");
623f856f099SNavdeep Parhar 	swstate->os_type = 0;
624f856f099SNavdeep Parhar 
625f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
626f856f099SNavdeep Parhar 	if (rc)
627f856f099SNavdeep Parhar 		goto err1;
628f856f099SNavdeep Parhar 
629f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
630f856f099SNavdeep Parhar 
631f856f099SNavdeep Parhar err1:
632f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
633f856f099SNavdeep Parhar err:
634f856f099SNavdeep Parhar 	return rc;
635f856f099SNavdeep Parhar }
636f856f099SNavdeep Parhar 
collect_ddp_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)637f856f099SNavdeep Parhar static int collect_ddp_stats(struct cudbg_init *pdbg_init,
638f856f099SNavdeep Parhar 			     struct cudbg_buffer *dbg_buff,
639f856f099SNavdeep Parhar 			     struct cudbg_error *cudbg_err)
640f856f099SNavdeep Parhar {
641f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
642f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
643f856f099SNavdeep Parhar 	struct tp_usm_stats  *tp_usm_stats_buff;
644f856f099SNavdeep Parhar 	u32 size;
645f856f099SNavdeep Parhar 	int rc = 0;
646f856f099SNavdeep Parhar 
647f856f099SNavdeep Parhar 	size = sizeof(struct tp_usm_stats);
648f856f099SNavdeep Parhar 
649f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
650f856f099SNavdeep Parhar 	if (rc)
651f856f099SNavdeep Parhar 		goto err;
652f856f099SNavdeep Parhar 
653f856f099SNavdeep Parhar 	tp_usm_stats_buff = (struct tp_usm_stats *) scratch_buff.data;
654f856f099SNavdeep Parhar 
655f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
656f856f099SNavdeep Parhar 	t4_get_usm_stats(padap, tp_usm_stats_buff, 1);
657f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
658f856f099SNavdeep Parhar 
659f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
660f856f099SNavdeep Parhar 	if (rc)
661f856f099SNavdeep Parhar 		goto err1;
662f856f099SNavdeep Parhar 
663f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
664f856f099SNavdeep Parhar 
665f856f099SNavdeep Parhar err1:
666f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
667f856f099SNavdeep Parhar err:
668f856f099SNavdeep Parhar 	return rc;
669f856f099SNavdeep Parhar }
670f856f099SNavdeep Parhar 
collect_ulptx_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)671f856f099SNavdeep Parhar static int collect_ulptx_la(struct cudbg_init *pdbg_init,
672f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
673f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
674f856f099SNavdeep Parhar {
675f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
676f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
677f856f099SNavdeep Parhar 	struct struct_ulptx_la *ulptx_la_buff;
678f856f099SNavdeep Parhar 	u32 size, i, j;
679f856f099SNavdeep Parhar 	int rc = 0;
680f856f099SNavdeep Parhar 
681f856f099SNavdeep Parhar 	size = sizeof(struct struct_ulptx_la);
682f856f099SNavdeep Parhar 
683f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
684f856f099SNavdeep Parhar 	if (rc)
685f856f099SNavdeep Parhar 		goto err;
686f856f099SNavdeep Parhar 
687f856f099SNavdeep Parhar 	ulptx_la_buff = (struct struct_ulptx_la *) scratch_buff.data;
688f856f099SNavdeep Parhar 
689f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
690f856f099SNavdeep Parhar 		ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
691f856f099SNavdeep Parhar 						      A_ULP_TX_LA_RDPTR_0 +
692f856f099SNavdeep Parhar 						      0x10 * i);
693f856f099SNavdeep Parhar 		ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
694f856f099SNavdeep Parhar 						      A_ULP_TX_LA_WRPTR_0 +
695f856f099SNavdeep Parhar 						      0x10 * i);
696f856f099SNavdeep Parhar 		ulptx_la_buff->rddata[i] = t4_read_reg(padap,
697f856f099SNavdeep Parhar 						       A_ULP_TX_LA_RDDATA_0 +
698f856f099SNavdeep Parhar 						       0x10 * i);
699f856f099SNavdeep Parhar 		for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++) {
700f856f099SNavdeep Parhar 			ulptx_la_buff->rd_data[i][j] =
701f856f099SNavdeep Parhar 				t4_read_reg(padap,
702f856f099SNavdeep Parhar 					    A_ULP_TX_LA_RDDATA_0 + 0x10 * i);
703f856f099SNavdeep Parhar 		}
704f856f099SNavdeep Parhar 	}
705f856f099SNavdeep Parhar 
706f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
707f856f099SNavdeep Parhar 	if (rc)
708f856f099SNavdeep Parhar 		goto err1;
709f856f099SNavdeep Parhar 
710f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
711f856f099SNavdeep Parhar 
712f856f099SNavdeep Parhar err1:
713f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
714f856f099SNavdeep Parhar err:
715f856f099SNavdeep Parhar 	return rc;
716f856f099SNavdeep Parhar 
717f856f099SNavdeep Parhar }
718f856f099SNavdeep Parhar 
collect_ulprx_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)719f856f099SNavdeep Parhar static int collect_ulprx_la(struct cudbg_init *pdbg_init,
720f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
721f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
722f856f099SNavdeep Parhar {
723f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
724f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
725f856f099SNavdeep Parhar 	struct struct_ulprx_la *ulprx_la_buff;
726f856f099SNavdeep Parhar 	u32 size;
727f856f099SNavdeep Parhar 	int rc = 0;
728f856f099SNavdeep Parhar 
729f856f099SNavdeep Parhar 	size = sizeof(struct struct_ulprx_la);
730f856f099SNavdeep Parhar 
731f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
732f856f099SNavdeep Parhar 	if (rc)
733f856f099SNavdeep Parhar 		goto err;
734f856f099SNavdeep Parhar 
735f856f099SNavdeep Parhar 	ulprx_la_buff = (struct struct_ulprx_la *) scratch_buff.data;
736f856f099SNavdeep Parhar 	t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
737f856f099SNavdeep Parhar 	ulprx_la_buff->size = ULPRX_LA_SIZE;
738f856f099SNavdeep Parhar 
739f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
740f856f099SNavdeep Parhar 	if (rc)
741f856f099SNavdeep Parhar 		goto err1;
742f856f099SNavdeep Parhar 
743f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
744f856f099SNavdeep Parhar 
745f856f099SNavdeep Parhar err1:
746f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
747f856f099SNavdeep Parhar err:
748f856f099SNavdeep Parhar 	return rc;
749f856f099SNavdeep Parhar }
750f856f099SNavdeep Parhar 
collect_cpl_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)751f856f099SNavdeep Parhar static int collect_cpl_stats(struct cudbg_init *pdbg_init,
752f856f099SNavdeep Parhar 			     struct cudbg_buffer *dbg_buff,
753f856f099SNavdeep Parhar 			     struct cudbg_error *cudbg_err)
754f856f099SNavdeep Parhar {
755f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
756f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
757f856f099SNavdeep Parhar 	struct struct_tp_cpl_stats *tp_cpl_stats_buff;
758f856f099SNavdeep Parhar 	u32 size;
759f856f099SNavdeep Parhar 	int rc = 0;
760f856f099SNavdeep Parhar 
761f856f099SNavdeep Parhar 	size = sizeof(struct struct_tp_cpl_stats);
762f856f099SNavdeep Parhar 
763f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
764f856f099SNavdeep Parhar 	if (rc)
765f856f099SNavdeep Parhar 		goto err;
766f856f099SNavdeep Parhar 
767f856f099SNavdeep Parhar 	tp_cpl_stats_buff = (struct struct_tp_cpl_stats *) scratch_buff.data;
768f856f099SNavdeep Parhar 	tp_cpl_stats_buff->nchan = padap->chip_params->nchan;
769f856f099SNavdeep Parhar 
770f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
771f856f099SNavdeep Parhar 	t4_tp_get_cpl_stats(padap, &tp_cpl_stats_buff->stats, 1);
772f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
773f856f099SNavdeep Parhar 
774f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
775f856f099SNavdeep Parhar 	if (rc)
776f856f099SNavdeep Parhar 		goto err1;
777f856f099SNavdeep Parhar 
778f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
779f856f099SNavdeep Parhar 
780f856f099SNavdeep Parhar err1:
781f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
782f856f099SNavdeep Parhar err:
783f856f099SNavdeep Parhar 	return rc;
784f856f099SNavdeep Parhar }
785f856f099SNavdeep Parhar 
collect_wc_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)786f856f099SNavdeep Parhar static int collect_wc_stats(struct cudbg_init *pdbg_init,
787f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
788f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
789f856f099SNavdeep Parhar {
790f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
791f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
792f856f099SNavdeep Parhar 	struct struct_wc_stats *wc_stats_buff;
793f856f099SNavdeep Parhar 	u32 val1;
794f856f099SNavdeep Parhar 	u32 val2;
795f856f099SNavdeep Parhar 	u32 size;
796f856f099SNavdeep Parhar 
797f856f099SNavdeep Parhar 	int rc = 0;
798f856f099SNavdeep Parhar 
799f856f099SNavdeep Parhar 	size = sizeof(struct struct_wc_stats);
800f856f099SNavdeep Parhar 
801f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
802f856f099SNavdeep Parhar 	if (rc)
803f856f099SNavdeep Parhar 		goto err;
804f856f099SNavdeep Parhar 
805f856f099SNavdeep Parhar 	wc_stats_buff = (struct struct_wc_stats *) scratch_buff.data;
806f856f099SNavdeep Parhar 
807f856f099SNavdeep Parhar 	if (!is_t4(padap)) {
808f856f099SNavdeep Parhar 		val1 = t4_read_reg(padap, A_SGE_STAT_TOTAL);
809f856f099SNavdeep Parhar 		val2 = t4_read_reg(padap, A_SGE_STAT_MATCH);
810f856f099SNavdeep Parhar 		wc_stats_buff->wr_cl_success = val1 - val2;
811f856f099SNavdeep Parhar 		wc_stats_buff->wr_cl_fail = val2;
812f856f099SNavdeep Parhar 	} else {
813f856f099SNavdeep Parhar 		wc_stats_buff->wr_cl_success = 0;
814f856f099SNavdeep Parhar 		wc_stats_buff->wr_cl_fail = 0;
815f856f099SNavdeep Parhar 	}
816f856f099SNavdeep Parhar 
817f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
818f856f099SNavdeep Parhar 	if (rc)
819f856f099SNavdeep Parhar 		goto err1;
820f856f099SNavdeep Parhar 
821f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
822f856f099SNavdeep Parhar err1:
823f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
824f856f099SNavdeep Parhar err:
825f856f099SNavdeep Parhar 	return rc;
826f856f099SNavdeep Parhar }
827f856f099SNavdeep Parhar 
mem_desc_cmp(const void * a,const void * b)828f856f099SNavdeep Parhar static int mem_desc_cmp(const void *a, const void *b)
829f856f099SNavdeep Parhar {
830f856f099SNavdeep Parhar 	return ((const struct struct_mem_desc *)a)->base -
831f856f099SNavdeep Parhar 		((const struct struct_mem_desc *)b)->base;
832f856f099SNavdeep Parhar }
833f856f099SNavdeep Parhar 
fill_meminfo(struct adapter * padap,struct struct_meminfo * meminfo_buff)834f856f099SNavdeep Parhar static int fill_meminfo(struct adapter *padap,
835f856f099SNavdeep Parhar 			struct struct_meminfo *meminfo_buff)
836f856f099SNavdeep Parhar {
837f856f099SNavdeep Parhar 	struct struct_mem_desc *md;
838f856f099SNavdeep Parhar 	u32 size, lo, hi;
839f856f099SNavdeep Parhar 	u32 used, alloc;
840f856f099SNavdeep Parhar 	int n, i, rc = 0;
841f856f099SNavdeep Parhar 
842f856f099SNavdeep Parhar 	size = sizeof(struct struct_meminfo);
843f856f099SNavdeep Parhar 
844f856f099SNavdeep Parhar 	memset(meminfo_buff->avail, 0,
845f856f099SNavdeep Parhar 	       ARRAY_SIZE(meminfo_buff->avail) *
846f856f099SNavdeep Parhar 	       sizeof(struct struct_mem_desc));
847f856f099SNavdeep Parhar 	memset(meminfo_buff->mem, 0,
848f856f099SNavdeep Parhar 	       (ARRAY_SIZE(region) + 3) * sizeof(struct struct_mem_desc));
849f856f099SNavdeep Parhar 	md  = meminfo_buff->mem;
850f856f099SNavdeep Parhar 
851f856f099SNavdeep Parhar 	for (i = 0; i < ARRAY_SIZE(meminfo_buff->mem); i++) {
852f856f099SNavdeep Parhar 		meminfo_buff->mem[i].limit = 0;
853f856f099SNavdeep Parhar 		meminfo_buff->mem[i].idx = i;
854f856f099SNavdeep Parhar 	}
855f856f099SNavdeep Parhar 
856f856f099SNavdeep Parhar 	i = 0;
857f856f099SNavdeep Parhar 
858f856f099SNavdeep Parhar 	lo = t4_read_reg(padap, A_MA_TARGET_MEM_ENABLE);
859f856f099SNavdeep Parhar 
860f856f099SNavdeep Parhar 	if (lo & F_EDRAM0_ENABLE) {
861f856f099SNavdeep Parhar 		hi = t4_read_reg(padap, A_MA_EDRAM0_BAR);
862f856f099SNavdeep Parhar 		meminfo_buff->avail[i].base = G_EDRAM0_BASE(hi) << 20;
863f856f099SNavdeep Parhar 		meminfo_buff->avail[i].limit = meminfo_buff->avail[i].base +
864f856f099SNavdeep Parhar 					       (G_EDRAM0_SIZE(hi) << 20);
865f856f099SNavdeep Parhar 		meminfo_buff->avail[i].idx = 0;
866f856f099SNavdeep Parhar 		i++;
867f856f099SNavdeep Parhar 	}
868f856f099SNavdeep Parhar 
869f856f099SNavdeep Parhar 	if (lo & F_EDRAM1_ENABLE) {
870f856f099SNavdeep Parhar 		hi =  t4_read_reg(padap, A_MA_EDRAM1_BAR);
871f856f099SNavdeep Parhar 		meminfo_buff->avail[i].base = G_EDRAM1_BASE(hi) << 20;
872f856f099SNavdeep Parhar 		meminfo_buff->avail[i].limit = meminfo_buff->avail[i].base +
873f856f099SNavdeep Parhar 					       (G_EDRAM1_SIZE(hi) << 20);
874f856f099SNavdeep Parhar 		meminfo_buff->avail[i].idx = 1;
875f856f099SNavdeep Parhar 		i++;
876f856f099SNavdeep Parhar 	}
877f856f099SNavdeep Parhar 
878f856f099SNavdeep Parhar 	if (is_t5(padap)) {
879f856f099SNavdeep Parhar 		if (lo & F_EXT_MEM0_ENABLE) {
880f856f099SNavdeep Parhar 			hi = t4_read_reg(padap, A_MA_EXT_MEMORY0_BAR);
881f856f099SNavdeep Parhar 			meminfo_buff->avail[i].base = G_EXT_MEM_BASE(hi) << 20;
882f856f099SNavdeep Parhar 			meminfo_buff->avail[i].limit =
883f856f099SNavdeep Parhar 				meminfo_buff->avail[i].base +
884f856f099SNavdeep Parhar 				(G_EXT_MEM_SIZE(hi) << 20);
885f856f099SNavdeep Parhar 			meminfo_buff->avail[i].idx = 3;
886f856f099SNavdeep Parhar 			i++;
887f856f099SNavdeep Parhar 		}
888f856f099SNavdeep Parhar 
889f856f099SNavdeep Parhar 		if (lo & F_EXT_MEM1_ENABLE) {
890f856f099SNavdeep Parhar 			hi = t4_read_reg(padap, A_MA_EXT_MEMORY1_BAR);
891f856f099SNavdeep Parhar 			meminfo_buff->avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
892f856f099SNavdeep Parhar 			meminfo_buff->avail[i].limit =
893f856f099SNavdeep Parhar 				meminfo_buff->avail[i].base +
894f856f099SNavdeep Parhar 				(G_EXT_MEM1_SIZE(hi) << 20);
895f856f099SNavdeep Parhar 			meminfo_buff->avail[i].idx = 4;
896f856f099SNavdeep Parhar 			i++;
897f856f099SNavdeep Parhar 		}
898f856f099SNavdeep Parhar 	} else if (is_t6(padap)) {
899f856f099SNavdeep Parhar 		if (lo & F_EXT_MEM_ENABLE) {
900f856f099SNavdeep Parhar 			hi = t4_read_reg(padap, A_MA_EXT_MEMORY_BAR);
901f856f099SNavdeep Parhar 			meminfo_buff->avail[i].base = G_EXT_MEM_BASE(hi) << 20;
902f856f099SNavdeep Parhar 			meminfo_buff->avail[i].limit =
903f856f099SNavdeep Parhar 				meminfo_buff->avail[i].base +
904f856f099SNavdeep Parhar 				(G_EXT_MEM_SIZE(hi) << 20);
905f856f099SNavdeep Parhar 			meminfo_buff->avail[i].idx = 2;
906f856f099SNavdeep Parhar 			i++;
907f856f099SNavdeep Parhar 		}
908f856f099SNavdeep Parhar 	}
909f856f099SNavdeep Parhar 
910f856f099SNavdeep Parhar 	if (!i) {				   /* no memory available */
911f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
912f856f099SNavdeep Parhar 		goto err;
913f856f099SNavdeep Parhar 	}
914f856f099SNavdeep Parhar 
915f856f099SNavdeep Parhar 	meminfo_buff->avail_c = i;
916f856f099SNavdeep Parhar 	qsort(meminfo_buff->avail, i, sizeof(struct struct_mem_desc),
917f856f099SNavdeep Parhar 	    mem_desc_cmp);
918f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_SGE_DBQ_CTXT_BADDR);
919f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_SGE_IMSG_CTXT_BADDR);
920f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_SGE_FLM_CACHE_BADDR);
921f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_TCB_BASE);
922f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_MM_BASE);
923f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_TIMER_BASE);
924f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_MM_RX_FLST_BASE);
925f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_MM_TX_FLST_BASE);
926f856f099SNavdeep Parhar 	(md++)->base = t4_read_reg(padap, A_TP_CMM_MM_PS_FLST_BASE);
927f856f099SNavdeep Parhar 
928f856f099SNavdeep Parhar 	/* the next few have explicit upper bounds */
929f856f099SNavdeep Parhar 	md->base = t4_read_reg(padap, A_TP_PMM_TX_BASE);
930f856f099SNavdeep Parhar 	md->limit = md->base - 1 +
931f856f099SNavdeep Parhar 		    t4_read_reg(padap,
932f856f099SNavdeep Parhar 				A_TP_PMM_TX_PAGE_SIZE) *
933f856f099SNavdeep Parhar 				G_PMTXMAXPAGE(t4_read_reg(padap,
934f856f099SNavdeep Parhar 							  A_TP_PMM_TX_MAX_PAGE)
935f856f099SNavdeep Parhar 					     );
936f856f099SNavdeep Parhar 	md++;
937f856f099SNavdeep Parhar 
938f856f099SNavdeep Parhar 	md->base = t4_read_reg(padap, A_TP_PMM_RX_BASE);
939f856f099SNavdeep Parhar 	md->limit = md->base - 1 +
940f856f099SNavdeep Parhar 		    t4_read_reg(padap,
941f856f099SNavdeep Parhar 				A_TP_PMM_RX_PAGE_SIZE) *
942f856f099SNavdeep Parhar 				G_PMRXMAXPAGE(t4_read_reg(padap,
943f856f099SNavdeep Parhar 							  A_TP_PMM_RX_MAX_PAGE)
944f856f099SNavdeep Parhar 					      );
945f856f099SNavdeep Parhar 	md++;
946f856f099SNavdeep Parhar 	if (t4_read_reg(padap, A_LE_DB_CONFIG) & F_HASHEN) {
947f856f099SNavdeep Parhar 		if (chip_id(padap) <= CHELSIO_T5) {
948f856f099SNavdeep Parhar 			hi = t4_read_reg(padap, A_LE_DB_TID_HASHBASE) / 4;
949f856f099SNavdeep Parhar 			md->base = t4_read_reg(padap, A_LE_DB_HASH_TID_BASE);
950f856f099SNavdeep Parhar 		} else {
951f856f099SNavdeep Parhar 			hi = t4_read_reg(padap, A_LE_DB_HASH_TID_BASE);
952f856f099SNavdeep Parhar 			md->base = t4_read_reg(padap,
953f856f099SNavdeep Parhar 					       A_LE_DB_HASH_TBL_BASE_ADDR);
954f856f099SNavdeep Parhar 		}
955f856f099SNavdeep Parhar 		md->limit = 0;
956f856f099SNavdeep Parhar 	} else {
957f856f099SNavdeep Parhar 		md->base = 0;
958f856f099SNavdeep Parhar 		md->idx = ARRAY_SIZE(region);  /* hide it */
959f856f099SNavdeep Parhar 	}
960f856f099SNavdeep Parhar 	md++;
961f856f099SNavdeep Parhar #define ulp_region(reg) \
962f856f099SNavdeep Parhar 	{\
963f856f099SNavdeep Parhar 		md->base = t4_read_reg(padap, A_ULP_ ## reg ## _LLIMIT);\
964f856f099SNavdeep Parhar 		(md++)->limit = t4_read_reg(padap, A_ULP_ ## reg ## _ULIMIT);\
965f856f099SNavdeep Parhar 	}
966f856f099SNavdeep Parhar 
967f856f099SNavdeep Parhar 	ulp_region(RX_ISCSI);
968f856f099SNavdeep Parhar 	ulp_region(RX_TDDP);
969f856f099SNavdeep Parhar 	ulp_region(TX_TPT);
970f856f099SNavdeep Parhar 	ulp_region(RX_STAG);
971f856f099SNavdeep Parhar 	ulp_region(RX_RQ);
972f856f099SNavdeep Parhar 	ulp_region(RX_RQUDP);
973f856f099SNavdeep Parhar 	ulp_region(RX_PBL);
974f856f099SNavdeep Parhar 	ulp_region(TX_PBL);
975f856f099SNavdeep Parhar #undef ulp_region
976f856f099SNavdeep Parhar 	md->base = 0;
977f856f099SNavdeep Parhar 	md->idx = ARRAY_SIZE(region);
978f856f099SNavdeep Parhar 	if (!is_t4(padap)) {
979f856f099SNavdeep Parhar 		u32 sge_ctrl = t4_read_reg(padap, A_SGE_CONTROL2);
980f856f099SNavdeep Parhar 		u32 fifo_size = t4_read_reg(padap, A_SGE_DBVFIFO_SIZE);
981f856f099SNavdeep Parhar 		if (is_t5(padap)) {
982f856f099SNavdeep Parhar 			if (sge_ctrl & F_VFIFO_ENABLE)
983f856f099SNavdeep Parhar 				size = G_DBVFIFO_SIZE(fifo_size);
984f856f099SNavdeep Parhar 		} else
985f856f099SNavdeep Parhar 			size = G_T6_DBVFIFO_SIZE(fifo_size);
986f856f099SNavdeep Parhar 
987f856f099SNavdeep Parhar 		if (size) {
988f856f099SNavdeep Parhar 			md->base = G_BASEADDR(t4_read_reg(padap,
989f856f099SNavdeep Parhar 							  A_SGE_DBVFIFO_BADDR));
990f856f099SNavdeep Parhar 			md->limit = md->base + (size << 2) - 1;
991f856f099SNavdeep Parhar 		}
992f856f099SNavdeep Parhar 	}
993f856f099SNavdeep Parhar 
994f856f099SNavdeep Parhar 	md++;
995f856f099SNavdeep Parhar 
996f856f099SNavdeep Parhar 	md->base = t4_read_reg(padap, A_ULP_RX_CTX_BASE);
997f856f099SNavdeep Parhar 	md->limit = 0;
998f856f099SNavdeep Parhar 	md++;
999f856f099SNavdeep Parhar 	md->base = t4_read_reg(padap, A_ULP_TX_ERR_TABLE_BASE);
1000f856f099SNavdeep Parhar 	md->limit = 0;
1001f856f099SNavdeep Parhar 	md++;
1002f856f099SNavdeep Parhar #ifndef __NO_DRIVER_OCQ_SUPPORT__
1003f856f099SNavdeep Parhar 	/*md->base = padap->vres.ocq.start;*/
1004f856f099SNavdeep Parhar 	/*if (adap->vres.ocq.size)*/
1005f856f099SNavdeep Parhar 	/*	  md->limit = md->base + adap->vres.ocq.size - 1;*/
1006f856f099SNavdeep Parhar 	/*else*/
1007f856f099SNavdeep Parhar 	md->idx = ARRAY_SIZE(region);  /* hide it */
1008f856f099SNavdeep Parhar 	md++;
1009f856f099SNavdeep Parhar #endif
1010f856f099SNavdeep Parhar 
1011f856f099SNavdeep Parhar 	/* add any address-space holes, there can be up to 3 */
1012f856f099SNavdeep Parhar 	for (n = 0; n < i - 1; n++)
1013f856f099SNavdeep Parhar 		if (meminfo_buff->avail[n].limit <
1014f856f099SNavdeep Parhar 		    meminfo_buff->avail[n + 1].base)
1015f856f099SNavdeep Parhar 			(md++)->base = meminfo_buff->avail[n].limit;
1016f856f099SNavdeep Parhar 
1017f856f099SNavdeep Parhar 	if (meminfo_buff->avail[n].limit)
1018f856f099SNavdeep Parhar 		(md++)->base = meminfo_buff->avail[n].limit;
1019f856f099SNavdeep Parhar 
1020f856f099SNavdeep Parhar 	n = (int) (md - meminfo_buff->mem);
1021f856f099SNavdeep Parhar 	meminfo_buff->mem_c = n;
1022f856f099SNavdeep Parhar 
1023f856f099SNavdeep Parhar 	qsort(meminfo_buff->mem, n, sizeof(struct struct_mem_desc),
1024f856f099SNavdeep Parhar 	    mem_desc_cmp);
1025f856f099SNavdeep Parhar 
1026f856f099SNavdeep Parhar 	lo = t4_read_reg(padap, A_CIM_SDRAM_BASE_ADDR);
1027f856f099SNavdeep Parhar 	hi = t4_read_reg(padap, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
1028f856f099SNavdeep Parhar 	meminfo_buff->up_ram_lo = lo;
1029f856f099SNavdeep Parhar 	meminfo_buff->up_ram_hi = hi;
1030f856f099SNavdeep Parhar 
1031f856f099SNavdeep Parhar 	lo = t4_read_reg(padap, A_CIM_EXTMEM2_BASE_ADDR);
1032f856f099SNavdeep Parhar 	hi = t4_read_reg(padap, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
1033f856f099SNavdeep Parhar 	meminfo_buff->up_extmem2_lo = lo;
1034f856f099SNavdeep Parhar 	meminfo_buff->up_extmem2_hi = hi;
1035f856f099SNavdeep Parhar 
1036f856f099SNavdeep Parhar 	lo = t4_read_reg(padap, A_TP_PMM_RX_MAX_PAGE);
1037f856f099SNavdeep Parhar 	meminfo_buff->rx_pages_data[0] =  G_PMRXMAXPAGE(lo);
1038f856f099SNavdeep Parhar 	meminfo_buff->rx_pages_data[1] =
1039f856f099SNavdeep Parhar 		t4_read_reg(padap, A_TP_PMM_RX_PAGE_SIZE) >> 10;
1040f856f099SNavdeep Parhar 	meminfo_buff->rx_pages_data[2] = (lo & F_PMRXNUMCHN) ? 2 : 1 ;
1041f856f099SNavdeep Parhar 
1042f856f099SNavdeep Parhar 	lo = t4_read_reg(padap, A_TP_PMM_TX_MAX_PAGE);
1043f856f099SNavdeep Parhar 	hi = t4_read_reg(padap, A_TP_PMM_TX_PAGE_SIZE);
1044f856f099SNavdeep Parhar 	meminfo_buff->tx_pages_data[0] = G_PMTXMAXPAGE(lo);
1045f856f099SNavdeep Parhar 	meminfo_buff->tx_pages_data[1] =
1046f856f099SNavdeep Parhar 		hi >= (1 << 20) ? (hi >> 20) : (hi >> 10);
1047f856f099SNavdeep Parhar 	meminfo_buff->tx_pages_data[2] =
1048f856f099SNavdeep Parhar 		hi >= (1 << 20) ? 'M' : 'K';
1049f856f099SNavdeep Parhar 	meminfo_buff->tx_pages_data[3] = 1 << G_PMTXNUMCHN(lo);
1050f856f099SNavdeep Parhar 
1051f856f099SNavdeep Parhar 	for (i = 0; i < 4; i++) {
1052f856f099SNavdeep Parhar 		if (chip_id(padap) > CHELSIO_T5)
1053f856f099SNavdeep Parhar 			lo = t4_read_reg(padap,
1054f856f099SNavdeep Parhar 					 A_MPS_RX_MAC_BG_PG_CNT0 + i * 4);
1055f856f099SNavdeep Parhar 		else
1056f856f099SNavdeep Parhar 			lo = t4_read_reg(padap, A_MPS_RX_PG_RSV0 + i * 4);
1057f856f099SNavdeep Parhar 		if (is_t5(padap)) {
1058f856f099SNavdeep Parhar 			used = G_T5_USED(lo);
1059f856f099SNavdeep Parhar 			alloc = G_T5_ALLOC(lo);
1060f856f099SNavdeep Parhar 		} else {
1061f856f099SNavdeep Parhar 			used = G_USED(lo);
1062f856f099SNavdeep Parhar 			alloc = G_ALLOC(lo);
1063f856f099SNavdeep Parhar 		}
1064f856f099SNavdeep Parhar 		meminfo_buff->port_used[i] = used;
1065f856f099SNavdeep Parhar 		meminfo_buff->port_alloc[i] = alloc;
1066f856f099SNavdeep Parhar 	}
1067f856f099SNavdeep Parhar 
1068f856f099SNavdeep Parhar 	for (i = 0; i < padap->chip_params->nchan; i++) {
1069f856f099SNavdeep Parhar 		if (chip_id(padap) > CHELSIO_T5)
1070f856f099SNavdeep Parhar 			lo = t4_read_reg(padap,
1071f856f099SNavdeep Parhar 					 A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4);
1072f856f099SNavdeep Parhar 		else
1073f856f099SNavdeep Parhar 			lo = t4_read_reg(padap, A_MPS_RX_PG_RSV4 + i * 4);
1074f856f099SNavdeep Parhar 		if (is_t5(padap)) {
1075f856f099SNavdeep Parhar 			used = G_T5_USED(lo);
1076f856f099SNavdeep Parhar 			alloc = G_T5_ALLOC(lo);
1077f856f099SNavdeep Parhar 		} else {
1078f856f099SNavdeep Parhar 			used = G_USED(lo);
1079f856f099SNavdeep Parhar 			alloc = G_ALLOC(lo);
1080f856f099SNavdeep Parhar 		}
1081f856f099SNavdeep Parhar 		meminfo_buff->loopback_used[i] = used;
1082f856f099SNavdeep Parhar 		meminfo_buff->loopback_alloc[i] = alloc;
1083f856f099SNavdeep Parhar 	}
1084f856f099SNavdeep Parhar err:
1085f856f099SNavdeep Parhar 	return rc;
1086f856f099SNavdeep Parhar }
1087f856f099SNavdeep Parhar 
collect_meminfo(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1088f856f099SNavdeep Parhar static int collect_meminfo(struct cudbg_init *pdbg_init,
1089f856f099SNavdeep Parhar 			   struct cudbg_buffer *dbg_buff,
1090f856f099SNavdeep Parhar 			   struct cudbg_error *cudbg_err)
1091f856f099SNavdeep Parhar {
1092f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1093f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1094f856f099SNavdeep Parhar 	struct struct_meminfo *meminfo_buff;
1095f856f099SNavdeep Parhar 	int rc = 0;
1096f856f099SNavdeep Parhar 	u32 size;
1097f856f099SNavdeep Parhar 
1098f856f099SNavdeep Parhar 	size = sizeof(struct struct_meminfo);
1099f856f099SNavdeep Parhar 
1100f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1101f856f099SNavdeep Parhar 	if (rc)
1102f856f099SNavdeep Parhar 		goto err;
1103f856f099SNavdeep Parhar 
1104f856f099SNavdeep Parhar 	meminfo_buff = (struct struct_meminfo *)scratch_buff.data;
1105f856f099SNavdeep Parhar 
1106f856f099SNavdeep Parhar 	rc = fill_meminfo(padap, meminfo_buff);
1107f856f099SNavdeep Parhar 	if (rc)
1108f856f099SNavdeep Parhar 		goto err;
1109f856f099SNavdeep Parhar 
1110f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1111f856f099SNavdeep Parhar 	if (rc)
1112f856f099SNavdeep Parhar 		goto err1;
1113f856f099SNavdeep Parhar 
1114f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1115f856f099SNavdeep Parhar err1:
1116f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1117f856f099SNavdeep Parhar err:
1118f856f099SNavdeep Parhar 	return rc;
1119f856f099SNavdeep Parhar }
1120f856f099SNavdeep Parhar 
collect_lb_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1121f856f099SNavdeep Parhar static int collect_lb_stats(struct cudbg_init *pdbg_init,
1122f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1123f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1124f856f099SNavdeep Parhar {
1125f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1126f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1127f856f099SNavdeep Parhar 	struct lb_port_stats *tmp_stats;
1128f856f099SNavdeep Parhar 	struct struct_lb_stats *lb_stats_buff;
1129f856f099SNavdeep Parhar 	u32 i, n, size;
1130f856f099SNavdeep Parhar 	int rc = 0;
1131f856f099SNavdeep Parhar 
1132f856f099SNavdeep Parhar 	rc = padap->params.nports;
1133f856f099SNavdeep Parhar 	if (rc < 0)
1134f856f099SNavdeep Parhar 		goto err;
1135f856f099SNavdeep Parhar 
1136f856f099SNavdeep Parhar 	n = rc;
1137f856f099SNavdeep Parhar 	size = sizeof(struct struct_lb_stats) +
1138f856f099SNavdeep Parhar 	       n * sizeof(struct lb_port_stats);
1139f856f099SNavdeep Parhar 
1140f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1141f856f099SNavdeep Parhar 	if (rc)
1142f856f099SNavdeep Parhar 		goto err;
1143f856f099SNavdeep Parhar 
1144f856f099SNavdeep Parhar 	lb_stats_buff = (struct struct_lb_stats *) scratch_buff.data;
1145f856f099SNavdeep Parhar 
1146f856f099SNavdeep Parhar 	lb_stats_buff->nchan = n;
1147f856f099SNavdeep Parhar 	tmp_stats = lb_stats_buff->s;
1148f856f099SNavdeep Parhar 
1149f856f099SNavdeep Parhar 	for (i = 0; i < n; i += 2, tmp_stats += 2) {
1150f856f099SNavdeep Parhar 		t4_get_lb_stats(padap, i, tmp_stats);
1151f856f099SNavdeep Parhar 		t4_get_lb_stats(padap, i + 1, tmp_stats+1);
1152f856f099SNavdeep Parhar 	}
1153f856f099SNavdeep Parhar 
1154f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1155f856f099SNavdeep Parhar 	if (rc)
1156f856f099SNavdeep Parhar 		goto err1;
1157f856f099SNavdeep Parhar 
1158f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1159f856f099SNavdeep Parhar err1:
1160f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1161f856f099SNavdeep Parhar err:
1162f856f099SNavdeep Parhar 	return rc;
1163f856f099SNavdeep Parhar }
1164f856f099SNavdeep Parhar 
collect_rdma_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_er)1165f856f099SNavdeep Parhar static int collect_rdma_stats(struct cudbg_init *pdbg_init,
1166f856f099SNavdeep Parhar 			      struct cudbg_buffer *dbg_buff,
1167f856f099SNavdeep Parhar 			      struct cudbg_error *cudbg_er)
1168f856f099SNavdeep Parhar {
1169f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1170f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1171f856f099SNavdeep Parhar 	struct tp_rdma_stats *rdma_stats_buff;
1172f856f099SNavdeep Parhar 	u32 size;
1173f856f099SNavdeep Parhar 	int rc = 0;
1174f856f099SNavdeep Parhar 
1175f856f099SNavdeep Parhar 	size = sizeof(struct tp_rdma_stats);
1176f856f099SNavdeep Parhar 
1177f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1178f856f099SNavdeep Parhar 	if (rc)
1179f856f099SNavdeep Parhar 		goto err;
1180f856f099SNavdeep Parhar 
1181f856f099SNavdeep Parhar 	rdma_stats_buff = (struct tp_rdma_stats *) scratch_buff.data;
1182f856f099SNavdeep Parhar 
1183f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
1184f856f099SNavdeep Parhar 	t4_tp_get_rdma_stats(padap, rdma_stats_buff, 1);
1185f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
1186f856f099SNavdeep Parhar 
1187f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1188f856f099SNavdeep Parhar 	if (rc)
1189f856f099SNavdeep Parhar 		goto err1;
1190f856f099SNavdeep Parhar 
1191f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1192f856f099SNavdeep Parhar err1:
1193f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1194f856f099SNavdeep Parhar err:
1195f856f099SNavdeep Parhar 	return rc;
1196f856f099SNavdeep Parhar }
1197f856f099SNavdeep Parhar 
collect_clk_info(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1198f856f099SNavdeep Parhar static int collect_clk_info(struct cudbg_init *pdbg_init,
1199f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1200f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1201f856f099SNavdeep Parhar {
1202f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1203f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1204f856f099SNavdeep Parhar 	struct struct_clk_info *clk_info_buff;
1205f856f099SNavdeep Parhar 	u64 tp_tick_us;
1206f856f099SNavdeep Parhar 	int size;
1207f856f099SNavdeep Parhar 	int rc = 0;
1208f856f099SNavdeep Parhar 
1209f856f099SNavdeep Parhar 	if (!padap->params.vpd.cclk) {
1210f856f099SNavdeep Parhar 		rc =  CUDBG_STATUS_CCLK_NOT_DEFINED;
1211f856f099SNavdeep Parhar 		goto err;
1212f856f099SNavdeep Parhar 	}
1213f856f099SNavdeep Parhar 
1214f856f099SNavdeep Parhar 	size = sizeof(struct struct_clk_info);
1215f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1216f856f099SNavdeep Parhar 	if (rc)
1217f856f099SNavdeep Parhar 		goto err;
1218f856f099SNavdeep Parhar 
1219f856f099SNavdeep Parhar 	clk_info_buff = (struct struct_clk_info *) scratch_buff.data;
1220f856f099SNavdeep Parhar 
1221f856f099SNavdeep Parhar 	clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk;  /* in ps
1222f856f099SNavdeep Parhar 	*/
1223f856f099SNavdeep Parhar 	clk_info_buff->res = t4_read_reg(padap, A_TP_TIMER_RESOLUTION);
1224f856f099SNavdeep Parhar 	clk_info_buff->tre = G_TIMERRESOLUTION(clk_info_buff->res);
1225f856f099SNavdeep Parhar 	clk_info_buff->dack_re = G_DELAYEDACKRESOLUTION(clk_info_buff->res);
1226f856f099SNavdeep Parhar 	tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
1227f856f099SNavdeep Parhar 	/* in us */
1228f856f099SNavdeep Parhar 	clk_info_buff->dack_timer = ((clk_info_buff->cclk_ps <<
1229f856f099SNavdeep Parhar 				      clk_info_buff->dack_re) / 1000000) *
1230f856f099SNavdeep Parhar 				     t4_read_reg(padap, A_TP_DACK_TIMER);
1231f856f099SNavdeep Parhar 
1232f856f099SNavdeep Parhar 	clk_info_buff->retransmit_min =
1233f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_RXT_MIN);
1234f856f099SNavdeep Parhar 	clk_info_buff->retransmit_max =
1235f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_RXT_MAX);
1236f856f099SNavdeep Parhar 
1237f856f099SNavdeep Parhar 	clk_info_buff->persist_timer_min =
1238f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_PERS_MIN);
1239f856f099SNavdeep Parhar 	clk_info_buff->persist_timer_max =
1240f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_PERS_MAX);
1241f856f099SNavdeep Parhar 
1242f856f099SNavdeep Parhar 	clk_info_buff->keepalive_idle_timer =
1243f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_KEEP_IDLE);
1244f856f099SNavdeep Parhar 	clk_info_buff->keepalive_interval =
1245f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_KEEP_INTVL);
1246f856f099SNavdeep Parhar 
1247f856f099SNavdeep Parhar 	clk_info_buff->initial_srtt =
1248f856f099SNavdeep Parhar 		tp_tick_us * G_INITSRTT(t4_read_reg(padap, A_TP_INIT_SRTT));
1249f856f099SNavdeep Parhar 	clk_info_buff->finwait2_timer =
1250f856f099SNavdeep Parhar 		tp_tick_us * t4_read_reg(padap, A_TP_FINWAIT2_TIMER);
1251f856f099SNavdeep Parhar 
1252f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1253f856f099SNavdeep Parhar 
1254f856f099SNavdeep Parhar 	if (rc)
1255f856f099SNavdeep Parhar 		goto err1;
1256f856f099SNavdeep Parhar 
1257f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1258f856f099SNavdeep Parhar err1:
1259f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1260f856f099SNavdeep Parhar err:
1261f856f099SNavdeep Parhar 	return rc;
1262f856f099SNavdeep Parhar 
1263f856f099SNavdeep Parhar }
1264f856f099SNavdeep Parhar 
collect_macstats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1265f856f099SNavdeep Parhar static int collect_macstats(struct cudbg_init *pdbg_init,
1266f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1267f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1268f856f099SNavdeep Parhar {
1269f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1270f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1271f856f099SNavdeep Parhar 	struct struct_mac_stats_rev1 *mac_stats_buff;
1272f856f099SNavdeep Parhar 	u32 i, n, size;
1273f856f099SNavdeep Parhar 	int rc = 0;
1274f856f099SNavdeep Parhar 
1275f856f099SNavdeep Parhar 	rc = padap->params.nports;
1276f856f099SNavdeep Parhar 	if (rc < 0)
1277f856f099SNavdeep Parhar 		goto err;
1278f856f099SNavdeep Parhar 
1279f856f099SNavdeep Parhar 	n = rc;
1280f856f099SNavdeep Parhar 	size = sizeof(struct struct_mac_stats_rev1);
1281f856f099SNavdeep Parhar 
1282f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1283f856f099SNavdeep Parhar 	if (rc)
1284f856f099SNavdeep Parhar 		goto err;
1285f856f099SNavdeep Parhar 
1286f856f099SNavdeep Parhar 	mac_stats_buff = (struct struct_mac_stats_rev1 *) scratch_buff.data;
1287f856f099SNavdeep Parhar 
1288f856f099SNavdeep Parhar 	mac_stats_buff->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
1289f856f099SNavdeep Parhar 	mac_stats_buff->ver_hdr.revision = CUDBG_MAC_STATS_REV;
1290f856f099SNavdeep Parhar 	mac_stats_buff->ver_hdr.size = sizeof(struct struct_mac_stats_rev1) -
1291f856f099SNavdeep Parhar 				       sizeof(struct cudbg_ver_hdr);
1292f856f099SNavdeep Parhar 
1293f856f099SNavdeep Parhar 	mac_stats_buff->port_count = n;
1294f856f099SNavdeep Parhar 	for (i = 0; i <  mac_stats_buff->port_count; i++)
1295f856f099SNavdeep Parhar 		t4_get_port_stats(padap, i, &mac_stats_buff->stats[i]);
1296f856f099SNavdeep Parhar 
1297f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1298f856f099SNavdeep Parhar 	if (rc)
1299f856f099SNavdeep Parhar 		goto err1;
1300f856f099SNavdeep Parhar 
1301f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1302f856f099SNavdeep Parhar err1:
1303f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1304f856f099SNavdeep Parhar err:
1305f856f099SNavdeep Parhar 	return rc;
1306f856f099SNavdeep Parhar }
1307f856f099SNavdeep Parhar 
collect_cim_pif_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1308f856f099SNavdeep Parhar static int collect_cim_pif_la(struct cudbg_init *pdbg_init,
1309f856f099SNavdeep Parhar 			      struct cudbg_buffer *dbg_buff,
1310f856f099SNavdeep Parhar 			      struct cudbg_error *cudbg_err)
1311f856f099SNavdeep Parhar {
1312f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1313f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1314f856f099SNavdeep Parhar 	struct cim_pif_la *cim_pif_la_buff;
1315f856f099SNavdeep Parhar 	u32 size;
1316f856f099SNavdeep Parhar 	int rc = 0;
1317f856f099SNavdeep Parhar 
1318f856f099SNavdeep Parhar 	size = sizeof(struct cim_pif_la) +
1319f856f099SNavdeep Parhar 	       2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
1320f856f099SNavdeep Parhar 
1321f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1322f856f099SNavdeep Parhar 	if (rc)
1323f856f099SNavdeep Parhar 		goto err;
1324f856f099SNavdeep Parhar 
1325f856f099SNavdeep Parhar 	cim_pif_la_buff = (struct cim_pif_la *) scratch_buff.data;
1326f856f099SNavdeep Parhar 	cim_pif_la_buff->size = CIM_PIFLA_SIZE;
1327f856f099SNavdeep Parhar 
1328f856f099SNavdeep Parhar 	t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
1329f856f099SNavdeep Parhar 			   (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
1330f856f099SNavdeep Parhar 			   NULL, NULL);
1331f856f099SNavdeep Parhar 
1332f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1333f856f099SNavdeep Parhar 	if (rc)
1334f856f099SNavdeep Parhar 		goto err1;
1335f856f099SNavdeep Parhar 
1336f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1337f856f099SNavdeep Parhar err1:
1338f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1339f856f099SNavdeep Parhar err:
1340f856f099SNavdeep Parhar 	return rc;
1341f856f099SNavdeep Parhar }
1342f856f099SNavdeep Parhar 
collect_tp_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1343f856f099SNavdeep Parhar static int collect_tp_la(struct cudbg_init *pdbg_init,
1344f856f099SNavdeep Parhar 			 struct cudbg_buffer *dbg_buff,
1345f856f099SNavdeep Parhar 			 struct cudbg_error *cudbg_err)
1346f856f099SNavdeep Parhar {
1347f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1348f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1349f856f099SNavdeep Parhar 	struct struct_tp_la *tp_la_buff;
1350f856f099SNavdeep Parhar 	u32 size;
1351f856f099SNavdeep Parhar 	int rc = 0;
1352f856f099SNavdeep Parhar 
1353f856f099SNavdeep Parhar 	size = sizeof(struct struct_tp_la) + TPLA_SIZE *  sizeof(u64);
1354f856f099SNavdeep Parhar 
1355f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1356f856f099SNavdeep Parhar 	if (rc)
1357f856f099SNavdeep Parhar 		goto err;
1358f856f099SNavdeep Parhar 
1359f856f099SNavdeep Parhar 	tp_la_buff = (struct struct_tp_la *) scratch_buff.data;
1360f856f099SNavdeep Parhar 
1361f856f099SNavdeep Parhar 	tp_la_buff->mode = G_DBGLAMODE(t4_read_reg(padap, A_TP_DBG_LA_CONFIG));
1362f856f099SNavdeep Parhar 	t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
1363f856f099SNavdeep Parhar 
1364f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1365f856f099SNavdeep Parhar 	if (rc)
1366f856f099SNavdeep Parhar 		goto err1;
1367f856f099SNavdeep Parhar 
1368f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1369f856f099SNavdeep Parhar err1:
1370f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1371f856f099SNavdeep Parhar err:
1372f856f099SNavdeep Parhar 	return rc;
1373f856f099SNavdeep Parhar }
1374f856f099SNavdeep Parhar 
collect_fcoe_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1375f856f099SNavdeep Parhar static int collect_fcoe_stats(struct cudbg_init *pdbg_init,
1376f856f099SNavdeep Parhar 			      struct cudbg_buffer *dbg_buff,
1377f856f099SNavdeep Parhar 			      struct cudbg_error *cudbg_err)
1378f856f099SNavdeep Parhar {
1379f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1380f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1381f856f099SNavdeep Parhar 	struct struct_tp_fcoe_stats  *tp_fcoe_stats_buff;
1382f856f099SNavdeep Parhar 	u32 size;
1383f856f099SNavdeep Parhar 	int rc = 0;
1384f856f099SNavdeep Parhar 
1385f856f099SNavdeep Parhar 	size = sizeof(struct struct_tp_fcoe_stats);
1386f856f099SNavdeep Parhar 
1387f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1388f856f099SNavdeep Parhar 	if (rc)
1389f856f099SNavdeep Parhar 		goto err;
1390f856f099SNavdeep Parhar 
1391f856f099SNavdeep Parhar 	tp_fcoe_stats_buff = (struct struct_tp_fcoe_stats *) scratch_buff.data;
1392f856f099SNavdeep Parhar 
1393f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
1394f856f099SNavdeep Parhar 	t4_get_fcoe_stats(padap, 0, &tp_fcoe_stats_buff->stats[0], 1);
1395f856f099SNavdeep Parhar 	t4_get_fcoe_stats(padap, 1, &tp_fcoe_stats_buff->stats[1], 1);
1396f856f099SNavdeep Parhar 	if (padap->chip_params->nchan == NCHAN) {
1397f856f099SNavdeep Parhar 		t4_get_fcoe_stats(padap, 2, &tp_fcoe_stats_buff->stats[2], 1);
1398f856f099SNavdeep Parhar 		t4_get_fcoe_stats(padap, 3, &tp_fcoe_stats_buff->stats[3], 1);
1399f856f099SNavdeep Parhar 	}
1400f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
1401f856f099SNavdeep Parhar 
1402f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1403f856f099SNavdeep Parhar 	if (rc)
1404f856f099SNavdeep Parhar 		goto err1;
1405f856f099SNavdeep Parhar 
1406f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1407f856f099SNavdeep Parhar err1:
1408f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1409f856f099SNavdeep Parhar err:
1410f856f099SNavdeep Parhar 	return rc;
1411f856f099SNavdeep Parhar }
1412f856f099SNavdeep Parhar 
collect_tp_err_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1413f856f099SNavdeep Parhar static int collect_tp_err_stats(struct cudbg_init *pdbg_init,
1414f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
1415f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
1416f856f099SNavdeep Parhar {
1417f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1418f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1419f856f099SNavdeep Parhar 	struct struct_tp_err_stats *tp_err_stats_buff;
1420f856f099SNavdeep Parhar 	u32 size;
1421f856f099SNavdeep Parhar 	int rc = 0;
1422f856f099SNavdeep Parhar 
1423f856f099SNavdeep Parhar 	size = sizeof(struct struct_tp_err_stats);
1424f856f099SNavdeep Parhar 
1425f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1426f856f099SNavdeep Parhar 	if (rc)
1427f856f099SNavdeep Parhar 		goto err;
1428f856f099SNavdeep Parhar 
1429f856f099SNavdeep Parhar 	tp_err_stats_buff = (struct struct_tp_err_stats *) scratch_buff.data;
1430f856f099SNavdeep Parhar 
1431f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
1432f856f099SNavdeep Parhar 	t4_tp_get_err_stats(padap, &tp_err_stats_buff->stats, 1);
1433f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
1434f856f099SNavdeep Parhar 	tp_err_stats_buff->nchan = padap->chip_params->nchan;
1435f856f099SNavdeep Parhar 
1436f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1437f856f099SNavdeep Parhar 	if (rc)
1438f856f099SNavdeep Parhar 		goto err1;
1439f856f099SNavdeep Parhar 
1440f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1441f856f099SNavdeep Parhar err1:
1442f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1443f856f099SNavdeep Parhar err:
1444f856f099SNavdeep Parhar 	return rc;
1445f856f099SNavdeep Parhar }
1446f856f099SNavdeep Parhar 
collect_tcp_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1447f856f099SNavdeep Parhar static int collect_tcp_stats(struct cudbg_init *pdbg_init,
1448f856f099SNavdeep Parhar 			     struct cudbg_buffer *dbg_buff,
1449f856f099SNavdeep Parhar 			     struct cudbg_error *cudbg_err)
1450f856f099SNavdeep Parhar {
1451f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1452f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1453f856f099SNavdeep Parhar 	struct struct_tcp_stats *tcp_stats_buff;
1454f856f099SNavdeep Parhar 	u32 size;
1455f856f099SNavdeep Parhar 	int rc = 0;
1456f856f099SNavdeep Parhar 
1457f856f099SNavdeep Parhar 	size = sizeof(struct struct_tcp_stats);
1458f856f099SNavdeep Parhar 
1459f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1460f856f099SNavdeep Parhar 	if (rc)
1461f856f099SNavdeep Parhar 		goto err;
1462f856f099SNavdeep Parhar 
1463f856f099SNavdeep Parhar 	tcp_stats_buff = (struct struct_tcp_stats *) scratch_buff.data;
1464f856f099SNavdeep Parhar 
1465f856f099SNavdeep Parhar 	/* spin_lock(&padap->stats_lock);	TODO*/
1466f856f099SNavdeep Parhar 	t4_tp_get_tcp_stats(padap, &tcp_stats_buff->v4, &tcp_stats_buff->v6, 1);
1467f856f099SNavdeep Parhar 	/* spin_unlock(&padap->stats_lock);	TODO*/
1468f856f099SNavdeep Parhar 
1469f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1470f856f099SNavdeep Parhar 	if (rc)
1471f856f099SNavdeep Parhar 		goto err1;
1472f856f099SNavdeep Parhar 
1473f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1474f856f099SNavdeep Parhar err1:
1475f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1476f856f099SNavdeep Parhar err:
1477f856f099SNavdeep Parhar 	return rc;
1478f856f099SNavdeep Parhar }
1479f856f099SNavdeep Parhar 
collect_hw_sched(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1480f856f099SNavdeep Parhar static int collect_hw_sched(struct cudbg_init *pdbg_init,
1481f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1482f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1483f856f099SNavdeep Parhar {
1484f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1485f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1486f856f099SNavdeep Parhar 	struct struct_hw_sched *hw_sched_buff;
1487f856f099SNavdeep Parhar 	u32 size;
1488f856f099SNavdeep Parhar 	int i, rc = 0;
1489f856f099SNavdeep Parhar 
1490f856f099SNavdeep Parhar 	if (!padap->params.vpd.cclk) {
1491f856f099SNavdeep Parhar 		rc =  CUDBG_STATUS_CCLK_NOT_DEFINED;
1492f856f099SNavdeep Parhar 		goto err;
1493f856f099SNavdeep Parhar 	}
1494f856f099SNavdeep Parhar 
1495f856f099SNavdeep Parhar 	size = sizeof(struct struct_hw_sched);
1496f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1497f856f099SNavdeep Parhar 	if (rc)
1498f856f099SNavdeep Parhar 		goto err;
1499f856f099SNavdeep Parhar 
1500f856f099SNavdeep Parhar 	hw_sched_buff = (struct struct_hw_sched *) scratch_buff.data;
1501f856f099SNavdeep Parhar 
1502f856f099SNavdeep Parhar 	hw_sched_buff->map = t4_read_reg(padap, A_TP_TX_MOD_QUEUE_REQ_MAP);
1503f856f099SNavdeep Parhar 	hw_sched_buff->mode = G_TIMERMODE(t4_read_reg(padap, A_TP_MOD_CONFIG));
1504f856f099SNavdeep Parhar 	t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
1505f856f099SNavdeep Parhar 
1506f856f099SNavdeep Parhar 	for (i = 0; i < NTX_SCHED; ++i) {
1507f856f099SNavdeep Parhar 		t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
1508f856f099SNavdeep Parhar 		    &hw_sched_buff->ipg[i], 1);
1509f856f099SNavdeep Parhar 	}
1510f856f099SNavdeep Parhar 
1511f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1512f856f099SNavdeep Parhar 	if (rc)
1513f856f099SNavdeep Parhar 		goto err1;
1514f856f099SNavdeep Parhar 
1515f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1516f856f099SNavdeep Parhar err1:
1517f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1518f856f099SNavdeep Parhar err:
1519f856f099SNavdeep Parhar 	return rc;
1520f856f099SNavdeep Parhar }
1521f856f099SNavdeep Parhar 
collect_pm_stats(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1522f856f099SNavdeep Parhar static int collect_pm_stats(struct cudbg_init *pdbg_init,
1523f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1524f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1525f856f099SNavdeep Parhar {
1526f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1527f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1528f856f099SNavdeep Parhar 	struct struct_pm_stats *pm_stats_buff;
1529f856f099SNavdeep Parhar 	u32 size;
1530f856f099SNavdeep Parhar 	int rc = 0;
1531f856f099SNavdeep Parhar 
1532f856f099SNavdeep Parhar 	size = sizeof(struct struct_pm_stats);
1533f856f099SNavdeep Parhar 
1534f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1535f856f099SNavdeep Parhar 	if (rc)
1536f856f099SNavdeep Parhar 		goto err;
1537f856f099SNavdeep Parhar 
1538f856f099SNavdeep Parhar 	pm_stats_buff = (struct struct_pm_stats *) scratch_buff.data;
1539f856f099SNavdeep Parhar 
1540f856f099SNavdeep Parhar 	t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
1541f856f099SNavdeep Parhar 	t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
1542f856f099SNavdeep Parhar 
1543f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1544f856f099SNavdeep Parhar 	if (rc)
1545f856f099SNavdeep Parhar 		goto err1;
1546f856f099SNavdeep Parhar 
1547f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1548f856f099SNavdeep Parhar err1:
1549f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1550f856f099SNavdeep Parhar err:
1551f856f099SNavdeep Parhar 	return rc;
1552f856f099SNavdeep Parhar }
1553f856f099SNavdeep Parhar 
collect_path_mtu(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1554f856f099SNavdeep Parhar static int collect_path_mtu(struct cudbg_init *pdbg_init,
1555f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
1556f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
1557f856f099SNavdeep Parhar {
1558f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1559f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1560f856f099SNavdeep Parhar 	u32 size;
1561f856f099SNavdeep Parhar 	int rc = 0;
1562f856f099SNavdeep Parhar 
1563f856f099SNavdeep Parhar 	size = NMTUS  * sizeof(u16);
1564f856f099SNavdeep Parhar 
1565f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1566f856f099SNavdeep Parhar 	if (rc)
1567f856f099SNavdeep Parhar 		goto err;
1568f856f099SNavdeep Parhar 
1569f856f099SNavdeep Parhar 	t4_read_mtu_tbl(padap, (u16 *)scratch_buff.data, NULL);
1570f856f099SNavdeep Parhar 
1571f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1572f856f099SNavdeep Parhar 	if (rc)
1573f856f099SNavdeep Parhar 		goto err1;
1574f856f099SNavdeep Parhar 
1575f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1576f856f099SNavdeep Parhar err1:
1577f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1578f856f099SNavdeep Parhar err:
1579f856f099SNavdeep Parhar 	return rc;
1580f856f099SNavdeep Parhar }
1581f856f099SNavdeep Parhar 
collect_rss_key(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1582f856f099SNavdeep Parhar static int collect_rss_key(struct cudbg_init *pdbg_init,
1583f856f099SNavdeep Parhar 			   struct cudbg_buffer *dbg_buff,
1584f856f099SNavdeep Parhar 			   struct cudbg_error *cudbg_err)
1585f856f099SNavdeep Parhar {
1586f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1587f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1588f856f099SNavdeep Parhar 	u32 size;
1589f856f099SNavdeep Parhar 
1590f856f099SNavdeep Parhar 	int rc = 0;
1591f856f099SNavdeep Parhar 
1592f856f099SNavdeep Parhar 	size = 10  * sizeof(u32);
1593f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1594f856f099SNavdeep Parhar 	if (rc)
1595f856f099SNavdeep Parhar 		goto err;
1596f856f099SNavdeep Parhar 
1597f856f099SNavdeep Parhar 	t4_read_rss_key(padap, (u32 *)scratch_buff.data, 1);
1598f856f099SNavdeep Parhar 
1599f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1600f856f099SNavdeep Parhar 	if (rc)
1601f856f099SNavdeep Parhar 		goto err1;
1602f856f099SNavdeep Parhar 
1603f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1604f856f099SNavdeep Parhar err1:
1605f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1606f856f099SNavdeep Parhar err:
1607f856f099SNavdeep Parhar 	return rc;
1608f856f099SNavdeep Parhar }
1609f856f099SNavdeep Parhar 
collect_rss_config(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1610f856f099SNavdeep Parhar static int collect_rss_config(struct cudbg_init *pdbg_init,
1611f856f099SNavdeep Parhar 			      struct cudbg_buffer *dbg_buff,
1612f856f099SNavdeep Parhar 			      struct cudbg_error *cudbg_err)
1613f856f099SNavdeep Parhar {
1614f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1615f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1616f856f099SNavdeep Parhar 	struct rss_config *rss_conf;
1617f856f099SNavdeep Parhar 	int rc;
1618f856f099SNavdeep Parhar 	u32 size;
1619f856f099SNavdeep Parhar 
1620f856f099SNavdeep Parhar 	size = sizeof(struct rss_config);
1621f856f099SNavdeep Parhar 
1622f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1623f856f099SNavdeep Parhar 	if (rc)
1624f856f099SNavdeep Parhar 		goto err;
1625f856f099SNavdeep Parhar 
1626f856f099SNavdeep Parhar 	rss_conf =  (struct rss_config *)scratch_buff.data;
1627f856f099SNavdeep Parhar 
1628f856f099SNavdeep Parhar 	rss_conf->tp_rssconf = t4_read_reg(padap, A_TP_RSS_CONFIG);
1629f856f099SNavdeep Parhar 	rss_conf->tp_rssconf_tnl = t4_read_reg(padap, A_TP_RSS_CONFIG_TNL);
1630f856f099SNavdeep Parhar 	rss_conf->tp_rssconf_ofd = t4_read_reg(padap, A_TP_RSS_CONFIG_OFD);
1631f856f099SNavdeep Parhar 	rss_conf->tp_rssconf_syn = t4_read_reg(padap, A_TP_RSS_CONFIG_SYN);
1632f856f099SNavdeep Parhar 	rss_conf->tp_rssconf_vrt = t4_read_reg(padap, A_TP_RSS_CONFIG_VRT);
1633f856f099SNavdeep Parhar 	rss_conf->tp_rssconf_cng = t4_read_reg(padap, A_TP_RSS_CONFIG_CNG);
1634f856f099SNavdeep Parhar 	rss_conf->chip = padap->params.chipid;
1635f856f099SNavdeep Parhar 
1636f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1637f856f099SNavdeep Parhar 	if (rc)
1638f856f099SNavdeep Parhar 		goto err1;
1639f856f099SNavdeep Parhar 
1640f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1641f856f099SNavdeep Parhar 
1642f856f099SNavdeep Parhar err1:
1643f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1644f856f099SNavdeep Parhar err:
1645f856f099SNavdeep Parhar 	return rc;
1646f856f099SNavdeep Parhar }
1647f856f099SNavdeep Parhar 
collect_rss_vf_config(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1648f856f099SNavdeep Parhar static int collect_rss_vf_config(struct cudbg_init *pdbg_init,
1649f856f099SNavdeep Parhar 				 struct cudbg_buffer *dbg_buff,
1650f856f099SNavdeep Parhar 				 struct cudbg_error *cudbg_err)
1651f856f099SNavdeep Parhar {
1652f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1653f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1654f856f099SNavdeep Parhar 	struct rss_vf_conf *vfconf;
1655f856f099SNavdeep Parhar 	int vf, rc, vf_count;
1656f856f099SNavdeep Parhar 	u32 size;
1657f856f099SNavdeep Parhar 
1658f856f099SNavdeep Parhar 	vf_count = padap->chip_params->vfcount;
1659f856f099SNavdeep Parhar 	size = vf_count * sizeof(*vfconf);
1660f856f099SNavdeep Parhar 
1661f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1662f856f099SNavdeep Parhar 	if (rc)
1663f856f099SNavdeep Parhar 		goto err;
1664f856f099SNavdeep Parhar 
1665f856f099SNavdeep Parhar 	vfconf =  (struct rss_vf_conf *)scratch_buff.data;
1666f856f099SNavdeep Parhar 
1667f856f099SNavdeep Parhar 	for (vf = 0; vf < vf_count; vf++) {
1668f856f099SNavdeep Parhar 		t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
1669f856f099SNavdeep Parhar 				      &vfconf[vf].rss_vf_vfh, 1);
1670f856f099SNavdeep Parhar 	}
1671f856f099SNavdeep Parhar 
1672f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1673f856f099SNavdeep Parhar 	if (rc)
1674f856f099SNavdeep Parhar 		goto err1;
1675f856f099SNavdeep Parhar 
1676f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1677f856f099SNavdeep Parhar 
1678f856f099SNavdeep Parhar err1:
1679f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1680f856f099SNavdeep Parhar err:
1681f856f099SNavdeep Parhar 	return rc;
1682f856f099SNavdeep Parhar }
1683f856f099SNavdeep Parhar 
collect_rss_pf_config(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1684f856f099SNavdeep Parhar static int collect_rss_pf_config(struct cudbg_init *pdbg_init,
1685f856f099SNavdeep Parhar 				 struct cudbg_buffer *dbg_buff,
1686f856f099SNavdeep Parhar 				 struct cudbg_error *cudbg_err)
1687f856f099SNavdeep Parhar {
1688f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1689f856f099SNavdeep Parhar 	struct rss_pf_conf *pfconf;
1690f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1691f856f099SNavdeep Parhar 	u32 rss_pf_map, rss_pf_mask, size;
1692f856f099SNavdeep Parhar 	int pf, rc;
1693f856f099SNavdeep Parhar 
1694f856f099SNavdeep Parhar 	size = 8  * sizeof(*pfconf);
1695f856f099SNavdeep Parhar 
1696f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1697f856f099SNavdeep Parhar 	if (rc)
1698f856f099SNavdeep Parhar 		goto err;
1699f856f099SNavdeep Parhar 
1700f856f099SNavdeep Parhar 	pfconf =  (struct rss_pf_conf *)scratch_buff.data;
1701f856f099SNavdeep Parhar 
1702f856f099SNavdeep Parhar 	rss_pf_map = t4_read_rss_pf_map(padap, 1);
1703f856f099SNavdeep Parhar 	rss_pf_mask = t4_read_rss_pf_mask(padap, 1);
1704f856f099SNavdeep Parhar 
1705f856f099SNavdeep Parhar 	for (pf = 0; pf < 8; pf++) {
1706f856f099SNavdeep Parhar 		pfconf[pf].rss_pf_map = rss_pf_map;
1707f856f099SNavdeep Parhar 		pfconf[pf].rss_pf_mask = rss_pf_mask;
1708f856f099SNavdeep Parhar 		/* no return val */
1709f856f099SNavdeep Parhar 		t4_read_rss_pf_config(padap, pf, &pfconf[pf].rss_pf_config, 1);
1710f856f099SNavdeep Parhar 	}
1711f856f099SNavdeep Parhar 
1712f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1713f856f099SNavdeep Parhar 	if (rc)
1714f856f099SNavdeep Parhar 		goto err1;
1715f856f099SNavdeep Parhar 
1716f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
1717f856f099SNavdeep Parhar err1:
1718f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1719f856f099SNavdeep Parhar err:
1720f856f099SNavdeep Parhar 	return rc;
1721f856f099SNavdeep Parhar }
1722f856f099SNavdeep Parhar 
check_valid(u32 * buf,int type)1723f856f099SNavdeep Parhar static int check_valid(u32 *buf, int type)
1724f856f099SNavdeep Parhar {
1725f856f099SNavdeep Parhar 	int index;
1726f856f099SNavdeep Parhar 	int bit;
1727f856f099SNavdeep Parhar 	int bit_pos = 0;
1728f856f099SNavdeep Parhar 
1729f856f099SNavdeep Parhar 	switch (type) {
1730f856f099SNavdeep Parhar 	case CTXT_EGRESS:
1731f856f099SNavdeep Parhar 		bit_pos = 176;
1732f856f099SNavdeep Parhar 		break;
1733f856f099SNavdeep Parhar 	case CTXT_INGRESS:
1734f856f099SNavdeep Parhar 		bit_pos = 141;
1735f856f099SNavdeep Parhar 		break;
1736f856f099SNavdeep Parhar 	case CTXT_FLM:
1737f856f099SNavdeep Parhar 		bit_pos = 89;
1738f856f099SNavdeep Parhar 		break;
1739f856f099SNavdeep Parhar 	}
1740f856f099SNavdeep Parhar 	index = bit_pos / 32;
1741f856f099SNavdeep Parhar 	bit =  bit_pos % 32;
1742f856f099SNavdeep Parhar 
1743f856f099SNavdeep Parhar 	return buf[index] & (1U << bit);
1744f856f099SNavdeep Parhar }
1745f856f099SNavdeep Parhar 
1746f856f099SNavdeep Parhar /**
1747f856f099SNavdeep Parhar  * Get EGRESS, INGRESS, FLM, and CNM max qid.
1748f856f099SNavdeep Parhar  *
1749f856f099SNavdeep Parhar  * For EGRESS and INGRESS, do the following calculation.
1750f856f099SNavdeep Parhar  * max_qid = (DBQ/IMSG context region size in bytes) /
1751f856f099SNavdeep Parhar  *	     (size of context in bytes).
1752f856f099SNavdeep Parhar  *
1753f856f099SNavdeep Parhar  * For FLM, do the following calculation.
1754f856f099SNavdeep Parhar  * max_qid = (FLM cache region size in bytes) /
1755f856f099SNavdeep Parhar  *	     ((number of pointers cached in EDRAM) * 8 (bytes per pointer)).
1756f856f099SNavdeep Parhar  *
1757f856f099SNavdeep Parhar  * There's a 1-to-1 mapping between FLM and CNM if there's no header splitting
1758f856f099SNavdeep Parhar  * enabled; i.e., max CNM qid is equal to max FLM qid. However, if header
1759f856f099SNavdeep Parhar  * splitting is enabled, then max CNM qid is half of max FLM qid.
1760f856f099SNavdeep Parhar  */
get_max_ctxt_qid(struct adapter * padap,struct struct_meminfo * meminfo,u32 * max_ctx_qid,u8 nelem)1761f856f099SNavdeep Parhar static int get_max_ctxt_qid(struct adapter *padap,
1762f856f099SNavdeep Parhar 			    struct struct_meminfo *meminfo,
1763f856f099SNavdeep Parhar 			    u32 *max_ctx_qid, u8 nelem)
1764f856f099SNavdeep Parhar {
1765f856f099SNavdeep Parhar 	u32 i, idx, found = 0;
1766f856f099SNavdeep Parhar 
1767f856f099SNavdeep Parhar 	if (nelem != (CTXT_CNM + 1))
1768f856f099SNavdeep Parhar 		return -EINVAL;
1769f856f099SNavdeep Parhar 
1770f856f099SNavdeep Parhar 	for (i = 0; i < meminfo->mem_c; i++) {
1771f856f099SNavdeep Parhar 		if (meminfo->mem[i].idx >= ARRAY_SIZE(region))
1772f856f099SNavdeep Parhar 			continue;                        /* skip holes */
1773f856f099SNavdeep Parhar 
1774f856f099SNavdeep Parhar 		idx = meminfo->mem[i].idx;
1775f856f099SNavdeep Parhar 		/* Get DBQ, IMSG, and FLM context region size */
1776f856f099SNavdeep Parhar 		if (idx <= CTXT_FLM) {
1777f856f099SNavdeep Parhar 			if (!(meminfo->mem[i].limit))
1778f856f099SNavdeep Parhar 				meminfo->mem[i].limit =
1779f856f099SNavdeep Parhar 					i < meminfo->mem_c - 1 ?
1780f856f099SNavdeep Parhar 					meminfo->mem[i + 1].base - 1 : ~0;
1781f856f099SNavdeep Parhar 
1782f856f099SNavdeep Parhar 			if (idx < CTXT_FLM) {
1783f856f099SNavdeep Parhar 				/* Get EGRESS and INGRESS max qid. */
1784f856f099SNavdeep Parhar 				max_ctx_qid[idx] = (meminfo->mem[i].limit -
1785f856f099SNavdeep Parhar 						    meminfo->mem[i].base + 1) /
1786f856f099SNavdeep Parhar 						   CUDBG_CTXT_SIZE_BYTES;
1787f856f099SNavdeep Parhar 				found++;
1788f856f099SNavdeep Parhar 			} else {
1789f856f099SNavdeep Parhar 				/* Get FLM and CNM max qid. */
1790f856f099SNavdeep Parhar 				u32 value, edram_ptr_count;
1791f856f099SNavdeep Parhar 				u8 bytes_per_ptr = 8;
1792f856f099SNavdeep Parhar 				u8 nohdr;
1793f856f099SNavdeep Parhar 
1794f856f099SNavdeep Parhar 				value = t4_read_reg(padap, A_SGE_FLM_CFG);
1795f856f099SNavdeep Parhar 
1796f856f099SNavdeep Parhar 				/* Check if header splitting is enabled. */
1797f856f099SNavdeep Parhar 				nohdr = (value >> S_NOHDR) & 1U;
1798f856f099SNavdeep Parhar 
1799f856f099SNavdeep Parhar 				/* Get the number of pointers in EDRAM per
1800f856f099SNavdeep Parhar 				 * qid in units of 32.
1801f856f099SNavdeep Parhar 				 */
1802f856f099SNavdeep Parhar 				edram_ptr_count = 32 *
1803f856f099SNavdeep Parhar 						  (1U << G_EDRAMPTRCNT(value));
1804f856f099SNavdeep Parhar 
1805f856f099SNavdeep Parhar 				/* EDRAMPTRCNT value of 3 is reserved.
1806f856f099SNavdeep Parhar 				 * So don't exceed 128.
1807f856f099SNavdeep Parhar 				 */
1808f856f099SNavdeep Parhar 				if (edram_ptr_count > 128)
1809f856f099SNavdeep Parhar 					edram_ptr_count = 128;
1810f856f099SNavdeep Parhar 
1811f856f099SNavdeep Parhar 				max_ctx_qid[idx] = (meminfo->mem[i].limit -
1812f856f099SNavdeep Parhar 						    meminfo->mem[i].base + 1) /
1813f856f099SNavdeep Parhar 						   (edram_ptr_count *
1814f856f099SNavdeep Parhar 						    bytes_per_ptr);
1815f856f099SNavdeep Parhar 				found++;
1816f856f099SNavdeep Parhar 
1817f856f099SNavdeep Parhar 				/* CNM has 1-to-1 mapping with FLM.
1818f856f099SNavdeep Parhar 				 * However, if header splitting is enabled,
1819f856f099SNavdeep Parhar 				 * then max CNM qid is half of max FLM qid.
1820f856f099SNavdeep Parhar 				 */
1821f856f099SNavdeep Parhar 				max_ctx_qid[CTXT_CNM] = nohdr ?
1822f856f099SNavdeep Parhar 							max_ctx_qid[idx] :
1823f856f099SNavdeep Parhar 							max_ctx_qid[idx] >> 1;
1824f856f099SNavdeep Parhar 
1825f856f099SNavdeep Parhar 				/* One more increment for CNM */
1826f856f099SNavdeep Parhar 				found++;
1827f856f099SNavdeep Parhar 			}
1828f856f099SNavdeep Parhar 		}
1829f856f099SNavdeep Parhar 		if (found == nelem)
1830f856f099SNavdeep Parhar 			break;
1831f856f099SNavdeep Parhar 	}
1832f856f099SNavdeep Parhar 
1833f856f099SNavdeep Parhar 	/* Sanity check. Ensure the values are within known max. */
1834f856f099SNavdeep Parhar 	max_ctx_qid[CTXT_EGRESS] = min_t(u32, max_ctx_qid[CTXT_EGRESS],
1835f856f099SNavdeep Parhar 					 M_CTXTQID);
1836f856f099SNavdeep Parhar 	max_ctx_qid[CTXT_INGRESS] = min_t(u32, max_ctx_qid[CTXT_INGRESS],
1837f856f099SNavdeep Parhar 					  CUDBG_MAX_INGRESS_QIDS);
1838f856f099SNavdeep Parhar 	max_ctx_qid[CTXT_FLM] = min_t(u32, max_ctx_qid[CTXT_FLM],
1839f856f099SNavdeep Parhar 				      CUDBG_MAX_FL_QIDS);
1840f856f099SNavdeep Parhar 	max_ctx_qid[CTXT_CNM] = min_t(u32, max_ctx_qid[CTXT_CNM],
1841f856f099SNavdeep Parhar 				      CUDBG_MAX_CNM_QIDS);
1842f856f099SNavdeep Parhar 	return 0;
1843f856f099SNavdeep Parhar }
1844f856f099SNavdeep Parhar 
collect_dump_context(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1845f856f099SNavdeep Parhar static int collect_dump_context(struct cudbg_init *pdbg_init,
1846f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
1847f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
1848f856f099SNavdeep Parhar {
1849f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1850f856f099SNavdeep Parhar 	struct cudbg_buffer temp_buff;
1851f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1852f856f099SNavdeep Parhar 	u32 size = 0, next_offset = 0, total_size = 0;
1853f856f099SNavdeep Parhar 	struct cudbg_ch_cntxt *buff = NULL;
1854f856f099SNavdeep Parhar 	struct struct_meminfo meminfo;
1855f856f099SNavdeep Parhar 	int bytes = 0;
1856f856f099SNavdeep Parhar 	int rc = 0;
1857f856f099SNavdeep Parhar 	u32 i, j;
1858f856f099SNavdeep Parhar 	u32 max_ctx_qid[CTXT_CNM + 1];
1859f856f099SNavdeep Parhar 	bool limit_qid = false;
1860f856f099SNavdeep Parhar 	u32 qid_count = 0;
1861f856f099SNavdeep Parhar 
1862f856f099SNavdeep Parhar 	rc = fill_meminfo(padap, &meminfo);
1863f856f099SNavdeep Parhar 	if (rc)
1864f856f099SNavdeep Parhar 		goto err;
1865f856f099SNavdeep Parhar 
1866f856f099SNavdeep Parhar 	/* Get max valid qid for each type of queue */
1867f856f099SNavdeep Parhar 	rc = get_max_ctxt_qid(padap, &meminfo, max_ctx_qid, CTXT_CNM + 1);
1868f856f099SNavdeep Parhar 	if (rc)
1869f856f099SNavdeep Parhar 		goto err;
1870f856f099SNavdeep Parhar 
1871f856f099SNavdeep Parhar 	/* There are four types of queues. Collect context upto max
1872f856f099SNavdeep Parhar 	 * qid of each type of queue.
1873f856f099SNavdeep Parhar 	 */
1874f856f099SNavdeep Parhar 	for (i = CTXT_EGRESS; i <= CTXT_CNM; i++)
1875f856f099SNavdeep Parhar 		size += sizeof(struct cudbg_ch_cntxt) * max_ctx_qid[i];
1876f856f099SNavdeep Parhar 
1877f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1878f856f099SNavdeep Parhar 	if (rc == CUDBG_STATUS_NO_SCRATCH_MEM) {
1879f856f099SNavdeep Parhar 		/* Not enough scratch Memory available.
1880f856f099SNavdeep Parhar 		 * Collect context of at least CUDBG_LOWMEM_MAX_CTXT_QIDS
1881f856f099SNavdeep Parhar 		 * for each queue type.
1882f856f099SNavdeep Parhar 		 */
1883f856f099SNavdeep Parhar 		size = 0;
1884f856f099SNavdeep Parhar 		for (i = CTXT_EGRESS; i <= CTXT_CNM; i++)
1885f856f099SNavdeep Parhar 			size += sizeof(struct cudbg_ch_cntxt) *
1886f856f099SNavdeep Parhar 				CUDBG_LOWMEM_MAX_CTXT_QIDS;
1887f856f099SNavdeep Parhar 
1888f856f099SNavdeep Parhar 		limit_qid = true;
1889f856f099SNavdeep Parhar 		rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
1890f856f099SNavdeep Parhar 		if (rc)
1891f856f099SNavdeep Parhar 			goto err;
1892f856f099SNavdeep Parhar 	}
1893f856f099SNavdeep Parhar 
1894f856f099SNavdeep Parhar 	buff = (struct cudbg_ch_cntxt *)scratch_buff.data;
1895f856f099SNavdeep Parhar 
1896f856f099SNavdeep Parhar 	/* Collect context data */
1897f856f099SNavdeep Parhar 	for (i = CTXT_EGRESS; i <= CTXT_FLM; i++) {
1898f856f099SNavdeep Parhar 		qid_count = 0;
1899f856f099SNavdeep Parhar 		for (j = 0; j < max_ctx_qid[i]; j++) {
1900f856f099SNavdeep Parhar 			read_sge_ctxt(pdbg_init, j, i, buff->data);
1901f856f099SNavdeep Parhar 
1902f856f099SNavdeep Parhar 			rc = check_valid(buff->data, i);
1903f856f099SNavdeep Parhar 			if (rc) {
1904f856f099SNavdeep Parhar 				buff->cntxt_type = i;
1905f856f099SNavdeep Parhar 				buff->cntxt_id = j;
1906f856f099SNavdeep Parhar 				buff++;
1907f856f099SNavdeep Parhar 				total_size += sizeof(struct cudbg_ch_cntxt);
1908f856f099SNavdeep Parhar 
1909f856f099SNavdeep Parhar 				if (i == CTXT_FLM) {
1910f856f099SNavdeep Parhar 					read_sge_ctxt(pdbg_init, j, CTXT_CNM,
1911f856f099SNavdeep Parhar 						      buff->data);
1912f856f099SNavdeep Parhar 					buff->cntxt_type = CTXT_CNM;
1913f856f099SNavdeep Parhar 					buff->cntxt_id = j;
1914f856f099SNavdeep Parhar 					buff++;
1915f856f099SNavdeep Parhar 					total_size +=
1916f856f099SNavdeep Parhar 						sizeof(struct cudbg_ch_cntxt);
1917f856f099SNavdeep Parhar 				}
1918f856f099SNavdeep Parhar 				qid_count++;
1919f856f099SNavdeep Parhar 			}
1920f856f099SNavdeep Parhar 
1921f856f099SNavdeep Parhar 			/* If there's not enough space to collect more qids,
1922f856f099SNavdeep Parhar 			 * then bail and move on to next queue type.
1923f856f099SNavdeep Parhar 			 */
1924f856f099SNavdeep Parhar 			if (limit_qid &&
1925f856f099SNavdeep Parhar 			    qid_count >= CUDBG_LOWMEM_MAX_CTXT_QIDS)
1926f856f099SNavdeep Parhar 				break;
1927f856f099SNavdeep Parhar 		}
1928f856f099SNavdeep Parhar 	}
1929f856f099SNavdeep Parhar 
1930f856f099SNavdeep Parhar 	scratch_buff.size = total_size;
1931f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
1932f856f099SNavdeep Parhar 	if (rc)
1933f856f099SNavdeep Parhar 		goto err1;
1934f856f099SNavdeep Parhar 
1935f856f099SNavdeep Parhar 	/* Splitting buffer and writing in terms of CUDBG_CHUNK_SIZE */
1936f856f099SNavdeep Parhar 	while (total_size > 0) {
1937f856f099SNavdeep Parhar 		bytes = min_t(unsigned long, (unsigned long)total_size,
1938f856f099SNavdeep Parhar 			      (unsigned long)CUDBG_CHUNK_SIZE);
1939f856f099SNavdeep Parhar 		temp_buff.size = bytes;
1940f856f099SNavdeep Parhar 		temp_buff.data = (void *)((char *)scratch_buff.data +
1941f856f099SNavdeep Parhar 					  next_offset);
1942f856f099SNavdeep Parhar 
1943f856f099SNavdeep Parhar 		rc = compress_buff(&temp_buff, dbg_buff);
1944f856f099SNavdeep Parhar 		if (rc)
1945f856f099SNavdeep Parhar 			goto err1;
1946f856f099SNavdeep Parhar 
1947f856f099SNavdeep Parhar 		total_size -= bytes;
1948f856f099SNavdeep Parhar 		next_offset += bytes;
1949f856f099SNavdeep Parhar 	}
1950f856f099SNavdeep Parhar 
1951f856f099SNavdeep Parhar err1:
1952f856f099SNavdeep Parhar 	scratch_buff.size = size;
1953f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
1954f856f099SNavdeep Parhar err:
1955f856f099SNavdeep Parhar 	return rc;
1956f856f099SNavdeep Parhar }
1957f856f099SNavdeep Parhar 
collect_fw_devlog(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)1958f856f099SNavdeep Parhar static int collect_fw_devlog(struct cudbg_init *pdbg_init,
1959f856f099SNavdeep Parhar 			     struct cudbg_buffer *dbg_buff,
1960f856f099SNavdeep Parhar 			     struct cudbg_error *cudbg_err)
1961f856f099SNavdeep Parhar {
1962f856f099SNavdeep Parhar #ifdef notyet
1963f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
1964f856f099SNavdeep Parhar 	struct devlog_params *dparams = &padap->params.devlog;
1965f856f099SNavdeep Parhar 	struct cudbg_param *params = NULL;
1966f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
1967f856f099SNavdeep Parhar 	u32 offset;
1968f856f099SNavdeep Parhar 	int rc = 0, i;
1969f856f099SNavdeep Parhar 
1970f856f099SNavdeep Parhar 	rc = t4_init_devlog_params(padap, 1);
1971f856f099SNavdeep Parhar 
1972f856f099SNavdeep Parhar 	if (rc < 0) {
1973f856f099SNavdeep Parhar 		pdbg_init->print("%s(), t4_init_devlog_params failed!, rc: "\
1974f856f099SNavdeep Parhar 				 "%d\n", __func__, rc);
1975f856f099SNavdeep Parhar 		for (i = 0; i < pdbg_init->dbg_params_cnt; i++) {
1976f856f099SNavdeep Parhar 			if (pdbg_init->dbg_params[i].param_type ==
1977f856f099SNavdeep Parhar 			    CUDBG_DEVLOG_PARAM) {
1978f856f099SNavdeep Parhar 				params = &pdbg_init->dbg_params[i];
1979f856f099SNavdeep Parhar 				break;
1980f856f099SNavdeep Parhar 			}
1981f856f099SNavdeep Parhar 		}
1982f856f099SNavdeep Parhar 
1983f856f099SNavdeep Parhar 		if (params) {
1984f856f099SNavdeep Parhar 			dparams->memtype = params->u.devlog_param.memtype;
1985f856f099SNavdeep Parhar 			dparams->start = params->u.devlog_param.start;
1986f856f099SNavdeep Parhar 			dparams->size = params->u.devlog_param.size;
1987f856f099SNavdeep Parhar 		} else {
1988f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
1989f856f099SNavdeep Parhar 			goto err;
1990f856f099SNavdeep Parhar 		}
1991f856f099SNavdeep Parhar 	}
1992f856f099SNavdeep Parhar 
1993f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, dparams->size, &scratch_buff);
1994f856f099SNavdeep Parhar 
1995f856f099SNavdeep Parhar 	if (rc)
1996f856f099SNavdeep Parhar 		goto err;
1997f856f099SNavdeep Parhar 
1998f856f099SNavdeep Parhar 	/* Collect FW devlog */
1999f856f099SNavdeep Parhar 	if (dparams->start != 0) {
2000f856f099SNavdeep Parhar 		offset = scratch_buff.offset;
2001f856f099SNavdeep Parhar 		rc = t4_memory_rw(padap, padap->params.drv_memwin,
2002f856f099SNavdeep Parhar 				  dparams->memtype, dparams->start,
2003f856f099SNavdeep Parhar 				  dparams->size,
2004f856f099SNavdeep Parhar 				  (__be32 *)((char *)scratch_buff.data +
2005f856f099SNavdeep Parhar 					     offset), 1);
2006f856f099SNavdeep Parhar 
2007f856f099SNavdeep Parhar 		if (rc) {
2008f856f099SNavdeep Parhar 			pdbg_init->print("%s(), t4_memory_rw failed!, rc: "\
2009f856f099SNavdeep Parhar 					 "%d\n", __func__, rc);
2010f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
2011f856f099SNavdeep Parhar 			goto err1;
2012f856f099SNavdeep Parhar 		}
2013f856f099SNavdeep Parhar 	}
2014f856f099SNavdeep Parhar 
2015f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2016f856f099SNavdeep Parhar 
2017f856f099SNavdeep Parhar 	if (rc)
2018f856f099SNavdeep Parhar 		goto err1;
2019f856f099SNavdeep Parhar 
2020f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2021f856f099SNavdeep Parhar 
2022f856f099SNavdeep Parhar err1:
2023f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2024f856f099SNavdeep Parhar err:
2025f856f099SNavdeep Parhar 	return rc;
2026f856f099SNavdeep Parhar #endif
20276cc4520bSNavdeep Parhar 	return (CUDBG_STATUS_NOT_IMPLEMENTED);
2028f856f099SNavdeep Parhar }
2029f856f099SNavdeep Parhar /* CIM OBQ */
2030f856f099SNavdeep Parhar 
collect_cim_obq_ulp0(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2031f856f099SNavdeep Parhar static int collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
2032f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2033f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2034f856f099SNavdeep Parhar {
2035f856f099SNavdeep Parhar 	int rc = 0, qid = 0;
2036f856f099SNavdeep Parhar 
2037f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2038f856f099SNavdeep Parhar 
2039f856f099SNavdeep Parhar 	return rc;
2040f856f099SNavdeep Parhar }
2041f856f099SNavdeep Parhar 
collect_cim_obq_ulp1(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2042f856f099SNavdeep Parhar static int collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
2043f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2044f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2045f856f099SNavdeep Parhar {
2046f856f099SNavdeep Parhar 	int rc = 0, qid = 1;
2047f856f099SNavdeep Parhar 
2048f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2049f856f099SNavdeep Parhar 
2050f856f099SNavdeep Parhar 	return rc;
2051f856f099SNavdeep Parhar }
2052f856f099SNavdeep Parhar 
collect_cim_obq_ulp2(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2053f856f099SNavdeep Parhar static int collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
2054f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2055f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2056f856f099SNavdeep Parhar {
2057f856f099SNavdeep Parhar 	int rc = 0, qid = 2;
2058f856f099SNavdeep Parhar 
2059f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2060f856f099SNavdeep Parhar 
2061f856f099SNavdeep Parhar 	return rc;
2062f856f099SNavdeep Parhar }
2063f856f099SNavdeep Parhar 
collect_cim_obq_ulp3(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2064f856f099SNavdeep Parhar static int collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
2065f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2066f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2067f856f099SNavdeep Parhar {
2068f856f099SNavdeep Parhar 	int rc = 0, qid = 3;
2069f856f099SNavdeep Parhar 
2070f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2071f856f099SNavdeep Parhar 
2072f856f099SNavdeep Parhar 	return rc;
2073f856f099SNavdeep Parhar }
2074f856f099SNavdeep Parhar 
collect_cim_obq_sge(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2075f856f099SNavdeep Parhar static int collect_cim_obq_sge(struct cudbg_init *pdbg_init,
2076f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2077f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2078f856f099SNavdeep Parhar {
2079f856f099SNavdeep Parhar 	int rc = 0, qid = 4;
2080f856f099SNavdeep Parhar 
2081f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2082f856f099SNavdeep Parhar 
2083f856f099SNavdeep Parhar 	return rc;
2084f856f099SNavdeep Parhar }
2085f856f099SNavdeep Parhar 
collect_cim_obq_ncsi(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2086f856f099SNavdeep Parhar static int collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
2087f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2088f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2089f856f099SNavdeep Parhar {
2090f856f099SNavdeep Parhar 	int rc = 0, qid = 5;
2091f856f099SNavdeep Parhar 
2092f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2093f856f099SNavdeep Parhar 
2094f856f099SNavdeep Parhar 	return rc;
2095f856f099SNavdeep Parhar }
2096f856f099SNavdeep Parhar 
collect_obq_sge_rx_q0(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2097f856f099SNavdeep Parhar static int collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
2098f856f099SNavdeep Parhar 				 struct cudbg_buffer *dbg_buff,
2099f856f099SNavdeep Parhar 				 struct cudbg_error *cudbg_err)
2100f856f099SNavdeep Parhar {
2101f856f099SNavdeep Parhar 	int rc = 0, qid = 6;
2102f856f099SNavdeep Parhar 
2103f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2104f856f099SNavdeep Parhar 
2105f856f099SNavdeep Parhar 	return rc;
2106f856f099SNavdeep Parhar }
2107f856f099SNavdeep Parhar 
collect_obq_sge_rx_q1(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2108f856f099SNavdeep Parhar static int collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
2109f856f099SNavdeep Parhar 				 struct cudbg_buffer *dbg_buff,
2110f856f099SNavdeep Parhar 				 struct cudbg_error *cudbg_err)
2111f856f099SNavdeep Parhar {
2112f856f099SNavdeep Parhar 	int rc = 0, qid = 7;
2113f856f099SNavdeep Parhar 
2114f856f099SNavdeep Parhar 	rc = read_cim_obq(pdbg_init, dbg_buff, cudbg_err, qid);
2115f856f099SNavdeep Parhar 
2116f856f099SNavdeep Parhar 	return rc;
2117f856f099SNavdeep Parhar }
2118f856f099SNavdeep Parhar 
read_cim_obq(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err,int qid)2119f856f099SNavdeep Parhar static int read_cim_obq(struct cudbg_init *pdbg_init,
2120f856f099SNavdeep Parhar 			struct cudbg_buffer *dbg_buff,
2121f856f099SNavdeep Parhar 			struct cudbg_error *cudbg_err, int qid)
2122f856f099SNavdeep Parhar {
2123f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2124f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2125f856f099SNavdeep Parhar 	u32 qsize;
2126f856f099SNavdeep Parhar 	int rc;
2127f856f099SNavdeep Parhar 	int no_of_read_words;
2128f856f099SNavdeep Parhar 
2129f856f099SNavdeep Parhar 	/* collect CIM OBQ */
2130f856f099SNavdeep Parhar 	qsize =  6 * CIM_OBQ_SIZE * 4 *  sizeof(u32);
2131f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, qsize, &scratch_buff);
2132f856f099SNavdeep Parhar 	if (rc)
2133f856f099SNavdeep Parhar 		goto err;
2134f856f099SNavdeep Parhar 
2135f856f099SNavdeep Parhar 	/* t4_read_cim_obq will return no. of read words or error */
2136f856f099SNavdeep Parhar 	no_of_read_words = t4_read_cim_obq(padap, qid,
2137f856f099SNavdeep Parhar 					   (u32 *)((u32 *)scratch_buff.data +
2138f856f099SNavdeep Parhar 					   scratch_buff.offset), qsize);
2139f856f099SNavdeep Parhar 
2140f856f099SNavdeep Parhar 	/* no_of_read_words is less than or equal to 0 means error */
2141f856f099SNavdeep Parhar 	if (no_of_read_words <= 0) {
2142f856f099SNavdeep Parhar 		if (no_of_read_words == 0)
2143f856f099SNavdeep Parhar 			rc = CUDBG_SYSTEM_ERROR;
2144f856f099SNavdeep Parhar 		else
2145f856f099SNavdeep Parhar 			rc = no_of_read_words;
2146f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2147f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_read_cim_obq failed (%d)\n",
2148f856f099SNavdeep Parhar 				 __func__, rc);
2149f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2150f856f099SNavdeep Parhar 		goto err1;
2151f856f099SNavdeep Parhar 	}
2152f856f099SNavdeep Parhar 
2153f856f099SNavdeep Parhar 	scratch_buff.size = no_of_read_words * 4;
2154f856f099SNavdeep Parhar 
2155f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2156f856f099SNavdeep Parhar 
2157f856f099SNavdeep Parhar 	if (rc)
2158f856f099SNavdeep Parhar 		goto err1;
2159f856f099SNavdeep Parhar 
2160f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2161f856f099SNavdeep Parhar 
2162f856f099SNavdeep Parhar 	if (rc)
2163f856f099SNavdeep Parhar 		goto err1;
2164f856f099SNavdeep Parhar 
2165f856f099SNavdeep Parhar err1:
2166f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2167f856f099SNavdeep Parhar err:
2168f856f099SNavdeep Parhar 	return rc;
2169f856f099SNavdeep Parhar }
2170f856f099SNavdeep Parhar 
2171f856f099SNavdeep Parhar /* CIM IBQ */
2172f856f099SNavdeep Parhar 
collect_cim_ibq_tp0(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2173f856f099SNavdeep Parhar static int collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
2174f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2175f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2176f856f099SNavdeep Parhar {
2177f856f099SNavdeep Parhar 	int rc = 0, qid = 0;
2178f856f099SNavdeep Parhar 
2179f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2180f856f099SNavdeep Parhar 	return rc;
2181f856f099SNavdeep Parhar }
2182f856f099SNavdeep Parhar 
collect_cim_ibq_tp1(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2183f856f099SNavdeep Parhar static int collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
2184f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2185f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2186f856f099SNavdeep Parhar {
2187f856f099SNavdeep Parhar 	int rc = 0, qid = 1;
2188f856f099SNavdeep Parhar 
2189f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2190f856f099SNavdeep Parhar 	return rc;
2191f856f099SNavdeep Parhar }
2192f856f099SNavdeep Parhar 
collect_cim_ibq_ulp(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2193f856f099SNavdeep Parhar static int collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
2194f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2195f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2196f856f099SNavdeep Parhar {
2197f856f099SNavdeep Parhar 	int rc = 0, qid = 2;
2198f856f099SNavdeep Parhar 
2199f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2200f856f099SNavdeep Parhar 	return rc;
2201f856f099SNavdeep Parhar }
2202f856f099SNavdeep Parhar 
collect_cim_ibq_sge0(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2203f856f099SNavdeep Parhar static int collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
2204f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2205f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2206f856f099SNavdeep Parhar {
2207f856f099SNavdeep Parhar 	int rc = 0, qid = 3;
2208f856f099SNavdeep Parhar 
2209f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2210f856f099SNavdeep Parhar 	return rc;
2211f856f099SNavdeep Parhar }
2212f856f099SNavdeep Parhar 
collect_cim_ibq_sge1(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2213f856f099SNavdeep Parhar static int collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
2214f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2215f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2216f856f099SNavdeep Parhar {
2217f856f099SNavdeep Parhar 	int rc = 0, qid = 4;
2218f856f099SNavdeep Parhar 
2219f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2220f856f099SNavdeep Parhar 	return rc;
2221f856f099SNavdeep Parhar }
2222f856f099SNavdeep Parhar 
collect_cim_ibq_ncsi(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2223f856f099SNavdeep Parhar static int collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
2224f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2225f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2226f856f099SNavdeep Parhar {
2227f856f099SNavdeep Parhar 	int rc, qid = 5;
2228f856f099SNavdeep Parhar 
2229f856f099SNavdeep Parhar 	rc = read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, qid);
2230f856f099SNavdeep Parhar 	return rc;
2231f856f099SNavdeep Parhar }
2232f856f099SNavdeep Parhar 
read_cim_ibq(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err,int qid)2233f856f099SNavdeep Parhar static int read_cim_ibq(struct cudbg_init *pdbg_init,
2234f856f099SNavdeep Parhar 			struct cudbg_buffer *dbg_buff,
2235f856f099SNavdeep Parhar 			struct cudbg_error *cudbg_err, int qid)
2236f856f099SNavdeep Parhar {
2237f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2238f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2239f856f099SNavdeep Parhar 	u32 qsize;
2240f856f099SNavdeep Parhar 	int rc;
2241f856f099SNavdeep Parhar 	int no_of_read_words;
2242f856f099SNavdeep Parhar 
2243f856f099SNavdeep Parhar 	/* collect CIM IBQ */
2244f856f099SNavdeep Parhar 	qsize = CIM_IBQ_SIZE * 4 *  sizeof(u32);
2245f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, qsize, &scratch_buff);
2246f856f099SNavdeep Parhar 
2247f856f099SNavdeep Parhar 	if (rc)
2248f856f099SNavdeep Parhar 		goto err;
2249f856f099SNavdeep Parhar 
2250f856f099SNavdeep Parhar 	/* t4_read_cim_ibq will return no. of read words or error */
2251f856f099SNavdeep Parhar 	no_of_read_words = t4_read_cim_ibq(padap, qid,
2252f856f099SNavdeep Parhar 					   (u32 *)((u32 *)scratch_buff.data +
2253f856f099SNavdeep Parhar 					   scratch_buff.offset), qsize);
2254f856f099SNavdeep Parhar 	/* no_of_read_words is less than or equal to 0 means error */
2255f856f099SNavdeep Parhar 	if (no_of_read_words <= 0) {
2256f856f099SNavdeep Parhar 		if (no_of_read_words == 0)
2257f856f099SNavdeep Parhar 			rc = CUDBG_SYSTEM_ERROR;
2258f856f099SNavdeep Parhar 		else
2259f856f099SNavdeep Parhar 			rc = no_of_read_words;
2260f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2261f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_read_cim_ibq failed (%d)\n",
2262f856f099SNavdeep Parhar 				 __func__, rc);
2263f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2264f856f099SNavdeep Parhar 		goto err1;
2265f856f099SNavdeep Parhar 	}
2266f856f099SNavdeep Parhar 
2267f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2268f856f099SNavdeep Parhar 	if (rc)
2269f856f099SNavdeep Parhar 		goto err1;
2270f856f099SNavdeep Parhar 
2271f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2272f856f099SNavdeep Parhar 	if (rc)
2273f856f099SNavdeep Parhar 		goto err1;
2274f856f099SNavdeep Parhar 
2275f856f099SNavdeep Parhar err1:
2276f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2277f856f099SNavdeep Parhar 
2278f856f099SNavdeep Parhar err:
2279f856f099SNavdeep Parhar 	return rc;
2280f856f099SNavdeep Parhar }
2281f856f099SNavdeep Parhar 
collect_cim_ma_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2282f856f099SNavdeep Parhar static int collect_cim_ma_la(struct cudbg_init *pdbg_init,
2283f856f099SNavdeep Parhar 			     struct cudbg_buffer *dbg_buff,
2284f856f099SNavdeep Parhar 			     struct cudbg_error *cudbg_err)
2285f856f099SNavdeep Parhar {
2286f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2287f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2288f856f099SNavdeep Parhar 	u32 rc = 0;
2289f856f099SNavdeep Parhar 
2290f856f099SNavdeep Parhar 	/* collect CIM MA LA */
2291f856f099SNavdeep Parhar 	scratch_buff.size =  2 * CIM_MALA_SIZE * 5 * sizeof(u32);
2292f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
2293f856f099SNavdeep Parhar 	if (rc)
2294f856f099SNavdeep Parhar 		goto err;
2295f856f099SNavdeep Parhar 
2296f856f099SNavdeep Parhar 	/* no return */
2297f856f099SNavdeep Parhar 	t4_cim_read_ma_la(padap,
2298f856f099SNavdeep Parhar 			  (u32 *) ((char *)scratch_buff.data +
2299f856f099SNavdeep Parhar 				   scratch_buff.offset),
2300f856f099SNavdeep Parhar 			  (u32 *) ((char *)scratch_buff.data +
2301f856f099SNavdeep Parhar 				   scratch_buff.offset + 5 * CIM_MALA_SIZE));
2302f856f099SNavdeep Parhar 
2303f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2304f856f099SNavdeep Parhar 	if (rc)
2305f856f099SNavdeep Parhar 		goto err1;
2306f856f099SNavdeep Parhar 
2307f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2308f856f099SNavdeep Parhar 
2309f856f099SNavdeep Parhar err1:
2310f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2311f856f099SNavdeep Parhar err:
2312f856f099SNavdeep Parhar 	return rc;
2313f856f099SNavdeep Parhar }
2314f856f099SNavdeep Parhar 
collect_cim_la(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2315f856f099SNavdeep Parhar static int collect_cim_la(struct cudbg_init *pdbg_init,
2316f856f099SNavdeep Parhar 			  struct cudbg_buffer *dbg_buff,
2317f856f099SNavdeep Parhar 			  struct cudbg_error *cudbg_err)
2318f856f099SNavdeep Parhar {
2319f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2320f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2321f856f099SNavdeep Parhar 
2322f856f099SNavdeep Parhar 	int rc;
2323f856f099SNavdeep Parhar 	u32 cfg = 0;
2324f856f099SNavdeep Parhar 	int size;
2325f856f099SNavdeep Parhar 
2326f856f099SNavdeep Parhar 	/* collect CIM LA */
2327f856f099SNavdeep Parhar 	if (is_t6(padap)) {
2328f856f099SNavdeep Parhar 		size = padap->params.cim_la_size / 10 + 1;
2329f856f099SNavdeep Parhar 		size *= 11 * sizeof(u32);
2330f856f099SNavdeep Parhar 	} else {
2331f856f099SNavdeep Parhar 		size = padap->params.cim_la_size / 8;
2332f856f099SNavdeep Parhar 		size *= 8 * sizeof(u32);
2333f856f099SNavdeep Parhar 	}
2334f856f099SNavdeep Parhar 
2335f856f099SNavdeep Parhar 	size += sizeof(cfg);
2336f856f099SNavdeep Parhar 
2337f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, size, &scratch_buff);
2338f856f099SNavdeep Parhar 	if (rc)
2339f856f099SNavdeep Parhar 		goto err;
2340f856f099SNavdeep Parhar 
2341f856f099SNavdeep Parhar 	rc = t4_cim_read(padap, A_UP_UP_DBG_LA_CFG, 1, &cfg);
2342f856f099SNavdeep Parhar 
2343f856f099SNavdeep Parhar 	if (rc) {
2344f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2345f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_cim_read failed (%d)\n",
2346f856f099SNavdeep Parhar 				 __func__, rc);
2347f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2348f856f099SNavdeep Parhar 		goto err1;
2349f856f099SNavdeep Parhar 	}
2350f856f099SNavdeep Parhar 
2351f856f099SNavdeep Parhar 	memcpy((char *)scratch_buff.data + scratch_buff.offset, &cfg,
2352f856f099SNavdeep Parhar 	       sizeof(cfg));
2353f856f099SNavdeep Parhar 
2354f856f099SNavdeep Parhar 	rc = t4_cim_read_la(padap,
2355f856f099SNavdeep Parhar 			    (u32 *) ((char *)scratch_buff.data +
2356f856f099SNavdeep Parhar 				     scratch_buff.offset + sizeof(cfg)), NULL);
2357f856f099SNavdeep Parhar 	if (rc < 0) {
2358f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2359f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_cim_read_la failed (%d)\n",
2360f856f099SNavdeep Parhar 				 __func__, rc);
2361f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2362f856f099SNavdeep Parhar 		goto err1;
2363f856f099SNavdeep Parhar 	}
2364f856f099SNavdeep Parhar 
2365f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2366f856f099SNavdeep Parhar 	if (rc)
2367f856f099SNavdeep Parhar 		goto err1;
2368f856f099SNavdeep Parhar 
2369f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2370f856f099SNavdeep Parhar 	if (rc)
2371f856f099SNavdeep Parhar 		goto err1;
2372f856f099SNavdeep Parhar 
2373f856f099SNavdeep Parhar err1:
2374f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2375f856f099SNavdeep Parhar err:
2376f856f099SNavdeep Parhar 	return rc;
2377f856f099SNavdeep Parhar }
2378f856f099SNavdeep Parhar 
collect_cim_qcfg(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2379f856f099SNavdeep Parhar static int collect_cim_qcfg(struct cudbg_init *pdbg_init,
2380f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
2381f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
2382f856f099SNavdeep Parhar {
2383f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2384f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2385f856f099SNavdeep Parhar 	u32 offset;
238639d5cbdcSNavdeep Parhar 	int rc = 0;
2387f856f099SNavdeep Parhar 
2388f856f099SNavdeep Parhar 	struct struct_cim_qcfg *cim_qcfg_data = NULL;
2389f856f099SNavdeep Parhar 
2390f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, sizeof(struct struct_cim_qcfg),
2391f856f099SNavdeep Parhar 			      &scratch_buff);
2392f856f099SNavdeep Parhar 
2393f856f099SNavdeep Parhar 	if (rc)
2394f856f099SNavdeep Parhar 		goto err;
2395f856f099SNavdeep Parhar 
2396f856f099SNavdeep Parhar 	offset = scratch_buff.offset;
2397f856f099SNavdeep Parhar 
2398f856f099SNavdeep Parhar 	cim_qcfg_data =
2399f856f099SNavdeep Parhar 		(struct struct_cim_qcfg *)((u8 *)((char *)scratch_buff.data +
2400f856f099SNavdeep Parhar 					   offset));
2401f856f099SNavdeep Parhar 
2402f856f099SNavdeep Parhar 	rc = t4_cim_read(padap, A_UP_IBQ_0_RDADDR,
2403f856f099SNavdeep Parhar 			 ARRAY_SIZE(cim_qcfg_data->stat), cim_qcfg_data->stat);
2404f856f099SNavdeep Parhar 
2405f856f099SNavdeep Parhar 	if (rc) {
2406f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2407f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_cim_read IBQ_0_RDADDR failed (%d)\n",
2408f856f099SNavdeep Parhar 			    __func__, rc);
2409f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2410f856f099SNavdeep Parhar 		goto err1;
2411f856f099SNavdeep Parhar 	}
2412f856f099SNavdeep Parhar 
2413f856f099SNavdeep Parhar 	rc = t4_cim_read(padap, A_UP_OBQ_0_REALADDR,
2414f856f099SNavdeep Parhar 			 ARRAY_SIZE(cim_qcfg_data->obq_wr),
2415f856f099SNavdeep Parhar 			 cim_qcfg_data->obq_wr);
2416f856f099SNavdeep Parhar 
2417f856f099SNavdeep Parhar 	if (rc) {
2418f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2419f856f099SNavdeep Parhar 			pdbg_init->print("%s: t4_cim_read OBQ_0_REALADDR failed (%d)\n",
2420f856f099SNavdeep Parhar 			    __func__, rc);
2421f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
2422f856f099SNavdeep Parhar 		goto err1;
2423f856f099SNavdeep Parhar 	}
2424f856f099SNavdeep Parhar 
2425f856f099SNavdeep Parhar 	/* no return val */
2426f856f099SNavdeep Parhar 	t4_read_cimq_cfg(padap,
2427f856f099SNavdeep Parhar 			cim_qcfg_data->base,
2428f856f099SNavdeep Parhar 			cim_qcfg_data->size,
2429f856f099SNavdeep Parhar 			cim_qcfg_data->thres);
2430f856f099SNavdeep Parhar 
2431f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2432f856f099SNavdeep Parhar 	if (rc)
2433f856f099SNavdeep Parhar 		goto err1;
2434f856f099SNavdeep Parhar 
2435f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2436f856f099SNavdeep Parhar 	if (rc)
2437f856f099SNavdeep Parhar 		goto err1;
2438f856f099SNavdeep Parhar 
2439f856f099SNavdeep Parhar err1:
2440f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2441f856f099SNavdeep Parhar err:
2442f856f099SNavdeep Parhar 	return rc;
2443f856f099SNavdeep Parhar }
2444f856f099SNavdeep Parhar 
2445f856f099SNavdeep Parhar /**
2446f856f099SNavdeep Parhar  * Fetch the TX/RX payload regions start and end.
2447f856f099SNavdeep Parhar  *
2448f856f099SNavdeep Parhar  * @padap (IN): adapter handle.
2449f856f099SNavdeep Parhar  * @mem_type (IN): EDC0, EDC1, MC/MC0/MC1.
2450f856f099SNavdeep Parhar  * @mem_tot_len (IN): total length of @mem_type memory region to read.
2451f856f099SNavdeep Parhar  * @payload_type (IN): TX or RX Payload.
2452f856f099SNavdeep Parhar  * @reg_info (OUT): store the payload region info.
2453f856f099SNavdeep Parhar  *
2454f856f099SNavdeep Parhar  * Fetch the TX/RX payload region information from meminfo.
2455f856f099SNavdeep Parhar  * However, reading from the @mem_type region starts at 0 and not
2456f856f099SNavdeep Parhar  * from whatever base info is stored in meminfo.  Hence, if the
2457f856f099SNavdeep Parhar  * payload region exists, then calculate the payload region
2458f856f099SNavdeep Parhar  * start and end wrt 0 and @mem_tot_len, respectively, and set
2459f856f099SNavdeep Parhar  * @reg_info->exist to true. Otherwise, set @reg_info->exist to false.
2460f856f099SNavdeep Parhar  */
2461f856f099SNavdeep Parhar #ifdef notyet
get_payload_range(struct adapter * padap,u8 mem_type,unsigned long mem_tot_len,u8 payload_type,struct struct_region_info * reg_info)2462f856f099SNavdeep Parhar static int get_payload_range(struct adapter *padap, u8 mem_type,
2463f856f099SNavdeep Parhar 			     unsigned long mem_tot_len, u8 payload_type,
2464f856f099SNavdeep Parhar 			     struct struct_region_info *reg_info)
2465f856f099SNavdeep Parhar {
2466f856f099SNavdeep Parhar 	struct struct_meminfo meminfo;
2467f856f099SNavdeep Parhar 	struct struct_mem_desc mem_region;
2468f856f099SNavdeep Parhar 	struct struct_mem_desc payload;
2469f856f099SNavdeep Parhar 	u32 i, idx, found = 0;
2470f856f099SNavdeep Parhar 	u8 mc_type;
2471f856f099SNavdeep Parhar 	int rc;
2472f856f099SNavdeep Parhar 
2473f856f099SNavdeep Parhar 	/* Get meminfo of all regions */
2474f856f099SNavdeep Parhar 	rc = fill_meminfo(padap, &meminfo);
2475f856f099SNavdeep Parhar 	if (rc)
2476f856f099SNavdeep Parhar 		return rc;
2477f856f099SNavdeep Parhar 
2478f856f099SNavdeep Parhar 	/* Extract the specified TX or RX Payload region range */
2479f856f099SNavdeep Parhar 	memset(&payload, 0, sizeof(struct struct_mem_desc));
2480f856f099SNavdeep Parhar 	for (i = 0; i < meminfo.mem_c; i++) {
2481f856f099SNavdeep Parhar 		if (meminfo.mem[i].idx >= ARRAY_SIZE(region))
2482f856f099SNavdeep Parhar 			continue;                        /* skip holes */
2483f856f099SNavdeep Parhar 
2484f856f099SNavdeep Parhar 		idx = meminfo.mem[i].idx;
2485f856f099SNavdeep Parhar 		/* Get TX or RX Payload region start and end */
2486f856f099SNavdeep Parhar 		if (idx == payload_type) {
2487f856f099SNavdeep Parhar 			if (!(meminfo.mem[i].limit))
2488f856f099SNavdeep Parhar 				meminfo.mem[i].limit =
2489f856f099SNavdeep Parhar 					i < meminfo.mem_c - 1 ?
2490f856f099SNavdeep Parhar 					meminfo.mem[i + 1].base - 1 : ~0;
2491f856f099SNavdeep Parhar 
2492f856f099SNavdeep Parhar 			memcpy(&payload, &meminfo.mem[i], sizeof(payload));
2493f856f099SNavdeep Parhar 			found = 1;
2494f856f099SNavdeep Parhar 			break;
2495f856f099SNavdeep Parhar 		}
2496f856f099SNavdeep Parhar 	}
2497f856f099SNavdeep Parhar 
2498f856f099SNavdeep Parhar 	/* If TX or RX Payload region is not found return error. */
2499f856f099SNavdeep Parhar 	if (!found)
2500f856f099SNavdeep Parhar 		return -EINVAL;
2501f856f099SNavdeep Parhar 
2502f856f099SNavdeep Parhar 	if (mem_type < MEM_MC) {
2503f856f099SNavdeep Parhar 		memcpy(&mem_region, &meminfo.avail[mem_type],
2504f856f099SNavdeep Parhar 		       sizeof(mem_region));
2505f856f099SNavdeep Parhar 	} else {
2506f856f099SNavdeep Parhar 		/* Check if both MC0 and MC1 exist by checking if a
2507f856f099SNavdeep Parhar 		 * base address for the specified @mem_type exists.
2508f856f099SNavdeep Parhar 		 * If a base address exists, then there is MC1 and
2509f856f099SNavdeep Parhar 		 * hence use the base address stored at index 3.
2510f856f099SNavdeep Parhar 		 * Otherwise, use the base address stored at index 2.
2511f856f099SNavdeep Parhar 		 */
2512f856f099SNavdeep Parhar 		mc_type = meminfo.avail[mem_type].base ?
2513f856f099SNavdeep Parhar 			  mem_type : mem_type - 1;
2514f856f099SNavdeep Parhar 		memcpy(&mem_region, &meminfo.avail[mc_type],
2515f856f099SNavdeep Parhar 		       sizeof(mem_region));
2516f856f099SNavdeep Parhar 	}
2517f856f099SNavdeep Parhar 
2518f856f099SNavdeep Parhar 	/* Check if payload region exists in current memory */
2519f856f099SNavdeep Parhar 	if (payload.base < mem_region.base && payload.limit < mem_region.base) {
2520f856f099SNavdeep Parhar 		reg_info->exist = false;
2521f856f099SNavdeep Parhar 		return 0;
2522f856f099SNavdeep Parhar 	}
2523f856f099SNavdeep Parhar 
2524f856f099SNavdeep Parhar 	/* Get Payload region start and end with respect to 0 and
2525f856f099SNavdeep Parhar 	 * mem_tot_len, respectively.  This is because reading from the
2526f856f099SNavdeep Parhar 	 * memory region starts at 0 and not at base info stored in meminfo.
2527f856f099SNavdeep Parhar 	 */
2528f856f099SNavdeep Parhar 	if (payload.base < mem_region.limit) {
2529f856f099SNavdeep Parhar 		reg_info->exist = true;
2530f856f099SNavdeep Parhar 		if (payload.base >= mem_region.base)
2531f856f099SNavdeep Parhar 			reg_info->start = payload.base - mem_region.base;
2532f856f099SNavdeep Parhar 		else
2533f856f099SNavdeep Parhar 			reg_info->start = 0;
2534f856f099SNavdeep Parhar 
2535f856f099SNavdeep Parhar 		if (payload.limit < mem_region.limit)
2536f856f099SNavdeep Parhar 			reg_info->end = payload.limit - mem_region.base;
2537f856f099SNavdeep Parhar 		else
2538f856f099SNavdeep Parhar 			reg_info->end = mem_tot_len;
2539f856f099SNavdeep Parhar 	}
2540f856f099SNavdeep Parhar 
2541f856f099SNavdeep Parhar 	return 0;
2542f856f099SNavdeep Parhar }
2543f856f099SNavdeep Parhar #endif
2544f856f099SNavdeep Parhar 
read_fw_mem(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,u8 mem_type,unsigned long tot_len,struct cudbg_error * cudbg_err)2545f856f099SNavdeep Parhar static int read_fw_mem(struct cudbg_init *pdbg_init,
2546f856f099SNavdeep Parhar 			struct cudbg_buffer *dbg_buff, u8 mem_type,
2547f856f099SNavdeep Parhar 			unsigned long tot_len, struct cudbg_error *cudbg_err)
2548f856f099SNavdeep Parhar {
2549f856f099SNavdeep Parhar #ifdef notyet
2550f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2551f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2552f856f099SNavdeep Parhar 	unsigned long bytes_read = 0;
2553f856f099SNavdeep Parhar 	unsigned long bytes_left;
2554f856f099SNavdeep Parhar 	unsigned long bytes;
2555f856f099SNavdeep Parhar 	int	      rc;
2556f856f099SNavdeep Parhar 	struct struct_region_info payload[2]; /* TX and RX Payload Region */
2557f856f099SNavdeep Parhar 	u16 get_payload_flag;
2558f856f099SNavdeep Parhar 	u8 i;
2559f856f099SNavdeep Parhar 
2560f856f099SNavdeep Parhar 	get_payload_flag =
2561f856f099SNavdeep Parhar 		pdbg_init->dbg_params[CUDBG_GET_PAYLOAD_PARAM].param_type;
2562f856f099SNavdeep Parhar 
2563f856f099SNavdeep Parhar 	/* If explicitly asked to get TX/RX Payload data,
2564f856f099SNavdeep Parhar 	 * then don't zero out the payload data. Otherwise,
2565f856f099SNavdeep Parhar 	 * zero out the payload data.
2566f856f099SNavdeep Parhar 	 */
2567f856f099SNavdeep Parhar 	if (!get_payload_flag) {
2568f856f099SNavdeep Parhar 		u8 region_index[2];
2569f856f099SNavdeep Parhar 		u8 j = 0;
2570f856f099SNavdeep Parhar 
2571f856f099SNavdeep Parhar 		/* Find the index of TX and RX Payload regions in meminfo */
2572f856f099SNavdeep Parhar 		for (i = 0; i < ARRAY_SIZE(region); i++) {
2573f856f099SNavdeep Parhar 			if (!strcmp(region[i], "Tx payload:") ||
2574f856f099SNavdeep Parhar 			    !strcmp(region[i], "Rx payload:")) {
2575f856f099SNavdeep Parhar 				region_index[j] = i;
2576f856f099SNavdeep Parhar 				j++;
2577f856f099SNavdeep Parhar 				if (j == 2)
2578f856f099SNavdeep Parhar 					break;
2579f856f099SNavdeep Parhar 			}
2580f856f099SNavdeep Parhar 		}
2581f856f099SNavdeep Parhar 
2582f856f099SNavdeep Parhar 		/* Get TX/RX Payload region range if they exist */
2583f856f099SNavdeep Parhar 		memset(payload, 0, ARRAY_SIZE(payload) * sizeof(payload[0]));
2584f856f099SNavdeep Parhar 		for (i = 0; i < ARRAY_SIZE(payload); i++) {
2585f856f099SNavdeep Parhar 			rc = get_payload_range(padap, mem_type, tot_len,
2586f856f099SNavdeep Parhar 					       region_index[i],
2587f856f099SNavdeep Parhar 					       &payload[i]);
2588f856f099SNavdeep Parhar 			if (rc)
2589f856f099SNavdeep Parhar 				goto err;
2590f856f099SNavdeep Parhar 
2591f856f099SNavdeep Parhar 			if (payload[i].exist) {
2592f856f099SNavdeep Parhar 				/* Align start and end to avoid wrap around */
2593f856f099SNavdeep Parhar 				payload[i].start =
2594f856f099SNavdeep Parhar 					roundup(payload[i].start,
2595f856f099SNavdeep Parhar 					    CUDBG_CHUNK_SIZE);
2596f856f099SNavdeep Parhar 				payload[i].end =
2597f856f099SNavdeep Parhar 					rounddown(payload[i].end,
2598f856f099SNavdeep Parhar 					    CUDBG_CHUNK_SIZE);
2599f856f099SNavdeep Parhar 			}
2600f856f099SNavdeep Parhar 		}
2601f856f099SNavdeep Parhar 	}
2602f856f099SNavdeep Parhar 
2603f856f099SNavdeep Parhar 	bytes_left = tot_len;
2604f856f099SNavdeep Parhar 	scratch_buff.size = tot_len;
2605f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2606f856f099SNavdeep Parhar 	if (rc)
2607f856f099SNavdeep Parhar 		goto err;
2608f856f099SNavdeep Parhar 
2609f856f099SNavdeep Parhar 	while (bytes_left > 0) {
2610f856f099SNavdeep Parhar 		bytes = min_t(unsigned long, bytes_left, (unsigned long)CUDBG_CHUNK_SIZE);
2611f856f099SNavdeep Parhar 		rc = get_scratch_buff(dbg_buff, bytes, &scratch_buff);
2612f856f099SNavdeep Parhar 
2613f856f099SNavdeep Parhar 		if (rc) {
2614f856f099SNavdeep Parhar 			rc = CUDBG_STATUS_NO_SCRATCH_MEM;
2615f856f099SNavdeep Parhar 			goto err;
2616f856f099SNavdeep Parhar 		}
2617f856f099SNavdeep Parhar 
2618f856f099SNavdeep Parhar 		if (!get_payload_flag) {
2619f856f099SNavdeep Parhar 			for (i = 0; i < ARRAY_SIZE(payload); i++) {
2620f856f099SNavdeep Parhar 				if (payload[i].exist &&
2621f856f099SNavdeep Parhar 				    bytes_read >= payload[i].start &&
2622f856f099SNavdeep Parhar 				    (bytes_read + bytes) <= payload[i].end) {
2623f856f099SNavdeep Parhar 					memset(scratch_buff.data, 0, bytes);
2624f856f099SNavdeep Parhar 					/* TX and RX Payload regions
2625f856f099SNavdeep Parhar 					 * can't overlap.
2626f856f099SNavdeep Parhar 					 */
2627f856f099SNavdeep Parhar 					goto skip_read;
2628f856f099SNavdeep Parhar 				}
2629f856f099SNavdeep Parhar 			}
2630f856f099SNavdeep Parhar 		}
2631f856f099SNavdeep Parhar 
2632f856f099SNavdeep Parhar 		/* Read from file */
2633f856f099SNavdeep Parhar 		/*fread(scratch_buff.data, 1, Bytes, in);*/
2634f856f099SNavdeep Parhar 		rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type, bytes_read,
2635f856f099SNavdeep Parhar 				  bytes, (__be32 *)(scratch_buff.data), 1);
2636f856f099SNavdeep Parhar 
2637f856f099SNavdeep Parhar 		if (rc) {
2638f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
2639f856f099SNavdeep Parhar 				pdbg_init->print("%s: t4_memory_rw failed (%d)",
2640f856f099SNavdeep Parhar 				    __func__, rc);
2641f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
2642f856f099SNavdeep Parhar 			goto err1;
2643f856f099SNavdeep Parhar 		}
2644f856f099SNavdeep Parhar 
2645f856f099SNavdeep Parhar skip_read:
2646f856f099SNavdeep Parhar 		rc = compress_buff(&scratch_buff, dbg_buff);
2647f856f099SNavdeep Parhar 		if (rc)
2648f856f099SNavdeep Parhar 			goto err1;
2649f856f099SNavdeep Parhar 
2650f856f099SNavdeep Parhar 		bytes_left -= bytes;
2651f856f099SNavdeep Parhar 		bytes_read += bytes;
2652f856f099SNavdeep Parhar 		release_scratch_buff(&scratch_buff, dbg_buff);
2653f856f099SNavdeep Parhar 	}
2654f856f099SNavdeep Parhar 
2655f856f099SNavdeep Parhar err1:
2656f856f099SNavdeep Parhar 	if (rc)
2657f856f099SNavdeep Parhar 		release_scratch_buff(&scratch_buff, dbg_buff);
2658f856f099SNavdeep Parhar 
2659f856f099SNavdeep Parhar err:
2660f856f099SNavdeep Parhar 	return rc;
2661f856f099SNavdeep Parhar #endif
26626cc4520bSNavdeep Parhar 	return (CUDBG_STATUS_NOT_IMPLEMENTED);
2663f856f099SNavdeep Parhar }
2664f856f099SNavdeep Parhar 
collect_mem_info(struct cudbg_init * pdbg_init,struct card_mem * mem_info)2665f856f099SNavdeep Parhar static void collect_mem_info(struct cudbg_init *pdbg_init,
2666f856f099SNavdeep Parhar 			     struct card_mem *mem_info)
2667f856f099SNavdeep Parhar {
2668f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2669f856f099SNavdeep Parhar 	u32 value;
2670f856f099SNavdeep Parhar 	int t4 = 0;
2671f856f099SNavdeep Parhar 
2672f856f099SNavdeep Parhar 	if (is_t4(padap))
2673f856f099SNavdeep Parhar 		t4 = 1;
2674f856f099SNavdeep Parhar 
2675f856f099SNavdeep Parhar 	if (t4) {
2676f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_MA_EXT_MEMORY_BAR);
2677f856f099SNavdeep Parhar 		value = G_EXT_MEM_SIZE(value);
2678f856f099SNavdeep Parhar 		mem_info->size_mc0 = (u16)value;  /* size in MB */
2679f856f099SNavdeep Parhar 
2680f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_MA_TARGET_MEM_ENABLE);
2681f856f099SNavdeep Parhar 		if (value & F_EXT_MEM_ENABLE)
2682f856f099SNavdeep Parhar 			mem_info->mem_flag |= (1 << MC0_FLAG); /* set mc0 flag
2683f856f099SNavdeep Parhar 								  bit */
2684f856f099SNavdeep Parhar 	} else {
2685f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_MA_EXT_MEMORY0_BAR);
2686f856f099SNavdeep Parhar 		value = G_EXT_MEM0_SIZE(value);
2687f856f099SNavdeep Parhar 		mem_info->size_mc0 = (u16)value;
2688f856f099SNavdeep Parhar 
2689f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_MA_EXT_MEMORY1_BAR);
2690f856f099SNavdeep Parhar 		value = G_EXT_MEM1_SIZE(value);
2691f856f099SNavdeep Parhar 		mem_info->size_mc1 = (u16)value;
2692f856f099SNavdeep Parhar 
2693f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_MA_TARGET_MEM_ENABLE);
2694f856f099SNavdeep Parhar 		if (value & F_EXT_MEM0_ENABLE)
2695f856f099SNavdeep Parhar 			mem_info->mem_flag |= (1 << MC0_FLAG);
2696f856f099SNavdeep Parhar 		if (value & F_EXT_MEM1_ENABLE)
2697f856f099SNavdeep Parhar 			mem_info->mem_flag |= (1 << MC1_FLAG);
2698f856f099SNavdeep Parhar 	}
2699f856f099SNavdeep Parhar 
2700f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_MA_EDRAM0_BAR);
2701f856f099SNavdeep Parhar 	value = G_EDRAM0_SIZE(value);
2702f856f099SNavdeep Parhar 	mem_info->size_edc0 = (u16)value;
2703f856f099SNavdeep Parhar 
2704f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_MA_EDRAM1_BAR);
2705f856f099SNavdeep Parhar 	value = G_EDRAM1_SIZE(value);
2706f856f099SNavdeep Parhar 	mem_info->size_edc1 = (u16)value;
2707f856f099SNavdeep Parhar 
2708f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_MA_TARGET_MEM_ENABLE);
2709f856f099SNavdeep Parhar 	if (value & F_EDRAM0_ENABLE)
2710f856f099SNavdeep Parhar 		mem_info->mem_flag |= (1 << EDC0_FLAG);
2711f856f099SNavdeep Parhar 	if (value & F_EDRAM1_ENABLE)
2712f856f099SNavdeep Parhar 		mem_info->mem_flag |= (1 << EDC1_FLAG);
2713f856f099SNavdeep Parhar 
2714f856f099SNavdeep Parhar }
2715f856f099SNavdeep Parhar 
cudbg_t4_fwcache(struct cudbg_init * pdbg_init,struct cudbg_error * cudbg_err)2716f856f099SNavdeep Parhar static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
2717f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2718f856f099SNavdeep Parhar {
2719f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2720f856f099SNavdeep Parhar 	int rc;
2721f856f099SNavdeep Parhar 
2722f856f099SNavdeep Parhar 	if (is_fw_attached(pdbg_init)) {
2723f856f099SNavdeep Parhar 
2724f856f099SNavdeep Parhar 		/* Flush uP dcache before reading edcX/mcX  */
27258ee789e9SNavdeep Parhar 		rc = begin_synchronized_op(padap, NULL, SLEEP_OK | INTR_OK,
27268ee789e9SNavdeep Parhar 		    "t4cudl");
27278ee789e9SNavdeep Parhar 		if (rc == 0) {
2728f856f099SNavdeep Parhar 			rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
27298ee789e9SNavdeep Parhar 			end_synchronized_op(padap, 0);
27308ee789e9SNavdeep Parhar 		}
2731f856f099SNavdeep Parhar 
2732f856f099SNavdeep Parhar 		if (rc) {
2733f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
2734f856f099SNavdeep Parhar 				pdbg_init->print("%s: t4_fwcache failed (%d)\n",
2735f856f099SNavdeep Parhar 				 __func__, rc);
2736f856f099SNavdeep Parhar 			cudbg_err->sys_warn = rc;
2737f856f099SNavdeep Parhar 		}
2738f856f099SNavdeep Parhar 	}
2739f856f099SNavdeep Parhar }
2740f856f099SNavdeep Parhar 
collect_edc0_meminfo(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2741f856f099SNavdeep Parhar static int collect_edc0_meminfo(struct cudbg_init *pdbg_init,
2742f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2743f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2744f856f099SNavdeep Parhar {
2745f856f099SNavdeep Parhar 	struct card_mem mem_info = {0};
2746f856f099SNavdeep Parhar 	unsigned long edc0_size;
2747f856f099SNavdeep Parhar 	int rc;
2748f856f099SNavdeep Parhar 
2749f856f099SNavdeep Parhar 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
2750f856f099SNavdeep Parhar 
2751f856f099SNavdeep Parhar 	collect_mem_info(pdbg_init, &mem_info);
2752f856f099SNavdeep Parhar 
2753f856f099SNavdeep Parhar 	if (mem_info.mem_flag & (1 << EDC0_FLAG)) {
2754f856f099SNavdeep Parhar 		edc0_size = (((unsigned long)mem_info.size_edc0) * 1024 * 1024);
2755f856f099SNavdeep Parhar 		rc = read_fw_mem(pdbg_init, dbg_buff, MEM_EDC0,
2756f856f099SNavdeep Parhar 				 edc0_size, cudbg_err);
2757f856f099SNavdeep Parhar 		if (rc)
2758f856f099SNavdeep Parhar 			goto err;
2759f856f099SNavdeep Parhar 
2760f856f099SNavdeep Parhar 	} else {
2761f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
2762f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2763f856f099SNavdeep Parhar 			pdbg_init->print("%s(), collect_mem_info failed!, %s\n",
2764f856f099SNavdeep Parhar 				 __func__, err_msg[-rc]);
2765f856f099SNavdeep Parhar 		goto err;
2766f856f099SNavdeep Parhar 
2767f856f099SNavdeep Parhar 	}
2768f856f099SNavdeep Parhar err:
2769f856f099SNavdeep Parhar 	return rc;
2770f856f099SNavdeep Parhar }
2771f856f099SNavdeep Parhar 
collect_edc1_meminfo(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2772f856f099SNavdeep Parhar static int collect_edc1_meminfo(struct cudbg_init *pdbg_init,
2773f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
2774f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
2775f856f099SNavdeep Parhar {
2776f856f099SNavdeep Parhar 	struct card_mem mem_info = {0};
2777f856f099SNavdeep Parhar 	unsigned long edc1_size;
2778f856f099SNavdeep Parhar 	int rc;
2779f856f099SNavdeep Parhar 
2780f856f099SNavdeep Parhar 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
2781f856f099SNavdeep Parhar 
2782f856f099SNavdeep Parhar 	collect_mem_info(pdbg_init, &mem_info);
2783f856f099SNavdeep Parhar 
2784f856f099SNavdeep Parhar 	if (mem_info.mem_flag & (1 << EDC1_FLAG)) {
2785f856f099SNavdeep Parhar 		edc1_size = (((unsigned long)mem_info.size_edc1) * 1024 * 1024);
2786f856f099SNavdeep Parhar 		rc = read_fw_mem(pdbg_init, dbg_buff, MEM_EDC1,
2787f856f099SNavdeep Parhar 				 edc1_size, cudbg_err);
2788f856f099SNavdeep Parhar 		if (rc)
2789f856f099SNavdeep Parhar 			goto err;
2790f856f099SNavdeep Parhar 	} else {
2791f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
2792f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2793f856f099SNavdeep Parhar 			pdbg_init->print("%s(), collect_mem_info failed!, %s\n",
2794f856f099SNavdeep Parhar 				 __func__, err_msg[-rc]);
2795f856f099SNavdeep Parhar 		goto err;
2796f856f099SNavdeep Parhar 	}
2797f856f099SNavdeep Parhar 
2798f856f099SNavdeep Parhar err:
2799f856f099SNavdeep Parhar 
2800f856f099SNavdeep Parhar 	return rc;
2801f856f099SNavdeep Parhar }
2802f856f099SNavdeep Parhar 
collect_mc0_meminfo(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2803f856f099SNavdeep Parhar static int collect_mc0_meminfo(struct cudbg_init *pdbg_init,
2804f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2805f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2806f856f099SNavdeep Parhar {
2807f856f099SNavdeep Parhar 	struct card_mem mem_info = {0};
2808f856f099SNavdeep Parhar 	unsigned long mc0_size;
2809f856f099SNavdeep Parhar 	int rc;
2810f856f099SNavdeep Parhar 
2811f856f099SNavdeep Parhar 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
2812f856f099SNavdeep Parhar 
2813f856f099SNavdeep Parhar 	collect_mem_info(pdbg_init, &mem_info);
2814f856f099SNavdeep Parhar 
2815f856f099SNavdeep Parhar 	if (mem_info.mem_flag & (1 << MC0_FLAG)) {
2816f856f099SNavdeep Parhar 		mc0_size = (((unsigned long)mem_info.size_mc0) * 1024 * 1024);
2817f856f099SNavdeep Parhar 		rc = read_fw_mem(pdbg_init, dbg_buff, MEM_MC0,
2818f856f099SNavdeep Parhar 				 mc0_size, cudbg_err);
2819f856f099SNavdeep Parhar 		if (rc)
2820f856f099SNavdeep Parhar 			goto err;
2821f856f099SNavdeep Parhar 	} else {
2822f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
2823f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2824f856f099SNavdeep Parhar 			pdbg_init->print("%s(), collect_mem_info failed!, %s\n",
2825f856f099SNavdeep Parhar 				 __func__, err_msg[-rc]);
2826f856f099SNavdeep Parhar 		goto err;
2827f856f099SNavdeep Parhar 	}
2828f856f099SNavdeep Parhar 
2829f856f099SNavdeep Parhar err:
2830f856f099SNavdeep Parhar 	return rc;
2831f856f099SNavdeep Parhar }
2832f856f099SNavdeep Parhar 
collect_mc1_meminfo(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2833f856f099SNavdeep Parhar static int collect_mc1_meminfo(struct cudbg_init *pdbg_init,
2834f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
2835f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
2836f856f099SNavdeep Parhar {
2837f856f099SNavdeep Parhar 	struct card_mem mem_info = {0};
2838f856f099SNavdeep Parhar 	unsigned long mc1_size;
2839f856f099SNavdeep Parhar 	int rc;
2840f856f099SNavdeep Parhar 
2841f856f099SNavdeep Parhar 	cudbg_t4_fwcache(pdbg_init, cudbg_err);
2842f856f099SNavdeep Parhar 
2843f856f099SNavdeep Parhar 	collect_mem_info(pdbg_init, &mem_info);
2844f856f099SNavdeep Parhar 
2845f856f099SNavdeep Parhar 	if (mem_info.mem_flag & (1 << MC1_FLAG)) {
2846f856f099SNavdeep Parhar 		mc1_size = (((unsigned long)mem_info.size_mc1) * 1024 * 1024);
2847f856f099SNavdeep Parhar 		rc = read_fw_mem(pdbg_init, dbg_buff, MEM_MC1,
2848f856f099SNavdeep Parhar 				 mc1_size, cudbg_err);
2849f856f099SNavdeep Parhar 		if (rc)
2850f856f099SNavdeep Parhar 			goto err;
2851f856f099SNavdeep Parhar 	} else {
2852f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
2853f856f099SNavdeep Parhar 
2854f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
2855f856f099SNavdeep Parhar 			pdbg_init->print("%s(), collect_mem_info failed!, %s\n",
2856f856f099SNavdeep Parhar 				 __func__, err_msg[-rc]);
2857f856f099SNavdeep Parhar 		goto err;
2858f856f099SNavdeep Parhar 	}
2859f856f099SNavdeep Parhar err:
2860f856f099SNavdeep Parhar 	return rc;
2861f856f099SNavdeep Parhar }
2862f856f099SNavdeep Parhar 
collect_reg_dump(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2863f856f099SNavdeep Parhar static int collect_reg_dump(struct cudbg_init *pdbg_init,
2864f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
2865f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
2866f856f099SNavdeep Parhar {
2867f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2868f856f099SNavdeep Parhar 	struct cudbg_buffer tmp_scratch_buff;
2869f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2870f856f099SNavdeep Parhar 	unsigned long	     bytes_read = 0;
2871f856f099SNavdeep Parhar 	unsigned long	     bytes_left;
2872f856f099SNavdeep Parhar 	u32		     buf_size = 0, bytes = 0;
2873f856f099SNavdeep Parhar 	int		     rc = 0;
2874f856f099SNavdeep Parhar 
2875f856f099SNavdeep Parhar 	if (is_t4(padap))
2876f856f099SNavdeep Parhar 		buf_size = T4_REGMAP_SIZE ;/*+ sizeof(unsigned int);*/
2877f856f099SNavdeep Parhar 	else if (is_t5(padap) || is_t6(padap))
2878f856f099SNavdeep Parhar 		buf_size = T5_REGMAP_SIZE;
2879f856f099SNavdeep Parhar 
2880f856f099SNavdeep Parhar 	scratch_buff.size = buf_size;
2881f856f099SNavdeep Parhar 
2882f856f099SNavdeep Parhar 	tmp_scratch_buff = scratch_buff;
2883f856f099SNavdeep Parhar 
2884f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
2885f856f099SNavdeep Parhar 	if (rc)
2886f856f099SNavdeep Parhar 		goto err;
2887f856f099SNavdeep Parhar 
2888f856f099SNavdeep Parhar 	/* no return */
2889f856f099SNavdeep Parhar 	t4_get_regs(padap, (void *)scratch_buff.data, scratch_buff.size);
2890f856f099SNavdeep Parhar 	bytes_left =   scratch_buff.size;
2891f856f099SNavdeep Parhar 
2892f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2893f856f099SNavdeep Parhar 	if (rc)
2894f856f099SNavdeep Parhar 		goto err1;
2895f856f099SNavdeep Parhar 
2896f856f099SNavdeep Parhar 	while (bytes_left > 0) {
2897f856f099SNavdeep Parhar 		tmp_scratch_buff.data =
2898f856f099SNavdeep Parhar 			((char *)scratch_buff.data) + bytes_read;
2899f856f099SNavdeep Parhar 		bytes = min_t(unsigned long, bytes_left, (unsigned long)CUDBG_CHUNK_SIZE);
2900f856f099SNavdeep Parhar 		tmp_scratch_buff.size = bytes;
2901f856f099SNavdeep Parhar 		compress_buff(&tmp_scratch_buff, dbg_buff);
2902f856f099SNavdeep Parhar 		bytes_left -= bytes;
2903f856f099SNavdeep Parhar 		bytes_read += bytes;
2904f856f099SNavdeep Parhar 	}
2905f856f099SNavdeep Parhar 
2906f856f099SNavdeep Parhar err1:
2907f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2908f856f099SNavdeep Parhar err:
2909f856f099SNavdeep Parhar 	return rc;
2910f856f099SNavdeep Parhar }
2911f856f099SNavdeep Parhar 
collect_cctrl(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)2912f856f099SNavdeep Parhar static int collect_cctrl(struct cudbg_init *pdbg_init,
2913f856f099SNavdeep Parhar 			 struct cudbg_buffer *dbg_buff,
2914f856f099SNavdeep Parhar 			 struct cudbg_error *cudbg_err)
2915f856f099SNavdeep Parhar {
2916f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
2917f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
2918f856f099SNavdeep Parhar 	u32 size;
2919f856f099SNavdeep Parhar 	int rc;
2920f856f099SNavdeep Parhar 
2921f856f099SNavdeep Parhar 	size = sizeof(u16) * NMTUS * NCCTRL_WIN;
2922f856f099SNavdeep Parhar 	scratch_buff.size = size;
2923f856f099SNavdeep Parhar 
2924f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
2925f856f099SNavdeep Parhar 	if (rc)
2926f856f099SNavdeep Parhar 		goto err;
2927f856f099SNavdeep Parhar 
2928f856f099SNavdeep Parhar 	t4_read_cong_tbl(padap, (void *)scratch_buff.data);
2929f856f099SNavdeep Parhar 
2930f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
2931f856f099SNavdeep Parhar 	if (rc)
2932f856f099SNavdeep Parhar 		goto err1;
2933f856f099SNavdeep Parhar 
2934f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
2935f856f099SNavdeep Parhar 
2936f856f099SNavdeep Parhar err1:
2937f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
2938f856f099SNavdeep Parhar err:
2939f856f099SNavdeep Parhar 	return rc;
2940f856f099SNavdeep Parhar }
2941f856f099SNavdeep Parhar 
check_busy_bit(struct adapter * padap)2942f856f099SNavdeep Parhar static int check_busy_bit(struct adapter *padap)
2943f856f099SNavdeep Parhar {
2944f856f099SNavdeep Parhar 	u32 val;
2945f856f099SNavdeep Parhar 	u32 busy = 1;
2946f856f099SNavdeep Parhar 	int i = 0;
2947f856f099SNavdeep Parhar 	int retry = 10;
2948f856f099SNavdeep Parhar 	int status = 0;
2949f856f099SNavdeep Parhar 
2950*fb0493d5SDimitry Andric 	while (busy && i < retry) {
2951f856f099SNavdeep Parhar 		val = t4_read_reg(padap, A_CIM_HOST_ACC_CTRL);
2952f856f099SNavdeep Parhar 		busy = (0 != (val & CUDBG_CIM_BUSY_BIT));
2953f856f099SNavdeep Parhar 		i++;
2954f856f099SNavdeep Parhar 	}
2955f856f099SNavdeep Parhar 
2956f856f099SNavdeep Parhar 	if (busy)
2957f856f099SNavdeep Parhar 		status = -1;
2958f856f099SNavdeep Parhar 
2959f856f099SNavdeep Parhar 	return status;
2960f856f099SNavdeep Parhar }
2961f856f099SNavdeep Parhar 
cim_ha_rreg(struct adapter * padap,u32 addr,u32 * val)2962f856f099SNavdeep Parhar static int cim_ha_rreg(struct adapter *padap, u32 addr, u32 *val)
2963f856f099SNavdeep Parhar {
2964f856f099SNavdeep Parhar 	int rc = 0;
2965f856f099SNavdeep Parhar 
2966f856f099SNavdeep Parhar 	/* write register address into the A_CIM_HOST_ACC_CTRL */
2967f856f099SNavdeep Parhar 	t4_write_reg(padap, A_CIM_HOST_ACC_CTRL, addr);
2968f856f099SNavdeep Parhar 
2969f856f099SNavdeep Parhar 	/* Poll HOSTBUSY */
2970f856f099SNavdeep Parhar 	rc = check_busy_bit(padap);
2971f856f099SNavdeep Parhar 	if (rc)
2972f856f099SNavdeep Parhar 		goto err;
2973f856f099SNavdeep Parhar 
2974f856f099SNavdeep Parhar 	/* Read value from A_CIM_HOST_ACC_DATA */
2975f856f099SNavdeep Parhar 	*val = t4_read_reg(padap, A_CIM_HOST_ACC_DATA);
2976f856f099SNavdeep Parhar 
2977f856f099SNavdeep Parhar err:
2978f856f099SNavdeep Parhar 	return rc;
2979f856f099SNavdeep Parhar }
2980f856f099SNavdeep Parhar 
dump_up_cim(struct adapter * padap,struct cudbg_init * pdbg_init,struct ireg_field * up_cim_reg,u32 * buff)2981f856f099SNavdeep Parhar static int dump_up_cim(struct adapter *padap, struct cudbg_init *pdbg_init,
2982f856f099SNavdeep Parhar 		       struct ireg_field *up_cim_reg, u32 *buff)
2983f856f099SNavdeep Parhar {
2984f856f099SNavdeep Parhar 	u32 i;
2985f856f099SNavdeep Parhar 	int rc = 0;
2986f856f099SNavdeep Parhar 
2987f856f099SNavdeep Parhar 	for (i = 0; i < up_cim_reg->ireg_offset_range; i++) {
2988f856f099SNavdeep Parhar 		rc = cim_ha_rreg(padap,
2989f856f099SNavdeep Parhar 				 up_cim_reg->ireg_local_offset + (i * 4),
2990f856f099SNavdeep Parhar 				buff);
2991f856f099SNavdeep Parhar 		if (rc) {
2992f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
2993f856f099SNavdeep Parhar 				pdbg_init->print("BUSY timeout reading"
2994f856f099SNavdeep Parhar 					 "CIM_HOST_ACC_CTRL\n");
2995f856f099SNavdeep Parhar 			goto err;
2996f856f099SNavdeep Parhar 		}
2997f856f099SNavdeep Parhar 
2998f856f099SNavdeep Parhar 		buff++;
2999f856f099SNavdeep Parhar 	}
3000f856f099SNavdeep Parhar 
3001f856f099SNavdeep Parhar err:
3002f856f099SNavdeep Parhar 	return rc;
3003f856f099SNavdeep Parhar }
3004f856f099SNavdeep Parhar 
collect_up_cim_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3005f856f099SNavdeep Parhar static int collect_up_cim_indirect(struct cudbg_init *pdbg_init,
3006f856f099SNavdeep Parhar 				   struct cudbg_buffer *dbg_buff,
3007f856f099SNavdeep Parhar 				   struct cudbg_error *cudbg_err)
3008f856f099SNavdeep Parhar {
3009f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3010f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3011f856f099SNavdeep Parhar 	struct ireg_buf *up_cim;
3012f856f099SNavdeep Parhar 	u32 size;
3013f856f099SNavdeep Parhar 	int i, rc, n;
3014f856f099SNavdeep Parhar 
3015f856f099SNavdeep Parhar 	n = sizeof(t5_up_cim_reg_array) / (4 * sizeof(u32));
3016f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n;
3017f856f099SNavdeep Parhar 	scratch_buff.size = size;
3018f856f099SNavdeep Parhar 
3019f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3020f856f099SNavdeep Parhar 	if (rc)
3021f856f099SNavdeep Parhar 		goto err;
3022f856f099SNavdeep Parhar 
3023f856f099SNavdeep Parhar 	up_cim = (struct ireg_buf *)scratch_buff.data;
3024f856f099SNavdeep Parhar 
3025f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3026f856f099SNavdeep Parhar 		struct ireg_field *up_cim_reg = &up_cim->tp_pio;
3027f856f099SNavdeep Parhar 		u32 *buff = up_cim->outbuf;
3028f856f099SNavdeep Parhar 
3029f856f099SNavdeep Parhar 		if (is_t5(padap)) {
3030f856f099SNavdeep Parhar 			up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
3031f856f099SNavdeep Parhar 			up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
3032f856f099SNavdeep Parhar 			up_cim_reg->ireg_local_offset =
3033f856f099SNavdeep Parhar 						t5_up_cim_reg_array[i][2];
3034f856f099SNavdeep Parhar 			up_cim_reg->ireg_offset_range =
3035f856f099SNavdeep Parhar 						t5_up_cim_reg_array[i][3];
3036f856f099SNavdeep Parhar 		} else if (is_t6(padap)) {
3037f856f099SNavdeep Parhar 			up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
3038f856f099SNavdeep Parhar 			up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
3039f856f099SNavdeep Parhar 			up_cim_reg->ireg_local_offset =
3040f856f099SNavdeep Parhar 						t6_up_cim_reg_array[i][2];
3041f856f099SNavdeep Parhar 			up_cim_reg->ireg_offset_range =
3042f856f099SNavdeep Parhar 						t6_up_cim_reg_array[i][3];
3043f856f099SNavdeep Parhar 		}
3044f856f099SNavdeep Parhar 
3045f856f099SNavdeep Parhar 		rc = dump_up_cim(padap, pdbg_init, up_cim_reg, buff);
3046f856f099SNavdeep Parhar 
3047f856f099SNavdeep Parhar 		up_cim++;
3048f856f099SNavdeep Parhar 	}
3049f856f099SNavdeep Parhar 
3050f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3051f856f099SNavdeep Parhar 	if (rc)
3052f856f099SNavdeep Parhar 		goto err1;
3053f856f099SNavdeep Parhar 
3054f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3055f856f099SNavdeep Parhar 
3056f856f099SNavdeep Parhar err1:
3057f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3058f856f099SNavdeep Parhar err:
3059f856f099SNavdeep Parhar 	return rc;
3060f856f099SNavdeep Parhar }
3061f856f099SNavdeep Parhar 
collect_mbox_log(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3062f856f099SNavdeep Parhar static int collect_mbox_log(struct cudbg_init *pdbg_init,
3063f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
3064f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
3065f856f099SNavdeep Parhar {
3066f856f099SNavdeep Parhar #ifdef notyet
3067f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3068f856f099SNavdeep Parhar 	struct cudbg_mbox_log *mboxlog = NULL;
3069f856f099SNavdeep Parhar 	struct mbox_cmd_log *log = NULL;
3070f856f099SNavdeep Parhar 	struct mbox_cmd *entry;
3071f856f099SNavdeep Parhar 	u64 flit;
3072f856f099SNavdeep Parhar 	u32 size;
3073f856f099SNavdeep Parhar 	unsigned int entry_idx;
3074f856f099SNavdeep Parhar 	int i, k, rc;
3075f856f099SNavdeep Parhar 	u16 mbox_cmds;
3076f856f099SNavdeep Parhar 
3077f856f099SNavdeep Parhar 	if (pdbg_init->dbg_params[CUDBG_MBOX_LOG_PARAM].u.mboxlog_param.log) {
3078f856f099SNavdeep Parhar 		log = pdbg_init->dbg_params[CUDBG_MBOX_LOG_PARAM].u.
3079f856f099SNavdeep Parhar 			mboxlog_param.log;
3080f856f099SNavdeep Parhar 		mbox_cmds = pdbg_init->dbg_params[CUDBG_MBOX_LOG_PARAM].u.
3081f856f099SNavdeep Parhar 				mboxlog_param.mbox_cmds;
3082f856f099SNavdeep Parhar 	} else {
3083f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
3084f856f099SNavdeep Parhar 			pdbg_init->print("Mbox log is not requested\n");
3085f856f099SNavdeep Parhar 		return CUDBG_STATUS_ENTITY_NOT_REQUESTED;
3086f856f099SNavdeep Parhar 	}
3087f856f099SNavdeep Parhar 
3088f856f099SNavdeep Parhar 	size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
3089f856f099SNavdeep Parhar 	scratch_buff.size = size;
3090f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3091f856f099SNavdeep Parhar 	if (rc)
3092f856f099SNavdeep Parhar 		goto err;
3093f856f099SNavdeep Parhar 
3094f856f099SNavdeep Parhar 	mboxlog = (struct cudbg_mbox_log *)scratch_buff.data;
3095f856f099SNavdeep Parhar 
3096f856f099SNavdeep Parhar 	for (k = 0; k < mbox_cmds; k++) {
3097f856f099SNavdeep Parhar 		entry_idx = log->cursor + k;
3098f856f099SNavdeep Parhar 		if (entry_idx >= log->size)
3099f856f099SNavdeep Parhar 			entry_idx -= log->size;
3100f856f099SNavdeep Parhar 		entry = mbox_cmd_log_entry(log, entry_idx);
3101f856f099SNavdeep Parhar 
3102f856f099SNavdeep Parhar 		/* skip over unused entries */
3103f856f099SNavdeep Parhar 		if (entry->timestamp == 0)
3104f856f099SNavdeep Parhar 			continue;
3105f856f099SNavdeep Parhar 
3106f856f099SNavdeep Parhar 		memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
3107f856f099SNavdeep Parhar 
3108f856f099SNavdeep Parhar 		for (i = 0; i < MBOX_LEN / 8; i++) {
3109f856f099SNavdeep Parhar 			flit = entry->cmd[i];
3110f856f099SNavdeep Parhar 			mboxlog->hi[i] = (u32)(flit >> 32);
3111f856f099SNavdeep Parhar 			mboxlog->lo[i] = (u32)flit;
3112f856f099SNavdeep Parhar 		}
3113f856f099SNavdeep Parhar 
3114f856f099SNavdeep Parhar 		mboxlog++;
3115f856f099SNavdeep Parhar 	}
3116f856f099SNavdeep Parhar 
3117f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3118f856f099SNavdeep Parhar 	if (rc)
3119f856f099SNavdeep Parhar 		goto err1;
3120f856f099SNavdeep Parhar 
3121f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3122f856f099SNavdeep Parhar 
3123f856f099SNavdeep Parhar err1:
3124f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3125f856f099SNavdeep Parhar err:
3126f856f099SNavdeep Parhar 	return rc;
3127f856f099SNavdeep Parhar #endif
31286cc4520bSNavdeep Parhar 	return (CUDBG_STATUS_NOT_IMPLEMENTED);
3129f856f099SNavdeep Parhar }
3130f856f099SNavdeep Parhar 
collect_pbt_tables(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3131f856f099SNavdeep Parhar static int collect_pbt_tables(struct cudbg_init *pdbg_init,
3132f856f099SNavdeep Parhar 			      struct cudbg_buffer *dbg_buff,
3133f856f099SNavdeep Parhar 			      struct cudbg_error *cudbg_err)
3134f856f099SNavdeep Parhar {
3135f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3136f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3137f856f099SNavdeep Parhar 	struct cudbg_pbt_tables *pbt = NULL;
3138f856f099SNavdeep Parhar 	u32 size;
3139f856f099SNavdeep Parhar 	u32 addr;
3140f856f099SNavdeep Parhar 	int i, rc;
3141f856f099SNavdeep Parhar 
3142f856f099SNavdeep Parhar 	size = sizeof(struct cudbg_pbt_tables);
3143f856f099SNavdeep Parhar 	scratch_buff.size = size;
3144f856f099SNavdeep Parhar 
3145f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3146f856f099SNavdeep Parhar 	if (rc)
3147f856f099SNavdeep Parhar 		goto err;
3148f856f099SNavdeep Parhar 
3149f856f099SNavdeep Parhar 	pbt = (struct cudbg_pbt_tables *)scratch_buff.data;
3150f856f099SNavdeep Parhar 
3151f856f099SNavdeep Parhar 	/* PBT dynamic entries */
3152f856f099SNavdeep Parhar 	addr = CUDBG_CHAC_PBT_ADDR;
3153f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
3154f856f099SNavdeep Parhar 		rc = cim_ha_rreg(padap, addr + (i * 4), &pbt->pbt_dynamic[i]);
3155f856f099SNavdeep Parhar 		if (rc) {
3156f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
3157f856f099SNavdeep Parhar 				pdbg_init->print("BUSY timeout reading"
3158f856f099SNavdeep Parhar 					 "CIM_HOST_ACC_CTRL\n");
3159f856f099SNavdeep Parhar 			goto err1;
3160f856f099SNavdeep Parhar 		}
3161f856f099SNavdeep Parhar 	}
3162f856f099SNavdeep Parhar 
3163f856f099SNavdeep Parhar 	/* PBT static entries */
3164f856f099SNavdeep Parhar 
3165f856f099SNavdeep Parhar 	/* static entries start when bit 6 is set */
3166f856f099SNavdeep Parhar 	addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
3167f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
3168f856f099SNavdeep Parhar 		rc = cim_ha_rreg(padap, addr + (i * 4), &pbt->pbt_static[i]);
3169f856f099SNavdeep Parhar 		if (rc) {
3170f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
3171f856f099SNavdeep Parhar 				pdbg_init->print("BUSY timeout reading"
3172f856f099SNavdeep Parhar 					 "CIM_HOST_ACC_CTRL\n");
3173f856f099SNavdeep Parhar 			goto err1;
3174f856f099SNavdeep Parhar 		}
3175f856f099SNavdeep Parhar 	}
3176f856f099SNavdeep Parhar 
3177f856f099SNavdeep Parhar 	/* LRF entries */
3178f856f099SNavdeep Parhar 	addr = CUDBG_CHAC_PBT_LRF;
3179f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
3180f856f099SNavdeep Parhar 		rc = cim_ha_rreg(padap, addr + (i * 4), &pbt->lrf_table[i]);
3181f856f099SNavdeep Parhar 		if (rc) {
3182f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
3183f856f099SNavdeep Parhar 				pdbg_init->print("BUSY timeout reading"
3184f856f099SNavdeep Parhar 					 "CIM_HOST_ACC_CTRL\n");
3185f856f099SNavdeep Parhar 			goto err1;
3186f856f099SNavdeep Parhar 		}
3187f856f099SNavdeep Parhar 	}
3188f856f099SNavdeep Parhar 
3189f856f099SNavdeep Parhar 	/* PBT data entries */
3190f856f099SNavdeep Parhar 	addr = CUDBG_CHAC_PBT_DATA;
3191f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
3192f856f099SNavdeep Parhar 		rc = cim_ha_rreg(padap, addr + (i * 4), &pbt->pbt_data[i]);
3193f856f099SNavdeep Parhar 		if (rc) {
3194f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
3195f856f099SNavdeep Parhar 				pdbg_init->print("BUSY timeout reading"
3196f856f099SNavdeep Parhar 					 "CIM_HOST_ACC_CTRL\n");
3197f856f099SNavdeep Parhar 			goto err1;
3198f856f099SNavdeep Parhar 		}
3199f856f099SNavdeep Parhar 	}
3200f856f099SNavdeep Parhar 
3201f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3202f856f099SNavdeep Parhar 	if (rc)
3203f856f099SNavdeep Parhar 		goto err1;
3204f856f099SNavdeep Parhar 
3205f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3206f856f099SNavdeep Parhar 
3207f856f099SNavdeep Parhar err1:
3208f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3209f856f099SNavdeep Parhar err:
3210f856f099SNavdeep Parhar 	return rc;
3211f856f099SNavdeep Parhar }
3212f856f099SNavdeep Parhar 
collect_pm_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3213f856f099SNavdeep Parhar static int collect_pm_indirect(struct cudbg_init *pdbg_init,
3214f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
3215f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
3216f856f099SNavdeep Parhar {
3217f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3218f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3219f856f099SNavdeep Parhar 	struct ireg_buf *ch_pm;
3220f856f099SNavdeep Parhar 	u32 size;
3221f856f099SNavdeep Parhar 	int i, rc, n;
3222f856f099SNavdeep Parhar 
3223f856f099SNavdeep Parhar 	n = sizeof(t5_pm_rx_array) / (4 * sizeof(u32));
3224f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n * 2;
3225f856f099SNavdeep Parhar 	scratch_buff.size = size;
3226f856f099SNavdeep Parhar 
3227f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3228f856f099SNavdeep Parhar 	if (rc)
3229f856f099SNavdeep Parhar 		goto err;
3230f856f099SNavdeep Parhar 
3231f856f099SNavdeep Parhar 	ch_pm = (struct ireg_buf *)scratch_buff.data;
3232f856f099SNavdeep Parhar 
3233f856f099SNavdeep Parhar 	/*PM_RX*/
3234f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3235f856f099SNavdeep Parhar 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
3236f856f099SNavdeep Parhar 		u32 *buff = ch_pm->outbuf;
3237f856f099SNavdeep Parhar 
3238f856f099SNavdeep Parhar 		pm_pio->ireg_addr = t5_pm_rx_array[i][0];
3239f856f099SNavdeep Parhar 		pm_pio->ireg_data = t5_pm_rx_array[i][1];
3240f856f099SNavdeep Parhar 		pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
3241f856f099SNavdeep Parhar 		pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
3242f856f099SNavdeep Parhar 
3243f856f099SNavdeep Parhar 		t4_read_indirect(padap,
3244f856f099SNavdeep Parhar 				pm_pio->ireg_addr,
3245f856f099SNavdeep Parhar 				pm_pio->ireg_data,
3246f856f099SNavdeep Parhar 				buff,
3247f856f099SNavdeep Parhar 				pm_pio->ireg_offset_range,
3248f856f099SNavdeep Parhar 				pm_pio->ireg_local_offset);
3249f856f099SNavdeep Parhar 
3250f856f099SNavdeep Parhar 		ch_pm++;
3251f856f099SNavdeep Parhar 	}
3252f856f099SNavdeep Parhar 
3253f856f099SNavdeep Parhar 	/*PM_Tx*/
3254f856f099SNavdeep Parhar 	n = sizeof(t5_pm_tx_array) / (4 * sizeof(u32));
3255f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3256f856f099SNavdeep Parhar 		struct ireg_field *pm_pio = &ch_pm->tp_pio;
3257f856f099SNavdeep Parhar 		u32 *buff = ch_pm->outbuf;
3258f856f099SNavdeep Parhar 
3259f856f099SNavdeep Parhar 		pm_pio->ireg_addr = t5_pm_tx_array[i][0];
3260f856f099SNavdeep Parhar 		pm_pio->ireg_data = t5_pm_tx_array[i][1];
3261f856f099SNavdeep Parhar 		pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
3262f856f099SNavdeep Parhar 		pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
3263f856f099SNavdeep Parhar 
3264f856f099SNavdeep Parhar 		t4_read_indirect(padap,
3265f856f099SNavdeep Parhar 				pm_pio->ireg_addr,
3266f856f099SNavdeep Parhar 				pm_pio->ireg_data,
3267f856f099SNavdeep Parhar 				buff,
3268f856f099SNavdeep Parhar 				pm_pio->ireg_offset_range,
3269f856f099SNavdeep Parhar 				pm_pio->ireg_local_offset);
3270f856f099SNavdeep Parhar 
3271f856f099SNavdeep Parhar 		ch_pm++;
3272f856f099SNavdeep Parhar 	}
3273f856f099SNavdeep Parhar 
3274f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3275f856f099SNavdeep Parhar 	if (rc)
3276f856f099SNavdeep Parhar 		goto err1;
3277f856f099SNavdeep Parhar 
3278f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3279f856f099SNavdeep Parhar 
3280f856f099SNavdeep Parhar err1:
3281f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3282f856f099SNavdeep Parhar err:
3283f856f099SNavdeep Parhar 	return rc;
3284f856f099SNavdeep Parhar 
3285f856f099SNavdeep Parhar }
3286f856f099SNavdeep Parhar 
collect_tid(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3287f856f099SNavdeep Parhar static int collect_tid(struct cudbg_init *pdbg_init,
3288f856f099SNavdeep Parhar 		       struct cudbg_buffer *dbg_buff,
3289f856f099SNavdeep Parhar 		       struct cudbg_error *cudbg_err)
3290f856f099SNavdeep Parhar {
3291f856f099SNavdeep Parhar 
3292f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3293f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3294f856f099SNavdeep Parhar 	struct tid_info_region *tid;
3295f856f099SNavdeep Parhar 	struct tid_info_region_rev1 *tid1;
3296f856f099SNavdeep Parhar 	u32 para[7], val[7];
3297f856f099SNavdeep Parhar 	u32 mbox, pf;
3298f856f099SNavdeep Parhar 	int rc;
3299f856f099SNavdeep Parhar 
3300f856f099SNavdeep Parhar 	scratch_buff.size = sizeof(struct tid_info_region_rev1);
3301f856f099SNavdeep Parhar 
3302f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3303f856f099SNavdeep Parhar 	if (rc)
3304f856f099SNavdeep Parhar 		goto err;
3305f856f099SNavdeep Parhar 
3306f856f099SNavdeep Parhar #define FW_PARAM_DEV_A(param) \
3307f856f099SNavdeep Parhar 	(V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
3308f856f099SNavdeep Parhar 	 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
3309f856f099SNavdeep Parhar #define FW_PARAM_PFVF_A(param) \
3310f856f099SNavdeep Parhar 	(V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
3311f856f099SNavdeep Parhar 	 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param)|  \
3312f856f099SNavdeep Parhar 	 V_FW_PARAMS_PARAM_Y(0) | \
3313f856f099SNavdeep Parhar 	 V_FW_PARAMS_PARAM_Z(0))
3314f856f099SNavdeep Parhar #define MAX_ATIDS_A 8192U
3315f856f099SNavdeep Parhar 
3316f856f099SNavdeep Parhar 	tid1 = (struct tid_info_region_rev1 *)scratch_buff.data;
3317f856f099SNavdeep Parhar 	tid = &(tid1->tid);
3318f856f099SNavdeep Parhar 	tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
3319f856f099SNavdeep Parhar 	tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
3320f856f099SNavdeep Parhar 	tid1->ver_hdr.size = sizeof(struct tid_info_region_rev1) -
3321f856f099SNavdeep Parhar 			     sizeof(struct cudbg_ver_hdr);
3322f856f099SNavdeep Parhar 
3323f856f099SNavdeep Parhar 	if (is_t5(padap)) {
3324f856f099SNavdeep Parhar 		tid->hash_base = t4_read_reg(padap, A_LE_DB_TID_HASHBASE);
3325f856f099SNavdeep Parhar 		tid1->tid_start = 0;
3326f856f099SNavdeep Parhar 	} else if (is_t6(padap)) {
3327f856f099SNavdeep Parhar 		tid->hash_base = t4_read_reg(padap, A_T6_LE_DB_HASH_TID_BASE);
3328f856f099SNavdeep Parhar 		tid1->tid_start = t4_read_reg(padap, A_LE_DB_ACTIVE_TABLE_START_INDEX);
3329f856f099SNavdeep Parhar 	}
3330f856f099SNavdeep Parhar 
3331f856f099SNavdeep Parhar 	tid->le_db_conf = t4_read_reg(padap, A_LE_DB_CONFIG);
3332f856f099SNavdeep Parhar 
3333f856f099SNavdeep Parhar 	para[0] = FW_PARAM_PFVF_A(FILTER_START);
3334f856f099SNavdeep Parhar 	para[1] = FW_PARAM_PFVF_A(FILTER_END);
3335f856f099SNavdeep Parhar 	para[2] = FW_PARAM_PFVF_A(ACTIVE_FILTER_START);
3336f856f099SNavdeep Parhar 	para[3] = FW_PARAM_PFVF_A(ACTIVE_FILTER_END);
3337f856f099SNavdeep Parhar 	para[4] = FW_PARAM_DEV_A(NTID);
3338f856f099SNavdeep Parhar 	para[5] = FW_PARAM_PFVF_A(SERVER_START);
3339f856f099SNavdeep Parhar 	para[6] = FW_PARAM_PFVF_A(SERVER_END);
3340f856f099SNavdeep Parhar 
33418ee789e9SNavdeep Parhar 	rc = begin_synchronized_op(padap, NULL, SLEEP_OK | INTR_OK, "t4cudq");
33428ee789e9SNavdeep Parhar 	if (rc)
33438ee789e9SNavdeep Parhar 		goto err;
3344f856f099SNavdeep Parhar 	mbox = padap->mbox;
3345f856f099SNavdeep Parhar 	pf = padap->pf;
3346f856f099SNavdeep Parhar 	rc = t4_query_params(padap, mbox, pf, 0, 7, para, val);
3347f856f099SNavdeep Parhar 	if (rc <  0) {
3348f856f099SNavdeep Parhar 		if (rc == -FW_EPERM) {
3349f856f099SNavdeep Parhar 			/* It looks like we don't have permission to use
3350f856f099SNavdeep Parhar 			 * padap->mbox.
3351f856f099SNavdeep Parhar 			 *
3352f856f099SNavdeep Parhar 			 * Try mbox 4.  If it works, we'll continue to
3353f856f099SNavdeep Parhar 			 * collect the rest of tid info from mbox 4.
3354f856f099SNavdeep Parhar 			 * Else, quit trying to collect tid info.
3355f856f099SNavdeep Parhar 			 */
3356f856f099SNavdeep Parhar 			mbox = 4;
3357f856f099SNavdeep Parhar 			pf = 4;
3358f856f099SNavdeep Parhar 			rc = t4_query_params(padap, mbox, pf, 0, 7, para, val);
3359f856f099SNavdeep Parhar 			if (rc < 0) {
3360f856f099SNavdeep Parhar 				cudbg_err->sys_err = rc;
3361f856f099SNavdeep Parhar 				goto err1;
3362f856f099SNavdeep Parhar 			}
3363f856f099SNavdeep Parhar 		} else {
3364f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
3365f856f099SNavdeep Parhar 			goto err1;
3366f856f099SNavdeep Parhar 		}
3367f856f099SNavdeep Parhar 	}
3368f856f099SNavdeep Parhar 
3369f856f099SNavdeep Parhar 	tid->ftid_base = val[0];
3370f856f099SNavdeep Parhar 	tid->nftids = val[1] - val[0] + 1;
3371f856f099SNavdeep Parhar 	/*active filter region*/
3372f856f099SNavdeep Parhar 	if (val[2] != val[3]) {
3373f856f099SNavdeep Parhar #ifdef notyet
3374f856f099SNavdeep Parhar 		tid->flags |= FW_OFLD_CONN;
3375f856f099SNavdeep Parhar #endif
3376f856f099SNavdeep Parhar 		tid->aftid_base = val[2];
3377f856f099SNavdeep Parhar 		tid->aftid_end = val[3];
3378f856f099SNavdeep Parhar 	}
3379f856f099SNavdeep Parhar 	tid->ntids = val[4];
3380f856f099SNavdeep Parhar 	tid->natids = min_t(u32, tid->ntids / 2, MAX_ATIDS_A);
3381f856f099SNavdeep Parhar 	tid->stid_base = val[5];
3382f856f099SNavdeep Parhar 	tid->nstids = val[6] - val[5] + 1;
3383f856f099SNavdeep Parhar 
3384f856f099SNavdeep Parhar 	if (chip_id(padap) >= CHELSIO_T6) {
3385f856f099SNavdeep Parhar 		para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
3386f856f099SNavdeep Parhar 		para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
3387f856f099SNavdeep Parhar 		rc = t4_query_params(padap, mbox, pf, 0, 2, para, val);
3388f856f099SNavdeep Parhar 		if (rc < 0) {
3389f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
3390f856f099SNavdeep Parhar 			goto err1;
3391f856f099SNavdeep Parhar 		}
3392f856f099SNavdeep Parhar 
3393f856f099SNavdeep Parhar 		tid->hpftid_base = val[0];
3394f856f099SNavdeep Parhar 		tid->nhpftids = val[1] - val[0] + 1;
3395f856f099SNavdeep Parhar 	}
3396f856f099SNavdeep Parhar 
3397f856f099SNavdeep Parhar 	if (chip_id(padap) <= CHELSIO_T5) {
3398f856f099SNavdeep Parhar 		tid->sb = t4_read_reg(padap, A_LE_DB_SERVER_INDEX) / 4;
3399f856f099SNavdeep Parhar 		tid->hash_base /= 4;
3400f856f099SNavdeep Parhar 	} else
3401f856f099SNavdeep Parhar 		tid->sb = t4_read_reg(padap, A_LE_DB_SRVR_START_INDEX);
3402f856f099SNavdeep Parhar 
3403f856f099SNavdeep Parhar 	/*UO context range*/
3404f856f099SNavdeep Parhar 	para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
3405f856f099SNavdeep Parhar 	para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
3406f856f099SNavdeep Parhar 
3407f856f099SNavdeep Parhar 	rc = t4_query_params(padap, mbox, pf, 0, 2, para, val);
3408f856f099SNavdeep Parhar 	if (rc <  0) {
3409f856f099SNavdeep Parhar 		cudbg_err->sys_err = rc;
3410f856f099SNavdeep Parhar 		goto err1;
3411f856f099SNavdeep Parhar 	}
3412f856f099SNavdeep Parhar 
3413f856f099SNavdeep Parhar 	if (val[0] != val[1]) {
3414f856f099SNavdeep Parhar 		tid->uotid_base = val[0];
3415f856f099SNavdeep Parhar 		tid->nuotids = val[1] - val[0] + 1;
3416f856f099SNavdeep Parhar 	}
3417f856f099SNavdeep Parhar 	tid->IP_users = t4_read_reg(padap, A_LE_DB_ACT_CNT_IPV4);
3418f856f099SNavdeep Parhar 	tid->IPv6_users = t4_read_reg(padap, A_LE_DB_ACT_CNT_IPV6);
3419f856f099SNavdeep Parhar 
3420f856f099SNavdeep Parhar #undef FW_PARAM_PFVF_A
3421f856f099SNavdeep Parhar #undef FW_PARAM_DEV_A
3422f856f099SNavdeep Parhar #undef MAX_ATIDS_A
3423f856f099SNavdeep Parhar 
3424f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3425f856f099SNavdeep Parhar 	if (rc)
3426f856f099SNavdeep Parhar 		goto err1;
3427f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3428f856f099SNavdeep Parhar 
3429f856f099SNavdeep Parhar err1:
34308ee789e9SNavdeep Parhar 	end_synchronized_op(padap, 0);
3431f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3432f856f099SNavdeep Parhar err:
3433f856f099SNavdeep Parhar 	return rc;
3434f856f099SNavdeep Parhar }
3435f856f099SNavdeep Parhar 
collect_tx_rate(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3436f856f099SNavdeep Parhar static int collect_tx_rate(struct cudbg_init *pdbg_init,
3437f856f099SNavdeep Parhar 			   struct cudbg_buffer *dbg_buff,
3438f856f099SNavdeep Parhar 			   struct cudbg_error *cudbg_err)
3439f856f099SNavdeep Parhar {
3440f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3441f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3442f856f099SNavdeep Parhar 	struct tx_rate *tx_rate;
3443f856f099SNavdeep Parhar 	u32 size;
3444f856f099SNavdeep Parhar 	int rc;
3445f856f099SNavdeep Parhar 
3446f856f099SNavdeep Parhar 	size = sizeof(struct tx_rate);
3447f856f099SNavdeep Parhar 	scratch_buff.size = size;
3448f856f099SNavdeep Parhar 
3449f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3450f856f099SNavdeep Parhar 	if (rc)
3451f856f099SNavdeep Parhar 		goto err;
3452f856f099SNavdeep Parhar 
3453f856f099SNavdeep Parhar 	tx_rate = (struct tx_rate *)scratch_buff.data;
3454f856f099SNavdeep Parhar 	t4_get_chan_txrate(padap, tx_rate->nrate, tx_rate->orate);
3455f856f099SNavdeep Parhar 	tx_rate->nchan = padap->chip_params->nchan;
3456f856f099SNavdeep Parhar 
3457f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3458f856f099SNavdeep Parhar 	if (rc)
3459f856f099SNavdeep Parhar 		goto err1;
3460f856f099SNavdeep Parhar 
3461f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3462f856f099SNavdeep Parhar 
3463f856f099SNavdeep Parhar err1:
3464f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3465f856f099SNavdeep Parhar err:
3466f856f099SNavdeep Parhar 	return rc;
3467f856f099SNavdeep Parhar }
3468f856f099SNavdeep Parhar 
cudbg_tcamxy2valmask(u64 x,u64 y,u8 * addr,u64 * mask)3469f856f099SNavdeep Parhar static inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
3470f856f099SNavdeep Parhar {
3471f856f099SNavdeep Parhar 	*mask = x | y;
3472f856f099SNavdeep Parhar 	y = (__force u64)cpu_to_be64(y);
3473f856f099SNavdeep Parhar 	memcpy(addr, (char *)&y + 2, ETH_ALEN);
3474f856f099SNavdeep Parhar }
3475f856f099SNavdeep Parhar 
mps_rpl_backdoor(struct adapter * padap,struct fw_ldst_mps_rplc * mps_rplc)3476f856f099SNavdeep Parhar static void mps_rpl_backdoor(struct adapter *padap, struct fw_ldst_mps_rplc *mps_rplc)
3477f856f099SNavdeep Parhar {
3478f856f099SNavdeep Parhar 	if (is_t5(padap)) {
3479f856f099SNavdeep Parhar 		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
3480f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP3));
3481f856f099SNavdeep Parhar 		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
3482f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP2));
3483f856f099SNavdeep Parhar 		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
3484f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP1));
3485f856f099SNavdeep Parhar 		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
3486f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP0));
3487f856f099SNavdeep Parhar 	} else {
3488f856f099SNavdeep Parhar 		mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
3489f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP7));
3490f856f099SNavdeep Parhar 		mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
3491f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP6));
3492f856f099SNavdeep Parhar 		mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
3493f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP5));
3494f856f099SNavdeep Parhar 		mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
3495f856f099SNavdeep Parhar 							  A_MPS_VF_RPLCT_MAP4));
3496f856f099SNavdeep Parhar 	}
3497f856f099SNavdeep Parhar 	mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, A_MPS_VF_RPLCT_MAP3));
3498f856f099SNavdeep Parhar 	mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, A_MPS_VF_RPLCT_MAP2));
3499f856f099SNavdeep Parhar 	mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, A_MPS_VF_RPLCT_MAP1));
3500f856f099SNavdeep Parhar 	mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, A_MPS_VF_RPLCT_MAP0));
3501f856f099SNavdeep Parhar }
3502f856f099SNavdeep Parhar 
collect_mps_tcam(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3503f856f099SNavdeep Parhar static int collect_mps_tcam(struct cudbg_init *pdbg_init,
3504f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
3505f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
3506f856f099SNavdeep Parhar {
3507f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3508f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3509f856f099SNavdeep Parhar 	struct cudbg_mps_tcam *tcam = NULL;
3510f856f099SNavdeep Parhar 	u32 size = 0, i, n, total_size = 0;
3511f856f099SNavdeep Parhar 	u32 ctl, data2;
3512f856f099SNavdeep Parhar 	u64 tcamy, tcamx, val;
3513f856f099SNavdeep Parhar 	int rc;
3514f856f099SNavdeep Parhar 
3515f856f099SNavdeep Parhar 	n = padap->chip_params->mps_tcam_size;
3516f856f099SNavdeep Parhar 	size = sizeof(struct cudbg_mps_tcam) * n;
3517f856f099SNavdeep Parhar 	scratch_buff.size = size;
3518f856f099SNavdeep Parhar 
3519f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3520f856f099SNavdeep Parhar 	if (rc)
3521f856f099SNavdeep Parhar 		goto err;
3522f856f099SNavdeep Parhar 	memset(scratch_buff.data, 0, size);
3523f856f099SNavdeep Parhar 
3524f856f099SNavdeep Parhar 	tcam = (struct cudbg_mps_tcam *)scratch_buff.data;
3525f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3526f856f099SNavdeep Parhar 		if (chip_id(padap) >= CHELSIO_T6) {
3527f856f099SNavdeep Parhar 			/* CtlReqID   - 1: use Host Driver Requester ID
3528f856f099SNavdeep Parhar 			 * CtlCmdType - 0: Read, 1: Write
3529f856f099SNavdeep Parhar 			 * CtlTcamSel - 0: TCAM0, 1: TCAM1
3530f856f099SNavdeep Parhar 			 * CtlXYBitSel- 0: Y bit, 1: X bit
3531f856f099SNavdeep Parhar 			 */
3532f856f099SNavdeep Parhar 
3533f856f099SNavdeep Parhar 			/* Read tcamy */
3534f856f099SNavdeep Parhar 			ctl = (V_CTLREQID(1) |
3535f856f099SNavdeep Parhar 			       V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0));
3536f856f099SNavdeep Parhar 			if (i < 256)
3537f856f099SNavdeep Parhar 				ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0);
3538f856f099SNavdeep Parhar 			else
3539f856f099SNavdeep Parhar 				ctl |= V_CTLTCAMINDEX(i - 256) |
3540f856f099SNavdeep Parhar 				       V_CTLTCAMSEL(1);
3541f856f099SNavdeep Parhar 
3542f856f099SNavdeep Parhar 			t4_write_reg(padap, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
3543f856f099SNavdeep Parhar 			val = t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
3544f856f099SNavdeep Parhar 			tcamy = G_DMACH(val) << 32;
3545f856f099SNavdeep Parhar 			tcamy |= t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
3546f856f099SNavdeep Parhar 			data2 = t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
3547f856f099SNavdeep Parhar 			tcam->lookup_type = G_DATALKPTYPE(data2);
3548f856f099SNavdeep Parhar 
3549f856f099SNavdeep Parhar 			/* 0 - Outer header, 1 - Inner header
3550f856f099SNavdeep Parhar 			 * [71:48] bit locations are overloaded for
3551f856f099SNavdeep Parhar 			 * outer vs. inner lookup types.
3552f856f099SNavdeep Parhar 			 */
3553f856f099SNavdeep Parhar 
3554f856f099SNavdeep Parhar 			if (tcam->lookup_type &&
3555f856f099SNavdeep Parhar 			    (tcam->lookup_type != M_DATALKPTYPE)) {
3556f856f099SNavdeep Parhar 				/* Inner header VNI */
3557f856f099SNavdeep Parhar 				tcam->vniy = ((data2 & F_DATAVIDH2) << 23) |
3558f856f099SNavdeep Parhar 					     (G_DATAVIDH1(data2) << 16) |
3559f856f099SNavdeep Parhar 					     G_VIDL(val);
3560f856f099SNavdeep Parhar 				tcam->dip_hit = data2 & F_DATADIPHIT;
3561f856f099SNavdeep Parhar 			} else {
3562f856f099SNavdeep Parhar 				tcam->vlan_vld = data2 & F_DATAVIDH2;
3563f856f099SNavdeep Parhar 				tcam->ivlan = G_VIDL(val);
3564f856f099SNavdeep Parhar 			}
3565f856f099SNavdeep Parhar 
3566f856f099SNavdeep Parhar 			tcam->port_num = G_DATAPORTNUM(data2);
3567f856f099SNavdeep Parhar 
3568f856f099SNavdeep Parhar 			/* Read tcamx. Change the control param */
3569f856f099SNavdeep Parhar 			ctl |= V_CTLXYBITSEL(1);
3570f856f099SNavdeep Parhar 			t4_write_reg(padap, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
3571f856f099SNavdeep Parhar 			val = t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
3572f856f099SNavdeep Parhar 			tcamx = G_DMACH(val) << 32;
3573f856f099SNavdeep Parhar 			tcamx |= t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
3574f856f099SNavdeep Parhar 			data2 = t4_read_reg(padap, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
3575f856f099SNavdeep Parhar 			if (tcam->lookup_type &&
3576f856f099SNavdeep Parhar 			    (tcam->lookup_type != M_DATALKPTYPE)) {
3577f856f099SNavdeep Parhar 				/* Inner header VNI mask */
3578f856f099SNavdeep Parhar 				tcam->vnix = ((data2 & F_DATAVIDH2) << 23) |
3579f856f099SNavdeep Parhar 					     (G_DATAVIDH1(data2) << 16) |
3580f856f099SNavdeep Parhar 					     G_VIDL(val);
3581f856f099SNavdeep Parhar 			}
3582f856f099SNavdeep Parhar 		} else {
3583f856f099SNavdeep Parhar 			tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(i));
3584f856f099SNavdeep Parhar 			tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(i));
3585f856f099SNavdeep Parhar 		}
3586f856f099SNavdeep Parhar 
3587f856f099SNavdeep Parhar 		if (tcamx & tcamy)
3588f856f099SNavdeep Parhar 			continue;
3589f856f099SNavdeep Parhar 
3590f856f099SNavdeep Parhar 		tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(i));
3591f856f099SNavdeep Parhar 		tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(i));
3592f856f099SNavdeep Parhar 
3593f856f099SNavdeep Parhar 		if (is_t5(padap))
3594f856f099SNavdeep Parhar 			tcam->repli = (tcam->cls_lo & F_REPLICATE);
3595f856f099SNavdeep Parhar 		else if (is_t6(padap))
3596f856f099SNavdeep Parhar 			tcam->repli = (tcam->cls_lo & F_T6_REPLICATE);
3597f856f099SNavdeep Parhar 
3598f856f099SNavdeep Parhar 		if (tcam->repli) {
3599f856f099SNavdeep Parhar 			struct fw_ldst_cmd ldst_cmd;
3600f856f099SNavdeep Parhar 			struct fw_ldst_mps_rplc mps_rplc;
3601f856f099SNavdeep Parhar 
3602f856f099SNavdeep Parhar 			memset(&ldst_cmd, 0, sizeof(ldst_cmd));
3603f856f099SNavdeep Parhar 			ldst_cmd.op_to_addrspace =
3604f856f099SNavdeep Parhar 				htonl(V_FW_CMD_OP(FW_LDST_CMD) |
3605f856f099SNavdeep Parhar 				      F_FW_CMD_REQUEST |
3606f856f099SNavdeep Parhar 				      F_FW_CMD_READ |
3607f856f099SNavdeep Parhar 				      V_FW_LDST_CMD_ADDRSPACE(
3608f856f099SNavdeep Parhar 					      FW_LDST_ADDRSPC_MPS));
3609f856f099SNavdeep Parhar 
3610f856f099SNavdeep Parhar 			ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
3611f856f099SNavdeep Parhar 
3612f856f099SNavdeep Parhar 			ldst_cmd.u.mps.rplc.fid_idx =
3613f856f099SNavdeep Parhar 				htons(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
3614f856f099SNavdeep Parhar 				      V_FW_LDST_CMD_IDX(i));
3615f856f099SNavdeep Parhar 
36168ee789e9SNavdeep Parhar 			rc = begin_synchronized_op(padap, NULL,
36178ee789e9SNavdeep Parhar 			    SLEEP_OK | INTR_OK, "t4cudm");
36188ee789e9SNavdeep Parhar 			if (rc == 0) {
3619f856f099SNavdeep Parhar 				rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd,
3620f856f099SNavdeep Parhar 						sizeof(ldst_cmd), &ldst_cmd);
36218ee789e9SNavdeep Parhar 				end_synchronized_op(padap, 0);
36228ee789e9SNavdeep Parhar 			}
3623f856f099SNavdeep Parhar 
3624f856f099SNavdeep Parhar 			if (rc)
3625f856f099SNavdeep Parhar 				mps_rpl_backdoor(padap, &mps_rplc);
3626f856f099SNavdeep Parhar 			else
3627f856f099SNavdeep Parhar 				mps_rplc = ldst_cmd.u.mps.rplc;
3628f856f099SNavdeep Parhar 
3629f856f099SNavdeep Parhar 			tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
3630f856f099SNavdeep Parhar 			tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
3631f856f099SNavdeep Parhar 			tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
3632f856f099SNavdeep Parhar 			tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
3633f856f099SNavdeep Parhar 			if (padap->chip_params->mps_rplc_size >
3634f856f099SNavdeep Parhar 					CUDBG_MAX_RPLC_SIZE) {
3635f856f099SNavdeep Parhar 				tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
3636f856f099SNavdeep Parhar 				tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
3637f856f099SNavdeep Parhar 				tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
3638f856f099SNavdeep Parhar 				tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
3639f856f099SNavdeep Parhar 			}
3640f856f099SNavdeep Parhar 		}
3641f856f099SNavdeep Parhar 		cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
3642f856f099SNavdeep Parhar 
3643f856f099SNavdeep Parhar 		tcam->idx = i;
3644f856f099SNavdeep Parhar 		tcam->rplc_size = padap->chip_params->mps_rplc_size;
3645f856f099SNavdeep Parhar 
3646f856f099SNavdeep Parhar 		total_size += sizeof(struct cudbg_mps_tcam);
3647f856f099SNavdeep Parhar 
3648f856f099SNavdeep Parhar 		tcam++;
3649f856f099SNavdeep Parhar 	}
3650f856f099SNavdeep Parhar 
3651f856f099SNavdeep Parhar 	if (total_size == 0) {
3652f856f099SNavdeep Parhar 		rc = CUDBG_SYSTEM_ERROR;
3653f856f099SNavdeep Parhar 		goto err1;
3654f856f099SNavdeep Parhar 	}
3655f856f099SNavdeep Parhar 
3656f856f099SNavdeep Parhar 	scratch_buff.size = total_size;
3657f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3658f856f099SNavdeep Parhar 	if (rc)
3659f856f099SNavdeep Parhar 		goto err1;
3660f856f099SNavdeep Parhar 
3661f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3662f856f099SNavdeep Parhar 
3663f856f099SNavdeep Parhar err1:
3664f856f099SNavdeep Parhar 	scratch_buff.size = size;
3665f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3666f856f099SNavdeep Parhar err:
3667f856f099SNavdeep Parhar 	return rc;
3668f856f099SNavdeep Parhar }
3669f856f099SNavdeep Parhar 
collect_pcie_config(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3670f856f099SNavdeep Parhar static int collect_pcie_config(struct cudbg_init *pdbg_init,
3671f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
3672f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
3673f856f099SNavdeep Parhar {
3674f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3675f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3676f856f099SNavdeep Parhar 	u32 size, *value, j;
3677f856f099SNavdeep Parhar 	int i, rc, n;
3678f856f099SNavdeep Parhar 
3679f856f099SNavdeep Parhar 	size = sizeof(u32) * NUM_PCIE_CONFIG_REGS;
3680f856f099SNavdeep Parhar 	n = sizeof(t5_pcie_config_array) / (2 * sizeof(u32));
3681f856f099SNavdeep Parhar 	scratch_buff.size = size;
3682f856f099SNavdeep Parhar 
3683f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3684f856f099SNavdeep Parhar 	if (rc)
3685f856f099SNavdeep Parhar 		goto err;
3686f856f099SNavdeep Parhar 
3687f856f099SNavdeep Parhar 	value = (u32 *)scratch_buff.data;
3688f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3689f856f099SNavdeep Parhar 		for (j = t5_pcie_config_array[i][0];
3690f856f099SNavdeep Parhar 		     j <= t5_pcie_config_array[i][1]; j += 4) {
3691f856f099SNavdeep Parhar 			*value++ = t4_hw_pci_read_cfg4(padap, j);
3692f856f099SNavdeep Parhar 		}
3693f856f099SNavdeep Parhar 	}
3694f856f099SNavdeep Parhar 
3695f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3696f856f099SNavdeep Parhar 	if (rc)
3697f856f099SNavdeep Parhar 		goto err1;
3698f856f099SNavdeep Parhar 
3699f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3700f856f099SNavdeep Parhar 
3701f856f099SNavdeep Parhar err1:
3702f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3703f856f099SNavdeep Parhar err:
3704f856f099SNavdeep Parhar 	return rc;
3705f856f099SNavdeep Parhar }
3706f856f099SNavdeep Parhar 
cudbg_read_tid(struct cudbg_init * pdbg_init,u32 tid,struct cudbg_tid_data * tid_data)3707f856f099SNavdeep Parhar static int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
3708f856f099SNavdeep Parhar 			  struct cudbg_tid_data *tid_data)
3709f856f099SNavdeep Parhar {
3710f856f099SNavdeep Parhar 	int i, cmd_retry = 8;
3711f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3712f856f099SNavdeep Parhar 	u32 val;
3713f856f099SNavdeep Parhar 
3714f856f099SNavdeep Parhar 	/* Fill REQ_DATA regs with 0's */
3715f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_NUM_REQ_REGS; i++)
3716f856f099SNavdeep Parhar 		t4_write_reg(padap, A_LE_DB_DBGI_REQ_DATA + (i << 2), 0);
3717f856f099SNavdeep Parhar 
3718f856f099SNavdeep Parhar 	/* Write DBIG command */
3719f856f099SNavdeep Parhar 	val = (0x4 << S_DBGICMD) | tid;
3720f856f099SNavdeep Parhar 	t4_write_reg(padap, A_LE_DB_DBGI_REQ_TCAM_CMD, val);
3721f856f099SNavdeep Parhar 	tid_data->dbig_cmd = val;
3722f856f099SNavdeep Parhar 
3723f856f099SNavdeep Parhar 	val = 0;
3724f856f099SNavdeep Parhar 	val |= 1 << S_DBGICMDSTRT;
3725f856f099SNavdeep Parhar 	val |= 1;  /* LE mode */
3726f856f099SNavdeep Parhar 	t4_write_reg(padap, A_LE_DB_DBGI_CONFIG, val);
3727f856f099SNavdeep Parhar 	tid_data->dbig_conf = val;
3728f856f099SNavdeep Parhar 
3729f856f099SNavdeep Parhar 	/* Poll the DBGICMDBUSY bit */
3730f856f099SNavdeep Parhar 	val = 1;
3731f856f099SNavdeep Parhar 	while (val) {
3732f856f099SNavdeep Parhar 		val = t4_read_reg(padap, A_LE_DB_DBGI_CONFIG);
3733f856f099SNavdeep Parhar 		val = (val >> S_DBGICMDBUSY) & 1;
3734f856f099SNavdeep Parhar 		cmd_retry--;
3735f856f099SNavdeep Parhar 		if (!cmd_retry) {
3736f856f099SNavdeep Parhar 			if (pdbg_init->verbose)
3737f856f099SNavdeep Parhar 				pdbg_init->print("%s(): Timeout waiting for non-busy\n",
3738f856f099SNavdeep Parhar 					 __func__);
3739f856f099SNavdeep Parhar 			return CUDBG_SYSTEM_ERROR;
3740f856f099SNavdeep Parhar 		}
3741f856f099SNavdeep Parhar 	}
3742f856f099SNavdeep Parhar 
3743f856f099SNavdeep Parhar 	/* Check RESP status */
3744f856f099SNavdeep Parhar 	val = 0;
3745f856f099SNavdeep Parhar 	val = t4_read_reg(padap, A_LE_DB_DBGI_RSP_STATUS);
3746f856f099SNavdeep Parhar 	tid_data->dbig_rsp_stat = val;
3747f856f099SNavdeep Parhar 	if (!(val & 1)) {
3748f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
3749f856f099SNavdeep Parhar 			pdbg_init->print("%s(): DBGI command failed\n", __func__);
3750f856f099SNavdeep Parhar 		return CUDBG_SYSTEM_ERROR;
3751f856f099SNavdeep Parhar 	}
3752f856f099SNavdeep Parhar 
3753f856f099SNavdeep Parhar 	/* Read RESP data */
3754f856f099SNavdeep Parhar 	for (i = 0; i < CUDBG_NUM_REQ_REGS; i++)
3755f856f099SNavdeep Parhar 		tid_data->data[i] = t4_read_reg(padap,
3756f856f099SNavdeep Parhar 						A_LE_DB_DBGI_RSP_DATA +
3757f856f099SNavdeep Parhar 						(i << 2));
3758f856f099SNavdeep Parhar 
3759f856f099SNavdeep Parhar 	tid_data->tid = tid;
3760f856f099SNavdeep Parhar 
3761f856f099SNavdeep Parhar 	return 0;
3762f856f099SNavdeep Parhar }
3763f856f099SNavdeep Parhar 
collect_le_tcam(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3764f856f099SNavdeep Parhar static int collect_le_tcam(struct cudbg_init *pdbg_init,
3765f856f099SNavdeep Parhar 			   struct cudbg_buffer *dbg_buff,
3766f856f099SNavdeep Parhar 			   struct cudbg_error *cudbg_err)
3767f856f099SNavdeep Parhar {
3768f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3769f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3770f856f099SNavdeep Parhar 	struct cudbg_tcam tcam_region = {0};
3771f856f099SNavdeep Parhar 	struct cudbg_tid_data *tid_data = NULL;
3772f856f099SNavdeep Parhar 	u32 value, bytes = 0, bytes_left  = 0;
3773f856f099SNavdeep Parhar 	u32 i;
3774f856f099SNavdeep Parhar 	int rc, size;
3775f856f099SNavdeep Parhar 
3776f856f099SNavdeep Parhar 	/* Get the LE regions */
3777f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_TID_HASHBASE); /* Get hash base
3778f856f099SNavdeep Parhar 							     index */
3779f856f099SNavdeep Parhar 	tcam_region.tid_hash_base = value;
3780f856f099SNavdeep Parhar 
3781f856f099SNavdeep Parhar 	/* Get routing table index */
3782f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_ROUTING_TABLE_INDEX);
3783f856f099SNavdeep Parhar 	tcam_region.routing_start = value;
3784f856f099SNavdeep Parhar 
3785f856f099SNavdeep Parhar 	/*Get clip table index */
3786f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_CLIP_TABLE_INDEX);
3787f856f099SNavdeep Parhar 	tcam_region.clip_start = value;
3788f856f099SNavdeep Parhar 
3789f856f099SNavdeep Parhar 	/* Get filter table index */
3790f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_FILTER_TABLE_INDEX);
3791f856f099SNavdeep Parhar 	tcam_region.filter_start = value;
3792f856f099SNavdeep Parhar 
3793f856f099SNavdeep Parhar 	/* Get server table index */
3794f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_SERVER_INDEX);
3795f856f099SNavdeep Parhar 	tcam_region.server_start = value;
3796f856f099SNavdeep Parhar 
3797f856f099SNavdeep Parhar 	/* Check whether hash is enabled and calculate the max tids */
3798f856f099SNavdeep Parhar 	value = t4_read_reg(padap, A_LE_DB_CONFIG);
3799f856f099SNavdeep Parhar 	if ((value >> S_HASHEN) & 1) {
3800f856f099SNavdeep Parhar 		value = t4_read_reg(padap, A_LE_DB_HASH_CONFIG);
3801f856f099SNavdeep Parhar 		if (chip_id(padap) > CHELSIO_T5)
3802f856f099SNavdeep Parhar 			tcam_region.max_tid = (value & 0xFFFFF) +
3803f856f099SNavdeep Parhar 					      tcam_region.tid_hash_base;
3804f856f099SNavdeep Parhar 		else {	    /* for T5 */
3805f856f099SNavdeep Parhar 			value = G_HASHTIDSIZE(value);
3806f856f099SNavdeep Parhar 			value = 1 << value;
3807f856f099SNavdeep Parhar 			tcam_region.max_tid = value +
3808f856f099SNavdeep Parhar 				tcam_region.tid_hash_base;
3809f856f099SNavdeep Parhar 		}
3810f856f099SNavdeep Parhar 	} else	 /* hash not enabled */
3811f856f099SNavdeep Parhar 		tcam_region.max_tid = CUDBG_MAX_TCAM_TID;
3812f856f099SNavdeep Parhar 
3813f856f099SNavdeep Parhar 	size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
3814f856f099SNavdeep Parhar 	size += sizeof(struct cudbg_tcam);
3815f856f099SNavdeep Parhar 	scratch_buff.size = size;
3816f856f099SNavdeep Parhar 
3817f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3818f856f099SNavdeep Parhar 	if (rc)
3819f856f099SNavdeep Parhar 		goto err;
3820f856f099SNavdeep Parhar 
3821f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, CUDBG_CHUNK_SIZE, &scratch_buff);
3822f856f099SNavdeep Parhar 	if (rc)
3823f856f099SNavdeep Parhar 		goto err;
3824f856f099SNavdeep Parhar 
3825f856f099SNavdeep Parhar 	memcpy(scratch_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
3826f856f099SNavdeep Parhar 
3827f856f099SNavdeep Parhar 	tid_data = (struct cudbg_tid_data *)(((struct cudbg_tcam *)
3828f856f099SNavdeep Parhar 					     scratch_buff.data) + 1);
3829f856f099SNavdeep Parhar 	bytes_left = CUDBG_CHUNK_SIZE - sizeof(struct cudbg_tcam);
3830f856f099SNavdeep Parhar 	bytes = sizeof(struct cudbg_tcam);
3831f856f099SNavdeep Parhar 
3832f856f099SNavdeep Parhar 	/* read all tid */
3833f856f099SNavdeep Parhar 	for (i = 0; i < tcam_region.max_tid; i++) {
3834f856f099SNavdeep Parhar 		if (bytes_left < sizeof(struct cudbg_tid_data)) {
3835f856f099SNavdeep Parhar 			scratch_buff.size = bytes;
3836f856f099SNavdeep Parhar 			rc = compress_buff(&scratch_buff, dbg_buff);
3837f856f099SNavdeep Parhar 			if (rc)
3838f856f099SNavdeep Parhar 				goto err1;
3839f856f099SNavdeep Parhar 			scratch_buff.size = CUDBG_CHUNK_SIZE;
3840f856f099SNavdeep Parhar 			release_scratch_buff(&scratch_buff, dbg_buff);
3841f856f099SNavdeep Parhar 
3842f856f099SNavdeep Parhar 			/* new alloc */
3843f856f099SNavdeep Parhar 			rc = get_scratch_buff(dbg_buff, CUDBG_CHUNK_SIZE,
3844f856f099SNavdeep Parhar 					      &scratch_buff);
3845f856f099SNavdeep Parhar 			if (rc)
3846f856f099SNavdeep Parhar 				goto err;
3847f856f099SNavdeep Parhar 
3848f856f099SNavdeep Parhar 			tid_data = (struct cudbg_tid_data *)(scratch_buff.data);
3849f856f099SNavdeep Parhar 			bytes_left = CUDBG_CHUNK_SIZE;
3850f856f099SNavdeep Parhar 			bytes = 0;
3851f856f099SNavdeep Parhar 		}
3852f856f099SNavdeep Parhar 
3853f856f099SNavdeep Parhar 		rc = cudbg_read_tid(pdbg_init, i, tid_data);
3854f856f099SNavdeep Parhar 
3855f856f099SNavdeep Parhar 		if (rc) {
3856f856f099SNavdeep Parhar 			cudbg_err->sys_err = rc;
3857f856f099SNavdeep Parhar 			goto err1;
3858f856f099SNavdeep Parhar 		}
3859f856f099SNavdeep Parhar 
3860f856f099SNavdeep Parhar 		tid_data++;
3861f856f099SNavdeep Parhar 		bytes_left -= sizeof(struct cudbg_tid_data);
3862f856f099SNavdeep Parhar 		bytes += sizeof(struct cudbg_tid_data);
3863f856f099SNavdeep Parhar 	}
3864f856f099SNavdeep Parhar 
3865f856f099SNavdeep Parhar 	if (bytes) {
3866f856f099SNavdeep Parhar 		scratch_buff.size = bytes;
3867f856f099SNavdeep Parhar 		rc = compress_buff(&scratch_buff, dbg_buff);
3868f856f099SNavdeep Parhar 	}
3869f856f099SNavdeep Parhar 
3870f856f099SNavdeep Parhar err1:
3871f856f099SNavdeep Parhar 	scratch_buff.size = CUDBG_CHUNK_SIZE;
3872f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3873f856f099SNavdeep Parhar err:
3874f856f099SNavdeep Parhar 	return rc;
3875f856f099SNavdeep Parhar }
3876f856f099SNavdeep Parhar 
collect_ma_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3877f856f099SNavdeep Parhar static int collect_ma_indirect(struct cudbg_init *pdbg_init,
3878f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
3879f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
3880f856f099SNavdeep Parhar {
3881f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3882f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3883f856f099SNavdeep Parhar 	struct ireg_buf *ma_indr = NULL;
3884f856f099SNavdeep Parhar 	u32 size, j;
3885f856f099SNavdeep Parhar 	int i, rc, n;
3886f856f099SNavdeep Parhar 
3887f856f099SNavdeep Parhar 	if (chip_id(padap) < CHELSIO_T6) {
3888f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
3889f856f099SNavdeep Parhar 			pdbg_init->print("MA indirect available only in T6\n");
3890f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
3891f856f099SNavdeep Parhar 		goto err;
3892f856f099SNavdeep Parhar 	}
3893f856f099SNavdeep Parhar 
3894f856f099SNavdeep Parhar 	n = sizeof(t6_ma_ireg_array) / (4 * sizeof(u32));
3895f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n * 2;
3896f856f099SNavdeep Parhar 	scratch_buff.size = size;
3897f856f099SNavdeep Parhar 
3898f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3899f856f099SNavdeep Parhar 	if (rc)
3900f856f099SNavdeep Parhar 		goto err;
3901f856f099SNavdeep Parhar 
3902f856f099SNavdeep Parhar 	ma_indr = (struct ireg_buf *)scratch_buff.data;
3903f856f099SNavdeep Parhar 
3904f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3905f856f099SNavdeep Parhar 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
3906f856f099SNavdeep Parhar 		u32 *buff = ma_indr->outbuf;
3907f856f099SNavdeep Parhar 
3908f856f099SNavdeep Parhar 		ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
3909f856f099SNavdeep Parhar 		ma_fli->ireg_data = t6_ma_ireg_array[i][1];
3910f856f099SNavdeep Parhar 		ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
3911f856f099SNavdeep Parhar 		ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
3912f856f099SNavdeep Parhar 
3913f856f099SNavdeep Parhar 		t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
3914f856f099SNavdeep Parhar 				 buff, ma_fli->ireg_offset_range,
3915f856f099SNavdeep Parhar 				 ma_fli->ireg_local_offset);
3916f856f099SNavdeep Parhar 
3917f856f099SNavdeep Parhar 		ma_indr++;
3918f856f099SNavdeep Parhar 
3919f856f099SNavdeep Parhar 	}
3920f856f099SNavdeep Parhar 
3921f856f099SNavdeep Parhar 	n = sizeof(t6_ma_ireg_array2) / (4 * sizeof(u32));
3922f856f099SNavdeep Parhar 
3923f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3924f856f099SNavdeep Parhar 		struct ireg_field *ma_fli = &ma_indr->tp_pio;
3925f856f099SNavdeep Parhar 		u32 *buff = ma_indr->outbuf;
3926f856f099SNavdeep Parhar 
3927f856f099SNavdeep Parhar 		ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
3928f856f099SNavdeep Parhar 		ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
3929f856f099SNavdeep Parhar 		ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
3930f856f099SNavdeep Parhar 
3931f856f099SNavdeep Parhar 		for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
3932f856f099SNavdeep Parhar 			t4_read_indirect(padap, ma_fli->ireg_addr,
3933f856f099SNavdeep Parhar 					 ma_fli->ireg_data, buff, 1,
3934f856f099SNavdeep Parhar 					 ma_fli->ireg_local_offset);
3935f856f099SNavdeep Parhar 			buff++;
3936f856f099SNavdeep Parhar 			ma_fli->ireg_local_offset += 0x20;
3937f856f099SNavdeep Parhar 		}
3938f856f099SNavdeep Parhar 		ma_indr++;
3939f856f099SNavdeep Parhar 	}
3940f856f099SNavdeep Parhar 
3941f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3942f856f099SNavdeep Parhar 	if (rc)
3943f856f099SNavdeep Parhar 		goto err1;
3944f856f099SNavdeep Parhar 
3945f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
3946f856f099SNavdeep Parhar 
3947f856f099SNavdeep Parhar err1:
3948f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
3949f856f099SNavdeep Parhar err:
3950f856f099SNavdeep Parhar 	return rc;
3951f856f099SNavdeep Parhar }
3952f856f099SNavdeep Parhar 
collect_hma_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)3953f856f099SNavdeep Parhar static int collect_hma_indirect(struct cudbg_init *pdbg_init,
3954f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
3955f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
3956f856f099SNavdeep Parhar {
3957f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
3958f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
3959f856f099SNavdeep Parhar 	struct ireg_buf *hma_indr = NULL;
3960f856f099SNavdeep Parhar 	u32 size;
3961f856f099SNavdeep Parhar 	int i, rc, n;
3962f856f099SNavdeep Parhar 
3963f856f099SNavdeep Parhar 	if (chip_id(padap) < CHELSIO_T6) {
3964f856f099SNavdeep Parhar 		if (pdbg_init->verbose)
3965f856f099SNavdeep Parhar 			pdbg_init->print("HMA indirect available only in T6\n");
3966f856f099SNavdeep Parhar 		rc = CUDBG_STATUS_ENTITY_NOT_FOUND;
3967f856f099SNavdeep Parhar 		goto err;
3968f856f099SNavdeep Parhar 	}
3969f856f099SNavdeep Parhar 
3970f856f099SNavdeep Parhar 	n = sizeof(t6_hma_ireg_array) / (4 * sizeof(u32));
3971f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n;
3972f856f099SNavdeep Parhar 	scratch_buff.size = size;
3973f856f099SNavdeep Parhar 
3974f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
3975f856f099SNavdeep Parhar 	if (rc)
3976f856f099SNavdeep Parhar 		goto err;
3977f856f099SNavdeep Parhar 
3978f856f099SNavdeep Parhar 	hma_indr = (struct ireg_buf *)scratch_buff.data;
3979f856f099SNavdeep Parhar 
3980f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
3981f856f099SNavdeep Parhar 		struct ireg_field *hma_fli = &hma_indr->tp_pio;
3982f856f099SNavdeep Parhar 		u32 *buff = hma_indr->outbuf;
3983f856f099SNavdeep Parhar 
3984f856f099SNavdeep Parhar 		hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
3985f856f099SNavdeep Parhar 		hma_fli->ireg_data = t6_hma_ireg_array[i][1];
3986f856f099SNavdeep Parhar 		hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
3987f856f099SNavdeep Parhar 		hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
3988f856f099SNavdeep Parhar 
3989f856f099SNavdeep Parhar 		t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
3990f856f099SNavdeep Parhar 				 buff, hma_fli->ireg_offset_range,
3991f856f099SNavdeep Parhar 				 hma_fli->ireg_local_offset);
3992f856f099SNavdeep Parhar 
3993f856f099SNavdeep Parhar 		hma_indr++;
3994f856f099SNavdeep Parhar 
3995f856f099SNavdeep Parhar 	}
3996f856f099SNavdeep Parhar 
3997f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
3998f856f099SNavdeep Parhar 	if (rc)
3999f856f099SNavdeep Parhar 		goto err1;
4000f856f099SNavdeep Parhar 
4001f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4002f856f099SNavdeep Parhar 
4003f856f099SNavdeep Parhar err1:
4004f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4005f856f099SNavdeep Parhar err:
4006f856f099SNavdeep Parhar 	return rc;
4007f856f099SNavdeep Parhar }
4008f856f099SNavdeep Parhar 
collect_pcie_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)4009f856f099SNavdeep Parhar static int collect_pcie_indirect(struct cudbg_init *pdbg_init,
4010f856f099SNavdeep Parhar 				 struct cudbg_buffer *dbg_buff,
4011f856f099SNavdeep Parhar 				 struct cudbg_error *cudbg_err)
4012f856f099SNavdeep Parhar {
4013f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
4014f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
4015f856f099SNavdeep Parhar 	struct ireg_buf *ch_pcie;
4016f856f099SNavdeep Parhar 	u32 size;
4017f856f099SNavdeep Parhar 	int i, rc, n;
4018f856f099SNavdeep Parhar 
4019f856f099SNavdeep Parhar 	n = sizeof(t5_pcie_pdbg_array) / (4 * sizeof(u32));
4020f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n * 2;
4021f856f099SNavdeep Parhar 	scratch_buff.size = size;
4022f856f099SNavdeep Parhar 
4023f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
4024f856f099SNavdeep Parhar 	if (rc)
4025f856f099SNavdeep Parhar 		goto err;
4026f856f099SNavdeep Parhar 
4027f856f099SNavdeep Parhar 	ch_pcie = (struct ireg_buf *)scratch_buff.data;
4028f856f099SNavdeep Parhar 
4029f856f099SNavdeep Parhar 	/*PCIE_PDBG*/
4030f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
4031f856f099SNavdeep Parhar 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
4032f856f099SNavdeep Parhar 		u32 *buff = ch_pcie->outbuf;
4033f856f099SNavdeep Parhar 
4034f856f099SNavdeep Parhar 		pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
4035f856f099SNavdeep Parhar 		pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
4036f856f099SNavdeep Parhar 		pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
4037f856f099SNavdeep Parhar 		pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
4038f856f099SNavdeep Parhar 
4039f856f099SNavdeep Parhar 		t4_read_indirect(padap,
4040f856f099SNavdeep Parhar 				pcie_pio->ireg_addr,
4041f856f099SNavdeep Parhar 				pcie_pio->ireg_data,
4042f856f099SNavdeep Parhar 				buff,
4043f856f099SNavdeep Parhar 				pcie_pio->ireg_offset_range,
4044f856f099SNavdeep Parhar 				pcie_pio->ireg_local_offset);
4045f856f099SNavdeep Parhar 
4046f856f099SNavdeep Parhar 		ch_pcie++;
4047f856f099SNavdeep Parhar 	}
4048f856f099SNavdeep Parhar 
4049f856f099SNavdeep Parhar 	/*PCIE_CDBG*/
4050f856f099SNavdeep Parhar 	n = sizeof(t5_pcie_cdbg_array) / (4 * sizeof(u32));
4051f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
4052f856f099SNavdeep Parhar 		struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
4053f856f099SNavdeep Parhar 		u32 *buff = ch_pcie->outbuf;
4054f856f099SNavdeep Parhar 
4055f856f099SNavdeep Parhar 		pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
4056f856f099SNavdeep Parhar 		pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
4057f856f099SNavdeep Parhar 		pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
4058f856f099SNavdeep Parhar 		pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
4059f856f099SNavdeep Parhar 
4060f856f099SNavdeep Parhar 		t4_read_indirect(padap,
4061f856f099SNavdeep Parhar 				pcie_pio->ireg_addr,
4062f856f099SNavdeep Parhar 				pcie_pio->ireg_data,
4063f856f099SNavdeep Parhar 				buff,
4064f856f099SNavdeep Parhar 				pcie_pio->ireg_offset_range,
4065f856f099SNavdeep Parhar 				pcie_pio->ireg_local_offset);
4066f856f099SNavdeep Parhar 
4067f856f099SNavdeep Parhar 		ch_pcie++;
4068f856f099SNavdeep Parhar 	}
4069f856f099SNavdeep Parhar 
4070f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
4071f856f099SNavdeep Parhar 	if (rc)
4072f856f099SNavdeep Parhar 		goto err1;
4073f856f099SNavdeep Parhar 
4074f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4075f856f099SNavdeep Parhar 
4076f856f099SNavdeep Parhar err1:
4077f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4078f856f099SNavdeep Parhar err:
4079f856f099SNavdeep Parhar 	return rc;
4080f856f099SNavdeep Parhar 
4081f856f099SNavdeep Parhar }
4082f856f099SNavdeep Parhar 
collect_tp_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)4083f856f099SNavdeep Parhar static int collect_tp_indirect(struct cudbg_init *pdbg_init,
4084f856f099SNavdeep Parhar 			       struct cudbg_buffer *dbg_buff,
4085f856f099SNavdeep Parhar 			       struct cudbg_error *cudbg_err)
4086f856f099SNavdeep Parhar {
4087f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
4088f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
4089f856f099SNavdeep Parhar 	struct ireg_buf *ch_tp_pio;
4090f856f099SNavdeep Parhar 	u32 size;
4091f856f099SNavdeep Parhar 	int i, rc, n = 0;
4092f856f099SNavdeep Parhar 
4093f856f099SNavdeep Parhar 	if (is_t5(padap))
4094f856f099SNavdeep Parhar 		n = sizeof(t5_tp_pio_array) / (4 * sizeof(u32));
4095f856f099SNavdeep Parhar 	else if (is_t6(padap))
4096f856f099SNavdeep Parhar 		n = sizeof(t6_tp_pio_array) / (4 * sizeof(u32));
4097f856f099SNavdeep Parhar 
4098f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * n * 3;
4099f856f099SNavdeep Parhar 	scratch_buff.size = size;
4100f856f099SNavdeep Parhar 
4101f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
4102f856f099SNavdeep Parhar 	if (rc)
4103f856f099SNavdeep Parhar 		goto err;
4104f856f099SNavdeep Parhar 
4105f856f099SNavdeep Parhar 	ch_tp_pio = (struct ireg_buf *)scratch_buff.data;
4106f856f099SNavdeep Parhar 
4107f856f099SNavdeep Parhar 	/* TP_PIO*/
4108f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
4109f856f099SNavdeep Parhar 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
4110f856f099SNavdeep Parhar 		u32 *buff = ch_tp_pio->outbuf;
4111f856f099SNavdeep Parhar 
4112f856f099SNavdeep Parhar 		if (is_t5(padap)) {
4113f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t5_tp_pio_array[i][0];
4114f856f099SNavdeep Parhar 			tp_pio->ireg_data = t5_tp_pio_array[i][1];
4115f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
4116f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
4117f856f099SNavdeep Parhar 		} else if (is_t6(padap)) {
4118f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t6_tp_pio_array[i][0];
4119f856f099SNavdeep Parhar 			tp_pio->ireg_data = t6_tp_pio_array[i][1];
4120f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
4121f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
4122f856f099SNavdeep Parhar 		}
4123f856f099SNavdeep Parhar 
4124f856f099SNavdeep Parhar 		t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
4125f856f099SNavdeep Parhar 			       tp_pio->ireg_local_offset, true);
4126f856f099SNavdeep Parhar 
4127f856f099SNavdeep Parhar 		ch_tp_pio++;
4128f856f099SNavdeep Parhar 	}
4129f856f099SNavdeep Parhar 
4130f856f099SNavdeep Parhar 	/* TP_TM_PIO*/
4131f856f099SNavdeep Parhar 	if (is_t5(padap))
4132f856f099SNavdeep Parhar 		n = sizeof(t5_tp_tm_pio_array) / (4 * sizeof(u32));
4133f856f099SNavdeep Parhar 	else if (is_t6(padap))
4134f856f099SNavdeep Parhar 		n = sizeof(t6_tp_tm_pio_array) / (4 * sizeof(u32));
4135f856f099SNavdeep Parhar 
4136f856f099SNavdeep Parhar 	for (i = 0; i < n; i++) {
4137f856f099SNavdeep Parhar 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
4138f856f099SNavdeep Parhar 		u32 *buff = ch_tp_pio->outbuf;
4139f856f099SNavdeep Parhar 
4140f856f099SNavdeep Parhar 		if (is_t5(padap)) {
4141f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
4142f856f099SNavdeep Parhar 			tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
4143f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
4144f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
4145f856f099SNavdeep Parhar 		} else if (is_t6(padap)) {
4146f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
4147f856f099SNavdeep Parhar 			tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
4148f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
4149f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
4150f856f099SNavdeep Parhar 		}
4151f856f099SNavdeep Parhar 
4152f856f099SNavdeep Parhar 		t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
4153f856f099SNavdeep Parhar 				  tp_pio->ireg_local_offset, true);
4154f856f099SNavdeep Parhar 
4155f856f099SNavdeep Parhar 		ch_tp_pio++;
4156f856f099SNavdeep Parhar 	}
4157f856f099SNavdeep Parhar 
4158f856f099SNavdeep Parhar 	/* TP_MIB_INDEX*/
4159f856f099SNavdeep Parhar 	if (is_t5(padap))
4160f856f099SNavdeep Parhar 		n = sizeof(t5_tp_mib_index_array) / (4 * sizeof(u32));
4161f856f099SNavdeep Parhar 	else if (is_t6(padap))
4162f856f099SNavdeep Parhar 		n = sizeof(t6_tp_mib_index_array) / (4 * sizeof(u32));
4163f856f099SNavdeep Parhar 
4164f856f099SNavdeep Parhar 	for (i = 0; i < n ; i++) {
4165f856f099SNavdeep Parhar 		struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
4166f856f099SNavdeep Parhar 		u32 *buff = ch_tp_pio->outbuf;
4167f856f099SNavdeep Parhar 
4168f856f099SNavdeep Parhar 		if (is_t5(padap)) {
4169f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
4170f856f099SNavdeep Parhar 			tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
4171f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset =
4172f856f099SNavdeep Parhar 				t5_tp_mib_index_array[i][2];
4173f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range =
4174f856f099SNavdeep Parhar 				t5_tp_mib_index_array[i][3];
4175f856f099SNavdeep Parhar 		} else if (is_t6(padap)) {
4176f856f099SNavdeep Parhar 			tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
4177f856f099SNavdeep Parhar 			tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
4178f856f099SNavdeep Parhar 			tp_pio->ireg_local_offset =
4179f856f099SNavdeep Parhar 				t6_tp_mib_index_array[i][2];
4180f856f099SNavdeep Parhar 			tp_pio->ireg_offset_range =
4181f856f099SNavdeep Parhar 				t6_tp_mib_index_array[i][3];
4182f856f099SNavdeep Parhar 		}
4183f856f099SNavdeep Parhar 
4184f856f099SNavdeep Parhar 		t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
4185f856f099SNavdeep Parhar 			       tp_pio->ireg_local_offset, true);
4186f856f099SNavdeep Parhar 
4187f856f099SNavdeep Parhar 		ch_tp_pio++;
4188f856f099SNavdeep Parhar 	}
4189f856f099SNavdeep Parhar 
4190f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
4191f856f099SNavdeep Parhar 	if (rc)
4192f856f099SNavdeep Parhar 		goto err1;
4193f856f099SNavdeep Parhar 
4194f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4195f856f099SNavdeep Parhar 
4196f856f099SNavdeep Parhar err1:
4197f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4198f856f099SNavdeep Parhar err:
4199f856f099SNavdeep Parhar 	return rc;
4200f856f099SNavdeep Parhar }
4201f856f099SNavdeep Parhar 
collect_sge_indirect(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)4202f856f099SNavdeep Parhar static int collect_sge_indirect(struct cudbg_init *pdbg_init,
4203f856f099SNavdeep Parhar 				struct cudbg_buffer *dbg_buff,
4204f856f099SNavdeep Parhar 				struct cudbg_error *cudbg_err)
4205f856f099SNavdeep Parhar {
4206f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
4207f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
4208f856f099SNavdeep Parhar 	struct ireg_buf *ch_sge_dbg;
4209f856f099SNavdeep Parhar 	u32 size;
4210f856f099SNavdeep Parhar 	int i, rc;
4211f856f099SNavdeep Parhar 
4212f856f099SNavdeep Parhar 	size = sizeof(struct ireg_buf) * 2;
4213f856f099SNavdeep Parhar 	scratch_buff.size = size;
4214f856f099SNavdeep Parhar 
4215f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
4216f856f099SNavdeep Parhar 	if (rc)
4217f856f099SNavdeep Parhar 		goto err;
4218f856f099SNavdeep Parhar 
4219f856f099SNavdeep Parhar 	ch_sge_dbg = (struct ireg_buf *)scratch_buff.data;
4220f856f099SNavdeep Parhar 
4221f856f099SNavdeep Parhar 	for (i = 0; i < 2; i++) {
4222f856f099SNavdeep Parhar 		struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
4223f856f099SNavdeep Parhar 		u32 *buff = ch_sge_dbg->outbuf;
4224f856f099SNavdeep Parhar 
4225f856f099SNavdeep Parhar 		sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
4226f856f099SNavdeep Parhar 		sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
4227f856f099SNavdeep Parhar 		sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
4228f856f099SNavdeep Parhar 		sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
4229f856f099SNavdeep Parhar 
4230f856f099SNavdeep Parhar 		t4_read_indirect(padap,
4231f856f099SNavdeep Parhar 				sge_pio->ireg_addr,
4232f856f099SNavdeep Parhar 				sge_pio->ireg_data,
4233f856f099SNavdeep Parhar 				buff,
4234f856f099SNavdeep Parhar 				sge_pio->ireg_offset_range,
4235f856f099SNavdeep Parhar 				sge_pio->ireg_local_offset);
4236f856f099SNavdeep Parhar 
4237f856f099SNavdeep Parhar 		ch_sge_dbg++;
4238f856f099SNavdeep Parhar 	}
4239f856f099SNavdeep Parhar 
4240f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
4241f856f099SNavdeep Parhar 	if (rc)
4242f856f099SNavdeep Parhar 		goto err1;
4243f856f099SNavdeep Parhar 
4244f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4245f856f099SNavdeep Parhar 
4246f856f099SNavdeep Parhar err1:
4247f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4248f856f099SNavdeep Parhar err:
4249f856f099SNavdeep Parhar 	return rc;
4250f856f099SNavdeep Parhar }
4251f856f099SNavdeep Parhar 
collect_full(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)4252f856f099SNavdeep Parhar static int collect_full(struct cudbg_init *pdbg_init,
4253f856f099SNavdeep Parhar 			struct cudbg_buffer *dbg_buff,
4254f856f099SNavdeep Parhar 			struct cudbg_error *cudbg_err)
4255f856f099SNavdeep Parhar {
4256f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
4257f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
4258f856f099SNavdeep Parhar 	u32 reg_addr, reg_data, reg_local_offset, reg_offset_range;
4259f856f099SNavdeep Parhar 	u32 *sp;
4260f856f099SNavdeep Parhar 	int rc;
4261f856f099SNavdeep Parhar 	int nreg = 0;
4262f856f099SNavdeep Parhar 
4263f856f099SNavdeep Parhar 	/* Collect Registers:
4264f856f099SNavdeep Parhar 	 * TP_DBG_SCHED_TX (0x7e40 + 0x6a),
4265f856f099SNavdeep Parhar 	 * TP_DBG_SCHED_RX (0x7e40 + 0x6b),
4266f856f099SNavdeep Parhar 	 * TP_DBG_CSIDE_INT (0x7e40 + 0x23f),
4267f856f099SNavdeep Parhar 	 * TP_DBG_ESIDE_INT (0x7e40 + 0x148),
4268f856f099SNavdeep Parhar 	 * PCIE_CDEBUG_INDEX[AppData0] (0x5a10 + 2),
4269f856f099SNavdeep Parhar 	 * PCIE_CDEBUG_INDEX[AppData1] (0x5a10 + 3)  This is for T6
4270f856f099SNavdeep Parhar 	 * SGE_DEBUG_DATA_HIGH_INDEX_10 (0x12a8)
4271f856f099SNavdeep Parhar 	 **/
4272f856f099SNavdeep Parhar 
4273f856f099SNavdeep Parhar 	if (is_t5(padap))
4274f856f099SNavdeep Parhar 		nreg = 6;
4275f856f099SNavdeep Parhar 	else if (is_t6(padap))
4276f856f099SNavdeep Parhar 		nreg = 7;
4277f856f099SNavdeep Parhar 
4278f856f099SNavdeep Parhar 	scratch_buff.size = nreg * sizeof(u32);
4279f856f099SNavdeep Parhar 
4280f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
4281f856f099SNavdeep Parhar 	if (rc)
4282f856f099SNavdeep Parhar 		goto err;
4283f856f099SNavdeep Parhar 
4284f856f099SNavdeep Parhar 	sp = (u32 *)scratch_buff.data;
4285f856f099SNavdeep Parhar 
4286f856f099SNavdeep Parhar 	/* TP_DBG_SCHED_TX */
4287f856f099SNavdeep Parhar 	reg_local_offset = t5_tp_pio_array[3][2] + 0xa;
4288f856f099SNavdeep Parhar 	reg_offset_range = 1;
4289f856f099SNavdeep Parhar 
4290f856f099SNavdeep Parhar 	t4_tp_pio_read(padap, sp, reg_offset_range, reg_local_offset, true);
4291f856f099SNavdeep Parhar 
4292f856f099SNavdeep Parhar 	sp++;
4293f856f099SNavdeep Parhar 
4294f856f099SNavdeep Parhar 	/* TP_DBG_SCHED_RX */
4295f856f099SNavdeep Parhar 	reg_local_offset = t5_tp_pio_array[3][2] + 0xb;
4296f856f099SNavdeep Parhar 	reg_offset_range = 1;
4297f856f099SNavdeep Parhar 
4298f856f099SNavdeep Parhar 	t4_tp_pio_read(padap, sp, reg_offset_range, reg_local_offset, true);
4299f856f099SNavdeep Parhar 
4300f856f099SNavdeep Parhar 	sp++;
4301f856f099SNavdeep Parhar 
4302f856f099SNavdeep Parhar 	/* TP_DBG_CSIDE_INT */
4303f856f099SNavdeep Parhar 	reg_local_offset = t5_tp_pio_array[9][2] + 0xf;
4304f856f099SNavdeep Parhar 	reg_offset_range = 1;
4305f856f099SNavdeep Parhar 
4306f856f099SNavdeep Parhar 	t4_tp_pio_read(padap, sp, reg_offset_range, reg_local_offset, true);
4307f856f099SNavdeep Parhar 
4308f856f099SNavdeep Parhar 	sp++;
4309f856f099SNavdeep Parhar 
4310f856f099SNavdeep Parhar 	/* TP_DBG_ESIDE_INT */
4311f856f099SNavdeep Parhar 	reg_local_offset = t5_tp_pio_array[8][2] + 3;
4312f856f099SNavdeep Parhar 	reg_offset_range = 1;
4313f856f099SNavdeep Parhar 
4314f856f099SNavdeep Parhar 	t4_tp_pio_read(padap, sp, reg_offset_range, reg_local_offset, true);
4315f856f099SNavdeep Parhar 
4316f856f099SNavdeep Parhar 	sp++;
4317f856f099SNavdeep Parhar 
4318f856f099SNavdeep Parhar 	/* PCIE_CDEBUG_INDEX[AppData0] */
4319f856f099SNavdeep Parhar 	reg_addr = t5_pcie_cdbg_array[0][0];
4320f856f099SNavdeep Parhar 	reg_data = t5_pcie_cdbg_array[0][1];
4321f856f099SNavdeep Parhar 	reg_local_offset = t5_pcie_cdbg_array[0][2] + 2;
4322f856f099SNavdeep Parhar 	reg_offset_range = 1;
4323f856f099SNavdeep Parhar 
4324f856f099SNavdeep Parhar 	t4_read_indirect(padap, reg_addr, reg_data, sp, reg_offset_range,
4325f856f099SNavdeep Parhar 			 reg_local_offset);
4326f856f099SNavdeep Parhar 
4327f856f099SNavdeep Parhar 	sp++;
4328f856f099SNavdeep Parhar 
4329f856f099SNavdeep Parhar 	if (is_t6(padap)) {
4330f856f099SNavdeep Parhar 		/* PCIE_CDEBUG_INDEX[AppData1] */
4331f856f099SNavdeep Parhar 		reg_addr = t5_pcie_cdbg_array[0][0];
4332f856f099SNavdeep Parhar 		reg_data = t5_pcie_cdbg_array[0][1];
4333f856f099SNavdeep Parhar 		reg_local_offset = t5_pcie_cdbg_array[0][2] + 3;
4334f856f099SNavdeep Parhar 		reg_offset_range = 1;
4335f856f099SNavdeep Parhar 
4336f856f099SNavdeep Parhar 		t4_read_indirect(padap, reg_addr, reg_data, sp,
4337f856f099SNavdeep Parhar 				 reg_offset_range, reg_local_offset);
4338f856f099SNavdeep Parhar 
4339f856f099SNavdeep Parhar 		sp++;
4340f856f099SNavdeep Parhar 	}
4341f856f099SNavdeep Parhar 
4342f856f099SNavdeep Parhar 	/* SGE_DEBUG_DATA_HIGH_INDEX_10 */
4343f856f099SNavdeep Parhar 	*sp = t4_read_reg(padap, A_SGE_DEBUG_DATA_HIGH_INDEX_10);
4344f856f099SNavdeep Parhar 
4345f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
4346f856f099SNavdeep Parhar 	if (rc)
4347f856f099SNavdeep Parhar 		goto err1;
4348f856f099SNavdeep Parhar 
4349f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4350f856f099SNavdeep Parhar 
4351f856f099SNavdeep Parhar err1:
4352f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4353f856f099SNavdeep Parhar err:
4354f856f099SNavdeep Parhar 	return rc;
4355f856f099SNavdeep Parhar }
4356f856f099SNavdeep Parhar 
collect_vpd_data(struct cudbg_init * pdbg_init,struct cudbg_buffer * dbg_buff,struct cudbg_error * cudbg_err)4357f856f099SNavdeep Parhar static int collect_vpd_data(struct cudbg_init *pdbg_init,
4358f856f099SNavdeep Parhar 			    struct cudbg_buffer *dbg_buff,
4359f856f099SNavdeep Parhar 			    struct cudbg_error *cudbg_err)
4360f856f099SNavdeep Parhar {
4361f856f099SNavdeep Parhar #ifdef notyet
4362f856f099SNavdeep Parhar 	struct cudbg_buffer scratch_buff;
4363f856f099SNavdeep Parhar 	struct adapter *padap = pdbg_init->adap;
4364f856f099SNavdeep Parhar 	struct struct_vpd_data *vpd_data;
4365f856f099SNavdeep Parhar 	char vpd_ver[4];
4366f856f099SNavdeep Parhar 	u32 fw_vers;
4367f856f099SNavdeep Parhar 	u32 size;
4368f856f099SNavdeep Parhar 	int rc;
4369f856f099SNavdeep Parhar 
4370f856f099SNavdeep Parhar 	size = sizeof(struct struct_vpd_data);
4371f856f099SNavdeep Parhar 	scratch_buff.size = size;
4372f856f099SNavdeep Parhar 
4373f856f099SNavdeep Parhar 	rc = get_scratch_buff(dbg_buff, scratch_buff.size, &scratch_buff);
4374f856f099SNavdeep Parhar 	if (rc)
4375f856f099SNavdeep Parhar 		goto err;
4376f856f099SNavdeep Parhar 
4377f856f099SNavdeep Parhar 	vpd_data = (struct struct_vpd_data *)scratch_buff.data;
4378f856f099SNavdeep Parhar 
4379f856f099SNavdeep Parhar 	if (is_t5(padap)) {
4380f856f099SNavdeep Parhar 		read_vpd_reg(padap, SN_REG_ADDR, SN_MAX_LEN, vpd_data->sn);
4381f856f099SNavdeep Parhar 		read_vpd_reg(padap, BN_REG_ADDR, BN_MAX_LEN, vpd_data->bn);
4382f856f099SNavdeep Parhar 		read_vpd_reg(padap, NA_REG_ADDR, NA_MAX_LEN, vpd_data->na);
4383f856f099SNavdeep Parhar 		read_vpd_reg(padap, MN_REG_ADDR, MN_MAX_LEN, vpd_data->mn);
4384f856f099SNavdeep Parhar 	} else if (is_t6(padap)) {
4385f856f099SNavdeep Parhar 		read_vpd_reg(padap, SN_T6_ADDR, SN_MAX_LEN, vpd_data->sn);
4386f856f099SNavdeep Parhar 		read_vpd_reg(padap, BN_T6_ADDR, BN_MAX_LEN, vpd_data->bn);
4387f856f099SNavdeep Parhar 		read_vpd_reg(padap, NA_T6_ADDR, NA_MAX_LEN, vpd_data->na);
4388f856f099SNavdeep Parhar 		read_vpd_reg(padap, MN_T6_ADDR, MN_MAX_LEN, vpd_data->mn);
4389f856f099SNavdeep Parhar 	}
4390f856f099SNavdeep Parhar 
4391f856f099SNavdeep Parhar 	if (is_fw_attached(pdbg_init)) {
4392f856f099SNavdeep Parhar 	   rc = t4_get_scfg_version(padap, &vpd_data->scfg_vers);
4393f856f099SNavdeep Parhar 	} else {
4394f856f099SNavdeep Parhar 		rc = 1;
4395f856f099SNavdeep Parhar 	}
4396f856f099SNavdeep Parhar 
4397f856f099SNavdeep Parhar 	if (rc) {
4398f856f099SNavdeep Parhar 		/* Now trying with backdoor mechanism */
4399f856f099SNavdeep Parhar 		rc = read_vpd_reg(padap, SCFG_VER_ADDR, SCFG_VER_LEN,
4400f856f099SNavdeep Parhar 				  (u8 *)&vpd_data->scfg_vers);
4401f856f099SNavdeep Parhar 		if (rc)
4402f856f099SNavdeep Parhar 			goto err1;
4403f856f099SNavdeep Parhar 	}
4404f856f099SNavdeep Parhar 
4405f856f099SNavdeep Parhar 	if (is_fw_attached(pdbg_init)) {
4406f856f099SNavdeep Parhar 		rc = t4_get_vpd_version(padap, &vpd_data->vpd_vers);
4407f856f099SNavdeep Parhar 	} else {
4408f856f099SNavdeep Parhar 		rc = 1;
4409f856f099SNavdeep Parhar 	}
4410f856f099SNavdeep Parhar 
4411f856f099SNavdeep Parhar 	if (rc) {
4412f856f099SNavdeep Parhar 		/* Now trying with backdoor mechanism */
4413f856f099SNavdeep Parhar 		rc = read_vpd_reg(padap, VPD_VER_ADDR, VPD_VER_LEN,
4414f856f099SNavdeep Parhar 				  (u8 *)vpd_ver);
4415f856f099SNavdeep Parhar 		if (rc)
4416f856f099SNavdeep Parhar 			goto err1;
4417f856f099SNavdeep Parhar 		/* read_vpd_reg return string of stored hex
4418f856f099SNavdeep Parhar 		 * converting hex string to char string
4419f856f099SNavdeep Parhar 		 * vpd version is 2 bytes only */
4420f856f099SNavdeep Parhar 		sprintf(vpd_ver, "%c%c\n", vpd_ver[0], vpd_ver[1]);
4421f856f099SNavdeep Parhar 		vpd_data->vpd_vers = simple_strtoul(vpd_ver, NULL, 16);
4422f856f099SNavdeep Parhar 	}
4423f856f099SNavdeep Parhar 
4424f856f099SNavdeep Parhar 	/* Get FW version if it's not already filled in */
4425f856f099SNavdeep Parhar 	fw_vers = padap->params.fw_vers;
4426f856f099SNavdeep Parhar 	if (!fw_vers) {
4427f856f099SNavdeep Parhar 		rc = t4_get_fw_version(padap, &fw_vers);
4428f856f099SNavdeep Parhar 		if (rc)
4429f856f099SNavdeep Parhar 			goto err1;
4430f856f099SNavdeep Parhar 	}
4431f856f099SNavdeep Parhar 
4432f856f099SNavdeep Parhar 	vpd_data->fw_major = G_FW_HDR_FW_VER_MAJOR(fw_vers);
4433f856f099SNavdeep Parhar 	vpd_data->fw_minor = G_FW_HDR_FW_VER_MINOR(fw_vers);
4434f856f099SNavdeep Parhar 	vpd_data->fw_micro = G_FW_HDR_FW_VER_MICRO(fw_vers);
4435f856f099SNavdeep Parhar 	vpd_data->fw_build = G_FW_HDR_FW_VER_BUILD(fw_vers);
4436f856f099SNavdeep Parhar 
4437f856f099SNavdeep Parhar 	rc = write_compression_hdr(&scratch_buff, dbg_buff);
4438f856f099SNavdeep Parhar 	if (rc)
4439f856f099SNavdeep Parhar 		goto err1;
4440f856f099SNavdeep Parhar 
4441f856f099SNavdeep Parhar 	rc = compress_buff(&scratch_buff, dbg_buff);
4442f856f099SNavdeep Parhar 
4443f856f099SNavdeep Parhar err1:
4444f856f099SNavdeep Parhar 	release_scratch_buff(&scratch_buff, dbg_buff);
4445f856f099SNavdeep Parhar err:
4446f856f099SNavdeep Parhar 	return rc;
4447f856f099SNavdeep Parhar #endif
44486cc4520bSNavdeep Parhar 	return (CUDBG_STATUS_NOT_IMPLEMENTED);
4449f856f099SNavdeep Parhar }
4450