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 * 93526Sxy150489 * Copyright(c) 1999 - 2007 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 /* 223526Sxy150489 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 233526Sxy150489 * Use is subject to license terms of the CDDLv1. 243526Sxy150489 */ 253526Sxy150489 263526Sxy150489 #pragma ident "%Z%%M% %I% %E% SMI" 273526Sxy150489 283526Sxy150489 /* 293526Sxy150489 * ********************************************************************** 303526Sxy150489 * * 313526Sxy150489 * Module Name: * 323526Sxy150489 * e1000g_main.c * 333526Sxy150489 * * 343526Sxy150489 * Abstract: * 35*4919Sxy150489 * This file contains the interface routines for the solaris OS. * 36*4919Sxy150489 * It has all DDI entry point routines and GLD entry point routines. * 373526Sxy150489 * * 38*4919Sxy150489 * This file also contains routines that take care of initialization * 39*4919Sxy150489 * uninit routine and interrupt routine. * 403526Sxy150489 * * 413526Sxy150489 * ********************************************************************** 423526Sxy150489 */ 433526Sxy150489 443526Sxy150489 #include <sys/dlpi.h> 453526Sxy150489 #include <sys/mac.h> 463526Sxy150489 #include "e1000g_sw.h" 473526Sxy150489 #include "e1000g_debug.h" 483526Sxy150489 493526Sxy150489 #define E1000_RX_INTPT_TIME 128 503526Sxy150489 #define E1000_RX_PKT_CNT 8 513526Sxy150489 52*4919Sxy150489 static char ident[] = "Intel PRO/1000 Ethernet 5.2.0"; 533526Sxy150489 static char e1000g_string[] = "Intel(R) PRO/1000 Network Connection"; 54*4919Sxy150489 static char e1000g_version[] = "Driver Ver. 5.2.0"; 553526Sxy150489 563526Sxy150489 /* 573526Sxy150489 * Proto types for DDI entry points 583526Sxy150489 */ 59*4919Sxy150489 static int e1000g_attach(dev_info_t *, ddi_attach_cmd_t); 60*4919Sxy150489 static int e1000g_detach(dev_info_t *, ddi_detach_cmd_t); 613526Sxy150489 623526Sxy150489 /* 633526Sxy150489 * init and intr routines prototype 643526Sxy150489 */ 65*4919Sxy150489 static int e1000g_resume(dev_info_t *); 66*4919Sxy150489 static int e1000g_suspend(dev_info_t *); 673526Sxy150489 static uint_t e1000g_intr_pciexpress(caddr_t); 683526Sxy150489 static uint_t e1000g_intr(caddr_t); 693526Sxy150489 static void e1000g_intr_work(struct e1000g *, uint32_t); 703526Sxy150489 #pragma inline(e1000g_intr_work) 713526Sxy150489 static int e1000g_init(struct e1000g *); 72*4919Sxy150489 static int e1000g_start(struct e1000g *, boolean_t); 73*4919Sxy150489 static void e1000g_stop(struct e1000g *, boolean_t); 743526Sxy150489 static int e1000g_m_start(void *); 753526Sxy150489 static void e1000g_m_stop(void *); 763526Sxy150489 static int e1000g_m_promisc(void *, boolean_t); 773526Sxy150489 static boolean_t e1000g_m_getcapab(void *, mac_capab_t, void *); 783526Sxy150489 static int e1000g_m_unicst(void *, const uint8_t *); 793526Sxy150489 static int e1000g_m_unicst_add(void *, mac_multi_addr_t *); 803526Sxy150489 static int e1000g_m_unicst_remove(void *, mac_addr_slot_t); 813526Sxy150489 static int e1000g_m_unicst_modify(void *, mac_multi_addr_t *); 823526Sxy150489 static int e1000g_m_unicst_get(void *, mac_multi_addr_t *); 833526Sxy150489 static int e1000g_m_multicst(void *, boolean_t, const uint8_t *); 843526Sxy150489 static void e1000g_m_blank(void *, time_t, uint32_t); 853526Sxy150489 static void e1000g_m_resources(void *); 863526Sxy150489 static void e1000g_m_ioctl(void *, queue_t *, mblk_t *); 87*4919Sxy150489 static void e1000g_init_locks(struct e1000g *); 88*4919Sxy150489 static void e1000g_destroy_locks(struct e1000g *); 89*4919Sxy150489 static int e1000g_identify_hardware(struct e1000g *); 90*4919Sxy150489 static int e1000g_regs_map(struct e1000g *); 91*4919Sxy150489 static int e1000g_set_driver_params(struct e1000g *); 92*4919Sxy150489 static int e1000g_register_mac(struct e1000g *); 93*4919Sxy150489 static boolean_t e1000g_rx_drain(struct e1000g *); 94*4919Sxy150489 static boolean_t e1000g_tx_drain(struct e1000g *); 95*4919Sxy150489 static void e1000g_init_unicst(struct e1000g *); 963526Sxy150489 static int e1000g_unicst_set(struct e1000g *, const uint8_t *, mac_addr_slot_t); 973526Sxy150489 983526Sxy150489 /* 993526Sxy150489 * Local routines 1003526Sxy150489 */ 101*4919Sxy150489 static void e1000g_tx_clean(struct e1000g *); 102*4919Sxy150489 static void e1000g_rx_clean(struct e1000g *); 1034061Sxy150489 static void e1000g_link_timer(void *); 104*4919Sxy150489 static void e1000g_local_timer(void *); 1054061Sxy150489 static boolean_t e1000g_link_check(struct e1000g *); 1063526Sxy150489 static boolean_t e1000g_stall_check(struct e1000g *); 1073526Sxy150489 static void e1000g_smartspeed(struct e1000g *); 108*4919Sxy150489 static void e1000g_get_conf(struct e1000g *); 109*4919Sxy150489 static int e1000g_get_prop(struct e1000g *, char *, int, int, int); 110*4919Sxy150489 static void enable_watchdog_timer(struct e1000g *); 111*4919Sxy150489 static void disable_watchdog_timer(struct e1000g *); 112*4919Sxy150489 static void start_watchdog_timer(struct e1000g *); 113*4919Sxy150489 static void restart_watchdog_timer(struct e1000g *); 114*4919Sxy150489 static void stop_watchdog_timer(struct e1000g *); 115*4919Sxy150489 static void stop_link_timer(struct e1000g *); 116*4919Sxy150489 static void stop_82547_timer(e1000g_tx_ring_t *); 117*4919Sxy150489 static void e1000g_force_speed_duplex(struct e1000g *); 118*4919Sxy150489 static void e1000g_get_max_frame_size(struct e1000g *); 119*4919Sxy150489 static boolean_t is_valid_mac_addr(uint8_t *); 1203526Sxy150489 static void e1000g_unattach(dev_info_t *, struct e1000g *); 121*4919Sxy150489 #ifdef E1000G_DEBUG 122*4919Sxy150489 static void e1000g_ioc_peek_reg(struct e1000g *, e1000g_peekpoke_t *); 123*4919Sxy150489 static void e1000g_ioc_poke_reg(struct e1000g *, e1000g_peekpoke_t *); 124*4919Sxy150489 static void e1000g_ioc_peek_mem(struct e1000g *, e1000g_peekpoke_t *); 125*4919Sxy150489 static void e1000g_ioc_poke_mem(struct e1000g *, e1000g_peekpoke_t *); 126*4919Sxy150489 static enum ioc_reply e1000g_pp_ioctl(struct e1000g *, 127*4919Sxy150489 struct iocblk *, mblk_t *); 128*4919Sxy150489 #endif 129*4919Sxy150489 static enum ioc_reply e1000g_loopback_ioctl(struct e1000g *, 130*4919Sxy150489 struct iocblk *, mblk_t *); 131*4919Sxy150489 static boolean_t e1000g_set_loopback_mode(struct e1000g *, uint32_t); 132*4919Sxy150489 static void e1000g_set_internal_loopback(struct e1000g *); 133*4919Sxy150489 static void e1000g_set_external_loopback_1000(struct e1000g *); 134*4919Sxy150489 static void e1000g_set_external_loopback_100(struct e1000g *); 135*4919Sxy150489 static void e1000g_set_external_loopback_10(struct e1000g *); 136*4919Sxy150489 static int e1000g_add_intrs(struct e1000g *); 137*4919Sxy150489 static int e1000g_intr_add(struct e1000g *, int); 138*4919Sxy150489 static int e1000g_rem_intrs(struct e1000g *); 139*4919Sxy150489 static int e1000g_enable_intrs(struct e1000g *); 140*4919Sxy150489 static int e1000g_disable_intrs(struct e1000g *); 141*4919Sxy150489 static boolean_t e1000g_link_up(struct e1000g *); 1423526Sxy150489 #ifdef __sparc 143*4919Sxy150489 static boolean_t e1000g_find_mac_address(struct e1000g *); 1443526Sxy150489 #endif 1453526Sxy150489 1463526Sxy150489 static struct cb_ops cb_ws_ops = { 1473526Sxy150489 nulldev, /* cb_open */ 1483526Sxy150489 nulldev, /* cb_close */ 1493526Sxy150489 nodev, /* cb_strategy */ 1503526Sxy150489 nodev, /* cb_print */ 1513526Sxy150489 nodev, /* cb_dump */ 1523526Sxy150489 nodev, /* cb_read */ 1533526Sxy150489 nodev, /* cb_write */ 1543526Sxy150489 nodev, /* cb_ioctl */ 1553526Sxy150489 nodev, /* cb_devmap */ 1563526Sxy150489 nodev, /* cb_mmap */ 1573526Sxy150489 nodev, /* cb_segmap */ 1583526Sxy150489 nochpoll, /* cb_chpoll */ 1593526Sxy150489 ddi_prop_op, /* cb_prop_op */ 1603526Sxy150489 NULL, /* cb_stream */ 1613526Sxy150489 D_MP | D_HOTPLUG, /* cb_flag */ 1623526Sxy150489 CB_REV, /* cb_rev */ 1633526Sxy150489 nodev, /* cb_aread */ 1643526Sxy150489 nodev /* cb_awrite */ 1653526Sxy150489 }; 1663526Sxy150489 1673526Sxy150489 static struct dev_ops ws_ops = { 1683526Sxy150489 DEVO_REV, /* devo_rev */ 1693526Sxy150489 0, /* devo_refcnt */ 1703526Sxy150489 NULL, /* devo_getinfo */ 1713526Sxy150489 nulldev, /* devo_identify */ 1723526Sxy150489 nulldev, /* devo_probe */ 173*4919Sxy150489 e1000g_attach, /* devo_attach */ 174*4919Sxy150489 e1000g_detach, /* devo_detach */ 1753526Sxy150489 nodev, /* devo_reset */ 1763526Sxy150489 &cb_ws_ops, /* devo_cb_ops */ 1773526Sxy150489 NULL, /* devo_bus_ops */ 1783526Sxy150489 ddi_power /* devo_power */ 1793526Sxy150489 }; 1803526Sxy150489 1813526Sxy150489 static struct modldrv modldrv = { 1823526Sxy150489 &mod_driverops, /* Type of module. This one is a driver */ 1833526Sxy150489 ident, /* Discription string */ 1843526Sxy150489 &ws_ops, /* driver ops */ 1853526Sxy150489 }; 1863526Sxy150489 1873526Sxy150489 static struct modlinkage modlinkage = { 1883526Sxy150489 MODREV_1, &modldrv, NULL 1893526Sxy150489 }; 1903526Sxy150489 191*4919Sxy150489 /* Access attributes for register mapping */ 192*4919Sxy150489 static ddi_device_acc_attr_t e1000g_regs_acc_attr = { 1933526Sxy150489 DDI_DEVICE_ATTR_V0, 1943526Sxy150489 DDI_STRUCTURE_LE_ACC, 1953526Sxy150489 DDI_STRICTORDER_ACC, 1963526Sxy150489 }; 1973526Sxy150489 1983526Sxy150489 #define E1000G_M_CALLBACK_FLAGS (MC_RESOURCES | MC_IOCTL | MC_GETCAPAB) 1993526Sxy150489 2003526Sxy150489 static mac_callbacks_t e1000g_m_callbacks = { 2013526Sxy150489 E1000G_M_CALLBACK_FLAGS, 2023526Sxy150489 e1000g_m_stat, 2033526Sxy150489 e1000g_m_start, 2043526Sxy150489 e1000g_m_stop, 2053526Sxy150489 e1000g_m_promisc, 2063526Sxy150489 e1000g_m_multicst, 2073526Sxy150489 e1000g_m_unicst, 2083526Sxy150489 e1000g_m_tx, 2093526Sxy150489 e1000g_m_resources, 2103526Sxy150489 e1000g_m_ioctl, 2113526Sxy150489 e1000g_m_getcapab 2123526Sxy150489 }; 2133526Sxy150489 2143526Sxy150489 /* 2153526Sxy150489 * Global variables 2163526Sxy150489 */ 2173526Sxy150489 uint32_t e1000g_mblks_pending = 0; 2183526Sxy150489 /* 2194894Syy150190 * Workaround for Dynamic Reconfiguration support, for x86 platform only. 2204349Sxy150489 * Here we maintain a private dev_info list if e1000g_force_detach is 2214349Sxy150489 * enabled. If we force the driver to detach while there are still some 2224349Sxy150489 * rx buffers retained in the upper layer, we have to keep a copy of the 2234349Sxy150489 * dev_info. In some cases (Dynamic Reconfiguration), the dev_info data 2244349Sxy150489 * structure will be freed after the driver is detached. However when we 2254349Sxy150489 * finally free those rx buffers released by the upper layer, we need to 2264349Sxy150489 * refer to the dev_info to free the dma buffers. So we save a copy of 2274894Syy150190 * the dev_info for this purpose. On x86 platform, we assume this copy 2284894Syy150190 * of dev_info is always valid, but on SPARC platform, it could be invalid 2294894Syy150190 * after the system board level DR operation. For this reason, the global 2304894Syy150190 * variable e1000g_force_detach must be B_FALSE on SPARC platform. 2314349Sxy150489 */ 2324894Syy150190 #ifdef __sparc 2334894Syy150190 boolean_t e1000g_force_detach = B_FALSE; 2344894Syy150190 #else 2354894Syy150190 boolean_t e1000g_force_detach = B_TRUE; 2364894Syy150190 #endif 2374349Sxy150489 private_devi_list_t *e1000g_private_devi_list = NULL; 2384894Syy150190 2394349Sxy150489 /* 2403526Sxy150489 * The rwlock is defined to protect the whole processing of rx recycling 2413526Sxy150489 * and the rx packets release in detach processing to make them mutually 2423526Sxy150489 * exclusive. 2433526Sxy150489 * The rx recycling processes different rx packets in different threads, 2443526Sxy150489 * so it will be protected with RW_READER and it won't block any other rx 2453526Sxy150489 * recycling threads. 2463526Sxy150489 * While the detach processing will be protected with RW_WRITER to make 2473526Sxy150489 * it mutually exclusive with the rx recycling. 2483526Sxy150489 */ 2493526Sxy150489 krwlock_t e1000g_rx_detach_lock; 2503526Sxy150489 /* 2513526Sxy150489 * The rwlock e1000g_dma_type_lock is defined to protect the global flag 2523526Sxy150489 * e1000g_dma_type. For SPARC, the initial value of the flag is "USE_DVMA". 2533526Sxy150489 * If there are many e1000g instances, the system may run out of DVMA 2543526Sxy150489 * resources during the initialization of the instances, then the flag will 2553526Sxy150489 * be changed to "USE_DMA". Because different e1000g instances are initialized 2563526Sxy150489 * in parallel, we need to use this lock to protect the flag. 2573526Sxy150489 */ 2583526Sxy150489 krwlock_t e1000g_dma_type_lock; 2593526Sxy150489 2603526Sxy150489 2613526Sxy150489 /* 2623526Sxy150489 * Loadable module configuration entry points for the driver 2633526Sxy150489 */ 2643526Sxy150489 2653526Sxy150489 /* 266*4919Sxy150489 * _init - module initialization 2673526Sxy150489 */ 2683526Sxy150489 int 2693526Sxy150489 _init(void) 2703526Sxy150489 { 2713526Sxy150489 int status; 2723526Sxy150489 2733526Sxy150489 mac_init_ops(&ws_ops, WSNAME); 2743526Sxy150489 status = mod_install(&modlinkage); 2753526Sxy150489 if (status != DDI_SUCCESS) 2763526Sxy150489 mac_fini_ops(&ws_ops); 2773526Sxy150489 else { 2783526Sxy150489 rw_init(&e1000g_rx_detach_lock, NULL, RW_DRIVER, NULL); 2793526Sxy150489 rw_init(&e1000g_dma_type_lock, NULL, RW_DRIVER, NULL); 2803526Sxy150489 } 2813526Sxy150489 2823526Sxy150489 return (status); 2833526Sxy150489 } 2843526Sxy150489 2853526Sxy150489 /* 286*4919Sxy150489 * _fini - module finalization 2873526Sxy150489 */ 2883526Sxy150489 int 2893526Sxy150489 _fini(void) 2903526Sxy150489 { 2913526Sxy150489 int status; 2923526Sxy150489 2933526Sxy150489 rw_enter(&e1000g_rx_detach_lock, RW_READER); 2943526Sxy150489 if (e1000g_mblks_pending != 0) { 2953526Sxy150489 rw_exit(&e1000g_rx_detach_lock); 2963526Sxy150489 return (EBUSY); 2973526Sxy150489 } 2983526Sxy150489 rw_exit(&e1000g_rx_detach_lock); 2993526Sxy150489 3003526Sxy150489 status = mod_remove(&modlinkage); 3013526Sxy150489 if (status == DDI_SUCCESS) { 3023526Sxy150489 mac_fini_ops(&ws_ops); 3034349Sxy150489 3044349Sxy150489 if (e1000g_force_detach) { 3054349Sxy150489 private_devi_list_t *devi_node; 3064349Sxy150489 3074349Sxy150489 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 3084349Sxy150489 while (e1000g_private_devi_list != NULL) { 3094349Sxy150489 devi_node = e1000g_private_devi_list; 3104349Sxy150489 e1000g_private_devi_list = 3114349Sxy150489 e1000g_private_devi_list->next; 3124349Sxy150489 3134349Sxy150489 kmem_free(devi_node->priv_dip, 3144349Sxy150489 sizeof (struct dev_info)); 3154349Sxy150489 kmem_free(devi_node, 3164349Sxy150489 sizeof (private_devi_list_t)); 3174349Sxy150489 } 3184349Sxy150489 rw_exit(&e1000g_rx_detach_lock); 3194349Sxy150489 } 3204349Sxy150489 3213526Sxy150489 rw_destroy(&e1000g_rx_detach_lock); 3223526Sxy150489 rw_destroy(&e1000g_dma_type_lock); 3233526Sxy150489 } 3243526Sxy150489 3253526Sxy150489 return (status); 3263526Sxy150489 } 3273526Sxy150489 3283526Sxy150489 /* 329*4919Sxy150489 * _info - module information 3303526Sxy150489 */ 3313526Sxy150489 int 3323526Sxy150489 _info(struct modinfo *modinfop) 3333526Sxy150489 { 3343526Sxy150489 return (mod_info(&modlinkage, modinfop)); 3353526Sxy150489 } 3363526Sxy150489 3373526Sxy150489 /* 338*4919Sxy150489 * e1000g_attach - driver attach 339*4919Sxy150489 * 340*4919Sxy150489 * This function is the device-specific initialization entry 341*4919Sxy150489 * point. This entry point is required and must be written. 342*4919Sxy150489 * The DDI_ATTACH command must be provided in the attach entry 343*4919Sxy150489 * point. When attach() is called with cmd set to DDI_ATTACH, 344*4919Sxy150489 * all normal kernel services (such as kmem_alloc(9F)) are 345*4919Sxy150489 * available for use by the driver. 346*4919Sxy150489 * 347*4919Sxy150489 * The attach() function will be called once for each instance 348*4919Sxy150489 * of the device on the system with cmd set to DDI_ATTACH. 349*4919Sxy150489 * Until attach() succeeds, the only driver entry points which 350*4919Sxy150489 * may be called are open(9E) and getinfo(9E). 3513526Sxy150489 */ 3523526Sxy150489 static int 353*4919Sxy150489 e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) 3543526Sxy150489 { 3553526Sxy150489 struct e1000g *Adapter; 3563526Sxy150489 struct e1000_hw *hw; 357*4919Sxy150489 struct e1000g_osdep *osdep; 3583526Sxy150489 int instance; 3593526Sxy150489 3603526Sxy150489 switch (cmd) { 3613526Sxy150489 default: 3623526Sxy150489 e1000g_log(NULL, CE_WARN, 363*4919Sxy150489 "Unsupported command send to e1000g_attach... "); 3643526Sxy150489 return (DDI_FAILURE); 3653526Sxy150489 3663526Sxy150489 case DDI_RESUME: 3673526Sxy150489 return (e1000g_resume(devinfo)); 3683526Sxy150489 3693526Sxy150489 case DDI_ATTACH: 3703526Sxy150489 break; 3713526Sxy150489 } 3723526Sxy150489 3733526Sxy150489 /* 3743526Sxy150489 * get device instance number 3753526Sxy150489 */ 3763526Sxy150489 instance = ddi_get_instance(devinfo); 3773526Sxy150489 3783526Sxy150489 /* 3793526Sxy150489 * Allocate soft data structure 3803526Sxy150489 */ 3813526Sxy150489 Adapter = 3823526Sxy150489 (struct e1000g *)kmem_zalloc(sizeof (*Adapter), KM_SLEEP); 3833526Sxy150489 3843526Sxy150489 Adapter->dip = devinfo; 385*4919Sxy150489 Adapter->instance = instance; 3863526Sxy150489 Adapter->tx_ring->adapter = Adapter; 3873526Sxy150489 Adapter->rx_ring->adapter = Adapter; 3883526Sxy150489 389*4919Sxy150489 hw = &Adapter->shared; 390*4919Sxy150489 osdep = &Adapter->osdep; 391*4919Sxy150489 hw->back = osdep; 392*4919Sxy150489 osdep->adapter = Adapter; 393*4919Sxy150489 3943526Sxy150489 ddi_set_driver_private(devinfo, (caddr_t)Adapter); 3953526Sxy150489 3964349Sxy150489 if (e1000g_force_detach) { 3974349Sxy150489 private_devi_list_t *devi_node; 3984894Syy150190 3994894Syy150190 Adapter->priv_dip = 4004894Syy150190 kmem_zalloc(sizeof (struct dev_info), KM_SLEEP); 4014894Syy150190 bcopy(DEVI(devinfo), DEVI(Adapter->priv_dip), 4024894Syy150190 sizeof (struct dev_info)); 4034894Syy150190 4044894Syy150190 devi_node = 4054894Syy150190 kmem_zalloc(sizeof (private_devi_list_t), KM_SLEEP); 4064894Syy150190 4074894Syy150190 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 4084894Syy150190 devi_node->dip = devinfo; 4094894Syy150190 devi_node->priv_dip = Adapter->priv_dip; 4104894Syy150190 devi_node->next = e1000g_private_devi_list; 4114894Syy150190 e1000g_private_devi_list = devi_node; 4124894Syy150190 rw_exit(&e1000g_rx_detach_lock); 4134349Sxy150489 } 4144349Sxy150489 415*4919Sxy150489 /* 416*4919Sxy150489 * PCI Configure 417*4919Sxy150489 */ 418*4919Sxy150489 if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) { 419*4919Sxy150489 e1000g_log(Adapter, CE_WARN, "PCI configuration failed"); 420*4919Sxy150489 goto attach_fail; 421*4919Sxy150489 } 422*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG; 423*4919Sxy150489 424*4919Sxy150489 /* 425*4919Sxy150489 * Setup hardware 426*4919Sxy150489 */ 427*4919Sxy150489 if (e1000g_identify_hardware(Adapter) != DDI_SUCCESS) { 428*4919Sxy150489 e1000g_log(Adapter, CE_WARN, "Identify hardware failed"); 429*4919Sxy150489 goto attach_fail; 430*4919Sxy150489 } 4313526Sxy150489 4323526Sxy150489 /* 4333526Sxy150489 * Map in the device registers. 4343526Sxy150489 */ 435*4919Sxy150489 if (e1000g_regs_map(Adapter) != DDI_SUCCESS) { 436*4919Sxy150489 e1000g_log(Adapter, CE_WARN, "Mapping registers failed"); 4373526Sxy150489 goto attach_fail; 4383526Sxy150489 } 439*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_REGS_MAP; 4403526Sxy150489 4413526Sxy150489 /* 4423526Sxy150489 * Initialize driver parameters 4433526Sxy150489 */ 4443526Sxy150489 if (e1000g_set_driver_params(Adapter) != DDI_SUCCESS) { 4453526Sxy150489 goto attach_fail; 4463526Sxy150489 } 447*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_SETUP; 4483526Sxy150489 4493526Sxy150489 /* 4503526Sxy150489 * Initialize interrupts 4513526Sxy150489 */ 4523526Sxy150489 if (e1000g_add_intrs(Adapter) != DDI_SUCCESS) { 4533526Sxy150489 e1000g_log(Adapter, CE_WARN, "Add interrupts failed"); 4543526Sxy150489 goto attach_fail; 4553526Sxy150489 } 456*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ADD_INTR; 4573526Sxy150489 4583526Sxy150489 /* 4593526Sxy150489 * Initialize mutex's for this device. 4603526Sxy150489 * Do this before enabling the interrupt handler and 4613526Sxy150489 * register the softint to avoid the condition where 4623526Sxy150489 * interrupt handler can try using uninitialized mutex 4633526Sxy150489 */ 4643526Sxy150489 e1000g_init_locks(Adapter); 4653526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_LOCKS; 4663526Sxy150489 467*4919Sxy150489 Adapter->tx_softint_pri = DDI_INTR_SOFTPRI_MAX; 4683526Sxy150489 if (ddi_intr_add_softint(devinfo, 4693526Sxy150489 &Adapter->tx_softint_handle, Adapter->tx_softint_pri, 470*4919Sxy150489 e1000g_tx_softint_worker, (caddr_t)Adapter) != DDI_SUCCESS) { 4713526Sxy150489 e1000g_log(Adapter, CE_WARN, "Add soft intr failed"); 4723526Sxy150489 goto attach_fail; 4733526Sxy150489 } 474*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_SOFT_INTR; 4753526Sxy150489 4763526Sxy150489 /* 4773526Sxy150489 * Initialize Driver Counters 4783526Sxy150489 */ 479*4919Sxy150489 if (e1000g_init_stats(Adapter) != DDI_SUCCESS) { 4803526Sxy150489 e1000g_log(Adapter, CE_WARN, "Init stats failed"); 4813526Sxy150489 goto attach_fail; 4823526Sxy150489 } 4833526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_KSTATS; 4843526Sxy150489 4853526Sxy150489 /* 4863526Sxy150489 * Initialize chip hardware and software structures 4873526Sxy150489 */ 4883526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) { 4893526Sxy150489 e1000g_log(Adapter, CE_WARN, "Adapter initialization failed"); 4903526Sxy150489 goto attach_fail; 4913526Sxy150489 } 4923526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 4933526Sxy150489 4943526Sxy150489 /* 4953526Sxy150489 * Initialize NDD parameters 4963526Sxy150489 */ 4973526Sxy150489 if (e1000g_nd_init(Adapter) != DDI_SUCCESS) { 498*4919Sxy150489 e1000g_log(Adapter, CE_WARN, "Init ndd failed"); 4993526Sxy150489 goto attach_fail; 5003526Sxy150489 } 5013526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_NDD; 5023526Sxy150489 5033526Sxy150489 /* 5043526Sxy150489 * Register the driver to the MAC 5053526Sxy150489 */ 5063526Sxy150489 if (e1000g_register_mac(Adapter) != DDI_SUCCESS) { 5073526Sxy150489 e1000g_log(Adapter, CE_WARN, "Register MAC failed"); 5083526Sxy150489 goto attach_fail; 5093526Sxy150489 } 510*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_MAC; 5113526Sxy150489 5123526Sxy150489 /* 5133526Sxy150489 * Now that mutex locks are initialized, and the chip is also 5143526Sxy150489 * initialized, enable interrupts. 5153526Sxy150489 */ 5163526Sxy150489 if (e1000g_enable_intrs(Adapter) != DDI_SUCCESS) { 5173526Sxy150489 e1000g_log(Adapter, CE_WARN, "Enable DDI interrupts failed"); 5183526Sxy150489 goto attach_fail; 5193526Sxy150489 } 520*4919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR; 5213526Sxy150489 5223526Sxy150489 cmn_err(CE_CONT, "!%s, %s\n", e1000g_string, e1000g_version); 5233526Sxy150489 5243526Sxy150489 return (DDI_SUCCESS); 5253526Sxy150489 5263526Sxy150489 attach_fail: 5273526Sxy150489 e1000g_unattach(devinfo, Adapter); 5283526Sxy150489 return (DDI_FAILURE); 5293526Sxy150489 } 5303526Sxy150489 5313526Sxy150489 static int 5323526Sxy150489 e1000g_register_mac(struct e1000g *Adapter) 5333526Sxy150489 { 534*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 5353526Sxy150489 mac_register_t *mac; 5363526Sxy150489 int err; 5373526Sxy150489 5383526Sxy150489 if ((mac = mac_alloc(MAC_VERSION)) == NULL) 5393526Sxy150489 return (DDI_FAILURE); 540*4919Sxy150489 5413526Sxy150489 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 5423526Sxy150489 mac->m_driver = Adapter; 5433526Sxy150489 mac->m_dip = Adapter->dip; 544*4919Sxy150489 mac->m_src_addr = hw->mac.addr; 5453526Sxy150489 mac->m_callbacks = &e1000g_m_callbacks; 5463526Sxy150489 mac->m_min_sdu = 0; 5473526Sxy150489 mac->m_max_sdu = 548*4919Sxy150489 (hw->mac.max_frame_size > FRAME_SIZE_UPTO_8K) ? 549*4919Sxy150489 hw->mac.max_frame_size - 256 : 550*4919Sxy150489 (hw->mac.max_frame_size != ETHERMAX) ? 551*4919Sxy150489 hw->mac.max_frame_size - 24 : ETHERMTU; 552*4919Sxy150489 5533526Sxy150489 err = mac_register(mac, &Adapter->mh); 5543526Sxy150489 mac_free(mac); 555*4919Sxy150489 5563526Sxy150489 return (err == 0 ? DDI_SUCCESS : DDI_FAILURE); 5573526Sxy150489 } 5583526Sxy150489 5593526Sxy150489 static int 560*4919Sxy150489 e1000g_identify_hardware(struct e1000g *Adapter) 561*4919Sxy150489 { 562*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 563*4919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep; 564*4919Sxy150489 565*4919Sxy150489 /* Get the device id */ 566*4919Sxy150489 hw->vendor_id = 567*4919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID); 568*4919Sxy150489 hw->device_id = 569*4919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID); 570*4919Sxy150489 hw->revision_id = 571*4919Sxy150489 pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID); 572*4919Sxy150489 hw->subsystem_device_id = 573*4919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID); 574*4919Sxy150489 hw->subsystem_vendor_id = 575*4919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID); 576*4919Sxy150489 577*4919Sxy150489 if (e1000_set_mac_type(hw) != E1000_SUCCESS) { 578*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 579*4919Sxy150489 "MAC type could not be set properly."); 580*4919Sxy150489 return (DDI_FAILURE); 581*4919Sxy150489 } 582*4919Sxy150489 583*4919Sxy150489 return (DDI_SUCCESS); 584*4919Sxy150489 } 585*4919Sxy150489 586*4919Sxy150489 static int 587*4919Sxy150489 e1000g_regs_map(struct e1000g *Adapter) 588*4919Sxy150489 { 589*4919Sxy150489 dev_info_t *devinfo = Adapter->dip; 590*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 591*4919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep; 592*4919Sxy150489 off_t mem_size; 593*4919Sxy150489 594*4919Sxy150489 /* 595*4919Sxy150489 * first get the size of device register to be mapped. The 596*4919Sxy150489 * second parameter is the register we are interested. I our 597*4919Sxy150489 * wiseman 0 is for config registers and 1 is for memory mapped 598*4919Sxy150489 * registers Mem size should have memory mapped region size 599*4919Sxy150489 */ 600*4919Sxy150489 if (ddi_dev_regsize(devinfo, 1, &mem_size) != DDI_SUCCESS) { 601*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 602*4919Sxy150489 "ddi_dev_regsize for registers failed"); 603*4919Sxy150489 return (DDI_FAILURE); 604*4919Sxy150489 } 605*4919Sxy150489 606*4919Sxy150489 if ((ddi_regs_map_setup(devinfo, 1, /* register of interest */ 607*4919Sxy150489 (caddr_t *)&hw->hw_addr, 0, mem_size, &e1000g_regs_acc_attr, 608*4919Sxy150489 &osdep->reg_handle)) != DDI_SUCCESS) { 609*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 610*4919Sxy150489 "ddi_regs_map_setup for registers failed"); 611*4919Sxy150489 goto regs_map_fail; 612*4919Sxy150489 } 613*4919Sxy150489 614*4919Sxy150489 /* ICH needs to map flash memory */ 615*4919Sxy150489 if (hw->mac.type == e1000_ich8lan || hw->mac.type == e1000_ich9lan) { 616*4919Sxy150489 /* get flash size */ 617*4919Sxy150489 if (ddi_dev_regsize(devinfo, ICH_FLASH_REG_SET, 618*4919Sxy150489 &mem_size) != DDI_SUCCESS) { 619*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 620*4919Sxy150489 "ddi_dev_regsize for ICH flash failed"); 621*4919Sxy150489 goto regs_map_fail; 622*4919Sxy150489 } 623*4919Sxy150489 624*4919Sxy150489 /* map flash in */ 625*4919Sxy150489 if (ddi_regs_map_setup(devinfo, ICH_FLASH_REG_SET, 626*4919Sxy150489 (caddr_t *)&hw->flash_address, 0, 627*4919Sxy150489 mem_size, &e1000g_regs_acc_attr, 628*4919Sxy150489 &osdep->ich_flash_handle) != DDI_SUCCESS) { 629*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 630*4919Sxy150489 "ddi_regs_map_setup for ICH flash failed"); 631*4919Sxy150489 goto regs_map_fail; 632*4919Sxy150489 } 633*4919Sxy150489 } 634*4919Sxy150489 635*4919Sxy150489 return (DDI_SUCCESS); 636*4919Sxy150489 637*4919Sxy150489 regs_map_fail: 638*4919Sxy150489 if (osdep->reg_handle != NULL) 639*4919Sxy150489 ddi_regs_map_free(&osdep->reg_handle); 640*4919Sxy150489 641*4919Sxy150489 return (DDI_FAILURE); 642*4919Sxy150489 } 643*4919Sxy150489 644*4919Sxy150489 static int 6453526Sxy150489 e1000g_set_driver_params(struct e1000g *Adapter) 6463526Sxy150489 { 6473526Sxy150489 struct e1000_hw *hw; 648*4919Sxy150489 e1000g_tx_ring_t *tx_ring; 649*4919Sxy150489 uint32_t mem_bar, io_bar, bar64; 6503526Sxy150489 #ifdef __sparc 651*4919Sxy150489 dev_info_t *devinfo = Adapter->dip; 6523526Sxy150489 ulong_t iommu_pagesize; 6533526Sxy150489 #endif 6543526Sxy150489 655*4919Sxy150489 hw = &Adapter->shared; 656*4919Sxy150489 657*4919Sxy150489 /* Set MAC type and initialize hardware functions */ 658*4919Sxy150489 if (e1000_setup_init_funcs(hw, B_TRUE) != E1000_SUCCESS) { 659*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 660*4919Sxy150489 "Could not setup hardware functions"); 6613526Sxy150489 return (DDI_FAILURE); 6623526Sxy150489 } 6633526Sxy150489 664*4919Sxy150489 /* Get bus information */ 665*4919Sxy150489 if (e1000_get_bus_info(hw) != E1000_SUCCESS) { 666*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN, 667*4919Sxy150489 "Could not get bus information"); 668*4919Sxy150489 return (DDI_FAILURE); 6693526Sxy150489 } 6703526Sxy150489 6713526Sxy150489 /* get mem_base addr */ 672*4919Sxy150489 mem_bar = pci_config_get32(Adapter->osdep.cfg_handle, PCI_CONF_BASE0); 673*4919Sxy150489 bar64 = mem_bar & PCI_BASE_TYPE_ALL; 6743526Sxy150489 6753526Sxy150489 /* get io_base addr */ 676*4919Sxy150489 if (hw->mac.type >= e1000_82544) { 677*4919Sxy150489 if (bar64) { 6783526Sxy150489 /* IO BAR is different for 64 bit BAR mode */ 679*4919Sxy150489 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 680*4919Sxy150489 PCI_CONF_BASE4); 6813526Sxy150489 } else { 6823526Sxy150489 /* normal 32-bit BAR mode */ 683*4919Sxy150489 io_bar = pci_config_get32(Adapter->osdep.cfg_handle, 684*4919Sxy150489 PCI_CONF_BASE2); 6853526Sxy150489 } 6863526Sxy150489 hw->io_base = io_bar & PCI_BASE_IO_ADDR_M; 6873526Sxy150489 } else { 6883526Sxy150489 /* no I/O access for adapters prior to 82544 */ 6893526Sxy150489 hw->io_base = 0x0; 6903526Sxy150489 } 6913526Sxy150489 692*4919Sxy150489 e1000_read_pci_cfg(hw, PCI_COMMAND_REGISTER, &hw->bus.pci_cmd_word); 693*4919Sxy150489 694*4919Sxy150489 hw->mac.autoneg_failed = B_TRUE; 695*4919Sxy150489 696*4919Sxy150489 /* Set the wait_for_link flag to B_FALSE */ 697*4919Sxy150489 hw->phy.wait_for_link = B_FALSE; 6983526Sxy150489 6993526Sxy150489 /* Adaptive IFS related changes */ 700*4919Sxy150489 hw->mac.adaptive_ifs = B_TRUE; 701*4919Sxy150489 702*4919Sxy150489 /* Enable phy init script for IGP phy of 82541/82547 */ 703*4919Sxy150489 if ((hw->mac.type == e1000_82547) || 704*4919Sxy150489 (hw->mac.type == e1000_82541) || 705*4919Sxy150489 (hw->mac.type == e1000_82547_rev_2) || 706*4919Sxy150489 (hw->mac.type == e1000_82541_rev_2)) 707*4919Sxy150489 e1000_init_script_state_82541(hw, B_TRUE); 708*4919Sxy150489 709*4919Sxy150489 /* Enable the TTL workaround for 82541/82547 */ 710*4919Sxy150489 e1000_set_ttl_workaround_state_82541(hw, B_TRUE); 7113526Sxy150489 7124608Syy150190 #ifdef __sparc 7134608Syy150190 Adapter->strip_crc = B_TRUE; 7144608Syy150190 #else 7154608Syy150190 Adapter->strip_crc = B_FALSE; 7164608Syy150190 #endif 7174608Syy150190 7183526Sxy150489 /* Get conf file properties */ 719*4919Sxy150489 e1000g_get_conf(Adapter); 720*4919Sxy150489 721*4919Sxy150489 /* Get speed/duplex settings in conf file */ 722*4919Sxy150489 hw->mac.forced_speed_duplex = ADVERTISE_100_FULL; 723*4919Sxy150489 hw->phy.autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; 7243526Sxy150489 e1000g_force_speed_duplex(Adapter); 7253526Sxy150489 726*4919Sxy150489 /* Get Jumbo Frames settings in conf file */ 7273526Sxy150489 e1000g_get_max_frame_size(Adapter); 728*4919Sxy150489 hw->mac.min_frame_size = 7293526Sxy150489 MINIMUM_ETHERNET_PACKET_SIZE + CRC_LENGTH; 7303526Sxy150489 7313526Sxy150489 #ifdef __sparc 7323526Sxy150489 /* Get the system page size */ 7333526Sxy150489 Adapter->sys_page_sz = ddi_ptob(devinfo, (ulong_t)1); 7343526Sxy150489 iommu_pagesize = dvma_pagesize(devinfo); 7353526Sxy150489 if (iommu_pagesize != 0) { 7363526Sxy150489 if (Adapter->sys_page_sz == iommu_pagesize) { 7373526Sxy150489 if (iommu_pagesize > 0x4000) 7383526Sxy150489 Adapter->sys_page_sz = 0x4000; 7393526Sxy150489 } else { 7403526Sxy150489 if (Adapter->sys_page_sz > iommu_pagesize) 7413526Sxy150489 Adapter->sys_page_sz = iommu_pagesize; 7423526Sxy150489 } 7433526Sxy150489 } 744*4919Sxy150489 Adapter->dvma_page_num = hw->mac.max_frame_size / 7453526Sxy150489 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM; 7463526Sxy150489 ASSERT(Adapter->dvma_page_num >= E1000G_DEFAULT_DVMA_PAGE_NUM); 7473526Sxy150489 #endif 7483526Sxy150489 7493526Sxy150489 /* Set Rx/Tx buffer size */ 750*4919Sxy150489 switch (hw->mac.max_frame_size) { 7513526Sxy150489 case ETHERMAX: 752*4919Sxy150489 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K; 753*4919Sxy150489 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K; 7543526Sxy150489 break; 7553526Sxy150489 case FRAME_SIZE_UPTO_4K: 756*4919Sxy150489 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_4K; 757*4919Sxy150489 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_4K; 7583526Sxy150489 break; 7593526Sxy150489 case FRAME_SIZE_UPTO_8K: 760*4919Sxy150489 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_8K; 761*4919Sxy150489 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_8K; 7623526Sxy150489 break; 763*4919Sxy150489 case FRAME_SIZE_UPTO_9K: 7643526Sxy150489 case FRAME_SIZE_UPTO_16K: 765*4919Sxy150489 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_16K; 766*4919Sxy150489 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_16K; 7673526Sxy150489 break; 7683526Sxy150489 default: 769*4919Sxy150489 Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K; 770*4919Sxy150489 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K; 7713526Sxy150489 break; 7723526Sxy150489 } 773*4919Sxy150489 Adapter->rx_buffer_size += E1000G_IPALIGNPRESERVEROOM; 774*4919Sxy150489 775*4919Sxy150489 #ifndef NO_82542_SUPPORT 7763526Sxy150489 /* 7773526Sxy150489 * For Wiseman adapters we have an requirement of having receive 7783526Sxy150489 * buffers aligned at 256 byte boundary. Since Livengood does not 7793526Sxy150489 * require this and forcing it for all hardwares will have 7803526Sxy150489 * performance implications, I am making it applicable only for 7813526Sxy150489 * Wiseman and for Jumbo frames enabled mode as rest of the time, 7823526Sxy150489 * it is okay to have normal frames...but it does involve a 7833526Sxy150489 * potential risk where we may loose data if buffer is not 7843526Sxy150489 * aligned...so all wiseman boards to have 256 byte aligned 7853526Sxy150489 * buffers 7863526Sxy150489 */ 787*4919Sxy150489 if (hw->mac.type < e1000_82543) 788*4919Sxy150489 Adapter->rx_buf_align = RECEIVE_BUFFER_ALIGN_SIZE; 7893526Sxy150489 else 790*4919Sxy150489 Adapter->rx_buf_align = 1; 791*4919Sxy150489 #endif 792*4919Sxy150489 793*4919Sxy150489 /* Master Latency Timer */ 794*4919Sxy150489 Adapter->master_latency_timer = DEFAULT_MASTER_LATENCY_TIMER; 795*4919Sxy150489 7963526Sxy150489 /* copper options */ 7973526Sxy150489 if (hw->media_type == e1000_media_type_copper) { 798*4919Sxy150489 hw->phy.mdix = 0; /* AUTO_ALL_MODES */ 799*4919Sxy150489 hw->phy.disable_polarity_correction = B_FALSE; 800*4919Sxy150489 hw->phy.ms_type = e1000_ms_hw_default; /* E1000_MASTER_SLAVE */ 8013526Sxy150489 } 8023526Sxy150489 803*4919Sxy150489 /* The initial link state should be "unknown" */ 8044061Sxy150489 Adapter->link_state = LINK_STATE_UNKNOWN; 8054061Sxy150489 806*4919Sxy150489 /* Initialize tx parameters */ 807*4919Sxy150489 Adapter->tx_intr_enable = DEFAULT_TX_INTR_ENABLE; 808*4919Sxy150489 Adapter->tx_bcopy_thresh = DEFAULT_TX_BCOPY_THRESHOLD; 809*4919Sxy150489 810*4919Sxy150489 tx_ring = Adapter->tx_ring; 811*4919Sxy150489 tx_ring->recycle_low_water = DEFAULT_TX_RECYCLE_LOW_WATER; 812*4919Sxy150489 tx_ring->recycle_num = DEFAULT_TX_RECYCLE_NUM; 813*4919Sxy150489 tx_ring->frags_limit = 814*4919Sxy150489 (hw->mac.max_frame_size / Adapter->tx_bcopy_thresh) + 2; 815*4919Sxy150489 if (tx_ring->frags_limit > (MAX_TX_DESC_PER_PACKET >> 1)) 816*4919Sxy150489 tx_ring->frags_limit = (MAX_TX_DESC_PER_PACKET >> 1); 817*4919Sxy150489 818*4919Sxy150489 /* Initialize rx parameters */ 819*4919Sxy150489 Adapter->rx_bcopy_thresh = DEFAULT_RX_BCOPY_THRESHOLD; 820*4919Sxy150489 8213526Sxy150489 return (DDI_SUCCESS); 8223526Sxy150489 } 8233526Sxy150489 8243526Sxy150489 /* 825*4919Sxy150489 * e1000g_detach - driver detach 826*4919Sxy150489 * 827*4919Sxy150489 * The detach() function is the complement of the attach routine. 828*4919Sxy150489 * If cmd is set to DDI_DETACH, detach() is used to remove the 829*4919Sxy150489 * state associated with a given instance of a device node 830*4919Sxy150489 * prior to the removal of that instance from the system. 831*4919Sxy150489 * 832*4919Sxy150489 * The detach() function will be called once for each instance 833*4919Sxy150489 * of the device for which there has been a successful attach() 834*4919Sxy150489 * once there are no longer any opens on the device. 835*4919Sxy150489 * 836*4919Sxy150489 * Interrupts routine are disabled, All memory allocated by this 837*4919Sxy150489 * driver are freed. 8383526Sxy150489 */ 8393526Sxy150489 static int 840*4919Sxy150489 e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd) 8413526Sxy150489 { 8423526Sxy150489 struct e1000g *Adapter; 8433526Sxy150489 8443526Sxy150489 switch (cmd) { 8453526Sxy150489 default: 8463526Sxy150489 return (DDI_FAILURE); 8473526Sxy150489 8483526Sxy150489 case DDI_SUSPEND: 8493526Sxy150489 return (e1000g_suspend(devinfo)); 8503526Sxy150489 8513526Sxy150489 case DDI_DETACH: 8523526Sxy150489 break; 8533526Sxy150489 } 8543526Sxy150489 8553526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 8563526Sxy150489 if (Adapter == NULL) 8573526Sxy150489 return (DDI_FAILURE); 8583526Sxy150489 859*4919Sxy150489 if (mac_unregister(Adapter->mh) != 0) { 860*4919Sxy150489 e1000g_log(Adapter, CE_WARN, "Unregister MAC failed"); 861*4919Sxy150489 return (DDI_FAILURE); 862*4919Sxy150489 } 863*4919Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_MAC; 864*4919Sxy150489 8653526Sxy150489 if (Adapter->started) 866*4919Sxy150489 e1000g_stop(Adapter, B_TRUE); 8673526Sxy150489 8683526Sxy150489 if (!e1000g_rx_drain(Adapter)) { 8694349Sxy150489 if (!e1000g_force_detach) 8703526Sxy150489 return (DDI_FAILURE); 8713526Sxy150489 } 8723526Sxy150489 8733526Sxy150489 e1000g_unattach(devinfo, Adapter); 8743526Sxy150489 8753526Sxy150489 return (DDI_SUCCESS); 8763526Sxy150489 } 8773526Sxy150489 8783526Sxy150489 static void 8793526Sxy150489 e1000g_unattach(dev_info_t *devinfo, struct e1000g *Adapter) 8803526Sxy150489 { 881*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) { 8823526Sxy150489 (void) e1000g_disable_intrs(Adapter); 8833526Sxy150489 } 8843526Sxy150489 885*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_MAC) { 8863526Sxy150489 (void) mac_unregister(Adapter->mh); 8873526Sxy150489 } 8883526Sxy150489 8893526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_NDD) { 8903526Sxy150489 e1000g_nd_cleanup(Adapter); 8913526Sxy150489 } 8923526Sxy150489 893*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ADD_INTR) { 8943526Sxy150489 (void) e1000g_rem_intrs(Adapter); 8953526Sxy150489 } 8963526Sxy150489 897*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_SOFT_INTR) { 8983526Sxy150489 (void) ddi_intr_remove_softint(Adapter->tx_softint_handle); 8993526Sxy150489 } 9003526Sxy150489 901*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_SETUP) { 9023526Sxy150489 (void) ddi_prop_remove_all(devinfo); 9033526Sxy150489 } 9043526Sxy150489 9053526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_KSTATS) { 9063526Sxy150489 kstat_delete((kstat_t *)Adapter->e1000g_ksp); 9073526Sxy150489 } 9083526Sxy150489 9093526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_INIT) { 910*4919Sxy150489 stop_link_timer(Adapter); 911*4919Sxy150489 e1000_reset_hw(&Adapter->shared); 9123526Sxy150489 } 9133526Sxy150489 914*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_REGS_MAP) { 915*4919Sxy150489 if (Adapter->osdep.reg_handle != NULL) 916*4919Sxy150489 ddi_regs_map_free(&Adapter->osdep.reg_handle); 917*4919Sxy150489 if (Adapter->osdep.ich_flash_handle != NULL) 918*4919Sxy150489 ddi_regs_map_free(&Adapter->osdep.ich_flash_handle); 9193526Sxy150489 } 9203526Sxy150489 921*4919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) { 922*4919Sxy150489 if (Adapter->osdep.cfg_handle != NULL) 923*4919Sxy150489 pci_config_teardown(&Adapter->osdep.cfg_handle); 9243526Sxy150489 } 9253526Sxy150489 9263526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_LOCKS) { 9273526Sxy150489 e1000g_destroy_locks(Adapter); 9283526Sxy150489 } 9293526Sxy150489 930*4919Sxy150489 e1000_remove_device(&Adapter->shared); 931*4919Sxy150489 9323526Sxy150489 kmem_free((caddr_t)Adapter, sizeof (struct e1000g)); 9333526Sxy150489 9343526Sxy150489 /* 9353526Sxy150489 * Another hotplug spec requirement, 9363526Sxy150489 * run ddi_set_driver_private(devinfo, null); 9373526Sxy150489 */ 9383526Sxy150489 ddi_set_driver_private(devinfo, NULL); 9393526Sxy150489 } 9403526Sxy150489 9413526Sxy150489 static void 9423526Sxy150489 e1000g_init_locks(struct e1000g *Adapter) 9433526Sxy150489 { 9443526Sxy150489 e1000g_tx_ring_t *tx_ring; 9453526Sxy150489 e1000g_rx_ring_t *rx_ring; 9463526Sxy150489 9473526Sxy150489 rw_init(&Adapter->chip_lock, NULL, 9483526Sxy150489 RW_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 949*4919Sxy150489 mutex_init(&Adapter->link_lock, NULL, 9503526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 951*4919Sxy150489 mutex_init(&Adapter->watchdog_lock, NULL, 9523526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9533526Sxy150489 9543526Sxy150489 tx_ring = Adapter->tx_ring; 9553526Sxy150489 9563526Sxy150489 mutex_init(&tx_ring->tx_lock, NULL, 9573526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9583526Sxy150489 mutex_init(&tx_ring->usedlist_lock, NULL, 9593526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9603526Sxy150489 mutex_init(&tx_ring->freelist_lock, NULL, 9613526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 962*4919Sxy150489 mutex_init(&tx_ring->mblks_lock, NULL, 963*4919Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9643526Sxy150489 9653526Sxy150489 rx_ring = Adapter->rx_ring; 9663526Sxy150489 9673526Sxy150489 mutex_init(&rx_ring->rx_lock, NULL, 9683526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9693526Sxy150489 mutex_init(&rx_ring->freelist_lock, NULL, 9703526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri)); 9713526Sxy150489 } 9723526Sxy150489 9733526Sxy150489 static void 9743526Sxy150489 e1000g_destroy_locks(struct e1000g *Adapter) 9753526Sxy150489 { 9763526Sxy150489 e1000g_tx_ring_t *tx_ring; 9773526Sxy150489 e1000g_rx_ring_t *rx_ring; 9783526Sxy150489 9793526Sxy150489 tx_ring = Adapter->tx_ring; 9803526Sxy150489 mutex_destroy(&tx_ring->tx_lock); 9813526Sxy150489 mutex_destroy(&tx_ring->usedlist_lock); 9823526Sxy150489 mutex_destroy(&tx_ring->freelist_lock); 983*4919Sxy150489 mutex_destroy(&tx_ring->mblks_lock); 9843526Sxy150489 9853526Sxy150489 rx_ring = Adapter->rx_ring; 9863526Sxy150489 mutex_destroy(&rx_ring->rx_lock); 9873526Sxy150489 mutex_destroy(&rx_ring->freelist_lock); 9883526Sxy150489 989*4919Sxy150489 mutex_destroy(&Adapter->link_lock); 990*4919Sxy150489 mutex_destroy(&Adapter->watchdog_lock); 9913526Sxy150489 rw_destroy(&Adapter->chip_lock); 9923526Sxy150489 } 9933526Sxy150489 9943526Sxy150489 static int 9953526Sxy150489 e1000g_resume(dev_info_t *devinfo) 9963526Sxy150489 { 9973526Sxy150489 struct e1000g *Adapter; 9983526Sxy150489 9993526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 10003526Sxy150489 if (Adapter == NULL) 10013526Sxy150489 return (DDI_FAILURE); 10023526Sxy150489 1003*4919Sxy150489 if (e1000g_start(Adapter, B_TRUE)) 10043526Sxy150489 return (DDI_FAILURE); 10053526Sxy150489 10063526Sxy150489 return (DDI_SUCCESS); 10073526Sxy150489 } 10083526Sxy150489 10093526Sxy150489 static int 10103526Sxy150489 e1000g_suspend(dev_info_t *devinfo) 10113526Sxy150489 { 10123526Sxy150489 struct e1000g *Adapter; 10133526Sxy150489 10143526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo); 10153526Sxy150489 if (Adapter == NULL) 10163526Sxy150489 return (DDI_FAILURE); 10173526Sxy150489 1018*4919Sxy150489 e1000g_stop(Adapter, B_TRUE); 10193526Sxy150489 10203526Sxy150489 return (DDI_SUCCESS); 10213526Sxy150489 } 10223526Sxy150489 10233526Sxy150489 static int 10243526Sxy150489 e1000g_init(struct e1000g *Adapter) 10253526Sxy150489 { 10263526Sxy150489 uint32_t pba; 1027*4919Sxy150489 uint32_t high_water; 10283526Sxy150489 struct e1000_hw *hw; 10294061Sxy150489 clock_t link_timeout; 10303526Sxy150489 1031*4919Sxy150489 hw = &Adapter->shared; 10323526Sxy150489 10333526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 10343526Sxy150489 10353526Sxy150489 /* 10363526Sxy150489 * reset to put the hardware in a known state 10373526Sxy150489 * before we try to do anything with the eeprom 10383526Sxy150489 */ 10393526Sxy150489 (void) e1000_reset_hw(hw); 10403526Sxy150489 1041*4919Sxy150489 if (e1000_validate_nvm_checksum(hw) < 0) { 10424061Sxy150489 /* 10434061Sxy150489 * Some PCI-E parts fail the first check due to 10444061Sxy150489 * the link being in sleep state. Call it again, 10454061Sxy150489 * if it fails a second time its a real issue. 10464061Sxy150489 */ 1047*4919Sxy150489 if (e1000_validate_nvm_checksum(hw) < 0) { 10484061Sxy150489 e1000g_log(Adapter, CE_WARN, 1049*4919Sxy150489 "Invalid NVM checksum. Please contact " 1050*4919Sxy150489 "the vendor to update the NVM."); 10514061Sxy150489 goto init_fail; 10524061Sxy150489 } 10533526Sxy150489 } 10543526Sxy150489 10553526Sxy150489 #ifdef __sparc 10563526Sxy150489 /* 10573526Sxy150489 * Firstly, we try to get the local ethernet address from OBP. If 10583526Sxy150489 * fail, we get from EEPROM of NIC card. 10593526Sxy150489 */ 10603526Sxy150489 if (!e1000g_find_mac_address(Adapter)) { 10613526Sxy150489 if (e1000_read_mac_addr(hw) < 0) { 10623526Sxy150489 e1000g_log(Adapter, CE_WARN, "Read mac addr failed"); 10633526Sxy150489 goto init_fail; 10643526Sxy150489 } 10653526Sxy150489 } 10663526Sxy150489 #else 10673526Sxy150489 /* Get the local ethernet address. */ 10683526Sxy150489 if (e1000_read_mac_addr(hw) < 0) { 10693526Sxy150489 e1000g_log(Adapter, CE_WARN, "Read mac addr failed"); 10703526Sxy150489 goto init_fail; 10713526Sxy150489 } 10723526Sxy150489 #endif 10733526Sxy150489 10743526Sxy150489 /* check for valid mac address */ 1075*4919Sxy150489 if (!is_valid_mac_addr(hw->mac.addr)) { 10763526Sxy150489 e1000g_log(Adapter, CE_WARN, "Invalid mac addr"); 10773526Sxy150489 goto init_fail; 10783526Sxy150489 } 10793526Sxy150489 1080*4919Sxy150489 /* Set LAA state for 82571 chipset */ 1081*4919Sxy150489 e1000_set_laa_state_82571(hw, B_TRUE); 10823526Sxy150489 10833526Sxy150489 /* Master Latency Timer implementation */ 1084*4919Sxy150489 if (Adapter->master_latency_timer) { 1085*4919Sxy150489 pci_config_put8(Adapter->osdep.cfg_handle, 1086*4919Sxy150489 PCI_CONF_LATENCY_TIMER, Adapter->master_latency_timer); 10873526Sxy150489 } 10883526Sxy150489 1089*4919Sxy150489 if (hw->mac.type < e1000_82547) { 10903526Sxy150489 /* 10913526Sxy150489 * Total FIFO is 64K 10923526Sxy150489 */ 1093*4919Sxy150489 if (hw->mac.max_frame_size > FRAME_SIZE_UPTO_8K) 10943526Sxy150489 pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */ 10953526Sxy150489 else 10963526Sxy150489 pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */ 1097*4919Sxy150489 } else if (hw->mac.type >= e1000_82571 && 1098*4919Sxy150489 hw->mac.type <= e1000_82572) { 10993526Sxy150489 /* 11003526Sxy150489 * Total FIFO is 48K 11013526Sxy150489 */ 1102*4919Sxy150489 if (hw->mac.max_frame_size > FRAME_SIZE_UPTO_8K) 11033526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 18K for Tx */ 11043526Sxy150489 else 11053526Sxy150489 pba = E1000_PBA_38K; /* 38K for Rx, 10K for Tx */ 1106*4919Sxy150489 } else if (hw->mac.type == e1000_ich8lan) { 11073526Sxy150489 pba = E1000_PBA_8K; /* 8K for Rx, 12K for Tx */ 1108*4919Sxy150489 } else if (hw->mac.type == e1000_ich9lan) { 1109*4919Sxy150489 pba = E1000_PBA_12K; 11103526Sxy150489 } else { 11113526Sxy150489 /* 11123526Sxy150489 * Total FIFO is 40K 11133526Sxy150489 */ 1114*4919Sxy150489 if (hw->mac.max_frame_size > FRAME_SIZE_UPTO_8K) 11153526Sxy150489 pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */ 11163526Sxy150489 else 11173526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */ 11183526Sxy150489 } 1119*4919Sxy150489 E1000_WRITE_REG(hw, E1000_PBA, pba); 11203526Sxy150489 11213526Sxy150489 /* 11223526Sxy150489 * These parameters set thresholds for the adapter's generation(Tx) 11233526Sxy150489 * and response(Rx) to Ethernet PAUSE frames. These are just threshold 11243526Sxy150489 * settings. Flow control is enabled or disabled in the configuration 11253526Sxy150489 * file. 11263526Sxy150489 * High-water mark is set down from the top of the rx fifo (not 11273526Sxy150489 * sensitive to max_frame_size) and low-water is set just below 11283526Sxy150489 * high-water mark. 1129*4919Sxy150489 * The high water mark must be low enough to fit one full frame above 1130*4919Sxy150489 * it in the rx FIFO. Should be the lower of: 1131*4919Sxy150489 * 90% of the Rx FIFO size and the full Rx FIFO size minus the early 1132*4919Sxy150489 * receive size (assuming ERT set to E1000_ERT_2048), or the full 1133*4919Sxy150489 * Rx FIFO size minus one full frame. 11343526Sxy150489 */ 1135*4919Sxy150489 high_water = min(((pba << 10) * 9 / 10), 1136*4919Sxy150489 ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_ich9lan) ? 1137*4919Sxy150489 ((pba << 10) - (E1000_ERT_2048 << 3)) : 1138*4919Sxy150489 ((pba << 10) - hw->mac.max_frame_size))); 1139*4919Sxy150489 1140*4919Sxy150489 hw->mac.fc_high_water = high_water & 0xFFF8; 1141*4919Sxy150489 hw->mac.fc_low_water = hw->mac.fc_high_water - 8; 1142*4919Sxy150489 1143*4919Sxy150489 if (hw->mac.type == e1000_80003es2lan) 1144*4919Sxy150489 hw->mac.fc_pause_time = 0xFFFF; 1145*4919Sxy150489 else 1146*4919Sxy150489 hw->mac.fc_pause_time = E1000_FC_PAUSE_TIME; 1147*4919Sxy150489 hw->mac.fc_send_xon = B_TRUE; 1148*4919Sxy150489 hw->mac.fc = hw->mac.original_fc; 11493526Sxy150489 11503526Sxy150489 /* 11513526Sxy150489 * Reset the adapter hardware the second time. 11523526Sxy150489 */ 11533526Sxy150489 (void) e1000_reset_hw(hw); 11543526Sxy150489 11553526Sxy150489 /* disable wakeup control by default */ 1156*4919Sxy150489 if (hw->mac.type >= e1000_82544) 1157*4919Sxy150489 E1000_WRITE_REG(hw, E1000_WUC, 0); 11583526Sxy150489 11593526Sxy150489 /* MWI setup */ 1160*4919Sxy150489 e1000_pci_set_mwi(hw); 11613526Sxy150489 11623526Sxy150489 /* 11633526Sxy150489 * Configure/Initialize hardware 11643526Sxy150489 */ 11653526Sxy150489 if (e1000_init_hw(hw) < 0) { 11663526Sxy150489 e1000g_log(Adapter, CE_WARN, "Initialize hw failed"); 11673526Sxy150489 goto init_fail; 11683526Sxy150489 } 11693526Sxy150489 11703526Sxy150489 /* Disable Smart Power Down */ 11713526Sxy150489 phy_spd_state(hw, B_FALSE); 11723526Sxy150489 11733526Sxy150489 /* 11743526Sxy150489 * Initialize unicast addresses. 11753526Sxy150489 */ 11763526Sxy150489 e1000g_init_unicst(Adapter); 11773526Sxy150489 11783526Sxy150489 /* 11793526Sxy150489 * Setup and initialize the mctable structures. After this routine 11803526Sxy150489 * completes Multicast table will be set 11813526Sxy150489 */ 1182*4919Sxy150489 e1000g_setup_multicast(Adapter); 1183*4919Sxy150489 msec_delay(5); 11843526Sxy150489 11853526Sxy150489 /* 11863526Sxy150489 * Implement Adaptive IFS 11873526Sxy150489 */ 11883526Sxy150489 e1000_reset_adaptive(hw); 11893526Sxy150489 11903526Sxy150489 /* Setup Interrupt Throttling Register */ 1191*4919Sxy150489 E1000_WRITE_REG(hw, E1000_ITR, Adapter->intr_throttling_rate); 11923526Sxy150489 11934061Sxy150489 /* Start the timer for link setup */ 1194*4919Sxy150489 if (hw->mac.autoneg) 1195*4919Sxy150489 link_timeout = PHY_AUTO_NEG_LIMIT * drv_usectohz(100000); 11964061Sxy150489 else 1197*4919Sxy150489 link_timeout = PHY_FORCE_LIMIT * drv_usectohz(100000); 1198*4919Sxy150489 1199*4919Sxy150489 mutex_enter(&Adapter->link_lock); 1200*4919Sxy150489 if (hw->phy.wait_for_link) { 12014061Sxy150489 Adapter->link_complete = B_TRUE; 12023526Sxy150489 } else { 12034061Sxy150489 Adapter->link_complete = B_FALSE; 12044061Sxy150489 Adapter->link_tid = timeout(e1000g_link_timer, 12054061Sxy150489 (void *)Adapter, link_timeout); 12063526Sxy150489 } 1207*4919Sxy150489 mutex_exit(&Adapter->link_lock); 12083526Sxy150489 12093526Sxy150489 /* Enable PCI-Ex master */ 1210*4919Sxy150489 if (hw->bus.type == e1000_bus_type_pci_express) { 12113526Sxy150489 e1000_enable_pciex_master(hw); 12123526Sxy150489 } 12133526Sxy150489 12143526Sxy150489 Adapter->init_count++; 12153526Sxy150489 12163526Sxy150489 rw_exit(&Adapter->chip_lock); 12173526Sxy150489 12183526Sxy150489 return (DDI_SUCCESS); 12193526Sxy150489 12203526Sxy150489 init_fail: 12213526Sxy150489 rw_exit(&Adapter->chip_lock); 12223526Sxy150489 return (DDI_FAILURE); 12233526Sxy150489 } 12243526Sxy150489 12253526Sxy150489 /* 12263526Sxy150489 * Check if the link is up 12273526Sxy150489 */ 12283526Sxy150489 static boolean_t 12293526Sxy150489 e1000g_link_up(struct e1000g *Adapter) 12303526Sxy150489 { 12313526Sxy150489 struct e1000_hw *hw; 12323526Sxy150489 boolean_t link_up; 12333526Sxy150489 1234*4919Sxy150489 hw = &Adapter->shared; 12353526Sxy150489 12363526Sxy150489 /* Ensure this is set to get accurate copper link status */ 1237*4919Sxy150489 hw->mac.get_link_status = B_TRUE; 12383526Sxy150489 12393526Sxy150489 e1000_check_for_link(hw); 12403526Sxy150489 1241*4919Sxy150489 if ((E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU) || 1242*4919Sxy150489 ((!hw->mac.get_link_status) && (hw->mac.type == e1000_82543)) || 12433526Sxy150489 ((hw->media_type == e1000_media_type_internal_serdes) && 1244*4919Sxy150489 (hw->mac.serdes_has_link))) { 12453526Sxy150489 link_up = B_TRUE; 12463526Sxy150489 } else { 12473526Sxy150489 link_up = B_FALSE; 12483526Sxy150489 } 12493526Sxy150489 12503526Sxy150489 return (link_up); 12513526Sxy150489 } 12523526Sxy150489 12533526Sxy150489 static void 12543526Sxy150489 e1000g_m_ioctl(void *arg, queue_t *q, mblk_t *mp) 12553526Sxy150489 { 12563526Sxy150489 struct iocblk *iocp; 12573526Sxy150489 struct e1000g *e1000gp; 12583526Sxy150489 enum ioc_reply status; 12593526Sxy150489 int err; 12603526Sxy150489 12613526Sxy150489 iocp = (struct iocblk *)mp->b_rptr; 12623526Sxy150489 iocp->ioc_error = 0; 12633526Sxy150489 e1000gp = (struct e1000g *)arg; 12643526Sxy150489 12653526Sxy150489 ASSERT(e1000gp); 12663526Sxy150489 if (e1000gp == NULL) { 12673526Sxy150489 miocnak(q, mp, 0, EINVAL); 12683526Sxy150489 return; 12693526Sxy150489 } 12703526Sxy150489 12713526Sxy150489 switch (iocp->ioc_cmd) { 12723526Sxy150489 12733526Sxy150489 case LB_GET_INFO_SIZE: 12743526Sxy150489 case LB_GET_INFO: 12753526Sxy150489 case LB_GET_MODE: 12763526Sxy150489 case LB_SET_MODE: 12773526Sxy150489 status = e1000g_loopback_ioctl(e1000gp, iocp, mp); 12783526Sxy150489 break; 12793526Sxy150489 12803526Sxy150489 case ND_GET: 12813526Sxy150489 case ND_SET: 12823526Sxy150489 status = e1000g_nd_ioctl(e1000gp, q, mp, iocp); 12833526Sxy150489 break; 12843526Sxy150489 1285*4919Sxy150489 #ifdef E1000G_DEBUG 12863526Sxy150489 case E1000G_IOC_REG_PEEK: 12873526Sxy150489 case E1000G_IOC_REG_POKE: 12883526Sxy150489 status = e1000g_pp_ioctl(e1000gp, iocp, mp); 12893526Sxy150489 break; 12903526Sxy150489 case E1000G_IOC_CHIP_RESET: 12913526Sxy150489 e1000gp->reset_count++; 12923526Sxy150489 if (e1000g_reset(e1000gp)) 12933526Sxy150489 status = IOC_ACK; 12943526Sxy150489 else 12953526Sxy150489 status = IOC_INVAL; 12963526Sxy150489 break; 1297*4919Sxy150489 #endif 12983526Sxy150489 default: 12993526Sxy150489 status = IOC_INVAL; 13003526Sxy150489 break; 13013526Sxy150489 } 13023526Sxy150489 13033526Sxy150489 /* 13043526Sxy150489 * Decide how to reply 13053526Sxy150489 */ 13063526Sxy150489 switch (status) { 13073526Sxy150489 default: 13083526Sxy150489 case IOC_INVAL: 13093526Sxy150489 /* 13103526Sxy150489 * Error, reply with a NAK and EINVAL or the specified error 13113526Sxy150489 */ 13123526Sxy150489 miocnak(q, mp, 0, iocp->ioc_error == 0 ? 13134349Sxy150489 EINVAL : iocp->ioc_error); 13143526Sxy150489 break; 13153526Sxy150489 13163526Sxy150489 case IOC_DONE: 13173526Sxy150489 /* 13183526Sxy150489 * OK, reply already sent 13193526Sxy150489 */ 13203526Sxy150489 break; 13213526Sxy150489 13223526Sxy150489 case IOC_ACK: 13233526Sxy150489 /* 13243526Sxy150489 * OK, reply with an ACK 13253526Sxy150489 */ 13263526Sxy150489 miocack(q, mp, 0, 0); 13273526Sxy150489 break; 13283526Sxy150489 13293526Sxy150489 case IOC_REPLY: 13303526Sxy150489 /* 13313526Sxy150489 * OK, send prepared reply as ACK or NAK 13323526Sxy150489 */ 13333526Sxy150489 mp->b_datap->db_type = iocp->ioc_error == 0 ? 13344349Sxy150489 M_IOCACK : M_IOCNAK; 13353526Sxy150489 qreply(q, mp); 13363526Sxy150489 break; 13373526Sxy150489 } 13383526Sxy150489 } 13393526Sxy150489 13403526Sxy150489 static void e1000g_m_blank(void *arg, time_t ticks, uint32_t count) 13413526Sxy150489 { 13423526Sxy150489 struct e1000g *Adapter; 13433526Sxy150489 13443526Sxy150489 Adapter = (struct e1000g *)arg; 13453526Sxy150489 13463526Sxy150489 /* 13473526Sxy150489 * Adjust ITR (Interrupt Throttling Register) to coalesce 13483526Sxy150489 * interrupts. This formula and its coefficient come from 13493526Sxy150489 * our experiments. 13503526Sxy150489 */ 13513526Sxy150489 if (Adapter->intr_adaptive) { 13523526Sxy150489 Adapter->intr_throttling_rate = count << 5; 1353*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_ITR, 13543526Sxy150489 Adapter->intr_throttling_rate); 13553526Sxy150489 } 13563526Sxy150489 } 13573526Sxy150489 13583526Sxy150489 static void 13593526Sxy150489 e1000g_m_resources(void *arg) 13603526Sxy150489 { 13613526Sxy150489 struct e1000g *adapter = (struct e1000g *)arg; 13623526Sxy150489 mac_rx_fifo_t mrf; 13633526Sxy150489 13643526Sxy150489 mrf.mrf_type = MAC_RX_FIFO; 13653526Sxy150489 mrf.mrf_blank = e1000g_m_blank; 13663526Sxy150489 mrf.mrf_arg = (void *)adapter; 13673526Sxy150489 mrf.mrf_normal_blank_time = E1000_RX_INTPT_TIME; 13683526Sxy150489 mrf.mrf_normal_pkt_count = E1000_RX_PKT_CNT; 13693526Sxy150489 13703526Sxy150489 adapter->mrh = mac_resource_add(adapter->mh, (mac_resource_t *)&mrf); 13713526Sxy150489 } 13723526Sxy150489 13733526Sxy150489 static int 13743526Sxy150489 e1000g_m_start(void *arg) 13753526Sxy150489 { 13763526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 13773526Sxy150489 1378*4919Sxy150489 return (e1000g_start(Adapter, B_TRUE)); 13793526Sxy150489 } 13803526Sxy150489 13813526Sxy150489 static int 1382*4919Sxy150489 e1000g_start(struct e1000g *Adapter, boolean_t global) 13833526Sxy150489 { 1384*4919Sxy150489 if (global) { 1385*4919Sxy150489 /* Allocate dma resources for descriptors and buffers */ 1386*4919Sxy150489 if (e1000g_alloc_dma_resources(Adapter) != DDI_SUCCESS) { 1387*4919Sxy150489 e1000g_log(Adapter, CE_WARN, 1388*4919Sxy150489 "Alloc DMA resources failed"); 1389*4919Sxy150489 return (ENOTACTIVE); 1390*4919Sxy150489 } 1391*4919Sxy150489 Adapter->rx_buffer_setup = B_FALSE; 1392*4919Sxy150489 } 1393*4919Sxy150489 13943526Sxy150489 if (!(Adapter->attach_progress & ATTACH_PROGRESS_INIT)) { 13953526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) { 13963526Sxy150489 e1000g_log(Adapter, CE_WARN, 13973526Sxy150489 "Adapter initialization failed"); 1398*4919Sxy150489 if (global) 1399*4919Sxy150489 e1000g_release_dma_resources(Adapter); 14003526Sxy150489 return (ENOTACTIVE); 14013526Sxy150489 } 14023526Sxy150489 } 14033526Sxy150489 14043526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 14053526Sxy150489 1406*4919Sxy150489 /* Setup and initialize the transmit structures */ 1407*4919Sxy150489 e1000g_tx_setup(Adapter); 1408*4919Sxy150489 msec_delay(5); 1409*4919Sxy150489 1410*4919Sxy150489 /* Setup and initialize the receive structures */ 1411*4919Sxy150489 e1000g_rx_setup(Adapter); 1412*4919Sxy150489 msec_delay(5); 1413*4919Sxy150489 1414*4919Sxy150489 e1000g_mask_interrupt(Adapter); 14153526Sxy150489 if (Adapter->tx_intr_enable) 1416*4919Sxy150489 e1000g_mask_tx_interrupt(Adapter); 14173526Sxy150489 14183526Sxy150489 Adapter->started = B_TRUE; 14193526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_INIT; 14203526Sxy150489 14213526Sxy150489 rw_exit(&Adapter->chip_lock); 14223526Sxy150489 1423*4919Sxy150489 /* Enable and start the watchdog timer */ 1424*4919Sxy150489 enable_watchdog_timer(Adapter); 1425*4919Sxy150489 14263526Sxy150489 return (0); 14273526Sxy150489 } 14283526Sxy150489 14293526Sxy150489 static void 14303526Sxy150489 e1000g_m_stop(void *arg) 14313526Sxy150489 { 14323526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 14333526Sxy150489 1434*4919Sxy150489 e1000g_stop(Adapter, B_TRUE); 14353526Sxy150489 } 14363526Sxy150489 14373526Sxy150489 static void 1438*4919Sxy150489 e1000g_stop(struct e1000g *Adapter, boolean_t global) 14393526Sxy150489 { 14403526Sxy150489 /* Set stop flags */ 14413526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 14423526Sxy150489 14433526Sxy150489 Adapter->started = B_FALSE; 14443526Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_INIT; 14453526Sxy150489 14463526Sxy150489 rw_exit(&Adapter->chip_lock); 14473526Sxy150489 14483526Sxy150489 /* Drain tx sessions */ 14493526Sxy150489 (void) e1000g_tx_drain(Adapter); 14503526Sxy150489 1451*4919Sxy150489 /* Disable and stop all the timers */ 1452*4919Sxy150489 disable_watchdog_timer(Adapter); 1453*4919Sxy150489 stop_link_timer(Adapter); 1454*4919Sxy150489 stop_82547_timer(Adapter->tx_ring); 14554061Sxy150489 14563526Sxy150489 /* Stop the chip and release pending resources */ 14573526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 14583526Sxy150489 1459*4919Sxy150489 e1000g_clear_all_interrupts(Adapter); 1460*4919Sxy150489 e1000_reset_hw(&Adapter->shared); 14613526Sxy150489 14623526Sxy150489 /* Release resources still held by the TX descriptors */ 1463*4919Sxy150489 e1000g_tx_clean(Adapter); 14644061Sxy150489 14654061Sxy150489 /* Clean the pending rx jumbo packet fragment */ 1466*4919Sxy150489 e1000g_rx_clean(Adapter); 14674061Sxy150489 14684061Sxy150489 rw_exit(&Adapter->chip_lock); 1469*4919Sxy150489 1470*4919Sxy150489 if (global) 1471*4919Sxy150489 e1000g_release_dma_resources(Adapter); 14724061Sxy150489 } 14734061Sxy150489 14744061Sxy150489 static void 1475*4919Sxy150489 e1000g_rx_clean(struct e1000g *Adapter) 1476*4919Sxy150489 { 1477*4919Sxy150489 e1000g_rx_ring_t *rx_ring = Adapter->rx_ring; 1478*4919Sxy150489 1479*4919Sxy150489 if (rx_ring->rx_mblk != NULL) { 1480*4919Sxy150489 freemsg(rx_ring->rx_mblk); 1481*4919Sxy150489 rx_ring->rx_mblk = NULL; 1482*4919Sxy150489 rx_ring->rx_mblk_tail = NULL; 1483*4919Sxy150489 rx_ring->rx_mblk_len = 0; 1484*4919Sxy150489 } 1485*4919Sxy150489 } 1486*4919Sxy150489 1487*4919Sxy150489 static void 1488*4919Sxy150489 e1000g_tx_clean(struct e1000g *Adapter) 14894061Sxy150489 { 14904061Sxy150489 e1000g_tx_ring_t *tx_ring; 1491*4919Sxy150489 p_tx_sw_packet_t packet; 14924061Sxy150489 mblk_t *mp; 14934061Sxy150489 mblk_t *nmp; 14944061Sxy150489 uint32_t packet_count; 14954061Sxy150489 14964061Sxy150489 tx_ring = Adapter->tx_ring; 14974061Sxy150489 14983526Sxy150489 /* 14993526Sxy150489 * Here we don't need to protect the lists using 15003526Sxy150489 * the usedlist_lock and freelist_lock, for they 15013526Sxy150489 * have been protected by the chip_lock. 15023526Sxy150489 */ 15033526Sxy150489 mp = NULL; 15043526Sxy150489 nmp = NULL; 15054061Sxy150489 packet_count = 0; 1506*4919Sxy150489 packet = (p_tx_sw_packet_t)QUEUE_GET_HEAD(&tx_ring->used_list); 15073526Sxy150489 while (packet != NULL) { 15083526Sxy150489 if (packet->mp != NULL) { 15093526Sxy150489 /* Assemble the message chain */ 15103526Sxy150489 if (mp == NULL) { 15113526Sxy150489 mp = packet->mp; 15123526Sxy150489 nmp = packet->mp; 15133526Sxy150489 } else { 15143526Sxy150489 nmp->b_next = packet->mp; 15153526Sxy150489 nmp = packet->mp; 15163526Sxy150489 } 15173526Sxy150489 /* Disconnect the message from the sw packet */ 15183526Sxy150489 packet->mp = NULL; 15193526Sxy150489 } 15203526Sxy150489 1521*4919Sxy150489 e1000g_free_tx_swpkt(packet); 15224061Sxy150489 packet_count++; 15233526Sxy150489 1524*4919Sxy150489 packet = (p_tx_sw_packet_t) 15253526Sxy150489 QUEUE_GET_NEXT(&tx_ring->used_list, &packet->Link); 15263526Sxy150489 } 15273526Sxy150489 15283526Sxy150489 if (mp != NULL) { 1529*4919Sxy150489 mutex_enter(&tx_ring->mblks_lock); 1530*4919Sxy150489 if (tx_ring->mblks.head == NULL) { 1531*4919Sxy150489 tx_ring->mblks.head = mp; 1532*4919Sxy150489 tx_ring->mblks.tail = nmp; 15333526Sxy150489 } else { 1534*4919Sxy150489 tx_ring->mblks.tail->b_next = mp; 1535*4919Sxy150489 tx_ring->mblks.tail = nmp; 15363526Sxy150489 } 1537*4919Sxy150489 mutex_exit(&tx_ring->mblks_lock); 15383526Sxy150489 } 15393526Sxy150489 15404061Sxy150489 ddi_intr_trigger_softint(Adapter->tx_softint_handle, NULL); 15414061Sxy150489 15424061Sxy150489 if (packet_count > 0) { 15434061Sxy150489 QUEUE_APPEND(&tx_ring->free_list, &tx_ring->used_list); 15444061Sxy150489 QUEUE_INIT_LIST(&tx_ring->used_list); 15454061Sxy150489 15464061Sxy150489 /* Setup TX descriptor pointers */ 15474061Sxy150489 tx_ring->tbd_next = tx_ring->tbd_first; 15484061Sxy150489 tx_ring->tbd_oldest = tx_ring->tbd_first; 15494061Sxy150489 15504061Sxy150489 /* Setup our HW Tx Head & Tail descriptor pointers */ 1551*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_TDH, 0); 1552*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_TDT, 0); 15533526Sxy150489 } 15543526Sxy150489 } 15553526Sxy150489 15563526Sxy150489 static boolean_t 15573526Sxy150489 e1000g_tx_drain(struct e1000g *Adapter) 15583526Sxy150489 { 15593526Sxy150489 int i; 15603526Sxy150489 boolean_t done; 15613526Sxy150489 e1000g_tx_ring_t *tx_ring; 15623526Sxy150489 15633526Sxy150489 tx_ring = Adapter->tx_ring; 15643526Sxy150489 15653526Sxy150489 /* Allow up to 'wsdraintime' for pending xmit's to complete. */ 1566*4919Sxy150489 for (i = 0; i < TX_DRAIN_TIME; i++) { 15673526Sxy150489 mutex_enter(&tx_ring->usedlist_lock); 15683526Sxy150489 done = IS_QUEUE_EMPTY(&tx_ring->used_list); 15693526Sxy150489 mutex_exit(&tx_ring->usedlist_lock); 15703526Sxy150489 15713526Sxy150489 if (done) 15723526Sxy150489 break; 15733526Sxy150489 15743526Sxy150489 msec_delay(1); 15753526Sxy150489 } 15763526Sxy150489 15773526Sxy150489 return (done); 15783526Sxy150489 } 15793526Sxy150489 15803526Sxy150489 static boolean_t 15813526Sxy150489 e1000g_rx_drain(struct e1000g *Adapter) 15823526Sxy150489 { 1583*4919Sxy150489 e1000g_rx_ring_t *rx_ring; 1584*4919Sxy150489 p_rx_sw_packet_t packet; 15853526Sxy150489 boolean_t done; 15863526Sxy150489 1587*4919Sxy150489 rx_ring = Adapter->rx_ring; 1588*4919Sxy150489 done = B_TRUE; 1589*4919Sxy150489 1590*4919Sxy150489 rw_enter(&e1000g_rx_detach_lock, RW_WRITER); 1591*4919Sxy150489 1592*4919Sxy150489 while (rx_ring->pending_list != NULL) { 1593*4919Sxy150489 packet = rx_ring->pending_list; 1594*4919Sxy150489 rx_ring->pending_list = 1595*4919Sxy150489 rx_ring->pending_list->next; 1596*4919Sxy150489 1597*4919Sxy150489 if (packet->flag == E1000G_RX_SW_STOP) { 1598*4919Sxy150489 packet->flag = E1000G_RX_SW_DETACH; 1599*4919Sxy150489 done = B_FALSE; 1600*4919Sxy150489 } else { 1601*4919Sxy150489 ASSERT(packet->flag == E1000G_RX_SW_FREE); 1602*4919Sxy150489 ASSERT(packet->mp == NULL); 1603*4919Sxy150489 e1000g_free_rx_sw_packet(packet); 1604*4919Sxy150489 } 1605*4919Sxy150489 } 1606*4919Sxy150489 1607*4919Sxy150489 rw_exit(&e1000g_rx_detach_lock); 16083526Sxy150489 16093526Sxy150489 return (done); 16103526Sxy150489 } 16113526Sxy150489 16124061Sxy150489 boolean_t 16133526Sxy150489 e1000g_reset(struct e1000g *Adapter) 16143526Sxy150489 { 1615*4919Sxy150489 e1000g_stop(Adapter, B_FALSE); 1616*4919Sxy150489 1617*4919Sxy150489 if (e1000g_start(Adapter, B_FALSE)) { 16183526Sxy150489 e1000g_log(Adapter, CE_WARN, "Reset failed"); 16193526Sxy150489 return (B_FALSE); 16203526Sxy150489 } 16213526Sxy150489 16223526Sxy150489 return (B_TRUE); 16233526Sxy150489 } 16243526Sxy150489 16253526Sxy150489 /* 1626*4919Sxy150489 * e1000g_intr_pciexpress - ISR for PCI Express chipsets 1627*4919Sxy150489 * 1628*4919Sxy150489 * This interrupt service routine is for PCI-Express adapters. 1629*4919Sxy150489 * The ICR contents is valid only when the E1000_ICR_INT_ASSERTED 1630*4919Sxy150489 * bit is set. 16313526Sxy150489 */ 16323526Sxy150489 static uint_t 16333526Sxy150489 e1000g_intr_pciexpress(caddr_t arg) 16343526Sxy150489 { 16353526Sxy150489 struct e1000g *Adapter; 1636*4919Sxy150489 uint32_t icr; 16373526Sxy150489 16383526Sxy150489 Adapter = (struct e1000g *)arg; 1639*4919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 1640*4919Sxy150489 1641*4919Sxy150489 if (icr & E1000_ICR_INT_ASSERTED) { 16423526Sxy150489 /* 16433526Sxy150489 * E1000_ICR_INT_ASSERTED bit was set: 16443526Sxy150489 * Read(Clear) the ICR, claim this interrupt, 16453526Sxy150489 * look for work to do. 16463526Sxy150489 */ 1647*4919Sxy150489 e1000g_intr_work(Adapter, icr); 16483526Sxy150489 return (DDI_INTR_CLAIMED); 16493526Sxy150489 } else { 16503526Sxy150489 /* 16513526Sxy150489 * E1000_ICR_INT_ASSERTED bit was not set: 16523526Sxy150489 * Don't claim this interrupt, return immediately. 16533526Sxy150489 */ 16543526Sxy150489 return (DDI_INTR_UNCLAIMED); 16553526Sxy150489 } 16563526Sxy150489 } 16573526Sxy150489 16583526Sxy150489 /* 1659*4919Sxy150489 * e1000g_intr - ISR for PCI/PCI-X chipsets 1660*4919Sxy150489 * 1661*4919Sxy150489 * This interrupt service routine is for PCI/PCI-X adapters. 1662*4919Sxy150489 * We check the ICR contents no matter the E1000_ICR_INT_ASSERTED 1663*4919Sxy150489 * bit is set or not. 16643526Sxy150489 */ 16653526Sxy150489 static uint_t 16663526Sxy150489 e1000g_intr(caddr_t arg) 16673526Sxy150489 { 16683526Sxy150489 struct e1000g *Adapter; 1669*4919Sxy150489 uint32_t icr; 16703526Sxy150489 16713526Sxy150489 Adapter = (struct e1000g *)arg; 1672*4919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR); 1673*4919Sxy150489 1674*4919Sxy150489 if (icr) { 16753526Sxy150489 /* 16763526Sxy150489 * Any bit was set in ICR: 16773526Sxy150489 * Read(Clear) the ICR, claim this interrupt, 16783526Sxy150489 * look for work to do. 16793526Sxy150489 */ 1680*4919Sxy150489 e1000g_intr_work(Adapter, icr); 16813526Sxy150489 return (DDI_INTR_CLAIMED); 16823526Sxy150489 } else { 16833526Sxy150489 /* 16843526Sxy150489 * No bit was set in ICR: 16853526Sxy150489 * Don't claim this interrupt, return immediately. 16863526Sxy150489 */ 16873526Sxy150489 return (DDI_INTR_UNCLAIMED); 16883526Sxy150489 } 16893526Sxy150489 } 16903526Sxy150489 16913526Sxy150489 /* 1692*4919Sxy150489 * e1000g_intr_work - actual processing of ISR 1693*4919Sxy150489 * 1694*4919Sxy150489 * Read(clear) the ICR contents and call appropriate interrupt 1695*4919Sxy150489 * processing routines. 16963526Sxy150489 */ 16973526Sxy150489 static void 1698*4919Sxy150489 e1000g_intr_work(struct e1000g *Adapter, uint32_t icr) 16993526Sxy150489 { 1700*4919Sxy150489 rw_enter(&Adapter->chip_lock, RW_READER); 1701*4919Sxy150489 /* 1702*4919Sxy150489 * Here we need to check the "started" flag within the chip_lock to 1703*4919Sxy150489 * ensure the receive routine will not execute when the adapter is 1704*4919Sxy150489 * being reset. 1705*4919Sxy150489 */ 1706*4919Sxy150489 if (!Adapter->started) { 1707*4919Sxy150489 rw_exit(&Adapter->chip_lock); 1708*4919Sxy150489 return; 1709*4919Sxy150489 } 1710*4919Sxy150489 1711*4919Sxy150489 if (icr & E1000_ICR_RXT0) { 17123526Sxy150489 mblk_t *mp; 17133526Sxy150489 1714*4919Sxy150489 mutex_enter(&Adapter->rx_ring->rx_lock); 1715*4919Sxy150489 mp = e1000g_receive(Adapter); 1716*4919Sxy150489 mutex_exit(&Adapter->rx_ring->rx_lock); 1717*4919Sxy150489 1718*4919Sxy150489 rw_exit(&Adapter->chip_lock); 1719*4919Sxy150489 1720*4919Sxy150489 if (mp != NULL) 1721*4919Sxy150489 mac_rx(Adapter->mh, Adapter->mrh, mp); 1722*4919Sxy150489 } else 1723*4919Sxy150489 rw_exit(&Adapter->chip_lock); 17243526Sxy150489 17253526Sxy150489 /* 17263526Sxy150489 * The Receive Sequence errors RXSEQ and the link status change LSC 17273526Sxy150489 * are checked to detect that the cable has been pulled out. For 17283526Sxy150489 * the Wiseman 2.0 silicon, the receive sequence errors interrupt 17293526Sxy150489 * are an indication that cable is not connected. 17303526Sxy150489 */ 1731*4919Sxy150489 if ((icr & E1000_ICR_RXSEQ) || 1732*4919Sxy150489 (icr & E1000_ICR_LSC) || 1733*4919Sxy150489 (icr & E1000_ICR_GPI_EN1)) { 17344061Sxy150489 boolean_t link_changed; 17354061Sxy150489 timeout_id_t tid = 0; 17363526Sxy150489 1737*4919Sxy150489 stop_watchdog_timer(Adapter); 1738*4919Sxy150489 1739*4919Sxy150489 mutex_enter(&Adapter->link_lock); 17404061Sxy150489 /* e1000g_link_check takes care of link status change */ 17414061Sxy150489 link_changed = e1000g_link_check(Adapter); 17424061Sxy150489 /* 17434061Sxy150489 * If the link timer has not timed out, we'll not notify 1744*4919Sxy150489 * the upper layer with any link state until the link is up. 17454061Sxy150489 */ 17464061Sxy150489 if (link_changed && !Adapter->link_complete) { 17474061Sxy150489 if (Adapter->link_state == LINK_STATE_UP) { 17484061Sxy150489 Adapter->link_complete = B_TRUE; 17494061Sxy150489 tid = Adapter->link_tid; 17504061Sxy150489 Adapter->link_tid = 0; 17514061Sxy150489 } else { 17524061Sxy150489 link_changed = B_FALSE; 17534061Sxy150489 } 17544061Sxy150489 } 1755*4919Sxy150489 mutex_exit(&Adapter->link_lock); 17563526Sxy150489 17574061Sxy150489 if (link_changed) { 17584061Sxy150489 if (tid != 0) 17594061Sxy150489 (void) untimeout(tid); 17604061Sxy150489 17614139Sxy150489 /* 17624139Sxy150489 * Workaround for esb2. Data stuck in fifo on a link 17634139Sxy150489 * down event. Reset the adapter to recover it. 17644139Sxy150489 */ 17654139Sxy150489 if ((Adapter->link_state == LINK_STATE_DOWN) && 1766*4919Sxy150489 (Adapter->shared.mac.type == e1000_80003es2lan)) 17674139Sxy150489 (void) e1000g_reset(Adapter); 17684139Sxy150489 17694061Sxy150489 mac_link_update(Adapter->mh, Adapter->link_state); 17703526Sxy150489 } 17713526Sxy150489 1772*4919Sxy150489 start_watchdog_timer(Adapter); 17733526Sxy150489 } 17743526Sxy150489 1775*4919Sxy150489 if (icr & E1000G_ICR_TX_INTR) { 1776*4919Sxy150489 e1000g_tx_ring_t *tx_ring = Adapter->tx_ring; 1777*4919Sxy150489 17783526Sxy150489 if (!Adapter->tx_intr_enable) 1779*4919Sxy150489 e1000g_clear_tx_interrupt(Adapter); 17803526Sxy150489 /* Schedule the re-transmit */ 1781*4919Sxy150489 if (tx_ring->resched_needed) { 1782*4919Sxy150489 E1000G_STAT(tx_ring->stat_reschedule); 1783*4919Sxy150489 tx_ring->resched_needed = B_FALSE; 17843526Sxy150489 mac_tx_update(Adapter->mh); 17853526Sxy150489 } 17863526Sxy150489 if (Adapter->tx_intr_enable) { 17873526Sxy150489 /* Recycle the tx descriptors */ 17883526Sxy150489 rw_enter(&Adapter->chip_lock, RW_READER); 1789*4919Sxy150489 E1000G_DEBUG_STAT(tx_ring->stat_recycle_intr); 1790*4919Sxy150489 e1000g_recycle(tx_ring); 17913526Sxy150489 rw_exit(&Adapter->chip_lock); 17923526Sxy150489 /* Free the recycled messages */ 17933526Sxy150489 ddi_intr_trigger_softint(Adapter->tx_softint_handle, 17943526Sxy150489 NULL); 17953526Sxy150489 } 17963526Sxy150489 } 17973526Sxy150489 } 17983526Sxy150489 17993526Sxy150489 static void 18003526Sxy150489 e1000g_init_unicst(struct e1000g *Adapter) 18013526Sxy150489 { 18023526Sxy150489 struct e1000_hw *hw; 18033526Sxy150489 int slot; 18043526Sxy150489 1805*4919Sxy150489 hw = &Adapter->shared; 18063526Sxy150489 18073526Sxy150489 if (Adapter->init_count == 0) { 18083526Sxy150489 /* Initialize the multiple unicast addresses */ 18093526Sxy150489 Adapter->unicst_total = MAX_NUM_UNICAST_ADDRESSES; 18103526Sxy150489 1811*4919Sxy150489 if ((hw->mac.type == e1000_82571) && 1812*4919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 18133526Sxy150489 Adapter->unicst_total--; 18143526Sxy150489 18153526Sxy150489 Adapter->unicst_avail = Adapter->unicst_total - 1; 18163526Sxy150489 18173526Sxy150489 /* Store the default mac address */ 1818*4919Sxy150489 e1000_rar_set(hw, hw->mac.addr, 0); 1819*4919Sxy150489 if ((hw->mac.type == e1000_82571) && 1820*4919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 1821*4919Sxy150489 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY); 1822*4919Sxy150489 1823*4919Sxy150489 bcopy(hw->mac.addr, Adapter->unicst_addr[0].mac.addr, 18243526Sxy150489 ETHERADDRL); 18253526Sxy150489 Adapter->unicst_addr[0].mac.set = 1; 18263526Sxy150489 18273526Sxy150489 for (slot = 1; slot < Adapter->unicst_total; slot++) 18283526Sxy150489 Adapter->unicst_addr[slot].mac.set = 0; 18293526Sxy150489 } else { 18303526Sxy150489 /* Recover the default mac address */ 1831*4919Sxy150489 bcopy(Adapter->unicst_addr[0].mac.addr, hw->mac.addr, 18323526Sxy150489 ETHERADDRL); 18333526Sxy150489 18343526Sxy150489 /* Store the default mac address */ 1835*4919Sxy150489 e1000_rar_set(hw, hw->mac.addr, 0); 1836*4919Sxy150489 if ((hw->mac.type == e1000_82571) && 1837*4919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 1838*4919Sxy150489 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY); 18393526Sxy150489 18403526Sxy150489 /* Re-configure the RAR registers */ 18413526Sxy150489 for (slot = 1; slot < Adapter->unicst_total; slot++) 18423526Sxy150489 e1000_rar_set(hw, 18433526Sxy150489 Adapter->unicst_addr[slot].mac.addr, slot); 18443526Sxy150489 } 18453526Sxy150489 } 18463526Sxy150489 18473526Sxy150489 static int 18483526Sxy150489 e1000g_m_unicst(void *arg, const uint8_t *mac_addr) 18493526Sxy150489 { 18503526Sxy150489 struct e1000g *Adapter; 18513526Sxy150489 18523526Sxy150489 Adapter = (struct e1000g *)arg; 18533526Sxy150489 18543526Sxy150489 /* Store the default MAC address */ 1855*4919Sxy150489 bcopy(mac_addr, Adapter->shared.mac.addr, ETHERADDRL); 18563526Sxy150489 18573526Sxy150489 /* Set MAC address in address slot 0, which is the default address */ 18583526Sxy150489 return (e1000g_unicst_set(Adapter, mac_addr, 0)); 18593526Sxy150489 } 18603526Sxy150489 18613526Sxy150489 static int 18623526Sxy150489 e1000g_unicst_set(struct e1000g *Adapter, const uint8_t *mac_addr, 18633526Sxy150489 mac_addr_slot_t slot) 18643526Sxy150489 { 18653526Sxy150489 struct e1000_hw *hw; 18663526Sxy150489 1867*4919Sxy150489 hw = &Adapter->shared; 18683526Sxy150489 18693526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 18703526Sxy150489 1871*4919Sxy150489 #ifndef NO_82542_SUPPORT 18723526Sxy150489 /* 18733526Sxy150489 * The first revision of Wiseman silicon (rev 2.0) has an errata 18743526Sxy150489 * that requires the receiver to be in reset when any of the 18753526Sxy150489 * receive address registers (RAR regs) are accessed. The first 18763526Sxy150489 * rev of Wiseman silicon also requires MWI to be disabled when 18773526Sxy150489 * a global reset or a receive reset is issued. So before we 18783526Sxy150489 * initialize the RARs, we check the rev of the Wiseman controller 18793526Sxy150489 * and work around any necessary HW errata. 18803526Sxy150489 */ 1881*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 1882*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 18833526Sxy150489 e1000_pci_clear_mwi(hw); 1884*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 1885*4919Sxy150489 msec_delay(5); 18863526Sxy150489 } 1887*4919Sxy150489 #endif 18883526Sxy150489 18893526Sxy150489 bcopy(mac_addr, Adapter->unicst_addr[slot].mac.addr, ETHERADDRL); 18903526Sxy150489 e1000_rar_set(hw, (uint8_t *)mac_addr, slot); 18913526Sxy150489 18923526Sxy150489 if (slot == 0) { 1893*4919Sxy150489 if ((hw->mac.type == e1000_82571) && 1894*4919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) 1895*4919Sxy150489 e1000_rar_set(hw, (uint8_t *)mac_addr, LAST_RAR_ENTRY); 18963526Sxy150489 } 18973526Sxy150489 1898*4919Sxy150489 #ifndef NO_82542_SUPPORT 18993526Sxy150489 /* 19003526Sxy150489 * If we are using Wiseman rev 2.0 silicon, we will have previously 19013526Sxy150489 * put the receive in reset, and disabled MWI, to work around some 19023526Sxy150489 * HW errata. Now we should take the receiver out of reset, and 19033526Sxy150489 * re-enabled if MWI if it was previously enabled by the PCI BIOS. 19043526Sxy150489 */ 1905*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 1906*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 1907*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0); 1908*4919Sxy150489 msec_delay(1); 1909*4919Sxy150489 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 19103526Sxy150489 e1000_pci_set_mwi(hw); 1911*4919Sxy150489 e1000g_rx_setup(Adapter); 19123526Sxy150489 } 1913*4919Sxy150489 #endif 19143526Sxy150489 19153526Sxy150489 rw_exit(&Adapter->chip_lock); 19163526Sxy150489 19173526Sxy150489 return (0); 19183526Sxy150489 } 19193526Sxy150489 19203526Sxy150489 /* 19213526Sxy150489 * e1000g_m_unicst_add() - will find an unused address slot, set the 19223526Sxy150489 * address value to the one specified, reserve that slot and enable 19233526Sxy150489 * the NIC to start filtering on the new MAC address. 19243526Sxy150489 * Returns 0 on success. 19253526Sxy150489 */ 19263526Sxy150489 static int 19273526Sxy150489 e1000g_m_unicst_add(void *arg, mac_multi_addr_t *maddr) 19283526Sxy150489 { 19293526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 19303526Sxy150489 mac_addr_slot_t slot; 19313526Sxy150489 int err; 19323526Sxy150489 19333526Sxy150489 if (mac_unicst_verify(Adapter->mh, 19343526Sxy150489 maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 19353526Sxy150489 return (EINVAL); 19363526Sxy150489 19373526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 19383526Sxy150489 if (Adapter->unicst_avail == 0) { 19393526Sxy150489 /* no slots available */ 19403526Sxy150489 rw_exit(&Adapter->chip_lock); 19413526Sxy150489 return (ENOSPC); 19423526Sxy150489 } 19433526Sxy150489 19443526Sxy150489 /* 19453526Sxy150489 * Primary/default address is in slot 0. The next addresses 19463526Sxy150489 * are the multiple MAC addresses. So multiple MAC address 0 19473526Sxy150489 * is in slot 1, 1 in slot 2, and so on. So the first multiple 19483526Sxy150489 * MAC address resides in slot 1. 19493526Sxy150489 */ 19503526Sxy150489 for (slot = 1; slot < Adapter->unicst_total; slot++) { 19513526Sxy150489 if (Adapter->unicst_addr[slot].mac.set == 0) { 19523526Sxy150489 Adapter->unicst_addr[slot].mac.set = 1; 19533526Sxy150489 break; 19543526Sxy150489 } 19553526Sxy150489 } 19563526Sxy150489 19573526Sxy150489 ASSERT((slot > 0) && (slot < Adapter->unicst_total)); 19583526Sxy150489 19593526Sxy150489 Adapter->unicst_avail--; 19603526Sxy150489 rw_exit(&Adapter->chip_lock); 19613526Sxy150489 19623526Sxy150489 maddr->mma_slot = slot; 19633526Sxy150489 19643526Sxy150489 if ((err = e1000g_unicst_set(Adapter, maddr->mma_addr, slot)) != 0) { 19653526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 19663526Sxy150489 Adapter->unicst_addr[slot].mac.set = 0; 19673526Sxy150489 Adapter->unicst_avail++; 19683526Sxy150489 rw_exit(&Adapter->chip_lock); 19693526Sxy150489 } 19703526Sxy150489 19713526Sxy150489 return (err); 19723526Sxy150489 } 19733526Sxy150489 19743526Sxy150489 /* 19753526Sxy150489 * e1000g_m_unicst_remove() - removes a MAC address that was added by a 19763526Sxy150489 * call to e1000g_m_unicst_add(). The slot number that was returned in 19773526Sxy150489 * e1000g_m_unicst_add() is passed in the call to remove the address. 19783526Sxy150489 * Returns 0 on success. 19793526Sxy150489 */ 19803526Sxy150489 static int 19813526Sxy150489 e1000g_m_unicst_remove(void *arg, mac_addr_slot_t slot) 19823526Sxy150489 { 19833526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 19843526Sxy150489 int err; 19853526Sxy150489 19863526Sxy150489 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 19873526Sxy150489 return (EINVAL); 19883526Sxy150489 19893526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 19903526Sxy150489 if (Adapter->unicst_addr[slot].mac.set == 1) { 19913526Sxy150489 Adapter->unicst_addr[slot].mac.set = 0; 19923526Sxy150489 Adapter->unicst_avail++; 19933526Sxy150489 rw_exit(&Adapter->chip_lock); 19943526Sxy150489 19953526Sxy150489 /* Copy the default address to the passed slot */ 19963526Sxy150489 if (err = e1000g_unicst_set(Adapter, 19973526Sxy150489 Adapter->unicst_addr[0].mac.addr, slot) != 0) { 19983526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 19993526Sxy150489 Adapter->unicst_addr[slot].mac.set = 1; 20003526Sxy150489 Adapter->unicst_avail--; 20013526Sxy150489 rw_exit(&Adapter->chip_lock); 20023526Sxy150489 } 20033526Sxy150489 return (err); 20043526Sxy150489 } 20053526Sxy150489 rw_exit(&Adapter->chip_lock); 20063526Sxy150489 20073526Sxy150489 return (EINVAL); 20083526Sxy150489 } 20093526Sxy150489 20103526Sxy150489 /* 20113526Sxy150489 * e1000g_m_unicst_modify() - modifies the value of an address that 20123526Sxy150489 * has been added by e1000g_m_unicst_add(). The new address, address 20133526Sxy150489 * length and the slot number that was returned in the call to add 20143526Sxy150489 * should be passed to e1000g_m_unicst_modify(). mma_flags should be 20153526Sxy150489 * set to 0. Returns 0 on success. 20163526Sxy150489 */ 20173526Sxy150489 static int 20183526Sxy150489 e1000g_m_unicst_modify(void *arg, mac_multi_addr_t *maddr) 20193526Sxy150489 { 20203526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 20213526Sxy150489 mac_addr_slot_t slot; 20223526Sxy150489 20233526Sxy150489 if (mac_unicst_verify(Adapter->mh, 20243526Sxy150489 maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 20253526Sxy150489 return (EINVAL); 20263526Sxy150489 20273526Sxy150489 slot = maddr->mma_slot; 20283526Sxy150489 20293526Sxy150489 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 20303526Sxy150489 return (EINVAL); 20313526Sxy150489 20323526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 20333526Sxy150489 if (Adapter->unicst_addr[slot].mac.set == 1) { 20343526Sxy150489 rw_exit(&Adapter->chip_lock); 20353526Sxy150489 20363526Sxy150489 return (e1000g_unicst_set(Adapter, maddr->mma_addr, slot)); 20373526Sxy150489 } 20383526Sxy150489 rw_exit(&Adapter->chip_lock); 20393526Sxy150489 20403526Sxy150489 return (EINVAL); 20413526Sxy150489 } 20423526Sxy150489 20433526Sxy150489 /* 20443526Sxy150489 * e1000g_m_unicst_get() - will get the MAC address and all other 20453526Sxy150489 * information related to the address slot passed in mac_multi_addr_t. 20463526Sxy150489 * mma_flags should be set to 0 in the call. 20473526Sxy150489 * On return, mma_flags can take the following values: 20483526Sxy150489 * 1) MMAC_SLOT_UNUSED 20493526Sxy150489 * 2) MMAC_SLOT_USED | MMAC_VENDOR_ADDR 20503526Sxy150489 * 3) MMAC_SLOT_UNUSED | MMAC_VENDOR_ADDR 20513526Sxy150489 * 4) MMAC_SLOT_USED 20523526Sxy150489 */ 20533526Sxy150489 static int 20543526Sxy150489 e1000g_m_unicst_get(void *arg, mac_multi_addr_t *maddr) 20553526Sxy150489 { 20563526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 20573526Sxy150489 mac_addr_slot_t slot; 20583526Sxy150489 20593526Sxy150489 slot = maddr->mma_slot; 20603526Sxy150489 20613526Sxy150489 if ((slot <= 0) || (slot >= Adapter->unicst_total)) 20623526Sxy150489 return (EINVAL); 20633526Sxy150489 20643526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 20653526Sxy150489 if (Adapter->unicst_addr[slot].mac.set == 1) { 20663526Sxy150489 bcopy(Adapter->unicst_addr[slot].mac.addr, 20673526Sxy150489 maddr->mma_addr, ETHERADDRL); 20683526Sxy150489 maddr->mma_flags = MMAC_SLOT_USED; 20693526Sxy150489 } else { 20703526Sxy150489 maddr->mma_flags = MMAC_SLOT_UNUSED; 20713526Sxy150489 } 20723526Sxy150489 rw_exit(&Adapter->chip_lock); 20733526Sxy150489 20743526Sxy150489 return (0); 20753526Sxy150489 } 20763526Sxy150489 20773526Sxy150489 static int 20783526Sxy150489 multicst_add(struct e1000g *Adapter, const uint8_t *multiaddr) 20793526Sxy150489 { 2080*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 20813526Sxy150489 unsigned i; 20823526Sxy150489 int res = 0; 20833526Sxy150489 20843526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 20853526Sxy150489 20863526Sxy150489 if ((multiaddr[0] & 01) == 0) { 20873526Sxy150489 res = EINVAL; 20883526Sxy150489 goto done; 20893526Sxy150489 } 20903526Sxy150489 20913526Sxy150489 if (Adapter->mcast_count >= MAX_NUM_MULTICAST_ADDRESSES) { 20923526Sxy150489 res = ENOENT; 20933526Sxy150489 goto done; 20943526Sxy150489 } 20953526Sxy150489 20963526Sxy150489 bcopy(multiaddr, 20973526Sxy150489 &Adapter->mcast_table[Adapter->mcast_count], ETHERADDRL); 20983526Sxy150489 Adapter->mcast_count++; 20993526Sxy150489 21003526Sxy150489 /* 21013526Sxy150489 * Update the MC table in the hardware 21023526Sxy150489 */ 2103*4919Sxy150489 e1000g_clear_interrupt(Adapter); 2104*4919Sxy150489 2105*4919Sxy150489 e1000g_setup_multicast(Adapter); 2106*4919Sxy150489 2107*4919Sxy150489 #ifndef NO_82542_SUPPORT 2108*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 2109*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) 2110*4919Sxy150489 e1000g_rx_setup(Adapter); 2111*4919Sxy150489 #endif 2112*4919Sxy150489 2113*4919Sxy150489 e1000g_mask_interrupt(Adapter); 21143526Sxy150489 21153526Sxy150489 done: 21163526Sxy150489 rw_exit(&Adapter->chip_lock); 21173526Sxy150489 return (res); 21183526Sxy150489 } 21193526Sxy150489 21203526Sxy150489 static int 21213526Sxy150489 multicst_remove(struct e1000g *Adapter, const uint8_t *multiaddr) 21223526Sxy150489 { 2123*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 21243526Sxy150489 unsigned i; 21253526Sxy150489 21263526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 21273526Sxy150489 21283526Sxy150489 for (i = 0; i < Adapter->mcast_count; i++) { 21293526Sxy150489 if (bcmp(multiaddr, &Adapter->mcast_table[i], 21303526Sxy150489 ETHERADDRL) == 0) { 21313526Sxy150489 for (i++; i < Adapter->mcast_count; i++) { 21323526Sxy150489 Adapter->mcast_table[i - 1] = 21333526Sxy150489 Adapter->mcast_table[i]; 21343526Sxy150489 } 21353526Sxy150489 Adapter->mcast_count--; 21363526Sxy150489 break; 21373526Sxy150489 } 21383526Sxy150489 } 21393526Sxy150489 21403526Sxy150489 /* 21413526Sxy150489 * Update the MC table in the hardware 21423526Sxy150489 */ 2143*4919Sxy150489 e1000g_clear_interrupt(Adapter); 2144*4919Sxy150489 2145*4919Sxy150489 e1000g_setup_multicast(Adapter); 2146*4919Sxy150489 2147*4919Sxy150489 #ifndef NO_82542_SUPPORT 2148*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 2149*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) 2150*4919Sxy150489 e1000g_rx_setup(Adapter); 2151*4919Sxy150489 #endif 2152*4919Sxy150489 2153*4919Sxy150489 e1000g_mask_interrupt(Adapter); 21543526Sxy150489 21553526Sxy150489 done: 21563526Sxy150489 rw_exit(&Adapter->chip_lock); 21573526Sxy150489 return (0); 21583526Sxy150489 } 21593526Sxy150489 2160*4919Sxy150489 /* 2161*4919Sxy150489 * e1000g_setup_multicast - setup multicast data structures 2162*4919Sxy150489 * 2163*4919Sxy150489 * This routine initializes all of the multicast related structures. 2164*4919Sxy150489 */ 2165*4919Sxy150489 void 2166*4919Sxy150489 e1000g_setup_multicast(struct e1000g *Adapter) 2167*4919Sxy150489 { 2168*4919Sxy150489 uint8_t *mc_addr_list; 2169*4919Sxy150489 uint32_t mc_addr_count; 2170*4919Sxy150489 uint32_t rctl; 2171*4919Sxy150489 struct e1000_hw *hw; 2172*4919Sxy150489 2173*4919Sxy150489 hw = &Adapter->shared; 2174*4919Sxy150489 2175*4919Sxy150489 /* 2176*4919Sxy150489 * The e1000g has the ability to do perfect filtering of 16 2177*4919Sxy150489 * addresses. The driver uses one of the e1000g's 16 receive 2178*4919Sxy150489 * address registers for its node/network/mac/individual address. 2179*4919Sxy150489 * So, we have room for up to 15 multicast addresses in the CAM, 2180*4919Sxy150489 * additional MC addresses are handled by the MTA (Multicast Table 2181*4919Sxy150489 * Array) 2182*4919Sxy150489 */ 2183*4919Sxy150489 2184*4919Sxy150489 rctl = E1000_READ_REG(hw, E1000_RCTL); 2185*4919Sxy150489 2186*4919Sxy150489 mc_addr_list = (uint8_t *)Adapter->mcast_table; 2187*4919Sxy150489 2188*4919Sxy150489 if (Adapter->mcast_count > MAX_NUM_MULTICAST_ADDRESSES) { 2189*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, CE_WARN, 2190*4919Sxy150489 "Adapter requested more than %d MC Addresses.\n", 2191*4919Sxy150489 MAX_NUM_MULTICAST_ADDRESSES); 2192*4919Sxy150489 mc_addr_count = MAX_NUM_MULTICAST_ADDRESSES; 2193*4919Sxy150489 } else { 2194*4919Sxy150489 /* 2195*4919Sxy150489 * Set the number of MC addresses that we are being 2196*4919Sxy150489 * requested to use 2197*4919Sxy150489 */ 2198*4919Sxy150489 mc_addr_count = Adapter->mcast_count; 2199*4919Sxy150489 } 2200*4919Sxy150489 #ifndef NO_82542_SUPPORT 2201*4919Sxy150489 /* 2202*4919Sxy150489 * The Wiseman 2.0 silicon has an errata by which the receiver will 2203*4919Sxy150489 * hang while writing to the receive address registers if the receiver 2204*4919Sxy150489 * is not in reset before writing to the registers. Updating the RAR 2205*4919Sxy150489 * is done during the setting up of the multicast table, hence the 2206*4919Sxy150489 * receiver has to be put in reset before updating the multicast table 2207*4919Sxy150489 * and then taken out of reset at the end 2208*4919Sxy150489 */ 2209*4919Sxy150489 /* 2210*4919Sxy150489 * if WMI was enabled then dis able it before issueing the global 2211*4919Sxy150489 * reset to the hardware. 2212*4919Sxy150489 */ 2213*4919Sxy150489 /* 2214*4919Sxy150489 * Only required for WISEMAN_2_0 2215*4919Sxy150489 */ 2216*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 2217*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 2218*4919Sxy150489 e1000_pci_clear_mwi(hw); 2219*4919Sxy150489 /* 2220*4919Sxy150489 * The e1000g must be in reset before changing any RA 2221*4919Sxy150489 * registers. Reset receive unit. The chip will remain in 2222*4919Sxy150489 * the reset state until software explicitly restarts it. 2223*4919Sxy150489 */ 2224*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST); 2225*4919Sxy150489 /* Allow receiver time to go in to reset */ 2226*4919Sxy150489 msec_delay(5); 2227*4919Sxy150489 } 2228*4919Sxy150489 #endif 2229*4919Sxy150489 2230*4919Sxy150489 e1000_mc_addr_list_update(hw, mc_addr_list, mc_addr_count, 2231*4919Sxy150489 Adapter->unicst_total, hw->mac.rar_entry_count); 2232*4919Sxy150489 2233*4919Sxy150489 #ifndef NO_82542_SUPPORT 2234*4919Sxy150489 /* 2235*4919Sxy150489 * Only for Wiseman_2_0 2236*4919Sxy150489 * If MWI was enabled then re-enable it after issueing (as we 2237*4919Sxy150489 * disabled it up there) the receive reset command. 2238*4919Sxy150489 * Wainwright does not have a receive reset command and only thing 2239*4919Sxy150489 * close to it is global reset which will require tx setup also 2240*4919Sxy150489 */ 2241*4919Sxy150489 if ((hw->mac.type == e1000_82542) && 2242*4919Sxy150489 (hw->revision_id == E1000_REVISION_2)) { 2243*4919Sxy150489 /* 2244*4919Sxy150489 * if WMI was enabled then reenable it after issueing the 2245*4919Sxy150489 * global or receive reset to the hardware. 2246*4919Sxy150489 */ 2247*4919Sxy150489 2248*4919Sxy150489 /* 2249*4919Sxy150489 * Take receiver out of reset 2250*4919Sxy150489 * clear E1000_RCTL_RST bit (and all others) 2251*4919Sxy150489 */ 2252*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0); 2253*4919Sxy150489 msec_delay(5); 2254*4919Sxy150489 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) 2255*4919Sxy150489 e1000_pci_set_mwi(hw); 2256*4919Sxy150489 } 2257*4919Sxy150489 #endif 2258*4919Sxy150489 2259*4919Sxy150489 /* 2260*4919Sxy150489 * Restore original value 2261*4919Sxy150489 */ 2262*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 2263*4919Sxy150489 } 2264*4919Sxy150489 22653526Sxy150489 int 22663526Sxy150489 e1000g_m_multicst(void *arg, boolean_t add, const uint8_t *addr) 22673526Sxy150489 { 22683526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 22693526Sxy150489 22703526Sxy150489 return ((add) ? multicst_add(Adapter, addr) 22714349Sxy150489 : multicst_remove(Adapter, addr)); 22723526Sxy150489 } 22733526Sxy150489 22743526Sxy150489 int 22753526Sxy150489 e1000g_m_promisc(void *arg, boolean_t on) 22763526Sxy150489 { 22773526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 2278*4919Sxy150489 uint32_t rctl; 22793526Sxy150489 22803526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 22813526Sxy150489 2282*4919Sxy150489 rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL); 22833526Sxy150489 22843526Sxy150489 if (on) 2285*4919Sxy150489 rctl |= 22863526Sxy150489 (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM); 22873526Sxy150489 else 2288*4919Sxy150489 rctl &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE)); 2289*4919Sxy150489 2290*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl); 22913526Sxy150489 22923526Sxy150489 Adapter->e1000g_promisc = on; 22933526Sxy150489 22943526Sxy150489 rw_exit(&Adapter->chip_lock); 22953526Sxy150489 22963526Sxy150489 return (0); 22973526Sxy150489 } 22983526Sxy150489 22993526Sxy150489 static boolean_t 23003526Sxy150489 e1000g_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 23013526Sxy150489 { 23023526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 2303*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 23043526Sxy150489 23053526Sxy150489 switch (cap) { 23063526Sxy150489 case MAC_CAPAB_HCKSUM: { 23073526Sxy150489 uint32_t *txflags = cap_data; 23083526Sxy150489 /* 23093526Sxy150489 * Checksum on/off selection via global parameters. 23103526Sxy150489 * 23113526Sxy150489 * If the chip is flagged as not capable of (correctly) 2312*4919Sxy150489 * handling checksumming, we don't enable it on either 23133526Sxy150489 * Rx or Tx side. Otherwise, we take this chip's settings 23143526Sxy150489 * from the patchable global defaults. 23153526Sxy150489 * 23163526Sxy150489 * We advertise our capabilities only if TX offload is 23173526Sxy150489 * enabled. On receive, the stack will accept checksummed 23183526Sxy150489 * packets anyway, even if we haven't said we can deliver 23193526Sxy150489 * them. 23203526Sxy150489 */ 2321*4919Sxy150489 switch (hw->mac.type) { 23223526Sxy150489 case e1000_82540: 2323*4919Sxy150489 case e1000_82544: 23243526Sxy150489 case e1000_82545: 2325*4919Sxy150489 case e1000_82545_rev_3: 2326*4919Sxy150489 case e1000_82546: 2327*4919Sxy150489 case e1000_82546_rev_3: 23283526Sxy150489 case e1000_82571: 23293526Sxy150489 case e1000_82572: 23303526Sxy150489 case e1000_82573: 23313526Sxy150489 case e1000_80003es2lan: 23323526Sxy150489 *txflags = HCKSUM_IPHDRCKSUM | HCKSUM_INET_PARTIAL; 23333526Sxy150489 break; 23343526Sxy150489 23353526Sxy150489 /* 2336*4919Sxy150489 * For the following Intel PRO/1000 chipsets, we have not 2337*4919Sxy150489 * tested the hardware checksum offload capability, so we 2338*4919Sxy150489 * disable the capability for them. 2339*4919Sxy150489 * e1000_82542, 23403526Sxy150489 * e1000_82543, 23413526Sxy150489 * e1000_82541, 23423526Sxy150489 * e1000_82541_rev_2, 23433526Sxy150489 * e1000_82547, 23443526Sxy150489 * e1000_82547_rev_2, 23453526Sxy150489 */ 23463526Sxy150489 default: 23473526Sxy150489 return (B_FALSE); 23483526Sxy150489 } 23493526Sxy150489 23503526Sxy150489 break; 23513526Sxy150489 } 23523526Sxy150489 case MAC_CAPAB_POLL: 23533526Sxy150489 /* 23543526Sxy150489 * There's nothing for us to fill in, simply returning 23553526Sxy150489 * B_TRUE stating that we support polling is sufficient. 23563526Sxy150489 */ 23573526Sxy150489 break; 23583526Sxy150489 23593526Sxy150489 case MAC_CAPAB_MULTIADDRESS: { 23603526Sxy150489 multiaddress_capab_t *mmacp = cap_data; 23613526Sxy150489 23623526Sxy150489 /* 23633526Sxy150489 * The number of MAC addresses made available by 23643526Sxy150489 * this capability is one less than the total as 23653526Sxy150489 * the primary address in slot 0 is counted in 23663526Sxy150489 * the total. 23673526Sxy150489 */ 23683526Sxy150489 mmacp->maddr_naddr = Adapter->unicst_total - 1; 23693526Sxy150489 mmacp->maddr_naddrfree = Adapter->unicst_avail; 23703526Sxy150489 /* No multiple factory addresses, set mma_flag to 0 */ 23713526Sxy150489 mmacp->maddr_flag = 0; 23723526Sxy150489 mmacp->maddr_handle = Adapter; 23733526Sxy150489 mmacp->maddr_add = e1000g_m_unicst_add; 23743526Sxy150489 mmacp->maddr_remove = e1000g_m_unicst_remove; 23753526Sxy150489 mmacp->maddr_modify = e1000g_m_unicst_modify; 23763526Sxy150489 mmacp->maddr_get = e1000g_m_unicst_get; 23773526Sxy150489 mmacp->maddr_reserve = NULL; 23783526Sxy150489 break; 23793526Sxy150489 } 23803526Sxy150489 default: 23813526Sxy150489 return (B_FALSE); 23823526Sxy150489 } 23833526Sxy150489 return (B_TRUE); 23843526Sxy150489 } 23853526Sxy150489 23863526Sxy150489 /* 2387*4919Sxy150489 * e1000g_get_conf - get configurations set in e1000g.conf 2388*4919Sxy150489 * 2389*4919Sxy150489 * This routine gets user-configured values out of the configuration 2390*4919Sxy150489 * file e1000g.conf. 2391*4919Sxy150489 * 2392*4919Sxy150489 * For each configurable value, there is a minimum, a maximum, and a 2393*4919Sxy150489 * default. 2394*4919Sxy150489 * If user does not configure a value, use the default. 2395*4919Sxy150489 * If user configures below the minimum, use the minumum. 2396*4919Sxy150489 * If user configures above the maximum, use the maxumum. 23973526Sxy150489 */ 23983526Sxy150489 static void 2399*4919Sxy150489 e1000g_get_conf(struct e1000g *Adapter) 24003526Sxy150489 { 2401*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 2402*4919Sxy150489 boolean_t tbi_compatibility = B_FALSE; 2403*4919Sxy150489 24043526Sxy150489 /* 24053526Sxy150489 * get each configurable property from e1000g.conf 24063526Sxy150489 */ 24073526Sxy150489 24083526Sxy150489 /* 24093526Sxy150489 * NumTxDescriptors 24103526Sxy150489 */ 2411*4919Sxy150489 Adapter->tx_desc_num = 2412*4919Sxy150489 e1000g_get_prop(Adapter, "NumTxDescriptors", 2413*4919Sxy150489 MIN_NUM_TX_DESCRIPTOR, MAX_NUM_TX_DESCRIPTOR, 2414*4919Sxy150489 DEFAULT_NUM_TX_DESCRIPTOR); 24153526Sxy150489 24163526Sxy150489 /* 24173526Sxy150489 * NumRxDescriptors 24183526Sxy150489 */ 2419*4919Sxy150489 Adapter->rx_desc_num = 2420*4919Sxy150489 e1000g_get_prop(Adapter, "NumRxDescriptors", 2421*4919Sxy150489 MIN_NUM_RX_DESCRIPTOR, MAX_NUM_RX_DESCRIPTOR, 2422*4919Sxy150489 DEFAULT_NUM_RX_DESCRIPTOR); 24233526Sxy150489 24243526Sxy150489 /* 24253526Sxy150489 * NumRxFreeList 24263526Sxy150489 */ 2427*4919Sxy150489 Adapter->rx_freelist_num = 2428*4919Sxy150489 e1000g_get_prop(Adapter, "NumRxFreeList", 2429*4919Sxy150489 MIN_NUM_RX_FREELIST, MAX_NUM_RX_FREELIST, 2430*4919Sxy150489 DEFAULT_NUM_RX_FREELIST); 24313526Sxy150489 24323526Sxy150489 /* 24333526Sxy150489 * NumTxPacketList 24343526Sxy150489 */ 2435*4919Sxy150489 Adapter->tx_freelist_num = 2436*4919Sxy150489 e1000g_get_prop(Adapter, "NumTxPacketList", 2437*4919Sxy150489 MIN_NUM_TX_FREELIST, MAX_NUM_TX_FREELIST, 2438*4919Sxy150489 DEFAULT_NUM_TX_FREELIST); 24393526Sxy150489 24403526Sxy150489 /* 24413526Sxy150489 * FlowControl 24423526Sxy150489 */ 2443*4919Sxy150489 hw->mac.fc_send_xon = B_TRUE; 2444*4919Sxy150489 hw->mac.fc = 2445*4919Sxy150489 e1000g_get_prop(Adapter, "FlowControl", 2446*4919Sxy150489 e1000_fc_none, 4, DEFAULT_FLOW_CONTROL); 24473526Sxy150489 /* 4 is the setting that says "let the eeprom decide" */ 2448*4919Sxy150489 if (hw->mac.fc == 4) 2449*4919Sxy150489 hw->mac.fc = e1000_fc_default; 24503526Sxy150489 24513526Sxy150489 /* 2452*4919Sxy150489 * Max Num Receive Packets on Interrupt 24533526Sxy150489 */ 2454*4919Sxy150489 Adapter->rx_limit_onintr = 2455*4919Sxy150489 e1000g_get_prop(Adapter, "MaxNumReceivePackets", 2456*4919Sxy150489 MIN_RX_LIMIT_ON_INTR, MAX_RX_LIMIT_ON_INTR, 2457*4919Sxy150489 DEFAULT_RX_LIMIT_ON_INTR); 24583526Sxy150489 24593526Sxy150489 /* 24603526Sxy150489 * PHY master slave setting 24613526Sxy150489 */ 2462*4919Sxy150489 hw->phy.ms_type = 2463*4919Sxy150489 e1000g_get_prop(Adapter, "SetMasterSlave", 24643526Sxy150489 e1000_ms_hw_default, e1000_ms_auto, 24653526Sxy150489 e1000_ms_hw_default); 24663526Sxy150489 24673526Sxy150489 /* 24683526Sxy150489 * Parameter which controls TBI mode workaround, which is only 24693526Sxy150489 * needed on certain switches such as Cisco 6500/Foundry 24703526Sxy150489 */ 2471*4919Sxy150489 tbi_compatibility = 2472*4919Sxy150489 e1000g_get_prop(Adapter, "TbiCompatibilityEnable", 2473*4919Sxy150489 0, 1, DEFAULT_TBI_COMPAT_ENABLE); 2474*4919Sxy150489 e1000_set_tbi_compatibility_82543(hw, tbi_compatibility); 24753526Sxy150489 24763526Sxy150489 /* 24773526Sxy150489 * MSI Enable 24783526Sxy150489 */ 24793526Sxy150489 Adapter->msi_enabled = 2480*4919Sxy150489 e1000g_get_prop(Adapter, "MSIEnable", 2481*4919Sxy150489 0, 1, DEFAULT_MSI_ENABLE); 24823526Sxy150489 24833526Sxy150489 /* 24843526Sxy150489 * Interrupt Throttling Rate 24853526Sxy150489 */ 24863526Sxy150489 Adapter->intr_throttling_rate = 2487*4919Sxy150489 e1000g_get_prop(Adapter, "intr_throttling_rate", 2488*4919Sxy150489 MIN_INTR_THROTTLING, MAX_INTR_THROTTLING, 2489*4919Sxy150489 DEFAULT_INTR_THROTTLING); 24903526Sxy150489 24913526Sxy150489 /* 24923526Sxy150489 * Adaptive Interrupt Blanking Enable/Disable 24933526Sxy150489 * It is enabled by default 24943526Sxy150489 */ 24953526Sxy150489 Adapter->intr_adaptive = 2496*4919Sxy150489 (e1000g_get_prop(Adapter, "intr_adaptive", 0, 1, 1) == 1) ? 24973526Sxy150489 B_TRUE : B_FALSE; 24983526Sxy150489 } 24993526Sxy150489 25003526Sxy150489 /* 2501*4919Sxy150489 * e1000g_get_prop - routine to read properties 2502*4919Sxy150489 * 2503*4919Sxy150489 * Get a user-configure property value out of the configuration 2504*4919Sxy150489 * file e1000g.conf. 2505*4919Sxy150489 * 2506*4919Sxy150489 * Caller provides name of the property, a default value, a minimum 2507*4919Sxy150489 * value, and a maximum value. 2508*4919Sxy150489 * 2509*4919Sxy150489 * Return configured value of the property, with default, minimum and 2510*4919Sxy150489 * maximum properly applied. 25113526Sxy150489 */ 25123526Sxy150489 static int 2513*4919Sxy150489 e1000g_get_prop(struct e1000g *Adapter, /* point to per-adapter structure */ 25143526Sxy150489 char *propname, /* name of the property */ 25153526Sxy150489 int minval, /* minimum acceptable value */ 25163526Sxy150489 int maxval, /* maximim acceptable value */ 25173526Sxy150489 int defval) /* default value */ 25183526Sxy150489 { 25193526Sxy150489 int propval; /* value returned for requested property */ 25203526Sxy150489 int *props; /* point to array of properties returned */ 25213526Sxy150489 uint_t nprops; /* number of property value returned */ 25223526Sxy150489 25233526Sxy150489 /* 25243526Sxy150489 * get the array of properties from the config file 25253526Sxy150489 */ 25263526Sxy150489 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, Adapter->dip, 25273526Sxy150489 DDI_PROP_DONTPASS, propname, &props, &nprops) == DDI_PROP_SUCCESS) { 25283526Sxy150489 /* got some properties, test if we got enough */ 2529*4919Sxy150489 if (Adapter->instance < nprops) { 2530*4919Sxy150489 propval = props[Adapter->instance]; 25313526Sxy150489 } else { 25323526Sxy150489 /* not enough properties configured */ 25333526Sxy150489 propval = defval; 2534*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 25353526Sxy150489 "Not Enough %s values found in e1000g.conf" 25363526Sxy150489 " - set to %d\n", 25373526Sxy150489 propname, propval); 25383526Sxy150489 } 25393526Sxy150489 25403526Sxy150489 /* free memory allocated for properties */ 25413526Sxy150489 ddi_prop_free(props); 25423526Sxy150489 25433526Sxy150489 } else { 25443526Sxy150489 propval = defval; 25453526Sxy150489 } 25463526Sxy150489 25473526Sxy150489 /* 25483526Sxy150489 * enforce limits 25493526Sxy150489 */ 25503526Sxy150489 if (propval > maxval) { 25513526Sxy150489 propval = maxval; 2552*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 25533526Sxy150489 "Too High %s value in e1000g.conf - set to %d\n", 25543526Sxy150489 propname, propval); 25553526Sxy150489 } 25563526Sxy150489 25573526Sxy150489 if (propval < minval) { 25583526Sxy150489 propval = minval; 2559*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL, 25603526Sxy150489 "Too Low %s value in e1000g.conf - set to %d\n", 25613526Sxy150489 propname, propval); 25623526Sxy150489 } 25633526Sxy150489 25643526Sxy150489 return (propval); 25653526Sxy150489 } 25663526Sxy150489 25673526Sxy150489 static boolean_t 25684061Sxy150489 e1000g_link_check(struct e1000g *Adapter) 25693526Sxy150489 { 25704061Sxy150489 uint16_t speed, duplex, phydata; 25714061Sxy150489 boolean_t link_changed = B_FALSE; 25723526Sxy150489 struct e1000_hw *hw; 25733526Sxy150489 uint32_t reg_tarc; 25743526Sxy150489 2575*4919Sxy150489 hw = &Adapter->shared; 25763526Sxy150489 25773526Sxy150489 if (e1000g_link_up(Adapter)) { 25783526Sxy150489 /* 25793526Sxy150489 * The Link is up, check whether it was marked as down earlier 25803526Sxy150489 */ 25814061Sxy150489 if (Adapter->link_state != LINK_STATE_UP) { 25824061Sxy150489 e1000_get_speed_and_duplex(hw, &speed, &duplex); 25834061Sxy150489 Adapter->link_speed = speed; 25844061Sxy150489 Adapter->link_duplex = duplex; 25854061Sxy150489 Adapter->link_state = LINK_STATE_UP; 25864061Sxy150489 link_changed = B_TRUE; 25874061Sxy150489 25884061Sxy150489 Adapter->tx_link_down_timeout = 0; 25894061Sxy150489 2590*4919Sxy150489 if ((hw->mac.type == e1000_82571) || 2591*4919Sxy150489 (hw->mac.type == e1000_82572)) { 2592*4919Sxy150489 reg_tarc = E1000_READ_REG(hw, E1000_TARC0); 25934061Sxy150489 if (speed == SPEED_1000) 25944061Sxy150489 reg_tarc |= (1 << 21); 25954061Sxy150489 else 25964061Sxy150489 reg_tarc &= ~(1 << 21); 2597*4919Sxy150489 E1000_WRITE_REG(hw, E1000_TARC0, reg_tarc); 25983526Sxy150489 } 25993526Sxy150489 } 26003526Sxy150489 Adapter->smartspeed = 0; 26013526Sxy150489 } else { 26024061Sxy150489 if (Adapter->link_state != LINK_STATE_DOWN) { 26033526Sxy150489 Adapter->link_speed = 0; 26043526Sxy150489 Adapter->link_duplex = 0; 26054061Sxy150489 Adapter->link_state = LINK_STATE_DOWN; 26064061Sxy150489 link_changed = B_TRUE; 26074061Sxy150489 26083526Sxy150489 /* 26093526Sxy150489 * SmartSpeed workaround for Tabor/TanaX, When the 26103526Sxy150489 * driver loses link disable auto master/slave 26113526Sxy150489 * resolution. 26123526Sxy150489 */ 2613*4919Sxy150489 if (hw->phy.type == e1000_phy_igp) { 26143526Sxy150489 e1000_read_phy_reg(hw, 26153526Sxy150489 PHY_1000T_CTRL, &phydata); 26163526Sxy150489 phydata |= CR_1000T_MS_ENABLE; 26173526Sxy150489 e1000_write_phy_reg(hw, 26183526Sxy150489 PHY_1000T_CTRL, phydata); 26193526Sxy150489 } 26203526Sxy150489 } else { 26213526Sxy150489 e1000g_smartspeed(Adapter); 26223526Sxy150489 } 26234061Sxy150489 26244061Sxy150489 if (Adapter->started) { 26254061Sxy150489 if (Adapter->tx_link_down_timeout < 26264061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) { 26274061Sxy150489 Adapter->tx_link_down_timeout++; 26284061Sxy150489 } else if (Adapter->tx_link_down_timeout == 26294061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) { 26304061Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER); 2631*4919Sxy150489 e1000g_tx_clean(Adapter); 26324061Sxy150489 rw_exit(&Adapter->chip_lock); 26334061Sxy150489 Adapter->tx_link_down_timeout++; 26344061Sxy150489 } 26354061Sxy150489 } 26363526Sxy150489 } 26373526Sxy150489 26384061Sxy150489 return (link_changed); 26394061Sxy150489 } 26404061Sxy150489 26414061Sxy150489 static void 2642*4919Sxy150489 e1000g_local_timer(void *ws) 26434061Sxy150489 { 26444061Sxy150489 struct e1000g *Adapter = (struct e1000g *)ws; 26454061Sxy150489 struct e1000_hw *hw; 26464061Sxy150489 e1000g_ether_addr_t ether_addr; 26474061Sxy150489 boolean_t link_changed; 26484061Sxy150489 2649*4919Sxy150489 hw = &Adapter->shared; 2650*4919Sxy150489 2651*4919Sxy150489 (void) e1000g_tx_freemsg(Adapter->tx_ring); 26524061Sxy150489 26534061Sxy150489 if (e1000g_stall_check(Adapter)) { 2654*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 26554061Sxy150489 "Tx stall detected. Activate automatic recovery.\n"); 26564061Sxy150489 Adapter->reset_count++; 26574061Sxy150489 (void) e1000g_reset(Adapter); 26584061Sxy150489 } 26594061Sxy150489 26604061Sxy150489 link_changed = B_FALSE; 2661*4919Sxy150489 mutex_enter(&Adapter->link_lock); 26624061Sxy150489 if (Adapter->link_complete) 26634061Sxy150489 link_changed = e1000g_link_check(Adapter); 2664*4919Sxy150489 mutex_exit(&Adapter->link_lock); 26654061Sxy150489 26664139Sxy150489 if (link_changed) { 26674139Sxy150489 /* 26684139Sxy150489 * Workaround for esb2. Data stuck in fifo on a link 26694139Sxy150489 * down event. Reset the adapter to recover it. 26704139Sxy150489 */ 26714139Sxy150489 if ((Adapter->link_state == LINK_STATE_DOWN) && 2672*4919Sxy150489 (hw->mac.type == e1000_80003es2lan)) 26734139Sxy150489 (void) e1000g_reset(Adapter); 26744139Sxy150489 26754061Sxy150489 mac_link_update(Adapter->mh, Adapter->link_state); 26764139Sxy150489 } 26774061Sxy150489 26783526Sxy150489 /* 26793526Sxy150489 * With 82571 controllers, any locally administered address will 26803526Sxy150489 * be overwritten when there is a reset on the other port. 26813526Sxy150489 * Detect this circumstance and correct it. 26823526Sxy150489 */ 2683*4919Sxy150489 if ((hw->mac.type == e1000_82571) && 2684*4919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) { 2685*4919Sxy150489 ether_addr.reg.low = E1000_READ_REG_ARRAY(hw, E1000_RA, 0); 2686*4919Sxy150489 ether_addr.reg.high = E1000_READ_REG_ARRAY(hw, E1000_RA, 1); 26873526Sxy150489 26883526Sxy150489 ether_addr.reg.low = ntohl(ether_addr.reg.low); 26893526Sxy150489 ether_addr.reg.high = ntohl(ether_addr.reg.high); 26903526Sxy150489 2691*4919Sxy150489 if ((ether_addr.mac.addr[5] != hw->mac.addr[0]) || 2692*4919Sxy150489 (ether_addr.mac.addr[4] != hw->mac.addr[1]) || 2693*4919Sxy150489 (ether_addr.mac.addr[3] != hw->mac.addr[2]) || 2694*4919Sxy150489 (ether_addr.mac.addr[2] != hw->mac.addr[3]) || 2695*4919Sxy150489 (ether_addr.mac.addr[1] != hw->mac.addr[4]) || 2696*4919Sxy150489 (ether_addr.mac.addr[0] != hw->mac.addr[5])) { 2697*4919Sxy150489 e1000_rar_set(hw, hw->mac.addr, 0); 26983526Sxy150489 } 26993526Sxy150489 } 27003526Sxy150489 27013526Sxy150489 /* 2702*4919Sxy150489 * Long TTL workaround for 82541/82547 27033526Sxy150489 */ 2704*4919Sxy150489 e1000_igp_ttl_workaround_82547(hw); 27053526Sxy150489 27063526Sxy150489 /* 27073526Sxy150489 * Check for Adaptive IFS settings If there are lots of collisions 27083526Sxy150489 * change the value in steps... 27093526Sxy150489 * These properties should only be set for 10/100 27103526Sxy150489 */ 27113526Sxy150489 if ((hw->media_type == e1000_media_type_copper) && 27124061Sxy150489 ((Adapter->link_speed == SPEED_100) || 27134061Sxy150489 (Adapter->link_speed == SPEED_10))) { 27143526Sxy150489 e1000_update_adaptive(hw); 27153526Sxy150489 } 27163526Sxy150489 /* 27173526Sxy150489 * Set Timer Interrupts 27183526Sxy150489 */ 2719*4919Sxy150489 E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0); 2720*4919Sxy150489 2721*4919Sxy150489 restart_watchdog_timer(Adapter); 27223526Sxy150489 } 27233526Sxy150489 27244061Sxy150489 /* 27254061Sxy150489 * The function e1000g_link_timer() is called when the timer for link setup 27264061Sxy150489 * is expired, which indicates the completion of the link setup. The link 27274061Sxy150489 * state will not be updated until the link setup is completed. And the 27284061Sxy150489 * link state will not be sent to the upper layer through mac_link_update() 27294061Sxy150489 * in this function. It will be updated in the local timer routine or the 27304061Sxy150489 * interrupt service routine after the interface is started (plumbed). 27314061Sxy150489 */ 27323526Sxy150489 static void 27334061Sxy150489 e1000g_link_timer(void *arg) 27343526Sxy150489 { 27354061Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg; 27363526Sxy150489 2737*4919Sxy150489 mutex_enter(&Adapter->link_lock); 27384061Sxy150489 Adapter->link_complete = B_TRUE; 27394061Sxy150489 Adapter->link_tid = 0; 2740*4919Sxy150489 mutex_exit(&Adapter->link_lock); 27413526Sxy150489 } 27423526Sxy150489 27433526Sxy150489 /* 2744*4919Sxy150489 * e1000g_force_speed_duplex - read forced speed/duplex out of e1000g.conf 2745*4919Sxy150489 * 2746*4919Sxy150489 * This function read the forced speed and duplex for 10/100 Mbps speeds 2747*4919Sxy150489 * and also for 1000 Mbps speeds from the e1000g.conf file 27483526Sxy150489 */ 27493526Sxy150489 static void 27503526Sxy150489 e1000g_force_speed_duplex(struct e1000g *Adapter) 27513526Sxy150489 { 27523526Sxy150489 int forced; 2753*4919Sxy150489 struct e1000_mac_info *mac = &Adapter->shared.mac; 2754*4919Sxy150489 struct e1000_phy_info *phy = &Adapter->shared.phy; 27553526Sxy150489 27563526Sxy150489 /* 27573526Sxy150489 * get value out of config file 27583526Sxy150489 */ 2759*4919Sxy150489 forced = e1000g_get_prop(Adapter, "ForceSpeedDuplex", 27603526Sxy150489 GDIAG_10_HALF, GDIAG_ANY, GDIAG_ANY); 27613526Sxy150489 27623526Sxy150489 switch (forced) { 27633526Sxy150489 case GDIAG_10_HALF: 27643526Sxy150489 /* 27653526Sxy150489 * Disable Auto Negotiation 27663526Sxy150489 */ 2767*4919Sxy150489 mac->autoneg = B_FALSE; 2768*4919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_HALF; 27693526Sxy150489 break; 27703526Sxy150489 case GDIAG_10_FULL: 27713526Sxy150489 /* 27723526Sxy150489 * Disable Auto Negotiation 27733526Sxy150489 */ 2774*4919Sxy150489 mac->autoneg = B_FALSE; 2775*4919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_FULL; 27763526Sxy150489 break; 27773526Sxy150489 case GDIAG_100_HALF: 27783526Sxy150489 /* 27793526Sxy150489 * Disable Auto Negotiation 27803526Sxy150489 */ 2781*4919Sxy150489 mac->autoneg = B_FALSE; 2782*4919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_HALF; 27833526Sxy150489 break; 27843526Sxy150489 case GDIAG_100_FULL: 27853526Sxy150489 /* 27863526Sxy150489 * Disable Auto Negotiation 27873526Sxy150489 */ 2788*4919Sxy150489 mac->autoneg = B_FALSE; 2789*4919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_FULL; 27903526Sxy150489 break; 27913526Sxy150489 case GDIAG_1000_FULL: 27923526Sxy150489 /* 27933526Sxy150489 * The gigabit spec requires autonegotiation. Therefore, 27943526Sxy150489 * when the user wants to force the speed to 1000Mbps, we 27953526Sxy150489 * enable AutoNeg, but only allow the harware to advertise 27963526Sxy150489 * 1000Mbps. This is different from 10/100 operation, where 27973526Sxy150489 * we are allowed to link without any negotiation. 27983526Sxy150489 */ 2799*4919Sxy150489 mac->autoneg = B_TRUE; 2800*4919Sxy150489 phy->autoneg_advertised = ADVERTISE_1000_FULL; 28013526Sxy150489 break; 28023526Sxy150489 default: /* obey the setting of AutoNegAdvertised */ 2803*4919Sxy150489 mac->autoneg = B_TRUE; 2804*4919Sxy150489 phy->autoneg_advertised = 2805*4919Sxy150489 (uint16_t)e1000g_get_prop(Adapter, "AutoNegAdvertised", 28064349Sxy150489 0, AUTONEG_ADVERTISE_SPEED_DEFAULT, 28074349Sxy150489 AUTONEG_ADVERTISE_SPEED_DEFAULT); 28083526Sxy150489 break; 28093526Sxy150489 } /* switch */ 28103526Sxy150489 } 28113526Sxy150489 28123526Sxy150489 /* 2813*4919Sxy150489 * e1000g_get_max_frame_size - get jumbo frame setting from e1000g.conf 2814*4919Sxy150489 * 2815*4919Sxy150489 * This function reads MaxFrameSize from e1000g.conf 28163526Sxy150489 */ 28173526Sxy150489 static void 28183526Sxy150489 e1000g_get_max_frame_size(struct e1000g *Adapter) 28193526Sxy150489 { 28203526Sxy150489 int max_frame; 2821*4919Sxy150489 struct e1000_mac_info *mac = &Adapter->shared.mac; 2822*4919Sxy150489 struct e1000_phy_info *phy = &Adapter->shared.phy; 28233526Sxy150489 28243526Sxy150489 /* 28253526Sxy150489 * get value out of config file 28263526Sxy150489 */ 2827*4919Sxy150489 max_frame = e1000g_get_prop(Adapter, "MaxFrameSize", 0, 3, 0); 28283526Sxy150489 28293526Sxy150489 switch (max_frame) { 28303526Sxy150489 case 0: 2831*4919Sxy150489 mac->max_frame_size = ETHERMAX; 28323526Sxy150489 break; 28333526Sxy150489 case 1: 2834*4919Sxy150489 mac->max_frame_size = FRAME_SIZE_UPTO_4K; 28353526Sxy150489 break; 28363526Sxy150489 case 2: 2837*4919Sxy150489 mac->max_frame_size = FRAME_SIZE_UPTO_8K; 28383526Sxy150489 break; 28393526Sxy150489 case 3: 2840*4919Sxy150489 if (mac->type < e1000_82571) 2841*4919Sxy150489 mac->max_frame_size = FRAME_SIZE_UPTO_16K; 28423526Sxy150489 else 2843*4919Sxy150489 mac->max_frame_size = FRAME_SIZE_UPTO_9K; 28443526Sxy150489 break; 28453526Sxy150489 default: 2846*4919Sxy150489 mac->max_frame_size = ETHERMAX; 28473526Sxy150489 break; 28483526Sxy150489 } /* switch */ 28493526Sxy150489 28503526Sxy150489 /* ich8 does not do jumbo frames */ 2851*4919Sxy150489 if (mac->type == e1000_ich8lan) { 2852*4919Sxy150489 mac->max_frame_size = ETHERMAX; 2853*4919Sxy150489 } 2854*4919Sxy150489 2855*4919Sxy150489 /* ich9 does not do jumbo frames on one phy type */ 2856*4919Sxy150489 if ((mac->type == e1000_ich9lan) && 2857*4919Sxy150489 (phy->type == e1000_phy_ife)) { 2858*4919Sxy150489 mac->max_frame_size = ETHERMAX; 28593526Sxy150489 } 28603526Sxy150489 } 28613526Sxy150489 28623526Sxy150489 static void 2863*4919Sxy150489 arm_watchdog_timer(struct e1000g *Adapter) 28643526Sxy150489 { 2865*4919Sxy150489 Adapter->watchdog_tid = 2866*4919Sxy150489 timeout(e1000g_local_timer, 28673526Sxy150489 (void *)Adapter, 1 * drv_usectohz(1000000)); 28683526Sxy150489 } 2869*4919Sxy150489 #pragma inline(arm_watchdog_timer) 2870*4919Sxy150489 2871*4919Sxy150489 static void 2872*4919Sxy150489 enable_watchdog_timer(struct e1000g *Adapter) 2873*4919Sxy150489 { 2874*4919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 2875*4919Sxy150489 2876*4919Sxy150489 if (!Adapter->watchdog_timer_enabled) { 2877*4919Sxy150489 Adapter->watchdog_timer_enabled = B_TRUE; 2878*4919Sxy150489 Adapter->watchdog_timer_started = B_TRUE; 2879*4919Sxy150489 arm_watchdog_timer(Adapter); 2880*4919Sxy150489 } 2881*4919Sxy150489 2882*4919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 2883*4919Sxy150489 } 28843526Sxy150489 28853526Sxy150489 static void 2886*4919Sxy150489 disable_watchdog_timer(struct e1000g *Adapter) 28873526Sxy150489 { 28883526Sxy150489 timeout_id_t tid; 28893526Sxy150489 2890*4919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 2891*4919Sxy150489 2892*4919Sxy150489 Adapter->watchdog_timer_enabled = B_FALSE; 2893*4919Sxy150489 Adapter->watchdog_timer_started = B_FALSE; 2894*4919Sxy150489 tid = Adapter->watchdog_tid; 2895*4919Sxy150489 Adapter->watchdog_tid = 0; 2896*4919Sxy150489 2897*4919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 28983526Sxy150489 28993526Sxy150489 if (tid != 0) 29003526Sxy150489 (void) untimeout(tid); 29013526Sxy150489 } 29023526Sxy150489 29033526Sxy150489 static void 2904*4919Sxy150489 start_watchdog_timer(struct e1000g *Adapter) 29053526Sxy150489 { 2906*4919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 2907*4919Sxy150489 2908*4919Sxy150489 if (Adapter->watchdog_timer_enabled) { 2909*4919Sxy150489 if (!Adapter->watchdog_timer_started) { 2910*4919Sxy150489 Adapter->watchdog_timer_started = B_TRUE; 2911*4919Sxy150489 arm_watchdog_timer(Adapter); 29123526Sxy150489 } 29133526Sxy150489 } 29143526Sxy150489 2915*4919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 2916*4919Sxy150489 } 2917*4919Sxy150489 2918*4919Sxy150489 static void 2919*4919Sxy150489 restart_watchdog_timer(struct e1000g *Adapter) 2920*4919Sxy150489 { 2921*4919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 2922*4919Sxy150489 2923*4919Sxy150489 if (Adapter->watchdog_timer_started) 2924*4919Sxy150489 arm_watchdog_timer(Adapter); 2925*4919Sxy150489 2926*4919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 29273526Sxy150489 } 29283526Sxy150489 29293526Sxy150489 static void 2930*4919Sxy150489 stop_watchdog_timer(struct e1000g *Adapter) 29313526Sxy150489 { 2932*4919Sxy150489 timeout_id_t tid; 2933*4919Sxy150489 2934*4919Sxy150489 mutex_enter(&Adapter->watchdog_lock); 2935*4919Sxy150489 2936*4919Sxy150489 Adapter->watchdog_timer_started = B_FALSE; 2937*4919Sxy150489 tid = Adapter->watchdog_tid; 2938*4919Sxy150489 Adapter->watchdog_tid = 0; 2939*4919Sxy150489 2940*4919Sxy150489 mutex_exit(&Adapter->watchdog_lock); 2941*4919Sxy150489 2942*4919Sxy150489 if (tid != 0) 2943*4919Sxy150489 (void) untimeout(tid); 29443526Sxy150489 } 29453526Sxy150489 29463526Sxy150489 static void 2947*4919Sxy150489 stop_link_timer(struct e1000g *Adapter) 29483526Sxy150489 { 29493526Sxy150489 timeout_id_t tid; 29503526Sxy150489 2951*4919Sxy150489 /* Disable the link timer */ 2952*4919Sxy150489 mutex_enter(&Adapter->link_lock); 2953*4919Sxy150489 2954*4919Sxy150489 tid = Adapter->link_tid; 2955*4919Sxy150489 Adapter->link_tid = 0; 2956*4919Sxy150489 2957*4919Sxy150489 mutex_exit(&Adapter->link_lock); 2958*4919Sxy150489 2959*4919Sxy150489 if (tid != 0) 2960*4919Sxy150489 (void) untimeout(tid); 2961*4919Sxy150489 } 2962*4919Sxy150489 2963*4919Sxy150489 static void 2964*4919Sxy150489 stop_82547_timer(e1000g_tx_ring_t *tx_ring) 2965*4919Sxy150489 { 2966*4919Sxy150489 timeout_id_t tid; 2967*4919Sxy150489 2968*4919Sxy150489 /* Disable the tx timer for 82547 chipset */ 2969*4919Sxy150489 mutex_enter(&tx_ring->tx_lock); 2970*4919Sxy150489 2971*4919Sxy150489 tx_ring->timer_enable_82547 = B_FALSE; 2972*4919Sxy150489 tid = tx_ring->timer_id_82547; 2973*4919Sxy150489 tx_ring->timer_id_82547 = 0; 2974*4919Sxy150489 2975*4919Sxy150489 mutex_exit(&tx_ring->tx_lock); 29763526Sxy150489 29773526Sxy150489 if (tid != 0) 29783526Sxy150489 (void) untimeout(tid); 29793526Sxy150489 } 29803526Sxy150489 29813526Sxy150489 void 2982*4919Sxy150489 e1000g_clear_interrupt(struct e1000g *Adapter) 29833526Sxy150489 { 2984*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 2985*4919Sxy150489 0xffffffff & ~E1000_IMS_RXSEQ); 29863526Sxy150489 } 29873526Sxy150489 29883526Sxy150489 void 2989*4919Sxy150489 e1000g_mask_interrupt(struct e1000g *Adapter) 29903526Sxy150489 { 2991*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, 29923526Sxy150489 IMS_ENABLE_MASK & ~E1000_IMS_TXDW & ~E1000_IMS_TXQE); 29933526Sxy150489 } 29943526Sxy150489 29953526Sxy150489 void 2996*4919Sxy150489 e1000g_clear_all_interrupts(struct e1000g *Adapter) 29973526Sxy150489 { 2998*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 0xffffffff); 29993526Sxy150489 } 30003526Sxy150489 30013526Sxy150489 void 3002*4919Sxy150489 e1000g_mask_tx_interrupt(struct e1000g *Adapter) 30033526Sxy150489 { 3004*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, E1000G_IMS_TX_INTR); 30053526Sxy150489 } 30063526Sxy150489 30073526Sxy150489 void 3008*4919Sxy150489 e1000g_clear_tx_interrupt(struct e1000g *Adapter) 30093526Sxy150489 { 3010*4919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, E1000G_IMS_TX_INTR); 30113526Sxy150489 } 30123526Sxy150489 30133526Sxy150489 static void 3014*4919Sxy150489 e1000g_smartspeed(struct e1000g *Adapter) 30153526Sxy150489 { 3016*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 30173526Sxy150489 uint16_t phy_status; 30183526Sxy150489 uint16_t phy_ctrl; 30193526Sxy150489 30203526Sxy150489 /* 30213526Sxy150489 * If we're not T-or-T, or we're not autoneg'ing, or we're not 30223526Sxy150489 * advertising 1000Full, we don't even use the workaround 30233526Sxy150489 */ 3024*4919Sxy150489 if ((hw->phy.type != e1000_phy_igp) || 3025*4919Sxy150489 !hw->mac.autoneg || 3026*4919Sxy150489 !(hw->phy.autoneg_advertised & ADVERTISE_1000_FULL)) 30273526Sxy150489 return; 30283526Sxy150489 30293526Sxy150489 /* 30303526Sxy150489 * True if this is the first call of this function or after every 30313526Sxy150489 * 30 seconds of not having link 30323526Sxy150489 */ 3033*4919Sxy150489 if (Adapter->smartspeed == 0) { 30343526Sxy150489 /* 30353526Sxy150489 * If Master/Slave config fault is asserted twice, we 30363526Sxy150489 * assume back-to-back 30373526Sxy150489 */ 3038*4919Sxy150489 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 30393526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 30403526Sxy150489 return; 30413526Sxy150489 3042*4919Sxy150489 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); 30433526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) 30443526Sxy150489 return; 30453526Sxy150489 /* 30463526Sxy150489 * We're assuming back-2-back because our status register 30473526Sxy150489 * insists! there's a fault in the master/slave 30483526Sxy150489 * relationship that was "negotiated" 30493526Sxy150489 */ 3050*4919Sxy150489 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 30513526Sxy150489 /* 30523526Sxy150489 * Is the phy configured for manual configuration of 30533526Sxy150489 * master/slave? 30543526Sxy150489 */ 30553526Sxy150489 if (phy_ctrl & CR_1000T_MS_ENABLE) { 30563526Sxy150489 /* 30573526Sxy150489 * Yes. Then disable manual configuration (enable 30583526Sxy150489 * auto configuration) of master/slave 30593526Sxy150489 */ 30603526Sxy150489 phy_ctrl &= ~CR_1000T_MS_ENABLE; 3061*4919Sxy150489 e1000_write_phy_reg(hw, 30623526Sxy150489 PHY_1000T_CTRL, phy_ctrl); 30633526Sxy150489 /* 30643526Sxy150489 * Effectively starting the clock 30653526Sxy150489 */ 3066*4919Sxy150489 Adapter->smartspeed++; 30673526Sxy150489 /* 30683526Sxy150489 * Restart autonegotiation 30693526Sxy150489 */ 3070*4919Sxy150489 if (!e1000_phy_setup_autoneg(hw) && 3071*4919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 30723526Sxy150489 phy_ctrl |= (MII_CR_AUTO_NEG_EN | 30733526Sxy150489 MII_CR_RESTART_AUTO_NEG); 3074*4919Sxy150489 e1000_write_phy_reg(hw, 3075*4919Sxy150489 PHY_CONTROL, phy_ctrl); 30763526Sxy150489 } 30773526Sxy150489 } 30783526Sxy150489 return; 30793526Sxy150489 /* 30803526Sxy150489 * Has 6 seconds transpired still without link? Remember, 30813526Sxy150489 * you should reset the smartspeed counter once you obtain 30823526Sxy150489 * link 30833526Sxy150489 */ 3084*4919Sxy150489 } else if (Adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { 30853526Sxy150489 /* 30863526Sxy150489 * Yes. Remember, we did at the start determine that 30873526Sxy150489 * there's a master/slave configuration fault, so we're 30883526Sxy150489 * still assuming there's someone on the other end, but we 30893526Sxy150489 * just haven't yet been able to talk to it. We then 30903526Sxy150489 * re-enable auto configuration of master/slave to see if 30913526Sxy150489 * we're running 2/3 pair cables. 30923526Sxy150489 */ 30933526Sxy150489 /* 30943526Sxy150489 * If still no link, perhaps using 2/3 pair cable 30953526Sxy150489 */ 3096*4919Sxy150489 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); 30973526Sxy150489 phy_ctrl |= CR_1000T_MS_ENABLE; 3098*4919Sxy150489 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); 30993526Sxy150489 /* 31003526Sxy150489 * Restart autoneg with phy enabled for manual 31013526Sxy150489 * configuration of master/slave 31023526Sxy150489 */ 3103*4919Sxy150489 if (!e1000_phy_setup_autoneg(hw) && 3104*4919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) { 31053526Sxy150489 phy_ctrl |= 31063526Sxy150489 (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); 3107*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl); 31083526Sxy150489 } 31093526Sxy150489 /* 31103526Sxy150489 * Hopefully, there are no more faults and we've obtained 31113526Sxy150489 * link as a result. 31123526Sxy150489 */ 31133526Sxy150489 } 31143526Sxy150489 /* 31153526Sxy150489 * Restart process after E1000_SMARTSPEED_MAX iterations (30 31163526Sxy150489 * seconds) 31173526Sxy150489 */ 3118*4919Sxy150489 if (Adapter->smartspeed++ == E1000_SMARTSPEED_MAX) 3119*4919Sxy150489 Adapter->smartspeed = 0; 31203526Sxy150489 } 31213526Sxy150489 31223526Sxy150489 static boolean_t 31233526Sxy150489 is_valid_mac_addr(uint8_t *mac_addr) 31243526Sxy150489 { 31253526Sxy150489 const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 }; 31263526Sxy150489 const uint8_t addr_test2[6] = 31273526Sxy150489 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 31283526Sxy150489 31293526Sxy150489 if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) || 31303526Sxy150489 !(bcmp(addr_test2, mac_addr, ETHERADDRL))) 31313526Sxy150489 return (B_FALSE); 31323526Sxy150489 31333526Sxy150489 return (B_TRUE); 31343526Sxy150489 } 31353526Sxy150489 31363526Sxy150489 /* 3137*4919Sxy150489 * e1000g_stall_check - check for tx stall 3138*4919Sxy150489 * 3139*4919Sxy150489 * This function checks if the adapter is stalled (in transmit). 3140*4919Sxy150489 * 3141*4919Sxy150489 * It is called each time the watchdog timeout is invoked. 3142*4919Sxy150489 * If the transmit descriptor reclaim continuously fails, 3143*4919Sxy150489 * the watchdog value will increment by 1. If the watchdog 3144*4919Sxy150489 * value exceeds the threshold, the adapter is assumed to 3145*4919Sxy150489 * have stalled and need to be reset. 31463526Sxy150489 */ 31473526Sxy150489 static boolean_t 31483526Sxy150489 e1000g_stall_check(struct e1000g *Adapter) 31493526Sxy150489 { 3150*4919Sxy150489 e1000g_tx_ring_t *tx_ring; 3151*4919Sxy150489 3152*4919Sxy150489 tx_ring = Adapter->tx_ring; 3153*4919Sxy150489 31544061Sxy150489 if (Adapter->link_state != LINK_STATE_UP) 31553526Sxy150489 return (B_FALSE); 31563526Sxy150489 3157*4919Sxy150489 if (tx_ring->recycle_fail > 0) 3158*4919Sxy150489 tx_ring->stall_watchdog++; 31593526Sxy150489 else 3160*4919Sxy150489 tx_ring->stall_watchdog = 0; 3161*4919Sxy150489 3162*4919Sxy150489 if (tx_ring->stall_watchdog < E1000G_STALL_WATCHDOG_COUNT) 31633526Sxy150489 return (B_FALSE); 31643526Sxy150489 3165*4919Sxy150489 tx_ring->stall_watchdog = 0; 3166*4919Sxy150489 tx_ring->recycle_fail = 0; 3167*4919Sxy150489 31683526Sxy150489 return (B_TRUE); 31693526Sxy150489 } 31703526Sxy150489 3171*4919Sxy150489 #ifdef E1000G_DEBUG 31723526Sxy150489 static enum ioc_reply 31733526Sxy150489 e1000g_pp_ioctl(struct e1000g *e1000gp, struct iocblk *iocp, mblk_t *mp) 31743526Sxy150489 { 31753526Sxy150489 void (*ppfn)(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd); 31763526Sxy150489 e1000g_peekpoke_t *ppd; 31773526Sxy150489 uint64_t mem_va; 31783526Sxy150489 uint64_t maxoff; 31793526Sxy150489 boolean_t peek; 31803526Sxy150489 31813526Sxy150489 switch (iocp->ioc_cmd) { 31823526Sxy150489 31833526Sxy150489 case E1000G_IOC_REG_PEEK: 31843526Sxy150489 peek = B_TRUE; 31853526Sxy150489 break; 31863526Sxy150489 31873526Sxy150489 case E1000G_IOC_REG_POKE: 31883526Sxy150489 peek = B_FALSE; 31893526Sxy150489 break; 31903526Sxy150489 31913526Sxy150489 deault: 3192*4919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 31934349Sxy150489 "e1000g_diag_ioctl: invalid ioctl command 0x%X\n", 31944349Sxy150489 iocp->ioc_cmd); 31953526Sxy150489 return (IOC_INVAL); 31963526Sxy150489 } 31973526Sxy150489 31983526Sxy150489 /* 31993526Sxy150489 * Validate format of ioctl 32003526Sxy150489 */ 32013526Sxy150489 if (iocp->ioc_count != sizeof (e1000g_peekpoke_t)) 32023526Sxy150489 return (IOC_INVAL); 32033526Sxy150489 if (mp->b_cont == NULL) 32043526Sxy150489 return (IOC_INVAL); 32053526Sxy150489 32063526Sxy150489 ppd = (e1000g_peekpoke_t *)mp->b_cont->b_rptr; 32073526Sxy150489 32083526Sxy150489 /* 32093526Sxy150489 * Validate request parameters 32103526Sxy150489 */ 32113526Sxy150489 switch (ppd->pp_acc_space) { 32123526Sxy150489 32133526Sxy150489 default: 3214*4919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL, 32154349Sxy150489 "e1000g_diag_ioctl: invalid access space 0x%X\n", 32164349Sxy150489 ppd->pp_acc_space); 32173526Sxy150489 return (IOC_INVAL); 32183526Sxy150489 32193526Sxy150489 case E1000G_PP_SPACE_REG: 32203526Sxy150489 /* 32213526Sxy150489 * Memory-mapped I/O space 32223526Sxy150489 */ 32233526Sxy150489 ASSERT(ppd->pp_acc_size == 4); 32243526Sxy150489 if (ppd->pp_acc_size != 4) 32253526Sxy150489 return (IOC_INVAL); 32263526Sxy150489 32273526Sxy150489 if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 32283526Sxy150489 return (IOC_INVAL); 32293526Sxy150489 32303526Sxy150489 mem_va = 0; 32313526Sxy150489 maxoff = 0x10000; 32323526Sxy150489 ppfn = peek ? e1000g_ioc_peek_reg : e1000g_ioc_poke_reg; 32333526Sxy150489 break; 32343526Sxy150489 32353526Sxy150489 case E1000G_PP_SPACE_E1000G: 32363526Sxy150489 /* 32373526Sxy150489 * E1000g data structure! 32383526Sxy150489 */ 32393526Sxy150489 mem_va = (uintptr_t)e1000gp; 32403526Sxy150489 maxoff = sizeof (struct e1000g); 32413526Sxy150489 ppfn = peek ? e1000g_ioc_peek_mem : e1000g_ioc_poke_mem; 32423526Sxy150489 break; 32433526Sxy150489 32443526Sxy150489 } 32453526Sxy150489 32463526Sxy150489 if (ppd->pp_acc_offset >= maxoff) 32473526Sxy150489 return (IOC_INVAL); 32483526Sxy150489 32493526Sxy150489 if (ppd->pp_acc_offset + ppd->pp_acc_size > maxoff) 32503526Sxy150489 return (IOC_INVAL); 32513526Sxy150489 32523526Sxy150489 /* 32533526Sxy150489 * All OK - go! 32543526Sxy150489 */ 32553526Sxy150489 ppd->pp_acc_offset += mem_va; 32563526Sxy150489 (*ppfn)(e1000gp, ppd); 32573526Sxy150489 return (peek ? IOC_REPLY : IOC_ACK); 32583526Sxy150489 } 32593526Sxy150489 32603526Sxy150489 static void 32613526Sxy150489 e1000g_ioc_peek_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 32623526Sxy150489 { 32633526Sxy150489 ddi_acc_handle_t handle; 32643526Sxy150489 uint32_t *regaddr; 32653526Sxy150489 3266*4919Sxy150489 handle = e1000gp->osdep.reg_handle; 32673526Sxy150489 regaddr = 3268*4919Sxy150489 (uint32_t *)(e1000gp->shared.hw_addr + ppd->pp_acc_offset); 32693526Sxy150489 32703526Sxy150489 ppd->pp_acc_data = ddi_get32(handle, regaddr); 32713526Sxy150489 } 32723526Sxy150489 32733526Sxy150489 static void 32743526Sxy150489 e1000g_ioc_poke_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 32753526Sxy150489 { 32763526Sxy150489 ddi_acc_handle_t handle; 32773526Sxy150489 uint32_t *regaddr; 32783526Sxy150489 uint32_t value; 32793526Sxy150489 3280*4919Sxy150489 handle = e1000gp->osdep.reg_handle; 32813526Sxy150489 regaddr = 3282*4919Sxy150489 (uint32_t *)(e1000gp->shared.hw_addr + ppd->pp_acc_offset); 32833526Sxy150489 value = (uint32_t)ppd->pp_acc_data; 32843526Sxy150489 32853526Sxy150489 ddi_put32(handle, regaddr, value); 32863526Sxy150489 } 32873526Sxy150489 32883526Sxy150489 static void 32893526Sxy150489 e1000g_ioc_peek_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 32903526Sxy150489 { 32913526Sxy150489 uint64_t value; 32923526Sxy150489 void *vaddr; 32933526Sxy150489 32943526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 32953526Sxy150489 32963526Sxy150489 switch (ppd->pp_acc_size) { 32973526Sxy150489 case 1: 32983526Sxy150489 value = *(uint8_t *)vaddr; 32993526Sxy150489 break; 33003526Sxy150489 33013526Sxy150489 case 2: 33023526Sxy150489 value = *(uint16_t *)vaddr; 33033526Sxy150489 break; 33043526Sxy150489 33053526Sxy150489 case 4: 33063526Sxy150489 value = *(uint32_t *)vaddr; 33073526Sxy150489 break; 33083526Sxy150489 33093526Sxy150489 case 8: 33103526Sxy150489 value = *(uint64_t *)vaddr; 33113526Sxy150489 break; 33123526Sxy150489 } 33133526Sxy150489 3314*4919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 33154349Sxy150489 "e1000g_ioc_peek_mem($%p, $%p) peeked 0x%llx from $%p\n", 33164349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr); 33173526Sxy150489 33183526Sxy150489 ppd->pp_acc_data = value; 33193526Sxy150489 } 33203526Sxy150489 33213526Sxy150489 static void 33223526Sxy150489 e1000g_ioc_poke_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd) 33233526Sxy150489 { 33243526Sxy150489 uint64_t value; 33253526Sxy150489 void *vaddr; 33263526Sxy150489 33273526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 33283526Sxy150489 value = ppd->pp_acc_data; 33293526Sxy150489 3330*4919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL, 33314349Sxy150489 "e1000g_ioc_poke_mem($%p, $%p) poking 0x%llx at $%p\n", 33324349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr); 33333526Sxy150489 33343526Sxy150489 switch (ppd->pp_acc_size) { 33353526Sxy150489 case 1: 33363526Sxy150489 *(uint8_t *)vaddr = (uint8_t)value; 33373526Sxy150489 break; 33383526Sxy150489 33393526Sxy150489 case 2: 33403526Sxy150489 *(uint16_t *)vaddr = (uint16_t)value; 33413526Sxy150489 break; 33423526Sxy150489 33433526Sxy150489 case 4: 33443526Sxy150489 *(uint32_t *)vaddr = (uint32_t)value; 33453526Sxy150489 break; 33463526Sxy150489 33473526Sxy150489 case 8: 33483526Sxy150489 *(uint64_t *)vaddr = (uint64_t)value; 33493526Sxy150489 break; 33503526Sxy150489 } 33513526Sxy150489 } 3352*4919Sxy150489 #endif 33533526Sxy150489 33543526Sxy150489 /* 33553526Sxy150489 * Loopback Support 33563526Sxy150489 */ 33573526Sxy150489 static lb_property_t lb_normal = 33583526Sxy150489 { normal, "normal", E1000G_LB_NONE }; 33593526Sxy150489 static lb_property_t lb_external1000 = 33603526Sxy150489 { external, "1000Mbps", E1000G_LB_EXTERNAL_1000 }; 33613526Sxy150489 static lb_property_t lb_external100 = 33623526Sxy150489 { external, "100Mbps", E1000G_LB_EXTERNAL_100 }; 33633526Sxy150489 static lb_property_t lb_external10 = 33643526Sxy150489 { external, "10Mbps", E1000G_LB_EXTERNAL_10 }; 33653526Sxy150489 static lb_property_t lb_phy = 33663526Sxy150489 { internal, "PHY", E1000G_LB_INTERNAL_PHY }; 33673526Sxy150489 33683526Sxy150489 static enum ioc_reply 33693526Sxy150489 e1000g_loopback_ioctl(struct e1000g *Adapter, struct iocblk *iocp, mblk_t *mp) 33703526Sxy150489 { 33713526Sxy150489 lb_info_sz_t *lbsp; 33723526Sxy150489 lb_property_t *lbpp; 33733526Sxy150489 struct e1000_hw *hw; 33743526Sxy150489 uint32_t *lbmp; 33753526Sxy150489 uint32_t size; 33763526Sxy150489 uint32_t value; 33773526Sxy150489 uint16_t phy_status; 33783526Sxy150489 uint16_t phy_ext_status; 33793526Sxy150489 3380*4919Sxy150489 hw = &Adapter->shared; 33813526Sxy150489 33823526Sxy150489 if (mp->b_cont == NULL) 33833526Sxy150489 return (IOC_INVAL); 33843526Sxy150489 33853526Sxy150489 switch (iocp->ioc_cmd) { 33863526Sxy150489 default: 33873526Sxy150489 return (IOC_INVAL); 33883526Sxy150489 33893526Sxy150489 case LB_GET_INFO_SIZE: 33903526Sxy150489 size = sizeof (lb_info_sz_t); 33913526Sxy150489 if (iocp->ioc_count != size) 33923526Sxy150489 return (IOC_INVAL); 33933526Sxy150489 33943526Sxy150489 e1000_read_phy_reg(hw, PHY_EXT_STATUS, &phy_ext_status); 33953526Sxy150489 e1000_read_phy_reg(hw, PHY_STATUS, &phy_status); 33963526Sxy150489 33973526Sxy150489 value = sizeof (lb_normal); 33983526Sxy150489 if ((phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 33993526Sxy150489 (phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 34003526Sxy150489 (hw->media_type == e1000_media_type_fiber) || 34013526Sxy150489 (hw->media_type == e1000_media_type_internal_serdes)) { 34023526Sxy150489 value += sizeof (lb_phy); 3403*4919Sxy150489 switch (hw->mac.type) { 34043526Sxy150489 case e1000_82571: 34053526Sxy150489 case e1000_82572: 34063526Sxy150489 value += sizeof (lb_external1000); 34073526Sxy150489 break; 34083526Sxy150489 } 34093526Sxy150489 } 34103526Sxy150489 if ((phy_status & MII_SR_100X_FD_CAPS) || 34113526Sxy150489 (phy_status & MII_SR_100T2_FD_CAPS)) 34123526Sxy150489 value += sizeof (lb_external100); 34133526Sxy150489 if (phy_status & MII_SR_10T_FD_CAPS) 34143526Sxy150489 value += sizeof (lb_external10); 34153526Sxy150489 34163526Sxy150489 lbsp = (lb_info_sz_t *)mp->b_cont->b_rptr; 34173526Sxy150489 *lbsp = value; 34183526Sxy150489 break; 34193526Sxy150489 34203526Sxy150489 case LB_GET_INFO: 34213526Sxy150489 e1000_read_phy_reg(hw, PHY_EXT_STATUS, &phy_ext_status); 34223526Sxy150489 e1000_read_phy_reg(hw, PHY_STATUS, &phy_status); 34233526Sxy150489 34243526Sxy150489 value = sizeof (lb_normal); 34253526Sxy150489 if ((phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 34263526Sxy150489 (phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 34273526Sxy150489 (hw->media_type == e1000_media_type_fiber) || 34283526Sxy150489 (hw->media_type == e1000_media_type_internal_serdes)) { 34293526Sxy150489 value += sizeof (lb_phy); 3430*4919Sxy150489 switch (hw->mac.type) { 34313526Sxy150489 case e1000_82571: 34323526Sxy150489 case e1000_82572: 34333526Sxy150489 value += sizeof (lb_external1000); 34343526Sxy150489 break; 34353526Sxy150489 } 34363526Sxy150489 } 34373526Sxy150489 if ((phy_status & MII_SR_100X_FD_CAPS) || 34383526Sxy150489 (phy_status & MII_SR_100T2_FD_CAPS)) 34393526Sxy150489 value += sizeof (lb_external100); 34403526Sxy150489 if (phy_status & MII_SR_10T_FD_CAPS) 34413526Sxy150489 value += sizeof (lb_external10); 34423526Sxy150489 34433526Sxy150489 size = value; 34443526Sxy150489 if (iocp->ioc_count != size) 34453526Sxy150489 return (IOC_INVAL); 34463526Sxy150489 34473526Sxy150489 value = 0; 34483526Sxy150489 lbpp = (lb_property_t *)mp->b_cont->b_rptr; 34493526Sxy150489 lbpp[value++] = lb_normal; 34503526Sxy150489 if ((phy_ext_status & IEEE_ESR_1000T_FD_CAPS) || 34513526Sxy150489 (phy_ext_status & IEEE_ESR_1000X_FD_CAPS) || 34523526Sxy150489 (hw->media_type == e1000_media_type_fiber) || 34533526Sxy150489 (hw->media_type == e1000_media_type_internal_serdes)) { 34543526Sxy150489 lbpp[value++] = lb_phy; 3455*4919Sxy150489 switch (hw->mac.type) { 34563526Sxy150489 case e1000_82571: 34573526Sxy150489 case e1000_82572: 34583526Sxy150489 lbpp[value++] = lb_external1000; 34593526Sxy150489 break; 34603526Sxy150489 } 34613526Sxy150489 } 34623526Sxy150489 if ((phy_status & MII_SR_100X_FD_CAPS) || 34633526Sxy150489 (phy_status & MII_SR_100T2_FD_CAPS)) 34643526Sxy150489 lbpp[value++] = lb_external100; 34653526Sxy150489 if (phy_status & MII_SR_10T_FD_CAPS) 34663526Sxy150489 lbpp[value++] = lb_external10; 34673526Sxy150489 break; 34683526Sxy150489 34693526Sxy150489 case LB_GET_MODE: 34703526Sxy150489 size = sizeof (uint32_t); 34713526Sxy150489 if (iocp->ioc_count != size) 34723526Sxy150489 return (IOC_INVAL); 34733526Sxy150489 34743526Sxy150489 lbmp = (uint32_t *)mp->b_cont->b_rptr; 34753526Sxy150489 *lbmp = Adapter->loopback_mode; 34763526Sxy150489 break; 34773526Sxy150489 34783526Sxy150489 case LB_SET_MODE: 34793526Sxy150489 size = 0; 34803526Sxy150489 if (iocp->ioc_count != sizeof (uint32_t)) 34813526Sxy150489 return (IOC_INVAL); 34823526Sxy150489 34833526Sxy150489 lbmp = (uint32_t *)mp->b_cont->b_rptr; 34843526Sxy150489 if (!e1000g_set_loopback_mode(Adapter, *lbmp)) 34853526Sxy150489 return (IOC_INVAL); 34863526Sxy150489 break; 34873526Sxy150489 } 34883526Sxy150489 34893526Sxy150489 iocp->ioc_count = size; 34903526Sxy150489 iocp->ioc_error = 0; 34913526Sxy150489 34923526Sxy150489 return (IOC_REPLY); 34933526Sxy150489 } 34943526Sxy150489 34953526Sxy150489 static boolean_t 34963526Sxy150489 e1000g_set_loopback_mode(struct e1000g *Adapter, uint32_t mode) 34973526Sxy150489 { 34983526Sxy150489 struct e1000_hw *hw; 34993526Sxy150489 #ifndef __sparc 35003526Sxy150489 uint32_t reg_rctl; 35013526Sxy150489 #endif 35023526Sxy150489 int i, times; 35033526Sxy150489 35043526Sxy150489 if (mode == Adapter->loopback_mode) 35053526Sxy150489 return (B_TRUE); 35063526Sxy150489 3507*4919Sxy150489 hw = &Adapter->shared; 35083526Sxy150489 times = 0; 35093526Sxy150489 35103526Sxy150489 again: 35113526Sxy150489 switch (mode) { 35123526Sxy150489 default: 35133526Sxy150489 return (B_FALSE); 35143526Sxy150489 35153526Sxy150489 case E1000G_LB_NONE: 35163526Sxy150489 /* Get original speed and duplex settings */ 35173526Sxy150489 e1000g_force_speed_duplex(Adapter); 35183526Sxy150489 /* Reset the chip */ 3519*4919Sxy150489 hw->phy.wait_for_link = B_TRUE; 35203526Sxy150489 (void) e1000g_reset(Adapter); 3521*4919Sxy150489 hw->phy.wait_for_link = B_FALSE; 35223526Sxy150489 break; 35233526Sxy150489 35243526Sxy150489 case E1000G_LB_EXTERNAL_1000: 35253526Sxy150489 e1000g_set_external_loopback_1000(Adapter); 35263526Sxy150489 break; 35273526Sxy150489 35283526Sxy150489 case E1000G_LB_EXTERNAL_100: 35293526Sxy150489 e1000g_set_external_loopback_100(Adapter); 35303526Sxy150489 break; 35313526Sxy150489 35323526Sxy150489 case E1000G_LB_EXTERNAL_10: 35333526Sxy150489 e1000g_set_external_loopback_10(Adapter); 35343526Sxy150489 break; 35353526Sxy150489 35363526Sxy150489 case E1000G_LB_INTERNAL_PHY: 35373526Sxy150489 e1000g_set_internal_loopback(Adapter); 35383526Sxy150489 break; 35393526Sxy150489 } 35403526Sxy150489 35413526Sxy150489 times++; 35423526Sxy150489 35433526Sxy150489 switch (mode) { 35443526Sxy150489 case E1000G_LB_EXTERNAL_1000: 35453526Sxy150489 case E1000G_LB_EXTERNAL_100: 35463526Sxy150489 case E1000G_LB_EXTERNAL_10: 35473526Sxy150489 case E1000G_LB_INTERNAL_PHY: 35483526Sxy150489 /* Wait for link up */ 3549*4919Sxy150489 for (i = (PHY_FORCE_LIMIT * 2); i > 0; i--) 35503526Sxy150489 msec_delay(100); 35513526Sxy150489 35523526Sxy150489 if (!e1000g_link_up(Adapter)) { 3553*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 35543526Sxy150489 "Failed to get the link up"); 35553526Sxy150489 if (times < 2) { 35563526Sxy150489 /* Reset the link */ 3557*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL, 35583526Sxy150489 "Reset the link ..."); 35593526Sxy150489 (void) e1000g_reset(Adapter); 35603526Sxy150489 goto again; 35613526Sxy150489 } 35623526Sxy150489 } 35633526Sxy150489 break; 35643526Sxy150489 } 35653526Sxy150489 35663526Sxy150489 Adapter->loopback_mode = mode; 35673526Sxy150489 35683526Sxy150489 return (B_TRUE); 35693526Sxy150489 } 35703526Sxy150489 35713526Sxy150489 /* 35723526Sxy150489 * The following loopback settings are from Intel's technical 35733526Sxy150489 * document - "How To Loopback". All the register settings and 35743526Sxy150489 * time delay values are directly inherited from the document 35753526Sxy150489 * without more explanations available. 35763526Sxy150489 */ 35773526Sxy150489 static void 35783526Sxy150489 e1000g_set_internal_loopback(struct e1000g *Adapter) 35793526Sxy150489 { 35803526Sxy150489 struct e1000_hw *hw; 35813526Sxy150489 uint32_t ctrl; 35823526Sxy150489 uint32_t status; 35833526Sxy150489 uint16_t phy_ctrl; 35843526Sxy150489 3585*4919Sxy150489 hw = &Adapter->shared; 35863526Sxy150489 35873526Sxy150489 /* Disable Smart Power Down */ 35883526Sxy150489 phy_spd_state(hw, B_FALSE); 35893526Sxy150489 3590*4919Sxy150489 e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl); 35913526Sxy150489 phy_ctrl &= ~(MII_CR_AUTO_NEG_EN | MII_CR_SPEED_100 | MII_CR_SPEED_10); 35923526Sxy150489 phy_ctrl |= MII_CR_FULL_DUPLEX | MII_CR_SPEED_1000; 35933526Sxy150489 3594*4919Sxy150489 switch (hw->mac.type) { 35953526Sxy150489 case e1000_82540: 35963526Sxy150489 case e1000_82545: 35973526Sxy150489 case e1000_82545_rev_3: 35983526Sxy150489 case e1000_82546: 35993526Sxy150489 case e1000_82546_rev_3: 36003526Sxy150489 case e1000_82573: 36013526Sxy150489 /* Auto-MDI/MDIX off */ 36023526Sxy150489 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); 36033526Sxy150489 /* Reset PHY to update Auto-MDI/MDIX */ 3604*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 36054349Sxy150489 phy_ctrl | MII_CR_RESET | MII_CR_AUTO_NEG_EN); 36063526Sxy150489 /* Reset PHY to auto-neg off and force 1000 */ 3607*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 36084349Sxy150489 phy_ctrl | MII_CR_RESET); 36093526Sxy150489 break; 36103526Sxy150489 } 36113526Sxy150489 36123526Sxy150489 /* Set loopback */ 3613*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl | MII_CR_LOOPBACK); 36143526Sxy150489 36153526Sxy150489 msec_delay(250); 36163526Sxy150489 36173526Sxy150489 /* Now set up the MAC to the same speed/duplex as the PHY. */ 3618*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 36193526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 36203526Sxy150489 ctrl |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 36214349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 36224349Sxy150489 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */ 36234349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 36243526Sxy150489 3625*4919Sxy150489 switch (hw->mac.type) { 36263526Sxy150489 case e1000_82540: 36273526Sxy150489 case e1000_82545: 36283526Sxy150489 case e1000_82545_rev_3: 36293526Sxy150489 case e1000_82546: 36303526Sxy150489 case e1000_82546_rev_3: 36313526Sxy150489 /* 36323526Sxy150489 * For some serdes we'll need to commit the writes now 36333526Sxy150489 * so that the status is updated on link 36343526Sxy150489 */ 36353526Sxy150489 if (hw->media_type == e1000_media_type_internal_serdes) { 3636*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 36373526Sxy150489 msec_delay(100); 3638*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 36393526Sxy150489 } 36403526Sxy150489 36413526Sxy150489 if (hw->media_type == e1000_media_type_copper) { 36423526Sxy150489 /* Invert Loss of Signal */ 36433526Sxy150489 ctrl |= E1000_CTRL_ILOS; 36443526Sxy150489 } else { 36453526Sxy150489 /* Set ILOS on fiber nic if half duplex is detected */ 3646*4919Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 36473526Sxy150489 if ((status & E1000_STATUS_FD) == 0) 36483526Sxy150489 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 36493526Sxy150489 } 36503526Sxy150489 break; 36513526Sxy150489 36523526Sxy150489 case e1000_82571: 36533526Sxy150489 case e1000_82572: 36543526Sxy150489 if (hw->media_type != e1000_media_type_copper) { 36553526Sxy150489 /* Set ILOS on fiber nic if half duplex is detected */ 3656*4919Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 36573526Sxy150489 if ((status & E1000_STATUS_FD) == 0) 36583526Sxy150489 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 36593526Sxy150489 } 36603526Sxy150489 break; 36613526Sxy150489 36623526Sxy150489 case e1000_82573: 36633526Sxy150489 ctrl |= E1000_CTRL_ILOS; 36643526Sxy150489 break; 36653526Sxy150489 } 36663526Sxy150489 3667*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 36683526Sxy150489 36693526Sxy150489 /* 36703526Sxy150489 * Disable PHY receiver for 82540/545/546 and 82573 Family. 36713526Sxy150489 * For background, see comments above e1000g_set_internal_loopback(). 36723526Sxy150489 */ 3673*4919Sxy150489 switch (hw->mac.type) { 36743526Sxy150489 case e1000_82540: 36753526Sxy150489 case e1000_82545: 36763526Sxy150489 case e1000_82545_rev_3: 36773526Sxy150489 case e1000_82546: 36783526Sxy150489 case e1000_82546_rev_3: 36793526Sxy150489 case e1000_82573: 36803526Sxy150489 e1000_write_phy_reg(hw, 29, 0x001F); 36813526Sxy150489 e1000_write_phy_reg(hw, 30, 0x8FFC); 36823526Sxy150489 e1000_write_phy_reg(hw, 29, 0x001A); 36833526Sxy150489 e1000_write_phy_reg(hw, 30, 0x8FF0); 36843526Sxy150489 break; 36853526Sxy150489 } 36863526Sxy150489 } 36873526Sxy150489 36883526Sxy150489 static void 36893526Sxy150489 e1000g_set_external_loopback_1000(struct e1000g *Adapter) 36903526Sxy150489 { 36913526Sxy150489 struct e1000_hw *hw; 36923526Sxy150489 uint32_t rctl; 36933526Sxy150489 uint32_t ctrl_ext; 36943526Sxy150489 uint32_t ctrl; 36953526Sxy150489 uint32_t status; 36963526Sxy150489 uint32_t txcw; 36973526Sxy150489 3698*4919Sxy150489 hw = &Adapter->shared; 36993526Sxy150489 37003526Sxy150489 /* Disable Smart Power Down */ 37013526Sxy150489 phy_spd_state(hw, B_FALSE); 37023526Sxy150489 37033526Sxy150489 switch (hw->media_type) { 37043526Sxy150489 case e1000_media_type_copper: 37053526Sxy150489 /* Force link up (Must be done before the PHY writes) */ 3706*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 37073526Sxy150489 ctrl |= E1000_CTRL_SLU; /* Force Link Up */ 3708*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 3709*4919Sxy150489 3710*4919Sxy150489 rctl = E1000_READ_REG(hw, E1000_RCTL); 37113526Sxy150489 rctl |= (E1000_RCTL_EN | 37124349Sxy150489 E1000_RCTL_SBP | 37134349Sxy150489 E1000_RCTL_UPE | 37144349Sxy150489 E1000_RCTL_MPE | 37154349Sxy150489 E1000_RCTL_LPE | 37164349Sxy150489 E1000_RCTL_BAM); /* 0x803E */ 3717*4919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, rctl); 3718*4919Sxy150489 3719*4919Sxy150489 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 37203526Sxy150489 ctrl_ext |= (E1000_CTRL_EXT_SDP4_DATA | 37214349Sxy150489 E1000_CTRL_EXT_SDP6_DATA | 37224349Sxy150489 E1000_CTRL_EXT_SDP7_DATA | 37234349Sxy150489 E1000_CTRL_EXT_SDP4_DIR | 37244349Sxy150489 E1000_CTRL_EXT_SDP6_DIR | 37254349Sxy150489 E1000_CTRL_EXT_SDP7_DIR); /* 0x0DD0 */ 3726*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 37273526Sxy150489 37283526Sxy150489 /* 37293526Sxy150489 * This sequence tunes the PHY's SDP and no customer 37303526Sxy150489 * settable values. For background, see comments above 37313526Sxy150489 * e1000g_set_internal_loopback(). 37323526Sxy150489 */ 37333526Sxy150489 e1000_write_phy_reg(hw, 0x0, 0x140); 37343526Sxy150489 msec_delay(10); 37353526Sxy150489 e1000_write_phy_reg(hw, 0x9, 0x1A00); 37363526Sxy150489 e1000_write_phy_reg(hw, 0x12, 0xC10); 37373526Sxy150489 e1000_write_phy_reg(hw, 0x12, 0x1C10); 37383526Sxy150489 e1000_write_phy_reg(hw, 0x1F37, 0x76); 37393526Sxy150489 e1000_write_phy_reg(hw, 0x1F33, 0x1); 37403526Sxy150489 e1000_write_phy_reg(hw, 0x1F33, 0x0); 37413526Sxy150489 37423526Sxy150489 e1000_write_phy_reg(hw, 0x1F35, 0x65); 37433526Sxy150489 e1000_write_phy_reg(hw, 0x1837, 0x3F7C); 37443526Sxy150489 e1000_write_phy_reg(hw, 0x1437, 0x3FDC); 37453526Sxy150489 e1000_write_phy_reg(hw, 0x1237, 0x3F7C); 37463526Sxy150489 e1000_write_phy_reg(hw, 0x1137, 0x3FDC); 37473526Sxy150489 37483526Sxy150489 msec_delay(50); 37493526Sxy150489 break; 37503526Sxy150489 case e1000_media_type_fiber: 37513526Sxy150489 case e1000_media_type_internal_serdes: 3752*4919Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 37533526Sxy150489 if (((status & E1000_STATUS_LU) == 0) || 37543526Sxy150489 (hw->media_type == e1000_media_type_internal_serdes)) { 3755*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 37563526Sxy150489 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU; 3757*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 37583526Sxy150489 } 37593526Sxy150489 37603526Sxy150489 /* Disable autoneg by setting bit 31 of TXCW to zero */ 3761*4919Sxy150489 txcw = E1000_READ_REG(hw, E1000_TXCW); 37623526Sxy150489 txcw &= ~((uint32_t)1 << 31); 3763*4919Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 37643526Sxy150489 37653526Sxy150489 /* 37663526Sxy150489 * Write 0x410 to Serdes Control register 37673526Sxy150489 * to enable Serdes analog loopback 37683526Sxy150489 */ 3769*4919Sxy150489 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410); 37703526Sxy150489 msec_delay(10); 37713526Sxy150489 break; 37723526Sxy150489 default: 37733526Sxy150489 break; 37743526Sxy150489 } 37753526Sxy150489 } 37763526Sxy150489 37773526Sxy150489 static void 37783526Sxy150489 e1000g_set_external_loopback_100(struct e1000g *Adapter) 37793526Sxy150489 { 37803526Sxy150489 struct e1000_hw *hw; 37813526Sxy150489 uint32_t ctrl; 37823526Sxy150489 uint16_t phy_ctrl; 37833526Sxy150489 3784*4919Sxy150489 hw = &Adapter->shared; 37853526Sxy150489 37863526Sxy150489 /* Disable Smart Power Down */ 37873526Sxy150489 phy_spd_state(hw, B_FALSE); 37883526Sxy150489 37893526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX | 37904349Sxy150489 MII_CR_SPEED_100); 37913526Sxy150489 37923526Sxy150489 /* Force 100/FD, reset PHY */ 3793*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 37944349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0xA100 */ 37953526Sxy150489 msec_delay(10); 37963526Sxy150489 37973526Sxy150489 /* Force 100/FD */ 3798*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 37994349Sxy150489 phy_ctrl); /* 0x2100 */ 38003526Sxy150489 msec_delay(10); 38013526Sxy150489 38023526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */ 3803*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 38043526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 38053526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 38064349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 38074349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 38084349Sxy150489 E1000_CTRL_SPD_100 | /* Force Speed to 100 */ 38094349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 38103526Sxy150489 3811*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 38123526Sxy150489 } 38133526Sxy150489 38143526Sxy150489 static void 38153526Sxy150489 e1000g_set_external_loopback_10(struct e1000g *Adapter) 38163526Sxy150489 { 38173526Sxy150489 struct e1000_hw *hw; 38183526Sxy150489 uint32_t ctrl; 38193526Sxy150489 uint16_t phy_ctrl; 38203526Sxy150489 3821*4919Sxy150489 hw = &Adapter->shared; 38223526Sxy150489 38233526Sxy150489 /* Disable Smart Power Down */ 38243526Sxy150489 phy_spd_state(hw, B_FALSE); 38253526Sxy150489 38263526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX | 38274349Sxy150489 MII_CR_SPEED_10); 38283526Sxy150489 38293526Sxy150489 /* Force 10/FD, reset PHY */ 3830*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 38314349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0x8100 */ 38323526Sxy150489 msec_delay(10); 38333526Sxy150489 38343526Sxy150489 /* Force 10/FD */ 3835*4919Sxy150489 e1000_write_phy_reg(hw, PHY_CONTROL, 38364349Sxy150489 phy_ctrl); /* 0x0100 */ 38373526Sxy150489 msec_delay(10); 38383526Sxy150489 38393526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */ 3840*4919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 38413526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 38423526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */ 38434349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 38444349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 38454349Sxy150489 E1000_CTRL_SPD_10 | /* Force Speed to 10 */ 38464349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */ 38473526Sxy150489 3848*4919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 38493526Sxy150489 } 38503526Sxy150489 38513526Sxy150489 #ifdef __sparc 38523526Sxy150489 static boolean_t 38533526Sxy150489 e1000g_find_mac_address(struct e1000g *Adapter) 38543526Sxy150489 { 3855*4919Sxy150489 struct e1000_hw *hw = &Adapter->shared; 38563526Sxy150489 uchar_t *bytes; 38573526Sxy150489 struct ether_addr sysaddr; 38583526Sxy150489 uint_t nelts; 38593526Sxy150489 int err; 38603526Sxy150489 boolean_t found = B_FALSE; 38613526Sxy150489 38623526Sxy150489 /* 38633526Sxy150489 * The "vendor's factory-set address" may already have 38643526Sxy150489 * been extracted from the chip, but if the property 38653526Sxy150489 * "local-mac-address" is set we use that instead. 38663526Sxy150489 * 38673526Sxy150489 * We check whether it looks like an array of 6 38683526Sxy150489 * bytes (which it should, if OBP set it). If we can't 38693526Sxy150489 * make sense of it this way, we'll ignore it. 38703526Sxy150489 */ 38713526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 38723526Sxy150489 DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts); 38733526Sxy150489 if (err == DDI_PROP_SUCCESS) { 38743526Sxy150489 if (nelts == ETHERADDRL) { 38753526Sxy150489 while (nelts--) 3876*4919Sxy150489 hw->mac.addr[nelts] = bytes[nelts]; 38773526Sxy150489 found = B_TRUE; 38783526Sxy150489 } 38793526Sxy150489 ddi_prop_free(bytes); 38803526Sxy150489 } 38813526Sxy150489 38823526Sxy150489 /* 38833526Sxy150489 * Look up the OBP property "local-mac-address?". If the user has set 38843526Sxy150489 * 'local-mac-address? = false', use "the system address" instead. 38853526Sxy150489 */ 38863526Sxy150489 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 0, 38873526Sxy150489 "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) { 38883526Sxy150489 if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) { 38893526Sxy150489 if (localetheraddr(NULL, &sysaddr) != 0) { 3890*4919Sxy150489 bcopy(&sysaddr, hw->mac.addr, ETHERADDRL); 38913526Sxy150489 found = B_TRUE; 38923526Sxy150489 } 38933526Sxy150489 } 38943526Sxy150489 ddi_prop_free(bytes); 38953526Sxy150489 } 38963526Sxy150489 38973526Sxy150489 /* 38983526Sxy150489 * Finally(!), if there's a valid "mac-address" property (created 38993526Sxy150489 * if we netbooted from this interface), we must use this instead 39003526Sxy150489 * of any of the above to ensure that the NFS/install server doesn't 39013526Sxy150489 * get confused by the address changing as Solaris takes over! 39023526Sxy150489 */ 39033526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 39043526Sxy150489 DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts); 39053526Sxy150489 if (err == DDI_PROP_SUCCESS) { 39063526Sxy150489 if (nelts == ETHERADDRL) { 39073526Sxy150489 while (nelts--) 3908*4919Sxy150489 hw->mac.addr[nelts] = bytes[nelts]; 39093526Sxy150489 found = B_TRUE; 39103526Sxy150489 } 39113526Sxy150489 ddi_prop_free(bytes); 39123526Sxy150489 } 39133526Sxy150489 39143526Sxy150489 if (found) { 3915*4919Sxy150489 bcopy(hw->mac.addr, hw->mac.perm_addr, 39163526Sxy150489 ETHERADDRL); 39173526Sxy150489 } 39183526Sxy150489 39193526Sxy150489 return (found); 39203526Sxy150489 } 39213526Sxy150489 #endif 39223526Sxy150489 39233526Sxy150489 static int 39243526Sxy150489 e1000g_add_intrs(struct e1000g *Adapter) 39253526Sxy150489 { 39263526Sxy150489 dev_info_t *devinfo; 39273526Sxy150489 int intr_types; 39283526Sxy150489 int rc; 39293526Sxy150489 39303526Sxy150489 devinfo = Adapter->dip; 39313526Sxy150489 39323526Sxy150489 /* Get supported interrupt types */ 39333526Sxy150489 rc = ddi_intr_get_supported_types(devinfo, &intr_types); 39343526Sxy150489 39353526Sxy150489 if (rc != DDI_SUCCESS) { 3936*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 39373526Sxy150489 "Get supported interrupt types failed: %d\n", rc); 39383526Sxy150489 return (DDI_FAILURE); 39393526Sxy150489 } 39403526Sxy150489 39413526Sxy150489 /* 39423526Sxy150489 * Based on Intel Technical Advisory document (TA-160), there are some 39433526Sxy150489 * cases where some older Intel PCI-X NICs may "advertise" to the OS 39443526Sxy150489 * that it supports MSI, but in fact has problems. 39453526Sxy150489 * So we should only enable MSI for PCI-E NICs and disable MSI for old 39463526Sxy150489 * PCI/PCI-X NICs. 39473526Sxy150489 */ 3948*4919Sxy150489 if (Adapter->shared.mac.type < e1000_82571) 39493526Sxy150489 Adapter->msi_enabled = B_FALSE; 39503526Sxy150489 39513526Sxy150489 if ((intr_types & DDI_INTR_TYPE_MSI) && Adapter->msi_enabled) { 39523526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_MSI); 39533526Sxy150489 39543526Sxy150489 if (rc != DDI_SUCCESS) { 3955*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 39563526Sxy150489 "Add MSI failed, trying Legacy interrupts\n"); 39573526Sxy150489 } else { 39583526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_MSI; 39593526Sxy150489 } 39603526Sxy150489 } 39613526Sxy150489 39623526Sxy150489 if ((Adapter->intr_type == 0) && 39633526Sxy150489 (intr_types & DDI_INTR_TYPE_FIXED)) { 39643526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_FIXED); 39653526Sxy150489 39663526Sxy150489 if (rc != DDI_SUCCESS) { 3967*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 39683526Sxy150489 "Add Legacy interrupts failed\n"); 39693526Sxy150489 return (DDI_FAILURE); 39703526Sxy150489 } 39713526Sxy150489 39723526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_FIXED; 39733526Sxy150489 } 39743526Sxy150489 39753526Sxy150489 if (Adapter->intr_type == 0) { 3976*4919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL, 39773526Sxy150489 "No interrupts registered\n"); 39783526Sxy150489 return (DDI_FAILURE); 39793526Sxy150489 } 39803526Sxy150489 39813526Sxy150489 return (DDI_SUCCESS); 39823526Sxy150489 } 39833526Sxy150489 39843526Sxy150489 /* 39853526Sxy150489 * e1000g_intr_add() handles MSI/Legacy interrupts 39863526Sxy150489 */ 39873526Sxy150489 static int 39883526Sxy150489 e1000g_intr_add(struct e1000g *Adapter, int intr_type) 39893526Sxy150489 { 39903526Sxy150489 dev_info_t *devinfo; 39913526Sxy150489 int count, avail, actual; 39923526Sxy150489 int x, y, rc, inum = 0; 39933526Sxy150489 int flag; 39943526Sxy150489 ddi_intr_handler_t *intr_handler; 39953526Sxy150489 39963526Sxy150489 devinfo = Adapter->dip; 39973526Sxy150489 39983526Sxy150489 /* get number of interrupts */ 39993526Sxy150489 rc = ddi_intr_get_nintrs(devinfo, intr_type, &count); 40003526Sxy150489 if ((rc != DDI_SUCCESS) || (count == 0)) { 4001*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 40023526Sxy150489 "Get interrupt number failed. Return: %d, count: %d\n", 40033526Sxy150489 rc, count); 40043526Sxy150489 return (DDI_FAILURE); 40053526Sxy150489 } 40063526Sxy150489 40073526Sxy150489 /* get number of available interrupts */ 40083526Sxy150489 rc = ddi_intr_get_navail(devinfo, intr_type, &avail); 40093526Sxy150489 if ((rc != DDI_SUCCESS) || (avail == 0)) { 4010*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 40113526Sxy150489 "Get interrupt available number failed. " 40123526Sxy150489 "Return: %d, available: %d\n", rc, avail); 40133526Sxy150489 return (DDI_FAILURE); 40143526Sxy150489 } 40153526Sxy150489 40163526Sxy150489 if (avail < count) { 4017*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 40183526Sxy150489 "Interrupts count: %d, available: %d\n", 40193526Sxy150489 count, avail); 40203526Sxy150489 } 40213526Sxy150489 40223526Sxy150489 /* Allocate an array of interrupt handles */ 40233526Sxy150489 Adapter->intr_size = count * sizeof (ddi_intr_handle_t); 40243526Sxy150489 Adapter->htable = kmem_alloc(Adapter->intr_size, KM_SLEEP); 40253526Sxy150489 40263526Sxy150489 /* Set NORMAL behavior for both MSI and FIXED interrupt */ 40273526Sxy150489 flag = DDI_INTR_ALLOC_NORMAL; 40283526Sxy150489 40293526Sxy150489 /* call ddi_intr_alloc() */ 40303526Sxy150489 rc = ddi_intr_alloc(devinfo, Adapter->htable, intr_type, inum, 40313526Sxy150489 count, &actual, flag); 40323526Sxy150489 40333526Sxy150489 if ((rc != DDI_SUCCESS) || (actual == 0)) { 4034*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 40353526Sxy150489 "Allocate interrupts failed: %d\n", rc); 40363526Sxy150489 40373526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 40383526Sxy150489 return (DDI_FAILURE); 40393526Sxy150489 } 40403526Sxy150489 40413526Sxy150489 if (actual < count) { 4042*4919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL, 40433526Sxy150489 "Interrupts requested: %d, received: %d\n", 40443526Sxy150489 count, actual); 40453526Sxy150489 } 40463526Sxy150489 40473526Sxy150489 Adapter->intr_cnt = actual; 40483526Sxy150489 40493526Sxy150489 /* Get priority for first msi, assume remaining are all the same */ 40503526Sxy150489 rc = ddi_intr_get_pri(Adapter->htable[0], &Adapter->intr_pri); 40513526Sxy150489 40523526Sxy150489 if (rc != DDI_SUCCESS) { 4053*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 40543526Sxy150489 "Get interrupt priority failed: %d\n", rc); 40553526Sxy150489 40563526Sxy150489 /* Free already allocated intr */ 40573526Sxy150489 for (y = 0; y < actual; y++) 40583526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 40593526Sxy150489 40603526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 40613526Sxy150489 return (DDI_FAILURE); 40623526Sxy150489 } 40633526Sxy150489 40643526Sxy150489 /* 40653526Sxy150489 * In Legacy Interrupt mode, for PCI-Express adapters, we should 40663526Sxy150489 * use the interrupt service routine e1000g_intr_pciexpress() 40673526Sxy150489 * to avoid interrupt stealing when sharing interrupt with other 40683526Sxy150489 * devices. 40693526Sxy150489 */ 4070*4919Sxy150489 if (Adapter->shared.mac.type < e1000_82571) 40713526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr; 40723526Sxy150489 else 40733526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr_pciexpress; 40743526Sxy150489 40753526Sxy150489 /* Call ddi_intr_add_handler() */ 40763526Sxy150489 for (x = 0; x < actual; x++) { 40773526Sxy150489 rc = ddi_intr_add_handler(Adapter->htable[x], 40783526Sxy150489 intr_handler, (caddr_t)Adapter, NULL); 40793526Sxy150489 40803526Sxy150489 if (rc != DDI_SUCCESS) { 4081*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 40823526Sxy150489 "Add interrupt handler failed: %d\n", rc); 40833526Sxy150489 40843526Sxy150489 /* Remove already added handler */ 40853526Sxy150489 for (y = 0; y < x; y++) 40863526Sxy150489 (void) ddi_intr_remove_handler( 40873526Sxy150489 Adapter->htable[y]); 40883526Sxy150489 40893526Sxy150489 /* Free already allocated intr */ 40903526Sxy150489 for (y = 0; y < actual; y++) 40913526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 40923526Sxy150489 40933526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 40943526Sxy150489 return (DDI_FAILURE); 40953526Sxy150489 } 40963526Sxy150489 } 40973526Sxy150489 40983526Sxy150489 rc = ddi_intr_get_cap(Adapter->htable[0], &Adapter->intr_cap); 40993526Sxy150489 41003526Sxy150489 if (rc != DDI_SUCCESS) { 4101*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41023526Sxy150489 "Get interrupt cap failed: %d\n", rc); 41033526Sxy150489 41043526Sxy150489 /* Free already allocated intr */ 41053526Sxy150489 for (y = 0; y < actual; y++) { 41063526Sxy150489 (void) ddi_intr_remove_handler(Adapter->htable[y]); 41073526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]); 41083526Sxy150489 } 41093526Sxy150489 41103526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 41113526Sxy150489 return (DDI_FAILURE); 41123526Sxy150489 } 41133526Sxy150489 41143526Sxy150489 return (DDI_SUCCESS); 41153526Sxy150489 } 41163526Sxy150489 41173526Sxy150489 static int 41183526Sxy150489 e1000g_rem_intrs(struct e1000g *Adapter) 41193526Sxy150489 { 41203526Sxy150489 int x; 41213526Sxy150489 int rc; 41223526Sxy150489 41233526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 41243526Sxy150489 rc = ddi_intr_remove_handler(Adapter->htable[x]); 41253526Sxy150489 if (rc != DDI_SUCCESS) { 4126*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41273526Sxy150489 "Remove intr handler failed: %d\n", rc); 41283526Sxy150489 return (DDI_FAILURE); 41293526Sxy150489 } 41303526Sxy150489 41313526Sxy150489 rc = ddi_intr_free(Adapter->htable[x]); 41323526Sxy150489 if (rc != DDI_SUCCESS) { 4133*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41343526Sxy150489 "Free intr failed: %d\n", rc); 41353526Sxy150489 return (DDI_FAILURE); 41363526Sxy150489 } 41373526Sxy150489 } 41383526Sxy150489 41393526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size); 41403526Sxy150489 41413526Sxy150489 return (DDI_SUCCESS); 41423526Sxy150489 } 41433526Sxy150489 41443526Sxy150489 static int 41453526Sxy150489 e1000g_enable_intrs(struct e1000g *Adapter) 41463526Sxy150489 { 41473526Sxy150489 int x; 41483526Sxy150489 int rc; 41493526Sxy150489 41503526Sxy150489 /* Enable interrupts */ 41513526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 41523526Sxy150489 /* Call ddi_intr_block_enable() for MSI */ 41533526Sxy150489 rc = ddi_intr_block_enable(Adapter->htable, 41543526Sxy150489 Adapter->intr_cnt); 41553526Sxy150489 if (rc != DDI_SUCCESS) { 4156*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41573526Sxy150489 "Enable block intr failed: %d\n", rc); 41583526Sxy150489 return (DDI_FAILURE); 41593526Sxy150489 } 41603526Sxy150489 } else { 41613526Sxy150489 /* Call ddi_intr_enable() for Legacy/MSI non block enable */ 41623526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 41633526Sxy150489 rc = ddi_intr_enable(Adapter->htable[x]); 41643526Sxy150489 if (rc != DDI_SUCCESS) { 4165*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41663526Sxy150489 "Enable intr failed: %d\n", rc); 41673526Sxy150489 return (DDI_FAILURE); 41683526Sxy150489 } 41693526Sxy150489 } 41703526Sxy150489 } 41713526Sxy150489 41723526Sxy150489 return (DDI_SUCCESS); 41733526Sxy150489 } 41743526Sxy150489 41753526Sxy150489 static int 41763526Sxy150489 e1000g_disable_intrs(struct e1000g *Adapter) 41773526Sxy150489 { 41783526Sxy150489 int x; 41793526Sxy150489 int rc; 41803526Sxy150489 41813526Sxy150489 /* Disable all interrupts */ 41823526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) { 41833526Sxy150489 rc = ddi_intr_block_disable(Adapter->htable, 41843526Sxy150489 Adapter->intr_cnt); 41853526Sxy150489 if (rc != DDI_SUCCESS) { 4186*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41873526Sxy150489 "Disable block intr failed: %d\n", rc); 41883526Sxy150489 return (DDI_FAILURE); 41893526Sxy150489 } 41903526Sxy150489 } else { 41913526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) { 41923526Sxy150489 rc = ddi_intr_disable(Adapter->htable[x]); 41933526Sxy150489 if (rc != DDI_SUCCESS) { 4194*4919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL, 41953526Sxy150489 "Disable intr failed: %d\n", rc); 41963526Sxy150489 return (DDI_FAILURE); 41973526Sxy150489 } 41983526Sxy150489 } 41993526Sxy150489 } 42003526Sxy150489 42013526Sxy150489 return (DDI_SUCCESS); 42023526Sxy150489 } 4203