1718cf2ccSPedro F. Giffuni /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4088fc971SDavid C Somayajulu * Copyright (c) 2011-2013 Qlogic Corporation
50bc7cf6fSBjoern A. Zeeb * All rights reserved.
60bc7cf6fSBjoern A. Zeeb *
70bc7cf6fSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without
80bc7cf6fSBjoern A. Zeeb * modification, are permitted provided that the following conditions
90bc7cf6fSBjoern A. Zeeb * are met:
100bc7cf6fSBjoern A. Zeeb *
110bc7cf6fSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright
120bc7cf6fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer.
130bc7cf6fSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright
140bc7cf6fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the
150bc7cf6fSBjoern A. Zeeb * documentation and/or other materials provided with the distribution.
160bc7cf6fSBjoern A. Zeeb *
170bc7cf6fSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
180bc7cf6fSBjoern A. Zeeb * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190bc7cf6fSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200bc7cf6fSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
210bc7cf6fSBjoern A. Zeeb * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220bc7cf6fSBjoern A. Zeeb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230bc7cf6fSBjoern A. Zeeb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240bc7cf6fSBjoern A. Zeeb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
250bc7cf6fSBjoern A. Zeeb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260bc7cf6fSBjoern A. Zeeb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270bc7cf6fSBjoern A. Zeeb * POSSIBILITY OF SUCH DAMAGE.
280bc7cf6fSBjoern A. Zeeb */
290bc7cf6fSBjoern A. Zeeb /*
300bc7cf6fSBjoern A. Zeeb * File : qla_dbg.c
310bc7cf6fSBjoern A. Zeeb * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
320bc7cf6fSBjoern A. Zeeb */
330bc7cf6fSBjoern A. Zeeb
340bc7cf6fSBjoern A. Zeeb #include <sys/cdefs.h>
350bc7cf6fSBjoern A. Zeeb #include "qla_os.h"
360bc7cf6fSBjoern A. Zeeb #include "qla_reg.h"
370bc7cf6fSBjoern A. Zeeb #include "qla_hw.h"
380bc7cf6fSBjoern A. Zeeb #include "qla_def.h"
390bc7cf6fSBjoern A. Zeeb #include "qla_inline.h"
400bc7cf6fSBjoern A. Zeeb #include "qla_ver.h"
410bc7cf6fSBjoern A. Zeeb #include "qla_glbl.h"
420bc7cf6fSBjoern A. Zeeb #include "qla_dbg.h"
430bc7cf6fSBjoern A. Zeeb
440bc7cf6fSBjoern A. Zeeb uint32_t dbg_level = 0 ;
450bc7cf6fSBjoern A. Zeeb /*
460bc7cf6fSBjoern A. Zeeb * Name: qla_dump_buf32
470bc7cf6fSBjoern A. Zeeb * Function: dumps a buffer as 32 bit words
480bc7cf6fSBjoern A. Zeeb */
qla_dump_buf32(qla_host_t * ha,char * msg,void * dbuf32,uint32_t len32)490bc7cf6fSBjoern A. Zeeb void qla_dump_buf32(qla_host_t *ha, char *msg, void *dbuf32, uint32_t len32)
500bc7cf6fSBjoern A. Zeeb {
510bc7cf6fSBjoern A. Zeeb device_t dev;
520bc7cf6fSBjoern A. Zeeb uint32_t i = 0;
530bc7cf6fSBjoern A. Zeeb uint32_t *buf;
540bc7cf6fSBjoern A. Zeeb
550bc7cf6fSBjoern A. Zeeb dev = ha->pci_dev;
560bc7cf6fSBjoern A. Zeeb buf = dbuf32;
570bc7cf6fSBjoern A. Zeeb
580bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s dump start\n", __func__, msg);
590bc7cf6fSBjoern A. Zeeb
600bc7cf6fSBjoern A. Zeeb while (len32 >= 4) {
610bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
620bc7cf6fSBjoern A. Zeeb i, buf[0], buf[1], buf[2], buf[3]);
630bc7cf6fSBjoern A. Zeeb i += 4 * 4;
640bc7cf6fSBjoern A. Zeeb len32 -= 4;
650bc7cf6fSBjoern A. Zeeb buf += 4;
660bc7cf6fSBjoern A. Zeeb }
670bc7cf6fSBjoern A. Zeeb switch (len32) {
680bc7cf6fSBjoern A. Zeeb case 1:
690bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
700bc7cf6fSBjoern A. Zeeb break;
710bc7cf6fSBjoern A. Zeeb case 2:
720bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
730bc7cf6fSBjoern A. Zeeb break;
740bc7cf6fSBjoern A. Zeeb case 3:
750bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
760bc7cf6fSBjoern A. Zeeb i, buf[0], buf[1], buf[2]);
770bc7cf6fSBjoern A. Zeeb break;
780bc7cf6fSBjoern A. Zeeb default:
790bc7cf6fSBjoern A. Zeeb break;
800bc7cf6fSBjoern A. Zeeb }
810bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s dump end\n", __func__, msg);
820bc7cf6fSBjoern A. Zeeb }
830bc7cf6fSBjoern A. Zeeb
840bc7cf6fSBjoern A. Zeeb /*
850bc7cf6fSBjoern A. Zeeb * Name: qla_dump_buf16
860bc7cf6fSBjoern A. Zeeb * Function: dumps a buffer as 16 bit words
870bc7cf6fSBjoern A. Zeeb */
qla_dump_buf16(qla_host_t * ha,char * msg,void * dbuf16,uint32_t len16)880bc7cf6fSBjoern A. Zeeb void qla_dump_buf16(qla_host_t *ha, char *msg, void *dbuf16, uint32_t len16)
890bc7cf6fSBjoern A. Zeeb {
900bc7cf6fSBjoern A. Zeeb device_t dev;
910bc7cf6fSBjoern A. Zeeb uint32_t i = 0;
920bc7cf6fSBjoern A. Zeeb uint16_t *buf;
930bc7cf6fSBjoern A. Zeeb
940bc7cf6fSBjoern A. Zeeb dev = ha->pci_dev;
950bc7cf6fSBjoern A. Zeeb buf = dbuf16;
960bc7cf6fSBjoern A. Zeeb
970bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s dump start\n", __func__, msg);
980bc7cf6fSBjoern A. Zeeb
990bc7cf6fSBjoern A. Zeeb while (len16 >= 8) {
1000bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
1010bc7cf6fSBjoern A. Zeeb " 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
1020bc7cf6fSBjoern A. Zeeb buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
1030bc7cf6fSBjoern A. Zeeb i += 16;
1040bc7cf6fSBjoern A. Zeeb len16 -= 8;
1050bc7cf6fSBjoern A. Zeeb buf += 8;
1060bc7cf6fSBjoern A. Zeeb }
1070bc7cf6fSBjoern A. Zeeb switch (len16) {
1080bc7cf6fSBjoern A. Zeeb case 1:
1090bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
1100bc7cf6fSBjoern A. Zeeb break;
1110bc7cf6fSBjoern A. Zeeb case 2:
1120bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
1130bc7cf6fSBjoern A. Zeeb break;
1140bc7cf6fSBjoern A. Zeeb case 3:
1150bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
1160bc7cf6fSBjoern A. Zeeb i, buf[0], buf[1], buf[2]);
1170bc7cf6fSBjoern A. Zeeb break;
1180bc7cf6fSBjoern A. Zeeb case 4:
1190bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1200bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3]);
1210bc7cf6fSBjoern A. Zeeb break;
1220bc7cf6fSBjoern A. Zeeb case 5:
1230bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1240bc7cf6fSBjoern A. Zeeb " 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1250bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4]);
1260bc7cf6fSBjoern A. Zeeb break;
1270bc7cf6fSBjoern A. Zeeb case 6:
1280bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1290bc7cf6fSBjoern A. Zeeb " 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1300bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
1310bc7cf6fSBjoern A. Zeeb break;
1320bc7cf6fSBjoern A. Zeeb case 7:
1330bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
1340bc7cf6fSBjoern A. Zeeb " 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
1350bc7cf6fSBjoern A. Zeeb buf[2], buf[3], buf[4], buf[5], buf[6]);
1360bc7cf6fSBjoern A. Zeeb break;
1370bc7cf6fSBjoern A. Zeeb default:
1380bc7cf6fSBjoern A. Zeeb break;
1390bc7cf6fSBjoern A. Zeeb }
1400bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s dump end\n", __func__, msg);
1410bc7cf6fSBjoern A. Zeeb }
1420bc7cf6fSBjoern A. Zeeb
1430bc7cf6fSBjoern A. Zeeb /*
1440bc7cf6fSBjoern A. Zeeb * Name: qla_dump_buf8
1450bc7cf6fSBjoern A. Zeeb * Function: dumps a buffer as bytes
1460bc7cf6fSBjoern A. Zeeb */
qla_dump_buf8(qla_host_t * ha,char * msg,void * dbuf,uint32_t len)1470bc7cf6fSBjoern A. Zeeb void qla_dump_buf8(qla_host_t *ha, char *msg, void *dbuf, uint32_t len)
1480bc7cf6fSBjoern A. Zeeb {
1490bc7cf6fSBjoern A. Zeeb device_t dev;
1500bc7cf6fSBjoern A. Zeeb uint32_t i = 0;
1510bc7cf6fSBjoern A. Zeeb uint8_t *buf;
1520bc7cf6fSBjoern A. Zeeb
1530bc7cf6fSBjoern A. Zeeb dev = ha->pci_dev;
1540bc7cf6fSBjoern A. Zeeb buf = dbuf;
1550bc7cf6fSBjoern A. Zeeb
1560bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
1570bc7cf6fSBjoern A. Zeeb
1580bc7cf6fSBjoern A. Zeeb while (len >= 16) {
1590bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1600bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
1610bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
1620bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3],
1630bc7cf6fSBjoern A. Zeeb buf[4], buf[5], buf[6], buf[7],
1640bc7cf6fSBjoern A. Zeeb buf[8], buf[9], buf[10], buf[11],
1650bc7cf6fSBjoern A. Zeeb buf[12], buf[13], buf[14], buf[15]);
1660bc7cf6fSBjoern A. Zeeb i += 16;
1670bc7cf6fSBjoern A. Zeeb len -= 16;
1680bc7cf6fSBjoern A. Zeeb buf += 16;
1690bc7cf6fSBjoern A. Zeeb }
1700bc7cf6fSBjoern A. Zeeb switch (len) {
1710bc7cf6fSBjoern A. Zeeb case 1:
1720bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
1730bc7cf6fSBjoern A. Zeeb break;
1740bc7cf6fSBjoern A. Zeeb case 2:
1750bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
1760bc7cf6fSBjoern A. Zeeb break;
1770bc7cf6fSBjoern A. Zeeb case 3:
1780bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: %02x %02x %02x\n",
1790bc7cf6fSBjoern A. Zeeb i, buf[0], buf[1], buf[2]);
1800bc7cf6fSBjoern A. Zeeb break;
1810bc7cf6fSBjoern A. Zeeb case 4:
1820bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
1830bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3]);
1840bc7cf6fSBjoern A. Zeeb break;
1850bc7cf6fSBjoern A. Zeeb case 5:
1860bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1870bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x\n", i,
1880bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4]);
1890bc7cf6fSBjoern A. Zeeb break;
1900bc7cf6fSBjoern A. Zeeb case 6:
1910bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1920bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x\n", i,
1930bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
1940bc7cf6fSBjoern A. Zeeb break;
1950bc7cf6fSBjoern A. Zeeb case 7:
1960bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
1970bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x\n", i,
1980bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
1990bc7cf6fSBjoern A. Zeeb break;
2000bc7cf6fSBjoern A. Zeeb case 8:
2010bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2020bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2030bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2040bc7cf6fSBjoern A. Zeeb buf[7]);
2050bc7cf6fSBjoern A. Zeeb break;
2060bc7cf6fSBjoern A. Zeeb case 9:
2070bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2080bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2090bc7cf6fSBjoern A. Zeeb " %02x\n", i,
2100bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2110bc7cf6fSBjoern A. Zeeb buf[7], buf[8]);
2120bc7cf6fSBjoern A. Zeeb break;
2130bc7cf6fSBjoern A. Zeeb case 10:
2140bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2150bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2160bc7cf6fSBjoern A. Zeeb " %02x %02x\n", i,
2170bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2180bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9]);
2190bc7cf6fSBjoern A. Zeeb break;
2200bc7cf6fSBjoern A. Zeeb case 11:
2210bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2220bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2230bc7cf6fSBjoern A. Zeeb " %02x %02x %02x\n", i,
2240bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2250bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9], buf[10]);
2260bc7cf6fSBjoern A. Zeeb break;
2270bc7cf6fSBjoern A. Zeeb case 12:
2280bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2290bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2300bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x\n", i,
2310bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2320bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9], buf[10], buf[11]);
2330bc7cf6fSBjoern A. Zeeb break;
2340bc7cf6fSBjoern A. Zeeb case 13:
2350bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2360bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2370bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x\n", i,
2380bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2390bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
2400bc7cf6fSBjoern A. Zeeb break;
2410bc7cf6fSBjoern A. Zeeb case 14:
2420bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2430bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2440bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x\n", i,
2450bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2460bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
2470bc7cf6fSBjoern A. Zeeb buf[13]);
2480bc7cf6fSBjoern A. Zeeb break;
2490bc7cf6fSBjoern A. Zeeb case 15:
2500bc7cf6fSBjoern A. Zeeb device_printf(dev,"0x%08x:"
2510bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x %02x"
2520bc7cf6fSBjoern A. Zeeb " %02x %02x %02x %02x %02x %02x %02x\n", i,
2530bc7cf6fSBjoern A. Zeeb buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2540bc7cf6fSBjoern A. Zeeb buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
2550bc7cf6fSBjoern A. Zeeb buf[13], buf[14]);
2560bc7cf6fSBjoern A. Zeeb break;
2570bc7cf6fSBjoern A. Zeeb default:
2580bc7cf6fSBjoern A. Zeeb break;
2590bc7cf6fSBjoern A. Zeeb }
2600bc7cf6fSBjoern A. Zeeb
2610bc7cf6fSBjoern A. Zeeb device_printf(dev, "%s: %s dump end\n", __func__, msg);
2620bc7cf6fSBjoern A. Zeeb }
263