xref: /freebsd/sys/dev/qlxgbe/ql_dbg.c (revision bd18fd57db1df29da1a3adf94d47924a977a29c2)
1 /*
2  * Copyright (c) 2013-2016 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 : ql_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 "ql_os.h"
35 #include "ql_hw.h"
36 #include "ql_def.h"
37 #include "ql_inline.h"
38 #include "ql_ver.h"
39 #include "ql_glbl.h"
40 #include "ql_dbg.h"
41 
42 /*
43  * Name: ql_dump_buf32
44  * Function: dumps a buffer as 32 bit words
45  */
46 void ql_dump_buf32(qla_host_t *ha, const char *msg, void *dbuf32, uint32_t len32)
47 {
48         device_t dev;
49 	uint32_t i = 0;
50 	uint32_t *buf;
51 
52         dev = ha->pci_dev;
53 	buf = dbuf32;
54 
55 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
56 
57 	while (len32 >= 4) {
58 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
59 			i, buf[0], buf[1], buf[2], buf[3]);
60 		i += 4 * 4;
61 		len32 -= 4;
62 		buf += 4;
63 	}
64 	switch (len32) {
65 	case 1:
66 		device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
67 		break;
68 	case 2:
69 		device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
70 		break;
71 	case 3:
72 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
73 			i, buf[0], buf[1], buf[2]);
74 		break;
75 	default:
76 		break;
77 	}
78 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
79 }
80 
81 /*
82  * Name: ql_dump_buf16
83  * Function: dumps a buffer as 16 bit words
84  */
85 void ql_dump_buf16(qla_host_t *ha, const char *msg, void *dbuf16, uint32_t len16)
86 {
87         device_t dev;
88 	uint32_t i = 0;
89 	uint16_t *buf;
90 
91         dev = ha->pci_dev;
92 	buf = dbuf16;
93 
94 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
95 
96 	while (len16 >= 8) {
97 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
98 			" 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
99 			buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
100 		i += 16;
101 		len16 -= 8;
102 		buf += 8;
103 	}
104 	switch (len16) {
105 	case 1:
106 		device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
107 		break;
108 	case 2:
109 		device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
110 		break;
111 	case 3:
112 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
113 			i, buf[0], buf[1], buf[2]);
114 		break;
115 	case 4:
116 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
117 			buf[0], buf[1], buf[2], buf[3]);
118 		break;
119 	case 5:
120 		device_printf(dev,"0x%08x:"
121 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
122 			buf[0], buf[1], buf[2], buf[3], buf[4]);
123 		break;
124 	case 6:
125 		device_printf(dev,"0x%08x:"
126 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
127 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
128 		break;
129 	case 7:
130 		device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
131 			" 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
132 			buf[2], buf[3], buf[4], buf[5], buf[6]);
133 		break;
134 	default:
135 		break;
136 	}
137 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
138 }
139 
140 /*
141  * Name: ql_dump_buf8
142  * Function: dumps a buffer as bytes
143  */
144 void ql_dump_buf8(qla_host_t *ha, const char *msg, void *dbuf, uint32_t len)
145 {
146         device_t dev;
147 	uint32_t i = 0;
148 	uint8_t *buf;
149 
150         dev = ha->pci_dev;
151 	buf = dbuf;
152 
153 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
154 
155 	while (len >= 16) {
156 		device_printf(dev,"0x%08x:"
157 			" %02x %02x %02x %02x %02x %02x %02x %02x"
158 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
159 			buf[0], buf[1], buf[2], buf[3],
160 			buf[4], buf[5], buf[6], buf[7],
161 			buf[8], buf[9], buf[10], buf[11],
162 			buf[12], buf[13], buf[14], buf[15]);
163 		i += 16;
164 		len -= 16;
165 		buf += 16;
166 	}
167 	switch (len) {
168 	case 1:
169 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
170 		break;
171 	case 2:
172 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
173 		break;
174 	case 3:
175 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
176 			i, buf[0], buf[1], buf[2]);
177 		break;
178 	case 4:
179 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
180 			buf[0], buf[1], buf[2], buf[3]);
181 		break;
182 	case 5:
183 		device_printf(dev,"0x%08x:"
184 			" %02x %02x %02x %02x %02x\n", i,
185 			buf[0], buf[1], buf[2], buf[3], buf[4]);
186 		break;
187 	case 6:
188 		device_printf(dev,"0x%08x:"
189 			" %02x %02x %02x %02x %02x %02x\n", i,
190 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
191 		break;
192 	case 7:
193 		device_printf(dev,"0x%08x:"
194 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
195 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
196 		break;
197 	case 8:
198 		device_printf(dev,"0x%08x:"
199 			" %02x %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 			buf[7]);
202 		break;
203 	case 9:
204 		device_printf(dev,"0x%08x:"
205 			" %02x %02x %02x %02x %02x %02x %02x %02x"
206 			" %02x\n", i,
207 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
208 			buf[7], buf[8]);
209 		break;
210 	case 10:
211 		device_printf(dev,"0x%08x:"
212 			" %02x %02x %02x %02x %02x %02x %02x %02x"
213 			" %02x %02x\n", i,
214 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
215 			buf[7], buf[8], buf[9]);
216 		break;
217 	case 11:
218 		device_printf(dev,"0x%08x:"
219 			" %02x %02x %02x %02x %02x %02x %02x %02x"
220 			" %02x %02x %02x\n", i,
221 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
222 			buf[7], buf[8], buf[9], buf[10]);
223 		break;
224 	case 12:
225 		device_printf(dev,"0x%08x:"
226 			" %02x %02x %02x %02x %02x %02x %02x %02x"
227 			" %02x %02x %02x %02x\n", i,
228 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
229 			buf[7], buf[8], buf[9], buf[10], buf[11]);
230 		break;
231 	case 13:
232 		device_printf(dev,"0x%08x:"
233 			" %02x %02x %02x %02x %02x %02x %02x %02x"
234 			" %02x %02x %02x %02x %02x\n", i,
235 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
236 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
237 		break;
238 	case 14:
239 		device_printf(dev,"0x%08x:"
240 			" %02x %02x %02x %02x %02x %02x %02x %02x"
241 			" %02x %02x %02x %02x %02x %02x\n", i,
242 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
243 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
244 			buf[13]);
245 		break;
246 	case 15:
247 		device_printf(dev,"0x%08x:"
248 			" %02x %02x %02x %02x %02x %02x %02x %02x"
249 			" %02x %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], buf[14]);
253 		break;
254 	default:
255 		break;
256 	}
257 
258 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
259 }
260 
261