xref: /freebsd-src/sys/dev/qlxgbe/ql_dbg.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
435291c22SDavid C Somayajulu  * Copyright (c) 2013-2016 Qlogic Corporation
5f10a77bbSDavid C Somayajulu  * All rights reserved.
6f10a77bbSDavid C Somayajulu  *
7f10a77bbSDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
8f10a77bbSDavid C Somayajulu  *  modification, are permitted provided that the following conditions
9f10a77bbSDavid C Somayajulu  *  are met:
10f10a77bbSDavid C Somayajulu  *
11f10a77bbSDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
12f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
13f10a77bbSDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
14f10a77bbSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
15f10a77bbSDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
16f10a77bbSDavid C Somayajulu  *
17f10a77bbSDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18f10a77bbSDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19f10a77bbSDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20f10a77bbSDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21f10a77bbSDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22f10a77bbSDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23f10a77bbSDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24f10a77bbSDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25f10a77bbSDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26f10a77bbSDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27f10a77bbSDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
28f10a77bbSDavid C Somayajulu  */
29f10a77bbSDavid C Somayajulu /*
30f10a77bbSDavid C Somayajulu  * File : ql_dbg.c
31f10a77bbSDavid C Somayajulu  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32f10a77bbSDavid C Somayajulu  */
33f10a77bbSDavid C Somayajulu #include <sys/cdefs.h>
34f10a77bbSDavid C Somayajulu #include "ql_os.h"
35f10a77bbSDavid C Somayajulu #include "ql_hw.h"
36f10a77bbSDavid C Somayajulu #include "ql_def.h"
37f10a77bbSDavid C Somayajulu #include "ql_inline.h"
38f10a77bbSDavid C Somayajulu #include "ql_ver.h"
39f10a77bbSDavid C Somayajulu #include "ql_glbl.h"
40f10a77bbSDavid C Somayajulu #include "ql_dbg.h"
41f10a77bbSDavid C Somayajulu 
42f10a77bbSDavid C Somayajulu /*
43f10a77bbSDavid C Somayajulu  * Name: ql_dump_buf32
44f10a77bbSDavid C Somayajulu  * Function: dumps a buffer as 32 bit words
45f10a77bbSDavid C Somayajulu  */
ql_dump_buf32(qla_host_t * ha,const char * msg,void * dbuf32,uint32_t len32)46f10a77bbSDavid C Somayajulu void ql_dump_buf32(qla_host_t *ha, const char *msg, void *dbuf32, uint32_t len32)
47f10a77bbSDavid C Somayajulu {
48f10a77bbSDavid C Somayajulu         device_t dev;
49f10a77bbSDavid C Somayajulu 	uint32_t i = 0;
50f10a77bbSDavid C Somayajulu 	uint32_t *buf;
51f10a77bbSDavid C Somayajulu 
52f10a77bbSDavid C Somayajulu         dev = ha->pci_dev;
53f10a77bbSDavid C Somayajulu 	buf = dbuf32;
54f10a77bbSDavid C Somayajulu 
55f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
56f10a77bbSDavid C Somayajulu 
57f10a77bbSDavid C Somayajulu 	while (len32 >= 4) {
58f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
59f10a77bbSDavid C Somayajulu 			i, buf[0], buf[1], buf[2], buf[3]);
60f10a77bbSDavid C Somayajulu 		i += 4 * 4;
61f10a77bbSDavid C Somayajulu 		len32 -= 4;
62f10a77bbSDavid C Somayajulu 		buf += 4;
63f10a77bbSDavid C Somayajulu 	}
64f10a77bbSDavid C Somayajulu 	switch (len32) {
65f10a77bbSDavid C Somayajulu 	case 1:
66f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
67f10a77bbSDavid C Somayajulu 		break;
68f10a77bbSDavid C Somayajulu 	case 2:
69f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
70f10a77bbSDavid C Somayajulu 		break;
71f10a77bbSDavid C Somayajulu 	case 3:
72f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
73f10a77bbSDavid C Somayajulu 			i, buf[0], buf[1], buf[2]);
74f10a77bbSDavid C Somayajulu 		break;
75f10a77bbSDavid C Somayajulu 	default:
76f10a77bbSDavid C Somayajulu 		break;
77f10a77bbSDavid C Somayajulu 	}
78f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
79f10a77bbSDavid C Somayajulu }
80f10a77bbSDavid C Somayajulu 
81f10a77bbSDavid C Somayajulu /*
82f10a77bbSDavid C Somayajulu  * Name: ql_dump_buf16
83f10a77bbSDavid C Somayajulu  * Function: dumps a buffer as 16 bit words
84f10a77bbSDavid C Somayajulu  */
ql_dump_buf16(qla_host_t * ha,const char * msg,void * dbuf16,uint32_t len16)85f10a77bbSDavid C Somayajulu void ql_dump_buf16(qla_host_t *ha, const char *msg, void *dbuf16, uint32_t len16)
86f10a77bbSDavid C Somayajulu {
87f10a77bbSDavid C Somayajulu         device_t dev;
88f10a77bbSDavid C Somayajulu 	uint32_t i = 0;
89f10a77bbSDavid C Somayajulu 	uint16_t *buf;
90f10a77bbSDavid C Somayajulu 
91f10a77bbSDavid C Somayajulu         dev = ha->pci_dev;
92f10a77bbSDavid C Somayajulu 	buf = dbuf16;
93f10a77bbSDavid C Somayajulu 
94f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
95f10a77bbSDavid C Somayajulu 
96f10a77bbSDavid C Somayajulu 	while (len16 >= 8) {
97f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
98f10a77bbSDavid C Somayajulu 			" 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
99f10a77bbSDavid C Somayajulu 			buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
100f10a77bbSDavid C Somayajulu 		i += 16;
101f10a77bbSDavid C Somayajulu 		len16 -= 8;
102f10a77bbSDavid C Somayajulu 		buf += 8;
103f10a77bbSDavid C Somayajulu 	}
104f10a77bbSDavid C Somayajulu 	switch (len16) {
105f10a77bbSDavid C Somayajulu 	case 1:
106f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
107f10a77bbSDavid C Somayajulu 		break;
108f10a77bbSDavid C Somayajulu 	case 2:
109f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
110f10a77bbSDavid C Somayajulu 		break;
111f10a77bbSDavid C Somayajulu 	case 3:
112f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
113f10a77bbSDavid C Somayajulu 			i, buf[0], buf[1], buf[2]);
114f10a77bbSDavid C Somayajulu 		break;
115f10a77bbSDavid C Somayajulu 	case 4:
116f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
117f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3]);
118f10a77bbSDavid C Somayajulu 		break;
119f10a77bbSDavid C Somayajulu 	case 5:
120f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
121f10a77bbSDavid C Somayajulu 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
122f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4]);
123f10a77bbSDavid C Somayajulu 		break;
124f10a77bbSDavid C Somayajulu 	case 6:
125f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
126f10a77bbSDavid C Somayajulu 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
127f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
128f10a77bbSDavid C Somayajulu 		break;
129f10a77bbSDavid C Somayajulu 	case 7:
130f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
131f10a77bbSDavid C Somayajulu 			" 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
132f10a77bbSDavid C Somayajulu 			buf[2], buf[3], buf[4], buf[5], buf[6]);
133f10a77bbSDavid C Somayajulu 		break;
134f10a77bbSDavid C Somayajulu 	default:
135f10a77bbSDavid C Somayajulu 		break;
136f10a77bbSDavid C Somayajulu 	}
137f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
138f10a77bbSDavid C Somayajulu }
139f10a77bbSDavid C Somayajulu 
140f10a77bbSDavid C Somayajulu /*
141f10a77bbSDavid C Somayajulu  * Name: ql_dump_buf8
142f10a77bbSDavid C Somayajulu  * Function: dumps a buffer as bytes
143f10a77bbSDavid C Somayajulu  */
ql_dump_buf8(qla_host_t * ha,const char * msg,void * dbuf,uint32_t len)144f10a77bbSDavid C Somayajulu void ql_dump_buf8(qla_host_t *ha, const char *msg, void *dbuf, uint32_t len)
145f10a77bbSDavid C Somayajulu {
146f10a77bbSDavid C Somayajulu         device_t dev;
147f10a77bbSDavid C Somayajulu 	uint32_t i = 0;
148f10a77bbSDavid C Somayajulu 	uint8_t *buf;
149f10a77bbSDavid C Somayajulu 
150f10a77bbSDavid C Somayajulu         dev = ha->pci_dev;
151f10a77bbSDavid C Somayajulu 	buf = dbuf;
152f10a77bbSDavid C Somayajulu 
153f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
154f10a77bbSDavid C Somayajulu 
155f10a77bbSDavid C Somayajulu 	while (len >= 16) {
156f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
157f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
158f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
159f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3],
160f10a77bbSDavid C Somayajulu 			buf[4], buf[5], buf[6], buf[7],
161f10a77bbSDavid C Somayajulu 			buf[8], buf[9], buf[10], buf[11],
162f10a77bbSDavid C Somayajulu 			buf[12], buf[13], buf[14], buf[15]);
163f10a77bbSDavid C Somayajulu 		i += 16;
164f10a77bbSDavid C Somayajulu 		len -= 16;
165f10a77bbSDavid C Somayajulu 		buf += 16;
166f10a77bbSDavid C Somayajulu 	}
167f10a77bbSDavid C Somayajulu 	switch (len) {
168f10a77bbSDavid C Somayajulu 	case 1:
169f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
170f10a77bbSDavid C Somayajulu 		break;
171f10a77bbSDavid C Somayajulu 	case 2:
172f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
173f10a77bbSDavid C Somayajulu 		break;
174f10a77bbSDavid C Somayajulu 	case 3:
175f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
176f10a77bbSDavid C Somayajulu 			i, buf[0], buf[1], buf[2]);
177f10a77bbSDavid C Somayajulu 		break;
178f10a77bbSDavid C Somayajulu 	case 4:
179f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
180f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3]);
181f10a77bbSDavid C Somayajulu 		break;
182f10a77bbSDavid C Somayajulu 	case 5:
183f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
184f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x\n", i,
185f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4]);
186f10a77bbSDavid C Somayajulu 		break;
187f10a77bbSDavid C Somayajulu 	case 6:
188f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
189f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x\n", i,
190f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
191f10a77bbSDavid C Somayajulu 		break;
192f10a77bbSDavid C Somayajulu 	case 7:
193f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
194f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
195f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
196f10a77bbSDavid C Somayajulu 		break;
197f10a77bbSDavid C Somayajulu 	case 8:
198f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
199f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
200f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
201f10a77bbSDavid C Somayajulu 			buf[7]);
202f10a77bbSDavid C Somayajulu 		break;
203f10a77bbSDavid C Somayajulu 	case 9:
204f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
205f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
206f10a77bbSDavid C Somayajulu 			" %02x\n", i,
207f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
208f10a77bbSDavid C Somayajulu 			buf[7], buf[8]);
209f10a77bbSDavid C Somayajulu 		break;
210f10a77bbSDavid C Somayajulu 	case 10:
211f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
212f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
213f10a77bbSDavid C Somayajulu 			" %02x %02x\n", i,
214f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
215f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9]);
216f10a77bbSDavid C Somayajulu 		break;
217f10a77bbSDavid C Somayajulu 	case 11:
218f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
219f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
220f10a77bbSDavid C Somayajulu 			" %02x %02x %02x\n", i,
221f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
222f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9], buf[10]);
223f10a77bbSDavid C Somayajulu 		break;
224f10a77bbSDavid C Somayajulu 	case 12:
225f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
226f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
227f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x\n", i,
228f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
229f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9], buf[10], buf[11]);
230f10a77bbSDavid C Somayajulu 		break;
231f10a77bbSDavid C Somayajulu 	case 13:
232f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
233f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
234f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x\n", i,
235f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
236f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
237f10a77bbSDavid C Somayajulu 		break;
238f10a77bbSDavid C Somayajulu 	case 14:
239f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
240f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
241f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x\n", i,
242f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
243f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
244f10a77bbSDavid C Somayajulu 			buf[13]);
245f10a77bbSDavid C Somayajulu 		break;
246f10a77bbSDavid C Somayajulu 	case 15:
247f10a77bbSDavid C Somayajulu 		device_printf(dev,"0x%08x:"
248f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x %02x"
249f10a77bbSDavid C Somayajulu 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
250f10a77bbSDavid C Somayajulu 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
251f10a77bbSDavid C Somayajulu 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
252f10a77bbSDavid C Somayajulu 			buf[13], buf[14]);
253f10a77bbSDavid C Somayajulu 		break;
254f10a77bbSDavid C Somayajulu 	default:
255f10a77bbSDavid C Somayajulu 		break;
256f10a77bbSDavid C Somayajulu 	}
257f10a77bbSDavid C Somayajulu 
258f10a77bbSDavid C Somayajulu 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
259f10a77bbSDavid C Somayajulu }
260