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