xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000g_debug.c (revision 6735:ba4d622bb38a)
13526Sxy150489 /*
23526Sxy150489  * This file is provided under a CDDLv1 license.  When using or
33526Sxy150489  * redistributing this file, you may do so under this license.
43526Sxy150489  * In redistributing this file this license must be included
53526Sxy150489  * and no other modification of this header file is permitted.
63526Sxy150489  *
73526Sxy150489  * CDDL LICENSE SUMMARY
83526Sxy150489  *
9*6735Scc210113  * Copyright(c) 1999 - 2008 Intel Corporation. All rights reserved.
103526Sxy150489  *
113526Sxy150489  * The contents of this file are subject to the terms of Version
123526Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
133526Sxy150489  *
143526Sxy150489  * You should have received a copy of the License with this software.
153526Sxy150489  * You can obtain a copy of the License at
163526Sxy150489  *	http://www.opensolaris.org/os/licensing.
173526Sxy150489  * See the License for the specific language governing permissions
183526Sxy150489  * and limitations under the License.
193526Sxy150489  */
203526Sxy150489 
213526Sxy150489 /*
22*6735Scc210113  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233526Sxy150489  * Use is subject to license terms of the CDDLv1.
243526Sxy150489  */
253526Sxy150489 
263526Sxy150489 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273526Sxy150489 
283526Sxy150489 /*
293526Sxy150489  * **********************************************************************
303526Sxy150489  *									*
313526Sxy150489  * Module Name:								*
324919Sxy150489  * 	e1000g_debug.c							*
333526Sxy150489  *									*
343526Sxy150489  * Abstract:								*
354919Sxy150489  *	This module includes the debug routines				*
363526Sxy150489  *									*
373526Sxy150489  * **********************************************************************
383526Sxy150489  */
393526Sxy150489 #ifdef GCC
403526Sxy150489 #ifdef __STDC__
413526Sxy150489 #include <stdarg.h>
423526Sxy150489 #else
433526Sxy150489 #include <varargs.h>
443526Sxy150489 #endif
453526Sxy150489 #define	_SYS_VARARGS_H
463526Sxy150489 #endif
473526Sxy150489 
484919Sxy150489 #include "e1000g_debug.h"
493526Sxy150489 #include "e1000g_sw.h"
505082Syy150190 #ifdef E1000G_DEBUG
515082Syy150190 #include <sys/pcie.h>
525082Syy150190 #endif
534919Sxy150489 
544919Sxy150489 #ifdef E1000G_DEBUG
555082Syy150190 #define	WPL		8	/* 8 16-bit words per line */
56*6735Scc210113 #define	NUM_REGS	155	/* must match the array initializer */
575082Syy150190 typedef struct {
585082Syy150190 	char		name[10];
595082Syy150190 	uint32_t	offset;
605082Syy150190 } Regi_t;
614919Sxy150489 int e1000g_debug = E1000G_WARN_LEVEL;
624919Sxy150489 #endif
634919Sxy150489 int e1000g_log_mode = E1000G_LOG_PRINT;
643526Sxy150489 
653526Sxy150489 void
664919Sxy150489 e1000g_log(void *instance, int level, char *fmt, ...)
673526Sxy150489 {
684919Sxy150489 	struct e1000g *Adapter = (struct e1000g *)instance;
693526Sxy150489 	auto char name[NAMELEN];
703526Sxy150489 	auto char buf[BUFSZ];
713526Sxy150489 	va_list ap;
723526Sxy150489 
734919Sxy150489 	switch (level) {
744919Sxy150489 #ifdef E1000G_DEBUG
754919Sxy150489 	case E1000G_VERBOSE_LEVEL:	/* 16 or 0x010 */
764919Sxy150489 		if (e1000g_debug < E1000G_VERBOSE_LEVEL)
774919Sxy150489 			return;
784919Sxy150489 		level = CE_CONT;
794919Sxy150489 		break;
804919Sxy150489 
814919Sxy150489 	case E1000G_TRACE_LEVEL:	/* 8 or 0x008 */
824919Sxy150489 		if (e1000g_debug < E1000G_TRACE_LEVEL)
834919Sxy150489 			return;
844919Sxy150489 		level = CE_CONT;
854919Sxy150489 		break;
864919Sxy150489 
874919Sxy150489 	case E1000G_INFO_LEVEL:		/* 4 or 0x004 */
884919Sxy150489 		if (e1000g_debug < E1000G_INFO_LEVEL)
894919Sxy150489 			return;
904919Sxy150489 		level = CE_CONT;
914919Sxy150489 		break;
924919Sxy150489 
934919Sxy150489 	case E1000G_WARN_LEVEL:		/* 2 or 0x002 */
944919Sxy150489 		if (e1000g_debug < E1000G_WARN_LEVEL)
954919Sxy150489 			return;
964919Sxy150489 		level = CE_CONT;
974919Sxy150489 		break;
984919Sxy150489 
994919Sxy150489 	case E1000G_ERRS_LEVEL:		/* 1 or 0x001 */
1004919Sxy150489 		level = CE_CONT;
1014919Sxy150489 		break;
1024919Sxy150489 #else
1034919Sxy150489 	case CE_CONT:
1044919Sxy150489 	case CE_NOTE:
1054919Sxy150489 	case CE_WARN:
1064919Sxy150489 	case CE_PANIC:
1074919Sxy150489 		break;
1084919Sxy150489 #endif
1094919Sxy150489 	default:
1104919Sxy150489 		level = CE_CONT;
1114919Sxy150489 		break;
1124919Sxy150489 	}
1134919Sxy150489 
1143526Sxy150489 	if (Adapter != NULL) {
1153526Sxy150489 		(void) sprintf(name, "%s - e1000g[%d] ",
1163526Sxy150489 		    ddi_get_name(Adapter->dip), ddi_get_instance(Adapter->dip));
1173526Sxy150489 	} else {
1183526Sxy150489 		(void) sprintf(name, "e1000g");
1193526Sxy150489 	}
1203526Sxy150489 	/*
1213526Sxy150489 	 * va_start uses built in macro __builtin_va_alist from the
1223526Sxy150489 	 * compiler libs which requires compiler system to have
1233526Sxy150489 	 * __BUILTIN_VA_ARG_INCR defined.
1243526Sxy150489 	 */
1253526Sxy150489 	/*
1263526Sxy150489 	 * Many compilation systems depend upon the use of special functions
1273526Sxy150489 	 * built into the the compilation system to handle variable argument
1283526Sxy150489 	 * lists and stack allocations.  The method to obtain this in SunOS
1293526Sxy150489 	 * is to define the feature test macro "__BUILTIN_VA_ARG_INCR" which
1303526Sxy150489 	 * enables the following special built-in functions:
1313526Sxy150489 	 *	__builtin_alloca
1323526Sxy150489 	 *	__builtin_va_alist
1333526Sxy150489 	 *	__builtin_va_arg_incr
1343526Sxy150489 	 * It is intended that the compilation system define this feature test
1353526Sxy150489 	 * macro, not the user of the system.
1363526Sxy150489 	 *
1373526Sxy150489 	 * The tests on the processor type are to provide a transitional period
1383526Sxy150489 	 * for existing compilation systems, and may be removed in a future
1393526Sxy150489 	 * release.
1403526Sxy150489 	 */
1413526Sxy150489 	/*
1423526Sxy150489 	 * Using GNU gcc compiler it doesn't expand to va_start....
1433526Sxy150489 	 */
1443526Sxy150489 	va_start(ap, fmt);
1453526Sxy150489 	(void) vsprintf(buf, fmt, ap);
1463526Sxy150489 	va_end(ap);
1473526Sxy150489 
1484919Sxy150489 	if ((e1000g_log_mode & E1000G_LOG_ALL) == E1000G_LOG_ALL)
1493526Sxy150489 		cmn_err(level, "%s: %s", name, buf);
1504919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_DISPLAY)
1514919Sxy150489 		cmn_err(level, "^%s: %s", name, buf);
1524919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_PRINT)
1534919Sxy150489 		cmn_err(level, "!%s: %s", name, buf);
1544919Sxy150489 	else /* if they are not set properly then do both */
1554919Sxy150489 		cmn_err(level, "%s: %s", name, buf);
1563526Sxy150489 }
1575082Syy150190 
1585082Syy150190 
1595082Syy150190 
1605082Syy150190 #ifdef E1000G_DEBUG
1615082Syy150190 void
1625082Syy150190 eeprom_dump(void *instance)
1635082Syy150190 {
1645082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
1655082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
1665082Syy150190 	uint16_t eeprom[WPL], size_field;
1675082Syy150190 	int i, ret, sign, size, lines, offset = 0;
1685082Syy150190 	int ee_size[] =
1695082Syy150190 	    {128, 256, 512, 1024, 2048, 4096, 16 * 1024, 32 * 1024, 64 * 1024};
1705082Syy150190 
1715082Syy150190 	if (ret = e1000_read_nvm(hw, 0x12, 1, &size_field)) {
1725082Syy150190 		e1000g_log(Adapter, CE_WARN,
1735082Syy150190 		    "e1000_read_nvm failed to read size: %d", ret);
1745082Syy150190 		return;
1755082Syy150190 	}
1765082Syy150190 
1775082Syy150190 	sign = (size_field & 0xc000) >> 14;
1785082Syy150190 	if (sign != 1) {
1795082Syy150190 		e1000g_log(Adapter, CE_WARN,
1805082Syy150190 		    "eeprom_dump invalid signature: %d", sign);
1815082Syy150190 	}
1825082Syy150190 
1835082Syy150190 	size = (size_field & 0x3c00) >> 10;
1845082Syy150190 	if (size < 0 || size > 11) {
1855082Syy150190 		e1000g_log(Adapter, CE_WARN,
1865082Syy150190 		    "eeprom_dump invalid size: %d", size);
1875082Syy150190 	}
1885082Syy150190 
1895082Syy150190 	e1000g_log(Adapter, CE_CONT,
1905082Syy150190 	    "eeprom_dump size field: %d  eeprom bytes: %d\n",
1915082Syy150190 	    size, ee_size[size]);
1925082Syy150190 
1935082Syy150190 	e1000g_log(Adapter, CE_CONT,
1945082Syy150190 	    "e1000_read_nvm hebs: %d\n", ((size_field & 0x000f) >> 10));
1955082Syy150190 
1965082Syy150190 	lines = ee_size[size] / WPL / 2;
1975082Syy150190 	e1000g_log(Adapter, CE_CONT,
1985082Syy150190 	    "dump eeprom %d lines of %d words per line\n", lines, WPL);
1995082Syy150190 
2005082Syy150190 	for (i = 0; i < lines; i++) {
2015082Syy150190 		if (ret = e1000_read_nvm(hw, offset, WPL, eeprom)) {
2025082Syy150190 			e1000g_log(Adapter, CE_WARN,
2035082Syy150190 			    "e1000_read_nvm failed: %d", ret);
2045082Syy150190 			return;
2055082Syy150190 		}
2065082Syy150190 
2075082Syy150190 		e1000g_log(Adapter, CE_CONT,
2085082Syy150190 		    "0x%04x    %04x %04x %04x %04x %04x %04x %04x %04x\n",
2095082Syy150190 		    offset,
2105082Syy150190 		    eeprom[0], eeprom[1], eeprom[2], eeprom[3],
2115082Syy150190 		    eeprom[4], eeprom[5], eeprom[6], eeprom[7]);
2125082Syy150190 		offset += WPL;
2135082Syy150190 	}
2145082Syy150190 }
2155082Syy150190 
2165082Syy150190 /*
2175082Syy150190  * phy_dump - dump important phy registers
2185082Syy150190  */
2195082Syy150190 void
2205082Syy150190 phy_dump(void *instance)
2215082Syy150190 {
2225082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
2235082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
2245082Syy150190 	/* offset to each phy register */
2255082Syy150190 	int32_t offset[] =
2265082Syy150190 	    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
2275082Syy150190 	    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2285082Syy150190 	    30, 31, 0x1796, 0x187A, 0x1895, 0x1F30, 0x1F35, 0x1F3E, 0x1F54,
2295082Syy150190 	    0x1F55, 0x1F56, 0x1F72, 0x1F76, 0x1F77, 0x1F78, 0x1F79, 0x1F98,
2305082Syy150190 	    0x2010, 0x2011, 0x20DC, 0x20DD, 0x20DE, 0x28B4, 0x2F52, 0x2F5B,
2315082Syy150190 	    0x2F70, 0x2F90, 0x2FB1, 0x2FB2 };
2325082Syy150190 	uint16_t value;	/* register value */
2335082Syy150190 	uint32_t stat;	/* status from e1000_read_phy_reg */
2345082Syy150190 	int i;
2355082Syy150190 
2365082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin PHY dump\n");
2375082Syy150190 	for (i = 0; i < ((sizeof (offset)) / sizeof (offset[0])); i++) {
2385082Syy150190 
2395082Syy150190 		stat = e1000_read_phy_reg(hw, offset[i], &value);
2405082Syy150190 		if (stat == 0) {
2415082Syy150190 			e1000g_log(Adapter, CE_CONT,
2425082Syy150190 			    "phyreg offset: %d   value: 0x%x\n",
2435082Syy150190 			    offset[i], value);
2445082Syy150190 		} else {
2455082Syy150190 			e1000g_log(Adapter, CE_WARN,
2465082Syy150190 			    "phyreg offset: %d   ERROR: 0x%x\n",
2475082Syy150190 			    offset[i], stat);
2485082Syy150190 		}
2495082Syy150190 	}
2505082Syy150190 }
2515082Syy150190 
2525082Syy150190 uint32_t
2535082Syy150190 e1000_read_reg(struct e1000_hw *hw, uint32_t offset)
2545082Syy150190 {
2555082Syy150190 	return (ddi_get32(((struct e1000g_osdep *)(hw)->back)->reg_handle,
2565082Syy150190 	    (uint32_t *)((hw)->hw_addr + offset)));
2575082Syy150190 }
2585082Syy150190 
2595082Syy150190 
2605082Syy150190 /*
2615082Syy150190  * mac_dump - dump important mac registers
2625082Syy150190  */
2635082Syy150190 void
2645082Syy150190 mac_dump(void *instance)
2655082Syy150190 {
2665082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
2675082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
2685082Syy150190 	int i;
2695082Syy150190 
2705082Syy150190 	/* {name, offset} for each mac register */
2715082Syy150190 	Regi_t macreg[NUM_REGS] = {
2725082Syy150190 	    {"CTRL",	E1000_CTRL},	{"STATUS",	E1000_STATUS},
2735082Syy150190 	    {"EECD",	E1000_EECD},	{"EERD",	E1000_EERD},
2745082Syy150190 	    {"CTRL_EXT", E1000_CTRL_EXT}, {"FLA",	E1000_FLA},
2755082Syy150190 	    {"MDIC",	E1000_MDIC},	{"SCTL",	E1000_SCTL},
2765082Syy150190 	    {"FCAL",	E1000_FCAL},	{"FCAH",	E1000_FCAH},
2775082Syy150190 	    {"FCT",	E1000_FCT},	{"VET",		E1000_VET},
2785082Syy150190 	    {"ICR",	E1000_ICR},	{"ITR",		E1000_ITR},
2795082Syy150190 	    {"ICS",	E1000_ICS},	{"IMS",		E1000_IMS},
2805082Syy150190 	    {"IMC",	E1000_IMC},	{"IAM",		E1000_IAM},
2815082Syy150190 	    {"RCTL",	E1000_RCTL},	{"FCTTV",	E1000_FCTTV},
2825082Syy150190 	    {"TXCW",	E1000_TXCW},	{"RXCW",	E1000_RXCW},
2835082Syy150190 	    {"TCTL",	E1000_TCTL},	{"TIPG",	E1000_TIPG},
2845082Syy150190 	    {"AIT",	E1000_AIT},	{"LEDCTL",	E1000_LEDCTL},
2855082Syy150190 	    {"PBA",	E1000_PBA},	{"PBS",		E1000_PBS},
2865082Syy150190 	    {"EEMNGCTL", E1000_EEMNGCTL}, {"ERT",	E1000_ERT},
2875082Syy150190 	    {"FCRTL",	E1000_FCRTL},	{"FCRTH",	E1000_FCRTH},
288*6735Scc210113 	    {"PSRCTL",	E1000_PSRCTL},	{"RDBAL(0)",	E1000_RDBAL(0)},
289*6735Scc210113 	    {"RDBAH(0)", E1000_RDBAH(0)}, {"RDLEN(0)",	E1000_RDLEN(0)},
290*6735Scc210113 	    {"RDH(0)",	E1000_RDH(0)},	{"RDT(0)",	E1000_RDT(0)},
291*6735Scc210113 	    {"RDTR",	E1000_RDTR},	{"RXDCTL(0)",	E1000_RXDCTL(0)},
292*6735Scc210113 	    {"RADV",	E1000_RADV},	{"RDBAL(1)",	E1000_RDBAL(1)},
293*6735Scc210113 	    {"RDBAH(1)", E1000_RDBAH(1)}, {"RDLEN(1)",	E1000_RDLEN(1)},
294*6735Scc210113 	    {"RDH(1)",	E1000_RDH(1)},	{"RDT(1)",	E1000_RDT(1)},
295*6735Scc210113 	    {"RXDCTL(1)", E1000_RXDCTL(1)}, {"RSRPD",	E1000_RSRPD},
2965082Syy150190 	    {"RAID",	E1000_RAID},	{"CPUVEC",	E1000_CPUVEC},
2975082Syy150190 	    {"TDFH",	E1000_TDFH},	{"TDFT",	E1000_TDFT},
2985082Syy150190 	    {"TDFHS",	E1000_TDFHS},	{"TDFTS",	E1000_TDFTS},
299*6735Scc210113 	    {"TDFPC",	E1000_TDFPC},	{"TDBAL(0)",	E1000_TDBAL(0)},
300*6735Scc210113 	    {"TDBAH(0)", E1000_TDBAH(0)}, {"TDLEN(0)",	E1000_TDLEN(0)},
301*6735Scc210113 	    {"TDH(0)",	E1000_TDH(0)},	{"TDT(0)",	E1000_TDT(0)},
302*6735Scc210113 	    {"TIDV",	E1000_TIDV},	{"TXDCTL(0)",	E1000_TXDCTL(0)},
303*6735Scc210113 	    {"TADV",	E1000_TADV},	{"TARC(0)",	E1000_TARC(0)},
304*6735Scc210113 	    {"TDBAL(1)", E1000_TDBAL(1)}, {"TDBAH(1)",	E1000_TDBAH(1)},
305*6735Scc210113 	    {"TDLEN(1)", E1000_TDLEN(1)}, {"TDH(1)",	E1000_TDH(1)},
306*6735Scc210113 	    {"TDT(1)",	E1000_TDT(1)},	{"TXDCTL(1)",	E1000_TXDCTL(1)},
307*6735Scc210113 	    {"TARC(1)",	E1000_TARC(1)},	{"ALGNERRC",	E1000_ALGNERRC},
3085082Syy150190 	    {"RXERRC",	E1000_RXERRC},	{"MPC",		E1000_MPC},
3095082Syy150190 	    {"SCC",	E1000_SCC},	{"ECOL",	E1000_ECOL},
3105082Syy150190 	    {"MCC",	E1000_MCC},	{"LATECOL",	E1000_LATECOL},
3115082Syy150190 	    {"COLC",	E1000_COLC},	{"DC",		E1000_DC},
3125082Syy150190 	    {"TNCRS",	E1000_TNCRS},	{"SEC",		E1000_SEC},
3135082Syy150190 	    {"CEXTERR",	E1000_CEXTERR},	{"RLEC",	E1000_RLEC},
3145082Syy150190 	    {"XONRXC",	E1000_XONRXC},	{"XONTXC",	E1000_XONTXC},
3155082Syy150190 	    {"XOFFRXC",	E1000_XOFFRXC},	{"XOFFTXC",	E1000_XOFFTXC},
3165082Syy150190 	    {"FCRUC",	E1000_FCRUC},	{"PRC64",	E1000_PRC64},
3175082Syy150190 	    {"PRC127",	E1000_PRC127},	{"PRC255",	E1000_PRC255},
3185082Syy150190 	    {"PRC511",	E1000_PRC511},	{"PRC1023",	E1000_PRC1023},
3195082Syy150190 	    {"PRC1522",	E1000_PRC1522},	{"GPRC",	E1000_GPRC},
3205082Syy150190 	    {"BPRC",	E1000_BPRC},	{"MPRC",	E1000_MPRC},
3215082Syy150190 	    {"GPTC",	E1000_GPTC},	{"GORCL",	E1000_GORCL},
3225082Syy150190 	    {"GORCH",	E1000_GORCH},	{"GOTCL",	E1000_GOTCL},
3235082Syy150190 	    {"GOTCH",	E1000_GOTCH},	{"RNBC",	E1000_RNBC},
3245082Syy150190 	    {"RUC",	E1000_RUC},	{"RFC",		E1000_RFC},
3255082Syy150190 	    {"ROC",	E1000_ROC},	{"RJC",		E1000_RJC},
3265082Syy150190 	    {"MGTPRC",	E1000_MGTPRC},	{"MGTPDC",	E1000_MGTPDC},
3275082Syy150190 	    {"MGTPTC",	E1000_MGTPTC},	{"TORL",	E1000_TORL},
3285082Syy150190 	    {"TORH",	E1000_TORH},	{"TOTL",	E1000_TOTL},
3295082Syy150190 	    {"TOTH",	E1000_TOTH},	{"TPR",		E1000_TPR},
3305082Syy150190 	    {"TPT",	E1000_TPT},	{"PTC64",	E1000_PTC64},
3315082Syy150190 	    {"PTC127",	E1000_PTC127},	{"PTC255",	E1000_PTC255},
3325082Syy150190 	    {"PTC511",	E1000_PTC511},	{"PTC1023",	E1000_PTC1023},
3335082Syy150190 	    {"PTC1522",	E1000_PTC1522},	{"MPTC",	E1000_MPTC},
3345082Syy150190 	    {"BPTC",	E1000_BPTC},	{"TSCTC",	E1000_TSCTC},
3355082Syy150190 	    {"TSCTFC",	E1000_TSCTFC},	{"IAC",		E1000_IAC},
3365082Syy150190 	    {"ICRXPTC",	E1000_ICRXPTC},	{"ICRXATC",	E1000_ICRXATC},
3375082Syy150190 	    {"ICTXPTC",	E1000_ICTXPTC},	{"ICTXATC",	E1000_ICTXATC},
3385082Syy150190 	    {"ICTXQEC",	E1000_ICTXQEC},	{"ICTXQMTC",	E1000_ICTXQMTC},
3395082Syy150190 	    {"ICRXDMTC", E1000_ICRXDMTC}, {"ICRXOC",	E1000_ICRXOC},
3405082Syy150190 	    {"RXCSUM",	E1000_RXCSUM},	{"RFCTL",	E1000_RFCTL},
3415082Syy150190 	    {"WUC",	E1000_WUC},	{"WUFC",	E1000_WUFC},
3425082Syy150190 	    {"WUS",	E1000_WUS},	{"MRQC",	E1000_MRQC},
3435082Syy150190 	    {"MANC",	E1000_MANC},	{"IPAV",	E1000_IPAV},
3445082Syy150190 	    {"MANC2H",	E1000_MANC2H},	{"RSSIM",	E1000_RSSIM},
3455082Syy150190 	    {"RSSIR",	E1000_RSSIR},	{"WUPL",	E1000_WUPL},
3465082Syy150190 	    {"GCR",	E1000_GCR},	{"GSCL_1",	E1000_GSCL_1},
3475082Syy150190 	    {"GSCL_2",	E1000_GSCL_2},	{"GSCL_3",	E1000_GSCL_3},
3485082Syy150190 	    {"GSCL_4",	E1000_GSCL_4},	{"FACTPS",	E1000_FACTPS},
3495082Syy150190 	    {"FWSM",	E1000_FWSM},
3505082Syy150190 	};
3515082Syy150190 
3525082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin MAC dump\n");
3535082Syy150190 
3545082Syy150190 	for (i = 0; i < NUM_REGS; i++) {
3555082Syy150190 		e1000g_log(Adapter, CE_CONT,
3565082Syy150190 		    "macreg %10s offset: 0x%x   value: 0x%x\n",
3575082Syy150190 		    macreg[i].name, macreg[i].offset,
3585082Syy150190 		    e1000_read_reg(hw, macreg[i].offset));
3595082Syy150190 	}
3605082Syy150190 }
3615082Syy150190 
3625082Syy150190 void
3635082Syy150190 pciconfig_dump(void *instance)
3645082Syy150190 {
3655082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
3665082Syy150190 	ddi_acc_handle_t handle;
3675082Syy150190 	uint8_t cap_ptr;
3685082Syy150190 	uint8_t next_ptr;
3695082Syy150190 	off_t offset;
3705082Syy150190 
3715082Syy150190 	handle = Adapter->osdep.cfg_handle;
3725082Syy150190 
3735082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin dump PCI config space\n");
3745082Syy150190 
3755082Syy150190 	e1000g_log(Adapter, CE_CONT,
3765082Syy150190 	    "PCI_CONF_VENID:\t0x%x\n",
3775082Syy150190 	    pci_config_get16(handle, PCI_CONF_VENID));
3785082Syy150190 	e1000g_log(Adapter, CE_CONT,
3795082Syy150190 	    "PCI_CONF_DEVID:\t0x%x\n",
3805082Syy150190 	    pci_config_get16(handle, PCI_CONF_DEVID));
3815082Syy150190 	e1000g_log(Adapter, CE_CONT,
3825082Syy150190 	    "PCI_CONF_COMMAND:\t0x%x\n",
3835082Syy150190 	    pci_config_get16(handle, PCI_CONF_COMM));
3845082Syy150190 	e1000g_log(Adapter, CE_CONT,
3855082Syy150190 	    "PCI_CONF_STATUS:\t0x%x\n",
3865082Syy150190 	    pci_config_get16(handle, PCI_CONF_STAT));
3875082Syy150190 	e1000g_log(Adapter, CE_CONT,
3885082Syy150190 	    "PCI_CONF_REVID:\t0x%x\n",
3895082Syy150190 	    pci_config_get8(handle, PCI_CONF_REVID));
3905082Syy150190 	e1000g_log(Adapter, CE_CONT,
3915082Syy150190 	    "PCI_CONF_PROG_CLASS:\t0x%x\n",
3925082Syy150190 	    pci_config_get8(handle, PCI_CONF_PROGCLASS));
3935082Syy150190 	e1000g_log(Adapter, CE_CONT,
3945082Syy150190 	    "PCI_CONF_SUB_CLASS:\t0x%x\n",
3955082Syy150190 	    pci_config_get8(handle, PCI_CONF_SUBCLASS));
3965082Syy150190 	e1000g_log(Adapter, CE_CONT,
3975082Syy150190 	    "PCI_CONF_BAS_CLASS:\t0x%x\n",
3985082Syy150190 	    pci_config_get8(handle, PCI_CONF_BASCLASS));
3995082Syy150190 	e1000g_log(Adapter, CE_CONT,
4005082Syy150190 	    "PCI_CONF_CACHE_LINESZ:\t0x%x\n",
4015082Syy150190 	    pci_config_get8(handle, PCI_CONF_CACHE_LINESZ));
4025082Syy150190 	e1000g_log(Adapter, CE_CONT,
4035082Syy150190 	    "PCI_CONF_LATENCY_TIMER:\t0x%x\n",
4045082Syy150190 	    pci_config_get8(handle, PCI_CONF_LATENCY_TIMER));
4055082Syy150190 	e1000g_log(Adapter, CE_CONT,
4065082Syy150190 	    "PCI_CONF_HEADER_TYPE:\t0x%x\n",
4075082Syy150190 	    pci_config_get8(handle, PCI_CONF_HEADER));
4085082Syy150190 	e1000g_log(Adapter, CE_CONT,
4095082Syy150190 	    "PCI_CONF_BIST:\t0x%x\n",
4105082Syy150190 	    pci_config_get8(handle, PCI_CONF_BIST));
411*6735Scc210113 
412*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE0, "PCI_CONF_BASE0");
413*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE1, "PCI_CONF_BASE1");
414*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE2, "PCI_CONF_BASE2");
415*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE3, "PCI_CONF_BASE3");
416*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE4, "PCI_CONF_BASE4");
417*6735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE5, "PCI_CONF_BASE5");
418*6735Scc210113 
4195082Syy150190 	e1000g_log(Adapter, CE_CONT,
4205082Syy150190 	    "PCI_CONF_CIS:\t0x%x\n",
4215082Syy150190 	    pci_config_get32(handle, PCI_CONF_CIS));
4225082Syy150190 	e1000g_log(Adapter, CE_CONT,
4235082Syy150190 	    "PCI_CONF_SUBVENID:\t0x%x\n",
4245082Syy150190 	    pci_config_get16(handle, PCI_CONF_SUBVENID));
4255082Syy150190 	e1000g_log(Adapter, CE_CONT,
4265082Syy150190 	    "PCI_CONF_SUBSYSID:\t0x%x\n",
4275082Syy150190 	    pci_config_get16(handle, PCI_CONF_SUBSYSID));
4285082Syy150190 	e1000g_log(Adapter, CE_CONT,
4295082Syy150190 	    "PCI_CONF_ROM:\t0x%x\n",
4305082Syy150190 	    pci_config_get32(handle, PCI_CONF_ROM));
4315082Syy150190 
4325082Syy150190 	cap_ptr = pci_config_get8(handle, PCI_CONF_CAP_PTR);
4335082Syy150190 
4345082Syy150190 	e1000g_log(Adapter, CE_CONT,
4355082Syy150190 	    "PCI_CONF_CAP_PTR:\t0x%x\n", cap_ptr);
4365082Syy150190 	e1000g_log(Adapter, CE_CONT,
4375082Syy150190 	    "PCI_CONF_ILINE:\t0x%x\n",
4385082Syy150190 	    pci_config_get8(handle, PCI_CONF_ILINE));
4395082Syy150190 	e1000g_log(Adapter, CE_CONT,
4405082Syy150190 	    "PCI_CONF_IPIN:\t0x%x\n",
4415082Syy150190 	    pci_config_get8(handle, PCI_CONF_IPIN));
4425082Syy150190 	e1000g_log(Adapter, CE_CONT,
4435082Syy150190 	    "PCI_CONF_MIN_G:\t0x%x\n",
4445082Syy150190 	    pci_config_get8(handle, PCI_CONF_MIN_G));
4455082Syy150190 	e1000g_log(Adapter, CE_CONT,
4465082Syy150190 	    "PCI_CONF_MAX_L:\t0x%x\n",
4475082Syy150190 	    pci_config_get8(handle, PCI_CONF_MAX_L));
4485082Syy150190 
4495082Syy150190 	/* Power Management */
4505082Syy150190 	offset = cap_ptr;
4515082Syy150190 
4525082Syy150190 	e1000g_log(Adapter, CE_CONT,
4535082Syy150190 	    "PCI_PM_CAP_ID:\t0x%x\n",
4545082Syy150190 	    pci_config_get8(handle, offset));
4555082Syy150190 
4565082Syy150190 	next_ptr = pci_config_get8(handle, offset + 1);
4575082Syy150190 
4585082Syy150190 	e1000g_log(Adapter, CE_CONT,
4595082Syy150190 	    "PCI_PM_NEXT_PTR:\t0x%x\n", next_ptr);
4605082Syy150190 	e1000g_log(Adapter, CE_CONT,
4615082Syy150190 	    "PCI_PM_CAP:\t0x%x\n",
4625082Syy150190 	    pci_config_get16(handle, offset + PCI_PMCAP));
4635082Syy150190 	e1000g_log(Adapter, CE_CONT,
4645082Syy150190 	    "PCI_PM_CSR:\t0x%x\n",
4655082Syy150190 	    pci_config_get16(handle, offset + PCI_PMCSR));
4665082Syy150190 	e1000g_log(Adapter, CE_CONT,
4675082Syy150190 	    "PCI_PM_CSR_BSE:\t0x%x\n",
4685082Syy150190 	    pci_config_get8(handle, offset + PCI_PMCSR_BSE));
4695082Syy150190 	e1000g_log(Adapter, CE_CONT,
4705082Syy150190 	    "PCI_PM_DATA:\t0x%x\n",
4715082Syy150190 	    pci_config_get8(handle, offset + PCI_PMDATA));
4725082Syy150190 
4735082Syy150190 	/* MSI Configuration */
4745082Syy150190 	offset = next_ptr;
4755082Syy150190 
4765082Syy150190 	e1000g_log(Adapter, CE_CONT,
4775082Syy150190 	    "PCI_MSI_CAP_ID:\t0x%x\n",
4785082Syy150190 	    pci_config_get8(handle, offset));
4795082Syy150190 
4805082Syy150190 	next_ptr = pci_config_get8(handle, offset + 1);
4815082Syy150190 
4825082Syy150190 	e1000g_log(Adapter, CE_CONT,
4835082Syy150190 	    "PCI_MSI_NEXT_PTR:\t0x%x\n", next_ptr);
4845082Syy150190 	e1000g_log(Adapter, CE_CONT,
4855082Syy150190 	    "PCI_MSI_CTRL:\t0x%x\n",
4865082Syy150190 	    pci_config_get16(handle, offset + PCI_MSI_CTRL));
4875082Syy150190 	e1000g_log(Adapter, CE_CONT,
4885082Syy150190 	    "PCI_MSI_ADDR:\t0x%x\n",
4895082Syy150190 	    pci_config_get32(handle, offset + PCI_MSI_ADDR_OFFSET));
4905082Syy150190 	e1000g_log(Adapter, CE_CONT,
4915082Syy150190 	    "PCI_MSI_ADDR_HI:\t0x%x\n",
4925082Syy150190 	    pci_config_get32(handle, offset + 0x8));
4935082Syy150190 	e1000g_log(Adapter, CE_CONT,
4945082Syy150190 	    "PCI_MSI_DATA:\t0x%x\n",
4955082Syy150190 	    pci_config_get16(handle, offset + 0xC));
4965082Syy150190 
4975082Syy150190 	/* PCI Express Configuration */
4985082Syy150190 	offset = next_ptr;
4995082Syy150190 
5005082Syy150190 	e1000g_log(Adapter, CE_CONT,
5015082Syy150190 	    "PCIE_CAP_ID:\t0x%x\n",
5025082Syy150190 	    pci_config_get8(handle, offset + PCIE_CAP_ID));
5035082Syy150190 
5045082Syy150190 	next_ptr = pci_config_get8(handle, offset + PCIE_CAP_NEXT_PTR);
5055082Syy150190 
5065082Syy150190 	e1000g_log(Adapter, CE_CONT,
5075082Syy150190 	    "PCIE_CAP_NEXT_PTR:\t0x%x\n", next_ptr);
5085082Syy150190 	e1000g_log(Adapter, CE_CONT,
5095082Syy150190 	    "PCIE_PCIECAP:\t0x%x\n",
5105082Syy150190 	    pci_config_get16(handle, offset + PCIE_PCIECAP));
5115082Syy150190 	e1000g_log(Adapter, CE_CONT,
5125082Syy150190 	    "PCIE_DEVCAP:\t0x%x\n",
5135082Syy150190 	    pci_config_get32(handle, offset + PCIE_DEVCAP));
5145082Syy150190 	e1000g_log(Adapter, CE_CONT,
5155082Syy150190 	    "PCIE_DEVCTL:\t0x%x\n",
5165082Syy150190 	    pci_config_get16(handle, offset + PCIE_DEVCTL));
5175082Syy150190 	e1000g_log(Adapter, CE_CONT,
5185082Syy150190 	    "PCIE_DEVSTS:\t0x%x\n",
5195082Syy150190 	    pci_config_get16(handle, offset + PCIE_DEVSTS));
5205082Syy150190 	e1000g_log(Adapter, CE_CONT,
5215082Syy150190 	    "PCIE_LINKCAP:\t0x%x\n",
5225082Syy150190 	    pci_config_get32(handle, offset + PCIE_LINKCAP));
5235082Syy150190 	e1000g_log(Adapter, CE_CONT,
5245082Syy150190 	    "PCIE_LINKCTL:\t0x%x\n",
5255082Syy150190 	    pci_config_get16(handle, offset + PCIE_LINKCTL));
5265082Syy150190 	e1000g_log(Adapter, CE_CONT,
5275082Syy150190 	    "PCIE_LINKSTS:\t0x%x\n",
5285082Syy150190 	    pci_config_get16(handle, offset + PCIE_LINKSTS));
5295082Syy150190 }
530*6735Scc210113 
531*6735Scc210113 void
532*6735Scc210113 pciconfig_bar(void *instance, uint32_t offset, char *name)
533*6735Scc210113 {
534*6735Scc210113 	struct e1000g *Adapter = (struct e1000g *)instance;
535*6735Scc210113 	ddi_acc_handle_t handle = Adapter->osdep.cfg_handle;
536*6735Scc210113 	uint32_t base = pci_config_get32(handle, offset);
537*6735Scc210113 	uint16_t comm = pci_config_get16(handle, PCI_CONF_COMM);
538*6735Scc210113 	uint32_t size;		/* derived size of the region */
539*6735Scc210113 	uint32_t bits_comm;	/* command word bits to disable */
540*6735Scc210113 	uint32_t size_mask;	/* mask for size extraction */
541*6735Scc210113 	char tag_type[32];	/* tag to show memory vs. i/o */
542*6735Scc210113 	char tag_mem[32];	/* tag to show memory characteristiccs */
543*6735Scc210113 
544*6735Scc210113 	/* base address zero, simple print */
545*6735Scc210113 	if (base == 0) {
546*6735Scc210113 		e1000g_log(Adapter, CE_CONT, "%s:\t0x%x\n", name, base);
547*6735Scc210113 
548*6735Scc210113 	/* base address non-zero, get size */
549*6735Scc210113 	} else {
550*6735Scc210113 		/* i/o factors that decode from the base address */
551*6735Scc210113 		if (base & PCI_BASE_SPACE_IO) {
552*6735Scc210113 			bits_comm = PCI_COMM_IO;
553*6735Scc210113 			size_mask = PCI_BASE_IO_ADDR_M;
554*6735Scc210113 			strcpy(tag_type, "i/o port size:");
555*6735Scc210113 			strcpy(tag_mem, "");
556*6735Scc210113 		/* memory factors that decode from the base address */
557*6735Scc210113 		} else {
558*6735Scc210113 			bits_comm = PCI_COMM_MAE;
559*6735Scc210113 			size_mask = PCI_BASE_M_ADDR_M;
560*6735Scc210113 			strcpy(tag_type, "memory size:");
561*6735Scc210113 			if (base & PCI_BASE_TYPE_ALL)
562*6735Scc210113 				strcpy(tag_mem, "64bit ");
563*6735Scc210113 			else
564*6735Scc210113 				strcpy(tag_mem, "32bit ");
565*6735Scc210113 			if (base & PCI_BASE_PREF_M)
566*6735Scc210113 				strcat(tag_mem, "prefetchable");
567*6735Scc210113 			else
568*6735Scc210113 				strcat(tag_mem, "non-prefetchable");
569*6735Scc210113 		}
570*6735Scc210113 
571*6735Scc210113 		/* disable memory decode */
572*6735Scc210113 		pci_config_put16(handle, PCI_CONF_COMM, (comm & ~bits_comm));
573*6735Scc210113 
574*6735Scc210113 		/* write to base register */
575*6735Scc210113 		pci_config_put32(handle, offset, 0xffffffff);
576*6735Scc210113 
577*6735Scc210113 		/* read back & compute size */
578*6735Scc210113 		size = pci_config_get32(handle, offset);
579*6735Scc210113 		size &= size_mask;
580*6735Scc210113 		size = (~size) + 1;
581*6735Scc210113 
582*6735Scc210113 		/* restore base register */
583*6735Scc210113 		pci_config_put32(handle, offset, base);
584*6735Scc210113 
585*6735Scc210113 		/* re-enable memory decode */
586*6735Scc210113 		pci_config_put16(handle, PCI_CONF_COMM, comm);
587*6735Scc210113 
588*6735Scc210113 		/* print results */
589*6735Scc210113 		e1000g_log(Adapter, CE_CONT, "%s:\t0x%x %s 0x%x %s\n",
590*6735Scc210113 		    name, base, tag_type, size, tag_mem);
591*6735Scc210113 	}
592*6735Scc210113 }
5935082Syy150190 #endif
594