xref: /freebsd/sys/dev/qlxgb/qla_dbg.c (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2011-2013 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 : qla_dbg.c
31  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32  */
33 
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36 
37 #include "qla_os.h"
38 #include "qla_reg.h"
39 #include "qla_hw.h"
40 #include "qla_def.h"
41 #include "qla_inline.h"
42 #include "qla_ver.h"
43 #include "qla_glbl.h"
44 #include "qla_dbg.h"
45 
46 
47 uint32_t dbg_level = 0 ;
48 /*
49  * Name: qla_dump_buf32
50  * Function: dumps a buffer as 32 bit words
51  */
52 void qla_dump_buf32(qla_host_t *ha, char *msg, void *dbuf32, uint32_t len32)
53 {
54         device_t dev;
55 	uint32_t i = 0;
56 	uint32_t *buf;
57 
58         dev = ha->pci_dev;
59 	buf = dbuf32;
60 
61 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
62 
63 	while (len32 >= 4) {
64 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
65 			i, buf[0], buf[1], buf[2], buf[3]);
66 		i += 4 * 4;
67 		len32 -= 4;
68 		buf += 4;
69 	}
70 	switch (len32) {
71 	case 1:
72 		device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
73 		break;
74 	case 2:
75 		device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
76 		break;
77 	case 3:
78 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
79 			i, buf[0], buf[1], buf[2]);
80 		break;
81 	default:
82 		break;
83 	}
84 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
85 }
86 
87 /*
88  * Name: qla_dump_buf16
89  * Function: dumps a buffer as 16 bit words
90  */
91 void qla_dump_buf16(qla_host_t *ha, 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 
146 /*
147  * Name: qla_dump_buf8
148  * Function: dumps a buffer as bytes
149  */
150 void qla_dump_buf8(qla_host_t *ha, char *msg, void *dbuf, uint32_t len)
151 {
152         device_t dev;
153 	uint32_t i = 0;
154 	uint8_t *buf;
155 
156         dev = ha->pci_dev;
157 	buf = dbuf;
158 
159 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
160 
161 	while (len >= 16) {
162 		device_printf(dev,"0x%08x:"
163 			" %02x %02x %02x %02x %02x %02x %02x %02x"
164 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
165 			buf[0], buf[1], buf[2], buf[3],
166 			buf[4], buf[5], buf[6], buf[7],
167 			buf[8], buf[9], buf[10], buf[11],
168 			buf[12], buf[13], buf[14], buf[15]);
169 		i += 16;
170 		len -= 16;
171 		buf += 16;
172 	}
173 	switch (len) {
174 	case 1:
175 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
176 		break;
177 	case 2:
178 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
179 		break;
180 	case 3:
181 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
182 			i, buf[0], buf[1], buf[2]);
183 		break;
184 	case 4:
185 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
186 			buf[0], buf[1], buf[2], buf[3]);
187 		break;
188 	case 5:
189 		device_printf(dev,"0x%08x:"
190 			" %02x %02x %02x %02x %02x\n", i,
191 			buf[0], buf[1], buf[2], buf[3], buf[4]);
192 		break;
193 	case 6:
194 		device_printf(dev,"0x%08x:"
195 			" %02x %02x %02x %02x %02x %02x\n", i,
196 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
197 		break;
198 	case 7:
199 		device_printf(dev,"0x%08x:"
200 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
201 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
202 		break;
203 	case 8:
204 		device_printf(dev,"0x%08x:"
205 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
206 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
207 			buf[7]);
208 		break;
209 	case 9:
210 		device_printf(dev,"0x%08x:"
211 			" %02x %02x %02x %02x %02x %02x %02x %02x"
212 			" %02x\n", i,
213 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
214 			buf[7], buf[8]);
215 		break;
216 	case 10:
217 		device_printf(dev,"0x%08x:"
218 			" %02x %02x %02x %02x %02x %02x %02x %02x"
219 			" %02x %02x\n", i,
220 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
221 			buf[7], buf[8], buf[9]);
222 		break;
223 	case 11:
224 		device_printf(dev,"0x%08x:"
225 			" %02x %02x %02x %02x %02x %02x %02x %02x"
226 			" %02x %02x %02x\n", i,
227 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
228 			buf[7], buf[8], buf[9], buf[10]);
229 		break;
230 	case 12:
231 		device_printf(dev,"0x%08x:"
232 			" %02x %02x %02x %02x %02x %02x %02x %02x"
233 			" %02x %02x %02x %02x\n", i,
234 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
235 			buf[7], buf[8], buf[9], buf[10], buf[11]);
236 		break;
237 	case 13:
238 		device_printf(dev,"0x%08x:"
239 			" %02x %02x %02x %02x %02x %02x %02x %02x"
240 			" %02x %02x %02x %02x %02x\n", i,
241 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
242 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
243 		break;
244 	case 14:
245 		device_printf(dev,"0x%08x:"
246 			" %02x %02x %02x %02x %02x %02x %02x %02x"
247 			" %02x %02x %02x %02x %02x %02x\n", i,
248 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
249 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
250 			buf[13]);
251 		break;
252 	case 15:
253 		device_printf(dev,"0x%08x:"
254 			" %02x %02x %02x %02x %02x %02x %02x %02x"
255 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
256 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
257 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
258 			buf[13], buf[14]);
259 		break;
260 	default:
261 		break;
262 	}
263 
264 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
265 }
266