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 * 98479SChenlu.Chen@Sun.COM * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved. 103526Sxy150489 * 113526Sxy150489 * The contents of this file are subject to the terms of Version 123526Sxy150489 * 1.0 of the Common Development and Distribution License (the "License"). 133526Sxy150489 * 143526Sxy150489 * You should have received a copy of the License with this software. 153526Sxy150489 * You can obtain a copy of the License at 163526Sxy150489 * http://www.opensolaris.org/os/licensing. 173526Sxy150489 * See the License for the specific language governing permissions 183526Sxy150489 * and limitations under the License. 193526Sxy150489 */ 203526Sxy150489 213526Sxy150489 /* 228479SChenlu.Chen@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 238118SVasumathi.Sundaram@Sun.COM * Use is subject to license terms. 243526Sxy150489 */ 253526Sxy150489 263526Sxy150489 /* 273526Sxy150489 * ********************************************************************** 283526Sxy150489 * * 293526Sxy150489 * Module Name: * 303526Sxy150489 * e1000g_main.c * 313526Sxy150489 * * 323526Sxy150489 * Abstract: * 334919Sxy150489 * This file contains the interface routines for the solaris OS. * 344919Sxy150489 * It has all DDI entry point routines and GLD entry point routines. * 353526Sxy150489 * * 364919Sxy150489 * This file also contains routines that take care of initialization * 374919Sxy150489 * uninit routine and interrupt routine. * 383526Sxy150489 * * 393526Sxy150489 * ********************************************************************** 403526Sxy150489 */ 413526Sxy150489 423526Sxy150489 #include <sys/dlpi.h> 433526Sxy150489 #include <sys/mac.h> 443526Sxy150489 #include "e1000g_sw.h" 453526Sxy150489 #include "e1000g_debug.h" 463526Sxy150489 477656SSherry.Moore@Sun.COM static char ident[] = "Intel PRO/1000 Ethernet"; 483526Sxy150489 static char e1000g_string[] = "Intel(R) PRO/1000 Network Connection"; 49*10434SGuoqing.Zhu@Sun.COM static char e1000g_version[] = "Driver Ver. 5.3.12"; 503526Sxy150489 513526Sxy150489 /* 523526Sxy150489 * Proto types for DDI entry points 533526Sxy150489 */ 544919Sxy150489 static int e1000g_attach(dev_info_t *, ddi_attach_cmd_t); 554919Sxy150489 static int e1000g_detach(dev_info_t *, ddi_detach_cmd_t); 567656SSherry.Moore@Sun.COM static int e1000g_quiesce(dev_info_t *); 573526Sxy150489 583526Sxy150489 /* 593526Sxy150489 * init and intr routines prototype 603526Sxy150489 */ 614919Sxy150489 static int e1000g_resume(dev_info_t *); 624919Sxy150489 static int e1000g_suspend(dev_info_t *); 633526Sxy150489 static uint_t e1000g_intr_pciexpress(caddr_t); 643526Sxy150489 static uint_t e1000g_intr(caddr_t); 653526Sxy150489 static void e1000g_intr_work(struct e1000g *, uint32_t); 663526Sxy150489 #pragma inline(e1000g_intr_work) 673526Sxy150489 static int e1000g_init(struct e1000g *); 684919Sxy150489 static int e1000g_start(struct e1000g *, boolean_t); 694919Sxy150489 static void e1000g_stop(struct e1000g *, boolean_t); 703526Sxy150489 static int e1000g_m_start(void *); 713526Sxy150489 static void e1000g_m_stop(void *); 723526Sxy150489 static int e1000g_m_promisc(void *, boolean_t); 733526Sxy150489 static boolean_t e1000g_m_getcapab(void *, mac_capab_t, void *); 743526Sxy150489 static int e1000g_m_multicst(void *, boolean_t, const uint8_t *); 753526Sxy150489 static void e1000g_m_ioctl(void *, queue_t *, mblk_t *); 766394Scc210113 static int e1000g_m_setprop(void *, const char *, mac_prop_id_t, 776394Scc210113 uint_t, const void *); 786394Scc210113 static int e1000g_m_getprop(void *, const char *, mac_prop_id_t, 798118SVasumathi.Sundaram@Sun.COM uint_t, uint_t, void *, uint_t *); 806394Scc210113 static int e1000g_set_priv_prop(struct e1000g *, const char *, uint_t, 816394Scc210113 const void *); 826394Scc210113 static int e1000g_get_priv_prop(struct e1000g *, const char *, uint_t, 838118SVasumathi.Sundaram@Sun.COM uint_t, void *, uint_t *); 844919Sxy150489 static void e1000g_init_locks(struct e1000g *); 854919Sxy150489 static void e1000g_destroy_locks(struct e1000g *); 864919Sxy150489 static int e1000g_identify_hardware(struct e1000g *); 874919Sxy150489 static int e1000g_regs_map(struct e1000g *); 884919Sxy150489 static int e1000g_set_driver_params(struct e1000g *); 896394Scc210113 static void e1000g_set_bufsize(struct e1000g *); 904919Sxy150489 static int e1000g_register_mac(struct e1000g *); 914919Sxy150489 static boolean_t e1000g_rx_drain(struct e1000g *); 924919Sxy150489 static boolean_t e1000g_tx_drain(struct e1000g *); 934919Sxy150489 static void e1000g_init_unicst(struct e1000g *); 948275SEric Cheng static int e1000g_unicst_set(struct e1000g *, const uint8_t *, int); 958850SMin.Xu@Sun.COM static int e1000g_alloc_rx_data(struct e1000g *); 969770SChangqing.Li@Sun.COM static void e1000g_release_multicast(struct e1000g *); 973526Sxy150489 983526Sxy150489 /* 993526Sxy150489 * Local routines 1003526Sxy150489 */ 1017656SSherry.Moore@Sun.COM static boolean_t e1000g_reset_adapter(struct e1000g *); 1024919Sxy150489 static void e1000g_tx_clean(struct e1000g *); 1034919Sxy150489 static void e1000g_rx_clean(struct e1000g *); 1044061Sxy150489 static void e1000g_link_timer(void *); 1054919Sxy150489 static void e1000g_local_timer(void *); 1064061Sxy150489 static boolean_t e1000g_link_check(struct e1000g *); 1073526Sxy150489 static boolean_t e1000g_stall_check(struct e1000g *); 1083526Sxy150489 static void e1000g_smartspeed(struct e1000g *); 1094919Sxy150489 static void e1000g_get_conf(struct e1000g *); 1104919Sxy150489 static int e1000g_get_prop(struct e1000g *, char *, int, int, int); 1114919Sxy150489 static void enable_watchdog_timer(struct e1000g *); 1124919Sxy150489 static void disable_watchdog_timer(struct e1000g *); 1134919Sxy150489 static void start_watchdog_timer(struct e1000g *); 1144919Sxy150489 static void restart_watchdog_timer(struct e1000g *); 1154919Sxy150489 static void stop_watchdog_timer(struct e1000g *); 1164919Sxy150489 static void stop_link_timer(struct e1000g *); 1174919Sxy150489 static void stop_82547_timer(e1000g_tx_ring_t *); 1184919Sxy150489 static void e1000g_force_speed_duplex(struct e1000g *); 1194919Sxy150489 static void e1000g_get_max_frame_size(struct e1000g *); 1204919Sxy150489 static boolean_t is_valid_mac_addr(uint8_t *); 1213526Sxy150489 static void e1000g_unattach(dev_info_t *, struct e1000g *); 1224919Sxy150489 #ifdef E1000G_DEBUG 1234919Sxy150489 static void e1000g_ioc_peek_reg(struct e1000g *, e1000g_peekpoke_t *); 1244919Sxy150489 static void e1000g_ioc_poke_reg(struct e1000g *, e1000g_peekpoke_t *); 1254919Sxy150489 static void e1000g_ioc_peek_mem(struct e1000g *, e1000g_peekpoke_t *); 1264919Sxy150489 static void e1000g_ioc_poke_mem(struct e1000g *, e1000g_peekpoke_t *); 1274919Sxy150489 static enum ioc_reply e1000g_pp_ioctl(struct e1000g *, 1284919Sxy150489 struct iocblk *, mblk_t *); 1294919Sxy150489 #endif 1304919Sxy150489 static enum ioc_reply e1000g_loopback_ioctl(struct e1000g *, 1314919Sxy150489 struct iocblk *, mblk_t *); 1327133Scc210113 static boolean_t e1000g_check_loopback_support(struct e1000_hw *); 1334919Sxy150489 static boolean_t e1000g_set_loopback_mode(struct e1000g *, uint32_t); 1344919Sxy150489 static void e1000g_set_internal_loopback(struct e1000g *); 1354919Sxy150489 static void e1000g_set_external_loopback_1000(struct e1000g *); 1364919Sxy150489 static void e1000g_set_external_loopback_100(struct e1000g *); 1374919Sxy150489 static void e1000g_set_external_loopback_10(struct e1000g *); 1384919Sxy150489 static int e1000g_add_intrs(struct e1000g *); 1394919Sxy150489 static int e1000g_intr_add(struct e1000g *, int); 1404919Sxy150489 static int e1000g_rem_intrs(struct e1000g *); 1414919Sxy150489 static int e1000g_enable_intrs(struct e1000g *); 1424919Sxy150489 static int e1000g_disable_intrs(struct e1000g *); 1434919Sxy150489 static boolean_t e1000g_link_up(struct e1000g *); 1443526Sxy150489 #ifdef __sparc 1454919Sxy150489 static boolean_t e1000g_find_mac_address(struct e1000g *); 1463526Sxy150489 #endif 1475082Syy150190 static void e1000g_get_phy_state(struct e1000g *); 1485273Sgl147354 static int e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, 1495273Sgl147354 const void *impl_data); 1505273Sgl147354 static void e1000g_fm_init(struct e1000g *Adapter); 1515273Sgl147354 static void e1000g_fm_fini(struct e1000g *Adapter); 1526512Ssowmini static int e1000g_get_def_val(struct e1000g *, mac_prop_id_t, uint_t, void *); 1536512Ssowmini static void e1000g_param_sync(struct e1000g *); 1547607STed.You@Sun.COM static void e1000g_get_driver_control(struct e1000_hw *); 1557607STed.You@Sun.COM static void e1000g_release_driver_control(struct e1000_hw *); 1567722SShuguo.Yang@Sun.COM static void e1000g_restore_promisc(struct e1000g *Adapter); 1576512Ssowmini 1586512Ssowmini mac_priv_prop_t e1000g_priv_props[] = { 1596512Ssowmini {"_tx_bcopy_threshold", MAC_PROP_PERM_RW}, 1606512Ssowmini {"_tx_interrupt_enable", MAC_PROP_PERM_RW}, 1616512Ssowmini {"_tx_intr_delay", MAC_PROP_PERM_RW}, 1626512Ssowmini {"_tx_intr_abs_delay", MAC_PROP_PERM_RW}, 1636512Ssowmini {"_rx_bcopy_threshold", MAC_PROP_PERM_RW}, 1646512Ssowmini {"_max_num_rcv_packets", MAC_PROP_PERM_RW}, 1656512Ssowmini {"_rx_intr_delay", MAC_PROP_PERM_RW}, 1666512Ssowmini {"_rx_intr_abs_delay", MAC_PROP_PERM_RW}, 1676512Ssowmini {"_intr_throttling_rate", MAC_PROP_PERM_RW}, 1686512Ssowmini {"_intr_adaptive", MAC_PROP_PERM_RW}, 1696512Ssowmini {"_adv_pause_cap", MAC_PROP_PERM_READ}, 1706512Ssowmini {"_adv_asym_pause_cap", MAC_PROP_PERM_READ}, 1716512Ssowmini }; 1726512Ssowmini #define E1000G_MAX_PRIV_PROPS \ 1736512Ssowmini (sizeof (e1000g_priv_props)/sizeof (mac_priv_prop_t)) 1746512Ssowmini 1753526Sxy150489 1763526Sxy150489 static struct cb_ops cb_ws_ops = { 1773526Sxy150489 nulldev, /* cb_open */ 1783526Sxy150489 nulldev, /* cb_close */ 1793526Sxy150489 nodev, /* cb_strategy */ 1803526Sxy150489 nodev, /* cb_print */ 1813526Sxy150489 nodev, /* cb_dump */ 1823526Sxy150489 nodev, /* cb_read */ 1833526Sxy150489 nodev, /* cb_write */ 1843526Sxy150489 nodev, /* cb_ioctl */ 1853526Sxy150489 nodev, /* cb_devmap */ 1863526Sxy150489 nodev, /* cb_mmap */ 1873526Sxy150489 nodev, /* cb_segmap */ 1883526Sxy150489 nochpoll, /* cb_chpoll */ 1893526Sxy150489 ddi_prop_op, /* cb_prop_op */ 1903526Sxy150489 NULL, /* cb_stream */ 1913526Sxy150489 D_MP | D_HOTPLUG, /* cb_flag */ 1923526Sxy150489 CB_REV, /* cb_rev */ 1933526Sxy150489 nodev, /* cb_aread */ 1943526Sxy150489 nodev /* cb_awrite */ 1953526Sxy150489 }; 1963526Sxy150489 1973526Sxy150489 static struct dev_ops ws_ops = { 1983526Sxy150489 DEVO_REV, /* devo_rev */ 1993526Sxy150489 0, /* devo_refcnt */ 2003526Sxy150489 NULL, /* devo_getinfo */ 2013526Sxy150489 nulldev, /* devo_identify */ 2023526Sxy150489 nulldev, /* devo_probe */ 2034919Sxy150489 e1000g_attach, /* devo_attach */ 2044919Sxy150489 e1000g_detach, /* devo_detach */ 2053526Sxy150489 nodev, /* devo_reset */ 2063526Sxy150489 &cb_ws_ops, /* devo_cb_ops */ 2073526Sxy150489 NULL, /* devo_bus_ops */ 2087656SSherry.Moore@Sun.COM ddi_power, /* devo_power */ 2097656SSherry.Moore@Sun.COM e1000g_quiesce /* devo_quiesce */ 2103526Sxy150489 }; 2113526Sxy150489 2123526Sxy150489 static struct modldrv modldrv = { 2133526Sxy150489 &mod_driverops, /* Type of module. This one is a driver */ 2143526Sxy150489 ident, /* Discription string */ 2153526Sxy150489 &ws_ops, /* driver ops */ 2163526Sxy150489 }; 2173526Sxy150489 2183526Sxy150489 static struct modlinkage modlinkage = { 2193526Sxy150489 MODREV_1, &modldrv, NULL 2203526Sxy150489 }; 2213526Sxy150489 2224919Sxy150489 /* Access attributes for register mapping */ 2234919Sxy150489 static ddi_device_acc_attr_t e1000g_regs_acc_attr = { 2243526Sxy150489 DDI_DEVICE_ATTR_V0, 2253526Sxy150489 DDI_STRUCTURE_LE_ACC, 2263526Sxy150489 DDI_STRICTORDER_ACC, 2275273Sgl147354 DDI_FLAGERR_ACC 2283526Sxy150489 }; 2293526Sxy150489 2306394Scc210113 #define E1000G_M_CALLBACK_FLAGS \ 2316394Scc210113 (MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 2323526Sxy150489 2333526Sxy150489 static mac_callbacks_t e1000g_m_callbacks = { 2343526Sxy150489 E1000G_M_CALLBACK_FLAGS, 2353526Sxy150489 e1000g_m_stat, 2363526Sxy150489 e1000g_m_start, 2373526Sxy150489 e1000g_m_stop, 2383526Sxy150489 e1000g_m_promisc, 2393526Sxy150489 e1000g_m_multicst, 2408275SEric Cheng NULL, 2413526Sxy150489 e1000g_m_tx, 2423526Sxy150489 e1000g_m_ioctl, 2436394Scc210113 e1000g_m_getcapab, 2446394Scc210113 NULL, 2456394Scc210113 NULL, 2466394Scc210113 e1000g_m_setprop, 2476394Scc210113 e1000g_m_getprop 2483526Sxy150489 }; 2493526Sxy150489 2503526Sxy150489 /* 2513526Sxy150489 * Global variables 2523526Sxy150489 */ 2533526Sxy150489 uint32_t e1000g_mblks_pending = 0; 2543526Sxy150489 /* 2554894Syy150190 * Workaround for Dynamic Reconfiguration support, for x86 platform only. 2564349Sxy150489 * Here we maintain a private dev_info list if e1000g_force_detach is 2574349Sxy150489 * enabled. If we force the driver to detach while there are still some 2584349Sxy150489 * rx buffers retained in the upper layer, we have to keep a copy of the 2594349Sxy150489 * dev_info. In some cases (Dynamic Reconfiguration), the dev_info data 2604349Sxy150489 * structure will be freed after the driver is detached. However when we 2614349Sxy150489 * finally free those rx buffers released by the upper layer, we need to 2624349Sxy150489 * refer to the dev_info to free the dma buffers. So we save a copy of 2634894Syy150190 * the dev_info for this purpose. On x86 platform, we assume this copy 2644894Syy150190 * of dev_info is always valid, but on SPARC platform, it could be invalid 2654894Syy150190 * after the system board level DR operation. For this reason, the global 2664894Syy150190 * variable e1000g_force_detach must be B_FALSE on SPARC platform. 2674349Sxy150489 */ 2684894Syy150190 #ifdef __sparc 2694894Syy150190 boolean_t e1000g_force_detach = B_FALSE; 2704894Syy150190 #else 2714894Syy150190 boolean_t e1000g_force_detach = B_TRUE; 2724894Syy150190 #endif 2734349Sxy150489 private_devi_list_t *e1000g_private_devi_list = NULL; 2744894Syy150190 2754349Sxy150489 /* 2768850SMin.Xu@Sun.COM * The mutex e1000g_rx_detach_lock is defined to protect the processing of 2778850SMin.Xu@Sun.COM * the private dev_info list, and to serialize the processing of rx buffer 2788850SMin.Xu@Sun.COM * freeing and rx buffer recycling. 2793526Sxy150489 */ 2808850SMin.Xu@Sun.COM kmutex_t e1000g_rx_detach_lock; 2813526Sxy150489 /* 2823526Sxy150489 * The rwlock e1000g_dma_type_lock is defined to protect the global flag 2833526Sxy150489 * e1000g_dma_type. For SPARC, the initial value of the flag is "USE_DVMA". 2843526Sxy150489 * If there are many e1000g instances, the system may run out of DVMA 2853526Sxy150489 * resources during the initialization of the instances, then the flag will 2863526Sxy150489 * be changed to "USE_DMA". Because different e1000g instances are initialized 2873526Sxy150489 * in parallel, we need to use this lock to protect the flag. 2883526Sxy150489 */ 2893526Sxy150489 krwlock_t e1000g_dma_type_lock; 2903526Sxy150489 2917133Scc210113 /* 2927133Scc210113 * The 82546 chipset is a dual-port device, both the ports share one eeprom. 2937133Scc210113 * Based on the information from Intel, the 82546 chipset has some hardware 2947133Scc210113 * problem. When one port is being reset and the other port is trying to 2957133Scc210113 * access the eeprom, it could cause system hang or panic. To workaround this 2967133Scc210113 * hardware problem, we use a global mutex to prevent such operations from 2977133Scc210113 * happening simultaneously on different instances. This workaround is applied 2987133Scc210113 * to all the devices supported by this driver. 2997133Scc210113 */ 3007133Scc210113 kmutex_t e1000g_nvm_lock; 3013526Sxy150489 3023526Sxy150489 /* 3033526Sxy150489 * Loadable module configuration entry points for the driver 3043526Sxy150489 */ 3053526Sxy150489 3063526Sxy150489 /* 3074919Sxy150489 * _init - module initialization 3083526Sxy150489 */ 3093526Sxy150489 int 3103526Sxy150489 _init(void) 3113526Sxy150489 { 3123526Sxy150489 int status; 3133526Sxy150489 3143526Sxy150489 mac_init_ops(&ws_ops, WSNAME); 3153526Sxy150489 status = mod_install(&modlinkage); 3163526Sxy150489 if (status != DDI_SUCCESS) 3173526Sxy150489 mac_fini_ops(&ws_ops); 3183526Sxy150489 else { 3198850SMin.Xu@Sun.COM mutex_init(&e1000g_rx_detach_lock, NULL, MUTEX_DRIVER, NULL); 3203526Sxy150489 rw_init(&e1000g_dma_type_lock, NULL, RW_DRIVER, NULL); 3217133Scc210113 mutex_init(&e1000g_nvm_lock, NULL, MUTEX_DRIVER, NULL); 3223526Sxy150489 } 3233526Sxy150489 3243526Sxy150489 return (status); 3253526Sxy150489 } 3263526Sxy150489 3273526Sxy150489 /* 3284919Sxy150489 * _fini - module finalization 3293526Sxy150489 */ 3303526Sxy150489 int 3313526Sxy150489 _fini(void) 3323526Sxy150489 { 3333526Sxy150489 int status; 3343526Sxy150489 3358850SMin.Xu@Sun.COM if (e1000g_mblks_pending != 0) 3363526Sxy150489 return (EBUSY); 3373526Sxy150489 3383526Sxy150489 status = mod_remove(&modlinkage); 3393526Sxy150489 if (status == DDI_SUCCESS) { 3403526Sxy150489 mac_fini_ops(&ws_ops); 3414349Sxy150489 3424349Sxy150489 if (e1000g_force_detach) { 3434349Sxy150489 private_devi_list_t *devi_node; 3444349Sxy150489 3458850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock); 3464349Sxy150489 while (e1000g_private_devi_list != NULL) { 3474349Sxy150489 devi_node = e1000g_private_devi_list; 3484349Sxy150489 e1000g_private_devi_list = 3494349Sxy150489 e1000g_private_devi_list->next; 3504349Sxy150489 3514349Sxy150489 kmem_free(devi_node->priv_dip, 3524349Sxy150489 sizeof (struct dev_info)); 3534349Sxy150489 kmem_free(devi_node, 3544349Sxy150489 sizeof (private_devi_list_t)); 3554349Sxy150489 } 3568850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock); 3574349Sxy150489 } 3584349Sxy150489 3598850SMin.Xu@Sun.COM mutex_destroy(&e1000g_rx_detach_lock); 3603526Sxy150489 rw_destroy(&e1000g_dma_type_lock); 3617133Scc210113 mutex_destroy(&e1000g_nvm_lock); 3623526Sxy150489 } 3633526Sxy150489 3643526Sxy150489 return (status); 3653526Sxy150489 } 3663526Sxy150489 3673526Sxy150489 /* 3684919Sxy150489 * _info - module information 3693526Sxy150489 */ 3703526Sxy150489 int 3713526Sxy150489 _info(struct modinfo *modinfop) 3723526Sxy150489 { 3733526Sxy150489 return (mod_info(&modlinkage, modinfop)); 3743526Sxy150489 } 3753526Sxy150489 3763526Sxy150489 /* 3774919Sxy150489 * e1000g_attach - driver attach 3784919Sxy150489 * 3794919Sxy150489 * This function is the device-specific initialization entry 3804919Sxy150489 * point. This entry point is required and must be written. 3814919Sxy150489 * The DDI_ATTACH command must be provided in the attach entry 3824919Sxy150489 * point. When attach() is called with cmd set to DDI_ATTACH, 3834919Sxy150489 * all normal kernel services (such as kmem_alloc(9F)) are 3844919Sxy150489 * available for use by the driver. 3854919Sxy150489 * 3864919Sxy150489 * The attach() function will be called once for each instance 3874919Sxy150489 * of the device on the system with cmd set to DDI_ATTACH. 3884919Sxy150489 * Until attach() succeeds, the only driver entry points which 3894919Sxy150489 * may be called are open(9E) and getinfo(9E). 3903526Sxy150489 */ 3913526Sxy150489 static int 3924919Sxy150489 e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) 3933526Sxy150489 { 3943526Sxy150489 struct e1000g *Adapter; 3953526Sxy150489 struct e1000_hw *hw; 3964919Sxy150489 struct e1000g_osdep *osdep; 3973526Sxy150489 int instance; 3983526Sxy150489 3993526Sxy150489 switch (cmd) { 4003526Sxy150489 default: 4013526Sxy150489 e1000g_log(NULL, CE_WARN, 4024919Sxy150489 "Unsupported command send to e1000g_attach... "); 4033526Sxy150489 return (DDI_FAILURE); 4043526Sxy150489 4053526Sxy150489 case DDI_RESUME: 4063526Sxy150489 return (e1000g_resume(devinfo)); 4073526Sxy150489 4083526Sxy150489 case DDI_ATTACH: 4093526Sxy150489 break; 4103526Sxy150489 } 4113526Sxy150489 4123526Sxy150489 /* 4133526Sxy150489 * get device instance number 4143526Sxy150489 */ 4153526Sxy150489 instance = ddi_get_instance(devinfo); 4163526Sxy150489 4173526Sxy150489 /* 4183526Sxy150489 * Allocate soft data structure 4193526Sxy150489 */ 4203526Sxy150489 Adapter = 4213526Sxy150489 (struct e1000g *)kmem_zalloc(sizeof (*Adapter), KM_SLEEP); 4223526Sxy150489 4233526Sxy150489 Adapter->dip = devinfo; 4244919Sxy150489 Adapter->instance = instance; 4253526Sxy150489 Adapter->tx_ring->adapter = Adapter; 4263526Sxy150489 Adapter->rx_ring->adapter = Adapter; 4273526Sxy150489 4284919Sxy150489 hw = &Adapter->shared; 4294919Sxy150489 osdep = &Adapter->osdep; 4304919Sxy150489 hw->back = osdep; 4314919Sxy150489 osdep->adapter = Adapter; 4324919Sxy150489 4333526Sxy150489 ddi_set_driver_private(devinfo, (caddr_t)Adapter); 4343526Sxy150489 4354919Sxy150489 /* 4365273Sgl147354 * Initialize for fma support 4375273Sgl147354 */ 4385273Sgl147354 Adapter->fm_capabilities = e1000g_get_prop(Adapter, "fm-capable", 4395273Sgl147354 0, 0x0f, 4405273Sgl147354 DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE | 4415273Sgl147354 DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE); 4425273Sgl147354 e1000g_fm_init(Adapter); 4435273Sgl147354 Adapter->attach_progress |= ATTACH_PROGRESS_FMINIT; 4445273Sgl147354 4455273Sgl147354 /* 4464919Sxy150489 * PCI Configure 4474919Sxy150489 */ 4484919Sxy150489 if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) { 4494919Sxy150489 e1000g_log(Adapter, CE_WARN, "PCI configuration failed"); 4504919Sxy150489 goto attach_fail; 4514919Sxy150489 } 4524919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG; 4534919Sxy150489 4544919Sxy150489 /* 4554919Sxy150489 * Setup hardware 4564919Sxy150489 */ 4574919Sxy150489 if (e1000g_identify_hardware(Adapter) != DDI_SUCCESS) { 4584919Sxy150489 e1000g_log(Adapter, CE_WARN, "Identify hardware failed"); 4594919Sxy150489 goto attach_fail; 4604919Sxy150489 } 4613526Sxy150489 4623526Sxy150489 /* 4633526Sxy150489 * Map in the device registers. 4643526Sxy150489 */ 4654919Sxy150489 if (e1000g_regs_map(Adapter) != DDI_SUCCESS) { 4664919Sxy150489 e1000g_log(Adapter, CE_WARN, "Mapping registers failed"); 4673526Sxy150489 goto attach_fail; 4683526Sxy150489 } 4694919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_REGS_MAP; 4703526Sxy150489 4713526Sxy150489 /* 4723526Sxy150489 * Initialize driver parameters 4733526Sxy150489 */ 4743526Sxy150489 if (e1000g_set_driver_params(Adapter) != DDI_SUCCESS) { 4753526Sxy150489 goto attach_fail; 4763526Sxy150489 } 4774919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_SETUP; 4783526Sxy150489 4795273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) { 4805273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 4815273Sgl147354 goto attach_fail; 4825273Sgl147354 } 4835273Sgl147354 4843526Sxy150489 /* 4853526Sxy150489 * Initialize interrupts 4863526Sxy150489 */ 4873526Sxy150489 if (e1000g_add_intrs(Adapter) != DDI_SUCCESS) { 4883526Sxy150489 e1000g_log(Adapter, CE_WARN, "Add interrupts failed"); 4893526Sxy150489 goto attach_fail; 4903526Sxy150489 } 4914919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ADD_INTR; 4923526Sxy150489 4933526Sxy150489 /* 4943526Sxy150489 * Initialize mutex's for this device. 4953526Sxy150489 * Do this before enabling the interrupt handler and 4963526Sxy150489 * register the softint to avoid the condition where 4973526Sxy150489 * interrupt handler can try using uninitialized mutex 4983526Sxy150489 */ 4993526Sxy150489 e1000g_init_locks(Adapter); 5003526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_LOCKS; 5013526Sxy150489 5023526Sxy150489 /* 5033526Sxy150489 * Initialize Driver Counters 5043526Sxy150489 */ 5054919Sxy150489 if (e1000g_init_stats(Adapter) != DDI_SUCCESS) { 5063526Sxy150489 e1000g_log(Adapter, CE_WARN, "Init stats failed"); 5073526Sxy150489 goto attach_fail; 5083526Sxy150489 } 5093526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_KSTATS; 5103526Sxy150489 5113526Sxy150489 /* 5123526Sxy150489 * Initialize chip hardware and software structures 5133526Sxy150489 */ 5148479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 5153526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) { 5168479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 5173526Sxy150489 e1000g_log(Adapter, CE_WARN, "Adapter initialization failed"); 5183526Sxy150489 goto attach_fail; 5193526Sxy150489 } 5208479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 5213526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 5223526Sxy150489 5233526Sxy150489 /* 5243526Sxy150489 * Register the driver to the MAC 5253526Sxy150489 */ 5263526Sxy150489 if (e1000g_register_mac(Adapter) != DDI_SUCCESS) { 5273526Sxy150489 e1000g_log(Adapter, CE_WARN, "Register MAC failed"); 5283526Sxy150489 goto attach_fail; 5293526Sxy150489 } 5304919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_MAC; 5313526Sxy150489 5323526Sxy150489 /* 5333526Sxy150489 * Now that mutex locks are initialized, and the chip is also 5343526Sxy150489 * initialized, enable interrupts. 5353526Sxy150489 */ 5363526Sxy150489 if (e1000g_enable_intrs(Adapter) != DDI_SUCCESS) { 5373526Sxy150489 e1000g_log(Adapter, CE_WARN, "Enable DDI interrupts failed"); 5383526Sxy150489 goto attach_fail; 5393526Sxy150489 } 5404919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR; 5413526Sxy150489 5424982Syy150190 /* 5434982Syy150190 * If e1000g_force_detach is enabled, in global private dip list, 5444982Syy150190 * we will create a new entry, which maintains the priv_dip for DR 5454982Syy150190 * supports after driver detached. 5464982Syy150190 */ 5474982Syy150190 if (e1000g_force_detach) { 5484982Syy150190 private_devi_list_t *devi_node; 5494982Syy150190 5504982Syy150190 Adapter->priv_dip = 5514982Syy150190 kmem_zalloc(sizeof (struct dev_info), KM_SLEEP); 5524982Syy150190 bcopy(DEVI(devinfo), DEVI(Adapter->priv_dip), 5534982Syy150190 sizeof (struct dev_info)); 5544982Syy150190 5554982Syy150190 devi_node = 5564982Syy150190 kmem_zalloc(sizeof (private_devi_list_t), KM_SLEEP); 5574982Syy150190 5588850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock); 5594982Syy150190 devi_node->priv_dip = Adapter->priv_dip; 5604982Syy150190 devi_node->flag = E1000G_PRIV_DEVI_ATTACH; 5618850SMin.Xu@Sun.COM devi_node->pending_rx_count = 0; 5628850SMin.Xu@Sun.COM 5638850SMin.Xu@Sun.COM Adapter->priv_devi_node = devi_node; 5648850SMin.Xu@Sun.COM 5658850SMin.Xu@Sun.COM if (e1000g_private_devi_list == NULL) { 5668850SMin.Xu@Sun.COM devi_node->prev = NULL; 5678850SMin.Xu@Sun.COM devi_node->next = NULL; 5688850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node; 5698850SMin.Xu@Sun.COM } else { 5708850SMin.Xu@Sun.COM devi_node->prev = NULL; 5718850SMin.Xu@Sun.COM devi_node->next = e1000g_private_devi_list; 5728850SMin.Xu@Sun.COM e1000g_private_devi_list->prev = devi_node; 5738850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node; 5748850SMin.Xu@Sun.COM } 5758850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock); 5764982Syy150190 } 5774982Syy150190 5783526Sxy150489 cmn_err(CE_CONT, "!%s, %s\n", e1000g_string, e1000g_version); 5798479SChenlu.Chen@Sun.COM Adapter->e1000g_state = E1000G_INITIALIZED; 5803526Sxy150489 5813526Sxy150489 return (DDI_SUCCESS); 5823526Sxy150489 5833526Sxy150489 attach_fail: 5843526Sxy150489 e1000g_unattach(devinfo, Adapter); 5853526Sxy150489 return (DDI_FAILURE); 5863526Sxy150489 } 5873526Sxy150489 5883526Sxy150489 static int 5893526Sxy150489 e1000g_register_mac(struct e1000g *Adapter) 5903526Sxy150489 { 5914919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 5923526Sxy150489 mac_register_t *mac; 5933526Sxy150489 int err; 5943526Sxy150489 5953526Sxy150489 if ((mac = mac_alloc(MAC_VERSION)) == NULL) 5963526Sxy150489 return (DDI_FAILURE); 5974919Sxy150489 5983526Sxy150489 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 5993526Sxy150489 mac->m_driver = Adapter; 6003526Sxy150489 mac->m_dip = Adapter->dip; 6014919Sxy150489 mac->m_src_addr = hw->mac.addr; 6023526Sxy150489 mac->m_callbacks = &e1000g_m_callbacks; 6033526Sxy150489 mac->m_min_sdu = 0; 6046394Scc210113 mac->m_max_sdu = Adapter->default_mtu; 6055895Syz147064 mac->m_margin = VLAN_TAGSZ; 6066512Ssowmini mac->m_priv_props = e1000g_priv_props; 6076512Ssowmini mac->m_priv_prop_count = E1000G_MAX_PRIV_PROPS; 6088275SEric Cheng mac->m_v12n = MAC_VIRT_LEVEL1; 6094919Sxy150489 6103526Sxy150489 err = mac_register(mac, &Adapter->mh); 6113526Sxy150489 mac_free(mac); 6124919Sxy150489 6133526Sxy150489 return (err == 0 ? DDI_SUCCESS : DDI_FAILURE); 6143526Sxy150489 } 6153526Sxy150489 6163526Sxy150489 static int 6174919Sxy150489 e1000g_identify_hardware(struct e1000g *Adapter) 6184919Sxy150489 { 6194919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 6204919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep; 6214919Sxy150489 6224919Sxy150489 /* Get the device id */ 6234919Sxy150489 hw->vendor_id = 6244919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID); 6254919Sxy150489 hw->device_id = 6264919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID); 6274919Sxy150489 hw->revision_id = 6284919Sxy150489 pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID); 6294919Sxy150489 hw->subsystem_device_id = 6304919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID); 6314919Sxy150489 hw->subsystem_vendor_id = 6324919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID); 6334919Sxy150489 6344919Sxy150489 if (e1000_set_mac_type(hw) != E1000_SUCCESS) { 6354919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 6364919Sxy150489 "MAC type could not be set properly."); 6374919Sxy150489 return (DDI_FAILURE); 6384919Sxy150489 } 6394919Sxy150489 6404919Sxy150489 return (DDI_SUCCESS); 6414919Sxy150489 } 6424919Sxy150489 6434919Sxy150489 static int 6444919Sxy150489 e1000g_regs_map(struct e1000g *Adapter) 6454919Sxy150489 { 6464919Sxy150489 dev_info_t *devinfo = Adapter->dip; 6474919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 6484919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep; 6494919Sxy150489 off_t mem_size; 6504919Sxy150489 6517607STed.You@Sun.COM /* Get size of adapter register memory */ 6527607STed.You@Sun.COM if (ddi_dev_regsize(devinfo, ADAPTER_REG_SET, &mem_size) != 6537607STed.You@Sun.COM DDI_SUCCESS) { 6544919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 6554919Sxy150489 "ddi_dev_regsize for registers failed"); 6564919Sxy150489 return (DDI_FAILURE); 6574919Sxy150489 } 6584919Sxy150489 6597607STed.You@Sun.COM /* Map adapter register memory */ 6607607STed.You@Sun.COM if ((ddi_regs_map_setup(devinfo, ADAPTER_REG_SET, 6614919Sxy150489 (caddr_t *)&hw->hw_addr, 0, mem_size, &e1000g_regs_acc_attr, 6624919Sxy150489 &osdep->reg_handle)) != DDI_SUCCESS) { 6634919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 6644919Sxy150489 "ddi_regs_map_setup for registers failed"); 6654919Sxy150489 goto regs_map_fail; 6664919Sxy150489 } 6674919Sxy150489 6684919Sxy150489 /* ICH needs to map flash memory */ 6697607STed.You@Sun.COM if (hw->mac.type == e1000_ich8lan || 6707607STed.You@Sun.COM hw->mac.type == e1000_ich9lan || 6717607STed.You@Sun.COM hw->mac.type == e1000_ich10lan) { 6724919Sxy150489 /* get flash size */ 6734919Sxy150489 if (ddi_dev_regsize(devinfo, ICH_FLASH_REG_SET, 6744919Sxy150489 &mem_size) != DDI_SUCCESS) { 6754919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 6764919Sxy150489 "ddi_dev_regsize for ICH flash failed"); 6774919Sxy150489 goto regs_map_fail; 6784919Sxy150489 } 6794919Sxy150489 6804919Sxy150489 /* map flash in */ 6814919Sxy150489 if (ddi_regs_map_setup(devinfo, ICH_FLASH_REG_SET, 6824919Sxy150489 (caddr_t *)&hw->flash_address, 0, 6834919Sxy150489 mem_size, &e1000g_regs_acc_attr, 6844919Sxy150489 &osdep->ich_flash_handle) != DDI_SUCCESS) { 6854919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 6864919Sxy150489 "ddi_regs_map_setup for ICH flash failed"); 6874919Sxy150489 goto regs_map_fail; 6884919Sxy150489 } 6894919Sxy150489 } 6904919Sxy150489 6914919Sxy150489 return (DDI_SUCCESS); 6924919Sxy150489 6934919Sxy150489 regs_map_fail: 6944919Sxy150489 if (osdep->reg_handle != NULL) 6954919Sxy150489 ddi_regs_map_free(&osdep->reg_handle); 6964919Sxy150489 6974919Sxy150489 return (DDI_FAILURE); 6984919Sxy150489 } 6994919Sxy150489 7004919Sxy150489 static int 7013526Sxy150489 e1000g_set_driver_params(struct e1000g *Adapter) 7023526Sxy150489 { 7033526Sxy150489 struct e1000_hw *hw; 7044919Sxy150489 uint32_t mem_bar, io_bar, bar64; 7053526Sxy150489 7064919Sxy150489 hw = &Adapter->shared; 7074919Sxy150489 7084919Sxy150489 /* Set MAC type and initialize hardware functions */ 7094919Sxy150489 if (e1000_setup_init_funcs(hw, B_TRUE) != E1000_SUCCESS) { 7104919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 7114919Sxy150489 "Could not setup hardware functions"); 7123526Sxy150489 return (DDI_FAILURE); 7133526Sxy150489 } 7143526Sxy150489 7154919Sxy150489 /* Get bus information */ 7164919Sxy150489 if (e1000_get_bus_info(hw) != E1000_SUCCESS) { 7174919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 7184919Sxy150489 "Could not get bus information"); 7194919Sxy150489 return (DDI_FAILURE); 7203526Sxy150489 } 7213526Sxy150489 7223526Sxy150489 /* get mem_base addr */ 7234919Sxy150489 mem_bar = pci_config_get32(Adapter->osdep.cfg_handle, PCI_CONF_BASE0); 7244919Sxy150489 bar64 = mem_bar & PCI_BASE_TYPE_ALL; 7253526Sxy150489 7263526Sxy150489 /* get io_base addr */ 7274919Sxy150489 if (hw->mac.type >= e1000_82544) { 7284919Sxy150489 if (bar64) { 7293526Sxy150489 /* IO BAR is different for 64 bit BAR mode */ 7304919Sxy150489 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 7314919Sxy150489 PCI_CONF_BASE4); 7323526Sxy150489 } else { 7333526Sxy150489 /* normal 32-bit BAR mode */ 7344919Sxy150489 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 7354919Sxy150489 PCI_CONF_BASE2); 7363526Sxy150489 } 7373526Sxy150489 hw->io_base = io_bar & PCI_BASE_IO_ADDR_M; 7383526Sxy150489 } else { 7393526Sxy150489 /* no I/O access for adapters prior to 82544 */ 7403526Sxy150489 hw->io_base = 0x0; 7413526Sxy150489 } 7423526Sxy150489 7434919Sxy150489 e1000_read_pci_cfg(hw, PCI_COMMAND_REGISTER, &hw->bus.pci_cmd_word); 7444919Sxy150489 7454919Sxy150489 hw->mac.autoneg_failed = B_TRUE; 7464919Sxy150489 7476735Scc210113 /* Set the autoneg_wait_to_complete flag to B_FALSE */ 7486735Scc210113 hw->phy.autoneg_wait_to_complete = B_FALSE; 7493526Sxy150489 7503526Sxy150489 /* Adaptive IFS related changes */ 7514919Sxy150489 hw->mac.adaptive_ifs = B_TRUE; 7524919Sxy150489 7534919Sxy150489 /* Enable phy init script for IGP phy of 82541/82547 */ 7544919Sxy150489 if ((hw->mac.type == e1000_82547) || 7554919Sxy150489 (hw->mac.type == e1000_82541) || 7564919Sxy150489 (hw->mac.type == e1000_82547_rev_2) || 7574919Sxy150489 (hw->mac.type == e1000_82541_rev_2)) 7584919Sxy150489 e1000_init_script_state_82541(hw, B_TRUE); 7594919Sxy150489 7604919Sxy150489 /* Enable the TTL workaround for 82541/82547 */ 7614919Sxy150489 e1000_set_ttl_workaround_state_82541(hw, B_TRUE); 7623526Sxy150489 7634608Syy150190 #ifdef __sparc 7644608Syy150190 Adapter->strip_crc = B_TRUE; 7654608Syy150190 #else 7664608Syy150190 Adapter->strip_crc = B_FALSE; 7674608Syy150190 #endif 7684608Syy150190 7693526Sxy150489 /* Get conf file properties */ 7704919Sxy150489 e1000g_get_conf(Adapter); 7714919Sxy150489 7724919Sxy150489 /* Get speed/duplex settings in conf file */ 7734919Sxy150489 hw->mac.forced_speed_duplex = ADVERTISE_100_FULL; 7744919Sxy150489 hw->phy.autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; 7753526Sxy150489 e1000g_force_speed_duplex(Adapter); 7763526Sxy150489 7774919Sxy150489 /* Get Jumbo Frames settings in conf file */ 7783526Sxy150489 e1000g_get_max_frame_size(Adapter); 7793526Sxy150489 7803526Sxy150489 /* Set Rx/Tx buffer size */ 7816394Scc210113 e1000g_set_bufsize(Adapter); 7824919Sxy150489 7834919Sxy150489 /* Master Latency Timer */ 7844919Sxy150489 Adapter->master_latency_timer = DEFAULT_MASTER_LATENCY_TIMER; 7854919Sxy150489 7863526Sxy150489 /* copper options */ 7876735Scc210113 if (hw->phy.media_type == e1000_media_type_copper) { 7884919Sxy150489 hw->phy.mdix = 0; /* AUTO_ALL_MODES */ 7894919Sxy150489 hw->phy.disable_polarity_correction = B_FALSE; 7904919Sxy150489 hw->phy.ms_type = e1000_ms_hw_default; /* E1000_MASTER_SLAVE */ 7913526Sxy150489 } 7923526Sxy150489 7934919Sxy150489 /* The initial link state should be "unknown" */ 7944061Sxy150489 Adapter->link_state = LINK_STATE_UNKNOWN; 7954061Sxy150489 7965882Syy150190 /* Initialize rx parameters */ 7975882Syy150190 Adapter->rx_intr_delay = DEFAULT_RX_INTR_DELAY; 7985882Syy150190 Adapter->rx_intr_abs_delay = DEFAULT_RX_INTR_ABS_DELAY; 7995882Syy150190 8004919Sxy150489 /* Initialize tx parameters */ 8014919Sxy150489 Adapter->tx_intr_enable = DEFAULT_TX_INTR_ENABLE; 8024919Sxy150489 Adapter->tx_bcopy_thresh = DEFAULT_TX_BCOPY_THRESHOLD; 8035882Syy150190 Adapter->tx_intr_delay = DEFAULT_TX_INTR_DELAY; 8045882Syy150190 Adapter->tx_intr_abs_delay = DEFAULT_TX_INTR_ABS_DELAY; 8054919Sxy150489 8064919Sxy150489 /* Initialize rx parameters */ 8074919Sxy150489 Adapter->rx_bcopy_thresh = DEFAULT_RX_BCOPY_THRESHOLD; 8084919Sxy150489 8093526Sxy150489 return (DDI_SUCCESS); 8103526Sxy150489 } 8113526Sxy150489 8126394Scc210113 static void 8136394Scc210113 e1000g_set_bufsize(struct e1000g *Adapter) 8146394Scc210113 { 8156394Scc210113 struct e1000_mac_info *mac = &Adapter->shared.mac; 8166394Scc210113 uint64_t rx_size; 8176394Scc210113 uint64_t tx_size; 8186394Scc210113 8198073SMin.Xu@Sun.COM dev_info_t *devinfo = Adapter->dip; 8206394Scc210113 #ifdef __sparc 8216394Scc210113 ulong_t iommu_pagesize; 8228073SMin.Xu@Sun.COM #endif 8236394Scc210113 /* Get the system page size */ 8246394Scc210113 Adapter->sys_page_sz = ddi_ptob(devinfo, (ulong_t)1); 8258073SMin.Xu@Sun.COM 8268073SMin.Xu@Sun.COM #ifdef __sparc 8276394Scc210113 iommu_pagesize = dvma_pagesize(devinfo); 8286394Scc210113 if (iommu_pagesize != 0) { 8296394Scc210113 if (Adapter->sys_page_sz == iommu_pagesize) { 8306394Scc210113 if (iommu_pagesize > 0x4000) 8316394Scc210113 Adapter->sys_page_sz = 0x4000; 8326394Scc210113 } else { 8336394Scc210113 if (Adapter->sys_page_sz > iommu_pagesize) 8346394Scc210113 Adapter->sys_page_sz = iommu_pagesize; 8356394Scc210113 } 8366394Scc210113 } 8376986Smx205022 if (Adapter->lso_enable) { 8386986Smx205022 Adapter->dvma_page_num = E1000_LSO_MAXLEN / 8396986Smx205022 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM; 8406986Smx205022 } else { 8416986Smx205022 Adapter->dvma_page_num = Adapter->max_frame_size / 8426986Smx205022 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM; 8436986Smx205022 } 8446394Scc210113 ASSERT(Adapter->dvma_page_num >= E1000G_DEFAULT_DVMA_PAGE_NUM); 8456394Scc210113 #endif 8466394Scc210113 8476735Scc210113 Adapter->min_frame_size = ETHERMIN + ETHERFCSL; 8486735Scc210113 8498417SChenlu.Chen@Sun.COM if (Adapter->mem_workaround_82546 && 8508417SChenlu.Chen@Sun.COM ((mac->type == e1000_82545) || 8518178SChenlu.Chen@Sun.COM (mac->type == e1000_82546) || 8528417SChenlu.Chen@Sun.COM (mac->type == e1000_82546_rev_3))) { 8536394Scc210113 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K; 8548178SChenlu.Chen@Sun.COM } else { 8558178SChenlu.Chen@Sun.COM rx_size = Adapter->max_frame_size + E1000G_IPALIGNPRESERVEROOM; 8568178SChenlu.Chen@Sun.COM if ((rx_size > FRAME_SIZE_UPTO_2K) && 8578178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_4K)) 8588178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_4K; 8598178SChenlu.Chen@Sun.COM else if ((rx_size > FRAME_SIZE_UPTO_4K) && 8608178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_8K)) 8618178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_8K; 8628178SChenlu.Chen@Sun.COM else if ((rx_size > FRAME_SIZE_UPTO_8K) && 8638178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_16K)) 8648178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_16K; 8658178SChenlu.Chen@Sun.COM else 8668178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K; 8678178SChenlu.Chen@Sun.COM } 8686394Scc210113 8696735Scc210113 tx_size = Adapter->max_frame_size; 8706394Scc210113 if ((tx_size > FRAME_SIZE_UPTO_2K) && (tx_size <= FRAME_SIZE_UPTO_4K)) 8716394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_4K; 8726394Scc210113 else if ((tx_size > FRAME_SIZE_UPTO_4K) && 8736394Scc210113 (tx_size <= FRAME_SIZE_UPTO_8K)) 8746394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_8K; 8756394Scc210113 else if ((tx_size > FRAME_SIZE_UPTO_8K) && 8766394Scc210113 (tx_size <= FRAME_SIZE_UPTO_16K)) 8776394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_16K; 8786394Scc210113 else 8796394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K; 8806394Scc210113 8816394Scc210113 /* 8826394Scc210113 * For Wiseman adapters we have an requirement of having receive 8836394Scc210113 * buffers aligned at 256 byte boundary. Since Livengood does not 8846394Scc210113 * require this and forcing it for all hardwares will have 8856394Scc210113 * performance implications, I am making it applicable only for 8866394Scc210113 * Wiseman and for Jumbo frames enabled mode as rest of the time, 8876394Scc210113 * it is okay to have normal frames...but it does involve a 8886394Scc210113 * potential risk where we may loose data if buffer is not 8896394Scc210113 * aligned...so all wiseman boards to have 256 byte aligned 8906394Scc210113 * buffers 8916394Scc210113 */ 8926394Scc210113 if (mac->type < e1000_82543) 8936394Scc210113 Adapter->rx_buf_align = RECEIVE_BUFFER_ALIGN_SIZE; 8946394Scc210113 else 8956394Scc210113 Adapter->rx_buf_align = 1; 8966394Scc210113 } 8976394Scc210113 8983526Sxy150489 /* 8994919Sxy150489 * e1000g_detach - driver detach 9004919Sxy150489 * 9014919Sxy150489 * The detach() function is the complement of the attach routine. 9024919Sxy150489 * If cmd is set to DDI_DETACH, detach() is used to remove the 9034919Sxy150489 * state associated with a given instance of a device node 9044919Sxy150489 * prior to the removal of that instance from the system. 9054919Sxy150489 * 9064919Sxy150489 * The detach() function will be called once for each instance 9074919Sxy150489 * of the device for which there has been a successful attach() 9084919Sxy150489 * once there are no longer any opens on the device. 9094919Sxy150489 * 9104919Sxy150489 * Interrupts routine are disabled, All memory allocated by this 9114919Sxy150489 * driver are freed. 9123526Sxy150489 */ 9133526Sxy150489 static int 9144919Sxy150489 e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd) 9153526Sxy150489 { 9163526Sxy150489 struct e1000g *Adapter; 9174982Syy150190 boolean_t rx_drain; 9183526Sxy150489 9193526Sxy150489 switch (cmd) { 9203526Sxy150489 default: 9213526Sxy150489 return (DDI_FAILURE); 9223526Sxy150489 9233526Sxy150489 case DDI_SUSPEND: 9243526Sxy150489 return (e1000g_suspend(devinfo)); 9253526Sxy150489 9263526Sxy150489 case DDI_DETACH: 9273526Sxy150489 break; 9283526Sxy150489 } 9293526Sxy150489 9303526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 9313526Sxy150489 if (Adapter == NULL) 9323526Sxy150489 return (DDI_FAILURE); 9333526Sxy150489 9348275SEric Cheng rx_drain = e1000g_rx_drain(Adapter); 9358275SEric Cheng if (!rx_drain && !e1000g_force_detach) 9368275SEric Cheng return (DDI_FAILURE); 9378275SEric Cheng 9384919Sxy150489 if (mac_unregister(Adapter->mh) != 0) { 9394919Sxy150489 e1000g_log(Adapter, CE_WARN, "Unregister MAC failed"); 9404919Sxy150489 return (DDI_FAILURE); 9414919Sxy150489 } 9424919Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_MAC; 9434919Sxy150489 9448479SChenlu.Chen@Sun.COM ASSERT(!(Adapter->e1000g_state & E1000G_STARTED)); 9454982Syy150190 9468850SMin.Xu@Sun.COM if (!e1000g_force_detach && !rx_drain) 9478850SMin.Xu@Sun.COM return (DDI_FAILURE); 9483526Sxy150489 9493526Sxy150489 e1000g_unattach(devinfo, Adapter); 9503526Sxy150489 9513526Sxy150489 return (DDI_SUCCESS); 9523526Sxy150489 } 9533526Sxy150489 9544982Syy150190 /* 9554982Syy150190 * e1000g_free_priv_devi_node - free a priv_dip entry for driver instance 9564982Syy150190 */ 9578850SMin.Xu@Sun.COM void 9588850SMin.Xu@Sun.COM e1000g_free_priv_devi_node(private_devi_list_t *devi_node) 9594982Syy150190 { 9604982Syy150190 ASSERT(e1000g_private_devi_list != NULL); 9618850SMin.Xu@Sun.COM ASSERT(devi_node != NULL); 9628850SMin.Xu@Sun.COM 9638850SMin.Xu@Sun.COM if (devi_node->prev != NULL) 9648850SMin.Xu@Sun.COM devi_node->prev->next = devi_node->next; 9658850SMin.Xu@Sun.COM if (devi_node->next != NULL) 9668850SMin.Xu@Sun.COM devi_node->next->prev = devi_node->prev; 9678850SMin.Xu@Sun.COM if (devi_node == e1000g_private_devi_list) 9688850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node->next; 9698850SMin.Xu@Sun.COM 9708850SMin.Xu@Sun.COM kmem_free(devi_node->priv_dip, 9718850SMin.Xu@Sun.COM sizeof (struct dev_info)); 9728850SMin.Xu@Sun.COM kmem_free(devi_node, 9738850SMin.Xu@Sun.COM sizeof (private_devi_list_t)); 9744982Syy150190 } 9754982Syy150190 9763526Sxy150489 static void 9773526Sxy150489 e1000g_unattach(dev_info_t *devinfo, struct e1000g *Adapter) 9783526Sxy150489 { 9798850SMin.Xu@Sun.COM private_devi_list_t *devi_node; 9807133Scc210113 int result; 9817133Scc210113 9824919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) { 9833526Sxy150489 (void) e1000g_disable_intrs(Adapter); 9843526Sxy150489 } 9853526Sxy150489 9864919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_MAC) { 9873526Sxy150489 (void) mac_unregister(Adapter->mh); 9883526Sxy150489 } 9893526Sxy150489 9904919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ADD_INTR) { 9913526Sxy150489 (void) e1000g_rem_intrs(Adapter); 9923526Sxy150489 } 9933526Sxy150489 9944919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_SETUP) { 9953526Sxy150489 (void) ddi_prop_remove_all(devinfo); 9963526Sxy150489 } 9973526Sxy150489 9983526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_KSTATS) { 9993526Sxy150489 kstat_delete((kstat_t *)Adapter->e1000g_ksp); 10003526Sxy150489 } 10013526Sxy150489 10023526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_INIT) { 10034919Sxy150489 stop_link_timer(Adapter); 10047133Scc210113 10057133Scc210113 mutex_enter(&e1000g_nvm_lock); 10067133Scc210113 result = e1000_reset_hw(&Adapter->shared); 10077133Scc210113 mutex_exit(&e1000g_nvm_lock); 10087133Scc210113 10097133Scc210113 if (result != E1000_SUCCESS) { 10105273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 10115273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 10125273Sgl147354 } 10133526Sxy150489 } 10143526Sxy150489 10159770SChangqing.Li@Sun.COM e1000g_release_multicast(Adapter); 10169770SChangqing.Li@Sun.COM 10174919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_REGS_MAP) { 10184919Sxy150489 if (Adapter->osdep.reg_handle != NULL) 10194919Sxy150489 ddi_regs_map_free(&Adapter->osdep.reg_handle); 10204919Sxy150489 if (Adapter->osdep.ich_flash_handle != NULL) 10214919Sxy150489 ddi_regs_map_free(&Adapter->osdep.ich_flash_handle); 10223526Sxy150489 } 10233526Sxy150489 10244919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) { 10254919Sxy150489 if (Adapter->osdep.cfg_handle != NULL) 10264919Sxy150489 pci_config_teardown(&Adapter->osdep.cfg_handle); 10273526Sxy150489 } 10283526Sxy150489 10293526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_LOCKS) { 10303526Sxy150489 e1000g_destroy_locks(Adapter); 10313526Sxy150489 } 10323526Sxy150489 10335273Sgl147354 if (Adapter->attach_progress & ATTACH_PROGRESS_FMINIT) { 10345273Sgl147354 e1000g_fm_fini(Adapter); 10355273Sgl147354 } 10365273Sgl147354 10378850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock); 10389190SMin.Xu@Sun.COM if (e1000g_force_detach && (Adapter->priv_devi_node != NULL)) { 10398850SMin.Xu@Sun.COM devi_node = Adapter->priv_devi_node; 10408850SMin.Xu@Sun.COM devi_node->flag |= E1000G_PRIV_DEVI_DETACH; 10418850SMin.Xu@Sun.COM 10428850SMin.Xu@Sun.COM if (devi_node->pending_rx_count == 0) { 10438850SMin.Xu@Sun.COM e1000g_free_priv_devi_node(devi_node); 10448850SMin.Xu@Sun.COM } 10458850SMin.Xu@Sun.COM } 10468850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock); 10478850SMin.Xu@Sun.COM 10483526Sxy150489 kmem_free((caddr_t)Adapter, sizeof (struct e1000g)); 10493526Sxy150489 10503526Sxy150489 /* 10513526Sxy150489 * Another hotplug spec requirement, 10523526Sxy150489 * run ddi_set_driver_private(devinfo, null); 10533526Sxy150489 */ 10543526Sxy150489 ddi_set_driver_private(devinfo, NULL); 10553526Sxy150489 } 10563526Sxy150489 10573526Sxy150489 static void 10583526Sxy150489 e1000g_init_locks(struct e1000g *Adapter) 10593526Sxy150489 { 10603526Sxy150489 e1000g_tx_ring_t *tx_ring; 10613526Sxy150489 e1000g_rx_ring_t *rx_ring; 10623526Sxy150489 10633526Sxy150489 rw_init(&Adapter->chip_lock, NULL, 10643526Sxy150489 RW_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10654919Sxy150489 mutex_init(&Adapter->link_lock, NULL, 10663526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10674919Sxy150489 mutex_init(&Adapter->watchdog_lock, NULL, 10683526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10693526Sxy150489 10703526Sxy150489 tx_ring = Adapter->tx_ring; 10713526Sxy150489 10723526Sxy150489 mutex_init(&tx_ring->tx_lock, NULL, 10733526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10743526Sxy150489 mutex_init(&tx_ring->usedlist_lock, NULL, 10753526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10763526Sxy150489 mutex_init(&tx_ring->freelist_lock, NULL, 10773526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10783526Sxy150489 10793526Sxy150489 rx_ring = Adapter->rx_ring; 10803526Sxy150489 10817436STed.You@Sun.COM mutex_init(&rx_ring->rx_lock, NULL, 10827436STed.You@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 10833526Sxy150489 } 10843526Sxy150489 10853526Sxy150489 static void 10863526Sxy150489 e1000g_destroy_locks(struct e1000g *Adapter) 10873526Sxy150489 { 10883526Sxy150489 e1000g_tx_ring_t *tx_ring; 10893526Sxy150489 e1000g_rx_ring_t *rx_ring; 10903526Sxy150489 10913526Sxy150489 tx_ring = Adapter->tx_ring; 10923526Sxy150489 mutex_destroy(&tx_ring->tx_lock); 10933526Sxy150489 mutex_destroy(&tx_ring->usedlist_lock); 10943526Sxy150489 mutex_destroy(&tx_ring->freelist_lock); 10953526Sxy150489 10963526Sxy150489 rx_ring = Adapter->rx_ring; 10977436STed.You@Sun.COM mutex_destroy(&rx_ring->rx_lock); 10983526Sxy150489 10994919Sxy150489 mutex_destroy(&Adapter->link_lock); 11004919Sxy150489 mutex_destroy(&Adapter->watchdog_lock); 11013526Sxy150489 rw_destroy(&Adapter->chip_lock); 11023526Sxy150489 } 11033526Sxy150489 11043526Sxy150489 static int 11053526Sxy150489 e1000g_resume(dev_info_t *devinfo) 11063526Sxy150489 { 11073526Sxy150489 struct e1000g *Adapter; 11083526Sxy150489 11093526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 11103526Sxy150489 if (Adapter == NULL) 11118479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_PANIC, 11128479SChenlu.Chen@Sun.COM "Instance pointer is null\n"); 11138479SChenlu.Chen@Sun.COM 11148479SChenlu.Chen@Sun.COM if (Adapter->dip != devinfo) 11158479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_PANIC, 11168479SChenlu.Chen@Sun.COM "Devinfo is not the same as saved devinfo\n"); 11178479SChenlu.Chen@Sun.COM 11188479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 11198479SChenlu.Chen@Sun.COM 11208479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) { 11218479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_FALSE) != DDI_SUCCESS) { 11228479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 11238479SChenlu.Chen@Sun.COM /* 11248479SChenlu.Chen@Sun.COM * We note the failure, but return success, as the 11258479SChenlu.Chen@Sun.COM * system is still usable without this controller. 11268479SChenlu.Chen@Sun.COM */ 11278479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_WARN, 11288479SChenlu.Chen@Sun.COM "e1000g_resume: failed to restart controller\n"); 11298479SChenlu.Chen@Sun.COM return (DDI_SUCCESS); 11308479SChenlu.Chen@Sun.COM } 11318479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */ 11328479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter); 11338479SChenlu.Chen@Sun.COM } 11348479SChenlu.Chen@Sun.COM 11358479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_SUSPENDED; 11368479SChenlu.Chen@Sun.COM 11378479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 11383526Sxy150489 11393526Sxy150489 return (DDI_SUCCESS); 11403526Sxy150489 } 11413526Sxy150489 11423526Sxy150489 static int 11433526Sxy150489 e1000g_suspend(dev_info_t *devinfo) 11443526Sxy150489 { 11453526Sxy150489 struct e1000g *Adapter; 11463526Sxy150489 11473526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 11483526Sxy150489 if (Adapter == NULL) 11493526Sxy150489 return (DDI_FAILURE); 11503526Sxy150489 11518479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 11528479SChenlu.Chen@Sun.COM 11538479SChenlu.Chen@Sun.COM Adapter->e1000g_state |= E1000G_SUSPENDED; 11548479SChenlu.Chen@Sun.COM 11558479SChenlu.Chen@Sun.COM /* if the port isn't plumbed, we can simply return */ 11568479SChenlu.Chen@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) { 11578479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 11588479SChenlu.Chen@Sun.COM return (DDI_SUCCESS); 11598479SChenlu.Chen@Sun.COM } 11608479SChenlu.Chen@Sun.COM 11618479SChenlu.Chen@Sun.COM e1000g_stop(Adapter, B_FALSE); 11628479SChenlu.Chen@Sun.COM 11638479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 11648479SChenlu.Chen@Sun.COM 11658479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */ 11668479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter); 11678479SChenlu.Chen@Sun.COM stop_link_timer(Adapter); 11688479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring); 11693526Sxy150489 11703526Sxy150489 return (DDI_SUCCESS); 11713526Sxy150489 } 11723526Sxy150489 11733526Sxy150489 static int 11743526Sxy150489 e1000g_init(struct e1000g *Adapter) 11753526Sxy150489 { 11763526Sxy150489 uint32_t pba; 11774919Sxy150489 uint32_t high_water; 11783526Sxy150489 struct e1000_hw *hw; 11794061Sxy150489 clock_t link_timeout; 11807133Scc210113 int result; 11813526Sxy150489 11824919Sxy150489 hw = &Adapter->shared; 11833526Sxy150489 11843526Sxy150489 /* 11853526Sxy150489 * reset to put the hardware in a known state 11863526Sxy150489 * before we try to do anything with the eeprom 11873526Sxy150489 */ 11887133Scc210113 mutex_enter(&e1000g_nvm_lock); 11897133Scc210113 result = e1000_reset_hw(hw); 11907133Scc210113 mutex_exit(&e1000g_nvm_lock); 11917133Scc210113 11927133Scc210113 if (result != E1000_SUCCESS) { 11935273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 11945273Sgl147354 goto init_fail; 11955273Sgl147354 } 11963526Sxy150489 11977133Scc210113 mutex_enter(&e1000g_nvm_lock); 11987133Scc210113 result = e1000_validate_nvm_checksum(hw); 11997133Scc210113 if (result < E1000_SUCCESS) { 12004061Sxy150489 /* 12014061Sxy150489 * Some PCI-E parts fail the first check due to 12024061Sxy150489 * the link being in sleep state. Call it again, 12034061Sxy150489 * if it fails a second time its a real issue. 12044061Sxy150489 */ 12057133Scc210113 result = e1000_validate_nvm_checksum(hw); 12067133Scc210113 } 12077133Scc210113 mutex_exit(&e1000g_nvm_lock); 12087133Scc210113 12097133Scc210113 if (result < E1000_SUCCESS) { 12107133Scc210113 e1000g_log(Adapter, CE_WARN, 12117133Scc210113 "Invalid NVM checksum. Please contact " 12127133Scc210113 "the vendor to update the NVM."); 12137133Scc210113 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 12147133Scc210113 goto init_fail; 12157133Scc210113 } 12167133Scc210113 12177133Scc210113 result = 0; 12183526Sxy150489 #ifdef __sparc 12193526Sxy150489 /* 12207607STed.You@Sun.COM * First, we try to get the local ethernet address from OBP. If 12217133Scc210113 * failed, then we get it from the EEPROM of NIC card. 12223526Sxy150489 */ 12237133Scc210113 result = e1000g_find_mac_address(Adapter); 12247133Scc210113 #endif 12253526Sxy150489 /* Get the local ethernet address. */ 12267133Scc210113 if (!result) { 12277133Scc210113 mutex_enter(&e1000g_nvm_lock); 12287140Scc210113 result = e1000_read_mac_addr(hw); 12297133Scc210113 mutex_exit(&e1000g_nvm_lock); 12307133Scc210113 } 12317133Scc210113 12327133Scc210113 if (result < E1000_SUCCESS) { 12333526Sxy150489 e1000g_log(Adapter, CE_WARN, "Read mac addr failed"); 12345273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 12353526Sxy150489 goto init_fail; 12363526Sxy150489 } 12373526Sxy150489 12383526Sxy150489 /* check for valid mac address */ 12394919Sxy150489 if (!is_valid_mac_addr(hw->mac.addr)) { 12403526Sxy150489 e1000g_log(Adapter, CE_WARN, "Invalid mac addr"); 12415273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 12423526Sxy150489 goto init_fail; 12433526Sxy150489 } 12443526Sxy150489 12454919Sxy150489 /* Set LAA state for 82571 chipset */ 12464919Sxy150489 e1000_set_laa_state_82571(hw, B_TRUE); 12473526Sxy150489 12483526Sxy150489 /* Master Latency Timer implementation */ 12494919Sxy150489 if (Adapter->master_latency_timer) { 12504919Sxy150489 pci_config_put8(Adapter->osdep.cfg_handle, 12514919Sxy150489 PCI_CONF_LATENCY_TIMER, Adapter->master_latency_timer); 12523526Sxy150489 } 12533526Sxy150489 12544919Sxy150489 if (hw->mac.type < e1000_82547) { 12553526Sxy150489 /* 12563526Sxy150489 * Total FIFO is 64K 12573526Sxy150489 */ 12586735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 12593526Sxy150489 pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */ 12603526Sxy150489 else 12613526Sxy150489 pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */ 12627140Scc210113 } else if ((hw->mac.type == e1000_82571) || 12637140Scc210113 (hw->mac.type == e1000_82572) || 12647140Scc210113 (hw->mac.type == e1000_80003es2lan)) { 12653526Sxy150489 /* 12663526Sxy150489 * Total FIFO is 48K 12673526Sxy150489 */ 12686735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 12693526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 18K for Tx */ 12703526Sxy150489 else 12713526Sxy150489 pba = E1000_PBA_38K; /* 38K for Rx, 10K for Tx */ 12727607STed.You@Sun.COM } else if (hw->mac.type == e1000_82573) { 12737607STed.You@Sun.COM pba = E1000_PBA_20K; /* 20K for Rx, 12K for Tx */ 12747607STed.You@Sun.COM } else if (hw->mac.type == e1000_82574) { 12757607STed.You@Sun.COM /* Keep adapter default: 20K for Rx, 20K for Tx */ 12767607STed.You@Sun.COM pba = E1000_READ_REG(hw, E1000_PBA); 12774919Sxy150489 } else if (hw->mac.type == e1000_ich8lan) { 12783526Sxy150489 pba = E1000_PBA_8K; /* 8K for Rx, 12K for Tx */ 12794919Sxy150489 } else if (hw->mac.type == e1000_ich9lan) { 12807607STed.You@Sun.COM pba = E1000_PBA_10K; 12817607STed.You@Sun.COM } else if (hw->mac.type == e1000_ich10lan) { 12827607STed.You@Sun.COM pba = E1000_PBA_10K; 12833526Sxy150489 } else { 12843526Sxy150489 /* 12853526Sxy150489 * Total FIFO is 40K 12863526Sxy150489 */ 12876735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K) 12883526Sxy150489 pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */ 12893526Sxy150489 else 12903526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */ 12913526Sxy150489 } 12924919Sxy150489 E1000_WRITE_REG(hw, E1000_PBA, pba); 12933526Sxy150489 12943526Sxy150489 /* 12953526Sxy150489 * These parameters set thresholds for the adapter's generation(Tx) 12963526Sxy150489 * and response(Rx) to Ethernet PAUSE frames. These are just threshold 12973526Sxy150489 * settings. Flow control is enabled or disabled in the configuration 12983526Sxy150489 * file. 12993526Sxy150489 * High-water mark is set down from the top of the rx fifo (not 13003526Sxy150489 * sensitive to max_frame_size) and low-water is set just below 13013526Sxy150489 * high-water mark. 13024919Sxy150489 * The high water mark must be low enough to fit one full frame above 13034919Sxy150489 * it in the rx FIFO. Should be the lower of: 13044919Sxy150489 * 90% of the Rx FIFO size and the full Rx FIFO size minus the early 13054919Sxy150489 * receive size (assuming ERT set to E1000_ERT_2048), or the full 13064919Sxy150489 * Rx FIFO size minus one full frame. 13073526Sxy150489 */ 13084919Sxy150489 high_water = min(((pba << 10) * 9 / 10), 13098479SChenlu.Chen@Sun.COM ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574 || 13108479SChenlu.Chen@Sun.COM hw->mac.type == e1000_ich9lan || hw->mac.type == e1000_ich10lan) ? 13114919Sxy150489 ((pba << 10) - (E1000_ERT_2048 << 3)) : 13126735Scc210113 ((pba << 10) - Adapter->max_frame_size))); 13136735Scc210113 13146735Scc210113 hw->fc.high_water = high_water & 0xFFF8; 13156735Scc210113 hw->fc.low_water = hw->fc.high_water - 8; 13164919Sxy150489 13174919Sxy150489 if (hw->mac.type == e1000_80003es2lan) 13186735Scc210113 hw->fc.pause_time = 0xFFFF; 13194919Sxy150489 else 13206735Scc210113 hw->fc.pause_time = E1000_FC_PAUSE_TIME; 13216735Scc210113 hw->fc.send_xon = B_TRUE; 13223526Sxy150489 13233526Sxy150489 /* 13243526Sxy150489 * Reset the adapter hardware the second time. 13253526Sxy150489 */ 13267133Scc210113 mutex_enter(&e1000g_nvm_lock); 13277133Scc210113 result = e1000_reset_hw(hw); 13287133Scc210113 mutex_exit(&e1000g_nvm_lock); 13297133Scc210113 13307133Scc210113 if (result != E1000_SUCCESS) { 13315273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 13325273Sgl147354 goto init_fail; 13335273Sgl147354 } 13343526Sxy150489 13353526Sxy150489 /* disable wakeup control by default */ 13364919Sxy150489 if (hw->mac.type >= e1000_82544) 13374919Sxy150489 E1000_WRITE_REG(hw, E1000_WUC, 0); 13383526Sxy150489 13398178SChenlu.Chen@Sun.COM /* 13408178SChenlu.Chen@Sun.COM * MWI should be disabled on 82546. 13418178SChenlu.Chen@Sun.COM */ 13428178SChenlu.Chen@Sun.COM if (hw->mac.type == e1000_82546) 13438178SChenlu.Chen@Sun.COM e1000_pci_clear_mwi(hw); 13448178SChenlu.Chen@Sun.COM else 13458178SChenlu.Chen@Sun.COM e1000_pci_set_mwi(hw); 13463526Sxy150489 13473526Sxy150489 /* 13483526Sxy150489 * Configure/Initialize hardware 13493526Sxy150489 */ 13507133Scc210113 mutex_enter(&e1000g_nvm_lock); 13517133Scc210113 result = e1000_init_hw(hw); 13527133Scc210113 mutex_exit(&e1000g_nvm_lock); 13537133Scc210113 13547133Scc210113 if (result < E1000_SUCCESS) { 13553526Sxy150489 e1000g_log(Adapter, CE_WARN, "Initialize hw failed"); 13565273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 13573526Sxy150489 goto init_fail; 13583526Sxy150489 } 13593526Sxy150489 13607436STed.You@Sun.COM /* 13617436STed.You@Sun.COM * Restore LED settings to the default from EEPROM 13627436STed.You@Sun.COM * to meet the standard for Sun platforms. 13637436STed.You@Sun.COM */ 13648572SMin.Xu@Sun.COM if ((hw->mac.type != e1000_82541) && 13658572SMin.Xu@Sun.COM (hw->mac.type != e1000_82541_rev_2) && 13668572SMin.Xu@Sun.COM (hw->mac.type != e1000_82547) && 13678572SMin.Xu@Sun.COM (hw->mac.type != e1000_82547_rev_2)) 13688572SMin.Xu@Sun.COM (void) e1000_cleanup_led(hw); 13697436STed.You@Sun.COM 13703526Sxy150489 /* Disable Smart Power Down */ 13713526Sxy150489 phy_spd_state(hw, B_FALSE); 13723526Sxy150489 13735082Syy150190 /* Make sure driver has control */ 13745082Syy150190 e1000g_get_driver_control(hw); 13755082Syy150190 13763526Sxy150489 /* 13773526Sxy150489 * Initialize unicast addresses. 13783526Sxy150489 */ 13793526Sxy150489 e1000g_init_unicst(Adapter); 13803526Sxy150489 13813526Sxy150489 /* 13823526Sxy150489 * Setup and initialize the mctable structures. After this routine 13833526Sxy150489 * completes Multicast table will be set 13843526Sxy150489 */ 13854919Sxy150489 e1000g_setup_multicast(Adapter); 13864919Sxy150489 msec_delay(5); 13873526Sxy150489 13883526Sxy150489 /* 13893526Sxy150489 * Implement Adaptive IFS 13903526Sxy150489 */ 13913526Sxy150489 e1000_reset_adaptive(hw); 13923526Sxy150489 13933526Sxy150489 /* Setup Interrupt Throttling Register */ 13945882Syy150190 if (hw->mac.type >= e1000_82540) { 13955882Syy150190 E1000_WRITE_REG(hw, E1000_ITR, Adapter->intr_throttling_rate); 13965882Syy150190 } else 13975882Syy150190 Adapter->intr_adaptive = B_FALSE; 13983526Sxy150489 13994061Sxy150489 /* Start the timer for link setup */ 14004919Sxy150489 if (hw->mac.autoneg) 14014919Sxy150489 link_timeout = PHY_AUTO_NEG_LIMIT * drv_usectohz(100000); 14024061Sxy150489 else 14034919Sxy150489 link_timeout = PHY_FORCE_LIMIT * drv_usectohz(100000); 14044919Sxy150489 14054919Sxy150489 mutex_enter(&Adapter->link_lock); 14066735Scc210113 if (hw->phy.autoneg_wait_to_complete) { 14074061Sxy150489 Adapter->link_complete = B_TRUE; 14083526Sxy150489 } else { 14094061Sxy150489 Adapter->link_complete = B_FALSE; 14104061Sxy150489 Adapter->link_tid = timeout(e1000g_link_timer, 14114061Sxy150489 (void *)Adapter, link_timeout); 14123526Sxy150489 } 14134919Sxy150489 mutex_exit(&Adapter->link_lock); 14143526Sxy150489 14153526Sxy150489 /* Enable PCI-Ex master */ 14164919Sxy150489 if (hw->bus.type == e1000_bus_type_pci_express) { 14173526Sxy150489 e1000_enable_pciex_master(hw); 14183526Sxy150489 } 14193526Sxy150489 14205082Syy150190 /* Save the state of the phy */ 14215082Syy150190 e1000g_get_phy_state(Adapter); 14225082Syy150190 14236512Ssowmini e1000g_param_sync(Adapter); 14246512Ssowmini 14253526Sxy150489 Adapter->init_count++; 14263526Sxy150489 14275273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) { 14285273Sgl147354 goto init_fail; 14295273Sgl147354 } 14305273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 14315273Sgl147354 goto init_fail; 14325273Sgl147354 } 14335273Sgl147354 14348275SEric Cheng Adapter->poll_mode = e1000g_poll_mode; 14358275SEric Cheng 14363526Sxy150489 return (DDI_SUCCESS); 14373526Sxy150489 14383526Sxy150489 init_fail: 14395273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 14403526Sxy150489 return (DDI_FAILURE); 14413526Sxy150489 } 14423526Sxy150489 14438850SMin.Xu@Sun.COM static int 14448850SMin.Xu@Sun.COM e1000g_alloc_rx_data(struct e1000g *Adapter) 14458850SMin.Xu@Sun.COM { 14468850SMin.Xu@Sun.COM e1000g_rx_ring_t *rx_ring; 14478850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data; 14488850SMin.Xu@Sun.COM 14498850SMin.Xu@Sun.COM rx_ring = Adapter->rx_ring; 14508850SMin.Xu@Sun.COM 14518850SMin.Xu@Sun.COM rx_data = kmem_zalloc(sizeof (e1000g_rx_data_t), KM_NOSLEEP); 14528850SMin.Xu@Sun.COM 14538850SMin.Xu@Sun.COM if (rx_data == NULL) 14548850SMin.Xu@Sun.COM return (DDI_FAILURE); 14558850SMin.Xu@Sun.COM 14568850SMin.Xu@Sun.COM rx_data->priv_devi_node = Adapter->priv_devi_node; 14578850SMin.Xu@Sun.COM rx_data->rx_ring = rx_ring; 14588850SMin.Xu@Sun.COM 14598850SMin.Xu@Sun.COM mutex_init(&rx_data->freelist_lock, NULL, 14608850SMin.Xu@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 14618850SMin.Xu@Sun.COM mutex_init(&rx_data->recycle_lock, NULL, 14628850SMin.Xu@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 14638850SMin.Xu@Sun.COM 14648850SMin.Xu@Sun.COM rx_ring->rx_data = rx_data; 14658850SMin.Xu@Sun.COM 14668850SMin.Xu@Sun.COM return (DDI_SUCCESS); 14678850SMin.Xu@Sun.COM } 14688850SMin.Xu@Sun.COM 14698850SMin.Xu@Sun.COM void 14708850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(e1000g_rx_data_t *rx_data) 14718850SMin.Xu@Sun.COM { 14728850SMin.Xu@Sun.COM rx_sw_packet_t *packet, *next_packet; 14738850SMin.Xu@Sun.COM 14748850SMin.Xu@Sun.COM if (rx_data == NULL) 14758850SMin.Xu@Sun.COM return; 14768850SMin.Xu@Sun.COM 14778850SMin.Xu@Sun.COM packet = rx_data->packet_area; 14788850SMin.Xu@Sun.COM while (packet != NULL) { 14798850SMin.Xu@Sun.COM next_packet = packet->next; 14808850SMin.Xu@Sun.COM e1000g_free_rx_sw_packet(packet, B_TRUE); 14818850SMin.Xu@Sun.COM packet = next_packet; 14828850SMin.Xu@Sun.COM } 14838850SMin.Xu@Sun.COM rx_data->packet_area = NULL; 14848850SMin.Xu@Sun.COM } 14858850SMin.Xu@Sun.COM 14868850SMin.Xu@Sun.COM void 14878850SMin.Xu@Sun.COM e1000g_free_rx_data(e1000g_rx_data_t *rx_data) 14888850SMin.Xu@Sun.COM { 14898850SMin.Xu@Sun.COM if (rx_data == NULL) 14908850SMin.Xu@Sun.COM return; 14918850SMin.Xu@Sun.COM 14928850SMin.Xu@Sun.COM mutex_destroy(&rx_data->freelist_lock); 14938850SMin.Xu@Sun.COM mutex_destroy(&rx_data->recycle_lock); 14948850SMin.Xu@Sun.COM 14958850SMin.Xu@Sun.COM kmem_free(rx_data, sizeof (e1000g_rx_data_t)); 14968850SMin.Xu@Sun.COM } 14978850SMin.Xu@Sun.COM 14983526Sxy150489 /* 14993526Sxy150489 * Check if the link is up 15003526Sxy150489 */ 15013526Sxy150489 static boolean_t 15023526Sxy150489 e1000g_link_up(struct e1000g *Adapter) 15033526Sxy150489 { 15043526Sxy150489 struct e1000_hw *hw; 15053526Sxy150489 boolean_t link_up; 15063526Sxy150489 15074919Sxy150489 hw = &Adapter->shared; 15083526Sxy150489 15097426SChenliang.Xu@Sun.COM (void) e1000_check_for_link(hw); 15103526Sxy150489 15114919Sxy150489 if ((E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU) || 15124919Sxy150489 ((!hw->mac.get_link_status) && (hw->mac.type == e1000_82543)) || 15136735Scc210113 ((hw->phy.media_type == e1000_media_type_internal_serdes) && 15144919Sxy150489 (hw->mac.serdes_has_link))) { 15153526Sxy150489 link_up = B_TRUE; 15163526Sxy150489 } else { 15173526Sxy150489 link_up = B_FALSE; 15183526Sxy150489 } 15193526Sxy150489 15203526Sxy150489 return (link_up); 15213526Sxy150489 } 15223526Sxy150489 15233526Sxy150489 static void 15243526Sxy150489 e1000g_m_ioctl(void *arg, queue_t *q, mblk_t *mp) 15253526Sxy150489 { 15263526Sxy150489 struct iocblk *iocp; 15273526Sxy150489 struct e1000g *e1000gp; 15283526Sxy150489 enum ioc_reply status; 15297426SChenliang.Xu@Sun.COM 15307426SChenliang.Xu@Sun.COM iocp = (struct iocblk *)(uintptr_t)mp->b_rptr; 15313526Sxy150489 iocp->ioc_error = 0; 15323526Sxy150489 e1000gp = (struct e1000g *)arg; 15333526Sxy150489 15343526Sxy150489 ASSERT(e1000gp); 15353526Sxy150489 if (e1000gp == NULL) { 15363526Sxy150489 miocnak(q, mp, 0, EINVAL); 15373526Sxy150489 return; 15383526Sxy150489 } 15393526Sxy150489 15408479SChenlu.Chen@Sun.COM rw_enter(&e1000gp->chip_lock, RW_READER); 15418479SChenlu.Chen@Sun.COM if (e1000gp->e1000g_state & E1000G_SUSPENDED) { 15428479SChenlu.Chen@Sun.COM rw_exit(&e1000gp->chip_lock); 15438479SChenlu.Chen@Sun.COM miocnak(q, mp, 0, EINVAL); 15448479SChenlu.Chen@Sun.COM return; 15458479SChenlu.Chen@Sun.COM } 15468479SChenlu.Chen@Sun.COM rw_exit(&e1000gp->chip_lock); 15478479SChenlu.Chen@Sun.COM 15483526Sxy150489 switch (iocp->ioc_cmd) { 15493526Sxy150489 15503526Sxy150489 case LB_GET_INFO_SIZE: 15513526Sxy150489 case LB_GET_INFO: 15523526Sxy150489 case LB_GET_MODE: 15533526Sxy150489 case LB_SET_MODE: 15543526Sxy150489 status = e1000g_loopback_ioctl(e1000gp, iocp, mp); 15553526Sxy150489 break; 15563526Sxy150489 15573526Sxy150489 15584919Sxy150489 #ifdef E1000G_DEBUG 15593526Sxy150489 case E1000G_IOC_REG_PEEK: 15603526Sxy150489 case E1000G_IOC_REG_POKE: 15613526Sxy150489 status = e1000g_pp_ioctl(e1000gp, iocp, mp); 15623526Sxy150489 break; 15633526Sxy150489 case E1000G_IOC_CHIP_RESET: 15643526Sxy150489 e1000gp->reset_count++; 15657656SSherry.Moore@Sun.COM if (e1000g_reset_adapter(e1000gp)) 15663526Sxy150489 status = IOC_ACK; 15673526Sxy150489 else 15683526Sxy150489 status = IOC_INVAL; 15693526Sxy150489 break; 15704919Sxy150489 #endif 15713526Sxy150489 default: 15723526Sxy150489 status = IOC_INVAL; 15733526Sxy150489 break; 15743526Sxy150489 } 15753526Sxy150489 15763526Sxy150489 /* 15773526Sxy150489 * Decide how to reply 15783526Sxy150489 */ 15793526Sxy150489 switch (status) { 15803526Sxy150489 default: 15813526Sxy150489 case IOC_INVAL: 15823526Sxy150489 /* 15833526Sxy150489 * Error, reply with a NAK and EINVAL or the specified error 15843526Sxy150489 */ 15853526Sxy150489 miocnak(q, mp, 0, iocp->ioc_error == 0 ? 15864349Sxy150489 EINVAL : iocp->ioc_error); 15873526Sxy150489 break; 15883526Sxy150489 15893526Sxy150489 case IOC_DONE: 15903526Sxy150489 /* 15913526Sxy150489 * OK, reply already sent 15923526Sxy150489 */ 15933526Sxy150489 break; 15943526Sxy150489 15953526Sxy150489 case IOC_ACK: 15963526Sxy150489 /* 15973526Sxy150489 * OK, reply with an ACK 15983526Sxy150489 */ 15993526Sxy150489 miocack(q, mp, 0, 0); 16003526Sxy150489 break; 16013526Sxy150489 16023526Sxy150489 case IOC_REPLY: 16033526Sxy150489 /* 16043526Sxy150489 * OK, send prepared reply as ACK or NAK 16053526Sxy150489 */ 16063526Sxy150489 mp->b_datap->db_type = iocp->ioc_error == 0 ? 16074349Sxy150489 M_IOCACK : M_IOCNAK; 16083526Sxy150489 qreply(q, mp); 16093526Sxy150489 break; 16103526Sxy150489 } 16113526Sxy150489 } 16123526Sxy150489 16138275SEric Cheng /* 16148275SEric Cheng * The default value of e1000g_poll_mode == 0 assumes that the NIC is 16158275SEric Cheng * capable of supporting only one interrupt and we shouldn't disable 16168275SEric Cheng * the physical interrupt. In this case we let the interrupt come and 16178275SEric Cheng * we queue the packets in the rx ring itself in case we are in polling 16188275SEric Cheng * mode (better latency but slightly lower performance and a very 16198275SEric Cheng * high intrrupt count in mpstat which is harmless). 16208275SEric Cheng * 16218275SEric Cheng * e1000g_poll_mode == 1 assumes that we have per Rx ring interrupt 16228275SEric Cheng * which can be disabled in poll mode. This gives better overall 16238275SEric Cheng * throughput (compared to the mode above), shows very low interrupt 16248275SEric Cheng * count but has slightly higher latency since we pick the packets when 16258275SEric Cheng * the poll thread does polling. 16268275SEric Cheng * 16278275SEric Cheng * Currently, this flag should be enabled only while doing performance 16288275SEric Cheng * measurement or when it can be guaranteed that entire NIC going 16298275SEric Cheng * in poll mode will not harm any traffic like cluster heartbeat etc. 16308275SEric Cheng */ 16318275SEric Cheng int e1000g_poll_mode = 0; 16328275SEric Cheng 16338275SEric Cheng /* 16348275SEric Cheng * Called from the upper layers when driver is in polling mode to 16358275SEric Cheng * pick up any queued packets. Care should be taken to not block 16368275SEric Cheng * this thread. 16378275SEric Cheng */ 16388275SEric Cheng static mblk_t *e1000g_poll_ring(void *arg, int bytes_to_pickup) 16398275SEric Cheng { 16408275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)arg; 16418275SEric Cheng mblk_t *mp = NULL; 16428275SEric Cheng mblk_t *tail; 16438275SEric Cheng struct e1000g *adapter; 16448275SEric Cheng 16458275SEric Cheng adapter = rx_ring->adapter; 16468275SEric Cheng 16478479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER); 16488479SChenlu.Chen@Sun.COM 16498479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) { 16508479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 16518479SChenlu.Chen@Sun.COM return (NULL); 16528479SChenlu.Chen@Sun.COM } 16538479SChenlu.Chen@Sun.COM 16548275SEric Cheng mutex_enter(&rx_ring->rx_lock); 16558833SVenu.Iyer@Sun.COM mp = e1000g_receive(rx_ring, &tail, bytes_to_pickup); 16568275SEric Cheng mutex_exit(&rx_ring->rx_lock); 16578479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 16588275SEric Cheng return (mp); 16598275SEric Cheng } 16608275SEric Cheng 16613526Sxy150489 static int 16623526Sxy150489 e1000g_m_start(void *arg) 16633526Sxy150489 { 16643526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 16653526Sxy150489 16668479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 16678479SChenlu.Chen@Sun.COM 16688479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 16698479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 16708479SChenlu.Chen@Sun.COM return (ECANCELED); 16718479SChenlu.Chen@Sun.COM } 16728479SChenlu.Chen@Sun.COM 16738479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_TRUE) != DDI_SUCCESS) { 16748479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 16758479SChenlu.Chen@Sun.COM return (ENOTACTIVE); 16768479SChenlu.Chen@Sun.COM } 16778479SChenlu.Chen@Sun.COM 16788479SChenlu.Chen@Sun.COM Adapter->e1000g_state |= E1000G_STARTED; 16798479SChenlu.Chen@Sun.COM 16808479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 16818479SChenlu.Chen@Sun.COM 16828479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */ 16838479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter); 16848479SChenlu.Chen@Sun.COM 16858479SChenlu.Chen@Sun.COM return (0); 16863526Sxy150489 } 16873526Sxy150489 16883526Sxy150489 static int 16894919Sxy150489 e1000g_start(struct e1000g *Adapter, boolean_t global) 16903526Sxy150489 { 16918850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data; 16928850SMin.Xu@Sun.COM 16934919Sxy150489 if (global) { 16948850SMin.Xu@Sun.COM if (e1000g_alloc_rx_data(Adapter) != DDI_SUCCESS) { 16958850SMin.Xu@Sun.COM e1000g_log(Adapter, CE_WARN, "Allocate rx data failed"); 16968850SMin.Xu@Sun.COM goto start_fail; 16978850SMin.Xu@Sun.COM } 16988850SMin.Xu@Sun.COM 16994919Sxy150489 /* Allocate dma resources for descriptors and buffers */ 17004919Sxy150489 if (e1000g_alloc_dma_resources(Adapter) != DDI_SUCCESS) { 17014919Sxy150489 e1000g_log(Adapter, CE_WARN, 17024919Sxy150489 "Alloc DMA resources failed"); 17038850SMin.Xu@Sun.COM goto start_fail; 17044919Sxy150489 } 17054919Sxy150489 Adapter->rx_buffer_setup = B_FALSE; 17064919Sxy150489 } 17074919Sxy150489 17083526Sxy150489 if (!(Adapter->attach_progress & ATTACH_PROGRESS_INIT)) { 17093526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) { 17103526Sxy150489 e1000g_log(Adapter, CE_WARN, 17113526Sxy150489 "Adapter initialization failed"); 17128850SMin.Xu@Sun.COM goto start_fail; 17133526Sxy150489 } 17143526Sxy150489 } 17153526Sxy150489 17164919Sxy150489 /* Setup and initialize the transmit structures */ 17174919Sxy150489 e1000g_tx_setup(Adapter); 17184919Sxy150489 msec_delay(5); 17194919Sxy150489 17204919Sxy150489 /* Setup and initialize the receive structures */ 17214919Sxy150489 e1000g_rx_setup(Adapter); 17224919Sxy150489 msec_delay(5); 17234919Sxy150489 17247722SShuguo.Yang@Sun.COM /* Restore the e1000g promiscuous mode */ 17257722SShuguo.Yang@Sun.COM e1000g_restore_promisc(Adapter); 17267722SShuguo.Yang@Sun.COM 17274919Sxy150489 e1000g_mask_interrupt(Adapter); 17283526Sxy150489 17298479SChenlu.Chen@Sun.COM Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 17308479SChenlu.Chen@Sun.COM 17315273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 17325273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 17338850SMin.Xu@Sun.COM goto start_fail; 17348479SChenlu.Chen@Sun.COM } 17358479SChenlu.Chen@Sun.COM 17368479SChenlu.Chen@Sun.COM return (DDI_SUCCESS); 17378850SMin.Xu@Sun.COM 17388850SMin.Xu@Sun.COM start_fail: 17398850SMin.Xu@Sun.COM rx_data = Adapter->rx_ring->rx_data; 17408850SMin.Xu@Sun.COM 17418850SMin.Xu@Sun.COM if (global) { 17428850SMin.Xu@Sun.COM e1000g_release_dma_resources(Adapter); 17438850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(rx_data); 17448850SMin.Xu@Sun.COM e1000g_free_rx_data(rx_data); 17458850SMin.Xu@Sun.COM } 17468850SMin.Xu@Sun.COM 17478850SMin.Xu@Sun.COM mutex_enter(&e1000g_nvm_lock); 17488850SMin.Xu@Sun.COM (void) e1000_reset_hw(&Adapter->shared); 17498850SMin.Xu@Sun.COM mutex_exit(&e1000g_nvm_lock); 17508850SMin.Xu@Sun.COM 17518850SMin.Xu@Sun.COM return (DDI_FAILURE); 17523526Sxy150489 } 17533526Sxy150489 17543526Sxy150489 static void 17553526Sxy150489 e1000g_m_stop(void *arg) 17563526Sxy150489 { 17573526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 17583526Sxy150489 17598479SChenlu.Chen@Sun.COM /* Drain tx sessions */ 17608479SChenlu.Chen@Sun.COM (void) e1000g_tx_drain(Adapter); 17618479SChenlu.Chen@Sun.COM 17628479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 17638479SChenlu.Chen@Sun.COM 17648479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 17658479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 17668479SChenlu.Chen@Sun.COM return; 17678479SChenlu.Chen@Sun.COM } 17688479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_STARTED; 17694919Sxy150489 e1000g_stop(Adapter, B_TRUE); 17708479SChenlu.Chen@Sun.COM 17718479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 17728479SChenlu.Chen@Sun.COM 17738479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */ 17748479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter); 17758479SChenlu.Chen@Sun.COM stop_link_timer(Adapter); 17768479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring); 17773526Sxy150489 } 17783526Sxy150489 17793526Sxy150489 static void 17804919Sxy150489 e1000g_stop(struct e1000g *Adapter, boolean_t global) 17813526Sxy150489 { 17828850SMin.Xu@Sun.COM private_devi_list_t *devi_node; 17838850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data; 17847133Scc210113 int result; 17857133Scc210113 17863526Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_INIT; 17873526Sxy150489 17883526Sxy150489 /* Stop the chip and release pending resources */ 17893526Sxy150489 17907607STed.You@Sun.COM /* Tell firmware driver is no longer in control */ 17917607STed.You@Sun.COM e1000g_release_driver_control(&Adapter->shared); 17927607STed.You@Sun.COM 17934919Sxy150489 e1000g_clear_all_interrupts(Adapter); 17947133Scc210113 17957133Scc210113 mutex_enter(&e1000g_nvm_lock); 17967133Scc210113 result = e1000_reset_hw(&Adapter->shared); 17977133Scc210113 mutex_exit(&e1000g_nvm_lock); 17987133Scc210113 17997133Scc210113 if (result != E1000_SUCCESS) { 18005273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE); 18015273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 18025273Sgl147354 } 18033526Sxy150489 18043526Sxy150489 /* Release resources still held by the TX descriptors */ 18054919Sxy150489 e1000g_tx_clean(Adapter); 18064061Sxy150489 18075273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 18085273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 18095273Sgl147354 18104061Sxy150489 /* Clean the pending rx jumbo packet fragment */ 18114919Sxy150489 e1000g_rx_clean(Adapter); 18124061Sxy150489 18138850SMin.Xu@Sun.COM if (global) { 18144919Sxy150489 e1000g_release_dma_resources(Adapter); 18158850SMin.Xu@Sun.COM 18168850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock); 18178850SMin.Xu@Sun.COM rx_data = Adapter->rx_ring->rx_data; 18188850SMin.Xu@Sun.COM rx_data->flag |= E1000G_RX_STOPPED; 18198850SMin.Xu@Sun.COM 18208850SMin.Xu@Sun.COM if (rx_data->pending_count == 0) { 18218850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(rx_data); 18228850SMin.Xu@Sun.COM e1000g_free_rx_data(rx_data); 18238850SMin.Xu@Sun.COM } else { 18248850SMin.Xu@Sun.COM devi_node = rx_data->priv_devi_node; 18258850SMin.Xu@Sun.COM if (devi_node != NULL) 18268850SMin.Xu@Sun.COM atomic_inc_32(&devi_node->pending_rx_count); 18278850SMin.Xu@Sun.COM else 18288850SMin.Xu@Sun.COM atomic_inc_32(&Adapter->pending_rx_count); 18298850SMin.Xu@Sun.COM } 18308850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock); 18318850SMin.Xu@Sun.COM } 18329190SMin.Xu@Sun.COM 18339190SMin.Xu@Sun.COM if (Adapter->link_state == LINK_STATE_UP) { 18349190SMin.Xu@Sun.COM Adapter->link_state = LINK_STATE_UNKNOWN; 18359190SMin.Xu@Sun.COM mac_link_update(Adapter->mh, Adapter->link_state); 18369190SMin.Xu@Sun.COM } 18374061Sxy150489 } 18384061Sxy150489 18394061Sxy150489 static void 18404919Sxy150489 e1000g_rx_clean(struct e1000g *Adapter) 18414919Sxy150489 { 18428850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data = Adapter->rx_ring->rx_data; 18438850SMin.Xu@Sun.COM 18448850SMin.Xu@Sun.COM if (rx_data == NULL) 18458850SMin.Xu@Sun.COM return; 18468850SMin.Xu@Sun.COM 18478850SMin.Xu@Sun.COM if (rx_data->rx_mblk != NULL) { 18488850SMin.Xu@Sun.COM freemsg(rx_data->rx_mblk); 18498850SMin.Xu@Sun.COM rx_data->rx_mblk = NULL; 18508850SMin.Xu@Sun.COM rx_data->rx_mblk_tail = NULL; 18518850SMin.Xu@Sun.COM rx_data->rx_mblk_len = 0; 18524919Sxy150489 } 18534919Sxy150489 } 18544919Sxy150489 18554919Sxy150489 static void 18564919Sxy150489 e1000g_tx_clean(struct e1000g *Adapter) 18574061Sxy150489 { 18584061Sxy150489 e1000g_tx_ring_t *tx_ring; 18594919Sxy150489 p_tx_sw_packet_t packet; 18604061Sxy150489 mblk_t *mp; 18614061Sxy150489 mblk_t *nmp; 18624061Sxy150489 uint32_t packet_count; 18634061Sxy150489 18644061Sxy150489 tx_ring = Adapter->tx_ring; 18654061Sxy150489 18663526Sxy150489 /* 18673526Sxy150489 * Here we don't need to protect the lists using 18683526Sxy150489 * the usedlist_lock and freelist_lock, for they 18693526Sxy150489 * have been protected by the chip_lock. 18703526Sxy150489 */ 18713526Sxy150489 mp = NULL; 18723526Sxy150489 nmp = NULL; 18734061Sxy150489 packet_count = 0; 18744919Sxy150489 packet = (p_tx_sw_packet_t)QUEUE_GET_HEAD(&tx_ring->used_list); 18753526Sxy150489 while (packet != NULL) { 18763526Sxy150489 if (packet->mp != NULL) { 18773526Sxy150489 /* Assemble the message chain */ 18783526Sxy150489 if (mp == NULL) { 18793526Sxy150489 mp = packet->mp; 18803526Sxy150489 nmp = packet->mp; 18813526Sxy150489 } else { 18823526Sxy150489 nmp->b_next = packet->mp; 18833526Sxy150489 nmp = packet->mp; 18843526Sxy150489 } 18853526Sxy150489 /* Disconnect the message from the sw packet */ 18863526Sxy150489 packet->mp = NULL; 18873526Sxy150489 } 18883526Sxy150489 18894919Sxy150489 e1000g_free_tx_swpkt(packet); 18904061Sxy150489 packet_count++; 18913526Sxy150489 18924919Sxy150489 packet = (p_tx_sw_packet_t) 18933526Sxy150489 QUEUE_GET_NEXT(&tx_ring->used_list, &packet->Link); 18943526Sxy150489 } 18953526Sxy150489 18965882Syy150190 if (mp != NULL) 18975882Syy150190 freemsgchain(mp); 18984061Sxy150489 18994061Sxy150489 if (packet_count > 0) { 19004061Sxy150489 QUEUE_APPEND(&tx_ring->free_list, &tx_ring->used_list); 19014061Sxy150489 QUEUE_INIT_LIST(&tx_ring->used_list); 19024061Sxy150489 19034061Sxy150489 /* Setup TX descriptor pointers */ 19044061Sxy150489 tx_ring->tbd_next = tx_ring->tbd_first; 19054061Sxy150489 tx_ring->tbd_oldest = tx_ring->tbd_first; 19064061Sxy150489 19074061Sxy150489 /* Setup our HW Tx Head & Tail descriptor pointers */ 19086735Scc210113 E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0); 19096735Scc210113 E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0); 19103526Sxy150489 } 19113526Sxy150489 } 19123526Sxy150489 19133526Sxy150489 static boolean_t 19143526Sxy150489 e1000g_tx_drain(struct e1000g *Adapter) 19153526Sxy150489 { 19163526Sxy150489 int i; 19173526Sxy150489 boolean_t done; 19183526Sxy150489 e1000g_tx_ring_t *tx_ring; 19193526Sxy150489 19203526Sxy150489 tx_ring = Adapter->tx_ring; 19213526Sxy150489 19223526Sxy150489 /* Allow up to 'wsdraintime' for pending xmit's to complete. */ 19234919Sxy150489 for (i = 0; i < TX_DRAIN_TIME; i++) { 19243526Sxy150489 mutex_enter(&tx_ring->usedlist_lock); 19253526Sxy150489 done = IS_QUEUE_EMPTY(&tx_ring->used_list); 19263526Sxy150489 mutex_exit(&tx_ring->usedlist_lock); 19273526Sxy150489 19283526Sxy150489 if (done) 19293526Sxy150489 break; 19303526Sxy150489 19313526Sxy150489 msec_delay(1); 19323526Sxy150489 } 19333526Sxy150489 19343526Sxy150489 return (done); 19353526Sxy150489 } 19363526Sxy150489 19373526Sxy150489 static boolean_t 19383526Sxy150489 e1000g_rx_drain(struct e1000g *Adapter) 19393526Sxy150489 { 19408850SMin.Xu@Sun.COM int i; 19413526Sxy150489 boolean_t done; 19423526Sxy150489 19438850SMin.Xu@Sun.COM /* 19448850SMin.Xu@Sun.COM * Allow up to RX_DRAIN_TIME for pending received packets to complete. 19458850SMin.Xu@Sun.COM */ 19468850SMin.Xu@Sun.COM for (i = 0; i < RX_DRAIN_TIME; i++) { 19478850SMin.Xu@Sun.COM done = (Adapter->pending_rx_count == 0); 19488850SMin.Xu@Sun.COM 19498850SMin.Xu@Sun.COM if (done) 19508850SMin.Xu@Sun.COM break; 19518850SMin.Xu@Sun.COM 19528850SMin.Xu@Sun.COM msec_delay(1); 19538850SMin.Xu@Sun.COM } 19543526Sxy150489 19553526Sxy150489 return (done); 19563526Sxy150489 } 19573526Sxy150489 19587656SSherry.Moore@Sun.COM static boolean_t 19597656SSherry.Moore@Sun.COM e1000g_reset_adapter(struct e1000g *Adapter) 19603526Sxy150489 { 19618479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */ 19628479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter); 19638479SChenlu.Chen@Sun.COM stop_link_timer(Adapter); 19648479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring); 19658479SChenlu.Chen@Sun.COM 19668479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 19678479SChenlu.Chen@Sun.COM 1968*10434SGuoqing.Zhu@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) { 1969*10434SGuoqing.Zhu@Sun.COM rw_exit(&Adapter->chip_lock); 1970*10434SGuoqing.Zhu@Sun.COM return (B_TRUE); 1971*10434SGuoqing.Zhu@Sun.COM } 1972*10434SGuoqing.Zhu@Sun.COM 19734919Sxy150489 e1000g_stop(Adapter, B_FALSE); 19744919Sxy150489 19758479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_FALSE) != DDI_SUCCESS) { 19768479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 19773526Sxy150489 e1000g_log(Adapter, CE_WARN, "Reset failed"); 19788479SChenlu.Chen@Sun.COM return (B_FALSE); 19798479SChenlu.Chen@Sun.COM } 19808479SChenlu.Chen@Sun.COM 19818479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 19828479SChenlu.Chen@Sun.COM 19838479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */ 19848479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter); 19853526Sxy150489 19863526Sxy150489 return (B_TRUE); 19873526Sxy150489 } 19883526Sxy150489 19895273Sgl147354 boolean_t 19905273Sgl147354 e1000g_global_reset(struct e1000g *Adapter) 19915273Sgl147354 { 19928479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */ 19938479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter); 19948479SChenlu.Chen@Sun.COM stop_link_timer(Adapter); 19958479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring); 19968479SChenlu.Chen@Sun.COM 19978479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 19988479SChenlu.Chen@Sun.COM 19995273Sgl147354 e1000g_stop(Adapter, B_TRUE); 20005273Sgl147354 20015273Sgl147354 Adapter->init_count = 0; 20025273Sgl147354 20038479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_TRUE) != DDI_SUCCESS) { 20048479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 20055273Sgl147354 e1000g_log(Adapter, CE_WARN, "Reset failed"); 20065273Sgl147354 return (B_FALSE); 20075273Sgl147354 } 20085273Sgl147354 20098479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 20108479SChenlu.Chen@Sun.COM 20118479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */ 20128479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter); 20138479SChenlu.Chen@Sun.COM 20145273Sgl147354 return (B_TRUE); 20155273Sgl147354 } 20165273Sgl147354 20173526Sxy150489 /* 20184919Sxy150489 * e1000g_intr_pciexpress - ISR for PCI Express chipsets 20194919Sxy150489 * 20204919Sxy150489 * This interrupt service routine is for PCI-Express adapters. 20214919Sxy150489 * The ICR contents is valid only when the E1000_ICR_INT_ASSERTED 20224919Sxy150489 * bit is set. 20233526Sxy150489 */ 20243526Sxy150489 static uint_t 20253526Sxy150489 e1000g_intr_pciexpress(caddr_t arg) 20263526Sxy150489 { 20273526Sxy150489 struct e1000g *Adapter; 20284919Sxy150489 uint32_t icr; 20293526Sxy150489 20307426SChenliang.Xu@Sun.COM Adapter = (struct e1000g *)(uintptr_t)arg; 20314919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 20324919Sxy150489 20335273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 20345273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 20355273Sgl147354 20364919Sxy150489 if (icr & E1000_ICR_INT_ASSERTED) { 20373526Sxy150489 /* 20383526Sxy150489 * E1000_ICR_INT_ASSERTED bit was set: 20393526Sxy150489 * Read(Clear) the ICR, claim this interrupt, 20403526Sxy150489 * look for work to do. 20413526Sxy150489 */ 20424919Sxy150489 e1000g_intr_work(Adapter, icr); 20433526Sxy150489 return (DDI_INTR_CLAIMED); 20443526Sxy150489 } else { 20453526Sxy150489 /* 20463526Sxy150489 * E1000_ICR_INT_ASSERTED bit was not set: 20473526Sxy150489 * Don't claim this interrupt, return immediately. 20483526Sxy150489 */ 20493526Sxy150489 return (DDI_INTR_UNCLAIMED); 20503526Sxy150489 } 20513526Sxy150489 } 20523526Sxy150489 20533526Sxy150489 /* 20544919Sxy150489 * e1000g_intr - ISR for PCI/PCI-X chipsets 20554919Sxy150489 * 20564919Sxy150489 * This interrupt service routine is for PCI/PCI-X adapters. 20574919Sxy150489 * We check the ICR contents no matter the E1000_ICR_INT_ASSERTED 20584919Sxy150489 * bit is set or not. 20593526Sxy150489 */ 20603526Sxy150489 static uint_t 20613526Sxy150489 e1000g_intr(caddr_t arg) 20623526Sxy150489 { 20633526Sxy150489 struct e1000g *Adapter; 20644919Sxy150489 uint32_t icr; 20653526Sxy150489 20667426SChenliang.Xu@Sun.COM Adapter = (struct e1000g *)(uintptr_t)arg; 20674919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 20684919Sxy150489 20695273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 20705273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 20715273Sgl147354 20724919Sxy150489 if (icr) { 20733526Sxy150489 /* 20743526Sxy150489 * Any bit was set in ICR: 20753526Sxy150489 * Read(Clear) the ICR, claim this interrupt, 20763526Sxy150489 * look for work to do. 20773526Sxy150489 */ 20784919Sxy150489 e1000g_intr_work(Adapter, icr); 20793526Sxy150489 return (DDI_INTR_CLAIMED); 20803526Sxy150489 } else { 20813526Sxy150489 /* 20823526Sxy150489 * No bit was set in ICR: 20833526Sxy150489 * Don't claim this interrupt, return immediately. 20843526Sxy150489 */ 20853526Sxy150489 return (DDI_INTR_UNCLAIMED); 20863526Sxy150489 } 20873526Sxy150489 } 20883526Sxy150489 20893526Sxy150489 /* 20904919Sxy150489 * e1000g_intr_work - actual processing of ISR 20914919Sxy150489 * 20924919Sxy150489 * Read(clear) the ICR contents and call appropriate interrupt 20934919Sxy150489 * processing routines. 20943526Sxy150489 */ 20953526Sxy150489 static void 20964919Sxy150489 e1000g_intr_work(struct e1000g *Adapter, uint32_t icr) 20973526Sxy150489 { 20985882Syy150190 struct e1000_hw *hw; 20995882Syy150190 hw = &Adapter->shared; 21005882Syy150190 e1000g_tx_ring_t *tx_ring = Adapter->tx_ring; 21015882Syy150190 21025882Syy150190 Adapter->rx_pkt_cnt = 0; 21035882Syy150190 Adapter->tx_pkt_cnt = 0; 21045882Syy150190 21054919Sxy150489 rw_enter(&Adapter->chip_lock, RW_READER); 21068479SChenlu.Chen@Sun.COM 21078479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 21088479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 21098479SChenlu.Chen@Sun.COM return; 21108479SChenlu.Chen@Sun.COM } 21114919Sxy150489 /* 21128479SChenlu.Chen@Sun.COM * Here we need to check the "e1000g_state" flag within the chip_lock to 21134919Sxy150489 * ensure the receive routine will not execute when the adapter is 21144919Sxy150489 * being reset. 21154919Sxy150489 */ 21168479SChenlu.Chen@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) { 21174919Sxy150489 rw_exit(&Adapter->chip_lock); 21184919Sxy150489 return; 21194919Sxy150489 } 21204919Sxy150489 21214919Sxy150489 if (icr & E1000_ICR_RXT0) { 21228833SVenu.Iyer@Sun.COM mblk_t *mp = NULL; 21238833SVenu.Iyer@Sun.COM mblk_t *tail = NULL; 21248275SEric Cheng e1000g_rx_ring_t *rx_ring; 21258275SEric Cheng 21268275SEric Cheng rx_ring = Adapter->rx_ring; 21278275SEric Cheng mutex_enter(&rx_ring->rx_lock); 21288275SEric Cheng /* 21298833SVenu.Iyer@Sun.COM * Sometimes with legacy interrupts, it possible that 21308833SVenu.Iyer@Sun.COM * there is a single interrupt for Rx/Tx. In which 21318833SVenu.Iyer@Sun.COM * case, if poll flag is set, we shouldn't really 21328833SVenu.Iyer@Sun.COM * be doing Rx processing. 21338275SEric Cheng */ 21348833SVenu.Iyer@Sun.COM if (!rx_ring->poll_flag) 21358833SVenu.Iyer@Sun.COM mp = e1000g_receive(rx_ring, &tail, 21368833SVenu.Iyer@Sun.COM E1000G_CHAIN_NO_LIMIT); 21378833SVenu.Iyer@Sun.COM mutex_exit(&rx_ring->rx_lock); 21384919Sxy150489 rw_exit(&Adapter->chip_lock); 21398833SVenu.Iyer@Sun.COM if (mp != NULL) 21408275SEric Cheng mac_rx_ring(Adapter->mh, rx_ring->mrh, 21418833SVenu.Iyer@Sun.COM mp, rx_ring->ring_gen_num); 21424919Sxy150489 } else 21434919Sxy150489 rw_exit(&Adapter->chip_lock); 21443526Sxy150489 21455882Syy150190 if (icr & E1000_ICR_TXDW) { 21465882Syy150190 if (!Adapter->tx_intr_enable) 21475882Syy150190 e1000g_clear_tx_interrupt(Adapter); 21485882Syy150190 21495882Syy150190 /* Recycle the tx descriptors */ 21505882Syy150190 rw_enter(&Adapter->chip_lock, RW_READER); 21517426SChenliang.Xu@Sun.COM (void) e1000g_recycle(tx_ring); 21525882Syy150190 E1000G_DEBUG_STAT(tx_ring->stat_recycle_intr); 21535882Syy150190 rw_exit(&Adapter->chip_lock); 21545882Syy150190 21555882Syy150190 if (tx_ring->resched_needed && 21565882Syy150190 (tx_ring->tbd_avail > DEFAULT_TX_UPDATE_THRESHOLD)) { 21575882Syy150190 tx_ring->resched_needed = B_FALSE; 21585882Syy150190 mac_tx_update(Adapter->mh); 21595882Syy150190 E1000G_STAT(tx_ring->stat_reschedule); 21605882Syy150190 } 21615882Syy150190 } 21625882Syy150190 21633526Sxy150489 /* 21643526Sxy150489 * The Receive Sequence errors RXSEQ and the link status change LSC 21653526Sxy150489 * are checked to detect that the cable has been pulled out. For 21663526Sxy150489 * the Wiseman 2.0 silicon, the receive sequence errors interrupt 21673526Sxy150489 * are an indication that cable is not connected. 21683526Sxy150489 */ 21694919Sxy150489 if ((icr & E1000_ICR_RXSEQ) || 21704919Sxy150489 (icr & E1000_ICR_LSC) || 21714919Sxy150489 (icr & E1000_ICR_GPI_EN1)) { 21724061Sxy150489 boolean_t link_changed; 21734061Sxy150489 timeout_id_t tid = 0; 21743526Sxy150489 21754919Sxy150489 stop_watchdog_timer(Adapter); 21764919Sxy150489 21775082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER); 21785082Syy150190 21795082Syy150190 /* 21805082Syy150190 * Because we got a link-status-change interrupt, force 21815082Syy150190 * e1000_check_for_link() to look at phy 21825082Syy150190 */ 21835082Syy150190 Adapter->shared.mac.get_link_status = B_TRUE; 21845082Syy150190 21854061Sxy150489 /* e1000g_link_check takes care of link status change */ 21864061Sxy150489 link_changed = e1000g_link_check(Adapter); 21875082Syy150190 21885082Syy150190 /* Get new phy state */ 21895082Syy150190 e1000g_get_phy_state(Adapter); 21905082Syy150190 21914061Sxy150489 /* 21924061Sxy150489 * If the link timer has not timed out, we'll not notify 21934919Sxy150489 * the upper layer with any link state until the link is up. 21944061Sxy150489 */ 21954061Sxy150489 if (link_changed && !Adapter->link_complete) { 21964061Sxy150489 if (Adapter->link_state == LINK_STATE_UP) { 21975082Syy150190 mutex_enter(&Adapter->link_lock); 21984061Sxy150489 Adapter->link_complete = B_TRUE; 21994061Sxy150489 tid = Adapter->link_tid; 22004061Sxy150489 Adapter->link_tid = 0; 22015082Syy150190 mutex_exit(&Adapter->link_lock); 22024061Sxy150489 } else { 22034061Sxy150489 link_changed = B_FALSE; 22044061Sxy150489 } 22054061Sxy150489 } 22065082Syy150190 rw_exit(&Adapter->chip_lock); 22073526Sxy150489 22084061Sxy150489 if (link_changed) { 22094061Sxy150489 if (tid != 0) 22104061Sxy150489 (void) untimeout(tid); 22114061Sxy150489 22124139Sxy150489 /* 22134139Sxy150489 * Workaround for esb2. Data stuck in fifo on a link 22147133Scc210113 * down event. Stop receiver here and reset in watchdog. 22154139Sxy150489 */ 22164139Sxy150489 if ((Adapter->link_state == LINK_STATE_DOWN) && 22177133Scc210113 (Adapter->shared.mac.type == e1000_80003es2lan)) { 22187133Scc210113 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL); 22197133Scc210113 E1000_WRITE_REG(hw, E1000_RCTL, 22207133Scc210113 rctl & ~E1000_RCTL_EN); 22217133Scc210113 e1000g_log(Adapter, CE_WARN, 22227133Scc210113 "ESB2 receiver disabled"); 22237133Scc210113 Adapter->esb2_workaround = B_TRUE; 22247133Scc210113 } 22258850SMin.Xu@Sun.COM if (!Adapter->reset_flag) 22268850SMin.Xu@Sun.COM mac_link_update(Adapter->mh, 22278850SMin.Xu@Sun.COM Adapter->link_state); 22288850SMin.Xu@Sun.COM if (Adapter->link_state == LINK_STATE_UP) 22298850SMin.Xu@Sun.COM Adapter->reset_flag = B_FALSE; 22303526Sxy150489 } 22313526Sxy150489 22324919Sxy150489 start_watchdog_timer(Adapter); 22333526Sxy150489 } 22345882Syy150190 } 22355882Syy150190 22363526Sxy150489 static void 22373526Sxy150489 e1000g_init_unicst(struct e1000g *Adapter) 22383526Sxy150489 { 22393526Sxy150489 struct e1000_hw *hw; 22403526Sxy150489 int slot; 22413526Sxy150489 22424919Sxy150489 hw = &Adapter->shared; 22433526Sxy150489 22448275SEric Cheng if (Adapter->init_count == 0) { 22453526Sxy150489 /* Initialize the multiple unicast addresses */ 22463526Sxy150489 Adapter->unicst_total = MAX_NUM_UNICAST_ADDRESSES; 22473526Sxy150489 22488275SEric Cheng /* Workaround for an erratum of 82571 chipst */ 22494919Sxy150489 if ((hw->mac.type == e1000_82571) && 22504919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 22513526Sxy150489 Adapter->unicst_total--; 22523526Sxy150489 22538275SEric Cheng Adapter->unicst_avail = Adapter->unicst_total; 22548275SEric Cheng 22558275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) { 22568275SEric Cheng /* Clear both the flag and MAC address */ 22578275SEric Cheng Adapter->unicst_addr[slot].reg.high = 0; 22588275SEric Cheng Adapter->unicst_addr[slot].reg.low = 0; 22598275SEric Cheng } 22603526Sxy150489 } else { 22618275SEric Cheng /* Workaround for an erratum of 82571 chipst */ 22624919Sxy150489 if ((hw->mac.type == e1000_82571) && 22634919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 22644919Sxy150489 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY); 22653526Sxy150489 22663526Sxy150489 /* Re-configure the RAR registers */ 22678275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) 22688275SEric Cheng if (Adapter->unicst_addr[slot].mac.set == 1) 22698275SEric Cheng e1000_rar_set(hw, 22708275SEric Cheng Adapter->unicst_addr[slot].mac.addr, slot); 22713526Sxy150489 } 22725273Sgl147354 22735273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 22745273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 22753526Sxy150489 } 22763526Sxy150489 22773526Sxy150489 static int 22783526Sxy150489 e1000g_unicst_set(struct e1000g *Adapter, const uint8_t *mac_addr, 22798275SEric Cheng int slot) 22803526Sxy150489 { 22813526Sxy150489 struct e1000_hw *hw; 22823526Sxy150489 22834919Sxy150489 hw = &Adapter->shared; 22843526Sxy150489 22853526Sxy150489 /* 22863526Sxy150489 * The first revision of Wiseman silicon (rev 2.0) has an errata 22873526Sxy150489 * that requires the receiver to be in reset when any of the 22883526Sxy150489 * receive address registers (RAR regs) are accessed. The first 22893526Sxy150489 * rev of Wiseman silicon also requires MWI to be disabled when 22903526Sxy150489 * a global reset or a receive reset is issued. So before we 22913526Sxy150489 * initialize the RARs, we check the rev of the Wiseman controller 22923526Sxy150489 * and work around any necessary HW errata. 22933526Sxy150489 */ 22944919Sxy150489 if ((hw->mac.type == e1000_82542) && 22954919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 22963526Sxy150489 e1000_pci_clear_mwi(hw); 22974919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 22984919Sxy150489 msec_delay(5); 22993526Sxy150489 } 23008275SEric Cheng if (mac_addr == NULL) { 23018275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, slot << 1, 0); 23028275SEric Cheng E1000_WRITE_FLUSH(hw); 23038275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, (slot << 1) + 1, 0); 23048275SEric Cheng E1000_WRITE_FLUSH(hw); 23058275SEric Cheng /* Clear both the flag and MAC address */ 23068275SEric Cheng Adapter->unicst_addr[slot].reg.high = 0; 23078275SEric Cheng Adapter->unicst_addr[slot].reg.low = 0; 23088275SEric Cheng } else { 23098275SEric Cheng bcopy(mac_addr, Adapter->unicst_addr[slot].mac.addr, 23108275SEric Cheng ETHERADDRL); 23118275SEric Cheng e1000_rar_set(hw, (uint8_t *)mac_addr, slot); 23128275SEric Cheng Adapter->unicst_addr[slot].mac.set = 1; 23138275SEric Cheng } 23148275SEric Cheng 23158275SEric Cheng /* Workaround for an erratum of 82571 chipst */ 23163526Sxy150489 if (slot == 0) { 23174919Sxy150489 if ((hw->mac.type == e1000_82571) && 23184919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 23198275SEric Cheng if (mac_addr == NULL) { 23208275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, 23218275SEric Cheng slot << 1, 0); 23228275SEric Cheng E1000_WRITE_FLUSH(hw); 23238275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, 23248275SEric Cheng (slot << 1) + 1, 0); 23258275SEric Cheng E1000_WRITE_FLUSH(hw); 23268275SEric Cheng } else { 23278275SEric Cheng e1000_rar_set(hw, (uint8_t *)mac_addr, 23288275SEric Cheng LAST_RAR_ENTRY); 23298275SEric Cheng } 23303526Sxy150489 } 23313526Sxy150489 23323526Sxy150489 /* 23333526Sxy150489 * If we are using Wiseman rev 2.0 silicon, we will have previously 23343526Sxy150489 * put the receive in reset, and disabled MWI, to work around some 23353526Sxy150489 * HW errata. Now we should take the receiver out of reset, and 23363526Sxy150489 * re-enabled if MWI if it was previously enabled by the PCI BIOS. 23373526Sxy150489 */ 23384919Sxy150489 if ((hw->mac.type == e1000_82542) && 23394919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 23404919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0); 23414919Sxy150489 msec_delay(1); 23424919Sxy150489 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 23433526Sxy150489 e1000_pci_set_mwi(hw); 23444919Sxy150489 e1000g_rx_setup(Adapter); 23453526Sxy150489 } 23463526Sxy150489 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 23553526Sxy150489 static int 23563526Sxy150489 multicst_add(struct e1000g *Adapter, const uint8_t *multiaddr) 23573526Sxy150489 { 23584919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 23599770SChangqing.Li@Sun.COM struct ether_addr *newtable; 23609770SChangqing.Li@Sun.COM size_t new_len; 23619770SChangqing.Li@Sun.COM size_t old_len; 23623526Sxy150489 int res = 0; 23633526Sxy150489 23643526Sxy150489 if ((multiaddr[0] & 01) == 0) { 23653526Sxy150489 res = EINVAL; 23669770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN, "Illegal multicast address"); 23673526Sxy150489 goto done; 23683526Sxy150489 } 23693526Sxy150489 23709770SChangqing.Li@Sun.COM if (Adapter->mcast_count >= Adapter->mcast_max_num) { 23713526Sxy150489 res = ENOENT; 23729770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN, 23739770SChangqing.Li@Sun.COM "Adapter requested more than %d mcast addresses", 23749770SChangqing.Li@Sun.COM Adapter->mcast_max_num); 23753526Sxy150489 goto done; 23763526Sxy150489 } 23773526Sxy150489 23789770SChangqing.Li@Sun.COM 23799770SChangqing.Li@Sun.COM if (Adapter->mcast_count == Adapter->mcast_alloc_count) { 23809770SChangqing.Li@Sun.COM old_len = Adapter->mcast_alloc_count * 23819770SChangqing.Li@Sun.COM sizeof (struct ether_addr); 23829770SChangqing.Li@Sun.COM new_len = (Adapter->mcast_alloc_count + MCAST_ALLOC_SIZE) * 23839770SChangqing.Li@Sun.COM sizeof (struct ether_addr); 23849770SChangqing.Li@Sun.COM 23859770SChangqing.Li@Sun.COM newtable = kmem_alloc(new_len, KM_NOSLEEP); 23869770SChangqing.Li@Sun.COM if (newtable == NULL) { 23879770SChangqing.Li@Sun.COM res = ENOMEM; 23889770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN, 23899770SChangqing.Li@Sun.COM "Not enough memory to alloc mcast table"); 23909770SChangqing.Li@Sun.COM goto done; 23919770SChangqing.Li@Sun.COM } 23929770SChangqing.Li@Sun.COM 23939770SChangqing.Li@Sun.COM if (Adapter->mcast_table != NULL) { 23949770SChangqing.Li@Sun.COM bcopy(Adapter->mcast_table, newtable, old_len); 23959770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table, old_len); 23969770SChangqing.Li@Sun.COM } 23979770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count += MCAST_ALLOC_SIZE; 23989770SChangqing.Li@Sun.COM Adapter->mcast_table = newtable; 23999770SChangqing.Li@Sun.COM } 24009770SChangqing.Li@Sun.COM 24013526Sxy150489 bcopy(multiaddr, 24023526Sxy150489 &Adapter->mcast_table[Adapter->mcast_count], ETHERADDRL); 24033526Sxy150489 Adapter->mcast_count++; 24043526Sxy150489 24053526Sxy150489 /* 24063526Sxy150489 * Update the MC table in the hardware 24073526Sxy150489 */ 24084919Sxy150489 e1000g_clear_interrupt(Adapter); 24094919Sxy150489 24104919Sxy150489 e1000g_setup_multicast(Adapter); 24114919Sxy150489 24124919Sxy150489 if ((hw->mac.type == e1000_82542) && 24134919Sxy150489 (hw->revision_id == E1000_REVISION_2)) 24144919Sxy150489 e1000g_rx_setup(Adapter); 24154919Sxy150489 24164919Sxy150489 e1000g_mask_interrupt(Adapter); 24173526Sxy150489 24185273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 24195273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 24205273Sgl147354 res = EIO; 24215273Sgl147354 } 24225273Sgl147354 24238479SChenlu.Chen@Sun.COM done: 24243526Sxy150489 return (res); 24253526Sxy150489 } 24263526Sxy150489 24273526Sxy150489 static int 24283526Sxy150489 multicst_remove(struct e1000g *Adapter, const uint8_t *multiaddr) 24293526Sxy150489 { 24304919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 24319770SChangqing.Li@Sun.COM struct ether_addr *newtable; 24329770SChangqing.Li@Sun.COM size_t new_len; 24339770SChangqing.Li@Sun.COM size_t old_len; 24343526Sxy150489 unsigned i; 24353526Sxy150489 24363526Sxy150489 for (i = 0; i < Adapter->mcast_count; i++) { 24373526Sxy150489 if (bcmp(multiaddr, &Adapter->mcast_table[i], 24383526Sxy150489 ETHERADDRL) == 0) { 24393526Sxy150489 for (i++; i < Adapter->mcast_count; i++) { 24403526Sxy150489 Adapter->mcast_table[i - 1] = 24413526Sxy150489 Adapter->mcast_table[i]; 24423526Sxy150489 } 24433526Sxy150489 Adapter->mcast_count--; 24443526Sxy150489 break; 24453526Sxy150489 } 24463526Sxy150489 } 24473526Sxy150489 24489770SChangqing.Li@Sun.COM if ((Adapter->mcast_alloc_count - Adapter->mcast_count) > 24499770SChangqing.Li@Sun.COM MCAST_ALLOC_SIZE) { 24509770SChangqing.Li@Sun.COM old_len = Adapter->mcast_alloc_count * 24519770SChangqing.Li@Sun.COM sizeof (struct ether_addr); 24529770SChangqing.Li@Sun.COM new_len = (Adapter->mcast_alloc_count - MCAST_ALLOC_SIZE) * 24539770SChangqing.Li@Sun.COM sizeof (struct ether_addr); 24549770SChangqing.Li@Sun.COM 24559770SChangqing.Li@Sun.COM newtable = kmem_alloc(new_len, KM_NOSLEEP); 24569770SChangqing.Li@Sun.COM if (newtable != NULL) { 24579770SChangqing.Li@Sun.COM bcopy(Adapter->mcast_table, newtable, new_len); 24589770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table, old_len); 24599770SChangqing.Li@Sun.COM 24609770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count -= MCAST_ALLOC_SIZE; 24619770SChangqing.Li@Sun.COM Adapter->mcast_table = newtable; 24629770SChangqing.Li@Sun.COM } 24639770SChangqing.Li@Sun.COM } 24649770SChangqing.Li@Sun.COM 24653526Sxy150489 /* 24663526Sxy150489 * Update the MC table in the hardware 24673526Sxy150489 */ 24684919Sxy150489 e1000g_clear_interrupt(Adapter); 24694919Sxy150489 24704919Sxy150489 e1000g_setup_multicast(Adapter); 24714919Sxy150489 24724919Sxy150489 if ((hw->mac.type == e1000_82542) && 24734919Sxy150489 (hw->revision_id == E1000_REVISION_2)) 24744919Sxy150489 e1000g_rx_setup(Adapter); 24754919Sxy150489 24764919Sxy150489 e1000g_mask_interrupt(Adapter); 24773526Sxy150489 24785273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 24795273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 24805273Sgl147354 return (EIO); 24815273Sgl147354 } 24825273Sgl147354 24833526Sxy150489 return (0); 24843526Sxy150489 } 24853526Sxy150489 24869770SChangqing.Li@Sun.COM static void 24879770SChangqing.Li@Sun.COM e1000g_release_multicast(struct e1000g *Adapter) 24889770SChangqing.Li@Sun.COM { 24899770SChangqing.Li@Sun.COM if (Adapter->mcast_table != NULL) { 24909770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table, 24919770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count * sizeof (struct ether_addr)); 24929770SChangqing.Li@Sun.COM Adapter->mcast_table = NULL; 24939770SChangqing.Li@Sun.COM } 24949770SChangqing.Li@Sun.COM } 24959770SChangqing.Li@Sun.COM 24964919Sxy150489 /* 24974919Sxy150489 * e1000g_setup_multicast - setup multicast data structures 24984919Sxy150489 * 24994919Sxy150489 * This routine initializes all of the multicast related structures. 25004919Sxy150489 */ 25014919Sxy150489 void 25024919Sxy150489 e1000g_setup_multicast(struct e1000g *Adapter) 25034919Sxy150489 { 25044919Sxy150489 uint8_t *mc_addr_list; 25054919Sxy150489 uint32_t mc_addr_count; 25064919Sxy150489 uint32_t rctl; 25074919Sxy150489 struct e1000_hw *hw; 25084919Sxy150489 25094919Sxy150489 hw = &Adapter->shared; 25104919Sxy150489 25114919Sxy150489 /* 25124919Sxy150489 * The e1000g has the ability to do perfect filtering of 16 25134919Sxy150489 * addresses. The driver uses one of the e1000g's 16 receive 25144919Sxy150489 * address registers for its node/network/mac/individual address. 25154919Sxy150489 * So, we have room for up to 15 multicast addresses in the CAM, 25164919Sxy150489 * additional MC addresses are handled by the MTA (Multicast Table 25174919Sxy150489 * Array) 25184919Sxy150489 */ 25194919Sxy150489 25204919Sxy150489 rctl = E1000_READ_REG(hw, E1000_RCTL); 25214919Sxy150489 25224919Sxy150489 mc_addr_list = (uint8_t *)Adapter->mcast_table; 25234919Sxy150489 25249770SChangqing.Li@Sun.COM ASSERT(Adapter->mcast_count <= Adapter->mcast_max_num); 25259770SChangqing.Li@Sun.COM 25269770SChangqing.Li@Sun.COM mc_addr_count = Adapter->mcast_count; 25274919Sxy150489 /* 25284919Sxy150489 * The Wiseman 2.0 silicon has an errata by which the receiver will 25294919Sxy150489 * hang while writing to the receive address registers if the receiver 25304919Sxy150489 * is not in reset before writing to the registers. Updating the RAR 25314919Sxy150489 * is done during the setting up of the multicast table, hence the 25324919Sxy150489 * receiver has to be put in reset before updating the multicast table 25334919Sxy150489 * and then taken out of reset at the end 25344919Sxy150489 */ 25354919Sxy150489 /* 25364919Sxy150489 * if WMI was enabled then dis able it before issueing the global 25374919Sxy150489 * reset to the hardware. 25384919Sxy150489 */ 25394919Sxy150489 /* 25404919Sxy150489 * Only required for WISEMAN_2_0 25414919Sxy150489 */ 25424919Sxy150489 if ((hw->mac.type == e1000_82542) && 25434919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 25444919Sxy150489 e1000_pci_clear_mwi(hw); 25454919Sxy150489 /* 25464919Sxy150489 * The e1000g must be in reset before changing any RA 25474919Sxy150489 * registers. Reset receive unit. The chip will remain in 25484919Sxy150489 * the reset state until software explicitly restarts it. 25494919Sxy150489 */ 25504919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 25514919Sxy150489 /* Allow receiver time to go in to reset */ 25524919Sxy150489 msec_delay(5); 25534919Sxy150489 } 25546735Scc210113 25556735Scc210113 e1000_update_mc_addr_list(hw, mc_addr_list, mc_addr_count, 25564919Sxy150489 Adapter->unicst_total, hw->mac.rar_entry_count); 25574919Sxy150489 25584919Sxy150489 /* 25594919Sxy150489 * Only for Wiseman_2_0 25604919Sxy150489 * If MWI was enabled then re-enable it after issueing (as we 25614919Sxy150489 * disabled it up there) the receive reset command. 25624919Sxy150489 * Wainwright does not have a receive reset command and only thing 25634919Sxy150489 * close to it is global reset which will require tx setup also 25644919Sxy150489 */ 25654919Sxy150489 if ((hw->mac.type == e1000_82542) && 25664919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 25674919Sxy150489 /* 25684919Sxy150489 * if WMI was enabled then reenable it after issueing the 25694919Sxy150489 * global or receive reset to the hardware. 25704919Sxy150489 */ 25714919Sxy150489 25724919Sxy150489 /* 25734919Sxy150489 * Take receiver out of reset 25744919Sxy150489 * clear E1000_RCTL_RST bit (and all others) 25754919Sxy150489 */ 25764919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0); 25774919Sxy150489 msec_delay(5); 25784919Sxy150489 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 25794919Sxy150489 e1000_pci_set_mwi(hw); 25804919Sxy150489 } 25814919Sxy150489 25824919Sxy150489 /* 25834919Sxy150489 * Restore original value 25844919Sxy150489 */ 25854919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 25864919Sxy150489 } 25874919Sxy150489 25883526Sxy150489 int 25893526Sxy150489 e1000g_m_multicst(void *arg, boolean_t add, const uint8_t *addr) 25903526Sxy150489 { 25913526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 25928479SChenlu.Chen@Sun.COM int result; 25938479SChenlu.Chen@Sun.COM 25948479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 25958479SChenlu.Chen@Sun.COM 25968479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 25978479SChenlu.Chen@Sun.COM result = ECANCELED; 25988479SChenlu.Chen@Sun.COM goto done; 25998479SChenlu.Chen@Sun.COM } 26008479SChenlu.Chen@Sun.COM 26018479SChenlu.Chen@Sun.COM result = (add) ? multicst_add(Adapter, addr) 26028479SChenlu.Chen@Sun.COM : multicst_remove(Adapter, addr); 26038479SChenlu.Chen@Sun.COM 26048479SChenlu.Chen@Sun.COM done: 26058479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 26068479SChenlu.Chen@Sun.COM return (result); 26078479SChenlu.Chen@Sun.COM 26083526Sxy150489 } 26093526Sxy150489 26103526Sxy150489 int 26113526Sxy150489 e1000g_m_promisc(void *arg, boolean_t on) 26123526Sxy150489 { 26133526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 26144919Sxy150489 uint32_t rctl; 26153526Sxy150489 26163526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 26173526Sxy150489 26188479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 26198479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 26208479SChenlu.Chen@Sun.COM return (ECANCELED); 26218479SChenlu.Chen@Sun.COM } 26228479SChenlu.Chen@Sun.COM 26234919Sxy150489 rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL); 26243526Sxy150489 26253526Sxy150489 if (on) 26264919Sxy150489 rctl |= 26273526Sxy150489 (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM); 26283526Sxy150489 else 26294919Sxy150489 rctl &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE)); 26304919Sxy150489 26314919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl); 26323526Sxy150489 26333526Sxy150489 Adapter->e1000g_promisc = on; 26343526Sxy150489 26353526Sxy150489 rw_exit(&Adapter->chip_lock); 26363526Sxy150489 26375273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 26385273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 26395273Sgl147354 return (EIO); 26405273Sgl147354 } 26415273Sgl147354 26423526Sxy150489 return (0); 26433526Sxy150489 } 26443526Sxy150489 26458275SEric Cheng /* 26468275SEric Cheng * Entry points to enable and disable interrupts at the granularity of 26478275SEric Cheng * a group. 26488275SEric Cheng * Turns the poll_mode for the whole adapter on and off to enable or 26498275SEric Cheng * override the ring level polling control over the hardware interrupts. 26508275SEric Cheng */ 26518275SEric Cheng static int 26528275SEric Cheng e1000g_rx_group_intr_enable(mac_intr_handle_t arg) 26538275SEric Cheng { 26548275SEric Cheng struct e1000g *adapter = (struct e1000g *)arg; 26558275SEric Cheng e1000g_rx_ring_t *rx_ring = adapter->rx_ring; 26568275SEric Cheng 26578275SEric Cheng /* 26588275SEric Cheng * Later interrupts at the granularity of the this ring will 26598275SEric Cheng * invoke mac_rx() with NULL, indicating the need for another 26608275SEric Cheng * software classification. 26618275SEric Cheng * We have a single ring usable per adapter now, so we only need to 26628275SEric Cheng * reset the rx handle for that one. 26638275SEric Cheng * When more RX rings can be used, we should update each one of them. 26648275SEric Cheng */ 26658275SEric Cheng mutex_enter(&rx_ring->rx_lock); 26668275SEric Cheng rx_ring->mrh = NULL; 26678275SEric Cheng adapter->poll_mode = B_FALSE; 26688275SEric Cheng mutex_exit(&rx_ring->rx_lock); 26698275SEric Cheng return (0); 26708275SEric Cheng } 26718275SEric Cheng 26728275SEric Cheng static int 26738275SEric Cheng e1000g_rx_group_intr_disable(mac_intr_handle_t arg) 26748275SEric Cheng { 26758275SEric Cheng struct e1000g *adapter = (struct e1000g *)arg; 26768275SEric Cheng e1000g_rx_ring_t *rx_ring = adapter->rx_ring; 26778275SEric Cheng 26788275SEric Cheng mutex_enter(&rx_ring->rx_lock); 26798275SEric Cheng 26808275SEric Cheng /* 26818275SEric Cheng * Later interrupts at the granularity of the this ring will 26828275SEric Cheng * invoke mac_rx() with the handle for this ring; 26838275SEric Cheng */ 26848275SEric Cheng adapter->poll_mode = B_TRUE; 26858275SEric Cheng rx_ring->mrh = rx_ring->mrh_init; 26868275SEric Cheng mutex_exit(&rx_ring->rx_lock); 26878275SEric Cheng return (0); 26888275SEric Cheng } 26898275SEric Cheng 26908275SEric Cheng /* 26918275SEric Cheng * Entry points to enable and disable interrupts at the granularity of 26928275SEric Cheng * a ring. 26938275SEric Cheng * adapter poll_mode controls whether we actually proceed with hardware 26948275SEric Cheng * interrupt toggling. 26958275SEric Cheng */ 26968275SEric Cheng static int 26978275SEric Cheng e1000g_rx_ring_intr_enable(mac_intr_handle_t intrh) 26988275SEric Cheng { 26998275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)intrh; 27008275SEric Cheng struct e1000g *adapter = rx_ring->adapter; 27018275SEric Cheng struct e1000_hw *hw = &adapter->shared; 27028275SEric Cheng uint32_t intr_mask; 27038275SEric Cheng 27048479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER); 27058479SChenlu.Chen@Sun.COM 27068479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) { 27078479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 27088479SChenlu.Chen@Sun.COM return (0); 27098479SChenlu.Chen@Sun.COM } 27108479SChenlu.Chen@Sun.COM 27118275SEric Cheng mutex_enter(&rx_ring->rx_lock); 27128275SEric Cheng rx_ring->poll_flag = 0; 27138275SEric Cheng mutex_exit(&rx_ring->rx_lock); 27148275SEric Cheng 27158833SVenu.Iyer@Sun.COM /* Rx interrupt enabling for MSI and legacy */ 27168833SVenu.Iyer@Sun.COM intr_mask = E1000_READ_REG(hw, E1000_IMS); 27178833SVenu.Iyer@Sun.COM intr_mask |= E1000_IMS_RXT0; 27188833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_IMS, intr_mask); 27198833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw); 27208833SVenu.Iyer@Sun.COM 27218833SVenu.Iyer@Sun.COM /* Trigger a Rx interrupt to check Rx ring */ 27228833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0); 27238833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw); 27248479SChenlu.Chen@Sun.COM 27258479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 27268275SEric Cheng return (0); 27278275SEric Cheng } 27288275SEric Cheng 27298275SEric Cheng static int 27308275SEric Cheng e1000g_rx_ring_intr_disable(mac_intr_handle_t intrh) 27318275SEric Cheng { 27328275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)intrh; 27338275SEric Cheng struct e1000g *adapter = rx_ring->adapter; 27348275SEric Cheng struct e1000_hw *hw = &adapter->shared; 27358275SEric Cheng 27368479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER); 27378479SChenlu.Chen@Sun.COM 27388479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) { 27398479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 27408479SChenlu.Chen@Sun.COM return (0); 27418479SChenlu.Chen@Sun.COM } 27428275SEric Cheng mutex_enter(&rx_ring->rx_lock); 27438275SEric Cheng rx_ring->poll_flag = 1; 27448275SEric Cheng mutex_exit(&rx_ring->rx_lock); 27458275SEric Cheng 27468833SVenu.Iyer@Sun.COM /* Rx interrupt disabling for MSI and legacy */ 27478833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_RXT0); 27488833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw); 27498479SChenlu.Chen@Sun.COM 27508479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock); 27518275SEric Cheng return (0); 27528275SEric Cheng } 27538275SEric Cheng 27548275SEric Cheng /* 27558275SEric Cheng * e1000g_unicst_find - Find the slot for the specified unicast address 27568275SEric Cheng */ 27578275SEric Cheng static int 27588275SEric Cheng e1000g_unicst_find(struct e1000g *Adapter, const uint8_t *mac_addr) 27598275SEric Cheng { 27608275SEric Cheng int slot; 27618275SEric Cheng 27628275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) { 27638479SChenlu.Chen@Sun.COM if ((Adapter->unicst_addr[slot].mac.set == 1) && 27648479SChenlu.Chen@Sun.COM (bcmp(Adapter->unicst_addr[slot].mac.addr, 27658479SChenlu.Chen@Sun.COM mac_addr, ETHERADDRL) == 0)) 27668275SEric Cheng return (slot); 27678275SEric Cheng } 27688275SEric Cheng 27698275SEric Cheng return (-1); 27708275SEric Cheng } 27718275SEric Cheng 27728275SEric Cheng /* 27738275SEric Cheng * Entry points to add and remove a MAC address to a ring group. 27748275SEric Cheng * The caller takes care of adding and removing the MAC addresses 27758275SEric Cheng * to the filter via these two routines. 27768275SEric Cheng */ 27778275SEric Cheng 27788275SEric Cheng static int 27798275SEric Cheng e1000g_addmac(void *arg, const uint8_t *mac_addr) 27808275SEric Cheng { 27818275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg; 27828400SNicolas.Droux@Sun.COM int slot, err; 27838275SEric Cheng 27848479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 27858479SChenlu.Chen@Sun.COM 27868479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 27878479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 27888479SChenlu.Chen@Sun.COM return (ECANCELED); 27898479SChenlu.Chen@Sun.COM } 27908275SEric Cheng 27918275SEric Cheng if (e1000g_unicst_find(Adapter, mac_addr) != -1) { 27928275SEric Cheng /* The same address is already in slot */ 27938479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 27948275SEric Cheng return (0); 27958275SEric Cheng } 27968275SEric Cheng 27978275SEric Cheng if (Adapter->unicst_avail == 0) { 27988275SEric Cheng /* no slots available */ 27998479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 28008275SEric Cheng return (ENOSPC); 28018275SEric Cheng } 28028275SEric Cheng 28038275SEric Cheng /* Search for a free slot */ 28048275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) { 28058275SEric Cheng if (Adapter->unicst_addr[slot].mac.set == 0) 28068275SEric Cheng break; 28078275SEric Cheng } 28088275SEric Cheng ASSERT(slot < Adapter->unicst_total); 28098275SEric Cheng 28108400SNicolas.Droux@Sun.COM err = e1000g_unicst_set(Adapter, mac_addr, slot); 28118400SNicolas.Droux@Sun.COM if (err == 0) 28128400SNicolas.Droux@Sun.COM Adapter->unicst_avail--; 28138275SEric Cheng 28148479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 28158275SEric Cheng 28168400SNicolas.Droux@Sun.COM return (err); 28178275SEric Cheng } 28188275SEric Cheng 28198275SEric Cheng static int 28208275SEric Cheng e1000g_remmac(void *arg, const uint8_t *mac_addr) 28218275SEric Cheng { 28228275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg; 28238400SNicolas.Droux@Sun.COM int slot, err; 28248275SEric Cheng 28258479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 28268479SChenlu.Chen@Sun.COM 28278479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 28288479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 28298479SChenlu.Chen@Sun.COM return (ECANCELED); 28308479SChenlu.Chen@Sun.COM } 28318275SEric Cheng 28328275SEric Cheng slot = e1000g_unicst_find(Adapter, mac_addr); 28338275SEric Cheng if (slot == -1) { 28348479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 28358275SEric Cheng return (EINVAL); 28368275SEric Cheng } 28378275SEric Cheng 28388275SEric Cheng ASSERT(Adapter->unicst_addr[slot].mac.set); 28398275SEric Cheng 28408275SEric Cheng /* Clear this slot */ 28418400SNicolas.Droux@Sun.COM err = e1000g_unicst_set(Adapter, NULL, slot); 28428400SNicolas.Droux@Sun.COM if (err == 0) 28438400SNicolas.Droux@Sun.COM Adapter->unicst_avail++; 28448275SEric Cheng 28458479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 28468275SEric Cheng 28478400SNicolas.Droux@Sun.COM return (err); 28488275SEric Cheng } 28498275SEric Cheng 28508275SEric Cheng static int 28518275SEric Cheng e1000g_ring_start(mac_ring_driver_t rh, uint64_t mr_gen_num) 28528275SEric Cheng { 28538275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)rh; 28548275SEric Cheng 28558275SEric Cheng mutex_enter(&rx_ring->rx_lock); 28568275SEric Cheng rx_ring->ring_gen_num = mr_gen_num; 28578275SEric Cheng mutex_exit(&rx_ring->rx_lock); 28588275SEric Cheng return (0); 28598275SEric Cheng } 28608275SEric Cheng 28618275SEric Cheng /* 28628275SEric Cheng * Callback funtion for MAC layer to register all rings. 28638275SEric Cheng * 28648275SEric Cheng * The hardware supports a single group with currently only one ring 28658275SEric Cheng * available. 28668275SEric Cheng * Though not offering virtualization ability per se, exposing the 28678275SEric Cheng * group/ring still enables the polling and interrupt toggling. 28688275SEric Cheng */ 28698275SEric Cheng void 28708275SEric Cheng e1000g_fill_ring(void *arg, mac_ring_type_t rtype, const int grp_index, 28718275SEric Cheng const int ring_index, mac_ring_info_t *infop, mac_ring_handle_t rh) 28728275SEric Cheng { 28738275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg; 28748275SEric Cheng e1000g_rx_ring_t *rx_ring = Adapter->rx_ring; 28758275SEric Cheng mac_intr_t *mintr; 28768275SEric Cheng 28778275SEric Cheng /* 28788275SEric Cheng * We advertised only RX group/rings, so the MAC framework shouldn't 28798275SEric Cheng * ask for any thing else. 28808275SEric Cheng */ 28818275SEric Cheng ASSERT(rtype == MAC_RING_TYPE_RX && grp_index == 0 && ring_index == 0); 28828275SEric Cheng 28838275SEric Cheng rx_ring->mrh = rx_ring->mrh_init = rh; 28848275SEric Cheng infop->mri_driver = (mac_ring_driver_t)rx_ring; 28858275SEric Cheng infop->mri_start = e1000g_ring_start; 28868275SEric Cheng infop->mri_stop = NULL; 28878275SEric Cheng infop->mri_poll = e1000g_poll_ring; 28888275SEric Cheng 28898275SEric Cheng /* Ring level interrupts */ 28908275SEric Cheng mintr = &infop->mri_intr; 28918275SEric Cheng mintr->mi_handle = (mac_intr_handle_t)rx_ring; 28928275SEric Cheng mintr->mi_enable = e1000g_rx_ring_intr_enable; 28938275SEric Cheng mintr->mi_disable = e1000g_rx_ring_intr_disable; 28948275SEric Cheng } 28958275SEric Cheng 28968275SEric Cheng static void 28978275SEric Cheng e1000g_fill_group(void *arg, mac_ring_type_t rtype, const int grp_index, 28988275SEric Cheng mac_group_info_t *infop, mac_group_handle_t gh) 28998275SEric Cheng { 29008275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg; 29018275SEric Cheng mac_intr_t *mintr; 29028275SEric Cheng 29038275SEric Cheng /* 29048275SEric Cheng * We advertised a single RX ring. Getting a request for anything else 29058275SEric Cheng * signifies a bug in the MAC framework. 29068275SEric Cheng */ 29078275SEric Cheng ASSERT(rtype == MAC_RING_TYPE_RX && grp_index == 0); 29088275SEric Cheng 29098275SEric Cheng Adapter->rx_group = gh; 29108275SEric Cheng 29118275SEric Cheng infop->mgi_driver = (mac_group_driver_t)Adapter; 29128275SEric Cheng infop->mgi_start = NULL; 29138275SEric Cheng infop->mgi_stop = NULL; 29148275SEric Cheng infop->mgi_addmac = e1000g_addmac; 29158275SEric Cheng infop->mgi_remmac = e1000g_remmac; 29168275SEric Cheng infop->mgi_count = 1; 29178275SEric Cheng 29188275SEric Cheng /* Group level interrupts */ 29198275SEric Cheng mintr = &infop->mgi_intr; 29208275SEric Cheng mintr->mi_handle = (mac_intr_handle_t)Adapter; 29218275SEric Cheng mintr->mi_enable = e1000g_rx_group_intr_enable; 29228275SEric Cheng mintr->mi_disable = e1000g_rx_group_intr_disable; 29238275SEric Cheng } 29248275SEric Cheng 29253526Sxy150489 static boolean_t 29263526Sxy150489 e1000g_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 29273526Sxy150489 { 29283526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 29293526Sxy150489 29303526Sxy150489 switch (cap) { 29313526Sxy150489 case MAC_CAPAB_HCKSUM: { 29323526Sxy150489 uint32_t *txflags = cap_data; 29336986Smx205022 29346986Smx205022 if (Adapter->tx_hcksum_enable) 29356986Smx205022 *txflags = HCKSUM_IPHDRCKSUM | 29366986Smx205022 HCKSUM_INET_PARTIAL; 29376986Smx205022 else 29383526Sxy150489 return (B_FALSE); 29393526Sxy150489 break; 29403526Sxy150489 } 29416986Smx205022 29426986Smx205022 case MAC_CAPAB_LSO: { 29436986Smx205022 mac_capab_lso_t *cap_lso = cap_data; 29446986Smx205022 29456986Smx205022 if (Adapter->lso_enable) { 29466986Smx205022 cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; 29476986Smx205022 cap_lso->lso_basic_tcp_ipv4.lso_max = 29486986Smx205022 E1000_LSO_MAXLEN; 29496986Smx205022 } else 29506986Smx205022 return (B_FALSE); 29516986Smx205022 break; 29526986Smx205022 } 29538275SEric Cheng case MAC_CAPAB_RINGS: { 29548275SEric Cheng mac_capab_rings_t *cap_rings = cap_data; 29558275SEric Cheng 29568275SEric Cheng /* No TX rings exposed yet */ 29578275SEric Cheng if (cap_rings->mr_type != MAC_RING_TYPE_RX) 29588275SEric Cheng return (B_FALSE); 29598275SEric Cheng 29608275SEric Cheng cap_rings->mr_group_type = MAC_GROUP_TYPE_STATIC; 29618275SEric Cheng cap_rings->mr_rnum = 1; 29628275SEric Cheng cap_rings->mr_gnum = 1; 29638275SEric Cheng cap_rings->mr_rget = e1000g_fill_ring; 29648275SEric Cheng cap_rings->mr_gget = e1000g_fill_group; 29658275SEric Cheng break; 29668275SEric Cheng } 29673526Sxy150489 default: 29683526Sxy150489 return (B_FALSE); 29693526Sxy150489 } 29703526Sxy150489 return (B_TRUE); 29713526Sxy150489 } 29723526Sxy150489 29736394Scc210113 static boolean_t 29746394Scc210113 e1000g_param_locked(mac_prop_id_t pr_num) 29756394Scc210113 { 29766394Scc210113 /* 29776394Scc210113 * All en_* parameters are locked (read-only) while 29786394Scc210113 * the device is in any sort of loopback mode ... 29796394Scc210113 */ 29806394Scc210113 switch (pr_num) { 29816789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 29826789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 29836789Sam223141 case MAC_PROP_EN_100FDX_CAP: 29846789Sam223141 case MAC_PROP_EN_100HDX_CAP: 29856789Sam223141 case MAC_PROP_EN_10FDX_CAP: 29866789Sam223141 case MAC_PROP_EN_10HDX_CAP: 29876789Sam223141 case MAC_PROP_AUTONEG: 29886789Sam223141 case MAC_PROP_FLOWCTRL: 29896394Scc210113 return (B_TRUE); 29906394Scc210113 } 29916394Scc210113 return (B_FALSE); 29926394Scc210113 } 29936394Scc210113 29946394Scc210113 /* 29956394Scc210113 * callback function for set/get of properties 29966394Scc210113 */ 29976394Scc210113 static int 29986394Scc210113 e1000g_m_setprop(void *arg, const char *pr_name, mac_prop_id_t pr_num, 29996394Scc210113 uint_t pr_valsize, const void *pr_val) 30006394Scc210113 { 30016394Scc210113 struct e1000g *Adapter = arg; 30026394Scc210113 struct e1000_mac_info *mac = &Adapter->shared.mac; 30036394Scc210113 struct e1000_phy_info *phy = &Adapter->shared.phy; 30046735Scc210113 struct e1000_fc_info *fc = &Adapter->shared.fc; 30056394Scc210113 int err = 0; 30066735Scc210113 link_flowctrl_t flowctrl; 30076512Ssowmini uint32_t cur_mtu, new_mtu; 30086394Scc210113 uint64_t tmp = 0; 30096394Scc210113 30106394Scc210113 rw_enter(&Adapter->chip_lock, RW_WRITER); 30118479SChenlu.Chen@Sun.COM 30128479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) { 30138479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 30148479SChenlu.Chen@Sun.COM return (ECANCELED); 30158479SChenlu.Chen@Sun.COM } 30168479SChenlu.Chen@Sun.COM 30176394Scc210113 if (Adapter->loopback_mode != E1000G_LB_NONE && 30186394Scc210113 e1000g_param_locked(pr_num)) { 30196394Scc210113 /* 30206394Scc210113 * All en_* parameters are locked (read-only) 30216394Scc210113 * while the device is in any sort of loopback mode. 30226394Scc210113 */ 30236394Scc210113 rw_exit(&Adapter->chip_lock); 30246394Scc210113 return (EBUSY); 30256394Scc210113 } 30266394Scc210113 30276394Scc210113 switch (pr_num) { 30286789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 30296394Scc210113 Adapter->param_en_1000fdx = *(uint8_t *)pr_val; 30306394Scc210113 Adapter->param_adv_1000fdx = *(uint8_t *)pr_val; 30316394Scc210113 goto reset; 30326789Sam223141 case MAC_PROP_EN_100FDX_CAP: 30336394Scc210113 Adapter->param_en_100fdx = *(uint8_t *)pr_val; 30346394Scc210113 Adapter->param_adv_100fdx = *(uint8_t *)pr_val; 30356394Scc210113 goto reset; 30366789Sam223141 case MAC_PROP_EN_100HDX_CAP: 30376394Scc210113 Adapter->param_en_100hdx = *(uint8_t *)pr_val; 30386394Scc210113 Adapter->param_adv_100hdx = *(uint8_t *)pr_val; 30396394Scc210113 goto reset; 30406789Sam223141 case MAC_PROP_EN_10FDX_CAP: 30416394Scc210113 Adapter->param_en_10fdx = *(uint8_t *)pr_val; 30426394Scc210113 Adapter->param_adv_10fdx = *(uint8_t *)pr_val; 30436394Scc210113 goto reset; 30446789Sam223141 case MAC_PROP_EN_10HDX_CAP: 30456394Scc210113 Adapter->param_en_10hdx = *(uint8_t *)pr_val; 30466394Scc210113 Adapter->param_adv_10hdx = *(uint8_t *)pr_val; 30476394Scc210113 goto reset; 30486789Sam223141 case MAC_PROP_AUTONEG: 30496394Scc210113 Adapter->param_adv_autoneg = *(uint8_t *)pr_val; 30506394Scc210113 goto reset; 30516789Sam223141 case MAC_PROP_FLOWCTRL: 30526735Scc210113 fc->send_xon = B_TRUE; 30536735Scc210113 bcopy(pr_val, &flowctrl, sizeof (flowctrl)); 30546735Scc210113 30556735Scc210113 switch (flowctrl) { 30566394Scc210113 default: 30576394Scc210113 err = EINVAL; 30586394Scc210113 break; 30596394Scc210113 case LINK_FLOWCTRL_NONE: 30608539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_none; 30616394Scc210113 break; 30626394Scc210113 case LINK_FLOWCTRL_RX: 30638539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_rx_pause; 30646394Scc210113 break; 30656394Scc210113 case LINK_FLOWCTRL_TX: 30668539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_tx_pause; 30676394Scc210113 break; 30686394Scc210113 case LINK_FLOWCTRL_BI: 30698539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_full; 30706394Scc210113 break; 30716394Scc210113 } 30726394Scc210113 reset: 30736394Scc210113 if (err == 0) { 30746394Scc210113 if (e1000g_reset_link(Adapter) != DDI_SUCCESS) 30756394Scc210113 err = EINVAL; 30766394Scc210113 } 30776394Scc210113 break; 30786789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 30796789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 30806789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 30816789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 30826789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 30836789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 30848118SVasumathi.Sundaram@Sun.COM case MAC_PROP_EN_1000HDX_CAP: 30856789Sam223141 case MAC_PROP_STATUS: 30866789Sam223141 case MAC_PROP_SPEED: 30876789Sam223141 case MAC_PROP_DUPLEX: 30886394Scc210113 err = ENOTSUP; /* read-only prop. Can't set this. */ 30896394Scc210113 break; 30906789Sam223141 case MAC_PROP_MTU: 30916394Scc210113 cur_mtu = Adapter->default_mtu; 30926394Scc210113 bcopy(pr_val, &new_mtu, sizeof (new_mtu)); 30936394Scc210113 if (new_mtu == cur_mtu) { 30946394Scc210113 err = 0; 30956394Scc210113 break; 30966394Scc210113 } 30976394Scc210113 30986394Scc210113 tmp = new_mtu + sizeof (struct ether_vlan_header) + 30996394Scc210113 ETHERFCSL; 31006394Scc210113 if ((tmp < DEFAULT_FRAME_SIZE) || 31016394Scc210113 (tmp > MAXIMUM_FRAME_SIZE)) { 31026394Scc210113 err = EINVAL; 31036394Scc210113 break; 31046394Scc210113 } 31056394Scc210113 31067607STed.You@Sun.COM /* ich8 does not support jumbo frames */ 31076394Scc210113 if ((mac->type == e1000_ich8lan) && 31086394Scc210113 (tmp > DEFAULT_FRAME_SIZE)) { 31096394Scc210113 err = EINVAL; 31106394Scc210113 break; 31116394Scc210113 } 31126394Scc210113 /* ich9 does not do jumbo frames on one phy type */ 31136394Scc210113 if ((mac->type == e1000_ich9lan) && 31146394Scc210113 (phy->type == e1000_phy_ife) && 31156394Scc210113 (tmp > DEFAULT_FRAME_SIZE)) { 31166394Scc210113 err = EINVAL; 31176394Scc210113 break; 31186394Scc210113 } 31198479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) { 31206394Scc210113 err = EBUSY; 31216394Scc210113 break; 31226394Scc210113 } 31236394Scc210113 31246394Scc210113 err = mac_maxsdu_update(Adapter->mh, new_mtu); 31256394Scc210113 if (err == 0) { 31267426SChenliang.Xu@Sun.COM Adapter->max_frame_size = (uint32_t)tmp; 31276394Scc210113 Adapter->default_mtu = new_mtu; 31286394Scc210113 e1000g_set_bufsize(Adapter); 31296394Scc210113 } 31306394Scc210113 break; 31316789Sam223141 case MAC_PROP_PRIVATE: 31326394Scc210113 err = e1000g_set_priv_prop(Adapter, pr_name, 31336394Scc210113 pr_valsize, pr_val); 31346394Scc210113 break; 31356394Scc210113 default: 31366394Scc210113 err = ENOTSUP; 31376394Scc210113 break; 31386394Scc210113 } 31396394Scc210113 rw_exit(&Adapter->chip_lock); 31406394Scc210113 return (err); 31416394Scc210113 } 31426394Scc210113 31436394Scc210113 static int 31446394Scc210113 e1000g_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num, 31458118SVasumathi.Sundaram@Sun.COM uint_t pr_flags, uint_t pr_valsize, void *pr_val, uint_t *perm) 31466394Scc210113 { 31476394Scc210113 struct e1000g *Adapter = arg; 31486735Scc210113 struct e1000_fc_info *fc = &Adapter->shared.fc; 31496512Ssowmini int err = 0; 31506735Scc210113 link_flowctrl_t flowctrl; 31516394Scc210113 uint64_t tmp = 0; 31526394Scc210113 31536512Ssowmini if (pr_valsize == 0) 31546512Ssowmini return (EINVAL); 31556512Ssowmini 31568118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_RW; 31578118SVasumathi.Sundaram@Sun.COM 31586394Scc210113 bzero(pr_val, pr_valsize); 31596789Sam223141 if ((pr_flags & MAC_PROP_DEFAULT) && (pr_num != MAC_PROP_PRIVATE)) { 31606512Ssowmini return (e1000g_get_def_val(Adapter, pr_num, 31616512Ssowmini pr_valsize, pr_val)); 31626512Ssowmini } 31636512Ssowmini 31646394Scc210113 switch (pr_num) { 31656789Sam223141 case MAC_PROP_DUPLEX: 31668118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 31676512Ssowmini if (pr_valsize >= sizeof (link_duplex_t)) { 31686512Ssowmini bcopy(&Adapter->link_duplex, pr_val, 31696512Ssowmini sizeof (link_duplex_t)); 31706512Ssowmini } else 31716512Ssowmini err = EINVAL; 31726394Scc210113 break; 31736789Sam223141 case MAC_PROP_SPEED: 31748118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 31756394Scc210113 if (pr_valsize >= sizeof (uint64_t)) { 31766394Scc210113 tmp = Adapter->link_speed * 1000000ull; 31776394Scc210113 bcopy(&tmp, pr_val, sizeof (tmp)); 31786512Ssowmini } else 31796512Ssowmini err = EINVAL; 31806394Scc210113 break; 31816789Sam223141 case MAC_PROP_AUTONEG: 31826512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_autoneg; 31836394Scc210113 break; 31846789Sam223141 case MAC_PROP_FLOWCTRL: 31856394Scc210113 if (pr_valsize >= sizeof (link_flowctrl_t)) { 31868479SChenlu.Chen@Sun.COM switch (fc->current_mode) { 31876394Scc210113 case e1000_fc_none: 31886735Scc210113 flowctrl = LINK_FLOWCTRL_NONE; 31896394Scc210113 break; 31906394Scc210113 case e1000_fc_rx_pause: 31916735Scc210113 flowctrl = LINK_FLOWCTRL_RX; 31926394Scc210113 break; 31936394Scc210113 case e1000_fc_tx_pause: 31946735Scc210113 flowctrl = LINK_FLOWCTRL_TX; 31956394Scc210113 break; 31966394Scc210113 case e1000_fc_full: 31976735Scc210113 flowctrl = LINK_FLOWCTRL_BI; 31986394Scc210113 break; 31996394Scc210113 } 32006735Scc210113 bcopy(&flowctrl, pr_val, sizeof (flowctrl)); 32016512Ssowmini } else 32026512Ssowmini err = EINVAL; 32036394Scc210113 break; 32046789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 32058118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32066512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_1000fdx; 32076394Scc210113 break; 32086789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 32096512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_1000fdx; 32106394Scc210113 break; 32116789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 32128118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32136512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_1000hdx; 32146394Scc210113 break; 32156789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 32168118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32176512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_1000hdx; 32186394Scc210113 break; 32196789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 32208118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32216512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100fdx; 32226394Scc210113 break; 32236789Sam223141 case MAC_PROP_EN_100FDX_CAP: 32246512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_100fdx; 32256394Scc210113 break; 32266789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 32278118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32286512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100hdx; 32296394Scc210113 break; 32306789Sam223141 case MAC_PROP_EN_100HDX_CAP: 32316512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_100hdx; 32326394Scc210113 break; 32336789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 32348118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32356512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_10fdx; 32366394Scc210113 break; 32376789Sam223141 case MAC_PROP_EN_10FDX_CAP: 32386512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_10fdx; 32396394Scc210113 break; 32406789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 32418118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32426512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_10hdx; 32436394Scc210113 break; 32446789Sam223141 case MAC_PROP_EN_10HDX_CAP: 32456512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_10hdx; 32466512Ssowmini break; 32476789Sam223141 case MAC_PROP_ADV_100T4_CAP: 32486789Sam223141 case MAC_PROP_EN_100T4_CAP: 32498118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 32506512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100t4; 32516394Scc210113 break; 32526789Sam223141 case MAC_PROP_PRIVATE: 32536394Scc210113 err = e1000g_get_priv_prop(Adapter, pr_name, 32548118SVasumathi.Sundaram@Sun.COM pr_flags, pr_valsize, pr_val, perm); 32556394Scc210113 break; 32569514SGirish.Moodalbail@Sun.COM case MAC_PROP_MTU: { 32579514SGirish.Moodalbail@Sun.COM struct e1000_mac_info *mac = &Adapter->shared.mac; 32589514SGirish.Moodalbail@Sun.COM struct e1000_phy_info *phy = &Adapter->shared.phy; 32599514SGirish.Moodalbail@Sun.COM mac_propval_range_t range; 32609514SGirish.Moodalbail@Sun.COM 32619514SGirish.Moodalbail@Sun.COM if (!(pr_flags & MAC_PROP_POSSIBLE)) 32629514SGirish.Moodalbail@Sun.COM return (ENOTSUP); 32639514SGirish.Moodalbail@Sun.COM if (pr_valsize < sizeof (mac_propval_range_t)) 32649514SGirish.Moodalbail@Sun.COM return (EINVAL); 32659514SGirish.Moodalbail@Sun.COM range.mpr_count = 1; 32669514SGirish.Moodalbail@Sun.COM range.mpr_type = MAC_PROPVAL_UINT32; 32679514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_min = DEFAULT_MTU; 32689514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_max = MAXIMUM_MTU; 32699514SGirish.Moodalbail@Sun.COM /* following MAC type do not support jumbo frames */ 32709514SGirish.Moodalbail@Sun.COM if ((mac->type == e1000_ich8lan) || 32719514SGirish.Moodalbail@Sun.COM ((mac->type == e1000_ich9lan) && (phy->type == 32729514SGirish.Moodalbail@Sun.COM e1000_phy_ife))) { 32739514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_max = DEFAULT_MTU; 32749514SGirish.Moodalbail@Sun.COM } 32759514SGirish.Moodalbail@Sun.COM bcopy(&range, pr_val, sizeof (range)); 32769514SGirish.Moodalbail@Sun.COM break; 32779514SGirish.Moodalbail@Sun.COM } 32786394Scc210113 default: 32796394Scc210113 err = ENOTSUP; 32806394Scc210113 break; 32816394Scc210113 } 32826394Scc210113 return (err); 32836394Scc210113 } 32846394Scc210113 32857426SChenliang.Xu@Sun.COM /* ARGSUSED2 */ 32866394Scc210113 static int 32876394Scc210113 e1000g_set_priv_prop(struct e1000g *Adapter, const char *pr_name, 32886394Scc210113 uint_t pr_valsize, const void *pr_val) 32896394Scc210113 { 32906394Scc210113 int err = 0; 32916394Scc210113 long result; 32926394Scc210113 struct e1000_hw *hw = &Adapter->shared; 32936394Scc210113 32946394Scc210113 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) { 32956394Scc210113 if (pr_val == NULL) { 32966394Scc210113 err = EINVAL; 32976394Scc210113 return (err); 32986394Scc210113 } 32996394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33006394Scc210113 if (result < MIN_TX_BCOPY_THRESHOLD || 33016394Scc210113 result > MAX_TX_BCOPY_THRESHOLD) 33026394Scc210113 err = EINVAL; 33036394Scc210113 else { 33046394Scc210113 Adapter->tx_bcopy_thresh = (uint32_t)result; 33056394Scc210113 } 33066394Scc210113 return (err); 33076394Scc210113 } 33086394Scc210113 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) { 33096394Scc210113 if (pr_val == NULL) { 33106394Scc210113 err = EINVAL; 33116394Scc210113 return (err); 33126394Scc210113 } 33136394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33146394Scc210113 if (result < 0 || result > 1) 33156394Scc210113 err = EINVAL; 33166394Scc210113 else { 33176394Scc210113 Adapter->tx_intr_enable = (result == 1) ? 33186394Scc210113 B_TRUE: B_FALSE; 33196394Scc210113 if (Adapter->tx_intr_enable) 33206394Scc210113 e1000g_mask_tx_interrupt(Adapter); 33216394Scc210113 else 33226394Scc210113 e1000g_clear_tx_interrupt(Adapter); 33236394Scc210113 if (e1000g_check_acc_handle( 33246394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 33256394Scc210113 ddi_fm_service_impact(Adapter->dip, 33266394Scc210113 DDI_SERVICE_DEGRADED); 33276394Scc210113 } 33286394Scc210113 return (err); 33296394Scc210113 } 33306394Scc210113 if (strcmp(pr_name, "_tx_intr_delay") == 0) { 33316394Scc210113 if (pr_val == NULL) { 33326394Scc210113 err = EINVAL; 33336394Scc210113 return (err); 33346394Scc210113 } 33356394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33366394Scc210113 if (result < MIN_TX_INTR_DELAY || 33376394Scc210113 result > MAX_TX_INTR_DELAY) 33386394Scc210113 err = EINVAL; 33396394Scc210113 else { 33406394Scc210113 Adapter->tx_intr_delay = (uint32_t)result; 33416394Scc210113 E1000_WRITE_REG(hw, E1000_TIDV, Adapter->tx_intr_delay); 33426394Scc210113 if (e1000g_check_acc_handle( 33436394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 33446394Scc210113 ddi_fm_service_impact(Adapter->dip, 33456394Scc210113 DDI_SERVICE_DEGRADED); 33466394Scc210113 } 33476394Scc210113 return (err); 33486394Scc210113 } 33496394Scc210113 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) { 33506394Scc210113 if (pr_val == NULL) { 33516394Scc210113 err = EINVAL; 33526394Scc210113 return (err); 33536394Scc210113 } 33546394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33556394Scc210113 if (result < MIN_TX_INTR_ABS_DELAY || 33566394Scc210113 result > MAX_TX_INTR_ABS_DELAY) 33576394Scc210113 err = EINVAL; 33586394Scc210113 else { 33596394Scc210113 Adapter->tx_intr_abs_delay = (uint32_t)result; 33606394Scc210113 E1000_WRITE_REG(hw, E1000_TADV, 33616394Scc210113 Adapter->tx_intr_abs_delay); 33626394Scc210113 if (e1000g_check_acc_handle( 33636394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 33646394Scc210113 ddi_fm_service_impact(Adapter->dip, 33656394Scc210113 DDI_SERVICE_DEGRADED); 33666394Scc210113 } 33676394Scc210113 return (err); 33686394Scc210113 } 33696394Scc210113 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) { 33706394Scc210113 if (pr_val == NULL) { 33716394Scc210113 err = EINVAL; 33726394Scc210113 return (err); 33736394Scc210113 } 33746394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33756394Scc210113 if (result < MIN_RX_BCOPY_THRESHOLD || 33766394Scc210113 result > MAX_RX_BCOPY_THRESHOLD) 33776394Scc210113 err = EINVAL; 33786394Scc210113 else 33796394Scc210113 Adapter->rx_bcopy_thresh = (uint32_t)result; 33806394Scc210113 return (err); 33816394Scc210113 } 33826394Scc210113 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) { 33836394Scc210113 if (pr_val == NULL) { 33846394Scc210113 err = EINVAL; 33856394Scc210113 return (err); 33866394Scc210113 } 33876394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 33886394Scc210113 if (result < MIN_RX_LIMIT_ON_INTR || 33896394Scc210113 result > MAX_RX_LIMIT_ON_INTR) 33906394Scc210113 err = EINVAL; 33916394Scc210113 else 33926394Scc210113 Adapter->rx_limit_onintr = (uint32_t)result; 33936394Scc210113 return (err); 33946394Scc210113 } 33956394Scc210113 if (strcmp(pr_name, "_rx_intr_delay") == 0) { 33966394Scc210113 if (pr_val == NULL) { 33976394Scc210113 err = EINVAL; 33986394Scc210113 return (err); 33996394Scc210113 } 34006394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 34016394Scc210113 if (result < MIN_RX_INTR_DELAY || 34026394Scc210113 result > MAX_RX_INTR_DELAY) 34036394Scc210113 err = EINVAL; 34046394Scc210113 else { 34056394Scc210113 Adapter->rx_intr_delay = (uint32_t)result; 34066394Scc210113 E1000_WRITE_REG(hw, E1000_RDTR, Adapter->rx_intr_delay); 34076394Scc210113 if (e1000g_check_acc_handle( 34086394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 34096394Scc210113 ddi_fm_service_impact(Adapter->dip, 34106394Scc210113 DDI_SERVICE_DEGRADED); 34116394Scc210113 } 34126394Scc210113 return (err); 34136394Scc210113 } 34146394Scc210113 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) { 34156394Scc210113 if (pr_val == NULL) { 34166394Scc210113 err = EINVAL; 34176394Scc210113 return (err); 34186394Scc210113 } 34196394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 34206394Scc210113 if (result < MIN_RX_INTR_ABS_DELAY || 34216394Scc210113 result > MAX_RX_INTR_ABS_DELAY) 34226394Scc210113 err = EINVAL; 34236394Scc210113 else { 34246394Scc210113 Adapter->rx_intr_abs_delay = (uint32_t)result; 34256394Scc210113 E1000_WRITE_REG(hw, E1000_RADV, 34266394Scc210113 Adapter->rx_intr_abs_delay); 34276394Scc210113 if (e1000g_check_acc_handle( 34286394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 34296394Scc210113 ddi_fm_service_impact(Adapter->dip, 34306394Scc210113 DDI_SERVICE_DEGRADED); 34316394Scc210113 } 34326394Scc210113 return (err); 34336394Scc210113 } 34346394Scc210113 if (strcmp(pr_name, "_intr_throttling_rate") == 0) { 34356394Scc210113 if (pr_val == NULL) { 34366394Scc210113 err = EINVAL; 34376394Scc210113 return (err); 34386394Scc210113 } 34396394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 34406394Scc210113 if (result < MIN_INTR_THROTTLING || 34416394Scc210113 result > MAX_INTR_THROTTLING) 34426394Scc210113 err = EINVAL; 34436394Scc210113 else { 34446394Scc210113 if (hw->mac.type >= e1000_82540) { 34456394Scc210113 Adapter->intr_throttling_rate = 34466394Scc210113 (uint32_t)result; 34476394Scc210113 E1000_WRITE_REG(hw, E1000_ITR, 34486394Scc210113 Adapter->intr_throttling_rate); 34496394Scc210113 if (e1000g_check_acc_handle( 34506394Scc210113 Adapter->osdep.reg_handle) != DDI_FM_OK) 34516394Scc210113 ddi_fm_service_impact(Adapter->dip, 34526394Scc210113 DDI_SERVICE_DEGRADED); 34536394Scc210113 } else 34546394Scc210113 err = EINVAL; 34556394Scc210113 } 34566394Scc210113 return (err); 34576394Scc210113 } 34586394Scc210113 if (strcmp(pr_name, "_intr_adaptive") == 0) { 34596394Scc210113 if (pr_val == NULL) { 34606394Scc210113 err = EINVAL; 34616394Scc210113 return (err); 34626394Scc210113 } 34636394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 34646394Scc210113 if (result < 0 || result > 1) 34656394Scc210113 err = EINVAL; 34666394Scc210113 else { 34676394Scc210113 if (hw->mac.type >= e1000_82540) { 34686394Scc210113 Adapter->intr_adaptive = (result == 1) ? 34696394Scc210113 B_TRUE : B_FALSE; 34706394Scc210113 } else { 34716394Scc210113 err = EINVAL; 34726394Scc210113 } 34736394Scc210113 } 34746394Scc210113 return (err); 34756394Scc210113 } 34766394Scc210113 return (ENOTSUP); 34776394Scc210113 } 34786394Scc210113 34796394Scc210113 static int 34806394Scc210113 e1000g_get_priv_prop(struct e1000g *Adapter, const char *pr_name, 34818118SVasumathi.Sundaram@Sun.COM uint_t pr_flags, uint_t pr_valsize, void *pr_val, uint_t *perm) 34826394Scc210113 { 34836394Scc210113 int err = ENOTSUP; 34846789Sam223141 boolean_t is_default = (pr_flags & MAC_PROP_DEFAULT); 34856512Ssowmini int value; 34866512Ssowmini 34876512Ssowmini if (strcmp(pr_name, "_adv_pause_cap") == 0) { 34888118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 34896512Ssowmini if (is_default) 34906512Ssowmini goto done; 34916512Ssowmini value = Adapter->param_adv_pause; 34926512Ssowmini err = 0; 34936512Ssowmini goto done; 34946512Ssowmini } 34956512Ssowmini if (strcmp(pr_name, "_adv_asym_pause_cap") == 0) { 34968118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 34976512Ssowmini if (is_default) 34986512Ssowmini goto done; 34996512Ssowmini value = Adapter->param_adv_asym_pause; 35006512Ssowmini err = 0; 35016512Ssowmini goto done; 35026512Ssowmini } 35036394Scc210113 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) { 35046512Ssowmini value = (is_default ? DEFAULT_TX_BCOPY_THRESHOLD : 35056512Ssowmini Adapter->tx_bcopy_thresh); 35066394Scc210113 err = 0; 35076394Scc210113 goto done; 35086394Scc210113 } 35096394Scc210113 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) { 35106512Ssowmini value = (is_default ? DEFAULT_TX_INTR_ENABLE : 35116512Ssowmini Adapter->tx_intr_enable); 35126394Scc210113 err = 0; 35136394Scc210113 goto done; 35146394Scc210113 } 35156394Scc210113 if (strcmp(pr_name, "_tx_intr_delay") == 0) { 35166512Ssowmini value = (is_default ? DEFAULT_TX_INTR_DELAY : 35176512Ssowmini Adapter->tx_intr_delay); 35186394Scc210113 err = 0; 35196394Scc210113 goto done; 35206394Scc210113 } 35216394Scc210113 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) { 35226512Ssowmini value = (is_default ? DEFAULT_TX_INTR_ABS_DELAY : 35236512Ssowmini Adapter->tx_intr_abs_delay); 35246394Scc210113 err = 0; 35256394Scc210113 goto done; 35266394Scc210113 } 35276394Scc210113 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) { 35286512Ssowmini value = (is_default ? DEFAULT_RX_BCOPY_THRESHOLD : 35296512Ssowmini Adapter->rx_bcopy_thresh); 35306394Scc210113 err = 0; 35316394Scc210113 goto done; 35326394Scc210113 } 35336394Scc210113 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) { 35346512Ssowmini value = (is_default ? DEFAULT_RX_LIMIT_ON_INTR : 35356512Ssowmini Adapter->rx_limit_onintr); 35366394Scc210113 err = 0; 35376394Scc210113 goto done; 35386394Scc210113 } 35396394Scc210113 if (strcmp(pr_name, "_rx_intr_delay") == 0) { 35406512Ssowmini value = (is_default ? DEFAULT_RX_INTR_DELAY : 35416512Ssowmini Adapter->rx_intr_delay); 35426394Scc210113 err = 0; 35436394Scc210113 goto done; 35446394Scc210113 } 35456394Scc210113 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) { 35466512Ssowmini value = (is_default ? DEFAULT_RX_INTR_ABS_DELAY : 35476512Ssowmini Adapter->rx_intr_abs_delay); 35486394Scc210113 err = 0; 35496394Scc210113 goto done; 35506394Scc210113 } 35516394Scc210113 if (strcmp(pr_name, "_intr_throttling_rate") == 0) { 35526512Ssowmini value = (is_default ? DEFAULT_INTR_THROTTLING : 35536512Ssowmini Adapter->intr_throttling_rate); 35546394Scc210113 err = 0; 35556394Scc210113 goto done; 35566394Scc210113 } 35576394Scc210113 if (strcmp(pr_name, "_intr_adaptive") == 0) { 35586512Ssowmini value = (is_default ? 1 : Adapter->intr_adaptive); 35596394Scc210113 err = 0; 35606394Scc210113 goto done; 35616394Scc210113 } 35626394Scc210113 done: 35636394Scc210113 if (err == 0) { 35646512Ssowmini (void) snprintf(pr_val, pr_valsize, "%d", value); 35656394Scc210113 } 35666394Scc210113 return (err); 35676394Scc210113 } 35686394Scc210113 35693526Sxy150489 /* 35704919Sxy150489 * e1000g_get_conf - get configurations set in e1000g.conf 35714919Sxy150489 * This routine gets user-configured values out of the configuration 35724919Sxy150489 * file e1000g.conf. 35734919Sxy150489 * 35744919Sxy150489 * For each configurable value, there is a minimum, a maximum, and a 35754919Sxy150489 * default. 35764919Sxy150489 * If user does not configure a value, use the default. 35774919Sxy150489 * If user configures below the minimum, use the minumum. 35784919Sxy150489 * If user configures above the maximum, use the maxumum. 35793526Sxy150489 */ 35803526Sxy150489 static void 35814919Sxy150489 e1000g_get_conf(struct e1000g *Adapter) 35823526Sxy150489 { 35834919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 35844919Sxy150489 boolean_t tbi_compatibility = B_FALSE; 35854919Sxy150489 35863526Sxy150489 /* 35873526Sxy150489 * get each configurable property from e1000g.conf 35883526Sxy150489 */ 35893526Sxy150489 35903526Sxy150489 /* 35913526Sxy150489 * NumTxDescriptors 35923526Sxy150489 */ 35934919Sxy150489 Adapter->tx_desc_num = 35944919Sxy150489 e1000g_get_prop(Adapter, "NumTxDescriptors", 35954919Sxy150489 MIN_NUM_TX_DESCRIPTOR, MAX_NUM_TX_DESCRIPTOR, 35964919Sxy150489 DEFAULT_NUM_TX_DESCRIPTOR); 35973526Sxy150489 35983526Sxy150489 /* 35993526Sxy150489 * NumRxDescriptors 36003526Sxy150489 */ 36014919Sxy150489 Adapter->rx_desc_num = 36024919Sxy150489 e1000g_get_prop(Adapter, "NumRxDescriptors", 36034919Sxy150489 MIN_NUM_RX_DESCRIPTOR, MAX_NUM_RX_DESCRIPTOR, 36044919Sxy150489 DEFAULT_NUM_RX_DESCRIPTOR); 36053526Sxy150489 36063526Sxy150489 /* 36073526Sxy150489 * NumRxFreeList 36083526Sxy150489 */ 36094919Sxy150489 Adapter->rx_freelist_num = 36104919Sxy150489 e1000g_get_prop(Adapter, "NumRxFreeList", 36114919Sxy150489 MIN_NUM_RX_FREELIST, MAX_NUM_RX_FREELIST, 36124919Sxy150489 DEFAULT_NUM_RX_FREELIST); 36133526Sxy150489 36143526Sxy150489 /* 36153526Sxy150489 * NumTxPacketList 36163526Sxy150489 */ 36174919Sxy150489 Adapter->tx_freelist_num = 36184919Sxy150489 e1000g_get_prop(Adapter, "NumTxPacketList", 36194919Sxy150489 MIN_NUM_TX_FREELIST, MAX_NUM_TX_FREELIST, 36204919Sxy150489 DEFAULT_NUM_TX_FREELIST); 36213526Sxy150489 36223526Sxy150489 /* 36233526Sxy150489 * FlowControl 36243526Sxy150489 */ 36256735Scc210113 hw->fc.send_xon = B_TRUE; 36268539SChenlu.Chen@Sun.COM hw->fc.requested_mode = 36274919Sxy150489 e1000g_get_prop(Adapter, "FlowControl", 36284919Sxy150489 e1000_fc_none, 4, DEFAULT_FLOW_CONTROL); 36293526Sxy150489 /* 4 is the setting that says "let the eeprom decide" */ 36308539SChenlu.Chen@Sun.COM if (hw->fc.requested_mode == 4) 36318539SChenlu.Chen@Sun.COM hw->fc.requested_mode = e1000_fc_default; 36323526Sxy150489 36333526Sxy150489 /* 36344919Sxy150489 * Max Num Receive Packets on Interrupt 36353526Sxy150489 */ 36364919Sxy150489 Adapter->rx_limit_onintr = 36374919Sxy150489 e1000g_get_prop(Adapter, "MaxNumReceivePackets", 36384919Sxy150489 MIN_RX_LIMIT_ON_INTR, MAX_RX_LIMIT_ON_INTR, 36394919Sxy150489 DEFAULT_RX_LIMIT_ON_INTR); 36403526Sxy150489 36413526Sxy150489 /* 36423526Sxy150489 * PHY master slave setting 36433526Sxy150489 */ 36444919Sxy150489 hw->phy.ms_type = 36454919Sxy150489 e1000g_get_prop(Adapter, "SetMasterSlave", 36463526Sxy150489 e1000_ms_hw_default, e1000_ms_auto, 36473526Sxy150489 e1000_ms_hw_default); 36483526Sxy150489 36493526Sxy150489 /* 36503526Sxy150489 * Parameter which controls TBI mode workaround, which is only 36513526Sxy150489 * needed on certain switches such as Cisco 6500/Foundry 36523526Sxy150489 */ 36534919Sxy150489 tbi_compatibility = 36544919Sxy150489 e1000g_get_prop(Adapter, "TbiCompatibilityEnable", 36554919Sxy150489 0, 1, DEFAULT_TBI_COMPAT_ENABLE); 36564919Sxy150489 e1000_set_tbi_compatibility_82543(hw, tbi_compatibility); 36573526Sxy150489 36583526Sxy150489 /* 36593526Sxy150489 * MSI Enable 36603526Sxy150489 */ 36616986Smx205022 Adapter->msi_enable = 36624919Sxy150489 e1000g_get_prop(Adapter, "MSIEnable", 36634919Sxy150489 0, 1, DEFAULT_MSI_ENABLE); 36643526Sxy150489 36653526Sxy150489 /* 36663526Sxy150489 * Interrupt Throttling Rate 36673526Sxy150489 */ 36683526Sxy150489 Adapter->intr_throttling_rate = 36694919Sxy150489 e1000g_get_prop(Adapter, "intr_throttling_rate", 36704919Sxy150489 MIN_INTR_THROTTLING, MAX_INTR_THROTTLING, 36714919Sxy150489 DEFAULT_INTR_THROTTLING); 36723526Sxy150489 36733526Sxy150489 /* 36743526Sxy150489 * Adaptive Interrupt Blanking Enable/Disable 36753526Sxy150489 * It is enabled by default 36763526Sxy150489 */ 36773526Sxy150489 Adapter->intr_adaptive = 36784919Sxy150489 (e1000g_get_prop(Adapter, "intr_adaptive", 0, 1, 1) == 1) ? 36793526Sxy150489 B_TRUE : B_FALSE; 36805882Syy150190 36815882Syy150190 /* 36826011Ssv141092 * Hardware checksum enable/disable parameter 36836011Ssv141092 */ 36846986Smx205022 Adapter->tx_hcksum_enable = 36856986Smx205022 e1000g_get_prop(Adapter, "tx_hcksum_enable", 36866011Ssv141092 0, 1, DEFAULT_TX_HCKSUM_ENABLE); 36876986Smx205022 /* 36886986Smx205022 * Checksum on/off selection via global parameters. 36896986Smx205022 * 36906986Smx205022 * If the chip is flagged as not capable of (correctly) 36916986Smx205022 * handling checksumming, we don't enable it on either 36926986Smx205022 * Rx or Tx side. Otherwise, we take this chip's settings 36936986Smx205022 * from the patchable global defaults. 36946986Smx205022 * 36956986Smx205022 * We advertise our capabilities only if TX offload is 36966986Smx205022 * enabled. On receive, the stack will accept checksummed 36976986Smx205022 * packets anyway, even if we haven't said we can deliver 36986986Smx205022 * them. 36996986Smx205022 */ 37006986Smx205022 switch (hw->mac.type) { 37016986Smx205022 case e1000_82540: 37026986Smx205022 case e1000_82544: 37036986Smx205022 case e1000_82545: 37046986Smx205022 case e1000_82545_rev_3: 37056986Smx205022 case e1000_82546: 37066986Smx205022 case e1000_82546_rev_3: 37076986Smx205022 case e1000_82571: 37086986Smx205022 case e1000_82572: 37096986Smx205022 case e1000_82573: 37106986Smx205022 case e1000_80003es2lan: 37116986Smx205022 break; 37126986Smx205022 /* 37136986Smx205022 * For the following Intel PRO/1000 chipsets, we have not 37146986Smx205022 * tested the hardware checksum offload capability, so we 37156986Smx205022 * disable the capability for them. 37166986Smx205022 * e1000_82542, 37176986Smx205022 * e1000_82543, 37186986Smx205022 * e1000_82541, 37196986Smx205022 * e1000_82541_rev_2, 37206986Smx205022 * e1000_82547, 37216986Smx205022 * e1000_82547_rev_2, 37226986Smx205022 */ 37236986Smx205022 default: 37246986Smx205022 Adapter->tx_hcksum_enable = B_FALSE; 37256986Smx205022 } 37266986Smx205022 37276986Smx205022 /* 37286986Smx205022 * Large Send Offloading(LSO) Enable/Disable 37296986Smx205022 * If the tx hardware checksum is not enabled, LSO should be 37306986Smx205022 * disabled. 37316986Smx205022 */ 37326986Smx205022 Adapter->lso_enable = 37336986Smx205022 e1000g_get_prop(Adapter, "lso_enable", 37346986Smx205022 0, 1, DEFAULT_LSO_ENABLE); 37356986Smx205022 37366986Smx205022 switch (hw->mac.type) { 37376986Smx205022 case e1000_82546: 37386986Smx205022 case e1000_82546_rev_3: 37396986Smx205022 if (Adapter->lso_enable) 37406986Smx205022 Adapter->lso_premature_issue = B_TRUE; 37417426SChenliang.Xu@Sun.COM /* FALLTHRU */ 37426986Smx205022 case e1000_82571: 37436986Smx205022 case e1000_82572: 37446986Smx205022 case e1000_82573: 37458073SMin.Xu@Sun.COM case e1000_80003es2lan: 37466986Smx205022 break; 37476986Smx205022 default: 37486986Smx205022 Adapter->lso_enable = B_FALSE; 37496986Smx205022 } 37506986Smx205022 37516986Smx205022 if (!Adapter->tx_hcksum_enable) { 37526986Smx205022 Adapter->lso_premature_issue = B_FALSE; 37536986Smx205022 Adapter->lso_enable = B_FALSE; 37546986Smx205022 } 37558417SChenlu.Chen@Sun.COM 37568417SChenlu.Chen@Sun.COM /* 37578417SChenlu.Chen@Sun.COM * If mem_workaround_82546 is enabled, the rx buffer allocated by 37588417SChenlu.Chen@Sun.COM * e1000_82545, e1000_82546 and e1000_82546_rev_3 37598417SChenlu.Chen@Sun.COM * will not cross 64k boundary. 37608417SChenlu.Chen@Sun.COM */ 37618417SChenlu.Chen@Sun.COM Adapter->mem_workaround_82546 = 37628417SChenlu.Chen@Sun.COM e1000g_get_prop(Adapter, "mem_workaround_82546", 37638417SChenlu.Chen@Sun.COM 0, 1, DEFAULT_MEM_WORKAROUND_82546); 37649770SChangqing.Li@Sun.COM 37659770SChangqing.Li@Sun.COM /* 37669770SChangqing.Li@Sun.COM * Max number of multicast addresses 37679770SChangqing.Li@Sun.COM */ 37689770SChangqing.Li@Sun.COM Adapter->mcast_max_num = 37699770SChangqing.Li@Sun.COM e1000g_get_prop(Adapter, "mcast_max_num", 37709770SChangqing.Li@Sun.COM MIN_MCAST_NUM, MAX_MCAST_NUM, hw->mac.mta_reg_count * 32); 37713526Sxy150489 } 37723526Sxy150489 37733526Sxy150489 /* 37744919Sxy150489 * e1000g_get_prop - routine to read properties 37754919Sxy150489 * 37764919Sxy150489 * Get a user-configure property value out of the configuration 37774919Sxy150489 * file e1000g.conf. 37784919Sxy150489 * 37794919Sxy150489 * Caller provides name of the property, a default value, a minimum 37804919Sxy150489 * value, and a maximum value. 37814919Sxy150489 * 37824919Sxy150489 * Return configured value of the property, with default, minimum and 37834919Sxy150489 * maximum properly applied. 37843526Sxy150489 */ 37853526Sxy150489 static int 37864919Sxy150489 e1000g_get_prop(struct e1000g *Adapter, /* point to per-adapter structure */ 37873526Sxy150489 char *propname, /* name of the property */ 37883526Sxy150489 int minval, /* minimum acceptable value */ 37893526Sxy150489 int maxval, /* maximim acceptable value */ 37903526Sxy150489 int defval) /* default value */ 37913526Sxy150489 { 37923526Sxy150489 int propval; /* value returned for requested property */ 37933526Sxy150489 int *props; /* point to array of properties returned */ 37943526Sxy150489 uint_t nprops; /* number of property value returned */ 37953526Sxy150489 37963526Sxy150489 /* 37973526Sxy150489 * get the array of properties from the config file 37983526Sxy150489 */ 37993526Sxy150489 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, Adapter->dip, 38003526Sxy150489 DDI_PROP_DONTPASS, propname, &props, &nprops) == DDI_PROP_SUCCESS) { 38013526Sxy150489 /* got some properties, test if we got enough */ 38024919Sxy150489 if (Adapter->instance < nprops) { 38034919Sxy150489 propval = props[Adapter->instance]; 38043526Sxy150489 } else { 38053526Sxy150489 /* not enough properties configured */ 38063526Sxy150489 propval = defval; 38074919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 38083526Sxy150489 "Not Enough %s values found in e1000g.conf" 38093526Sxy150489 " - set to %d\n", 38103526Sxy150489 propname, propval); 38113526Sxy150489 } 38123526Sxy150489 38133526Sxy150489 /* free memory allocated for properties */ 38143526Sxy150489 ddi_prop_free(props); 38153526Sxy150489 38163526Sxy150489 } else { 38173526Sxy150489 propval = defval; 38183526Sxy150489 } 38193526Sxy150489 38203526Sxy150489 /* 38213526Sxy150489 * enforce limits 38223526Sxy150489 */ 38233526Sxy150489 if (propval > maxval) { 38243526Sxy150489 propval = maxval; 38254919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 38263526Sxy150489 "Too High %s value in e1000g.conf - set to %d\n", 38273526Sxy150489 propname, propval); 38283526Sxy150489 } 38293526Sxy150489 38303526Sxy150489 if (propval < minval) { 38313526Sxy150489 propval = minval; 38324919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 38333526Sxy150489 "Too Low %s value in e1000g.conf - set to %d\n", 38343526Sxy150489 propname, propval); 38353526Sxy150489 } 38363526Sxy150489 38373526Sxy150489 return (propval); 38383526Sxy150489 } 38393526Sxy150489 38403526Sxy150489 static boolean_t 38414061Sxy150489 e1000g_link_check(struct e1000g *Adapter) 38423526Sxy150489 { 38434061Sxy150489 uint16_t speed, duplex, phydata; 38444061Sxy150489 boolean_t link_changed = B_FALSE; 38453526Sxy150489 struct e1000_hw *hw; 38463526Sxy150489 uint32_t reg_tarc; 38473526Sxy150489 38484919Sxy150489 hw = &Adapter->shared; 38493526Sxy150489 38503526Sxy150489 if (e1000g_link_up(Adapter)) { 38513526Sxy150489 /* 38523526Sxy150489 * The Link is up, check whether it was marked as down earlier 38533526Sxy150489 */ 38544061Sxy150489 if (Adapter->link_state != LINK_STATE_UP) { 38557426SChenliang.Xu@Sun.COM (void) e1000_get_speed_and_duplex(hw, &speed, &duplex); 38564061Sxy150489 Adapter->link_speed = speed; 38574061Sxy150489 Adapter->link_duplex = duplex; 38584061Sxy150489 Adapter->link_state = LINK_STATE_UP; 38594061Sxy150489 link_changed = B_TRUE; 38604061Sxy150489 38618850SMin.Xu@Sun.COM if (Adapter->link_speed == SPEED_1000) 38628850SMin.Xu@Sun.COM Adapter->stall_threshold = TX_STALL_TIME_2S; 38638850SMin.Xu@Sun.COM else 38648850SMin.Xu@Sun.COM Adapter->stall_threshold = TX_STALL_TIME_8S; 38658850SMin.Xu@Sun.COM 38664061Sxy150489 Adapter->tx_link_down_timeout = 0; 38674061Sxy150489 38684919Sxy150489 if ((hw->mac.type == e1000_82571) || 38694919Sxy150489 (hw->mac.type == e1000_82572)) { 38706735Scc210113 reg_tarc = E1000_READ_REG(hw, E1000_TARC(0)); 38714061Sxy150489 if (speed == SPEED_1000) 38724061Sxy150489 reg_tarc |= (1 << 21); 38734061Sxy150489 else 38744061Sxy150489 reg_tarc &= ~(1 << 21); 38756735Scc210113 E1000_WRITE_REG(hw, E1000_TARC(0), reg_tarc); 38763526Sxy150489 } 38773526Sxy150489 } 38783526Sxy150489 Adapter->smartspeed = 0; 38793526Sxy150489 } else { 38804061Sxy150489 if (Adapter->link_state != LINK_STATE_DOWN) { 38813526Sxy150489 Adapter->link_speed = 0; 38823526Sxy150489 Adapter->link_duplex = 0; 38834061Sxy150489 Adapter->link_state = LINK_STATE_DOWN; 38844061Sxy150489 link_changed = B_TRUE; 38854061Sxy150489 38863526Sxy150489 /* 38873526Sxy150489 * SmartSpeed workaround for Tabor/TanaX, When the 38883526Sxy150489 * driver loses link disable auto master/slave 38893526Sxy150489 * resolution. 38903526Sxy150489 */ 38914919Sxy150489 if (hw->phy.type == e1000_phy_igp) { 38927426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, 38933526Sxy150489 PHY_1000T_CTRL, &phydata); 38943526Sxy150489 phydata |= CR_1000T_MS_ENABLE; 38957426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 38963526Sxy150489 PHY_1000T_CTRL, phydata); 38973526Sxy150489 } 38983526Sxy150489 } else { 38993526Sxy150489 e1000g_smartspeed(Adapter); 39003526Sxy150489 } 39014061Sxy150489 39028479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) { 39034061Sxy150489 if (Adapter->tx_link_down_timeout < 39044061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) { 39054061Sxy150489 Adapter->tx_link_down_timeout++; 39064061Sxy150489 } else if (Adapter->tx_link_down_timeout == 39074061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) { 39084919Sxy150489 e1000g_tx_clean(Adapter); 39094061Sxy150489 Adapter->tx_link_down_timeout++; 39104061Sxy150489 } 39114061Sxy150489 } 39123526Sxy150489 } 39133526Sxy150489 39145273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 39155273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 39165273Sgl147354 39174061Sxy150489 return (link_changed); 39184061Sxy150489 } 39194061Sxy150489 39206394Scc210113 /* 39216394Scc210113 * e1000g_reset_link - Using the link properties to setup the link 39226394Scc210113 */ 39236394Scc210113 int 39246394Scc210113 e1000g_reset_link(struct e1000g *Adapter) 39256394Scc210113 { 39266394Scc210113 struct e1000_mac_info *mac; 39276394Scc210113 struct e1000_phy_info *phy; 39286394Scc210113 boolean_t invalid; 39296394Scc210113 39306394Scc210113 mac = &Adapter->shared.mac; 39316394Scc210113 phy = &Adapter->shared.phy; 39326394Scc210113 invalid = B_FALSE; 39336394Scc210113 39346394Scc210113 if (Adapter->param_adv_autoneg == 1) { 39356394Scc210113 mac->autoneg = B_TRUE; 39366394Scc210113 phy->autoneg_advertised = 0; 39376394Scc210113 39386394Scc210113 /* 39396394Scc210113 * 1000hdx is not supported for autonegotiation 39406394Scc210113 */ 39416394Scc210113 if (Adapter->param_adv_1000fdx == 1) 39426394Scc210113 phy->autoneg_advertised |= ADVERTISE_1000_FULL; 39436394Scc210113 39446394Scc210113 if (Adapter->param_adv_100fdx == 1) 39456394Scc210113 phy->autoneg_advertised |= ADVERTISE_100_FULL; 39466394Scc210113 39476394Scc210113 if (Adapter->param_adv_100hdx == 1) 39486394Scc210113 phy->autoneg_advertised |= ADVERTISE_100_HALF; 39496394Scc210113 39506394Scc210113 if (Adapter->param_adv_10fdx == 1) 39516394Scc210113 phy->autoneg_advertised |= ADVERTISE_10_FULL; 39526394Scc210113 39536394Scc210113 if (Adapter->param_adv_10hdx == 1) 39546394Scc210113 phy->autoneg_advertised |= ADVERTISE_10_HALF; 39556394Scc210113 39566394Scc210113 if (phy->autoneg_advertised == 0) 39576394Scc210113 invalid = B_TRUE; 39586394Scc210113 } else { 39596394Scc210113 mac->autoneg = B_FALSE; 39606394Scc210113 39616394Scc210113 /* 39626394Scc210113 * 1000fdx and 1000hdx are not supported for forced link 39636394Scc210113 */ 39646394Scc210113 if (Adapter->param_adv_100fdx == 1) 39656394Scc210113 mac->forced_speed_duplex = ADVERTISE_100_FULL; 39666394Scc210113 else if (Adapter->param_adv_100hdx == 1) 39676394Scc210113 mac->forced_speed_duplex = ADVERTISE_100_HALF; 39686394Scc210113 else if (Adapter->param_adv_10fdx == 1) 39696394Scc210113 mac->forced_speed_duplex = ADVERTISE_10_FULL; 39706394Scc210113 else if (Adapter->param_adv_10hdx == 1) 39716394Scc210113 mac->forced_speed_duplex = ADVERTISE_10_HALF; 39726394Scc210113 else 39736394Scc210113 invalid = B_TRUE; 39746394Scc210113 39756394Scc210113 } 39766394Scc210113 39776394Scc210113 if (invalid) { 39786394Scc210113 e1000g_log(Adapter, CE_WARN, 39796394Scc210113 "Invalid link sets. Setup link to" 39806394Scc210113 "support autonegotiation with all link capabilities."); 39816394Scc210113 mac->autoneg = B_TRUE; 39826394Scc210113 phy->autoneg_advertised = ADVERTISE_1000_FULL | 39836394Scc210113 ADVERTISE_100_FULL | ADVERTISE_100_HALF | 39846394Scc210113 ADVERTISE_10_FULL | ADVERTISE_10_HALF; 39856394Scc210113 } 39866394Scc210113 39876394Scc210113 return (e1000_setup_link(&Adapter->shared)); 39886394Scc210113 } 39896394Scc210113 39904061Sxy150489 static void 39918275SEric Cheng e1000g_timer_tx_resched(struct e1000g *Adapter) 39928275SEric Cheng { 39938275SEric Cheng e1000g_tx_ring_t *tx_ring = Adapter->tx_ring; 39948275SEric Cheng 39958479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_READER); 39968479SChenlu.Chen@Sun.COM 39978275SEric Cheng if (tx_ring->resched_needed && 39988275SEric Cheng ((ddi_get_lbolt() - tx_ring->resched_timestamp) > 39998275SEric Cheng drv_usectohz(1000000)) && 40008479SChenlu.Chen@Sun.COM (Adapter->e1000g_state & E1000G_STARTED) && 40018275SEric Cheng (tx_ring->tbd_avail >= DEFAULT_TX_NO_RESOURCE)) { 40028275SEric Cheng tx_ring->resched_needed = B_FALSE; 40038275SEric Cheng mac_tx_update(Adapter->mh); 40048275SEric Cheng E1000G_STAT(tx_ring->stat_reschedule); 40058275SEric Cheng E1000G_STAT(tx_ring->stat_timer_reschedule); 40068275SEric Cheng } 40078479SChenlu.Chen@Sun.COM 40088479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 40098275SEric Cheng } 40108275SEric Cheng 40118275SEric Cheng static void 40124919Sxy150489 e1000g_local_timer(void *ws) 40134061Sxy150489 { 40144061Sxy150489 struct e1000g *Adapter = (struct e1000g *)ws; 40154061Sxy150489 struct e1000_hw *hw; 40164061Sxy150489 e1000g_ether_addr_t ether_addr; 40174061Sxy150489 boolean_t link_changed; 40184061Sxy150489 40194919Sxy150489 hw = &Adapter->shared; 40204919Sxy150489 40218479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_ERROR) { 40228479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER); 40238479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_ERROR; 40248479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock); 40258479SChenlu.Chen@Sun.COM 40265273Sgl147354 Adapter->reset_count++; 40278275SEric Cheng if (e1000g_global_reset(Adapter)) { 40285273Sgl147354 ddi_fm_service_impact(Adapter->dip, 40295273Sgl147354 DDI_SERVICE_RESTORED); 40308275SEric Cheng e1000g_timer_tx_resched(Adapter); 40318275SEric Cheng } else 40325273Sgl147354 ddi_fm_service_impact(Adapter->dip, 40335273Sgl147354 DDI_SERVICE_LOST); 40345273Sgl147354 return; 40355273Sgl147354 } 40365273Sgl147354 40374061Sxy150489 if (e1000g_stall_check(Adapter)) { 40384919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 40394061Sxy150489 "Tx stall detected. Activate automatic recovery.\n"); 40405273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_STALL); 40418479SChenlu.Chen@Sun.COM ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST); 40424061Sxy150489 Adapter->reset_count++; 40438275SEric Cheng if (e1000g_reset_adapter(Adapter)) { 40445273Sgl147354 ddi_fm_service_impact(Adapter->dip, 40455273Sgl147354 DDI_SERVICE_RESTORED); 40468275SEric Cheng e1000g_timer_tx_resched(Adapter); 40478479SChenlu.Chen@Sun.COM } 40485273Sgl147354 return; 40494061Sxy150489 } 40504061Sxy150489 40514061Sxy150489 link_changed = B_FALSE; 40525082Syy150190 rw_enter(&Adapter->chip_lock, RW_READER); 40534061Sxy150489 if (Adapter->link_complete) 40544061Sxy150489 link_changed = e1000g_link_check(Adapter); 40555082Syy150190 rw_exit(&Adapter->chip_lock); 40564061Sxy150489 40578850SMin.Xu@Sun.COM if (link_changed) { 40588850SMin.Xu@Sun.COM if (!Adapter->reset_flag) 40598850SMin.Xu@Sun.COM mac_link_update(Adapter->mh, Adapter->link_state); 40608850SMin.Xu@Sun.COM if (Adapter->link_state == LINK_STATE_UP) 40618850SMin.Xu@Sun.COM Adapter->reset_flag = B_FALSE; 40628850SMin.Xu@Sun.COM } 40637133Scc210113 /* 40647133Scc210113 * Workaround for esb2. Data stuck in fifo on a link 40657133Scc210113 * down event. Reset the adapter to recover it. 40667133Scc210113 */ 40677133Scc210113 if (Adapter->esb2_workaround) { 40687133Scc210113 Adapter->esb2_workaround = B_FALSE; 40697656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter); 40708479SChenlu.Chen@Sun.COM return; 40714139Sxy150489 } 40724061Sxy150489 40733526Sxy150489 /* 40743526Sxy150489 * With 82571 controllers, any locally administered address will 40753526Sxy150489 * be overwritten when there is a reset on the other port. 40763526Sxy150489 * Detect this circumstance and correct it. 40773526Sxy150489 */ 40784919Sxy150489 if ((hw->mac.type == e1000_82571) && 40794919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) { 40804919Sxy150489 ether_addr.reg.low = E1000_READ_REG_ARRAY(hw, E1000_RA, 0); 40814919Sxy150489 ether_addr.reg.high = E1000_READ_REG_ARRAY(hw, E1000_RA, 1); 40823526Sxy150489 40833526Sxy150489 ether_addr.reg.low = ntohl(ether_addr.reg.low); 40843526Sxy150489 ether_addr.reg.high = ntohl(ether_addr.reg.high); 40853526Sxy150489 40864919Sxy150489 if ((ether_addr.mac.addr[5] != hw->mac.addr[0]) || 40874919Sxy150489 (ether_addr.mac.addr[4] != hw->mac.addr[1]) || 40884919Sxy150489 (ether_addr.mac.addr[3] != hw->mac.addr[2]) || 40894919Sxy150489 (ether_addr.mac.addr[2] != hw->mac.addr[3]) || 40904919Sxy150489 (ether_addr.mac.addr[1] != hw->mac.addr[4]) || 40914919Sxy150489 (ether_addr.mac.addr[0] != hw->mac.addr[5])) { 40924919Sxy150489 e1000_rar_set(hw, hw->mac.addr, 0); 40933526Sxy150489 } 40943526Sxy150489 } 40953526Sxy150489 40963526Sxy150489 /* 40974919Sxy150489 * Long TTL workaround for 82541/82547 40983526Sxy150489 */ 40997426SChenliang.Xu@Sun.COM (void) e1000_igp_ttl_workaround_82547(hw); 41003526Sxy150489 41013526Sxy150489 /* 41023526Sxy150489 * Check for Adaptive IFS settings If there are lots of collisions 41033526Sxy150489 * change the value in steps... 41043526Sxy150489 * These properties should only be set for 10/100 41053526Sxy150489 */ 41066735Scc210113 if ((hw->phy.media_type == e1000_media_type_copper) && 41074061Sxy150489 ((Adapter->link_speed == SPEED_100) || 41084061Sxy150489 (Adapter->link_speed == SPEED_10))) { 41093526Sxy150489 e1000_update_adaptive(hw); 41103526Sxy150489 } 41113526Sxy150489 /* 41123526Sxy150489 * Set Timer Interrupts 41133526Sxy150489 */ 41144919Sxy150489 E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0); 41154919Sxy150489 41165273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) 41175273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 41188275SEric Cheng else 41198275SEric Cheng e1000g_timer_tx_resched(Adapter); 41205273Sgl147354 41214919Sxy150489 restart_watchdog_timer(Adapter); 41223526Sxy150489 } 41233526Sxy150489 41244061Sxy150489 /* 41254061Sxy150489 * The function e1000g_link_timer() is called when the timer for link setup 41264061Sxy150489 * is expired, which indicates the completion of the link setup. The link 41274061Sxy150489 * state will not be updated until the link setup is completed. And the 41284061Sxy150489 * link state will not be sent to the upper layer through mac_link_update() 41294061Sxy150489 * in this function. It will be updated in the local timer routine or the 41304061Sxy150489 * interrupt service routine after the interface is started (plumbed). 41314061Sxy150489 */ 41323526Sxy150489 static void 41334061Sxy150489 e1000g_link_timer(void *arg) 41343526Sxy150489 { 41354061Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 41363526Sxy150489 41374919Sxy150489 mutex_enter(&Adapter->link_lock); 41384061Sxy150489 Adapter->link_complete = B_TRUE; 41394061Sxy150489 Adapter->link_tid = 0; 41404919Sxy150489 mutex_exit(&Adapter->link_lock); 41413526Sxy150489 } 41423526Sxy150489 41433526Sxy150489 /* 41444919Sxy150489 * e1000g_force_speed_duplex - read forced speed/duplex out of e1000g.conf 41454919Sxy150489 * 41464919Sxy150489 * This function read the forced speed and duplex for 10/100 Mbps speeds 41474919Sxy150489 * and also for 1000 Mbps speeds from the e1000g.conf file 41483526Sxy150489 */ 41493526Sxy150489 static void 41503526Sxy150489 e1000g_force_speed_duplex(struct e1000g *Adapter) 41513526Sxy150489 { 41523526Sxy150489 int forced; 41534919Sxy150489 struct e1000_mac_info *mac = &Adapter->shared.mac; 41544919Sxy150489 struct e1000_phy_info *phy = &Adapter->shared.phy; 41553526Sxy150489 41563526Sxy150489 /* 41573526Sxy150489 * get value out of config file 41583526Sxy150489 */ 41594919Sxy150489 forced = e1000g_get_prop(Adapter, "ForceSpeedDuplex", 41603526Sxy150489 GDIAG_10_HALF, GDIAG_ANY, GDIAG_ANY); 41613526Sxy150489 41623526Sxy150489 switch (forced) { 41633526Sxy150489 case GDIAG_10_HALF: 41643526Sxy150489 /* 41653526Sxy150489 * Disable Auto Negotiation 41663526Sxy150489 */ 41674919Sxy150489 mac->autoneg = B_FALSE; 41684919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_HALF; 41693526Sxy150489 break; 41703526Sxy150489 case GDIAG_10_FULL: 41713526Sxy150489 /* 41723526Sxy150489 * Disable Auto Negotiation 41733526Sxy150489 */ 41744919Sxy150489 mac->autoneg = B_FALSE; 41754919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_FULL; 41763526Sxy150489 break; 41773526Sxy150489 case GDIAG_100_HALF: 41783526Sxy150489 /* 41793526Sxy150489 * Disable Auto Negotiation 41803526Sxy150489 */ 41814919Sxy150489 mac->autoneg = B_FALSE; 41824919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_HALF; 41833526Sxy150489 break; 41843526Sxy150489 case GDIAG_100_FULL: 41853526Sxy150489 /* 41863526Sxy150489 * Disable Auto Negotiation 41873526Sxy150489 */ 41884919Sxy150489 mac->autoneg = B_FALSE; 41894919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_FULL; 41903526Sxy150489 break; 41913526Sxy150489 case GDIAG_1000_FULL: 41923526Sxy150489 /* 41933526Sxy150489 * The gigabit spec requires autonegotiation. Therefore, 41943526Sxy150489 * when the user wants to force the speed to 1000Mbps, we 41953526Sxy150489 * enable AutoNeg, but only allow the harware to advertise 41963526Sxy150489 * 1000Mbps. This is different from 10/100 operation, where 41973526Sxy150489 * we are allowed to link without any negotiation. 41983526Sxy150489 */ 41994919Sxy150489 mac->autoneg = B_TRUE; 42004919Sxy150489 phy->autoneg_advertised = ADVERTISE_1000_FULL; 42013526Sxy150489 break; 42023526Sxy150489 default: /* obey the setting of AutoNegAdvertised */ 42034919Sxy150489 mac->autoneg = B_TRUE; 42044919Sxy150489 phy->autoneg_advertised = 42054919Sxy150489 (uint16_t)e1000g_get_prop(Adapter, "AutoNegAdvertised", 42064349Sxy150489 0, AUTONEG_ADVERTISE_SPEED_DEFAULT, 42074349Sxy150489 AUTONEG_ADVERTISE_SPEED_DEFAULT); 42083526Sxy150489 break; 42093526Sxy150489 } /* switch */ 42103526Sxy150489 } 42113526Sxy150489 42123526Sxy150489 /* 42134919Sxy150489 * e1000g_get_max_frame_size - get jumbo frame setting from e1000g.conf 42144919Sxy150489 * 42154919Sxy150489 * This function reads MaxFrameSize from e1000g.conf 42163526Sxy150489 */ 42173526Sxy150489 static void 42183526Sxy150489 e1000g_get_max_frame_size(struct e1000g *Adapter) 42193526Sxy150489 { 42203526Sxy150489 int max_frame; 42214919Sxy150489 struct e1000_mac_info *mac = &Adapter->shared.mac; 42224919Sxy150489 struct e1000_phy_info *phy = &Adapter->shared.phy; 42233526Sxy150489 42243526Sxy150489 /* 42253526Sxy150489 * get value out of config file 42263526Sxy150489 */ 42274919Sxy150489 max_frame = e1000g_get_prop(Adapter, "MaxFrameSize", 0, 3, 0); 42283526Sxy150489 42293526Sxy150489 switch (max_frame) { 42303526Sxy150489 case 0: 42316394Scc210113 Adapter->default_mtu = ETHERMTU; 42323526Sxy150489 break; 42336394Scc210113 /* 42346394Scc210113 * To avoid excessive memory allocation for rx buffers, 42356394Scc210113 * the bytes of E1000G_IPALIGNPRESERVEROOM are reserved. 42366394Scc210113 */ 42373526Sxy150489 case 1: 42386394Scc210113 Adapter->default_mtu = FRAME_SIZE_UPTO_4K - 42396394Scc210113 sizeof (struct ether_vlan_header) - ETHERFCSL - 42406394Scc210113 E1000G_IPALIGNPRESERVEROOM; 42413526Sxy150489 break; 42423526Sxy150489 case 2: 42436394Scc210113 Adapter->default_mtu = FRAME_SIZE_UPTO_8K - 42446394Scc210113 sizeof (struct ether_vlan_header) - ETHERFCSL - 42456394Scc210113 E1000G_IPALIGNPRESERVEROOM; 42463526Sxy150489 break; 42473526Sxy150489 case 3: 42486394Scc210113 if (mac->type >= e1000_82571) 42496394Scc210113 Adapter->default_mtu = MAXIMUM_MTU; 42503526Sxy150489 else 42516394Scc210113 Adapter->default_mtu = FRAME_SIZE_UPTO_16K - 42526394Scc210113 sizeof (struct ether_vlan_header) - ETHERFCSL - 42536394Scc210113 E1000G_IPALIGNPRESERVEROOM; 42543526Sxy150489 break; 42553526Sxy150489 default: 42566394Scc210113 Adapter->default_mtu = ETHERMTU; 42573526Sxy150489 break; 42583526Sxy150489 } /* switch */ 42593526Sxy150489 42606735Scc210113 Adapter->max_frame_size = Adapter->default_mtu + 42616394Scc210113 sizeof (struct ether_vlan_header) + ETHERFCSL; 42626394Scc210113 42633526Sxy150489 /* ich8 does not do jumbo frames */ 42644919Sxy150489 if (mac->type == e1000_ich8lan) { 42658178SChenlu.Chen@Sun.COM Adapter->default_mtu = ETHERMTU; 42667133Scc210113 Adapter->max_frame_size = ETHERMTU + 42677133Scc210113 sizeof (struct ether_vlan_header) + ETHERFCSL; 42684919Sxy150489 } 42694919Sxy150489 42704919Sxy150489 /* ich9 does not do jumbo frames on one phy type */ 42714919Sxy150489 if ((mac->type == e1000_ich9lan) && 42724919Sxy150489 (phy->type == e1000_phy_ife)) { 42738178SChenlu.Chen@Sun.COM Adapter->default_mtu = ETHERMTU; 42747133Scc210113 Adapter->max_frame_size = ETHERMTU + 42757133Scc210113 sizeof (struct ether_vlan_header) + ETHERFCSL; 42763526Sxy150489 } 42773526Sxy150489 } 42783526Sxy150489 42793526Sxy150489 static void 42804919Sxy150489 arm_watchdog_timer(struct e1000g *Adapter) 42813526Sxy150489 { 42824919Sxy150489 Adapter->watchdog_tid = 42834919Sxy150489 timeout(e1000g_local_timer, 42843526Sxy150489 (void *)Adapter, 1 * drv_usectohz(1000000)); 42853526Sxy150489 } 42864919Sxy150489 #pragma inline(arm_watchdog_timer) 42874919Sxy150489 42884919Sxy150489 static void 42894919Sxy150489 enable_watchdog_timer(struct e1000g *Adapter) 42904919Sxy150489 { 42914919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 42924919Sxy150489 42934919Sxy150489 if (!Adapter->watchdog_timer_enabled) { 42944919Sxy150489 Adapter->watchdog_timer_enabled = B_TRUE; 42954919Sxy150489 Adapter->watchdog_timer_started = B_TRUE; 42964919Sxy150489 arm_watchdog_timer(Adapter); 42974919Sxy150489 } 42984919Sxy150489 42994919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 43004919Sxy150489 } 43013526Sxy150489 43023526Sxy150489 static void 43034919Sxy150489 disable_watchdog_timer(struct e1000g *Adapter) 43043526Sxy150489 { 43053526Sxy150489 timeout_id_t tid; 43063526Sxy150489 43074919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 43084919Sxy150489 43094919Sxy150489 Adapter->watchdog_timer_enabled = B_FALSE; 43104919Sxy150489 Adapter->watchdog_timer_started = B_FALSE; 43114919Sxy150489 tid = Adapter->watchdog_tid; 43124919Sxy150489 Adapter->watchdog_tid = 0; 43134919Sxy150489 43144919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 43153526Sxy150489 43163526Sxy150489 if (tid != 0) 43173526Sxy150489 (void) untimeout(tid); 43183526Sxy150489 } 43193526Sxy150489 43203526Sxy150489 static void 43214919Sxy150489 start_watchdog_timer(struct e1000g *Adapter) 43223526Sxy150489 { 43234919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 43244919Sxy150489 43254919Sxy150489 if (Adapter->watchdog_timer_enabled) { 43264919Sxy150489 if (!Adapter->watchdog_timer_started) { 43274919Sxy150489 Adapter->watchdog_timer_started = B_TRUE; 43284919Sxy150489 arm_watchdog_timer(Adapter); 43293526Sxy150489 } 43303526Sxy150489 } 43313526Sxy150489 43324919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 43334919Sxy150489 } 43344919Sxy150489 43354919Sxy150489 static void 43364919Sxy150489 restart_watchdog_timer(struct e1000g *Adapter) 43374919Sxy150489 { 43384919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 43394919Sxy150489 43404919Sxy150489 if (Adapter->watchdog_timer_started) 43414919Sxy150489 arm_watchdog_timer(Adapter); 43424919Sxy150489 43434919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 43443526Sxy150489 } 43453526Sxy150489 43463526Sxy150489 static void 43474919Sxy150489 stop_watchdog_timer(struct e1000g *Adapter) 43483526Sxy150489 { 43494919Sxy150489 timeout_id_t tid; 43504919Sxy150489 43514919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 43524919Sxy150489 43534919Sxy150489 Adapter->watchdog_timer_started = B_FALSE; 43544919Sxy150489 tid = Adapter->watchdog_tid; 43554919Sxy150489 Adapter->watchdog_tid = 0; 43564919Sxy150489 43574919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 43584919Sxy150489 43594919Sxy150489 if (tid != 0) 43604919Sxy150489 (void) untimeout(tid); 43613526Sxy150489 } 43623526Sxy150489 43633526Sxy150489 static void 43644919Sxy150489 stop_link_timer(struct e1000g *Adapter) 43653526Sxy150489 { 43663526Sxy150489 timeout_id_t tid; 43673526Sxy150489 43684919Sxy150489 /* Disable the link timer */ 43694919Sxy150489 mutex_enter(&Adapter->link_lock); 43704919Sxy150489 43714919Sxy150489 tid = Adapter->link_tid; 43724919Sxy150489 Adapter->link_tid = 0; 43734919Sxy150489 43744919Sxy150489 mutex_exit(&Adapter->link_lock); 43754919Sxy150489 43764919Sxy150489 if (tid != 0) 43774919Sxy150489 (void) untimeout(tid); 43784919Sxy150489 } 43794919Sxy150489 43804919Sxy150489 static void 43814919Sxy150489 stop_82547_timer(e1000g_tx_ring_t *tx_ring) 43824919Sxy150489 { 43834919Sxy150489 timeout_id_t tid; 43844919Sxy150489 43854919Sxy150489 /* Disable the tx timer for 82547 chipset */ 43864919Sxy150489 mutex_enter(&tx_ring->tx_lock); 43874919Sxy150489 43884919Sxy150489 tx_ring->timer_enable_82547 = B_FALSE; 43894919Sxy150489 tid = tx_ring->timer_id_82547; 43904919Sxy150489 tx_ring->timer_id_82547 = 0; 43914919Sxy150489 43924919Sxy150489 mutex_exit(&tx_ring->tx_lock); 43933526Sxy150489 43943526Sxy150489 if (tid != 0) 43953526Sxy150489 (void) untimeout(tid); 43963526Sxy150489 } 43973526Sxy150489 43983526Sxy150489 void 43994919Sxy150489 e1000g_clear_interrupt(struct e1000g *Adapter) 44003526Sxy150489 { 44014919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 44024919Sxy150489 0xffffffff & ~E1000_IMS_RXSEQ); 44033526Sxy150489 } 44043526Sxy150489 44053526Sxy150489 void 44064919Sxy150489 e1000g_mask_interrupt(struct e1000g *Adapter) 44073526Sxy150489 { 44084919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, 44095882Syy150190 IMS_ENABLE_MASK & ~E1000_IMS_TXDW); 44105882Syy150190 44115882Syy150190 if (Adapter->tx_intr_enable) 44125882Syy150190 e1000g_mask_tx_interrupt(Adapter); 44133526Sxy150489 } 44143526Sxy150489 44157656SSherry.Moore@Sun.COM /* 44167656SSherry.Moore@Sun.COM * This routine is called by e1000g_quiesce(), therefore must not block. 44177656SSherry.Moore@Sun.COM */ 44183526Sxy150489 void 44194919Sxy150489 e1000g_clear_all_interrupts(struct e1000g *Adapter) 44203526Sxy150489 { 44214919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 0xffffffff); 44223526Sxy150489 } 44233526Sxy150489 44243526Sxy150489 void 44254919Sxy150489 e1000g_mask_tx_interrupt(struct e1000g *Adapter) 44263526Sxy150489 { 44275882Syy150190 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, E1000_IMS_TXDW); 44283526Sxy150489 } 44293526Sxy150489 44303526Sxy150489 void 44314919Sxy150489 e1000g_clear_tx_interrupt(struct e1000g *Adapter) 44323526Sxy150489 { 44335882Syy150190 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, E1000_IMS_TXDW); 44343526Sxy150489 } 44353526Sxy150489 44363526Sxy150489 static void 44374919Sxy150489 e1000g_smartspeed(struct e1000g *Adapter) 44383526Sxy150489 { 44394919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 44403526Sxy150489 uint16_t phy_status; 44413526Sxy150489 uint16_t phy_ctrl; 44423526Sxy150489 44433526Sxy150489 /* 44443526Sxy150489 * If we're not T-or-T, or we're not autoneg'ing, or we're not 44453526Sxy150489 * advertising 1000Full, we don't even use the workaround 44463526Sxy150489 */ 44474919Sxy150489 if ((hw->phy.type != e1000_phy_igp) || 44484919Sxy150489 !hw->mac.autoneg || 44494919Sxy150489 !(hw->phy.autoneg_advertised & ADVERTISE_1000_FULL)) 44503526Sxy150489 return; 44513526Sxy150489 44523526Sxy150489 /* 44533526Sxy150489 * True if this is the first call of this function or after every 44543526Sxy150489 * 30 seconds of not having link 44553526Sxy150489 */ 44564919Sxy150489 if (Adapter->smartspeed == 0) { 44573526Sxy150489 /* 44583526Sxy150489 * If Master/Slave config fault is asserted twice, we 44593526Sxy150489 * assume back-to-back 44603526Sxy150489 */ 44617426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 44623526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 44633526Sxy150489 return; 44643526Sxy150489 44657426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 44663526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 44673526Sxy150489 return; 44683526Sxy150489 /* 44693526Sxy150489 * We're assuming back-2-back because our status register 44703526Sxy150489 * insists! there's a fault in the master/slave 44713526Sxy150489 * relationship that was "negotiated" 44723526Sxy150489 */ 44737426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 44743526Sxy150489 /* 44753526Sxy150489 * Is the phy configured for manual configuration of 44763526Sxy150489 * master/slave? 44773526Sxy150489 */ 44783526Sxy150489 if (phy_ctrl & CR_1000T_MS_ENABLE) { 44793526Sxy150489 /* 44803526Sxy150489 * Yes. Then disable manual configuration (enable 44813526Sxy150489 * auto configuration) of master/slave 44823526Sxy150489 */ 44833526Sxy150489 phy_ctrl &= ~CR_1000T_MS_ENABLE; 44847426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 44853526Sxy150489 PHY_1000T_CTRL, phy_ctrl); 44863526Sxy150489 /* 44873526Sxy150489 * Effectively starting the clock 44883526Sxy150489 */ 44894919Sxy150489 Adapter->smartspeed++; 44903526Sxy150489 /* 44913526Sxy150489 * Restart autonegotiation 44923526Sxy150489 */ 44934919Sxy150489 if (!e1000_phy_setup_autoneg(hw) && 44944919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 44953526Sxy150489 phy_ctrl |= (MII_CR_AUTO_NEG_EN | 44963526Sxy150489 MII_CR_RESTART_AUTO_NEG); 44977426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 44984919Sxy150489 PHY_CONTROL, phy_ctrl); 44993526Sxy150489 } 45003526Sxy150489 } 45013526Sxy150489 return; 45023526Sxy150489 /* 45033526Sxy150489 * Has 6 seconds transpired still without link? Remember, 45043526Sxy150489 * you should reset the smartspeed counter once you obtain 45053526Sxy150489 * link 45063526Sxy150489 */ 45074919Sxy150489 } else if (Adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { 45083526Sxy150489 /* 45093526Sxy150489 * Yes. Remember, we did at the start determine that 45103526Sxy150489 * there's a master/slave configuration fault, so we're 45113526Sxy150489 * still assuming there's someone on the other end, but we 45123526Sxy150489 * just haven't yet been able to talk to it. We then 45133526Sxy150489 * re-enable auto configuration of master/slave to see if 45143526Sxy150489 * we're running 2/3 pair cables. 45153526Sxy150489 */ 45163526Sxy150489 /* 45173526Sxy150489 * If still no link, perhaps using 2/3 pair cable 45183526Sxy150489 */ 45197426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 45203526Sxy150489 phy_ctrl |= CR_1000T_MS_ENABLE; 45217426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); 45223526Sxy150489 /* 45233526Sxy150489 * Restart autoneg with phy enabled for manual 45243526Sxy150489 * configuration of master/slave 45253526Sxy150489 */ 45264919Sxy150489 if (!e1000_phy_setup_autoneg(hw) && 45274919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 45283526Sxy150489 phy_ctrl |= 45293526Sxy150489 (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); 45307426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl); 45313526Sxy150489 } 45323526Sxy150489 /* 45333526Sxy150489 * Hopefully, there are no more faults and we've obtained 45343526Sxy150489 * link as a result. 45353526Sxy150489 */ 45363526Sxy150489 } 45373526Sxy150489 /* 45383526Sxy150489 * Restart process after E1000_SMARTSPEED_MAX iterations (30 45393526Sxy150489 * seconds) 45403526Sxy150489 */ 45414919Sxy150489 if (Adapter->smartspeed++ == E1000_SMARTSPEED_MAX) 45424919Sxy150489 Adapter->smartspeed = 0; 45433526Sxy150489 } 45443526Sxy150489 45453526Sxy150489 static boolean_t 45463526Sxy150489 is_valid_mac_addr(uint8_t *mac_addr) 45473526Sxy150489 { 45483526Sxy150489 const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 }; 45493526Sxy150489 const uint8_t addr_test2[6] = 45503526Sxy150489 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 45513526Sxy150489 45523526Sxy150489 if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) || 45533526Sxy150489 !(bcmp(addr_test2, mac_addr, ETHERADDRL))) 45543526Sxy150489 return (B_FALSE); 45553526Sxy150489 45563526Sxy150489 return (B_TRUE); 45573526Sxy150489 } 45583526Sxy150489 45593526Sxy150489 /* 45604919Sxy150489 * e1000g_stall_check - check for tx stall 45614919Sxy150489 * 45624919Sxy150489 * This function checks if the adapter is stalled (in transmit). 45634919Sxy150489 * 45644919Sxy150489 * It is called each time the watchdog timeout is invoked. 45654919Sxy150489 * If the transmit descriptor reclaim continuously fails, 45664919Sxy150489 * the watchdog value will increment by 1. If the watchdog 45674919Sxy150489 * value exceeds the threshold, the adapter is assumed to 45684919Sxy150489 * have stalled and need to be reset. 45693526Sxy150489 */ 45703526Sxy150489 static boolean_t 45713526Sxy150489 e1000g_stall_check(struct e1000g *Adapter) 45723526Sxy150489 { 45734919Sxy150489 e1000g_tx_ring_t *tx_ring; 45744919Sxy150489 45754919Sxy150489 tx_ring = Adapter->tx_ring; 45764919Sxy150489 45774061Sxy150489 if (Adapter->link_state != LINK_STATE_UP) 45783526Sxy150489 return (B_FALSE); 45793526Sxy150489 45808850SMin.Xu@Sun.COM (void) e1000g_recycle(tx_ring); 45818850SMin.Xu@Sun.COM 45828850SMin.Xu@Sun.COM if (Adapter->stall_flag) { 45838850SMin.Xu@Sun.COM Adapter->stall_flag = B_FALSE; 45848850SMin.Xu@Sun.COM Adapter->reset_flag = B_TRUE; 45858850SMin.Xu@Sun.COM return (B_TRUE); 45868850SMin.Xu@Sun.COM } 45878850SMin.Xu@Sun.COM 45888850SMin.Xu@Sun.COM return (B_FALSE); 45893526Sxy150489 } 45903526Sxy150489 45914919Sxy150489 #ifdef E1000G_DEBUG 45923526Sxy150489 static enum ioc_reply 45933526Sxy150489 e1000g_pp_ioctl(struct e1000g *e1000gp, struct iocblk *iocp, mblk_t *mp) 45943526Sxy150489 { 45953526Sxy150489 void (*ppfn)(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd); 45963526Sxy150489 e1000g_peekpoke_t *ppd; 45973526Sxy150489 uint64_t mem_va; 45983526Sxy150489 uint64_t maxoff; 45993526Sxy150489 boolean_t peek; 46003526Sxy150489 46013526Sxy150489 switch (iocp->ioc_cmd) { 46023526Sxy150489 46033526Sxy150489 case E1000G_IOC_REG_PEEK: 46043526Sxy150489 peek = B_TRUE; 46053526Sxy150489 break; 46063526Sxy150489 46073526Sxy150489 case E1000G_IOC_REG_POKE: 46083526Sxy150489 peek = B_FALSE; 46093526Sxy150489 break; 46103526Sxy150489 46113526Sxy150489 deault: 46124919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 46134349Sxy150489 "e1000g_diag_ioctl: invalid ioctl command 0x%X\n", 46144349Sxy150489 iocp->ioc_cmd); 46153526Sxy150489 return (IOC_INVAL); 46163526Sxy150489 } 46173526Sxy150489 46183526Sxy150489 /* 46193526Sxy150489 * Validate format of ioctl 46203526Sxy150489 */ 46213526Sxy150489 if (iocp->ioc_count != sizeof (e1000g_peekpoke_t)) 46223526Sxy150489 return (IOC_INVAL); 46233526Sxy150489 if (mp->b_cont == NULL) 46243526Sxy150489 return (IOC_INVAL); 46253526Sxy150489 46267426SChenliang.Xu@Sun.COM ppd = (e1000g_peekpoke_t *)(uintptr_t)mp->b_cont->b_rptr; 46273526Sxy150489 46283526Sxy150489 /* 46293526Sxy150489 * Validate request parameters 46303526Sxy150489 */ 46313526Sxy150489 switch (ppd->pp_acc_space) { 46323526Sxy150489 46333526Sxy150489 default: 46344919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 46354349Sxy150489 "e1000g_diag_ioctl: invalid access space 0x%X\n", 46364349Sxy150489 ppd->pp_acc_space); 46373526Sxy150489 return (IOC_INVAL); 46383526Sxy150489 46393526Sxy150489 case E1000G_PP_SPACE_REG: 46403526Sxy150489 /* 46413526Sxy150489 * Memory-mapped I/O space 46423526Sxy150489 */ 46433526Sxy150489 ASSERT(ppd->pp_acc_size == 4); 46443526Sxy150489 if (ppd->pp_acc_size != 4) 46453526Sxy150489 return (IOC_INVAL); 46463526Sxy150489 46473526Sxy150489 if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 46483526Sxy150489 return (IOC_INVAL); 46493526Sxy150489 46503526Sxy150489 mem_va = 0; 46513526Sxy150489 maxoff = 0x10000; 46523526Sxy150489 ppfn = peek ? e1000g_ioc_peek_reg : e1000g_ioc_poke_reg; 46533526Sxy150489 break; 46543526Sxy150489 46553526Sxy150489 case E1000G_PP_SPACE_E1000G: 46563526Sxy150489 /* 46573526Sxy150489 * E1000g data structure! 46583526Sxy150489 */ 46593526Sxy150489 mem_va = (uintptr_t)e1000gp; 46603526Sxy150489 maxoff = sizeof (struct e1000g); 46613526Sxy150489 ppfn = peek ? e1000g_ioc_peek_mem : e1000g_ioc_poke_mem; 46623526Sxy150489 break; 46633526Sxy150489 46643526Sxy150489 } 46653526Sxy150489 46663526Sxy150489 if (ppd->pp_acc_offset >= maxoff) 46673526Sxy150489 return (IOC_INVAL); 46683526Sxy150489 46693526Sxy150489 if (ppd->pp_acc_offset + ppd->pp_acc_size > maxoff) 46703526Sxy150489 return (IOC_INVAL); 46713526Sxy150489 46723526Sxy150489 /* 46733526Sxy150489 * All OK - go! 46743526Sxy150489 */ 46753526Sxy150489 ppd->pp_acc_offset += mem_va; 46763526Sxy150489 (*ppfn)(e1000gp, ppd); 46773526Sxy150489 return (peek ? IOC_REPLY : IOC_ACK); 46783526Sxy150489 } 46793526Sxy150489 46803526Sxy150489 static void 46813526Sxy150489 e1000g_ioc_peek_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 46823526Sxy150489 { 46833526Sxy150489 ddi_acc_handle_t handle; 46843526Sxy150489 uint32_t *regaddr; 46853526Sxy150489 46864919Sxy150489 handle = e1000gp->osdep.reg_handle; 46877426SChenliang.Xu@Sun.COM regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr + 46887426SChenliang.Xu@Sun.COM (uintptr_t)ppd->pp_acc_offset); 46893526Sxy150489 46903526Sxy150489 ppd->pp_acc_data = ddi_get32(handle, regaddr); 46913526Sxy150489 } 46923526Sxy150489 46933526Sxy150489 static void 46943526Sxy150489 e1000g_ioc_poke_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 46953526Sxy150489 { 46963526Sxy150489 ddi_acc_handle_t handle; 46973526Sxy150489 uint32_t *regaddr; 46983526Sxy150489 uint32_t value; 46993526Sxy150489 47004919Sxy150489 handle = e1000gp->osdep.reg_handle; 47017426SChenliang.Xu@Sun.COM regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr + 47027426SChenliang.Xu@Sun.COM (uintptr_t)ppd->pp_acc_offset); 47033526Sxy150489 value = (uint32_t)ppd->pp_acc_data; 47043526Sxy150489 47053526Sxy150489 ddi_put32(handle, regaddr, value); 47063526Sxy150489 } 47073526Sxy150489 47083526Sxy150489 static void 47093526Sxy150489 e1000g_ioc_peek_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 47103526Sxy150489 { 47113526Sxy150489 uint64_t value; 47123526Sxy150489 void *vaddr; 47133526Sxy150489 47143526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47153526Sxy150489 47163526Sxy150489 switch (ppd->pp_acc_size) { 47173526Sxy150489 case 1: 47183526Sxy150489 value = *(uint8_t *)vaddr; 47193526Sxy150489 break; 47203526Sxy150489 47213526Sxy150489 case 2: 47223526Sxy150489 value = *(uint16_t *)vaddr; 47233526Sxy150489 break; 47243526Sxy150489 47253526Sxy150489 case 4: 47263526Sxy150489 value = *(uint32_t *)vaddr; 47273526Sxy150489 break; 47283526Sxy150489 47293526Sxy150489 case 8: 47303526Sxy150489 value = *(uint64_t *)vaddr; 47313526Sxy150489 break; 47323526Sxy150489 } 47333526Sxy150489 47344919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 47354349Sxy150489 "e1000g_ioc_peek_mem($%p, $%p) peeked 0x%llx from $%p\n", 47364349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr); 47373526Sxy150489 47383526Sxy150489 ppd->pp_acc_data = value; 47393526Sxy150489 } 47403526Sxy150489 47413526Sxy150489 static void 47423526Sxy150489 e1000g_ioc_poke_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 47433526Sxy150489 { 47443526Sxy150489 uint64_t value; 47453526Sxy150489 void *vaddr; 47463526Sxy150489 47473526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47483526Sxy150489 value = ppd->pp_acc_data; 47493526Sxy150489 47504919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 47514349Sxy150489 "e1000g_ioc_poke_mem($%p, $%p) poking 0x%llx at $%p\n", 47524349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr); 47533526Sxy150489 47543526Sxy150489 switch (ppd->pp_acc_size) { 47553526Sxy150489 case 1: 47563526Sxy150489 *(uint8_t *)vaddr = (uint8_t)value; 47573526Sxy150489 break; 47583526Sxy150489 47593526Sxy150489 case 2: 47603526Sxy150489 *(uint16_t *)vaddr = (uint16_t)value; 47613526Sxy150489 break; 47623526Sxy150489 47633526Sxy150489 case 4: 47643526Sxy150489 *(uint32_t *)vaddr = (uint32_t)value; 47653526Sxy150489 break; 47663526Sxy150489 47673526Sxy150489 case 8: 47683526Sxy150489 *(uint64_t *)vaddr = (uint64_t)value; 47693526Sxy150489 break; 47703526Sxy150489 } 47713526Sxy150489 } 47724919Sxy150489 #endif 47733526Sxy150489 47743526Sxy150489 /* 47753526Sxy150489 * Loopback Support 47763526Sxy150489 */ 47773526Sxy150489 static lb_property_t lb_normal = 47783526Sxy150489 { normal, "normal", E1000G_LB_NONE }; 47793526Sxy150489 static lb_property_t lb_external1000 = 47803526Sxy150489 { external, "1000Mbps", E1000G_LB_EXTERNAL_1000 }; 47813526Sxy150489 static lb_property_t lb_external100 = 47823526Sxy150489 { external, "100Mbps", E1000G_LB_EXTERNAL_100 }; 47833526Sxy150489 static lb_property_t lb_external10 = 47843526Sxy150489 { external, "10Mbps", E1000G_LB_EXTERNAL_10 }; 47853526Sxy150489 static lb_property_t lb_phy = 47863526Sxy150489 { internal, "PHY", E1000G_LB_INTERNAL_PHY }; 47873526Sxy150489 47883526Sxy150489 static enum ioc_reply 47893526Sxy150489 e1000g_loopback_ioctl(struct e1000g *Adapter, struct iocblk *iocp, mblk_t *mp) 47903526Sxy150489 { 47913526Sxy150489 lb_info_sz_t *lbsp; 47923526Sxy150489 lb_property_t *lbpp; 47933526Sxy150489 struct e1000_hw *hw; 47943526Sxy150489 uint32_t *lbmp; 47953526Sxy150489 uint32_t size; 47963526Sxy150489 uint32_t value; 47973526Sxy150489 47984919Sxy150489 hw = &Adapter->shared; 47993526Sxy150489 48003526Sxy150489 if (mp->b_cont == NULL) 48013526Sxy150489 return (IOC_INVAL); 48023526Sxy150489 48037133Scc210113 if (!e1000g_check_loopback_support(hw)) { 48047133Scc210113 e1000g_log(NULL, CE_WARN, 48057133Scc210113 "Loopback is not supported on e1000g%d", Adapter->instance); 48067133Scc210113 return (IOC_INVAL); 48077133Scc210113 } 48087133Scc210113 48093526Sxy150489 switch (iocp->ioc_cmd) { 48103526Sxy150489 default: 48113526Sxy150489 return (IOC_INVAL); 48123526Sxy150489 48133526Sxy150489 case LB_GET_INFO_SIZE: 48143526Sxy150489 size = sizeof (lb_info_sz_t); 48153526Sxy150489 if (iocp->ioc_count != size) 48163526Sxy150489 return (IOC_INVAL); 48173526Sxy150489 48185082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER); 48195082Syy150190 e1000g_get_phy_state(Adapter); 48205082Syy150190 48215082Syy150190 /* 48225082Syy150190 * Workaround for hardware faults. In order to get a stable 48235082Syy150190 * state of phy, we will wait for a specific interval and 48245082Syy150190 * try again. The time delay is an experiential value based 48255082Syy150190 * on our testing. 48265082Syy150190 */ 48275082Syy150190 msec_delay(100); 48285082Syy150190 e1000g_get_phy_state(Adapter); 48295082Syy150190 rw_exit(&Adapter->chip_lock); 48303526Sxy150489 48313526Sxy150489 value = sizeof (lb_normal); 48325082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 48335082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 48346735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) || 48356735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 48363526Sxy150489 value += sizeof (lb_phy); 48374919Sxy150489 switch (hw->mac.type) { 48383526Sxy150489 case e1000_82571: 48393526Sxy150489 case e1000_82572: 48407133Scc210113 case e1000_80003es2lan: 48413526Sxy150489 value += sizeof (lb_external1000); 48423526Sxy150489 break; 48433526Sxy150489 } 48443526Sxy150489 } 48455082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 48465082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 48473526Sxy150489 value += sizeof (lb_external100); 48485082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 48493526Sxy150489 value += sizeof (lb_external10); 48503526Sxy150489 48517426SChenliang.Xu@Sun.COM lbsp = (lb_info_sz_t *)(uintptr_t)mp->b_cont->b_rptr; 48523526Sxy150489 *lbsp = value; 48533526Sxy150489 break; 48543526Sxy150489 48553526Sxy150489 case LB_GET_INFO: 48563526Sxy150489 value = sizeof (lb_normal); 48575082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 48585082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 48596735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) || 48606735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 48613526Sxy150489 value += sizeof (lb_phy); 48624919Sxy150489 switch (hw->mac.type) { 48633526Sxy150489 case e1000_82571: 48643526Sxy150489 case e1000_82572: 48657133Scc210113 case e1000_80003es2lan: 48663526Sxy150489 value += sizeof (lb_external1000); 48673526Sxy150489 break; 48683526Sxy150489 } 48693526Sxy150489 } 48705082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 48715082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 48723526Sxy150489 value += sizeof (lb_external100); 48735082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 48743526Sxy150489 value += sizeof (lb_external10); 48753526Sxy150489 48763526Sxy150489 size = value; 48773526Sxy150489 if (iocp->ioc_count != size) 48783526Sxy150489 return (IOC_INVAL); 48793526Sxy150489 48803526Sxy150489 value = 0; 48817426SChenliang.Xu@Sun.COM lbpp = (lb_property_t *)(uintptr_t)mp->b_cont->b_rptr; 48823526Sxy150489 lbpp[value++] = lb_normal; 48835082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 48845082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 48856735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) || 48866735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) { 48873526Sxy150489 lbpp[value++] = lb_phy; 48884919Sxy150489 switch (hw->mac.type) { 48893526Sxy150489 case e1000_82571: 48903526Sxy150489 case e1000_82572: 48917133Scc210113 case e1000_80003es2lan: 48923526Sxy150489 lbpp[value++] = lb_external1000; 48933526Sxy150489 break; 48943526Sxy150489 } 48953526Sxy150489 } 48965082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 48975082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) 48983526Sxy150489 lbpp[value++] = lb_external100; 48995082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS) 49003526Sxy150489 lbpp[value++] = lb_external10; 49013526Sxy150489 break; 49023526Sxy150489 49033526Sxy150489 case LB_GET_MODE: 49043526Sxy150489 size = sizeof (uint32_t); 49053526Sxy150489 if (iocp->ioc_count != size) 49063526Sxy150489 return (IOC_INVAL); 49073526Sxy150489 49087426SChenliang.Xu@Sun.COM lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 49093526Sxy150489 *lbmp = Adapter->loopback_mode; 49103526Sxy150489 break; 49113526Sxy150489 49123526Sxy150489 case LB_SET_MODE: 49133526Sxy150489 size = 0; 49143526Sxy150489 if (iocp->ioc_count != sizeof (uint32_t)) 49153526Sxy150489 return (IOC_INVAL); 49163526Sxy150489 49177426SChenliang.Xu@Sun.COM lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 49183526Sxy150489 if (!e1000g_set_loopback_mode(Adapter, *lbmp)) 49193526Sxy150489 return (IOC_INVAL); 49203526Sxy150489 break; 49213526Sxy150489 } 49223526Sxy150489 49233526Sxy150489 iocp->ioc_count = size; 49243526Sxy150489 iocp->ioc_error = 0; 49253526Sxy150489 49265273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) { 49275273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED); 49285273Sgl147354 return (IOC_INVAL); 49295273Sgl147354 } 49305273Sgl147354 49313526Sxy150489 return (IOC_REPLY); 49323526Sxy150489 } 49333526Sxy150489 49343526Sxy150489 static boolean_t 49357133Scc210113 e1000g_check_loopback_support(struct e1000_hw *hw) 49367133Scc210113 { 49377133Scc210113 switch (hw->mac.type) { 49387133Scc210113 case e1000_82540: 49397133Scc210113 case e1000_82545: 49407133Scc210113 case e1000_82545_rev_3: 49417133Scc210113 case e1000_82546: 49427133Scc210113 case e1000_82546_rev_3: 49437133Scc210113 case e1000_82541: 49447133Scc210113 case e1000_82541_rev_2: 49457133Scc210113 case e1000_82547: 49467133Scc210113 case e1000_82547_rev_2: 49477133Scc210113 case e1000_82571: 49487133Scc210113 case e1000_82572: 49497133Scc210113 case e1000_82573: 49508479SChenlu.Chen@Sun.COM case e1000_82574: 49517133Scc210113 case e1000_80003es2lan: 49528479SChenlu.Chen@Sun.COM case e1000_ich9lan: 49538479SChenlu.Chen@Sun.COM case e1000_ich10lan: 49547133Scc210113 return (B_TRUE); 49557133Scc210113 } 49567133Scc210113 return (B_FALSE); 49577133Scc210113 } 49587133Scc210113 49597133Scc210113 static boolean_t 49603526Sxy150489 e1000g_set_loopback_mode(struct e1000g *Adapter, uint32_t mode) 49613526Sxy150489 { 49623526Sxy150489 struct e1000_hw *hw; 49633526Sxy150489 int i, times; 49645082Syy150190 boolean_t link_up; 49653526Sxy150489 49663526Sxy150489 if (mode == Adapter->loopback_mode) 49673526Sxy150489 return (B_TRUE); 49683526Sxy150489 49694919Sxy150489 hw = &Adapter->shared; 49703526Sxy150489 times = 0; 49713526Sxy150489 49725082Syy150190 Adapter->loopback_mode = mode; 49735082Syy150190 49745082Syy150190 if (mode == E1000G_LB_NONE) { 49753526Sxy150489 /* Reset the chip */ 49766735Scc210113 hw->phy.autoneg_wait_to_complete = B_TRUE; 49777656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter); 49786735Scc210113 hw->phy.autoneg_wait_to_complete = B_FALSE; 49795082Syy150190 return (B_TRUE); 49805082Syy150190 } 49815082Syy150190 49825082Syy150190 again: 49835082Syy150190 49845082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER); 49855082Syy150190 49865082Syy150190 switch (mode) { 49875082Syy150190 default: 49885082Syy150190 rw_exit(&Adapter->chip_lock); 49895082Syy150190 return (B_FALSE); 49903526Sxy150489 49913526Sxy150489 case E1000G_LB_EXTERNAL_1000: 49923526Sxy150489 e1000g_set_external_loopback_1000(Adapter); 49933526Sxy150489 break; 49943526Sxy150489 49953526Sxy150489 case E1000G_LB_EXTERNAL_100: 49963526Sxy150489 e1000g_set_external_loopback_100(Adapter); 49973526Sxy150489 break; 49983526Sxy150489 49993526Sxy150489 case E1000G_LB_EXTERNAL_10: 50003526Sxy150489 e1000g_set_external_loopback_10(Adapter); 50013526Sxy150489 break; 50023526Sxy150489 50033526Sxy150489 case E1000G_LB_INTERNAL_PHY: 50043526Sxy150489 e1000g_set_internal_loopback(Adapter); 50053526Sxy150489 break; 50063526Sxy150489 } 50073526Sxy150489 50083526Sxy150489 times++; 50093526Sxy150489 50105858Scc210113 rw_exit(&Adapter->chip_lock); 50115858Scc210113 50125082Syy150190 /* Wait for link up */ 50135082Syy150190 for (i = (PHY_FORCE_LIMIT * 2); i > 0; i--) 50145082Syy150190 msec_delay(100); 50155082Syy150190 50165858Scc210113 rw_enter(&Adapter->chip_lock, RW_WRITER); 50175858Scc210113 50185082Syy150190 link_up = e1000g_link_up(Adapter); 50195082Syy150190 50205082Syy150190 rw_exit(&Adapter->chip_lock); 50215082Syy150190 50225082Syy150190 if (!link_up) { 50235082Syy150190 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 50245082Syy150190 "Failed to get the link up"); 50255082Syy150190 if (times < 2) { 50265082Syy150190 /* Reset the link */ 50274919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 50285082Syy150190 "Reset the link ..."); 50297656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter); 50305082Syy150190 goto again; 50313526Sxy150489 } 50323526Sxy150489 } 50333526Sxy150489 50343526Sxy150489 return (B_TRUE); 50353526Sxy150489 } 50363526Sxy150489 50373526Sxy150489 /* 50383526Sxy150489 * The following loopback settings are from Intel's technical 50393526Sxy150489 * document - "How To Loopback". All the register settings and 50403526Sxy150489 * time delay values are directly inherited from the document 50413526Sxy150489 * without more explanations available. 50423526Sxy150489 */ 50433526Sxy150489 static void 50443526Sxy150489 e1000g_set_internal_loopback(struct e1000g *Adapter) 50453526Sxy150489 { 50463526Sxy150489 struct e1000_hw *hw; 50473526Sxy150489 uint32_t ctrl; 50483526Sxy150489 uint32_t status; 50493526Sxy150489 uint16_t phy_ctrl; 50508479SChenlu.Chen@Sun.COM uint16_t phy_reg; 50515082Syy150190 uint32_t txcw; 50523526Sxy150489 50534919Sxy150489 hw = &Adapter->shared; 50543526Sxy150489 50553526Sxy150489 /* Disable Smart Power Down */ 50563526Sxy150489 phy_spd_state(hw, B_FALSE); 50573526Sxy150489 50587426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl); 50593526Sxy150489 phy_ctrl &= ~(MII_CR_AUTO_NEG_EN | MII_CR_SPEED_100 | MII_CR_SPEED_10); 50603526Sxy150489 phy_ctrl |= MII_CR_FULL_DUPLEX | MII_CR_SPEED_1000; 50613526Sxy150489 50624919Sxy150489 switch (hw->mac.type) { 50633526Sxy150489 case e1000_82540: 50643526Sxy150489 case e1000_82545: 50653526Sxy150489 case e1000_82545_rev_3: 50663526Sxy150489 case e1000_82546: 50673526Sxy150489 case e1000_82546_rev_3: 50683526Sxy150489 case e1000_82573: 50693526Sxy150489 /* Auto-MDI/MDIX off */ 50707426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); 50713526Sxy150489 /* Reset PHY to update Auto-MDI/MDIX */ 50727426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 50734349Sxy150489 phy_ctrl | MII_CR_RESET | MII_CR_AUTO_NEG_EN); 50743526Sxy150489 /* Reset PHY to auto-neg off and force 1000 */ 50757426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 50764349Sxy150489 phy_ctrl | MII_CR_RESET); 50775082Syy150190 /* 50785082Syy150190 * Disable PHY receiver for 82540/545/546 and 82573 Family. 50795082Syy150190 * See comments above e1000g_set_internal_loopback() for the 50805082Syy150190 * background. 50815082Syy150190 */ 50827426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 29, 0x001F); 50837426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 30, 0x8FFC); 50847426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 29, 0x001A); 50857426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 30, 0x8FF0); 50863526Sxy150489 break; 50877133Scc210113 case e1000_80003es2lan: 50887133Scc210113 /* Force Link Up */ 50897426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, 50907426SChenliang.Xu@Sun.COM 0x1CC); 50917133Scc210113 /* Sets PCS loopback at 1Gbs */ 50927426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, 50937426SChenliang.Xu@Sun.COM 0x1046); 50947133Scc210113 break; 50953526Sxy150489 } 50963526Sxy150489 50978479SChenlu.Chen@Sun.COM /* 50988479SChenlu.Chen@Sun.COM * The following registers should be set for e1000_phy_bm phy type. 50998479SChenlu.Chen@Sun.COM * e1000_82574, e1000_ich10lan and some e1000_ich9lan use this phy. 51008479SChenlu.Chen@Sun.COM * For others, we do not need to set these registers. 51018479SChenlu.Chen@Sun.COM */ 51028479SChenlu.Chen@Sun.COM if (hw->phy.type == e1000_phy_bm) { 51038479SChenlu.Chen@Sun.COM /* Set Default MAC Interface speed to 1GB */ 51048850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(2, 21), &phy_reg); 51058479SChenlu.Chen@Sun.COM phy_reg &= ~0x0007; 51068479SChenlu.Chen@Sun.COM phy_reg |= 0x006; 51078850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(2, 21), phy_reg); 51088479SChenlu.Chen@Sun.COM /* Assert SW reset for above settings to take effect */ 51098850SMin.Xu@Sun.COM (void) e1000_phy_commit(hw); 51108479SChenlu.Chen@Sun.COM msec_delay(1); 51118479SChenlu.Chen@Sun.COM /* Force Full Duplex */ 51128850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 16), &phy_reg); 51138850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 16), 51148850SMin.Xu@Sun.COM phy_reg | 0x000C); 51158479SChenlu.Chen@Sun.COM /* Set Link Up (in force link) */ 51168850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(776, 16), &phy_reg); 51178850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(776, 16), 51188850SMin.Xu@Sun.COM phy_reg | 0x0040); 51198479SChenlu.Chen@Sun.COM /* Force Link */ 51208850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 16), &phy_reg); 51218850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 16), 51228850SMin.Xu@Sun.COM phy_reg | 0x0040); 51238479SChenlu.Chen@Sun.COM /* Set Early Link Enable */ 51248850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 20), &phy_reg); 51258850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 20), 51268850SMin.Xu@Sun.COM phy_reg | 0x0400); 51278479SChenlu.Chen@Sun.COM } 51288479SChenlu.Chen@Sun.COM 51293526Sxy150489 /* Set loopback */ 51307426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl | MII_CR_LOOPBACK); 51313526Sxy150489 51323526Sxy150489 msec_delay(250); 51333526Sxy150489 51343526Sxy150489 /* Now set up the MAC to the same speed/duplex as the PHY. */ 51354919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 51363526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 51373526Sxy150489 ctrl |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 51384349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 51394349Sxy150489 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */ 51404349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 51413526Sxy150489 51424919Sxy150489 switch (hw->mac.type) { 51433526Sxy150489 case e1000_82540: 51443526Sxy150489 case e1000_82545: 51453526Sxy150489 case e1000_82545_rev_3: 51463526Sxy150489 case e1000_82546: 51473526Sxy150489 case e1000_82546_rev_3: 51483526Sxy150489 /* 51493526Sxy150489 * For some serdes we'll need to commit the writes now 51503526Sxy150489 * so that the status is updated on link 51513526Sxy150489 */ 51526735Scc210113 if (hw->phy.media_type == e1000_media_type_internal_serdes) { 51534919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 51543526Sxy150489 msec_delay(100); 51554919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 51563526Sxy150489 } 51573526Sxy150489 51586735Scc210113 if (hw->phy.media_type == e1000_media_type_copper) { 51593526Sxy150489 /* Invert Loss of Signal */ 51603526Sxy150489 ctrl |= E1000_CTRL_ILOS; 51613526Sxy150489 } else { 51623526Sxy150489 /* Set ILOS on fiber nic if half duplex is detected */ 51634919Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 51643526Sxy150489 if ((status & E1000_STATUS_FD) == 0) 51653526Sxy150489 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 51663526Sxy150489 } 51673526Sxy150489 break; 51683526Sxy150489 51693526Sxy150489 case e1000_82571: 51703526Sxy150489 case e1000_82572: 51715082Syy150190 /* 51725082Syy150190 * The fiber/SerDes versions of this adapter do not contain an 51735082Syy150190 * accessible PHY. Therefore, loopback beyond MAC must be done 51745082Syy150190 * using SerDes analog loopback. 51755082Syy150190 */ 51766735Scc210113 if (hw->phy.media_type != e1000_media_type_copper) { 51775082Syy150190 /* Disable autoneg by setting bit 31 of TXCW to zero */ 51785082Syy150190 txcw = E1000_READ_REG(hw, E1000_TXCW); 51795082Syy150190 txcw &= ~((uint32_t)1 << 31); 51805082Syy150190 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 51815082Syy150190 51825082Syy150190 /* 51835082Syy150190 * Write 0x410 to Serdes Control register 51845082Syy150190 * to enable Serdes analog loopback 51855082Syy150190 */ 51865082Syy150190 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410); 51875082Syy150190 msec_delay(10); 51883526Sxy150489 } 51898479SChenlu.Chen@Sun.COM 51908479SChenlu.Chen@Sun.COM status = E1000_READ_REG(hw, E1000_STATUS); 51918479SChenlu.Chen@Sun.COM /* Set ILOS on fiber nic if half duplex is detected */ 51928479SChenlu.Chen@Sun.COM if ((hw->phy.media_type == e1000_media_type_fiber) && 51938479SChenlu.Chen@Sun.COM ((status & E1000_STATUS_FD) == 0 || 51948479SChenlu.Chen@Sun.COM (status & E1000_STATUS_LU) == 0)) 51958479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 51968479SChenlu.Chen@Sun.COM else if (hw->phy.media_type == e1000_media_type_internal_serdes) 51978479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU; 51983526Sxy150489 break; 51993526Sxy150489 52003526Sxy150489 case e1000_82573: 52013526Sxy150489 ctrl |= E1000_CTRL_ILOS; 52028479SChenlu.Chen@Sun.COM break; 52038479SChenlu.Chen@Sun.COM case e1000_ich9lan: 52048479SChenlu.Chen@Sun.COM case e1000_ich10lan: 52058479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU; 52063526Sxy150489 break; 52073526Sxy150489 } 52088479SChenlu.Chen@Sun.COM if (hw->phy.type == e1000_phy_bm) 52098479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU | E1000_CTRL_ILOS; 52108479SChenlu.Chen@Sun.COM 52118479SChenlu.Chen@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 52123526Sxy150489 } 52133526Sxy150489 52143526Sxy150489 static void 52153526Sxy150489 e1000g_set_external_loopback_1000(struct e1000g *Adapter) 52163526Sxy150489 { 52173526Sxy150489 struct e1000_hw *hw; 52183526Sxy150489 uint32_t rctl; 52193526Sxy150489 uint32_t ctrl_ext; 52203526Sxy150489 uint32_t ctrl; 52213526Sxy150489 uint32_t status; 52223526Sxy150489 uint32_t txcw; 52237133Scc210113 uint16_t phydata; 52243526Sxy150489 52254919Sxy150489 hw = &Adapter->shared; 52263526Sxy150489 52273526Sxy150489 /* Disable Smart Power Down */ 52283526Sxy150489 phy_spd_state(hw, B_FALSE); 52293526Sxy150489 52307133Scc210113 switch (hw->mac.type) { 52317133Scc210113 case e1000_82571: 52327133Scc210113 case e1000_82572: 52337133Scc210113 switch (hw->phy.media_type) { 52347133Scc210113 case e1000_media_type_copper: 52357133Scc210113 /* Force link up (Must be done before the PHY writes) */ 52367133Scc210113 ctrl = E1000_READ_REG(hw, E1000_CTRL); 52377133Scc210113 ctrl |= E1000_CTRL_SLU; /* Force Link Up */ 52387133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 52397133Scc210113 52407133Scc210113 rctl = E1000_READ_REG(hw, E1000_RCTL); 52417133Scc210113 rctl |= (E1000_RCTL_EN | 52427133Scc210113 E1000_RCTL_SBP | 52437133Scc210113 E1000_RCTL_UPE | 52447133Scc210113 E1000_RCTL_MPE | 52457133Scc210113 E1000_RCTL_LPE | 52467133Scc210113 E1000_RCTL_BAM); /* 0x803E */ 52477133Scc210113 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 52487133Scc210113 52497133Scc210113 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 52507133Scc210113 ctrl_ext |= (E1000_CTRL_EXT_SDP4_DATA | 52517133Scc210113 E1000_CTRL_EXT_SDP6_DATA | 52527133Scc210113 E1000_CTRL_EXT_SDP7_DATA | 52537133Scc210113 E1000_CTRL_EXT_SDP4_DIR | 52547133Scc210113 E1000_CTRL_EXT_SDP6_DIR | 52557133Scc210113 E1000_CTRL_EXT_SDP7_DIR); /* 0x0DD0 */ 52567133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 52577133Scc210113 52587133Scc210113 /* 52597133Scc210113 * This sequence tunes the PHY's SDP and no customer 52607133Scc210113 * settable values. For background, see comments above 52617133Scc210113 * e1000g_set_internal_loopback(). 52627133Scc210113 */ 52637426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x0, 0x140); 52647133Scc210113 msec_delay(10); 52657426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x9, 0x1A00); 52667426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x12, 0xC10); 52677426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x12, 0x1C10); 52687426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F37, 0x76); 52697426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F33, 0x1); 52707426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F33, 0x0); 52717426SChenliang.Xu@Sun.COM 52727426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F35, 0x65); 52737426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1837, 0x3F7C); 52747426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1437, 0x3FDC); 52757426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1237, 0x3F7C); 52767426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1137, 0x3FDC); 52777133Scc210113 52787133Scc210113 msec_delay(50); 52797133Scc210113 break; 52807133Scc210113 case e1000_media_type_fiber: 52817133Scc210113 case e1000_media_type_internal_serdes: 52827133Scc210113 status = E1000_READ_REG(hw, E1000_STATUS); 52837133Scc210113 if (((status & E1000_STATUS_LU) == 0) || 52847133Scc210113 (hw->phy.media_type == 52857133Scc210113 e1000_media_type_internal_serdes)) { 52867133Scc210113 ctrl = E1000_READ_REG(hw, E1000_CTRL); 52877133Scc210113 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 52887133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 52897133Scc210113 } 52907133Scc210113 52917133Scc210113 /* Disable autoneg by setting bit 31 of TXCW to zero */ 52927133Scc210113 txcw = E1000_READ_REG(hw, E1000_TXCW); 52937133Scc210113 txcw &= ~((uint32_t)1 << 31); 52947133Scc210113 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 52957133Scc210113 52967133Scc210113 /* 52977133Scc210113 * Write 0x410 to Serdes Control register 52987133Scc210113 * to enable Serdes analog loopback 52997133Scc210113 */ 53007133Scc210113 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410); 53017133Scc210113 msec_delay(10); 53027133Scc210113 break; 53037133Scc210113 default: 53047133Scc210113 break; 53057133Scc210113 } 53063526Sxy150489 break; 53078479SChenlu.Chen@Sun.COM case e1000_82574: 53087133Scc210113 case e1000_80003es2lan: 53098479SChenlu.Chen@Sun.COM case e1000_ich9lan: 53108479SChenlu.Chen@Sun.COM case e1000_ich10lan: 53117426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, GG82563_REG(6, 16), &phydata); 53127426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_REG(6, 16), 53137426SChenliang.Xu@Sun.COM phydata | (1 << 5)); 53147133Scc210113 Adapter->param_adv_autoneg = 1; 53157133Scc210113 Adapter->param_adv_1000fdx = 1; 53167426SChenliang.Xu@Sun.COM (void) e1000g_reset_link(Adapter); 53173526Sxy150489 break; 53183526Sxy150489 } 53193526Sxy150489 } 53203526Sxy150489 53213526Sxy150489 static void 53223526Sxy150489 e1000g_set_external_loopback_100(struct e1000g *Adapter) 53233526Sxy150489 { 53243526Sxy150489 struct e1000_hw *hw; 53253526Sxy150489 uint32_t ctrl; 53263526Sxy150489 uint16_t phy_ctrl; 53273526Sxy150489 53284919Sxy150489 hw = &Adapter->shared; 53293526Sxy150489 53303526Sxy150489 /* Disable Smart Power Down */ 53313526Sxy150489 phy_spd_state(hw, B_FALSE); 53323526Sxy150489 53333526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX | 53344349Sxy150489 MII_CR_SPEED_100); 53353526Sxy150489 53363526Sxy150489 /* Force 100/FD, reset PHY */ 53377426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 53384349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0xA100 */ 53393526Sxy150489 msec_delay(10); 53403526Sxy150489 53413526Sxy150489 /* Force 100/FD */ 53427426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 53434349Sxy150489 phy_ctrl); /* 0x2100 */ 53443526Sxy150489 msec_delay(10); 53453526Sxy150489 53463526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */ 53474919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 53483526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 53493526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 53504349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 53514349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 53524349Sxy150489 E1000_CTRL_SPD_100 | /* Force Speed to 100 */ 53534349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 53543526Sxy150489 53554919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 53563526Sxy150489 } 53573526Sxy150489 53583526Sxy150489 static void 53593526Sxy150489 e1000g_set_external_loopback_10(struct e1000g *Adapter) 53603526Sxy150489 { 53613526Sxy150489 struct e1000_hw *hw; 53623526Sxy150489 uint32_t ctrl; 53633526Sxy150489 uint16_t phy_ctrl; 53643526Sxy150489 53654919Sxy150489 hw = &Adapter->shared; 53663526Sxy150489 53673526Sxy150489 /* Disable Smart Power Down */ 53683526Sxy150489 phy_spd_state(hw, B_FALSE); 53693526Sxy150489 53703526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX | 53714349Sxy150489 MII_CR_SPEED_10); 53723526Sxy150489 53733526Sxy150489 /* Force 10/FD, reset PHY */ 53747426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 53754349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0x8100 */ 53763526Sxy150489 msec_delay(10); 53773526Sxy150489 53783526Sxy150489 /* Force 10/FD */ 53797426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, 53804349Sxy150489 phy_ctrl); /* 0x0100 */ 53813526Sxy150489 msec_delay(10); 53823526Sxy150489 53833526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */ 53844919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 53853526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 53863526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 53874349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 53884349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 53894349Sxy150489 E1000_CTRL_SPD_10 | /* Force Speed to 10 */ 53904349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 53913526Sxy150489 53924919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 53933526Sxy150489 } 53943526Sxy150489 53953526Sxy150489 #ifdef __sparc 53963526Sxy150489 static boolean_t 53973526Sxy150489 e1000g_find_mac_address(struct e1000g *Adapter) 53983526Sxy150489 { 53994919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 54003526Sxy150489 uchar_t *bytes; 54013526Sxy150489 struct ether_addr sysaddr; 54023526Sxy150489 uint_t nelts; 54033526Sxy150489 int err; 54043526Sxy150489 boolean_t found = B_FALSE; 54053526Sxy150489 54063526Sxy150489 /* 54073526Sxy150489 * The "vendor's factory-set address" may already have 54083526Sxy150489 * been extracted from the chip, but if the property 54093526Sxy150489 * "local-mac-address" is set we use that instead. 54103526Sxy150489 * 54113526Sxy150489 * We check whether it looks like an array of 6 54123526Sxy150489 * bytes (which it should, if OBP set it). If we can't 54133526Sxy150489 * make sense of it this way, we'll ignore it. 54143526Sxy150489 */ 54153526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 54163526Sxy150489 DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts); 54173526Sxy150489 if (err == DDI_PROP_SUCCESS) { 54183526Sxy150489 if (nelts == ETHERADDRL) { 54193526Sxy150489 while (nelts--) 54204919Sxy150489 hw->mac.addr[nelts] = bytes[nelts]; 54213526Sxy150489 found = B_TRUE; 54223526Sxy150489 } 54233526Sxy150489 ddi_prop_free(bytes); 54243526Sxy150489 } 54253526Sxy150489 54263526Sxy150489 /* 54273526Sxy150489 * Look up the OBP property "local-mac-address?". If the user has set 54283526Sxy150489 * 'local-mac-address? = false', use "the system address" instead. 54293526Sxy150489 */ 54303526Sxy150489 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 0, 54313526Sxy150489 "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) { 54323526Sxy150489 if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) { 54333526Sxy150489 if (localetheraddr(NULL, &sysaddr) != 0) { 54344919Sxy150489 bcopy(&sysaddr, hw->mac.addr, ETHERADDRL); 54353526Sxy150489 found = B_TRUE; 54363526Sxy150489 } 54373526Sxy150489 } 54383526Sxy150489 ddi_prop_free(bytes); 54393526Sxy150489 } 54403526Sxy150489 54413526Sxy150489 /* 54423526Sxy150489 * Finally(!), if there's a valid "mac-address" property (created 54433526Sxy150489 * if we netbooted from this interface), we must use this instead 54443526Sxy150489 * of any of the above to ensure that the NFS/install server doesn't 54453526Sxy150489 * get confused by the address changing as Solaris takes over! 54463526Sxy150489 */ 54473526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 54483526Sxy150489 DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts); 54493526Sxy150489 if (err == DDI_PROP_SUCCESS) { 54503526Sxy150489 if (nelts == ETHERADDRL) { 54513526Sxy150489 while (nelts--) 54524919Sxy150489 hw->mac.addr[nelts] = bytes[nelts]; 54533526Sxy150489 found = B_TRUE; 54543526Sxy150489 } 54553526Sxy150489 ddi_prop_free(bytes); 54563526Sxy150489 } 54573526Sxy150489 54583526Sxy150489 if (found) { 54594919Sxy150489 bcopy(hw->mac.addr, hw->mac.perm_addr, 54603526Sxy150489 ETHERADDRL); 54613526Sxy150489 } 54623526Sxy150489 54633526Sxy150489 return (found); 54643526Sxy150489 } 54653526Sxy150489 #endif 54663526Sxy150489 54673526Sxy150489 static int 54683526Sxy150489 e1000g_add_intrs(struct e1000g *Adapter) 54693526Sxy150489 { 54703526Sxy150489 dev_info_t *devinfo; 54713526Sxy150489 int intr_types; 54723526Sxy150489 int rc; 54733526Sxy150489 54743526Sxy150489 devinfo = Adapter->dip; 54753526Sxy150489 54763526Sxy150489 /* Get supported interrupt types */ 54773526Sxy150489 rc = ddi_intr_get_supported_types(devinfo, &intr_types); 54783526Sxy150489 54793526Sxy150489 if (rc != DDI_SUCCESS) { 54804919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 54813526Sxy150489 "Get supported interrupt types failed: %d\n", rc); 54823526Sxy150489 return (DDI_FAILURE); 54833526Sxy150489 } 54843526Sxy150489 54853526Sxy150489 /* 54863526Sxy150489 * Based on Intel Technical Advisory document (TA-160), there are some 54873526Sxy150489 * cases where some older Intel PCI-X NICs may "advertise" to the OS 54883526Sxy150489 * that it supports MSI, but in fact has problems. 54893526Sxy150489 * So we should only enable MSI for PCI-E NICs and disable MSI for old 54903526Sxy150489 * PCI/PCI-X NICs. 54913526Sxy150489 */ 54924919Sxy150489 if (Adapter->shared.mac.type < e1000_82571) 54936986Smx205022 Adapter->msi_enable = B_FALSE; 54946986Smx205022 54956986Smx205022 if ((intr_types & DDI_INTR_TYPE_MSI) && Adapter->msi_enable) { 54963526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_MSI); 54973526Sxy150489 54983526Sxy150489 if (rc != DDI_SUCCESS) { 54994919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 55003526Sxy150489 "Add MSI failed, trying Legacy interrupts\n"); 55013526Sxy150489 } else { 55023526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_MSI; 55033526Sxy150489 } 55043526Sxy150489 } 55053526Sxy150489 55063526Sxy150489 if ((Adapter->intr_type == 0) && 55073526Sxy150489 (intr_types & DDI_INTR_TYPE_FIXED)) { 55083526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_FIXED); 55093526Sxy150489 55103526Sxy150489 if (rc != DDI_SUCCESS) { 55114919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 55123526Sxy150489 "Add Legacy interrupts failed\n"); 55133526Sxy150489 return (DDI_FAILURE); 55143526Sxy150489 } 55153526Sxy150489 55163526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_FIXED; 55173526Sxy150489 } 55183526Sxy150489 55193526Sxy150489 if (Adapter->intr_type == 0) { 55204919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 55213526Sxy150489 "No interrupts registered\n"); 55223526Sxy150489 return (DDI_FAILURE); 55233526Sxy150489 } 55243526Sxy150489 55253526Sxy150489 return (DDI_SUCCESS); 55263526Sxy150489 } 55273526Sxy150489 55283526Sxy150489 /* 55293526Sxy150489 * e1000g_intr_add() handles MSI/Legacy interrupts 55303526Sxy150489 */ 55313526Sxy150489 static int 55323526Sxy150489 e1000g_intr_add(struct e1000g *Adapter, int intr_type) 55333526Sxy150489 { 55343526Sxy150489 dev_info_t *devinfo; 55353526Sxy150489 int count, avail, actual; 55363526Sxy150489 int x, y, rc, inum = 0; 55373526Sxy150489 int flag; 55383526Sxy150489 ddi_intr_handler_t *intr_handler; 55393526Sxy150489 55403526Sxy150489 devinfo = Adapter->dip; 55413526Sxy150489 55423526Sxy150489 /* get number of interrupts */ 55433526Sxy150489 rc = ddi_intr_get_nintrs(devinfo, intr_type, &count); 55443526Sxy150489 if ((rc != DDI_SUCCESS) || (count == 0)) { 55454919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 55463526Sxy150489 "Get interrupt number failed. Return: %d, count: %d\n", 55473526Sxy150489 rc, count); 55483526Sxy150489 return (DDI_FAILURE); 55493526Sxy150489 } 55503526Sxy150489 55513526Sxy150489 /* get number of available interrupts */ 55523526Sxy150489 rc = ddi_intr_get_navail(devinfo, intr_type, &avail); 55533526Sxy150489 if ((rc != DDI_SUCCESS) || (avail == 0)) { 55544919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 55553526Sxy150489 "Get interrupt available number failed. " 55563526Sxy150489 "Return: %d, available: %d\n", rc, avail); 55573526Sxy150489 return (DDI_FAILURE); 55583526Sxy150489 } 55593526Sxy150489 55603526Sxy150489 if (avail < count) { 55614919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 55623526Sxy150489 "Interrupts count: %d, available: %d\n", 55633526Sxy150489 count, avail); 55643526Sxy150489 } 55653526Sxy150489 55663526Sxy150489 /* Allocate an array of interrupt handles */ 55673526Sxy150489 Adapter->intr_size = count * sizeof (ddi_intr_handle_t); 55683526Sxy150489 Adapter->htable = kmem_alloc(Adapter->intr_size, KM_SLEEP); 55693526Sxy150489 55703526Sxy150489 /* Set NORMAL behavior for both MSI and FIXED interrupt */ 55713526Sxy150489 flag = DDI_INTR_ALLOC_NORMAL; 55723526Sxy150489 55733526Sxy150489 /* call ddi_intr_alloc() */ 55743526Sxy150489 rc = ddi_intr_alloc(devinfo, Adapter->htable, intr_type, inum, 55753526Sxy150489 count, &actual, flag); 55763526Sxy150489 55773526Sxy150489 if ((rc != DDI_SUCCESS) || (actual == 0)) { 55784919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 55793526Sxy150489 "Allocate interrupts failed: %d\n", rc); 55803526Sxy150489 55813526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 55823526Sxy150489 return (DDI_FAILURE); 55833526Sxy150489 } 55843526Sxy150489 55853526Sxy150489 if (actual < count) { 55864919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 55873526Sxy150489 "Interrupts requested: %d, received: %d\n", 55883526Sxy150489 count, actual); 55893526Sxy150489 } 55903526Sxy150489 55913526Sxy150489 Adapter->intr_cnt = actual; 55923526Sxy150489 55933526Sxy150489 /* Get priority for first msi, assume remaining are all the same */ 55943526Sxy150489 rc = ddi_intr_get_pri(Adapter->htable[0], &Adapter->intr_pri); 55953526Sxy150489 55963526Sxy150489 if (rc != DDI_SUCCESS) { 55974919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 55983526Sxy150489 "Get interrupt priority failed: %d\n", rc); 55993526Sxy150489 56003526Sxy150489 /* Free already allocated intr */ 56013526Sxy150489 for (y = 0; y < actual; y++) 56023526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 56033526Sxy150489 56043526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 56053526Sxy150489 return (DDI_FAILURE); 56063526Sxy150489 } 56073526Sxy150489 56083526Sxy150489 /* 56093526Sxy150489 * In Legacy Interrupt mode, for PCI-Express adapters, we should 56103526Sxy150489 * use the interrupt service routine e1000g_intr_pciexpress() 56113526Sxy150489 * to avoid interrupt stealing when sharing interrupt with other 56123526Sxy150489 * devices. 56133526Sxy150489 */ 56144919Sxy150489 if (Adapter->shared.mac.type < e1000_82571) 56153526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr; 56163526Sxy150489 else 56173526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr_pciexpress; 56183526Sxy150489 56193526Sxy150489 /* Call ddi_intr_add_handler() */ 56203526Sxy150489 for (x = 0; x < actual; x++) { 56213526Sxy150489 rc = ddi_intr_add_handler(Adapter->htable[x], 56223526Sxy150489 intr_handler, (caddr_t)Adapter, NULL); 56233526Sxy150489 56243526Sxy150489 if (rc != DDI_SUCCESS) { 56254919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 56263526Sxy150489 "Add interrupt handler failed: %d\n", rc); 56273526Sxy150489 56283526Sxy150489 /* Remove already added handler */ 56293526Sxy150489 for (y = 0; y < x; y++) 56303526Sxy150489 (void) ddi_intr_remove_handler( 56313526Sxy150489 Adapter->htable[y]); 56323526Sxy150489 56333526Sxy150489 /* Free already allocated intr */ 56343526Sxy150489 for (y = 0; y < actual; y++) 56353526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 56363526Sxy150489 56373526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 56383526Sxy150489 return (DDI_FAILURE); 56393526Sxy150489 } 56403526Sxy150489 } 56413526Sxy150489 56423526Sxy150489 rc = ddi_intr_get_cap(Adapter->htable[0], &Adapter->intr_cap); 56433526Sxy150489 56443526Sxy150489 if (rc != DDI_SUCCESS) { 56454919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 56463526Sxy150489 "Get interrupt cap failed: %d\n", rc); 56473526Sxy150489 56483526Sxy150489 /* Free already allocated intr */ 56493526Sxy150489 for (y = 0; y < actual; y++) { 56503526Sxy150489 (void) ddi_intr_remove_handler(Adapter->htable[y]); 56513526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 56523526Sxy150489 } 56533526Sxy150489 56543526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 56553526Sxy150489 return (DDI_FAILURE); 56563526Sxy150489 } 56573526Sxy150489 56583526Sxy150489 return (DDI_SUCCESS); 56593526Sxy150489 } 56603526Sxy150489 56613526Sxy150489 static int 56623526Sxy150489 e1000g_rem_intrs(struct e1000g *Adapter) 56633526Sxy150489 { 56643526Sxy150489 int x; 56653526Sxy150489 int rc; 56663526Sxy150489 56673526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 56683526Sxy150489 rc = ddi_intr_remove_handler(Adapter->htable[x]); 56693526Sxy150489 if (rc != DDI_SUCCESS) { 56704919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 56713526Sxy150489 "Remove intr handler failed: %d\n", rc); 56723526Sxy150489 return (DDI_FAILURE); 56733526Sxy150489 } 56743526Sxy150489 56753526Sxy150489 rc = ddi_intr_free(Adapter->htable[x]); 56763526Sxy150489 if (rc != DDI_SUCCESS) { 56774919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 56783526Sxy150489 "Free intr failed: %d\n", rc); 56793526Sxy150489 return (DDI_FAILURE); 56803526Sxy150489 } 56813526Sxy150489 } 56823526Sxy150489 56833526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 56843526Sxy150489 56853526Sxy150489 return (DDI_SUCCESS); 56863526Sxy150489 } 56873526Sxy150489 56883526Sxy150489 static int 56893526Sxy150489 e1000g_enable_intrs(struct e1000g *Adapter) 56903526Sxy150489 { 56913526Sxy150489 int x; 56923526Sxy150489 int rc; 56933526Sxy150489 56943526Sxy150489 /* Enable interrupts */ 56953526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 56963526Sxy150489 /* Call ddi_intr_block_enable() for MSI */ 56973526Sxy150489 rc = ddi_intr_block_enable(Adapter->htable, 56983526Sxy150489 Adapter->intr_cnt); 56993526Sxy150489 if (rc != DDI_SUCCESS) { 57004919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 57013526Sxy150489 "Enable block intr failed: %d\n", rc); 57023526Sxy150489 return (DDI_FAILURE); 57033526Sxy150489 } 57043526Sxy150489 } else { 57053526Sxy150489 /* Call ddi_intr_enable() for Legacy/MSI non block enable */ 57063526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 57073526Sxy150489 rc = ddi_intr_enable(Adapter->htable[x]); 57083526Sxy150489 if (rc != DDI_SUCCESS) { 57094919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 57103526Sxy150489 "Enable intr failed: %d\n", rc); 57113526Sxy150489 return (DDI_FAILURE); 57123526Sxy150489 } 57133526Sxy150489 } 57143526Sxy150489 } 57153526Sxy150489 57163526Sxy150489 return (DDI_SUCCESS); 57173526Sxy150489 } 57183526Sxy150489 57193526Sxy150489 static int 57203526Sxy150489 e1000g_disable_intrs(struct e1000g *Adapter) 57213526Sxy150489 { 57223526Sxy150489 int x; 57233526Sxy150489 int rc; 57243526Sxy150489 57253526Sxy150489 /* Disable all interrupts */ 57263526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 57273526Sxy150489 rc = ddi_intr_block_disable(Adapter->htable, 57283526Sxy150489 Adapter->intr_cnt); 57293526Sxy150489 if (rc != DDI_SUCCESS) { 57304919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 57313526Sxy150489 "Disable block intr failed: %d\n", rc); 57323526Sxy150489 return (DDI_FAILURE); 57333526Sxy150489 } 57343526Sxy150489 } else { 57353526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 57363526Sxy150489 rc = ddi_intr_disable(Adapter->htable[x]); 57373526Sxy150489 if (rc != DDI_SUCCESS) { 57384919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 57393526Sxy150489 "Disable intr failed: %d\n", rc); 57403526Sxy150489 return (DDI_FAILURE); 57413526Sxy150489 } 57423526Sxy150489 } 57433526Sxy150489 } 57443526Sxy150489 57453526Sxy150489 return (DDI_SUCCESS); 57463526Sxy150489 } 57475082Syy150190 57485082Syy150190 /* 57495082Syy150190 * e1000g_get_phy_state - get the state of PHY registers, save in the adapter 57505082Syy150190 */ 57515082Syy150190 static void 57525082Syy150190 e1000g_get_phy_state(struct e1000g *Adapter) 57535082Syy150190 { 57545082Syy150190 struct e1000_hw *hw = &Adapter->shared; 57555082Syy150190 57567426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_CONTROL, &Adapter->phy_ctrl); 57577426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_STATUS, &Adapter->phy_status); 57587426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &Adapter->phy_an_adv); 57597426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &Adapter->phy_an_exp); 57607426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_EXT_STATUS, &Adapter->phy_ext_status); 57617426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &Adapter->phy_1000t_ctrl); 57627426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, 57637426SChenliang.Xu@Sun.COM &Adapter->phy_1000t_status); 57647426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_LP_ABILITY, &Adapter->phy_lp_able); 57656394Scc210113 57666394Scc210113 Adapter->param_autoneg_cap = 57676394Scc210113 (Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0; 57686394Scc210113 Adapter->param_pause_cap = 57696394Scc210113 (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0; 57706394Scc210113 Adapter->param_asym_pause_cap = 57716394Scc210113 (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0; 57726394Scc210113 Adapter->param_1000fdx_cap = 57736394Scc210113 ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 57746394Scc210113 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0; 57756394Scc210113 Adapter->param_1000hdx_cap = 57766394Scc210113 ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) || 57776394Scc210113 (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0; 57786394Scc210113 Adapter->param_100t4_cap = 57796394Scc210113 (Adapter->phy_status & MII_SR_100T4_CAPS) ? 1 : 0; 57806394Scc210113 Adapter->param_100fdx_cap = 57816394Scc210113 ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 57826394Scc210113 (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0; 57836394Scc210113 Adapter->param_100hdx_cap = 57846394Scc210113 ((Adapter->phy_status & MII_SR_100X_HD_CAPS) || 57856394Scc210113 (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0; 57866394Scc210113 Adapter->param_10fdx_cap = 57876394Scc210113 (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0; 57886394Scc210113 Adapter->param_10hdx_cap = 57896394Scc210113 (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0; 57906394Scc210113 57916394Scc210113 Adapter->param_adv_autoneg = hw->mac.autoneg; 57926394Scc210113 Adapter->param_adv_pause = 57936394Scc210113 (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0; 57946394Scc210113 Adapter->param_adv_asym_pause = 57956394Scc210113 (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0; 57966394Scc210113 Adapter->param_adv_1000hdx = 57976394Scc210113 (Adapter->phy_1000t_ctrl & CR_1000T_HD_CAPS) ? 1 : 0; 57986394Scc210113 Adapter->param_adv_100t4 = 57996394Scc210113 (Adapter->phy_an_adv & NWAY_AR_100T4_CAPS) ? 1 : 0; 58006394Scc210113 if (Adapter->param_adv_autoneg == 1) { 58016394Scc210113 Adapter->param_adv_1000fdx = 58026394Scc210113 (Adapter->phy_1000t_ctrl & CR_1000T_FD_CAPS) ? 1 : 0; 58036394Scc210113 Adapter->param_adv_100fdx = 58046394Scc210113 (Adapter->phy_an_adv & NWAY_AR_100TX_FD_CAPS) ? 1 : 0; 58056394Scc210113 Adapter->param_adv_100hdx = 58066394Scc210113 (Adapter->phy_an_adv & NWAY_AR_100TX_HD_CAPS) ? 1 : 0; 58076394Scc210113 Adapter->param_adv_10fdx = 58086394Scc210113 (Adapter->phy_an_adv & NWAY_AR_10T_FD_CAPS) ? 1 : 0; 58096394Scc210113 Adapter->param_adv_10hdx = 58106394Scc210113 (Adapter->phy_an_adv & NWAY_AR_10T_HD_CAPS) ? 1 : 0; 58116394Scc210113 } 58126394Scc210113 58136394Scc210113 Adapter->param_lp_autoneg = 58146394Scc210113 (Adapter->phy_an_exp & NWAY_ER_LP_NWAY_CAPS) ? 1 : 0; 58156394Scc210113 Adapter->param_lp_pause = 58166394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_PAUSE) ? 1 : 0; 58176394Scc210113 Adapter->param_lp_asym_pause = 58186394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_ASM_DIR) ? 1 : 0; 58196394Scc210113 Adapter->param_lp_1000fdx = 58206394Scc210113 (Adapter->phy_1000t_status & SR_1000T_LP_FD_CAPS) ? 1 : 0; 58216394Scc210113 Adapter->param_lp_1000hdx = 58226394Scc210113 (Adapter->phy_1000t_status & SR_1000T_LP_HD_CAPS) ? 1 : 0; 58236394Scc210113 Adapter->param_lp_100t4 = 58246394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_100T4_CAPS) ? 1 : 0; 58256394Scc210113 Adapter->param_lp_100fdx = 58266394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_100TX_FD_CAPS) ? 1 : 0; 58276394Scc210113 Adapter->param_lp_100hdx = 58286394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_100TX_HD_CAPS) ? 1 : 0; 58296394Scc210113 Adapter->param_lp_10fdx = 58306394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_10T_FD_CAPS) ? 1 : 0; 58316394Scc210113 Adapter->param_lp_10hdx = 58326394Scc210113 (Adapter->phy_lp_able & NWAY_LPAR_10T_HD_CAPS) ? 1 : 0; 58335082Syy150190 } 58345273Sgl147354 58355273Sgl147354 /* 58365273Sgl147354 * FMA support 58375273Sgl147354 */ 58385273Sgl147354 58395273Sgl147354 int 58405273Sgl147354 e1000g_check_acc_handle(ddi_acc_handle_t handle) 58415273Sgl147354 { 58425273Sgl147354 ddi_fm_error_t de; 58435273Sgl147354 58445273Sgl147354 ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION); 58455273Sgl147354 ddi_fm_acc_err_clear(handle, DDI_FME_VERSION); 58465273Sgl147354 return (de.fme_status); 58475273Sgl147354 } 58485273Sgl147354 58495273Sgl147354 int 58505273Sgl147354 e1000g_check_dma_handle(ddi_dma_handle_t handle) 58515273Sgl147354 { 58525273Sgl147354 ddi_fm_error_t de; 58535273Sgl147354 58545273Sgl147354 ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION); 58555273Sgl147354 return (de.fme_status); 58565273Sgl147354 } 58575273Sgl147354 58585273Sgl147354 /* 58595273Sgl147354 * The IO fault service error handling callback function 58605273Sgl147354 */ 58617426SChenliang.Xu@Sun.COM /* ARGSUSED2 */ 58625273Sgl147354 static int 58635273Sgl147354 e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data) 58645273Sgl147354 { 58655273Sgl147354 /* 58665273Sgl147354 * as the driver can always deal with an error in any dma or 58675273Sgl147354 * access handle, we can just return the fme_status value. 58685273Sgl147354 */ 58695273Sgl147354 pci_ereport_post(dip, err, NULL); 58705273Sgl147354 return (err->fme_status); 58715273Sgl147354 } 58725273Sgl147354 58735273Sgl147354 static void 58745273Sgl147354 e1000g_fm_init(struct e1000g *Adapter) 58755273Sgl147354 { 58765273Sgl147354 ddi_iblock_cookie_t iblk; 58775273Sgl147354 int fma_acc_flag, fma_dma_flag; 58785273Sgl147354 58795273Sgl147354 /* Only register with IO Fault Services if we have some capability */ 58805273Sgl147354 if (Adapter->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) { 58815273Sgl147354 e1000g_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC; 58825273Sgl147354 fma_acc_flag = 1; 58835273Sgl147354 } else { 58845273Sgl147354 e1000g_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC; 58855273Sgl147354 fma_acc_flag = 0; 58865273Sgl147354 } 58875273Sgl147354 58885273Sgl147354 if (Adapter->fm_capabilities & DDI_FM_DMACHK_CAPABLE) { 58895273Sgl147354 fma_dma_flag = 1; 58905273Sgl147354 } else { 58915273Sgl147354 fma_dma_flag = 0; 58925273Sgl147354 } 58935273Sgl147354 58945273Sgl147354 (void) e1000g_set_fma_flags(Adapter, fma_acc_flag, fma_dma_flag); 58955273Sgl147354 58965273Sgl147354 if (Adapter->fm_capabilities) { 58975273Sgl147354 58985273Sgl147354 /* Register capabilities with IO Fault Services */ 58995273Sgl147354 ddi_fm_init(Adapter->dip, &Adapter->fm_capabilities, &iblk); 59005273Sgl147354 59015273Sgl147354 /* 59025273Sgl147354 * Initialize pci ereport capabilities if ereport capable 59035273Sgl147354 */ 59045273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) || 59055273Sgl147354 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 59065273Sgl147354 pci_ereport_setup(Adapter->dip); 59075273Sgl147354 59085273Sgl147354 /* 59095273Sgl147354 * Register error callback if error callback capable 59105273Sgl147354 */ 59115273Sgl147354 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 59125273Sgl147354 ddi_fm_handler_register(Adapter->dip, 59135273Sgl147354 e1000g_fm_error_cb, (void*) Adapter); 59145273Sgl147354 } 59155273Sgl147354 } 59165273Sgl147354 59175273Sgl147354 static void 59185273Sgl147354 e1000g_fm_fini(struct e1000g *Adapter) 59195273Sgl147354 { 59205273Sgl147354 /* Only unregister FMA capabilities if we registered some */ 59215273Sgl147354 if (Adapter->fm_capabilities) { 59225273Sgl147354 59235273Sgl147354 /* 59245273Sgl147354 * Release any resources allocated by pci_ereport_setup() 59255273Sgl147354 */ 59265273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) || 59275273Sgl147354 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 59285273Sgl147354 pci_ereport_teardown(Adapter->dip); 59295273Sgl147354 59305273Sgl147354 /* 59315273Sgl147354 * Un-register error callback if error callback capable 59325273Sgl147354 */ 59335273Sgl147354 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities)) 59345273Sgl147354 ddi_fm_handler_unregister(Adapter->dip); 59355273Sgl147354 59365273Sgl147354 /* Unregister from IO Fault Services */ 59378949SChangqing.Li@Sun.COM mutex_enter(&e1000g_rx_detach_lock); 59385273Sgl147354 ddi_fm_fini(Adapter->dip); 59398949SChangqing.Li@Sun.COM if (Adapter->priv_dip != NULL) { 59408949SChangqing.Li@Sun.COM DEVI(Adapter->priv_dip)->devi_fmhdl = NULL; 59418949SChangqing.Li@Sun.COM } 59428949SChangqing.Li@Sun.COM mutex_exit(&e1000g_rx_detach_lock); 59435273Sgl147354 } 59445273Sgl147354 } 59455273Sgl147354 59465273Sgl147354 void 59475273Sgl147354 e1000g_fm_ereport(struct e1000g *Adapter, char *detail) 59485273Sgl147354 { 59495273Sgl147354 uint64_t ena; 59505273Sgl147354 char buf[FM_MAX_CLASS]; 59515273Sgl147354 59525273Sgl147354 (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail); 59535273Sgl147354 ena = fm_ena_generate(0, FM_ENA_FMT1); 59545273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities)) { 59555273Sgl147354 ddi_fm_ereport_post(Adapter->dip, buf, ena, DDI_NOSLEEP, 59565273Sgl147354 FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL); 59575273Sgl147354 } 59585273Sgl147354 } 59596512Ssowmini 59607656SSherry.Moore@Sun.COM /* 59617656SSherry.Moore@Sun.COM * quiesce(9E) entry point. 59627656SSherry.Moore@Sun.COM * 59637656SSherry.Moore@Sun.COM * This function is called when the system is single-threaded at high 59647656SSherry.Moore@Sun.COM * PIL with preemption disabled. Therefore, this function must not be 59657656SSherry.Moore@Sun.COM * blocked. 59667656SSherry.Moore@Sun.COM * 59677656SSherry.Moore@Sun.COM * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure. 59687656SSherry.Moore@Sun.COM * DDI_FAILURE indicates an error condition and should almost never happen. 59697656SSherry.Moore@Sun.COM */ 59707656SSherry.Moore@Sun.COM static int 59717656SSherry.Moore@Sun.COM e1000g_quiesce(dev_info_t *devinfo) 59727656SSherry.Moore@Sun.COM { 59737656SSherry.Moore@Sun.COM struct e1000g *Adapter; 59747656SSherry.Moore@Sun.COM 59757656SSherry.Moore@Sun.COM Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 59767656SSherry.Moore@Sun.COM 59777656SSherry.Moore@Sun.COM if (Adapter == NULL) 59787656SSherry.Moore@Sun.COM return (DDI_FAILURE); 59797656SSherry.Moore@Sun.COM 59807656SSherry.Moore@Sun.COM e1000g_clear_all_interrupts(Adapter); 59817656SSherry.Moore@Sun.COM 59827656SSherry.Moore@Sun.COM (void) e1000_reset_hw(&Adapter->shared); 59837656SSherry.Moore@Sun.COM 59847656SSherry.Moore@Sun.COM /* Setup our HW Tx Head & Tail descriptor pointers */ 59857656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0); 59867656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0); 59877656SSherry.Moore@Sun.COM 59887656SSherry.Moore@Sun.COM /* Setup our HW Rx Head & Tail descriptor pointers */ 59897656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RDH(0), 0); 59907656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RDT(0), 0); 59917656SSherry.Moore@Sun.COM 59927656SSherry.Moore@Sun.COM return (DDI_SUCCESS); 59937656SSherry.Moore@Sun.COM } 59947656SSherry.Moore@Sun.COM 59956512Ssowmini static int 59966512Ssowmini e1000g_get_def_val(struct e1000g *Adapter, mac_prop_id_t pr_num, 59976512Ssowmini uint_t pr_valsize, void *pr_val) 59986512Ssowmini { 59996512Ssowmini link_flowctrl_t fl; 60006512Ssowmini int err = 0; 60016512Ssowmini 60026512Ssowmini ASSERT(pr_valsize > 0); 60036512Ssowmini switch (pr_num) { 60046789Sam223141 case MAC_PROP_AUTONEG: 60056512Ssowmini *(uint8_t *)pr_val = 60066512Ssowmini ((Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0); 60076512Ssowmini break; 60086789Sam223141 case MAC_PROP_FLOWCTRL: 60096512Ssowmini if (pr_valsize < sizeof (link_flowctrl_t)) 60106512Ssowmini return (EINVAL); 60116512Ssowmini fl = LINK_FLOWCTRL_BI; 60126512Ssowmini bcopy(&fl, pr_val, sizeof (fl)); 60136512Ssowmini break; 60146789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 60156789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 60166512Ssowmini *(uint8_t *)pr_val = 60176512Ssowmini ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 60186512Ssowmini (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0; 60196512Ssowmini break; 60206789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 60216789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 60226512Ssowmini *(uint8_t *)pr_val = 60236512Ssowmini ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) || 60246512Ssowmini (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0; 60256512Ssowmini break; 60266789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 60276789Sam223141 case MAC_PROP_EN_100FDX_CAP: 60286512Ssowmini *(uint8_t *)pr_val = 60296512Ssowmini ((Adapter->phy_status & MII_SR_100X_FD_CAPS) || 60306512Ssowmini (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0; 60317426SChenliang.Xu@Sun.COM break; 60326789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 60336789Sam223141 case MAC_PROP_EN_100HDX_CAP: 60346512Ssowmini *(uint8_t *)pr_val = 60356512Ssowmini ((Adapter->phy_status & MII_SR_100X_HD_CAPS) || 60366512Ssowmini (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0; 60376512Ssowmini break; 60386789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 60396789Sam223141 case MAC_PROP_EN_10FDX_CAP: 60406512Ssowmini *(uint8_t *)pr_val = 60416512Ssowmini (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0; 60426512Ssowmini break; 60436789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 60446789Sam223141 case MAC_PROP_EN_10HDX_CAP: 60456512Ssowmini *(uint8_t *)pr_val = 60466512Ssowmini (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0; 60476512Ssowmini break; 60486512Ssowmini default: 60496512Ssowmini err = ENOTSUP; 60506512Ssowmini break; 60516512Ssowmini } 60526512Ssowmini return (err); 60536512Ssowmini } 60546512Ssowmini 60556512Ssowmini /* 60566512Ssowmini * synchronize the adv* and en* parameters. 60576512Ssowmini * 60586512Ssowmini * See comments in <sys/dld.h> for details of the *_en_* 60596512Ssowmini * parameters. The usage of ndd for setting adv parameters will 60606512Ssowmini * synchronize all the en parameters with the e1000g parameters, 60617607STed.You@Sun.COM * implicitly disabling any settings made via dladm. 60626512Ssowmini */ 60636512Ssowmini static void 60646512Ssowmini e1000g_param_sync(struct e1000g *Adapter) 60656512Ssowmini { 60666512Ssowmini Adapter->param_en_1000fdx = Adapter->param_adv_1000fdx; 60676512Ssowmini Adapter->param_en_1000hdx = Adapter->param_adv_1000hdx; 60686512Ssowmini Adapter->param_en_100fdx = Adapter->param_adv_100fdx; 60696512Ssowmini Adapter->param_en_100hdx = Adapter->param_adv_100hdx; 60706512Ssowmini Adapter->param_en_10fdx = Adapter->param_adv_10fdx; 60716512Ssowmini Adapter->param_en_10hdx = Adapter->param_adv_10hdx; 60726512Ssowmini } 60737607STed.You@Sun.COM 60747607STed.You@Sun.COM /* 60757607STed.You@Sun.COM * e1000g_get_driver_control - tell manageability firmware that the driver 60767607STed.You@Sun.COM * has control. 60777607STed.You@Sun.COM */ 60787607STed.You@Sun.COM static void 60797607STed.You@Sun.COM e1000g_get_driver_control(struct e1000_hw *hw) 60807607STed.You@Sun.COM { 60817607STed.You@Sun.COM uint32_t ctrl_ext; 60827607STed.You@Sun.COM uint32_t swsm; 60837607STed.You@Sun.COM 60847607STed.You@Sun.COM /* tell manageability firmware the driver has taken over */ 60857607STed.You@Sun.COM switch (hw->mac.type) { 60867607STed.You@Sun.COM case e1000_82573: 60877607STed.You@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM); 60887607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD); 60897607STed.You@Sun.COM break; 60907607STed.You@Sun.COM case e1000_82571: 60917607STed.You@Sun.COM case e1000_82572: 60927607STed.You@Sun.COM case e1000_82574: 60937607STed.You@Sun.COM case e1000_80003es2lan: 60947607STed.You@Sun.COM case e1000_ich8lan: 60957607STed.You@Sun.COM case e1000_ich9lan: 60967607STed.You@Sun.COM case e1000_ich10lan: 60977607STed.You@Sun.COM ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 60987607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL_EXT, 60997607STed.You@Sun.COM ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); 61007607STed.You@Sun.COM break; 61017607STed.You@Sun.COM default: 61027607STed.You@Sun.COM /* no manageability firmware: do nothing */ 61037607STed.You@Sun.COM break; 61047607STed.You@Sun.COM } 61057607STed.You@Sun.COM } 61067607STed.You@Sun.COM 61077607STed.You@Sun.COM /* 61087607STed.You@Sun.COM * e1000g_release_driver_control - tell manageability firmware that the driver 61097607STed.You@Sun.COM * has released control. 61107607STed.You@Sun.COM */ 61117607STed.You@Sun.COM static void 61127607STed.You@Sun.COM e1000g_release_driver_control(struct e1000_hw *hw) 61137607STed.You@Sun.COM { 61147607STed.You@Sun.COM uint32_t ctrl_ext; 61157607STed.You@Sun.COM uint32_t swsm; 61167607STed.You@Sun.COM 61177607STed.You@Sun.COM /* tell manageability firmware the driver has released control */ 61187607STed.You@Sun.COM switch (hw->mac.type) { 61197607STed.You@Sun.COM case e1000_82573: 61207607STed.You@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM); 61217607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD); 61227607STed.You@Sun.COM break; 61237607STed.You@Sun.COM case e1000_82571: 61247607STed.You@Sun.COM case e1000_82572: 61257607STed.You@Sun.COM case e1000_82574: 61267607STed.You@Sun.COM case e1000_80003es2lan: 61277607STed.You@Sun.COM case e1000_ich8lan: 61287607STed.You@Sun.COM case e1000_ich9lan: 61297607STed.You@Sun.COM case e1000_ich10lan: 61307607STed.You@Sun.COM ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 61317607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL_EXT, 61327607STed.You@Sun.COM ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); 61337607STed.You@Sun.COM break; 61347607STed.You@Sun.COM default: 61357607STed.You@Sun.COM /* no manageability firmware: do nothing */ 61367607STed.You@Sun.COM break; 61377607STed.You@Sun.COM } 61387607STed.You@Sun.COM } 61397722SShuguo.Yang@Sun.COM 61407722SShuguo.Yang@Sun.COM /* 61417722SShuguo.Yang@Sun.COM * Restore e1000g promiscuous mode. 61427722SShuguo.Yang@Sun.COM */ 61437722SShuguo.Yang@Sun.COM static void 61447722SShuguo.Yang@Sun.COM e1000g_restore_promisc(struct e1000g *Adapter) 61457722SShuguo.Yang@Sun.COM { 61467722SShuguo.Yang@Sun.COM if (Adapter->e1000g_promisc) { 61477722SShuguo.Yang@Sun.COM uint32_t rctl; 61487722SShuguo.Yang@Sun.COM 61497722SShuguo.Yang@Sun.COM rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL); 61507722SShuguo.Yang@Sun.COM rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM); 61517722SShuguo.Yang@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl); 61527722SShuguo.Yang@Sun.COM } 61537722SShuguo.Yang@Sun.COM } 6154