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