xref: /freebsd/sys/dev/qlxgb/qla_dbg.c (revision 718cf2cc)
1718cf2ccSPedro F. Giffuni /*-
2718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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 __FBSDID("$FreeBSD$");
360bc7cf6fSBjoern A. Zeeb 
370bc7cf6fSBjoern A. Zeeb #include "qla_os.h"
380bc7cf6fSBjoern A. Zeeb #include "qla_reg.h"
390bc7cf6fSBjoern A. Zeeb #include "qla_hw.h"
400bc7cf6fSBjoern A. Zeeb #include "qla_def.h"
410bc7cf6fSBjoern A. Zeeb #include "qla_inline.h"
420bc7cf6fSBjoern A. Zeeb #include "qla_ver.h"
430bc7cf6fSBjoern A. Zeeb #include "qla_glbl.h"
440bc7cf6fSBjoern A. Zeeb #include "qla_dbg.h"
450bc7cf6fSBjoern A. Zeeb 
460bc7cf6fSBjoern A. Zeeb 
470bc7cf6fSBjoern A. Zeeb uint32_t dbg_level = 0 ;
480bc7cf6fSBjoern A. Zeeb /*
490bc7cf6fSBjoern A. Zeeb  * Name: qla_dump_buf32
500bc7cf6fSBjoern A. Zeeb  * Function: dumps a buffer as 32 bit words
510bc7cf6fSBjoern A. Zeeb  */
520bc7cf6fSBjoern A. Zeeb void qla_dump_buf32(qla_host_t *ha, char *msg, void *dbuf32, uint32_t len32)
530bc7cf6fSBjoern A. Zeeb {
540bc7cf6fSBjoern A. Zeeb         device_t dev;
550bc7cf6fSBjoern A. Zeeb 	uint32_t i = 0;
560bc7cf6fSBjoern A. Zeeb 	uint32_t *buf;
570bc7cf6fSBjoern A. Zeeb 
580bc7cf6fSBjoern A. Zeeb         dev = ha->pci_dev;
590bc7cf6fSBjoern A. Zeeb 	buf = dbuf32;
600bc7cf6fSBjoern A. Zeeb 
610bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
620bc7cf6fSBjoern A. Zeeb 
630bc7cf6fSBjoern A. Zeeb 	while (len32 >= 4) {
640bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
650bc7cf6fSBjoern A. Zeeb 			i, buf[0], buf[1], buf[2], buf[3]);
660bc7cf6fSBjoern A. Zeeb 		i += 4 * 4;
670bc7cf6fSBjoern A. Zeeb 		len32 -= 4;
680bc7cf6fSBjoern A. Zeeb 		buf += 4;
690bc7cf6fSBjoern A. Zeeb 	}
700bc7cf6fSBjoern A. Zeeb 	switch (len32) {
710bc7cf6fSBjoern A. Zeeb 	case 1:
720bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%08x\n", i, buf[0]);
730bc7cf6fSBjoern A. Zeeb 		break;
740bc7cf6fSBjoern A. Zeeb 	case 2:
750bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%08x 0x%08x\n", i, buf[0], buf[1]);
760bc7cf6fSBjoern A. Zeeb 		break;
770bc7cf6fSBjoern A. Zeeb 	case 3:
780bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%08x 0x%08x 0x%08x\n",
790bc7cf6fSBjoern A. Zeeb 			i, buf[0], buf[1], buf[2]);
800bc7cf6fSBjoern A. Zeeb 		break;
810bc7cf6fSBjoern A. Zeeb 	default:
820bc7cf6fSBjoern A. Zeeb 		break;
830bc7cf6fSBjoern A. Zeeb 	}
840bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
850bc7cf6fSBjoern A. Zeeb }
860bc7cf6fSBjoern A. Zeeb 
870bc7cf6fSBjoern A. Zeeb /*
880bc7cf6fSBjoern A. Zeeb  * Name: qla_dump_buf16
890bc7cf6fSBjoern A. Zeeb  * Function: dumps a buffer as 16 bit words
900bc7cf6fSBjoern A. Zeeb  */
910bc7cf6fSBjoern A. Zeeb void qla_dump_buf16(qla_host_t *ha, char *msg, void *dbuf16, uint32_t len16)
920bc7cf6fSBjoern A. Zeeb {
930bc7cf6fSBjoern A. Zeeb         device_t dev;
940bc7cf6fSBjoern A. Zeeb 	uint32_t i = 0;
950bc7cf6fSBjoern A. Zeeb 	uint16_t *buf;
960bc7cf6fSBjoern A. Zeeb 
970bc7cf6fSBjoern A. Zeeb         dev = ha->pci_dev;
980bc7cf6fSBjoern A. Zeeb 	buf = dbuf16;
990bc7cf6fSBjoern A. Zeeb 
1000bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s dump start\n", __func__, msg);
1010bc7cf6fSBjoern A. Zeeb 
1020bc7cf6fSBjoern A. Zeeb 	while (len16 >= 8) {
1030bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x"
1040bc7cf6fSBjoern A. Zeeb 			" 0x%04x 0x%04x 0x%04x 0x%04x\n", i, buf[0],
1050bc7cf6fSBjoern A. Zeeb 			buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
1060bc7cf6fSBjoern A. Zeeb 		i += 16;
1070bc7cf6fSBjoern A. Zeeb 		len16 -= 8;
1080bc7cf6fSBjoern A. Zeeb 		buf += 8;
1090bc7cf6fSBjoern A. Zeeb 	}
1100bc7cf6fSBjoern A. Zeeb 	switch (len16) {
1110bc7cf6fSBjoern A. Zeeb 	case 1:
1120bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%04x\n", i, buf[0]);
1130bc7cf6fSBjoern A. Zeeb 		break;
1140bc7cf6fSBjoern A. Zeeb 	case 2:
1150bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%04x 0x%04x\n", i, buf[0], buf[1]);
1160bc7cf6fSBjoern A. Zeeb 		break;
1170bc7cf6fSBjoern A. Zeeb 	case 3:
1180bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x\n",
1190bc7cf6fSBjoern A. Zeeb 			i, buf[0], buf[1], buf[2]);
1200bc7cf6fSBjoern A. Zeeb 		break;
1210bc7cf6fSBjoern A. Zeeb 	case 4:
1220bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1230bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3]);
1240bc7cf6fSBjoern A. Zeeb 		break;
1250bc7cf6fSBjoern A. Zeeb 	case 5:
1260bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
1270bc7cf6fSBjoern A. Zeeb 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1280bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4]);
1290bc7cf6fSBjoern A. Zeeb 		break;
1300bc7cf6fSBjoern A. Zeeb 	case 6:
1310bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
1320bc7cf6fSBjoern A. Zeeb 			" 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", i,
1330bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
1340bc7cf6fSBjoern A. Zeeb 		break;
1350bc7cf6fSBjoern A. Zeeb 	case 7:
1360bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%04x: 0x%04x 0x%04x 0x%04x 0x%04x"
1370bc7cf6fSBjoern A. Zeeb 			" 0x%04x 0x%04x 0x%04x\n", i, buf[0], buf[1],
1380bc7cf6fSBjoern A. Zeeb 			buf[2], buf[3], buf[4], buf[5], buf[6]);
1390bc7cf6fSBjoern A. Zeeb 		break;
1400bc7cf6fSBjoern A. Zeeb 	default:
1410bc7cf6fSBjoern A. Zeeb 		break;
1420bc7cf6fSBjoern A. Zeeb 	}
1430bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
1440bc7cf6fSBjoern A. Zeeb }
1450bc7cf6fSBjoern A. Zeeb 
1460bc7cf6fSBjoern A. Zeeb /*
1470bc7cf6fSBjoern A. Zeeb  * Name: qla_dump_buf8
1480bc7cf6fSBjoern A. Zeeb  * Function: dumps a buffer as bytes
1490bc7cf6fSBjoern A. Zeeb  */
1500bc7cf6fSBjoern A. Zeeb void qla_dump_buf8(qla_host_t *ha, char *msg, void *dbuf, uint32_t len)
1510bc7cf6fSBjoern A. Zeeb {
1520bc7cf6fSBjoern A. Zeeb         device_t dev;
1530bc7cf6fSBjoern A. Zeeb 	uint32_t i = 0;
1540bc7cf6fSBjoern A. Zeeb 	uint8_t *buf;
1550bc7cf6fSBjoern A. Zeeb 
1560bc7cf6fSBjoern A. Zeeb         dev = ha->pci_dev;
1570bc7cf6fSBjoern A. Zeeb 	buf = dbuf;
1580bc7cf6fSBjoern A. Zeeb 
1590bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
1600bc7cf6fSBjoern A. Zeeb 
1610bc7cf6fSBjoern A. Zeeb 	while (len >= 16) {
1620bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
1630bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
1640bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
1650bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3],
1660bc7cf6fSBjoern A. Zeeb 			buf[4], buf[5], buf[6], buf[7],
1670bc7cf6fSBjoern A. Zeeb 			buf[8], buf[9], buf[10], buf[11],
1680bc7cf6fSBjoern A. Zeeb 			buf[12], buf[13], buf[14], buf[15]);
1690bc7cf6fSBjoern A. Zeeb 		i += 16;
1700bc7cf6fSBjoern A. Zeeb 		len -= 16;
1710bc7cf6fSBjoern A. Zeeb 		buf += 16;
1720bc7cf6fSBjoern A. Zeeb 	}
1730bc7cf6fSBjoern A. Zeeb 	switch (len) {
1740bc7cf6fSBjoern A. Zeeb 	case 1:
1750bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
1760bc7cf6fSBjoern A. Zeeb 		break;
1770bc7cf6fSBjoern A. Zeeb 	case 2:
1780bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
1790bc7cf6fSBjoern A. Zeeb 		break;
1800bc7cf6fSBjoern A. Zeeb 	case 3:
1810bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: %02x %02x %02x\n",
1820bc7cf6fSBjoern A. Zeeb 			i, buf[0], buf[1], buf[2]);
1830bc7cf6fSBjoern A. Zeeb 		break;
1840bc7cf6fSBjoern A. Zeeb 	case 4:
1850bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
1860bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3]);
1870bc7cf6fSBjoern A. Zeeb 		break;
1880bc7cf6fSBjoern A. Zeeb 	case 5:
1890bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
1900bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x\n", i,
1910bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4]);
1920bc7cf6fSBjoern A. Zeeb 		break;
1930bc7cf6fSBjoern A. Zeeb 	case 6:
1940bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
1950bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x\n", i,
1960bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
1970bc7cf6fSBjoern A. Zeeb 		break;
1980bc7cf6fSBjoern A. Zeeb 	case 7:
1990bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2000bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
2010bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
2020bc7cf6fSBjoern A. Zeeb 		break;
2030bc7cf6fSBjoern A. Zeeb 	case 8:
2040bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2050bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2060bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2070bc7cf6fSBjoern A. Zeeb 			buf[7]);
2080bc7cf6fSBjoern A. Zeeb 		break;
2090bc7cf6fSBjoern A. Zeeb 	case 9:
2100bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2110bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2120bc7cf6fSBjoern A. Zeeb 			" %02x\n", i,
2130bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2140bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8]);
2150bc7cf6fSBjoern A. Zeeb 		break;
2160bc7cf6fSBjoern A. Zeeb 	case 10:
2170bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2180bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2190bc7cf6fSBjoern A. Zeeb 			" %02x %02x\n", i,
2200bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2210bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9]);
2220bc7cf6fSBjoern A. Zeeb 		break;
2230bc7cf6fSBjoern A. Zeeb 	case 11:
2240bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2250bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2260bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x\n", i,
2270bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2280bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9], buf[10]);
2290bc7cf6fSBjoern A. Zeeb 		break;
2300bc7cf6fSBjoern A. Zeeb 	case 12:
2310bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2320bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2330bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x\n", i,
2340bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2350bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9], buf[10], buf[11]);
2360bc7cf6fSBjoern A. Zeeb 		break;
2370bc7cf6fSBjoern A. Zeeb 	case 13:
2380bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2390bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2400bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x\n", i,
2410bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2420bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
2430bc7cf6fSBjoern A. Zeeb 		break;
2440bc7cf6fSBjoern A. Zeeb 	case 14:
2450bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2460bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2470bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x\n", i,
2480bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2490bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
2500bc7cf6fSBjoern A. Zeeb 			buf[13]);
2510bc7cf6fSBjoern A. Zeeb 		break;
2520bc7cf6fSBjoern A. Zeeb 	case 15:
2530bc7cf6fSBjoern A. Zeeb 		device_printf(dev,"0x%08x:"
2540bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x %02x"
2550bc7cf6fSBjoern A. Zeeb 			" %02x %02x %02x %02x %02x %02x %02x\n", i,
2560bc7cf6fSBjoern A. Zeeb 			buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
2570bc7cf6fSBjoern A. Zeeb 			buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
2580bc7cf6fSBjoern A. Zeeb 			buf[13], buf[14]);
2590bc7cf6fSBjoern A. Zeeb 		break;
2600bc7cf6fSBjoern A. Zeeb 	default:
2610bc7cf6fSBjoern A. Zeeb 		break;
2620bc7cf6fSBjoern A. Zeeb 	}
2630bc7cf6fSBjoern A. Zeeb 
2640bc7cf6fSBjoern A. Zeeb 	device_printf(dev, "%s: %s dump end\n", __func__, msg);
2650bc7cf6fSBjoern A. Zeeb }
266