1*7e6ad469SVishal Kulkarni /*
2*7e6ad469SVishal Kulkarni  * This file and its contents are supplied under the terms of the
3*7e6ad469SVishal Kulkarni  * Common Development and Distribution License ("CDDL"), version 1.0.
4*7e6ad469SVishal Kulkarni  * You may only use this file in accordance with the terms of version
5*7e6ad469SVishal Kulkarni  * 1.0 of the CDDL.
6*7e6ad469SVishal Kulkarni  *
7*7e6ad469SVishal Kulkarni  * A full copy of the text of the CDDL should have accompanied this
8*7e6ad469SVishal Kulkarni  * source.  A copy of the CDDL is also available via the Internet at
9*7e6ad469SVishal Kulkarni  * http://www.illumos.org/license/CDDL.
10*7e6ad469SVishal Kulkarni  */
11*7e6ad469SVishal Kulkarni 
12*7e6ad469SVishal Kulkarni /*
13*7e6ad469SVishal Kulkarni  * Copyright (c) 2019 by Chelsio Communications, Inc.
14*7e6ad469SVishal Kulkarni  */
15*7e6ad469SVishal Kulkarni 
16*7e6ad469SVishal Kulkarni #include <stdio.h>
17*7e6ad469SVishal Kulkarni #include <stddef.h>
18*7e6ad469SVishal Kulkarni #include <stdlib.h>
19*7e6ad469SVishal Kulkarni #include <string.h>
20*7e6ad469SVishal Kulkarni #include <ctype.h>
21*7e6ad469SVishal Kulkarni #include <fcntl.h>
22*7e6ad469SVishal Kulkarni #include <unistd.h>
23*7e6ad469SVishal Kulkarni #include <assert.h>
24*7e6ad469SVishal Kulkarni 
25*7e6ad469SVishal Kulkarni #include "t4_regs.h"
26*7e6ad469SVishal Kulkarni #include "t4_chip_type.h"
27*7e6ad469SVishal Kulkarni #include "cudbg_view.h"
28*7e6ad469SVishal Kulkarni #include "osdep.h"
29*7e6ad469SVishal Kulkarni #include "t4fw_interface.h"
30*7e6ad469SVishal Kulkarni 
31*7e6ad469SVishal Kulkarni #include "cudbg_view_entity.h"
32*7e6ad469SVishal Kulkarni #include "cudbg_entity.h"
33*7e6ad469SVishal Kulkarni #include "cudbg.h"
34*7e6ad469SVishal Kulkarni #include "cudbg_lib_common.h"
35*7e6ad469SVishal Kulkarni #include "fastlz.h"
36*7e6ad469SVishal Kulkarni 
37*7e6ad469SVishal Kulkarni extern struct reg_info t6_sge_regs[];
38*7e6ad469SVishal Kulkarni extern struct reg_info t6_pcie_regs[];
39*7e6ad469SVishal Kulkarni extern struct reg_info t6_dbg_regs[];
40*7e6ad469SVishal Kulkarni extern struct reg_info t6_ma_regs[];
41*7e6ad469SVishal Kulkarni extern struct reg_info t6_cim_regs[];
42*7e6ad469SVishal Kulkarni extern struct reg_info t6_tp_regs[];
43*7e6ad469SVishal Kulkarni extern struct reg_info t6_ulp_tx_regs[];
44*7e6ad469SVishal Kulkarni extern struct reg_info t6_pm_rx_regs[];
45*7e6ad469SVishal Kulkarni extern struct reg_info t6_pm_tx_regs[];
46*7e6ad469SVishal Kulkarni extern struct reg_info t6_mps_regs[];
47*7e6ad469SVishal Kulkarni extern struct reg_info t6_cpl_switch_regs[];
48*7e6ad469SVishal Kulkarni extern struct reg_info t6_smb_regs[];
49*7e6ad469SVishal Kulkarni extern struct reg_info t6_i2cm_regs[];
50*7e6ad469SVishal Kulkarni extern struct reg_info t6_mi_regs[];
51*7e6ad469SVishal Kulkarni extern struct reg_info t6_uart_regs[];
52*7e6ad469SVishal Kulkarni extern struct reg_info t6_pmu_regs[];
53*7e6ad469SVishal Kulkarni extern struct reg_info t6_ulp_rx_regs[];
54*7e6ad469SVishal Kulkarni extern struct reg_info t6_sf_regs[];
55*7e6ad469SVishal Kulkarni extern struct reg_info t6_pl_regs[];
56*7e6ad469SVishal Kulkarni extern struct reg_info t6_le_regs[];
57*7e6ad469SVishal Kulkarni extern struct reg_info t6_ncsi_regs[];
58*7e6ad469SVishal Kulkarni extern struct reg_info t6_mac_regs[];
59*7e6ad469SVishal Kulkarni extern struct reg_info t6_mc_0_regs[];
60*7e6ad469SVishal Kulkarni extern struct reg_info t6_edc_t60_regs[];
61*7e6ad469SVishal Kulkarni extern struct reg_info t6_edc_t61_regs[];
62*7e6ad469SVishal Kulkarni extern struct reg_info t6_hma_t6_regs[];
63*7e6ad469SVishal Kulkarni 
64*7e6ad469SVishal Kulkarni extern struct reg_info t5_sge_regs[];
65*7e6ad469SVishal Kulkarni extern struct reg_info t5_pcie_regs[];
66*7e6ad469SVishal Kulkarni extern struct reg_info t5_dbg_regs[];
67*7e6ad469SVishal Kulkarni extern struct reg_info t5_ma_regs[];
68*7e6ad469SVishal Kulkarni extern struct reg_info t5_cim_regs[];
69*7e6ad469SVishal Kulkarni extern struct reg_info t5_tp_regs[];
70*7e6ad469SVishal Kulkarni extern struct reg_info t5_ulp_tx_regs[];
71*7e6ad469SVishal Kulkarni extern struct reg_info t5_pm_rx_regs[];
72*7e6ad469SVishal Kulkarni extern struct reg_info t5_pm_tx_regs[];
73*7e6ad469SVishal Kulkarni extern struct reg_info t5_mps_regs[];
74*7e6ad469SVishal Kulkarni extern struct reg_info t5_cpl_switch_regs[];
75*7e6ad469SVishal Kulkarni extern struct reg_info t5_smb_regs[];
76*7e6ad469SVishal Kulkarni extern struct reg_info t5_i2cm_regs[];
77*7e6ad469SVishal Kulkarni extern struct reg_info t5_mi_regs[];
78*7e6ad469SVishal Kulkarni extern struct reg_info t5_uart_regs[];
79*7e6ad469SVishal Kulkarni extern struct reg_info t5_pmu_regs[];
80*7e6ad469SVishal Kulkarni extern struct reg_info t5_ulp_rx_regs[];
81*7e6ad469SVishal Kulkarni extern struct reg_info t5_sf_regs[];
82*7e6ad469SVishal Kulkarni extern struct reg_info t5_pl_regs[];
83*7e6ad469SVishal Kulkarni extern struct reg_info t5_le_regs[];
84*7e6ad469SVishal Kulkarni extern struct reg_info t5_ncsi_regs[];
85*7e6ad469SVishal Kulkarni extern struct reg_info t5_mac_regs[];
86*7e6ad469SVishal Kulkarni extern struct reg_info t5_mc_0_regs[];
87*7e6ad469SVishal Kulkarni extern struct reg_info t5_mc_1_regs[];
88*7e6ad469SVishal Kulkarni extern struct reg_info t5_edc_t50_regs[];
89*7e6ad469SVishal Kulkarni extern struct reg_info t5_edc_t51_regs[];
90*7e6ad469SVishal Kulkarni extern struct reg_info t5_hma_t5_regs[];
91*7e6ad469SVishal Kulkarni 
92*7e6ad469SVishal Kulkarni #include "reg_defs_t5.c"
93*7e6ad469SVishal Kulkarni #include "reg_defs_t6.c"
94*7e6ad469SVishal Kulkarni 
95*7e6ad469SVishal Kulkarni #include <time.h>
96*7e6ad469SVishal Kulkarni #include <stdarg.h>
97*7e6ad469SVishal Kulkarni 
is_t5(enum chip_type chip)98*7e6ad469SVishal Kulkarni int is_t5(enum chip_type chip)
99*7e6ad469SVishal Kulkarni {
100*7e6ad469SVishal Kulkarni 	return (CHELSIO_CHIP_VERSION(chip) == CHELSIO_T5);
101*7e6ad469SVishal Kulkarni }
102*7e6ad469SVishal Kulkarni 
is_t6(enum chip_type chip)103*7e6ad469SVishal Kulkarni int is_t6(enum chip_type chip)
104*7e6ad469SVishal Kulkarni {
105*7e6ad469SVishal Kulkarni 	return (CHELSIO_CHIP_VERSION(chip) == CHELSIO_T6);
106*7e6ad469SVishal Kulkarni }
107*7e6ad469SVishal Kulkarni 
108*7e6ad469SVishal Kulkarni enum {                                 /* adapter flags */
109*7e6ad469SVishal Kulkarni 	FULL_INIT_DONE     = (1 << 0),
110*7e6ad469SVishal Kulkarni 	USING_MSI          = (1 << 1),
111*7e6ad469SVishal Kulkarni 	USING_MSIX         = (1 << 2),
112*7e6ad469SVishal Kulkarni 	QUEUES_BOUND       = (1 << 3),
113*7e6ad469SVishal Kulkarni 	FW_OK              = (1 << 4),
114*7e6ad469SVishal Kulkarni 	RSS_TNLALLLOOKUP   = (1 << 5),
115*7e6ad469SVishal Kulkarni 	USING_SOFT_PARAMS  = (1 << 6),
116*7e6ad469SVishal Kulkarni 	MASTER_PF          = (1 << 7),
117*7e6ad469SVishal Kulkarni 	BYPASS_DROP        = (1 << 8),
118*7e6ad469SVishal Kulkarni 	FW_OFLD_CONN       = (1 << 9),
119*7e6ad469SVishal Kulkarni };
120*7e6ad469SVishal Kulkarni 
121*7e6ad469SVishal Kulkarni static struct ver_cs {
122*7e6ad469SVishal Kulkarni 	int major;
123*7e6ad469SVishal Kulkarni 	int minor;
124*7e6ad469SVishal Kulkarni 	int changeset;
125*7e6ad469SVishal Kulkarni } ver_to_cs[] = {
126*7e6ad469SVishal Kulkarni 	{1, 9, 12852},
127*7e6ad469SVishal Kulkarni 	{1, 10, 13182},
128*7e6ad469SVishal Kulkarni 	{1, 11, 13257},
129*7e6ad469SVishal Kulkarni 	{1, 12, 13495},
130*7e6ad469SVishal Kulkarni 	{1, 13, 13905},
131*7e6ad469SVishal Kulkarni 	{1, 14, 13969},
132*7e6ad469SVishal Kulkarni };
133*7e6ad469SVishal Kulkarni 
134*7e6ad469SVishal Kulkarni static bool flash_info_banner = true;
135*7e6ad469SVishal Kulkarni 
136*7e6ad469SVishal Kulkarni #include "cudbg_view_compat.c"
137*7e6ad469SVishal Kulkarni 
138*7e6ad469SVishal Kulkarni int
cudbg_sge_ctxt_check_valid(u32 * buf,int type)139*7e6ad469SVishal Kulkarni cudbg_sge_ctxt_check_valid(u32 *buf, int type)
140*7e6ad469SVishal Kulkarni {
141*7e6ad469SVishal Kulkarni 	int index, bit, bit_pos = 0;
142*7e6ad469SVishal Kulkarni 
143*7e6ad469SVishal Kulkarni 	switch (type) {
144*7e6ad469SVishal Kulkarni 		case CTXT_EGRESS:
145*7e6ad469SVishal Kulkarni 			bit_pos = 176;
146*7e6ad469SVishal Kulkarni 			break;
147*7e6ad469SVishal Kulkarni 		case CTXT_INGRESS:
148*7e6ad469SVishal Kulkarni 			bit_pos = 141;
149*7e6ad469SVishal Kulkarni 			break;
150*7e6ad469SVishal Kulkarni 		case CTXT_FLM:
151*7e6ad469SVishal Kulkarni 			bit_pos = 89;
152*7e6ad469SVishal Kulkarni 			break;
153*7e6ad469SVishal Kulkarni 	}
154*7e6ad469SVishal Kulkarni 	index = bit_pos / 32;
155*7e6ad469SVishal Kulkarni 	bit =  bit_pos % 32;
156*7e6ad469SVishal Kulkarni 	return buf[index] & (1U << bit);
157*7e6ad469SVishal Kulkarni }
158*7e6ad469SVishal Kulkarni 
159*7e6ad469SVishal Kulkarni int
cudbg_view_decompress_buff(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * c_buff,struct cudbg_buffer * dc_buff)160*7e6ad469SVishal Kulkarni cudbg_view_decompress_buff(char *pbuf,
161*7e6ad469SVishal Kulkarni 			   struct cudbg_entity_hdr *entity_hdr,
162*7e6ad469SVishal Kulkarni 			   struct cudbg_buffer *c_buff,
163*7e6ad469SVishal Kulkarni 			   struct cudbg_buffer *dc_buff)
164*7e6ad469SVishal Kulkarni {
165*7e6ad469SVishal Kulkarni 	int rc = 0;
166*7e6ad469SVishal Kulkarni 
167*7e6ad469SVishal Kulkarni 	c_buff->data = pbuf + entity_hdr->start_offset;
168*7e6ad469SVishal Kulkarni 	/* Remove padding bytes, if any */
169*7e6ad469SVishal Kulkarni 	if (entity_hdr->num_pad)
170*7e6ad469SVishal Kulkarni 		c_buff->size = entity_hdr->size - entity_hdr->num_pad;
171*7e6ad469SVishal Kulkarni 	else
172*7e6ad469SVishal Kulkarni 		c_buff->size = entity_hdr->size;
173*7e6ad469SVishal Kulkarni 	c_buff->offset = 0;
174*7e6ad469SVishal Kulkarni 	memset(dc_buff, 0, sizeof(struct cudbg_buffer));
175*7e6ad469SVishal Kulkarni 
176*7e6ad469SVishal Kulkarni 	rc = validate_buffer(c_buff);
177*7e6ad469SVishal Kulkarni 	if (rc)
178*7e6ad469SVishal Kulkarni 		return rc;
179*7e6ad469SVishal Kulkarni 
180*7e6ad469SVishal Kulkarni 	rc = decompress_buffer_wrapper(c_buff, dc_buff);
181*7e6ad469SVishal Kulkarni 	if (rc) {
182*7e6ad469SVishal Kulkarni 		free(dc_buff->data);
183*7e6ad469SVishal Kulkarni 		return rc;
184*7e6ad469SVishal Kulkarni 	}
185*7e6ad469SVishal Kulkarni 	return rc;
186*7e6ad469SVishal Kulkarni }
187*7e6ad469SVishal Kulkarni 
188*7e6ad469SVishal Kulkarni int
get_entity_rev(struct cudbg_ver_hdr * ver_hdr)189*7e6ad469SVishal Kulkarni get_entity_rev(struct cudbg_ver_hdr *ver_hdr)
190*7e6ad469SVishal Kulkarni {
191*7e6ad469SVishal Kulkarni 	if (ver_hdr->signature == CUDBG_ENTITY_SIGNATURE)
192*7e6ad469SVishal Kulkarni 		return ver_hdr->revision;
193*7e6ad469SVishal Kulkarni 	return 0;
194*7e6ad469SVishal Kulkarni }
195*7e6ad469SVishal Kulkarni 
196*7e6ad469SVishal Kulkarni /* Find Mercurial sw repo changeset number
197*7e6ad469SVishal Kulkarni  * where major or minor number set to given number
198*7e6ad469SVishal Kulkarni  * */
199*7e6ad469SVishal Kulkarni int
cudbg_find_changeset(int major,int minor)200*7e6ad469SVishal Kulkarni cudbg_find_changeset(int major, int minor)
201*7e6ad469SVishal Kulkarni {
202*7e6ad469SVishal Kulkarni 	int i;
203*7e6ad469SVishal Kulkarni 
204*7e6ad469SVishal Kulkarni 	for (i = 0; i < sizeof(ver_to_cs)/sizeof(struct ver_cs); i++) {
205*7e6ad469SVishal Kulkarni 		if (ver_to_cs[i].major == major &&
206*7e6ad469SVishal Kulkarni 		    ver_to_cs[i].minor == minor)
207*7e6ad469SVishal Kulkarni 			return ver_to_cs[i].changeset;
208*7e6ad469SVishal Kulkarni 	}
209*7e6ad469SVishal Kulkarni 
210*7e6ad469SVishal Kulkarni 	return -1;
211*7e6ad469SVishal Kulkarni }
212*7e6ad469SVishal Kulkarni 
213*7e6ad469SVishal Kulkarni /* Format a value in a unit that differs from the
214*7e6ad469SVishal Kulkarni  * value's native unit by the
215*7e6ad469SVishal Kulkarni  * given factor.
216*7e6ad469SVishal Kulkarni  */
217*7e6ad469SVishal Kulkarni static void
unit_conv(char * buf,size_t len,unsigned int val,unsigned int factor)218*7e6ad469SVishal Kulkarni unit_conv(char *buf, size_t len, unsigned int val,
219*7e6ad469SVishal Kulkarni 	  unsigned int factor)
220*7e6ad469SVishal Kulkarni {
221*7e6ad469SVishal Kulkarni 	unsigned int rem = val % factor;
222*7e6ad469SVishal Kulkarni 
223*7e6ad469SVishal Kulkarni 	if (rem == 0)
224*7e6ad469SVishal Kulkarni 		(void) snprintf(buf, len, "%u", val / factor);
225*7e6ad469SVishal Kulkarni 	else {
226*7e6ad469SVishal Kulkarni 		while (rem % 10 == 0)
227*7e6ad469SVishal Kulkarni 			rem /= 10;
228*7e6ad469SVishal Kulkarni 		(void) snprintf(buf, len, "%u.%u", val / factor, rem);
229*7e6ad469SVishal Kulkarni 	}
230*7e6ad469SVishal Kulkarni }
231*7e6ad469SVishal Kulkarni 
232*7e6ad469SVishal Kulkarni int
validate_next_rec_offset(void * pinbuf,u32 inbuf_size,u32 next_rec_offset)233*7e6ad469SVishal Kulkarni validate_next_rec_offset(void *pinbuf, u32 inbuf_size, u32
234*7e6ad469SVishal Kulkarni 			 next_rec_offset)
235*7e6ad469SVishal Kulkarni {
236*7e6ad469SVishal Kulkarni 	struct cudbg_hdr *cudbg_hdr;
237*7e6ad469SVishal Kulkarni 
238*7e6ad469SVishal Kulkarni 	if (inbuf_size <= next_rec_offset)
239*7e6ad469SVishal Kulkarni 		return 0;
240*7e6ad469SVishal Kulkarni 
241*7e6ad469SVishal Kulkarni 	cudbg_hdr = (struct cudbg_hdr *)((char *)pinbuf + next_rec_offset);
242*7e6ad469SVishal Kulkarni 	if ((cudbg_hdr->signature != CUDBG_SIGNATURE) &&
243*7e6ad469SVishal Kulkarni 	    (cudbg_hdr->signature != CUDBG_LEGACY_SIGNATURE))
244*7e6ad469SVishal Kulkarni 		return 0; /* no next rec */
245*7e6ad469SVishal Kulkarni 
246*7e6ad469SVishal Kulkarni 	return next_rec_offset;
247*7e6ad469SVishal Kulkarni }
248*7e6ad469SVishal Kulkarni 
249*7e6ad469SVishal Kulkarni int
view_ext_entity(char * pinbuf,struct cudbg_entity_hdr * ent_hdr,struct cudbg_buffer * cudbg_poutbuf,enum chip_type chip)250*7e6ad469SVishal Kulkarni view_ext_entity(char *pinbuf, struct cudbg_entity_hdr *ent_hdr,
251*7e6ad469SVishal Kulkarni 		struct cudbg_buffer *cudbg_poutbuf,
252*7e6ad469SVishal Kulkarni 		enum chip_type chip)
253*7e6ad469SVishal Kulkarni {
254*7e6ad469SVishal Kulkarni 	struct cudbg_entity_hdr *entity_hdr = NULL;
255*7e6ad469SVishal Kulkarni 	u32 size, total_size = 0;
256*7e6ad469SVishal Kulkarni 	u32 next_ext_offset = 0;
257*7e6ad469SVishal Kulkarni 	u32 entity_type;
258*7e6ad469SVishal Kulkarni 	int rc = 0;
259*7e6ad469SVishal Kulkarni 
260*7e6ad469SVishal Kulkarni 	entity_hdr = (struct cudbg_entity_hdr *)
261*7e6ad469SVishal Kulkarni 		     (pinbuf + ent_hdr->start_offset);
262*7e6ad469SVishal Kulkarni 	/* Remove padding bytes, if any */
263*7e6ad469SVishal Kulkarni 	size = ent_hdr->num_pad ? ent_hdr->size - ent_hdr->num_pad :
264*7e6ad469SVishal Kulkarni 				  ent_hdr->size;
265*7e6ad469SVishal Kulkarni 	while ((entity_hdr->flag & CUDBG_EXT_DATA_VALID)
266*7e6ad469SVishal Kulkarni 		&& (total_size < size)) {
267*7e6ad469SVishal Kulkarni 		entity_type = entity_hdr->entity_type;
268*7e6ad469SVishal Kulkarni 		if (entity_hdr->sys_warn)
269*7e6ad469SVishal Kulkarni 			printf("Entity warning: Type %s , %d\n",
270*7e6ad469SVishal Kulkarni 			       entity_list[entity_type].name,
271*7e6ad469SVishal Kulkarni 			       entity_hdr->sys_warn);
272*7e6ad469SVishal Kulkarni 
273*7e6ad469SVishal Kulkarni 		if (entity_hdr->hdr_flags) {
274*7e6ad469SVishal Kulkarni 			printf("Entity error: Type %s, %s\n",
275*7e6ad469SVishal Kulkarni 			       entity_list[entity_type].name,
276*7e6ad469SVishal Kulkarni 			       err_msg[-entity_hdr->hdr_flags]);
277*7e6ad469SVishal Kulkarni 			if (entity_hdr->sys_err)
278*7e6ad469SVishal Kulkarni 				printf("System error  %d\n",
279*7e6ad469SVishal Kulkarni 				       entity_hdr->sys_err);
280*7e6ad469SVishal Kulkarni 
281*7e6ad469SVishal Kulkarni 			next_ext_offset = entity_hdr->next_ext_offset;
282*7e6ad469SVishal Kulkarni 			entity_hdr = (struct cudbg_entity_hdr *)
283*7e6ad469SVishal Kulkarni 				     (pinbuf + ent_hdr->start_offset +
284*7e6ad469SVishal Kulkarni 				      next_ext_offset);
285*7e6ad469SVishal Kulkarni 			continue;
286*7e6ad469SVishal Kulkarni 		}
287*7e6ad469SVishal Kulkarni 		if (entity_hdr->size > 0) {
288*7e6ad469SVishal Kulkarni 			total_size += entity_hdr->size +
289*7e6ad469SVishal Kulkarni 					sizeof(struct cudbg_entity_hdr);
290*7e6ad469SVishal Kulkarni 
291*7e6ad469SVishal Kulkarni 			rc = view_entity[entity_type - 1]
292*7e6ad469SVishal Kulkarni 				(pinbuf + ent_hdr->start_offset,
293*7e6ad469SVishal Kulkarni 				 entity_hdr,
294*7e6ad469SVishal Kulkarni 				 cudbg_poutbuf,
295*7e6ad469SVishal Kulkarni 				 chip);
296*7e6ad469SVishal Kulkarni 			if (rc < 0)
297*7e6ad469SVishal Kulkarni 				goto out;
298*7e6ad469SVishal Kulkarni 		}
299*7e6ad469SVishal Kulkarni 		next_ext_offset = entity_hdr->next_ext_offset;
300*7e6ad469SVishal Kulkarni 		entity_hdr = (struct cudbg_entity_hdr *)
301*7e6ad469SVishal Kulkarni 			     (pinbuf + ent_hdr->start_offset + next_ext_offset);
302*7e6ad469SVishal Kulkarni 	}
303*7e6ad469SVishal Kulkarni 
304*7e6ad469SVishal Kulkarni 	if (total_size != size)
305*7e6ad469SVishal Kulkarni 		printf("Entity warning: Extended entity size mismatch\n");
306*7e6ad469SVishal Kulkarni 
307*7e6ad469SVishal Kulkarni out:
308*7e6ad469SVishal Kulkarni 	return rc;
309*7e6ad469SVishal Kulkarni }
310*7e6ad469SVishal Kulkarni 
311*7e6ad469SVishal Kulkarni static void
cudbg_print_cudbg_header(struct cudbg_hdr * hdr)312*7e6ad469SVishal Kulkarni cudbg_print_cudbg_header(struct cudbg_hdr *hdr)
313*7e6ad469SVishal Kulkarni {
314*7e6ad469SVishal Kulkarni 	printf("\n/***************Header Information***************/\n");
315*7e6ad469SVishal Kulkarni 	printf("Library Version: %u.%u\n", hdr->major_ver, hdr->minor_ver);
316*7e6ad469SVishal Kulkarni 	printf("Compressed with: ");
317*7e6ad469SVishal Kulkarni 	printf("Chip Version: ");
318*7e6ad469SVishal Kulkarni 	switch (CHELSIO_CHIP_VERSION(hdr->chip_ver)) {
319*7e6ad469SVishal Kulkarni 	case CHELSIO_T4:
320*7e6ad469SVishal Kulkarni 		printf("T4 rev: %u\n", CHELSIO_CHIP_RELEASE(hdr->chip_ver));
321*7e6ad469SVishal Kulkarni 		break;
322*7e6ad469SVishal Kulkarni 	case CHELSIO_T5:
323*7e6ad469SVishal Kulkarni 		printf("T5 rev: %u\n", CHELSIO_CHIP_RELEASE(hdr->chip_ver));
324*7e6ad469SVishal Kulkarni 		break;
325*7e6ad469SVishal Kulkarni 	case CHELSIO_T6:
326*7e6ad469SVishal Kulkarni 		printf("T6 rev: %u\n", CHELSIO_CHIP_RELEASE(hdr->chip_ver));
327*7e6ad469SVishal Kulkarni 		break;
328*7e6ad469SVishal Kulkarni 	default:
329*7e6ad469SVishal Kulkarni 		printf("%u (unknown)\n", hdr->chip_ver);
330*7e6ad469SVishal Kulkarni 		break;
331*7e6ad469SVishal Kulkarni 	}
332*7e6ad469SVishal Kulkarni 	printf("/************************************************/\n\n");
333*7e6ad469SVishal Kulkarni }
334*7e6ad469SVishal Kulkarni 
335*7e6ad469SVishal Kulkarni void
cudbg_print_flash_header(void * pinbuf)336*7e6ad469SVishal Kulkarni cudbg_print_flash_header(void *pinbuf)
337*7e6ad469SVishal Kulkarni {
338*7e6ad469SVishal Kulkarni 	struct cudbg_flash_hdr *fl_hdr = (struct cudbg_flash_hdr *)pinbuf;
339*7e6ad469SVishal Kulkarni 
340*7e6ad469SVishal Kulkarni 	if (fl_hdr->signature == CUDBG_FL_SIGNATURE && flash_info_banner) {
341*7e6ad469SVishal Kulkarni 		printf("\n/***************Flash Header information***************/\n");
342*7e6ad469SVishal Kulkarni 		printf("Flash signature: %c%c%c%c\n",
343*7e6ad469SVishal Kulkarni 		       (fl_hdr->signature  >> 24) & 0xFF,
344*7e6ad469SVishal Kulkarni 		       (fl_hdr->signature  >> 16) & 0xFF,
345*7e6ad469SVishal Kulkarni 		       (fl_hdr->signature  >> 8) & 0xFF,
346*7e6ad469SVishal Kulkarni 		       fl_hdr->signature & 0xFF);
347*7e6ad469SVishal Kulkarni 
348*7e6ad469SVishal Kulkarni 		printf("Flash payload timestamp (GMT): %s",
349*7e6ad469SVishal Kulkarni 		       asctime(gmtime((time_t *)&fl_hdr->timestamp)));
350*7e6ad469SVishal Kulkarni 		printf("Flash payload size: %u bytes\n", fl_hdr->data_len);
351*7e6ad469SVishal Kulkarni 		printf("/******************************************************/\n");
352*7e6ad469SVishal Kulkarni 		flash_info_banner = false;
353*7e6ad469SVishal Kulkarni 	}
354*7e6ad469SVishal Kulkarni }
355*7e6ad469SVishal Kulkarni 
356*7e6ad469SVishal Kulkarni int
cudbg_view(void * handle,void * pinbuf,u32 inbuf_size,void * poutbuf,s64 * poutbuf_size)357*7e6ad469SVishal Kulkarni cudbg_view(void *handle, void *pinbuf, u32 inbuf_size,
358*7e6ad469SVishal Kulkarni 	   void *poutbuf, s64 *poutbuf_size)
359*7e6ad469SVishal Kulkarni {
360*7e6ad469SVishal Kulkarni 
361*7e6ad469SVishal Kulkarni 	struct cudbg_buffer cudbg_poutbuf = {0};
362*7e6ad469SVishal Kulkarni 	struct cudbg_entity_hdr *entity_hdr;
363*7e6ad469SVishal Kulkarni 	u32 info, offset, max_entities, i;
364*7e6ad469SVishal Kulkarni 	struct cudbg_hdr *tmp_hdr;
365*7e6ad469SVishal Kulkarni 	u32 next_rec_offset = 0;
366*7e6ad469SVishal Kulkarni 	int index, bit, all;
367*7e6ad469SVishal Kulkarni 	int rc = 0, cs;
368*7e6ad469SVishal Kulkarni 	u8 *dbg_bitmap;
369*7e6ad469SVishal Kulkarni 	int count = 0;
370*7e6ad469SVishal Kulkarni 
371*7e6ad469SVishal Kulkarni 	dbg_bitmap = ((struct cudbg_private *)handle)->dbg_init.dbg_bitmap;
372*7e6ad469SVishal Kulkarni 	info = ((struct cudbg_private *)handle)->dbg_init.info;
373*7e6ad469SVishal Kulkarni 
374*7e6ad469SVishal Kulkarni 	if (inbuf_size < (sizeof(struct cudbg_entity_hdr) +
375*7e6ad469SVishal Kulkarni 			  sizeof(struct cudbg_hdr))) {
376*7e6ad469SVishal Kulkarni 		printf("\n\tInvalid cudbg dump file\n");
377*7e6ad469SVishal Kulkarni 		return CUDBG_STATUS_NO_SIGNATURE;
378*7e6ad469SVishal Kulkarni 	}
379*7e6ad469SVishal Kulkarni 
380*7e6ad469SVishal Kulkarni 	tmp_hdr  = (struct cudbg_hdr *)pinbuf;
381*7e6ad469SVishal Kulkarni 	if ((tmp_hdr->signature != CUDBG_SIGNATURE) &&
382*7e6ad469SVishal Kulkarni 	    (tmp_hdr->signature != CUDBG_LEGACY_SIGNATURE)) {
383*7e6ad469SVishal Kulkarni 		printf("\n\tInvalid cudbg dump file\n");
384*7e6ad469SVishal Kulkarni 		return CUDBG_STATUS_NO_SIGNATURE;
385*7e6ad469SVishal Kulkarni 	}
386*7e6ad469SVishal Kulkarni 
387*7e6ad469SVishal Kulkarni 	if ((tmp_hdr->major_ver != CUDBG_MAJOR_VERSION) ||
388*7e6ad469SVishal Kulkarni 	    (tmp_hdr->minor_ver != CUDBG_MINOR_VERSION)) {
389*7e6ad469SVishal Kulkarni 		printf("\n\tMeta data version mismatch\n");
390*7e6ad469SVishal Kulkarni 		printf("\tMeta data version expected %d.%d\n",
391*7e6ad469SVishal Kulkarni 		       CUDBG_MAJOR_VERSION, CUDBG_MINOR_VERSION);
392*7e6ad469SVishal Kulkarni 		printf("\tMeta data version in dump %d.%d\n",
393*7e6ad469SVishal Kulkarni 		       tmp_hdr->major_ver, tmp_hdr->minor_ver);
394*7e6ad469SVishal Kulkarni 
395*7e6ad469SVishal Kulkarni 		cs = cudbg_find_changeset(tmp_hdr->major_ver,
396*7e6ad469SVishal Kulkarni 					  tmp_hdr->minor_ver);
397*7e6ad469SVishal Kulkarni 		if (cs != -1) {
398*7e6ad469SVishal Kulkarni 			printf("\n\tPlease use changeset %d in sw Mercurial "\
399*7e6ad469SVishal Kulkarni 			       "repo to build cudbg_app with version %d.%d\n",
400*7e6ad469SVishal Kulkarni 			       cs, tmp_hdr->major_ver, tmp_hdr->minor_ver);
401*7e6ad469SVishal Kulkarni 
402*7e6ad469SVishal Kulkarni 			printf("\n\tOr\n\n\tUse precompiled cudbg_app binary for RHEL 5.x from "\
403*7e6ad469SVishal Kulkarni 			       "vnc52:/home/surendra/vnc52/"\
404*7e6ad469SVishal Kulkarni 			       "cudbg_app/cudbg_app_<version>\"\n\n");
405*7e6ad469SVishal Kulkarni 
406*7e6ad469SVishal Kulkarni 
407*7e6ad469SVishal Kulkarni 		}
408*7e6ad469SVishal Kulkarni 		return CUDBG_METADATA_VERSION_MISMATCH;
409*7e6ad469SVishal Kulkarni 	}
410*7e6ad469SVishal Kulkarni 
411*7e6ad469SVishal Kulkarni 	if (info)
412*7e6ad469SVishal Kulkarni 		cudbg_print_cudbg_header(tmp_hdr);
413*7e6ad469SVishal Kulkarni 
414*7e6ad469SVishal Kulkarni 	next_rec_offset += tmp_hdr->data_len;
415*7e6ad469SVishal Kulkarni 	offset = tmp_hdr->hdr_len;
416*7e6ad469SVishal Kulkarni 	all = dbg_bitmap[0] & (1 << CUDBG_ALL);
417*7e6ad469SVishal Kulkarni 	max_entities = min(tmp_hdr->max_entities, CUDBG_MAX_ENTITY);
418*7e6ad469SVishal Kulkarni 
419*7e6ad469SVishal Kulkarni 	for (i = 1; i < max_entities; i++) {
420*7e6ad469SVishal Kulkarni 		index = i / 8;
421*7e6ad469SVishal Kulkarni 		bit = i % 8;
422*7e6ad469SVishal Kulkarni 
423*7e6ad469SVishal Kulkarni 		if (all || (dbg_bitmap[index] & (1 << bit))) {
424*7e6ad469SVishal Kulkarni 			entity_hdr =
425*7e6ad469SVishal Kulkarni 				(struct cudbg_entity_hdr *)((char *)pinbuf + offset);
426*7e6ad469SVishal Kulkarni 
427*7e6ad469SVishal Kulkarni 			if (entity_hdr->sys_warn)
428*7e6ad469SVishal Kulkarni 				printf("Entity warning: Type %s , %d\n",
429*7e6ad469SVishal Kulkarni 				       entity_list[i].name,
430*7e6ad469SVishal Kulkarni 				       entity_hdr->sys_warn);
431*7e6ad469SVishal Kulkarni 
432*7e6ad469SVishal Kulkarni 			if (entity_hdr->hdr_flags) {
433*7e6ad469SVishal Kulkarni 				offset += sizeof(struct cudbg_entity_hdr);
434*7e6ad469SVishal Kulkarni 				printf("Entity error: Type %s, %s\n",
435*7e6ad469SVishal Kulkarni 				       entity_list[i].name,
436*7e6ad469SVishal Kulkarni 				       err_msg[-entity_hdr->hdr_flags]);
437*7e6ad469SVishal Kulkarni 				if (entity_hdr->sys_err)
438*7e6ad469SVishal Kulkarni 					printf("System error  %d\n",
439*7e6ad469SVishal Kulkarni 					       entity_hdr->sys_err);
440*7e6ad469SVishal Kulkarni 
441*7e6ad469SVishal Kulkarni 				if (poutbuf)
442*7e6ad469SVishal Kulkarni 					*poutbuf_size = 0;
443*7e6ad469SVishal Kulkarni 
444*7e6ad469SVishal Kulkarni 				continue;
445*7e6ad469SVishal Kulkarni 			}
446*7e6ad469SVishal Kulkarni 			memset(&cudbg_poutbuf, 0, sizeof(cudbg_poutbuf));
447*7e6ad469SVishal Kulkarni 			if (entity_hdr->size > 0) {
448*7e6ad469SVishal Kulkarni 				if (poutbuf) {
449*7e6ad469SVishal Kulkarni 					cudbg_poutbuf.data = poutbuf;
450*7e6ad469SVishal Kulkarni 					/* poutbuf_size value should not be
451*7e6ad469SVishal Kulkarni  					 * more than 32 bit value
452*7e6ad469SVishal Kulkarni  					 */
453*7e6ad469SVishal Kulkarni 					assert(!((*poutbuf_size) >> 32));
454*7e6ad469SVishal Kulkarni 					cudbg_poutbuf.size = (u32)*poutbuf_size;
455*7e6ad469SVishal Kulkarni 					cudbg_poutbuf.offset = 0;
456*7e6ad469SVishal Kulkarni 				}
457*7e6ad469SVishal Kulkarni 
458*7e6ad469SVishal Kulkarni 				if (info)
459*7e6ad469SVishal Kulkarni 					printf("%-20s compressed size %u\n",
460*7e6ad469SVishal Kulkarni 					       entity_list[i].name,
461*7e6ad469SVishal Kulkarni 					       entity_hdr->size);
462*7e6ad469SVishal Kulkarni 				else {
463*7e6ad469SVishal Kulkarni 					if (entity_hdr->entity_type !=
464*7e6ad469SVishal Kulkarni 					    CUDBG_EXT_ENTITY)
465*7e6ad469SVishal Kulkarni 						printf("%s() dbg entity : %s\n",
466*7e6ad469SVishal Kulkarni 						       __func__,
467*7e6ad469SVishal Kulkarni 						       entity_list[i].name);
468*7e6ad469SVishal Kulkarni 
469*7e6ad469SVishal Kulkarni 					rc = view_entity[i - 1]
470*7e6ad469SVishal Kulkarni 						((char *)pinbuf,
471*7e6ad469SVishal Kulkarni 						 entity_hdr,
472*7e6ad469SVishal Kulkarni 						 &cudbg_poutbuf,
473*7e6ad469SVishal Kulkarni 						 tmp_hdr->chip_ver);
474*7e6ad469SVishal Kulkarni 
475*7e6ad469SVishal Kulkarni 					count++;
476*7e6ad469SVishal Kulkarni 				}
477*7e6ad469SVishal Kulkarni 			} else if (!all && i !=
478*7e6ad469SVishal Kulkarni 				   CUDBG_EXT_ENTITY) {
479*7e6ad469SVishal Kulkarni 				printf("%s() dbg entity : %s\n",
480*7e6ad469SVishal Kulkarni 				       __func__, entity_list[i].name);
481*7e6ad469SVishal Kulkarni 				printf("\t%s not available\n",
482*7e6ad469SVishal Kulkarni 				       entity_list[i].name);
483*7e6ad469SVishal Kulkarni 			}
484*7e6ad469SVishal Kulkarni 			if (rc < 0)
485*7e6ad469SVishal Kulkarni 				goto out;
486*7e6ad469SVishal Kulkarni 		}
487*7e6ad469SVishal Kulkarni 		offset += sizeof(struct cudbg_entity_hdr);
488*7e6ad469SVishal Kulkarni 	}
489*7e6ad469SVishal Kulkarni 
490*7e6ad469SVishal Kulkarni 	/* if max_entities in dump is less than current CUDBG_MAX_ENTITY
491*7e6ad469SVishal Kulkarni 	 * it means entities after tmp_hdr->max_entities does not exist
492*7e6ad469SVishal Kulkarni 	 * in that dump
493*7e6ad469SVishal Kulkarni 	 */
494*7e6ad469SVishal Kulkarni 	if (tmp_hdr->max_entities < CUDBG_MAX_ENTITY) {
495*7e6ad469SVishal Kulkarni 		for (i = tmp_hdr->max_entities; i < CUDBG_MAX_ENTITY; i++) {
496*7e6ad469SVishal Kulkarni 			index = i / 8;
497*7e6ad469SVishal Kulkarni 			bit = i % 8;
498*7e6ad469SVishal Kulkarni 
499*7e6ad469SVishal Kulkarni 			if (all || (dbg_bitmap[index] & (1 << bit))) {
500*7e6ad469SVishal Kulkarni 				printf("%s() dbg entity : %s\n",
501*7e6ad469SVishal Kulkarni 				       __func__, entity_list[i].name);
502*7e6ad469SVishal Kulkarni 				printf("\t%s does not Exist\n",
503*7e6ad469SVishal Kulkarni 				       entity_list[i].name);
504*7e6ad469SVishal Kulkarni 			}
505*7e6ad469SVishal Kulkarni 		}
506*7e6ad469SVishal Kulkarni 	}
507*7e6ad469SVishal Kulkarni 	if (poutbuf) {
508*7e6ad469SVishal Kulkarni 		if (!count)
509*7e6ad469SVishal Kulkarni 			*poutbuf_size = 0;
510*7e6ad469SVishal Kulkarni 		else
511*7e6ad469SVishal Kulkarni 			*poutbuf_size = cudbg_poutbuf.size;
512*7e6ad469SVishal Kulkarni 	}
513*7e6ad469SVishal Kulkarni 
514*7e6ad469SVishal Kulkarni 	return validate_next_rec_offset(pinbuf, inbuf_size, next_rec_offset);
515*7e6ad469SVishal Kulkarni 
516*7e6ad469SVishal Kulkarni out:
517*7e6ad469SVishal Kulkarni 	if (poutbuf)
518*7e6ad469SVishal Kulkarni 		*poutbuf_size = cudbg_poutbuf.size;
519*7e6ad469SVishal Kulkarni 	return rc;
520*7e6ad469SVishal Kulkarni }
521*7e6ad469SVishal Kulkarni 
522*7e6ad469SVishal Kulkarni int
view_cim_q(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf,enum chip_type chip)523*7e6ad469SVishal Kulkarni view_cim_q(char *pbuf, struct cudbg_entity_hdr *entity_hdr,
524*7e6ad469SVishal Kulkarni 	   struct cudbg_buffer *cudbg_poutbuf,
525*7e6ad469SVishal Kulkarni 	   enum chip_type chip)
526*7e6ad469SVishal Kulkarni {
527*7e6ad469SVishal Kulkarni 	struct cudbg_buffer c_buff, dc_buff;
528*7e6ad469SVishal Kulkarni 	u32 i, *pdata = NULL;
529*7e6ad469SVishal Kulkarni 	int rc;
530*7e6ad469SVishal Kulkarni 
531*7e6ad469SVishal Kulkarni 	rc = cudbg_view_decompress_buff(pbuf, entity_hdr, &c_buff, &dc_buff);
532*7e6ad469SVishal Kulkarni 	if (rc)
533*7e6ad469SVishal Kulkarni 		return rc;
534*7e6ad469SVishal Kulkarni 
535*7e6ad469SVishal Kulkarni 	pdata = (u32 *)dc_buff.data;
536*7e6ad469SVishal Kulkarni 	for (i = 0; i < dc_buff.offset / 4; i += 4)
537*7e6ad469SVishal Kulkarni 		printf("%#06x: %08x %08x %08x "\
538*7e6ad469SVishal Kulkarni 			     "%08x\n", i * 4,
539*7e6ad469SVishal Kulkarni 			     pdata[i + 0], pdata[i + 1],
540*7e6ad469SVishal Kulkarni 			     pdata[i + 2], pdata[i + 3]);
541*7e6ad469SVishal Kulkarni 
542*7e6ad469SVishal Kulkarni 	return rc;
543*7e6ad469SVishal Kulkarni }
544*7e6ad469SVishal Kulkarni 
545*7e6ad469SVishal Kulkarni static int
view_cim_la_t6(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf)546*7e6ad469SVishal Kulkarni view_cim_la_t6(char *pbuf, struct cudbg_entity_hdr *entity_hdr,
547*7e6ad469SVishal Kulkarni 	       struct cudbg_buffer *cudbg_poutbuf)
548*7e6ad469SVishal Kulkarni {
549*7e6ad469SVishal Kulkarni 	struct cudbg_buffer c_buff, dc_buff;
550*7e6ad469SVishal Kulkarni 	u32 i, *p, cfg, dc_size;
551*7e6ad469SVishal Kulkarni 	int rc;
552*7e6ad469SVishal Kulkarni 
553*7e6ad469SVishal Kulkarni 	rc = cudbg_view_decompress_buff(pbuf, entity_hdr, &c_buff, &dc_buff);
554*7e6ad469SVishal Kulkarni 	if (rc)
555*7e6ad469SVishal Kulkarni 		return rc;
556*7e6ad469SVishal Kulkarni 
557*7e6ad469SVishal Kulkarni 	dc_size = dc_buff.offset;
558*7e6ad469SVishal Kulkarni 	p = (u32 *)((char *)dc_buff.data + sizeof(cfg));
559*7e6ad469SVishal Kulkarni 	cfg = *((u32 *)dc_buff.data);
560*7e6ad469SVishal Kulkarni 	dc_size -= sizeof(cfg);
561*7e6ad469SVishal Kulkarni 
562*7e6ad469SVishal Kulkarni 	if (cfg & F_UPDBGLACAPTPCONLY) {
563*7e6ad469SVishal Kulkarni 		printf("Status   Inst    Data      "\
564*7e6ad469SVishal Kulkarni 			     "PC\r\n");
565*7e6ad469SVishal Kulkarni 
566*7e6ad469SVishal Kulkarni 		for (i = 0; i < dc_size; i += 40, p += 10) {
567*7e6ad469SVishal Kulkarni 			printf("  %02x   %08x %08x %08x\n",
568*7e6ad469SVishal Kulkarni 				p[3] & 0xff, p[2], p[1], p[0]);
569*7e6ad469SVishal Kulkarni 
570*7e6ad469SVishal Kulkarni 			printf("  %02x   %02x%06x %02x%06x %02x%06x\n",
571*7e6ad469SVishal Kulkarni 				(p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
572*7e6ad469SVishal Kulkarni 				     p[5] & 0xff, p[4] >> 8, p[4] & 0xff,
573*7e6ad469SVishal Kulkarni 				     p[3] >> 8);
574*7e6ad469SVishal Kulkarni 
575*7e6ad469SVishal Kulkarni 			printf("  %02x   %04x%04x %04x%04x %04x%04x\n",
576*7e6ad469SVishal Kulkarni 				(p[9] >> 16) & 0xff, p[9] & 0xffff,
577*7e6ad469SVishal Kulkarni 				p[8] >> 16, p[8] & 0xffff, p[7] >> 16,
578*7e6ad469SVishal Kulkarni 				p[7] & 0xffff, p[6] >> 16);
579*7e6ad469SVishal Kulkarni 		}
580*7e6ad469SVishal Kulkarni 		goto err1;
581*7e6ad469SVishal Kulkarni 	}
582*7e6ad469SVishal Kulkarni 
583*7e6ad469SVishal Kulkarni 	printf("Status   Inst    Data      PC     "\
584*7e6ad469SVishal Kulkarni 		     "LS0Stat  LS0Addr  LS0Data  LS1Stat  LS1Addr  LS1Data\n");
585*7e6ad469SVishal Kulkarni 
586*7e6ad469SVishal Kulkarni 	for (i = 0; i < dc_size; i += 40, p += 10) {
587*7e6ad469SVishal Kulkarni 		printf("  %02x   %04x%04x %04x%04x "\
588*7e6ad469SVishal Kulkarni 			     "%04x%04x %08x %08x %08x %08x %08x %08x\n",
589*7e6ad469SVishal Kulkarni 			     (p[9] >> 16) & 0xff,       /* Status */
590*7e6ad469SVishal Kulkarni 			     p[9] & 0xffff, p[8] >> 16, /* Inst */
591*7e6ad469SVishal Kulkarni 			     p[8] & 0xffff, p[7] >> 16, /* Data */
592*7e6ad469SVishal Kulkarni 			     p[7] & 0xffff, p[6] >> 16, /* PC */
593*7e6ad469SVishal Kulkarni 			     p[2], p[1], p[0],          /* LS0 Stat, Addr
594*7e6ad469SVishal Kulkarni 							   and Data */
595*7e6ad469SVishal Kulkarni 			     p[5], p[4], p[3]);         /* LS1 Stat, Addr
596*7e6ad469SVishal Kulkarni 							   and Data */
597*7e6ad469SVishal Kulkarni 	}
598*7e6ad469SVishal Kulkarni 
599*7e6ad469SVishal Kulkarni err1:
600*7e6ad469SVishal Kulkarni 	return rc;
601*7e6ad469SVishal Kulkarni }
602*7e6ad469SVishal Kulkarni 
603*7e6ad469SVishal Kulkarni static int
view_cim_la_t5(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf)604*7e6ad469SVishal Kulkarni view_cim_la_t5(char *pbuf, struct cudbg_entity_hdr *entity_hdr,
605*7e6ad469SVishal Kulkarni 	       struct cudbg_buffer *cudbg_poutbuf)
606*7e6ad469SVishal Kulkarni {
607*7e6ad469SVishal Kulkarni 	struct cudbg_buffer c_buff, dc_buff;
608*7e6ad469SVishal Kulkarni 	u32 i, *p, cfg, dc_size;
609*7e6ad469SVishal Kulkarni 	int rc;
610*7e6ad469SVishal Kulkarni 
611*7e6ad469SVishal Kulkarni 	rc = cudbg_view_decompress_buff(pbuf, entity_hdr, &c_buff, &dc_buff);
612*7e6ad469SVishal Kulkarni 	if (rc)
613*7e6ad469SVishal Kulkarni 		return rc;
614*7e6ad469SVishal Kulkarni 
615*7e6ad469SVishal Kulkarni 	dc_size = dc_buff.offset;
616*7e6ad469SVishal Kulkarni 	p = (u32 *)((char *)dc_buff.data + sizeof(cfg));
617*7e6ad469SVishal Kulkarni 	cfg = *((u32 *)dc_buff.data);
618*7e6ad469SVishal Kulkarni 	dc_size -= sizeof(cfg);
619*7e6ad469SVishal Kulkarni 
620*7e6ad469SVishal Kulkarni 	if (cfg & F_UPDBGLACAPTPCONLY) {
621*7e6ad469SVishal Kulkarni 		/* as per cim_la_show_3in1() (in
622*7e6ad469SVishal Kulkarni 		 * sw\dev\linux\drv\cxgb4_main.c)*/
623*7e6ad469SVishal Kulkarni 		printf("Status   Data      PC\r\n");
624*7e6ad469SVishal Kulkarni 
625*7e6ad469SVishal Kulkarni 		for (i = 0; i < dc_size; i += 32, p += 8) {
626*7e6ad469SVishal Kulkarni 			printf("  %02X   %08X %08X\r\n",
627*7e6ad469SVishal Kulkarni 				(p[5] & 0xFF), p[6], p[7]);
628*7e6ad469SVishal Kulkarni 
629*7e6ad469SVishal Kulkarni 			printf(
630*7e6ad469SVishal Kulkarni 				     "  %02X   %02X%06X %02X%06X\n",
631*7e6ad469SVishal Kulkarni 				     ((p[3] >> 8) & 0xFF), (p[3] & 0xFF),
632*7e6ad469SVishal Kulkarni 				     (p[4] >> 8), (p[4] & 0xFF), (p[5] >> 8));
633*7e6ad469SVishal Kulkarni 
634*7e6ad469SVishal Kulkarni 			printf(
635*7e6ad469SVishal Kulkarni 				     "  %02X   %X%07X %X%07X\r\n",
636*7e6ad469SVishal Kulkarni 				     ((p[0] >> 4) & 0xFF), (p[0] & 0xF),
637*7e6ad469SVishal Kulkarni 				     (p[1] >> 4), (p[1] & 0xF), (p[2] >> 4));
638*7e6ad469SVishal Kulkarni 		}
639*7e6ad469SVishal Kulkarni 		goto err1;
640*7e6ad469SVishal Kulkarni 	}
641*7e6ad469SVishal Kulkarni 
642*7e6ad469SVishal Kulkarni 	printf("Status   Data      PC     LS0Stat  "\
643*7e6ad469SVishal Kulkarni 		     "LS0Addr             LS0Data\n");
644*7e6ad469SVishal Kulkarni 
645*7e6ad469SVishal Kulkarni 	for (i = 0; i < dc_size; i += 32, p += 8) {
646*7e6ad469SVishal Kulkarni 		printf("%02x   %x%07x %x%07x %08x "\
647*7e6ad469SVishal Kulkarni 			     "%08x %08x%08x%08x%08x\n",
648*7e6ad469SVishal Kulkarni 			     ((p[0] >> 4) & 0xFF), (p[0] & 0xF), (p[1] >> 4),
649*7e6ad469SVishal Kulkarni 			     (p[1] & 0xF), (p[2] >> 4), (p[2] & 0xF), p[3],
650*7e6ad469SVishal Kulkarni 			     p[4], p[5], p[6], p[7]);
651*7e6ad469SVishal Kulkarni 	}
652*7e6ad469SVishal Kulkarni err1:
653*7e6ad469SVishal Kulkarni 	return rc;
654*7e6ad469SVishal Kulkarni }
655*7e6ad469SVishal Kulkarni 
656*7e6ad469SVishal Kulkarni int
view_cim_la(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf,enum chip_type chip)657*7e6ad469SVishal Kulkarni view_cim_la(char *pbuf, struct cudbg_entity_hdr *entity_hdr,
658*7e6ad469SVishal Kulkarni 	    struct cudbg_buffer *cudbg_poutbuf, enum chip_type chip)
659*7e6ad469SVishal Kulkarni {
660*7e6ad469SVishal Kulkarni 	int rc = -1;
661*7e6ad469SVishal Kulkarni 
662*7e6ad469SVishal Kulkarni 	if (is_t5(chip))
663*7e6ad469SVishal Kulkarni 		rc = view_cim_la_t5(pbuf, entity_hdr, cudbg_poutbuf);
664*7e6ad469SVishal Kulkarni 	else if (is_t6(chip))
665*7e6ad469SVishal Kulkarni 		rc = view_cim_la_t6(pbuf, entity_hdr, cudbg_poutbuf);
666*7e6ad469SVishal Kulkarni 
667*7e6ad469SVishal Kulkarni 	return rc;
668*7e6ad469SVishal Kulkarni }
669*7e6ad469SVishal Kulkarni 
670*7e6ad469SVishal Kulkarni int
view_cim_ma_la(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf,enum chip_type chip)671*7e6ad469SVishal Kulkarni view_cim_ma_la(char *pbuf, struct cudbg_entity_hdr *entity_hdr,
672*7e6ad469SVishal Kulkarni 	       struct cudbg_buffer *cudbg_poutbuf, enum chip_type chip)
673*7e6ad469SVishal Kulkarni {
674*7e6ad469SVishal Kulkarni 	struct cudbg_buffer c_buff, dc_buff;
675*7e6ad469SVishal Kulkarni 	int rc, i, j;
676*7e6ad469SVishal Kulkarni 	u32 *p;
677*7e6ad469SVishal Kulkarni 
678*7e6ad469SVishal Kulkarni 	rc = cudbg_view_decompress_buff(pbuf, entity_hdr, &c_buff, &dc_buff);
679*7e6ad469SVishal Kulkarni 	if (rc)
680*7e6ad469SVishal Kulkarni 		return rc;
681*7e6ad469SVishal Kulkarni 
682*7e6ad469SVishal Kulkarni 	p = (u32 *)dc_buff.data;
683*7e6ad469SVishal Kulkarni 	for (i = 0; i <= CIM_MALA_SIZE; i++, p += 4) {
684*7e6ad469SVishal Kulkarni 		if (i < CIM_MALA_SIZE) {
685*7e6ad469SVishal Kulkarni 			printf(
686*7e6ad469SVishal Kulkarni 				     "%02x%08x%08x%08x%08x\n",
687*7e6ad469SVishal Kulkarni 				     p[4], p[3], p[2], p[1], p[0]);
688*7e6ad469SVishal Kulkarni 		} else {
689*7e6ad469SVishal Kulkarni 			printf("\nCnt ID Tag UE   "\
690*7e6ad469SVishal Kulkarni 				     "   Data       RDY VLD\n");
691*7e6ad469SVishal Kulkarni 			for (j = 0; j < CIM_MALA_SIZE ; j++, p += 3) {
692*7e6ad469SVishal Kulkarni 				printf(
693*7e6ad469SVishal Kulkarni 					     "%3u %2u  %x  %u %08x%08x  %u   "\
694*7e6ad469SVishal Kulkarni 					     "%u\n",
695*7e6ad469SVishal Kulkarni 					     (p[2] >> 10) & 0xff,
696*7e6ad469SVishal Kulkarni 					     (p[2] >> 7) & 7, (p[2] >> 3) & 0xf,
697*7e6ad469SVishal Kulkarni 					     (p[2] >> 2) & 1,
698*7e6ad469SVishal Kulkarni 					     (p[1] >> 2) | ((p[2] & 3) << 30),
699*7e6ad469SVishal Kulkarni 					     (p[0] >> 2) | ((p[1] & 3) << 30),
700*7e6ad469SVishal Kulkarni 					     (p[0] >> 1) & 1, p[0] & 1);
701*7e6ad469SVishal Kulkarni 			}
702*7e6ad469SVishal Kulkarni 		}
703*7e6ad469SVishal Kulkarni 	}
704*7e6ad469SVishal Kulkarni 
705*7e6ad469SVishal Kulkarni 	return rc;
706*7e6ad469SVishal Kulkarni }
707*7e6ad469SVishal Kulkarni 
708*7e6ad469SVishal Kulkarni int
view_cim_qcfg(char * pbuf,struct cudbg_entity_hdr * entity_hdr,struct cudbg_buffer * cudbg_poutbuf,enum chip_type chip)709*7e6ad469SVishal Kulkarni view_cim_qcfg(char *pbuf, struct cudbg_entity_hdr *entity_hdr,