xref: /freebsd/sys/dev/qlxgbe/ql_dbg.c (revision 1f474190)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2013-2016 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 : ql_dbg.c
31  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32  */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35 
36 #include "ql_os.h"
37 #include "ql_hw.h"
38 #include "ql_def.h"
39 #include "ql_inline.h"
40 #include "ql_ver.h"
41 #include "ql_glbl.h"
42 #include "ql_dbg.h"
43 
44 /*
45  * Name: ql_dump_buf32
46  * Function: dumps a buffer as 32 bit words
47  */
48 void ql_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: 0x%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 
83 /*
84  * Name: ql_dump_buf16
85  * Function: dumps a buffer as 16 bit words
86  */
87 void ql_dump_buf16(qla_host_t *ha, const char *msg, void *dbuf16, uint32_t len16)
88 {
89         device_t dev;
90 	uint32_t i = 0;
91 	uint16_t *buf;
92 
93         dev = ha->pci_dev;
94 	buf = dbuf16;
95 
96 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
97 
98 	while (len16 >= 8) {
99 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
100 			" 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
101 			buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
102 		i += 16;
103 		len16 -= 8;
104 		buf += 8;
105 	}
106 	switch (len16) {
107 	case 1:
108 		device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
109 		break;
110 	case 2:
111 		device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
112 		break;
113 	case 3:
114 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
115 			i, buf[0], buf[1], buf[2]);
116 		break;
117 	case 4:
118 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
119 			buf[0], buf[1], buf[2], buf[3]);
120 		break;
121 	case 5:
122 		device_printf(dev,"0x%08x:"
123 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
124 			buf[0], buf[1], buf[2], buf[3], buf[4]);
125 		break;
126 	case 6:
127 		device_printf(dev,"0x%08x:"
128 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
129 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
130 		break;
131 	case 7:
132 		device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
133 			" 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
134 			buf[2], buf[3], buf[4], buf[5], buf[6]);
135 		break;
136 	default:
137 		break;
138 	}
139 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
140 }
141 
142 /*
143  * Name: ql_dump_buf8
144  * Function: dumps a buffer as bytes
145  */
146 void ql_dump_buf8(qla_host_t *ha, const char *msg, void *dbuf, uint32_t len)
147 {
148         device_t dev;
149 	uint32_t i = 0;
150 	uint8_t *buf;
151 
152         dev = ha->pci_dev;
153 	buf = dbuf;
154 
155 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
156 
157 	while (len >= 16) {
158 		device_printf(dev,"0x%08x:"
159 			" %02x %02x %02x %02x %02x %02x %02x %02x"
160 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
161 			buf[0], buf[1], buf[2], buf[3],
162 			buf[4], buf[5], buf[6], buf[7],
163 			buf[8], buf[9], buf[10], buf[11],
164 			buf[12], buf[13], buf[14], buf[15]);
165 		i += 16;
166 		len -= 16;
167 		buf += 16;
168 	}
169 	switch (len) {
170 	case 1:
171 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
172 		break;
173 	case 2:
174 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
175 		break;
176 	case 3:
177 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
178 			i, buf[0], buf[1], buf[2]);
179 		break;
180 	case 4:
181 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
182 			buf[0], buf[1], buf[2], buf[3]);
183 		break;
184 	case 5:
185 		device_printf(dev,"0x%08x:"
186 			" %02x %02x %02x %02x %02x\n", i,
187 			buf[0], buf[1], buf[2], buf[3], buf[4]);
188 		break;
189 	case 6:
190 		device_printf(dev,"0x%08x:"
191 			" %02x %02x %02x %02x %02x %02x\n", i,
192 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
193 		break;
194 	case 7:
195 		device_printf(dev,"0x%08x:"
196 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
197 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
198 		break;
199 	case 8:
200 		device_printf(dev,"0x%08x:"
201 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
202 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
203 			buf[7]);
204 		break;
205 	case 9:
206 		device_printf(dev,"0x%08x:"
207 			" %02x %02x %02x %02x %02x %02x %02x %02x"
208 			" %02x\n", i,
209 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
210 			buf[7], buf[8]);
211 		break;
212 	case 10:
213 		device_printf(dev,"0x%08x:"
214 			" %02x %02x %02x %02x %02x %02x %02x %02x"
215 			" %02x %02x\n", i,
216 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
217 			buf[7], buf[8], buf[9]);
218 		break;
219 	case 11:
220 		device_printf(dev,"0x%08x:"
221 			" %02x %02x %02x %02x %02x %02x %02x %02x"
222 			" %02x %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], buf[10]);
225 		break;
226 	case 12:
227 		device_printf(dev,"0x%08x:"
228 			" %02x %02x %02x %02x %02x %02x %02x %02x"
229 			" %02x %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], buf[11]);
232 		break;
233 	case 13:
234 		device_printf(dev,"0x%08x:"
235 			" %02x %02x %02x %02x %02x %02x %02x %02x"
236 			" %02x %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], buf[12]);
239 		break;
240 	case 14:
241 		device_printf(dev,"0x%08x:"
242 			" %02x %02x %02x %02x %02x %02x %02x %02x"
243 			" %02x %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 			buf[13]);
247 		break;
248 	case 15:
249 		device_printf(dev,"0x%08x:"
250 			" %02x %02x %02x %02x %02x %02x %02x %02x"
251 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
252 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
253 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
254 			buf[13], buf[14]);
255 		break;
256 	default:
257 		break;
258 	}
259 
260 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
261 }
262