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