xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000g_debug.c (revision 10680:45bda3640f27)
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*10680SMin.Xu@Sun.COM  * Copyright(c) 1999 - 2009 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*10680SMin.Xu@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
233526Sxy150489  * Use is subject to license terms of the CDDLv1.
243526Sxy150489  */
253526Sxy150489 
263526Sxy150489 /*
273526Sxy150489  * **********************************************************************
283526Sxy150489  *									*
293526Sxy150489  * Module Name:								*
304919Sxy150489  * 	e1000g_debug.c							*
313526Sxy150489  *									*
323526Sxy150489  * Abstract:								*
334919Sxy150489  *	This module includes the debug routines				*
343526Sxy150489  *									*
353526Sxy150489  * **********************************************************************
363526Sxy150489  */
373526Sxy150489 #ifdef GCC
383526Sxy150489 #ifdef __STDC__
393526Sxy150489 #include <stdarg.h>
403526Sxy150489 #else
413526Sxy150489 #include <varargs.h>
423526Sxy150489 #endif
433526Sxy150489 #define	_SYS_VARARGS_H
443526Sxy150489 #endif
453526Sxy150489 
464919Sxy150489 #include "e1000g_debug.h"
473526Sxy150489 #include "e1000g_sw.h"
485082Syy150190 #ifdef E1000G_DEBUG
495082Syy150190 #include <sys/pcie.h>
505082Syy150190 #endif
514919Sxy150489 
524919Sxy150489 #ifdef E1000G_DEBUG
535082Syy150190 #define	WPL		8	/* 8 16-bit words per line */
546735Scc210113 #define	NUM_REGS	155	/* must match the array initializer */
555082Syy150190 typedef struct {
565082Syy150190 	char		name[10];
575082Syy150190 	uint32_t	offset;
585082Syy150190 } Regi_t;
59*10680SMin.Xu@Sun.COM 
604919Sxy150489 int e1000g_debug = E1000G_WARN_LEVEL;
61*10680SMin.Xu@Sun.COM #endif	/* E1000G_DEBUG */
624919Sxy150489 int e1000g_log_mode = E1000G_LOG_PRINT;
633526Sxy150489 
643526Sxy150489 void
e1000g_log(void * instance,int level,char * fmt,...)654919Sxy150489 e1000g_log(void *instance, int level, char *fmt, ...)
663526Sxy150489 {
674919Sxy150489 	struct e1000g *Adapter = (struct e1000g *)instance;
683526Sxy150489 	auto char name[NAMELEN];
693526Sxy150489 	auto char buf[BUFSZ];
703526Sxy150489 	va_list ap;
713526Sxy150489 
724919Sxy150489 	switch (level) {
734919Sxy150489 #ifdef E1000G_DEBUG
744919Sxy150489 	case E1000G_VERBOSE_LEVEL:	/* 16 or 0x010 */
754919Sxy150489 		if (e1000g_debug < E1000G_VERBOSE_LEVEL)
764919Sxy150489 			return;
774919Sxy150489 		level = CE_CONT;
784919Sxy150489 		break;
794919Sxy150489 
804919Sxy150489 	case E1000G_TRACE_LEVEL:	/* 8 or 0x008 */
814919Sxy150489 		if (e1000g_debug < E1000G_TRACE_LEVEL)
824919Sxy150489 			return;
834919Sxy150489 		level = CE_CONT;
844919Sxy150489 		break;
854919Sxy150489 
864919Sxy150489 	case E1000G_INFO_LEVEL:		/* 4 or 0x004 */
874919Sxy150489 		if (e1000g_debug < E1000G_INFO_LEVEL)
884919Sxy150489 			return;
894919Sxy150489 		level = CE_CONT;
904919Sxy150489 		break;
914919Sxy150489 
924919Sxy150489 	case E1000G_WARN_LEVEL:		/* 2 or 0x002 */
934919Sxy150489 		if (e1000g_debug < E1000G_WARN_LEVEL)
944919Sxy150489 			return;
954919Sxy150489 		level = CE_CONT;
964919Sxy150489 		break;
974919Sxy150489 
984919Sxy150489 	case E1000G_ERRS_LEVEL:		/* 1 or 0x001 */
994919Sxy150489 		level = CE_CONT;
1004919Sxy150489 		break;
1014919Sxy150489 #else
1024919Sxy150489 	case CE_CONT:
1034919Sxy150489 	case CE_NOTE:
1044919Sxy150489 	case CE_WARN:
1054919Sxy150489 	case CE_PANIC:
1064919Sxy150489 		break;
1074919Sxy150489 #endif
1084919Sxy150489 	default:
1094919Sxy150489 		level = CE_CONT;
1104919Sxy150489 		break;
1114919Sxy150489 	}
1124919Sxy150489 
1133526Sxy150489 	if (Adapter != NULL) {
1143526Sxy150489 		(void) sprintf(name, "%s - e1000g[%d] ",
1153526Sxy150489 		    ddi_get_name(Adapter->dip), ddi_get_instance(Adapter->dip));
1163526Sxy150489 	} else {
1173526Sxy150489 		(void) sprintf(name, "e1000g");
1183526Sxy150489 	}
1193526Sxy150489 	/*
1203526Sxy150489 	 * va_start uses built in macro __builtin_va_alist from the
1213526Sxy150489 	 * compiler libs which requires compiler system to have
1223526Sxy150489 	 * __BUILTIN_VA_ARG_INCR defined.
1233526Sxy150489 	 */
1243526Sxy150489 	/*
1253526Sxy150489 	 * Many compilation systems depend upon the use of special functions
1263526Sxy150489 	 * built into the the compilation system to handle variable argument
1273526Sxy150489 	 * lists and stack allocations.  The method to obtain this in SunOS
1283526Sxy150489 	 * is to define the feature test macro "__BUILTIN_VA_ARG_INCR" which
1293526Sxy150489 	 * enables the following special built-in functions:
1303526Sxy150489 	 *	__builtin_alloca
1313526Sxy150489 	 *	__builtin_va_alist
1323526Sxy150489 	 *	__builtin_va_arg_incr
1333526Sxy150489 	 * It is intended that the compilation system define this feature test
1343526Sxy150489 	 * macro, not the user of the system.
1353526Sxy150489 	 *
1363526Sxy150489 	 * The tests on the processor type are to provide a transitional period
1373526Sxy150489 	 * for existing compilation systems, and may be removed in a future
1383526Sxy150489 	 * release.
1393526Sxy150489 	 */
1403526Sxy150489 	/*
1413526Sxy150489 	 * Using GNU gcc compiler it doesn't expand to va_start....
1423526Sxy150489 	 */
1433526Sxy150489 	va_start(ap, fmt);
1443526Sxy150489 	(void) vsprintf(buf, fmt, ap);
1453526Sxy150489 	va_end(ap);
1463526Sxy150489 
1474919Sxy150489 	if ((e1000g_log_mode & E1000G_LOG_ALL) == E1000G_LOG_ALL)
1483526Sxy150489 		cmn_err(level, "%s: %s", name, buf);
1494919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_DISPLAY)
1504919Sxy150489 		cmn_err(level, "^%s: %s", name, buf);
1514919Sxy150489 	else if (e1000g_log_mode & E1000G_LOG_PRINT)
1524919Sxy150489 		cmn_err(level, "!%s: %s", name, buf);
1534919Sxy150489 	else /* if they are not set properly then do both */
1544919Sxy150489 		cmn_err(level, "%s: %s", name, buf);
1553526Sxy150489 }
1565082Syy150190 
1575082Syy150190 
1585082Syy150190 
1595082Syy150190 #ifdef E1000G_DEBUG
1607133Scc210113 extern kmutex_t e1000g_nvm_lock;
1617133Scc210113 
1625082Syy150190 void
eeprom_dump(void * instance)1635082Syy150190 eeprom_dump(void *instance)
1645082Syy150190 {
1655082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
1665082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
1675082Syy150190 	uint16_t eeprom[WPL], size_field;
1685082Syy150190 	int i, ret, sign, size, lines, offset = 0;
1695082Syy150190 	int ee_size[] =
1705082Syy150190 	    {128, 256, 512, 1024, 2048, 4096, 16 * 1024, 32 * 1024, 64 * 1024};
1715082Syy150190 
1727133Scc210113 	mutex_enter(&e1000g_nvm_lock);
1737133Scc210113 
1745082Syy150190 	if (ret = e1000_read_nvm(hw, 0x12, 1, &size_field)) {
1755082Syy150190 		e1000g_log(Adapter, CE_WARN,
1765082Syy150190 		    "e1000_read_nvm failed to read size: %d", ret);
1777133Scc210113 		goto eeprom_dump_end;
1785082Syy150190 	}
1795082Syy150190 
1805082Syy150190 	sign = (size_field & 0xc000) >> 14;
1815082Syy150190 	if (sign != 1) {
1825082Syy150190 		e1000g_log(Adapter, CE_WARN,
1835082Syy150190 		    "eeprom_dump invalid signature: %d", sign);
1845082Syy150190 	}
1855082Syy150190 
1865082Syy150190 	size = (size_field & 0x3c00) >> 10;
1875082Syy150190 	if (size < 0 || size > 11) {
1885082Syy150190 		e1000g_log(Adapter, CE_WARN,
1895082Syy150190 		    "eeprom_dump invalid size: %d", size);
1905082Syy150190 	}
1915082Syy150190 
1925082Syy150190 	e1000g_log(Adapter, CE_CONT,
1935082Syy150190 	    "eeprom_dump size field: %d  eeprom bytes: %d\n",
1945082Syy150190 	    size, ee_size[size]);
1955082Syy150190 
1965082Syy150190 	e1000g_log(Adapter, CE_CONT,
1975082Syy150190 	    "e1000_read_nvm hebs: %d\n", ((size_field & 0x000f) >> 10));
1985082Syy150190 
1995082Syy150190 	lines = ee_size[size] / WPL / 2;
2005082Syy150190 	e1000g_log(Adapter, CE_CONT,
2015082Syy150190 	    "dump eeprom %d lines of %d words per line\n", lines, WPL);
2025082Syy150190 
2035082Syy150190 	for (i = 0; i < lines; i++) {
2045082Syy150190 		if (ret = e1000_read_nvm(hw, offset, WPL, eeprom)) {
2055082Syy150190 			e1000g_log(Adapter, CE_WARN,
2065082Syy150190 			    "e1000_read_nvm failed: %d", ret);
2077133Scc210113 			goto eeprom_dump_end;
2085082Syy150190 		}
2095082Syy150190 
2105082Syy150190 		e1000g_log(Adapter, CE_CONT,
2115082Syy150190 		    "0x%04x    %04x %04x %04x %04x %04x %04x %04x %04x\n",
2125082Syy150190 		    offset,
2135082Syy150190 		    eeprom[0], eeprom[1], eeprom[2], eeprom[3],
2145082Syy150190 		    eeprom[4], eeprom[5], eeprom[6], eeprom[7]);
2155082Syy150190 		offset += WPL;
2165082Syy150190 	}
2177133Scc210113 
2187133Scc210113 eeprom_dump_end:
2197133Scc210113 	mutex_exit(&e1000g_nvm_lock);
2205082Syy150190 }
2215082Syy150190 
2225082Syy150190 /*
2235082Syy150190  * phy_dump - dump important phy registers
2245082Syy150190  */
2255082Syy150190 void
phy_dump(void * instance)2265082Syy150190 phy_dump(void *instance)
2275082Syy150190 {
2285082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
2295082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
2305082Syy150190 	/* offset to each phy register */
2315082Syy150190 	int32_t offset[] =
2325082Syy150190 	    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
2335082Syy150190 	    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2345082Syy150190 	    30, 31, 0x1796, 0x187A, 0x1895, 0x1F30, 0x1F35, 0x1F3E, 0x1F54,
2355082Syy150190 	    0x1F55, 0x1F56, 0x1F72, 0x1F76, 0x1F77, 0x1F78, 0x1F79, 0x1F98,
2365082Syy150190 	    0x2010, 0x2011, 0x20DC, 0x20DD, 0x20DE, 0x28B4, 0x2F52, 0x2F5B,
2375082Syy150190 	    0x2F70, 0x2F90, 0x2FB1, 0x2FB2 };
2385082Syy150190 	uint16_t value;	/* register value */
2395082Syy150190 	uint32_t stat;	/* status from e1000_read_phy_reg */
2405082Syy150190 	int i;
2415082Syy150190 
2425082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin PHY dump\n");
2435082Syy150190 	for (i = 0; i < ((sizeof (offset)) / sizeof (offset[0])); i++) {
2445082Syy150190 
2455082Syy150190 		stat = e1000_read_phy_reg(hw, offset[i], &value);
2465082Syy150190 		if (stat == 0) {
2475082Syy150190 			e1000g_log(Adapter, CE_CONT,
2485082Syy150190 			    "phyreg offset: %d   value: 0x%x\n",
2495082Syy150190 			    offset[i], value);
2505082Syy150190 		} else {
2515082Syy150190 			e1000g_log(Adapter, CE_WARN,
2525082Syy150190 			    "phyreg offset: %d   ERROR: 0x%x\n",
2535082Syy150190 			    offset[i], stat);
2545082Syy150190 		}
2555082Syy150190 	}
2565082Syy150190 }
2575082Syy150190 
2585082Syy150190 uint32_t
e1000_read_reg(struct e1000_hw * hw,uint32_t offset)2595082Syy150190 e1000_read_reg(struct e1000_hw *hw, uint32_t offset)
2605082Syy150190 {
2615082Syy150190 	return (ddi_get32(((struct e1000g_osdep *)(hw)->back)->reg_handle,
2627426SChenliang.Xu@Sun.COM 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + offset)));
2635082Syy150190 }
2645082Syy150190 
2655082Syy150190 
2665082Syy150190 /*
2675082Syy150190  * mac_dump - dump important mac registers
2685082Syy150190  */
2695082Syy150190 void
mac_dump(void * instance)2705082Syy150190 mac_dump(void *instance)
2715082Syy150190 {
2725082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
2735082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
2745082Syy150190 	int i;
2755082Syy150190 
2765082Syy150190 	/* {name, offset} for each mac register */
2775082Syy150190 	Regi_t macreg[NUM_REGS] = {
2785082Syy150190 	    {"CTRL",	E1000_CTRL},	{"STATUS",	E1000_STATUS},
2795082Syy150190 	    {"EECD",	E1000_EECD},	{"EERD",	E1000_EERD},
2805082Syy150190 	    {"CTRL_EXT", E1000_CTRL_EXT}, {"FLA",	E1000_FLA},
2815082Syy150190 	    {"MDIC",	E1000_MDIC},	{"SCTL",	E1000_SCTL},
2825082Syy150190 	    {"FCAL",	E1000_FCAL},	{"FCAH",	E1000_FCAH},
2835082Syy150190 	    {"FCT",	E1000_FCT},	{"VET",		E1000_VET},
2845082Syy150190 	    {"ICR",	E1000_ICR},	{"ITR",		E1000_ITR},
2855082Syy150190 	    {"ICS",	E1000_ICS},	{"IMS",		E1000_IMS},
2865082Syy150190 	    {"IMC",	E1000_IMC},	{"IAM",		E1000_IAM},
2875082Syy150190 	    {"RCTL",	E1000_RCTL},	{"FCTTV",	E1000_FCTTV},
2885082Syy150190 	    {"TXCW",	E1000_TXCW},	{"RXCW",	E1000_RXCW},
2895082Syy150190 	    {"TCTL",	E1000_TCTL},	{"TIPG",	E1000_TIPG},
2905082Syy150190 	    {"AIT",	E1000_AIT},	{"LEDCTL",	E1000_LEDCTL},
2915082Syy150190 	    {"PBA",	E1000_PBA},	{"PBS",		E1000_PBS},
2925082Syy150190 	    {"EEMNGCTL", E1000_EEMNGCTL}, {"ERT",	E1000_ERT},
2935082Syy150190 	    {"FCRTL",	E1000_FCRTL},	{"FCRTH",	E1000_FCRTH},
2946735Scc210113 	    {"PSRCTL",	E1000_PSRCTL},	{"RDBAL(0)",	E1000_RDBAL(0)},
2956735Scc210113 	    {"RDBAH(0)", E1000_RDBAH(0)}, {"RDLEN(0)",	E1000_RDLEN(0)},
2966735Scc210113 	    {"RDH(0)",	E1000_RDH(0)},	{"RDT(0)",	E1000_RDT(0)},
2976735Scc210113 	    {"RDTR",	E1000_RDTR},	{"RXDCTL(0)",	E1000_RXDCTL(0)},
2986735Scc210113 	    {"RADV",	E1000_RADV},	{"RDBAL(1)",	E1000_RDBAL(1)},
2996735Scc210113 	    {"RDBAH(1)", E1000_RDBAH(1)}, {"RDLEN(1)",	E1000_RDLEN(1)},
3006735Scc210113 	    {"RDH(1)",	E1000_RDH(1)},	{"RDT(1)",	E1000_RDT(1)},
3016735Scc210113 	    {"RXDCTL(1)", E1000_RXDCTL(1)}, {"RSRPD",	E1000_RSRPD},
3025082Syy150190 	    {"RAID",	E1000_RAID},	{"CPUVEC",	E1000_CPUVEC},
3035082Syy150190 	    {"TDFH",	E1000_TDFH},	{"TDFT",	E1000_TDFT},
3045082Syy150190 	    {"TDFHS",	E1000_TDFHS},	{"TDFTS",	E1000_TDFTS},
3056735Scc210113 	    {"TDFPC",	E1000_TDFPC},	{"TDBAL(0)",	E1000_TDBAL(0)},
3066735Scc210113 	    {"TDBAH(0)", E1000_TDBAH(0)}, {"TDLEN(0)",	E1000_TDLEN(0)},
3076735Scc210113 	    {"TDH(0)",	E1000_TDH(0)},	{"TDT(0)",	E1000_TDT(0)},
3086735Scc210113 	    {"TIDV",	E1000_TIDV},	{"TXDCTL(0)",	E1000_TXDCTL(0)},
3096735Scc210113 	    {"TADV",	E1000_TADV},	{"TARC(0)",	E1000_TARC(0)},
3106735Scc210113 	    {"TDBAL(1)", E1000_TDBAL(1)}, {"TDBAH(1)",	E1000_TDBAH(1)},
3116735Scc210113 	    {"TDLEN(1)", E1000_TDLEN(1)}, {"TDH(1)",	E1000_TDH(1)},
3126735Scc210113 	    {"TDT(1)",	E1000_TDT(1)},	{"TXDCTL(1)",	E1000_TXDCTL(1)},
3136735Scc210113 	    {"TARC(1)",	E1000_TARC(1)},	{"ALGNERRC",	E1000_ALGNERRC},
3145082Syy150190 	    {"RXERRC",	E1000_RXERRC},	{"MPC",		E1000_MPC},
3155082Syy150190 	    {"SCC",	E1000_SCC},	{"ECOL",	E1000_ECOL},
3165082Syy150190 	    {"MCC",	E1000_MCC},	{"LATECOL",	E1000_LATECOL},
3175082Syy150190 	    {"COLC",	E1000_COLC},	{"DC",		E1000_DC},
3185082Syy150190 	    {"TNCRS",	E1000_TNCRS},	{"SEC",		E1000_SEC},
3195082Syy150190 	    {"CEXTERR",	E1000_CEXTERR},	{"RLEC",	E1000_RLEC},
3205082Syy150190 	    {"XONRXC",	E1000_XONRXC},	{"XONTXC",	E1000_XONTXC},
3215082Syy150190 	    {"XOFFRXC",	E1000_XOFFRXC},	{"XOFFTXC",	E1000_XOFFTXC},
3225082Syy150190 	    {"FCRUC",	E1000_FCRUC},	{"PRC64",	E1000_PRC64},
3235082Syy150190 	    {"PRC127",	E1000_PRC127},	{"PRC255",	E1000_PRC255},
3245082Syy150190 	    {"PRC511",	E1000_PRC511},	{"PRC1023",	E1000_PRC1023},
3255082Syy150190 	    {"PRC1522",	E1000_PRC1522},	{"GPRC",	E1000_GPRC},
3265082Syy150190 	    {"BPRC",	E1000_BPRC},	{"MPRC",	E1000_MPRC},
3275082Syy150190 	    {"GPTC",	E1000_GPTC},	{"GORCL",	E1000_GORCL},
3285082Syy150190 	    {"GORCH",	E1000_GORCH},	{"GOTCL",	E1000_GOTCL},
3295082Syy150190 	    {"GOTCH",	E1000_GOTCH},	{"RNBC",	E1000_RNBC},
3305082Syy150190 	    {"RUC",	E1000_RUC},	{"RFC",		E1000_RFC},
3315082Syy150190 	    {"ROC",	E1000_ROC},	{"RJC",		E1000_RJC},
3325082Syy150190 	    {"MGTPRC",	E1000_MGTPRC},	{"MGTPDC",	E1000_MGTPDC},
3335082Syy150190 	    {"MGTPTC",	E1000_MGTPTC},	{"TORL",	E1000_TORL},
3345082Syy150190 	    {"TORH",	E1000_TORH},	{"TOTL",	E1000_TOTL},
3355082Syy150190 	    {"TOTH",	E1000_TOTH},	{"TPR",		E1000_TPR},
3365082Syy150190 	    {"TPT",	E1000_TPT},	{"PTC64",	E1000_PTC64},
3375082Syy150190 	    {"PTC127",	E1000_PTC127},	{"PTC255",	E1000_PTC255},
3385082Syy150190 	    {"PTC511",	E1000_PTC511},	{"PTC1023",	E1000_PTC1023},
3395082Syy150190 	    {"PTC1522",	E1000_PTC1522},	{"MPTC",	E1000_MPTC},
3405082Syy150190 	    {"BPTC",	E1000_BPTC},	{"TSCTC",	E1000_TSCTC},
3415082Syy150190 	    {"TSCTFC",	E1000_TSCTFC},	{"IAC",		E1000_IAC},
3425082Syy150190 	    {"ICRXPTC",	E1000_ICRXPTC},	{"ICRXATC",	E1000_ICRXATC},
3435082Syy150190 	    {"ICTXPTC",	E1000_ICTXPTC},	{"ICTXATC",	E1000_ICTXATC},
3445082Syy150190 	    {"ICTXQEC",	E1000_ICTXQEC},	{"ICTXQMTC",	E1000_ICTXQMTC},
3455082Syy150190 	    {"ICRXDMTC", E1000_ICRXDMTC}, {"ICRXOC",	E1000_ICRXOC},
3465082Syy150190 	    {"RXCSUM",	E1000_RXCSUM},	{"RFCTL",	E1000_RFCTL},
3475082Syy150190 	    {"WUC",	E1000_WUC},	{"WUFC",	E1000_WUFC},
3485082Syy150190 	    {"WUS",	E1000_WUS},	{"MRQC",	E1000_MRQC},
3495082Syy150190 	    {"MANC",	E1000_MANC},	{"IPAV",	E1000_IPAV},
3505082Syy150190 	    {"MANC2H",	E1000_MANC2H},	{"RSSIM",	E1000_RSSIM},
3515082Syy150190 	    {"RSSIR",	E1000_RSSIR},	{"WUPL",	E1000_WUPL},
3525082Syy150190 	    {"GCR",	E1000_GCR},	{"GSCL_1",	E1000_GSCL_1},
3535082Syy150190 	    {"GSCL_2",	E1000_GSCL_2},	{"GSCL_3",	E1000_GSCL_3},
3545082Syy150190 	    {"GSCL_4",	E1000_GSCL_4},	{"FACTPS",	E1000_FACTPS},
3555082Syy150190 	    {"FWSM",	E1000_FWSM},
3565082Syy150190 	};
3575082Syy150190 
3585082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin MAC dump\n");
3595082Syy150190 
3605082Syy150190 	for (i = 0; i < NUM_REGS; i++) {
3615082Syy150190 		e1000g_log(Adapter, CE_CONT,
3625082Syy150190 		    "macreg %10s offset: 0x%x   value: 0x%x\n",
3635082Syy150190 		    macreg[i].name, macreg[i].offset,
3645082Syy150190 		    e1000_read_reg(hw, macreg[i].offset));
3655082Syy150190 	}
3665082Syy150190 }
3675082Syy150190 
3685082Syy150190 void
pciconfig_dump(void * instance)3695082Syy150190 pciconfig_dump(void *instance)
3705082Syy150190 {
3715082Syy150190 	struct e1000g *Adapter = (struct e1000g *)instance;
3725082Syy150190 	ddi_acc_handle_t handle;
3735082Syy150190 	uint8_t cap_ptr;
3745082Syy150190 	uint8_t next_ptr;
3755082Syy150190 	off_t offset;
3765082Syy150190 
3775082Syy150190 	handle = Adapter->osdep.cfg_handle;
3785082Syy150190 
3795082Syy150190 	e1000g_log(Adapter, CE_CONT, "Begin dump PCI config space\n");
3805082Syy150190 
3815082Syy150190 	e1000g_log(Adapter, CE_CONT,
3825082Syy150190 	    "PCI_CONF_VENID:\t0x%x\n",
3835082Syy150190 	    pci_config_get16(handle, PCI_CONF_VENID));
3845082Syy150190 	e1000g_log(Adapter, CE_CONT,
3855082Syy150190 	    "PCI_CONF_DEVID:\t0x%x\n",
3865082Syy150190 	    pci_config_get16(handle, PCI_CONF_DEVID));
3875082Syy150190 	e1000g_log(Adapter, CE_CONT,
3885082Syy150190 	    "PCI_CONF_COMMAND:\t0x%x\n",
3895082Syy150190 	    pci_config_get16(handle, PCI_CONF_COMM));
3905082Syy150190 	e1000g_log(Adapter, CE_CONT,
3915082Syy150190 	    "PCI_CONF_STATUS:\t0x%x\n",
3925082Syy150190 	    pci_config_get16(handle, PCI_CONF_STAT));
3935082Syy150190 	e1000g_log(Adapter, CE_CONT,
3945082Syy150190 	    "PCI_CONF_REVID:\t0x%x\n",
3955082Syy150190 	    pci_config_get8(handle, PCI_CONF_REVID));
3965082Syy150190 	e1000g_log(Adapter, CE_CONT,
3975082Syy150190 	    "PCI_CONF_PROG_CLASS:\t0x%x\n",
3985082Syy150190 	    pci_config_get8(handle, PCI_CONF_PROGCLASS));
3995082Syy150190 	e1000g_log(Adapter, CE_CONT,
4005082Syy150190 	    "PCI_CONF_SUB_CLASS:\t0x%x\n",
4015082Syy150190 	    pci_config_get8(handle, PCI_CONF_SUBCLASS));
4025082Syy150190 	e1000g_log(Adapter, CE_CONT,
4035082Syy150190 	    "PCI_CONF_BAS_CLASS:\t0x%x\n",
4045082Syy150190 	    pci_config_get8(handle, PCI_CONF_BASCLASS));
4055082Syy150190 	e1000g_log(Adapter, CE_CONT,
4065082Syy150190 	    "PCI_CONF_CACHE_LINESZ:\t0x%x\n",
4075082Syy150190 	    pci_config_get8(handle, PCI_CONF_CACHE_LINESZ));
4085082Syy150190 	e1000g_log(Adapter, CE_CONT,
4095082Syy150190 	    "PCI_CONF_LATENCY_TIMER:\t0x%x\n",
4105082Syy150190 	    pci_config_get8(handle, PCI_CONF_LATENCY_TIMER));
4115082Syy150190 	e1000g_log(Adapter, CE_CONT,
4125082Syy150190 	    "PCI_CONF_HEADER_TYPE:\t0x%x\n",
4135082Syy150190 	    pci_config_get8(handle, PCI_CONF_HEADER));
4145082Syy150190 	e1000g_log(Adapter, CE_CONT,
4155082Syy150190 	    "PCI_CONF_BIST:\t0x%x\n",
4165082Syy150190 	    pci_config_get8(handle, PCI_CONF_BIST));
4176735Scc210113 
4186735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE0, "PCI_CONF_BASE0");
4196735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE1, "PCI_CONF_BASE1");
4206735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE2, "PCI_CONF_BASE2");
4216735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE3, "PCI_CONF_BASE3");
4226735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE4, "PCI_CONF_BASE4");
4236735Scc210113 	pciconfig_bar(Adapter, PCI_CONF_BASE5, "PCI_CONF_BASE5");
4246735Scc210113 
4255082Syy150190 	e1000g_log(Adapter, CE_CONT,
4265082Syy150190 	    "PCI_CONF_CIS:\t0x%x\n",
4275082Syy150190 	    pci_config_get32(handle, PCI_CONF_CIS));
4285082Syy150190 	e1000g_log(Adapter, CE_CONT,
4295082Syy150190 	    "PCI_CONF_SUBVENID:\t0x%x\n",
4305082Syy150190 	    pci_config_get16(handle, PCI_CONF_SUBVENID));
4315082Syy150190 	e1000g_log(Adapter, CE_CONT,
4325082Syy150190 	    "PCI_CONF_SUBSYSID:\t0x%x\n",
4335082Syy150190 	    pci_config_get16(handle, PCI_CONF_SUBSYSID));
4345082Syy150190 	e1000g_log(Adapter, CE_CONT,
4355082Syy150190 	    "PCI_CONF_ROM:\t0x%x\n",
4365082Syy150190 	    pci_config_get32(handle, PCI_CONF_ROM));
4375082Syy150190 
4385082Syy150190 	cap_ptr = pci_config_get8(handle, PCI_CONF_CAP_PTR);
4395082Syy150190 
4405082Syy150190 	e1000g_log(Adapter, CE_CONT,
4415082Syy150190 	    "PCI_CONF_CAP_PTR:\t0x%x\n", cap_ptr);
4425082Syy150190 	e1000g_log(Adapter, CE_CONT,
4435082Syy150190 	    "PCI_CONF_ILINE:\t0x%x\n",
4445082Syy150190 	    pci_config_get8(handle, PCI_CONF_ILINE));
4455082Syy150190 	e1000g_log(Adapter, CE_CONT,
4465082Syy150190 	    "PCI_CONF_IPIN:\t0x%x\n",
4475082Syy150190 	    pci_config_get8(handle, PCI_CONF_IPIN));
4485082Syy150190 	e1000g_log(Adapter, CE_CONT,
4495082Syy150190 	    "PCI_CONF_MIN_G:\t0x%x\n",
4505082Syy150190 	    pci_config_get8(handle, PCI_CONF_MIN_G));
4515082Syy150190 	e1000g_log(Adapter, CE_CONT,
4525082Syy150190 	    "PCI_CONF_MAX_L:\t0x%x\n",
4535082Syy150190 	    pci_config_get8(handle, PCI_CONF_MAX_L));
4545082Syy150190 
4555082Syy150190 	/* Power Management */
4565082Syy150190 	offset = cap_ptr;
4575082Syy150190 
4585082Syy150190 	e1000g_log(Adapter, CE_CONT,
4595082Syy150190 	    "PCI_PM_CAP_ID:\t0x%x\n",
4605082Syy150190 	    pci_config_get8(handle, offset));
4615082Syy150190 
4625082Syy150190 	next_ptr = pci_config_get8(handle, offset + 1);
4635082Syy150190 
4645082Syy150190 	e1000g_log(Adapter, CE_CONT,
4655082Syy150190 	    "PCI_PM_NEXT_PTR:\t0x%x\n", next_ptr);
4665082Syy150190 	e1000g_log(Adapter, CE_CONT,
4675082Syy150190 	    "PCI_PM_CAP:\t0x%x\n",
4685082Syy150190 	    pci_config_get16(handle, offset + PCI_PMCAP));
4695082Syy150190 	e1000g_log(Adapter, CE_CONT,
4705082Syy150190 	    "PCI_PM_CSR:\t0x%x\n",
4715082Syy150190 	    pci_config_get16(handle, offset + PCI_PMCSR));
4725082Syy150190 	e1000g_log(Adapter, CE_CONT,
4735082Syy150190 	    "PCI_PM_CSR_BSE:\t0x%x\n",
4745082Syy150190 	    pci_config_get8(handle, offset + PCI_PMCSR_BSE));
4755082Syy150190 	e1000g_log(Adapter, CE_CONT,
4765082Syy150190 	    "PCI_PM_DATA:\t0x%x\n",
4775082Syy150190 	    pci_config_get8(handle, offset + PCI_PMDATA));
4785082Syy150190 
4795082Syy150190 	/* MSI Configuration */
4805082Syy150190 	offset = next_ptr;
4815082Syy150190 
4825082Syy150190 	e1000g_log(Adapter, CE_CONT,
4835082Syy150190 	    "PCI_MSI_CAP_ID:\t0x%x\n",
4845082Syy150190 	    pci_config_get8(handle, offset));
4855082Syy150190 
4865082Syy150190 	next_ptr = pci_config_get8(handle, offset + 1);
4875082Syy150190 
4885082Syy150190 	e1000g_log(Adapter, CE_CONT,
4895082Syy150190 	    "PCI_MSI_NEXT_PTR:\t0x%x\n", next_ptr);
4905082Syy150190 	e1000g_log(Adapter, CE_CONT,
4915082Syy150190 	    "PCI_MSI_CTRL:\t0x%x\n",
4925082Syy150190 	    pci_config_get16(handle, offset + PCI_MSI_CTRL));
4935082Syy150190 	e1000g_log(Adapter, CE_CONT,
4945082Syy150190 	    "PCI_MSI_ADDR:\t0x%x\n",
4955082Syy150190 	    pci_config_get32(handle, offset + PCI_MSI_ADDR_OFFSET));
4965082Syy150190 	e1000g_log(Adapter, CE_CONT,
4975082Syy150190 	    "PCI_MSI_ADDR_HI:\t0x%x\n",
4985082Syy150190 	    pci_config_get32(handle, offset + 0x8));
4995082Syy150190 	e1000g_log(Adapter, CE_CONT,
5005082Syy150190 	    "PCI_MSI_DATA:\t0x%x\n",
5015082Syy150190 	    pci_config_get16(handle, offset + 0xC));
5025082Syy150190 
5035082Syy150190 	/* PCI Express Configuration */
5045082Syy150190 	offset = next_ptr;
5055082Syy150190 
5065082Syy150190 	e1000g_log(Adapter, CE_CONT,
5075082Syy150190 	    "PCIE_CAP_ID:\t0x%x\n",
5085082Syy150190 	    pci_config_get8(handle, offset + PCIE_CAP_ID));
5095082Syy150190 
5105082Syy150190 	next_ptr = pci_config_get8(handle, offset + PCIE_CAP_NEXT_PTR);
5115082Syy150190 
5125082Syy150190 	e1000g_log(Adapter, CE_CONT,
5135082Syy150190 	    "PCIE_CAP_NEXT_PTR:\t0x%x\n", next_ptr);
5145082Syy150190 	e1000g_log(Adapter, CE_CONT,
5155082Syy150190 	    "PCIE_PCIECAP:\t0x%x\n",
5165082Syy150190 	    pci_config_get16(handle, offset + PCIE_PCIECAP));
5175082Syy150190 	e1000g_log(Adapter, CE_CONT,
5185082Syy150190 	    "PCIE_DEVCAP:\t0x%x\n",
5195082Syy150190 	    pci_config_get32(handle, offset + PCIE_DEVCAP));
5205082Syy150190 	e1000g_log(Adapter, CE_CONT,
5215082Syy150190 	    "PCIE_DEVCTL:\t0x%x\n",
5225082Syy150190 	    pci_config_get16(handle, offset + PCIE_DEVCTL));
5235082Syy150190 	e1000g_log(Adapter, CE_CONT,
5245082Syy150190 	    "PCIE_DEVSTS:\t0x%x\n",
5255082Syy150190 	    pci_config_get16(handle, offset + PCIE_DEVSTS));
5265082Syy150190 	e1000g_log(Adapter, CE_CONT,
5275082Syy150190 	    "PCIE_LINKCAP:\t0x%x\n",
5285082Syy150190 	    pci_config_get32(handle, offset + PCIE_LINKCAP));
5295082Syy150190 	e1000g_log(Adapter, CE_CONT,
5305082Syy150190 	    "PCIE_LINKCTL:\t0x%x\n",
5315082Syy150190 	    pci_config_get16(handle, offset + PCIE_LINKCTL));
5325082Syy150190 	e1000g_log(Adapter, CE_CONT,
5335082Syy150190 	    "PCIE_LINKSTS:\t0x%x\n",
5345082Syy150190 	    pci_config_get16(handle, offset + PCIE_LINKSTS));
5355082Syy150190 }
5366735Scc210113 
5376735Scc210113 void
pciconfig_bar(void * instance,uint32_t offset,char * name)5386735Scc210113 pciconfig_bar(void *instance, uint32_t offset, char *name)
5396735Scc210113 {
5406735Scc210113 	struct e1000g *Adapter = (struct e1000g *)instance;
5416735Scc210113 	ddi_acc_handle_t handle = Adapter->osdep.cfg_handle;
5426735Scc210113 	uint32_t base = pci_config_get32(handle, offset);
5436735Scc210113 	uint16_t comm = pci_config_get16(handle, PCI_CONF_COMM);
5446735Scc210113 	uint32_t size;		/* derived size of the region */
5456735Scc210113 	uint32_t bits_comm;	/* command word bits to disable */
5466735Scc210113 	uint32_t size_mask;	/* mask for size extraction */
5476735Scc210113 	char tag_type[32];	/* tag to show memory vs. i/o */
5486735Scc210113 	char tag_mem[32];	/* tag to show memory characteristiccs */
5496735Scc210113 
5506735Scc210113 	/* base address zero, simple print */
5516735Scc210113 	if (base == 0) {
5526735Scc210113 		e1000g_log(Adapter, CE_CONT, "%s:\t0x%x\n", name, base);
5536735Scc210113 
5546735Scc210113 	/* base address non-zero, get size */
5556735Scc210113 	} else {
5566735Scc210113 		/* i/o factors that decode from the base address */
5576735Scc210113 		if (base & PCI_BASE_SPACE_IO) {
5586735Scc210113 			bits_comm = PCI_COMM_IO;
5596735Scc210113 			size_mask = PCI_BASE_IO_ADDR_M;
5607426SChenliang.Xu@Sun.COM 			(void) strcpy(tag_type, "i/o port size:");
5617426SChenliang.Xu@Sun.COM 			(void) strcpy(tag_mem, "");
5626735Scc210113 		/* memory factors that decode from the base address */
5636735Scc210113 		} else {
5646735Scc210113 			bits_comm = PCI_COMM_MAE;
5656735Scc210113 			size_mask = PCI_BASE_M_ADDR_M;
5667426SChenliang.Xu@Sun.COM 			(void) strcpy(tag_type, "memory size:");
5676735Scc210113 			if (base & PCI_BASE_TYPE_ALL)
5687426SChenliang.Xu@Sun.COM 				(void) strcpy(tag_mem, "64bit ");
5696735Scc210113 			else
5707426SChenliang.Xu@Sun.COM 				(void) strcpy(tag_mem, "32bit ");
5716735Scc210113 			if (base & PCI_BASE_PREF_M)
5727426SChenliang.Xu@Sun.COM 				(void) strcat(tag_mem, "prefetchable");
5736735Scc210113 			else
5747426SChenliang.Xu@Sun.COM 				(void) strcat(tag_mem, "non-prefetchable");
5756735Scc210113 		}
5766735Scc210113 
5776735Scc210113 		/* disable memory decode */
5786735Scc210113 		pci_config_put16(handle, PCI_CONF_COMM, (comm & ~bits_comm));
5796735Scc210113 
5806735Scc210113 		/* write to base register */
5816735Scc210113 		pci_config_put32(handle, offset, 0xffffffff);
5826735Scc210113 
5836735Scc210113 		/* read back & compute size */
5846735Scc210113 		size = pci_config_get32(handle, offset);
5856735Scc210113 		size &= size_mask;
5866735Scc210113 		size = (~size) + 1;
5876735Scc210113 
5886735Scc210113 		/* restore base register */
5896735Scc210113 		pci_config_put32(handle, offset, base);
5906735Scc210113 
5916735Scc210113 		/* re-enable memory decode */
5926735Scc210113 		pci_config_put16(handle, PCI_CONF_COMM, comm);
5936735Scc210113 
5946735Scc210113 		/* print results */
5956735Scc210113 		e1000g_log(Adapter, CE_CONT, "%s:\t0x%x %s 0x%x %s\n",
5966735Scc210113 		    name, base, tag_type, size, tag_mem);
5976735Scc210113 	}
5986735Scc210113 }
599*10680SMin.Xu@Sun.COM #endif	/* E1000G_DEBUG */
600