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