1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4711bcba0SDavid C Somayajulu * Copyright (c) 2013-2014 Qlogic Corporation
5711bcba0SDavid C Somayajulu * All rights reserved.
6711bcba0SDavid C Somayajulu *
7711bcba0SDavid C Somayajulu * Redistribution and use in source and binary forms, with or without
8711bcba0SDavid C Somayajulu * modification, are permitted provided that the following conditions
9711bcba0SDavid C Somayajulu * are met:
10711bcba0SDavid C Somayajulu *
11711bcba0SDavid C Somayajulu * 1. Redistributions of source code must retain the above copyright
12711bcba0SDavid C Somayajulu * notice, this list of conditions and the following disclaimer.
13711bcba0SDavid C Somayajulu * 2. Redistributions in binary form must reproduce the above copyright
14711bcba0SDavid C Somayajulu * notice, this list of conditions and the following disclaimer in the
15711bcba0SDavid C Somayajulu * documentation and/or other materials provided with the distribution.
16711bcba0SDavid C Somayajulu *
17711bcba0SDavid C Somayajulu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18711bcba0SDavid C Somayajulu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19711bcba0SDavid C Somayajulu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20711bcba0SDavid C Somayajulu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21711bcba0SDavid C Somayajulu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22711bcba0SDavid C Somayajulu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23711bcba0SDavid C Somayajulu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24711bcba0SDavid C Somayajulu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25711bcba0SDavid C Somayajulu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26711bcba0SDavid C Somayajulu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27711bcba0SDavid C Somayajulu * POSSIBILITY OF SUCH DAMAGE.
28711bcba0SDavid C Somayajulu */
29711bcba0SDavid C Somayajulu /*
30711bcba0SDavid C Somayajulu * File : qls_dbg.c
31711bcba0SDavid C Somayajulu * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32711bcba0SDavid C Somayajulu */
33711bcba0SDavid C Somayajulu #include <sys/cdefs.h>
34711bcba0SDavid C Somayajulu #include "qls_os.h"
35711bcba0SDavid C Somayajulu #include "qls_hw.h"
36711bcba0SDavid C Somayajulu #include "qls_def.h"
37711bcba0SDavid C Somayajulu #include "qls_inline.h"
38711bcba0SDavid C Somayajulu #include "qls_ver.h"
39711bcba0SDavid C Somayajulu #include "qls_glbl.h"
40711bcba0SDavid C Somayajulu #include "qls_dbg.h"
41711bcba0SDavid C Somayajulu
42711bcba0SDavid C Somayajulu uint32_t qls_dbg_level = 0 ;
43711bcba0SDavid C Somayajulu /*
44711bcba0SDavid C Somayajulu * Name: qls_dump_buf32
45711bcba0SDavid C Somayajulu * Function: dumps a buffer as 32 bit words
46711bcba0SDavid C Somayajulu */
47711bcba0SDavid C Somayajulu void
qls_dump_buf32(qla_host_t * ha,const char * msg,void * dbuf32,uint32_t len32)48711bcba0SDavid C Somayajulu qls_dump_buf32(qla_host_t *ha, const char *msg, void *dbuf32, uint32_t len32)
49711bcba0SDavid C Somayajulu {
50711bcba0SDavid C Somayajulu device_t dev;
51711bcba0SDavid C Somayajulu uint32_t i = 0;
52711bcba0SDavid C Somayajulu uint32_t *buf;
53711bcba0SDavid C Somayajulu
54711bcba0SDavid C Somayajulu dev = ha->pci_dev;
55711bcba0SDavid C Somayajulu buf = dbuf32;
56711bcba0SDavid C Somayajulu
57711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s dump start\n", __func__, msg);
58711bcba0SDavid C Somayajulu
59711bcba0SDavid C Somayajulu while (len32 >= 4) {
60711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:\t0x%08x, 0x%08x, 0x%08x, 0x%08x,\n",
61711bcba0SDavid C Somayajulu i, buf[0], buf[1], buf[2], buf[3]);
62711bcba0SDavid C Somayajulu i += 4 * 4;
63711bcba0SDavid C Somayajulu len32 -= 4;
64711bcba0SDavid C Somayajulu buf += 4;
65711bcba0SDavid C Somayajulu }
66711bcba0SDavid C Somayajulu switch (len32) {
67711bcba0SDavid C Somayajulu case 1:
68711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
69711bcba0SDavid C Somayajulu break;
70711bcba0SDavid C Somayajulu case 2:
71711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
72711bcba0SDavid C Somayajulu break;
73711bcba0SDavid C Somayajulu case 3:
74711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
75711bcba0SDavid C Somayajulu i, buf[0], buf[1], buf[2]);
76711bcba0SDavid C Somayajulu break;
77711bcba0SDavid C Somayajulu default:
78711bcba0SDavid C Somayajulu break;
79711bcba0SDavid C Somayajulu }
80711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s dump end\n", __func__, msg);
81711bcba0SDavid C Somayajulu
82711bcba0SDavid C Somayajulu return;
83711bcba0SDavid C Somayajulu }
84711bcba0SDavid C Somayajulu
85711bcba0SDavid C Somayajulu /*
86711bcba0SDavid C Somayajulu * Name: qls_dump_buf16
87711bcba0SDavid C Somayajulu * Function: dumps a buffer as 16 bit words
88711bcba0SDavid C Somayajulu */
89711bcba0SDavid C Somayajulu void
qls_dump_buf16(qla_host_t * ha,const char * msg,void * dbuf16,uint32_t len16)90711bcba0SDavid C Somayajulu qls_dump_buf16(qla_host_t *ha, const char *msg, void *dbuf16, uint32_t len16)
91711bcba0SDavid C Somayajulu {
92711bcba0SDavid C Somayajulu device_t dev;
93711bcba0SDavid C Somayajulu uint32_t i = 0;
94711bcba0SDavid C Somayajulu uint16_t *buf;
95711bcba0SDavid C Somayajulu
96711bcba0SDavid C Somayajulu dev = ha->pci_dev;
97711bcba0SDavid C Somayajulu buf = dbuf16;
98711bcba0SDavid C Somayajulu
99711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s dump start\n", __func__, msg);
100711bcba0SDavid C Somayajulu
101711bcba0SDavid C Somayajulu while (len16 >= 8) {
102711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
103711bcba0SDavid C Somayajulu " 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
104711bcba0SDavid C Somayajulu buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
105711bcba0SDavid C Somayajulu i += 16;
106711bcba0SDavid C Somayajulu len16 -= 8;
107711bcba0SDavid C Somayajulu buf += 8;
108711bcba0SDavid C Somayajulu }
109711bcba0SDavid C Somayajulu switch (len16) {
110711bcba0SDavid C Somayajulu case 1:
111711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
112711bcba0SDavid C Somayajulu break;
113711bcba0SDavid C Somayajulu case 2:
114711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
115711bcba0SDavid C Somayajulu break;
116711bcba0SDavid C Somayajulu case 3:
117711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
118711bcba0SDavid C Somayajulu i, buf[0], buf[1], buf[2]);
119711bcba0SDavid C Somayajulu break;
120711bcba0SDavid C Somayajulu case 4:
121711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
122711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3]);
123711bcba0SDavid C Somayajulu break;
124711bcba0SDavid C Somayajulu case 5:
125711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
126711bcba0SDavid C Somayajulu " 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
127711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4]);
128711bcba0SDavid C Somayajulu break;
129711bcba0SDavid C Somayajulu case 6:
130711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
131711bcba0SDavid C Somayajulu " 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
132711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
133711bcba0SDavid C Somayajulu break;
134711bcba0SDavid C Somayajulu case 7:
135711bcba0SDavid C Somayajulu device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
136711bcba0SDavid C Somayajulu " 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
137711bcba0SDavid C Somayajulu buf[2], buf[3], buf[4], buf[5], buf[6]);
138711bcba0SDavid C Somayajulu break;
139711bcba0SDavid C Somayajulu default:
140711bcba0SDavid C Somayajulu break;
141711bcba0SDavid C Somayajulu }
142711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s dump end\n", __func__, msg);
143711bcba0SDavid C Somayajulu
144711bcba0SDavid C Somayajulu return;
145711bcba0SDavid C Somayajulu }
146711bcba0SDavid C Somayajulu
147711bcba0SDavid C Somayajulu /*
148711bcba0SDavid C Somayajulu * Name: qls_dump_buf8
149711bcba0SDavid C Somayajulu * Function: dumps a buffer as bytes
150711bcba0SDavid C Somayajulu */
151711bcba0SDavid C Somayajulu void
qls_dump_buf8(qla_host_t * ha,const char * msg,void * dbuf,uint32_t len)152711bcba0SDavid C Somayajulu qls_dump_buf8(qla_host_t *ha, const char *msg, void *dbuf, uint32_t len)
153711bcba0SDavid C Somayajulu {
154711bcba0SDavid C Somayajulu device_t dev;
155711bcba0SDavid C Somayajulu uint32_t i = 0;
156711bcba0SDavid C Somayajulu uint8_t *buf;
157711bcba0SDavid C Somayajulu
158711bcba0SDavid C Somayajulu dev = ha->pci_dev;
159711bcba0SDavid C Somayajulu buf = dbuf;
160711bcba0SDavid C Somayajulu
161711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
162711bcba0SDavid C Somayajulu
163711bcba0SDavid C Somayajulu while (len >= 16) {
164711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
165711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
166711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
167711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3],
168711bcba0SDavid C Somayajulu buf[4], buf[5], buf[6], buf[7],
169711bcba0SDavid C Somayajulu buf[8], buf[9], buf[10], buf[11],
170711bcba0SDavid C Somayajulu buf[12], buf[13], buf[14], buf[15]);
171711bcba0SDavid C Somayajulu i += 16;
172711bcba0SDavid C Somayajulu len -= 16;
173711bcba0SDavid C Somayajulu buf += 16;
174711bcba0SDavid C Somayajulu }
175711bcba0SDavid C Somayajulu switch (len) {
176711bcba0SDavid C Somayajulu case 1:
177711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
178711bcba0SDavid C Somayajulu break;
179711bcba0SDavid C Somayajulu case 2:
180711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
181711bcba0SDavid C Somayajulu break;
182711bcba0SDavid C Somayajulu case 3:
183711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: %02x %02x %02x\n",
184711bcba0SDavid C Somayajulu i, buf[0], buf[1], buf[2]);
185711bcba0SDavid C Somayajulu break;
186711bcba0SDavid C Somayajulu case 4:
187711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
188711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3]);
189711bcba0SDavid C Somayajulu break;
190711bcba0SDavid C Somayajulu case 5:
191711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
192711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x\n", i,
193711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4]);
194711bcba0SDavid C Somayajulu break;
195711bcba0SDavid C Somayajulu case 6:
196711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
197711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x\n", i,
198711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
199711bcba0SDavid C Somayajulu break;
200711bcba0SDavid C Somayajulu case 7:
201711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
202711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x\n", i,
203711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
204711bcba0SDavid C Somayajulu break;
205711bcba0SDavid C Somayajulu case 8:
206711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
207711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
208711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
209711bcba0SDavid C Somayajulu buf[7]);
210711bcba0SDavid C Somayajulu break;
211711bcba0SDavid C Somayajulu case 9:
212711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
213711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
214711bcba0SDavid C Somayajulu " %02x\n", i,
215711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
216711bcba0SDavid C Somayajulu buf[7], buf[8]);
217711bcba0SDavid C Somayajulu break;
218711bcba0SDavid C Somayajulu case 10:
219711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
220711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
221711bcba0SDavid C Somayajulu " %02x %02x\n", i,
222711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
223711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9]);
224711bcba0SDavid C Somayajulu break;
225711bcba0SDavid C Somayajulu case 11:
226711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
227711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
228711bcba0SDavid C Somayajulu " %02x %02x %02x\n", i,
229711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
230711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9], buf[10]);
231711bcba0SDavid C Somayajulu break;
232711bcba0SDavid C Somayajulu case 12:
233711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
234711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
235711bcba0SDavid C Somayajulu " %02x %02x %02x %02x\n", i,
236711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
237711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9], buf[10], buf[11]);
238711bcba0SDavid C Somayajulu break;
239711bcba0SDavid C Somayajulu case 13:
240711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
241711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
242711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x\n", i,
243711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
244711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
245711bcba0SDavid C Somayajulu break;
246711bcba0SDavid C Somayajulu case 14:
247711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
248711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
249711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x\n", i,
250711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
251711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
252711bcba0SDavid C Somayajulu buf[13]);
253711bcba0SDavid C Somayajulu break;
254711bcba0SDavid C Somayajulu case 15:
255711bcba0SDavid C Somayajulu device_printf(dev,"0x%08x:"
256711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x %02x"
257711bcba0SDavid C Somayajulu " %02x %02x %02x %02x %02x %02x %02x\n", i,
258711bcba0SDavid C Somayajulu buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
259711bcba0SDavid C Somayajulu buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
260711bcba0SDavid C Somayajulu buf[13], buf[14]);
261711bcba0SDavid C Somayajulu break;
262711bcba0SDavid C Somayajulu default:
263711bcba0SDavid C Somayajulu break;
264711bcba0SDavid C Somayajulu }
265711bcba0SDavid C Somayajulu
266711bcba0SDavid C Somayajulu device_printf(dev, "%s: %s dump end\n", __func__, msg);
267711bcba0SDavid C Somayajulu
268711bcba0SDavid C Somayajulu return;
269711bcba0SDavid C Somayajulu }
270711bcba0SDavid C Somayajulu
271711bcba0SDavid C Somayajulu void
qls_dump_cq(qla_host_t * ha)272711bcba0SDavid C Somayajulu qls_dump_cq(qla_host_t *ha)
273711bcba0SDavid C Somayajulu {
274711bcba0SDavid C Somayajulu qls_dump_buf32(ha, "cq_icb", ha->rx_ring[0].cq_icb_vaddr,
275711bcba0SDavid C Somayajulu (sizeof (q81_cq_icb_t) >> 2));
276711bcba0SDavid C Somayajulu
277711bcba0SDavid C Somayajulu device_printf(ha->pci_dev, "%s: lbq_addr_tbl_paddr %p\n", __func__,
278711bcba0SDavid C Somayajulu (void *)ha->rx_ring[0].lbq_addr_tbl_paddr);
279711bcba0SDavid C Somayajulu
280711bcba0SDavid C Somayajulu qls_dump_buf32(ha, "lbq_addr_tbl", ha->rx_ring[0].lbq_addr_tbl_vaddr,
281711bcba0SDavid C Somayajulu (PAGE_SIZE >> 2));
282711bcba0SDavid C Somayajulu
283711bcba0SDavid C Somayajulu device_printf(ha->pci_dev, "%s: lbq_paddr %p\n", __func__,
284711bcba0SDavid C Somayajulu (void *)ha->rx_ring[0].lbq_paddr);
285711bcba0SDavid C Somayajulu
286711bcba0SDavid C Somayajulu qls_dump_buf32(ha, "lbq", ha->rx_ring[0].lbq_vaddr,
287711bcba0SDavid C Somayajulu (QLA_LBQ_SIZE >> 2));
288711bcba0SDavid C Somayajulu
289711bcba0SDavid C Somayajulu device_printf(ha->pci_dev, "%s: sbq_addr_tbl_paddr %p\n", __func__,
290711bcba0SDavid C Somayajulu (void *)ha->rx_ring[0].sbq_addr_tbl_paddr);
291711bcba0SDavid C Somayajulu
292711bcba0SDavid C Somayajulu qls_dump_buf32(ha, "sbq_addr_tbl", ha->rx_ring[0].sbq_addr_tbl_vaddr,
293711bcba0SDavid C Somayajulu (PAGE_SIZE >> 2));
294711bcba0SDavid C Somayajulu
295711bcba0SDavid C Somayajulu device_printf(ha->pci_dev, "%s: sbq_paddr %p\n", __func__,
296711bcba0SDavid C Somayajulu (void *)ha->rx_ring[0].sbq_paddr);
297711bcba0SDavid C Somayajulu
298711bcba0SDavid C Somayajulu qls_dump_buf32(ha, "sbq", ha->rx_ring[0].sbq_vaddr,
299711bcba0SDavid C Somayajulu (QLA_SBQ_SIZE >> 2) );
300711bcba0SDavid C Somayajulu
301711bcba0SDavid C Somayajulu device_printf(ha->pci_dev, "%s: lb_paddr %p\n", __func__,
302711bcba0SDavid C Somayajulu (void *)ha->rx_ring[0].lb_paddr);
303711bcba0SDavid C Somayajulu
304711bcba0SDavid C Somayajulu return;
305711bcba0SDavid C Somayajulu }
306