xref: /freebsd/sys/dev/qlxge/qls_dbg.c (revision 1c05a6ea6b849ff95e539c31adea887c644a6a01)
1 /*
2  * Copyright (c) 2013-2014 Qlogic Corporation
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  */
27 /*
28  * File : qls_dbg.c
29  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
30  */
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 #include "qls_os.h"
35 #include "qls_hw.h"
36 #include "qls_def.h"
37 #include "qls_inline.h"
38 #include "qls_ver.h"
39 #include "qls_glbl.h"
40 #include "qls_dbg.h"
41 
42 
43 uint32_t qls_dbg_level = 0 ;
44 /*
45  * Name: qls_dump_buf32
46  * Function: dumps a buffer as 32 bit words
47  */
48 void
49 qls_dump_buf32(qla_host_t *ha, const char *msg, void *dbuf32, uint32_t len32)
50 {
51         device_t dev;
52 	uint32_t i = 0;
53 	uint32_t *buf;
54 
55         dev = ha->pci_dev;
56 	buf = dbuf32;
57 
58 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
59 
60 	while (len32 >= 4) {
61 		device_printf(dev,"0x%08x:\t0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
62 			i, buf[0], buf[1], buf[2], buf[3]);
63 		i += 4 * 4;
64 		len32 -= 4;
65 		buf += 4;
66 	}
67 	switch (len32) {
68 	case 1:
69 		device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
70 		break;
71 	case 2:
72 		device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
73 		break;
74 	case 3:
75 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
76 			i, buf[0], buf[1], buf[2]);
77 		break;
78 	default:
79 		break;
80 	}
81 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
82 
83 	return;
84 }
85 
86 /*
87  * Name: qls_dump_buf16
88  * Function: dumps a buffer as 16 bit words
89  */
90 void
91 qls_dump_buf16(qla_host_t *ha, const char *msg, void *dbuf16, uint32_t len16)
92 {
93         device_t dev;
94 	uint32_t i = 0;
95 	uint16_t *buf;
96 
97         dev = ha->pci_dev;
98 	buf = dbuf16;
99 
100 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
101 
102 	while (len16 >= 8) {
103 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
104 			" 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
105 			buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
106 		i += 16;
107 		len16 -= 8;
108 		buf += 8;
109 	}
110 	switch (len16) {
111 	case 1:
112 		device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
113 		break;
114 	case 2:
115 		device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
116 		break;
117 	case 3:
118 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
119 			i, buf[0], buf[1], buf[2]);
120 		break;
121 	case 4:
122 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
123 			buf[0], buf[1], buf[2], buf[3]);
124 		break;
125 	case 5:
126 		device_printf(dev,"0x%08x:"
127 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
128 			buf[0], buf[1], buf[2], buf[3], buf[4]);
129 		break;
130 	case 6:
131 		device_printf(dev,"0x%08x:"
132 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
133 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
134 		break;
135 	case 7:
136 		device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
137 			" 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
138 			buf[2], buf[3], buf[4], buf[5], buf[6]);
139 		break;
140 	default:
141 		break;
142 	}
143 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
144 
145 	return;
146 }
147 
148 /*
149  * Name: qls_dump_buf8
150  * Function: dumps a buffer as bytes
151  */
152 void
153 qls_dump_buf8(qla_host_t *ha, const char *msg, void *dbuf, uint32_t len)
154 {
155         device_t dev;
156 	uint32_t i = 0;
157 	uint8_t *buf;
158 
159         dev = ha->pci_dev;
160 	buf = dbuf;
161 
162 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
163 
164 	while (len >= 16) {
165 		device_printf(dev,"0x%08x:"
166 			" %02x %02x %02x %02x %02x %02x %02x %02x"
167 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
168 			buf[0], buf[1], buf[2], buf[3],
169 			buf[4], buf[5], buf[6], buf[7],
170 			buf[8], buf[9], buf[10], buf[11],
171 			buf[12], buf[13], buf[14], buf[15]);
172 		i += 16;
173 		len -= 16;
174 		buf += 16;
175 	}
176 	switch (len) {
177 	case 1:
178 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
179 		break;
180 	case 2:
181 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
182 		break;
183 	case 3:
184 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
185 			i, buf[0], buf[1], buf[2]);
186 		break;
187 	case 4:
188 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
189 			buf[0], buf[1], buf[2], buf[3]);
190 		break;
191 	case 5:
192 		device_printf(dev,"0x%08x:"
193 			" %02x %02x %02x %02x %02x\n", i,
194 			buf[0], buf[1], buf[2], buf[3], buf[4]);
195 		break;
196 	case 6:
197 		device_printf(dev,"0x%08x:"
198 			" %02x %02x %02x %02x %02x %02x\n", i,
199 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
200 		break;
201 	case 7:
202 		device_printf(dev,"0x%08x:"
203 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
204 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
205 		break;
206 	case 8:
207 		device_printf(dev,"0x%08x:"
208 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
209 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
210 			buf[7]);
211 		break;
212 	case 9:
213 		device_printf(dev,"0x%08x:"
214 			" %02x %02x %02x %02x %02x %02x %02x %02x"
215 			" %02x\n", i,
216 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
217 			buf[7], buf[8]);
218 		break;
219 	case 10:
220 		device_printf(dev,"0x%08x:"
221 			" %02x %02x %02x %02x %02x %02x %02x %02x"
222 			" %02x %02x\n", i,
223 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
224 			buf[7], buf[8], buf[9]);
225 		break;
226 	case 11:
227 		device_printf(dev,"0x%08x:"
228 			" %02x %02x %02x %02x %02x %02x %02x %02x"
229 			" %02x %02x %02x\n", i,
230 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
231 			buf[7], buf[8], buf[9], buf[10]);
232 		break;
233 	case 12:
234 		device_printf(dev,"0x%08x:"
235 			" %02x %02x %02x %02x %02x %02x %02x %02x"
236 			" %02x %02x %02x %02x\n", i,
237 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
238 			buf[7], buf[8], buf[9], buf[10], buf[11]);
239 		break;
240 	case 13:
241 		device_printf(dev,"0x%08x:"
242 			" %02x %02x %02x %02x %02x %02x %02x %02x"
243 			" %02x %02x %02x %02x %02x\n", i,
244 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
245 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
246 		break;
247 	case 14:
248 		device_printf(dev,"0x%08x:"
249 			" %02x %02x %02x %02x %02x %02x %02x %02x"
250 			" %02x %02x %02x %02x %02x %02x\n", i,
251 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
252 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
253 			buf[13]);
254 		break;
255 	case 15:
256 		device_printf(dev,"0x%08x:"
257 			" %02x %02x %02x %02x %02x %02x %02x %02x"
258 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
259 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
260 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
261 			buf[13], buf[14]);
262 		break;
263 	default:
264 		break;
265 	}
266 
267 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
268 
269 	return;
270 }
271 
272 void
273 qls_dump_cq(qla_host_t *ha)
274 {
275 	qls_dump_buf32(ha, "cq_icb", ha->rx_ring[0].cq_icb_vaddr,
276 		(sizeof (q81_cq_icb_t) >> 2));
277 
278 	device_printf(ha->pci_dev, "%s: lbq_addr_tbl_paddr  %p\n", __func__,
279 		(void *)ha->rx_ring[0].lbq_addr_tbl_paddr);
280 
281 	qls_dump_buf32(ha, "lbq_addr_tbl", ha->rx_ring[0].lbq_addr_tbl_vaddr,
282 		(PAGE_SIZE >> 2));
283 
284 	device_printf(ha->pci_dev, "%s: lbq_paddr  %p\n", __func__,
285 		(void *)ha->rx_ring[0].lbq_paddr);
286 
287 	qls_dump_buf32(ha, "lbq", ha->rx_ring[0].lbq_vaddr,
288 		(QLA_LBQ_SIZE >> 2));
289 
290 	device_printf(ha->pci_dev, "%s: sbq_addr_tbl_paddr  %p\n", __func__,
291 		(void *)ha->rx_ring[0].sbq_addr_tbl_paddr);
292 
293 	qls_dump_buf32(ha, "sbq_addr_tbl", ha->rx_ring[0].sbq_addr_tbl_vaddr,
294 		(PAGE_SIZE >> 2));
295 
296 	device_printf(ha->pci_dev, "%s: sbq_paddr  %p\n", __func__,
297 		(void *)ha->rx_ring[0].sbq_paddr);
298 
299 	qls_dump_buf32(ha, "sbq", ha->rx_ring[0].sbq_vaddr,
300 		(QLA_SBQ_SIZE >> 2) );
301 
302 	device_printf(ha->pci_dev, "%s: lb_paddr  %p\n", __func__,
303 		(void *)ha->rx_ring[0].lb_paddr);
304 
305 	return;
306 }
307 
308