xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000g_main.c (revision 6986:1e7638a44ce6)
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  *
95882Syy150190  * 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 /*
225858Scc210113  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
236789Sam223141  * Use is subject to license terms.
243526Sxy150489  */
253526Sxy150489 
263526Sxy150489 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273526Sxy150489 
283526Sxy150489 /*
293526Sxy150489  * **********************************************************************
303526Sxy150489  *									*
313526Sxy150489  * Module Name:								*
323526Sxy150489  *   e1000g_main.c							*
333526Sxy150489  *									*
343526Sxy150489  * Abstract:								*
354919Sxy150489  *   This file contains the interface routines for the solaris OS.	*
364919Sxy150489  *   It has all DDI entry point routines and GLD entry point routines.	*
373526Sxy150489  *									*
384919Sxy150489  *   This file also contains routines that take care of initialization	*
394919Sxy150489  *   uninit routine and interrupt routine.				*
403526Sxy150489  *									*
413526Sxy150489  * **********************************************************************
423526Sxy150489  */
433526Sxy150489 
443526Sxy150489 #include <sys/dlpi.h>
453526Sxy150489 #include <sys/mac.h>
463526Sxy150489 #include "e1000g_sw.h"
473526Sxy150489 #include "e1000g_debug.h"
483526Sxy150489 
49*6986Smx205022 static char ident[] = "Intel PRO/1000 Ethernet 5.2.10";
503526Sxy150489 static char e1000g_string[] = "Intel(R) PRO/1000 Network Connection";
51*6986Smx205022 static char e1000g_version[] = "Driver Ver. 5.2.10";
523526Sxy150489 
533526Sxy150489 /*
543526Sxy150489  * Proto types for DDI entry points
553526Sxy150489  */
564919Sxy150489 static int e1000g_attach(dev_info_t *, ddi_attach_cmd_t);
574919Sxy150489 static int e1000g_detach(dev_info_t *, ddi_detach_cmd_t);
583526Sxy150489 
593526Sxy150489 /*
603526Sxy150489  * init and intr routines prototype
613526Sxy150489  */
624919Sxy150489 static int e1000g_resume(dev_info_t *);
634919Sxy150489 static int e1000g_suspend(dev_info_t *);
643526Sxy150489 static uint_t e1000g_intr_pciexpress(caddr_t);
653526Sxy150489 static uint_t e1000g_intr(caddr_t);
663526Sxy150489 static void e1000g_intr_work(struct e1000g *, uint32_t);
673526Sxy150489 #pragma inline(e1000g_intr_work)
685882Syy150190 static uint32_t e1000g_get_itr(uint32_t, uint32_t, uint32_t);
695882Syy150190 #pragma inline(e1000g_get_itr)
703526Sxy150489 static int e1000g_init(struct e1000g *);
714919Sxy150489 static int e1000g_start(struct e1000g *, boolean_t);
724919Sxy150489 static void e1000g_stop(struct e1000g *, boolean_t);
733526Sxy150489 static int e1000g_m_start(void *);
743526Sxy150489 static void e1000g_m_stop(void *);
753526Sxy150489 static int e1000g_m_promisc(void *, boolean_t);
763526Sxy150489 static boolean_t e1000g_m_getcapab(void *, mac_capab_t, void *);
773526Sxy150489 static int e1000g_m_unicst(void *, const uint8_t *);
783526Sxy150489 static int e1000g_m_unicst_add(void *, mac_multi_addr_t *);
793526Sxy150489 static int e1000g_m_unicst_remove(void *, mac_addr_slot_t);
803526Sxy150489 static int e1000g_m_unicst_modify(void *, mac_multi_addr_t *);
813526Sxy150489 static int e1000g_m_unicst_get(void *, mac_multi_addr_t *);
823526Sxy150489 static int e1000g_m_multicst(void *, boolean_t, const uint8_t *);
833526Sxy150489 static void e1000g_m_ioctl(void *, queue_t *, mblk_t *);
846394Scc210113 static int e1000g_m_setprop(void *, const char *, mac_prop_id_t,
856394Scc210113     uint_t, const void *);
866394Scc210113 static int e1000g_m_getprop(void *, const char *, mac_prop_id_t,
876512Ssowmini     uint_t, uint_t, void *);
886394Scc210113 static int e1000g_set_priv_prop(struct e1000g *, const char *, uint_t,
896394Scc210113     const void *);
906394Scc210113 static int e1000g_get_priv_prop(struct e1000g *, const char *, uint_t,
916512Ssowmini     uint_t, void *);
924919Sxy150489 static void e1000g_init_locks(struct e1000g *);
934919Sxy150489 static void e1000g_destroy_locks(struct e1000g *);
944919Sxy150489 static int e1000g_identify_hardware(struct e1000g *);
954919Sxy150489 static int e1000g_regs_map(struct e1000g *);
964919Sxy150489 static int e1000g_set_driver_params(struct e1000g *);
976394Scc210113 static void e1000g_set_bufsize(struct e1000g *);
984919Sxy150489 static int e1000g_register_mac(struct e1000g *);
994919Sxy150489 static boolean_t e1000g_rx_drain(struct e1000g *);
1004919Sxy150489 static boolean_t e1000g_tx_drain(struct e1000g *);
1014919Sxy150489 static void e1000g_init_unicst(struct e1000g *);
1023526Sxy150489 static int e1000g_unicst_set(struct e1000g *, const uint8_t *, mac_addr_slot_t);
1033526Sxy150489 
1043526Sxy150489 /*
1053526Sxy150489  * Local routines
1063526Sxy150489  */
1074919Sxy150489 static void e1000g_tx_clean(struct e1000g *);
1084919Sxy150489 static void e1000g_rx_clean(struct e1000g *);
1094061Sxy150489 static void e1000g_link_timer(void *);
1104919Sxy150489 static void e1000g_local_timer(void *);
1114061Sxy150489 static boolean_t e1000g_link_check(struct e1000g *);
1123526Sxy150489 static boolean_t e1000g_stall_check(struct e1000g *);
1133526Sxy150489 static void e1000g_smartspeed(struct e1000g *);
1144919Sxy150489 static void e1000g_get_conf(struct e1000g *);
1154919Sxy150489 static int e1000g_get_prop(struct e1000g *, char *, int, int, int);
1164919Sxy150489 static void enable_watchdog_timer(struct e1000g *);
1174919Sxy150489 static void disable_watchdog_timer(struct e1000g *);
1184919Sxy150489 static void start_watchdog_timer(struct e1000g *);
1194919Sxy150489 static void restart_watchdog_timer(struct e1000g *);
1204919Sxy150489 static void stop_watchdog_timer(struct e1000g *);
1214919Sxy150489 static void stop_link_timer(struct e1000g *);
1224919Sxy150489 static void stop_82547_timer(e1000g_tx_ring_t *);
1234919Sxy150489 static void e1000g_force_speed_duplex(struct e1000g *);
1244919Sxy150489 static void e1000g_get_max_frame_size(struct e1000g *);
1254919Sxy150489 static boolean_t is_valid_mac_addr(uint8_t *);
1263526Sxy150489 static void e1000g_unattach(dev_info_t *, struct e1000g *);
1274919Sxy150489 #ifdef E1000G_DEBUG
1284919Sxy150489 static void e1000g_ioc_peek_reg(struct e1000g *, e1000g_peekpoke_t *);
1294919Sxy150489 static void e1000g_ioc_poke_reg(struct e1000g *, e1000g_peekpoke_t *);
1304919Sxy150489 static void e1000g_ioc_peek_mem(struct e1000g *, e1000g_peekpoke_t *);
1314919Sxy150489 static void e1000g_ioc_poke_mem(struct e1000g *, e1000g_peekpoke_t *);
1324919Sxy150489 static enum ioc_reply e1000g_pp_ioctl(struct e1000g *,
1334919Sxy150489     struct iocblk *, mblk_t *);
1344919Sxy150489 #endif
1354919Sxy150489 static enum ioc_reply e1000g_loopback_ioctl(struct e1000g *,
1364919Sxy150489     struct iocblk *, mblk_t *);
1374919Sxy150489 static boolean_t e1000g_set_loopback_mode(struct e1000g *, uint32_t);
1384919Sxy150489 static void e1000g_set_internal_loopback(struct e1000g *);
1394919Sxy150489 static void e1000g_set_external_loopback_1000(struct e1000g *);
1404919Sxy150489 static void e1000g_set_external_loopback_100(struct e1000g *);
1414919Sxy150489 static void e1000g_set_external_loopback_10(struct e1000g *);
1424919Sxy150489 static int e1000g_add_intrs(struct e1000g *);
1434919Sxy150489 static int e1000g_intr_add(struct e1000g *, int);
1444919Sxy150489 static int e1000g_rem_intrs(struct e1000g *);
1454919Sxy150489 static int e1000g_enable_intrs(struct e1000g *);
1464919Sxy150489 static int e1000g_disable_intrs(struct e1000g *);
1474919Sxy150489 static boolean_t e1000g_link_up(struct e1000g *);
1483526Sxy150489 #ifdef __sparc
1494919Sxy150489 static boolean_t e1000g_find_mac_address(struct e1000g *);
1503526Sxy150489 #endif
1515082Syy150190 static void e1000g_get_phy_state(struct e1000g *);
1524982Syy150190 static void e1000g_free_priv_devi_node(struct e1000g *, boolean_t);
1535273Sgl147354 static int e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
1545273Sgl147354     const void *impl_data);
1555273Sgl147354 static void e1000g_fm_init(struct e1000g *Adapter);
1565273Sgl147354 static void e1000g_fm_fini(struct e1000g *Adapter);
1576512Ssowmini static int e1000g_get_def_val(struct e1000g *, mac_prop_id_t, uint_t, void *);
1586512Ssowmini static void e1000g_param_sync(struct e1000g *);
1596512Ssowmini 
1606512Ssowmini mac_priv_prop_t e1000g_priv_props[] = {
1616512Ssowmini 	{"_tx_bcopy_threshold", MAC_PROP_PERM_RW},
1626512Ssowmini 	{"_tx_interrupt_enable", MAC_PROP_PERM_RW},
1636512Ssowmini 	{"_tx_intr_delay", MAC_PROP_PERM_RW},
1646512Ssowmini 	{"_tx_intr_abs_delay", MAC_PROP_PERM_RW},
1656512Ssowmini 	{"_rx_bcopy_threshold", MAC_PROP_PERM_RW},
1666512Ssowmini 	{"_max_num_rcv_packets", MAC_PROP_PERM_RW},
1676512Ssowmini 	{"_rx_intr_delay", MAC_PROP_PERM_RW},
1686512Ssowmini 	{"_rx_intr_abs_delay", MAC_PROP_PERM_RW},
1696512Ssowmini 	{"_intr_throttling_rate", MAC_PROP_PERM_RW},
1706512Ssowmini 	{"_intr_adaptive", MAC_PROP_PERM_RW},
1716512Ssowmini 	{"_tx_recycle_thresh", MAC_PROP_PERM_RW},
1726512Ssowmini 	{"_adv_pause_cap", MAC_PROP_PERM_READ},
1736512Ssowmini 	{"_adv_asym_pause_cap", MAC_PROP_PERM_READ},
1746512Ssowmini 	{"_tx_recycle_num", MAC_PROP_PERM_RW}
1756512Ssowmini };
1766512Ssowmini #define	E1000G_MAX_PRIV_PROPS	\
1776512Ssowmini 	(sizeof (e1000g_priv_props)/sizeof (mac_priv_prop_t))
1786512Ssowmini 
1793526Sxy150489 
1803526Sxy150489 static struct cb_ops cb_ws_ops = {
1813526Sxy150489 	nulldev,		/* cb_open */
1823526Sxy150489 	nulldev,		/* cb_close */
1833526Sxy150489 	nodev,			/* cb_strategy */
1843526Sxy150489 	nodev,			/* cb_print */
1853526Sxy150489 	nodev,			/* cb_dump */
1863526Sxy150489 	nodev,			/* cb_read */
1873526Sxy150489 	nodev,			/* cb_write */
1883526Sxy150489 	nodev,			/* cb_ioctl */
1893526Sxy150489 	nodev,			/* cb_devmap */
1903526Sxy150489 	nodev,			/* cb_mmap */
1913526Sxy150489 	nodev,			/* cb_segmap */
1923526Sxy150489 	nochpoll,		/* cb_chpoll */
1933526Sxy150489 	ddi_prop_op,		/* cb_prop_op */
1943526Sxy150489 	NULL,			/* cb_stream */
1953526Sxy150489 	D_MP | D_HOTPLUG,	/* cb_flag */
1963526Sxy150489 	CB_REV,			/* cb_rev */
1973526Sxy150489 	nodev,			/* cb_aread */
1983526Sxy150489 	nodev			/* cb_awrite */
1993526Sxy150489 };
2003526Sxy150489 
2013526Sxy150489 static struct dev_ops ws_ops = {
2023526Sxy150489 	DEVO_REV,		/* devo_rev */
2033526Sxy150489 	0,			/* devo_refcnt */
2043526Sxy150489 	NULL,			/* devo_getinfo */
2053526Sxy150489 	nulldev,		/* devo_identify */
2063526Sxy150489 	nulldev,		/* devo_probe */
2074919Sxy150489 	e1000g_attach,		/* devo_attach */
2084919Sxy150489 	e1000g_detach,		/* devo_detach */
2093526Sxy150489 	nodev,			/* devo_reset */
2103526Sxy150489 	&cb_ws_ops,		/* devo_cb_ops */
2113526Sxy150489 	NULL,			/* devo_bus_ops */
2123526Sxy150489 	ddi_power		/* devo_power */
2133526Sxy150489 };
2143526Sxy150489 
2153526Sxy150489 static struct modldrv modldrv = {
2163526Sxy150489 	&mod_driverops,		/* Type of module.  This one is a driver */
2173526Sxy150489 	ident,			/* Discription string */
2183526Sxy150489 	&ws_ops,		/* driver ops */
2193526Sxy150489 };
2203526Sxy150489 
2213526Sxy150489 static struct modlinkage modlinkage = {
2223526Sxy150489 	MODREV_1, &modldrv, NULL
2233526Sxy150489 };
2243526Sxy150489 
2254919Sxy150489 /* Access attributes for register mapping */
2264919Sxy150489 static ddi_device_acc_attr_t e1000g_regs_acc_attr = {
2273526Sxy150489 	DDI_DEVICE_ATTR_V0,
2283526Sxy150489 	DDI_STRUCTURE_LE_ACC,
2293526Sxy150489 	DDI_STRICTORDER_ACC,
2305273Sgl147354 	DDI_FLAGERR_ACC
2313526Sxy150489 };
2323526Sxy150489 
2336394Scc210113 #define	E1000G_M_CALLBACK_FLAGS \
2346394Scc210113 	(MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP)
2353526Sxy150489 
2363526Sxy150489 static mac_callbacks_t e1000g_m_callbacks = {
2373526Sxy150489 	E1000G_M_CALLBACK_FLAGS,
2383526Sxy150489 	e1000g_m_stat,
2393526Sxy150489 	e1000g_m_start,
2403526Sxy150489 	e1000g_m_stop,
2413526Sxy150489 	e1000g_m_promisc,
2423526Sxy150489 	e1000g_m_multicst,
2433526Sxy150489 	e1000g_m_unicst,
2443526Sxy150489 	e1000g_m_tx,
2455882Syy150190 	NULL,
2463526Sxy150489 	e1000g_m_ioctl,
2476394Scc210113 	e1000g_m_getcapab,
2486394Scc210113 	NULL,
2496394Scc210113 	NULL,
2506394Scc210113 	e1000g_m_setprop,
2516394Scc210113 	e1000g_m_getprop
2523526Sxy150489 };
2533526Sxy150489 
2543526Sxy150489 /*
2553526Sxy150489  * Global variables
2563526Sxy150489  */
2573526Sxy150489 uint32_t e1000g_mblks_pending = 0;
2583526Sxy150489 /*
2594894Syy150190  * Workaround for Dynamic Reconfiguration support, for x86 platform only.
2604349Sxy150489  * Here we maintain a private dev_info list if e1000g_force_detach is
2614349Sxy150489  * enabled. If we force the driver to detach while there are still some
2624349Sxy150489  * rx buffers retained in the upper layer, we have to keep a copy of the
2634349Sxy150489  * dev_info. In some cases (Dynamic Reconfiguration), the dev_info data
2644349Sxy150489  * structure will be freed after the driver is detached. However when we
2654349Sxy150489  * finally free those rx buffers released by the upper layer, we need to
2664349Sxy150489  * refer to the dev_info to free the dma buffers. So we save a copy of
2674894Syy150190  * the dev_info for this purpose. On x86 platform, we assume this copy
2684894Syy150190  * of dev_info is always valid, but on SPARC platform, it could be invalid
2694894Syy150190  * after the system board level DR operation. For this reason, the global
2704894Syy150190  * variable e1000g_force_detach must be B_FALSE on SPARC platform.
2714349Sxy150489  */
2724894Syy150190 #ifdef __sparc
2734894Syy150190 boolean_t e1000g_force_detach = B_FALSE;
2744894Syy150190 #else
2754894Syy150190 boolean_t e1000g_force_detach = B_TRUE;
2764894Syy150190 #endif
2774349Sxy150489 private_devi_list_t *e1000g_private_devi_list = NULL;
2784894Syy150190 
2794349Sxy150489 /*
2803526Sxy150489  * The rwlock is defined to protect the whole processing of rx recycling
2813526Sxy150489  * and the rx packets release in detach processing to make them mutually
2823526Sxy150489  * exclusive.
2833526Sxy150489  * The rx recycling processes different rx packets in different threads,
2843526Sxy150489  * so it will be protected with RW_READER and it won't block any other rx
2853526Sxy150489  * recycling threads.
2863526Sxy150489  * While the detach processing will be protected with RW_WRITER to make
2873526Sxy150489  * it mutually exclusive with the rx recycling.
2883526Sxy150489  */
2893526Sxy150489 krwlock_t e1000g_rx_detach_lock;
2903526Sxy150489 /*
2913526Sxy150489  * The rwlock e1000g_dma_type_lock is defined to protect the global flag
2923526Sxy150489  * e1000g_dma_type. For SPARC, the initial value of the flag is "USE_DVMA".
2933526Sxy150489  * If there are many e1000g instances, the system may run out of DVMA
2943526Sxy150489  * resources during the initialization of the instances, then the flag will
2953526Sxy150489  * be changed to "USE_DMA". Because different e1000g instances are initialized
2963526Sxy150489  * in parallel, we need to use this lock to protect the flag.
2973526Sxy150489  */
2983526Sxy150489 krwlock_t e1000g_dma_type_lock;
2993526Sxy150489 
3003526Sxy150489 
3013526Sxy150489 /*
3023526Sxy150489  * Loadable module configuration entry points for the driver
3033526Sxy150489  */
3043526Sxy150489 
3053526Sxy150489 /*
3064919Sxy150489  * _init - module initialization
3073526Sxy150489  */
3083526Sxy150489 int
3093526Sxy150489 _init(void)
3103526Sxy150489 {
3113526Sxy150489 	int status;
3123526Sxy150489 
3133526Sxy150489 	mac_init_ops(&ws_ops, WSNAME);
3143526Sxy150489 	status = mod_install(&modlinkage);
3153526Sxy150489 	if (status != DDI_SUCCESS)
3163526Sxy150489 		mac_fini_ops(&ws_ops);
3173526Sxy150489 	else {
3183526Sxy150489 		rw_init(&e1000g_rx_detach_lock, NULL, RW_DRIVER, NULL);
3193526Sxy150489 		rw_init(&e1000g_dma_type_lock, NULL, RW_DRIVER, NULL);
3203526Sxy150489 	}
3213526Sxy150489 
3223526Sxy150489 	return (status);
3233526Sxy150489 }
3243526Sxy150489 
3253526Sxy150489 /*
3264919Sxy150489  * _fini - module finalization
3273526Sxy150489  */
3283526Sxy150489 int
3293526Sxy150489 _fini(void)
3303526Sxy150489 {
3313526Sxy150489 	int status;
3323526Sxy150489 
3333526Sxy150489 	rw_enter(&e1000g_rx_detach_lock, RW_READER);
3343526Sxy150489 	if (e1000g_mblks_pending != 0) {
3353526Sxy150489 		rw_exit(&e1000g_rx_detach_lock);
3363526Sxy150489 		return (EBUSY);
3373526Sxy150489 	}
3383526Sxy150489 	rw_exit(&e1000g_rx_detach_lock);
3393526Sxy150489 
3403526Sxy150489 	status = mod_remove(&modlinkage);
3413526Sxy150489 	if (status == DDI_SUCCESS) {
3423526Sxy150489 		mac_fini_ops(&ws_ops);
3434349Sxy150489 
3444349Sxy150489 		if (e1000g_force_detach) {
3454349Sxy150489 			private_devi_list_t *devi_node;
3464349Sxy150489 
3474349Sxy150489 			rw_enter(&e1000g_rx_detach_lock, RW_WRITER);
3484349Sxy150489 			while (e1000g_private_devi_list != NULL) {
3494349Sxy150489 				devi_node = e1000g_private_devi_list;
3504349Sxy150489 				e1000g_private_devi_list =
3514349Sxy150489 				    e1000g_private_devi_list->next;
3524349Sxy150489 
3534349Sxy150489 				kmem_free(devi_node->priv_dip,
3544349Sxy150489 				    sizeof (struct dev_info));
3554349Sxy150489 				kmem_free(devi_node,
3564349Sxy150489 				    sizeof (private_devi_list_t));
3574349Sxy150489 			}
3584349Sxy150489 			rw_exit(&e1000g_rx_detach_lock);
3594349Sxy150489 		}
3604349Sxy150489 
3613526Sxy150489 		rw_destroy(&e1000g_rx_detach_lock);
3623526Sxy150489 		rw_destroy(&e1000g_dma_type_lock);
3633526Sxy150489 	}
3643526Sxy150489 
3653526Sxy150489 	return (status);
3663526Sxy150489 }
3673526Sxy150489 
3683526Sxy150489 /*
3694919Sxy150489  * _info - module information
3703526Sxy150489  */
3713526Sxy150489 int
3723526Sxy150489 _info(struct modinfo *modinfop)
3733526Sxy150489 {
3743526Sxy150489 	return (mod_info(&modlinkage, modinfop));
3753526Sxy150489 }
3763526Sxy150489 
3773526Sxy150489 /*
3784919Sxy150489  * e1000g_attach - driver attach
3794919Sxy150489  *
3804919Sxy150489  * This function is the device-specific initialization entry
3814919Sxy150489  * point. This entry point is required and must be written.
3824919Sxy150489  * The DDI_ATTACH command must be provided in the attach entry
3834919Sxy150489  * point. When attach() is called with cmd set to DDI_ATTACH,
3844919Sxy150489  * all normal kernel services (such as kmem_alloc(9F)) are
3854919Sxy150489  * available for use by the driver.
3864919Sxy150489  *
3874919Sxy150489  * The attach() function will be called once for each instance
3884919Sxy150489  * of  the  device  on  the  system with cmd set to DDI_ATTACH.
3894919Sxy150489  * Until attach() succeeds, the only driver entry points which
3904919Sxy150489  * may be called are open(9E) and getinfo(9E).
3913526Sxy150489  */
3923526Sxy150489 static int
3934919Sxy150489 e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
3943526Sxy150489 {
3953526Sxy150489 	struct e1000g *Adapter;
3963526Sxy150489 	struct e1000_hw *hw;
3974919Sxy150489 	struct e1000g_osdep *osdep;
3983526Sxy150489 	int instance;
3993526Sxy150489 
4003526Sxy150489 	switch (cmd) {
4013526Sxy150489 	default:
4023526Sxy150489 		e1000g_log(NULL, CE_WARN,
4034919Sxy150489 		    "Unsupported command send to e1000g_attach... ");
4043526Sxy150489 		return (DDI_FAILURE);
4053526Sxy150489 
4063526Sxy150489 	case DDI_RESUME:
4073526Sxy150489 		return (e1000g_resume(devinfo));
4083526Sxy150489 
4093526Sxy150489 	case DDI_ATTACH:
4103526Sxy150489 		break;
4113526Sxy150489 	}
4123526Sxy150489 
4133526Sxy150489 	/*
4143526Sxy150489 	 * get device instance number
4153526Sxy150489 	 */
4163526Sxy150489 	instance = ddi_get_instance(devinfo);
4173526Sxy150489 
4183526Sxy150489 	/*
4193526Sxy150489 	 * Allocate soft data structure
4203526Sxy150489 	 */
4213526Sxy150489 	Adapter =
4223526Sxy150489 	    (struct e1000g *)kmem_zalloc(sizeof (*Adapter), KM_SLEEP);
4233526Sxy150489 
4243526Sxy150489 	Adapter->dip = devinfo;
4254919Sxy150489 	Adapter->instance = instance;
4263526Sxy150489 	Adapter->tx_ring->adapter = Adapter;
4273526Sxy150489 	Adapter->rx_ring->adapter = Adapter;
4283526Sxy150489 
4294919Sxy150489 	hw = &Adapter->shared;
4304919Sxy150489 	osdep = &Adapter->osdep;
4314919Sxy150489 	hw->back = osdep;
4324919Sxy150489 	osdep->adapter = Adapter;
4334919Sxy150489 
4343526Sxy150489 	ddi_set_driver_private(devinfo, (caddr_t)Adapter);
4353526Sxy150489 
4364919Sxy150489 	/*
4375273Sgl147354 	 * Initialize for fma support
4385273Sgl147354 	 */
4395273Sgl147354 	Adapter->fm_capabilities = e1000g_get_prop(Adapter, "fm-capable",
4405273Sgl147354 	    0, 0x0f,
4415273Sgl147354 	    DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE |
4425273Sgl147354 	    DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE);
4435273Sgl147354 	e1000g_fm_init(Adapter);
4445273Sgl147354 	Adapter->attach_progress |= ATTACH_PROGRESS_FMINIT;
4455273Sgl147354 
4465273Sgl147354 	/*
4474919Sxy150489 	 * PCI Configure
4484919Sxy150489 	 */
4494919Sxy150489 	if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) {
4504919Sxy150489 		e1000g_log(Adapter, CE_WARN, "PCI configuration failed");
4514919Sxy150489 		goto attach_fail;
4524919Sxy150489 	}
4534919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG;
4544919Sxy150489 
4554919Sxy150489 	/*
4564919Sxy150489 	 * Setup hardware
4574919Sxy150489 	 */
4584919Sxy150489 	if (e1000g_identify_hardware(Adapter) != DDI_SUCCESS) {
4594919Sxy150489 		e1000g_log(Adapter, CE_WARN, "Identify hardware failed");
4604919Sxy150489 		goto attach_fail;
4614919Sxy150489 	}
4623526Sxy150489 
4633526Sxy150489 	/*
4643526Sxy150489 	 * Map in the device registers.
4653526Sxy150489 	 */
4664919Sxy150489 	if (e1000g_regs_map(Adapter) != DDI_SUCCESS) {
4674919Sxy150489 		e1000g_log(Adapter, CE_WARN, "Mapping registers failed");
4683526Sxy150489 		goto attach_fail;
4693526Sxy150489 	}
4704919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_REGS_MAP;
4713526Sxy150489 
4723526Sxy150489 	/*
4733526Sxy150489 	 * Initialize driver parameters
4743526Sxy150489 	 */
4753526Sxy150489 	if (e1000g_set_driver_params(Adapter) != DDI_SUCCESS) {
4763526Sxy150489 		goto attach_fail;
4773526Sxy150489 	}
4784919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_SETUP;
4793526Sxy150489 
4805273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) {
4815273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
4825273Sgl147354 		goto attach_fail;
4835273Sgl147354 	}
4845273Sgl147354 
4853526Sxy150489 	/*
4863526Sxy150489 	 * Initialize interrupts
4873526Sxy150489 	 */
4883526Sxy150489 	if (e1000g_add_intrs(Adapter) != DDI_SUCCESS) {
4893526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Add interrupts failed");
4903526Sxy150489 		goto attach_fail;
4913526Sxy150489 	}
4924919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_ADD_INTR;
4933526Sxy150489 
4943526Sxy150489 	/*
4953526Sxy150489 	 * Initialize mutex's for this device.
4963526Sxy150489 	 * Do this before enabling the interrupt handler and
4973526Sxy150489 	 * register the softint to avoid the condition where
4983526Sxy150489 	 * interrupt handler can try using uninitialized mutex
4993526Sxy150489 	 */
5003526Sxy150489 	e1000g_init_locks(Adapter);
5013526Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_LOCKS;
5023526Sxy150489 
5033526Sxy150489 	/*
5043526Sxy150489 	 * Initialize Driver Counters
5053526Sxy150489 	 */
5064919Sxy150489 	if (e1000g_init_stats(Adapter) != DDI_SUCCESS) {
5073526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Init stats failed");
5083526Sxy150489 		goto attach_fail;
5093526Sxy150489 	}
5103526Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_KSTATS;
5113526Sxy150489 
5123526Sxy150489 	/*
5133526Sxy150489 	 * Initialize chip hardware and software structures
5143526Sxy150489 	 */
5153526Sxy150489 	if (e1000g_init(Adapter) != DDI_SUCCESS) {
5163526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Adapter initialization failed");
5173526Sxy150489 		goto attach_fail;
5183526Sxy150489 	}
5193526Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_INIT;
5203526Sxy150489 
5213526Sxy150489 	/*
5223526Sxy150489 	 * Register the driver to the MAC
5233526Sxy150489 	 */
5243526Sxy150489 	if (e1000g_register_mac(Adapter) != DDI_SUCCESS) {
5253526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Register MAC failed");
5263526Sxy150489 		goto attach_fail;
5273526Sxy150489 	}
5284919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_MAC;
5293526Sxy150489 
5303526Sxy150489 	/*
5313526Sxy150489 	 * Now that mutex locks are initialized, and the chip is also
5323526Sxy150489 	 * initialized, enable interrupts.
5333526Sxy150489 	 */
5343526Sxy150489 	if (e1000g_enable_intrs(Adapter) != DDI_SUCCESS) {
5353526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Enable DDI interrupts failed");
5363526Sxy150489 		goto attach_fail;
5373526Sxy150489 	}
5384919Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR;
5393526Sxy150489 
5404982Syy150190 	/*
5414982Syy150190 	 * If e1000g_force_detach is enabled, in global private dip list,
5424982Syy150190 	 * we will create a new entry, which maintains the priv_dip for DR
5434982Syy150190 	 * supports after driver detached.
5444982Syy150190 	 */
5454982Syy150190 	if (e1000g_force_detach) {
5464982Syy150190 		private_devi_list_t *devi_node;
5474982Syy150190 
5484982Syy150190 		Adapter->priv_dip =
5494982Syy150190 		    kmem_zalloc(sizeof (struct dev_info), KM_SLEEP);
5504982Syy150190 		bcopy(DEVI(devinfo), DEVI(Adapter->priv_dip),
5514982Syy150190 		    sizeof (struct dev_info));
5524982Syy150190 
5534982Syy150190 		devi_node =
5544982Syy150190 		    kmem_zalloc(sizeof (private_devi_list_t), KM_SLEEP);
5554982Syy150190 
5564982Syy150190 		rw_enter(&e1000g_rx_detach_lock, RW_WRITER);
5574982Syy150190 		devi_node->priv_dip = Adapter->priv_dip;
5584982Syy150190 		devi_node->flag = E1000G_PRIV_DEVI_ATTACH;
5594982Syy150190 		devi_node->next = e1000g_private_devi_list;
5604982Syy150190 		e1000g_private_devi_list = devi_node;
5614982Syy150190 		rw_exit(&e1000g_rx_detach_lock);
5624982Syy150190 	}
5634982Syy150190 
5643526Sxy150489 	cmn_err(CE_CONT, "!%s, %s\n", e1000g_string, e1000g_version);
5653526Sxy150489 
5663526Sxy150489 	return (DDI_SUCCESS);
5673526Sxy150489 
5683526Sxy150489 attach_fail:
5693526Sxy150489 	e1000g_unattach(devinfo, Adapter);
5703526Sxy150489 	return (DDI_FAILURE);
5713526Sxy150489 }
5723526Sxy150489 
5733526Sxy150489 static int
5743526Sxy150489 e1000g_register_mac(struct e1000g *Adapter)
5753526Sxy150489 {
5764919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
5773526Sxy150489 	mac_register_t *mac;
5783526Sxy150489 	int err;
5793526Sxy150489 
5803526Sxy150489 	if ((mac = mac_alloc(MAC_VERSION)) == NULL)
5813526Sxy150489 		return (DDI_FAILURE);
5824919Sxy150489 
5833526Sxy150489 	mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
5843526Sxy150489 	mac->m_driver = Adapter;
5853526Sxy150489 	mac->m_dip = Adapter->dip;
5864919Sxy150489 	mac->m_src_addr = hw->mac.addr;
5873526Sxy150489 	mac->m_callbacks = &e1000g_m_callbacks;
5883526Sxy150489 	mac->m_min_sdu = 0;
5896394Scc210113 	mac->m_max_sdu = Adapter->default_mtu;
5905895Syz147064 	mac->m_margin = VLAN_TAGSZ;
5916512Ssowmini 	mac->m_priv_props = e1000g_priv_props;
5926512Ssowmini 	mac->m_priv_prop_count = E1000G_MAX_PRIV_PROPS;
5934919Sxy150489 
5943526Sxy150489 	err = mac_register(mac, &Adapter->mh);
5953526Sxy150489 	mac_free(mac);
5964919Sxy150489 
5973526Sxy150489 	return (err == 0 ? DDI_SUCCESS : DDI_FAILURE);
5983526Sxy150489 }
5993526Sxy150489 
6003526Sxy150489 static int
6014919Sxy150489 e1000g_identify_hardware(struct e1000g *Adapter)
6024919Sxy150489 {
6034919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
6044919Sxy150489 	struct e1000g_osdep *osdep = &Adapter->osdep;
6054919Sxy150489 
6064919Sxy150489 	/* Get the device id */
6074919Sxy150489 	hw->vendor_id =
6084919Sxy150489 	    pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID);
6094919Sxy150489 	hw->device_id =
6104919Sxy150489 	    pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID);
6114919Sxy150489 	hw->revision_id =
6124919Sxy150489 	    pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID);
6134919Sxy150489 	hw->subsystem_device_id =
6144919Sxy150489 	    pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID);
6154919Sxy150489 	hw->subsystem_vendor_id =
6164919Sxy150489 	    pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID);
6174919Sxy150489 
6184919Sxy150489 	if (e1000_set_mac_type(hw) != E1000_SUCCESS) {
6194919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
6204919Sxy150489 		    "MAC type could not be set properly.");
6214919Sxy150489 		return (DDI_FAILURE);
6224919Sxy150489 	}
6234919Sxy150489 
6244919Sxy150489 	return (DDI_SUCCESS);
6254919Sxy150489 }
6264919Sxy150489 
6274919Sxy150489 static int
6284919Sxy150489 e1000g_regs_map(struct e1000g *Adapter)
6294919Sxy150489 {
6304919Sxy150489 	dev_info_t *devinfo = Adapter->dip;
6314919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
6324919Sxy150489 	struct e1000g_osdep *osdep = &Adapter->osdep;
6334919Sxy150489 	off_t mem_size;
6344919Sxy150489 
6354919Sxy150489 	/*
6364919Sxy150489 	 * first get the size of device register to be mapped. The
6374919Sxy150489 	 * second parameter is the register we are interested. I our
6384919Sxy150489 	 * wiseman 0 is for config registers and 1 is for memory mapped
6394919Sxy150489 	 * registers Mem size should have memory mapped region size
6404919Sxy150489 	 */
6414919Sxy150489 	if (ddi_dev_regsize(devinfo, 1, &mem_size) != DDI_SUCCESS) {
6424919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6434919Sxy150489 		    "ddi_dev_regsize for registers failed");
6444919Sxy150489 		return (DDI_FAILURE);
6454919Sxy150489 	}
6464919Sxy150489 
6474919Sxy150489 	if ((ddi_regs_map_setup(devinfo, 1, /* register of interest */
6484919Sxy150489 	    (caddr_t *)&hw->hw_addr, 0, mem_size, &e1000g_regs_acc_attr,
6494919Sxy150489 	    &osdep->reg_handle)) != DDI_SUCCESS) {
6504919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6514919Sxy150489 		    "ddi_regs_map_setup for registers failed");
6524919Sxy150489 		goto regs_map_fail;
6534919Sxy150489 	}
6544919Sxy150489 
6554919Sxy150489 	/* ICH needs to map flash memory */
6564919Sxy150489 	if (hw->mac.type == e1000_ich8lan || hw->mac.type == e1000_ich9lan) {
6574919Sxy150489 		/* get flash size */
6584919Sxy150489 		if (ddi_dev_regsize(devinfo, ICH_FLASH_REG_SET,
6594919Sxy150489 		    &mem_size) != DDI_SUCCESS) {
6604919Sxy150489 			E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6614919Sxy150489 			    "ddi_dev_regsize for ICH flash failed");
6624919Sxy150489 			goto regs_map_fail;
6634919Sxy150489 		}
6644919Sxy150489 
6654919Sxy150489 		/* map flash in */
6664919Sxy150489 		if (ddi_regs_map_setup(devinfo, ICH_FLASH_REG_SET,
6674919Sxy150489 		    (caddr_t *)&hw->flash_address, 0,
6684919Sxy150489 		    mem_size, &e1000g_regs_acc_attr,
6694919Sxy150489 		    &osdep->ich_flash_handle) != DDI_SUCCESS) {
6704919Sxy150489 			E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6714919Sxy150489 			    "ddi_regs_map_setup for ICH flash failed");
6724919Sxy150489 			goto regs_map_fail;
6734919Sxy150489 		}
6744919Sxy150489 	}
6754919Sxy150489 
6764919Sxy150489 	return (DDI_SUCCESS);
6774919Sxy150489 
6784919Sxy150489 regs_map_fail:
6794919Sxy150489 	if (osdep->reg_handle != NULL)
6804919Sxy150489 		ddi_regs_map_free(&osdep->reg_handle);
6814919Sxy150489 
6824919Sxy150489 	return (DDI_FAILURE);
6834919Sxy150489 }
6844919Sxy150489 
6854919Sxy150489 static int
6863526Sxy150489 e1000g_set_driver_params(struct e1000g *Adapter)
6873526Sxy150489 {
6883526Sxy150489 	struct e1000_hw *hw;
6894919Sxy150489 	uint32_t mem_bar, io_bar, bar64;
6903526Sxy150489 
6914919Sxy150489 	hw = &Adapter->shared;
6924919Sxy150489 
6934919Sxy150489 	/* Set MAC type and initialize hardware functions */
6944919Sxy150489 	if (e1000_setup_init_funcs(hw, B_TRUE) != E1000_SUCCESS) {
6954919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6964919Sxy150489 		    "Could not setup hardware functions");
6973526Sxy150489 		return (DDI_FAILURE);
6983526Sxy150489 	}
6993526Sxy150489 
7004919Sxy150489 	/* Get bus information */
7014919Sxy150489 	if (e1000_get_bus_info(hw) != E1000_SUCCESS) {
7024919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, CE_WARN,
7034919Sxy150489 		    "Could not get bus information");
7044919Sxy150489 		return (DDI_FAILURE);
7053526Sxy150489 	}
7063526Sxy150489 
7073526Sxy150489 	/* get mem_base addr */
7084919Sxy150489 	mem_bar = pci_config_get32(Adapter->osdep.cfg_handle, PCI_CONF_BASE0);
7094919Sxy150489 	bar64 = mem_bar & PCI_BASE_TYPE_ALL;
7103526Sxy150489 
7113526Sxy150489 	/* get io_base addr */
7124919Sxy150489 	if (hw->mac.type >= e1000_82544) {
7134919Sxy150489 		if (bar64) {
7143526Sxy150489 			/* IO BAR is different for 64 bit BAR mode */
7154919Sxy150489 			io_bar = pci_config_get32(Adapter->osdep.cfg_handle,
7164919Sxy150489 			    PCI_CONF_BASE4);
7173526Sxy150489 		} else {
7183526Sxy150489 			/* normal 32-bit BAR mode */
7194919Sxy150489 			io_bar = pci_config_get32(Adapter->osdep.cfg_handle,
7204919Sxy150489 			    PCI_CONF_BASE2);
7213526Sxy150489 		}
7223526Sxy150489 		hw->io_base = io_bar & PCI_BASE_IO_ADDR_M;
7233526Sxy150489 	} else {
7243526Sxy150489 		/* no I/O access for adapters prior to 82544 */
7253526Sxy150489 		hw->io_base = 0x0;
7263526Sxy150489 	}
7273526Sxy150489 
7284919Sxy150489 	e1000_read_pci_cfg(hw, PCI_COMMAND_REGISTER, &hw->bus.pci_cmd_word);
7294919Sxy150489 
7304919Sxy150489 	hw->mac.autoneg_failed = B_TRUE;
7314919Sxy150489 
7326735Scc210113 	/* Set the autoneg_wait_to_complete flag to B_FALSE */
7336735Scc210113 	hw->phy.autoneg_wait_to_complete = B_FALSE;
7343526Sxy150489 
7353526Sxy150489 	/* Adaptive IFS related changes */
7364919Sxy150489 	hw->mac.adaptive_ifs = B_TRUE;
7374919Sxy150489 
7384919Sxy150489 	/* Enable phy init script for IGP phy of 82541/82547 */
7394919Sxy150489 	if ((hw->mac.type == e1000_82547) ||
7404919Sxy150489 	    (hw->mac.type == e1000_82541) ||
7414919Sxy150489 	    (hw->mac.type == e1000_82547_rev_2) ||
7424919Sxy150489 	    (hw->mac.type == e1000_82541_rev_2))
7434919Sxy150489 		e1000_init_script_state_82541(hw, B_TRUE);
7444919Sxy150489 
7454919Sxy150489 	/* Enable the TTL workaround for 82541/82547 */
7464919Sxy150489 	e1000_set_ttl_workaround_state_82541(hw, B_TRUE);
7473526Sxy150489 
7484608Syy150190 #ifdef __sparc
7494608Syy150190 	Adapter->strip_crc = B_TRUE;
7504608Syy150190 #else
7514608Syy150190 	Adapter->strip_crc = B_FALSE;
7524608Syy150190 #endif
7534608Syy150190 
7543526Sxy150489 	/* Get conf file properties */
7554919Sxy150489 	e1000g_get_conf(Adapter);
7564919Sxy150489 
7574919Sxy150489 	/* Get speed/duplex settings in conf file */
7584919Sxy150489 	hw->mac.forced_speed_duplex = ADVERTISE_100_FULL;
7594919Sxy150489 	hw->phy.autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
7603526Sxy150489 	e1000g_force_speed_duplex(Adapter);
7613526Sxy150489 
7624919Sxy150489 	/* Get Jumbo Frames settings in conf file */
7633526Sxy150489 	e1000g_get_max_frame_size(Adapter);
7643526Sxy150489 
7653526Sxy150489 	/* Set Rx/Tx buffer size */
7666394Scc210113 	e1000g_set_bufsize(Adapter);
7674919Sxy150489 
7684919Sxy150489 	/* Master Latency Timer */
7694919Sxy150489 	Adapter->master_latency_timer = DEFAULT_MASTER_LATENCY_TIMER;
7704919Sxy150489 
7713526Sxy150489 	/* copper options */
7726735Scc210113 	if (hw->phy.media_type == e1000_media_type_copper) {
7734919Sxy150489 		hw->phy.mdix = 0;	/* AUTO_ALL_MODES */
7744919Sxy150489 		hw->phy.disable_polarity_correction = B_FALSE;
7754919Sxy150489 		hw->phy.ms_type = e1000_ms_hw_default;	/* E1000_MASTER_SLAVE */
7763526Sxy150489 	}
7773526Sxy150489 
7784919Sxy150489 	/* The initial link state should be "unknown" */
7794061Sxy150489 	Adapter->link_state = LINK_STATE_UNKNOWN;
7804061Sxy150489 
7815882Syy150190 	/* Initialize rx parameters */
7825882Syy150190 	Adapter->rx_intr_delay = DEFAULT_RX_INTR_DELAY;
7835882Syy150190 	Adapter->rx_intr_abs_delay = DEFAULT_RX_INTR_ABS_DELAY;
7845882Syy150190 
7854919Sxy150489 	/* Initialize tx parameters */
7864919Sxy150489 	Adapter->tx_intr_enable = DEFAULT_TX_INTR_ENABLE;
7874919Sxy150489 	Adapter->tx_bcopy_thresh = DEFAULT_TX_BCOPY_THRESHOLD;
7885882Syy150190 	Adapter->tx_intr_delay = DEFAULT_TX_INTR_DELAY;
7895882Syy150190 	Adapter->tx_intr_abs_delay = DEFAULT_TX_INTR_ABS_DELAY;
7904919Sxy150489 
7914919Sxy150489 	/* Initialize rx parameters */
7924919Sxy150489 	Adapter->rx_bcopy_thresh = DEFAULT_RX_BCOPY_THRESHOLD;
7934919Sxy150489 
7943526Sxy150489 	return (DDI_SUCCESS);
7953526Sxy150489 }
7963526Sxy150489 
7976394Scc210113 static void
7986394Scc210113 e1000g_set_bufsize(struct e1000g *Adapter)
7996394Scc210113 {
8006394Scc210113 	struct e1000_mac_info *mac = &Adapter->shared.mac;
8016394Scc210113 	uint64_t rx_size;
8026394Scc210113 	uint64_t tx_size;
8036394Scc210113 
8046394Scc210113 #ifdef __sparc
8056394Scc210113 	dev_info_t *devinfo = Adapter->dip;
8066394Scc210113 	ulong_t iommu_pagesize;
8076394Scc210113 
8086394Scc210113 	/* Get the system page size */
8096394Scc210113 	Adapter->sys_page_sz = ddi_ptob(devinfo, (ulong_t)1);
8106394Scc210113 	iommu_pagesize = dvma_pagesize(devinfo);
8116394Scc210113 	if (iommu_pagesize != 0) {
8126394Scc210113 		if (Adapter->sys_page_sz == iommu_pagesize) {
8136394Scc210113 			if (iommu_pagesize > 0x4000)
8146394Scc210113 				Adapter->sys_page_sz = 0x4000;
8156394Scc210113 		} else {
8166394Scc210113 			if (Adapter->sys_page_sz > iommu_pagesize)
8176394Scc210113 				Adapter->sys_page_sz = iommu_pagesize;
8186394Scc210113 		}
8196394Scc210113 	}
820*6986Smx205022 	if (Adapter->lso_enable) {
821*6986Smx205022 		Adapter->dvma_page_num = E1000_LSO_MAXLEN /
822*6986Smx205022 		    Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM;
823*6986Smx205022 	} else {
824*6986Smx205022 		Adapter->dvma_page_num = Adapter->max_frame_size /
825*6986Smx205022 		    Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM;
826*6986Smx205022 	}
8276394Scc210113 	ASSERT(Adapter->dvma_page_num >= E1000G_DEFAULT_DVMA_PAGE_NUM);
8286394Scc210113 #endif
8296394Scc210113 
8306735Scc210113 	Adapter->min_frame_size = ETHERMIN + ETHERFCSL;
8316735Scc210113 
8326735Scc210113 	rx_size = Adapter->max_frame_size + E1000G_IPALIGNPRESERVEROOM;
8336394Scc210113 	if ((rx_size > FRAME_SIZE_UPTO_2K) && (rx_size <= FRAME_SIZE_UPTO_4K))
8346394Scc210113 		Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_4K;
8356394Scc210113 	else if ((rx_size > FRAME_SIZE_UPTO_4K) &&
8366394Scc210113 	    (rx_size <= FRAME_SIZE_UPTO_8K))
8376394Scc210113 		Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_8K;
8386394Scc210113 	else if ((rx_size > FRAME_SIZE_UPTO_8K) &&
8396394Scc210113 	    (rx_size <= FRAME_SIZE_UPTO_16K))
8406394Scc210113 		Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_16K;
8416394Scc210113 	else
8426394Scc210113 		Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K;
8436394Scc210113 
8446735Scc210113 	tx_size = Adapter->max_frame_size;
8456394Scc210113 	if ((tx_size > FRAME_SIZE_UPTO_2K) && (tx_size <= FRAME_SIZE_UPTO_4K))
8466394Scc210113 		Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_4K;
8476394Scc210113 	else if ((tx_size > FRAME_SIZE_UPTO_4K) &&
8486394Scc210113 	    (tx_size <= FRAME_SIZE_UPTO_8K))
8496394Scc210113 		Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_8K;
8506394Scc210113 	else if ((tx_size > FRAME_SIZE_UPTO_8K) &&
8516394Scc210113 	    (tx_size <= FRAME_SIZE_UPTO_16K))
8526394Scc210113 		Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_16K;
8536394Scc210113 	else
8546394Scc210113 		Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K;
8556394Scc210113 
8566394Scc210113 	/*
8576394Scc210113 	 * For Wiseman adapters we have an requirement of having receive
8586394Scc210113 	 * buffers aligned at 256 byte boundary. Since Livengood does not
8596394Scc210113 	 * require this and forcing it for all hardwares will have
8606394Scc210113 	 * performance implications, I am making it applicable only for
8616394Scc210113 	 * Wiseman and for Jumbo frames enabled mode as rest of the time,
8626394Scc210113 	 * it is okay to have normal frames...but it does involve a
8636394Scc210113 	 * potential risk where we may loose data if buffer is not
8646394Scc210113 	 * aligned...so all wiseman boards to have 256 byte aligned
8656394Scc210113 	 * buffers
8666394Scc210113 	 */
8676394Scc210113 	if (mac->type < e1000_82543)
8686394Scc210113 		Adapter->rx_buf_align = RECEIVE_BUFFER_ALIGN_SIZE;
8696394Scc210113 	else
8706394Scc210113 		Adapter->rx_buf_align = 1;
8716394Scc210113 }
8726394Scc210113 
8733526Sxy150489 /*
8744919Sxy150489  * e1000g_detach - driver detach
8754919Sxy150489  *
8764919Sxy150489  * The detach() function is the complement of the attach routine.
8774919Sxy150489  * If cmd is set to DDI_DETACH, detach() is used to remove  the
8784919Sxy150489  * state  associated  with  a  given  instance of a device node
8794919Sxy150489  * prior to the removal of that instance from the system.
8804919Sxy150489  *
8814919Sxy150489  * The detach() function will be called once for each  instance
8824919Sxy150489  * of the device for which there has been a successful attach()
8834919Sxy150489  * once there are no longer  any  opens  on  the  device.
8844919Sxy150489  *
8854919Sxy150489  * Interrupts routine are disabled, All memory allocated by this
8864919Sxy150489  * driver are freed.
8873526Sxy150489  */
8883526Sxy150489 static int
8894919Sxy150489 e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
8903526Sxy150489 {
8913526Sxy150489 	struct e1000g *Adapter;
8924982Syy150190 	boolean_t rx_drain;
8933526Sxy150489 
8943526Sxy150489 	switch (cmd) {
8953526Sxy150489 	default:
8963526Sxy150489 		return (DDI_FAILURE);
8973526Sxy150489 
8983526Sxy150489 	case DDI_SUSPEND:
8993526Sxy150489 		return (e1000g_suspend(devinfo));
9003526Sxy150489 
9013526Sxy150489 	case DDI_DETACH:
9023526Sxy150489 		break;
9033526Sxy150489 	}
9043526Sxy150489 
9053526Sxy150489 	Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
9063526Sxy150489 	if (Adapter == NULL)
9073526Sxy150489 		return (DDI_FAILURE);
9083526Sxy150489 
9094919Sxy150489 	if (mac_unregister(Adapter->mh) != 0) {
9104919Sxy150489 		e1000g_log(Adapter, CE_WARN, "Unregister MAC failed");
9114919Sxy150489 		return (DDI_FAILURE);
9124919Sxy150489 	}
9134919Sxy150489 	Adapter->attach_progress &= ~ATTACH_PROGRESS_MAC;
9144919Sxy150489 
9155273Sgl147354 
9165273Sgl147354 	if (Adapter->chip_state != E1000G_STOP)
9174919Sxy150489 		e1000g_stop(Adapter, B_TRUE);
9183526Sxy150489 
9194982Syy150190 	rx_drain = e1000g_rx_drain(Adapter);
9204982Syy150190 
9214982Syy150190 	/*
9224982Syy150190 	 * If e1000g_force_detach is enabled, driver detach is safe.
9234982Syy150190 	 * We will let e1000g_free_priv_devi_node routine determine
9244982Syy150190 	 * whether we need to free the priv_dip entry for current
9254982Syy150190 	 * driver instance.
9264982Syy150190 	 */
9274982Syy150190 	if (e1000g_force_detach) {
9284982Syy150190 		e1000g_free_priv_devi_node(Adapter, rx_drain);
9294982Syy150190 	} else {
9304982Syy150190 		if (!rx_drain)
9313526Sxy150489 			return (DDI_FAILURE);
9323526Sxy150489 	}
9333526Sxy150489 
9343526Sxy150489 	e1000g_unattach(devinfo, Adapter);
9353526Sxy150489 
9363526Sxy150489 	return (DDI_SUCCESS);
9373526Sxy150489 }
9383526Sxy150489 
9394982Syy150190 /*
9404982Syy150190  * e1000g_free_priv_devi_node - free a priv_dip entry for driver instance
9414982Syy150190  *
9424982Syy150190  * If free_flag is true, that indicates the upper layer is not holding
9434982Syy150190  * the rx buffers, we could free the priv_dip entry safely.
9444982Syy150190  *
9454982Syy150190  * Otherwise, we have to keep this entry even after driver detached,
9464982Syy150190  * and we also need to mark this entry with E1000G_PRIV_DEVI_DETACH flag,
9474982Syy150190  * so that driver could free it while all of rx buffers are returned
9484982Syy150190  * by upper layer later.
9494982Syy150190  */
9504982Syy150190 static void
9514982Syy150190 e1000g_free_priv_devi_node(struct e1000g *Adapter, boolean_t free_flag)
9524982Syy150190 {
9534982Syy150190 	private_devi_list_t *devi_node, *devi_del;
9544982Syy150190 
9554982Syy150190 	rw_enter(&e1000g_rx_detach_lock, RW_WRITER);
9564982Syy150190 	ASSERT(e1000g_private_devi_list != NULL);
9574982Syy150190 	ASSERT(Adapter->priv_dip != NULL);
9584982Syy150190 
9594982Syy150190 	devi_node = e1000g_private_devi_list;
9604982Syy150190 	if (devi_node->priv_dip == Adapter->priv_dip) {
9614982Syy150190 		if (free_flag) {
9624982Syy150190 			e1000g_private_devi_list =
9634982Syy150190 			    devi_node->next;
9644982Syy150190 			kmem_free(devi_node->priv_dip,
9654982Syy150190 			    sizeof (struct dev_info));
9664982Syy150190 			kmem_free(devi_node,
9674982Syy150190 			    sizeof (private_devi_list_t));
9684982Syy150190 		} else {
9694982Syy150190 			ASSERT(e1000g_mblks_pending != 0);
9704982Syy150190 			devi_node->flag =
9714982Syy150190 			    E1000G_PRIV_DEVI_DETACH;
9724982Syy150190 		}
9734982Syy150190 		rw_exit(&e1000g_rx_detach_lock);
9744982Syy150190 		return;
9754982Syy150190 	}
9764982Syy150190 
9774982Syy150190 	devi_node = e1000g_private_devi_list;
9784982Syy150190 	while (devi_node->next != NULL) {
9794982Syy150190 		if (devi_node->next->priv_dip == Adapter->priv_dip) {
9804982Syy150190 			if (free_flag) {
9814982Syy150190 				devi_del = devi_node->next;
9824982Syy150190 				devi_node->next = devi_del->next;
9834982Syy150190 				kmem_free(devi_del->priv_dip,
9844982Syy150190 				    sizeof (struct dev_info));
9854982Syy150190 				kmem_free(devi_del,
9864982Syy150190 				    sizeof (private_devi_list_t));
9874982Syy150190 			} else {
9884982Syy150190 				ASSERT(e1000g_mblks_pending != 0);
9894982Syy150190 				devi_node->next->flag =
9904982Syy150190 				    E1000G_PRIV_DEVI_DETACH;
9914982Syy150190 			}
9924982Syy150190 			break;
9934982Syy150190 		}
9944982Syy150190 		devi_node = devi_node->next;
9954982Syy150190 	}
9964982Syy150190 	rw_exit(&e1000g_rx_detach_lock);
9974982Syy150190 }
9984982Syy150190 
9993526Sxy150489 static void
10003526Sxy150489 e1000g_unattach(dev_info_t *devinfo, struct e1000g *Adapter)
10013526Sxy150489 {
10024919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) {
10033526Sxy150489 		(void) e1000g_disable_intrs(Adapter);
10043526Sxy150489 	}
10053526Sxy150489 
10064919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_MAC) {
10073526Sxy150489 		(void) mac_unregister(Adapter->mh);
10083526Sxy150489 	}
10093526Sxy150489 
10104919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_ADD_INTR) {
10113526Sxy150489 		(void) e1000g_rem_intrs(Adapter);
10123526Sxy150489 	}
10133526Sxy150489 
10144919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_SETUP) {
10153526Sxy150489 		(void) ddi_prop_remove_all(devinfo);
10163526Sxy150489 	}
10173526Sxy150489 
10183526Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_KSTATS) {
10193526Sxy150489 		kstat_delete((kstat_t *)Adapter->e1000g_ksp);
10203526Sxy150489 	}
10213526Sxy150489 
10223526Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_INIT) {
10234919Sxy150489 		stop_link_timer(Adapter);
10245273Sgl147354 		if (e1000_reset_hw(&Adapter->shared) != 0) {
10255273Sgl147354 			e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
10265273Sgl147354 			ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
10275273Sgl147354 		}
10283526Sxy150489 	}
10293526Sxy150489 
10304919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_REGS_MAP) {
10314919Sxy150489 		if (Adapter->osdep.reg_handle != NULL)
10324919Sxy150489 			ddi_regs_map_free(&Adapter->osdep.reg_handle);
10334919Sxy150489 		if (Adapter->osdep.ich_flash_handle != NULL)
10344919Sxy150489 			ddi_regs_map_free(&Adapter->osdep.ich_flash_handle);
10353526Sxy150489 	}
10363526Sxy150489 
10374919Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) {
10384919Sxy150489 		if (Adapter->osdep.cfg_handle != NULL)
10394919Sxy150489 			pci_config_teardown(&Adapter->osdep.cfg_handle);
10403526Sxy150489 	}
10413526Sxy150489 
10423526Sxy150489 	if (Adapter->attach_progress & ATTACH_PROGRESS_LOCKS) {
10433526Sxy150489 		e1000g_destroy_locks(Adapter);
10443526Sxy150489 	}
10453526Sxy150489 
10465273Sgl147354 	if (Adapter->attach_progress & ATTACH_PROGRESS_FMINIT) {
10475273Sgl147354 		e1000g_fm_fini(Adapter);
10485273Sgl147354 	}
10495273Sgl147354 
10504919Sxy150489 	e1000_remove_device(&Adapter->shared);
10514919Sxy150489 
10523526Sxy150489 	kmem_free((caddr_t)Adapter, sizeof (struct e1000g));
10533526Sxy150489 
10543526Sxy150489 	/*
10553526Sxy150489 	 * Another hotplug spec requirement,
10563526Sxy150489 	 * run ddi_set_driver_private(devinfo, null);
10573526Sxy150489 	 */
10583526Sxy150489 	ddi_set_driver_private(devinfo, NULL);
10593526Sxy150489 }
10603526Sxy150489 
10613526Sxy150489 static void
10623526Sxy150489 e1000g_init_locks(struct e1000g *Adapter)
10633526Sxy150489 {
10643526Sxy150489 	e1000g_tx_ring_t *tx_ring;
10653526Sxy150489 	e1000g_rx_ring_t *rx_ring;
10663526Sxy150489 
10673526Sxy150489 	rw_init(&Adapter->chip_lock, NULL,
10683526Sxy150489 	    RW_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10694919Sxy150489 	mutex_init(&Adapter->link_lock, NULL,
10703526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10714919Sxy150489 	mutex_init(&Adapter->watchdog_lock, NULL,
10723526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10733526Sxy150489 
10743526Sxy150489 	tx_ring = Adapter->tx_ring;
10753526Sxy150489 
10763526Sxy150489 	mutex_init(&tx_ring->tx_lock, NULL,
10773526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10783526Sxy150489 	mutex_init(&tx_ring->usedlist_lock, NULL,
10793526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10803526Sxy150489 	mutex_init(&tx_ring->freelist_lock, NULL,
10813526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10823526Sxy150489 
10833526Sxy150489 	rx_ring = Adapter->rx_ring;
10843526Sxy150489 
10853526Sxy150489 	mutex_init(&rx_ring->freelist_lock, NULL,
10863526Sxy150489 	    MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
10873526Sxy150489 }
10883526Sxy150489 
10893526Sxy150489 static void
10903526Sxy150489 e1000g_destroy_locks(struct e1000g *Adapter)
10913526Sxy150489 {
10923526Sxy150489 	e1000g_tx_ring_t *tx_ring;
10933526Sxy150489 	e1000g_rx_ring_t *rx_ring;
10943526Sxy150489 
10953526Sxy150489 	tx_ring = Adapter->tx_ring;
10963526Sxy150489 	mutex_destroy(&tx_ring->tx_lock);
10973526Sxy150489 	mutex_destroy(&tx_ring->usedlist_lock);
10983526Sxy150489 	mutex_destroy(&tx_ring->freelist_lock);
10993526Sxy150489 
11003526Sxy150489 	rx_ring = Adapter->rx_ring;
11013526Sxy150489 	mutex_destroy(&rx_ring->freelist_lock);
11023526Sxy150489 
11034919Sxy150489 	mutex_destroy(&Adapter->link_lock);
11044919Sxy150489 	mutex_destroy(&Adapter->watchdog_lock);
11053526Sxy150489 	rw_destroy(&Adapter->chip_lock);
11063526Sxy150489 }
11073526Sxy150489 
11083526Sxy150489 static int
11093526Sxy150489 e1000g_resume(dev_info_t *devinfo)
11103526Sxy150489 {
11113526Sxy150489 	struct e1000g *Adapter;
11123526Sxy150489 
11133526Sxy150489 	Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
11143526Sxy150489 	if (Adapter == NULL)
11153526Sxy150489 		return (DDI_FAILURE);
11163526Sxy150489 
11174919Sxy150489 	if (e1000g_start(Adapter, B_TRUE))
11183526Sxy150489 		return (DDI_FAILURE);
11193526Sxy150489 
11203526Sxy150489 	return (DDI_SUCCESS);
11213526Sxy150489 }
11223526Sxy150489 
11233526Sxy150489 static int
11243526Sxy150489 e1000g_suspend(dev_info_t *devinfo)
11253526Sxy150489 {
11263526Sxy150489 	struct e1000g *Adapter;
11273526Sxy150489 
11283526Sxy150489 	Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
11293526Sxy150489 	if (Adapter == NULL)
11303526Sxy150489 		return (DDI_FAILURE);
11313526Sxy150489 
11324919Sxy150489 	e1000g_stop(Adapter, B_TRUE);
11333526Sxy150489 
11343526Sxy150489 	return (DDI_SUCCESS);
11353526Sxy150489 }
11363526Sxy150489 
11373526Sxy150489 static int
11383526Sxy150489 e1000g_init(struct e1000g *Adapter)
11393526Sxy150489 {
11403526Sxy150489 	uint32_t pba;
11414919Sxy150489 	uint32_t high_water;
11423526Sxy150489 	struct e1000_hw *hw;
11434061Sxy150489 	clock_t link_timeout;
11443526Sxy150489 
11454919Sxy150489 	hw = &Adapter->shared;
11463526Sxy150489 
11473526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
11483526Sxy150489 
11493526Sxy150489 	/*
11503526Sxy150489 	 * reset to put the hardware in a known state
11513526Sxy150489 	 * before we try to do anything with the eeprom
11523526Sxy150489 	 */
11535273Sgl147354 	if (e1000_reset_hw(hw) != 0) {
11545273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11555273Sgl147354 		goto init_fail;
11565273Sgl147354 	}
11573526Sxy150489 
11584919Sxy150489 	if (e1000_validate_nvm_checksum(hw) < 0) {
11594061Sxy150489 		/*
11604061Sxy150489 		 * Some PCI-E parts fail the first check due to
11614061Sxy150489 		 * the link being in sleep state.  Call it again,
11624061Sxy150489 		 * if it fails a second time its a real issue.
11634061Sxy150489 		 */
11644919Sxy150489 		if (e1000_validate_nvm_checksum(hw) < 0) {
11654061Sxy150489 			e1000g_log(Adapter, CE_WARN,
11664919Sxy150489 			    "Invalid NVM checksum. Please contact "
11674919Sxy150489 			    "the vendor to update the NVM.");
11685273Sgl147354 			e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11694061Sxy150489 			goto init_fail;
11704061Sxy150489 		}
11713526Sxy150489 	}
11723526Sxy150489 
11733526Sxy150489 #ifdef __sparc
11743526Sxy150489 	/*
11753526Sxy150489 	 * Firstly, we try to get the local ethernet address from OBP. If
11763526Sxy150489 	 * fail, we get from EEPROM of NIC card.
11773526Sxy150489 	 */
11783526Sxy150489 	if (!e1000g_find_mac_address(Adapter)) {
11793526Sxy150489 		if (e1000_read_mac_addr(hw) < 0) {
11803526Sxy150489 			e1000g_log(Adapter, CE_WARN, "Read mac addr failed");
11815273Sgl147354 			e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11823526Sxy150489 			goto init_fail;
11833526Sxy150489 		}
11843526Sxy150489 	}
11853526Sxy150489 #else
11863526Sxy150489 	/* Get the local ethernet address. */
11873526Sxy150489 	if (e1000_read_mac_addr(hw) < 0) {
11883526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Read mac addr failed");
11895273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11903526Sxy150489 		goto init_fail;
11913526Sxy150489 	}
11923526Sxy150489 #endif
11933526Sxy150489 
11943526Sxy150489 	/* check for valid mac address */
11954919Sxy150489 	if (!is_valid_mac_addr(hw->mac.addr)) {
11963526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Invalid mac addr");
11975273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11983526Sxy150489 		goto init_fail;
11993526Sxy150489 	}
12003526Sxy150489 
12014919Sxy150489 	/* Set LAA state for 82571 chipset */
12024919Sxy150489 	e1000_set_laa_state_82571(hw, B_TRUE);
12033526Sxy150489 
12043526Sxy150489 	/* Master Latency Timer implementation */
12054919Sxy150489 	if (Adapter->master_latency_timer) {
12064919Sxy150489 		pci_config_put8(Adapter->osdep.cfg_handle,
12074919Sxy150489 		    PCI_CONF_LATENCY_TIMER, Adapter->master_latency_timer);
12083526Sxy150489 	}
12093526Sxy150489 
12104919Sxy150489 	if (hw->mac.type < e1000_82547) {
12113526Sxy150489 		/*
12123526Sxy150489 		 * Total FIFO is 64K
12133526Sxy150489 		 */
12146735Scc210113 		if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
12153526Sxy150489 			pba = E1000_PBA_40K;	/* 40K for Rx, 24K for Tx */
12163526Sxy150489 		else
12173526Sxy150489 			pba = E1000_PBA_48K;	/* 48K for Rx, 16K for Tx */
12184919Sxy150489 	} else if (hw->mac.type >= e1000_82571 &&
12194919Sxy150489 	    hw->mac.type <= e1000_82572) {
12203526Sxy150489 		/*
12213526Sxy150489 		 * Total FIFO is 48K
12223526Sxy150489 		 */
12236735Scc210113 		if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
12243526Sxy150489 			pba = E1000_PBA_30K;	/* 30K for Rx, 18K for Tx */
12253526Sxy150489 		else
12263526Sxy150489 			pba = E1000_PBA_38K;	/* 38K for Rx, 10K for Tx */
12274919Sxy150489 	} else if (hw->mac.type == e1000_ich8lan) {
12283526Sxy150489 		pba = E1000_PBA_8K;		/* 8K for Rx, 12K for Tx */
12294919Sxy150489 	} else if (hw->mac.type == e1000_ich9lan) {
12304919Sxy150489 		pba = E1000_PBA_12K;
12313526Sxy150489 	} else {
12323526Sxy150489 		/*
12333526Sxy150489 		 * Total FIFO is 40K
12343526Sxy150489 		 */
12356735Scc210113 		if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
12363526Sxy150489 			pba = E1000_PBA_22K;	/* 22K for Rx, 18K for Tx */
12373526Sxy150489 		else
12383526Sxy150489 			pba = E1000_PBA_30K;	/* 30K for Rx, 10K for Tx */
12393526Sxy150489 	}
12404919Sxy150489 	E1000_WRITE_REG(hw, E1000_PBA, pba);
12413526Sxy150489 
12423526Sxy150489 	/*
12433526Sxy150489 	 * These parameters set thresholds for the adapter's generation(Tx)
12443526Sxy150489 	 * and response(Rx) to Ethernet PAUSE frames.  These are just threshold
12453526Sxy150489 	 * settings.  Flow control is enabled or disabled in the configuration
12463526Sxy150489 	 * file.
12473526Sxy150489 	 * High-water mark is set down from the top of the rx fifo (not
12483526Sxy150489 	 * sensitive to max_frame_size) and low-water is set just below
12493526Sxy150489 	 * high-water mark.
12504919Sxy150489 	 * The high water mark must be low enough to fit one full frame above
12514919Sxy150489 	 * it in the rx FIFO.  Should be the lower of:
12524919Sxy150489 	 * 90% of the Rx FIFO size and the full Rx FIFO size minus the early
12534919Sxy150489 	 * receive size (assuming ERT set to E1000_ERT_2048), or the full
12544919Sxy150489 	 * Rx FIFO size minus one full frame.
12553526Sxy150489 	 */
12564919Sxy150489 	high_water = min(((pba << 10) * 9 / 10),
12574919Sxy150489 	    ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_ich9lan) ?
12584919Sxy150489 	    ((pba << 10) - (E1000_ERT_2048 << 3)) :
12596735Scc210113 	    ((pba << 10) - Adapter->max_frame_size)));
12606735Scc210113 
12616735Scc210113 	hw->fc.high_water = high_water & 0xFFF8;
12626735Scc210113 	hw->fc.low_water = hw->fc.high_water - 8;
12634919Sxy150489 
12644919Sxy150489 	if (hw->mac.type == e1000_80003es2lan)
12656735Scc210113 		hw->fc.pause_time = 0xFFFF;
12664919Sxy150489 	else
12676735Scc210113 		hw->fc.pause_time = E1000_FC_PAUSE_TIME;
12686735Scc210113 	hw->fc.send_xon = B_TRUE;
12693526Sxy150489 
12703526Sxy150489 	/*
12713526Sxy150489 	 * Reset the adapter hardware the second time.
12723526Sxy150489 	 */
12735273Sgl147354 	if (e1000_reset_hw(hw) != 0) {
12745273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
12755273Sgl147354 		goto init_fail;
12765273Sgl147354 	}
12773526Sxy150489 
12783526Sxy150489 	/* disable wakeup control by default */
12794919Sxy150489 	if (hw->mac.type >= e1000_82544)
12804919Sxy150489 		E1000_WRITE_REG(hw, E1000_WUC, 0);
12813526Sxy150489 
12823526Sxy150489 	/* MWI setup */
12834919Sxy150489 	e1000_pci_set_mwi(hw);
12843526Sxy150489 
12853526Sxy150489 	/*
12863526Sxy150489 	 * Configure/Initialize hardware
12873526Sxy150489 	 */
12883526Sxy150489 	if (e1000_init_hw(hw) < 0) {
12893526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Initialize hw failed");
12905273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
12913526Sxy150489 		goto init_fail;
12923526Sxy150489 	}
12933526Sxy150489 
12943526Sxy150489 	/* Disable Smart Power Down */
12953526Sxy150489 	phy_spd_state(hw, B_FALSE);
12963526Sxy150489 
12975082Syy150190 	/* Make sure driver has control */
12985082Syy150190 	e1000g_get_driver_control(hw);
12995082Syy150190 
13003526Sxy150489 	/*
13013526Sxy150489 	 * Initialize unicast addresses.
13023526Sxy150489 	 */
13033526Sxy150489 	e1000g_init_unicst(Adapter);
13043526Sxy150489 
13053526Sxy150489 	/*
13063526Sxy150489 	 * Setup and initialize the mctable structures.  After this routine
13073526Sxy150489 	 * completes  Multicast table will be set
13083526Sxy150489 	 */
13094919Sxy150489 	e1000g_setup_multicast(Adapter);
13104919Sxy150489 	msec_delay(5);
13113526Sxy150489 
13123526Sxy150489 	/*
13133526Sxy150489 	 * Implement Adaptive IFS
13143526Sxy150489 	 */
13153526Sxy150489 	e1000_reset_adaptive(hw);
13163526Sxy150489 
13173526Sxy150489 	/* Setup Interrupt Throttling Register */
13185882Syy150190 	if (hw->mac.type >= e1000_82540) {
13195882Syy150190 		E1000_WRITE_REG(hw, E1000_ITR, Adapter->intr_throttling_rate);
13205882Syy150190 	} else
13215882Syy150190 		Adapter->intr_adaptive = B_FALSE;
13223526Sxy150489 
13234061Sxy150489 	/* Start the timer for link setup */
13244919Sxy150489 	if (hw->mac.autoneg)
13254919Sxy150489 		link_timeout = PHY_AUTO_NEG_LIMIT * drv_usectohz(100000);
13264061Sxy150489 	else
13274919Sxy150489 		link_timeout = PHY_FORCE_LIMIT * drv_usectohz(100000);
13284919Sxy150489 
13294919Sxy150489 	mutex_enter(&Adapter->link_lock);
13306735Scc210113 	if (hw->phy.autoneg_wait_to_complete) {
13314061Sxy150489 		Adapter->link_complete = B_TRUE;
13323526Sxy150489 	} else {
13334061Sxy150489 		Adapter->link_complete = B_FALSE;
13344061Sxy150489 		Adapter->link_tid = timeout(e1000g_link_timer,
13354061Sxy150489 		    (void *)Adapter, link_timeout);
13363526Sxy150489 	}
13374919Sxy150489 	mutex_exit(&Adapter->link_lock);
13383526Sxy150489 
13393526Sxy150489 	/* Enable PCI-Ex master */
13404919Sxy150489 	if (hw->bus.type == e1000_bus_type_pci_express) {
13413526Sxy150489 		e1000_enable_pciex_master(hw);
13423526Sxy150489 	}
13433526Sxy150489 
13445082Syy150190 	/* Save the state of the phy */
13455082Syy150190 	e1000g_get_phy_state(Adapter);
13465082Syy150190 
13476512Ssowmini 	e1000g_param_sync(Adapter);
13486512Ssowmini 
13493526Sxy150489 	Adapter->init_count++;
13503526Sxy150489 
13515273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) {
13525273Sgl147354 		goto init_fail;
13535273Sgl147354 	}
13545273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
13555273Sgl147354 		goto init_fail;
13565273Sgl147354 	}
13575273Sgl147354 
13583526Sxy150489 	rw_exit(&Adapter->chip_lock);
13593526Sxy150489 
13603526Sxy150489 	return (DDI_SUCCESS);
13613526Sxy150489 
13623526Sxy150489 init_fail:
13633526Sxy150489 	rw_exit(&Adapter->chip_lock);
13645273Sgl147354 	ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
13653526Sxy150489 	return (DDI_FAILURE);
13663526Sxy150489 }
13673526Sxy150489 
13683526Sxy150489 /*
13693526Sxy150489  * Check if the link is up
13703526Sxy150489  */
13713526Sxy150489 static boolean_t
13723526Sxy150489 e1000g_link_up(struct e1000g *Adapter)
13733526Sxy150489 {
13743526Sxy150489 	struct e1000_hw *hw;
13753526Sxy150489 	boolean_t link_up;
13763526Sxy150489 
13774919Sxy150489 	hw = &Adapter->shared;
13783526Sxy150489 
13793526Sxy150489 	e1000_check_for_link(hw);
13803526Sxy150489 
13814919Sxy150489 	if ((E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU) ||
13824919Sxy150489 	    ((!hw->mac.get_link_status) && (hw->mac.type == e1000_82543)) ||
13836735Scc210113 	    ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
13844919Sxy150489 	    (hw->mac.serdes_has_link))) {
13853526Sxy150489 		link_up = B_TRUE;
13863526Sxy150489 	} else {
13873526Sxy150489 		link_up = B_FALSE;
13883526Sxy150489 	}
13893526Sxy150489 
13903526Sxy150489 	return (link_up);
13913526Sxy150489 }
13923526Sxy150489 
13933526Sxy150489 static void
13943526Sxy150489 e1000g_m_ioctl(void *arg, queue_t *q, mblk_t *mp)
13953526Sxy150489 {
13963526Sxy150489 	struct iocblk *iocp;
13973526Sxy150489 	struct e1000g *e1000gp;
13983526Sxy150489 	enum ioc_reply status;
13993526Sxy150489 	int err;
14003526Sxy150489 
14013526Sxy150489 	iocp = (struct iocblk *)mp->b_rptr;
14023526Sxy150489 	iocp->ioc_error = 0;
14033526Sxy150489 	e1000gp = (struct e1000g *)arg;
14043526Sxy150489 
14053526Sxy150489 	ASSERT(e1000gp);
14063526Sxy150489 	if (e1000gp == NULL) {
14073526Sxy150489 		miocnak(q, mp, 0, EINVAL);
14083526Sxy150489 		return;
14093526Sxy150489 	}
14103526Sxy150489 
14113526Sxy150489 	switch (iocp->ioc_cmd) {
14123526Sxy150489 
14133526Sxy150489 	case LB_GET_INFO_SIZE:
14143526Sxy150489 	case LB_GET_INFO:
14153526Sxy150489 	case LB_GET_MODE:
14163526Sxy150489 	case LB_SET_MODE:
14173526Sxy150489 		status = e1000g_loopback_ioctl(e1000gp, iocp, mp);
14183526Sxy150489 		break;
14193526Sxy150489 
14203526Sxy150489 
14214919Sxy150489 #ifdef E1000G_DEBUG
14223526Sxy150489 	case E1000G_IOC_REG_PEEK:
14233526Sxy150489 	case E1000G_IOC_REG_POKE:
14243526Sxy150489 		status = e1000g_pp_ioctl(e1000gp, iocp, mp);
14253526Sxy150489 		break;
14263526Sxy150489 	case E1000G_IOC_CHIP_RESET:
14273526Sxy150489 		e1000gp->reset_count++;
14283526Sxy150489 		if (e1000g_reset(e1000gp))
14293526Sxy150489 			status = IOC_ACK;
14303526Sxy150489 		else
14313526Sxy150489 			status = IOC_INVAL;
14323526Sxy150489 		break;
14334919Sxy150489 #endif
14343526Sxy150489 	default:
14353526Sxy150489 		status = IOC_INVAL;
14363526Sxy150489 		break;
14373526Sxy150489 	}
14383526Sxy150489 
14393526Sxy150489 	/*
14403526Sxy150489 	 * Decide how to reply
14413526Sxy150489 	 */
14423526Sxy150489 	switch (status) {
14433526Sxy150489 	default:
14443526Sxy150489 	case IOC_INVAL:
14453526Sxy150489 		/*
14463526Sxy150489 		 * Error, reply with a NAK and EINVAL or the specified error
14473526Sxy150489 		 */
14483526Sxy150489 		miocnak(q, mp, 0, iocp->ioc_error == 0 ?
14494349Sxy150489 		    EINVAL : iocp->ioc_error);
14503526Sxy150489 		break;
14513526Sxy150489 
14523526Sxy150489 	case IOC_DONE:
14533526Sxy150489 		/*
14543526Sxy150489 		 * OK, reply already sent
14553526Sxy150489 		 */
14563526Sxy150489 		break;
14573526Sxy150489 
14583526Sxy150489 	case IOC_ACK:
14593526Sxy150489 		/*
14603526Sxy150489 		 * OK, reply with an ACK
14613526Sxy150489 		 */
14623526Sxy150489 		miocack(q, mp, 0, 0);
14633526Sxy150489 		break;
14643526Sxy150489 
14653526Sxy150489 	case IOC_REPLY:
14663526Sxy150489 		/*
14673526Sxy150489 		 * OK, send prepared reply as ACK or NAK
14683526Sxy150489 		 */
14693526Sxy150489 		mp->b_datap->db_type = iocp->ioc_error == 0 ?
14704349Sxy150489 		    M_IOCACK : M_IOCNAK;
14713526Sxy150489 		qreply(q, mp);
14723526Sxy150489 		break;
14733526Sxy150489 	}
14743526Sxy150489 }
14753526Sxy150489 
14763526Sxy150489 static int
14773526Sxy150489 e1000g_m_start(void *arg)
14783526Sxy150489 {
14793526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
14803526Sxy150489 
14814919Sxy150489 	return (e1000g_start(Adapter, B_TRUE));
14823526Sxy150489 }
14833526Sxy150489 
14843526Sxy150489 static int
14854919Sxy150489 e1000g_start(struct e1000g *Adapter, boolean_t global)
14863526Sxy150489 {
14874919Sxy150489 	if (global) {
14884919Sxy150489 		/* Allocate dma resources for descriptors and buffers */
14894919Sxy150489 		if (e1000g_alloc_dma_resources(Adapter) != DDI_SUCCESS) {
14904919Sxy150489 			e1000g_log(Adapter, CE_WARN,
14914919Sxy150489 			    "Alloc DMA resources failed");
14924919Sxy150489 			return (ENOTACTIVE);
14934919Sxy150489 		}
14944919Sxy150489 		Adapter->rx_buffer_setup = B_FALSE;
14954919Sxy150489 	}
14964919Sxy150489 
14973526Sxy150489 	if (!(Adapter->attach_progress & ATTACH_PROGRESS_INIT)) {
14983526Sxy150489 		if (e1000g_init(Adapter) != DDI_SUCCESS) {
14993526Sxy150489 			e1000g_log(Adapter, CE_WARN,
15003526Sxy150489 			    "Adapter initialization failed");
15014919Sxy150489 			if (global)
15024919Sxy150489 				e1000g_release_dma_resources(Adapter);
15033526Sxy150489 			return (ENOTACTIVE);
15043526Sxy150489 		}
15053526Sxy150489 	}
15063526Sxy150489 
15073526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
15083526Sxy150489 
15094919Sxy150489 	/* Setup and initialize the transmit structures */
15104919Sxy150489 	e1000g_tx_setup(Adapter);
15114919Sxy150489 	msec_delay(5);
15124919Sxy150489 
15134919Sxy150489 	/* Setup and initialize the receive structures */
15144919Sxy150489 	e1000g_rx_setup(Adapter);
15154919Sxy150489 	msec_delay(5);
15164919Sxy150489 
15174919Sxy150489 	e1000g_mask_interrupt(Adapter);
15183526Sxy150489 
15195273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
15205273Sgl147354 		rw_exit(&Adapter->chip_lock);
15215273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
15225273Sgl147354 		return (ENOTACTIVE);
15235273Sgl147354 	}
15245273Sgl147354 
15255273Sgl147354 	Adapter->chip_state = E1000G_START;
15263526Sxy150489 	Adapter->attach_progress |= ATTACH_PROGRESS_INIT;
15273526Sxy150489 
15283526Sxy150489 	rw_exit(&Adapter->chip_lock);
15293526Sxy150489 
15304919Sxy150489 	/* Enable and start the watchdog timer */
15314919Sxy150489 	enable_watchdog_timer(Adapter);
15324919Sxy150489 
15333526Sxy150489 	return (0);
15343526Sxy150489 }
15353526Sxy150489 
15363526Sxy150489 static void
15373526Sxy150489 e1000g_m_stop(void *arg)
15383526Sxy150489 {
15393526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
15403526Sxy150489 
15414919Sxy150489 	e1000g_stop(Adapter, B_TRUE);
15423526Sxy150489 }
15433526Sxy150489 
15443526Sxy150489 static void
15454919Sxy150489 e1000g_stop(struct e1000g *Adapter, boolean_t global)
15463526Sxy150489 {
15473526Sxy150489 	/* Set stop flags */
15483526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
15493526Sxy150489 
15505273Sgl147354 	Adapter->chip_state = E1000G_STOP;
15513526Sxy150489 	Adapter->attach_progress &= ~ATTACH_PROGRESS_INIT;
15523526Sxy150489 
15533526Sxy150489 	rw_exit(&Adapter->chip_lock);
15543526Sxy150489 
15553526Sxy150489 	/* Drain tx sessions */
15563526Sxy150489 	(void) e1000g_tx_drain(Adapter);
15573526Sxy150489 
15584919Sxy150489 	/* Disable and stop all the timers */
15594919Sxy150489 	disable_watchdog_timer(Adapter);
15604919Sxy150489 	stop_link_timer(Adapter);
15614919Sxy150489 	stop_82547_timer(Adapter->tx_ring);
15624061Sxy150489 
15633526Sxy150489 	/* Stop the chip and release pending resources */
15643526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
15653526Sxy150489 
15664919Sxy150489 	e1000g_clear_all_interrupts(Adapter);
15675273Sgl147354 	if (e1000_reset_hw(&Adapter->shared) != 0) {
15685273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
15695273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
15705273Sgl147354 	}
15713526Sxy150489 
15723526Sxy150489 	/* Release resources still held by the TX descriptors */
15734919Sxy150489 	e1000g_tx_clean(Adapter);
15744061Sxy150489 
15755273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
15765273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
15775273Sgl147354 
15784061Sxy150489 	/* Clean the pending rx jumbo packet fragment */
15794919Sxy150489 	e1000g_rx_clean(Adapter);
15804061Sxy150489 
15814061Sxy150489 	rw_exit(&Adapter->chip_lock);
15824919Sxy150489 
15834919Sxy150489 	if (global)
15844919Sxy150489 		e1000g_release_dma_resources(Adapter);
15854061Sxy150489 }
15864061Sxy150489 
15874061Sxy150489 static void
15884919Sxy150489 e1000g_rx_clean(struct e1000g *Adapter)
15894919Sxy150489 {
15904919Sxy150489 	e1000g_rx_ring_t *rx_ring = Adapter->rx_ring;
15914919Sxy150489 
15924919Sxy150489 	if (rx_ring->rx_mblk != NULL) {
15934919Sxy150489 		freemsg(rx_ring->rx_mblk);
15944919Sxy150489 		rx_ring->rx_mblk = NULL;
15954919Sxy150489 		rx_ring->rx_mblk_tail = NULL;
15964919Sxy150489 		rx_ring->rx_mblk_len = 0;
15974919Sxy150489 	}
15984919Sxy150489 }
15994919Sxy150489 
16004919Sxy150489 static void
16014919Sxy150489 e1000g_tx_clean(struct e1000g *Adapter)
16024061Sxy150489 {
16034061Sxy150489 	e1000g_tx_ring_t *tx_ring;
16044919Sxy150489 	p_tx_sw_packet_t packet;
16054061Sxy150489 	mblk_t *mp;
16064061Sxy150489 	mblk_t *nmp;
16074061Sxy150489 	uint32_t packet_count;
16084061Sxy150489 
16094061Sxy150489 	tx_ring = Adapter->tx_ring;
16104061Sxy150489 
16113526Sxy150489 	/*
16123526Sxy150489 	 * Here we don't need to protect the lists using
16133526Sxy150489 	 * the usedlist_lock and freelist_lock, for they
16143526Sxy150489 	 * have been protected by the chip_lock.
16153526Sxy150489 	 */
16163526Sxy150489 	mp = NULL;
16173526Sxy150489 	nmp = NULL;
16184061Sxy150489 	packet_count = 0;
16194919Sxy150489 	packet = (p_tx_sw_packet_t)QUEUE_GET_HEAD(&tx_ring->used_list);
16203526Sxy150489 	while (packet != NULL) {
16213526Sxy150489 		if (packet->mp != NULL) {
16223526Sxy150489 			/* Assemble the message chain */
16233526Sxy150489 			if (mp == NULL) {
16243526Sxy150489 				mp = packet->mp;
16253526Sxy150489 				nmp = packet->mp;
16263526Sxy150489 			} else {
16273526Sxy150489 				nmp->b_next = packet->mp;
16283526Sxy150489 				nmp = packet->mp;
16293526Sxy150489 			}
16303526Sxy150489 			/* Disconnect the message from the sw packet */
16313526Sxy150489 			packet->mp = NULL;
16323526Sxy150489 		}
16333526Sxy150489 
16344919Sxy150489 		e1000g_free_tx_swpkt(packet);
16354061Sxy150489 		packet_count++;
16363526Sxy150489 
16374919Sxy150489 		packet = (p_tx_sw_packet_t)
16383526Sxy150489 		    QUEUE_GET_NEXT(&tx_ring->used_list, &packet->Link);
16393526Sxy150489 	}
16403526Sxy150489 
16415882Syy150190 	if (mp != NULL)
16425882Syy150190 		freemsgchain(mp);
16434061Sxy150489 
16444061Sxy150489 	if (packet_count > 0) {
16454061Sxy150489 		QUEUE_APPEND(&tx_ring->free_list, &tx_ring->used_list);
16464061Sxy150489 		QUEUE_INIT_LIST(&tx_ring->used_list);
16474061Sxy150489 
16484061Sxy150489 		/* Setup TX descriptor pointers */
16494061Sxy150489 		tx_ring->tbd_next = tx_ring->tbd_first;
16504061Sxy150489 		tx_ring->tbd_oldest = tx_ring->tbd_first;
16514061Sxy150489 
16524061Sxy150489 		/* Setup our HW Tx Head & Tail descriptor pointers */
16536735Scc210113 		E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0);
16546735Scc210113 		E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0);
16553526Sxy150489 	}
16563526Sxy150489 }
16573526Sxy150489 
16583526Sxy150489 static boolean_t
16593526Sxy150489 e1000g_tx_drain(struct e1000g *Adapter)
16603526Sxy150489 {
16613526Sxy150489 	int i;
16623526Sxy150489 	boolean_t done;
16633526Sxy150489 	e1000g_tx_ring_t *tx_ring;
16643526Sxy150489 
16653526Sxy150489 	tx_ring = Adapter->tx_ring;
16663526Sxy150489 
16673526Sxy150489 	/* Allow up to 'wsdraintime' for pending xmit's to complete. */
16684919Sxy150489 	for (i = 0; i < TX_DRAIN_TIME; i++) {
16693526Sxy150489 		mutex_enter(&tx_ring->usedlist_lock);
16703526Sxy150489 		done = IS_QUEUE_EMPTY(&tx_ring->used_list);
16713526Sxy150489 		mutex_exit(&tx_ring->usedlist_lock);
16723526Sxy150489 
16733526Sxy150489 		if (done)
16743526Sxy150489 			break;
16753526Sxy150489 
16763526Sxy150489 		msec_delay(1);
16773526Sxy150489 	}
16783526Sxy150489 
16793526Sxy150489 	return (done);
16803526Sxy150489 }
16813526Sxy150489 
16823526Sxy150489 static boolean_t
16833526Sxy150489 e1000g_rx_drain(struct e1000g *Adapter)
16843526Sxy150489 {
16854919Sxy150489 	e1000g_rx_ring_t *rx_ring;
16864919Sxy150489 	p_rx_sw_packet_t packet;
16873526Sxy150489 	boolean_t done;
16883526Sxy150489 
16894919Sxy150489 	rx_ring = Adapter->rx_ring;
16904919Sxy150489 	done = B_TRUE;
16914919Sxy150489 
16924919Sxy150489 	rw_enter(&e1000g_rx_detach_lock, RW_WRITER);
16934919Sxy150489 
16944919Sxy150489 	while (rx_ring->pending_list != NULL) {
16954919Sxy150489 		packet = rx_ring->pending_list;
16964919Sxy150489 		rx_ring->pending_list =
16974919Sxy150489 		    rx_ring->pending_list->next;
16984919Sxy150489 
16994919Sxy150489 		if (packet->flag == E1000G_RX_SW_STOP) {
17004919Sxy150489 			packet->flag = E1000G_RX_SW_DETACH;
17014919Sxy150489 			done = B_FALSE;
17024919Sxy150489 		} else {
17034919Sxy150489 			ASSERT(packet->flag == E1000G_RX_SW_FREE);
17044919Sxy150489 			ASSERT(packet->mp == NULL);
17054919Sxy150489 			e1000g_free_rx_sw_packet(packet);
17064919Sxy150489 		}
17074919Sxy150489 	}
17084919Sxy150489 
17094919Sxy150489 	rw_exit(&e1000g_rx_detach_lock);
17103526Sxy150489 
17113526Sxy150489 	return (done);
17123526Sxy150489 }
17133526Sxy150489 
17144061Sxy150489 boolean_t
17153526Sxy150489 e1000g_reset(struct e1000g *Adapter)
17163526Sxy150489 {
17174919Sxy150489 	e1000g_stop(Adapter, B_FALSE);
17184919Sxy150489 
17194919Sxy150489 	if (e1000g_start(Adapter, B_FALSE)) {
17203526Sxy150489 		e1000g_log(Adapter, CE_WARN, "Reset failed");
17213526Sxy150489 		return (B_FALSE);
17223526Sxy150489 	}
17233526Sxy150489 
17243526Sxy150489 	return (B_TRUE);
17253526Sxy150489 }
17263526Sxy150489 
17275273Sgl147354 boolean_t
17285273Sgl147354 e1000g_global_reset(struct e1000g *Adapter)
17295273Sgl147354 {
17305273Sgl147354 	e1000g_stop(Adapter, B_TRUE);
17315273Sgl147354 
17325273Sgl147354 	Adapter->init_count = 0;
17335273Sgl147354 
17345273Sgl147354 	if (e1000g_start(Adapter, B_TRUE)) {
17355273Sgl147354 		e1000g_log(Adapter, CE_WARN, "Reset failed");
17365273Sgl147354 		return (B_FALSE);
17375273Sgl147354 	}
17385273Sgl147354 
17395273Sgl147354 	return (B_TRUE);
17405273Sgl147354 }
17415273Sgl147354 
17423526Sxy150489 /*
17434919Sxy150489  * e1000g_intr_pciexpress - ISR for PCI Express chipsets
17444919Sxy150489  *
17454919Sxy150489  * This interrupt service routine is for PCI-Express adapters.
17464919Sxy150489  * The ICR contents is valid only when the E1000_ICR_INT_ASSERTED
17474919Sxy150489  * bit is set.
17483526Sxy150489  */
17493526Sxy150489 static uint_t
17503526Sxy150489 e1000g_intr_pciexpress(caddr_t arg)
17513526Sxy150489 {
17523526Sxy150489 	struct e1000g *Adapter;
17534919Sxy150489 	uint32_t icr;
17543526Sxy150489 
17553526Sxy150489 	Adapter = (struct e1000g *)arg;
17564919Sxy150489 	icr = E1000_READ_REG(&Adapter->shared, E1000_ICR);
17574919Sxy150489 
17585273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
17595273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
17605273Sgl147354 
17614919Sxy150489 	if (icr & E1000_ICR_INT_ASSERTED) {
17623526Sxy150489 		/*
17633526Sxy150489 		 * E1000_ICR_INT_ASSERTED bit was set:
17643526Sxy150489 		 * Read(Clear) the ICR, claim this interrupt,
17653526Sxy150489 		 * look for work to do.
17663526Sxy150489 		 */
17674919Sxy150489 		e1000g_intr_work(Adapter, icr);
17683526Sxy150489 		return (DDI_INTR_CLAIMED);
17693526Sxy150489 	} else {
17703526Sxy150489 		/*
17713526Sxy150489 		 * E1000_ICR_INT_ASSERTED bit was not set:
17723526Sxy150489 		 * Don't claim this interrupt, return immediately.
17733526Sxy150489 		 */
17743526Sxy150489 		return (DDI_INTR_UNCLAIMED);
17753526Sxy150489 	}
17763526Sxy150489 }
17773526Sxy150489 
17783526Sxy150489 /*
17794919Sxy150489  * e1000g_intr - ISR for PCI/PCI-X chipsets
17804919Sxy150489  *
17814919Sxy150489  * This interrupt service routine is for PCI/PCI-X adapters.
17824919Sxy150489  * We check the ICR contents no matter the E1000_ICR_INT_ASSERTED
17834919Sxy150489  * bit is set or not.
17843526Sxy150489  */
17853526Sxy150489 static uint_t
17863526Sxy150489 e1000g_intr(caddr_t arg)
17873526Sxy150489 {
17883526Sxy150489 	struct e1000g *Adapter;
17894919Sxy150489 	uint32_t icr;
17903526Sxy150489 
17913526Sxy150489 	Adapter = (struct e1000g *)arg;
17924919Sxy150489 	icr = E1000_READ_REG(&Adapter->shared, E1000_ICR);
17934919Sxy150489 
17945273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
17955273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
17965273Sgl147354 
17974919Sxy150489 	if (icr) {
17983526Sxy150489 		/*
17993526Sxy150489 		 * Any bit was set in ICR:
18003526Sxy150489 		 * Read(Clear) the ICR, claim this interrupt,
18013526Sxy150489 		 * look for work to do.
18023526Sxy150489 		 */
18034919Sxy150489 		e1000g_intr_work(Adapter, icr);
18043526Sxy150489 		return (DDI_INTR_CLAIMED);
18053526Sxy150489 	} else {
18063526Sxy150489 		/*
18073526Sxy150489 		 * No bit was set in ICR:
18083526Sxy150489 		 * Don't claim this interrupt, return immediately.
18093526Sxy150489 		 */
18103526Sxy150489 		return (DDI_INTR_UNCLAIMED);
18113526Sxy150489 	}
18123526Sxy150489 }
18133526Sxy150489 
18143526Sxy150489 /*
18154919Sxy150489  * e1000g_intr_work - actual processing of ISR
18164919Sxy150489  *
18174919Sxy150489  * Read(clear) the ICR contents and call appropriate interrupt
18184919Sxy150489  * processing routines.
18193526Sxy150489  */
18203526Sxy150489 static void
18214919Sxy150489 e1000g_intr_work(struct e1000g *Adapter, uint32_t icr)
18223526Sxy150489 {
18235882Syy150190 	struct e1000_hw *hw;
18245882Syy150190 	hw = &Adapter->shared;
18255882Syy150190 	e1000g_tx_ring_t *tx_ring = Adapter->tx_ring;
18265882Syy150190 	uint32_t itr;
18275882Syy150190 
18285882Syy150190 	Adapter->rx_pkt_cnt = 0;
18295882Syy150190 	Adapter->tx_pkt_cnt = 0;
18305882Syy150190 
18314919Sxy150489 	rw_enter(&Adapter->chip_lock, RW_READER);
18324919Sxy150489 	/*
18335273Sgl147354 	 * Here we need to check the "chip_state" flag within the chip_lock to
18344919Sxy150489 	 * ensure the receive routine will not execute when the adapter is
18354919Sxy150489 	 * being reset.
18364919Sxy150489 	 */
18375273Sgl147354 	if (Adapter->chip_state != E1000G_START) {
18384919Sxy150489 		rw_exit(&Adapter->chip_lock);
18394919Sxy150489 		return;
18404919Sxy150489 	}
18414919Sxy150489 
18424919Sxy150489 	if (icr & E1000_ICR_RXT0) {
18433526Sxy150489 		mblk_t *mp;
18443526Sxy150489 
18456735Scc210113 		mutex_enter(&Adapter->rx_ring->rx_lock);
18464919Sxy150489 		mp = e1000g_receive(Adapter);
18476735Scc210113 		mutex_exit(&Adapter->rx_ring->rx_lock);
18484919Sxy150489 
18494919Sxy150489 		rw_exit(&Adapter->chip_lock);
18504919Sxy150489 
18514919Sxy150489 		if (mp != NULL)
18524919Sxy150489 			mac_rx(Adapter->mh, Adapter->mrh, mp);
18534919Sxy150489 	} else
18544919Sxy150489 		rw_exit(&Adapter->chip_lock);
18553526Sxy150489 
18565882Syy150190 	if (icr & E1000_ICR_TXDW) {
18575882Syy150190 		if (!Adapter->tx_intr_enable)
18585882Syy150190 			e1000g_clear_tx_interrupt(Adapter);
18595882Syy150190 
18605882Syy150190 		/* Recycle the tx descriptors */
18615882Syy150190 		rw_enter(&Adapter->chip_lock, RW_READER);
18625882Syy150190 		e1000g_recycle(tx_ring);
18635882Syy150190 		E1000G_DEBUG_STAT(tx_ring->stat_recycle_intr);
18645882Syy150190 		rw_exit(&Adapter->chip_lock);
18655882Syy150190 
18665882Syy150190 		/* Schedule the re-transmit */
18675882Syy150190 		if (tx_ring->resched_needed &&
18685882Syy150190 		    (tx_ring->tbd_avail > DEFAULT_TX_UPDATE_THRESHOLD)) {
18695882Syy150190 			tx_ring->resched_needed = B_FALSE;
18705882Syy150190 			mac_tx_update(Adapter->mh);
18715882Syy150190 			E1000G_STAT(tx_ring->stat_reschedule);
18725882Syy150190 		}
18735882Syy150190 	}
18745882Syy150190 
18755882Syy150190 	if (Adapter->intr_adaptive) {
18765882Syy150190 		itr = e1000g_get_itr(Adapter->rx_pkt_cnt, Adapter->tx_pkt_cnt,
18775882Syy150190 		    Adapter->intr_throttling_rate);
18785882Syy150190 		if (itr) {
18795882Syy150190 			E1000_WRITE_REG(hw, E1000_ITR, itr);
18805882Syy150190 			Adapter->intr_throttling_rate = itr;
18815882Syy150190 		}
18825882Syy150190 	}
18835882Syy150190 
18843526Sxy150489 	/*
18853526Sxy150489 	 * The Receive Sequence errors RXSEQ and the link status change LSC
18863526Sxy150489 	 * are checked to detect that the cable has been pulled out. For
18873526Sxy150489 	 * the Wiseman 2.0 silicon, the receive sequence errors interrupt
18883526Sxy150489 	 * are an indication that cable is not connected.
18893526Sxy150489 	 */
18904919Sxy150489 	if ((icr & E1000_ICR_RXSEQ) ||
18914919Sxy150489 	    (icr & E1000_ICR_LSC) ||
18924919Sxy150489 	    (icr & E1000_ICR_GPI_EN1)) {
18934061Sxy150489 		boolean_t link_changed;
18944061Sxy150489 		timeout_id_t tid = 0;
18953526Sxy150489 
18964919Sxy150489 		stop_watchdog_timer(Adapter);
18974919Sxy150489 
18985082Syy150190 		rw_enter(&Adapter->chip_lock, RW_WRITER);
18995082Syy150190 
19005082Syy150190 		/*
19015082Syy150190 		 * Because we got a link-status-change interrupt, force
19025082Syy150190 		 * e1000_check_for_link() to look at phy
19035082Syy150190 		 */
19045082Syy150190 		Adapter->shared.mac.get_link_status = B_TRUE;
19055082Syy150190 
19064061Sxy150489 		/* e1000g_link_check takes care of link status change */
19074061Sxy150489 		link_changed = e1000g_link_check(Adapter);
19085082Syy150190 
19095082Syy150190 		/* Get new phy state */
19105082Syy150190 		e1000g_get_phy_state(Adapter);
19115082Syy150190 
19124061Sxy150489 		/*
19134061Sxy150489 		 * If the link timer has not timed out, we'll not notify
19144919Sxy150489 		 * the upper layer with any link state until the link is up.
19154061Sxy150489 		 */
19164061Sxy150489 		if (link_changed && !Adapter->link_complete) {
19174061Sxy150489 			if (Adapter->link_state == LINK_STATE_UP) {
19185082Syy150190 				mutex_enter(&Adapter->link_lock);
19194061Sxy150489 				Adapter->link_complete = B_TRUE;
19204061Sxy150489 				tid = Adapter->link_tid;
19214061Sxy150489 				Adapter->link_tid = 0;
19225082Syy150190 				mutex_exit(&Adapter->link_lock);
19234061Sxy150489 			} else {
19244061Sxy150489 				link_changed = B_FALSE;
19254061Sxy150489 			}
19264061Sxy150489 		}
19275082Syy150190 		rw_exit(&Adapter->chip_lock);
19283526Sxy150489 
19294061Sxy150489 		if (link_changed) {
19304061Sxy150489 			if (tid != 0)
19314061Sxy150489 				(void) untimeout(tid);
19324061Sxy150489 
19334139Sxy150489 			/*
19344139Sxy150489 			 * Workaround for esb2. Data stuck in fifo on a link
19354139Sxy150489 			 * down event. Reset the adapter to recover it.
19364139Sxy150489 			 */
19374139Sxy150489 			if ((Adapter->link_state == LINK_STATE_DOWN) &&
19384919Sxy150489 			    (Adapter->shared.mac.type == e1000_80003es2lan))
19394139Sxy150489 				(void) e1000g_reset(Adapter);
19404139Sxy150489 
19414061Sxy150489 			mac_link_update(Adapter->mh, Adapter->link_state);
19423526Sxy150489 		}
19433526Sxy150489 
19444919Sxy150489 		start_watchdog_timer(Adapter);
19453526Sxy150489 	}
19465882Syy150190 }
19475882Syy150190 
19485882Syy150190 static uint32_t
19495882Syy150190 e1000g_get_itr(uint32_t rx_packet, uint32_t tx_packet, uint32_t cur_itr)
19505882Syy150190 {
19515882Syy150190 	uint32_t new_itr;
19525882Syy150190 
19535882Syy150190 	/*
19545882Syy150190 	 * Determine a propper itr according to rx/tx packet count
19555882Syy150190 	 * per interrupt, the value of itr are based on document
19565882Syy150190 	 * and testing.
19575882Syy150190 	 */
19585882Syy150190 	if ((rx_packet < DEFAULT_INTR_PACKET_LOW) ||
19595882Syy150190 	    (tx_packet < DEFAULT_INTR_PACKET_LOW)) {
19605882Syy150190 		new_itr = DEFAULT_INTR_THROTTLING_LOW;
19615882Syy150190 		goto itr_done;
19623526Sxy150489 	}
19635882Syy150190 	if ((rx_packet > DEFAULT_INTR_PACKET_HIGH) ||
19645882Syy150190 	    (tx_packet > DEFAULT_INTR_PACKET_HIGH)) {
19655882Syy150190 		new_itr = DEFAULT_INTR_THROTTLING_LOW;
19665882Syy150190 		goto itr_done;
19675882Syy150190 	}
19685882Syy150190 	if (cur_itr < DEFAULT_INTR_THROTTLING_HIGH) {
19695882Syy150190 		new_itr = cur_itr + (DEFAULT_INTR_THROTTLING_HIGH >> 2);
19705882Syy150190 		if (new_itr > DEFAULT_INTR_THROTTLING_HIGH)
19715882Syy150190 			new_itr = DEFAULT_INTR_THROTTLING_HIGH;
19725882Syy150190 	} else
19735882Syy150190 		new_itr = DEFAULT_INTR_THROTTLING_HIGH;
19745882Syy150190 
19755882Syy150190 itr_done:
19765882Syy150190 	if (cur_itr == new_itr)
19775882Syy150190 		return (0);
19785882Syy150190 	else
19795882Syy150190 		return (new_itr);
19803526Sxy150489 }
19813526Sxy150489 
19823526Sxy150489 static void
19833526Sxy150489 e1000g_init_unicst(struct e1000g *Adapter)
19843526Sxy150489 {
19853526Sxy150489 	struct e1000_hw *hw;
19863526Sxy150489 	int slot;
19873526Sxy150489 
19884919Sxy150489 	hw = &Adapter->shared;
19893526Sxy150489 
19905273Sgl147354 	if (!Adapter->unicst_init) {
19913526Sxy150489 		/* Initialize the multiple unicast addresses */
19923526Sxy150489 		Adapter->unicst_total = MAX_NUM_UNICAST_ADDRESSES;
19933526Sxy150489 
19944919Sxy150489 		if ((hw->mac.type == e1000_82571) &&
19954919Sxy150489 		    (e1000_get_laa_state_82571(hw) == B_TRUE))
19963526Sxy150489 			Adapter->unicst_total--;
19973526Sxy150489 
19983526Sxy150489 		Adapter->unicst_avail = Adapter->unicst_total - 1;
19993526Sxy150489 
20003526Sxy150489 		/* Store the default mac address */
20014919Sxy150489 		e1000_rar_set(hw, hw->mac.addr, 0);
20024919Sxy150489 		if ((hw->mac.type == e1000_82571) &&
20034919Sxy150489 		    (e1000_get_laa_state_82571(hw) == B_TRUE))
20044919Sxy150489 			e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY);
20054919Sxy150489 
20064919Sxy150489 		bcopy(hw->mac.addr, Adapter->unicst_addr[0].mac.addr,
20073526Sxy150489 		    ETHERADDRL);
20083526Sxy150489 		Adapter->unicst_addr[0].mac.set = 1;
20093526Sxy150489 
20103526Sxy150489 		for (slot = 1; slot < Adapter->unicst_total; slot++)
20113526Sxy150489 			Adapter->unicst_addr[slot].mac.set = 0;
20125273Sgl147354 
20135273Sgl147354 		Adapter->unicst_init = B_TRUE;
20143526Sxy150489 	} else {
20153526Sxy150489 		/* Recover the default mac address */
20164919Sxy150489 		bcopy(Adapter->unicst_addr[0].mac.addr, hw->mac.addr,
20173526Sxy150489 		    ETHERADDRL);
20183526Sxy150489 
20193526Sxy150489 		/* Store the default mac address */
20204919Sxy150489 		e1000_rar_set(hw, hw->mac.addr, 0);
20214919Sxy150489 		if ((hw->mac.type == e1000_82571) &&
20224919Sxy150489 		    (e1000_get_laa_state_82571(hw) == B_TRUE))
20234919Sxy150489 			e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY);
20243526Sxy150489 
20253526Sxy150489 		/* Re-configure the RAR registers */
20263526Sxy150489 		for (slot = 1; slot < Adapter->unicst_total; slot++)
20273526Sxy150489 			e1000_rar_set(hw,
20283526Sxy150489 			    Adapter->unicst_addr[slot].mac.addr, slot);
20293526Sxy150489 	}
20305273Sgl147354 
20315273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
20325273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
20333526Sxy150489 }
20343526Sxy150489 
20353526Sxy150489 static int
20363526Sxy150489 e1000g_m_unicst(void *arg, const uint8_t *mac_addr)
20373526Sxy150489 {
20383526Sxy150489 	struct e1000g *Adapter;
20393526Sxy150489 
20403526Sxy150489 	Adapter = (struct e1000g *)arg;
20413526Sxy150489 
20423526Sxy150489 	/* Store the default MAC address */
20434919Sxy150489 	bcopy(mac_addr, Adapter->shared.mac.addr, ETHERADDRL);
20443526Sxy150489 
20453526Sxy150489 	/* Set MAC address in address slot 0, which is the default address */
20463526Sxy150489 	return (e1000g_unicst_set(Adapter, mac_addr, 0));
20473526Sxy150489 }
20483526Sxy150489 
20493526Sxy150489 static int
20503526Sxy150489 e1000g_unicst_set(struct e1000g *Adapter, const uint8_t *mac_addr,
20513526Sxy150489     mac_addr_slot_t slot)
20523526Sxy150489 {
20533526Sxy150489 	struct e1000_hw *hw;
20543526Sxy150489 
20554919Sxy150489 	hw = &Adapter->shared;
20563526Sxy150489 
20573526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
20583526Sxy150489 
20593526Sxy150489 	/*
20603526Sxy150489 	 * The first revision of Wiseman silicon (rev 2.0) has an errata
20613526Sxy150489 	 * that requires the receiver to be in reset when any of the
20623526Sxy150489 	 * receive address registers (RAR regs) are accessed.  The first
20633526Sxy150489 	 * rev of Wiseman silicon also requires MWI to be disabled when
20643526Sxy150489 	 * a global reset or a receive reset is issued.  So before we
20653526Sxy150489 	 * initialize the RARs, we check the rev of the Wiseman controller
20663526Sxy150489 	 * and work around any necessary HW errata.
20673526Sxy150489 	 */
20684919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
20694919Sxy150489 	    (hw->revision_id == E1000_REVISION_2)) {
20703526Sxy150489 		e1000_pci_clear_mwi(hw);
20714919Sxy150489 		E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST);
20724919Sxy150489 		msec_delay(5);
20733526Sxy150489 	}
20743526Sxy150489 
20753526Sxy150489 	bcopy(mac_addr, Adapter->unicst_addr[slot].mac.addr, ETHERADDRL);
20763526Sxy150489 	e1000_rar_set(hw, (uint8_t *)mac_addr, slot);
20773526Sxy150489 
20783526Sxy150489 	if (slot == 0) {
20794919Sxy150489 		if ((hw->mac.type == e1000_82571) &&
20804919Sxy150489 		    (e1000_get_laa_state_82571(hw) == B_TRUE))
20814919Sxy150489 			e1000_rar_set(hw, (uint8_t *)mac_addr, LAST_RAR_ENTRY);
20823526Sxy150489 	}
20833526Sxy150489 
20843526Sxy150489 	/*
20853526Sxy150489 	 * If we are using Wiseman rev 2.0 silicon, we will have previously
20863526Sxy150489 	 * put the receive in reset, and disabled MWI, to work around some
20873526Sxy150489 	 * HW errata.  Now we should take the receiver out of reset, and
20883526Sxy150489 	 * re-enabled if MWI if it was previously enabled by the PCI BIOS.
20893526Sxy150489 	 */
20904919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
20914919Sxy150489 	    (hw->revision_id == E1000_REVISION_2)) {
20924919Sxy150489 		E1000_WRITE_REG(hw, E1000_RCTL, 0);
20934919Sxy150489 		msec_delay(1);
20944919Sxy150489 		if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
20953526Sxy150489 			e1000_pci_set_mwi(hw);
20964919Sxy150489 		e1000g_rx_setup(Adapter);
20973526Sxy150489 	}
20983526Sxy150489 
20993526Sxy150489 	rw_exit(&Adapter->chip_lock);
21003526Sxy150489 
21015273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
21025273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
21035273Sgl147354 		return (EIO);
21045273Sgl147354 	}
21055273Sgl147354 
21063526Sxy150489 	return (0);
21073526Sxy150489 }
21083526Sxy150489 
21093526Sxy150489 /*
21103526Sxy150489  * e1000g_m_unicst_add() - will find an unused address slot, set the
21113526Sxy150489  * address value to the one specified, reserve that slot and enable
21123526Sxy150489  * the NIC to start filtering on the new MAC address.
21133526Sxy150489  * Returns 0 on success.
21143526Sxy150489  */
21153526Sxy150489 static int
21163526Sxy150489 e1000g_m_unicst_add(void *arg, mac_multi_addr_t *maddr)
21173526Sxy150489 {
21183526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
21193526Sxy150489 	mac_addr_slot_t slot;
21203526Sxy150489 	int err;
21213526Sxy150489 
21223526Sxy150489 	if (mac_unicst_verify(Adapter->mh,
21233526Sxy150489 	    maddr->mma_addr, maddr->mma_addrlen) == B_FALSE)
21243526Sxy150489 		return (EINVAL);
21253526Sxy150489 
21263526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
21273526Sxy150489 	if (Adapter->unicst_avail == 0) {
21283526Sxy150489 		/* no slots available */
21293526Sxy150489 		rw_exit(&Adapter->chip_lock);
21303526Sxy150489 		return (ENOSPC);
21313526Sxy150489 	}
21323526Sxy150489 
21333526Sxy150489 	/*
21343526Sxy150489 	 * Primary/default address is in slot 0. The next addresses
21353526Sxy150489 	 * are the multiple MAC addresses. So multiple MAC address 0
21363526Sxy150489 	 * is in slot 1, 1 in slot 2, and so on. So the first multiple
21373526Sxy150489 	 * MAC address resides in slot 1.
21383526Sxy150489 	 */
21393526Sxy150489 	for (slot = 1; slot < Adapter->unicst_total; slot++) {
21403526Sxy150489 		if (Adapter->unicst_addr[slot].mac.set == 0) {
21413526Sxy150489 			Adapter->unicst_addr[slot].mac.set = 1;
21423526Sxy150489 			break;
21433526Sxy150489 		}
21443526Sxy150489 	}
21453526Sxy150489 
21463526Sxy150489 	ASSERT((slot > 0) && (slot < Adapter->unicst_total));
21473526Sxy150489 
21483526Sxy150489 	Adapter->unicst_avail--;
21493526Sxy150489 	rw_exit(&Adapter->chip_lock);
21503526Sxy150489 
21513526Sxy150489 	maddr->mma_slot = slot;
21523526Sxy150489 
21533526Sxy150489 	if ((err = e1000g_unicst_set(Adapter, maddr->mma_addr, slot)) != 0) {
21543526Sxy150489 		rw_enter(&Adapter->chip_lock, RW_WRITER);
21553526Sxy150489 		Adapter->unicst_addr[slot].mac.set = 0;
21563526Sxy150489 		Adapter->unicst_avail++;
21573526Sxy150489 		rw_exit(&Adapter->chip_lock);
21583526Sxy150489 	}
21593526Sxy150489 
21603526Sxy150489 	return (err);
21613526Sxy150489 }
21623526Sxy150489 
21633526Sxy150489 /*
21643526Sxy150489  * e1000g_m_unicst_remove() - removes a MAC address that was added by a
21653526Sxy150489  * call to e1000g_m_unicst_add(). The slot number that was returned in
21663526Sxy150489  * e1000g_m_unicst_add() is passed in the call to remove the address.
21673526Sxy150489  * Returns 0 on success.
21683526Sxy150489  */
21693526Sxy150489 static int
21703526Sxy150489 e1000g_m_unicst_remove(void *arg, mac_addr_slot_t slot)
21713526Sxy150489 {
21723526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
21733526Sxy150489 	int err;
21743526Sxy150489 
21753526Sxy150489 	if ((slot <= 0) || (slot >= Adapter->unicst_total))
21763526Sxy150489 		return (EINVAL);
21773526Sxy150489 
21783526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
21793526Sxy150489 	if (Adapter->unicst_addr[slot].mac.set == 1) {
21803526Sxy150489 		Adapter->unicst_addr[slot].mac.set = 0;
21813526Sxy150489 		Adapter->unicst_avail++;
21823526Sxy150489 		rw_exit(&Adapter->chip_lock);
21833526Sxy150489 
21843526Sxy150489 		/* Copy the default address to the passed slot */
21853526Sxy150489 		if (err = e1000g_unicst_set(Adapter,
21863526Sxy150489 		    Adapter->unicst_addr[0].mac.addr, slot) != 0) {
21873526Sxy150489 			rw_enter(&Adapter->chip_lock, RW_WRITER);
21883526Sxy150489 			Adapter->unicst_addr[slot].mac.set = 1;
21893526Sxy150489 			Adapter->unicst_avail--;
21903526Sxy150489 			rw_exit(&Adapter->chip_lock);
21913526Sxy150489 		}
21923526Sxy150489 		return (err);
21933526Sxy150489 	}
21943526Sxy150489 	rw_exit(&Adapter->chip_lock);
21953526Sxy150489 
21963526Sxy150489 	return (EINVAL);
21973526Sxy150489 }
21983526Sxy150489 
21993526Sxy150489 /*
22003526Sxy150489  * e1000g_m_unicst_modify() - modifies the value of an address that
22013526Sxy150489  * has been added by e1000g_m_unicst_add(). The new address, address
22023526Sxy150489  * length and the slot number that was returned in the call to add
22033526Sxy150489  * should be passed to e1000g_m_unicst_modify(). mma_flags should be
22043526Sxy150489  * set to 0. Returns 0 on success.
22053526Sxy150489  */
22063526Sxy150489 static int
22073526Sxy150489 e1000g_m_unicst_modify(void *arg, mac_multi_addr_t *maddr)
22083526Sxy150489 {
22093526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
22103526Sxy150489 	mac_addr_slot_t slot;
22113526Sxy150489 
22123526Sxy150489 	if (mac_unicst_verify(Adapter->mh,
22133526Sxy150489 	    maddr->mma_addr, maddr->mma_addrlen) == B_FALSE)
22143526Sxy150489 		return (EINVAL);
22153526Sxy150489 
22163526Sxy150489 	slot = maddr->mma_slot;
22173526Sxy150489 
22183526Sxy150489 	if ((slot <= 0) || (slot >= Adapter->unicst_total))
22193526Sxy150489 		return (EINVAL);
22203526Sxy150489 
22213526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
22223526Sxy150489 	if (Adapter->unicst_addr[slot].mac.set == 1) {
22233526Sxy150489 		rw_exit(&Adapter->chip_lock);
22243526Sxy150489 
22253526Sxy150489 		return (e1000g_unicst_set(Adapter, maddr->mma_addr, slot));
22263526Sxy150489 	}
22273526Sxy150489 	rw_exit(&Adapter->chip_lock);
22283526Sxy150489 
22293526Sxy150489 	return (EINVAL);
22303526Sxy150489 }
22313526Sxy150489 
22323526Sxy150489 /*
22333526Sxy150489  * e1000g_m_unicst_get() - will get the MAC address and all other
22343526Sxy150489  * information related to the address slot passed in mac_multi_addr_t.
22353526Sxy150489  * mma_flags should be set to 0 in the call.
22363526Sxy150489  * On return, mma_flags can take the following values:
22373526Sxy150489  * 1) MMAC_SLOT_UNUSED
22383526Sxy150489  * 2) MMAC_SLOT_USED | MMAC_VENDOR_ADDR
22393526Sxy150489  * 3) MMAC_SLOT_UNUSED | MMAC_VENDOR_ADDR
22403526Sxy150489  * 4) MMAC_SLOT_USED
22413526Sxy150489  */
22423526Sxy150489 static int
22433526Sxy150489 e1000g_m_unicst_get(void *arg, mac_multi_addr_t *maddr)
22443526Sxy150489 {
22453526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
22463526Sxy150489 	mac_addr_slot_t slot;
22473526Sxy150489 
22483526Sxy150489 	slot = maddr->mma_slot;
22493526Sxy150489 
22503526Sxy150489 	if ((slot <= 0) || (slot >= Adapter->unicst_total))
22513526Sxy150489 		return (EINVAL);
22523526Sxy150489 
22533526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
22543526Sxy150489 	if (Adapter->unicst_addr[slot].mac.set == 1) {
22553526Sxy150489 		bcopy(Adapter->unicst_addr[slot].mac.addr,
22563526Sxy150489 		    maddr->mma_addr, ETHERADDRL);
22573526Sxy150489 		maddr->mma_flags = MMAC_SLOT_USED;
22583526Sxy150489 	} else {
22593526Sxy150489 		maddr->mma_flags = MMAC_SLOT_UNUSED;
22603526Sxy150489 	}
22613526Sxy150489 	rw_exit(&Adapter->chip_lock);
22623526Sxy150489 
22633526Sxy150489 	return (0);
22643526Sxy150489 }
22653526Sxy150489 
22663526Sxy150489 static int
22673526Sxy150489 multicst_add(struct e1000g *Adapter, const uint8_t *multiaddr)
22683526Sxy150489 {
22694919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
22703526Sxy150489 	unsigned i;
22713526Sxy150489 	int res = 0;
22723526Sxy150489 
22733526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
22743526Sxy150489 
22753526Sxy150489 	if ((multiaddr[0] & 01) == 0) {
22763526Sxy150489 		res = EINVAL;
22773526Sxy150489 		goto done;
22783526Sxy150489 	}
22793526Sxy150489 
22803526Sxy150489 	if (Adapter->mcast_count >= MAX_NUM_MULTICAST_ADDRESSES) {
22813526Sxy150489 		res = ENOENT;
22823526Sxy150489 		goto done;
22833526Sxy150489 	}
22843526Sxy150489 
22853526Sxy150489 	bcopy(multiaddr,
22863526Sxy150489 	    &Adapter->mcast_table[Adapter->mcast_count], ETHERADDRL);
22873526Sxy150489 	Adapter->mcast_count++;
22883526Sxy150489 
22893526Sxy150489 	/*
22903526Sxy150489 	 * Update the MC table in the hardware
22913526Sxy150489 	 */
22924919Sxy150489 	e1000g_clear_interrupt(Adapter);
22934919Sxy150489 
22944919Sxy150489 	e1000g_setup_multicast(Adapter);
22954919Sxy150489 
22964919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
22974919Sxy150489 	    (hw->revision_id == E1000_REVISION_2))
22984919Sxy150489 		e1000g_rx_setup(Adapter);
22994919Sxy150489 
23004919Sxy150489 	e1000g_mask_interrupt(Adapter);
23013526Sxy150489 
23023526Sxy150489 done:
23033526Sxy150489 	rw_exit(&Adapter->chip_lock);
23045273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
23055273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
23065273Sgl147354 		res = EIO;
23075273Sgl147354 	}
23085273Sgl147354 
23093526Sxy150489 	return (res);
23103526Sxy150489 }
23113526Sxy150489 
23123526Sxy150489 static int
23133526Sxy150489 multicst_remove(struct e1000g *Adapter, const uint8_t *multiaddr)
23143526Sxy150489 {
23154919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
23163526Sxy150489 	unsigned i;
23173526Sxy150489 
23183526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
23193526Sxy150489 
23203526Sxy150489 	for (i = 0; i < Adapter->mcast_count; i++) {
23213526Sxy150489 		if (bcmp(multiaddr, &Adapter->mcast_table[i],
23223526Sxy150489 		    ETHERADDRL) == 0) {
23233526Sxy150489 			for (i++; i < Adapter->mcast_count; i++) {
23243526Sxy150489 				Adapter->mcast_table[i - 1] =
23253526Sxy150489 				    Adapter->mcast_table[i];
23263526Sxy150489 			}
23273526Sxy150489 			Adapter->mcast_count--;
23283526Sxy150489 			break;
23293526Sxy150489 		}
23303526Sxy150489 	}
23313526Sxy150489 
23323526Sxy150489 	/*
23333526Sxy150489 	 * Update the MC table in the hardware
23343526Sxy150489 	 */
23354919Sxy150489 	e1000g_clear_interrupt(Adapter);
23364919Sxy150489 
23374919Sxy150489 	e1000g_setup_multicast(Adapter);
23384919Sxy150489 
23394919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
23404919Sxy150489 	    (hw->revision_id == E1000_REVISION_2))
23414919Sxy150489 		e1000g_rx_setup(Adapter);
23424919Sxy150489 
23434919Sxy150489 	e1000g_mask_interrupt(Adapter);
23443526Sxy150489 
23453526Sxy150489 done:
23463526Sxy150489 	rw_exit(&Adapter->chip_lock);
23475273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
23485273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
23495273Sgl147354 		return (EIO);
23505273Sgl147354 	}
23515273Sgl147354 
23523526Sxy150489 	return (0);
23533526Sxy150489 }
23543526Sxy150489 
23554919Sxy150489 /*
23564919Sxy150489  * e1000g_setup_multicast - setup multicast data structures
23574919Sxy150489  *
23584919Sxy150489  * This routine initializes all of the multicast related structures.
23594919Sxy150489  */
23604919Sxy150489 void
23614919Sxy150489 e1000g_setup_multicast(struct e1000g *Adapter)
23624919Sxy150489 {
23634919Sxy150489 	uint8_t *mc_addr_list;
23644919Sxy150489 	uint32_t mc_addr_count;
23654919Sxy150489 	uint32_t rctl;
23664919Sxy150489 	struct e1000_hw *hw;
23674919Sxy150489 
23684919Sxy150489 	hw = &Adapter->shared;
23694919Sxy150489 
23704919Sxy150489 	/*
23714919Sxy150489 	 * The e1000g has the ability to do perfect filtering of 16
23724919Sxy150489 	 * addresses. The driver uses one of the e1000g's 16 receive
23734919Sxy150489 	 * address registers for its node/network/mac/individual address.
23744919Sxy150489 	 * So, we have room for up to 15 multicast addresses in the CAM,
23754919Sxy150489 	 * additional MC addresses are handled by the MTA (Multicast Table
23764919Sxy150489 	 * Array)
23774919Sxy150489 	 */
23784919Sxy150489 
23794919Sxy150489 	rctl = E1000_READ_REG(hw, E1000_RCTL);
23804919Sxy150489 
23814919Sxy150489 	mc_addr_list = (uint8_t *)Adapter->mcast_table;
23824919Sxy150489 
23834919Sxy150489 	if (Adapter->mcast_count > MAX_NUM_MULTICAST_ADDRESSES) {
23844919Sxy150489 		E1000G_DEBUGLOG_1(Adapter, CE_WARN,
23854919Sxy150489 		    "Adapter requested more than %d MC Addresses.\n",
23864919Sxy150489 		    MAX_NUM_MULTICAST_ADDRESSES);
23874919Sxy150489 		mc_addr_count = MAX_NUM_MULTICAST_ADDRESSES;
23884919Sxy150489 	} else {
23894919Sxy150489 		/*
23904919Sxy150489 		 * Set the number of MC addresses that we are being
23914919Sxy150489 		 * requested to use
23924919Sxy150489 		 */
23934919Sxy150489 		mc_addr_count = Adapter->mcast_count;
23944919Sxy150489 	}
23954919Sxy150489 	/*
23964919Sxy150489 	 * The Wiseman 2.0 silicon has an errata by which the receiver will
23974919Sxy150489 	 * hang  while writing to the receive address registers if the receiver
23984919Sxy150489 	 * is not in reset before writing to the registers. Updating the RAR
23994919Sxy150489 	 * is done during the setting up of the multicast table, hence the
24004919Sxy150489 	 * receiver has to be put in reset before updating the multicast table
24014919Sxy150489 	 * and then taken out of reset at the end
24024919Sxy150489 	 */
24034919Sxy150489 	/*
24044919Sxy150489 	 * if WMI was enabled then dis able it before issueing the global
24054919Sxy150489 	 * reset to the hardware.
24064919Sxy150489 	 */
24074919Sxy150489 	/*
24084919Sxy150489 	 * Only required for WISEMAN_2_0
24094919Sxy150489 	 */
24104919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
24114919Sxy150489 	    (hw->revision_id == E1000_REVISION_2)) {
24124919Sxy150489 		e1000_pci_clear_mwi(hw);
24134919Sxy150489 		/*
24144919Sxy150489 		 * The e1000g must be in reset before changing any RA
24154919Sxy150489 		 * registers. Reset receive unit.  The chip will remain in
24164919Sxy150489 		 * the reset state until software explicitly restarts it.
24174919Sxy150489 		 */
24184919Sxy150489 		E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST);
24194919Sxy150489 		/* Allow receiver time to go in to reset */
24204919Sxy150489 		msec_delay(5);
24214919Sxy150489 	}
24226735Scc210113 
24236735Scc210113 	e1000_update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
24244919Sxy150489 	    Adapter->unicst_total, hw->mac.rar_entry_count);
24254919Sxy150489 
24264919Sxy150489 	/*
24274919Sxy150489 	 * Only for Wiseman_2_0
24284919Sxy150489 	 * If MWI was enabled then re-enable it after issueing (as we
24294919Sxy150489 	 * disabled it up there) the receive reset command.
24304919Sxy150489 	 * Wainwright does not have a receive reset command and only thing
24314919Sxy150489 	 * close to it is global reset which will require tx setup also
24324919Sxy150489 	 */
24334919Sxy150489 	if ((hw->mac.type == e1000_82542) &&
24344919Sxy150489 	    (hw->revision_id == E1000_REVISION_2)) {
24354919Sxy150489 		/*
24364919Sxy150489 		 * if WMI was enabled then reenable it after issueing the
24374919Sxy150489 		 * global or receive reset to the hardware.
24384919Sxy150489 		 */
24394919Sxy150489 
24404919Sxy150489 		/*
24414919Sxy150489 		 * Take receiver out of reset
24424919Sxy150489 		 * clear E1000_RCTL_RST bit (and all others)
24434919Sxy150489 		 */
24444919Sxy150489 		E1000_WRITE_REG(hw, E1000_RCTL, 0);
24454919Sxy150489 		msec_delay(5);
24464919Sxy150489 		if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
24474919Sxy150489 			e1000_pci_set_mwi(hw);
24484919Sxy150489 	}
24494919Sxy150489 
24504919Sxy150489 	/*
24514919Sxy150489 	 * Restore original value
24524919Sxy150489 	 */
24534919Sxy150489 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
24544919Sxy150489 }
24554919Sxy150489 
24563526Sxy150489 int
24573526Sxy150489 e1000g_m_multicst(void *arg, boolean_t add, const uint8_t *addr)
24583526Sxy150489 {
24593526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
24603526Sxy150489 
24613526Sxy150489 	return ((add) ? multicst_add(Adapter, addr)
24624349Sxy150489 	    : multicst_remove(Adapter, addr));
24633526Sxy150489 }
24643526Sxy150489 
24653526Sxy150489 int
24663526Sxy150489 e1000g_m_promisc(void *arg, boolean_t on)
24673526Sxy150489 {
24683526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
24694919Sxy150489 	uint32_t rctl;
24703526Sxy150489 
24713526Sxy150489 	rw_enter(&Adapter->chip_lock, RW_WRITER);
24723526Sxy150489 
24734919Sxy150489 	rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL);
24743526Sxy150489 
24753526Sxy150489 	if (on)
24764919Sxy150489 		rctl |=
24773526Sxy150489 		    (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM);
24783526Sxy150489 	else
24794919Sxy150489 		rctl &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE));
24804919Sxy150489 
24814919Sxy150489 	E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl);
24823526Sxy150489 
24833526Sxy150489 	Adapter->e1000g_promisc = on;
24843526Sxy150489 
24853526Sxy150489 	rw_exit(&Adapter->chip_lock);
24863526Sxy150489 
24875273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
24885273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
24895273Sgl147354 		return (EIO);
24905273Sgl147354 	}
24915273Sgl147354 
24923526Sxy150489 	return (0);
24933526Sxy150489 }
24943526Sxy150489 
24953526Sxy150489 static boolean_t
24963526Sxy150489 e1000g_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
24973526Sxy150489 {
24983526Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
24994919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
25003526Sxy150489 
25013526Sxy150489 	switch (cap) {
25023526Sxy150489 	case MAC_CAPAB_HCKSUM: {
25033526Sxy150489 		uint32_t *txflags = cap_data;
2504*6986Smx205022 
2505*6986Smx205022 		if (Adapter->tx_hcksum_enable)
2506*6986Smx205022 			*txflags = HCKSUM_IPHDRCKSUM |
2507*6986Smx205022 			    HCKSUM_INET_PARTIAL;
2508*6986Smx205022 		else
25093526Sxy150489 			return (B_FALSE);
25103526Sxy150489 		break;
25113526Sxy150489 	}
25123526Sxy150489 	case MAC_CAPAB_POLL:
25133526Sxy150489 		/*
25143526Sxy150489 		 * There's nothing for us to fill in, simply returning
25153526Sxy150489 		 * B_TRUE stating that we support polling is sufficient.
25163526Sxy150489 		 */
25173526Sxy150489 		break;
25183526Sxy150489 
25193526Sxy150489 	case MAC_CAPAB_MULTIADDRESS: {
25203526Sxy150489 		multiaddress_capab_t *mmacp = cap_data;
25213526Sxy150489 
25223526Sxy150489 		/*
25233526Sxy150489 		 * The number of MAC addresses made available by
25243526Sxy150489 		 * this capability is one less than the total as
25253526Sxy150489 		 * the primary address in slot 0 is counted in
25263526Sxy150489 		 * the total.
25273526Sxy150489 		 */
25283526Sxy150489 		mmacp->maddr_naddr = Adapter->unicst_total - 1;
25293526Sxy150489 		mmacp->maddr_naddrfree = Adapter->unicst_avail;
25303526Sxy150489 		/* No multiple factory addresses, set mma_flag to 0 */
25313526Sxy150489 		mmacp->maddr_flag = 0;
25323526Sxy150489 		mmacp->maddr_handle = Adapter;
25333526Sxy150489 		mmacp->maddr_add = e1000g_m_unicst_add;
25343526Sxy150489 		mmacp->maddr_remove = e1000g_m_unicst_remove;
25353526Sxy150489 		mmacp->maddr_modify = e1000g_m_unicst_modify;
25363526Sxy150489 		mmacp->maddr_get = e1000g_m_unicst_get;
25373526Sxy150489 		mmacp->maddr_reserve = NULL;
25383526Sxy150489 		break;
25393526Sxy150489 	}
2540*6986Smx205022 
2541*6986Smx205022 	case MAC_CAPAB_LSO: {
2542*6986Smx205022 		mac_capab_lso_t *cap_lso = cap_data;
2543*6986Smx205022 
2544*6986Smx205022 		if (Adapter->lso_enable) {
2545*6986Smx205022 			cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4;
2546*6986Smx205022 			cap_lso->lso_basic_tcp_ipv4.lso_max =
2547*6986Smx205022 			    E1000_LSO_MAXLEN;
2548*6986Smx205022 		} else
2549*6986Smx205022 			return (B_FALSE);
2550*6986Smx205022 		break;
2551*6986Smx205022 	}
2552*6986Smx205022 
25533526Sxy150489 	default:
25543526Sxy150489 		return (B_FALSE);
25553526Sxy150489 	}
25563526Sxy150489 	return (B_TRUE);
25573526Sxy150489 }
25583526Sxy150489 
25596394Scc210113 static boolean_t
25606394Scc210113 e1000g_param_locked(mac_prop_id_t pr_num)
25616394Scc210113 {
25626394Scc210113 	/*
25636394Scc210113 	 * All en_* parameters are locked (read-only) while
25646394Scc210113 	 * the device is in any sort of loopback mode ...
25656394Scc210113 	 */
25666394Scc210113 	switch (pr_num) {
25676789Sam223141 		case MAC_PROP_EN_1000FDX_CAP:
25686789Sam223141 		case MAC_PROP_EN_1000HDX_CAP:
25696789Sam223141 		case MAC_PROP_EN_100FDX_CAP:
25706789Sam223141 		case MAC_PROP_EN_100HDX_CAP:
25716789Sam223141 		case MAC_PROP_EN_10FDX_CAP:
25726789Sam223141 		case MAC_PROP_EN_10HDX_CAP:
25736789Sam223141 		case MAC_PROP_AUTONEG:
25746789Sam223141 		case MAC_PROP_FLOWCTRL:
25756394Scc210113 			return (B_TRUE);
25766394Scc210113 	}
25776394Scc210113 	return (B_FALSE);
25786394Scc210113 }
25796394Scc210113 
25806394Scc210113 /*
25816394Scc210113  * callback function for set/get of properties
25826394Scc210113  */
25836394Scc210113 static int
25846394Scc210113 e1000g_m_setprop(void *arg, const char *pr_name, mac_prop_id_t pr_num,
25856394Scc210113     uint_t pr_valsize, const void *pr_val)
25866394Scc210113 {
25876394Scc210113 	struct e1000g *Adapter = arg;
25886394Scc210113 	struct e1000_mac_info *mac = &Adapter->shared.mac;
25896394Scc210113 	struct e1000_phy_info *phy = &Adapter->shared.phy;
25906735Scc210113 	struct e1000_fc_info *fc = &Adapter->shared.fc;
25916394Scc210113 	int err = 0;
25926735Scc210113 	link_flowctrl_t flowctrl;
25936512Ssowmini 	uint32_t cur_mtu, new_mtu;
25946394Scc210113 	uint64_t tmp = 0;
25956394Scc210113 
25966394Scc210113 	rw_enter(&Adapter->chip_lock, RW_WRITER);
25976394Scc210113 	if (Adapter->loopback_mode != E1000G_LB_NONE &&
25986394Scc210113 	    e1000g_param_locked(pr_num)) {
25996394Scc210113 		/*
26006394Scc210113 		 * All en_* parameters are locked (read-only)
26016394Scc210113 		 * while the device is in any sort of loopback mode.
26026394Scc210113 		 */
26036394Scc210113 		rw_exit(&Adapter->chip_lock);
26046394Scc210113 		return (EBUSY);
26056394Scc210113 	}
26066394Scc210113 
26076394Scc210113 	switch (pr_num) {
26086789Sam223141 		case MAC_PROP_EN_1000FDX_CAP:
26096394Scc210113 			Adapter->param_en_1000fdx = *(uint8_t *)pr_val;
26106394Scc210113 			Adapter->param_adv_1000fdx = *(uint8_t *)pr_val;
26116394Scc210113 			goto reset;
26126789Sam223141 		case MAC_PROP_EN_1000HDX_CAP:
26136394Scc210113 			Adapter->param_en_1000hdx = *(uint8_t *)pr_val;
26146394Scc210113 			Adapter->param_adv_1000hdx = *(uint8_t *)pr_val;
26156394Scc210113 			goto reset;
26166789Sam223141 		case MAC_PROP_EN_100FDX_CAP:
26176394Scc210113 			Adapter->param_en_100fdx = *(uint8_t *)pr_val;
26186394Scc210113 			Adapter->param_adv_100fdx = *(uint8_t *)pr_val;
26196394Scc210113 			goto reset;
26206789Sam223141 		case MAC_PROP_EN_100HDX_CAP:
26216394Scc210113 			Adapter->param_en_100hdx = *(uint8_t *)pr_val;
26226394Scc210113 			Adapter->param_adv_100hdx = *(uint8_t *)pr_val;
26236394Scc210113 			goto reset;
26246789Sam223141 		case MAC_PROP_EN_10FDX_CAP:
26256394Scc210113 			Adapter->param_en_10fdx = *(uint8_t *)pr_val;
26266394Scc210113 			Adapter->param_adv_10fdx = *(uint8_t *)pr_val;
26276394Scc210113 			goto reset;
26286789Sam223141 		case MAC_PROP_EN_10HDX_CAP:
26296394Scc210113 			Adapter->param_en_10hdx = *(uint8_t *)pr_val;
26306394Scc210113 			Adapter->param_adv_10hdx = *(uint8_t *)pr_val;
26316394Scc210113 			goto reset;
26326789Sam223141 		case MAC_PROP_AUTONEG:
26336394Scc210113 			Adapter->param_adv_autoneg = *(uint8_t *)pr_val;
26346394Scc210113 			goto reset;
26356789Sam223141 		case MAC_PROP_FLOWCTRL:
26366735Scc210113 			fc->send_xon = B_TRUE;
26376735Scc210113 			bcopy(pr_val, &flowctrl, sizeof (flowctrl));
26386735Scc210113 
26396735Scc210113 			switch (flowctrl) {
26406394Scc210113 			default:
26416394Scc210113 				err = EINVAL;
26426394Scc210113 				break;
26436394Scc210113 			case LINK_FLOWCTRL_NONE:
26446735Scc210113 				fc->type = e1000_fc_none;
26456394Scc210113 				break;
26466394Scc210113 			case LINK_FLOWCTRL_RX:
26476735Scc210113 				fc->type = e1000_fc_rx_pause;
26486394Scc210113 				break;
26496394Scc210113 			case LINK_FLOWCTRL_TX:
26506735Scc210113 				fc->type = e1000_fc_tx_pause;
26516394Scc210113 				break;
26526394Scc210113 			case LINK_FLOWCTRL_BI:
26536735Scc210113 				fc->type = e1000_fc_full;
26546394Scc210113 				break;
26556394Scc210113 			}
26566394Scc210113 reset:
26576394Scc210113 			if (err == 0) {
26586394Scc210113 				if (e1000g_reset_link(Adapter) != DDI_SUCCESS)
26596394Scc210113 					err = EINVAL;
26606394Scc210113 			}
26616394Scc210113 			break;
26626789Sam223141 		case MAC_PROP_ADV_1000FDX_CAP:
26636789Sam223141 		case MAC_PROP_ADV_1000HDX_CAP:
26646789Sam223141 		case MAC_PROP_ADV_100FDX_CAP:
26656789Sam223141 		case MAC_PROP_ADV_100HDX_CAP:
26666789Sam223141 		case MAC_PROP_ADV_10FDX_CAP:
26676789Sam223141 		case MAC_PROP_ADV_10HDX_CAP:
26686789Sam223141 		case MAC_PROP_STATUS:
26696789Sam223141 		case MAC_PROP_SPEED:
26706789Sam223141 		case MAC_PROP_DUPLEX:
26716394Scc210113 			err = ENOTSUP; /* read-only prop. Can't set this. */
26726394Scc210113 			break;
26736789Sam223141 		case MAC_PROP_MTU:
26746394Scc210113 			cur_mtu = Adapter->default_mtu;
26756394Scc210113 			bcopy(pr_val, &new_mtu, sizeof (new_mtu));
26766394Scc210113 			if (new_mtu == cur_mtu) {
26776394Scc210113 				err = 0;
26786394Scc210113 				break;
26796394Scc210113 			}
26806394Scc210113 
26816394Scc210113 			tmp = new_mtu + sizeof (struct ether_vlan_header) +
26826394Scc210113 			    ETHERFCSL;
26836394Scc210113 			if ((tmp < DEFAULT_FRAME_SIZE) ||
26846394Scc210113 			    (tmp > MAXIMUM_FRAME_SIZE)) {
26856394Scc210113 				err = EINVAL;
26866394Scc210113 				break;
26876394Scc210113 			}
26886394Scc210113 
26896394Scc210113 			/* ich8 doed not support jumbo frames */
26906394Scc210113 			if ((mac->type == e1000_ich8lan) &&
26916394Scc210113 			    (tmp > DEFAULT_FRAME_SIZE)) {
26926394Scc210113 				err = EINVAL;
26936394Scc210113 				break;
26946394Scc210113 			}
26956394Scc210113 			/* ich9 does not do jumbo frames on one phy type */
26966394Scc210113 			if ((mac->type == e1000_ich9lan) &&
26976394Scc210113 			    (phy->type == e1000_phy_ife) &&
26986394Scc210113 			    (tmp > DEFAULT_FRAME_SIZE)) {
26996394Scc210113 				err = EINVAL;
27006394Scc210113 				break;
27016394Scc210113 			}
27026394Scc210113 			if (Adapter->chip_state != E1000G_STOP) {
27036394Scc210113 				err = EBUSY;
27046394Scc210113 				break;
27056394Scc210113 			}
27066394Scc210113 
27076394Scc210113 			err = mac_maxsdu_update(Adapter->mh, new_mtu);
27086394Scc210113 			if (err == 0) {
27096735Scc210113 				Adapter->max_frame_size = tmp;
27106394Scc210113 				Adapter->default_mtu = new_mtu;
27116394Scc210113 				e1000g_set_bufsize(Adapter);
27126394Scc210113 			}
27136394Scc210113 			break;
27146789Sam223141 		case MAC_PROP_PRIVATE:
27156394Scc210113 			err = e1000g_set_priv_prop(Adapter, pr_name,
27166394Scc210113 			    pr_valsize, pr_val);
27176394Scc210113 			break;
27186394Scc210113 		default:
27196394Scc210113 			err = ENOTSUP;
27206394Scc210113 			break;
27216394Scc210113 	}
27226394Scc210113 	rw_exit(&Adapter->chip_lock);
27236394Scc210113 	return (err);
27246394Scc210113 }
27256394Scc210113 
27266394Scc210113 static int
27276394Scc210113 e1000g_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num,
27286512Ssowmini     uint_t pr_flags, uint_t pr_valsize, void *pr_val)
27296394Scc210113 {
27306394Scc210113 	struct e1000g *Adapter = arg;
27316394Scc210113 	struct e1000_mac_info *mac = &Adapter->shared.mac;
27326735Scc210113 	struct e1000_fc_info *fc = &Adapter->shared.fc;
27336512Ssowmini 	int err = 0;
27346735Scc210113 	link_flowctrl_t flowctrl;
27356394Scc210113 	uint64_t tmp = 0;
27366394Scc210113 
27376512Ssowmini 	if (pr_valsize == 0)
27386512Ssowmini 		return (EINVAL);
27396512Ssowmini 
27406394Scc210113 	bzero(pr_val, pr_valsize);
27416789Sam223141 	if ((pr_flags & MAC_PROP_DEFAULT) && (pr_num != MAC_PROP_PRIVATE)) {
27426512Ssowmini 		return (e1000g_get_def_val(Adapter, pr_num,
27436512Ssowmini 		    pr_valsize, pr_val));
27446512Ssowmini 	}
27456512Ssowmini 
27466394Scc210113 	switch (pr_num) {
27476789Sam223141 		case MAC_PROP_DUPLEX:
27486512Ssowmini 			if (pr_valsize >= sizeof (link_duplex_t)) {
27496512Ssowmini 				bcopy(&Adapter->link_duplex, pr_val,
27506512Ssowmini 				    sizeof (link_duplex_t));
27516512Ssowmini 			} else
27526512Ssowmini 				err = EINVAL;
27536394Scc210113 			break;
27546789Sam223141 		case MAC_PROP_SPEED:
27556394Scc210113 			if (pr_valsize >= sizeof (uint64_t)) {
27566394Scc210113 				tmp = Adapter->link_speed * 1000000ull;
27576394Scc210113 				bcopy(&tmp, pr_val, sizeof (tmp));
27586512Ssowmini 			} else
27596512Ssowmini 				err = EINVAL;
27606394Scc210113 			break;
27616789Sam223141 		case MAC_PROP_AUTONEG:
27626512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_autoneg;
27636394Scc210113 			break;
27646789Sam223141 		case MAC_PROP_FLOWCTRL:
27656394Scc210113 			if (pr_valsize >= sizeof (link_flowctrl_t)) {
27666735Scc210113 				switch (fc->type) {
27676394Scc210113 					case e1000_fc_none:
27686735Scc210113 						flowctrl = LINK_FLOWCTRL_NONE;
27696394Scc210113 						break;
27706394Scc210113 					case e1000_fc_rx_pause:
27716735Scc210113 						flowctrl = LINK_FLOWCTRL_RX;
27726394Scc210113 						break;
27736394Scc210113 					case e1000_fc_tx_pause:
27746735Scc210113 						flowctrl = LINK_FLOWCTRL_TX;
27756394Scc210113 						break;
27766394Scc210113 					case e1000_fc_full:
27776735Scc210113 						flowctrl = LINK_FLOWCTRL_BI;
27786394Scc210113 						break;
27796394Scc210113 				}
27806735Scc210113 				bcopy(&flowctrl, pr_val, sizeof (flowctrl));
27816512Ssowmini 			} else
27826512Ssowmini 				err = EINVAL;
27836394Scc210113 			break;
27846789Sam223141 		case MAC_PROP_ADV_1000FDX_CAP:
27856512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_1000fdx;
27866394Scc210113 			break;
27876789Sam223141 		case MAC_PROP_EN_1000FDX_CAP:
27886512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_1000fdx;
27896394Scc210113 			break;
27906789Sam223141 		case MAC_PROP_ADV_1000HDX_CAP:
27916512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_1000hdx;
27926394Scc210113 			break;
27936789Sam223141 		case MAC_PROP_EN_1000HDX_CAP:
27946512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_1000hdx;
27956394Scc210113 			break;
27966789Sam223141 		case MAC_PROP_ADV_100FDX_CAP:
27976512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_100fdx;
27986394Scc210113 			break;
27996789Sam223141 		case MAC_PROP_EN_100FDX_CAP:
28006512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_100fdx;
28016394Scc210113 			break;
28026789Sam223141 		case MAC_PROP_ADV_100HDX_CAP:
28036512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_100hdx;
28046394Scc210113 			break;
28056789Sam223141 		case MAC_PROP_EN_100HDX_CAP:
28066512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_100hdx;
28076394Scc210113 			break;
28086789Sam223141 		case MAC_PROP_ADV_10FDX_CAP:
28096512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_10fdx;
28106394Scc210113 			break;
28116789Sam223141 		case MAC_PROP_EN_10FDX_CAP:
28126512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_10fdx;
28136394Scc210113 			break;
28146789Sam223141 		case MAC_PROP_ADV_10HDX_CAP:
28156512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_10hdx;
28166394Scc210113 			break;
28176789Sam223141 		case MAC_PROP_EN_10HDX_CAP:
28186512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_en_10hdx;
28196512Ssowmini 			break;
28206789Sam223141 		case MAC_PROP_ADV_100T4_CAP:
28216789Sam223141 		case MAC_PROP_EN_100T4_CAP:
28226512Ssowmini 			*(uint8_t *)pr_val = Adapter->param_adv_100t4;
28236394Scc210113 			break;
28246789Sam223141 		case MAC_PROP_PRIVATE:
28256394Scc210113 			err = e1000g_get_priv_prop(Adapter, pr_name,
28266512Ssowmini 			    pr_flags, pr_valsize, pr_val);
28276394Scc210113 			break;
28286394Scc210113 		default:
28296394Scc210113 			err = ENOTSUP;
28306394Scc210113 			break;
28316394Scc210113 	}
28326394Scc210113 	return (err);
28336394Scc210113 }
28346394Scc210113 
28356394Scc210113 /* ARGUSED */
28366394Scc210113 static int
28376394Scc210113 e1000g_set_priv_prop(struct e1000g *Adapter, const char *pr_name,
28386394Scc210113     uint_t pr_valsize, const void *pr_val)
28396394Scc210113 {
28406394Scc210113 	int err = 0;
28416394Scc210113 	long result;
28426394Scc210113 	struct e1000_hw *hw = &Adapter->shared;
28436394Scc210113 
28446394Scc210113 	if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) {
28456394Scc210113 		if (pr_val == NULL) {
28466394Scc210113 			err = EINVAL;
28476394Scc210113 			return (err);
28486394Scc210113 		}
28496394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
28506394Scc210113 		if (result < MIN_TX_BCOPY_THRESHOLD ||
28516394Scc210113 		    result > MAX_TX_BCOPY_THRESHOLD)
28526394Scc210113 			err = EINVAL;
28536394Scc210113 		else {
28546394Scc210113 			Adapter->tx_bcopy_thresh = (uint32_t)result;
28556394Scc210113 		}
28566394Scc210113 		return (err);
28576394Scc210113 	}
28586394Scc210113 	if (strcmp(pr_name, "_tx_interrupt_enable") == 0) {
28596394Scc210113 		if (pr_val == NULL) {
28606394Scc210113 			err = EINVAL;
28616394Scc210113 			return (err);
28626394Scc210113 		}
28636394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
28646394Scc210113 		if (result < 0 || result > 1)
28656394Scc210113 			err = EINVAL;
28666394Scc210113 		else {
28676394Scc210113 			Adapter->tx_intr_enable = (result == 1) ?
28686394Scc210113 			    B_TRUE: B_FALSE;
28696394Scc210113 			if (Adapter->tx_intr_enable)
28706394Scc210113 				e1000g_mask_tx_interrupt(Adapter);
28716394Scc210113 			else
28726394Scc210113 				e1000g_clear_tx_interrupt(Adapter);
28736394Scc210113 			if (e1000g_check_acc_handle(
28746394Scc210113 			    Adapter->osdep.reg_handle) != DDI_FM_OK)
28756394Scc210113 				ddi_fm_service_impact(Adapter->dip,
28766394Scc210113 				    DDI_SERVICE_DEGRADED);
28776394Scc210113 		}
28786394Scc210113 		return (err);
28796394Scc210113 	}
28806394Scc210113 	if (strcmp(pr_name, "_tx_intr_delay") == 0) {
28816394Scc210113 		if (pr_val == NULL) {
28826394Scc210113 			err = EINVAL;
28836394Scc210113 			return (err);
28846394Scc210113 		}
28856394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
28866394Scc210113 		if (result < MIN_TX_INTR_DELAY ||
28876394Scc210113 		    result > MAX_TX_INTR_DELAY)
28886394Scc210113 			err = EINVAL;
28896394Scc210113 		else {
28906394Scc210113 			Adapter->tx_intr_delay = (uint32_t)result;
28916394Scc210113 			E1000_WRITE_REG(hw, E1000_TIDV, Adapter->tx_intr_delay);
28926394Scc210113 			if (e1000g_check_acc_handle(
28936394Scc210113 			    Adapter->osdep.reg_handle) != DDI_FM_OK)
28946394Scc210113 				ddi_fm_service_impact(Adapter->dip,
28956394Scc210113 				    DDI_SERVICE_DEGRADED);
28966394Scc210113 		}
28976394Scc210113 		return (err);
28986394Scc210113 	}
28996394Scc210113 	if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) {
29006394Scc210113 		if (pr_val == NULL) {
29016394Scc210113 			err = EINVAL;
29026394Scc210113 			return (err);
29036394Scc210113 		}
29046394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29056394Scc210113 		if (result < MIN_TX_INTR_ABS_DELAY ||
29066394Scc210113 		    result > MAX_TX_INTR_ABS_DELAY)
29076394Scc210113 			err = EINVAL;
29086394Scc210113 		else {
29096394Scc210113 			Adapter->tx_intr_abs_delay = (uint32_t)result;
29106394Scc210113 			E1000_WRITE_REG(hw, E1000_TADV,
29116394Scc210113 			    Adapter->tx_intr_abs_delay);
29126394Scc210113 			if (e1000g_check_acc_handle(
29136394Scc210113 			    Adapter->osdep.reg_handle) != DDI_FM_OK)
29146394Scc210113 				ddi_fm_service_impact(Adapter->dip,
29156394Scc210113 				    DDI_SERVICE_DEGRADED);
29166394Scc210113 		}
29176394Scc210113 		return (err);
29186394Scc210113 	}
29196394Scc210113 	if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) {
29206394Scc210113 		if (pr_val == NULL) {
29216394Scc210113 			err = EINVAL;
29226394Scc210113 			return (err);
29236394Scc210113 		}
29246394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29256394Scc210113 		if (result < MIN_RX_BCOPY_THRESHOLD ||
29266394Scc210113 		    result > MAX_RX_BCOPY_THRESHOLD)
29276394Scc210113 			err = EINVAL;
29286394Scc210113 		else
29296394Scc210113 			Adapter->rx_bcopy_thresh = (uint32_t)result;
29306394Scc210113 		return (err);
29316394Scc210113 	}
29326394Scc210113 	if (strcmp(pr_name, "_max_num_rcv_packets") == 0) {
29336394Scc210113 		if (pr_val == NULL) {
29346394Scc210113 			err = EINVAL;
29356394Scc210113 			return (err);
29366394Scc210113 		}
29376394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29386394Scc210113 		if (result < MIN_RX_LIMIT_ON_INTR ||
29396394Scc210113 		    result > MAX_RX_LIMIT_ON_INTR)
29406394Scc210113 			err = EINVAL;
29416394Scc210113 		else
29426394Scc210113 			Adapter->rx_limit_onintr = (uint32_t)result;
29436394Scc210113 		return (err);
29446394Scc210113 	}
29456394Scc210113 	if (strcmp(pr_name, "_rx_intr_delay") == 0) {
29466394Scc210113 		if (pr_val == NULL) {
29476394Scc210113 			err = EINVAL;
29486394Scc210113 			return (err);
29496394Scc210113 		}
29506394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29516394Scc210113 		if (result < MIN_RX_INTR_DELAY ||
29526394Scc210113 		    result > MAX_RX_INTR_DELAY)
29536394Scc210113 			err = EINVAL;
29546394Scc210113 		else {
29556394Scc210113 			Adapter->rx_intr_delay = (uint32_t)result;
29566394Scc210113 			E1000_WRITE_REG(hw, E1000_RDTR, Adapter->rx_intr_delay);
29576394Scc210113 			if (e1000g_check_acc_handle(
29586394Scc210113 			    Adapter->osdep.reg_handle) != DDI_FM_OK)
29596394Scc210113 				ddi_fm_service_impact(Adapter->dip,
29606394Scc210113 				    DDI_SERVICE_DEGRADED);
29616394Scc210113 		}
29626394Scc210113 		return (err);
29636394Scc210113 	}
29646394Scc210113 	if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) {
29656394Scc210113 		if (pr_val == NULL) {
29666394Scc210113 			err = EINVAL;
29676394Scc210113 			return (err);
29686394Scc210113 		}
29696394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29706394Scc210113 		if (result < MIN_RX_INTR_ABS_DELAY ||
29716394Scc210113 		    result > MAX_RX_INTR_ABS_DELAY)
29726394Scc210113 			err = EINVAL;
29736394Scc210113 		else {
29746394Scc210113 			Adapter->rx_intr_abs_delay = (uint32_t)result;
29756394Scc210113 			E1000_WRITE_REG(hw, E1000_RADV,
29766394Scc210113 			    Adapter->rx_intr_abs_delay);
29776394Scc210113 			if (e1000g_check_acc_handle(
29786394Scc210113 			    Adapter->osdep.reg_handle) != DDI_FM_OK)
29796394Scc210113 				ddi_fm_service_impact(Adapter->dip,
29806394Scc210113 				    DDI_SERVICE_DEGRADED);
29816394Scc210113 		}
29826394Scc210113 		return (err);
29836394Scc210113 	}
29846394Scc210113 	if (strcmp(pr_name, "_intr_throttling_rate") == 0) {
29856394Scc210113 		if (pr_val == NULL) {
29866394Scc210113 			err = EINVAL;
29876394Scc210113 			return (err);
29886394Scc210113 		}
29896394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
29906394Scc210113 		if (result < MIN_INTR_THROTTLING ||
29916394Scc210113 		    result > MAX_INTR_THROTTLING)
29926394Scc210113 			err = EINVAL;
29936394Scc210113 		else {
29946394Scc210113 			if (hw->mac.type >= e1000_82540) {
29956394Scc210113 				Adapter->intr_throttling_rate =
29966394Scc210113 				    (uint32_t)result;
29976394Scc210113 				E1000_WRITE_REG(hw, E1000_ITR,
29986394Scc210113 				    Adapter->intr_throttling_rate);
29996394Scc210113 				if (e1000g_check_acc_handle(
30006394Scc210113 				    Adapter->osdep.reg_handle) != DDI_FM_OK)
30016394Scc210113 					ddi_fm_service_impact(Adapter->dip,
30026394Scc210113 					    DDI_SERVICE_DEGRADED);
30036394Scc210113 			} else
30046394Scc210113 				err = EINVAL;
30056394Scc210113 		}
30066394Scc210113 		return (err);
30076394Scc210113 	}
30086394Scc210113 	if (strcmp(pr_name, "_intr_adaptive") == 0) {
30096394Scc210113 		if (pr_val == NULL) {
30106394Scc210113 			err = EINVAL;
30116394Scc210113 			return (err);
30126394Scc210113 		}
30136394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
30146394Scc210113 		if (result < 0 || result > 1)
30156394Scc210113 			err = EINVAL;
30166394Scc210113 		else {
30176394Scc210113 			if (hw->mac.type >= e1000_82540) {
30186394Scc210113 				Adapter->intr_adaptive = (result == 1) ?
30196394Scc210113 				    B_TRUE : B_FALSE;
30206394Scc210113 			} else {
30216394Scc210113 				err = EINVAL;
30226394Scc210113 			}
30236394Scc210113 		}
30246394Scc210113 		return (err);
30256394Scc210113 	}
30266394Scc210113 	if (strcmp(pr_name, "_tx_recycle_thresh") == 0) {
30276394Scc210113 		if (pr_val == NULL) {
30286394Scc210113 			err = EINVAL;
30296394Scc210113 			return (err);
30306394Scc210113 		}
30316394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
30326394Scc210113 		if (result < MIN_TX_RECYCLE_THRESHOLD ||
30336394Scc210113 		    result > MAX_TX_RECYCLE_THRESHOLD)
30346394Scc210113 			err = EINVAL;
30356394Scc210113 		else
30366394Scc210113 			Adapter->tx_recycle_thresh = (uint32_t)result;
30376394Scc210113 		return (err);
30386394Scc210113 	}
30396394Scc210113 	if (strcmp(pr_name, "_tx_recycle_num") == 0) {
30406394Scc210113 		if (pr_val == NULL) {
30416394Scc210113 			err = EINVAL;
30426394Scc210113 			return (err);
30436394Scc210113 		}
30446394Scc210113 		(void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
30456394Scc210113 		if (result < MIN_TX_RECYCLE_NUM ||
30466394Scc210113 		    result > MAX_TX_RECYCLE_NUM)
30476394Scc210113 			err = EINVAL;
30486394Scc210113 		else
30496394Scc210113 			Adapter->tx_recycle_num = (uint32_t)result;
30506394Scc210113 		return (err);
30516394Scc210113 	}
30526394Scc210113 	return (ENOTSUP);
30536394Scc210113 }
30546394Scc210113 
30556394Scc210113 static int
30566394Scc210113 e1000g_get_priv_prop(struct e1000g *Adapter, const char *pr_name,
30576512Ssowmini     uint_t pr_flags, uint_t pr_valsize, void *pr_val)
30586394Scc210113 {
30596394Scc210113 	char valstr[MAXNAMELEN];
30606394Scc210113 	int err = ENOTSUP;
30616394Scc210113 	uint_t strsize;
30626789Sam223141 	boolean_t is_default = (pr_flags & MAC_PROP_DEFAULT);
30636512Ssowmini 	int value;
30646512Ssowmini 
30656512Ssowmini 	if (strcmp(pr_name, "_adv_pause_cap") == 0) {
30666512Ssowmini 		if (is_default)
30676512Ssowmini 			goto done;
30686512Ssowmini 		value = Adapter->param_adv_pause;
30696512Ssowmini 		err = 0;
30706512Ssowmini 		goto done;
30716512Ssowmini 	}
30726512Ssowmini 	if (strcmp(pr_name, "_adv_asym_pause_cap") == 0) {
30736512Ssowmini 		if (is_default)
30746512Ssowmini 			goto done;
30756512Ssowmini 		value = Adapter->param_adv_asym_pause;
30766512Ssowmini 		err = 0;
30776512Ssowmini 		goto done;
30786512Ssowmini 	}
30796394Scc210113 	if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) {
30806512Ssowmini 		value = (is_default ? DEFAULT_TX_BCOPY_THRESHOLD :
30816512Ssowmini 		    Adapter->tx_bcopy_thresh);
30826394Scc210113 		err = 0;
30836394Scc210113 		goto done;
30846394Scc210113 	}
30856394Scc210113 	if (strcmp(pr_name, "_tx_interrupt_enable") == 0) {
30866512Ssowmini 		value = (is_default ? DEFAULT_TX_INTR_ENABLE :
30876512Ssowmini 		    Adapter->tx_intr_enable);
30886394Scc210113 		err = 0;
30896394Scc210113 		goto done;
30906394Scc210113 	}
30916394Scc210113 	if (strcmp(pr_name, "_tx_intr_delay") == 0) {
30926512Ssowmini 		value = (is_default ? DEFAULT_TX_INTR_DELAY :
30936512Ssowmini 		    Adapter->tx_intr_delay);
30946394Scc210113 		err = 0;
30956394Scc210113 		goto done;
30966394Scc210113 	}
30976394Scc210113 	if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) {
30986512Ssowmini 		value = (is_default ? DEFAULT_TX_INTR_ABS_DELAY :
30996512Ssowmini 		    Adapter->tx_intr_abs_delay);
31006394Scc210113 		err = 0;
31016394Scc210113 		goto done;
31026394Scc210113 	}
31036394Scc210113 	if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) {
31046512Ssowmini 		value = (is_default ? DEFAULT_RX_BCOPY_THRESHOLD :
31056512Ssowmini 		    Adapter->rx_bcopy_thresh);
31066394Scc210113 		err = 0;
31076394Scc210113 		goto done;
31086394Scc210113 	}
31096394Scc210113 	if (strcmp(pr_name, "_max_num_rcv_packets") == 0) {
31106512Ssowmini 		value = (is_default ? DEFAULT_RX_LIMIT_ON_INTR :
31116512Ssowmini 		    Adapter->rx_limit_onintr);
31126394Scc210113 		err = 0;
31136394Scc210113 		goto done;
31146394Scc210113 	}
31156394Scc210113 	if (strcmp(pr_name, "_rx_intr_delay") == 0) {
31166512Ssowmini 		value = (is_default ? DEFAULT_RX_INTR_DELAY :
31176512Ssowmini 		    Adapter->rx_intr_delay);
31186394Scc210113 		err = 0;
31196394Scc210113 		goto done;
31206394Scc210113 	}
31216394Scc210113 	if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) {
31226512Ssowmini 		value = (is_default ? DEFAULT_RX_INTR_ABS_DELAY :
31236512Ssowmini 		    Adapter->rx_intr_abs_delay);
31246394Scc210113 		err = 0;
31256394Scc210113 		goto done;
31266394Scc210113 	}
31276394Scc210113 	if (strcmp(pr_name, "_intr_throttling_rate") == 0) {
31286512Ssowmini 		value = (is_default ? DEFAULT_INTR_THROTTLING :
31296512Ssowmini 		    Adapter->intr_throttling_rate);
31306394Scc210113 		err = 0;
31316394Scc210113 		goto done;
31326394Scc210113 	}
31336394Scc210113 	if (strcmp(pr_name, "_intr_adaptive") == 0) {
31346512Ssowmini 		value = (is_default ? 1 : Adapter->intr_adaptive);
31356394Scc210113 		err = 0;
31366394Scc210113 		goto done;
31376394Scc210113 	}
31386394Scc210113 	if (strcmp(pr_name, "_tx_recycle_thresh") == 0) {
31396512Ssowmini 		value = (is_default ? DEFAULT_TX_RECYCLE_THRESHOLD :
31406512Ssowmini 		    Adapter->tx_recycle_thresh);
31416394Scc210113 		err = 0;
31426394Scc210113 		goto done;
31436394Scc210113 	}
31446394Scc210113 	if (strcmp(pr_name, "_tx_recycle_num") == 0) {
31456512Ssowmini 		value = (is_default ? DEFAULT_TX_RECYCLE_NUM :
31466512Ssowmini 		    Adapter->tx_recycle_num);
31476394Scc210113 		err = 0;
31486394Scc210113 		goto done;
31496394Scc210113 	}
31506394Scc210113 done:
31516394Scc210113 	if (err == 0) {
31526512Ssowmini 		(void) snprintf(pr_val, pr_valsize, "%d", value);
31536394Scc210113 	}
31546394Scc210113 	return (err);
31556394Scc210113 }
31566394Scc210113 
31573526Sxy150489 /*
31584919Sxy150489  * e1000g_get_conf - get configurations set in e1000g.conf
31594919Sxy150489  * This routine gets user-configured values out of the configuration
31604919Sxy150489  * file e1000g.conf.
31614919Sxy150489  *
31624919Sxy150489  * For each configurable value, there is a minimum, a maximum, and a
31634919Sxy150489  * default.
31644919Sxy150489  * If user does not configure a value, use the default.
31654919Sxy150489  * If user configures below the minimum, use the minumum.
31664919Sxy150489  * If user configures above the maximum, use the maxumum.
31673526Sxy150489  */
31683526Sxy150489 static void
31694919Sxy150489 e1000g_get_conf(struct e1000g *Adapter)
31703526Sxy150489 {
31714919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
31724919Sxy150489 	boolean_t tbi_compatibility = B_FALSE;
31734919Sxy150489 
31743526Sxy150489 	/*
31753526Sxy150489 	 * get each configurable property from e1000g.conf
31763526Sxy150489 	 */
31773526Sxy150489 
31783526Sxy150489 	/*
31793526Sxy150489 	 * NumTxDescriptors
31803526Sxy150489 	 */
31814919Sxy150489 	Adapter->tx_desc_num =
31824919Sxy150489 	    e1000g_get_prop(Adapter, "NumTxDescriptors",
31834919Sxy150489 	    MIN_NUM_TX_DESCRIPTOR, MAX_NUM_TX_DESCRIPTOR,
31844919Sxy150489 	    DEFAULT_NUM_TX_DESCRIPTOR);
31853526Sxy150489 
31863526Sxy150489 	/*
31873526Sxy150489 	 * NumRxDescriptors
31883526Sxy150489 	 */
31894919Sxy150489 	Adapter->rx_desc_num =
31904919Sxy150489 	    e1000g_get_prop(Adapter, "NumRxDescriptors",
31914919Sxy150489 	    MIN_NUM_RX_DESCRIPTOR, MAX_NUM_RX_DESCRIPTOR,
31924919Sxy150489 	    DEFAULT_NUM_RX_DESCRIPTOR);
31933526Sxy150489 
31943526Sxy150489 	/*
31953526Sxy150489 	 * NumRxFreeList
31963526Sxy150489 	 */
31974919Sxy150489 	Adapter->rx_freelist_num =
31984919Sxy150489 	    e1000g_get_prop(Adapter, "NumRxFreeList",
31994919Sxy150489 	    MIN_NUM_RX_FREELIST, MAX_NUM_RX_FREELIST,
32004919Sxy150489 	    DEFAULT_NUM_RX_FREELIST);
32013526Sxy150489 
32023526Sxy150489 	/*
32033526Sxy150489 	 * NumTxPacketList
32043526Sxy150489 	 */
32054919Sxy150489 	Adapter->tx_freelist_num =
32064919Sxy150489 	    e1000g_get_prop(Adapter, "NumTxPacketList",
32074919Sxy150489 	    MIN_NUM_TX_FREELIST, MAX_NUM_TX_FREELIST,
32084919Sxy150489 	    DEFAULT_NUM_TX_FREELIST);
32093526Sxy150489 
32103526Sxy150489 	/*
32113526Sxy150489 	 * FlowControl
32123526Sxy150489 	 */
32136735Scc210113 	hw->fc.send_xon = B_TRUE;
32146735Scc210113 	hw->fc.type =
32154919Sxy150489 	    e1000g_get_prop(Adapter, "FlowControl",
32164919Sxy150489 	    e1000_fc_none, 4, DEFAULT_FLOW_CONTROL);
32173526Sxy150489 	/* 4 is the setting that says "let the eeprom decide" */
32186735Scc210113 	if (hw->fc.type == 4)
32196735Scc210113 		hw->fc.type = e1000_fc_default;
32203526Sxy150489 
32213526Sxy150489 	/*
32224919Sxy150489 	 * Max Num Receive Packets on Interrupt
32233526Sxy150489 	 */
32244919Sxy150489 	Adapter->rx_limit_onintr =
32254919Sxy150489 	    e1000g_get_prop(Adapter, "MaxNumReceivePackets",
32264919Sxy150489 	    MIN_RX_LIMIT_ON_INTR, MAX_RX_LIMIT_ON_INTR,
32274919Sxy150489 	    DEFAULT_RX_LIMIT_ON_INTR);
32283526Sxy150489 
32293526Sxy150489 	/*
32303526Sxy150489 	 * PHY master slave setting
32313526Sxy150489 	 */
32324919Sxy150489 	hw->phy.ms_type =
32334919Sxy150489 	    e1000g_get_prop(Adapter, "SetMasterSlave",
32343526Sxy150489 	    e1000_ms_hw_default, e1000_ms_auto,
32353526Sxy150489 	    e1000_ms_hw_default);
32363526Sxy150489 
32373526Sxy150489 	/*
32383526Sxy150489 	 * Parameter which controls TBI mode workaround, which is only
32393526Sxy150489 	 * needed on certain switches such as Cisco 6500/Foundry
32403526Sxy150489 	 */
32414919Sxy150489 	tbi_compatibility =
32424919Sxy150489 	    e1000g_get_prop(Adapter, "TbiCompatibilityEnable",
32434919Sxy150489 	    0, 1, DEFAULT_TBI_COMPAT_ENABLE);
32444919Sxy150489 	e1000_set_tbi_compatibility_82543(hw, tbi_compatibility);
32453526Sxy150489 
32463526Sxy150489 	/*
32473526Sxy150489 	 * MSI Enable
32483526Sxy150489 	 */
3249*6986Smx205022 	Adapter->msi_enable =
32504919Sxy150489 	    e1000g_get_prop(Adapter, "MSIEnable",
32514919Sxy150489 	    0, 1, DEFAULT_MSI_ENABLE);
32523526Sxy150489 
32533526Sxy150489 	/*
32543526Sxy150489 	 * Interrupt Throttling Rate
32553526Sxy150489 	 */
32563526Sxy150489 	Adapter->intr_throttling_rate =
32574919Sxy150489 	    e1000g_get_prop(Adapter, "intr_throttling_rate",
32584919Sxy150489 	    MIN_INTR_THROTTLING, MAX_INTR_THROTTLING,
32594919Sxy150489 	    DEFAULT_INTR_THROTTLING);
32603526Sxy150489 
32613526Sxy150489 	/*
32623526Sxy150489 	 * Adaptive Interrupt Blanking Enable/Disable
32633526Sxy150489 	 * It is enabled by default
32643526Sxy150489 	 */
32653526Sxy150489 	Adapter->intr_adaptive =
32664919Sxy150489 	    (e1000g_get_prop(Adapter, "intr_adaptive", 0, 1, 1) == 1) ?
32673526Sxy150489 	    B_TRUE : B_FALSE;
32685882Syy150190 
32695882Syy150190 	/*
32705882Syy150190 	 * Tx recycle threshold
32715882Syy150190 	 */
32725882Syy150190 	Adapter->tx_recycle_thresh =
32735882Syy150190 	    e1000g_get_prop(Adapter, "tx_recycle_thresh",
32745882Syy150190 	    MIN_TX_RECYCLE_THRESHOLD, MAX_TX_RECYCLE_THRESHOLD,
32755882Syy150190 	    DEFAULT_TX_RECYCLE_THRESHOLD);
32765882Syy150190 
32775882Syy150190 	/*
32785882Syy150190 	 * Tx recycle descriptor number
32795882Syy150190 	 */
32805882Syy150190 	Adapter->tx_recycle_num =
32815882Syy150190 	    e1000g_get_prop(Adapter, "tx_recycle_num",
32825882Syy150190 	    MIN_TX_RECYCLE_NUM, MAX_TX_RECYCLE_NUM,
32835882Syy150190 	    DEFAULT_TX_RECYCLE_NUM);
32846011Ssv141092 
32856011Ssv141092 	/*
32866011Ssv141092 	 * Hardware checksum enable/disable parameter
32876011Ssv141092 	 */
3288*6986Smx205022 	Adapter->tx_hcksum_enable =
3289*6986Smx205022 	    e1000g_get_prop(Adapter, "tx_hcksum_enable",
32906011Ssv141092 	    0, 1, DEFAULT_TX_HCKSUM_ENABLE);
3291*6986Smx205022 	/*
3292*6986Smx205022 	 * Checksum on/off selection via global parameters.
3293*6986Smx205022 	 *
3294*6986Smx205022 	 * If the chip is flagged as not capable of (correctly)
3295*6986Smx205022 	 * handling checksumming, we don't enable it on either
3296*6986Smx205022 	 * Rx or Tx side.  Otherwise, we take this chip's settings
3297*6986Smx205022 	 * from the patchable global defaults.
3298*6986Smx205022 	 *
3299*6986Smx205022 	 * We advertise our capabilities only if TX offload is
3300*6986Smx205022 	 * enabled.  On receive, the stack will accept checksummed
3301*6986Smx205022 	 * packets anyway, even if we haven't said we can deliver
3302*6986Smx205022 	 * them.
3303*6986Smx205022 	 */
3304*6986Smx205022 	switch (hw->mac.type) {
3305*6986Smx205022 		case e1000_82540:
3306*6986Smx205022 		case e1000_82544:
3307*6986Smx205022 		case e1000_82545:
3308*6986Smx205022 		case e1000_82545_rev_3:
3309*6986Smx205022 		case e1000_82546:
3310*6986Smx205022 		case e1000_82546_rev_3:
3311*6986Smx205022 		case e1000_82571:
3312*6986Smx205022 		case e1000_82572:
3313*6986Smx205022 		case e1000_82573:
3314*6986Smx205022 		case e1000_80003es2lan:
3315*6986Smx205022 			break;
3316*6986Smx205022 		/*
3317*6986Smx205022 		 * For the following Intel PRO/1000 chipsets, we have not
3318*6986Smx205022 		 * tested the hardware checksum offload capability, so we
3319*6986Smx205022 		 * disable the capability for them.
3320*6986Smx205022 		 *	e1000_82542,
3321*6986Smx205022 		 *	e1000_82543,
3322*6986Smx205022 		 *	e1000_82541,
3323*6986Smx205022 		 *	e1000_82541_rev_2,
3324*6986Smx205022 		 *	e1000_82547,
3325*6986Smx205022 		 *	e1000_82547_rev_2,
3326*6986Smx205022 		 */
3327*6986Smx205022 		default:
3328*6986Smx205022 			Adapter->tx_hcksum_enable = B_FALSE;
3329*6986Smx205022 	}
3330*6986Smx205022 
3331*6986Smx205022 	/*
3332*6986Smx205022 	 * Large Send Offloading(LSO) Enable/Disable
3333*6986Smx205022 	 * If the tx hardware checksum is not enabled, LSO should be
3334*6986Smx205022 	 * disabled.
3335*6986Smx205022 	 */
3336*6986Smx205022 	Adapter->lso_enable =
3337*6986Smx205022 	    e1000g_get_prop(Adapter, "lso_enable",
3338*6986Smx205022 	    0, 1, DEFAULT_LSO_ENABLE);
3339*6986Smx205022 
3340*6986Smx205022 	switch (hw->mac.type) {
3341*6986Smx205022 		case e1000_82546:
3342*6986Smx205022 		case e1000_82546_rev_3:
3343*6986Smx205022 			if (Adapter->lso_enable)
3344*6986Smx205022 				Adapter->lso_premature_issue = B_TRUE;
3345*6986Smx205022 		case e1000_82571:
3346*6986Smx205022 		case e1000_82572:
3347*6986Smx205022 		case e1000_82573:
3348*6986Smx205022 			break;
3349*6986Smx205022 		default:
3350*6986Smx205022 			Adapter->lso_enable = B_FALSE;
3351*6986Smx205022 	}
3352*6986Smx205022 
3353*6986Smx205022 	if (!Adapter->tx_hcksum_enable) {
3354*6986Smx205022 		Adapter->lso_premature_issue = B_FALSE;
3355*6986Smx205022 		Adapter->lso_enable = B_FALSE;
3356*6986Smx205022 	}
33573526Sxy150489 }
33583526Sxy150489 
33593526Sxy150489 /*
33604919Sxy150489  * e1000g_get_prop - routine to read properties
33614919Sxy150489  *
33624919Sxy150489  * Get a user-configure property value out of the configuration
33634919Sxy150489  * file e1000g.conf.
33644919Sxy150489  *
33654919Sxy150489  * Caller provides name of the property, a default value, a minimum
33664919Sxy150489  * value, and a maximum value.
33674919Sxy150489  *
33684919Sxy150489  * Return configured value of the property, with default, minimum and
33694919Sxy150489  * maximum properly applied.
33703526Sxy150489  */
33713526Sxy150489 static int
33724919Sxy150489 e1000g_get_prop(struct e1000g *Adapter,	/* point to per-adapter structure */
33733526Sxy150489     char *propname,		/* name of the property */
33743526Sxy150489     int minval,			/* minimum acceptable value */
33753526Sxy150489     int maxval,			/* maximim acceptable value */
33763526Sxy150489     int defval)			/* default value */
33773526Sxy150489 {
33783526Sxy150489 	int propval;		/* value returned for requested property */
33793526Sxy150489 	int *props;		/* point to array of properties returned */
33803526Sxy150489 	uint_t nprops;		/* number of property value returned */
33813526Sxy150489 
33823526Sxy150489 	/*
33833526Sxy150489 	 * get the array of properties from the config file
33843526Sxy150489 	 */
33853526Sxy150489 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, Adapter->dip,
33863526Sxy150489 	    DDI_PROP_DONTPASS, propname, &props, &nprops) == DDI_PROP_SUCCESS) {
33873526Sxy150489 		/* got some properties, test if we got enough */
33884919Sxy150489 		if (Adapter->instance < nprops) {
33894919Sxy150489 			propval = props[Adapter->instance];
33903526Sxy150489 		} else {
33913526Sxy150489 			/* not enough properties configured */
33923526Sxy150489 			propval = defval;
33934919Sxy150489 			E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
33943526Sxy150489 			    "Not Enough %s values found in e1000g.conf"
33953526Sxy150489 			    " - set to %d\n",
33963526Sxy150489 			    propname, propval);
33973526Sxy150489 		}
33983526Sxy150489 
33993526Sxy150489 		/* free memory allocated for properties */
34003526Sxy150489 		ddi_prop_free(props);
34013526Sxy150489 
34023526Sxy150489 	} else {
34033526Sxy150489 		propval = defval;
34043526Sxy150489 	}
34053526Sxy150489 
34063526Sxy150489 	/*
34073526Sxy150489 	 * enforce limits
34083526Sxy150489 	 */
34093526Sxy150489 	if (propval > maxval) {
34103526Sxy150489 		propval = maxval;
34114919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
34123526Sxy150489 		    "Too High %s value in e1000g.conf - set to %d\n",
34133526Sxy150489 		    propname, propval);
34143526Sxy150489 	}
34153526Sxy150489 
34163526Sxy150489 	if (propval < minval) {
34173526Sxy150489 		propval = minval;
34184919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
34193526Sxy150489 		    "Too Low %s value in e1000g.conf - set to %d\n",
34203526Sxy150489 		    propname, propval);
34213526Sxy150489 	}
34223526Sxy150489 
34233526Sxy150489 	return (propval);
34243526Sxy150489 }
34253526Sxy150489 
34263526Sxy150489 static boolean_t
34274061Sxy150489 e1000g_link_check(struct e1000g *Adapter)
34283526Sxy150489 {
34294061Sxy150489 	uint16_t speed, duplex, phydata;
34304061Sxy150489 	boolean_t link_changed = B_FALSE;
34313526Sxy150489 	struct e1000_hw *hw;
34323526Sxy150489 	uint32_t reg_tarc;
34333526Sxy150489 
34344919Sxy150489 	hw = &Adapter->shared;
34353526Sxy150489 
34363526Sxy150489 	if (e1000g_link_up(Adapter)) {
34373526Sxy150489 		/*
34383526Sxy150489 		 * The Link is up, check whether it was marked as down earlier
34393526Sxy150489 		 */
34404061Sxy150489 		if (Adapter->link_state != LINK_STATE_UP) {
34414061Sxy150489 			e1000_get_speed_and_duplex(hw, &speed, &duplex);
34424061Sxy150489 			Adapter->link_speed = speed;
34434061Sxy150489 			Adapter->link_duplex = duplex;
34444061Sxy150489 			Adapter->link_state = LINK_STATE_UP;
34454061Sxy150489 			link_changed = B_TRUE;
34464061Sxy150489 
34474061Sxy150489 			Adapter->tx_link_down_timeout = 0;
34484061Sxy150489 
34494919Sxy150489 			if ((hw->mac.type == e1000_82571) ||
34504919Sxy150489 			    (hw->mac.type == e1000_82572)) {
34516735Scc210113 				reg_tarc = E1000_READ_REG(hw, E1000_TARC(0));
34524061Sxy150489 				if (speed == SPEED_1000)
34534061Sxy150489 					reg_tarc |= (1 << 21);
34544061Sxy150489 				else
34554061Sxy150489 					reg_tarc &= ~(1 << 21);
34566735Scc210113 				E1000_WRITE_REG(hw, E1000_TARC(0), reg_tarc);
34573526Sxy150489 			}
34583526Sxy150489 		}
34593526Sxy150489 		Adapter->smartspeed = 0;
34603526Sxy150489 	} else {
34614061Sxy150489 		if (Adapter->link_state != LINK_STATE_DOWN) {
34623526Sxy150489 			Adapter->link_speed = 0;
34633526Sxy150489 			Adapter->link_duplex = 0;
34644061Sxy150489 			Adapter->link_state = LINK_STATE_DOWN;
34654061Sxy150489 			link_changed = B_TRUE;
34664061Sxy150489 
34673526Sxy150489 			/*
34683526Sxy150489 			 * SmartSpeed workaround for Tabor/TanaX, When the
34693526Sxy150489 			 * driver loses link disable auto master/slave
34703526Sxy150489 			 * resolution.
34713526Sxy150489 			 */
34724919Sxy150489 			if (hw->phy.type == e1000_phy_igp) {
34733526Sxy150489 				e1000_read_phy_reg(hw,
34743526Sxy150489 				    PHY_1000T_CTRL, &phydata);
34753526Sxy150489 				phydata |= CR_1000T_MS_ENABLE;
34763526Sxy150489 				e1000_write_phy_reg(hw,
34773526Sxy150489 				    PHY_1000T_CTRL, phydata);
34783526Sxy150489 			}
34793526Sxy150489 		} else {
34803526Sxy150489 			e1000g_smartspeed(Adapter);
34813526Sxy150489 		}
34824061Sxy150489 
34835273Sgl147354 		if (Adapter->chip_state == E1000G_START) {
34844061Sxy150489 			if (Adapter->tx_link_down_timeout <
34854061Sxy150489 			    MAX_TX_LINK_DOWN_TIMEOUT) {
34864061Sxy150489 				Adapter->tx_link_down_timeout++;
34874061Sxy150489 			} else if (Adapter->tx_link_down_timeout ==
34884061Sxy150489 			    MAX_TX_LINK_DOWN_TIMEOUT) {
34894919Sxy150489 				e1000g_tx_clean(Adapter);
34904061Sxy150489 				Adapter->tx_link_down_timeout++;
34914061Sxy150489 			}
34924061Sxy150489 		}
34933526Sxy150489 	}
34943526Sxy150489 
34955273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
34965273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
34975273Sgl147354 
34984061Sxy150489 	return (link_changed);
34994061Sxy150489 }
35004061Sxy150489 
35016394Scc210113 /*
35026394Scc210113  * e1000g_reset_link - Using the link properties to setup the link
35036394Scc210113  */
35046394Scc210113 int
35056394Scc210113 e1000g_reset_link(struct e1000g *Adapter)
35066394Scc210113 {
35076394Scc210113 	struct e1000_mac_info *mac;
35086394Scc210113 	struct e1000_phy_info *phy;
35096394Scc210113 	boolean_t invalid;
35106394Scc210113 
35116394Scc210113 	mac = &Adapter->shared.mac;
35126394Scc210113 	phy = &Adapter->shared.phy;
35136394Scc210113 	invalid = B_FALSE;
35146394Scc210113 
35156394Scc210113 	if (Adapter->param_adv_autoneg == 1) {
35166394Scc210113 		mac->autoneg = B_TRUE;
35176394Scc210113 		phy->autoneg_advertised = 0;
35186394Scc210113 
35196394Scc210113 		/*
35206394Scc210113 		 * 1000hdx is not supported for autonegotiation
35216394Scc210113 		 */
35226394Scc210113 		if (Adapter->param_adv_1000fdx == 1)
35236394Scc210113 			phy->autoneg_advertised |= ADVERTISE_1000_FULL;
35246394Scc210113 
35256394Scc210113 		if (Adapter->param_adv_100fdx == 1)
35266394Scc210113 			phy->autoneg_advertised |= ADVERTISE_100_FULL;
35276394Scc210113 
35286394Scc210113 		if (Adapter->param_adv_100hdx == 1)
35296394Scc210113 			phy->autoneg_advertised |= ADVERTISE_100_HALF;
35306394Scc210113 
35316394Scc210113 		if (Adapter->param_adv_10fdx == 1)
35326394Scc210113 			phy->autoneg_advertised |= ADVERTISE_10_FULL;
35336394Scc210113 
35346394Scc210113 		if (Adapter->param_adv_10hdx == 1)
35356394Scc210113 			phy->autoneg_advertised |= ADVERTISE_10_HALF;
35366394Scc210113 
35376394Scc210113 		if (phy->autoneg_advertised == 0)
35386394Scc210113 			invalid = B_TRUE;
35396394Scc210113 	} else {
35406394Scc210113 		mac->autoneg = B_FALSE;
35416394Scc210113 
35426394Scc210113 		/*
35436394Scc210113 		 * 1000fdx and 1000hdx are not supported for forced link
35446394Scc210113 		 */
35456394Scc210113 		if (Adapter->param_adv_100fdx == 1)
35466394Scc210113 			mac->forced_speed_duplex = ADVERTISE_100_FULL;
35476394Scc210113 		else if (Adapter->param_adv_100hdx == 1)
35486394Scc210113 			mac->forced_speed_duplex = ADVERTISE_100_HALF;
35496394Scc210113 		else if (Adapter->param_adv_10fdx == 1)
35506394Scc210113 			mac->forced_speed_duplex = ADVERTISE_10_FULL;
35516394Scc210113 		else if (Adapter->param_adv_10hdx == 1)
35526394Scc210113 			mac->forced_speed_duplex = ADVERTISE_10_HALF;
35536394Scc210113 		else
35546394Scc210113 			invalid = B_TRUE;
35556394Scc210113 
35566394Scc210113 	}
35576394Scc210113 
35586394Scc210113 	if (invalid) {
35596394Scc210113 		e1000g_log(Adapter, CE_WARN,
35606394Scc210113 		    "Invalid link sets. Setup link to"
35616394Scc210113 		    "support autonegotiation with all link capabilities.");
35626394Scc210113 		mac->autoneg = B_TRUE;
35636394Scc210113 		phy->autoneg_advertised = ADVERTISE_1000_FULL |
35646394Scc210113 		    ADVERTISE_100_FULL | ADVERTISE_100_HALF |
35656394Scc210113 		    ADVERTISE_10_FULL | ADVERTISE_10_HALF;
35666394Scc210113 	}
35676394Scc210113 
35686394Scc210113 	return (e1000_setup_link(&Adapter->shared));
35696394Scc210113 }
35706394Scc210113 
35714061Sxy150489 static void
35724919Sxy150489 e1000g_local_timer(void *ws)
35734061Sxy150489 {
35744061Sxy150489 	struct e1000g *Adapter = (struct e1000g *)ws;
35754061Sxy150489 	struct e1000_hw *hw;
35764061Sxy150489 	e1000g_ether_addr_t ether_addr;
35774061Sxy150489 	boolean_t link_changed;
35784061Sxy150489 
35794919Sxy150489 	hw = &Adapter->shared;
35804919Sxy150489 
35815273Sgl147354 	if (Adapter->chip_state == E1000G_ERROR) {
35825273Sgl147354 		Adapter->reset_count++;
35835273Sgl147354 		if (e1000g_global_reset(Adapter))
35845273Sgl147354 			ddi_fm_service_impact(Adapter->dip,
35855273Sgl147354 			    DDI_SERVICE_RESTORED);
35865273Sgl147354 		else
35875273Sgl147354 			ddi_fm_service_impact(Adapter->dip,
35885273Sgl147354 			    DDI_SERVICE_LOST);
35895273Sgl147354 		return;
35905273Sgl147354 	}
35915273Sgl147354 
35924061Sxy150489 	if (e1000g_stall_check(Adapter)) {
35934919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
35944061Sxy150489 		    "Tx stall detected. Activate automatic recovery.\n");
35955273Sgl147354 		e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_STALL);
35964061Sxy150489 		Adapter->reset_count++;
35975273Sgl147354 		if (e1000g_reset(Adapter))
35985273Sgl147354 			ddi_fm_service_impact(Adapter->dip,
35995273Sgl147354 			    DDI_SERVICE_RESTORED);
36005273Sgl147354 		else
36015273Sgl147354 			ddi_fm_service_impact(Adapter->dip,
36025273Sgl147354 			    DDI_SERVICE_LOST);
36035273Sgl147354 		return;
36044061Sxy150489 	}
36054061Sxy150489 
36064061Sxy150489 	link_changed = B_FALSE;
36075082Syy150190 	rw_enter(&Adapter->chip_lock, RW_READER);
36084061Sxy150489 	if (Adapter->link_complete)
36094061Sxy150489 		link_changed = e1000g_link_check(Adapter);
36105082Syy150190 	rw_exit(&Adapter->chip_lock);
36114061Sxy150489 
36124139Sxy150489 	if (link_changed) {
36134139Sxy150489 		/*
36144139Sxy150489 		 * Workaround for esb2. Data stuck in fifo on a link
36154139Sxy150489 		 * down event. Reset the adapter to recover it.
36164139Sxy150489 		 */
36174139Sxy150489 		if ((Adapter->link_state == LINK_STATE_DOWN) &&
36184919Sxy150489 		    (hw->mac.type == e1000_80003es2lan))
36194139Sxy150489 			(void) e1000g_reset(Adapter);
36204139Sxy150489 
36214061Sxy150489 		mac_link_update(Adapter->mh, Adapter->link_state);
36224139Sxy150489 	}
36234061Sxy150489 
36243526Sxy150489 	/*
36253526Sxy150489 	 * With 82571 controllers, any locally administered address will
36263526Sxy150489 	 * be overwritten when there is a reset on the other port.
36273526Sxy150489 	 * Detect this circumstance and correct it.
36283526Sxy150489 	 */
36294919Sxy150489 	if ((hw->mac.type == e1000_82571) &&
36304919Sxy150489 	    (e1000_get_laa_state_82571(hw) == B_TRUE)) {
36314919Sxy150489 		ether_addr.reg.low = E1000_READ_REG_ARRAY(hw, E1000_RA, 0);
36324919Sxy150489 		ether_addr.reg.high = E1000_READ_REG_ARRAY(hw, E1000_RA, 1);
36333526Sxy150489 
36343526Sxy150489 		ether_addr.reg.low = ntohl(ether_addr.reg.low);
36353526Sxy150489 		ether_addr.reg.high = ntohl(ether_addr.reg.high);
36363526Sxy150489 
36374919Sxy150489 		if ((ether_addr.mac.addr[5] != hw->mac.addr[0]) ||
36384919Sxy150489 		    (ether_addr.mac.addr[4] != hw->mac.addr[1]) ||
36394919Sxy150489 		    (ether_addr.mac.addr[3] != hw->mac.addr[2]) ||
36404919Sxy150489 		    (ether_addr.mac.addr[2] != hw->mac.addr[3]) ||
36414919Sxy150489 		    (ether_addr.mac.addr[1] != hw->mac.addr[4]) ||
36424919Sxy150489 		    (ether_addr.mac.addr[0] != hw->mac.addr[5])) {
36434919Sxy150489 			e1000_rar_set(hw, hw->mac.addr, 0);
36443526Sxy150489 		}
36453526Sxy150489 	}
36463526Sxy150489 
36473526Sxy150489 	/*
36484919Sxy150489 	 * Long TTL workaround for 82541/82547
36493526Sxy150489 	 */
36504919Sxy150489 	e1000_igp_ttl_workaround_82547(hw);
36513526Sxy150489 
36523526Sxy150489 	/*
36533526Sxy150489 	 * Check for Adaptive IFS settings If there are lots of collisions
36543526Sxy150489 	 * change the value in steps...
36553526Sxy150489 	 * These properties should only be set for 10/100
36563526Sxy150489 	 */
36576735Scc210113 	if ((hw->phy.media_type == e1000_media_type_copper) &&
36584061Sxy150489 	    ((Adapter->link_speed == SPEED_100) ||
36594061Sxy150489 	    (Adapter->link_speed == SPEED_10))) {
36603526Sxy150489 		e1000_update_adaptive(hw);
36613526Sxy150489 	}
36623526Sxy150489 	/*
36633526Sxy150489 	 * Set Timer Interrupts
36643526Sxy150489 	 */
36654919Sxy150489 	E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0);
36664919Sxy150489 
36675273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
36685273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
36695273Sgl147354 
36704919Sxy150489 	restart_watchdog_timer(Adapter);
36713526Sxy150489 }
36723526Sxy150489 
36734061Sxy150489 /*
36744061Sxy150489  * The function e1000g_link_timer() is called when the timer for link setup
36754061Sxy150489  * is expired, which indicates the completion of the link setup. The link
36764061Sxy150489  * state will not be updated until the link setup is completed. And the
36774061Sxy150489  * link state will not be sent to the upper layer through mac_link_update()
36784061Sxy150489  * in this function. It will be updated in the local timer routine or the
36794061Sxy150489  * interrupt service routine after the interface is started (plumbed).
36804061Sxy150489  */
36813526Sxy150489 static void
36824061Sxy150489 e1000g_link_timer(void *arg)
36833526Sxy150489 {
36844061Sxy150489 	struct e1000g *Adapter = (struct e1000g *)arg;
36853526Sxy150489 
36864919Sxy150489 	mutex_enter(&Adapter->link_lock);
36874061Sxy150489 	Adapter->link_complete = B_TRUE;
36884061Sxy150489 	Adapter->link_tid = 0;
36894919Sxy150489 	mutex_exit(&Adapter->link_lock);
36903526Sxy150489 }
36913526Sxy150489 
36923526Sxy150489 /*
36934919Sxy150489  * e1000g_force_speed_duplex - read forced speed/duplex out of e1000g.conf
36944919Sxy150489  *
36954919Sxy150489  * This function read the forced speed and duplex for 10/100 Mbps speeds
36964919Sxy150489  * and also for 1000 Mbps speeds from the e1000g.conf file
36973526Sxy150489  */
36983526Sxy150489 static void
36993526Sxy150489 e1000g_force_speed_duplex(struct e1000g *Adapter)
37003526Sxy150489 {
37013526Sxy150489 	int forced;
37024919Sxy150489 	struct e1000_mac_info *mac = &Adapter->shared.mac;
37034919Sxy150489 	struct e1000_phy_info *phy = &Adapter->shared.phy;
37043526Sxy150489 
37053526Sxy150489 	/*
37063526Sxy150489 	 * get value out of config file
37073526Sxy150489 	 */
37084919Sxy150489 	forced = e1000g_get_prop(Adapter, "ForceSpeedDuplex",
37093526Sxy150489 	    GDIAG_10_HALF, GDIAG_ANY, GDIAG_ANY);
37103526Sxy150489 
37113526Sxy150489 	switch (forced) {
37123526Sxy150489 	case GDIAG_10_HALF:
37133526Sxy150489 		/*
37143526Sxy150489 		 * Disable Auto Negotiation
37153526Sxy150489 		 */
37164919Sxy150489 		mac->autoneg = B_FALSE;
37174919Sxy150489 		mac->forced_speed_duplex = ADVERTISE_10_HALF;
37183526Sxy150489 		break;
37193526Sxy150489 	case GDIAG_10_FULL:
37203526Sxy150489 		/*
37213526Sxy150489 		 * Disable Auto Negotiation
37223526Sxy150489 		 */
37234919Sxy150489 		mac->autoneg = B_FALSE;
37244919Sxy150489 		mac->forced_speed_duplex = ADVERTISE_10_FULL;
37253526Sxy150489 		break;
37263526Sxy150489 	case GDIAG_100_HALF:
37273526Sxy150489 		/*
37283526Sxy150489 		 * Disable Auto Negotiation
37293526Sxy150489 		 */
37304919Sxy150489 		mac->autoneg = B_FALSE;
37314919Sxy150489 		mac->forced_speed_duplex = ADVERTISE_100_HALF;
37323526Sxy150489 		break;
37333526Sxy150489 	case GDIAG_100_FULL:
37343526Sxy150489 		/*
37353526Sxy150489 		 * Disable Auto Negotiation
37363526Sxy150489 		 */
37374919Sxy150489 		mac->autoneg = B_FALSE;
37384919Sxy150489 		mac->forced_speed_duplex = ADVERTISE_100_FULL;
37393526Sxy150489 		break;
37403526Sxy150489 	case GDIAG_1000_FULL:
37413526Sxy150489 		/*
37423526Sxy150489 		 * The gigabit spec requires autonegotiation.  Therefore,
37433526Sxy150489 		 * when the user wants to force the speed to 1000Mbps, we
37443526Sxy150489 		 * enable AutoNeg, but only allow the harware to advertise
37453526Sxy150489 		 * 1000Mbps.  This is different from 10/100 operation, where
37463526Sxy150489 		 * we are allowed to link without any negotiation.
37473526Sxy150489 		 */
37484919Sxy150489 		mac->autoneg = B_TRUE;
37494919Sxy150489 		phy->autoneg_advertised = ADVERTISE_1000_FULL;
37503526Sxy150489 		break;
37513526Sxy150489 	default:	/* obey the setting of AutoNegAdvertised */
37524919Sxy150489 		mac->autoneg = B_TRUE;
37534919Sxy150489 		phy->autoneg_advertised =
37544919Sxy150489 		    (uint16_t)e1000g_get_prop(Adapter, "AutoNegAdvertised",
37554349Sxy150489 		    0, AUTONEG_ADVERTISE_SPEED_DEFAULT,
37564349Sxy150489 		    AUTONEG_ADVERTISE_SPEED_DEFAULT);
37573526Sxy150489 		break;
37583526Sxy150489 	}	/* switch */
37593526Sxy150489 }
37603526Sxy150489 
37613526Sxy150489 /*
37624919Sxy150489  * e1000g_get_max_frame_size - get jumbo frame setting from e1000g.conf
37634919Sxy150489  *
37644919Sxy150489  * This function reads MaxFrameSize from e1000g.conf
37653526Sxy150489  */
37663526Sxy150489 static void
37673526Sxy150489 e1000g_get_max_frame_size(struct e1000g *Adapter)
37683526Sxy150489 {
37693526Sxy150489 	int max_frame;
37704919Sxy150489 	struct e1000_mac_info *mac = &Adapter->shared.mac;
37714919Sxy150489 	struct e1000_phy_info *phy = &Adapter->shared.phy;
37723526Sxy150489 
37733526Sxy150489 	/*
37743526Sxy150489 	 * get value out of config file
37753526Sxy150489 	 */
37764919Sxy150489 	max_frame = e1000g_get_prop(Adapter, "MaxFrameSize", 0, 3, 0);
37773526Sxy150489 
37783526Sxy150489 	switch (max_frame) {
37793526Sxy150489 	case 0:
37806394Scc210113 		Adapter->default_mtu = ETHERMTU;
37813526Sxy150489 		break;
37826394Scc210113 	/*
37836394Scc210113 	 * To avoid excessive memory allocation for rx buffers,
37846394Scc210113 	 * the bytes of E1000G_IPALIGNPRESERVEROOM are reserved.
37856394Scc210113 	 */
37863526Sxy150489 	case 1:
37876394Scc210113 		Adapter->default_mtu = FRAME_SIZE_UPTO_4K -
37886394Scc210113 		    sizeof (struct ether_vlan_header) - ETHERFCSL -
37896394Scc210113 		    E1000G_IPALIGNPRESERVEROOM;
37903526Sxy150489 		break;
37913526Sxy150489 	case 2:
37926394Scc210113 		Adapter->default_mtu = FRAME_SIZE_UPTO_8K -
37936394Scc210113 		    sizeof (struct ether_vlan_header) - ETHERFCSL -
37946394Scc210113 		    E1000G_IPALIGNPRESERVEROOM;
37953526Sxy150489 		break;
37963526Sxy150489 	case 3:
37976394Scc210113 		if (mac->type >= e1000_82571)
37986394Scc210113 			Adapter->default_mtu = MAXIMUM_MTU;
37993526Sxy150489 		else
38006394Scc210113 			Adapter->default_mtu = FRAME_SIZE_UPTO_16K -
38016394Scc210113 			    sizeof (struct ether_vlan_header) - ETHERFCSL -
38026394Scc210113 			    E1000G_IPALIGNPRESERVEROOM;
38033526Sxy150489 		break;
38043526Sxy150489 	default:
38056394Scc210113 		Adapter->default_mtu = ETHERMTU;
38063526Sxy150489 		break;
38073526Sxy150489 	}	/* switch */
38083526Sxy150489 
38096735Scc210113 	Adapter->max_frame_size = Adapter->default_mtu +
38106394Scc210113 	    sizeof (struct ether_vlan_header) + ETHERFCSL;
38116394Scc210113 
38123526Sxy150489 	/* ich8 does not do jumbo frames */
38134919Sxy150489 	if (mac->type == e1000_ich8lan) {
38146735Scc210113 		Adapter->max_frame_size = ETHERMAX;
38154919Sxy150489 	}
38164919Sxy150489 
38174919Sxy150489 	/* ich9 does not do jumbo frames on one phy type */
38184919Sxy150489 	if ((mac->type == e1000_ich9lan) &&
38194919Sxy150489 	    (phy->type == e1000_phy_ife)) {
38206735Scc210113 		Adapter->max_frame_size = ETHERMAX;
38213526Sxy150489 	}
38223526Sxy150489 }
38233526Sxy150489 
38243526Sxy150489 static void
38254919Sxy150489 arm_watchdog_timer(struct e1000g *Adapter)
38263526Sxy150489 {
38274919Sxy150489 	Adapter->watchdog_tid =
38284919Sxy150489 	    timeout(e1000g_local_timer,
38293526Sxy150489 	    (void *)Adapter, 1 * drv_usectohz(1000000));
38303526Sxy150489 }
38314919Sxy150489 #pragma inline(arm_watchdog_timer)
38324919Sxy150489 
38334919Sxy150489 static void
38344919Sxy150489 enable_watchdog_timer(struct e1000g *Adapter)
38354919Sxy150489 {
38364919Sxy150489 	mutex_enter(&Adapter->watchdog_lock);
38374919Sxy150489 
38384919Sxy150489 	if (!Adapter->watchdog_timer_enabled) {
38394919Sxy150489 		Adapter->watchdog_timer_enabled = B_TRUE;
38404919Sxy150489 		Adapter->watchdog_timer_started = B_TRUE;
38414919Sxy150489 		arm_watchdog_timer(Adapter);
38424919Sxy150489 	}
38434919Sxy150489 
38444919Sxy150489 	mutex_exit(&Adapter->watchdog_lock);
38454919Sxy150489 }
38463526Sxy150489 
38473526Sxy150489 static void
38484919Sxy150489 disable_watchdog_timer(struct e1000g *Adapter)
38493526Sxy150489 {
38503526Sxy150489 	timeout_id_t tid;
38513526Sxy150489 
38524919Sxy150489 	mutex_enter(&Adapter->watchdog_lock);
38534919Sxy150489 
38544919Sxy150489 	Adapter->watchdog_timer_enabled = B_FALSE;
38554919Sxy150489 	Adapter->watchdog_timer_started = B_FALSE;
38564919Sxy150489 	tid = Adapter->watchdog_tid;
38574919Sxy150489 	Adapter->watchdog_tid = 0;
38584919Sxy150489 
38594919Sxy150489 	mutex_exit(&Adapter->watchdog_lock);
38603526Sxy150489 
38613526Sxy150489 	if (tid != 0)
38623526Sxy150489 		(void) untimeout(tid);
38633526Sxy150489 }
38643526Sxy150489 
38653526Sxy150489 static void
38664919Sxy150489 start_watchdog_timer(struct e1000g *Adapter)
38673526Sxy150489 {
38684919Sxy150489 	mutex_enter(&Adapter->watchdog_lock);
38694919Sxy150489 
38704919Sxy150489 	if (Adapter->watchdog_timer_enabled) {
38714919Sxy150489 		if (!Adapter->watchdog_timer_started) {
38724919Sxy150489 			Adapter->watchdog_timer_started = B_TRUE;
38734919Sxy150489 			arm_watchdog_timer(Adapter);
38743526Sxy150489 		}
38753526Sxy150489 	}
38763526Sxy150489 
38774919Sxy150489 	mutex_exit(&Adapter->watchdog_lock);
38784919Sxy150489 }
38794919Sxy150489 
38804919Sxy150489 static void
38814919Sxy150489 restart_watchdog_timer(struct e1000g *Adapter)
38824919Sxy150489 {
38834919Sxy150489 	mutex_enter(&Adapter->watchdog_lock);
38844919Sxy150489 
38854919Sxy150489 	if (Adapter->watchdog_timer_started)
38864919Sxy150489 		arm_watchdog_timer(Adapter);
38874919Sxy150489 
38884919Sxy150489 	mutex_exit(&Adapter->watchdog_lock);
38893526Sxy150489 }
38903526Sxy150489 
38913526Sxy150489 static void
38924919Sxy150489 stop_watchdog_timer(struct e1000g *Adapter)
38933526Sxy150489 {
38944919Sxy150489 	timeout_id_t tid;
38954919Sxy150489 
38964919Sxy150489 	mutex_enter(&Adapter->watchdog_lock);
38974919Sxy150489 
38984919Sxy150489 	Adapter->watchdog_timer_started = B_FALSE;
38994919Sxy150489 	tid = Adapter->watchdog_tid;
39004919Sxy150489 	Adapter->watchdog_tid = 0;
39014919Sxy150489 
39024919Sxy150489 	mutex_exit(&Adapter->watchdog_lock);
39034919Sxy150489 
39044919Sxy150489 	if (tid != 0)
39054919Sxy150489 		(void) untimeout(tid);
39063526Sxy150489 }
39073526Sxy150489 
39083526Sxy150489 static void
39094919Sxy150489 stop_link_timer(struct e1000g *Adapter)
39103526Sxy150489 {
39113526Sxy150489 	timeout_id_t tid;
39123526Sxy150489 
39134919Sxy150489 	/* Disable the link timer */
39144919Sxy150489 	mutex_enter(&Adapter->link_lock);
39154919Sxy150489 
39164919Sxy150489 	tid = Adapter->link_tid;
39174919Sxy150489 	Adapter->link_tid = 0;
39184919Sxy150489 
39194919Sxy150489 	mutex_exit(&Adapter->link_lock);
39204919Sxy150489 
39214919Sxy150489 	if (tid != 0)
39224919Sxy150489 		(void) untimeout(tid);
39234919Sxy150489 }
39244919Sxy150489 
39254919Sxy150489 static void
39264919Sxy150489 stop_82547_timer(e1000g_tx_ring_t *tx_ring)
39274919Sxy150489 {
39284919Sxy150489 	timeout_id_t tid;
39294919Sxy150489 
39304919Sxy150489 	/* Disable the tx timer for 82547 chipset */
39314919Sxy150489 	mutex_enter(&tx_ring->tx_lock);
39324919Sxy150489 
39334919Sxy150489 	tx_ring->timer_enable_82547 = B_FALSE;
39344919Sxy150489 	tid = tx_ring->timer_id_82547;
39354919Sxy150489 	tx_ring->timer_id_82547 = 0;
39364919Sxy150489 
39374919Sxy150489 	mutex_exit(&tx_ring->tx_lock);
39383526Sxy150489 
39393526Sxy150489 	if (tid != 0)
39403526Sxy150489 		(void) untimeout(tid);
39413526Sxy150489 }
39423526Sxy150489 
39433526Sxy150489 void
39444919Sxy150489 e1000g_clear_interrupt(struct e1000g *Adapter)
39453526Sxy150489 {
39464919Sxy150489 	E1000_WRITE_REG(&Adapter->shared, E1000_IMC,
39474919Sxy150489 	    0xffffffff & ~E1000_IMS_RXSEQ);
39483526Sxy150489 }
39493526Sxy150489 
39503526Sxy150489 void
39514919Sxy150489 e1000g_mask_interrupt(struct e1000g *Adapter)
39523526Sxy150489 {
39534919Sxy150489 	E1000_WRITE_REG(&Adapter->shared, E1000_IMS,
39545882Syy150190 	    IMS_ENABLE_MASK & ~E1000_IMS_TXDW);
39555882Syy150190 
39565882Syy150190 	if (Adapter->tx_intr_enable)
39575882Syy150190 		e1000g_mask_tx_interrupt(Adapter);
39583526Sxy150489 }
39593526Sxy150489 
39603526Sxy150489 void
39614919Sxy150489 e1000g_clear_all_interrupts(struct e1000g *Adapter)
39623526Sxy150489 {
39634919Sxy150489 	E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 0xffffffff);
39643526Sxy150489 }
39653526Sxy150489 
39663526Sxy150489 void
39674919Sxy150489 e1000g_mask_tx_interrupt(struct e1000g *Adapter)
39683526Sxy150489 {
39695882Syy150190 	E1000_WRITE_REG(&Adapter->shared, E1000_IMS, E1000_IMS_TXDW);
39703526Sxy150489 }
39713526Sxy150489 
39723526Sxy150489 void
39734919Sxy150489 e1000g_clear_tx_interrupt(struct e1000g *Adapter)
39743526Sxy150489 {
39755882Syy150190 	E1000_WRITE_REG(&Adapter->shared, E1000_IMC, E1000_IMS_TXDW);
39763526Sxy150489 }
39773526Sxy150489 
39783526Sxy150489 static void
39794919Sxy150489 e1000g_smartspeed(struct e1000g *Adapter)
39803526Sxy150489 {
39814919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
39823526Sxy150489 	uint16_t phy_status;
39833526Sxy150489 	uint16_t phy_ctrl;
39843526Sxy150489 
39853526Sxy150489 	/*
39863526Sxy150489 	 * If we're not T-or-T, or we're not autoneg'ing, or we're not
39873526Sxy150489 	 * advertising 1000Full, we don't even use the workaround
39883526Sxy150489 	 */
39894919Sxy150489 	if ((hw->phy.type != e1000_phy_igp) ||
39904919Sxy150489 	    !hw->mac.autoneg ||
39914919Sxy150489 	    !(hw->phy.autoneg_advertised & ADVERTISE_1000_FULL))
39923526Sxy150489 		return;
39933526Sxy150489 
39943526Sxy150489 	/*
39953526Sxy150489 	 * True if this is the first call of this function or after every
39963526Sxy150489 	 * 30 seconds of not having link
39973526Sxy150489 	 */
39984919Sxy150489 	if (Adapter->smartspeed == 0) {
39993526Sxy150489 		/*
40003526Sxy150489 		 * If Master/Slave config fault is asserted twice, we
40013526Sxy150489 		 * assume back-to-back
40023526Sxy150489 		 */
40034919Sxy150489 		e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
40043526Sxy150489 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
40053526Sxy150489 			return;
40063526Sxy150489 
40074919Sxy150489 		e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
40083526Sxy150489 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
40093526Sxy150489 			return;
40103526Sxy150489 		/*
40113526Sxy150489 		 * We're assuming back-2-back because our status register
40123526Sxy150489 		 * insists! there's a fault in the master/slave
40133526Sxy150489 		 * relationship that was "negotiated"
40143526Sxy150489 		 */
40154919Sxy150489 		e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
40163526Sxy150489 		/*
40173526Sxy150489 		 * Is the phy configured for manual configuration of
40183526Sxy150489 		 * master/slave?
40193526Sxy150489 		 */
40203526Sxy150489 		if (phy_ctrl & CR_1000T_MS_ENABLE) {
40213526Sxy150489 			/*
40223526Sxy150489 			 * Yes.  Then disable manual configuration (enable
40233526Sxy150489 			 * auto configuration) of master/slave
40243526Sxy150489 			 */
40253526Sxy150489 			phy_ctrl &= ~CR_1000T_MS_ENABLE;
40264919Sxy150489 			e1000_write_phy_reg(hw,
40273526Sxy150489 			    PHY_1000T_CTRL, phy_ctrl);
40283526Sxy150489 			/*
40293526Sxy150489 			 * Effectively starting the clock
40303526Sxy150489 			 */
40314919Sxy150489 			Adapter->smartspeed++;
40323526Sxy150489 			/*
40333526Sxy150489 			 * Restart autonegotiation
40343526Sxy150489 			 */
40354919Sxy150489 			if (!e1000_phy_setup_autoneg(hw) &&
40364919Sxy150489 			    !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) {
40373526Sxy150489 				phy_ctrl |= (MII_CR_AUTO_NEG_EN |
40383526Sxy150489 				    MII_CR_RESTART_AUTO_NEG);
40394919Sxy150489 				e1000_write_phy_reg(hw,
40404919Sxy150489 				    PHY_CONTROL, phy_ctrl);
40413526Sxy150489 			}
40423526Sxy150489 		}
40433526Sxy150489 		return;
40443526Sxy150489 		/*
40453526Sxy150489 		 * Has 6 seconds transpired still without link? Remember,
40463526Sxy150489 		 * you should reset the smartspeed counter once you obtain
40473526Sxy150489 		 * link
40483526Sxy150489 		 */
40494919Sxy150489 	} else if (Adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
40503526Sxy150489 		/*
40513526Sxy150489 		 * Yes.  Remember, we did at the start determine that
40523526Sxy150489 		 * there's a master/slave configuration fault, so we're
40533526Sxy150489 		 * still assuming there's someone on the other end, but we
40543526Sxy150489 		 * just haven't yet been able to talk to it. We then
40553526Sxy150489 		 * re-enable auto configuration of master/slave to see if
40563526Sxy150489 		 * we're running 2/3 pair cables.
40573526Sxy150489 		 */
40583526Sxy150489 		/*
40593526Sxy150489 		 * If still no link, perhaps using 2/3 pair cable
40603526Sxy150489 		 */
40614919Sxy150489 		e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
40623526Sxy150489 		phy_ctrl |= CR_1000T_MS_ENABLE;
40634919Sxy150489 		e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
40643526Sxy150489 		/*
40653526Sxy150489 		 * Restart autoneg with phy enabled for manual
40663526Sxy150489 		 * configuration of master/slave
40673526Sxy150489 		 */
40684919Sxy150489 		if (!e1000_phy_setup_autoneg(hw) &&
40694919Sxy150489 		    !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) {
40703526Sxy150489 			phy_ctrl |=
40713526Sxy150489 			    (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
40724919Sxy150489 			e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl);
40733526Sxy150489 		}
40743526Sxy150489 		/*
40753526Sxy150489 		 * Hopefully, there are no more faults and we've obtained
40763526Sxy150489 		 * link as a result.
40773526Sxy150489 		 */
40783526Sxy150489 	}
40793526Sxy150489 	/*
40803526Sxy150489 	 * Restart process after E1000_SMARTSPEED_MAX iterations (30
40813526Sxy150489 	 * seconds)
40823526Sxy150489 	 */
40834919Sxy150489 	if (Adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
40844919Sxy150489 		Adapter->smartspeed = 0;
40853526Sxy150489 }
40863526Sxy150489 
40873526Sxy150489 static boolean_t
40883526Sxy150489 is_valid_mac_addr(uint8_t *mac_addr)
40893526Sxy150489 {
40903526Sxy150489 	const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 };
40913526Sxy150489 	const uint8_t addr_test2[6] =
40923526Sxy150489 	    { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
40933526Sxy150489 
40943526Sxy150489 	if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) ||
40953526Sxy150489 	    !(bcmp(addr_test2, mac_addr, ETHERADDRL)))
40963526Sxy150489 		return (B_FALSE);
40973526Sxy150489 
40983526Sxy150489 	return (B_TRUE);
40993526Sxy150489 }
41003526Sxy150489 
41013526Sxy150489 /*
41024919Sxy150489  * e1000g_stall_check - check for tx stall
41034919Sxy150489  *
41044919Sxy150489  * This function checks if the adapter is stalled (in transmit).
41054919Sxy150489  *
41064919Sxy150489  * It is called each time the watchdog timeout is invoked.
41074919Sxy150489  * If the transmit descriptor reclaim continuously fails,
41084919Sxy150489  * the watchdog value will increment by 1. If the watchdog
41094919Sxy150489  * value exceeds the threshold, the adapter is assumed to
41104919Sxy150489  * have stalled and need to be reset.
41113526Sxy150489  */
41123526Sxy150489 static boolean_t
41133526Sxy150489 e1000g_stall_check(struct e1000g *Adapter)
41143526Sxy150489 {
41154919Sxy150489 	e1000g_tx_ring_t *tx_ring;
41164919Sxy150489 
41174919Sxy150489 	tx_ring = Adapter->tx_ring;
41184919Sxy150489 
41194061Sxy150489 	if (Adapter->link_state != LINK_STATE_UP)
41203526Sxy150489 		return (B_FALSE);
41213526Sxy150489 
41224919Sxy150489 	if (tx_ring->recycle_fail > 0)
41234919Sxy150489 		tx_ring->stall_watchdog++;
41243526Sxy150489 	else
41254919Sxy150489 		tx_ring->stall_watchdog = 0;
41264919Sxy150489 
41274919Sxy150489 	if (tx_ring->stall_watchdog < E1000G_STALL_WATCHDOG_COUNT)
41283526Sxy150489 		return (B_FALSE);
41293526Sxy150489 
41304919Sxy150489 	tx_ring->stall_watchdog = 0;
41314919Sxy150489 	tx_ring->recycle_fail = 0;
41324919Sxy150489 
41333526Sxy150489 	return (B_TRUE);
41343526Sxy150489 }
41353526Sxy150489 
41364919Sxy150489 #ifdef E1000G_DEBUG
41373526Sxy150489 static enum ioc_reply
41383526Sxy150489 e1000g_pp_ioctl(struct e1000g *e1000gp, struct iocblk *iocp, mblk_t *mp)
41393526Sxy150489 {
41403526Sxy150489 	void (*ppfn)(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd);
41413526Sxy150489 	e1000g_peekpoke_t *ppd;
41423526Sxy150489 	uint64_t mem_va;
41433526Sxy150489 	uint64_t maxoff;
41443526Sxy150489 	boolean_t peek;
41453526Sxy150489 
41463526Sxy150489 	switch (iocp->ioc_cmd) {
41473526Sxy150489 
41483526Sxy150489 	case E1000G_IOC_REG_PEEK:
41493526Sxy150489 		peek = B_TRUE;
41503526Sxy150489 		break;
41513526Sxy150489 
41523526Sxy150489 	case E1000G_IOC_REG_POKE:
41533526Sxy150489 		peek = B_FALSE;
41543526Sxy150489 		break;
41553526Sxy150489 
41563526Sxy150489 	deault:
41574919Sxy150489 		E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL,
41584349Sxy150489 		    "e1000g_diag_ioctl: invalid ioctl command 0x%X\n",
41594349Sxy150489 		    iocp->ioc_cmd);
41603526Sxy150489 		return (IOC_INVAL);
41613526Sxy150489 	}
41623526Sxy150489 
41633526Sxy150489 	/*
41643526Sxy150489 	 * Validate format of ioctl
41653526Sxy150489 	 */
41663526Sxy150489 	if (iocp->ioc_count != sizeof (e1000g_peekpoke_t))
41673526Sxy150489 		return (IOC_INVAL);
41683526Sxy150489 	if (mp->b_cont == NULL)
41693526Sxy150489 		return (IOC_INVAL);
41703526Sxy150489 
41713526Sxy150489 	ppd = (e1000g_peekpoke_t *)mp->b_cont->b_rptr;
41723526Sxy150489 
41733526Sxy150489 	/*
41743526Sxy150489 	 * Validate request parameters
41753526Sxy150489 	 */
41763526Sxy150489 	switch (ppd->pp_acc_space) {
41773526Sxy150489 
41783526Sxy150489 	default:
41794919Sxy150489 		E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL,
41804349Sxy150489 		    "e1000g_diag_ioctl: invalid access space 0x%X\n",
41814349Sxy150489 		    ppd->pp_acc_space);
41823526Sxy150489 		return (IOC_INVAL);
41833526Sxy150489 
41843526Sxy150489 	case E1000G_PP_SPACE_REG:
41853526Sxy150489 		/*
41863526Sxy150489 		 * Memory-mapped I/O space
41873526Sxy150489 		 */
41883526Sxy150489 		ASSERT(ppd->pp_acc_size == 4);
41893526Sxy150489 		if (ppd->pp_acc_size != 4)
41903526Sxy150489 			return (IOC_INVAL);
41913526Sxy150489 
41923526Sxy150489 		if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0)
41933526Sxy150489 			return (IOC_INVAL);
41943526Sxy150489 
41953526Sxy150489 		mem_va = 0;
41963526Sxy150489 		maxoff = 0x10000;
41973526Sxy150489 		ppfn = peek ? e1000g_ioc_peek_reg : e1000g_ioc_poke_reg;
41983526Sxy150489 		break;
41993526Sxy150489 
42003526Sxy150489 	case E1000G_PP_SPACE_E1000G:
42013526Sxy150489 		/*
42023526Sxy150489 		 * E1000g data structure!
42033526Sxy150489 		 */
42043526Sxy150489 		mem_va = (uintptr_t)e1000gp;
42053526Sxy150489 		maxoff = sizeof (struct e1000g);
42063526Sxy150489 		ppfn = peek ? e1000g_ioc_peek_mem : e1000g_ioc_poke_mem;
42073526Sxy150489 		break;
42083526Sxy150489 
42093526Sxy150489 	}
42103526Sxy150489 
42113526Sxy150489 	if (ppd->pp_acc_offset >= maxoff)
42123526Sxy150489 		return (IOC_INVAL);
42133526Sxy150489 
42143526Sxy150489 	if (ppd->pp_acc_offset + ppd->pp_acc_size > maxoff)
42153526Sxy150489 		return (IOC_INVAL);
42163526Sxy150489 
42173526Sxy150489 	/*
42183526Sxy150489 	 * All OK - go!
42193526Sxy150489 	 */
42203526Sxy150489 	ppd->pp_acc_offset += mem_va;
42213526Sxy150489 	(*ppfn)(e1000gp, ppd);
42223526Sxy150489 	return (peek ? IOC_REPLY : IOC_ACK);
42233526Sxy150489 }
42243526Sxy150489 
42253526Sxy150489 static void
42263526Sxy150489 e1000g_ioc_peek_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
42273526Sxy150489 {
42283526Sxy150489 	ddi_acc_handle_t handle;
42293526Sxy150489 	uint32_t *regaddr;
42303526Sxy150489 
42314919Sxy150489 	handle = e1000gp->osdep.reg_handle;
42323526Sxy150489 	regaddr =
42334919Sxy150489 	    (uint32_t *)(e1000gp->shared.hw_addr + ppd->pp_acc_offset);
42343526Sxy150489 
42353526Sxy150489 	ppd->pp_acc_data = ddi_get32(handle, regaddr);
42363526Sxy150489 }
42373526Sxy150489 
42383526Sxy150489 static void
42393526Sxy150489 e1000g_ioc_poke_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
42403526Sxy150489 {
42413526Sxy150489 	ddi_acc_handle_t handle;
42423526Sxy150489 	uint32_t *regaddr;
42433526Sxy150489 	uint32_t value;
42443526Sxy150489 
42454919Sxy150489 	handle = e1000gp->osdep.reg_handle;
42463526Sxy150489 	regaddr =
42474919Sxy150489 	    (uint32_t *)(e1000gp->shared.hw_addr + ppd->pp_acc_offset);
42483526Sxy150489 	value = (uint32_t)ppd->pp_acc_data;
42493526Sxy150489 
42503526Sxy150489 	ddi_put32(handle, regaddr, value);
42513526Sxy150489 }
42523526Sxy150489 
42533526Sxy150489 static void
42543526Sxy150489 e1000g_ioc_peek_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
42553526Sxy150489 {
42563526Sxy150489 	uint64_t value;
42573526Sxy150489 	void *vaddr;
42583526Sxy150489 
42593526Sxy150489 	vaddr = (void *)(uintptr_t)ppd->pp_acc_offset;
42603526Sxy150489 
42613526Sxy150489 	switch (ppd->pp_acc_size) {
42623526Sxy150489 	case 1:
42633526Sxy150489 		value = *(uint8_t *)vaddr;
42643526Sxy150489 		break;
42653526Sxy150489 
42663526Sxy150489 	case 2:
42673526Sxy150489 		value = *(uint16_t *)vaddr;
42683526Sxy150489 		break;
42693526Sxy150489 
42703526Sxy150489 	case 4:
42713526Sxy150489 		value = *(uint32_t *)vaddr;
42723526Sxy150489 		break;
42733526Sxy150489 
42743526Sxy150489 	case 8:
42753526Sxy150489 		value = *(uint64_t *)vaddr;
42763526Sxy150489 		break;
42773526Sxy150489 	}
42783526Sxy150489 
42794919Sxy150489 	E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL,
42804349Sxy150489 	    "e1000g_ioc_peek_mem($%p, $%p) peeked 0x%llx from $%p\n",
42814349Sxy150489 	    (void *)e1000gp, (void *)ppd, value, vaddr);
42823526Sxy150489 
42833526Sxy150489 	ppd->pp_acc_data = value;
42843526Sxy150489 }
42853526Sxy150489 
42863526Sxy150489 static void
42873526Sxy150489 e1000g_ioc_poke_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
42883526Sxy150489 {
42893526Sxy150489 	uint64_t value;
42903526Sxy150489 	void *vaddr;
42913526Sxy150489 
42923526Sxy150489 	vaddr = (void *)(uintptr_t)ppd->pp_acc_offset;
42933526Sxy150489 	value = ppd->pp_acc_data;
42943526Sxy150489 
42954919Sxy150489 	E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL,
42964349Sxy150489 	    "e1000g_ioc_poke_mem($%p, $%p) poking 0x%llx at $%p\n",
42974349Sxy150489 	    (void *)e1000gp, (void *)ppd, value, vaddr);
42983526Sxy150489 
42993526Sxy150489 	switch (ppd->pp_acc_size) {
43003526Sxy150489 	case 1:
43013526Sxy150489 		*(uint8_t *)vaddr = (uint8_t)value;
43023526Sxy150489 		break;
43033526Sxy150489 
43043526Sxy150489 	case 2:
43053526Sxy150489 		*(uint16_t *)vaddr = (uint16_t)value;
43063526Sxy150489 		break;
43073526Sxy150489 
43083526Sxy150489 	case 4:
43093526Sxy150489 		*(uint32_t *)vaddr = (uint32_t)value;
43103526Sxy150489 		break;
43113526Sxy150489 
43123526Sxy150489 	case 8:
43133526Sxy150489 		*(uint64_t *)vaddr = (uint64_t)value;
43143526Sxy150489 		break;
43153526Sxy150489 	}
43163526Sxy150489 }
43174919Sxy150489 #endif
43183526Sxy150489 
43193526Sxy150489 /*
43203526Sxy150489  * Loopback Support
43213526Sxy150489  */
43223526Sxy150489 static lb_property_t lb_normal =
43233526Sxy150489 	{ normal,	"normal",	E1000G_LB_NONE		};
43243526Sxy150489 static lb_property_t lb_external1000 =
43253526Sxy150489 	{ external,	"1000Mbps",	E1000G_LB_EXTERNAL_1000	};
43263526Sxy150489 static lb_property_t lb_external100 =
43273526Sxy150489 	{ external,	"100Mbps",	E1000G_LB_EXTERNAL_100	};
43283526Sxy150489 static lb_property_t lb_external10 =
43293526Sxy150489 	{ external,	"10Mbps",	E1000G_LB_EXTERNAL_10	};
43303526Sxy150489 static lb_property_t lb_phy =
43313526Sxy150489 	{ internal,	"PHY",		E1000G_LB_INTERNAL_PHY	};
43323526Sxy150489 
43333526Sxy150489 static enum ioc_reply
43343526Sxy150489 e1000g_loopback_ioctl(struct e1000g *Adapter, struct iocblk *iocp, mblk_t *mp)
43353526Sxy150489 {
43363526Sxy150489 	lb_info_sz_t *lbsp;
43373526Sxy150489 	lb_property_t *lbpp;
43383526Sxy150489 	struct e1000_hw *hw;
43393526Sxy150489 	uint32_t *lbmp;
43403526Sxy150489 	uint32_t size;
43413526Sxy150489 	uint32_t value;
43423526Sxy150489 
43434919Sxy150489 	hw = &Adapter->shared;
43443526Sxy150489 
43453526Sxy150489 	if (mp->b_cont == NULL)
43463526Sxy150489 		return (IOC_INVAL);
43473526Sxy150489 
43483526Sxy150489 	switch (iocp->ioc_cmd) {
43493526Sxy150489 	default:
43503526Sxy150489 		return (IOC_INVAL);
43513526Sxy150489 
43523526Sxy150489 	case LB_GET_INFO_SIZE:
43533526Sxy150489 		size = sizeof (lb_info_sz_t);
43543526Sxy150489 		if (iocp->ioc_count != size)
43553526Sxy150489 			return (IOC_INVAL);
43563526Sxy150489 
43575082Syy150190 		rw_enter(&Adapter->chip_lock, RW_WRITER);
43585082Syy150190 		e1000g_get_phy_state(Adapter);
43595082Syy150190 
43605082Syy150190 		/*
43615082Syy150190 		 * Workaround for hardware faults. In order to get a stable
43625082Syy150190 		 * state of phy, we will wait for a specific interval and
43635082Syy150190 		 * try again. The time delay is an experiential value based
43645082Syy150190 		 * on our testing.
43655082Syy150190 		 */
43665082Syy150190 		msec_delay(100);
43675082Syy150190 		e1000g_get_phy_state(Adapter);
43685082Syy150190 		rw_exit(&Adapter->chip_lock);
43693526Sxy150489 
43703526Sxy150489 		value = sizeof (lb_normal);
43715082Syy150190 		if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
43725082Syy150190 		    (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
43736735Scc210113 		    (hw->phy.media_type == e1000_media_type_fiber) ||
43746735Scc210113 		    (hw->phy.media_type == e1000_media_type_internal_serdes)) {
43753526Sxy150489 			value += sizeof (lb_phy);
43764919Sxy150489 			switch (hw->mac.type) {
43773526Sxy150489 			case e1000_82571:
43783526Sxy150489 			case e1000_82572:
43793526Sxy150489 				value += sizeof (lb_external1000);
43803526Sxy150489 				break;
43813526Sxy150489 			}
43823526Sxy150489 		}
43835082Syy150190 		if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
43845082Syy150190 		    (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
43853526Sxy150489 			value += sizeof (lb_external100);
43865082Syy150190 		if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
43873526Sxy150489 			value += sizeof (lb_external10);
43883526Sxy150489 
43893526Sxy150489 		lbsp = (lb_info_sz_t *)mp->b_cont->b_rptr;
43903526Sxy150489 		*lbsp = value;
43913526Sxy150489 		break;
43923526Sxy150489 
43933526Sxy150489 	case LB_GET_INFO:
43943526Sxy150489 		value = sizeof (lb_normal);
43955082Syy150190 		if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
43965082Syy150190 		    (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
43976735Scc210113 		    (hw->phy.media_type == e1000_media_type_fiber) ||
43986735Scc210113 		    (hw->phy.media_type == e1000_media_type_internal_serdes)) {
43993526Sxy150489 			value += sizeof (lb_phy);
44004919Sxy150489 			switch (hw->mac.type) {
44013526Sxy150489 			case e1000_82571:
44023526Sxy150489 			case e1000_82572:
44033526Sxy150489 				value += sizeof (lb_external1000);
44043526Sxy150489 				break;
44053526Sxy150489 			}
44063526Sxy150489 		}
44075082Syy150190 		if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
44085082Syy150190 		    (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
44093526Sxy150489 			value += sizeof (lb_external100);
44105082Syy150190 		if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
44113526Sxy150489 			value += sizeof (lb_external10);
44123526Sxy150489 
44133526Sxy150489 		size = value;
44143526Sxy150489 		if (iocp->ioc_count != size)
44153526Sxy150489 			return (IOC_INVAL);
44163526Sxy150489 
44173526Sxy150489 		value = 0;
44183526Sxy150489 		lbpp = (lb_property_t *)mp->b_cont->b_rptr;
44193526Sxy150489 		lbpp[value++] = lb_normal;
44205082Syy150190 		if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
44215082Syy150190 		    (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
44226735Scc210113 		    (hw->phy.media_type == e1000_media_type_fiber) ||
44236735Scc210113 		    (hw->phy.media_type == e1000_media_type_internal_serdes)) {
44243526Sxy150489 			lbpp[value++] = lb_phy;
44254919Sxy150489 			switch (hw->mac.type) {
44263526Sxy150489 			case e1000_82571:
44273526Sxy150489 			case e1000_82572:
44283526Sxy150489 				lbpp[value++] = lb_external1000;
44293526Sxy150489 				break;
44303526Sxy150489 			}
44313526Sxy150489 		}
44325082Syy150190 		if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
44335082Syy150190 		    (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
44343526Sxy150489 			lbpp[value++] = lb_external100;
44355082Syy150190 		if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
44363526Sxy150489 			lbpp[value++] = lb_external10;
44373526Sxy150489 		break;
44383526Sxy150489 
44393526Sxy150489 	case LB_GET_MODE:
44403526Sxy150489 		size = sizeof (uint32_t);
44413526Sxy150489 		if (iocp->ioc_count != size)
44423526Sxy150489 			return (IOC_INVAL);
44433526Sxy150489 
44443526Sxy150489 		lbmp = (uint32_t *)mp->b_cont->b_rptr;
44453526Sxy150489 		*lbmp = Adapter->loopback_mode;
44463526Sxy150489 		break;
44473526Sxy150489 
44483526Sxy150489 	case LB_SET_MODE:
44493526Sxy150489 		size = 0;
44503526Sxy150489 		if (iocp->ioc_count != sizeof (uint32_t))
44513526Sxy150489 			return (IOC_INVAL);
44523526Sxy150489 
44533526Sxy150489 		lbmp = (uint32_t *)mp->b_cont->b_rptr;
44543526Sxy150489 		if (!e1000g_set_loopback_mode(Adapter, *lbmp))
44553526Sxy150489 			return (IOC_INVAL);
44563526Sxy150489 		break;
44573526Sxy150489 	}
44583526Sxy150489 
44593526Sxy150489 	iocp->ioc_count = size;
44603526Sxy150489 	iocp->ioc_error = 0;
44613526Sxy150489 
44625273Sgl147354 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
44635273Sgl147354 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
44645273Sgl147354 		return (IOC_INVAL);
44655273Sgl147354 	}
44665273Sgl147354 
44673526Sxy150489 	return (IOC_REPLY);
44683526Sxy150489 }
44693526Sxy150489 
44703526Sxy150489 static boolean_t
44713526Sxy150489 e1000g_set_loopback_mode(struct e1000g *Adapter, uint32_t mode)
44723526Sxy150489 {
44733526Sxy150489 	struct e1000_hw *hw;
44743526Sxy150489 	int i, times;
44755082Syy150190 	boolean_t link_up;
44763526Sxy150489 
44773526Sxy150489 	if (mode == Adapter->loopback_mode)
44783526Sxy150489 		return (B_TRUE);
44793526Sxy150489 
44804919Sxy150489 	hw = &Adapter->shared;
44813526Sxy150489 	times = 0;
44823526Sxy150489 
44835082Syy150190 	Adapter->loopback_mode = mode;
44845082Syy150190 
44855082Syy150190 	if (mode == E1000G_LB_NONE) {
44863526Sxy150489 		/* Reset the chip */
44876735Scc210113 		hw->phy.autoneg_wait_to_complete = B_TRUE;
44883526Sxy150489 		(void) e1000g_reset(Adapter);
44896735Scc210113 		hw->phy.autoneg_wait_to_complete = B_FALSE;
44905082Syy150190 		return (B_TRUE);
44915082Syy150190 	}
44925082Syy150190 
44935082Syy150190 again:
44945082Syy150190 
44955082Syy150190 	rw_enter(&Adapter->chip_lock, RW_WRITER);
44965082Syy150190 
44975082Syy150190 	switch (mode) {
44985082Syy150190 	default:
44995082Syy150190 		rw_exit(&Adapter->chip_lock);
45005082Syy150190 		return (B_FALSE);
45013526Sxy150489 
45023526Sxy150489 	case E1000G_LB_EXTERNAL_1000:
45033526Sxy150489 		e1000g_set_external_loopback_1000(Adapter);
45043526Sxy150489 		break;
45053526Sxy150489 
45063526Sxy150489 	case E1000G_LB_EXTERNAL_100:
45073526Sxy150489 		e1000g_set_external_loopback_100(Adapter);
45083526Sxy150489 		break;
45093526Sxy150489 
45103526Sxy150489 	case E1000G_LB_EXTERNAL_10:
45113526Sxy150489 		e1000g_set_external_loopback_10(Adapter);
45123526Sxy150489 		break;
45133526Sxy150489 
45143526Sxy150489 	case E1000G_LB_INTERNAL_PHY:
45153526Sxy150489 		e1000g_set_internal_loopback(Adapter);
45163526Sxy150489 		break;
45173526Sxy150489 	}
45183526Sxy150489 
45193526Sxy150489 	times++;
45203526Sxy150489 
45215858Scc210113 	rw_exit(&Adapter->chip_lock);
45225858Scc210113 
45235082Syy150190 	/* Wait for link up */
45245082Syy150190 	for (i = (PHY_FORCE_LIMIT * 2); i > 0; i--)
45255082Syy150190 		msec_delay(100);
45265082Syy150190 
45275858Scc210113 	rw_enter(&Adapter->chip_lock, RW_WRITER);
45285858Scc210113 
45295082Syy150190 	link_up = e1000g_link_up(Adapter);
45305082Syy150190 
45315082Syy150190 	rw_exit(&Adapter->chip_lock);
45325082Syy150190 
45335082Syy150190 	if (!link_up) {
45345082Syy150190 		E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
45355082Syy150190 		    "Failed to get the link up");
45365082Syy150190 		if (times < 2) {
45375082Syy150190 			/* Reset the link */
45384919Sxy150489 			E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
45395082Syy150190 			    "Reset the link ...");
45405082Syy150190 			(void) e1000g_reset(Adapter);
45415082Syy150190 			goto again;
45423526Sxy150489 		}
45433526Sxy150489 	}
45443526Sxy150489 
45453526Sxy150489 	return (B_TRUE);
45463526Sxy150489 }
45473526Sxy150489 
45483526Sxy150489 /*
45493526Sxy150489  * The following loopback settings are from Intel's technical
45503526Sxy150489  * document - "How To Loopback". All the register settings and
45513526Sxy150489  * time delay values are directly inherited from the document
45523526Sxy150489  * without more explanations available.
45533526Sxy150489  */
45543526Sxy150489 static void
45553526Sxy150489 e1000g_set_internal_loopback(struct e1000g *Adapter)
45563526Sxy150489 {
45573526Sxy150489 	struct e1000_hw *hw;
45583526Sxy150489 	uint32_t ctrl;
45593526Sxy150489 	uint32_t status;
45603526Sxy150489 	uint16_t phy_ctrl;
45615082Syy150190 	uint32_t txcw;
45623526Sxy150489 
45634919Sxy150489 	hw = &Adapter->shared;
45643526Sxy150489 
45653526Sxy150489 	/* Disable Smart Power Down */
45663526Sxy150489 	phy_spd_state(hw, B_FALSE);
45673526Sxy150489 
45684919Sxy150489 	e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl);
45693526Sxy150489 	phy_ctrl &= ~(MII_CR_AUTO_NEG_EN | MII_CR_SPEED_100 | MII_CR_SPEED_10);
45703526Sxy150489 	phy_ctrl |= MII_CR_FULL_DUPLEX | MII_CR_SPEED_1000;
45713526Sxy150489 
45724919Sxy150489 	switch (hw->mac.type) {
45733526Sxy150489 	case e1000_82540:
45743526Sxy150489 	case e1000_82545:
45753526Sxy150489 	case e1000_82545_rev_3:
45763526Sxy150489 	case e1000_82546:
45773526Sxy150489 	case e1000_82546_rev_3:
45783526Sxy150489 	case e1000_82573:
45793526Sxy150489 		/* Auto-MDI/MDIX off */
45803526Sxy150489 		e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
45813526Sxy150489 		/* Reset PHY to update Auto-MDI/MDIX */
45824919Sxy150489 		e1000_write_phy_reg(hw, PHY_CONTROL,
45834349Sxy150489 		    phy_ctrl | MII_CR_RESET | MII_CR_AUTO_NEG_EN);
45843526Sxy150489 		/* Reset PHY to auto-neg off and force 1000 */
45854919Sxy150489 		e1000_write_phy_reg(hw, PHY_CONTROL,
45864349Sxy150489 		    phy_ctrl | MII_CR_RESET);
45875082Syy150190 		/*
45885082Syy150190 		 * Disable PHY receiver for 82540/545/546 and 82573 Family.
45895082Syy150190 		 * See comments above e1000g_set_internal_loopback() for the
45905082Syy150190 		 * background.
45915082Syy150190 		 */
45925082Syy150190 		e1000_write_phy_reg(hw, 29, 0x001F);
45935082Syy150190 		e1000_write_phy_reg(hw, 30, 0x8FFC);
45945082Syy150190 		e1000_write_phy_reg(hw, 29, 0x001A);
45955082Syy150190 		e1000_write_phy_reg(hw, 30, 0x8FF0);
45963526Sxy150489 		break;
45973526Sxy150489 	}
45983526Sxy150489 
45993526Sxy150489 	/* Set loopback */
46004919Sxy150489 	e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl | MII_CR_LOOPBACK);
46013526Sxy150489 
46023526Sxy150489 	msec_delay(250);
46033526Sxy150489 
46043526Sxy150489 	/* Now set up the MAC to the same speed/duplex as the PHY. */
46054919Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
46063526Sxy150489 	ctrl &= ~E1000_CTRL_SPD_SEL;	/* Clear the speed sel bits */
46073526Sxy150489 	ctrl |= (E1000_CTRL_FRCSPD |	/* Set the Force Speed Bit */
46084349Sxy150489 	    E1000_CTRL_FRCDPX |		/* Set the Force Duplex Bit */
46094349Sxy150489 	    E1000_CTRL_SPD_1000 |	/* Force Speed to 1000 */
46104349Sxy150489 	    E1000_CTRL_FD);		/* Force Duplex to FULL */
46113526Sxy150489 
46124919Sxy150489 	switch (hw->mac.type) {
46133526Sxy150489 	case e1000_82540:
46143526Sxy150489 	case e1000_82545:
46153526Sxy150489 	case e1000_82545_rev_3:
46163526Sxy150489 	case e1000_82546:
46173526Sxy150489 	case e1000_82546_rev_3:
46183526Sxy150489 		/*
46193526Sxy150489 		 * For some serdes we'll need to commit the writes now
46203526Sxy150489 		 * so that the status is updated on link
46213526Sxy150489 		 */
46226735Scc210113 		if (hw->phy.media_type == e1000_media_type_internal_serdes) {
46234919Sxy150489 			E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
46243526Sxy150489 			msec_delay(100);
46254919Sxy150489 			ctrl = E1000_READ_REG(hw, E1000_CTRL);
46263526Sxy150489 		}
46273526Sxy150489 
46286735Scc210113 		if (hw->phy.media_type == e1000_media_type_copper) {
46293526Sxy150489 			/* Invert Loss of Signal */
46303526Sxy150489 			ctrl |= E1000_CTRL_ILOS;
46313526Sxy150489 		} else {
46323526Sxy150489 			/* Set ILOS on fiber nic if half duplex is detected */
46334919Sxy150489 			status = E1000_READ_REG(hw, E1000_STATUS);
46343526Sxy150489 			if ((status & E1000_STATUS_FD) == 0)
46353526Sxy150489 				ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
46363526Sxy150489 		}
46373526Sxy150489 		break;
46383526Sxy150489 
46393526Sxy150489 	case e1000_82571:
46403526Sxy150489 	case e1000_82572:
46415082Syy150190 		/*
46425082Syy150190 		 * The fiber/SerDes versions of this adapter do not contain an
46435082Syy150190 		 * accessible PHY. Therefore, loopback beyond MAC must be done
46445082Syy150190 		 * using SerDes analog loopback.
46455082Syy150190 		 */
46466735Scc210113 		if (hw->phy.media_type != e1000_media_type_copper) {
46474919Sxy150489 			status = E1000_READ_REG(hw, E1000_STATUS);
46485082Syy150190 			/* Set ILOS on fiber nic if half duplex is detected */
46495082Syy150190 			if (((status & E1000_STATUS_LU) == 0) ||
46505082Syy150190 			    ((status & E1000_STATUS_FD) == 0) ||
46516735Scc210113 			    (hw->phy.media_type ==
46525082Syy150190 			    e1000_media_type_internal_serdes))
46533526Sxy150489 				ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
46545082Syy150190 
46555082Syy150190 			/* Disable autoneg by setting bit 31 of TXCW to zero */
46565082Syy150190 			txcw = E1000_READ_REG(hw, E1000_TXCW);
46575082Syy150190 			txcw &= ~((uint32_t)1 << 31);
46585082Syy150190 			E1000_WRITE_REG(hw, E1000_TXCW, txcw);
46595082Syy150190 
46605082Syy150190 			/*
46615082Syy150190 			 * Write 0x410 to Serdes Control register
46625082Syy150190 			 * to enable Serdes analog loopback
46635082Syy150190 			 */
46645082Syy150190 			E1000_WRITE_REG(hw, E1000_SCTL, 0x0410);
46655082Syy150190 			msec_delay(10);
46663526Sxy150489 		}
46673526Sxy150489 		break;
46683526Sxy150489 
46693526Sxy150489 	case e1000_82573:
46703526Sxy150489 		ctrl |= E1000_CTRL_ILOS;
46713526Sxy150489 		break;
46723526Sxy150489 	}
46733526Sxy150489 
46744919Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
46753526Sxy150489 
46763526Sxy150489 }
46773526Sxy150489 
46783526Sxy150489 static void
46793526Sxy150489 e1000g_set_external_loopback_1000(struct e1000g *Adapter)
46803526Sxy150489 {
46813526Sxy150489 	struct e1000_hw *hw;
46823526Sxy150489 	uint32_t rctl;
46833526Sxy150489 	uint32_t ctrl_ext;
46843526Sxy150489 	uint32_t ctrl;
46853526Sxy150489 	uint32_t status;
46863526Sxy150489 	uint32_t txcw;
46873526Sxy150489 
46884919Sxy150489 	hw = &Adapter->shared;
46893526Sxy150489 
46903526Sxy150489 	/* Disable Smart Power Down */
46913526Sxy150489 	phy_spd_state(hw, B_FALSE);
46923526Sxy150489 
46936735Scc210113 	switch (hw->phy.media_type) {
46943526Sxy150489 	case e1000_media_type_copper:
46953526Sxy150489 		/* Force link up (Must be done before the PHY writes) */
46964919Sxy150489 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
46973526Sxy150489 		ctrl |= E1000_CTRL_SLU;	/* Force Link Up */
46984919Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
46994919Sxy150489 
47004919Sxy150489 		rctl = E1000_READ_REG(hw, E1000_RCTL);
47013526Sxy150489 		rctl |= (E1000_RCTL_EN |
47024349Sxy150489 		    E1000_RCTL_SBP |
47034349Sxy150489 		    E1000_RCTL_UPE |
47044349Sxy150489 		    E1000_RCTL_MPE |
47054349Sxy150489 		    E1000_RCTL_LPE |
47064349Sxy150489 		    E1000_RCTL_BAM);		/* 0x803E */
47074919Sxy150489 		E1000_WRITE_REG(hw, E1000_RCTL, rctl);
47084919Sxy150489 
47094919Sxy150489 		ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
47103526Sxy150489 		ctrl_ext |= (E1000_CTRL_EXT_SDP4_DATA |
47114349Sxy150489 		    E1000_CTRL_EXT_SDP6_DATA |
47124349Sxy150489 		    E1000_CTRL_EXT_SDP7_DATA |
47134349Sxy150489 		    E1000_CTRL_EXT_SDP4_DIR |
47144349Sxy150489 		    E1000_CTRL_EXT_SDP6_DIR |
47154349Sxy150489 		    E1000_CTRL_EXT_SDP7_DIR);	/* 0x0DD0 */
47164919Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
47173526Sxy150489 
47183526Sxy150489 		/*
47193526Sxy150489 		 * This sequence tunes the PHY's SDP and no customer
47203526Sxy150489 		 * settable values. For background, see comments above
47213526Sxy150489 		 * e1000g_set_internal_loopback().
47223526Sxy150489 		 */
47233526Sxy150489 		e1000_write_phy_reg(hw, 0x0, 0x140);
47243526Sxy150489 		msec_delay(10);
47253526Sxy150489 		e1000_write_phy_reg(hw, 0x9, 0x1A00);
47263526Sxy150489 		e1000_write_phy_reg(hw, 0x12, 0xC10);
47273526Sxy150489 		e1000_write_phy_reg(hw, 0x12, 0x1C10);
47283526Sxy150489 		e1000_write_phy_reg(hw, 0x1F37, 0x76);
47293526Sxy150489 		e1000_write_phy_reg(hw, 0x1F33, 0x1);
47303526Sxy150489 		e1000_write_phy_reg(hw, 0x1F33, 0x0);
47313526Sxy150489 
47323526Sxy150489 		e1000_write_phy_reg(hw, 0x1F35, 0x65);
47333526Sxy150489 		e1000_write_phy_reg(hw, 0x1837, 0x3F7C);
47343526Sxy150489 		e1000_write_phy_reg(hw, 0x1437, 0x3FDC);
47353526Sxy150489 		e1000_write_phy_reg(hw, 0x1237, 0x3F7C);
47363526Sxy150489 		e1000_write_phy_reg(hw, 0x1137, 0x3FDC);
47373526Sxy150489 
47383526Sxy150489 		msec_delay(50);
47393526Sxy150489 		break;
47403526Sxy150489 	case e1000_media_type_fiber:
47413526Sxy150489 	case e1000_media_type_internal_serdes:
47424919Sxy150489 		status = E1000_READ_REG(hw, E1000_STATUS);
47433526Sxy150489 		if (((status & E1000_STATUS_LU) == 0) ||
47446735Scc210113 		    (hw->phy.media_type == e1000_media_type_internal_serdes)) {
47454919Sxy150489 			ctrl = E1000_READ_REG(hw, E1000_CTRL);
47463526Sxy150489 			ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
47474919Sxy150489 			E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
47483526Sxy150489 		}
47493526Sxy150489 
47503526Sxy150489 		/* Disable autoneg by setting bit 31 of TXCW to zero */
47514919Sxy150489 		txcw = E1000_READ_REG(hw, E1000_TXCW);
47523526Sxy150489 		txcw &= ~((uint32_t)1 << 31);
47534919Sxy150489 		E1000_WRITE_REG(hw, E1000_TXCW, txcw);
47543526Sxy150489 
47553526Sxy150489 		/*
47563526Sxy150489 		 * Write 0x410 to Serdes Control register
47573526Sxy150489 		 * to enable Serdes analog loopback
47583526Sxy150489 		 */
47594919Sxy150489 		E1000_WRITE_REG(hw, E1000_SCTL, 0x0410);
47603526Sxy150489 		msec_delay(10);
47613526Sxy150489 		break;
47623526Sxy150489 	default:
47633526Sxy150489 		break;
47643526Sxy150489 	}
47653526Sxy150489 }
47663526Sxy150489 
47673526Sxy150489 static void
47683526Sxy150489 e1000g_set_external_loopback_100(struct e1000g *Adapter)
47693526Sxy150489 {
47703526Sxy150489 	struct e1000_hw *hw;
47713526Sxy150489 	uint32_t ctrl;
47723526Sxy150489 	uint16_t phy_ctrl;
47733526Sxy150489 
47744919Sxy150489 	hw = &Adapter->shared;
47753526Sxy150489 
47763526Sxy150489 	/* Disable Smart Power Down */
47773526Sxy150489 	phy_spd_state(hw, B_FALSE);
47783526Sxy150489 
47793526Sxy150489 	phy_ctrl = (MII_CR_FULL_DUPLEX |
47804349Sxy150489 	    MII_CR_SPEED_100);
47813526Sxy150489 
47823526Sxy150489 	/* Force 100/FD, reset PHY */
47834919Sxy150489 	e1000_write_phy_reg(hw, PHY_CONTROL,
47844349Sxy150489 	    phy_ctrl | MII_CR_RESET);	/* 0xA100 */
47853526Sxy150489 	msec_delay(10);
47863526Sxy150489 
47873526Sxy150489 	/* Force 100/FD */
47884919Sxy150489 	e1000_write_phy_reg(hw, PHY_CONTROL,
47894349Sxy150489 	    phy_ctrl);			/* 0x2100 */
47903526Sxy150489 	msec_delay(10);
47913526Sxy150489 
47923526Sxy150489 	/* Now setup the MAC to the same speed/duplex as the PHY. */
47934919Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
47943526Sxy150489 	ctrl &= ~E1000_CTRL_SPD_SEL;	/* Clear the speed sel bits */
47953526Sxy150489 	ctrl |= (E1000_CTRL_SLU |	/* Force Link Up */
47964349Sxy150489 	    E1000_CTRL_FRCSPD |		/* Set the Force Speed Bit */
47974349Sxy150489 	    E1000_CTRL_FRCDPX |		/* Set the Force Duplex Bit */
47984349Sxy150489 	    E1000_CTRL_SPD_100 |	/* Force Speed to 100 */
47994349Sxy150489 	    E1000_CTRL_FD);		/* Force Duplex to FULL */
48003526Sxy150489 
48014919Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
48023526Sxy150489 }
48033526Sxy150489 
48043526Sxy150489 static void
48053526Sxy150489 e1000g_set_external_loopback_10(struct e1000g *Adapter)
48063526Sxy150489 {
48073526Sxy150489 	struct e1000_hw *hw;
48083526Sxy150489 	uint32_t ctrl;
48093526Sxy150489 	uint16_t phy_ctrl;
48103526Sxy150489 
48114919Sxy150489 	hw = &Adapter->shared;
48123526Sxy150489 
48133526Sxy150489 	/* Disable Smart Power Down */
48143526Sxy150489 	phy_spd_state(hw, B_FALSE);
48153526Sxy150489 
48163526Sxy150489 	phy_ctrl = (MII_CR_FULL_DUPLEX |
48174349Sxy150489 	    MII_CR_SPEED_10);
48183526Sxy150489 
48193526Sxy150489 	/* Force 10/FD, reset PHY */
48204919Sxy150489 	e1000_write_phy_reg(hw, PHY_CONTROL,
48214349Sxy150489 	    phy_ctrl | MII_CR_RESET);	/* 0x8100 */
48223526Sxy150489 	msec_delay(10);
48233526Sxy150489 
48243526Sxy150489 	/* Force 10/FD */
48254919Sxy150489 	e1000_write_phy_reg(hw, PHY_CONTROL,
48264349Sxy150489 	    phy_ctrl);			/* 0x0100 */
48273526Sxy150489 	msec_delay(10);
48283526Sxy150489 
48293526Sxy150489 	/* Now setup the MAC to the same speed/duplex as the PHY. */
48304919Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
48313526Sxy150489 	ctrl &= ~E1000_CTRL_SPD_SEL;	/* Clear the speed sel bits */
48323526Sxy150489 	ctrl |= (E1000_CTRL_SLU |	/* Force Link Up */
48334349Sxy150489 	    E1000_CTRL_FRCSPD |		/* Set the Force Speed Bit */
48344349Sxy150489 	    E1000_CTRL_FRCDPX |		/* Set the Force Duplex Bit */
48354349Sxy150489 	    E1000_CTRL_SPD_10 |		/* Force Speed to 10 */
48364349Sxy150489 	    E1000_CTRL_FD);		/* Force Duplex to FULL */
48373526Sxy150489 
48384919Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
48393526Sxy150489 }
48403526Sxy150489 
48413526Sxy150489 #ifdef __sparc
48423526Sxy150489 static boolean_t
48433526Sxy150489 e1000g_find_mac_address(struct e1000g *Adapter)
48443526Sxy150489 {
48454919Sxy150489 	struct e1000_hw *hw = &Adapter->shared;
48463526Sxy150489 	uchar_t *bytes;
48473526Sxy150489 	struct ether_addr sysaddr;
48483526Sxy150489 	uint_t nelts;
48493526Sxy150489 	int err;
48503526Sxy150489 	boolean_t found = B_FALSE;
48513526Sxy150489 
48523526Sxy150489 	/*
48533526Sxy150489 	 * The "vendor's factory-set address" may already have
48543526Sxy150489 	 * been extracted from the chip, but if the property
48553526Sxy150489 	 * "local-mac-address" is set we use that instead.
48563526Sxy150489 	 *
48573526Sxy150489 	 * We check whether it looks like an array of 6
48583526Sxy150489 	 * bytes (which it should, if OBP set it).  If we can't
48593526Sxy150489 	 * make sense of it this way, we'll ignore it.
48603526Sxy150489 	 */
48613526Sxy150489 	err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip,
48623526Sxy150489 	    DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts);
48633526Sxy150489 	if (err == DDI_PROP_SUCCESS) {
48643526Sxy150489 		if (nelts == ETHERADDRL) {
48653526Sxy150489 			while (nelts--)
48664919Sxy150489 				hw->mac.addr[nelts] = bytes[nelts];
48673526Sxy150489 			found = B_TRUE;
48683526Sxy150489 		}
48693526Sxy150489 		ddi_prop_free(bytes);
48703526Sxy150489 	}
48713526Sxy150489 
48723526Sxy150489 	/*
48733526Sxy150489 	 * Look up the OBP property "local-mac-address?". If the user has set
48743526Sxy150489 	 * 'local-mac-address? = false', use "the system address" instead.
48753526Sxy150489 	 */
48763526Sxy150489 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 0,
48773526Sxy150489 	    "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) {
48783526Sxy150489 		if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) {
48793526Sxy150489 			if (localetheraddr(NULL, &sysaddr) != 0) {
48804919Sxy150489 				bcopy(&sysaddr, hw->mac.addr, ETHERADDRL);
48813526Sxy150489 				found = B_TRUE;
48823526Sxy150489 			}
48833526Sxy150489 		}
48843526Sxy150489 		ddi_prop_free(bytes);
48853526Sxy150489 	}
48863526Sxy150489 
48873526Sxy150489 	/*
48883526Sxy150489 	 * Finally(!), if there's a valid "mac-address" property (created
48893526Sxy150489 	 * if we netbooted from this interface), we must use this instead
48903526Sxy150489 	 * of any of the above to ensure that the NFS/install server doesn't
48913526Sxy150489 	 * get confused by the address changing as Solaris takes over!
48923526Sxy150489 	 */
48933526Sxy150489 	err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip,
48943526Sxy150489 	    DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts);
48953526Sxy150489 	if (err == DDI_PROP_SUCCESS) {
48963526Sxy150489 		if (nelts == ETHERADDRL) {
48973526Sxy150489 			while (nelts--)
48984919Sxy150489 				hw->mac.addr[nelts] = bytes[nelts];
48993526Sxy150489 			found = B_TRUE;
49003526Sxy150489 		}
49013526Sxy150489 		ddi_prop_free(bytes);
49023526Sxy150489 	}
49033526Sxy150489 
49043526Sxy150489 	if (found) {
49054919Sxy150489 		bcopy(hw->mac.addr, hw->mac.perm_addr,
49063526Sxy150489 		    ETHERADDRL);
49073526Sxy150489 	}
49083526Sxy150489 
49093526Sxy150489 	return (found);
49103526Sxy150489 }
49113526Sxy150489 #endif
49123526Sxy150489 
49133526Sxy150489 static int
49143526Sxy150489 e1000g_add_intrs(struct e1000g *Adapter)
49153526Sxy150489 {
49163526Sxy150489 	dev_info_t *devinfo;
49173526Sxy150489 	int intr_types;
49183526Sxy150489 	int rc;
49193526Sxy150489 
49203526Sxy150489 	devinfo = Adapter->dip;
49213526Sxy150489 
49223526Sxy150489 	/* Get supported interrupt types */
49233526Sxy150489 	rc = ddi_intr_get_supported_types(devinfo, &intr_types);
49243526Sxy150489 
49253526Sxy150489 	if (rc != DDI_SUCCESS) {
49264919Sxy150489 		E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
49273526Sxy150489 		    "Get supported interrupt types failed: %d\n", rc);
49283526Sxy150489 		return (DDI_FAILURE);
49293526Sxy150489 	}
49303526Sxy150489 
49313526Sxy150489 	/*
49323526Sxy150489 	 * Based on Intel Technical Advisory document (TA-160), there are some
49333526Sxy150489 	 * cases where some older Intel PCI-X NICs may "advertise" to the OS
49343526Sxy150489 	 * that it supports MSI, but in fact has problems.
49353526Sxy150489 	 * So we should only enable MSI for PCI-E NICs and disable MSI for old
49363526Sxy150489 	 * PCI/PCI-X NICs.
49373526Sxy150489 	 */
49384919Sxy150489 	if (Adapter->shared.mac.type < e1000_82571)
4939*6986Smx205022 		Adapter->msi_enable = B_FALSE;
4940*6986Smx205022 
4941*6986Smx205022 	if ((intr_types & DDI_INTR_TYPE_MSI) && Adapter->msi_enable) {
49423526Sxy150489 		rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_MSI);
49433526Sxy150489 
49443526Sxy150489 		if (rc != DDI_SUCCESS) {
49454919Sxy150489 			E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
49463526Sxy150489 			    "Add MSI failed, trying Legacy interrupts\n");
49473526Sxy150489 		} else {
49483526Sxy150489 			Adapter->intr_type = DDI_INTR_TYPE_MSI;
49493526Sxy150489 		}
49503526Sxy150489 	}
49513526Sxy150489 
49523526Sxy150489 	if ((Adapter->intr_type == 0) &&
49533526Sxy150489 	    (intr_types & DDI_INTR_TYPE_FIXED)) {
49543526Sxy150489 		rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_FIXED);
49553526Sxy150489 
49563526Sxy150489 		if (rc != DDI_SUCCESS) {
49574919Sxy150489 			E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
49583526Sxy150489 			    "Add Legacy interrupts failed\n");
49593526Sxy150489 			return (DDI_FAILURE);
49603526Sxy150489 		}
49613526Sxy150489 
49623526Sxy150489 		Adapter->intr_type = DDI_INTR_TYPE_FIXED;
49633526Sxy150489 	}
49643526Sxy150489 
49653526Sxy150489 	if (Adapter->intr_type == 0) {
49664919Sxy150489 		E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
49673526Sxy150489 		    "No interrupts registered\n");
49683526Sxy150489 		return (DDI_FAILURE);
49693526Sxy150489 	}
49703526Sxy150489 
49713526Sxy150489 	return (DDI_SUCCESS);
49723526Sxy150489 }
49733526Sxy150489 
49743526Sxy150489 /*
49753526Sxy150489  * e1000g_intr_add() handles MSI/Legacy interrupts
49763526Sxy150489  */
49773526Sxy150489 static int
49783526Sxy150489 e1000g_intr_add(struct e1000g *Adapter, int intr_type)
49793526Sxy150489 {
49803526Sxy150489 	dev_info_t *devinfo;
49813526Sxy150489 	int count, avail, actual;
49823526Sxy150489 	int x, y, rc, inum = 0;
49833526Sxy150489 	int flag;
49843526Sxy150489 	ddi_intr_handler_t *intr_handler;
49853526Sxy150489 
49863526Sxy150489 	devinfo = Adapter->dip;
49873526Sxy150489 
49883526Sxy150489 	/* get number of interrupts */
49893526Sxy150489 	rc = ddi_intr_get_nintrs(devinfo, intr_type, &count);
49903526Sxy150489 	if ((rc != DDI_SUCCESS) || (count == 0)) {
49914919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
49923526Sxy150489 		    "Get interrupt number failed. Return: %d, count: %d\n",
49933526Sxy150489 		    rc, count);
49943526Sxy150489 		return (DDI_FAILURE);
49953526Sxy150489 	}
49963526Sxy150489 
49973526Sxy150489 	/* get number of available interrupts */
49983526Sxy150489 	rc = ddi_intr_get_navail(devinfo, intr_type, &avail);
49993526Sxy150489 	if ((rc != DDI_SUCCESS) || (avail == 0)) {
50004919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
50013526Sxy150489 		    "Get interrupt available number failed. "
50023526Sxy150489 		    "Return: %d, available: %d\n", rc, avail);
50033526Sxy150489 		return (DDI_FAILURE);
50043526Sxy150489 	}
50053526Sxy150489 
50063526Sxy150489 	if (avail < count) {
50074919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
50083526Sxy150489 		    "Interrupts count: %d, available: %d\n",
50093526Sxy150489 		    count, avail);
50103526Sxy150489 	}
50113526Sxy150489 
50123526Sxy150489 	/* Allocate an array of interrupt handles */
50133526Sxy150489 	Adapter->intr_size = count * sizeof (ddi_intr_handle_t);
50143526Sxy150489 	Adapter->htable = kmem_alloc(Adapter->intr_size, KM_SLEEP);
50153526Sxy150489 
50163526Sxy150489 	/* Set NORMAL behavior for both MSI and FIXED interrupt */
50173526Sxy150489 	flag = DDI_INTR_ALLOC_NORMAL;
50183526Sxy150489 
50193526Sxy150489 	/* call ddi_intr_alloc() */
50203526Sxy150489 	rc = ddi_intr_alloc(devinfo, Adapter->htable, intr_type, inum,
50213526Sxy150489 	    count, &actual, flag);
50223526Sxy150489 
50233526Sxy150489 	if ((rc != DDI_SUCCESS) || (actual == 0)) {
50244919Sxy150489 		E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
50253526Sxy150489 		    "Allocate interrupts failed: %d\n", rc);
50263526Sxy150489 
50273526Sxy150489 		kmem_free(Adapter->htable, Adapter->intr_size);
50283526Sxy150489 		return (DDI_FAILURE);
50293526Sxy150489 	}
50303526Sxy150489 
50313526Sxy150489 	if (actual < count) {
50324919Sxy150489 		E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
50333526Sxy150489 		    "Interrupts requested: %d, received: %d\n",
50343526Sxy150489 		    count, actual);
50353526Sxy150489 	}
50363526Sxy150489 
50373526Sxy150489 	Adapter->intr_cnt = actual;
50383526Sxy150489 
50393526Sxy150489 	/* Get priority for first msi, assume remaining are all the same */
50403526Sxy150489 	rc = ddi_intr_get_pri(Adapter->htable[0], &Adapter->intr_pri);
50413526Sxy150489 
50423526Sxy150489 	if (rc != DDI_SUCCESS) {
50434919Sxy150489 		E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
50443526Sxy150489 		    "Get interrupt priority failed: %d\n", rc);
50453526Sxy150489 
50463526Sxy150489 		/* Free already allocated intr */
50473526Sxy150489 		for (y = 0; y < actual; y++)
50483526Sxy150489 			(void) ddi_intr_free(Adapter->htable[y]);
50493526Sxy150489 
50503526Sxy150489 		kmem_free(Adapter->htable, Adapter->intr_size);
50513526Sxy150489 		return (DDI_FAILURE);
50523526Sxy150489 	}
50533526Sxy150489 
50543526Sxy150489 	/*
50553526Sxy150489 	 * In Legacy Interrupt mode, for PCI-Express adapters, we should
50563526Sxy150489 	 * use the interrupt service routine e1000g_intr_pciexpress()
50573526Sxy150489 	 * to avoid interrupt stealing when sharing interrupt with other
50583526Sxy150489 	 * devices.
50593526Sxy150489 	 */
50604919Sxy150489 	if (Adapter->shared.mac.type < e1000_82571)
50613526Sxy150489 		intr_handler = (ddi_intr_handler_t *)e1000g_intr;
50623526Sxy150489 	else
50633526Sxy150489 		intr_handler = (ddi_intr_handler_t *)e1000g_intr_pciexpress;
50643526Sxy150489 
50653526Sxy150489 	/* Call ddi_intr_add_handler() */
50663526Sxy150489 	for (x = 0; x < actual; x++) {
50673526Sxy150489 		rc = ddi_intr_add_handler(Adapter->htable[x],
50683526Sxy150489 		    intr_handler, (caddr_t)Adapter, NULL);
50693526Sxy150489 
50703526Sxy150489 		if (rc != DDI_SUCCESS) {
50714919Sxy150489 			E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
50723526Sxy150489 			    "Add interrupt handler failed: %d\n", rc);
50733526Sxy150489 
50743526Sxy150489 			/* Remove already added handler */
50753526Sxy150489 			for (y = 0; y < x; y++)
50763526Sxy150489 				(void) ddi_intr_remove_handler(
50773526Sxy150489 				    Adapter->htable[y]);
50783526Sxy150489 
50793526Sxy150489 			/* Free already allocated intr */
50803526Sxy150489 			for (y = 0; y < actual; y++)
50813526Sxy150489 				(void) ddi_intr_free(Adapter->htable[y]);
50823526Sxy150489 
50833526Sxy150489 			kmem_free(Adapter->htable, Adapter->intr_size);
50843526Sxy150489 			return (DDI_FAILURE);
50853526Sxy150489 		}
50863526Sxy150489 	}
50873526Sxy150489 
50883526Sxy150489 	rc = ddi_intr_get_cap(Adapter->htable[0], &Adapter->intr_cap);
50893526Sxy150489 
50903526Sxy150489 	if (rc != DDI_SUCCESS) {
50914919Sxy150489 		E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
50923526Sxy150489 		    "Get interrupt cap failed: %d\n", rc);
50933526Sxy150489 
50943526Sxy150489 		/* Free already allocated intr */
50953526Sxy150489 		for (y = 0; y < actual; y++) {
50963526Sxy150489 			(void) ddi_intr_remove_handler(Adapter->htable[y]);
50973526Sxy150489 			(void) ddi_intr_free(Adapter->htable[y]);
50983526Sxy150489 		}
50993526Sxy150489 
51003526Sxy150489 		kmem_free(Adapter->htable, Adapter->intr_size);
51013526Sxy150489 		return (DDI_FAILURE);
51023526Sxy150489 	}
51033526Sxy150489 
51043526Sxy150489 	return (DDI_SUCCESS);
51053526Sxy150489 }
51063526Sxy150489 
51073526Sxy150489 static int
51083526Sxy150489 e1000g_rem_intrs(struct e1000g *Adapter)
51093526Sxy150489 {
51103526Sxy150489 	int x;
51113526Sxy150489 	int rc;
51123526Sxy150489 
51133526Sxy150489 	for (x = 0; x < Adapter->intr_cnt; x++) {
51143526Sxy150489 		rc = ddi_intr_remove_handler(Adapter->htable[x]);
51153526Sxy150489 		if (rc != DDI_SUCCESS) {
51164919Sxy150489 			E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51173526Sxy150489 			    "Remove intr handler failed: %d\n", rc);
51183526Sxy150489 			return (DDI_FAILURE);
51193526Sxy150489 		}
51203526Sxy150489 
51213526Sxy150489 		rc = ddi_intr_free(Adapter->htable[x]);
51223526Sxy150489 		if (rc != DDI_SUCCESS) {
51234919Sxy150489 			E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51243526Sxy150489 			    "Free intr failed: %d\n", rc);
51253526Sxy150489 			return (DDI_FAILURE);
51263526Sxy150489 		}
51273526Sxy150489 	}
51283526Sxy150489 
51293526Sxy150489 	kmem_free(Adapter->htable, Adapter->intr_size);
51303526Sxy150489 
51313526Sxy150489 	return (DDI_SUCCESS);
51323526Sxy150489 }
51333526Sxy150489 
51343526Sxy150489 static int
51353526Sxy150489 e1000g_enable_intrs(struct e1000g *Adapter)
51363526Sxy150489 {
51373526Sxy150489 	int x;
51383526Sxy150489 	int rc;
51393526Sxy150489 
51403526Sxy150489 	/* Enable interrupts */
51413526Sxy150489 	if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) {
51423526Sxy150489 		/* Call ddi_intr_block_enable() for MSI */
51433526Sxy150489 		rc = ddi_intr_block_enable(Adapter->htable,
51443526Sxy150489 		    Adapter->intr_cnt);
51453526Sxy150489 		if (rc != DDI_SUCCESS) {
51464919Sxy150489 			E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51473526Sxy150489 			    "Enable block intr failed: %d\n", rc);
51483526Sxy150489 			return (DDI_FAILURE);
51493526Sxy150489 		}
51503526Sxy150489 	} else {
51513526Sxy150489 		/* Call ddi_intr_enable() for Legacy/MSI non block enable */
51523526Sxy150489 		for (x = 0; x < Adapter->intr_cnt; x++) {
51533526Sxy150489 			rc = ddi_intr_enable(Adapter->htable[x]);
51543526Sxy150489 			if (rc != DDI_SUCCESS) {
51554919Sxy150489 				E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51563526Sxy150489 				    "Enable intr failed: %d\n", rc);
51573526Sxy150489 				return (DDI_FAILURE);
51583526Sxy150489 			}
51593526Sxy150489 		}
51603526Sxy150489 	}
51613526Sxy150489 
51623526Sxy150489 	return (DDI_SUCCESS);
51633526Sxy150489 }
51643526Sxy150489 
51653526Sxy150489 static int
51663526Sxy150489 e1000g_disable_intrs(struct e1000g *Adapter)
51673526Sxy150489 {
51683526Sxy150489 	int x;
51693526Sxy150489 	int rc;
51703526Sxy150489 
51713526Sxy150489 	/* Disable all interrupts */
51723526Sxy150489 	if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) {
51733526Sxy150489 		rc = ddi_intr_block_disable(Adapter->htable,
51743526Sxy150489 		    Adapter->intr_cnt);
51753526Sxy150489 		if (rc != DDI_SUCCESS) {
51764919Sxy150489 			E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51773526Sxy150489 			    "Disable block intr failed: %d\n", rc);
51783526Sxy150489 			return (DDI_FAILURE);
51793526Sxy150489 		}
51803526Sxy150489 	} else {
51813526Sxy150489 		for (x = 0; x < Adapter->intr_cnt; x++) {
51823526Sxy150489 			rc = ddi_intr_disable(Adapter->htable[x]);
51833526Sxy150489 			if (rc != DDI_SUCCESS) {
51844919Sxy150489 				E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
51853526Sxy150489 				    "Disable intr failed: %d\n", rc);
51863526Sxy150489 				return (DDI_FAILURE);
51873526Sxy150489 			}
51883526Sxy150489 		}
51893526Sxy150489 	}
51903526Sxy150489 
51913526Sxy150489 	return (DDI_SUCCESS);
51923526Sxy150489 }
51935082Syy150190 
51945082Syy150190 /*
51955082Syy150190  * e1000g_get_phy_state - get the state of PHY registers, save in the adapter
51965082Syy150190  */
51975082Syy150190 static void
51985082Syy150190 e1000g_get_phy_state(struct e1000g *Adapter)
51995082Syy150190 {
52005082Syy150190 	struct e1000_hw *hw = &Adapter->shared;
52015082Syy150190 
52025082Syy150190 	e1000_read_phy_reg(hw, PHY_CONTROL, &Adapter->phy_ctrl);
52035082Syy150190 	e1000_read_phy_reg(hw, PHY_STATUS, &Adapter->phy_status);
52045082Syy150190 	e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &Adapter->phy_an_adv);
52055082Syy150190 	e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &Adapter->phy_an_exp);
52065082Syy150190 	e1000_read_phy_reg(hw, PHY_EXT_STATUS, &Adapter->phy_ext_status);
52075082Syy150190 	e1000_read_phy_reg(hw, PHY_1000T_CTRL, &Adapter->phy_1000t_ctrl);
52085082Syy150190 	e1000_read_phy_reg(hw, PHY_1000T_STATUS, &Adapter->phy_1000t_status);
52095082Syy150190 	e1000_read_phy_reg(hw, PHY_LP_ABILITY, &Adapter->phy_lp_able);
52106394Scc210113 
52116394Scc210113 	Adapter->param_autoneg_cap =
52126394Scc210113 	    (Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0;
52136394Scc210113 	Adapter->param_pause_cap =
52146394Scc210113 	    (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0;
52156394Scc210113 	Adapter->param_asym_pause_cap =
52166394Scc210113 	    (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0;
52176394Scc210113 	Adapter->param_1000fdx_cap =
52186394Scc210113 	    ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
52196394Scc210113 	    (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0;
52206394Scc210113 	Adapter->param_1000hdx_cap =
52216394Scc210113 	    ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) ||
52226394Scc210113 	    (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0;
52236394Scc210113 	Adapter->param_100t4_cap =
52246394Scc210113 	    (Adapter->phy_status & MII_SR_100T4_CAPS) ? 1 : 0;
52256394Scc210113 	Adapter->param_100fdx_cap =
52266394Scc210113 	    ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
52276394Scc210113 	    (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0;
52286394Scc210113 	Adapter->param_100hdx_cap =
52296394Scc210113 	    ((Adapter->phy_status & MII_SR_100X_HD_CAPS) ||
52306394Scc210113 	    (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0;
52316394Scc210113 	Adapter->param_10fdx_cap =
52326394Scc210113 	    (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0;
52336394Scc210113 	Adapter->param_10hdx_cap =
52346394Scc210113 	    (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0;
52356394Scc210113 
52366394Scc210113 	Adapter->param_adv_autoneg = hw->mac.autoneg;
52376394Scc210113 	Adapter->param_adv_pause =
52386394Scc210113 	    (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0;
52396394Scc210113 	Adapter->param_adv_asym_pause =
52406394Scc210113 	    (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0;
52416394Scc210113 	Adapter->param_adv_1000hdx =
52426394Scc210113 	    (Adapter->phy_1000t_ctrl & CR_1000T_HD_CAPS) ? 1 : 0;
52436394Scc210113 	Adapter->param_adv_100t4 =
52446394Scc210113 	    (Adapter->phy_an_adv & NWAY_AR_100T4_CAPS) ? 1 : 0;
52456394Scc210113 	if (Adapter->param_adv_autoneg == 1) {
52466394Scc210113 		Adapter->param_adv_1000fdx =
52476394Scc210113 		    (Adapter->phy_1000t_ctrl & CR_1000T_FD_CAPS) ? 1 : 0;
52486394Scc210113 		Adapter->param_adv_100fdx =
52496394Scc210113 		    (Adapter->phy_an_adv & NWAY_AR_100TX_FD_CAPS) ? 1 : 0;
52506394Scc210113 		Adapter->param_adv_100hdx =
52516394Scc210113 		    (Adapter->phy_an_adv & NWAY_AR_100TX_HD_CAPS) ? 1 : 0;
52526394Scc210113 		Adapter->param_adv_10fdx =
52536394Scc210113 		    (Adapter->phy_an_adv & NWAY_AR_10T_FD_CAPS) ? 1 : 0;
52546394Scc210113 		Adapter->param_adv_10hdx =
52556394Scc210113 		    (Adapter->phy_an_adv & NWAY_AR_10T_HD_CAPS) ? 1 : 0;
52566394Scc210113 	}
52576394Scc210113 
52586394Scc210113 	Adapter->param_lp_autoneg =
52596394Scc210113 	    (Adapter->phy_an_exp & NWAY_ER_LP_NWAY_CAPS) ? 1 : 0;
52606394Scc210113 	Adapter->param_lp_pause =
52616394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_PAUSE) ? 1 : 0;
52626394Scc210113 	Adapter->param_lp_asym_pause =
52636394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_ASM_DIR) ? 1 : 0;
52646394Scc210113 	Adapter->param_lp_1000fdx =
52656394Scc210113 	    (Adapter->phy_1000t_status & SR_1000T_LP_FD_CAPS) ? 1 : 0;
52666394Scc210113 	Adapter->param_lp_1000hdx =
52676394Scc210113 	    (Adapter->phy_1000t_status & SR_1000T_LP_HD_CAPS) ? 1 : 0;
52686394Scc210113 	Adapter->param_lp_100t4 =
52696394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_100T4_CAPS) ? 1 : 0;
52706394Scc210113 	Adapter->param_lp_100fdx =
52716394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_100TX_FD_CAPS) ? 1 : 0;
52726394Scc210113 	Adapter->param_lp_100hdx =
52736394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_100TX_HD_CAPS) ? 1 : 0;
52746394Scc210113 	Adapter->param_lp_10fdx =
52756394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_10T_FD_CAPS) ? 1 : 0;
52766394Scc210113 	Adapter->param_lp_10hdx =
52776394Scc210113 	    (Adapter->phy_lp_able & NWAY_LPAR_10T_HD_CAPS) ? 1 : 0;
52785082Syy150190 }
52795273Sgl147354 
52805273Sgl147354 /*
52815273Sgl147354  * FMA support
52825273Sgl147354  */
52835273Sgl147354 
52845273Sgl147354 int
52855273Sgl147354 e1000g_check_acc_handle(ddi_acc_handle_t handle)
52865273Sgl147354 {
52875273Sgl147354 	ddi_fm_error_t de;
52885273Sgl147354 
52895273Sgl147354 	ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION);
52905273Sgl147354 	ddi_fm_acc_err_clear(handle, DDI_FME_VERSION);
52915273Sgl147354 	return (de.fme_status);
52925273Sgl147354 }
52935273Sgl147354 
52945273Sgl147354 int
52955273Sgl147354 e1000g_check_dma_handle(ddi_dma_handle_t handle)
52965273Sgl147354 {
52975273Sgl147354 	ddi_fm_error_t de;
52985273Sgl147354 
52995273Sgl147354 	ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION);
53005273Sgl147354 	return (de.fme_status);
53015273Sgl147354 }
53025273Sgl147354 
53035273Sgl147354 /*
53045273Sgl147354  * The IO fault service error handling callback function
53055273Sgl147354  */
53065273Sgl147354 static int
53075273Sgl147354 e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data)
53085273Sgl147354 {
53095273Sgl147354 	/*
53105273Sgl147354 	 * as the driver can always deal with an error in any dma or
53115273Sgl147354 	 * access handle, we can just return the fme_status value.
53125273Sgl147354 	 */
53135273Sgl147354 	pci_ereport_post(dip, err, NULL);
53145273Sgl147354 	return (err->fme_status);
53155273Sgl147354 }
53165273Sgl147354 
53175273Sgl147354 static void
53185273Sgl147354 e1000g_fm_init(struct e1000g *Adapter)
53195273Sgl147354 {
53205273Sgl147354 	ddi_iblock_cookie_t iblk;
53215273Sgl147354 	int fma_acc_flag, fma_dma_flag;
53225273Sgl147354 
53235273Sgl147354 	/* Only register with IO Fault Services if we have some capability */
53245273Sgl147354 	if (Adapter->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) {
53255273Sgl147354 		e1000g_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC;
53265273Sgl147354 		fma_acc_flag = 1;
53275273Sgl147354 	} else {
53285273Sgl147354 		e1000g_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC;
53295273Sgl147354 		fma_acc_flag = 0;
53305273Sgl147354 	}
53315273Sgl147354 
53325273Sgl147354 	if (Adapter->fm_capabilities & DDI_FM_DMACHK_CAPABLE) {
53335273Sgl147354 		fma_dma_flag = 1;
53345273Sgl147354 	} else {
53355273Sgl147354 		fma_dma_flag = 0;
53365273Sgl147354 	}
53375273Sgl147354 
53385273Sgl147354 	(void) e1000g_set_fma_flags(Adapter, fma_acc_flag, fma_dma_flag);
53395273Sgl147354 
53405273Sgl147354 	if (Adapter->fm_capabilities) {
53415273Sgl147354 
53425273Sgl147354 		/* Register capabilities with IO Fault Services */
53435273Sgl147354 		ddi_fm_init(Adapter->dip, &Adapter->fm_capabilities, &iblk);
53445273Sgl147354 
53455273Sgl147354 		/*
53465273Sgl147354 		 * Initialize pci ereport capabilities if ereport capable
53475273Sgl147354 		 */
53485273Sgl147354 		if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) ||
53495273Sgl147354 		    DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
53505273Sgl147354 			pci_ereport_setup(Adapter->dip);
53515273Sgl147354 
53525273Sgl147354 		/*
53535273Sgl147354 		 * Register error callback if error callback capable
53545273Sgl147354 		 */
53555273Sgl147354 		if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
53565273Sgl147354 			ddi_fm_handler_register(Adapter->dip,
53575273Sgl147354 			    e1000g_fm_error_cb, (void*) Adapter);
53585273Sgl147354 	}
53595273Sgl147354 }
53605273Sgl147354 
53615273Sgl147354 static void
53625273Sgl147354 e1000g_fm_fini(struct e1000g *Adapter)
53635273Sgl147354 {
53645273Sgl147354 	/* Only unregister FMA capabilities if we registered some */
53655273Sgl147354 	if (Adapter->fm_capabilities) {
53665273Sgl147354 
53675273Sgl147354 		/*
53685273Sgl147354 		 * Release any resources allocated by pci_ereport_setup()
53695273Sgl147354 		 */
53705273Sgl147354 		if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) ||
53715273Sgl147354 		    DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
53725273Sgl147354 			pci_ereport_teardown(Adapter->dip);
53735273Sgl147354 
53745273Sgl147354 		/*
53755273Sgl147354 		 * Un-register error callback if error callback capable
53765273Sgl147354 		 */
53775273Sgl147354 		if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
53785273Sgl147354 			ddi_fm_handler_unregister(Adapter->dip);
53795273Sgl147354 
53805273Sgl147354 		/* Unregister from IO Fault Services */
53815273Sgl147354 		ddi_fm_fini(Adapter->dip);
53825273Sgl147354 	}
53835273Sgl147354 }
53845273Sgl147354 
53855273Sgl147354 void
53865273Sgl147354 e1000g_fm_ereport(struct e1000g *Adapter, char *detail)
53875273Sgl147354 {
53885273Sgl147354 	uint64_t ena;
53895273Sgl147354 	char buf[FM_MAX_CLASS];
53905273Sgl147354 
53915273Sgl147354 	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
53925273Sgl147354 	ena = fm_ena_generate(0, FM_ENA_FMT1);
53935273Sgl147354 	if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities)) {
53945273Sgl147354 		ddi_fm_ereport_post(Adapter->dip, buf, ena, DDI_NOSLEEP,
53955273Sgl147354 		    FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
53965273Sgl147354 	}
53975273Sgl147354 }
53986512Ssowmini 
53996512Ssowmini static int
54006512Ssowmini e1000g_get_def_val(struct e1000g *Adapter, mac_prop_id_t pr_num,
54016512Ssowmini     uint_t pr_valsize, void *pr_val)
54026512Ssowmini {
54036512Ssowmini 	link_flowctrl_t fl;
54046512Ssowmini 	uint32_t fc;
54056512Ssowmini 	int err = 0;
54066512Ssowmini 
54076512Ssowmini 	ASSERT(pr_valsize > 0);
54086512Ssowmini 	switch (pr_num) {
54096789Sam223141 	case MAC_PROP_AUTONEG:
54106512Ssowmini 		*(uint8_t *)pr_val =
54116512Ssowmini 		    ((Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0);
54126512Ssowmini 		break;
54136789Sam223141 	case MAC_PROP_FLOWCTRL:
54146512Ssowmini 		if (pr_valsize < sizeof (link_flowctrl_t))
54156512Ssowmini 			return (EINVAL);
54166512Ssowmini 		fl = LINK_FLOWCTRL_BI;
54176512Ssowmini 		bcopy(&fl, pr_val, sizeof (fl));
54186512Ssowmini 		break;
54196789Sam223141 	case MAC_PROP_ADV_1000FDX_CAP:
54206789Sam223141 	case MAC_PROP_EN_1000FDX_CAP:
54216512Ssowmini 		*(uint8_t *)pr_val =
54226512Ssowmini 		    ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
54236512Ssowmini 		    (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0;
54246512Ssowmini 		break;
54256789Sam223141 	case MAC_PROP_ADV_1000HDX_CAP:
54266789Sam223141 	case MAC_PROP_EN_1000HDX_CAP:
54276512Ssowmini 		*(uint8_t *)pr_val =
54286512Ssowmini 		    ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) ||
54296512Ssowmini 		    (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0;
54306512Ssowmini 		break;
54316789Sam223141 	case MAC_PROP_ADV_100FDX_CAP:
54326789Sam223141 	case MAC_PROP_EN_100FDX_CAP:
54336512Ssowmini 		*(uint8_t *)pr_val =
54346512Ssowmini 		    ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
54356512Ssowmini 		    (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0;
54366789Sam223141 	case MAC_PROP_ADV_100HDX_CAP:
54376789Sam223141 	case MAC_PROP_EN_100HDX_CAP:
54386512Ssowmini 		*(uint8_t *)pr_val =
54396512Ssowmini 		    ((Adapter->phy_status & MII_SR_100X_HD_CAPS) ||
54406512Ssowmini 		    (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0;
54416512Ssowmini 		break;
54426789Sam223141 	case MAC_PROP_ADV_10FDX_CAP:
54436789Sam223141 	case MAC_PROP_EN_10FDX_CAP:
54446512Ssowmini 		*(uint8_t *)pr_val =
54456512Ssowmini 		    (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0;
54466512Ssowmini 		break;
54476789Sam223141 	case MAC_PROP_ADV_10HDX_CAP:
54486789Sam223141 	case MAC_PROP_EN_10HDX_CAP:
54496512Ssowmini 		*(uint8_t *)pr_val =
54506512Ssowmini 		    (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0;
54516512Ssowmini 		break;
54526512Ssowmini 	default:
54536512Ssowmini 		err = ENOTSUP;
54546512Ssowmini 		break;
54556512Ssowmini 	}
54566512Ssowmini 	return (err);
54576512Ssowmini }
54586512Ssowmini 
54596512Ssowmini /*
54606512Ssowmini  * synchronize the adv* and en* parameters.
54616512Ssowmini  *
54626512Ssowmini  * See comments in <sys/dld.h> for details of the *_en_*
54636512Ssowmini  * parameters. The usage of ndd for setting adv parameters will
54646512Ssowmini  * synchronize all the en parameters with the e1000g parameters,
54656512Ssowmini  * implicity disalbing any settings made via dladm.
54666512Ssowmini  */
54676512Ssowmini static void
54686512Ssowmini e1000g_param_sync(struct e1000g *Adapter)
54696512Ssowmini {
54706512Ssowmini 	Adapter->param_en_1000fdx = Adapter->param_adv_1000fdx;
54716512Ssowmini 	Adapter->param_en_1000hdx = Adapter->param_adv_1000hdx;
54726512Ssowmini 	Adapter->param_en_100fdx = Adapter->param_adv_100fdx;
54736512Ssowmini 	Adapter->param_en_100hdx = Adapter->param_adv_100hdx;
54746512Ssowmini 	Adapter->param_en_10fdx = Adapter->param_adv_10fdx;
54756512Ssowmini 	Adapter->param_en_10hdx = Adapter->param_adv_10hdx;
54766512Ssowmini }
5477