13526Sxy150489 /*
23526Sxy150489 * This file is provided under a CDDLv1 license. When using or
33526Sxy150489 * redistributing this file, you may do so under this license.
43526Sxy150489 * In redistributing this file this license must be included
53526Sxy150489 * and no other modification of this header file is permitted.
63526Sxy150489 *
73526Sxy150489 * CDDL LICENSE SUMMARY
83526Sxy150489 *
98479SChenlu.Chen@Sun.COM * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
103526Sxy150489 *
113526Sxy150489 * The contents of this file are subject to the terms of Version
123526Sxy150489 * 1.0 of the Common Development and Distribution License (the "License").
133526Sxy150489 *
143526Sxy150489 * You should have received a copy of the License with this software.
153526Sxy150489 * You can obtain a copy of the License at
163526Sxy150489 * http://www.opensolaris.org/os/licensing.
173526Sxy150489 * See the License for the specific language governing permissions
183526Sxy150489 * and limitations under the License.
193526Sxy150489 */
203526Sxy150489
213526Sxy150489 /*
22*12853SChangqing.Li@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
233526Sxy150489 */
243526Sxy150489
253526Sxy150489 /*
263526Sxy150489 * **********************************************************************
273526Sxy150489 * *
283526Sxy150489 * Module Name: *
293526Sxy150489 * e1000g_main.c *
303526Sxy150489 * *
313526Sxy150489 * Abstract: *
324919Sxy150489 * This file contains the interface routines for the solaris OS. *
334919Sxy150489 * It has all DDI entry point routines and GLD entry point routines. *
343526Sxy150489 * *
354919Sxy150489 * This file also contains routines that take care of initialization *
364919Sxy150489 * uninit routine and interrupt routine. *
373526Sxy150489 * *
383526Sxy150489 * **********************************************************************
393526Sxy150489 */
403526Sxy150489
413526Sxy150489 #include <sys/dlpi.h>
423526Sxy150489 #include <sys/mac.h>
433526Sxy150489 #include "e1000g_sw.h"
443526Sxy150489 #include "e1000g_debug.h"
453526Sxy150489
467656SSherry.Moore@Sun.COM static char ident[] = "Intel PRO/1000 Ethernet";
47*12853SChangqing.Li@Sun.COM /* LINTED E_STATIC_UNUSED */
48*12853SChangqing.Li@Sun.COM static char e1000g_version[] = "Driver Ver. 5.3.24";
493526Sxy150489
503526Sxy150489 /*
513526Sxy150489 * Proto types for DDI entry points
523526Sxy150489 */
534919Sxy150489 static int e1000g_attach(dev_info_t *, ddi_attach_cmd_t);
544919Sxy150489 static int e1000g_detach(dev_info_t *, ddi_detach_cmd_t);
557656SSherry.Moore@Sun.COM static int e1000g_quiesce(dev_info_t *);
563526Sxy150489
573526Sxy150489 /*
583526Sxy150489 * init and intr routines prototype
593526Sxy150489 */
604919Sxy150489 static int e1000g_resume(dev_info_t *);
614919Sxy150489 static int e1000g_suspend(dev_info_t *);
623526Sxy150489 static uint_t e1000g_intr_pciexpress(caddr_t);
633526Sxy150489 static uint_t e1000g_intr(caddr_t);
643526Sxy150489 static void e1000g_intr_work(struct e1000g *, uint32_t);
653526Sxy150489 #pragma inline(e1000g_intr_work)
663526Sxy150489 static int e1000g_init(struct e1000g *);
674919Sxy150489 static int e1000g_start(struct e1000g *, boolean_t);
684919Sxy150489 static void e1000g_stop(struct e1000g *, boolean_t);
693526Sxy150489 static int e1000g_m_start(void *);
703526Sxy150489 static void e1000g_m_stop(void *);
713526Sxy150489 static int e1000g_m_promisc(void *, boolean_t);
723526Sxy150489 static boolean_t e1000g_m_getcapab(void *, mac_capab_t, void *);
733526Sxy150489 static int e1000g_m_multicst(void *, boolean_t, const uint8_t *);
743526Sxy150489 static void e1000g_m_ioctl(void *, queue_t *, mblk_t *);
756394Scc210113 static int e1000g_m_setprop(void *, const char *, mac_prop_id_t,
766394Scc210113 uint_t, const void *);
776394Scc210113 static int e1000g_m_getprop(void *, const char *, mac_prop_id_t,
7811878SVenu.Iyer@Sun.COM uint_t, void *);
7911878SVenu.Iyer@Sun.COM static void e1000g_m_propinfo(void *, const char *, mac_prop_id_t,
8011878SVenu.Iyer@Sun.COM mac_prop_info_handle_t);
816394Scc210113 static int e1000g_set_priv_prop(struct e1000g *, const char *, uint_t,
826394Scc210113 const void *);
8311878SVenu.Iyer@Sun.COM static int e1000g_get_priv_prop(struct e1000g *, const char *, uint_t, void *);
844919Sxy150489 static void e1000g_init_locks(struct e1000g *);
854919Sxy150489 static void e1000g_destroy_locks(struct e1000g *);
864919Sxy150489 static int e1000g_identify_hardware(struct e1000g *);
874919Sxy150489 static int e1000g_regs_map(struct e1000g *);
884919Sxy150489 static int e1000g_set_driver_params(struct e1000g *);
896394Scc210113 static void e1000g_set_bufsize(struct e1000g *);
904919Sxy150489 static int e1000g_register_mac(struct e1000g *);
914919Sxy150489 static boolean_t e1000g_rx_drain(struct e1000g *);
924919Sxy150489 static boolean_t e1000g_tx_drain(struct e1000g *);
934919Sxy150489 static void e1000g_init_unicst(struct e1000g *);
948275SEric Cheng static int e1000g_unicst_set(struct e1000g *, const uint8_t *, int);
958850SMin.Xu@Sun.COM static int e1000g_alloc_rx_data(struct e1000g *);
969770SChangqing.Li@Sun.COM static void e1000g_release_multicast(struct e1000g *);
9710680SMin.Xu@Sun.COM static void e1000g_pch_limits(struct e1000g *);
9810680SMin.Xu@Sun.COM static uint32_t e1000g_mtu2maxframe(uint32_t);
993526Sxy150489
1003526Sxy150489 /*
1013526Sxy150489 * Local routines
1023526Sxy150489 */
1037656SSherry.Moore@Sun.COM static boolean_t e1000g_reset_adapter(struct e1000g *);
1044919Sxy150489 static void e1000g_tx_clean(struct e1000g *);
1054919Sxy150489 static void e1000g_rx_clean(struct e1000g *);
1064061Sxy150489 static void e1000g_link_timer(void *);
1074919Sxy150489 static void e1000g_local_timer(void *);
1084061Sxy150489 static boolean_t e1000g_link_check(struct e1000g *);
1093526Sxy150489 static boolean_t e1000g_stall_check(struct e1000g *);
1103526Sxy150489 static void e1000g_smartspeed(struct e1000g *);
1114919Sxy150489 static void e1000g_get_conf(struct e1000g *);
11211339SGuoqing.Zhu@Sun.COM static boolean_t e1000g_get_prop(struct e1000g *, char *, int, int, int,
11311339SGuoqing.Zhu@Sun.COM int *);
1144919Sxy150489 static void enable_watchdog_timer(struct e1000g *);
1154919Sxy150489 static void disable_watchdog_timer(struct e1000g *);
1164919Sxy150489 static void start_watchdog_timer(struct e1000g *);
1174919Sxy150489 static void restart_watchdog_timer(struct e1000g *);
1184919Sxy150489 static void stop_watchdog_timer(struct e1000g *);
1194919Sxy150489 static void stop_link_timer(struct e1000g *);
1204919Sxy150489 static void stop_82547_timer(e1000g_tx_ring_t *);
1214919Sxy150489 static void e1000g_force_speed_duplex(struct e1000g *);
12210680SMin.Xu@Sun.COM static void e1000g_setup_max_mtu(struct e1000g *);
1234919Sxy150489 static void e1000g_get_max_frame_size(struct e1000g *);
1244919Sxy150489 static boolean_t is_valid_mac_addr(uint8_t *);
1253526Sxy150489 static void e1000g_unattach(dev_info_t *, struct e1000g *);
12611532SGuoqing.Zhu@Sun.COM static int e1000g_get_bar_info(dev_info_t *, int, bar_info_t *);
1274919Sxy150489 #ifdef E1000G_DEBUG
1284919Sxy150489 static void e1000g_ioc_peek_reg(struct e1000g *, e1000g_peekpoke_t *);
1294919Sxy150489 static void e1000g_ioc_poke_reg(struct e1000g *, e1000g_peekpoke_t *);
1304919Sxy150489 static void e1000g_ioc_peek_mem(struct e1000g *, e1000g_peekpoke_t *);
1314919Sxy150489 static void e1000g_ioc_poke_mem(struct e1000g *, e1000g_peekpoke_t *);
1324919Sxy150489 static enum ioc_reply e1000g_pp_ioctl(struct e1000g *,
1334919Sxy150489 struct iocblk *, mblk_t *);
1344919Sxy150489 #endif
1354919Sxy150489 static enum ioc_reply e1000g_loopback_ioctl(struct e1000g *,
1364919Sxy150489 struct iocblk *, mblk_t *);
1377133Scc210113 static boolean_t e1000g_check_loopback_support(struct e1000_hw *);
1384919Sxy150489 static boolean_t e1000g_set_loopback_mode(struct e1000g *, uint32_t);
1394919Sxy150489 static void e1000g_set_internal_loopback(struct e1000g *);
1404919Sxy150489 static void e1000g_set_external_loopback_1000(struct e1000g *);
1414919Sxy150489 static void e1000g_set_external_loopback_100(struct e1000g *);
1424919Sxy150489 static void e1000g_set_external_loopback_10(struct e1000g *);
1434919Sxy150489 static int e1000g_add_intrs(struct e1000g *);
1444919Sxy150489 static int e1000g_intr_add(struct e1000g *, int);
1454919Sxy150489 static int e1000g_rem_intrs(struct e1000g *);
1464919Sxy150489 static int e1000g_enable_intrs(struct e1000g *);
1474919Sxy150489 static int e1000g_disable_intrs(struct e1000g *);
1484919Sxy150489 static boolean_t e1000g_link_up(struct e1000g *);
1493526Sxy150489 #ifdef __sparc
1504919Sxy150489 static boolean_t e1000g_find_mac_address(struct e1000g *);
1513526Sxy150489 #endif
1525082Syy150190 static void e1000g_get_phy_state(struct e1000g *);
1535273Sgl147354 static int e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
1545273Sgl147354 const void *impl_data);
1555273Sgl147354 static void e1000g_fm_init(struct e1000g *Adapter);
1565273Sgl147354 static void e1000g_fm_fini(struct e1000g *Adapter);
1576512Ssowmini static void e1000g_param_sync(struct e1000g *);
1587607STed.You@Sun.COM static void e1000g_get_driver_control(struct e1000_hw *);
1597607STed.You@Sun.COM static void e1000g_release_driver_control(struct e1000_hw *);
1607722SShuguo.Yang@Sun.COM static void e1000g_restore_promisc(struct e1000g *Adapter);
1616512Ssowmini
16211878SVenu.Iyer@Sun.COM char *e1000g_priv_props[] = {
16311878SVenu.Iyer@Sun.COM "_tx_bcopy_threshold",
16411878SVenu.Iyer@Sun.COM "_tx_interrupt_enable",
16511878SVenu.Iyer@Sun.COM "_tx_intr_delay",
16611878SVenu.Iyer@Sun.COM "_tx_intr_abs_delay",
16711878SVenu.Iyer@Sun.COM "_rx_bcopy_threshold",
16811878SVenu.Iyer@Sun.COM "_max_num_rcv_packets",
16911878SVenu.Iyer@Sun.COM "_rx_intr_delay",
17011878SVenu.Iyer@Sun.COM "_rx_intr_abs_delay",
17111878SVenu.Iyer@Sun.COM "_intr_throttling_rate",
17211878SVenu.Iyer@Sun.COM "_intr_adaptive",
17311878SVenu.Iyer@Sun.COM "_adv_pause_cap",
17411878SVenu.Iyer@Sun.COM "_adv_asym_pause_cap",
17511878SVenu.Iyer@Sun.COM NULL
1766512Ssowmini };
1773526Sxy150489
1783526Sxy150489 static struct cb_ops cb_ws_ops = {
1793526Sxy150489 nulldev, /* cb_open */
1803526Sxy150489 nulldev, /* cb_close */
1813526Sxy150489 nodev, /* cb_strategy */
1823526Sxy150489 nodev, /* cb_print */
1833526Sxy150489 nodev, /* cb_dump */
1843526Sxy150489 nodev, /* cb_read */
1853526Sxy150489 nodev, /* cb_write */
1863526Sxy150489 nodev, /* cb_ioctl */
1873526Sxy150489 nodev, /* cb_devmap */
1883526Sxy150489 nodev, /* cb_mmap */
1893526Sxy150489 nodev, /* cb_segmap */
1903526Sxy150489 nochpoll, /* cb_chpoll */
1913526Sxy150489 ddi_prop_op, /* cb_prop_op */
1923526Sxy150489 NULL, /* cb_stream */
1933526Sxy150489 D_MP | D_HOTPLUG, /* cb_flag */
1943526Sxy150489 CB_REV, /* cb_rev */
1953526Sxy150489 nodev, /* cb_aread */
1963526Sxy150489 nodev /* cb_awrite */
1973526Sxy150489 };
1983526Sxy150489
1993526Sxy150489 static struct dev_ops ws_ops = {
2003526Sxy150489 DEVO_REV, /* devo_rev */
2013526Sxy150489 0, /* devo_refcnt */
2023526Sxy150489 NULL, /* devo_getinfo */
2033526Sxy150489 nulldev, /* devo_identify */
2043526Sxy150489 nulldev, /* devo_probe */
2054919Sxy150489 e1000g_attach, /* devo_attach */
2064919Sxy150489 e1000g_detach, /* devo_detach */
2073526Sxy150489 nodev, /* devo_reset */
2083526Sxy150489 &cb_ws_ops, /* devo_cb_ops */
2093526Sxy150489 NULL, /* devo_bus_ops */
2107656SSherry.Moore@Sun.COM ddi_power, /* devo_power */
2117656SSherry.Moore@Sun.COM e1000g_quiesce /* devo_quiesce */
2123526Sxy150489 };
2133526Sxy150489
2143526Sxy150489 static struct modldrv modldrv = {
2153526Sxy150489 &mod_driverops, /* Type of module. This one is a driver */
2163526Sxy150489 ident, /* Discription string */
2173526Sxy150489 &ws_ops, /* driver ops */
2183526Sxy150489 };
2193526Sxy150489
2203526Sxy150489 static struct modlinkage modlinkage = {
2213526Sxy150489 MODREV_1, &modldrv, NULL
2223526Sxy150489 };
2233526Sxy150489
2244919Sxy150489 /* Access attributes for register mapping */
2254919Sxy150489 static ddi_device_acc_attr_t e1000g_regs_acc_attr = {
22611236SStephen.Hanson@Sun.COM DDI_DEVICE_ATTR_V1,
2273526Sxy150489 DDI_STRUCTURE_LE_ACC,
2283526Sxy150489 DDI_STRICTORDER_ACC,
2295273Sgl147354 DDI_FLAGERR_ACC
2303526Sxy150489 };
2313526Sxy150489
2326394Scc210113 #define E1000G_M_CALLBACK_FLAGS \
23311878SVenu.Iyer@Sun.COM (MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP | MC_PROPINFO)
2343526Sxy150489
2353526Sxy150489 static mac_callbacks_t e1000g_m_callbacks = {
2363526Sxy150489 E1000G_M_CALLBACK_FLAGS,
2373526Sxy150489 e1000g_m_stat,
2383526Sxy150489 e1000g_m_start,
2393526Sxy150489 e1000g_m_stop,
2403526Sxy150489 e1000g_m_promisc,
2413526Sxy150489 e1000g_m_multicst,
2428275SEric Cheng NULL,
2433526Sxy150489 e1000g_m_tx,
24411878SVenu.Iyer@Sun.COM NULL,
2453526Sxy150489 e1000g_m_ioctl,
2466394Scc210113 e1000g_m_getcapab,
2476394Scc210113 NULL,
2486394Scc210113 NULL,
2496394Scc210113 e1000g_m_setprop,
25011878SVenu.Iyer@Sun.COM e1000g_m_getprop,
25111878SVenu.Iyer@Sun.COM e1000g_m_propinfo
2523526Sxy150489 };
2533526Sxy150489
2543526Sxy150489 /*
2553526Sxy150489 * Global variables
2563526Sxy150489 */
257*12853SChangqing.Li@Sun.COM uint32_t e1000g_jumbo_mtu = MAXIMUM_MTU_9K;
2583526Sxy150489 uint32_t e1000g_mblks_pending = 0;
2593526Sxy150489 /*
2604894Syy150190 * Workaround for Dynamic Reconfiguration support, for x86 platform only.
2614349Sxy150489 * Here we maintain a private dev_info list if e1000g_force_detach is
2624349Sxy150489 * enabled. If we force the driver to detach while there are still some
2634349Sxy150489 * rx buffers retained in the upper layer, we have to keep a copy of the
2644349Sxy150489 * dev_info. In some cases (Dynamic Reconfiguration), the dev_info data
2654349Sxy150489 * structure will be freed after the driver is detached. However when we
2664349Sxy150489 * finally free those rx buffers released by the upper layer, we need to
2674349Sxy150489 * refer to the dev_info to free the dma buffers. So we save a copy of
2684894Syy150190 * the dev_info for this purpose. On x86 platform, we assume this copy
2694894Syy150190 * of dev_info is always valid, but on SPARC platform, it could be invalid
2704894Syy150190 * after the system board level DR operation. For this reason, the global
2714894Syy150190 * variable e1000g_force_detach must be B_FALSE on SPARC platform.
2724349Sxy150489 */
2734894Syy150190 #ifdef __sparc
2744894Syy150190 boolean_t e1000g_force_detach = B_FALSE;
2754894Syy150190 #else
2764894Syy150190 boolean_t e1000g_force_detach = B_TRUE;
2774894Syy150190 #endif
2784349Sxy150489 private_devi_list_t *e1000g_private_devi_list = NULL;
2794894Syy150190
2804349Sxy150489 /*
2818850SMin.Xu@Sun.COM * The mutex e1000g_rx_detach_lock is defined to protect the processing of
2828850SMin.Xu@Sun.COM * the private dev_info list, and to serialize the processing of rx buffer
2838850SMin.Xu@Sun.COM * freeing and rx buffer recycling.
2843526Sxy150489 */
2858850SMin.Xu@Sun.COM kmutex_t e1000g_rx_detach_lock;
2863526Sxy150489 /*
2873526Sxy150489 * The rwlock e1000g_dma_type_lock is defined to protect the global flag
2883526Sxy150489 * e1000g_dma_type. For SPARC, the initial value of the flag is "USE_DVMA".
2893526Sxy150489 * If there are many e1000g instances, the system may run out of DVMA
2903526Sxy150489 * resources during the initialization of the instances, then the flag will
2913526Sxy150489 * be changed to "USE_DMA". Because different e1000g instances are initialized
2923526Sxy150489 * in parallel, we need to use this lock to protect the flag.
2933526Sxy150489 */
2943526Sxy150489 krwlock_t e1000g_dma_type_lock;
2953526Sxy150489
2967133Scc210113 /*
2977133Scc210113 * The 82546 chipset is a dual-port device, both the ports share one eeprom.
2987133Scc210113 * Based on the information from Intel, the 82546 chipset has some hardware
2997133Scc210113 * problem. When one port is being reset and the other port is trying to
3007133Scc210113 * access the eeprom, it could cause system hang or panic. To workaround this
3017133Scc210113 * hardware problem, we use a global mutex to prevent such operations from
3027133Scc210113 * happening simultaneously on different instances. This workaround is applied
3037133Scc210113 * to all the devices supported by this driver.
3047133Scc210113 */
3057133Scc210113 kmutex_t e1000g_nvm_lock;
3063526Sxy150489
3073526Sxy150489 /*
3083526Sxy150489 * Loadable module configuration entry points for the driver
3093526Sxy150489 */
3103526Sxy150489
3113526Sxy150489 /*
3124919Sxy150489 * _init - module initialization
3133526Sxy150489 */
3143526Sxy150489 int
_init(void)3153526Sxy150489 _init(void)
3163526Sxy150489 {
3173526Sxy150489 int status;
3183526Sxy150489
3193526Sxy150489 mac_init_ops(&ws_ops, WSNAME);
3203526Sxy150489 status = mod_install(&modlinkage);
3213526Sxy150489 if (status != DDI_SUCCESS)
3223526Sxy150489 mac_fini_ops(&ws_ops);
3233526Sxy150489 else {
3248850SMin.Xu@Sun.COM mutex_init(&e1000g_rx_detach_lock, NULL, MUTEX_DRIVER, NULL);
3253526Sxy150489 rw_init(&e1000g_dma_type_lock, NULL, RW_DRIVER, NULL);
3267133Scc210113 mutex_init(&e1000g_nvm_lock, NULL, MUTEX_DRIVER, NULL);
3273526Sxy150489 }
3283526Sxy150489
3293526Sxy150489 return (status);
3303526Sxy150489 }
3313526Sxy150489
3323526Sxy150489 /*
3334919Sxy150489 * _fini - module finalization
3343526Sxy150489 */
3353526Sxy150489 int
_fini(void)3363526Sxy150489 _fini(void)
3373526Sxy150489 {
3383526Sxy150489 int status;
3393526Sxy150489
3408850SMin.Xu@Sun.COM if (e1000g_mblks_pending != 0)
3413526Sxy150489 return (EBUSY);
3423526Sxy150489
3433526Sxy150489 status = mod_remove(&modlinkage);
3443526Sxy150489 if (status == DDI_SUCCESS) {
3453526Sxy150489 mac_fini_ops(&ws_ops);
3464349Sxy150489
3474349Sxy150489 if (e1000g_force_detach) {
3484349Sxy150489 private_devi_list_t *devi_node;
3494349Sxy150489
3508850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock);
3514349Sxy150489 while (e1000g_private_devi_list != NULL) {
3524349Sxy150489 devi_node = e1000g_private_devi_list;
3534349Sxy150489 e1000g_private_devi_list =
3544349Sxy150489 e1000g_private_devi_list->next;
3554349Sxy150489
3564349Sxy150489 kmem_free(devi_node->priv_dip,
3574349Sxy150489 sizeof (struct dev_info));
3584349Sxy150489 kmem_free(devi_node,
3594349Sxy150489 sizeof (private_devi_list_t));
3604349Sxy150489 }
3618850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock);
3624349Sxy150489 }
3634349Sxy150489
3648850SMin.Xu@Sun.COM mutex_destroy(&e1000g_rx_detach_lock);
3653526Sxy150489 rw_destroy(&e1000g_dma_type_lock);
3667133Scc210113 mutex_destroy(&e1000g_nvm_lock);
3673526Sxy150489 }
3683526Sxy150489
3693526Sxy150489 return (status);
3703526Sxy150489 }
3713526Sxy150489
3723526Sxy150489 /*
3734919Sxy150489 * _info - module information
3743526Sxy150489 */
3753526Sxy150489 int
_info(struct modinfo * modinfop)3763526Sxy150489 _info(struct modinfo *modinfop)
3773526Sxy150489 {
3783526Sxy150489 return (mod_info(&modlinkage, modinfop));
3793526Sxy150489 }
3803526Sxy150489
3813526Sxy150489 /*
3824919Sxy150489 * e1000g_attach - driver attach
3834919Sxy150489 *
3844919Sxy150489 * This function is the device-specific initialization entry
3854919Sxy150489 * point. This entry point is required and must be written.
3864919Sxy150489 * The DDI_ATTACH command must be provided in the attach entry
3874919Sxy150489 * point. When attach() is called with cmd set to DDI_ATTACH,
3884919Sxy150489 * all normal kernel services (such as kmem_alloc(9F)) are
3894919Sxy150489 * available for use by the driver.
3904919Sxy150489 *
3914919Sxy150489 * The attach() function will be called once for each instance
3924919Sxy150489 * of the device on the system with cmd set to DDI_ATTACH.
3934919Sxy150489 * Until attach() succeeds, the only driver entry points which
3944919Sxy150489 * may be called are open(9E) and getinfo(9E).
3953526Sxy150489 */
3963526Sxy150489 static int
e1000g_attach(dev_info_t * devinfo,ddi_attach_cmd_t cmd)3974919Sxy150489 e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
3983526Sxy150489 {
3993526Sxy150489 struct e1000g *Adapter;
4003526Sxy150489 struct e1000_hw *hw;
4014919Sxy150489 struct e1000g_osdep *osdep;
4023526Sxy150489 int instance;
4033526Sxy150489
4043526Sxy150489 switch (cmd) {
4053526Sxy150489 default:
4063526Sxy150489 e1000g_log(NULL, CE_WARN,
4074919Sxy150489 "Unsupported command send to e1000g_attach... ");
4083526Sxy150489 return (DDI_FAILURE);
4093526Sxy150489
4103526Sxy150489 case DDI_RESUME:
4113526Sxy150489 return (e1000g_resume(devinfo));
4123526Sxy150489
4133526Sxy150489 case DDI_ATTACH:
4143526Sxy150489 break;
4153526Sxy150489 }
4163526Sxy150489
4173526Sxy150489 /*
4183526Sxy150489 * get device instance number
4193526Sxy150489 */
4203526Sxy150489 instance = ddi_get_instance(devinfo);
4213526Sxy150489
4223526Sxy150489 /*
4233526Sxy150489 * Allocate soft data structure
4243526Sxy150489 */
4253526Sxy150489 Adapter =
4263526Sxy150489 (struct e1000g *)kmem_zalloc(sizeof (*Adapter), KM_SLEEP);
4273526Sxy150489
4283526Sxy150489 Adapter->dip = devinfo;
4294919Sxy150489 Adapter->instance = instance;
4303526Sxy150489 Adapter->tx_ring->adapter = Adapter;
4313526Sxy150489 Adapter->rx_ring->adapter = Adapter;
4323526Sxy150489
4334919Sxy150489 hw = &Adapter->shared;
4344919Sxy150489 osdep = &Adapter->osdep;
4354919Sxy150489 hw->back = osdep;
4364919Sxy150489 osdep->adapter = Adapter;
4374919Sxy150489
4383526Sxy150489 ddi_set_driver_private(devinfo, (caddr_t)Adapter);
4393526Sxy150489
4404919Sxy150489 /*
4415273Sgl147354 * Initialize for fma support
4425273Sgl147354 */
44311339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "fm-capable",
4445273Sgl147354 0, 0x0f,
4455273Sgl147354 DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE |
44611339SGuoqing.Zhu@Sun.COM DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE,
44711339SGuoqing.Zhu@Sun.COM &Adapter->fm_capabilities);
4485273Sgl147354 e1000g_fm_init(Adapter);
4495273Sgl147354 Adapter->attach_progress |= ATTACH_PROGRESS_FMINIT;
4505273Sgl147354
4515273Sgl147354 /*
4524919Sxy150489 * PCI Configure
4534919Sxy150489 */
4544919Sxy150489 if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) {
4554919Sxy150489 e1000g_log(Adapter, CE_WARN, "PCI configuration failed");
4564919Sxy150489 goto attach_fail;
4574919Sxy150489 }
4584919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG;
4594919Sxy150489
4604919Sxy150489 /*
4614919Sxy150489 * Setup hardware
4624919Sxy150489 */
4634919Sxy150489 if (e1000g_identify_hardware(Adapter) != DDI_SUCCESS) {
4644919Sxy150489 e1000g_log(Adapter, CE_WARN, "Identify hardware failed");
4654919Sxy150489 goto attach_fail;
4664919Sxy150489 }
4673526Sxy150489
4683526Sxy150489 /*
4693526Sxy150489 * Map in the device registers.
4703526Sxy150489 */
4714919Sxy150489 if (e1000g_regs_map(Adapter) != DDI_SUCCESS) {
4724919Sxy150489 e1000g_log(Adapter, CE_WARN, "Mapping registers failed");
4733526Sxy150489 goto attach_fail;
4743526Sxy150489 }
4754919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_REGS_MAP;
4763526Sxy150489
4773526Sxy150489 /*
4783526Sxy150489 * Initialize driver parameters
4793526Sxy150489 */
4803526Sxy150489 if (e1000g_set_driver_params(Adapter) != DDI_SUCCESS) {
4813526Sxy150489 goto attach_fail;
4823526Sxy150489 }
4834919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_SETUP;
4843526Sxy150489
4855273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) {
4865273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
4875273Sgl147354 goto attach_fail;
4885273Sgl147354 }
4895273Sgl147354
4903526Sxy150489 /*
4913526Sxy150489 * Initialize interrupts
4923526Sxy150489 */
4933526Sxy150489 if (e1000g_add_intrs(Adapter) != DDI_SUCCESS) {
4943526Sxy150489 e1000g_log(Adapter, CE_WARN, "Add interrupts failed");
4953526Sxy150489 goto attach_fail;
4963526Sxy150489 }
4974919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ADD_INTR;
4983526Sxy150489
4993526Sxy150489 /*
5003526Sxy150489 * Initialize mutex's for this device.
5013526Sxy150489 * Do this before enabling the interrupt handler and
5023526Sxy150489 * register the softint to avoid the condition where
5033526Sxy150489 * interrupt handler can try using uninitialized mutex
5043526Sxy150489 */
5053526Sxy150489 e1000g_init_locks(Adapter);
5063526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_LOCKS;
5073526Sxy150489
5083526Sxy150489 /*
5093526Sxy150489 * Initialize Driver Counters
5103526Sxy150489 */
5114919Sxy150489 if (e1000g_init_stats(Adapter) != DDI_SUCCESS) {
5123526Sxy150489 e1000g_log(Adapter, CE_WARN, "Init stats failed");
5133526Sxy150489 goto attach_fail;
5143526Sxy150489 }
5153526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_KSTATS;
5163526Sxy150489
5173526Sxy150489 /*
5183526Sxy150489 * Initialize chip hardware and software structures
5193526Sxy150489 */
5208479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
5213526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) {
5228479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
5233526Sxy150489 e1000g_log(Adapter, CE_WARN, "Adapter initialization failed");
5243526Sxy150489 goto attach_fail;
5253526Sxy150489 }
5268479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
5273526Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_INIT;
5283526Sxy150489
5293526Sxy150489 /*
5303526Sxy150489 * Register the driver to the MAC
5313526Sxy150489 */
5323526Sxy150489 if (e1000g_register_mac(Adapter) != DDI_SUCCESS) {
5333526Sxy150489 e1000g_log(Adapter, CE_WARN, "Register MAC failed");
5343526Sxy150489 goto attach_fail;
5353526Sxy150489 }
5364919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_MAC;
5373526Sxy150489
5383526Sxy150489 /*
5393526Sxy150489 * Now that mutex locks are initialized, and the chip is also
5403526Sxy150489 * initialized, enable interrupts.
5413526Sxy150489 */
5423526Sxy150489 if (e1000g_enable_intrs(Adapter) != DDI_SUCCESS) {
5433526Sxy150489 e1000g_log(Adapter, CE_WARN, "Enable DDI interrupts failed");
5443526Sxy150489 goto attach_fail;
5453526Sxy150489 }
5464919Sxy150489 Adapter->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR;
5473526Sxy150489
5484982Syy150190 /*
5494982Syy150190 * If e1000g_force_detach is enabled, in global private dip list,
5504982Syy150190 * we will create a new entry, which maintains the priv_dip for DR
5514982Syy150190 * supports after driver detached.
5524982Syy150190 */
5534982Syy150190 if (e1000g_force_detach) {
5544982Syy150190 private_devi_list_t *devi_node;
5554982Syy150190
5564982Syy150190 Adapter->priv_dip =
5574982Syy150190 kmem_zalloc(sizeof (struct dev_info), KM_SLEEP);
5584982Syy150190 bcopy(DEVI(devinfo), DEVI(Adapter->priv_dip),
5594982Syy150190 sizeof (struct dev_info));
5604982Syy150190
5614982Syy150190 devi_node =
5624982Syy150190 kmem_zalloc(sizeof (private_devi_list_t), KM_SLEEP);
5634982Syy150190
5648850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock);
5654982Syy150190 devi_node->priv_dip = Adapter->priv_dip;
5664982Syy150190 devi_node->flag = E1000G_PRIV_DEVI_ATTACH;
5678850SMin.Xu@Sun.COM devi_node->pending_rx_count = 0;
5688850SMin.Xu@Sun.COM
5698850SMin.Xu@Sun.COM Adapter->priv_devi_node = devi_node;
5708850SMin.Xu@Sun.COM
5718850SMin.Xu@Sun.COM if (e1000g_private_devi_list == NULL) {
5728850SMin.Xu@Sun.COM devi_node->prev = NULL;
5738850SMin.Xu@Sun.COM devi_node->next = NULL;
5748850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node;
5758850SMin.Xu@Sun.COM } else {
5768850SMin.Xu@Sun.COM devi_node->prev = NULL;
5778850SMin.Xu@Sun.COM devi_node->next = e1000g_private_devi_list;
5788850SMin.Xu@Sun.COM e1000g_private_devi_list->prev = devi_node;
5798850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node;
5808850SMin.Xu@Sun.COM }
5818850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock);
5824982Syy150190 }
5834982Syy150190
5848479SChenlu.Chen@Sun.COM Adapter->e1000g_state = E1000G_INITIALIZED;
5853526Sxy150489 return (DDI_SUCCESS);
5863526Sxy150489
5873526Sxy150489 attach_fail:
5883526Sxy150489 e1000g_unattach(devinfo, Adapter);
5893526Sxy150489 return (DDI_FAILURE);
5903526Sxy150489 }
5913526Sxy150489
5923526Sxy150489 static int
e1000g_register_mac(struct e1000g * Adapter)5933526Sxy150489 e1000g_register_mac(struct e1000g *Adapter)
5943526Sxy150489 {
5954919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
5963526Sxy150489 mac_register_t *mac;
5973526Sxy150489 int err;
5983526Sxy150489
5993526Sxy150489 if ((mac = mac_alloc(MAC_VERSION)) == NULL)
6003526Sxy150489 return (DDI_FAILURE);
6014919Sxy150489
6023526Sxy150489 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
6033526Sxy150489 mac->m_driver = Adapter;
6043526Sxy150489 mac->m_dip = Adapter->dip;
6054919Sxy150489 mac->m_src_addr = hw->mac.addr;
6063526Sxy150489 mac->m_callbacks = &e1000g_m_callbacks;
6073526Sxy150489 mac->m_min_sdu = 0;
6086394Scc210113 mac->m_max_sdu = Adapter->default_mtu;
6095895Syz147064 mac->m_margin = VLAN_TAGSZ;
6106512Ssowmini mac->m_priv_props = e1000g_priv_props;
6118275SEric Cheng mac->m_v12n = MAC_VIRT_LEVEL1;
6124919Sxy150489
6133526Sxy150489 err = mac_register(mac, &Adapter->mh);
6143526Sxy150489 mac_free(mac);
6154919Sxy150489
6163526Sxy150489 return (err == 0 ? DDI_SUCCESS : DDI_FAILURE);
6173526Sxy150489 }
6183526Sxy150489
6193526Sxy150489 static int
e1000g_identify_hardware(struct e1000g * Adapter)6204919Sxy150489 e1000g_identify_hardware(struct e1000g *Adapter)
6214919Sxy150489 {
6224919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
6234919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep;
6244919Sxy150489
6254919Sxy150489 /* Get the device id */
6264919Sxy150489 hw->vendor_id =
6274919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID);
6284919Sxy150489 hw->device_id =
6294919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID);
6304919Sxy150489 hw->revision_id =
6314919Sxy150489 pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID);
6324919Sxy150489 hw->subsystem_device_id =
6334919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID);
6344919Sxy150489 hw->subsystem_vendor_id =
6354919Sxy150489 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID);
6364919Sxy150489
6374919Sxy150489 if (e1000_set_mac_type(hw) != E1000_SUCCESS) {
6384919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
6394919Sxy150489 "MAC type could not be set properly.");
6404919Sxy150489 return (DDI_FAILURE);
6414919Sxy150489 }
6424919Sxy150489
6434919Sxy150489 return (DDI_SUCCESS);
6444919Sxy150489 }
6454919Sxy150489
6464919Sxy150489 static int
e1000g_regs_map(struct e1000g * Adapter)6474919Sxy150489 e1000g_regs_map(struct e1000g *Adapter)
6484919Sxy150489 {
6494919Sxy150489 dev_info_t *devinfo = Adapter->dip;
6504919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
6514919Sxy150489 struct e1000g_osdep *osdep = &Adapter->osdep;
6524919Sxy150489 off_t mem_size;
65311532SGuoqing.Zhu@Sun.COM bar_info_t bar_info;
65411532SGuoqing.Zhu@Sun.COM int offset, rnumber;
65511532SGuoqing.Zhu@Sun.COM
65611532SGuoqing.Zhu@Sun.COM rnumber = ADAPTER_REG_SET;
6577607STed.You@Sun.COM /* Get size of adapter register memory */
65811532SGuoqing.Zhu@Sun.COM if (ddi_dev_regsize(devinfo, rnumber, &mem_size) !=
6597607STed.You@Sun.COM DDI_SUCCESS) {
6604919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6614919Sxy150489 "ddi_dev_regsize for registers failed");
6624919Sxy150489 return (DDI_FAILURE);
6634919Sxy150489 }
6644919Sxy150489
6657607STed.You@Sun.COM /* Map adapter register memory */
66611532SGuoqing.Zhu@Sun.COM if ((ddi_regs_map_setup(devinfo, rnumber,
6674919Sxy150489 (caddr_t *)&hw->hw_addr, 0, mem_size, &e1000g_regs_acc_attr,
6684919Sxy150489 &osdep->reg_handle)) != DDI_SUCCESS) {
6694919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6704919Sxy150489 "ddi_regs_map_setup for registers failed");
6714919Sxy150489 goto regs_map_fail;
6724919Sxy150489 }
6734919Sxy150489
6744919Sxy150489 /* ICH needs to map flash memory */
67511532SGuoqing.Zhu@Sun.COM switch (hw->mac.type) {
67611532SGuoqing.Zhu@Sun.COM case e1000_ich8lan:
67711532SGuoqing.Zhu@Sun.COM case e1000_ich9lan:
67811532SGuoqing.Zhu@Sun.COM case e1000_ich10lan:
67911532SGuoqing.Zhu@Sun.COM case e1000_pchlan:
68011532SGuoqing.Zhu@Sun.COM rnumber = ICH_FLASH_REG_SET;
68111532SGuoqing.Zhu@Sun.COM
6824919Sxy150489 /* get flash size */
68311532SGuoqing.Zhu@Sun.COM if (ddi_dev_regsize(devinfo, rnumber,
6844919Sxy150489 &mem_size) != DDI_SUCCESS) {
6854919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6864919Sxy150489 "ddi_dev_regsize for ICH flash failed");
6874919Sxy150489 goto regs_map_fail;
6884919Sxy150489 }
6894919Sxy150489
6904919Sxy150489 /* map flash in */
69111532SGuoqing.Zhu@Sun.COM if (ddi_regs_map_setup(devinfo, rnumber,
6924919Sxy150489 (caddr_t *)&hw->flash_address, 0,
6934919Sxy150489 mem_size, &e1000g_regs_acc_attr,
6944919Sxy150489 &osdep->ich_flash_handle) != DDI_SUCCESS) {
6954919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
6964919Sxy150489 "ddi_regs_map_setup for ICH flash failed");
6974919Sxy150489 goto regs_map_fail;
6984919Sxy150489 }
69911532SGuoqing.Zhu@Sun.COM break;
70011532SGuoqing.Zhu@Sun.COM default:
70111532SGuoqing.Zhu@Sun.COM break;
70211532SGuoqing.Zhu@Sun.COM }
70311532SGuoqing.Zhu@Sun.COM
70411532SGuoqing.Zhu@Sun.COM /* map io space */
70511532SGuoqing.Zhu@Sun.COM switch (hw->mac.type) {
70611532SGuoqing.Zhu@Sun.COM case e1000_82544:
70711532SGuoqing.Zhu@Sun.COM case e1000_82540:
70811532SGuoqing.Zhu@Sun.COM case e1000_82545:
70911532SGuoqing.Zhu@Sun.COM case e1000_82546:
71011532SGuoqing.Zhu@Sun.COM case e1000_82541:
71111532SGuoqing.Zhu@Sun.COM case e1000_82541_rev_2:
71211532SGuoqing.Zhu@Sun.COM /* find the IO bar */
71311532SGuoqing.Zhu@Sun.COM rnumber = -1;
71411532SGuoqing.Zhu@Sun.COM for (offset = PCI_CONF_BASE1;
71511532SGuoqing.Zhu@Sun.COM offset <= PCI_CONF_BASE5; offset += 4) {
71611532SGuoqing.Zhu@Sun.COM if (e1000g_get_bar_info(devinfo, offset, &bar_info)
71711532SGuoqing.Zhu@Sun.COM != DDI_SUCCESS)
71811532SGuoqing.Zhu@Sun.COM continue;
71911532SGuoqing.Zhu@Sun.COM if (bar_info.type == E1000G_BAR_IO) {
72011532SGuoqing.Zhu@Sun.COM rnumber = bar_info.rnumber;
72111532SGuoqing.Zhu@Sun.COM break;
72211532SGuoqing.Zhu@Sun.COM }
72311532SGuoqing.Zhu@Sun.COM }
72411532SGuoqing.Zhu@Sun.COM
72511532SGuoqing.Zhu@Sun.COM if (rnumber < 0) {
72611532SGuoqing.Zhu@Sun.COM E1000G_DEBUGLOG_0(Adapter, CE_WARN,
72711532SGuoqing.Zhu@Sun.COM "No io space is found");
72811532SGuoqing.Zhu@Sun.COM goto regs_map_fail;
72911532SGuoqing.Zhu@Sun.COM }
73011532SGuoqing.Zhu@Sun.COM
73111532SGuoqing.Zhu@Sun.COM /* get io space size */
73211532SGuoqing.Zhu@Sun.COM if (ddi_dev_regsize(devinfo, rnumber,
73311532SGuoqing.Zhu@Sun.COM &mem_size) != DDI_SUCCESS) {
73411532SGuoqing.Zhu@Sun.COM E1000G_DEBUGLOG_0(Adapter, CE_WARN,
73511532SGuoqing.Zhu@Sun.COM "ddi_dev_regsize for io space failed");
73611532SGuoqing.Zhu@Sun.COM goto regs_map_fail;
73711532SGuoqing.Zhu@Sun.COM }
73811532SGuoqing.Zhu@Sun.COM
73911532SGuoqing.Zhu@Sun.COM /* map io space */
74011532SGuoqing.Zhu@Sun.COM if ((ddi_regs_map_setup(devinfo, rnumber,
74111532SGuoqing.Zhu@Sun.COM (caddr_t *)&hw->io_base, 0, mem_size,
74211532SGuoqing.Zhu@Sun.COM &e1000g_regs_acc_attr,
74311532SGuoqing.Zhu@Sun.COM &osdep->io_reg_handle)) != DDI_SUCCESS) {
74411532SGuoqing.Zhu@Sun.COM E1000G_DEBUGLOG_0(Adapter, CE_WARN,
74511532SGuoqing.Zhu@Sun.COM "ddi_regs_map_setup for io space failed");
74611532SGuoqing.Zhu@Sun.COM goto regs_map_fail;
74711532SGuoqing.Zhu@Sun.COM }
74811532SGuoqing.Zhu@Sun.COM break;
74911532SGuoqing.Zhu@Sun.COM default:
75011532SGuoqing.Zhu@Sun.COM hw->io_base = 0;
75111532SGuoqing.Zhu@Sun.COM break;
7524919Sxy150489 }
7534919Sxy150489
7544919Sxy150489 return (DDI_SUCCESS);
7554919Sxy150489
7564919Sxy150489 regs_map_fail:
7574919Sxy150489 if (osdep->reg_handle != NULL)
7584919Sxy150489 ddi_regs_map_free(&osdep->reg_handle);
75911532SGuoqing.Zhu@Sun.COM if (osdep->ich_flash_handle != NULL)
76011532SGuoqing.Zhu@Sun.COM ddi_regs_map_free(&osdep->ich_flash_handle);
7614919Sxy150489 return (DDI_FAILURE);
7624919Sxy150489 }
7634919Sxy150489
7644919Sxy150489 static int
e1000g_set_driver_params(struct e1000g * Adapter)7653526Sxy150489 e1000g_set_driver_params(struct e1000g *Adapter)
7663526Sxy150489 {
7673526Sxy150489 struct e1000_hw *hw;
7683526Sxy150489
7694919Sxy150489 hw = &Adapter->shared;
7704919Sxy150489
7714919Sxy150489 /* Set MAC type and initialize hardware functions */
7724919Sxy150489 if (e1000_setup_init_funcs(hw, B_TRUE) != E1000_SUCCESS) {
7734919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
7744919Sxy150489 "Could not setup hardware functions");
7753526Sxy150489 return (DDI_FAILURE);
7763526Sxy150489 }
7773526Sxy150489
7784919Sxy150489 /* Get bus information */
7794919Sxy150489 if (e1000_get_bus_info(hw) != E1000_SUCCESS) {
7804919Sxy150489 E1000G_DEBUGLOG_0(Adapter, CE_WARN,
7814919Sxy150489 "Could not get bus information");
7824919Sxy150489 return (DDI_FAILURE);
7833526Sxy150489 }
7843526Sxy150489
7854919Sxy150489 e1000_read_pci_cfg(hw, PCI_COMMAND_REGISTER, &hw->bus.pci_cmd_word);
7864919Sxy150489
7874919Sxy150489 hw->mac.autoneg_failed = B_TRUE;
7884919Sxy150489
7896735Scc210113 /* Set the autoneg_wait_to_complete flag to B_FALSE */
7906735Scc210113 hw->phy.autoneg_wait_to_complete = B_FALSE;
7913526Sxy150489
7923526Sxy150489 /* Adaptive IFS related changes */
7934919Sxy150489 hw->mac.adaptive_ifs = B_TRUE;
7944919Sxy150489
7954919Sxy150489 /* Enable phy init script for IGP phy of 82541/82547 */
7964919Sxy150489 if ((hw->mac.type == e1000_82547) ||
7974919Sxy150489 (hw->mac.type == e1000_82541) ||
7984919Sxy150489 (hw->mac.type == e1000_82547_rev_2) ||
7994919Sxy150489 (hw->mac.type == e1000_82541_rev_2))
8004919Sxy150489 e1000_init_script_state_82541(hw, B_TRUE);
8014919Sxy150489
8024919Sxy150489 /* Enable the TTL workaround for 82541/82547 */
8034919Sxy150489 e1000_set_ttl_workaround_state_82541(hw, B_TRUE);
8043526Sxy150489
8054608Syy150190 #ifdef __sparc
8064608Syy150190 Adapter->strip_crc = B_TRUE;
8074608Syy150190 #else
8084608Syy150190 Adapter->strip_crc = B_FALSE;
8094608Syy150190 #endif
8104608Syy150190
81110680SMin.Xu@Sun.COM /* setup the maximum MTU size of the chip */
81210680SMin.Xu@Sun.COM e1000g_setup_max_mtu(Adapter);
81310680SMin.Xu@Sun.COM
8144919Sxy150489 /* Get speed/duplex settings in conf file */
8154919Sxy150489 hw->mac.forced_speed_duplex = ADVERTISE_100_FULL;
8164919Sxy150489 hw->phy.autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
8173526Sxy150489 e1000g_force_speed_duplex(Adapter);
8183526Sxy150489
8194919Sxy150489 /* Get Jumbo Frames settings in conf file */
8203526Sxy150489 e1000g_get_max_frame_size(Adapter);
8213526Sxy150489
82211339SGuoqing.Zhu@Sun.COM /* Get conf file properties */
82311339SGuoqing.Zhu@Sun.COM e1000g_get_conf(Adapter);
82411339SGuoqing.Zhu@Sun.COM
82510680SMin.Xu@Sun.COM /* enforce PCH limits */
82610680SMin.Xu@Sun.COM e1000g_pch_limits(Adapter);
82710680SMin.Xu@Sun.COM
8283526Sxy150489 /* Set Rx/Tx buffer size */
8296394Scc210113 e1000g_set_bufsize(Adapter);
8304919Sxy150489
8314919Sxy150489 /* Master Latency Timer */
8324919Sxy150489 Adapter->master_latency_timer = DEFAULT_MASTER_LATENCY_TIMER;
8334919Sxy150489
8343526Sxy150489 /* copper options */
8356735Scc210113 if (hw->phy.media_type == e1000_media_type_copper) {
8364919Sxy150489 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
8374919Sxy150489 hw->phy.disable_polarity_correction = B_FALSE;
8384919Sxy150489 hw->phy.ms_type = e1000_ms_hw_default; /* E1000_MASTER_SLAVE */
8393526Sxy150489 }
8403526Sxy150489
8414919Sxy150489 /* The initial link state should be "unknown" */
8424061Sxy150489 Adapter->link_state = LINK_STATE_UNKNOWN;
8434061Sxy150489
8445882Syy150190 /* Initialize rx parameters */
8455882Syy150190 Adapter->rx_intr_delay = DEFAULT_RX_INTR_DELAY;
8465882Syy150190 Adapter->rx_intr_abs_delay = DEFAULT_RX_INTR_ABS_DELAY;
8475882Syy150190
8484919Sxy150489 /* Initialize tx parameters */
8494919Sxy150489 Adapter->tx_intr_enable = DEFAULT_TX_INTR_ENABLE;
8504919Sxy150489 Adapter->tx_bcopy_thresh = DEFAULT_TX_BCOPY_THRESHOLD;
8515882Syy150190 Adapter->tx_intr_delay = DEFAULT_TX_INTR_DELAY;
8525882Syy150190 Adapter->tx_intr_abs_delay = DEFAULT_TX_INTR_ABS_DELAY;
8534919Sxy150489
8544919Sxy150489 /* Initialize rx parameters */
8554919Sxy150489 Adapter->rx_bcopy_thresh = DEFAULT_RX_BCOPY_THRESHOLD;
8564919Sxy150489
8573526Sxy150489 return (DDI_SUCCESS);
8583526Sxy150489 }
8593526Sxy150489
8606394Scc210113 static void
e1000g_setup_max_mtu(struct e1000g * Adapter)86110680SMin.Xu@Sun.COM e1000g_setup_max_mtu(struct e1000g *Adapter)
86210680SMin.Xu@Sun.COM {
86310680SMin.Xu@Sun.COM struct e1000_mac_info *mac = &Adapter->shared.mac;
86410680SMin.Xu@Sun.COM struct e1000_phy_info *phy = &Adapter->shared.phy;
86510680SMin.Xu@Sun.COM
86610680SMin.Xu@Sun.COM switch (mac->type) {
86710680SMin.Xu@Sun.COM /* types that do not support jumbo frames */
86810680SMin.Xu@Sun.COM case e1000_ich8lan:
86910680SMin.Xu@Sun.COM case e1000_82573:
87010680SMin.Xu@Sun.COM case e1000_82583:
87110680SMin.Xu@Sun.COM Adapter->max_mtu = ETHERMTU;
87210680SMin.Xu@Sun.COM break;
87310680SMin.Xu@Sun.COM /* ich9 supports jumbo frames except on one phy type */
87410680SMin.Xu@Sun.COM case e1000_ich9lan:
87510680SMin.Xu@Sun.COM if (phy->type == e1000_phy_ife)
87610680SMin.Xu@Sun.COM Adapter->max_mtu = ETHERMTU;
87710680SMin.Xu@Sun.COM else
87810680SMin.Xu@Sun.COM Adapter->max_mtu = MAXIMUM_MTU_9K;
87910680SMin.Xu@Sun.COM break;
88010680SMin.Xu@Sun.COM /* pch can do jumbo frames up to 4K */
88110680SMin.Xu@Sun.COM case e1000_pchlan:
88210680SMin.Xu@Sun.COM Adapter->max_mtu = MAXIMUM_MTU_4K;
88310680SMin.Xu@Sun.COM break;
88410680SMin.Xu@Sun.COM /* types with a special limit */
88510680SMin.Xu@Sun.COM case e1000_82571:
88610680SMin.Xu@Sun.COM case e1000_82572:
88710680SMin.Xu@Sun.COM case e1000_82574:
88810680SMin.Xu@Sun.COM case e1000_80003es2lan:
88910680SMin.Xu@Sun.COM case e1000_ich10lan:
890*12853SChangqing.Li@Sun.COM if (e1000g_jumbo_mtu >= ETHERMTU &&
891*12853SChangqing.Li@Sun.COM e1000g_jumbo_mtu <= MAXIMUM_MTU_9K) {
892*12853SChangqing.Li@Sun.COM Adapter->max_mtu = e1000g_jumbo_mtu;
893*12853SChangqing.Li@Sun.COM } else {
894*12853SChangqing.Li@Sun.COM Adapter->max_mtu = MAXIMUM_MTU_9K;
895*12853SChangqing.Li@Sun.COM }
89610680SMin.Xu@Sun.COM break;
89710680SMin.Xu@Sun.COM /* default limit is 16K */
89810680SMin.Xu@Sun.COM default:
89910680SMin.Xu@Sun.COM Adapter->max_mtu = FRAME_SIZE_UPTO_16K -
900*12853SChangqing.Li@Sun.COM sizeof (struct ether_vlan_header) - ETHERFCSL;
90110680SMin.Xu@Sun.COM break;
90210680SMin.Xu@Sun.COM }
90310680SMin.Xu@Sun.COM }
90410680SMin.Xu@Sun.COM
90510680SMin.Xu@Sun.COM static void
e1000g_set_bufsize(struct e1000g * Adapter)9066394Scc210113 e1000g_set_bufsize(struct e1000g *Adapter)
9076394Scc210113 {
9086394Scc210113 struct e1000_mac_info *mac = &Adapter->shared.mac;
9096394Scc210113 uint64_t rx_size;
9106394Scc210113 uint64_t tx_size;
9116394Scc210113
9128073SMin.Xu@Sun.COM dev_info_t *devinfo = Adapter->dip;
9136394Scc210113 #ifdef __sparc
9146394Scc210113 ulong_t iommu_pagesize;
9158073SMin.Xu@Sun.COM #endif
9166394Scc210113 /* Get the system page size */
9176394Scc210113 Adapter->sys_page_sz = ddi_ptob(devinfo, (ulong_t)1);
9188073SMin.Xu@Sun.COM
9198073SMin.Xu@Sun.COM #ifdef __sparc
9206394Scc210113 iommu_pagesize = dvma_pagesize(devinfo);
9216394Scc210113 if (iommu_pagesize != 0) {
9226394Scc210113 if (Adapter->sys_page_sz == iommu_pagesize) {
9236394Scc210113 if (iommu_pagesize > 0x4000)
9246394Scc210113 Adapter->sys_page_sz = 0x4000;
9256394Scc210113 } else {
9266394Scc210113 if (Adapter->sys_page_sz > iommu_pagesize)
9276394Scc210113 Adapter->sys_page_sz = iommu_pagesize;
9286394Scc210113 }
9296394Scc210113 }
9306986Smx205022 if (Adapter->lso_enable) {
9316986Smx205022 Adapter->dvma_page_num = E1000_LSO_MAXLEN /
9326986Smx205022 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM;
9336986Smx205022 } else {
9346986Smx205022 Adapter->dvma_page_num = Adapter->max_frame_size /
9356986Smx205022 Adapter->sys_page_sz + E1000G_DEFAULT_DVMA_PAGE_NUM;
9366986Smx205022 }
9376394Scc210113 ASSERT(Adapter->dvma_page_num >= E1000G_DEFAULT_DVMA_PAGE_NUM);
9386394Scc210113 #endif
9396394Scc210113
9406735Scc210113 Adapter->min_frame_size = ETHERMIN + ETHERFCSL;
9416735Scc210113
9428417SChenlu.Chen@Sun.COM if (Adapter->mem_workaround_82546 &&
9438417SChenlu.Chen@Sun.COM ((mac->type == e1000_82545) ||
9448178SChenlu.Chen@Sun.COM (mac->type == e1000_82546) ||
9458417SChenlu.Chen@Sun.COM (mac->type == e1000_82546_rev_3))) {
946*12853SChangqing.Li@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K;
9478178SChenlu.Chen@Sun.COM } else {
948*12853SChangqing.Li@Sun.COM rx_size = Adapter->max_frame_size;
9498178SChenlu.Chen@Sun.COM if ((rx_size > FRAME_SIZE_UPTO_2K) &&
9508178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_4K))
9518178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_4K;
9528178SChenlu.Chen@Sun.COM else if ((rx_size > FRAME_SIZE_UPTO_4K) &&
9538178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_8K))
9548178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_8K;
9558178SChenlu.Chen@Sun.COM else if ((rx_size > FRAME_SIZE_UPTO_8K) &&
9568178SChenlu.Chen@Sun.COM (rx_size <= FRAME_SIZE_UPTO_16K))
9578178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_16K;
9588178SChenlu.Chen@Sun.COM else
9598178SChenlu.Chen@Sun.COM Adapter->rx_buffer_size = E1000_RX_BUFFER_SIZE_2K;
9608178SChenlu.Chen@Sun.COM }
961*12853SChangqing.Li@Sun.COM Adapter->rx_buffer_size += E1000G_IPALIGNROOM;
9626394Scc210113
9636735Scc210113 tx_size = Adapter->max_frame_size;
9646394Scc210113 if ((tx_size > FRAME_SIZE_UPTO_2K) && (tx_size <= FRAME_SIZE_UPTO_4K))
9656394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_4K;
9666394Scc210113 else if ((tx_size > FRAME_SIZE_UPTO_4K) &&
9676394Scc210113 (tx_size <= FRAME_SIZE_UPTO_8K))
9686394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_8K;
9696394Scc210113 else if ((tx_size > FRAME_SIZE_UPTO_8K) &&
9706394Scc210113 (tx_size <= FRAME_SIZE_UPTO_16K))
9716394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_16K;
9726394Scc210113 else
9736394Scc210113 Adapter->tx_buffer_size = E1000_TX_BUFFER_SIZE_2K;
9746394Scc210113
9756394Scc210113 /*
9766394Scc210113 * For Wiseman adapters we have an requirement of having receive
9776394Scc210113 * buffers aligned at 256 byte boundary. Since Livengood does not
9786394Scc210113 * require this and forcing it for all hardwares will have
9796394Scc210113 * performance implications, I am making it applicable only for
9806394Scc210113 * Wiseman and for Jumbo frames enabled mode as rest of the time,
9816394Scc210113 * it is okay to have normal frames...but it does involve a
9826394Scc210113 * potential risk where we may loose data if buffer is not
9836394Scc210113 * aligned...so all wiseman boards to have 256 byte aligned
9846394Scc210113 * buffers
9856394Scc210113 */
9866394Scc210113 if (mac->type < e1000_82543)
9876394Scc210113 Adapter->rx_buf_align = RECEIVE_BUFFER_ALIGN_SIZE;
9886394Scc210113 else
9896394Scc210113 Adapter->rx_buf_align = 1;
9906394Scc210113 }
9916394Scc210113
9923526Sxy150489 /*
9934919Sxy150489 * e1000g_detach - driver detach
9944919Sxy150489 *
9954919Sxy150489 * The detach() function is the complement of the attach routine.
9964919Sxy150489 * If cmd is set to DDI_DETACH, detach() is used to remove the
9974919Sxy150489 * state associated with a given instance of a device node
9984919Sxy150489 * prior to the removal of that instance from the system.
9994919Sxy150489 *
10004919Sxy150489 * The detach() function will be called once for each instance
10014919Sxy150489 * of the device for which there has been a successful attach()
10024919Sxy150489 * once there are no longer any opens on the device.
10034919Sxy150489 *
10044919Sxy150489 * Interrupts routine are disabled, All memory allocated by this
10054919Sxy150489 * driver are freed.
10063526Sxy150489 */
10073526Sxy150489 static int
e1000g_detach(dev_info_t * devinfo,ddi_detach_cmd_t cmd)10084919Sxy150489 e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
10093526Sxy150489 {
10103526Sxy150489 struct e1000g *Adapter;
10114982Syy150190 boolean_t rx_drain;
10123526Sxy150489
10133526Sxy150489 switch (cmd) {
10143526Sxy150489 default:
10153526Sxy150489 return (DDI_FAILURE);
10163526Sxy150489
10173526Sxy150489 case DDI_SUSPEND:
10183526Sxy150489 return (e1000g_suspend(devinfo));
10193526Sxy150489
10203526Sxy150489 case DDI_DETACH:
10213526Sxy150489 break;
10223526Sxy150489 }
10233526Sxy150489
10243526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
10253526Sxy150489 if (Adapter == NULL)
10263526Sxy150489 return (DDI_FAILURE);
10273526Sxy150489
10288275SEric Cheng rx_drain = e1000g_rx_drain(Adapter);
10298275SEric Cheng if (!rx_drain && !e1000g_force_detach)
10308275SEric Cheng return (DDI_FAILURE);
10318275SEric Cheng
10324919Sxy150489 if (mac_unregister(Adapter->mh) != 0) {
10334919Sxy150489 e1000g_log(Adapter, CE_WARN, "Unregister MAC failed");
10344919Sxy150489 return (DDI_FAILURE);
10354919Sxy150489 }
10364919Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_MAC;
10374919Sxy150489
10388479SChenlu.Chen@Sun.COM ASSERT(!(Adapter->e1000g_state & E1000G_STARTED));
10394982Syy150190
10408850SMin.Xu@Sun.COM if (!e1000g_force_detach && !rx_drain)
10418850SMin.Xu@Sun.COM return (DDI_FAILURE);
10423526Sxy150489
10433526Sxy150489 e1000g_unattach(devinfo, Adapter);
10443526Sxy150489
10453526Sxy150489 return (DDI_SUCCESS);
10463526Sxy150489 }
10473526Sxy150489
10484982Syy150190 /*
10494982Syy150190 * e1000g_free_priv_devi_node - free a priv_dip entry for driver instance
10504982Syy150190 */
10518850SMin.Xu@Sun.COM void
e1000g_free_priv_devi_node(private_devi_list_t * devi_node)10528850SMin.Xu@Sun.COM e1000g_free_priv_devi_node(private_devi_list_t *devi_node)
10534982Syy150190 {
10544982Syy150190 ASSERT(e1000g_private_devi_list != NULL);
10558850SMin.Xu@Sun.COM ASSERT(devi_node != NULL);
10568850SMin.Xu@Sun.COM
10578850SMin.Xu@Sun.COM if (devi_node->prev != NULL)
10588850SMin.Xu@Sun.COM devi_node->prev->next = devi_node->next;
10598850SMin.Xu@Sun.COM if (devi_node->next != NULL)
10608850SMin.Xu@Sun.COM devi_node->next->prev = devi_node->prev;
10618850SMin.Xu@Sun.COM if (devi_node == e1000g_private_devi_list)
10628850SMin.Xu@Sun.COM e1000g_private_devi_list = devi_node->next;
10638850SMin.Xu@Sun.COM
10648850SMin.Xu@Sun.COM kmem_free(devi_node->priv_dip,
10658850SMin.Xu@Sun.COM sizeof (struct dev_info));
10668850SMin.Xu@Sun.COM kmem_free(devi_node,
10678850SMin.Xu@Sun.COM sizeof (private_devi_list_t));
10684982Syy150190 }
10694982Syy150190
10703526Sxy150489 static void
e1000g_unattach(dev_info_t * devinfo,struct e1000g * Adapter)10713526Sxy150489 e1000g_unattach(dev_info_t *devinfo, struct e1000g *Adapter)
10723526Sxy150489 {
10738850SMin.Xu@Sun.COM private_devi_list_t *devi_node;
10747133Scc210113 int result;
10757133Scc210113
10764919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) {
10773526Sxy150489 (void) e1000g_disable_intrs(Adapter);
10783526Sxy150489 }
10793526Sxy150489
10804919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_MAC) {
10813526Sxy150489 (void) mac_unregister(Adapter->mh);
10823526Sxy150489 }
10833526Sxy150489
10844919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_ADD_INTR) {
10853526Sxy150489 (void) e1000g_rem_intrs(Adapter);
10863526Sxy150489 }
10873526Sxy150489
10884919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_SETUP) {
10893526Sxy150489 (void) ddi_prop_remove_all(devinfo);
10903526Sxy150489 }
10913526Sxy150489
10923526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_KSTATS) {
10933526Sxy150489 kstat_delete((kstat_t *)Adapter->e1000g_ksp);
10943526Sxy150489 }
10953526Sxy150489
10963526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_INIT) {
10974919Sxy150489 stop_link_timer(Adapter);
10987133Scc210113
10997133Scc210113 mutex_enter(&e1000g_nvm_lock);
11007133Scc210113 result = e1000_reset_hw(&Adapter->shared);
11017133Scc210113 mutex_exit(&e1000g_nvm_lock);
11027133Scc210113
11037133Scc210113 if (result != E1000_SUCCESS) {
11045273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
11055273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
11065273Sgl147354 }
11073526Sxy150489 }
11083526Sxy150489
11099770SChangqing.Li@Sun.COM e1000g_release_multicast(Adapter);
11109770SChangqing.Li@Sun.COM
11114919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_REGS_MAP) {
11124919Sxy150489 if (Adapter->osdep.reg_handle != NULL)
11134919Sxy150489 ddi_regs_map_free(&Adapter->osdep.reg_handle);
11144919Sxy150489 if (Adapter->osdep.ich_flash_handle != NULL)
11154919Sxy150489 ddi_regs_map_free(&Adapter->osdep.ich_flash_handle);
111611532SGuoqing.Zhu@Sun.COM if (Adapter->osdep.io_reg_handle != NULL)
111711532SGuoqing.Zhu@Sun.COM ddi_regs_map_free(&Adapter->osdep.io_reg_handle);
11183526Sxy150489 }
11193526Sxy150489
11204919Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) {
11214919Sxy150489 if (Adapter->osdep.cfg_handle != NULL)
11224919Sxy150489 pci_config_teardown(&Adapter->osdep.cfg_handle);
11233526Sxy150489 }
11243526Sxy150489
11253526Sxy150489 if (Adapter->attach_progress & ATTACH_PROGRESS_LOCKS) {
11263526Sxy150489 e1000g_destroy_locks(Adapter);
11273526Sxy150489 }
11283526Sxy150489
11295273Sgl147354 if (Adapter->attach_progress & ATTACH_PROGRESS_FMINIT) {
11305273Sgl147354 e1000g_fm_fini(Adapter);
11315273Sgl147354 }
11325273Sgl147354
11338850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock);
11349190SMin.Xu@Sun.COM if (e1000g_force_detach && (Adapter->priv_devi_node != NULL)) {
11358850SMin.Xu@Sun.COM devi_node = Adapter->priv_devi_node;
11368850SMin.Xu@Sun.COM devi_node->flag |= E1000G_PRIV_DEVI_DETACH;
11378850SMin.Xu@Sun.COM
11388850SMin.Xu@Sun.COM if (devi_node->pending_rx_count == 0) {
11398850SMin.Xu@Sun.COM e1000g_free_priv_devi_node(devi_node);
11408850SMin.Xu@Sun.COM }
11418850SMin.Xu@Sun.COM }
11428850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock);
11438850SMin.Xu@Sun.COM
11443526Sxy150489 kmem_free((caddr_t)Adapter, sizeof (struct e1000g));
11453526Sxy150489
11463526Sxy150489 /*
11473526Sxy150489 * Another hotplug spec requirement,
11483526Sxy150489 * run ddi_set_driver_private(devinfo, null);
11493526Sxy150489 */
11503526Sxy150489 ddi_set_driver_private(devinfo, NULL);
11513526Sxy150489 }
11523526Sxy150489
115311532SGuoqing.Zhu@Sun.COM /*
115411532SGuoqing.Zhu@Sun.COM * Get the BAR type and rnumber for a given PCI BAR offset
115511532SGuoqing.Zhu@Sun.COM */
115611532SGuoqing.Zhu@Sun.COM static int
e1000g_get_bar_info(dev_info_t * dip,int bar_offset,bar_info_t * bar_info)115711532SGuoqing.Zhu@Sun.COM e1000g_get_bar_info(dev_info_t *dip, int bar_offset, bar_info_t *bar_info)
115811532SGuoqing.Zhu@Sun.COM {
115911532SGuoqing.Zhu@Sun.COM pci_regspec_t *regs;
116011532SGuoqing.Zhu@Sun.COM uint_t regs_length;
116111604SGuoqing.Zhu@Sun.COM int type, rnumber, rcount;
116211532SGuoqing.Zhu@Sun.COM
116311532SGuoqing.Zhu@Sun.COM ASSERT((bar_offset >= PCI_CONF_BASE0) &&
116411532SGuoqing.Zhu@Sun.COM (bar_offset <= PCI_CONF_BASE5));
116511532SGuoqing.Zhu@Sun.COM
116611532SGuoqing.Zhu@Sun.COM /*
116711532SGuoqing.Zhu@Sun.COM * Get the DDI "reg" property
116811532SGuoqing.Zhu@Sun.COM */
116911532SGuoqing.Zhu@Sun.COM if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
117011532SGuoqing.Zhu@Sun.COM DDI_PROP_DONTPASS, "reg", (int **)®s,
117111532SGuoqing.Zhu@Sun.COM ®s_length) != DDI_PROP_SUCCESS) {
117211532SGuoqing.Zhu@Sun.COM return (DDI_FAILURE);
117311532SGuoqing.Zhu@Sun.COM }
117411532SGuoqing.Zhu@Sun.COM
117511604SGuoqing.Zhu@Sun.COM rcount = regs_length * sizeof (int) / sizeof (pci_regspec_t);
117611532SGuoqing.Zhu@Sun.COM /*
117711532SGuoqing.Zhu@Sun.COM * Check the BAR offset
117811532SGuoqing.Zhu@Sun.COM */
117911604SGuoqing.Zhu@Sun.COM for (rnumber = 0; rnumber < rcount; ++rnumber) {
118011532SGuoqing.Zhu@Sun.COM if (PCI_REG_REG_G(regs[rnumber].pci_phys_hi) == bar_offset) {
118111532SGuoqing.Zhu@Sun.COM type = regs[rnumber].pci_phys_hi & PCI_ADDR_MASK;
118211532SGuoqing.Zhu@Sun.COM break;
118311532SGuoqing.Zhu@Sun.COM }
118411532SGuoqing.Zhu@Sun.COM }
118511532SGuoqing.Zhu@Sun.COM
118611532SGuoqing.Zhu@Sun.COM ddi_prop_free(regs);
118711532SGuoqing.Zhu@Sun.COM
118811604SGuoqing.Zhu@Sun.COM if (rnumber >= rcount)
118911532SGuoqing.Zhu@Sun.COM return (DDI_FAILURE);
119011532SGuoqing.Zhu@Sun.COM
119111532SGuoqing.Zhu@Sun.COM switch (type) {
119211532SGuoqing.Zhu@Sun.COM case PCI_ADDR_CONFIG:
119311532SGuoqing.Zhu@Sun.COM bar_info->type = E1000G_BAR_CONFIG;
119411532SGuoqing.Zhu@Sun.COM break;
119511532SGuoqing.Zhu@Sun.COM case PCI_ADDR_IO:
119611532SGuoqing.Zhu@Sun.COM bar_info->type = E1000G_BAR_IO;
119711532SGuoqing.Zhu@Sun.COM break;
119811532SGuoqing.Zhu@Sun.COM case PCI_ADDR_MEM32:
119911532SGuoqing.Zhu@Sun.COM bar_info->type = E1000G_BAR_MEM32;
120011532SGuoqing.Zhu@Sun.COM break;
120111532SGuoqing.Zhu@Sun.COM case PCI_ADDR_MEM64:
120211532SGuoqing.Zhu@Sun.COM bar_info->type = E1000G_BAR_MEM64;
120311532SGuoqing.Zhu@Sun.COM break;
120411532SGuoqing.Zhu@Sun.COM default:
120511532SGuoqing.Zhu@Sun.COM return (DDI_FAILURE);
120611532SGuoqing.Zhu@Sun.COM }
120711532SGuoqing.Zhu@Sun.COM bar_info->rnumber = rnumber;
120811532SGuoqing.Zhu@Sun.COM return (DDI_SUCCESS);
120911532SGuoqing.Zhu@Sun.COM }
121011532SGuoqing.Zhu@Sun.COM
12113526Sxy150489 static void
e1000g_init_locks(struct e1000g * Adapter)12123526Sxy150489 e1000g_init_locks(struct e1000g *Adapter)
12133526Sxy150489 {
12143526Sxy150489 e1000g_tx_ring_t *tx_ring;
12153526Sxy150489 e1000g_rx_ring_t *rx_ring;
12163526Sxy150489
12173526Sxy150489 rw_init(&Adapter->chip_lock, NULL,
12183526Sxy150489 RW_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12194919Sxy150489 mutex_init(&Adapter->link_lock, NULL,
12203526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12214919Sxy150489 mutex_init(&Adapter->watchdog_lock, NULL,
12223526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12233526Sxy150489
12243526Sxy150489 tx_ring = Adapter->tx_ring;
12253526Sxy150489
12263526Sxy150489 mutex_init(&tx_ring->tx_lock, NULL,
12273526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12283526Sxy150489 mutex_init(&tx_ring->usedlist_lock, NULL,
12293526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12303526Sxy150489 mutex_init(&tx_ring->freelist_lock, NULL,
12313526Sxy150489 MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12323526Sxy150489
12333526Sxy150489 rx_ring = Adapter->rx_ring;
12343526Sxy150489
12357436STed.You@Sun.COM mutex_init(&rx_ring->rx_lock, NULL,
12367436STed.You@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
12373526Sxy150489 }
12383526Sxy150489
12393526Sxy150489 static void
e1000g_destroy_locks(struct e1000g * Adapter)12403526Sxy150489 e1000g_destroy_locks(struct e1000g *Adapter)
12413526Sxy150489 {
12423526Sxy150489 e1000g_tx_ring_t *tx_ring;
12433526Sxy150489 e1000g_rx_ring_t *rx_ring;
12443526Sxy150489
12453526Sxy150489 tx_ring = Adapter->tx_ring;
12463526Sxy150489 mutex_destroy(&tx_ring->tx_lock);
12473526Sxy150489 mutex_destroy(&tx_ring->usedlist_lock);
12483526Sxy150489 mutex_destroy(&tx_ring->freelist_lock);
12493526Sxy150489
12503526Sxy150489 rx_ring = Adapter->rx_ring;
12517436STed.You@Sun.COM mutex_destroy(&rx_ring->rx_lock);
12523526Sxy150489
12534919Sxy150489 mutex_destroy(&Adapter->link_lock);
12544919Sxy150489 mutex_destroy(&Adapter->watchdog_lock);
12553526Sxy150489 rw_destroy(&Adapter->chip_lock);
125610680SMin.Xu@Sun.COM
125710680SMin.Xu@Sun.COM /* destory mutex initialized in shared code */
125810680SMin.Xu@Sun.COM e1000_destroy_hw_mutex(&Adapter->shared);
12593526Sxy150489 }
12603526Sxy150489
12613526Sxy150489 static int
e1000g_resume(dev_info_t * devinfo)12623526Sxy150489 e1000g_resume(dev_info_t *devinfo)
12633526Sxy150489 {
12643526Sxy150489 struct e1000g *Adapter;
12653526Sxy150489
12663526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
12673526Sxy150489 if (Adapter == NULL)
12688479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_PANIC,
12698479SChenlu.Chen@Sun.COM "Instance pointer is null\n");
12708479SChenlu.Chen@Sun.COM
12718479SChenlu.Chen@Sun.COM if (Adapter->dip != devinfo)
12728479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_PANIC,
12738479SChenlu.Chen@Sun.COM "Devinfo is not the same as saved devinfo\n");
12748479SChenlu.Chen@Sun.COM
12758479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
12768479SChenlu.Chen@Sun.COM
12778479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) {
12788479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_FALSE) != DDI_SUCCESS) {
12798479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
12808479SChenlu.Chen@Sun.COM /*
12818479SChenlu.Chen@Sun.COM * We note the failure, but return success, as the
12828479SChenlu.Chen@Sun.COM * system is still usable without this controller.
12838479SChenlu.Chen@Sun.COM */
12848479SChenlu.Chen@Sun.COM e1000g_log(Adapter, CE_WARN,
12858479SChenlu.Chen@Sun.COM "e1000g_resume: failed to restart controller\n");
12868479SChenlu.Chen@Sun.COM return (DDI_SUCCESS);
12878479SChenlu.Chen@Sun.COM }
12888479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */
12898479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter);
12908479SChenlu.Chen@Sun.COM }
12918479SChenlu.Chen@Sun.COM
12928479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_SUSPENDED;
12938479SChenlu.Chen@Sun.COM
12948479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
12953526Sxy150489
12963526Sxy150489 return (DDI_SUCCESS);
12973526Sxy150489 }
12983526Sxy150489
12993526Sxy150489 static int
e1000g_suspend(dev_info_t * devinfo)13003526Sxy150489 e1000g_suspend(dev_info_t *devinfo)
13013526Sxy150489 {
13023526Sxy150489 struct e1000g *Adapter;
13033526Sxy150489
13043526Sxy150489 Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
13053526Sxy150489 if (Adapter == NULL)
13063526Sxy150489 return (DDI_FAILURE);
13073526Sxy150489
13088479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
13098479SChenlu.Chen@Sun.COM
13108479SChenlu.Chen@Sun.COM Adapter->e1000g_state |= E1000G_SUSPENDED;
13118479SChenlu.Chen@Sun.COM
13128479SChenlu.Chen@Sun.COM /* if the port isn't plumbed, we can simply return */
13138479SChenlu.Chen@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) {
13148479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
13158479SChenlu.Chen@Sun.COM return (DDI_SUCCESS);
13168479SChenlu.Chen@Sun.COM }
13178479SChenlu.Chen@Sun.COM
13188479SChenlu.Chen@Sun.COM e1000g_stop(Adapter, B_FALSE);
13198479SChenlu.Chen@Sun.COM
13208479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
13218479SChenlu.Chen@Sun.COM
13228479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */
13238479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter);
13248479SChenlu.Chen@Sun.COM stop_link_timer(Adapter);
13258479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring);
13263526Sxy150489
13273526Sxy150489 return (DDI_SUCCESS);
13283526Sxy150489 }
13293526Sxy150489
13303526Sxy150489 static int
e1000g_init(struct e1000g * Adapter)13313526Sxy150489 e1000g_init(struct e1000g *Adapter)
13323526Sxy150489 {
13333526Sxy150489 uint32_t pba;
13344919Sxy150489 uint32_t high_water;
13353526Sxy150489 struct e1000_hw *hw;
13364061Sxy150489 clock_t link_timeout;
13377133Scc210113 int result;
13383526Sxy150489
13394919Sxy150489 hw = &Adapter->shared;
13403526Sxy150489
13413526Sxy150489 /*
13423526Sxy150489 * reset to put the hardware in a known state
13433526Sxy150489 * before we try to do anything with the eeprom
13443526Sxy150489 */
13457133Scc210113 mutex_enter(&e1000g_nvm_lock);
13467133Scc210113 result = e1000_reset_hw(hw);
13477133Scc210113 mutex_exit(&e1000g_nvm_lock);
13487133Scc210113
13497133Scc210113 if (result != E1000_SUCCESS) {
13505273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
13515273Sgl147354 goto init_fail;
13525273Sgl147354 }
13533526Sxy150489
13547133Scc210113 mutex_enter(&e1000g_nvm_lock);
13557133Scc210113 result = e1000_validate_nvm_checksum(hw);
13567133Scc210113 if (result < E1000_SUCCESS) {
13574061Sxy150489 /*
13584061Sxy150489 * Some PCI-E parts fail the first check due to
13594061Sxy150489 * the link being in sleep state. Call it again,
13604061Sxy150489 * if it fails a second time its a real issue.
13614061Sxy150489 */
13627133Scc210113 result = e1000_validate_nvm_checksum(hw);
13637133Scc210113 }
13647133Scc210113 mutex_exit(&e1000g_nvm_lock);
13657133Scc210113
13667133Scc210113 if (result < E1000_SUCCESS) {
13677133Scc210113 e1000g_log(Adapter, CE_WARN,
13687133Scc210113 "Invalid NVM checksum. Please contact "
13697133Scc210113 "the vendor to update the NVM.");
13707133Scc210113 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
13717133Scc210113 goto init_fail;
13727133Scc210113 }
13737133Scc210113
13747133Scc210113 result = 0;
13753526Sxy150489 #ifdef __sparc
13763526Sxy150489 /*
13777607STed.You@Sun.COM * First, we try to get the local ethernet address from OBP. If
13787133Scc210113 * failed, then we get it from the EEPROM of NIC card.
13793526Sxy150489 */
13807133Scc210113 result = e1000g_find_mac_address(Adapter);
13817133Scc210113 #endif
13823526Sxy150489 /* Get the local ethernet address. */
13837133Scc210113 if (!result) {
13847133Scc210113 mutex_enter(&e1000g_nvm_lock);
13857140Scc210113 result = e1000_read_mac_addr(hw);
13867133Scc210113 mutex_exit(&e1000g_nvm_lock);
13877133Scc210113 }
13887133Scc210113
13897133Scc210113 if (result < E1000_SUCCESS) {
13903526Sxy150489 e1000g_log(Adapter, CE_WARN, "Read mac addr failed");
13915273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
13923526Sxy150489 goto init_fail;
13933526Sxy150489 }
13943526Sxy150489
13953526Sxy150489 /* check for valid mac address */
13964919Sxy150489 if (!is_valid_mac_addr(hw->mac.addr)) {
13973526Sxy150489 e1000g_log(Adapter, CE_WARN, "Invalid mac addr");
13985273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
13993526Sxy150489 goto init_fail;
14003526Sxy150489 }
14013526Sxy150489
14024919Sxy150489 /* Set LAA state for 82571 chipset */
14034919Sxy150489 e1000_set_laa_state_82571(hw, B_TRUE);
14043526Sxy150489
14053526Sxy150489 /* Master Latency Timer implementation */
14064919Sxy150489 if (Adapter->master_latency_timer) {
14074919Sxy150489 pci_config_put8(Adapter->osdep.cfg_handle,
14084919Sxy150489 PCI_CONF_LATENCY_TIMER, Adapter->master_latency_timer);
14093526Sxy150489 }
14103526Sxy150489
14114919Sxy150489 if (hw->mac.type < e1000_82547) {
14123526Sxy150489 /*
14133526Sxy150489 * Total FIFO is 64K
14143526Sxy150489 */
14156735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
14163526Sxy150489 pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
14173526Sxy150489 else
14183526Sxy150489 pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */
14197140Scc210113 } else if ((hw->mac.type == e1000_82571) ||
14207140Scc210113 (hw->mac.type == e1000_82572) ||
14217140Scc210113 (hw->mac.type == e1000_80003es2lan)) {
14223526Sxy150489 /*
14233526Sxy150489 * Total FIFO is 48K
14243526Sxy150489 */
14256735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
14263526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 18K for Tx */
14273526Sxy150489 else
14283526Sxy150489 pba = E1000_PBA_38K; /* 38K for Rx, 10K for Tx */
14297607STed.You@Sun.COM } else if (hw->mac.type == e1000_82573) {
14307607STed.You@Sun.COM pba = E1000_PBA_20K; /* 20K for Rx, 12K for Tx */
14317607STed.You@Sun.COM } else if (hw->mac.type == e1000_82574) {
14327607STed.You@Sun.COM /* Keep adapter default: 20K for Rx, 20K for Tx */
14337607STed.You@Sun.COM pba = E1000_READ_REG(hw, E1000_PBA);
14344919Sxy150489 } else if (hw->mac.type == e1000_ich8lan) {
14353526Sxy150489 pba = E1000_PBA_8K; /* 8K for Rx, 12K for Tx */
14364919Sxy150489 } else if (hw->mac.type == e1000_ich9lan) {
14377607STed.You@Sun.COM pba = E1000_PBA_10K;
14387607STed.You@Sun.COM } else if (hw->mac.type == e1000_ich10lan) {
14397607STed.You@Sun.COM pba = E1000_PBA_10K;
144010680SMin.Xu@Sun.COM } else if (hw->mac.type == e1000_pchlan) {
144110680SMin.Xu@Sun.COM pba = E1000_PBA_26K;
14423526Sxy150489 } else {
14433526Sxy150489 /*
14443526Sxy150489 * Total FIFO is 40K
14453526Sxy150489 */
14466735Scc210113 if (Adapter->max_frame_size > FRAME_SIZE_UPTO_8K)
14473526Sxy150489 pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
14483526Sxy150489 else
14493526Sxy150489 pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */
14503526Sxy150489 }
14514919Sxy150489 E1000_WRITE_REG(hw, E1000_PBA, pba);
14523526Sxy150489
14533526Sxy150489 /*
14543526Sxy150489 * These parameters set thresholds for the adapter's generation(Tx)
14553526Sxy150489 * and response(Rx) to Ethernet PAUSE frames. These are just threshold
14563526Sxy150489 * settings. Flow control is enabled or disabled in the configuration
14573526Sxy150489 * file.
14583526Sxy150489 * High-water mark is set down from the top of the rx fifo (not
14593526Sxy150489 * sensitive to max_frame_size) and low-water is set just below
14603526Sxy150489 * high-water mark.
14614919Sxy150489 * The high water mark must be low enough to fit one full frame above
14624919Sxy150489 * it in the rx FIFO. Should be the lower of:
14634919Sxy150489 * 90% of the Rx FIFO size and the full Rx FIFO size minus the early
14644919Sxy150489 * receive size (assuming ERT set to E1000_ERT_2048), or the full
14654919Sxy150489 * Rx FIFO size minus one full frame.
14663526Sxy150489 */
14674919Sxy150489 high_water = min(((pba << 10) * 9 / 10),
14688479SChenlu.Chen@Sun.COM ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574 ||
14698479SChenlu.Chen@Sun.COM hw->mac.type == e1000_ich9lan || hw->mac.type == e1000_ich10lan) ?
14704919Sxy150489 ((pba << 10) - (E1000_ERT_2048 << 3)) :
14716735Scc210113 ((pba << 10) - Adapter->max_frame_size)));
14726735Scc210113
14736735Scc210113 hw->fc.high_water = high_water & 0xFFF8;
14746735Scc210113 hw->fc.low_water = hw->fc.high_water - 8;
14754919Sxy150489
14764919Sxy150489 if (hw->mac.type == e1000_80003es2lan)
14776735Scc210113 hw->fc.pause_time = 0xFFFF;
14784919Sxy150489 else
14796735Scc210113 hw->fc.pause_time = E1000_FC_PAUSE_TIME;
14806735Scc210113 hw->fc.send_xon = B_TRUE;
14813526Sxy150489
14823526Sxy150489 /*
14833526Sxy150489 * Reset the adapter hardware the second time.
14843526Sxy150489 */
14857133Scc210113 mutex_enter(&e1000g_nvm_lock);
14867133Scc210113 result = e1000_reset_hw(hw);
14877133Scc210113 mutex_exit(&e1000g_nvm_lock);
14887133Scc210113
14897133Scc210113 if (result != E1000_SUCCESS) {
14905273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
14915273Sgl147354 goto init_fail;
14925273Sgl147354 }
14933526Sxy150489
14943526Sxy150489 /* disable wakeup control by default */
14954919Sxy150489 if (hw->mac.type >= e1000_82544)
14964919Sxy150489 E1000_WRITE_REG(hw, E1000_WUC, 0);
14973526Sxy150489
14988178SChenlu.Chen@Sun.COM /*
14998178SChenlu.Chen@Sun.COM * MWI should be disabled on 82546.
15008178SChenlu.Chen@Sun.COM */
15018178SChenlu.Chen@Sun.COM if (hw->mac.type == e1000_82546)
15028178SChenlu.Chen@Sun.COM e1000_pci_clear_mwi(hw);
15038178SChenlu.Chen@Sun.COM else
15048178SChenlu.Chen@Sun.COM e1000_pci_set_mwi(hw);
15053526Sxy150489
15063526Sxy150489 /*
15073526Sxy150489 * Configure/Initialize hardware
15083526Sxy150489 */
15097133Scc210113 mutex_enter(&e1000g_nvm_lock);
15107133Scc210113 result = e1000_init_hw(hw);
15117133Scc210113 mutex_exit(&e1000g_nvm_lock);
15127133Scc210113
15137133Scc210113 if (result < E1000_SUCCESS) {
15143526Sxy150489 e1000g_log(Adapter, CE_WARN, "Initialize hw failed");
15155273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
15163526Sxy150489 goto init_fail;
15173526Sxy150489 }
15183526Sxy150489
15197436STed.You@Sun.COM /*
15207436STed.You@Sun.COM * Restore LED settings to the default from EEPROM
15217436STed.You@Sun.COM * to meet the standard for Sun platforms.
15227436STed.You@Sun.COM */
152310605SMin.Xu@Sun.COM (void) e1000_cleanup_led(hw);
15247436STed.You@Sun.COM
15253526Sxy150489 /* Disable Smart Power Down */
15263526Sxy150489 phy_spd_state(hw, B_FALSE);
15273526Sxy150489
15285082Syy150190 /* Make sure driver has control */
15295082Syy150190 e1000g_get_driver_control(hw);
15305082Syy150190
15313526Sxy150489 /*
15323526Sxy150489 * Initialize unicast addresses.
15333526Sxy150489 */
15343526Sxy150489 e1000g_init_unicst(Adapter);
15353526Sxy150489
15363526Sxy150489 /*
15373526Sxy150489 * Setup and initialize the mctable structures. After this routine
15383526Sxy150489 * completes Multicast table will be set
15393526Sxy150489 */
154010680SMin.Xu@Sun.COM e1000_update_mc_addr_list(hw,
154110680SMin.Xu@Sun.COM (uint8_t *)Adapter->mcast_table, Adapter->mcast_count);
15424919Sxy150489 msec_delay(5);
15433526Sxy150489
15443526Sxy150489 /*
15453526Sxy150489 * Implement Adaptive IFS
15463526Sxy150489 */
15473526Sxy150489 e1000_reset_adaptive(hw);
15483526Sxy150489
15493526Sxy150489 /* Setup Interrupt Throttling Register */
15505882Syy150190 if (hw->mac.type >= e1000_82540) {
15515882Syy150190 E1000_WRITE_REG(hw, E1000_ITR, Adapter->intr_throttling_rate);
15525882Syy150190 } else
15535882Syy150190 Adapter->intr_adaptive = B_FALSE;
15543526Sxy150489
15554061Sxy150489 /* Start the timer for link setup */
15564919Sxy150489 if (hw->mac.autoneg)
15574919Sxy150489 link_timeout = PHY_AUTO_NEG_LIMIT * drv_usectohz(100000);
15584061Sxy150489 else
15594919Sxy150489 link_timeout = PHY_FORCE_LIMIT * drv_usectohz(100000);
15604919Sxy150489
15614919Sxy150489 mutex_enter(&Adapter->link_lock);
15626735Scc210113 if (hw->phy.autoneg_wait_to_complete) {
15634061Sxy150489 Adapter->link_complete = B_TRUE;
15643526Sxy150489 } else {
15654061Sxy150489 Adapter->link_complete = B_FALSE;
15664061Sxy150489 Adapter->link_tid = timeout(e1000g_link_timer,
15674061Sxy150489 (void *)Adapter, link_timeout);
15683526Sxy150489 }
15694919Sxy150489 mutex_exit(&Adapter->link_lock);
15703526Sxy150489
15715082Syy150190 /* Save the state of the phy */
15725082Syy150190 e1000g_get_phy_state(Adapter);
15735082Syy150190
15746512Ssowmini e1000g_param_sync(Adapter);
15756512Ssowmini
15763526Sxy150489 Adapter->init_count++;
15773526Sxy150489
15785273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.cfg_handle) != DDI_FM_OK) {
15795273Sgl147354 goto init_fail;
15805273Sgl147354 }
15815273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
15825273Sgl147354 goto init_fail;
15835273Sgl147354 }
15845273Sgl147354
15858275SEric Cheng Adapter->poll_mode = e1000g_poll_mode;
15868275SEric Cheng
15873526Sxy150489 return (DDI_SUCCESS);
15883526Sxy150489
15893526Sxy150489 init_fail:
15905273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
15913526Sxy150489 return (DDI_FAILURE);
15923526Sxy150489 }
15933526Sxy150489
15948850SMin.Xu@Sun.COM static int
e1000g_alloc_rx_data(struct e1000g * Adapter)15958850SMin.Xu@Sun.COM e1000g_alloc_rx_data(struct e1000g *Adapter)
15968850SMin.Xu@Sun.COM {
15978850SMin.Xu@Sun.COM e1000g_rx_ring_t *rx_ring;
15988850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data;
15998850SMin.Xu@Sun.COM
16008850SMin.Xu@Sun.COM rx_ring = Adapter->rx_ring;
16018850SMin.Xu@Sun.COM
16028850SMin.Xu@Sun.COM rx_data = kmem_zalloc(sizeof (e1000g_rx_data_t), KM_NOSLEEP);
16038850SMin.Xu@Sun.COM
16048850SMin.Xu@Sun.COM if (rx_data == NULL)
16058850SMin.Xu@Sun.COM return (DDI_FAILURE);
16068850SMin.Xu@Sun.COM
16078850SMin.Xu@Sun.COM rx_data->priv_devi_node = Adapter->priv_devi_node;
16088850SMin.Xu@Sun.COM rx_data->rx_ring = rx_ring;
16098850SMin.Xu@Sun.COM
16108850SMin.Xu@Sun.COM mutex_init(&rx_data->freelist_lock, NULL,
16118850SMin.Xu@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
16128850SMin.Xu@Sun.COM mutex_init(&rx_data->recycle_lock, NULL,
16138850SMin.Xu@Sun.COM MUTEX_DRIVER, DDI_INTR_PRI(Adapter->intr_pri));
16148850SMin.Xu@Sun.COM
16158850SMin.Xu@Sun.COM rx_ring->rx_data = rx_data;
16168850SMin.Xu@Sun.COM
16178850SMin.Xu@Sun.COM return (DDI_SUCCESS);
16188850SMin.Xu@Sun.COM }
16198850SMin.Xu@Sun.COM
16208850SMin.Xu@Sun.COM void
e1000g_free_rx_pending_buffers(e1000g_rx_data_t * rx_data)16218850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(e1000g_rx_data_t *rx_data)
16228850SMin.Xu@Sun.COM {
16238850SMin.Xu@Sun.COM rx_sw_packet_t *packet, *next_packet;
16248850SMin.Xu@Sun.COM
16258850SMin.Xu@Sun.COM if (rx_data == NULL)
16268850SMin.Xu@Sun.COM return;
16278850SMin.Xu@Sun.COM
16288850SMin.Xu@Sun.COM packet = rx_data->packet_area;
16298850SMin.Xu@Sun.COM while (packet != NULL) {
16308850SMin.Xu@Sun.COM next_packet = packet->next;
16318850SMin.Xu@Sun.COM e1000g_free_rx_sw_packet(packet, B_TRUE);
16328850SMin.Xu@Sun.COM packet = next_packet;
16338850SMin.Xu@Sun.COM }
16348850SMin.Xu@Sun.COM rx_data->packet_area = NULL;
16358850SMin.Xu@Sun.COM }
16368850SMin.Xu@Sun.COM
16378850SMin.Xu@Sun.COM void
e1000g_free_rx_data(e1000g_rx_data_t * rx_data)16388850SMin.Xu@Sun.COM e1000g_free_rx_data(e1000g_rx_data_t *rx_data)
16398850SMin.Xu@Sun.COM {
16408850SMin.Xu@Sun.COM if (rx_data == NULL)
16418850SMin.Xu@Sun.COM return;
16428850SMin.Xu@Sun.COM
16438850SMin.Xu@Sun.COM mutex_destroy(&rx_data->freelist_lock);
16448850SMin.Xu@Sun.COM mutex_destroy(&rx_data->recycle_lock);
16458850SMin.Xu@Sun.COM
16468850SMin.Xu@Sun.COM kmem_free(rx_data, sizeof (e1000g_rx_data_t));
16478850SMin.Xu@Sun.COM }
16488850SMin.Xu@Sun.COM
16493526Sxy150489 /*
16503526Sxy150489 * Check if the link is up
16513526Sxy150489 */
16523526Sxy150489 static boolean_t
e1000g_link_up(struct e1000g * Adapter)16533526Sxy150489 e1000g_link_up(struct e1000g *Adapter)
16543526Sxy150489 {
165510680SMin.Xu@Sun.COM struct e1000_hw *hw = &Adapter->shared;
165610680SMin.Xu@Sun.COM boolean_t link_up = B_FALSE;
165710680SMin.Xu@Sun.COM
165810680SMin.Xu@Sun.COM /*
165910680SMin.Xu@Sun.COM * get_link_status is set in the interrupt handler on link-status-change
166010680SMin.Xu@Sun.COM * or rx sequence error interrupt. get_link_status will stay
166110680SMin.Xu@Sun.COM * false until the e1000_check_for_link establishes link only
166210680SMin.Xu@Sun.COM * for copper adapters.
166310680SMin.Xu@Sun.COM */
166410680SMin.Xu@Sun.COM switch (hw->phy.media_type) {
166510680SMin.Xu@Sun.COM case e1000_media_type_copper:
166610680SMin.Xu@Sun.COM if (hw->mac.get_link_status) {
166710680SMin.Xu@Sun.COM (void) e1000_check_for_link(hw);
1668*12853SChangqing.Li@Sun.COM if ((E1000_READ_REG(hw, E1000_STATUS) &
1669*12853SChangqing.Li@Sun.COM E1000_STATUS_LU)) {
1670*12853SChangqing.Li@Sun.COM link_up = B_TRUE;
1671*12853SChangqing.Li@Sun.COM } else {
1672*12853SChangqing.Li@Sun.COM link_up = !hw->mac.get_link_status;
1673*12853SChangqing.Li@Sun.COM }
167410680SMin.Xu@Sun.COM } else {
167510680SMin.Xu@Sun.COM link_up = B_TRUE;
167610680SMin.Xu@Sun.COM }
167710680SMin.Xu@Sun.COM break;
167810680SMin.Xu@Sun.COM case e1000_media_type_fiber:
167910680SMin.Xu@Sun.COM (void) e1000_check_for_link(hw);
168010680SMin.Xu@Sun.COM link_up = (E1000_READ_REG(hw, E1000_STATUS) &
168110680SMin.Xu@Sun.COM E1000_STATUS_LU);
168210680SMin.Xu@Sun.COM break;
168310680SMin.Xu@Sun.COM case e1000_media_type_internal_serdes:
168410680SMin.Xu@Sun.COM (void) e1000_check_for_link(hw);
168510680SMin.Xu@Sun.COM link_up = hw->mac.serdes_has_link;
168610680SMin.Xu@Sun.COM break;
16873526Sxy150489 }
16883526Sxy150489
16893526Sxy150489 return (link_up);
16903526Sxy150489 }
16913526Sxy150489
16923526Sxy150489 static void
e1000g_m_ioctl(void * arg,queue_t * q,mblk_t * mp)16933526Sxy150489 e1000g_m_ioctl(void *arg, queue_t *q, mblk_t *mp)
16943526Sxy150489 {
16953526Sxy150489 struct iocblk *iocp;
16963526Sxy150489 struct e1000g *e1000gp;
16973526Sxy150489 enum ioc_reply status;
16987426SChenliang.Xu@Sun.COM
16997426SChenliang.Xu@Sun.COM iocp = (struct iocblk *)(uintptr_t)mp->b_rptr;
17003526Sxy150489 iocp->ioc_error = 0;
17013526Sxy150489 e1000gp = (struct e1000g *)arg;
17023526Sxy150489
17033526Sxy150489 ASSERT(e1000gp);
17043526Sxy150489 if (e1000gp == NULL) {
17053526Sxy150489 miocnak(q, mp, 0, EINVAL);
17063526Sxy150489 return;
17073526Sxy150489 }
17083526Sxy150489
17098479SChenlu.Chen@Sun.COM rw_enter(&e1000gp->chip_lock, RW_READER);
17108479SChenlu.Chen@Sun.COM if (e1000gp->e1000g_state & E1000G_SUSPENDED) {
17118479SChenlu.Chen@Sun.COM rw_exit(&e1000gp->chip_lock);
17128479SChenlu.Chen@Sun.COM miocnak(q, mp, 0, EINVAL);
17138479SChenlu.Chen@Sun.COM return;
17148479SChenlu.Chen@Sun.COM }
17158479SChenlu.Chen@Sun.COM rw_exit(&e1000gp->chip_lock);
17168479SChenlu.Chen@Sun.COM
17173526Sxy150489 switch (iocp->ioc_cmd) {
17183526Sxy150489
17193526Sxy150489 case LB_GET_INFO_SIZE:
17203526Sxy150489 case LB_GET_INFO:
17213526Sxy150489 case LB_GET_MODE:
17223526Sxy150489 case LB_SET_MODE:
17233526Sxy150489 status = e1000g_loopback_ioctl(e1000gp, iocp, mp);
17243526Sxy150489 break;
17253526Sxy150489
17263526Sxy150489
17274919Sxy150489 #ifdef E1000G_DEBUG
17283526Sxy150489 case E1000G_IOC_REG_PEEK:
17293526Sxy150489 case E1000G_IOC_REG_POKE:
17303526Sxy150489 status = e1000g_pp_ioctl(e1000gp, iocp, mp);
17313526Sxy150489 break;
17323526Sxy150489 case E1000G_IOC_CHIP_RESET:
17333526Sxy150489 e1000gp->reset_count++;
17347656SSherry.Moore@Sun.COM if (e1000g_reset_adapter(e1000gp))
17353526Sxy150489 status = IOC_ACK;
17363526Sxy150489 else
17373526Sxy150489 status = IOC_INVAL;
17383526Sxy150489 break;
17394919Sxy150489 #endif
17403526Sxy150489 default:
17413526Sxy150489 status = IOC_INVAL;
17423526Sxy150489 break;
17433526Sxy150489 }
17443526Sxy150489
17453526Sxy150489 /*
17463526Sxy150489 * Decide how to reply
17473526Sxy150489 */
17483526Sxy150489 switch (status) {
17493526Sxy150489 default:
17503526Sxy150489 case IOC_INVAL:
17513526Sxy150489 /*
17523526Sxy150489 * Error, reply with a NAK and EINVAL or the specified error
17533526Sxy150489 */
17543526Sxy150489 miocnak(q, mp, 0, iocp->ioc_error == 0 ?
17554349Sxy150489 EINVAL : iocp->ioc_error);
17563526Sxy150489 break;
17573526Sxy150489
17583526Sxy150489 case IOC_DONE:
17593526Sxy150489 /*
17603526Sxy150489 * OK, reply already sent
17613526Sxy150489 */
17623526Sxy150489 break;
17633526Sxy150489
17643526Sxy150489 case IOC_ACK:
17653526Sxy150489 /*
17663526Sxy150489 * OK, reply with an ACK
17673526Sxy150489 */
17683526Sxy150489 miocack(q, mp, 0, 0);
17693526Sxy150489 break;
17703526Sxy150489
17713526Sxy150489 case IOC_REPLY:
17723526Sxy150489 /*
17733526Sxy150489 * OK, send prepared reply as ACK or NAK
17743526Sxy150489 */
17753526Sxy150489 mp->b_datap->db_type = iocp->ioc_error == 0 ?
17764349Sxy150489 M_IOCACK : M_IOCNAK;
17773526Sxy150489 qreply(q, mp);
17783526Sxy150489 break;
17793526Sxy150489 }
17803526Sxy150489 }
17813526Sxy150489
17828275SEric Cheng /*
17838275SEric Cheng * The default value of e1000g_poll_mode == 0 assumes that the NIC is
17848275SEric Cheng * capable of supporting only one interrupt and we shouldn't disable
17858275SEric Cheng * the physical interrupt. In this case we let the interrupt come and
17868275SEric Cheng * we queue the packets in the rx ring itself in case we are in polling
17878275SEric Cheng * mode (better latency but slightly lower performance and a very
17888275SEric Cheng * high intrrupt count in mpstat which is harmless).
17898275SEric Cheng *
17908275SEric Cheng * e1000g_poll_mode == 1 assumes that we have per Rx ring interrupt
17918275SEric Cheng * which can be disabled in poll mode. This gives better overall
17928275SEric Cheng * throughput (compared to the mode above), shows very low interrupt
17938275SEric Cheng * count but has slightly higher latency since we pick the packets when
17948275SEric Cheng * the poll thread does polling.
17958275SEric Cheng *
17968275SEric Cheng * Currently, this flag should be enabled only while doing performance
17978275SEric Cheng * measurement or when it can be guaranteed that entire NIC going
17988275SEric Cheng * in poll mode will not harm any traffic like cluster heartbeat etc.
17998275SEric Cheng */
18008275SEric Cheng int e1000g_poll_mode = 0;
18018275SEric Cheng
18028275SEric Cheng /*
18038275SEric Cheng * Called from the upper layers when driver is in polling mode to
18048275SEric Cheng * pick up any queued packets. Care should be taken to not block
18058275SEric Cheng * this thread.
18068275SEric Cheng */
e1000g_poll_ring(void * arg,int bytes_to_pickup)18078275SEric Cheng static mblk_t *e1000g_poll_ring(void *arg, int bytes_to_pickup)
18088275SEric Cheng {
18098275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)arg;
18108275SEric Cheng mblk_t *mp = NULL;
18118275SEric Cheng mblk_t *tail;
18128275SEric Cheng struct e1000g *adapter;
18138275SEric Cheng
18148275SEric Cheng adapter = rx_ring->adapter;
18158275SEric Cheng
18168479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER);
18178479SChenlu.Chen@Sun.COM
18188479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) {
18198479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
18208479SChenlu.Chen@Sun.COM return (NULL);
18218479SChenlu.Chen@Sun.COM }
18228479SChenlu.Chen@Sun.COM
18238275SEric Cheng mutex_enter(&rx_ring->rx_lock);
18248833SVenu.Iyer@Sun.COM mp = e1000g_receive(rx_ring, &tail, bytes_to_pickup);
18258275SEric Cheng mutex_exit(&rx_ring->rx_lock);
18268479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
18278275SEric Cheng return (mp);
18288275SEric Cheng }
18298275SEric Cheng
18303526Sxy150489 static int
e1000g_m_start(void * arg)18313526Sxy150489 e1000g_m_start(void *arg)
18323526Sxy150489 {
18333526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
18343526Sxy150489
18358479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
18368479SChenlu.Chen@Sun.COM
18378479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
18388479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
18398479SChenlu.Chen@Sun.COM return (ECANCELED);
18408479SChenlu.Chen@Sun.COM }
18418479SChenlu.Chen@Sun.COM
18428479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_TRUE) != DDI_SUCCESS) {
18438479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
18448479SChenlu.Chen@Sun.COM return (ENOTACTIVE);
18458479SChenlu.Chen@Sun.COM }
18468479SChenlu.Chen@Sun.COM
18478479SChenlu.Chen@Sun.COM Adapter->e1000g_state |= E1000G_STARTED;
18488479SChenlu.Chen@Sun.COM
18498479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
18508479SChenlu.Chen@Sun.COM
18518479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */
18528479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter);
18538479SChenlu.Chen@Sun.COM
18548479SChenlu.Chen@Sun.COM return (0);
18553526Sxy150489 }
18563526Sxy150489
18573526Sxy150489 static int
e1000g_start(struct e1000g * Adapter,boolean_t global)18584919Sxy150489 e1000g_start(struct e1000g *Adapter, boolean_t global)
18593526Sxy150489 {
18608850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data;
18618850SMin.Xu@Sun.COM
18624919Sxy150489 if (global) {
18638850SMin.Xu@Sun.COM if (e1000g_alloc_rx_data(Adapter) != DDI_SUCCESS) {
18648850SMin.Xu@Sun.COM e1000g_log(Adapter, CE_WARN, "Allocate rx data failed");
18658850SMin.Xu@Sun.COM goto start_fail;
18668850SMin.Xu@Sun.COM }
18678850SMin.Xu@Sun.COM
18684919Sxy150489 /* Allocate dma resources for descriptors and buffers */
18694919Sxy150489 if (e1000g_alloc_dma_resources(Adapter) != DDI_SUCCESS) {
18704919Sxy150489 e1000g_log(Adapter, CE_WARN,
18714919Sxy150489 "Alloc DMA resources failed");
18728850SMin.Xu@Sun.COM goto start_fail;
18734919Sxy150489 }
18744919Sxy150489 Adapter->rx_buffer_setup = B_FALSE;
18754919Sxy150489 }
18764919Sxy150489
18773526Sxy150489 if (!(Adapter->attach_progress & ATTACH_PROGRESS_INIT)) {
18783526Sxy150489 if (e1000g_init(Adapter) != DDI_SUCCESS) {
18793526Sxy150489 e1000g_log(Adapter, CE_WARN,
18803526Sxy150489 "Adapter initialization failed");
18818850SMin.Xu@Sun.COM goto start_fail;
18823526Sxy150489 }
18833526Sxy150489 }
18843526Sxy150489
18854919Sxy150489 /* Setup and initialize the transmit structures */
18864919Sxy150489 e1000g_tx_setup(Adapter);
18874919Sxy150489 msec_delay(5);
18884919Sxy150489
18894919Sxy150489 /* Setup and initialize the receive structures */
18904919Sxy150489 e1000g_rx_setup(Adapter);
18914919Sxy150489 msec_delay(5);
18924919Sxy150489
18937722SShuguo.Yang@Sun.COM /* Restore the e1000g promiscuous mode */
18947722SShuguo.Yang@Sun.COM e1000g_restore_promisc(Adapter);
18957722SShuguo.Yang@Sun.COM
18964919Sxy150489 e1000g_mask_interrupt(Adapter);
18973526Sxy150489
18988479SChenlu.Chen@Sun.COM Adapter->attach_progress |= ATTACH_PROGRESS_INIT;
18998479SChenlu.Chen@Sun.COM
19005273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
19015273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
19028850SMin.Xu@Sun.COM goto start_fail;
19038479SChenlu.Chen@Sun.COM }
19048479SChenlu.Chen@Sun.COM
19058479SChenlu.Chen@Sun.COM return (DDI_SUCCESS);
19068850SMin.Xu@Sun.COM
19078850SMin.Xu@Sun.COM start_fail:
19088850SMin.Xu@Sun.COM rx_data = Adapter->rx_ring->rx_data;
19098850SMin.Xu@Sun.COM
19108850SMin.Xu@Sun.COM if (global) {
19118850SMin.Xu@Sun.COM e1000g_release_dma_resources(Adapter);
19128850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(rx_data);
19138850SMin.Xu@Sun.COM e1000g_free_rx_data(rx_data);
19148850SMin.Xu@Sun.COM }
19158850SMin.Xu@Sun.COM
19168850SMin.Xu@Sun.COM mutex_enter(&e1000g_nvm_lock);
19178850SMin.Xu@Sun.COM (void) e1000_reset_hw(&Adapter->shared);
19188850SMin.Xu@Sun.COM mutex_exit(&e1000g_nvm_lock);
19198850SMin.Xu@Sun.COM
19208850SMin.Xu@Sun.COM return (DDI_FAILURE);
19213526Sxy150489 }
19223526Sxy150489
19233526Sxy150489 static void
e1000g_m_stop(void * arg)19243526Sxy150489 e1000g_m_stop(void *arg)
19253526Sxy150489 {
19263526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
19273526Sxy150489
19288479SChenlu.Chen@Sun.COM /* Drain tx sessions */
19298479SChenlu.Chen@Sun.COM (void) e1000g_tx_drain(Adapter);
19308479SChenlu.Chen@Sun.COM
19318479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
19328479SChenlu.Chen@Sun.COM
19338479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
19348479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
19358479SChenlu.Chen@Sun.COM return;
19368479SChenlu.Chen@Sun.COM }
19378479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_STARTED;
19384919Sxy150489 e1000g_stop(Adapter, B_TRUE);
19398479SChenlu.Chen@Sun.COM
19408479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
19418479SChenlu.Chen@Sun.COM
19428479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */
19438479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter);
19448479SChenlu.Chen@Sun.COM stop_link_timer(Adapter);
19458479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring);
19463526Sxy150489 }
19473526Sxy150489
19483526Sxy150489 static void
e1000g_stop(struct e1000g * Adapter,boolean_t global)19494919Sxy150489 e1000g_stop(struct e1000g *Adapter, boolean_t global)
19503526Sxy150489 {
19518850SMin.Xu@Sun.COM private_devi_list_t *devi_node;
19528850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data;
19537133Scc210113 int result;
19547133Scc210113
19553526Sxy150489 Adapter->attach_progress &= ~ATTACH_PROGRESS_INIT;
19563526Sxy150489
19573526Sxy150489 /* Stop the chip and release pending resources */
19583526Sxy150489
19597607STed.You@Sun.COM /* Tell firmware driver is no longer in control */
19607607STed.You@Sun.COM e1000g_release_driver_control(&Adapter->shared);
19617607STed.You@Sun.COM
19624919Sxy150489 e1000g_clear_all_interrupts(Adapter);
19637133Scc210113
19647133Scc210113 mutex_enter(&e1000g_nvm_lock);
19657133Scc210113 result = e1000_reset_hw(&Adapter->shared);
19667133Scc210113 mutex_exit(&e1000g_nvm_lock);
19677133Scc210113
19687133Scc210113 if (result != E1000_SUCCESS) {
19695273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_INVAL_STATE);
19705273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
19715273Sgl147354 }
19723526Sxy150489
197311878SVenu.Iyer@Sun.COM mutex_enter(&Adapter->link_lock);
197411878SVenu.Iyer@Sun.COM Adapter->link_complete = B_FALSE;
197511878SVenu.Iyer@Sun.COM mutex_exit(&Adapter->link_lock);
197611878SVenu.Iyer@Sun.COM
19773526Sxy150489 /* Release resources still held by the TX descriptors */
19784919Sxy150489 e1000g_tx_clean(Adapter);
19794061Sxy150489
19805273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
19815273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
19825273Sgl147354
19834061Sxy150489 /* Clean the pending rx jumbo packet fragment */
19844919Sxy150489 e1000g_rx_clean(Adapter);
19854061Sxy150489
19868850SMin.Xu@Sun.COM if (global) {
19874919Sxy150489 e1000g_release_dma_resources(Adapter);
19888850SMin.Xu@Sun.COM
19898850SMin.Xu@Sun.COM mutex_enter(&e1000g_rx_detach_lock);
19908850SMin.Xu@Sun.COM rx_data = Adapter->rx_ring->rx_data;
19918850SMin.Xu@Sun.COM rx_data->flag |= E1000G_RX_STOPPED;
19928850SMin.Xu@Sun.COM
19938850SMin.Xu@Sun.COM if (rx_data->pending_count == 0) {
19948850SMin.Xu@Sun.COM e1000g_free_rx_pending_buffers(rx_data);
19958850SMin.Xu@Sun.COM e1000g_free_rx_data(rx_data);
19968850SMin.Xu@Sun.COM } else {
19978850SMin.Xu@Sun.COM devi_node = rx_data->priv_devi_node;
19988850SMin.Xu@Sun.COM if (devi_node != NULL)
19998850SMin.Xu@Sun.COM atomic_inc_32(&devi_node->pending_rx_count);
20008850SMin.Xu@Sun.COM else
20018850SMin.Xu@Sun.COM atomic_inc_32(&Adapter->pending_rx_count);
20028850SMin.Xu@Sun.COM }
20038850SMin.Xu@Sun.COM mutex_exit(&e1000g_rx_detach_lock);
20048850SMin.Xu@Sun.COM }
20059190SMin.Xu@Sun.COM
2006*12853SChangqing.Li@Sun.COM if (Adapter->link_state != LINK_STATE_UNKNOWN) {
20079190SMin.Xu@Sun.COM Adapter->link_state = LINK_STATE_UNKNOWN;
200811402SChangqing.Li@Sun.COM if (!Adapter->reset_flag)
200911402SChangqing.Li@Sun.COM mac_link_update(Adapter->mh, Adapter->link_state);
20109190SMin.Xu@Sun.COM }
20114061Sxy150489 }
20124061Sxy150489
20134061Sxy150489 static void
e1000g_rx_clean(struct e1000g * Adapter)20144919Sxy150489 e1000g_rx_clean(struct e1000g *Adapter)
20154919Sxy150489 {
20168850SMin.Xu@Sun.COM e1000g_rx_data_t *rx_data = Adapter->rx_ring->rx_data;
20178850SMin.Xu@Sun.COM
20188850SMin.Xu@Sun.COM if (rx_data == NULL)
20198850SMin.Xu@Sun.COM return;
20208850SMin.Xu@Sun.COM
20218850SMin.Xu@Sun.COM if (rx_data->rx_mblk != NULL) {
20228850SMin.Xu@Sun.COM freemsg(rx_data->rx_mblk);
20238850SMin.Xu@Sun.COM rx_data->rx_mblk = NULL;
20248850SMin.Xu@Sun.COM rx_data->rx_mblk_tail = NULL;
20258850SMin.Xu@Sun.COM rx_data->rx_mblk_len = 0;
20264919Sxy150489 }
20274919Sxy150489 }
20284919Sxy150489
20294919Sxy150489 static void
e1000g_tx_clean(struct e1000g * Adapter)20304919Sxy150489 e1000g_tx_clean(struct e1000g *Adapter)
20314061Sxy150489 {
20324061Sxy150489 e1000g_tx_ring_t *tx_ring;
20334919Sxy150489 p_tx_sw_packet_t packet;
20344061Sxy150489 mblk_t *mp;
20354061Sxy150489 mblk_t *nmp;
20364061Sxy150489 uint32_t packet_count;
20374061Sxy150489
20384061Sxy150489 tx_ring = Adapter->tx_ring;
20394061Sxy150489
20403526Sxy150489 /*
20413526Sxy150489 * Here we don't need to protect the lists using
20423526Sxy150489 * the usedlist_lock and freelist_lock, for they
20433526Sxy150489 * have been protected by the chip_lock.
20443526Sxy150489 */
20453526Sxy150489 mp = NULL;
20463526Sxy150489 nmp = NULL;
20474061Sxy150489 packet_count = 0;
20484919Sxy150489 packet = (p_tx_sw_packet_t)QUEUE_GET_HEAD(&tx_ring->used_list);
20493526Sxy150489 while (packet != NULL) {
20503526Sxy150489 if (packet->mp != NULL) {
20513526Sxy150489 /* Assemble the message chain */
20523526Sxy150489 if (mp == NULL) {
20533526Sxy150489 mp = packet->mp;
20543526Sxy150489 nmp = packet->mp;
20553526Sxy150489 } else {
20563526Sxy150489 nmp->b_next = packet->mp;
20573526Sxy150489 nmp = packet->mp;
20583526Sxy150489 }
20593526Sxy150489 /* Disconnect the message from the sw packet */
20603526Sxy150489 packet->mp = NULL;
20613526Sxy150489 }
20623526Sxy150489
20634919Sxy150489 e1000g_free_tx_swpkt(packet);
20644061Sxy150489 packet_count++;
20653526Sxy150489
20664919Sxy150489 packet = (p_tx_sw_packet_t)
20673526Sxy150489 QUEUE_GET_NEXT(&tx_ring->used_list, &packet->Link);
20683526Sxy150489 }
20693526Sxy150489
20705882Syy150190 if (mp != NULL)
20715882Syy150190 freemsgchain(mp);
20724061Sxy150489
20734061Sxy150489 if (packet_count > 0) {
20744061Sxy150489 QUEUE_APPEND(&tx_ring->free_list, &tx_ring->used_list);
20754061Sxy150489 QUEUE_INIT_LIST(&tx_ring->used_list);
20764061Sxy150489
20774061Sxy150489 /* Setup TX descriptor pointers */
20784061Sxy150489 tx_ring->tbd_next = tx_ring->tbd_first;
20794061Sxy150489 tx_ring->tbd_oldest = tx_ring->tbd_first;
20804061Sxy150489
20814061Sxy150489 /* Setup our HW Tx Head & Tail descriptor pointers */
20826735Scc210113 E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0);
20836735Scc210113 E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0);
20843526Sxy150489 }
20853526Sxy150489 }
20863526Sxy150489
20873526Sxy150489 static boolean_t
e1000g_tx_drain(struct e1000g * Adapter)20883526Sxy150489 e1000g_tx_drain(struct e1000g *Adapter)
20893526Sxy150489 {
20903526Sxy150489 int i;
20913526Sxy150489 boolean_t done;
20923526Sxy150489 e1000g_tx_ring_t *tx_ring;
20933526Sxy150489
20943526Sxy150489 tx_ring = Adapter->tx_ring;
20953526Sxy150489
20963526Sxy150489 /* Allow up to 'wsdraintime' for pending xmit's to complete. */
20974919Sxy150489 for (i = 0; i < TX_DRAIN_TIME; i++) {
20983526Sxy150489 mutex_enter(&tx_ring->usedlist_lock);
20993526Sxy150489 done = IS_QUEUE_EMPTY(&tx_ring->used_list);
21003526Sxy150489 mutex_exit(&tx_ring->usedlist_lock);
21013526Sxy150489
21023526Sxy150489 if (done)
21033526Sxy150489 break;
21043526Sxy150489
21053526Sxy150489 msec_delay(1);
21063526Sxy150489 }
21073526Sxy150489
21083526Sxy150489 return (done);
21093526Sxy150489 }
21103526Sxy150489
21113526Sxy150489 static boolean_t
e1000g_rx_drain(struct e1000g * Adapter)21123526Sxy150489 e1000g_rx_drain(struct e1000g *Adapter)
21133526Sxy150489 {
21148850SMin.Xu@Sun.COM int i;
21153526Sxy150489 boolean_t done;
21163526Sxy150489
21178850SMin.Xu@Sun.COM /*
21188850SMin.Xu@Sun.COM * Allow up to RX_DRAIN_TIME for pending received packets to complete.
21198850SMin.Xu@Sun.COM */
21208850SMin.Xu@Sun.COM for (i = 0; i < RX_DRAIN_TIME; i++) {
21218850SMin.Xu@Sun.COM done = (Adapter->pending_rx_count == 0);
21228850SMin.Xu@Sun.COM
21238850SMin.Xu@Sun.COM if (done)
21248850SMin.Xu@Sun.COM break;
21258850SMin.Xu@Sun.COM
21268850SMin.Xu@Sun.COM msec_delay(1);
21278850SMin.Xu@Sun.COM }
21283526Sxy150489
21293526Sxy150489 return (done);
21303526Sxy150489 }
21313526Sxy150489
21327656SSherry.Moore@Sun.COM static boolean_t
e1000g_reset_adapter(struct e1000g * Adapter)21337656SSherry.Moore@Sun.COM e1000g_reset_adapter(struct e1000g *Adapter)
21343526Sxy150489 {
21358479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */
21368479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter);
21378479SChenlu.Chen@Sun.COM stop_link_timer(Adapter);
21388479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring);
21398479SChenlu.Chen@Sun.COM
21408479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
21418479SChenlu.Chen@Sun.COM
214211402SChangqing.Li@Sun.COM if (Adapter->stall_flag) {
214311402SChangqing.Li@Sun.COM Adapter->stall_flag = B_FALSE;
214411402SChangqing.Li@Sun.COM Adapter->reset_flag = B_TRUE;
214511402SChangqing.Li@Sun.COM }
214611402SChangqing.Li@Sun.COM
214710434SGuoqing.Zhu@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) {
214810434SGuoqing.Zhu@Sun.COM rw_exit(&Adapter->chip_lock);
214910434SGuoqing.Zhu@Sun.COM return (B_TRUE);
215010434SGuoqing.Zhu@Sun.COM }
215110434SGuoqing.Zhu@Sun.COM
21524919Sxy150489 e1000g_stop(Adapter, B_FALSE);
21534919Sxy150489
21548479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_FALSE) != DDI_SUCCESS) {
21558479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
21563526Sxy150489 e1000g_log(Adapter, CE_WARN, "Reset failed");
21578479SChenlu.Chen@Sun.COM return (B_FALSE);
21588479SChenlu.Chen@Sun.COM }
21598479SChenlu.Chen@Sun.COM
21608479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
21618479SChenlu.Chen@Sun.COM
21628479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */
21638479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter);
21643526Sxy150489
21653526Sxy150489 return (B_TRUE);
21663526Sxy150489 }
21673526Sxy150489
21685273Sgl147354 boolean_t
e1000g_global_reset(struct e1000g * Adapter)21695273Sgl147354 e1000g_global_reset(struct e1000g *Adapter)
21705273Sgl147354 {
21718479SChenlu.Chen@Sun.COM /* Disable and stop all the timers */
21728479SChenlu.Chen@Sun.COM disable_watchdog_timer(Adapter);
21738479SChenlu.Chen@Sun.COM stop_link_timer(Adapter);
21748479SChenlu.Chen@Sun.COM stop_82547_timer(Adapter->tx_ring);
21758479SChenlu.Chen@Sun.COM
21768479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
21778479SChenlu.Chen@Sun.COM
21785273Sgl147354 e1000g_stop(Adapter, B_TRUE);
21795273Sgl147354
21805273Sgl147354 Adapter->init_count = 0;
21815273Sgl147354
21828479SChenlu.Chen@Sun.COM if (e1000g_start(Adapter, B_TRUE) != DDI_SUCCESS) {
21838479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
21845273Sgl147354 e1000g_log(Adapter, CE_WARN, "Reset failed");
21855273Sgl147354 return (B_FALSE);
21865273Sgl147354 }
21875273Sgl147354
21888479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
21898479SChenlu.Chen@Sun.COM
21908479SChenlu.Chen@Sun.COM /* Enable and start the watchdog timer */
21918479SChenlu.Chen@Sun.COM enable_watchdog_timer(Adapter);
21928479SChenlu.Chen@Sun.COM
21935273Sgl147354 return (B_TRUE);
21945273Sgl147354 }
21955273Sgl147354
21963526Sxy150489 /*
21974919Sxy150489 * e1000g_intr_pciexpress - ISR for PCI Express chipsets
21984919Sxy150489 *
21994919Sxy150489 * This interrupt service routine is for PCI-Express adapters.
22004919Sxy150489 * The ICR contents is valid only when the E1000_ICR_INT_ASSERTED
22014919Sxy150489 * bit is set.
22023526Sxy150489 */
22033526Sxy150489 static uint_t
e1000g_intr_pciexpress(caddr_t arg)22043526Sxy150489 e1000g_intr_pciexpress(caddr_t arg)
22053526Sxy150489 {
22063526Sxy150489 struct e1000g *Adapter;
22074919Sxy150489 uint32_t icr;
22083526Sxy150489
22097426SChenliang.Xu@Sun.COM Adapter = (struct e1000g *)(uintptr_t)arg;
22104919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR);
22114919Sxy150489
221210805SChangqing.Li@Sun.COM if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
22135273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
221410805SChangqing.Li@Sun.COM return (DDI_INTR_CLAIMED);
221510805SChangqing.Li@Sun.COM }
22165273Sgl147354
22174919Sxy150489 if (icr & E1000_ICR_INT_ASSERTED) {
22183526Sxy150489 /*
22193526Sxy150489 * E1000_ICR_INT_ASSERTED bit was set:
22203526Sxy150489 * Read(Clear) the ICR, claim this interrupt,
22213526Sxy150489 * look for work to do.
22223526Sxy150489 */
22234919Sxy150489 e1000g_intr_work(Adapter, icr);
22243526Sxy150489 return (DDI_INTR_CLAIMED);
22253526Sxy150489 } else {
22263526Sxy150489 /*
22273526Sxy150489 * E1000_ICR_INT_ASSERTED bit was not set:
22283526Sxy150489 * Don't claim this interrupt, return immediately.
22293526Sxy150489 */
22303526Sxy150489 return (DDI_INTR_UNCLAIMED);
22313526Sxy150489 }
22323526Sxy150489 }
22333526Sxy150489
22343526Sxy150489 /*
22354919Sxy150489 * e1000g_intr - ISR for PCI/PCI-X chipsets
22364919Sxy150489 *
22374919Sxy150489 * This interrupt service routine is for PCI/PCI-X adapters.
22384919Sxy150489 * We check the ICR contents no matter the E1000_ICR_INT_ASSERTED
22394919Sxy150489 * bit is set or not.
22403526Sxy150489 */
22413526Sxy150489 static uint_t
e1000g_intr(caddr_t arg)22423526Sxy150489 e1000g_intr(caddr_t arg)
22433526Sxy150489 {
22443526Sxy150489 struct e1000g *Adapter;
22454919Sxy150489 uint32_t icr;
22463526Sxy150489
22477426SChenliang.Xu@Sun.COM Adapter = (struct e1000g *)(uintptr_t)arg;
22484919Sxy150489 icr = E1000_READ_REG(&Adapter->shared, E1000_ICR);
22494919Sxy150489
225010805SChangqing.Li@Sun.COM if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
22515273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
225210805SChangqing.Li@Sun.COM return (DDI_INTR_CLAIMED);
225310805SChangqing.Li@Sun.COM }
22545273Sgl147354
22554919Sxy150489 if (icr) {
22563526Sxy150489 /*
22573526Sxy150489 * Any bit was set in ICR:
22583526Sxy150489 * Read(Clear) the ICR, claim this interrupt,
22593526Sxy150489 * look for work to do.
22603526Sxy150489 */
22614919Sxy150489 e1000g_intr_work(Adapter, icr);
22623526Sxy150489 return (DDI_INTR_CLAIMED);
22633526Sxy150489 } else {
22643526Sxy150489 /*
22653526Sxy150489 * No bit was set in ICR:
22663526Sxy150489 * Don't claim this interrupt, return immediately.
22673526Sxy150489 */
22683526Sxy150489 return (DDI_INTR_UNCLAIMED);
22693526Sxy150489 }
22703526Sxy150489 }
22713526Sxy150489
22723526Sxy150489 /*
22734919Sxy150489 * e1000g_intr_work - actual processing of ISR
22744919Sxy150489 *
22754919Sxy150489 * Read(clear) the ICR contents and call appropriate interrupt
22764919Sxy150489 * processing routines.
22773526Sxy150489 */
22783526Sxy150489 static void
e1000g_intr_work(struct e1000g * Adapter,uint32_t icr)22794919Sxy150489 e1000g_intr_work(struct e1000g *Adapter, uint32_t icr)
22803526Sxy150489 {
22815882Syy150190 struct e1000_hw *hw;
22825882Syy150190 hw = &Adapter->shared;
22835882Syy150190 e1000g_tx_ring_t *tx_ring = Adapter->tx_ring;
22845882Syy150190
22855882Syy150190 Adapter->rx_pkt_cnt = 0;
22865882Syy150190 Adapter->tx_pkt_cnt = 0;
22875882Syy150190
22884919Sxy150489 rw_enter(&Adapter->chip_lock, RW_READER);
22898479SChenlu.Chen@Sun.COM
22908479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
22918479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
22928479SChenlu.Chen@Sun.COM return;
22938479SChenlu.Chen@Sun.COM }
22944919Sxy150489 /*
22958479SChenlu.Chen@Sun.COM * Here we need to check the "e1000g_state" flag within the chip_lock to
22964919Sxy150489 * ensure the receive routine will not execute when the adapter is
22974919Sxy150489 * being reset.
22984919Sxy150489 */
22998479SChenlu.Chen@Sun.COM if (!(Adapter->e1000g_state & E1000G_STARTED)) {
23004919Sxy150489 rw_exit(&Adapter->chip_lock);
23014919Sxy150489 return;
23024919Sxy150489 }
23034919Sxy150489
23044919Sxy150489 if (icr & E1000_ICR_RXT0) {
23058833SVenu.Iyer@Sun.COM mblk_t *mp = NULL;
23068833SVenu.Iyer@Sun.COM mblk_t *tail = NULL;
23078275SEric Cheng e1000g_rx_ring_t *rx_ring;
23088275SEric Cheng
23098275SEric Cheng rx_ring = Adapter->rx_ring;
23108275SEric Cheng mutex_enter(&rx_ring->rx_lock);
23118275SEric Cheng /*
23128833SVenu.Iyer@Sun.COM * Sometimes with legacy interrupts, it possible that
23138833SVenu.Iyer@Sun.COM * there is a single interrupt for Rx/Tx. In which
23148833SVenu.Iyer@Sun.COM * case, if poll flag is set, we shouldn't really
23158833SVenu.Iyer@Sun.COM * be doing Rx processing.
23168275SEric Cheng */
23178833SVenu.Iyer@Sun.COM if (!rx_ring->poll_flag)
23188833SVenu.Iyer@Sun.COM mp = e1000g_receive(rx_ring, &tail,
23198833SVenu.Iyer@Sun.COM E1000G_CHAIN_NO_LIMIT);
23208833SVenu.Iyer@Sun.COM mutex_exit(&rx_ring->rx_lock);
23214919Sxy150489 rw_exit(&Adapter->chip_lock);
23228833SVenu.Iyer@Sun.COM if (mp != NULL)
23238275SEric Cheng mac_rx_ring(Adapter->mh, rx_ring->mrh,
23248833SVenu.Iyer@Sun.COM mp, rx_ring->ring_gen_num);
23254919Sxy150489 } else
23264919Sxy150489 rw_exit(&Adapter->chip_lock);
23273526Sxy150489
23285882Syy150190 if (icr & E1000_ICR_TXDW) {
23295882Syy150190 if (!Adapter->tx_intr_enable)
23305882Syy150190 e1000g_clear_tx_interrupt(Adapter);
23315882Syy150190
23325882Syy150190 /* Recycle the tx descriptors */
23335882Syy150190 rw_enter(&Adapter->chip_lock, RW_READER);
23347426SChenliang.Xu@Sun.COM (void) e1000g_recycle(tx_ring);
23355882Syy150190 E1000G_DEBUG_STAT(tx_ring->stat_recycle_intr);
23365882Syy150190 rw_exit(&Adapter->chip_lock);
23375882Syy150190
23385882Syy150190 if (tx_ring->resched_needed &&
23395882Syy150190 (tx_ring->tbd_avail > DEFAULT_TX_UPDATE_THRESHOLD)) {
23405882Syy150190 tx_ring->resched_needed = B_FALSE;
23415882Syy150190 mac_tx_update(Adapter->mh);
23425882Syy150190 E1000G_STAT(tx_ring->stat_reschedule);
23435882Syy150190 }
23445882Syy150190 }
23455882Syy150190
23463526Sxy150489 /*
23473526Sxy150489 * The Receive Sequence errors RXSEQ and the link status change LSC
23483526Sxy150489 * are checked to detect that the cable has been pulled out. For
23493526Sxy150489 * the Wiseman 2.0 silicon, the receive sequence errors interrupt
23503526Sxy150489 * are an indication that cable is not connected.
23513526Sxy150489 */
23524919Sxy150489 if ((icr & E1000_ICR_RXSEQ) ||
23534919Sxy150489 (icr & E1000_ICR_LSC) ||
23544919Sxy150489 (icr & E1000_ICR_GPI_EN1)) {
23554061Sxy150489 boolean_t link_changed;
23564061Sxy150489 timeout_id_t tid = 0;
23573526Sxy150489
23584919Sxy150489 stop_watchdog_timer(Adapter);
23594919Sxy150489
23605082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER);
23615082Syy150190
23625082Syy150190 /*
23635082Syy150190 * Because we got a link-status-change interrupt, force
23645082Syy150190 * e1000_check_for_link() to look at phy
23655082Syy150190 */
23665082Syy150190 Adapter->shared.mac.get_link_status = B_TRUE;
23675082Syy150190
23684061Sxy150489 /* e1000g_link_check takes care of link status change */
23694061Sxy150489 link_changed = e1000g_link_check(Adapter);
23705082Syy150190
23715082Syy150190 /* Get new phy state */
23725082Syy150190 e1000g_get_phy_state(Adapter);
23735082Syy150190
23744061Sxy150489 /*
23754061Sxy150489 * If the link timer has not timed out, we'll not notify
23764919Sxy150489 * the upper layer with any link state until the link is up.
23774061Sxy150489 */
23784061Sxy150489 if (link_changed && !Adapter->link_complete) {
23794061Sxy150489 if (Adapter->link_state == LINK_STATE_UP) {
23805082Syy150190 mutex_enter(&Adapter->link_lock);
23814061Sxy150489 Adapter->link_complete = B_TRUE;
23824061Sxy150489 tid = Adapter->link_tid;
23834061Sxy150489 Adapter->link_tid = 0;
23845082Syy150190 mutex_exit(&Adapter->link_lock);
23854061Sxy150489 } else {
23864061Sxy150489 link_changed = B_FALSE;
23874061Sxy150489 }
23884061Sxy150489 }
23895082Syy150190 rw_exit(&Adapter->chip_lock);
23903526Sxy150489
23914061Sxy150489 if (link_changed) {
23924061Sxy150489 if (tid != 0)
23934061Sxy150489 (void) untimeout(tid);
23944061Sxy150489
23954139Sxy150489 /*
23964139Sxy150489 * Workaround for esb2. Data stuck in fifo on a link
23977133Scc210113 * down event. Stop receiver here and reset in watchdog.
23984139Sxy150489 */
23994139Sxy150489 if ((Adapter->link_state == LINK_STATE_DOWN) &&
24007133Scc210113 (Adapter->shared.mac.type == e1000_80003es2lan)) {
24017133Scc210113 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
24027133Scc210113 E1000_WRITE_REG(hw, E1000_RCTL,
24037133Scc210113 rctl & ~E1000_RCTL_EN);
24047133Scc210113 e1000g_log(Adapter, CE_WARN,
24057133Scc210113 "ESB2 receiver disabled");
24067133Scc210113 Adapter->esb2_workaround = B_TRUE;
24077133Scc210113 }
24088850SMin.Xu@Sun.COM if (!Adapter->reset_flag)
24098850SMin.Xu@Sun.COM mac_link_update(Adapter->mh,
24108850SMin.Xu@Sun.COM Adapter->link_state);
24118850SMin.Xu@Sun.COM if (Adapter->link_state == LINK_STATE_UP)
24128850SMin.Xu@Sun.COM Adapter->reset_flag = B_FALSE;
24133526Sxy150489 }
24143526Sxy150489
24154919Sxy150489 start_watchdog_timer(Adapter);
24163526Sxy150489 }
24175882Syy150190 }
24185882Syy150190
24193526Sxy150489 static void
e1000g_init_unicst(struct e1000g * Adapter)24203526Sxy150489 e1000g_init_unicst(struct e1000g *Adapter)
24213526Sxy150489 {
24223526Sxy150489 struct e1000_hw *hw;
24233526Sxy150489 int slot;
24243526Sxy150489
24254919Sxy150489 hw = &Adapter->shared;
24263526Sxy150489
24278275SEric Cheng if (Adapter->init_count == 0) {
24283526Sxy150489 /* Initialize the multiple unicast addresses */
24293526Sxy150489 Adapter->unicst_total = MAX_NUM_UNICAST_ADDRESSES;
24303526Sxy150489
24318275SEric Cheng /* Workaround for an erratum of 82571 chipst */
24324919Sxy150489 if ((hw->mac.type == e1000_82571) &&
24334919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE))
24343526Sxy150489 Adapter->unicst_total--;
24353526Sxy150489
24368275SEric Cheng Adapter->unicst_avail = Adapter->unicst_total;
24378275SEric Cheng
24388275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) {
24398275SEric Cheng /* Clear both the flag and MAC address */
24408275SEric Cheng Adapter->unicst_addr[slot].reg.high = 0;
24418275SEric Cheng Adapter->unicst_addr[slot].reg.low = 0;
24428275SEric Cheng }
24433526Sxy150489 } else {
24448275SEric Cheng /* Workaround for an erratum of 82571 chipst */
24454919Sxy150489 if ((hw->mac.type == e1000_82571) &&
24464919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE))
24474919Sxy150489 e1000_rar_set(hw, hw->mac.addr, LAST_RAR_ENTRY);
24483526Sxy150489
24493526Sxy150489 /* Re-configure the RAR registers */
24508275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++)
24518275SEric Cheng if (Adapter->unicst_addr[slot].mac.set == 1)
24528275SEric Cheng e1000_rar_set(hw,
24538275SEric Cheng Adapter->unicst_addr[slot].mac.addr, slot);
24543526Sxy150489 }
24555273Sgl147354
24565273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
24575273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
24583526Sxy150489 }
24593526Sxy150489
24603526Sxy150489 static int
e1000g_unicst_set(struct e1000g * Adapter,const uint8_t * mac_addr,int slot)24613526Sxy150489 e1000g_unicst_set(struct e1000g *Adapter, const uint8_t *mac_addr,
24628275SEric Cheng int slot)
24633526Sxy150489 {
24643526Sxy150489 struct e1000_hw *hw;
24653526Sxy150489
24664919Sxy150489 hw = &Adapter->shared;
24673526Sxy150489
24683526Sxy150489 /*
24693526Sxy150489 * The first revision of Wiseman silicon (rev 2.0) has an errata
24703526Sxy150489 * that requires the receiver to be in reset when any of the
24713526Sxy150489 * receive address registers (RAR regs) are accessed. The first
24723526Sxy150489 * rev of Wiseman silicon also requires MWI to be disabled when
24733526Sxy150489 * a global reset or a receive reset is issued. So before we
24743526Sxy150489 * initialize the RARs, we check the rev of the Wiseman controller
24753526Sxy150489 * and work around any necessary HW errata.
24763526Sxy150489 */
24774919Sxy150489 if ((hw->mac.type == e1000_82542) &&
24784919Sxy150489 (hw->revision_id == E1000_REVISION_2)) {
24793526Sxy150489 e1000_pci_clear_mwi(hw);
24804919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST);
24814919Sxy150489 msec_delay(5);
24823526Sxy150489 }
24838275SEric Cheng if (mac_addr == NULL) {
24848275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, slot << 1, 0);
24858275SEric Cheng E1000_WRITE_FLUSH(hw);
24868275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA, (slot << 1) + 1, 0);
24878275SEric Cheng E1000_WRITE_FLUSH(hw);
24888275SEric Cheng /* Clear both the flag and MAC address */
24898275SEric Cheng Adapter->unicst_addr[slot].reg.high = 0;
24908275SEric Cheng Adapter->unicst_addr[slot].reg.low = 0;
24918275SEric Cheng } else {
24928275SEric Cheng bcopy(mac_addr, Adapter->unicst_addr[slot].mac.addr,
24938275SEric Cheng ETHERADDRL);
24948275SEric Cheng e1000_rar_set(hw, (uint8_t *)mac_addr, slot);
24958275SEric Cheng Adapter->unicst_addr[slot].mac.set = 1;
24968275SEric Cheng }
24978275SEric Cheng
24988275SEric Cheng /* Workaround for an erratum of 82571 chipst */
24993526Sxy150489 if (slot == 0) {
25004919Sxy150489 if ((hw->mac.type == e1000_82571) &&
25014919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE))
25028275SEric Cheng if (mac_addr == NULL) {
25038275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA,
25048275SEric Cheng slot << 1, 0);
25058275SEric Cheng E1000_WRITE_FLUSH(hw);
25068275SEric Cheng E1000_WRITE_REG_ARRAY(hw, E1000_RA,
25078275SEric Cheng (slot << 1) + 1, 0);
25088275SEric Cheng E1000_WRITE_FLUSH(hw);
25098275SEric Cheng } else {
25108275SEric Cheng e1000_rar_set(hw, (uint8_t *)mac_addr,
25118275SEric Cheng LAST_RAR_ENTRY);
25128275SEric Cheng }
25133526Sxy150489 }
25143526Sxy150489
25153526Sxy150489 /*
25163526Sxy150489 * If we are using Wiseman rev 2.0 silicon, we will have previously
25173526Sxy150489 * put the receive in reset, and disabled MWI, to work around some
25183526Sxy150489 * HW errata. Now we should take the receiver out of reset, and
25193526Sxy150489 * re-enabled if MWI if it was previously enabled by the PCI BIOS.
25203526Sxy150489 */
25214919Sxy150489 if ((hw->mac.type == e1000_82542) &&
25224919Sxy150489 (hw->revision_id == E1000_REVISION_2)) {
25234919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0);
25244919Sxy150489 msec_delay(1);
25254919Sxy150489 if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
25263526Sxy150489 e1000_pci_set_mwi(hw);
25274919Sxy150489 e1000g_rx_setup(Adapter);
25283526Sxy150489 }
25293526Sxy150489
25305273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
25315273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
25325273Sgl147354 return (EIO);
25335273Sgl147354 }
25345273Sgl147354
25353526Sxy150489 return (0);
25363526Sxy150489 }
25373526Sxy150489
25383526Sxy150489 static int
multicst_add(struct e1000g * Adapter,const uint8_t * multiaddr)25393526Sxy150489 multicst_add(struct e1000g *Adapter, const uint8_t *multiaddr)
25403526Sxy150489 {
25414919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
25429770SChangqing.Li@Sun.COM struct ether_addr *newtable;
25439770SChangqing.Li@Sun.COM size_t new_len;
25449770SChangqing.Li@Sun.COM size_t old_len;
25453526Sxy150489 int res = 0;
25463526Sxy150489
25473526Sxy150489 if ((multiaddr[0] & 01) == 0) {
25483526Sxy150489 res = EINVAL;
25499770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN, "Illegal multicast address");
25503526Sxy150489 goto done;
25513526Sxy150489 }
25523526Sxy150489
25539770SChangqing.Li@Sun.COM if (Adapter->mcast_count >= Adapter->mcast_max_num) {
25543526Sxy150489 res = ENOENT;
25559770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN,
25569770SChangqing.Li@Sun.COM "Adapter requested more than %d mcast addresses",
25579770SChangqing.Li@Sun.COM Adapter->mcast_max_num);
25583526Sxy150489 goto done;
25593526Sxy150489 }
25603526Sxy150489
25619770SChangqing.Li@Sun.COM
25629770SChangqing.Li@Sun.COM if (Adapter->mcast_count == Adapter->mcast_alloc_count) {
25639770SChangqing.Li@Sun.COM old_len = Adapter->mcast_alloc_count *
25649770SChangqing.Li@Sun.COM sizeof (struct ether_addr);
25659770SChangqing.Li@Sun.COM new_len = (Adapter->mcast_alloc_count + MCAST_ALLOC_SIZE) *
25669770SChangqing.Li@Sun.COM sizeof (struct ether_addr);
25679770SChangqing.Li@Sun.COM
25689770SChangqing.Li@Sun.COM newtable = kmem_alloc(new_len, KM_NOSLEEP);
25699770SChangqing.Li@Sun.COM if (newtable == NULL) {
25709770SChangqing.Li@Sun.COM res = ENOMEM;
25719770SChangqing.Li@Sun.COM e1000g_log(Adapter, CE_WARN,
25729770SChangqing.Li@Sun.COM "Not enough memory to alloc mcast table");
25739770SChangqing.Li@Sun.COM goto done;
25749770SChangqing.Li@Sun.COM }
25759770SChangqing.Li@Sun.COM
25769770SChangqing.Li@Sun.COM if (Adapter->mcast_table != NULL) {
25779770SChangqing.Li@Sun.COM bcopy(Adapter->mcast_table, newtable, old_len);
25789770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table, old_len);
25799770SChangqing.Li@Sun.COM }
25809770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count += MCAST_ALLOC_SIZE;
25819770SChangqing.Li@Sun.COM Adapter->mcast_table = newtable;
25829770SChangqing.Li@Sun.COM }
25839770SChangqing.Li@Sun.COM
25843526Sxy150489 bcopy(multiaddr,
25853526Sxy150489 &Adapter->mcast_table[Adapter->mcast_count], ETHERADDRL);
25863526Sxy150489 Adapter->mcast_count++;
25873526Sxy150489
25883526Sxy150489 /*
25893526Sxy150489 * Update the MC table in the hardware
25903526Sxy150489 */
25914919Sxy150489 e1000g_clear_interrupt(Adapter);
25924919Sxy150489
259310680SMin.Xu@Sun.COM e1000_update_mc_addr_list(hw,
259410680SMin.Xu@Sun.COM (uint8_t *)Adapter->mcast_table, Adapter->mcast_count);
25954919Sxy150489
25964919Sxy150489 e1000g_mask_interrupt(Adapter);
25973526Sxy150489
25985273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
25995273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
26005273Sgl147354 res = EIO;
26015273Sgl147354 }
26025273Sgl147354
26038479SChenlu.Chen@Sun.COM done:
26043526Sxy150489 return (res);
26053526Sxy150489 }
26063526Sxy150489
26073526Sxy150489 static int
multicst_remove(struct e1000g * Adapter,const uint8_t * multiaddr)26083526Sxy150489 multicst_remove(struct e1000g *Adapter, const uint8_t *multiaddr)
26093526Sxy150489 {
26104919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
26119770SChangqing.Li@Sun.COM struct ether_addr *newtable;
26129770SChangqing.Li@Sun.COM size_t new_len;
26139770SChangqing.Li@Sun.COM size_t old_len;
26143526Sxy150489 unsigned i;
26153526Sxy150489
26163526Sxy150489 for (i = 0; i < Adapter->mcast_count; i++) {
26173526Sxy150489 if (bcmp(multiaddr, &Adapter->mcast_table[i],
26183526Sxy150489 ETHERADDRL) == 0) {
26193526Sxy150489 for (i++; i < Adapter->mcast_count; i++) {
26203526Sxy150489 Adapter->mcast_table[i - 1] =
26213526Sxy150489 Adapter->mcast_table[i];
26223526Sxy150489 }
26233526Sxy150489 Adapter->mcast_count--;
26243526Sxy150489 break;
26253526Sxy150489 }
26263526Sxy150489 }
26273526Sxy150489
26289770SChangqing.Li@Sun.COM if ((Adapter->mcast_alloc_count - Adapter->mcast_count) >
26299770SChangqing.Li@Sun.COM MCAST_ALLOC_SIZE) {
26309770SChangqing.Li@Sun.COM old_len = Adapter->mcast_alloc_count *
26319770SChangqing.Li@Sun.COM sizeof (struct ether_addr);
26329770SChangqing.Li@Sun.COM new_len = (Adapter->mcast_alloc_count - MCAST_ALLOC_SIZE) *
26339770SChangqing.Li@Sun.COM sizeof (struct ether_addr);
26349770SChangqing.Li@Sun.COM
26359770SChangqing.Li@Sun.COM newtable = kmem_alloc(new_len, KM_NOSLEEP);
26369770SChangqing.Li@Sun.COM if (newtable != NULL) {
26379770SChangqing.Li@Sun.COM bcopy(Adapter->mcast_table, newtable, new_len);
26389770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table, old_len);
26399770SChangqing.Li@Sun.COM
26409770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count -= MCAST_ALLOC_SIZE;
26419770SChangqing.Li@Sun.COM Adapter->mcast_table = newtable;
26429770SChangqing.Li@Sun.COM }
26439770SChangqing.Li@Sun.COM }
26449770SChangqing.Li@Sun.COM
26453526Sxy150489 /*
26463526Sxy150489 * Update the MC table in the hardware
26473526Sxy150489 */
26484919Sxy150489 e1000g_clear_interrupt(Adapter);
26494919Sxy150489
265010680SMin.Xu@Sun.COM e1000_update_mc_addr_list(hw,
265110680SMin.Xu@Sun.COM (uint8_t *)Adapter->mcast_table, Adapter->mcast_count);
26524919Sxy150489
26534919Sxy150489 e1000g_mask_interrupt(Adapter);
26543526Sxy150489
26555273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
26565273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
26575273Sgl147354 return (EIO);
26585273Sgl147354 }
26595273Sgl147354
26603526Sxy150489 return (0);
26613526Sxy150489 }
26623526Sxy150489
26639770SChangqing.Li@Sun.COM static void
e1000g_release_multicast(struct e1000g * Adapter)26649770SChangqing.Li@Sun.COM e1000g_release_multicast(struct e1000g *Adapter)
26659770SChangqing.Li@Sun.COM {
26669770SChangqing.Li@Sun.COM if (Adapter->mcast_table != NULL) {
26679770SChangqing.Li@Sun.COM kmem_free(Adapter->mcast_table,
26689770SChangqing.Li@Sun.COM Adapter->mcast_alloc_count * sizeof (struct ether_addr));
26699770SChangqing.Li@Sun.COM Adapter->mcast_table = NULL;
26709770SChangqing.Li@Sun.COM }
26719770SChangqing.Li@Sun.COM }
26729770SChangqing.Li@Sun.COM
26733526Sxy150489 int
e1000g_m_multicst(void * arg,boolean_t add,const uint8_t * addr)26743526Sxy150489 e1000g_m_multicst(void *arg, boolean_t add, const uint8_t *addr)
26753526Sxy150489 {
26763526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
26778479SChenlu.Chen@Sun.COM int result;
26788479SChenlu.Chen@Sun.COM
26798479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
26808479SChenlu.Chen@Sun.COM
26818479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
26828479SChenlu.Chen@Sun.COM result = ECANCELED;
26838479SChenlu.Chen@Sun.COM goto done;
26848479SChenlu.Chen@Sun.COM }
26858479SChenlu.Chen@Sun.COM
26868479SChenlu.Chen@Sun.COM result = (add) ? multicst_add(Adapter, addr)
26878479SChenlu.Chen@Sun.COM : multicst_remove(Adapter, addr);
26888479SChenlu.Chen@Sun.COM
26898479SChenlu.Chen@Sun.COM done:
26908479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
26918479SChenlu.Chen@Sun.COM return (result);
26928479SChenlu.Chen@Sun.COM
26933526Sxy150489 }
26943526Sxy150489
26953526Sxy150489 int
e1000g_m_promisc(void * arg,boolean_t on)26963526Sxy150489 e1000g_m_promisc(void *arg, boolean_t on)
26973526Sxy150489 {
26983526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
26994919Sxy150489 uint32_t rctl;
27003526Sxy150489
27013526Sxy150489 rw_enter(&Adapter->chip_lock, RW_WRITER);
27023526Sxy150489
27038479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
27048479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
27058479SChenlu.Chen@Sun.COM return (ECANCELED);
27068479SChenlu.Chen@Sun.COM }
27078479SChenlu.Chen@Sun.COM
27084919Sxy150489 rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL);
27093526Sxy150489
27103526Sxy150489 if (on)
27114919Sxy150489 rctl |=
27123526Sxy150489 (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM);
27133526Sxy150489 else
27144919Sxy150489 rctl &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE));
27154919Sxy150489
27164919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl);
27173526Sxy150489
27183526Sxy150489 Adapter->e1000g_promisc = on;
27193526Sxy150489
27203526Sxy150489 rw_exit(&Adapter->chip_lock);
27213526Sxy150489
27225273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
27235273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
27245273Sgl147354 return (EIO);
27255273Sgl147354 }
27265273Sgl147354
27273526Sxy150489 return (0);
27283526Sxy150489 }
27293526Sxy150489
27308275SEric Cheng /*
27318275SEric Cheng * Entry points to enable and disable interrupts at the granularity of
27328275SEric Cheng * a group.
27338275SEric Cheng * Turns the poll_mode for the whole adapter on and off to enable or
27348275SEric Cheng * override the ring level polling control over the hardware interrupts.
27358275SEric Cheng */
27368275SEric Cheng static int
e1000g_rx_group_intr_enable(mac_intr_handle_t arg)27378275SEric Cheng e1000g_rx_group_intr_enable(mac_intr_handle_t arg)
27388275SEric Cheng {
27398275SEric Cheng struct e1000g *adapter = (struct e1000g *)arg;
27408275SEric Cheng e1000g_rx_ring_t *rx_ring = adapter->rx_ring;
27418275SEric Cheng
27428275SEric Cheng /*
27438275SEric Cheng * Later interrupts at the granularity of the this ring will
27448275SEric Cheng * invoke mac_rx() with NULL, indicating the need for another
27458275SEric Cheng * software classification.
27468275SEric Cheng * We have a single ring usable per adapter now, so we only need to
27478275SEric Cheng * reset the rx handle for that one.
27488275SEric Cheng * When more RX rings can be used, we should update each one of them.
27498275SEric Cheng */
27508275SEric Cheng mutex_enter(&rx_ring->rx_lock);
27518275SEric Cheng rx_ring->mrh = NULL;
27528275SEric Cheng adapter->poll_mode = B_FALSE;
27538275SEric Cheng mutex_exit(&rx_ring->rx_lock);
27548275SEric Cheng return (0);
27558275SEric Cheng }
27568275SEric Cheng
27578275SEric Cheng static int
e1000g_rx_group_intr_disable(mac_intr_handle_t arg)27588275SEric Cheng e1000g_rx_group_intr_disable(mac_intr_handle_t arg)
27598275SEric Cheng {
27608275SEric Cheng struct e1000g *adapter = (struct e1000g *)arg;
27618275SEric Cheng e1000g_rx_ring_t *rx_ring = adapter->rx_ring;
27628275SEric Cheng
27638275SEric Cheng mutex_enter(&rx_ring->rx_lock);
27648275SEric Cheng
27658275SEric Cheng /*
27668275SEric Cheng * Later interrupts at the granularity of the this ring will
27678275SEric Cheng * invoke mac_rx() with the handle for this ring;
27688275SEric Cheng */
27698275SEric Cheng adapter->poll_mode = B_TRUE;
27708275SEric Cheng rx_ring->mrh = rx_ring->mrh_init;
27718275SEric Cheng mutex_exit(&rx_ring->rx_lock);
27728275SEric Cheng return (0);
27738275SEric Cheng }
27748275SEric Cheng
27758275SEric Cheng /*
27768275SEric Cheng * Entry points to enable and disable interrupts at the granularity of
27778275SEric Cheng * a ring.
27788275SEric Cheng * adapter poll_mode controls whether we actually proceed with hardware
27798275SEric Cheng * interrupt toggling.
27808275SEric Cheng */
27818275SEric Cheng static int
e1000g_rx_ring_intr_enable(mac_intr_handle_t intrh)27828275SEric Cheng e1000g_rx_ring_intr_enable(mac_intr_handle_t intrh)
27838275SEric Cheng {
27848275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)intrh;
27858275SEric Cheng struct e1000g *adapter = rx_ring->adapter;
27868275SEric Cheng struct e1000_hw *hw = &adapter->shared;
27878275SEric Cheng uint32_t intr_mask;
27888275SEric Cheng
27898479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER);
27908479SChenlu.Chen@Sun.COM
27918479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) {
27928479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
27938479SChenlu.Chen@Sun.COM return (0);
27948479SChenlu.Chen@Sun.COM }
27958479SChenlu.Chen@Sun.COM
27968275SEric Cheng mutex_enter(&rx_ring->rx_lock);
27978275SEric Cheng rx_ring->poll_flag = 0;
27988275SEric Cheng mutex_exit(&rx_ring->rx_lock);
27998275SEric Cheng
28008833SVenu.Iyer@Sun.COM /* Rx interrupt enabling for MSI and legacy */
28018833SVenu.Iyer@Sun.COM intr_mask = E1000_READ_REG(hw, E1000_IMS);
28028833SVenu.Iyer@Sun.COM intr_mask |= E1000_IMS_RXT0;
28038833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_IMS, intr_mask);
28048833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw);
28058833SVenu.Iyer@Sun.COM
28068833SVenu.Iyer@Sun.COM /* Trigger a Rx interrupt to check Rx ring */
28078833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0);
28088833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw);
28098479SChenlu.Chen@Sun.COM
28108479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
28118275SEric Cheng return (0);
28128275SEric Cheng }
28138275SEric Cheng
28148275SEric Cheng static int
e1000g_rx_ring_intr_disable(mac_intr_handle_t intrh)28158275SEric Cheng e1000g_rx_ring_intr_disable(mac_intr_handle_t intrh)
28168275SEric Cheng {
28178275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)intrh;
28188275SEric Cheng struct e1000g *adapter = rx_ring->adapter;
28198275SEric Cheng struct e1000_hw *hw = &adapter->shared;
28208275SEric Cheng
28218479SChenlu.Chen@Sun.COM rw_enter(&adapter->chip_lock, RW_READER);
28228479SChenlu.Chen@Sun.COM
28238479SChenlu.Chen@Sun.COM if (adapter->e1000g_state & E1000G_SUSPENDED) {
28248479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
28258479SChenlu.Chen@Sun.COM return (0);
28268479SChenlu.Chen@Sun.COM }
28278275SEric Cheng mutex_enter(&rx_ring->rx_lock);
28288275SEric Cheng rx_ring->poll_flag = 1;
28298275SEric Cheng mutex_exit(&rx_ring->rx_lock);
28308275SEric Cheng
28318833SVenu.Iyer@Sun.COM /* Rx interrupt disabling for MSI and legacy */
28328833SVenu.Iyer@Sun.COM E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_RXT0);
28338833SVenu.Iyer@Sun.COM E1000_WRITE_FLUSH(hw);
28348479SChenlu.Chen@Sun.COM
28358479SChenlu.Chen@Sun.COM rw_exit(&adapter->chip_lock);
28368275SEric Cheng return (0);
28378275SEric Cheng }
28388275SEric Cheng
28398275SEric Cheng /*
28408275SEric Cheng * e1000g_unicst_find - Find the slot for the specified unicast address
28418275SEric Cheng */
28428275SEric Cheng static int
e1000g_unicst_find(struct e1000g * Adapter,const uint8_t * mac_addr)28438275SEric Cheng e1000g_unicst_find(struct e1000g *Adapter, const uint8_t *mac_addr)
28448275SEric Cheng {
28458275SEric Cheng int slot;
28468275SEric Cheng
28478275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) {
28488479SChenlu.Chen@Sun.COM if ((Adapter->unicst_addr[slot].mac.set == 1) &&
28498479SChenlu.Chen@Sun.COM (bcmp(Adapter->unicst_addr[slot].mac.addr,
28508479SChenlu.Chen@Sun.COM mac_addr, ETHERADDRL) == 0))
28518275SEric Cheng return (slot);
28528275SEric Cheng }
28538275SEric Cheng
28548275SEric Cheng return (-1);
28558275SEric Cheng }
28568275SEric Cheng
28578275SEric Cheng /*
28588275SEric Cheng * Entry points to add and remove a MAC address to a ring group.
28598275SEric Cheng * The caller takes care of adding and removing the MAC addresses
28608275SEric Cheng * to the filter via these two routines.
28618275SEric Cheng */
28628275SEric Cheng
28638275SEric Cheng static int
e1000g_addmac(void * arg,const uint8_t * mac_addr)28648275SEric Cheng e1000g_addmac(void *arg, const uint8_t *mac_addr)
28658275SEric Cheng {
28668275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg;
28678400SNicolas.Droux@Sun.COM int slot, err;
28688275SEric Cheng
28698479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
28708479SChenlu.Chen@Sun.COM
28718479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
28728479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
28738479SChenlu.Chen@Sun.COM return (ECANCELED);
28748479SChenlu.Chen@Sun.COM }
28758275SEric Cheng
28768275SEric Cheng if (e1000g_unicst_find(Adapter, mac_addr) != -1) {
28778275SEric Cheng /* The same address is already in slot */
28788479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
28798275SEric Cheng return (0);
28808275SEric Cheng }
28818275SEric Cheng
28828275SEric Cheng if (Adapter->unicst_avail == 0) {
28838275SEric Cheng /* no slots available */
28848479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
28858275SEric Cheng return (ENOSPC);
28868275SEric Cheng }
28878275SEric Cheng
28888275SEric Cheng /* Search for a free slot */
28898275SEric Cheng for (slot = 0; slot < Adapter->unicst_total; slot++) {
28908275SEric Cheng if (Adapter->unicst_addr[slot].mac.set == 0)
28918275SEric Cheng break;
28928275SEric Cheng }
28938275SEric Cheng ASSERT(slot < Adapter->unicst_total);
28948275SEric Cheng
28958400SNicolas.Droux@Sun.COM err = e1000g_unicst_set(Adapter, mac_addr, slot);
28968400SNicolas.Droux@Sun.COM if (err == 0)
28978400SNicolas.Droux@Sun.COM Adapter->unicst_avail--;
28988275SEric Cheng
28998479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
29008275SEric Cheng
29018400SNicolas.Droux@Sun.COM return (err);
29028275SEric Cheng }
29038275SEric Cheng
29048275SEric Cheng static int
e1000g_remmac(void * arg,const uint8_t * mac_addr)29058275SEric Cheng e1000g_remmac(void *arg, const uint8_t *mac_addr)
29068275SEric Cheng {
29078275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg;
29088400SNicolas.Droux@Sun.COM int slot, err;
29098275SEric Cheng
29108479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
29118479SChenlu.Chen@Sun.COM
29128479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
29138479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
29148479SChenlu.Chen@Sun.COM return (ECANCELED);
29158479SChenlu.Chen@Sun.COM }
29168275SEric Cheng
29178275SEric Cheng slot = e1000g_unicst_find(Adapter, mac_addr);
29188275SEric Cheng if (slot == -1) {
29198479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
29208275SEric Cheng return (EINVAL);
29218275SEric Cheng }
29228275SEric Cheng
29238275SEric Cheng ASSERT(Adapter->unicst_addr[slot].mac.set);
29248275SEric Cheng
29258275SEric Cheng /* Clear this slot */
29268400SNicolas.Droux@Sun.COM err = e1000g_unicst_set(Adapter, NULL, slot);
29278400SNicolas.Droux@Sun.COM if (err == 0)
29288400SNicolas.Droux@Sun.COM Adapter->unicst_avail++;
29298275SEric Cheng
29308479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
29318275SEric Cheng
29328400SNicolas.Droux@Sun.COM return (err);
29338275SEric Cheng }
29348275SEric Cheng
29358275SEric Cheng static int
e1000g_ring_start(mac_ring_driver_t rh,uint64_t mr_gen_num)29368275SEric Cheng e1000g_ring_start(mac_ring_driver_t rh, uint64_t mr_gen_num)
29378275SEric Cheng {
29388275SEric Cheng e1000g_rx_ring_t *rx_ring = (e1000g_rx_ring_t *)rh;
29398275SEric Cheng
29408275SEric Cheng mutex_enter(&rx_ring->rx_lock);
29418275SEric Cheng rx_ring->ring_gen_num = mr_gen_num;
29428275SEric Cheng mutex_exit(&rx_ring->rx_lock);
29438275SEric Cheng return (0);
29448275SEric Cheng }
29458275SEric Cheng
29468275SEric Cheng /*
29478275SEric Cheng * Callback funtion for MAC layer to register all rings.
29488275SEric Cheng *
29498275SEric Cheng * The hardware supports a single group with currently only one ring
29508275SEric Cheng * available.
29518275SEric Cheng * Though not offering virtualization ability per se, exposing the
29528275SEric Cheng * group/ring still enables the polling and interrupt toggling.
29538275SEric Cheng */
295411143SGuoqing.Zhu@Sun.COM /* ARGSUSED */
29558275SEric Cheng void
e1000g_fill_ring(void * arg,mac_ring_type_t rtype,const int grp_index,const int ring_index,mac_ring_info_t * infop,mac_ring_handle_t rh)29568275SEric Cheng e1000g_fill_ring(void *arg, mac_ring_type_t rtype, const int grp_index,
29578275SEric Cheng const int ring_index, mac_ring_info_t *infop, mac_ring_handle_t rh)
29588275SEric Cheng {
29598275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg;
29608275SEric Cheng e1000g_rx_ring_t *rx_ring = Adapter->rx_ring;
29618275SEric Cheng mac_intr_t *mintr;
29628275SEric Cheng
29638275SEric Cheng /*
29648275SEric Cheng * We advertised only RX group/rings, so the MAC framework shouldn't
29658275SEric Cheng * ask for any thing else.
29668275SEric Cheng */
29678275SEric Cheng ASSERT(rtype == MAC_RING_TYPE_RX && grp_index == 0 && ring_index == 0);
29688275SEric Cheng
29698275SEric Cheng rx_ring->mrh = rx_ring->mrh_init = rh;
29708275SEric Cheng infop->mri_driver = (mac_ring_driver_t)rx_ring;
29718275SEric Cheng infop->mri_start = e1000g_ring_start;
29728275SEric Cheng infop->mri_stop = NULL;
29738275SEric Cheng infop->mri_poll = e1000g_poll_ring;
297411878SVenu.Iyer@Sun.COM infop->mri_stat = e1000g_rx_ring_stat;
29758275SEric Cheng
29768275SEric Cheng /* Ring level interrupts */
29778275SEric Cheng mintr = &infop->mri_intr;
29788275SEric Cheng mintr->mi_handle = (mac_intr_handle_t)rx_ring;
29798275SEric Cheng mintr->mi_enable = e1000g_rx_ring_intr_enable;
29808275SEric Cheng mintr->mi_disable = e1000g_rx_ring_intr_disable;
298111878SVenu.Iyer@Sun.COM if (Adapter->msi_enable)
298211878SVenu.Iyer@Sun.COM mintr->mi_ddi_handle = Adapter->htable[0];
29838275SEric Cheng }
29848275SEric Cheng
298511143SGuoqing.Zhu@Sun.COM /* ARGSUSED */
29868275SEric Cheng static void
e1000g_fill_group(void * arg,mac_ring_type_t rtype,const int grp_index,mac_group_info_t * infop,mac_group_handle_t gh)29878275SEric Cheng e1000g_fill_group(void *arg, mac_ring_type_t rtype, const int grp_index,
29888275SEric Cheng mac_group_info_t *infop, mac_group_handle_t gh)
29898275SEric Cheng {
29908275SEric Cheng struct e1000g *Adapter = (struct e1000g *)arg;
29918275SEric Cheng mac_intr_t *mintr;
29928275SEric Cheng
29938275SEric Cheng /*
29948275SEric Cheng * We advertised a single RX ring. Getting a request for anything else
29958275SEric Cheng * signifies a bug in the MAC framework.
29968275SEric Cheng */
29978275SEric Cheng ASSERT(rtype == MAC_RING_TYPE_RX && grp_index == 0);
29988275SEric Cheng
29998275SEric Cheng Adapter->rx_group = gh;
30008275SEric Cheng
30018275SEric Cheng infop->mgi_driver = (mac_group_driver_t)Adapter;
30028275SEric Cheng infop->mgi_start = NULL;
30038275SEric Cheng infop->mgi_stop = NULL;
30048275SEric Cheng infop->mgi_addmac = e1000g_addmac;
30058275SEric Cheng infop->mgi_remmac = e1000g_remmac;
30068275SEric Cheng infop->mgi_count = 1;
30078275SEric Cheng
30088275SEric Cheng /* Group level interrupts */
30098275SEric Cheng mintr = &infop->mgi_intr;
30108275SEric Cheng mintr->mi_handle = (mac_intr_handle_t)Adapter;
30118275SEric Cheng mintr->mi_enable = e1000g_rx_group_intr_enable;
30128275SEric Cheng mintr->mi_disable = e1000g_rx_group_intr_disable;
30138275SEric Cheng }
30148275SEric Cheng
30153526Sxy150489 static boolean_t
e1000g_m_getcapab(void * arg,mac_capab_t cap,void * cap_data)30163526Sxy150489 e1000g_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
30173526Sxy150489 {
30183526Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
30193526Sxy150489
30203526Sxy150489 switch (cap) {
30213526Sxy150489 case MAC_CAPAB_HCKSUM: {
30223526Sxy150489 uint32_t *txflags = cap_data;
30236986Smx205022
30246986Smx205022 if (Adapter->tx_hcksum_enable)
30256986Smx205022 *txflags = HCKSUM_IPHDRCKSUM |
30266986Smx205022 HCKSUM_INET_PARTIAL;
30276986Smx205022 else
30283526Sxy150489 return (B_FALSE);
30293526Sxy150489 break;
30303526Sxy150489 }
30316986Smx205022
30326986Smx205022 case MAC_CAPAB_LSO: {
30336986Smx205022 mac_capab_lso_t *cap_lso = cap_data;
30346986Smx205022
30356986Smx205022 if (Adapter->lso_enable) {
30366986Smx205022 cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4;
30376986Smx205022 cap_lso->lso_basic_tcp_ipv4.lso_max =
30386986Smx205022 E1000_LSO_MAXLEN;
30396986Smx205022 } else
30406986Smx205022 return (B_FALSE);
30416986Smx205022 break;
30426986Smx205022 }
30438275SEric Cheng case MAC_CAPAB_RINGS: {
30448275SEric Cheng mac_capab_rings_t *cap_rings = cap_data;
30458275SEric Cheng
30468275SEric Cheng /* No TX rings exposed yet */
30478275SEric Cheng if (cap_rings->mr_type != MAC_RING_TYPE_RX)
30488275SEric Cheng return (B_FALSE);
30498275SEric Cheng
30508275SEric Cheng cap_rings->mr_group_type = MAC_GROUP_TYPE_STATIC;
30518275SEric Cheng cap_rings->mr_rnum = 1;
30528275SEric Cheng cap_rings->mr_gnum = 1;
30538275SEric Cheng cap_rings->mr_rget = e1000g_fill_ring;
30548275SEric Cheng cap_rings->mr_gget = e1000g_fill_group;
30558275SEric Cheng break;
30568275SEric Cheng }
30573526Sxy150489 default:
30583526Sxy150489 return (B_FALSE);
30593526Sxy150489 }
30603526Sxy150489 return (B_TRUE);
30613526Sxy150489 }
30623526Sxy150489
30636394Scc210113 static boolean_t
e1000g_param_locked(mac_prop_id_t pr_num)30646394Scc210113 e1000g_param_locked(mac_prop_id_t pr_num)
30656394Scc210113 {
30666394Scc210113 /*
30676394Scc210113 * All en_* parameters are locked (read-only) while
30686394Scc210113 * the device is in any sort of loopback mode ...
30696394Scc210113 */
30706394Scc210113 switch (pr_num) {
30716789Sam223141 case MAC_PROP_EN_1000FDX_CAP:
30726789Sam223141 case MAC_PROP_EN_1000HDX_CAP:
30736789Sam223141 case MAC_PROP_EN_100FDX_CAP:
30746789Sam223141 case MAC_PROP_EN_100HDX_CAP:
30756789Sam223141 case MAC_PROP_EN_10FDX_CAP:
30766789Sam223141 case MAC_PROP_EN_10HDX_CAP:
30776789Sam223141 case MAC_PROP_AUTONEG:
30786789Sam223141 case MAC_PROP_FLOWCTRL:
30796394Scc210113 return (B_TRUE);
30806394Scc210113 }
30816394Scc210113 return (B_FALSE);
30826394Scc210113 }
30836394Scc210113
30846394Scc210113 /*
30856394Scc210113 * callback function for set/get of properties
30866394Scc210113 */
30876394Scc210113 static int
e1000g_m_setprop(void * arg,const char * pr_name,mac_prop_id_t pr_num,uint_t pr_valsize,const void * pr_val)30886394Scc210113 e1000g_m_setprop(void *arg, const char *pr_name, mac_prop_id_t pr_num,
30896394Scc210113 uint_t pr_valsize, const void *pr_val)
30906394Scc210113 {
30916394Scc210113 struct e1000g *Adapter = arg;
309210605SMin.Xu@Sun.COM struct e1000_hw *hw = &Adapter->shared;
30936735Scc210113 struct e1000_fc_info *fc = &Adapter->shared.fc;
30946394Scc210113 int err = 0;
30956735Scc210113 link_flowctrl_t flowctrl;
30966512Ssowmini uint32_t cur_mtu, new_mtu;
30976394Scc210113
30986394Scc210113 rw_enter(&Adapter->chip_lock, RW_WRITER);
30998479SChenlu.Chen@Sun.COM
31008479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_SUSPENDED) {
31018479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
31028479SChenlu.Chen@Sun.COM return (ECANCELED);
31038479SChenlu.Chen@Sun.COM }
31048479SChenlu.Chen@Sun.COM
31056394Scc210113 if (Adapter->loopback_mode != E1000G_LB_NONE &&
31066394Scc210113 e1000g_param_locked(pr_num)) {
31076394Scc210113 /*
31086394Scc210113 * All en_* parameters are locked (read-only)
31096394Scc210113 * while the device is in any sort of loopback mode.
31106394Scc210113 */
31116394Scc210113 rw_exit(&Adapter->chip_lock);
31126394Scc210113 return (EBUSY);
31136394Scc210113 }
31146394Scc210113
31156394Scc210113 switch (pr_num) {
31166789Sam223141 case MAC_PROP_EN_1000FDX_CAP:
311710605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
311810605SMin.Xu@Sun.COM err = ENOTSUP;
311910605SMin.Xu@Sun.COM break;
312010605SMin.Xu@Sun.COM }
31216394Scc210113 Adapter->param_en_1000fdx = *(uint8_t *)pr_val;
31226394Scc210113 Adapter->param_adv_1000fdx = *(uint8_t *)pr_val;
31236394Scc210113 goto reset;
31246789Sam223141 case MAC_PROP_EN_100FDX_CAP:
312510605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
312610605SMin.Xu@Sun.COM err = ENOTSUP;
312710605SMin.Xu@Sun.COM break;
312810605SMin.Xu@Sun.COM }
31296394Scc210113 Adapter->param_en_100fdx = *(uint8_t *)pr_val;
31306394Scc210113 Adapter->param_adv_100fdx = *(uint8_t *)pr_val;
31316394Scc210113 goto reset;
31326789Sam223141 case MAC_PROP_EN_100HDX_CAP:
313310605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
313410605SMin.Xu@Sun.COM err = ENOTSUP;
313510605SMin.Xu@Sun.COM break;
313610605SMin.Xu@Sun.COM }
31376394Scc210113 Adapter->param_en_100hdx = *(uint8_t *)pr_val;
31386394Scc210113 Adapter->param_adv_100hdx = *(uint8_t *)pr_val;
31396394Scc210113 goto reset;
31406789Sam223141 case MAC_PROP_EN_10FDX_CAP:
314110605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
314210605SMin.Xu@Sun.COM err = ENOTSUP;
314310605SMin.Xu@Sun.COM break;
314410605SMin.Xu@Sun.COM }
31456394Scc210113 Adapter->param_en_10fdx = *(uint8_t *)pr_val;
31466394Scc210113 Adapter->param_adv_10fdx = *(uint8_t *)pr_val;
31476394Scc210113 goto reset;
31486789Sam223141 case MAC_PROP_EN_10HDX_CAP:
314910605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
315010605SMin.Xu@Sun.COM err = ENOTSUP;
315110605SMin.Xu@Sun.COM break;
315210605SMin.Xu@Sun.COM }
31536394Scc210113 Adapter->param_en_10hdx = *(uint8_t *)pr_val;
31546394Scc210113 Adapter->param_adv_10hdx = *(uint8_t *)pr_val;
31556394Scc210113 goto reset;
31566789Sam223141 case MAC_PROP_AUTONEG:
315710605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
315810605SMin.Xu@Sun.COM err = ENOTSUP;
315910605SMin.Xu@Sun.COM break;
316010605SMin.Xu@Sun.COM }
31616394Scc210113 Adapter->param_adv_autoneg = *(uint8_t *)pr_val;
31626394Scc210113 goto reset;
31636789Sam223141 case MAC_PROP_FLOWCTRL:
31646735Scc210113 fc->send_xon = B_TRUE;
31656735Scc210113 bcopy(pr_val, &flowctrl, sizeof (flowctrl));
31666735Scc210113
31676735Scc210113 switch (flowctrl) {
31686394Scc210113 default:
31696394Scc210113 err = EINVAL;
31706394Scc210113 break;
31716394Scc210113 case LINK_FLOWCTRL_NONE:
31728539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_none;
31736394Scc210113 break;
31746394Scc210113 case LINK_FLOWCTRL_RX:
31758539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_rx_pause;
31766394Scc210113 break;
31776394Scc210113 case LINK_FLOWCTRL_TX:
31788539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_tx_pause;
31796394Scc210113 break;
31806394Scc210113 case LINK_FLOWCTRL_BI:
31818539SChenlu.Chen@Sun.COM fc->requested_mode = e1000_fc_full;
31826394Scc210113 break;
31836394Scc210113 }
31846394Scc210113 reset:
31856394Scc210113 if (err == 0) {
318610680SMin.Xu@Sun.COM /* check PCH limits & reset the link */
318710680SMin.Xu@Sun.COM e1000g_pch_limits(Adapter);
31886394Scc210113 if (e1000g_reset_link(Adapter) != DDI_SUCCESS)
31896394Scc210113 err = EINVAL;
31906394Scc210113 }
31916394Scc210113 break;
31926789Sam223141 case MAC_PROP_ADV_1000FDX_CAP:
31936789Sam223141 case MAC_PROP_ADV_1000HDX_CAP:
31946789Sam223141 case MAC_PROP_ADV_100FDX_CAP:
31956789Sam223141 case MAC_PROP_ADV_100HDX_CAP:
31966789Sam223141 case MAC_PROP_ADV_10FDX_CAP:
31976789Sam223141 case MAC_PROP_ADV_10HDX_CAP:
31988118SVasumathi.Sundaram@Sun.COM case MAC_PROP_EN_1000HDX_CAP:
31996789Sam223141 case MAC_PROP_STATUS:
32006789Sam223141 case MAC_PROP_SPEED:
32016789Sam223141 case MAC_PROP_DUPLEX:
32026394Scc210113 err = ENOTSUP; /* read-only prop. Can't set this. */
32036394Scc210113 break;
32046789Sam223141 case MAC_PROP_MTU:
320510680SMin.Xu@Sun.COM /* adapter must be stopped for an MTU change */
320610680SMin.Xu@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) {
320710680SMin.Xu@Sun.COM err = EBUSY;
320810680SMin.Xu@Sun.COM break;
320910680SMin.Xu@Sun.COM }
321010680SMin.Xu@Sun.COM
32116394Scc210113 cur_mtu = Adapter->default_mtu;
321210680SMin.Xu@Sun.COM
321310680SMin.Xu@Sun.COM /* get new requested MTU */
32146394Scc210113 bcopy(pr_val, &new_mtu, sizeof (new_mtu));
32156394Scc210113 if (new_mtu == cur_mtu) {
32166394Scc210113 err = 0;
32176394Scc210113 break;
32186394Scc210113 }
32196394Scc210113
322010680SMin.Xu@Sun.COM if ((new_mtu < DEFAULT_MTU) ||
322110680SMin.Xu@Sun.COM (new_mtu > Adapter->max_mtu)) {
32226394Scc210113 err = EINVAL;
32236394Scc210113 break;
32246394Scc210113 }
322510680SMin.Xu@Sun.COM
322610680SMin.Xu@Sun.COM /* inform MAC framework of new MTU */
32276394Scc210113 err = mac_maxsdu_update(Adapter->mh, new_mtu);
322810680SMin.Xu@Sun.COM
32296394Scc210113 if (err == 0) {
32306394Scc210113 Adapter->default_mtu = new_mtu;
323110680SMin.Xu@Sun.COM Adapter->max_frame_size =
323210680SMin.Xu@Sun.COM e1000g_mtu2maxframe(new_mtu);
323310680SMin.Xu@Sun.COM
323410680SMin.Xu@Sun.COM /*
323510680SMin.Xu@Sun.COM * check PCH limits & set buffer sizes to
323610680SMin.Xu@Sun.COM * match new MTU
323710680SMin.Xu@Sun.COM */
323810680SMin.Xu@Sun.COM e1000g_pch_limits(Adapter);
32396394Scc210113 e1000g_set_bufsize(Adapter);
324011339SGuoqing.Zhu@Sun.COM
324111339SGuoqing.Zhu@Sun.COM /*
324211339SGuoqing.Zhu@Sun.COM * decrease the number of descriptors and free
324311339SGuoqing.Zhu@Sun.COM * packets for jumbo frames to reduce tx/rx
324411339SGuoqing.Zhu@Sun.COM * resource consumption
324511339SGuoqing.Zhu@Sun.COM */
324611339SGuoqing.Zhu@Sun.COM if (Adapter->max_frame_size >=
3247*12853SChangqing.Li@Sun.COM (FRAME_SIZE_UPTO_4K)) {
324811339SGuoqing.Zhu@Sun.COM if (Adapter->tx_desc_num_flag == 0)
324911339SGuoqing.Zhu@Sun.COM Adapter->tx_desc_num =
325011339SGuoqing.Zhu@Sun.COM DEFAULT_JUMBO_NUM_TX_DESC;
325111339SGuoqing.Zhu@Sun.COM
325211339SGuoqing.Zhu@Sun.COM if (Adapter->rx_desc_num_flag == 0)
325311339SGuoqing.Zhu@Sun.COM Adapter->rx_desc_num =
325411339SGuoqing.Zhu@Sun.COM DEFAULT_JUMBO_NUM_RX_DESC;
325511339SGuoqing.Zhu@Sun.COM
325611339SGuoqing.Zhu@Sun.COM if (Adapter->tx_buf_num_flag == 0)
325711339SGuoqing.Zhu@Sun.COM Adapter->tx_freelist_num =
325811339SGuoqing.Zhu@Sun.COM DEFAULT_JUMBO_NUM_TX_BUF;
325911339SGuoqing.Zhu@Sun.COM
326011339SGuoqing.Zhu@Sun.COM if (Adapter->rx_buf_num_flag == 0)
3261*12853SChangqing.Li@Sun.COM Adapter->rx_freelist_limit =
326211339SGuoqing.Zhu@Sun.COM DEFAULT_JUMBO_NUM_RX_BUF;
326311339SGuoqing.Zhu@Sun.COM } else {
326411339SGuoqing.Zhu@Sun.COM if (Adapter->tx_desc_num_flag == 0)
326511339SGuoqing.Zhu@Sun.COM Adapter->tx_desc_num =
326611339SGuoqing.Zhu@Sun.COM DEFAULT_NUM_TX_DESCRIPTOR;
326711339SGuoqing.Zhu@Sun.COM
326811339SGuoqing.Zhu@Sun.COM if (Adapter->rx_desc_num_flag == 0)
326911339SGuoqing.Zhu@Sun.COM Adapter->rx_desc_num =
327011339SGuoqing.Zhu@Sun.COM DEFAULT_NUM_RX_DESCRIPTOR;
327111339SGuoqing.Zhu@Sun.COM
327211339SGuoqing.Zhu@Sun.COM if (Adapter->tx_buf_num_flag == 0)
327311339SGuoqing.Zhu@Sun.COM Adapter->tx_freelist_num =
327411339SGuoqing.Zhu@Sun.COM DEFAULT_NUM_TX_FREELIST;
327511339SGuoqing.Zhu@Sun.COM
327611339SGuoqing.Zhu@Sun.COM if (Adapter->rx_buf_num_flag == 0)
3277*12853SChangqing.Li@Sun.COM Adapter->rx_freelist_limit =
327811339SGuoqing.Zhu@Sun.COM DEFAULT_NUM_RX_FREELIST;
327911339SGuoqing.Zhu@Sun.COM }
32806394Scc210113 }
32816394Scc210113 break;
32826789Sam223141 case MAC_PROP_PRIVATE:
32836394Scc210113 err = e1000g_set_priv_prop(Adapter, pr_name,
32846394Scc210113 pr_valsize, pr_val);
32856394Scc210113 break;
32866394Scc210113 default:
32876394Scc210113 err = ENOTSUP;
32886394Scc210113 break;
32896394Scc210113 }
32906394Scc210113 rw_exit(&Adapter->chip_lock);
32916394Scc210113 return (err);
32926394Scc210113 }
32936394Scc210113
32946394Scc210113 static int
e1000g_m_getprop(void * arg,const char * pr_name,mac_prop_id_t pr_num,uint_t pr_valsize,void * pr_val)32956394Scc210113 e1000g_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num,
329611878SVenu.Iyer@Sun.COM uint_t pr_valsize, void *pr_val)
32976394Scc210113 {
32986394Scc210113 struct e1000g *Adapter = arg;
32996735Scc210113 struct e1000_fc_info *fc = &Adapter->shared.fc;
33006512Ssowmini int err = 0;
33016735Scc210113 link_flowctrl_t flowctrl;
33026394Scc210113 uint64_t tmp = 0;
33036394Scc210113
33046394Scc210113 switch (pr_num) {
33056789Sam223141 case MAC_PROP_DUPLEX:
330611878SVenu.Iyer@Sun.COM ASSERT(pr_valsize >= sizeof (link_duplex_t));
330711878SVenu.Iyer@Sun.COM bcopy(&Adapter->link_duplex, pr_val,
330811878SVenu.Iyer@Sun.COM sizeof (link_duplex_t));
33096394Scc210113 break;
33106789Sam223141 case MAC_PROP_SPEED:
331111878SVenu.Iyer@Sun.COM ASSERT(pr_valsize >= sizeof (uint64_t));
331211878SVenu.Iyer@Sun.COM tmp = Adapter->link_speed * 1000000ull;
331311878SVenu.Iyer@Sun.COM bcopy(&tmp, pr_val, sizeof (tmp));
33146394Scc210113 break;
33156789Sam223141 case MAC_PROP_AUTONEG:
33166512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_autoneg;
33176394Scc210113 break;
33186789Sam223141 case MAC_PROP_FLOWCTRL:
331911878SVenu.Iyer@Sun.COM ASSERT(pr_valsize >= sizeof (link_flowctrl_t));
332011878SVenu.Iyer@Sun.COM switch (fc->current_mode) {
332111878SVenu.Iyer@Sun.COM case e1000_fc_none:
332211878SVenu.Iyer@Sun.COM flowctrl = LINK_FLOWCTRL_NONE;
332311878SVenu.Iyer@Sun.COM break;
332411878SVenu.Iyer@Sun.COM case e1000_fc_rx_pause:
332511878SVenu.Iyer@Sun.COM flowctrl = LINK_FLOWCTRL_RX;
332611878SVenu.Iyer@Sun.COM break;
332711878SVenu.Iyer@Sun.COM case e1000_fc_tx_pause:
332811878SVenu.Iyer@Sun.COM flowctrl = LINK_FLOWCTRL_TX;
332911878SVenu.Iyer@Sun.COM break;
333011878SVenu.Iyer@Sun.COM case e1000_fc_full:
333111878SVenu.Iyer@Sun.COM flowctrl = LINK_FLOWCTRL_BI;
333211878SVenu.Iyer@Sun.COM break;
333311878SVenu.Iyer@Sun.COM }
333411878SVenu.Iyer@Sun.COM bcopy(&flowctrl, pr_val, sizeof (flowctrl));
33356394Scc210113 break;
33366789Sam223141 case MAC_PROP_ADV_1000FDX_CAP:
33376512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_1000fdx;
33386394Scc210113 break;
33396789Sam223141 case MAC_PROP_EN_1000FDX_CAP:
33406512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_1000fdx;
33416394Scc210113 break;
33426789Sam223141 case MAC_PROP_ADV_1000HDX_CAP:
33436512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_1000hdx;
33446394Scc210113 break;
33456789Sam223141 case MAC_PROP_EN_1000HDX_CAP:
33466512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_1000hdx;
33476394Scc210113 break;
33486789Sam223141 case MAC_PROP_ADV_100FDX_CAP:
33496512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100fdx;
33506394Scc210113 break;
33516789Sam223141 case MAC_PROP_EN_100FDX_CAP:
33526512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_100fdx;
33536394Scc210113 break;
33546789Sam223141 case MAC_PROP_ADV_100HDX_CAP:
33556512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100hdx;
33566394Scc210113 break;
33576789Sam223141 case MAC_PROP_EN_100HDX_CAP:
33586512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_100hdx;
33596394Scc210113 break;
33606789Sam223141 case MAC_PROP_ADV_10FDX_CAP:
33616512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_10fdx;
33626394Scc210113 break;
33636789Sam223141 case MAC_PROP_EN_10FDX_CAP:
33646512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_10fdx;
33656394Scc210113 break;
33666789Sam223141 case MAC_PROP_ADV_10HDX_CAP:
33676512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_10hdx;
33686394Scc210113 break;
33696789Sam223141 case MAC_PROP_EN_10HDX_CAP:
33706512Ssowmini *(uint8_t *)pr_val = Adapter->param_en_10hdx;
33716512Ssowmini break;
33726789Sam223141 case MAC_PROP_ADV_100T4_CAP:
33736789Sam223141 case MAC_PROP_EN_100T4_CAP:
33746512Ssowmini *(uint8_t *)pr_val = Adapter->param_adv_100t4;
33756394Scc210113 break;
33766789Sam223141 case MAC_PROP_PRIVATE:
33776394Scc210113 err = e1000g_get_priv_prop(Adapter, pr_name,
337811878SVenu.Iyer@Sun.COM pr_valsize, pr_val);
33796394Scc210113 break;
33806394Scc210113 default:
33816394Scc210113 err = ENOTSUP;
33826394Scc210113 break;
33836394Scc210113 }
338411878SVenu.Iyer@Sun.COM
33856394Scc210113 return (err);
33866394Scc210113 }
33876394Scc210113
338811878SVenu.Iyer@Sun.COM static void
e1000g_m_propinfo(void * arg,const char * pr_name,mac_prop_id_t pr_num,mac_prop_info_handle_t prh)338911878SVenu.Iyer@Sun.COM e1000g_m_propinfo(void *arg, const char *pr_name, mac_prop_id_t pr_num,
339011878SVenu.Iyer@Sun.COM mac_prop_info_handle_t prh)
339111878SVenu.Iyer@Sun.COM {
339211878SVenu.Iyer@Sun.COM struct e1000g *Adapter = arg;
339311878SVenu.Iyer@Sun.COM struct e1000_hw *hw = &Adapter->shared;
339411878SVenu.Iyer@Sun.COM
339511878SVenu.Iyer@Sun.COM switch (pr_num) {
339611878SVenu.Iyer@Sun.COM case MAC_PROP_DUPLEX:
339711878SVenu.Iyer@Sun.COM case MAC_PROP_SPEED:
339811878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_1000FDX_CAP:
339911878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_1000HDX_CAP:
340011878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_100FDX_CAP:
340111878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_100HDX_CAP:
340211878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_10FDX_CAP:
340311878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_10HDX_CAP:
340411878SVenu.Iyer@Sun.COM case MAC_PROP_ADV_100T4_CAP:
340511878SVenu.Iyer@Sun.COM case MAC_PROP_EN_100T4_CAP:
340611878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
340711878SVenu.Iyer@Sun.COM break;
340811878SVenu.Iyer@Sun.COM
340911878SVenu.Iyer@Sun.COM case MAC_PROP_EN_1000FDX_CAP:
341011878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
341111878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
341211878SVenu.Iyer@Sun.COM } else {
341311878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
341411878SVenu.Iyer@Sun.COM ((Adapter->phy_ext_status &
341511878SVenu.Iyer@Sun.COM IEEE_ESR_1000T_FD_CAPS) ||
341611878SVenu.Iyer@Sun.COM (Adapter->phy_ext_status &
341711878SVenu.Iyer@Sun.COM IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0);
341811878SVenu.Iyer@Sun.COM }
341911878SVenu.Iyer@Sun.COM break;
342011878SVenu.Iyer@Sun.COM
342111878SVenu.Iyer@Sun.COM case MAC_PROP_EN_100FDX_CAP:
342211878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
342311878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
342411878SVenu.Iyer@Sun.COM } else {
342511878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
342611878SVenu.Iyer@Sun.COM ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
342711878SVenu.Iyer@Sun.COM (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
342811878SVenu.Iyer@Sun.COM ? 1 : 0);
342911878SVenu.Iyer@Sun.COM }
343011878SVenu.Iyer@Sun.COM break;
343111878SVenu.Iyer@Sun.COM
343211878SVenu.Iyer@Sun.COM case MAC_PROP_EN_100HDX_CAP:
343311878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
343411878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
343511878SVenu.Iyer@Sun.COM } else {
343611878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
343711878SVenu.Iyer@Sun.COM ((Adapter->phy_status & MII_SR_100X_HD_CAPS) ||
343811878SVenu.Iyer@Sun.COM (Adapter->phy_status & MII_SR_100T2_HD_CAPS))
343911878SVenu.Iyer@Sun.COM ? 1 : 0);
344011878SVenu.Iyer@Sun.COM }
344111878SVenu.Iyer@Sun.COM break;
344211878SVenu.Iyer@Sun.COM
344311878SVenu.Iyer@Sun.COM case MAC_PROP_EN_10FDX_CAP:
344411878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
344511878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
344611878SVenu.Iyer@Sun.COM } else {
344711878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
344811878SVenu.Iyer@Sun.COM (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0);
344911878SVenu.Iyer@Sun.COM }
345011878SVenu.Iyer@Sun.COM break;
345111878SVenu.Iyer@Sun.COM
345211878SVenu.Iyer@Sun.COM case MAC_PROP_EN_10HDX_CAP:
345311878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
345411878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
345511878SVenu.Iyer@Sun.COM } else {
345611878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
345711878SVenu.Iyer@Sun.COM (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0);
345811878SVenu.Iyer@Sun.COM }
345911878SVenu.Iyer@Sun.COM break;
346011878SVenu.Iyer@Sun.COM
346111878SVenu.Iyer@Sun.COM case MAC_PROP_EN_1000HDX_CAP:
346211878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper)
346311878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
346411878SVenu.Iyer@Sun.COM break;
346511878SVenu.Iyer@Sun.COM
346611878SVenu.Iyer@Sun.COM case MAC_PROP_AUTONEG:
346711878SVenu.Iyer@Sun.COM if (hw->phy.media_type != e1000_media_type_copper) {
346811878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
346911878SVenu.Iyer@Sun.COM } else {
347011878SVenu.Iyer@Sun.COM mac_prop_info_set_default_uint8(prh,
347111878SVenu.Iyer@Sun.COM (Adapter->phy_status & MII_SR_AUTONEG_CAPS)
347211878SVenu.Iyer@Sun.COM ? 1 : 0);
347311878SVenu.Iyer@Sun.COM }
347411878SVenu.Iyer@Sun.COM break;
347511878SVenu.Iyer@Sun.COM
347611878SVenu.Iyer@Sun.COM case MAC_PROP_FLOWCTRL:
347711878SVenu.Iyer@Sun.COM mac_prop_info_set_default_link_flowctrl(prh, LINK_FLOWCTRL_BI);
347811878SVenu.Iyer@Sun.COM break;
347911878SVenu.Iyer@Sun.COM
348011878SVenu.Iyer@Sun.COM case MAC_PROP_MTU: {
348111878SVenu.Iyer@Sun.COM struct e1000_mac_info *mac = &Adapter->shared.mac;
348211878SVenu.Iyer@Sun.COM struct e1000_phy_info *phy = &Adapter->shared.phy;
348311878SVenu.Iyer@Sun.COM uint32_t max;
348411878SVenu.Iyer@Sun.COM
348511878SVenu.Iyer@Sun.COM /* some MAC types do not support jumbo frames */
348611878SVenu.Iyer@Sun.COM if ((mac->type == e1000_ich8lan) ||
348711878SVenu.Iyer@Sun.COM ((mac->type == e1000_ich9lan) && (phy->type ==
348811878SVenu.Iyer@Sun.COM e1000_phy_ife))) {
348911878SVenu.Iyer@Sun.COM max = DEFAULT_MTU;
349011878SVenu.Iyer@Sun.COM } else {
349111878SVenu.Iyer@Sun.COM max = Adapter->max_mtu;
349211878SVenu.Iyer@Sun.COM }
349311878SVenu.Iyer@Sun.COM
349411878SVenu.Iyer@Sun.COM mac_prop_info_set_range_uint32(prh, DEFAULT_MTU, max);
349511878SVenu.Iyer@Sun.COM break;
349611878SVenu.Iyer@Sun.COM }
349711878SVenu.Iyer@Sun.COM case MAC_PROP_PRIVATE: {
349811878SVenu.Iyer@Sun.COM char valstr[64];
349911878SVenu.Iyer@Sun.COM int value;
350011878SVenu.Iyer@Sun.COM
350111878SVenu.Iyer@Sun.COM if (strcmp(pr_name, "_adv_pause_cap") == 0 ||
350211878SVenu.Iyer@Sun.COM strcmp(pr_name, "_adv_asym_pause_cap") == 0) {
350311878SVenu.Iyer@Sun.COM mac_prop_info_set_perm(prh, MAC_PROP_PERM_READ);
350411878SVenu.Iyer@Sun.COM return;
350511878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) {
350611878SVenu.Iyer@Sun.COM value = DEFAULT_TX_BCOPY_THRESHOLD;
350711878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_tx_interrupt_enable") == 0) {
350811878SVenu.Iyer@Sun.COM value = DEFAULT_TX_INTR_ENABLE;
350911878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_tx_intr_delay") == 0) {
351011878SVenu.Iyer@Sun.COM value = DEFAULT_TX_INTR_DELAY;
351111878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) {
351211878SVenu.Iyer@Sun.COM value = DEFAULT_TX_INTR_ABS_DELAY;
351311878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) {
351411878SVenu.Iyer@Sun.COM value = DEFAULT_RX_BCOPY_THRESHOLD;
351511878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_max_num_rcv_packets") == 0) {
351611878SVenu.Iyer@Sun.COM value = DEFAULT_RX_LIMIT_ON_INTR;
351711878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_rx_intr_delay") == 0) {
351811878SVenu.Iyer@Sun.COM value = DEFAULT_RX_INTR_DELAY;
351911878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) {
352011878SVenu.Iyer@Sun.COM value = DEFAULT_RX_INTR_ABS_DELAY;
352111878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_intr_throttling_rate") == 0) {
352211878SVenu.Iyer@Sun.COM value = DEFAULT_INTR_THROTTLING;
352311878SVenu.Iyer@Sun.COM } else if (strcmp(pr_name, "_intr_adaptive") == 0) {
352411878SVenu.Iyer@Sun.COM value = 1;
352511878SVenu.Iyer@Sun.COM } else {
352611878SVenu.Iyer@Sun.COM return;
352711878SVenu.Iyer@Sun.COM }
352811878SVenu.Iyer@Sun.COM
352911878SVenu.Iyer@Sun.COM (void) snprintf(valstr, sizeof (valstr), "%d", value);
353011878SVenu.Iyer@Sun.COM mac_prop_info_set_default_str(prh, valstr);
353111878SVenu.Iyer@Sun.COM break;
353211878SVenu.Iyer@Sun.COM }
353311878SVenu.Iyer@Sun.COM }
353411878SVenu.Iyer@Sun.COM }
353511878SVenu.Iyer@Sun.COM
35367426SChenliang.Xu@Sun.COM /* ARGSUSED2 */
35376394Scc210113 static int
e1000g_set_priv_prop(struct e1000g * Adapter,const char * pr_name,uint_t pr_valsize,const void * pr_val)35386394Scc210113 e1000g_set_priv_prop(struct e1000g *Adapter, const char *pr_name,
35396394Scc210113 uint_t pr_valsize, const void *pr_val)
35406394Scc210113 {
35416394Scc210113 int err = 0;
35426394Scc210113 long result;
35436394Scc210113 struct e1000_hw *hw = &Adapter->shared;
35446394Scc210113
35456394Scc210113 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) {
35466394Scc210113 if (pr_val == NULL) {
35476394Scc210113 err = EINVAL;
35486394Scc210113 return (err);
35496394Scc210113 }
35506394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
35516394Scc210113 if (result < MIN_TX_BCOPY_THRESHOLD ||
35526394Scc210113 result > MAX_TX_BCOPY_THRESHOLD)
35536394Scc210113 err = EINVAL;
35546394Scc210113 else {
35556394Scc210113 Adapter->tx_bcopy_thresh = (uint32_t)result;
35566394Scc210113 }
35576394Scc210113 return (err);
35586394Scc210113 }
35596394Scc210113 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) {
35606394Scc210113 if (pr_val == NULL) {
35616394Scc210113 err = EINVAL;
35626394Scc210113 return (err);
35636394Scc210113 }
35646394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
35656394Scc210113 if (result < 0 || result > 1)
35666394Scc210113 err = EINVAL;
35676394Scc210113 else {
35686394Scc210113 Adapter->tx_intr_enable = (result == 1) ?
35696394Scc210113 B_TRUE: B_FALSE;
35706394Scc210113 if (Adapter->tx_intr_enable)
35716394Scc210113 e1000g_mask_tx_interrupt(Adapter);
35726394Scc210113 else
35736394Scc210113 e1000g_clear_tx_interrupt(Adapter);
35746394Scc210113 if (e1000g_check_acc_handle(
357510805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
35766394Scc210113 ddi_fm_service_impact(Adapter->dip,
35776394Scc210113 DDI_SERVICE_DEGRADED);
357810805SChangqing.Li@Sun.COM err = EIO;
357910805SChangqing.Li@Sun.COM }
35806394Scc210113 }
35816394Scc210113 return (err);
35826394Scc210113 }
35836394Scc210113 if (strcmp(pr_name, "_tx_intr_delay") == 0) {
35846394Scc210113 if (pr_val == NULL) {
35856394Scc210113 err = EINVAL;
35866394Scc210113 return (err);
35876394Scc210113 }
35886394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
35896394Scc210113 if (result < MIN_TX_INTR_DELAY ||
35906394Scc210113 result > MAX_TX_INTR_DELAY)
35916394Scc210113 err = EINVAL;
35926394Scc210113 else {
35936394Scc210113 Adapter->tx_intr_delay = (uint32_t)result;
35946394Scc210113 E1000_WRITE_REG(hw, E1000_TIDV, Adapter->tx_intr_delay);
35956394Scc210113 if (e1000g_check_acc_handle(
359610805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
35976394Scc210113 ddi_fm_service_impact(Adapter->dip,
35986394Scc210113 DDI_SERVICE_DEGRADED);
359910805SChangqing.Li@Sun.COM err = EIO;
360010805SChangqing.Li@Sun.COM }
36016394Scc210113 }
36026394Scc210113 return (err);
36036394Scc210113 }
36046394Scc210113 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) {
36056394Scc210113 if (pr_val == NULL) {
36066394Scc210113 err = EINVAL;
36076394Scc210113 return (err);
36086394Scc210113 }
36096394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
36106394Scc210113 if (result < MIN_TX_INTR_ABS_DELAY ||
36116394Scc210113 result > MAX_TX_INTR_ABS_DELAY)
36126394Scc210113 err = EINVAL;
36136394Scc210113 else {
36146394Scc210113 Adapter->tx_intr_abs_delay = (uint32_t)result;
36156394Scc210113 E1000_WRITE_REG(hw, E1000_TADV,
36166394Scc210113 Adapter->tx_intr_abs_delay);
36176394Scc210113 if (e1000g_check_acc_handle(
361810805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
36196394Scc210113 ddi_fm_service_impact(Adapter->dip,
36206394Scc210113 DDI_SERVICE_DEGRADED);
362110805SChangqing.Li@Sun.COM err = EIO;
362210805SChangqing.Li@Sun.COM }
36236394Scc210113 }
36246394Scc210113 return (err);
36256394Scc210113 }
36266394Scc210113 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) {
36276394Scc210113 if (pr_val == NULL) {
36286394Scc210113 err = EINVAL;
36296394Scc210113 return (err);
36306394Scc210113 }
36316394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
36326394Scc210113 if (result < MIN_RX_BCOPY_THRESHOLD ||
36336394Scc210113 result > MAX_RX_BCOPY_THRESHOLD)
36346394Scc210113 err = EINVAL;
36356394Scc210113 else
36366394Scc210113 Adapter->rx_bcopy_thresh = (uint32_t)result;
36376394Scc210113 return (err);
36386394Scc210113 }
36396394Scc210113 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) {
36406394Scc210113 if (pr_val == NULL) {
36416394Scc210113 err = EINVAL;
36426394Scc210113 return (err);
36436394Scc210113 }
36446394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
36456394Scc210113 if (result < MIN_RX_LIMIT_ON_INTR ||
36466394Scc210113 result > MAX_RX_LIMIT_ON_INTR)
36476394Scc210113 err = EINVAL;
36486394Scc210113 else
36496394Scc210113 Adapter->rx_limit_onintr = (uint32_t)result;
36506394Scc210113 return (err);
36516394Scc210113 }
36526394Scc210113 if (strcmp(pr_name, "_rx_intr_delay") == 0) {
36536394Scc210113 if (pr_val == NULL) {
36546394Scc210113 err = EINVAL;
36556394Scc210113 return (err);
36566394Scc210113 }
36576394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
36586394Scc210113 if (result < MIN_RX_INTR_DELAY ||
36596394Scc210113 result > MAX_RX_INTR_DELAY)
36606394Scc210113 err = EINVAL;
36616394Scc210113 else {
36626394Scc210113 Adapter->rx_intr_delay = (uint32_t)result;
36636394Scc210113 E1000_WRITE_REG(hw, E1000_RDTR, Adapter->rx_intr_delay);
36646394Scc210113 if (e1000g_check_acc_handle(
366510805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
36666394Scc210113 ddi_fm_service_impact(Adapter->dip,
36676394Scc210113 DDI_SERVICE_DEGRADED);
366810805SChangqing.Li@Sun.COM err = EIO;
366910805SChangqing.Li@Sun.COM }
36706394Scc210113 }
36716394Scc210113 return (err);
36726394Scc210113 }
36736394Scc210113 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) {
36746394Scc210113 if (pr_val == NULL) {
36756394Scc210113 err = EINVAL;
36766394Scc210113 return (err);
36776394Scc210113 }
36786394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
36796394Scc210113 if (result < MIN_RX_INTR_ABS_DELAY ||
36806394Scc210113 result > MAX_RX_INTR_ABS_DELAY)
36816394Scc210113 err = EINVAL;
36826394Scc210113 else {
36836394Scc210113 Adapter->rx_intr_abs_delay = (uint32_t)result;
36846394Scc210113 E1000_WRITE_REG(hw, E1000_RADV,
36856394Scc210113 Adapter->rx_intr_abs_delay);
36866394Scc210113 if (e1000g_check_acc_handle(
368710805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
36886394Scc210113 ddi_fm_service_impact(Adapter->dip,
36896394Scc210113 DDI_SERVICE_DEGRADED);
369010805SChangqing.Li@Sun.COM err = EIO;
369110805SChangqing.Li@Sun.COM }
36926394Scc210113 }
36936394Scc210113 return (err);
36946394Scc210113 }
36956394Scc210113 if (strcmp(pr_name, "_intr_throttling_rate") == 0) {
36966394Scc210113 if (pr_val == NULL) {
36976394Scc210113 err = EINVAL;
36986394Scc210113 return (err);
36996394Scc210113 }
37006394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
37016394Scc210113 if (result < MIN_INTR_THROTTLING ||
37026394Scc210113 result > MAX_INTR_THROTTLING)
37036394Scc210113 err = EINVAL;
37046394Scc210113 else {
37056394Scc210113 if (hw->mac.type >= e1000_82540) {
37066394Scc210113 Adapter->intr_throttling_rate =
37076394Scc210113 (uint32_t)result;
37086394Scc210113 E1000_WRITE_REG(hw, E1000_ITR,
37096394Scc210113 Adapter->intr_throttling_rate);
37106394Scc210113 if (e1000g_check_acc_handle(
371110805SChangqing.Li@Sun.COM Adapter->osdep.reg_handle) != DDI_FM_OK) {
37126394Scc210113 ddi_fm_service_impact(Adapter->dip,
37136394Scc210113 DDI_SERVICE_DEGRADED);
371410805SChangqing.Li@Sun.COM err = EIO;
371510805SChangqing.Li@Sun.COM }
37166394Scc210113 } else
37176394Scc210113 err = EINVAL;
37186394Scc210113 }
37196394Scc210113 return (err);
37206394Scc210113 }
37216394Scc210113 if (strcmp(pr_name, "_intr_adaptive") == 0) {
37226394Scc210113 if (pr_val == NULL) {
37236394Scc210113 err = EINVAL;
37246394Scc210113 return (err);
37256394Scc210113 }
37266394Scc210113 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result);
37276394Scc210113 if (result < 0 || result > 1)
37286394Scc210113 err = EINVAL;
37296394Scc210113 else {
37306394Scc210113 if (hw->mac.type >= e1000_82540) {
37316394Scc210113 Adapter->intr_adaptive = (result == 1) ?
37326394Scc210113 B_TRUE : B_FALSE;
37336394Scc210113 } else {
37346394Scc210113 err = EINVAL;
37356394Scc210113 }
37366394Scc210113 }
37376394Scc210113 return (err);
37386394Scc210113 }
37396394Scc210113 return (ENOTSUP);
37406394Scc210113 }
37416394Scc210113
37426394Scc210113 static int
e1000g_get_priv_prop(struct e1000g * Adapter,const char * pr_name,uint_t pr_valsize,void * pr_val)37436394Scc210113 e1000g_get_priv_prop(struct e1000g *Adapter, const char *pr_name,
374411878SVenu.Iyer@Sun.COM uint_t pr_valsize, void *pr_val)
37456394Scc210113 {
37466394Scc210113 int err = ENOTSUP;
37476512Ssowmini int value;
37486512Ssowmini
37496512Ssowmini if (strcmp(pr_name, "_adv_pause_cap") == 0) {
37506512Ssowmini value = Adapter->param_adv_pause;
37516512Ssowmini err = 0;
37526512Ssowmini goto done;
37536512Ssowmini }
37546512Ssowmini if (strcmp(pr_name, "_adv_asym_pause_cap") == 0) {
37556512Ssowmini value = Adapter->param_adv_asym_pause;
37566512Ssowmini err = 0;
37576512Ssowmini goto done;
37586512Ssowmini }
37596394Scc210113 if (strcmp(pr_name, "_tx_bcopy_threshold") == 0) {
376011878SVenu.Iyer@Sun.COM value = Adapter->tx_bcopy_thresh;
37616394Scc210113 err = 0;
37626394Scc210113 goto done;
37636394Scc210113 }
37646394Scc210113 if (strcmp(pr_name, "_tx_interrupt_enable") == 0) {
376511878SVenu.Iyer@Sun.COM value = Adapter->tx_intr_enable;
37666394Scc210113 err = 0;
37676394Scc210113 goto done;
37686394Scc210113 }
37696394Scc210113 if (strcmp(pr_name, "_tx_intr_delay") == 0) {
377011878SVenu.Iyer@Sun.COM value = Adapter->tx_intr_delay;
37716394Scc210113 err = 0;
37726394Scc210113 goto done;
37736394Scc210113 }
37746394Scc210113 if (strcmp(pr_name, "_tx_intr_abs_delay") == 0) {
377511878SVenu.Iyer@Sun.COM value = Adapter->tx_intr_abs_delay;
37766394Scc210113 err = 0;
37776394Scc210113 goto done;
37786394Scc210113 }
37796394Scc210113 if (strcmp(pr_name, "_rx_bcopy_threshold") == 0) {
378011878SVenu.Iyer@Sun.COM value = Adapter->rx_bcopy_thresh;
37816394Scc210113 err = 0;
37826394Scc210113 goto done;
37836394Scc210113 }
37846394Scc210113 if (strcmp(pr_name, "_max_num_rcv_packets") == 0) {
378511878SVenu.Iyer@Sun.COM value = Adapter->rx_limit_onintr;
37866394Scc210113 err = 0;
37876394Scc210113 goto done;
37886394Scc210113 }
37896394Scc210113 if (strcmp(pr_name, "_rx_intr_delay") == 0) {
379011878SVenu.Iyer@Sun.COM value = Adapter->rx_intr_delay;
37916394Scc210113 err = 0;
37926394Scc210113 goto done;
37936394Scc210113 }
37946394Scc210113 if (strcmp(pr_name, "_rx_intr_abs_delay") == 0) {
379511878SVenu.Iyer@Sun.COM value = Adapter->rx_intr_abs_delay;
37966394Scc210113 err = 0;
37976394Scc210113 goto done;
37986394Scc210113 }
37996394Scc210113 if (strcmp(pr_name, "_intr_throttling_rate") == 0) {
380011878SVenu.Iyer@Sun.COM value = Adapter->intr_throttling_rate;
38016394Scc210113 err = 0;
38026394Scc210113 goto done;
38036394Scc210113 }
38046394Scc210113 if (strcmp(pr_name, "_intr_adaptive") == 0) {
380511878SVenu.Iyer@Sun.COM value = Adapter->intr_adaptive;
38066394Scc210113 err = 0;
38076394Scc210113 goto done;
38086394Scc210113 }
38096394Scc210113 done:
38106394Scc210113 if (err == 0) {
38116512Ssowmini (void) snprintf(pr_val, pr_valsize, "%d", value);
38126394Scc210113 }
38136394Scc210113 return (err);
38146394Scc210113 }
38156394Scc210113
38163526Sxy150489 /*
38174919Sxy150489 * e1000g_get_conf - get configurations set in e1000g.conf
38184919Sxy150489 * This routine gets user-configured values out of the configuration
38194919Sxy150489 * file e1000g.conf.
38204919Sxy150489 *
38214919Sxy150489 * For each configurable value, there is a minimum, a maximum, and a
38224919Sxy150489 * default.
38234919Sxy150489 * If user does not configure a value, use the default.
38244919Sxy150489 * If user configures below the minimum, use the minumum.
38254919Sxy150489 * If user configures above the maximum, use the maxumum.
38263526Sxy150489 */
38273526Sxy150489 static void
e1000g_get_conf(struct e1000g * Adapter)38284919Sxy150489 e1000g_get_conf(struct e1000g *Adapter)
38293526Sxy150489 {
38304919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
38314919Sxy150489 boolean_t tbi_compatibility = B_FALSE;
383211339SGuoqing.Zhu@Sun.COM boolean_t is_jumbo = B_FALSE;
383311339SGuoqing.Zhu@Sun.COM int propval;
383411339SGuoqing.Zhu@Sun.COM /*
383511339SGuoqing.Zhu@Sun.COM * decrease the number of descriptors and free packets
383611339SGuoqing.Zhu@Sun.COM * for jumbo frames to reduce tx/rx resource consumption
383711339SGuoqing.Zhu@Sun.COM */
3838*12853SChangqing.Li@Sun.COM if (Adapter->max_frame_size >= FRAME_SIZE_UPTO_4K) {
383911339SGuoqing.Zhu@Sun.COM is_jumbo = B_TRUE;
384011339SGuoqing.Zhu@Sun.COM }
38414919Sxy150489
38423526Sxy150489 /*
38433526Sxy150489 * get each configurable property from e1000g.conf
38443526Sxy150489 */
38453526Sxy150489
38463526Sxy150489 /*
38473526Sxy150489 * NumTxDescriptors
38483526Sxy150489 */
384911339SGuoqing.Zhu@Sun.COM Adapter->tx_desc_num_flag =
38504919Sxy150489 e1000g_get_prop(Adapter, "NumTxDescriptors",
38514919Sxy150489 MIN_NUM_TX_DESCRIPTOR, MAX_NUM_TX_DESCRIPTOR,
385211339SGuoqing.Zhu@Sun.COM is_jumbo ? DEFAULT_JUMBO_NUM_TX_DESC
385311339SGuoqing.Zhu@Sun.COM : DEFAULT_NUM_TX_DESCRIPTOR, &propval);
385411339SGuoqing.Zhu@Sun.COM Adapter->tx_desc_num = propval;
38553526Sxy150489
38563526Sxy150489 /*
38573526Sxy150489 * NumRxDescriptors
38583526Sxy150489 */
385911339SGuoqing.Zhu@Sun.COM Adapter->rx_desc_num_flag =
38604919Sxy150489 e1000g_get_prop(Adapter, "NumRxDescriptors",
38614919Sxy150489 MIN_NUM_RX_DESCRIPTOR, MAX_NUM_RX_DESCRIPTOR,
386211339SGuoqing.Zhu@Sun.COM is_jumbo ? DEFAULT_JUMBO_NUM_RX_DESC
386311339SGuoqing.Zhu@Sun.COM : DEFAULT_NUM_RX_DESCRIPTOR, &propval);
386411339SGuoqing.Zhu@Sun.COM Adapter->rx_desc_num = propval;
38653526Sxy150489
38663526Sxy150489 /*
38673526Sxy150489 * NumRxFreeList
38683526Sxy150489 */
386911339SGuoqing.Zhu@Sun.COM Adapter->rx_buf_num_flag =
38704919Sxy150489 e1000g_get_prop(Adapter, "NumRxFreeList",
38714919Sxy150489 MIN_NUM_RX_FREELIST, MAX_NUM_RX_FREELIST,
387211339SGuoqing.Zhu@Sun.COM is_jumbo ? DEFAULT_JUMBO_NUM_RX_BUF
387311339SGuoqing.Zhu@Sun.COM : DEFAULT_NUM_RX_FREELIST, &propval);
3874*12853SChangqing.Li@Sun.COM Adapter->rx_freelist_limit = propval;
38753526Sxy150489
38763526Sxy150489 /*
38773526Sxy150489 * NumTxPacketList
38783526Sxy150489 */
387911339SGuoqing.Zhu@Sun.COM Adapter->tx_buf_num_flag =
38804919Sxy150489 e1000g_get_prop(Adapter, "NumTxPacketList",
38814919Sxy150489 MIN_NUM_TX_FREELIST, MAX_NUM_TX_FREELIST,
388211339SGuoqing.Zhu@Sun.COM is_jumbo ? DEFAULT_JUMBO_NUM_TX_BUF
388311339SGuoqing.Zhu@Sun.COM : DEFAULT_NUM_TX_FREELIST, &propval);
388411339SGuoqing.Zhu@Sun.COM Adapter->tx_freelist_num = propval;
38853526Sxy150489
38863526Sxy150489 /*
38873526Sxy150489 * FlowControl
38883526Sxy150489 */
38896735Scc210113 hw->fc.send_xon = B_TRUE;
389011339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "FlowControl",
389111339SGuoqing.Zhu@Sun.COM e1000_fc_none, 4, DEFAULT_FLOW_CONTROL, &propval);
389211339SGuoqing.Zhu@Sun.COM hw->fc.requested_mode = propval;
38933526Sxy150489 /* 4 is the setting that says "let the eeprom decide" */
38948539SChenlu.Chen@Sun.COM if (hw->fc.requested_mode == 4)
38958539SChenlu.Chen@Sun.COM hw->fc.requested_mode = e1000_fc_default;
38963526Sxy150489
38973526Sxy150489 /*
38984919Sxy150489 * Max Num Receive Packets on Interrupt
38993526Sxy150489 */
390011339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "MaxNumReceivePackets",
39014919Sxy150489 MIN_RX_LIMIT_ON_INTR, MAX_RX_LIMIT_ON_INTR,
390211339SGuoqing.Zhu@Sun.COM DEFAULT_RX_LIMIT_ON_INTR, &propval);
390311339SGuoqing.Zhu@Sun.COM Adapter->rx_limit_onintr = propval;
39043526Sxy150489
39053526Sxy150489 /*
39063526Sxy150489 * PHY master slave setting
39073526Sxy150489 */
390811339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "SetMasterSlave",
39093526Sxy150489 e1000_ms_hw_default, e1000_ms_auto,
391011339SGuoqing.Zhu@Sun.COM e1000_ms_hw_default, &propval);
391111339SGuoqing.Zhu@Sun.COM hw->phy.ms_type = propval;
39123526Sxy150489
39133526Sxy150489 /*
39143526Sxy150489 * Parameter which controls TBI mode workaround, which is only
39153526Sxy150489 * needed on certain switches such as Cisco 6500/Foundry
39163526Sxy150489 */
391711339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "TbiCompatibilityEnable",
391811339SGuoqing.Zhu@Sun.COM 0, 1, DEFAULT_TBI_COMPAT_ENABLE, &propval);
391911339SGuoqing.Zhu@Sun.COM tbi_compatibility = (propval == 1);
39204919Sxy150489 e1000_set_tbi_compatibility_82543(hw, tbi_compatibility);
39213526Sxy150489
39223526Sxy150489 /*
39233526Sxy150489 * MSI Enable
39243526Sxy150489 */
392511339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "MSIEnable",
392611339SGuoqing.Zhu@Sun.COM 0, 1, DEFAULT_MSI_ENABLE, &propval);
392711339SGuoqing.Zhu@Sun.COM Adapter->msi_enable = (propval == 1);
39283526Sxy150489
39293526Sxy150489 /*
39303526Sxy150489 * Interrupt Throttling Rate
39313526Sxy150489 */
393211339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "intr_throttling_rate",
39334919Sxy150489 MIN_INTR_THROTTLING, MAX_INTR_THROTTLING,
393411339SGuoqing.Zhu@Sun.COM DEFAULT_INTR_THROTTLING, &propval);
393511339SGuoqing.Zhu@Sun.COM Adapter->intr_throttling_rate = propval;
39363526Sxy150489
39373526Sxy150489 /*
39383526Sxy150489 * Adaptive Interrupt Blanking Enable/Disable
39393526Sxy150489 * It is enabled by default
39403526Sxy150489 */
394111339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "intr_adaptive", 0, 1, 1,
394211339SGuoqing.Zhu@Sun.COM &propval);
394311339SGuoqing.Zhu@Sun.COM Adapter->intr_adaptive = (propval == 1);
39445882Syy150190
39455882Syy150190 /*
39466011Ssv141092 * Hardware checksum enable/disable parameter
39476011Ssv141092 */
394811339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "tx_hcksum_enable",
394911339SGuoqing.Zhu@Sun.COM 0, 1, DEFAULT_TX_HCKSUM_ENABLE, &propval);
395011339SGuoqing.Zhu@Sun.COM Adapter->tx_hcksum_enable = (propval == 1);
39516986Smx205022 /*
39526986Smx205022 * Checksum on/off selection via global parameters.
39536986Smx205022 *
39546986Smx205022 * If the chip is flagged as not capable of (correctly)
39556986Smx205022 * handling checksumming, we don't enable it on either
39566986Smx205022 * Rx or Tx side. Otherwise, we take this chip's settings
39576986Smx205022 * from the patchable global defaults.
39586986Smx205022 *
39596986Smx205022 * We advertise our capabilities only if TX offload is
39606986Smx205022 * enabled. On receive, the stack will accept checksummed
39616986Smx205022 * packets anyway, even if we haven't said we can deliver
39626986Smx205022 * them.
39636986Smx205022 */
39646986Smx205022 switch (hw->mac.type) {
39656986Smx205022 case e1000_82540:
39666986Smx205022 case e1000_82544:
39676986Smx205022 case e1000_82545:
39686986Smx205022 case e1000_82545_rev_3:
39696986Smx205022 case e1000_82546:
39706986Smx205022 case e1000_82546_rev_3:
39716986Smx205022 case e1000_82571:
39726986Smx205022 case e1000_82572:
39736986Smx205022 case e1000_82573:
39746986Smx205022 case e1000_80003es2lan:
39756986Smx205022 break;
39766986Smx205022 /*
39776986Smx205022 * For the following Intel PRO/1000 chipsets, we have not
39786986Smx205022 * tested the hardware checksum offload capability, so we
39796986Smx205022 * disable the capability for them.
39806986Smx205022 * e1000_82542,
39816986Smx205022 * e1000_82543,
39826986Smx205022 * e1000_82541,
39836986Smx205022 * e1000_82541_rev_2,
39846986Smx205022 * e1000_82547,
39856986Smx205022 * e1000_82547_rev_2,
39866986Smx205022 */
39876986Smx205022 default:
39886986Smx205022 Adapter->tx_hcksum_enable = B_FALSE;
39896986Smx205022 }
39906986Smx205022
39916986Smx205022 /*
39926986Smx205022 * Large Send Offloading(LSO) Enable/Disable
39936986Smx205022 * If the tx hardware checksum is not enabled, LSO should be
39946986Smx205022 * disabled.
39956986Smx205022 */
399611339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "lso_enable",
399711339SGuoqing.Zhu@Sun.COM 0, 1, DEFAULT_LSO_ENABLE, &propval);
399811339SGuoqing.Zhu@Sun.COM Adapter->lso_enable = (propval == 1);
39996986Smx205022
40006986Smx205022 switch (hw->mac.type) {
40016986Smx205022 case e1000_82546:
40026986Smx205022 case e1000_82546_rev_3:
40036986Smx205022 if (Adapter->lso_enable)
40046986Smx205022 Adapter->lso_premature_issue = B_TRUE;
40057426SChenliang.Xu@Sun.COM /* FALLTHRU */
40066986Smx205022 case e1000_82571:
40076986Smx205022 case e1000_82572:
40086986Smx205022 case e1000_82573:
40098073SMin.Xu@Sun.COM case e1000_80003es2lan:
40106986Smx205022 break;
40116986Smx205022 default:
40126986Smx205022 Adapter->lso_enable = B_FALSE;
40136986Smx205022 }
40146986Smx205022
40156986Smx205022 if (!Adapter->tx_hcksum_enable) {
40166986Smx205022 Adapter->lso_premature_issue = B_FALSE;
40176986Smx205022 Adapter->lso_enable = B_FALSE;
40186986Smx205022 }
40198417SChenlu.Chen@Sun.COM
40208417SChenlu.Chen@Sun.COM /*
40218417SChenlu.Chen@Sun.COM * If mem_workaround_82546 is enabled, the rx buffer allocated by
40228417SChenlu.Chen@Sun.COM * e1000_82545, e1000_82546 and e1000_82546_rev_3
40238417SChenlu.Chen@Sun.COM * will not cross 64k boundary.
40248417SChenlu.Chen@Sun.COM */
402511339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "mem_workaround_82546",
402611339SGuoqing.Zhu@Sun.COM 0, 1, DEFAULT_MEM_WORKAROUND_82546, &propval);
402711339SGuoqing.Zhu@Sun.COM Adapter->mem_workaround_82546 = (propval == 1);
40289770SChangqing.Li@Sun.COM
40299770SChangqing.Li@Sun.COM /*
40309770SChangqing.Li@Sun.COM * Max number of multicast addresses
40319770SChangqing.Li@Sun.COM */
403211339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "mcast_max_num",
403311339SGuoqing.Zhu@Sun.COM MIN_MCAST_NUM, MAX_MCAST_NUM, hw->mac.mta_reg_count * 32,
403411339SGuoqing.Zhu@Sun.COM &propval);
403511339SGuoqing.Zhu@Sun.COM Adapter->mcast_max_num = propval;
40363526Sxy150489 }
40373526Sxy150489
40383526Sxy150489 /*
40394919Sxy150489 * e1000g_get_prop - routine to read properties
40404919Sxy150489 *
40414919Sxy150489 * Get a user-configure property value out of the configuration
40424919Sxy150489 * file e1000g.conf.
40434919Sxy150489 *
40444919Sxy150489 * Caller provides name of the property, a default value, a minimum
404511339SGuoqing.Zhu@Sun.COM * value, a maximum value and a pointer to the returned property
404611339SGuoqing.Zhu@Sun.COM * value.
40474919Sxy150489 *
404811339SGuoqing.Zhu@Sun.COM * Return B_TRUE if the configured value of the property is not a default
404911339SGuoqing.Zhu@Sun.COM * value, otherwise return B_FALSE.
40503526Sxy150489 */
405111339SGuoqing.Zhu@Sun.COM static boolean_t
e1000g_get_prop(struct e1000g * Adapter,char * propname,int minval,int maxval,int defval,int * propvalue)40524919Sxy150489 e1000g_get_prop(struct e1000g *Adapter, /* point to per-adapter structure */
40533526Sxy150489 char *propname, /* name of the property */
40543526Sxy150489 int minval, /* minimum acceptable value */
40553526Sxy150489 int maxval, /* maximim acceptable value */
405611339SGuoqing.Zhu@Sun.COM int defval, /* default value */
405711339SGuoqing.Zhu@Sun.COM int *propvalue) /* property value return to caller */
40583526Sxy150489 {
40593526Sxy150489 int propval; /* value returned for requested property */
40603526Sxy150489 int *props; /* point to array of properties returned */
40613526Sxy150489 uint_t nprops; /* number of property value returned */
406211339SGuoqing.Zhu@Sun.COM boolean_t ret = B_TRUE;
40633526Sxy150489
40643526Sxy150489 /*
40653526Sxy150489 * get the array of properties from the config file
40663526Sxy150489 */
40673526Sxy150489 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, Adapter->dip,
40683526Sxy150489 DDI_PROP_DONTPASS, propname, &props, &nprops) == DDI_PROP_SUCCESS) {
40693526Sxy150489 /* got some properties, test if we got enough */
40704919Sxy150489 if (Adapter->instance < nprops) {
40714919Sxy150489 propval = props[Adapter->instance];
40723526Sxy150489 } else {
40733526Sxy150489 /* not enough properties configured */
40743526Sxy150489 propval = defval;
40754919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
40763526Sxy150489 "Not Enough %s values found in e1000g.conf"
40773526Sxy150489 " - set to %d\n",
40783526Sxy150489 propname, propval);
407911339SGuoqing.Zhu@Sun.COM ret = B_FALSE;
40803526Sxy150489 }
40813526Sxy150489
40823526Sxy150489 /* free memory allocated for properties */
40833526Sxy150489 ddi_prop_free(props);
40843526Sxy150489
40853526Sxy150489 } else {
40863526Sxy150489 propval = defval;
408711339SGuoqing.Zhu@Sun.COM ret = B_FALSE;
40883526Sxy150489 }
40893526Sxy150489
40903526Sxy150489 /*
40913526Sxy150489 * enforce limits
40923526Sxy150489 */
40933526Sxy150489 if (propval > maxval) {
40943526Sxy150489 propval = maxval;
40954919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
40963526Sxy150489 "Too High %s value in e1000g.conf - set to %d\n",
40973526Sxy150489 propname, propval);
40983526Sxy150489 }
40993526Sxy150489
41003526Sxy150489 if (propval < minval) {
41013526Sxy150489 propval = minval;
41024919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_INFO_LEVEL,
41033526Sxy150489 "Too Low %s value in e1000g.conf - set to %d\n",
41043526Sxy150489 propname, propval);
41053526Sxy150489 }
41063526Sxy150489
410711339SGuoqing.Zhu@Sun.COM *propvalue = propval;
410811339SGuoqing.Zhu@Sun.COM return (ret);
41093526Sxy150489 }
41103526Sxy150489
41113526Sxy150489 static boolean_t
e1000g_link_check(struct e1000g * Adapter)41124061Sxy150489 e1000g_link_check(struct e1000g *Adapter)
41133526Sxy150489 {
41144061Sxy150489 uint16_t speed, duplex, phydata;
41154061Sxy150489 boolean_t link_changed = B_FALSE;
41163526Sxy150489 struct e1000_hw *hw;
41173526Sxy150489 uint32_t reg_tarc;
41183526Sxy150489
41194919Sxy150489 hw = &Adapter->shared;
41203526Sxy150489
41213526Sxy150489 if (e1000g_link_up(Adapter)) {
41223526Sxy150489 /*
41233526Sxy150489 * The Link is up, check whether it was marked as down earlier
41243526Sxy150489 */
41254061Sxy150489 if (Adapter->link_state != LINK_STATE_UP) {
41267426SChenliang.Xu@Sun.COM (void) e1000_get_speed_and_duplex(hw, &speed, &duplex);
41274061Sxy150489 Adapter->link_speed = speed;
41284061Sxy150489 Adapter->link_duplex = duplex;
41294061Sxy150489 Adapter->link_state = LINK_STATE_UP;
41304061Sxy150489 link_changed = B_TRUE;
41314061Sxy150489
41328850SMin.Xu@Sun.COM if (Adapter->link_speed == SPEED_1000)
41338850SMin.Xu@Sun.COM Adapter->stall_threshold = TX_STALL_TIME_2S;
41348850SMin.Xu@Sun.COM else
41358850SMin.Xu@Sun.COM Adapter->stall_threshold = TX_STALL_TIME_8S;
41368850SMin.Xu@Sun.COM
41374061Sxy150489 Adapter->tx_link_down_timeout = 0;
41384061Sxy150489
41394919Sxy150489 if ((hw->mac.type == e1000_82571) ||
41404919Sxy150489 (hw->mac.type == e1000_82572)) {
41416735Scc210113 reg_tarc = E1000_READ_REG(hw, E1000_TARC(0));
41424061Sxy150489 if (speed == SPEED_1000)
41434061Sxy150489 reg_tarc |= (1 << 21);
41444061Sxy150489 else
41454061Sxy150489 reg_tarc &= ~(1 << 21);
41466735Scc210113 E1000_WRITE_REG(hw, E1000_TARC(0), reg_tarc);
41473526Sxy150489 }
41483526Sxy150489 }
41493526Sxy150489 Adapter->smartspeed = 0;
41503526Sxy150489 } else {
41514061Sxy150489 if (Adapter->link_state != LINK_STATE_DOWN) {
41523526Sxy150489 Adapter->link_speed = 0;
41533526Sxy150489 Adapter->link_duplex = 0;
41544061Sxy150489 Adapter->link_state = LINK_STATE_DOWN;
41554061Sxy150489 link_changed = B_TRUE;
41564061Sxy150489
41573526Sxy150489 /*
41583526Sxy150489 * SmartSpeed workaround for Tabor/TanaX, When the
41593526Sxy150489 * driver loses link disable auto master/slave
41603526Sxy150489 * resolution.
41613526Sxy150489 */
41624919Sxy150489 if (hw->phy.type == e1000_phy_igp) {
41637426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw,
41643526Sxy150489 PHY_1000T_CTRL, &phydata);
41653526Sxy150489 phydata |= CR_1000T_MS_ENABLE;
41667426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw,
41673526Sxy150489 PHY_1000T_CTRL, phydata);
41683526Sxy150489 }
41693526Sxy150489 } else {
41703526Sxy150489 e1000g_smartspeed(Adapter);
41713526Sxy150489 }
41724061Sxy150489
41738479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_STARTED) {
41744061Sxy150489 if (Adapter->tx_link_down_timeout <
41754061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) {
41764061Sxy150489 Adapter->tx_link_down_timeout++;
41774061Sxy150489 } else if (Adapter->tx_link_down_timeout ==
41784061Sxy150489 MAX_TX_LINK_DOWN_TIMEOUT) {
41794919Sxy150489 e1000g_tx_clean(Adapter);
41804061Sxy150489 Adapter->tx_link_down_timeout++;
41814061Sxy150489 }
41824061Sxy150489 }
41833526Sxy150489 }
41843526Sxy150489
41855273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
41865273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
41875273Sgl147354
41884061Sxy150489 return (link_changed);
41894061Sxy150489 }
41904061Sxy150489
41916394Scc210113 /*
41926394Scc210113 * e1000g_reset_link - Using the link properties to setup the link
41936394Scc210113 */
41946394Scc210113 int
e1000g_reset_link(struct e1000g * Adapter)41956394Scc210113 e1000g_reset_link(struct e1000g *Adapter)
41966394Scc210113 {
41976394Scc210113 struct e1000_mac_info *mac;
41986394Scc210113 struct e1000_phy_info *phy;
419910605SMin.Xu@Sun.COM struct e1000_hw *hw;
42006394Scc210113 boolean_t invalid;
42016394Scc210113
42026394Scc210113 mac = &Adapter->shared.mac;
42036394Scc210113 phy = &Adapter->shared.phy;
420410605SMin.Xu@Sun.COM hw = &Adapter->shared;
42056394Scc210113 invalid = B_FALSE;
42066394Scc210113
420710605SMin.Xu@Sun.COM if (hw->phy.media_type != e1000_media_type_copper)
420810605SMin.Xu@Sun.COM goto out;
420910605SMin.Xu@Sun.COM
42106394Scc210113 if (Adapter->param_adv_autoneg == 1) {
42116394Scc210113 mac->autoneg = B_TRUE;
42126394Scc210113 phy->autoneg_advertised = 0;
42136394Scc210113
42146394Scc210113 /*
42156394Scc210113 * 1000hdx is not supported for autonegotiation
42166394Scc210113 */
42176394Scc210113 if (Adapter->param_adv_1000fdx == 1)
42186394Scc210113 phy->autoneg_advertised |= ADVERTISE_1000_FULL;
42196394Scc210113
42206394Scc210113 if (Adapter->param_adv_100fdx == 1)
42216394Scc210113 phy->autoneg_advertised |= ADVERTISE_100_FULL;
42226394Scc210113
42236394Scc210113 if (Adapter->param_adv_100hdx == 1)
42246394Scc210113 phy->autoneg_advertised |= ADVERTISE_100_HALF;
42256394Scc210113
42266394Scc210113 if (Adapter->param_adv_10fdx == 1)
42276394Scc210113 phy->autoneg_advertised |= ADVERTISE_10_FULL;
42286394Scc210113
42296394Scc210113 if (Adapter->param_adv_10hdx == 1)
42306394Scc210113 phy->autoneg_advertised |= ADVERTISE_10_HALF;
42316394Scc210113
42326394Scc210113 if (phy->autoneg_advertised == 0)
42336394Scc210113 invalid = B_TRUE;
42346394Scc210113 } else {
42356394Scc210113 mac->autoneg = B_FALSE;
42366394Scc210113
42376394Scc210113 /*
423810605SMin.Xu@Sun.COM * For Intel copper cards, 1000fdx and 1000hdx are not
423910605SMin.Xu@Sun.COM * supported for forced link
42406394Scc210113 */
42416394Scc210113 if (Adapter->param_adv_100fdx == 1)
42426394Scc210113 mac->forced_speed_duplex = ADVERTISE_100_FULL;
42436394Scc210113 else if (Adapter->param_adv_100hdx == 1)
42446394Scc210113 mac->forced_speed_duplex = ADVERTISE_100_HALF;
42456394Scc210113 else if (Adapter->param_adv_10fdx == 1)
42466394Scc210113 mac->forced_speed_duplex = ADVERTISE_10_FULL;
42476394Scc210113 else if (Adapter->param_adv_10hdx == 1)
42486394Scc210113 mac->forced_speed_duplex = ADVERTISE_10_HALF;
42496394Scc210113 else
42506394Scc210113 invalid = B_TRUE;
42516394Scc210113
42526394Scc210113 }
42536394Scc210113
42546394Scc210113 if (invalid) {
42556394Scc210113 e1000g_log(Adapter, CE_WARN,
425610680SMin.Xu@Sun.COM "Invalid link settings. Setup link to "
42576394Scc210113 "support autonegotiation with all link capabilities.");
42586394Scc210113 mac->autoneg = B_TRUE;
425910680SMin.Xu@Sun.COM phy->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
42606394Scc210113 }
42616394Scc210113
426210605SMin.Xu@Sun.COM out:
42636394Scc210113 return (e1000_setup_link(&Adapter->shared));
42646394Scc210113 }
42656394Scc210113
42664061Sxy150489 static void
e1000g_timer_tx_resched(struct e1000g * Adapter)42678275SEric Cheng e1000g_timer_tx_resched(struct e1000g *Adapter)
42688275SEric Cheng {
42698275SEric Cheng e1000g_tx_ring_t *tx_ring = Adapter->tx_ring;
42708275SEric Cheng
42718479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_READER);
42728479SChenlu.Chen@Sun.COM
42738275SEric Cheng if (tx_ring->resched_needed &&
42748275SEric Cheng ((ddi_get_lbolt() - tx_ring->resched_timestamp) >
42758275SEric Cheng drv_usectohz(1000000)) &&
42768479SChenlu.Chen@Sun.COM (Adapter->e1000g_state & E1000G_STARTED) &&
42778275SEric Cheng (tx_ring->tbd_avail >= DEFAULT_TX_NO_RESOURCE)) {
42788275SEric Cheng tx_ring->resched_needed = B_FALSE;
42798275SEric Cheng mac_tx_update(Adapter->mh);
42808275SEric Cheng E1000G_STAT(tx_ring->stat_reschedule);
42818275SEric Cheng E1000G_STAT(tx_ring->stat_timer_reschedule);
42828275SEric Cheng }
42838479SChenlu.Chen@Sun.COM
42848479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
42858275SEric Cheng }
42868275SEric Cheng
42878275SEric Cheng static void
e1000g_local_timer(void * ws)42884919Sxy150489 e1000g_local_timer(void *ws)
42894061Sxy150489 {
42904061Sxy150489 struct e1000g *Adapter = (struct e1000g *)ws;
42914061Sxy150489 struct e1000_hw *hw;
42924061Sxy150489 e1000g_ether_addr_t ether_addr;
42934061Sxy150489 boolean_t link_changed;
42944061Sxy150489
42954919Sxy150489 hw = &Adapter->shared;
42964919Sxy150489
42978479SChenlu.Chen@Sun.COM if (Adapter->e1000g_state & E1000G_ERROR) {
42988479SChenlu.Chen@Sun.COM rw_enter(&Adapter->chip_lock, RW_WRITER);
42998479SChenlu.Chen@Sun.COM Adapter->e1000g_state &= ~E1000G_ERROR;
43008479SChenlu.Chen@Sun.COM rw_exit(&Adapter->chip_lock);
43018479SChenlu.Chen@Sun.COM
43025273Sgl147354 Adapter->reset_count++;
43038275SEric Cheng if (e1000g_global_reset(Adapter)) {
43045273Sgl147354 ddi_fm_service_impact(Adapter->dip,
43055273Sgl147354 DDI_SERVICE_RESTORED);
43068275SEric Cheng e1000g_timer_tx_resched(Adapter);
43078275SEric Cheng } else
43085273Sgl147354 ddi_fm_service_impact(Adapter->dip,
43095273Sgl147354 DDI_SERVICE_LOST);
43105273Sgl147354 return;
43115273Sgl147354 }
43125273Sgl147354
43134061Sxy150489 if (e1000g_stall_check(Adapter)) {
43144919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
43154061Sxy150489 "Tx stall detected. Activate automatic recovery.\n");
43165273Sgl147354 e1000g_fm_ereport(Adapter, DDI_FM_DEVICE_STALL);
43178479SChenlu.Chen@Sun.COM ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_LOST);
43184061Sxy150489 Adapter->reset_count++;
43198275SEric Cheng if (e1000g_reset_adapter(Adapter)) {
43205273Sgl147354 ddi_fm_service_impact(Adapter->dip,
43215273Sgl147354 DDI_SERVICE_RESTORED);
43228275SEric Cheng e1000g_timer_tx_resched(Adapter);
43238479SChenlu.Chen@Sun.COM }
43245273Sgl147354 return;
43254061Sxy150489 }
43264061Sxy150489
43274061Sxy150489 link_changed = B_FALSE;
43285082Syy150190 rw_enter(&Adapter->chip_lock, RW_READER);
43294061Sxy150489 if (Adapter->link_complete)
43304061Sxy150489 link_changed = e1000g_link_check(Adapter);
43315082Syy150190 rw_exit(&Adapter->chip_lock);
43324061Sxy150489
43338850SMin.Xu@Sun.COM if (link_changed) {
433411604SGuoqing.Zhu@Sun.COM if (!Adapter->reset_flag &&
433511604SGuoqing.Zhu@Sun.COM (Adapter->e1000g_state & E1000G_STARTED) &&
433611604SGuoqing.Zhu@Sun.COM !(Adapter->e1000g_state & E1000G_SUSPENDED))
43378850SMin.Xu@Sun.COM mac_link_update(Adapter->mh, Adapter->link_state);
43388850SMin.Xu@Sun.COM if (Adapter->link_state == LINK_STATE_UP)
43398850SMin.Xu@Sun.COM Adapter->reset_flag = B_FALSE;
43408850SMin.Xu@Sun.COM }
43417133Scc210113 /*
43427133Scc210113 * Workaround for esb2. Data stuck in fifo on a link
43437133Scc210113 * down event. Reset the adapter to recover it.
43447133Scc210113 */
43457133Scc210113 if (Adapter->esb2_workaround) {
43467133Scc210113 Adapter->esb2_workaround = B_FALSE;
43477656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter);
43488479SChenlu.Chen@Sun.COM return;
43494139Sxy150489 }
43504061Sxy150489
43513526Sxy150489 /*
43523526Sxy150489 * With 82571 controllers, any locally administered address will
43533526Sxy150489 * be overwritten when there is a reset on the other port.
43543526Sxy150489 * Detect this circumstance and correct it.
43553526Sxy150489 */
43564919Sxy150489 if ((hw->mac.type == e1000_82571) &&
43574919Sxy150489 (e1000_get_laa_state_82571(hw) == B_TRUE)) {
43584919Sxy150489 ether_addr.reg.low = E1000_READ_REG_ARRAY(hw, E1000_RA, 0);
43594919Sxy150489 ether_addr.reg.high = E1000_READ_REG_ARRAY(hw, E1000_RA, 1);
43603526Sxy150489
43613526Sxy150489 ether_addr.reg.low = ntohl(ether_addr.reg.low);
43623526Sxy150489 ether_addr.reg.high = ntohl(ether_addr.reg.high);
43633526Sxy150489
43644919Sxy150489 if ((ether_addr.mac.addr[5] != hw->mac.addr[0]) ||
43654919Sxy150489 (ether_addr.mac.addr[4] != hw->mac.addr[1]) ||
43664919Sxy150489 (ether_addr.mac.addr[3] != hw->mac.addr[2]) ||
43674919Sxy150489 (ether_addr.mac.addr[2] != hw->mac.addr[3]) ||
43684919Sxy150489 (ether_addr.mac.addr[1] != hw->mac.addr[4]) ||
43694919Sxy150489 (ether_addr.mac.addr[0] != hw->mac.addr[5])) {
43704919Sxy150489 e1000_rar_set(hw, hw->mac.addr, 0);
43713526Sxy150489 }
43723526Sxy150489 }
43733526Sxy150489
43743526Sxy150489 /*
43754919Sxy150489 * Long TTL workaround for 82541/82547
43763526Sxy150489 */
43777426SChenliang.Xu@Sun.COM (void) e1000_igp_ttl_workaround_82547(hw);
43783526Sxy150489
43793526Sxy150489 /*
43803526Sxy150489 * Check for Adaptive IFS settings If there are lots of collisions
43813526Sxy150489 * change the value in steps...
43823526Sxy150489 * These properties should only be set for 10/100
43833526Sxy150489 */
43846735Scc210113 if ((hw->phy.media_type == e1000_media_type_copper) &&
43854061Sxy150489 ((Adapter->link_speed == SPEED_100) ||
43864061Sxy150489 (Adapter->link_speed == SPEED_10))) {
43873526Sxy150489 e1000_update_adaptive(hw);
43883526Sxy150489 }
43893526Sxy150489 /*
43903526Sxy150489 * Set Timer Interrupts
43913526Sxy150489 */
43924919Sxy150489 E1000_WRITE_REG(hw, E1000_ICS, E1000_IMS_RXT0);
43934919Sxy150489
43945273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
43955273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
43968275SEric Cheng else
43978275SEric Cheng e1000g_timer_tx_resched(Adapter);
43985273Sgl147354
43994919Sxy150489 restart_watchdog_timer(Adapter);
44003526Sxy150489 }
44013526Sxy150489
44024061Sxy150489 /*
44034061Sxy150489 * The function e1000g_link_timer() is called when the timer for link setup
44044061Sxy150489 * is expired, which indicates the completion of the link setup. The link
44054061Sxy150489 * state will not be updated until the link setup is completed. And the
44064061Sxy150489 * link state will not be sent to the upper layer through mac_link_update()
44074061Sxy150489 * in this function. It will be updated in the local timer routine or the
44084061Sxy150489 * interrupt service routine after the interface is started (plumbed).
44094061Sxy150489 */
44103526Sxy150489 static void
e1000g_link_timer(void * arg)44114061Sxy150489 e1000g_link_timer(void *arg)
44123526Sxy150489 {
44134061Sxy150489 struct e1000g *Adapter = (struct e1000g *)arg;
44143526Sxy150489
44154919Sxy150489 mutex_enter(&Adapter->link_lock);
44164061Sxy150489 Adapter->link_complete = B_TRUE;
44174061Sxy150489 Adapter->link_tid = 0;
44184919Sxy150489 mutex_exit(&Adapter->link_lock);
44193526Sxy150489 }
44203526Sxy150489
44213526Sxy150489 /*
44224919Sxy150489 * e1000g_force_speed_duplex - read forced speed/duplex out of e1000g.conf
44234919Sxy150489 *
44244919Sxy150489 * This function read the forced speed and duplex for 10/100 Mbps speeds
44254919Sxy150489 * and also for 1000 Mbps speeds from the e1000g.conf file
44263526Sxy150489 */
44273526Sxy150489 static void
e1000g_force_speed_duplex(struct e1000g * Adapter)44283526Sxy150489 e1000g_force_speed_duplex(struct e1000g *Adapter)
44293526Sxy150489 {
44303526Sxy150489 int forced;
443111339SGuoqing.Zhu@Sun.COM int propval;
44324919Sxy150489 struct e1000_mac_info *mac = &Adapter->shared.mac;
44334919Sxy150489 struct e1000_phy_info *phy = &Adapter->shared.phy;
44343526Sxy150489
44353526Sxy150489 /*
44363526Sxy150489 * get value out of config file
44373526Sxy150489 */
443811339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "ForceSpeedDuplex",
443911339SGuoqing.Zhu@Sun.COM GDIAG_10_HALF, GDIAG_ANY, GDIAG_ANY, &forced);
44403526Sxy150489
44413526Sxy150489 switch (forced) {
44423526Sxy150489 case GDIAG_10_HALF:
44433526Sxy150489 /*
44443526Sxy150489 * Disable Auto Negotiation
44453526Sxy150489 */
44464919Sxy150489 mac->autoneg = B_FALSE;
44474919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_HALF;
44483526Sxy150489 break;
44493526Sxy150489 case GDIAG_10_FULL:
44503526Sxy150489 /*
44513526Sxy150489 * Disable Auto Negotiation
44523526Sxy150489 */
44534919Sxy150489 mac->autoneg = B_FALSE;
44544919Sxy150489 mac->forced_speed_duplex = ADVERTISE_10_FULL;
44553526Sxy150489 break;
44563526Sxy150489 case GDIAG_100_HALF:
44573526Sxy150489 /*
44583526Sxy150489 * Disable Auto Negotiation
44593526Sxy150489 */
44604919Sxy150489 mac->autoneg = B_FALSE;
44614919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_HALF;
44623526Sxy150489 break;
44633526Sxy150489 case GDIAG_100_FULL:
44643526Sxy150489 /*
44653526Sxy150489 * Disable Auto Negotiation
44663526Sxy150489 */
44674919Sxy150489 mac->autoneg = B_FALSE;
44684919Sxy150489 mac->forced_speed_duplex = ADVERTISE_100_FULL;
44693526Sxy150489 break;
44703526Sxy150489 case GDIAG_1000_FULL:
44713526Sxy150489 /*
44723526Sxy150489 * The gigabit spec requires autonegotiation. Therefore,
44733526Sxy150489 * when the user wants to force the speed to 1000Mbps, we
44743526Sxy150489 * enable AutoNeg, but only allow the harware to advertise
44753526Sxy150489 * 1000Mbps. This is different from 10/100 operation, where
44763526Sxy150489 * we are allowed to link without any negotiation.
44773526Sxy150489 */
44784919Sxy150489 mac->autoneg = B_TRUE;
44794919Sxy150489 phy->autoneg_advertised = ADVERTISE_1000_FULL;
44803526Sxy150489 break;
44813526Sxy150489 default: /* obey the setting of AutoNegAdvertised */
44824919Sxy150489 mac->autoneg = B_TRUE;
448311339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "AutoNegAdvertised",
44844349Sxy150489 0, AUTONEG_ADVERTISE_SPEED_DEFAULT,
448511339SGuoqing.Zhu@Sun.COM AUTONEG_ADVERTISE_SPEED_DEFAULT, &propval);
448611339SGuoqing.Zhu@Sun.COM phy->autoneg_advertised = (uint16_t)propval;
44873526Sxy150489 break;
44883526Sxy150489 } /* switch */
44893526Sxy150489 }
44903526Sxy150489
44913526Sxy150489 /*
44924919Sxy150489 * e1000g_get_max_frame_size - get jumbo frame setting from e1000g.conf
44934919Sxy150489 *
44944919Sxy150489 * This function reads MaxFrameSize from e1000g.conf
44953526Sxy150489 */
44963526Sxy150489 static void
e1000g_get_max_frame_size(struct e1000g * Adapter)44973526Sxy150489 e1000g_get_max_frame_size(struct e1000g *Adapter)
44983526Sxy150489 {
44993526Sxy150489 int max_frame;
45003526Sxy150489
45013526Sxy150489 /*
45023526Sxy150489 * get value out of config file
45033526Sxy150489 */
450411339SGuoqing.Zhu@Sun.COM (void) e1000g_get_prop(Adapter, "MaxFrameSize", 0, 3, 0,
450511339SGuoqing.Zhu@Sun.COM &max_frame);
45063526Sxy150489
45073526Sxy150489 switch (max_frame) {
45083526Sxy150489 case 0:
45096394Scc210113 Adapter->default_mtu = ETHERMTU;
45103526Sxy150489 break;
45113526Sxy150489 case 1:
45126394Scc210113 Adapter->default_mtu = FRAME_SIZE_UPTO_4K -
4513*12853SChangqing.Li@Sun.COM sizeof (struct ether_vlan_header) - ETHERFCSL;
45143526Sxy150489 break;
45153526Sxy150489 case 2:
45166394Scc210113 Adapter->default_mtu = FRAME_SIZE_UPTO_8K -
4517*12853SChangqing.Li@Sun.COM sizeof (struct ether_vlan_header) - ETHERFCSL;
45183526Sxy150489 break;
45193526Sxy150489 case 3:
452010680SMin.Xu@Sun.COM Adapter->default_mtu = FRAME_SIZE_UPTO_16K -
4521*12853SChangqing.Li@Sun.COM sizeof (struct ether_vlan_header) - ETHERFCSL;
45223526Sxy150489 break;
45233526Sxy150489 default:
45246394Scc210113 Adapter->default_mtu = ETHERMTU;
45253526Sxy150489 break;
45263526Sxy150489 } /* switch */
45273526Sxy150489
452810680SMin.Xu@Sun.COM /*
452910680SMin.Xu@Sun.COM * If the user configed MTU is larger than the deivce's maximum MTU,
453010680SMin.Xu@Sun.COM * the MTU is set to the deivce's maximum value.
453110680SMin.Xu@Sun.COM */
453210680SMin.Xu@Sun.COM if (Adapter->default_mtu > Adapter->max_mtu)
453310680SMin.Xu@Sun.COM Adapter->default_mtu = Adapter->max_mtu;
453410680SMin.Xu@Sun.COM
453510680SMin.Xu@Sun.COM Adapter->max_frame_size = e1000g_mtu2maxframe(Adapter->default_mtu);
453610680SMin.Xu@Sun.COM }
453710680SMin.Xu@Sun.COM
453810680SMin.Xu@Sun.COM /*
453910680SMin.Xu@Sun.COM * e1000g_pch_limits - Apply limits of the PCH silicon type
454010680SMin.Xu@Sun.COM *
454110680SMin.Xu@Sun.COM * At any frame size larger than the ethernet default,
454210680SMin.Xu@Sun.COM * prevent linking at 10/100 speeds.
454310680SMin.Xu@Sun.COM */
454410680SMin.Xu@Sun.COM static void
e1000g_pch_limits(struct e1000g * Adapter)454510680SMin.Xu@Sun.COM e1000g_pch_limits(struct e1000g *Adapter)
454610680SMin.Xu@Sun.COM {
454710680SMin.Xu@Sun.COM struct e1000_hw *hw = &Adapter->shared;
454810680SMin.Xu@Sun.COM
454910680SMin.Xu@Sun.COM /* only applies to PCH silicon type */
455010680SMin.Xu@Sun.COM if (hw->mac.type != e1000_pchlan)
455110680SMin.Xu@Sun.COM return;
455210680SMin.Xu@Sun.COM
455310680SMin.Xu@Sun.COM /* only applies to frames larger than ethernet default */
455410680SMin.Xu@Sun.COM if (Adapter->max_frame_size > DEFAULT_FRAME_SIZE) {
455510680SMin.Xu@Sun.COM hw->mac.autoneg = B_TRUE;
455610680SMin.Xu@Sun.COM hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
455710680SMin.Xu@Sun.COM
455810680SMin.Xu@Sun.COM Adapter->param_adv_autoneg = 1;
455910680SMin.Xu@Sun.COM Adapter->param_adv_1000fdx = 1;
456010680SMin.Xu@Sun.COM
456110680SMin.Xu@Sun.COM Adapter->param_adv_100fdx = 0;
456210680SMin.Xu@Sun.COM Adapter->param_adv_100hdx = 0;
456310680SMin.Xu@Sun.COM Adapter->param_adv_10fdx = 0;
456410680SMin.Xu@Sun.COM Adapter->param_adv_10hdx = 0;
456510680SMin.Xu@Sun.COM
456610680SMin.Xu@Sun.COM e1000g_param_sync(Adapter);
456710680SMin.Xu@Sun.COM }
456810680SMin.Xu@Sun.COM }
456910680SMin.Xu@Sun.COM
457010680SMin.Xu@Sun.COM /*
457110680SMin.Xu@Sun.COM * e1000g_mtu2maxframe - convert given MTU to maximum frame size
457210680SMin.Xu@Sun.COM */
457310680SMin.Xu@Sun.COM static uint32_t
e1000g_mtu2maxframe(uint32_t mtu)457410680SMin.Xu@Sun.COM e1000g_mtu2maxframe(uint32_t mtu)
457510680SMin.Xu@Sun.COM {
457610680SMin.Xu@Sun.COM uint32_t maxframe;
457710680SMin.Xu@Sun.COM
457810680SMin.Xu@Sun.COM maxframe = mtu + sizeof (struct ether_vlan_header) + ETHERFCSL;
457910680SMin.Xu@Sun.COM
458010680SMin.Xu@Sun.COM return (maxframe);
45813526Sxy150489 }
45823526Sxy150489
45833526Sxy150489 static void
arm_watchdog_timer(struct e1000g * Adapter)45844919Sxy150489 arm_watchdog_timer(struct e1000g *Adapter)
45853526Sxy150489 {
45864919Sxy150489 Adapter->watchdog_tid =
45874919Sxy150489 timeout(e1000g_local_timer,
45883526Sxy150489 (void *)Adapter, 1 * drv_usectohz(1000000));
45893526Sxy150489 }
45904919Sxy150489 #pragma inline(arm_watchdog_timer)
45914919Sxy150489
45924919Sxy150489 static void
enable_watchdog_timer(struct e1000g * Adapter)45934919Sxy150489 enable_watchdog_timer(struct e1000g *Adapter)
45944919Sxy150489 {
45954919Sxy150489 mutex_enter(&Adapter->watchdog_lock);
45964919Sxy150489
45974919Sxy150489 if (!Adapter->watchdog_timer_enabled) {
45984919Sxy150489 Adapter->watchdog_timer_enabled = B_TRUE;
45994919Sxy150489 Adapter->watchdog_timer_started = B_TRUE;
46004919Sxy150489 arm_watchdog_timer(Adapter);
46014919Sxy150489 }
46024919Sxy150489
46034919Sxy150489 mutex_exit(&Adapter->watchdog_lock);
46044919Sxy150489 }
46053526Sxy150489
46063526Sxy150489 static void
disable_watchdog_timer(struct e1000g * Adapter)46074919Sxy150489 disable_watchdog_timer(struct e1000g *Adapter)
46083526Sxy150489 {
46093526Sxy150489 timeout_id_t tid;
46103526Sxy150489
46114919Sxy150489 mutex_enter(&Adapter->watchdog_lock);
46124919Sxy150489
46134919Sxy150489 Adapter->watchdog_timer_enabled = B_FALSE;
46144919Sxy150489 Adapter->watchdog_timer_started = B_FALSE;
46154919Sxy150489 tid = Adapter->watchdog_tid;
46164919Sxy150489 Adapter->watchdog_tid = 0;
46174919Sxy150489
46184919Sxy150489 mutex_exit(&Adapter->watchdog_lock);
46193526Sxy150489
46203526Sxy150489 if (tid != 0)
46213526Sxy150489 (void) untimeout(tid);
46223526Sxy150489 }
46233526Sxy150489
46243526Sxy150489 static void
start_watchdog_timer(struct e1000g * Adapter)46254919Sxy150489 start_watchdog_timer(struct e1000g *Adapter)
46263526Sxy150489 {
46274919Sxy150489 mutex_enter(&Adapter->watchdog_lock);
46284919Sxy150489
46294919Sxy150489 if (Adapter->watchdog_timer_enabled) {
46304919Sxy150489 if (!Adapter->watchdog_timer_started) {
46314919Sxy150489 Adapter->watchdog_timer_started = B_TRUE;
46324919Sxy150489 arm_watchdog_timer(Adapter);
46333526Sxy150489 }
46343526Sxy150489 }
46353526Sxy150489
46364919Sxy150489 mutex_exit(&Adapter->watchdog_lock);
46374919Sxy150489 }
46384919Sxy150489
46394919Sxy150489 static void
restart_watchdog_timer(struct e1000g * Adapter)46404919Sxy150489 restart_watchdog_timer(struct e1000g *Adapter)
46414919Sxy150489 {
46424919Sxy150489 mutex_enter(&Adapter->watchdog_lock);
46434919Sxy150489
46444919Sxy150489 if (Adapter->watchdog_timer_started)
46454919Sxy150489 arm_watchdog_timer(Adapter);
46464919Sxy150489
46474919Sxy150489 mutex_exit(&Adapter->watchdog_lock);
46483526Sxy150489 }
46493526Sxy150489
46503526Sxy150489 static void
stop_watchdog_timer(struct e1000g * Adapter)46514919Sxy150489 stop_watchdog_timer(struct e1000g *Adapter)
46523526Sxy150489 {
46534919Sxy150489 timeout_id_t tid;
46544919Sxy150489
46554919Sxy150489 mutex_enter(&Adapter->watchdog_lock);
46564919Sxy150489
46574919Sxy150489 Adapter->watchdog_timer_started = B_FALSE;
46584919Sxy150489 tid = Adapter->watchdog_tid;
46594919Sxy150489 Adapter->watchdog_tid = 0;
46604919Sxy150489
46614919Sxy150489 mutex_exit(&Adapter->watchdog_lock);
46624919Sxy150489
46634919Sxy150489 if (tid != 0)
46644919Sxy150489 (void) untimeout(tid);
46653526Sxy150489 }
46663526Sxy150489
46673526Sxy150489 static void
stop_link_timer(struct e1000g * Adapter)46684919Sxy150489 stop_link_timer(struct e1000g *Adapter)
46693526Sxy150489 {
46703526Sxy150489 timeout_id_t tid;
46713526Sxy150489
46724919Sxy150489 /* Disable the link timer */
46734919Sxy150489 mutex_enter(&Adapter->link_lock);
46744919Sxy150489
46754919Sxy150489 tid = Adapter->link_tid;
46764919Sxy150489 Adapter->link_tid = 0;
46774919Sxy150489
46784919Sxy150489 mutex_exit(&Adapter->link_lock);
46794919Sxy150489
46804919Sxy150489 if (tid != 0)
46814919Sxy150489 (void) untimeout(tid);
46824919Sxy150489 }
46834919Sxy150489
46844919Sxy150489 static void
stop_82547_timer(e1000g_tx_ring_t * tx_ring)46854919Sxy150489 stop_82547_timer(e1000g_tx_ring_t *tx_ring)
46864919Sxy150489 {
46874919Sxy150489 timeout_id_t tid;
46884919Sxy150489
46894919Sxy150489 /* Disable the tx timer for 82547 chipset */
46904919Sxy150489 mutex_enter(&tx_ring->tx_lock);
46914919Sxy150489
46924919Sxy150489 tx_ring->timer_enable_82547 = B_FALSE;
46934919Sxy150489 tid = tx_ring->timer_id_82547;
46944919Sxy150489 tx_ring->timer_id_82547 = 0;
46954919Sxy150489
46964919Sxy150489 mutex_exit(&tx_ring->tx_lock);
46973526Sxy150489
46983526Sxy150489 if (tid != 0)
46993526Sxy150489 (void) untimeout(tid);
47003526Sxy150489 }
47013526Sxy150489
47023526Sxy150489 void
e1000g_clear_interrupt(struct e1000g * Adapter)47034919Sxy150489 e1000g_clear_interrupt(struct e1000g *Adapter)
47043526Sxy150489 {
47054919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC,
47064919Sxy150489 0xffffffff & ~E1000_IMS_RXSEQ);
47073526Sxy150489 }
47083526Sxy150489
47093526Sxy150489 void
e1000g_mask_interrupt(struct e1000g * Adapter)47104919Sxy150489 e1000g_mask_interrupt(struct e1000g *Adapter)
47113526Sxy150489 {
47124919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMS,
47135882Syy150190 IMS_ENABLE_MASK & ~E1000_IMS_TXDW);
47145882Syy150190
47155882Syy150190 if (Adapter->tx_intr_enable)
47165882Syy150190 e1000g_mask_tx_interrupt(Adapter);
47173526Sxy150489 }
47183526Sxy150489
47197656SSherry.Moore@Sun.COM /*
47207656SSherry.Moore@Sun.COM * This routine is called by e1000g_quiesce(), therefore must not block.
47217656SSherry.Moore@Sun.COM */
47223526Sxy150489 void
e1000g_clear_all_interrupts(struct e1000g * Adapter)47234919Sxy150489 e1000g_clear_all_interrupts(struct e1000g *Adapter)
47243526Sxy150489 {
47254919Sxy150489 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, 0xffffffff);
47263526Sxy150489 }
47273526Sxy150489
47283526Sxy150489 void
e1000g_mask_tx_interrupt(struct e1000g * Adapter)47294919Sxy150489 e1000g_mask_tx_interrupt(struct e1000g *Adapter)
47303526Sxy150489 {
47315882Syy150190 E1000_WRITE_REG(&Adapter->shared, E1000_IMS, E1000_IMS_TXDW);
47323526Sxy150489 }
47333526Sxy150489
47343526Sxy150489 void
e1000g_clear_tx_interrupt(struct e1000g * Adapter)47354919Sxy150489 e1000g_clear_tx_interrupt(struct e1000g *Adapter)
47363526Sxy150489 {
47375882Syy150190 E1000_WRITE_REG(&Adapter->shared, E1000_IMC, E1000_IMS_TXDW);
47383526Sxy150489 }
47393526Sxy150489
47403526Sxy150489 static void
e1000g_smartspeed(struct e1000g * Adapter)47414919Sxy150489 e1000g_smartspeed(struct e1000g *Adapter)
47423526Sxy150489 {
47434919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
47443526Sxy150489 uint16_t phy_status;
47453526Sxy150489 uint16_t phy_ctrl;
47463526Sxy150489
47473526Sxy150489 /*
47483526Sxy150489 * If we're not T-or-T, or we're not autoneg'ing, or we're not
47493526Sxy150489 * advertising 1000Full, we don't even use the workaround
47503526Sxy150489 */
47514919Sxy150489 if ((hw->phy.type != e1000_phy_igp) ||
47524919Sxy150489 !hw->mac.autoneg ||
47534919Sxy150489 !(hw->phy.autoneg_advertised & ADVERTISE_1000_FULL))
47543526Sxy150489 return;
47553526Sxy150489
47563526Sxy150489 /*
47573526Sxy150489 * True if this is the first call of this function or after every
47583526Sxy150489 * 30 seconds of not having link
47593526Sxy150489 */
47604919Sxy150489 if (Adapter->smartspeed == 0) {
47613526Sxy150489 /*
47623526Sxy150489 * If Master/Slave config fault is asserted twice, we
47633526Sxy150489 * assume back-to-back
47643526Sxy150489 */
47657426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
47663526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
47673526Sxy150489 return;
47683526Sxy150489
47697426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
47703526Sxy150489 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
47713526Sxy150489 return;
47723526Sxy150489 /*
47733526Sxy150489 * We're assuming back-2-back because our status register
47743526Sxy150489 * insists! there's a fault in the master/slave
47753526Sxy150489 * relationship that was "negotiated"
47763526Sxy150489 */
47777426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
47783526Sxy150489 /*
47793526Sxy150489 * Is the phy configured for manual configuration of
47803526Sxy150489 * master/slave?
47813526Sxy150489 */
47823526Sxy150489 if (phy_ctrl & CR_1000T_MS_ENABLE) {
47833526Sxy150489 /*
47843526Sxy150489 * Yes. Then disable manual configuration (enable
47853526Sxy150489 * auto configuration) of master/slave
47863526Sxy150489 */
47873526Sxy150489 phy_ctrl &= ~CR_1000T_MS_ENABLE;
47887426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw,
47893526Sxy150489 PHY_1000T_CTRL, phy_ctrl);
47903526Sxy150489 /*
47913526Sxy150489 * Effectively starting the clock
47923526Sxy150489 */
47934919Sxy150489 Adapter->smartspeed++;
47943526Sxy150489 /*
47953526Sxy150489 * Restart autonegotiation
47963526Sxy150489 */
47974919Sxy150489 if (!e1000_phy_setup_autoneg(hw) &&
47984919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) {
47993526Sxy150489 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
48003526Sxy150489 MII_CR_RESTART_AUTO_NEG);
48017426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw,
48024919Sxy150489 PHY_CONTROL, phy_ctrl);
48033526Sxy150489 }
48043526Sxy150489 }
48053526Sxy150489 return;
48063526Sxy150489 /*
48073526Sxy150489 * Has 6 seconds transpired still without link? Remember,
48083526Sxy150489 * you should reset the smartspeed counter once you obtain
48093526Sxy150489 * link
48103526Sxy150489 */
48114919Sxy150489 } else if (Adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
48123526Sxy150489 /*
48133526Sxy150489 * Yes. Remember, we did at the start determine that
48143526Sxy150489 * there's a master/slave configuration fault, so we're
48153526Sxy150489 * still assuming there's someone on the other end, but we
48163526Sxy150489 * just haven't yet been able to talk to it. We then
48173526Sxy150489 * re-enable auto configuration of master/slave to see if
48183526Sxy150489 * we're running 2/3 pair cables.
48193526Sxy150489 */
48203526Sxy150489 /*
48213526Sxy150489 * If still no link, perhaps using 2/3 pair cable
48223526Sxy150489 */
48237426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
48243526Sxy150489 phy_ctrl |= CR_1000T_MS_ENABLE;
48257426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
48263526Sxy150489 /*
48273526Sxy150489 * Restart autoneg with phy enabled for manual
48283526Sxy150489 * configuration of master/slave
48293526Sxy150489 */
48304919Sxy150489 if (!e1000_phy_setup_autoneg(hw) &&
48314919Sxy150489 !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl)) {
48323526Sxy150489 phy_ctrl |=
48333526Sxy150489 (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
48347426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl);
48353526Sxy150489 }
48363526Sxy150489 /*
48373526Sxy150489 * Hopefully, there are no more faults and we've obtained
48383526Sxy150489 * link as a result.
48393526Sxy150489 */
48403526Sxy150489 }
48413526Sxy150489 /*
48423526Sxy150489 * Restart process after E1000_SMARTSPEED_MAX iterations (30
48433526Sxy150489 * seconds)
48443526Sxy150489 */
48454919Sxy150489 if (Adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
48464919Sxy150489 Adapter->smartspeed = 0;
48473526Sxy150489 }
48483526Sxy150489
48493526Sxy150489 static boolean_t
is_valid_mac_addr(uint8_t * mac_addr)48503526Sxy150489 is_valid_mac_addr(uint8_t *mac_addr)
48513526Sxy150489 {
48523526Sxy150489 const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 };
48533526Sxy150489 const uint8_t addr_test2[6] =
48543526Sxy150489 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
48553526Sxy150489
48563526Sxy150489 if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) ||
48573526Sxy150489 !(bcmp(addr_test2, mac_addr, ETHERADDRL)))
48583526Sxy150489 return (B_FALSE);
48593526Sxy150489
48603526Sxy150489 return (B_TRUE);
48613526Sxy150489 }
48623526Sxy150489
48633526Sxy150489 /*
48644919Sxy150489 * e1000g_stall_check - check for tx stall
48654919Sxy150489 *
48664919Sxy150489 * This function checks if the adapter is stalled (in transmit).
48674919Sxy150489 *
48684919Sxy150489 * It is called each time the watchdog timeout is invoked.
48694919Sxy150489 * If the transmit descriptor reclaim continuously fails,
48704919Sxy150489 * the watchdog value will increment by 1. If the watchdog
48714919Sxy150489 * value exceeds the threshold, the adapter is assumed to
48724919Sxy150489 * have stalled and need to be reset.
48733526Sxy150489 */
48743526Sxy150489 static boolean_t
e1000g_stall_check(struct e1000g * Adapter)48753526Sxy150489 e1000g_stall_check(struct e1000g *Adapter)
48763526Sxy150489 {
48774919Sxy150489 e1000g_tx_ring_t *tx_ring;
48784919Sxy150489
48794919Sxy150489 tx_ring = Adapter->tx_ring;
48804919Sxy150489
48814061Sxy150489 if (Adapter->link_state != LINK_STATE_UP)
48823526Sxy150489 return (B_FALSE);
48833526Sxy150489
48848850SMin.Xu@Sun.COM (void) e1000g_recycle(tx_ring);
48858850SMin.Xu@Sun.COM
488611402SChangqing.Li@Sun.COM if (Adapter->stall_flag)
48878850SMin.Xu@Sun.COM return (B_TRUE);
48888850SMin.Xu@Sun.COM
48898850SMin.Xu@Sun.COM return (B_FALSE);
48903526Sxy150489 }
48913526Sxy150489
48924919Sxy150489 #ifdef E1000G_DEBUG
48933526Sxy150489 static enum ioc_reply
e1000g_pp_ioctl(struct e1000g * e1000gp,struct iocblk * iocp,mblk_t * mp)48943526Sxy150489 e1000g_pp_ioctl(struct e1000g *e1000gp, struct iocblk *iocp, mblk_t *mp)
48953526Sxy150489 {
48963526Sxy150489 void (*ppfn)(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd);
48973526Sxy150489 e1000g_peekpoke_t *ppd;
48983526Sxy150489 uint64_t mem_va;
48993526Sxy150489 uint64_t maxoff;
49003526Sxy150489 boolean_t peek;
49013526Sxy150489
49023526Sxy150489 switch (iocp->ioc_cmd) {
49033526Sxy150489
49043526Sxy150489 case E1000G_IOC_REG_PEEK:
49053526Sxy150489 peek = B_TRUE;
49063526Sxy150489 break;
49073526Sxy150489
49083526Sxy150489 case E1000G_IOC_REG_POKE:
49093526Sxy150489 peek = B_FALSE;
49103526Sxy150489 break;
49113526Sxy150489
49123526Sxy150489 deault:
49134919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL,
49144349Sxy150489 "e1000g_diag_ioctl: invalid ioctl command 0x%X\n",
49154349Sxy150489 iocp->ioc_cmd);
49163526Sxy150489 return (IOC_INVAL);
49173526Sxy150489 }
49183526Sxy150489
49193526Sxy150489 /*
49203526Sxy150489 * Validate format of ioctl
49213526Sxy150489 */
49223526Sxy150489 if (iocp->ioc_count != sizeof (e1000g_peekpoke_t))
49233526Sxy150489 return (IOC_INVAL);
49243526Sxy150489 if (mp->b_cont == NULL)
49253526Sxy150489 return (IOC_INVAL);
49263526Sxy150489
49277426SChenliang.Xu@Sun.COM ppd = (e1000g_peekpoke_t *)(uintptr_t)mp->b_cont->b_rptr;
49283526Sxy150489
49293526Sxy150489 /*
49303526Sxy150489 * Validate request parameters
49313526Sxy150489 */
49323526Sxy150489 switch (ppd->pp_acc_space) {
49333526Sxy150489
49343526Sxy150489 default:
49354919Sxy150489 E1000G_DEBUGLOG_1(e1000gp, E1000G_INFO_LEVEL,
49364349Sxy150489 "e1000g_diag_ioctl: invalid access space 0x%X\n",
49374349Sxy150489 ppd->pp_acc_space);
49383526Sxy150489 return (IOC_INVAL);
49393526Sxy150489
49403526Sxy150489 case E1000G_PP_SPACE_REG:
49413526Sxy150489 /*
49423526Sxy150489 * Memory-mapped I/O space
49433526Sxy150489 */
49443526Sxy150489 ASSERT(ppd->pp_acc_size == 4);
49453526Sxy150489 if (ppd->pp_acc_size != 4)
49463526Sxy150489 return (IOC_INVAL);
49473526Sxy150489
49483526Sxy150489 if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0)
49493526Sxy150489 return (IOC_INVAL);
49503526Sxy150489
49513526Sxy150489 mem_va = 0;
49523526Sxy150489 maxoff = 0x10000;
49533526Sxy150489 ppfn = peek ? e1000g_ioc_peek_reg : e1000g_ioc_poke_reg;
49543526Sxy150489 break;
49553526Sxy150489
49563526Sxy150489 case E1000G_PP_SPACE_E1000G:
49573526Sxy150489 /*
49583526Sxy150489 * E1000g data structure!
49593526Sxy150489 */
49603526Sxy150489 mem_va = (uintptr_t)e1000gp;
49613526Sxy150489 maxoff = sizeof (struct e1000g);
49623526Sxy150489 ppfn = peek ? e1000g_ioc_peek_mem : e1000g_ioc_poke_mem;
49633526Sxy150489 break;
49643526Sxy150489
49653526Sxy150489 }
49663526Sxy150489
49673526Sxy150489 if (ppd->pp_acc_offset >= maxoff)
49683526Sxy150489 return (IOC_INVAL);
49693526Sxy150489
49703526Sxy150489 if (ppd->pp_acc_offset + ppd->pp_acc_size > maxoff)
49713526Sxy150489 return (IOC_INVAL);
49723526Sxy150489
49733526Sxy150489 /*
49743526Sxy150489 * All OK - go!
49753526Sxy150489 */
49763526Sxy150489 ppd->pp_acc_offset += mem_va;
49773526Sxy150489 (*ppfn)(e1000gp, ppd);
49783526Sxy150489 return (peek ? IOC_REPLY : IOC_ACK);
49793526Sxy150489 }
49803526Sxy150489
49813526Sxy150489 static void
e1000g_ioc_peek_reg(struct e1000g * e1000gp,e1000g_peekpoke_t * ppd)49823526Sxy150489 e1000g_ioc_peek_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
49833526Sxy150489 {
49843526Sxy150489 ddi_acc_handle_t handle;
49853526Sxy150489 uint32_t *regaddr;
49863526Sxy150489
49874919Sxy150489 handle = e1000gp->osdep.reg_handle;
49887426SChenliang.Xu@Sun.COM regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr +
49897426SChenliang.Xu@Sun.COM (uintptr_t)ppd->pp_acc_offset);
49903526Sxy150489
49913526Sxy150489 ppd->pp_acc_data = ddi_get32(handle, regaddr);
49923526Sxy150489 }
49933526Sxy150489
49943526Sxy150489 static void
e1000g_ioc_poke_reg(struct e1000g * e1000gp,e1000g_peekpoke_t * ppd)49953526Sxy150489 e1000g_ioc_poke_reg(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
49963526Sxy150489 {
49973526Sxy150489 ddi_acc_handle_t handle;
49983526Sxy150489 uint32_t *regaddr;
49993526Sxy150489 uint32_t value;
50003526Sxy150489
50014919Sxy150489 handle = e1000gp->osdep.reg_handle;
50027426SChenliang.Xu@Sun.COM regaddr = (uint32_t *)((uintptr_t)e1000gp->shared.hw_addr +
50037426SChenliang.Xu@Sun.COM (uintptr_t)ppd->pp_acc_offset);
50043526Sxy150489 value = (uint32_t)ppd->pp_acc_data;
50053526Sxy150489
50063526Sxy150489 ddi_put32(handle, regaddr, value);
50073526Sxy150489 }
50083526Sxy150489
50093526Sxy150489 static void
e1000g_ioc_peek_mem(struct e1000g * e1000gp,e1000g_peekpoke_t * ppd)50103526Sxy150489 e1000g_ioc_peek_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
50113526Sxy150489 {
50123526Sxy150489 uint64_t value;
50133526Sxy150489 void *vaddr;
50143526Sxy150489
50153526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset;
50163526Sxy150489
50173526Sxy150489 switch (ppd->pp_acc_size) {
50183526Sxy150489 case 1:
50193526Sxy150489 value = *(uint8_t *)vaddr;
50203526Sxy150489 break;
50213526Sxy150489
50223526Sxy150489 case 2:
50233526Sxy150489 value = *(uint16_t *)vaddr;
50243526Sxy150489 break;
50253526Sxy150489
50263526Sxy150489 case 4:
50273526Sxy150489 value = *(uint32_t *)vaddr;
50283526Sxy150489 break;
50293526Sxy150489
50303526Sxy150489 case 8:
50313526Sxy150489 value = *(uint64_t *)vaddr;
50323526Sxy150489 break;
50333526Sxy150489 }
50343526Sxy150489
50354919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL,
50364349Sxy150489 "e1000g_ioc_peek_mem($%p, $%p) peeked 0x%llx from $%p\n",
50374349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr);
50383526Sxy150489
50393526Sxy150489 ppd->pp_acc_data = value;
50403526Sxy150489 }
50413526Sxy150489
50423526Sxy150489 static void
e1000g_ioc_poke_mem(struct e1000g * e1000gp,e1000g_peekpoke_t * ppd)50433526Sxy150489 e1000g_ioc_poke_mem(struct e1000g *e1000gp, e1000g_peekpoke_t *ppd)
50443526Sxy150489 {
50453526Sxy150489 uint64_t value;
50463526Sxy150489 void *vaddr;
50473526Sxy150489
50483526Sxy150489 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset;
50493526Sxy150489 value = ppd->pp_acc_data;
50503526Sxy150489
50514919Sxy150489 E1000G_DEBUGLOG_4(e1000gp, E1000G_INFO_LEVEL,
50524349Sxy150489 "e1000g_ioc_poke_mem($%p, $%p) poking 0x%llx at $%p\n",
50534349Sxy150489 (void *)e1000gp, (void *)ppd, value, vaddr);
50543526Sxy150489
50553526Sxy150489 switch (ppd->pp_acc_size) {
50563526Sxy150489 case 1:
50573526Sxy150489 *(uint8_t *)vaddr = (uint8_t)value;
50583526Sxy150489 break;
50593526Sxy150489
50603526Sxy150489 case 2:
50613526Sxy150489 *(uint16_t *)vaddr = (uint16_t)value;
50623526Sxy150489 break;
50633526Sxy150489
50643526Sxy150489 case 4:
50653526Sxy150489 *(uint32_t *)vaddr = (uint32_t)value;
50663526Sxy150489 break;
50673526Sxy150489
50683526Sxy150489 case 8:
50693526Sxy150489 *(uint64_t *)vaddr = (uint64_t)value;
50703526Sxy150489 break;
50713526Sxy150489 }
50723526Sxy150489 }
50734919Sxy150489 #endif
50743526Sxy150489
50753526Sxy150489 /*
50763526Sxy150489 * Loopback Support
50773526Sxy150489 */
50783526Sxy150489 static lb_property_t lb_normal =
50793526Sxy150489 { normal, "normal", E1000G_LB_NONE };
50803526Sxy150489 static lb_property_t lb_external1000 =
50813526Sxy150489 { external, "1000Mbps", E1000G_LB_EXTERNAL_1000 };
50823526Sxy150489 static lb_property_t lb_external100 =
50833526Sxy150489 { external, "100Mbps", E1000G_LB_EXTERNAL_100 };
50843526Sxy150489 static lb_property_t lb_external10 =
50853526Sxy150489 { external, "10Mbps", E1000G_LB_EXTERNAL_10 };
50863526Sxy150489 static lb_property_t lb_phy =
50873526Sxy150489 { internal, "PHY", E1000G_LB_INTERNAL_PHY };
50883526Sxy150489
50893526Sxy150489 static enum ioc_reply
e1000g_loopback_ioctl(struct e1000g * Adapter,struct iocblk * iocp,mblk_t * mp)50903526Sxy150489 e1000g_loopback_ioctl(struct e1000g *Adapter, struct iocblk *iocp, mblk_t *mp)
50913526Sxy150489 {
50923526Sxy150489 lb_info_sz_t *lbsp;
50933526Sxy150489 lb_property_t *lbpp;
50943526Sxy150489 struct e1000_hw *hw;
50953526Sxy150489 uint32_t *lbmp;
50963526Sxy150489 uint32_t size;
50973526Sxy150489 uint32_t value;
50983526Sxy150489
50994919Sxy150489 hw = &Adapter->shared;
51003526Sxy150489
51013526Sxy150489 if (mp->b_cont == NULL)
51023526Sxy150489 return (IOC_INVAL);
51033526Sxy150489
51047133Scc210113 if (!e1000g_check_loopback_support(hw)) {
51057133Scc210113 e1000g_log(NULL, CE_WARN,
51067133Scc210113 "Loopback is not supported on e1000g%d", Adapter->instance);
51077133Scc210113 return (IOC_INVAL);
51087133Scc210113 }
51097133Scc210113
51103526Sxy150489 switch (iocp->ioc_cmd) {
51113526Sxy150489 default:
51123526Sxy150489 return (IOC_INVAL);
51133526Sxy150489
51143526Sxy150489 case LB_GET_INFO_SIZE:
51153526Sxy150489 size = sizeof (lb_info_sz_t);
51163526Sxy150489 if (iocp->ioc_count != size)
51173526Sxy150489 return (IOC_INVAL);
51183526Sxy150489
51195082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER);
51205082Syy150190 e1000g_get_phy_state(Adapter);
51215082Syy150190
51225082Syy150190 /*
51235082Syy150190 * Workaround for hardware faults. In order to get a stable
51245082Syy150190 * state of phy, we will wait for a specific interval and
51255082Syy150190 * try again. The time delay is an experiential value based
51265082Syy150190 * on our testing.
51275082Syy150190 */
51285082Syy150190 msec_delay(100);
51295082Syy150190 e1000g_get_phy_state(Adapter);
51305082Syy150190 rw_exit(&Adapter->chip_lock);
51313526Sxy150489
51323526Sxy150489 value = sizeof (lb_normal);
51335082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
51345082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
51356735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) ||
51366735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) {
51373526Sxy150489 value += sizeof (lb_phy);
51384919Sxy150489 switch (hw->mac.type) {
51393526Sxy150489 case e1000_82571:
51403526Sxy150489 case e1000_82572:
51417133Scc210113 case e1000_80003es2lan:
51423526Sxy150489 value += sizeof (lb_external1000);
51433526Sxy150489 break;
51443526Sxy150489 }
51453526Sxy150489 }
51465082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
51475082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
51483526Sxy150489 value += sizeof (lb_external100);
51495082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
51503526Sxy150489 value += sizeof (lb_external10);
51513526Sxy150489
51527426SChenliang.Xu@Sun.COM lbsp = (lb_info_sz_t *)(uintptr_t)mp->b_cont->b_rptr;
51533526Sxy150489 *lbsp = value;
51543526Sxy150489 break;
51553526Sxy150489
51563526Sxy150489 case LB_GET_INFO:
51573526Sxy150489 value = sizeof (lb_normal);
51585082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
51595082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
51606735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) ||
51616735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) {
51623526Sxy150489 value += sizeof (lb_phy);
51634919Sxy150489 switch (hw->mac.type) {
51643526Sxy150489 case e1000_82571:
51653526Sxy150489 case e1000_82572:
51667133Scc210113 case e1000_80003es2lan:
51673526Sxy150489 value += sizeof (lb_external1000);
51683526Sxy150489 break;
51693526Sxy150489 }
51703526Sxy150489 }
51715082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
51725082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
51733526Sxy150489 value += sizeof (lb_external100);
51745082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
51753526Sxy150489 value += sizeof (lb_external10);
51763526Sxy150489
51773526Sxy150489 size = value;
51783526Sxy150489 if (iocp->ioc_count != size)
51793526Sxy150489 return (IOC_INVAL);
51803526Sxy150489
51813526Sxy150489 value = 0;
51827426SChenliang.Xu@Sun.COM lbpp = (lb_property_t *)(uintptr_t)mp->b_cont->b_rptr;
51833526Sxy150489 lbpp[value++] = lb_normal;
51845082Syy150190 if ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
51855082Syy150190 (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS) ||
51866735Scc210113 (hw->phy.media_type == e1000_media_type_fiber) ||
51876735Scc210113 (hw->phy.media_type == e1000_media_type_internal_serdes)) {
51883526Sxy150489 lbpp[value++] = lb_phy;
51894919Sxy150489 switch (hw->mac.type) {
51903526Sxy150489 case e1000_82571:
51913526Sxy150489 case e1000_82572:
51927133Scc210113 case e1000_80003es2lan:
51933526Sxy150489 lbpp[value++] = lb_external1000;
51943526Sxy150489 break;
51953526Sxy150489 }
51963526Sxy150489 }
51975082Syy150190 if ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
51985082Syy150190 (Adapter->phy_status & MII_SR_100T2_FD_CAPS))
51993526Sxy150489 lbpp[value++] = lb_external100;
52005082Syy150190 if (Adapter->phy_status & MII_SR_10T_FD_CAPS)
52013526Sxy150489 lbpp[value++] = lb_external10;
52023526Sxy150489 break;
52033526Sxy150489
52043526Sxy150489 case LB_GET_MODE:
52053526Sxy150489 size = sizeof (uint32_t);
52063526Sxy150489 if (iocp->ioc_count != size)
52073526Sxy150489 return (IOC_INVAL);
52083526Sxy150489
52097426SChenliang.Xu@Sun.COM lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr;
52103526Sxy150489 *lbmp = Adapter->loopback_mode;
52113526Sxy150489 break;
52123526Sxy150489
52133526Sxy150489 case LB_SET_MODE:
52143526Sxy150489 size = 0;
52153526Sxy150489 if (iocp->ioc_count != sizeof (uint32_t))
52163526Sxy150489 return (IOC_INVAL);
52173526Sxy150489
52187426SChenliang.Xu@Sun.COM lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr;
52193526Sxy150489 if (!e1000g_set_loopback_mode(Adapter, *lbmp))
52203526Sxy150489 return (IOC_INVAL);
52213526Sxy150489 break;
52223526Sxy150489 }
52233526Sxy150489
52243526Sxy150489 iocp->ioc_count = size;
52253526Sxy150489 iocp->ioc_error = 0;
52263526Sxy150489
52275273Sgl147354 if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK) {
52285273Sgl147354 ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_DEGRADED);
52295273Sgl147354 return (IOC_INVAL);
52305273Sgl147354 }
52315273Sgl147354
52323526Sxy150489 return (IOC_REPLY);
52333526Sxy150489 }
52343526Sxy150489
52353526Sxy150489 static boolean_t
e1000g_check_loopback_support(struct e1000_hw * hw)52367133Scc210113 e1000g_check_loopback_support(struct e1000_hw *hw)
52377133Scc210113 {
52387133Scc210113 switch (hw->mac.type) {
52397133Scc210113 case e1000_82540:
52407133Scc210113 case e1000_82545:
52417133Scc210113 case e1000_82545_rev_3:
52427133Scc210113 case e1000_82546:
52437133Scc210113 case e1000_82546_rev_3:
52447133Scc210113 case e1000_82541:
52457133Scc210113 case e1000_82541_rev_2:
52467133Scc210113 case e1000_82547:
52477133Scc210113 case e1000_82547_rev_2:
52487133Scc210113 case e1000_82571:
52497133Scc210113 case e1000_82572:
52507133Scc210113 case e1000_82573:
52518479SChenlu.Chen@Sun.COM case e1000_82574:
52527133Scc210113 case e1000_80003es2lan:
52538479SChenlu.Chen@Sun.COM case e1000_ich9lan:
52548479SChenlu.Chen@Sun.COM case e1000_ich10lan:
52557133Scc210113 return (B_TRUE);
52567133Scc210113 }
52577133Scc210113 return (B_FALSE);
52587133Scc210113 }
52597133Scc210113
52607133Scc210113 static boolean_t
e1000g_set_loopback_mode(struct e1000g * Adapter,uint32_t mode)52613526Sxy150489 e1000g_set_loopback_mode(struct e1000g *Adapter, uint32_t mode)
52623526Sxy150489 {
52633526Sxy150489 struct e1000_hw *hw;
52643526Sxy150489 int i, times;
52655082Syy150190 boolean_t link_up;
52663526Sxy150489
52673526Sxy150489 if (mode == Adapter->loopback_mode)
52683526Sxy150489 return (B_TRUE);
52693526Sxy150489
52704919Sxy150489 hw = &Adapter->shared;
52713526Sxy150489 times = 0;
52723526Sxy150489
52735082Syy150190 Adapter->loopback_mode = mode;
52745082Syy150190
52755082Syy150190 if (mode == E1000G_LB_NONE) {
52763526Sxy150489 /* Reset the chip */
52776735Scc210113 hw->phy.autoneg_wait_to_complete = B_TRUE;
52787656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter);
52796735Scc210113 hw->phy.autoneg_wait_to_complete = B_FALSE;
52805082Syy150190 return (B_TRUE);
52815082Syy150190 }
52825082Syy150190
52835082Syy150190 again:
52845082Syy150190
52855082Syy150190 rw_enter(&Adapter->chip_lock, RW_WRITER);
52865082Syy150190
52875082Syy150190 switch (mode) {
52885082Syy150190 default:
52895082Syy150190 rw_exit(&Adapter->chip_lock);
52905082Syy150190 return (B_FALSE);
52913526Sxy150489
52923526Sxy150489 case E1000G_LB_EXTERNAL_1000:
52933526Sxy150489 e1000g_set_external_loopback_1000(Adapter);
52943526Sxy150489 break;
52953526Sxy150489
52963526Sxy150489 case E1000G_LB_EXTERNAL_100:
52973526Sxy150489 e1000g_set_external_loopback_100(Adapter);
52983526Sxy150489 break;
52993526Sxy150489
53003526Sxy150489 case E1000G_LB_EXTERNAL_10:
53013526Sxy150489 e1000g_set_external_loopback_10(Adapter);
53023526Sxy150489 break;
53033526Sxy150489
53043526Sxy150489 case E1000G_LB_INTERNAL_PHY:
53053526Sxy150489 e1000g_set_internal_loopback(Adapter);
53063526Sxy150489 break;
53073526Sxy150489 }
53083526Sxy150489
53093526Sxy150489 times++;
53103526Sxy150489
53115858Scc210113 rw_exit(&Adapter->chip_lock);
53125858Scc210113
53135082Syy150190 /* Wait for link up */
53145082Syy150190 for (i = (PHY_FORCE_LIMIT * 2); i > 0; i--)
53155082Syy150190 msec_delay(100);
53165082Syy150190
53175858Scc210113 rw_enter(&Adapter->chip_lock, RW_WRITER);
53185858Scc210113
53195082Syy150190 link_up = e1000g_link_up(Adapter);
53205082Syy150190
53215082Syy150190 rw_exit(&Adapter->chip_lock);
53225082Syy150190
53235082Syy150190 if (!link_up) {
53245082Syy150190 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
53255082Syy150190 "Failed to get the link up");
53265082Syy150190 if (times < 2) {
53275082Syy150190 /* Reset the link */
53284919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
53295082Syy150190 "Reset the link ...");
53307656SSherry.Moore@Sun.COM (void) e1000g_reset_adapter(Adapter);
53315082Syy150190 goto again;
53323526Sxy150489 }
533311402SChangqing.Li@Sun.COM
533411402SChangqing.Li@Sun.COM /*
533511402SChangqing.Li@Sun.COM * Reset driver to loopback none when set loopback failed
533611402SChangqing.Li@Sun.COM * for the second time.
533711402SChangqing.Li@Sun.COM */
533811402SChangqing.Li@Sun.COM Adapter->loopback_mode = E1000G_LB_NONE;
533911402SChangqing.Li@Sun.COM
534011402SChangqing.Li@Sun.COM /* Reset the chip */
534111402SChangqing.Li@Sun.COM hw->phy.autoneg_wait_to_complete = B_TRUE;
534211402SChangqing.Li@Sun.COM (void) e1000g_reset_adapter(Adapter);
534311402SChangqing.Li@Sun.COM hw->phy.autoneg_wait_to_complete = B_FALSE;
534411402SChangqing.Li@Sun.COM
534511402SChangqing.Li@Sun.COM E1000G_DEBUGLOG_0(Adapter, E1000G_INFO_LEVEL,
534611402SChangqing.Li@Sun.COM "Set loopback mode failed, reset to loopback none");
534711402SChangqing.Li@Sun.COM
534811402SChangqing.Li@Sun.COM return (B_FALSE);
53493526Sxy150489 }
53503526Sxy150489
53513526Sxy150489 return (B_TRUE);
53523526Sxy150489 }
53533526Sxy150489
53543526Sxy150489 /*
53553526Sxy150489 * The following loopback settings are from Intel's technical
53563526Sxy150489 * document - "How To Loopback". All the register settings and
53573526Sxy150489 * time delay values are directly inherited from the document
53583526Sxy150489 * without more explanations available.
53593526Sxy150489 */
53603526Sxy150489 static void
e1000g_set_internal_loopback(struct e1000g * Adapter)53613526Sxy150489 e1000g_set_internal_loopback(struct e1000g *Adapter)
53623526Sxy150489 {
53633526Sxy150489 struct e1000_hw *hw;
53643526Sxy150489 uint32_t ctrl;
53653526Sxy150489 uint32_t status;
53663526Sxy150489 uint16_t phy_ctrl;
53678479SChenlu.Chen@Sun.COM uint16_t phy_reg;
53685082Syy150190 uint32_t txcw;
53693526Sxy150489
53704919Sxy150489 hw = &Adapter->shared;
53713526Sxy150489
53723526Sxy150489 /* Disable Smart Power Down */
53733526Sxy150489 phy_spd_state(hw, B_FALSE);
53743526Sxy150489
53757426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_CONTROL, &phy_ctrl);
53763526Sxy150489 phy_ctrl &= ~(MII_CR_AUTO_NEG_EN | MII_CR_SPEED_100 | MII_CR_SPEED_10);
53773526Sxy150489 phy_ctrl |= MII_CR_FULL_DUPLEX | MII_CR_SPEED_1000;
53783526Sxy150489
53794919Sxy150489 switch (hw->mac.type) {
53803526Sxy150489 case e1000_82540:
53813526Sxy150489 case e1000_82545:
53823526Sxy150489 case e1000_82545_rev_3:
53833526Sxy150489 case e1000_82546:
53843526Sxy150489 case e1000_82546_rev_3:
53853526Sxy150489 case e1000_82573:
53863526Sxy150489 /* Auto-MDI/MDIX off */
53877426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
53883526Sxy150489 /* Reset PHY to update Auto-MDI/MDIX */
53897426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
53904349Sxy150489 phy_ctrl | MII_CR_RESET | MII_CR_AUTO_NEG_EN);
53913526Sxy150489 /* Reset PHY to auto-neg off and force 1000 */
53927426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
53934349Sxy150489 phy_ctrl | MII_CR_RESET);
53945082Syy150190 /*
53955082Syy150190 * Disable PHY receiver for 82540/545/546 and 82573 Family.
53965082Syy150190 * See comments above e1000g_set_internal_loopback() for the
53975082Syy150190 * background.
53985082Syy150190 */
53997426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 29, 0x001F);
54007426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 30, 0x8FFC);
54017426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 29, 0x001A);
54027426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 30, 0x8FF0);
54033526Sxy150489 break;
54047133Scc210113 case e1000_80003es2lan:
54057133Scc210113 /* Force Link Up */
54067426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
54077426SChenliang.Xu@Sun.COM 0x1CC);
54087133Scc210113 /* Sets PCS loopback at 1Gbs */
54097426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
54107426SChenliang.Xu@Sun.COM 0x1046);
54117133Scc210113 break;
54123526Sxy150489 }
54133526Sxy150489
54148479SChenlu.Chen@Sun.COM /*
54158479SChenlu.Chen@Sun.COM * The following registers should be set for e1000_phy_bm phy type.
54168479SChenlu.Chen@Sun.COM * e1000_82574, e1000_ich10lan and some e1000_ich9lan use this phy.
54178479SChenlu.Chen@Sun.COM * For others, we do not need to set these registers.
54188479SChenlu.Chen@Sun.COM */
54198479SChenlu.Chen@Sun.COM if (hw->phy.type == e1000_phy_bm) {
54208479SChenlu.Chen@Sun.COM /* Set Default MAC Interface speed to 1GB */
54218850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(2, 21), &phy_reg);
54228479SChenlu.Chen@Sun.COM phy_reg &= ~0x0007;
54238479SChenlu.Chen@Sun.COM phy_reg |= 0x006;
54248850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(2, 21), phy_reg);
54258479SChenlu.Chen@Sun.COM /* Assert SW reset for above settings to take effect */
54268850SMin.Xu@Sun.COM (void) e1000_phy_commit(hw);
54278479SChenlu.Chen@Sun.COM msec_delay(1);
54288479SChenlu.Chen@Sun.COM /* Force Full Duplex */
54298850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 16), &phy_reg);
54308850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 16),
54318850SMin.Xu@Sun.COM phy_reg | 0x000C);
54328479SChenlu.Chen@Sun.COM /* Set Link Up (in force link) */
54338850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(776, 16), &phy_reg);
54348850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(776, 16),
54358850SMin.Xu@Sun.COM phy_reg | 0x0040);
54368479SChenlu.Chen@Sun.COM /* Force Link */
54378850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 16), &phy_reg);
54388850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 16),
54398850SMin.Xu@Sun.COM phy_reg | 0x0040);
54408479SChenlu.Chen@Sun.COM /* Set Early Link Enable */
54418850SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_REG(769, 20), &phy_reg);
54428850SMin.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_REG(769, 20),
54438850SMin.Xu@Sun.COM phy_reg | 0x0400);
54448479SChenlu.Chen@Sun.COM }
54458479SChenlu.Chen@Sun.COM
54463526Sxy150489 /* Set loopback */
54477426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL, phy_ctrl | MII_CR_LOOPBACK);
54483526Sxy150489
54493526Sxy150489 msec_delay(250);
54503526Sxy150489
54513526Sxy150489 /* Now set up the MAC to the same speed/duplex as the PHY. */
54524919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
54533526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
54543526Sxy150489 ctrl |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
54554349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
54564349Sxy150489 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
54574349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */
54583526Sxy150489
54594919Sxy150489 switch (hw->mac.type) {
54603526Sxy150489 case e1000_82540:
54613526Sxy150489 case e1000_82545:
54623526Sxy150489 case e1000_82545_rev_3:
54633526Sxy150489 case e1000_82546:
54643526Sxy150489 case e1000_82546_rev_3:
54653526Sxy150489 /*
54663526Sxy150489 * For some serdes we'll need to commit the writes now
54673526Sxy150489 * so that the status is updated on link
54683526Sxy150489 */
54696735Scc210113 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
54704919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
54713526Sxy150489 msec_delay(100);
54724919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
54733526Sxy150489 }
54743526Sxy150489
54756735Scc210113 if (hw->phy.media_type == e1000_media_type_copper) {
54763526Sxy150489 /* Invert Loss of Signal */
54773526Sxy150489 ctrl |= E1000_CTRL_ILOS;
54783526Sxy150489 } else {
54793526Sxy150489 /* Set ILOS on fiber nic if half duplex is detected */
54804919Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS);
54813526Sxy150489 if ((status & E1000_STATUS_FD) == 0)
54823526Sxy150489 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
54833526Sxy150489 }
54843526Sxy150489 break;
54853526Sxy150489
54863526Sxy150489 case e1000_82571:
54873526Sxy150489 case e1000_82572:
54885082Syy150190 /*
54895082Syy150190 * The fiber/SerDes versions of this adapter do not contain an
54905082Syy150190 * accessible PHY. Therefore, loopback beyond MAC must be done
54915082Syy150190 * using SerDes analog loopback.
54925082Syy150190 */
54936735Scc210113 if (hw->phy.media_type != e1000_media_type_copper) {
54945082Syy150190 /* Disable autoneg by setting bit 31 of TXCW to zero */
54955082Syy150190 txcw = E1000_READ_REG(hw, E1000_TXCW);
54965082Syy150190 txcw &= ~((uint32_t)1 << 31);
54975082Syy150190 E1000_WRITE_REG(hw, E1000_TXCW, txcw);
54985082Syy150190
54995082Syy150190 /*
55005082Syy150190 * Write 0x410 to Serdes Control register
55015082Syy150190 * to enable Serdes analog loopback
55025082Syy150190 */
55035082Syy150190 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410);
55045082Syy150190 msec_delay(10);
55053526Sxy150489 }
55068479SChenlu.Chen@Sun.COM
55078479SChenlu.Chen@Sun.COM status = E1000_READ_REG(hw, E1000_STATUS);
55088479SChenlu.Chen@Sun.COM /* Set ILOS on fiber nic if half duplex is detected */
55098479SChenlu.Chen@Sun.COM if ((hw->phy.media_type == e1000_media_type_fiber) &&
55108479SChenlu.Chen@Sun.COM ((status & E1000_STATUS_FD) == 0 ||
55118479SChenlu.Chen@Sun.COM (status & E1000_STATUS_LU) == 0))
55128479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
55138479SChenlu.Chen@Sun.COM else if (hw->phy.media_type == e1000_media_type_internal_serdes)
55148479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU;
55153526Sxy150489 break;
55163526Sxy150489
55173526Sxy150489 case e1000_82573:
55183526Sxy150489 ctrl |= E1000_CTRL_ILOS;
55198479SChenlu.Chen@Sun.COM break;
55208479SChenlu.Chen@Sun.COM case e1000_ich9lan:
55218479SChenlu.Chen@Sun.COM case e1000_ich10lan:
55228479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU;
55233526Sxy150489 break;
55243526Sxy150489 }
55258479SChenlu.Chen@Sun.COM if (hw->phy.type == e1000_phy_bm)
55268479SChenlu.Chen@Sun.COM ctrl |= E1000_CTRL_SLU | E1000_CTRL_ILOS;
55278479SChenlu.Chen@Sun.COM
55288479SChenlu.Chen@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
55293526Sxy150489 }
55303526Sxy150489
55313526Sxy150489 static void
e1000g_set_external_loopback_1000(struct e1000g * Adapter)55323526Sxy150489 e1000g_set_external_loopback_1000(struct e1000g *Adapter)
55333526Sxy150489 {
55343526Sxy150489 struct e1000_hw *hw;
55353526Sxy150489 uint32_t rctl;
55363526Sxy150489 uint32_t ctrl_ext;
55373526Sxy150489 uint32_t ctrl;
55383526Sxy150489 uint32_t status;
55393526Sxy150489 uint32_t txcw;
55407133Scc210113 uint16_t phydata;
55413526Sxy150489
55424919Sxy150489 hw = &Adapter->shared;
55433526Sxy150489
55443526Sxy150489 /* Disable Smart Power Down */
55453526Sxy150489 phy_spd_state(hw, B_FALSE);
55463526Sxy150489
55477133Scc210113 switch (hw->mac.type) {
55487133Scc210113 case e1000_82571:
55497133Scc210113 case e1000_82572:
55507133Scc210113 switch (hw->phy.media_type) {
55517133Scc210113 case e1000_media_type_copper:
55527133Scc210113 /* Force link up (Must be done before the PHY writes) */
55537133Scc210113 ctrl = E1000_READ_REG(hw, E1000_CTRL);
55547133Scc210113 ctrl |= E1000_CTRL_SLU; /* Force Link Up */
55557133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
55567133Scc210113
55577133Scc210113 rctl = E1000_READ_REG(hw, E1000_RCTL);
55587133Scc210113 rctl |= (E1000_RCTL_EN |
55597133Scc210113 E1000_RCTL_SBP |
55607133Scc210113 E1000_RCTL_UPE |
55617133Scc210113 E1000_RCTL_MPE |
55627133Scc210113 E1000_RCTL_LPE |
55637133Scc210113 E1000_RCTL_BAM); /* 0x803E */
55647133Scc210113 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
55657133Scc210113
55667133Scc210113 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
55677133Scc210113 ctrl_ext |= (E1000_CTRL_EXT_SDP4_DATA |
55687133Scc210113 E1000_CTRL_EXT_SDP6_DATA |
556910680SMin.Xu@Sun.COM E1000_CTRL_EXT_SDP3_DATA |
55707133Scc210113 E1000_CTRL_EXT_SDP4_DIR |
55717133Scc210113 E1000_CTRL_EXT_SDP6_DIR |
557210680SMin.Xu@Sun.COM E1000_CTRL_EXT_SDP3_DIR); /* 0x0DD0 */
55737133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
55747133Scc210113
55757133Scc210113 /*
55767133Scc210113 * This sequence tunes the PHY's SDP and no customer
55777133Scc210113 * settable values. For background, see comments above
55787133Scc210113 * e1000g_set_internal_loopback().
55797133Scc210113 */
55807426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x0, 0x140);
55817133Scc210113 msec_delay(10);
55827426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x9, 0x1A00);
55837426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x12, 0xC10);
55847426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x12, 0x1C10);
55857426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F37, 0x76);
55867426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F33, 0x1);
55877426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F33, 0x0);
55887426SChenliang.Xu@Sun.COM
55897426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1F35, 0x65);
55907426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1837, 0x3F7C);
55917426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1437, 0x3FDC);
55927426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1237, 0x3F7C);
55937426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, 0x1137, 0x3FDC);
55947133Scc210113
55957133Scc210113 msec_delay(50);
55967133Scc210113 break;
55977133Scc210113 case e1000_media_type_fiber:
55987133Scc210113 case e1000_media_type_internal_serdes:
55997133Scc210113 status = E1000_READ_REG(hw, E1000_STATUS);
56007133Scc210113 if (((status & E1000_STATUS_LU) == 0) ||
56017133Scc210113 (hw->phy.media_type ==
56027133Scc210113 e1000_media_type_internal_serdes)) {
56037133Scc210113 ctrl = E1000_READ_REG(hw, E1000_CTRL);
56047133Scc210113 ctrl |= E1000_CTRL_ILOS | E1000_CTRL_SLU;
56057133Scc210113 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
56067133Scc210113 }
56077133Scc210113
56087133Scc210113 /* Disable autoneg by setting bit 31 of TXCW to zero */
56097133Scc210113 txcw = E1000_READ_REG(hw, E1000_TXCW);
56107133Scc210113 txcw &= ~((uint32_t)1 << 31);
56117133Scc210113 E1000_WRITE_REG(hw, E1000_TXCW, txcw);
56127133Scc210113
56137133Scc210113 /*
56147133Scc210113 * Write 0x410 to Serdes Control register
56157133Scc210113 * to enable Serdes analog loopback
56167133Scc210113 */
56177133Scc210113 E1000_WRITE_REG(hw, E1000_SCTL, 0x0410);
56187133Scc210113 msec_delay(10);
56197133Scc210113 break;
56207133Scc210113 default:
56217133Scc210113 break;
56227133Scc210113 }
56233526Sxy150489 break;
56248479SChenlu.Chen@Sun.COM case e1000_82574:
56257133Scc210113 case e1000_80003es2lan:
56268479SChenlu.Chen@Sun.COM case e1000_ich9lan:
56278479SChenlu.Chen@Sun.COM case e1000_ich10lan:
56287426SChenliang.Xu@Sun.COM (void) e1000_read_phy_reg(hw, GG82563_REG(6, 16), &phydata);
56297426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, GG82563_REG(6, 16),
56307426SChenliang.Xu@Sun.COM phydata | (1 << 5));
56317133Scc210113 Adapter->param_adv_autoneg = 1;
56327133Scc210113 Adapter->param_adv_1000fdx = 1;
56337426SChenliang.Xu@Sun.COM (void) e1000g_reset_link(Adapter);
56343526Sxy150489 break;
56353526Sxy150489 }
56363526Sxy150489 }
56373526Sxy150489
56383526Sxy150489 static void
e1000g_set_external_loopback_100(struct e1000g * Adapter)56393526Sxy150489 e1000g_set_external_loopback_100(struct e1000g *Adapter)
56403526Sxy150489 {
56413526Sxy150489 struct e1000_hw *hw;
56423526Sxy150489 uint32_t ctrl;
56433526Sxy150489 uint16_t phy_ctrl;
56443526Sxy150489
56454919Sxy150489 hw = &Adapter->shared;
56463526Sxy150489
56473526Sxy150489 /* Disable Smart Power Down */
56483526Sxy150489 phy_spd_state(hw, B_FALSE);
56493526Sxy150489
56503526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX |
56514349Sxy150489 MII_CR_SPEED_100);
56523526Sxy150489
56533526Sxy150489 /* Force 100/FD, reset PHY */
56547426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
56554349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0xA100 */
56563526Sxy150489 msec_delay(10);
56573526Sxy150489
56583526Sxy150489 /* Force 100/FD */
56597426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
56604349Sxy150489 phy_ctrl); /* 0x2100 */
56613526Sxy150489 msec_delay(10);
56623526Sxy150489
56633526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */
56644919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
56653526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
56663526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */
56674349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
56684349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
56694349Sxy150489 E1000_CTRL_SPD_100 | /* Force Speed to 100 */
56704349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */
56713526Sxy150489
56724919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
56733526Sxy150489 }
56743526Sxy150489
56753526Sxy150489 static void
e1000g_set_external_loopback_10(struct e1000g * Adapter)56763526Sxy150489 e1000g_set_external_loopback_10(struct e1000g *Adapter)
56773526Sxy150489 {
56783526Sxy150489 struct e1000_hw *hw;
56793526Sxy150489 uint32_t ctrl;
56803526Sxy150489 uint16_t phy_ctrl;
56813526Sxy150489
56824919Sxy150489 hw = &Adapter->shared;
56833526Sxy150489
56843526Sxy150489 /* Disable Smart Power Down */
56853526Sxy150489 phy_spd_state(hw, B_FALSE);
56863526Sxy150489
56873526Sxy150489 phy_ctrl = (MII_CR_FULL_DUPLEX |
56884349Sxy150489 MII_CR_SPEED_10);
56893526Sxy150489
56903526Sxy150489 /* Force 10/FD, reset PHY */
56917426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
56924349Sxy150489 phy_ctrl | MII_CR_RESET); /* 0x8100 */
56933526Sxy150489 msec_delay(10);
56943526Sxy150489
56953526Sxy150489 /* Force 10/FD */
56967426SChenliang.Xu@Sun.COM (void) e1000_write_phy_reg(hw, PHY_CONTROL,
56974349Sxy150489 phy_ctrl); /* 0x0100 */
56983526Sxy150489 msec_delay(10);
56993526Sxy150489
57003526Sxy150489 /* Now setup the MAC to the same speed/duplex as the PHY. */
57014919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
57023526Sxy150489 ctrl &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
57033526Sxy150489 ctrl |= (E1000_CTRL_SLU | /* Force Link Up */
57044349Sxy150489 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
57054349Sxy150489 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
57064349Sxy150489 E1000_CTRL_SPD_10 | /* Force Speed to 10 */
57074349Sxy150489 E1000_CTRL_FD); /* Force Duplex to FULL */
57083526Sxy150489
57094919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
57103526Sxy150489 }
57113526Sxy150489
57123526Sxy150489 #ifdef __sparc
57133526Sxy150489 static boolean_t
e1000g_find_mac_address(struct e1000g * Adapter)57143526Sxy150489 e1000g_find_mac_address(struct e1000g *Adapter)
57153526Sxy150489 {
57164919Sxy150489 struct e1000_hw *hw = &Adapter->shared;
57173526Sxy150489 uchar_t *bytes;
57183526Sxy150489 struct ether_addr sysaddr;
57193526Sxy150489 uint_t nelts;
57203526Sxy150489 int err;
57213526Sxy150489 boolean_t found = B_FALSE;
57223526Sxy150489
57233526Sxy150489 /*
57243526Sxy150489 * The "vendor's factory-set address" may already have
57253526Sxy150489 * been extracted from the chip, but if the property
57263526Sxy150489 * "local-mac-address" is set we use that instead.
57273526Sxy150489 *
57283526Sxy150489 * We check whether it looks like an array of 6
57293526Sxy150489 * bytes (which it should, if OBP set it). If we can't
57303526Sxy150489 * make sense of it this way, we'll ignore it.
57313526Sxy150489 */
57323526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip,
57333526Sxy150489 DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts);
57343526Sxy150489 if (err == DDI_PROP_SUCCESS) {
57353526Sxy150489 if (nelts == ETHERADDRL) {
57363526Sxy150489 while (nelts--)
57374919Sxy150489 hw->mac.addr[nelts] = bytes[nelts];
57383526Sxy150489 found = B_TRUE;
57393526Sxy150489 }
57403526Sxy150489 ddi_prop_free(bytes);
57413526Sxy150489 }
57423526Sxy150489
57433526Sxy150489 /*
57443526Sxy150489 * Look up the OBP property "local-mac-address?". If the user has set
57453526Sxy150489 * 'local-mac-address? = false', use "the system address" instead.
57463526Sxy150489 */
57473526Sxy150489 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip, 0,
57483526Sxy150489 "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) {
57493526Sxy150489 if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) {
57503526Sxy150489 if (localetheraddr(NULL, &sysaddr) != 0) {
57514919Sxy150489 bcopy(&sysaddr, hw->mac.addr, ETHERADDRL);
57523526Sxy150489 found = B_TRUE;
57533526Sxy150489 }
57543526Sxy150489 }
57553526Sxy150489 ddi_prop_free(bytes);
57563526Sxy150489 }
57573526Sxy150489
57583526Sxy150489 /*
57593526Sxy150489 * Finally(!), if there's a valid "mac-address" property (created
57603526Sxy150489 * if we netbooted from this interface), we must use this instead
57613526Sxy150489 * of any of the above to ensure that the NFS/install server doesn't
57623526Sxy150489 * get confused by the address changing as Solaris takes over!
57633526Sxy150489 */
57643526Sxy150489 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, Adapter->dip,
57653526Sxy150489 DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts);
57663526Sxy150489 if (err == DDI_PROP_SUCCESS) {
57673526Sxy150489 if (nelts == ETHERADDRL) {
57683526Sxy150489 while (nelts--)
57694919Sxy150489 hw->mac.addr[nelts] = bytes[nelts];
57703526Sxy150489 found = B_TRUE;
57713526Sxy150489 }
57723526Sxy150489 ddi_prop_free(bytes);
57733526Sxy150489 }
57743526Sxy150489
57753526Sxy150489 if (found) {
57764919Sxy150489 bcopy(hw->mac.addr, hw->mac.perm_addr,
57773526Sxy150489 ETHERADDRL);
57783526Sxy150489 }
57793526Sxy150489
57803526Sxy150489 return (found);
57813526Sxy150489 }
57823526Sxy150489 #endif
57833526Sxy150489
57843526Sxy150489 static int
e1000g_add_intrs(struct e1000g * Adapter)57853526Sxy150489 e1000g_add_intrs(struct e1000g *Adapter)
57863526Sxy150489 {
57873526Sxy150489 dev_info_t *devinfo;
57883526Sxy150489 int intr_types;
57893526Sxy150489 int rc;
57903526Sxy150489
57913526Sxy150489 devinfo = Adapter->dip;
57923526Sxy150489
57933526Sxy150489 /* Get supported interrupt types */
57943526Sxy150489 rc = ddi_intr_get_supported_types(devinfo, &intr_types);
57953526Sxy150489
57963526Sxy150489 if (rc != DDI_SUCCESS) {
57974919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
57983526Sxy150489 "Get supported interrupt types failed: %d\n", rc);
57993526Sxy150489 return (DDI_FAILURE);
58003526Sxy150489 }
58013526Sxy150489
58023526Sxy150489 /*
58033526Sxy150489 * Based on Intel Technical Advisory document (TA-160), there are some
58043526Sxy150489 * cases where some older Intel PCI-X NICs may "advertise" to the OS
58053526Sxy150489 * that it supports MSI, but in fact has problems.
58063526Sxy150489 * So we should only enable MSI for PCI-E NICs and disable MSI for old
58073526Sxy150489 * PCI/PCI-X NICs.
58083526Sxy150489 */
58094919Sxy150489 if (Adapter->shared.mac.type < e1000_82571)
58106986Smx205022 Adapter->msi_enable = B_FALSE;
58116986Smx205022
58126986Smx205022 if ((intr_types & DDI_INTR_TYPE_MSI) && Adapter->msi_enable) {
58133526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_MSI);
58143526Sxy150489
58153526Sxy150489 if (rc != DDI_SUCCESS) {
581611143SGuoqing.Zhu@Sun.COM /* EMPTY */
58174919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
58183526Sxy150489 "Add MSI failed, trying Legacy interrupts\n");
58193526Sxy150489 } else {
58203526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_MSI;
58213526Sxy150489 }
58223526Sxy150489 }
58233526Sxy150489
58243526Sxy150489 if ((Adapter->intr_type == 0) &&
58253526Sxy150489 (intr_types & DDI_INTR_TYPE_FIXED)) {
58263526Sxy150489 rc = e1000g_intr_add(Adapter, DDI_INTR_TYPE_FIXED);
58273526Sxy150489
58283526Sxy150489 if (rc != DDI_SUCCESS) {
58294919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
58303526Sxy150489 "Add Legacy interrupts failed\n");
58313526Sxy150489 return (DDI_FAILURE);
58323526Sxy150489 }
58333526Sxy150489
58343526Sxy150489 Adapter->intr_type = DDI_INTR_TYPE_FIXED;
58353526Sxy150489 }
58363526Sxy150489
58373526Sxy150489 if (Adapter->intr_type == 0) {
58384919Sxy150489 E1000G_DEBUGLOG_0(Adapter, E1000G_WARN_LEVEL,
58393526Sxy150489 "No interrupts registered\n");
58403526Sxy150489 return (DDI_FAILURE);
58413526Sxy150489 }
58423526Sxy150489
58433526Sxy150489 return (DDI_SUCCESS);
58443526Sxy150489 }
58453526Sxy150489
58463526Sxy150489 /*
58473526Sxy150489 * e1000g_intr_add() handles MSI/Legacy interrupts
58483526Sxy150489 */
58493526Sxy150489 static int
e1000g_intr_add(struct e1000g * Adapter,int intr_type)58503526Sxy150489 e1000g_intr_add(struct e1000g *Adapter, int intr_type)
58513526Sxy150489 {
58523526Sxy150489 dev_info_t *devinfo;
58533526Sxy150489 int count, avail, actual;
58543526Sxy150489 int x, y, rc, inum = 0;
58553526Sxy150489 int flag;
58563526Sxy150489 ddi_intr_handler_t *intr_handler;
58573526Sxy150489
58583526Sxy150489 devinfo = Adapter->dip;
58593526Sxy150489
58603526Sxy150489 /* get number of interrupts */
58613526Sxy150489 rc = ddi_intr_get_nintrs(devinfo, intr_type, &count);
58623526Sxy150489 if ((rc != DDI_SUCCESS) || (count == 0)) {
58634919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
58643526Sxy150489 "Get interrupt number failed. Return: %d, count: %d\n",
58653526Sxy150489 rc, count);
58663526Sxy150489 return (DDI_FAILURE);
58673526Sxy150489 }
58683526Sxy150489
58693526Sxy150489 /* get number of available interrupts */
58703526Sxy150489 rc = ddi_intr_get_navail(devinfo, intr_type, &avail);
58713526Sxy150489 if ((rc != DDI_SUCCESS) || (avail == 0)) {
58724919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
58733526Sxy150489 "Get interrupt available number failed. "
58743526Sxy150489 "Return: %d, available: %d\n", rc, avail);
58753526Sxy150489 return (DDI_FAILURE);
58763526Sxy150489 }
58773526Sxy150489
58783526Sxy150489 if (avail < count) {
587911143SGuoqing.Zhu@Sun.COM /* EMPTY */
58804919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
58813526Sxy150489 "Interrupts count: %d, available: %d\n",
58823526Sxy150489 count, avail);
58833526Sxy150489 }
58843526Sxy150489
58853526Sxy150489 /* Allocate an array of interrupt handles */
58863526Sxy150489 Adapter->intr_size = count * sizeof (ddi_intr_handle_t);
58873526Sxy150489 Adapter->htable = kmem_alloc(Adapter->intr_size, KM_SLEEP);
58883526Sxy150489
58893526Sxy150489 /* Set NORMAL behavior for both MSI and FIXED interrupt */
58903526Sxy150489 flag = DDI_INTR_ALLOC_NORMAL;
58913526Sxy150489
58923526Sxy150489 /* call ddi_intr_alloc() */
58933526Sxy150489 rc = ddi_intr_alloc(devinfo, Adapter->htable, intr_type, inum,
58943526Sxy150489 count, &actual, flag);
58953526Sxy150489
58963526Sxy150489 if ((rc != DDI_SUCCESS) || (actual == 0)) {
58974919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
58983526Sxy150489 "Allocate interrupts failed: %d\n", rc);
58993526Sxy150489
59003526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size);
59013526Sxy150489 return (DDI_FAILURE);
59023526Sxy150489 }
59033526Sxy150489
59043526Sxy150489 if (actual < count) {
590511143SGuoqing.Zhu@Sun.COM /* EMPTY */
59064919Sxy150489 E1000G_DEBUGLOG_2(Adapter, E1000G_WARN_LEVEL,
59073526Sxy150489 "Interrupts requested: %d, received: %d\n",
59083526Sxy150489 count, actual);
59093526Sxy150489 }
59103526Sxy150489
59113526Sxy150489 Adapter->intr_cnt = actual;
59123526Sxy150489
59133526Sxy150489 /* Get priority for first msi, assume remaining are all the same */
59143526Sxy150489 rc = ddi_intr_get_pri(Adapter->htable[0], &Adapter->intr_pri);
59153526Sxy150489
59163526Sxy150489 if (rc != DDI_SUCCESS) {
59174919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
59183526Sxy150489 "Get interrupt priority failed: %d\n", rc);
59193526Sxy150489
59203526Sxy150489 /* Free already allocated intr */
59213526Sxy150489 for (y = 0; y < actual; y++)
59223526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]);
59233526Sxy150489
59243526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size);
59253526Sxy150489 return (DDI_FAILURE);
59263526Sxy150489 }
59273526Sxy150489
59283526Sxy150489 /*
59293526Sxy150489 * In Legacy Interrupt mode, for PCI-Express adapters, we should
59303526Sxy150489 * use the interrupt service routine e1000g_intr_pciexpress()
59313526Sxy150489 * to avoid interrupt stealing when sharing interrupt with other
59323526Sxy150489 * devices.
59333526Sxy150489 */
59344919Sxy150489 if (Adapter->shared.mac.type < e1000_82571)
59353526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr;
59363526Sxy150489 else
59373526Sxy150489 intr_handler = (ddi_intr_handler_t *)e1000g_intr_pciexpress;
59383526Sxy150489
59393526Sxy150489 /* Call ddi_intr_add_handler() */
59403526Sxy150489 for (x = 0; x < actual; x++) {
59413526Sxy150489 rc = ddi_intr_add_handler(Adapter->htable[x],
59423526Sxy150489 intr_handler, (caddr_t)Adapter, NULL);
59433526Sxy150489
59443526Sxy150489 if (rc != DDI_SUCCESS) {
59454919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
59463526Sxy150489 "Add interrupt handler failed: %d\n", rc);
59473526Sxy150489
59483526Sxy150489 /* Remove already added handler */
59493526Sxy150489 for (y = 0; y < x; y++)
59503526Sxy150489 (void) ddi_intr_remove_handler(
59513526Sxy150489 Adapter->htable[y]);
59523526Sxy150489
59533526Sxy150489 /* Free already allocated intr */
59543526Sxy150489 for (y = 0; y < actual; y++)
59553526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]);
59563526Sxy150489
59573526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size);
59583526Sxy150489 return (DDI_FAILURE);
59593526Sxy150489 }
59603526Sxy150489 }
59613526Sxy150489
59623526Sxy150489 rc = ddi_intr_get_cap(Adapter->htable[0], &Adapter->intr_cap);
59633526Sxy150489
59643526Sxy150489 if (rc != DDI_SUCCESS) {
59654919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
59663526Sxy150489 "Get interrupt cap failed: %d\n", rc);
59673526Sxy150489
59683526Sxy150489 /* Free already allocated intr */
59693526Sxy150489 for (y = 0; y < actual; y++) {
59703526Sxy150489 (void) ddi_intr_remove_handler(Adapter->htable[y]);
59713526Sxy150489 (void) ddi_intr_free(Adapter->htable[y]);
59723526Sxy150489 }
59733526Sxy150489
59743526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size);
59753526Sxy150489 return (DDI_FAILURE);
59763526Sxy150489 }
59773526Sxy150489
59783526Sxy150489 return (DDI_SUCCESS);
59793526Sxy150489 }
59803526Sxy150489
59813526Sxy150489 static int
e1000g_rem_intrs(struct e1000g * Adapter)59823526Sxy150489 e1000g_rem_intrs(struct e1000g *Adapter)
59833526Sxy150489 {
59843526Sxy150489 int x;
59853526Sxy150489 int rc;
59863526Sxy150489
59873526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) {
59883526Sxy150489 rc = ddi_intr_remove_handler(Adapter->htable[x]);
59893526Sxy150489 if (rc != DDI_SUCCESS) {
59904919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
59913526Sxy150489 "Remove intr handler failed: %d\n", rc);
59923526Sxy150489 return (DDI_FAILURE);
59933526Sxy150489 }
59943526Sxy150489
59953526Sxy150489 rc = ddi_intr_free(Adapter->htable[x]);
59963526Sxy150489 if (rc != DDI_SUCCESS) {
59974919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
59983526Sxy150489 "Free intr failed: %d\n", rc);
59993526Sxy150489 return (DDI_FAILURE);
60003526Sxy150489 }
60013526Sxy150489 }
60023526Sxy150489
60033526Sxy150489 kmem_free(Adapter->htable, Adapter->intr_size);
60043526Sxy150489
60053526Sxy150489 return (DDI_SUCCESS);
60063526Sxy150489 }
60073526Sxy150489
60083526Sxy150489 static int
e1000g_enable_intrs(struct e1000g * Adapter)60093526Sxy150489 e1000g_enable_intrs(struct e1000g *Adapter)
60103526Sxy150489 {
60113526Sxy150489 int x;
60123526Sxy150489 int rc;
60133526Sxy150489
60143526Sxy150489 /* Enable interrupts */
60153526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) {
60163526Sxy150489 /* Call ddi_intr_block_enable() for MSI */
60173526Sxy150489 rc = ddi_intr_block_enable(Adapter->htable,
60183526Sxy150489 Adapter->intr_cnt);
60193526Sxy150489 if (rc != DDI_SUCCESS) {
60204919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
60213526Sxy150489 "Enable block intr failed: %d\n", rc);
60223526Sxy150489 return (DDI_FAILURE);
60233526Sxy150489 }
60243526Sxy150489 } else {
60253526Sxy150489 /* Call ddi_intr_enable() for Legacy/MSI non block enable */
60263526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) {
60273526Sxy150489 rc = ddi_intr_enable(Adapter->htable[x]);
60283526Sxy150489 if (rc != DDI_SUCCESS) {
60294919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
60303526Sxy150489 "Enable intr failed: %d\n", rc);
60313526Sxy150489 return (DDI_FAILURE);
60323526Sxy150489 }
60333526Sxy150489 }
60343526Sxy150489 }
60353526Sxy150489
60363526Sxy150489 return (DDI_SUCCESS);
60373526Sxy150489 }
60383526Sxy150489
60393526Sxy150489 static int
e1000g_disable_intrs(struct e1000g * Adapter)60403526Sxy150489 e1000g_disable_intrs(struct e1000g *Adapter)
60413526Sxy150489 {
60423526Sxy150489 int x;
60433526Sxy150489 int rc;
60443526Sxy150489
60453526Sxy150489 /* Disable all interrupts */
60463526Sxy150489 if (Adapter->intr_cap & DDI_INTR_FLAG_BLOCK) {
60473526Sxy150489 rc = ddi_intr_block_disable(Adapter->htable,
60483526Sxy150489 Adapter->intr_cnt);
60493526Sxy150489 if (rc != DDI_SUCCESS) {
60504919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
60513526Sxy150489 "Disable block intr failed: %d\n", rc);
60523526Sxy150489 return (DDI_FAILURE);
60533526Sxy150489 }
60543526Sxy150489 } else {
60553526Sxy150489 for (x = 0; x < Adapter->intr_cnt; x++) {
60563526Sxy150489 rc = ddi_intr_disable(Adapter->htable[x]);
60573526Sxy150489 if (rc != DDI_SUCCESS) {
60584919Sxy150489 E1000G_DEBUGLOG_1(Adapter, E1000G_WARN_LEVEL,
60593526Sxy150489 "Disable intr failed: %d\n", rc);
60603526Sxy150489 return (DDI_FAILURE);
60613526Sxy150489 }
60623526Sxy150489 }
60633526Sxy150489 }
60643526Sxy150489
60653526Sxy150489 return (DDI_SUCCESS);
60663526Sxy150489 }
60675082Syy150190
60685082Syy150190 /*
60695082Syy150190 * e1000g_get_phy_state - get the state of PHY registers, save in the adapter
60705082Syy150190 */
60715082Syy150190 static void
e1000g_get_phy_state(struct e1000g * Adapter)60725082Syy150190 e1000g_get_phy_state(struct e1000g *Adapter)
60735082Syy150190 {
60745082Syy150190 struct e1000_hw *hw = &Adapter->shared;
60755082Syy150190
607610605SMin.Xu@Sun.COM if (hw->phy.media_type == e1000_media_type_copper) {
607710605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_CONTROL, &Adapter->phy_ctrl);
607810605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_STATUS, &Adapter->phy_status);
607910605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
608010605SMin.Xu@Sun.COM &Adapter->phy_an_adv);
608110605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_AUTONEG_EXP,
608210605SMin.Xu@Sun.COM &Adapter->phy_an_exp);
608310605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_EXT_STATUS,
608410605SMin.Xu@Sun.COM &Adapter->phy_ext_status);
608510605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_CTRL,
608610605SMin.Xu@Sun.COM &Adapter->phy_1000t_ctrl);
608710605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_1000T_STATUS,
608810605SMin.Xu@Sun.COM &Adapter->phy_1000t_status);
608910605SMin.Xu@Sun.COM (void) e1000_read_phy_reg(hw, PHY_LP_ABILITY,
609010605SMin.Xu@Sun.COM &Adapter->phy_lp_able);
609110605SMin.Xu@Sun.COM
609210605SMin.Xu@Sun.COM Adapter->param_autoneg_cap =
609310605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_AUTONEG_CAPS) ? 1 : 0;
609410605SMin.Xu@Sun.COM Adapter->param_pause_cap =
609510605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0;
609610605SMin.Xu@Sun.COM Adapter->param_asym_pause_cap =
609710605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0;
609810605SMin.Xu@Sun.COM Adapter->param_1000fdx_cap =
609910605SMin.Xu@Sun.COM ((Adapter->phy_ext_status & IEEE_ESR_1000T_FD_CAPS) ||
610010605SMin.Xu@Sun.COM (Adapter->phy_ext_status & IEEE_ESR_1000X_FD_CAPS)) ? 1 : 0;
610110605SMin.Xu@Sun.COM Adapter->param_1000hdx_cap =
610210605SMin.Xu@Sun.COM ((Adapter->phy_ext_status & IEEE_ESR_1000T_HD_CAPS) ||
610310605SMin.Xu@Sun.COM (Adapter->phy_ext_status & IEEE_ESR_1000X_HD_CAPS)) ? 1 : 0;
610410605SMin.Xu@Sun.COM Adapter->param_100t4_cap =
610510605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_100T4_CAPS) ? 1 : 0;
610610605SMin.Xu@Sun.COM Adapter->param_100fdx_cap =
610710605SMin.Xu@Sun.COM ((Adapter->phy_status & MII_SR_100X_FD_CAPS) ||
610810605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_100T2_FD_CAPS)) ? 1 : 0;
610910605SMin.Xu@Sun.COM Adapter->param_100hdx_cap =
611010605SMin.Xu@Sun.COM ((Adapter->phy_status & MII_SR_100X_HD_CAPS) ||
611110605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_100T2_HD_CAPS)) ? 1 : 0;
611210605SMin.Xu@Sun.COM Adapter->param_10fdx_cap =
611310605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_10T_FD_CAPS) ? 1 : 0;
611410605SMin.Xu@Sun.COM Adapter->param_10hdx_cap =
611510605SMin.Xu@Sun.COM (Adapter->phy_status & MII_SR_10T_HD_CAPS) ? 1 : 0;
611610605SMin.Xu@Sun.COM
611710605SMin.Xu@Sun.COM Adapter->param_adv_autoneg = hw->mac.autoneg;
611810605SMin.Xu@Sun.COM Adapter->param_adv_pause =
611910605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_PAUSE) ? 1 : 0;
612010605SMin.Xu@Sun.COM Adapter->param_adv_asym_pause =
612110605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_ASM_DIR) ? 1 : 0;
612210605SMin.Xu@Sun.COM Adapter->param_adv_1000hdx =
612310605SMin.Xu@Sun.COM (Adapter->phy_1000t_ctrl & CR_1000T_HD_CAPS) ? 1 : 0;
612410605SMin.Xu@Sun.COM Adapter->param_adv_100t4 =
612510605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_100T4_CAPS) ? 1 : 0;
612610605SMin.Xu@Sun.COM if (Adapter->param_adv_autoneg == 1) {
612710605SMin.Xu@Sun.COM Adapter->param_adv_1000fdx =
612810605SMin.Xu@Sun.COM (Adapter->phy_1000t_ctrl & CR_1000T_FD_CAPS)
612910605SMin.Xu@Sun.COM ? 1 : 0;
613010605SMin.Xu@Sun.COM Adapter->param_adv_100fdx =
613110605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_100TX_FD_CAPS)
613210605SMin.Xu@Sun.COM ? 1 : 0;
613310605SMin.Xu@Sun.COM Adapter->param_adv_100hdx =
613410605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_100TX_HD_CAPS)
613510605SMin.Xu@Sun.COM ? 1 : 0;
613610605SMin.Xu@Sun.COM Adapter->param_adv_10fdx =
613710605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_10T_FD_CAPS) ? 1 : 0;
613810605SMin.Xu@Sun.COM Adapter->param_adv_10hdx =
613910605SMin.Xu@Sun.COM (Adapter->phy_an_adv & NWAY_AR_10T_HD_CAPS) ? 1 : 0;
614010605SMin.Xu@Sun.COM }
614110605SMin.Xu@Sun.COM
614210605SMin.Xu@Sun.COM Adapter->param_lp_autoneg =
614310605SMin.Xu@Sun.COM (Adapter->phy_an_exp & NWAY_ER_LP_NWAY_CAPS) ? 1 : 0;
614410605SMin.Xu@Sun.COM Adapter->param_lp_pause =
614510605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_PAUSE) ? 1 : 0;
614610605SMin.Xu@Sun.COM Adapter->param_lp_asym_pause =
614710605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_ASM_DIR) ? 1 : 0;
614810605SMin.Xu@Sun.COM Adapter->param_lp_1000fdx =
614910605SMin.Xu@Sun.COM (Adapter->phy_1000t_status & SR_1000T_LP_FD_CAPS) ? 1 : 0;
615010605SMin.Xu@Sun.COM Adapter->param_lp_1000hdx =
615110605SMin.Xu@Sun.COM (Adapter->phy_1000t_status & SR_1000T_LP_HD_CAPS) ? 1 : 0;
615210605SMin.Xu@Sun.COM Adapter->param_lp_100t4 =
615310605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_100T4_CAPS) ? 1 : 0;
615410605SMin.Xu@Sun.COM Adapter->param_lp_100fdx =
615510605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_100TX_FD_CAPS) ? 1 : 0;
615610605SMin.Xu@Sun.COM Adapter->param_lp_100hdx =
615710605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_100TX_HD_CAPS) ? 1 : 0;
615810605SMin.Xu@Sun.COM Adapter->param_lp_10fdx =
615910605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_10T_FD_CAPS) ? 1 : 0;
616010605SMin.Xu@Sun.COM Adapter->param_lp_10hdx =
616110605SMin.Xu@Sun.COM (Adapter->phy_lp_able & NWAY_LPAR_10T_HD_CAPS) ? 1 : 0;
616210605SMin.Xu@Sun.COM } else {
616310605SMin.Xu@Sun.COM /*
616410605SMin.Xu@Sun.COM * 1Gig Fiber adapter only offers 1Gig Full Duplex. Meaning,
616510605SMin.Xu@Sun.COM * it can only work with 1Gig Full Duplex Link Partner.
616610605SMin.Xu@Sun.COM */
616710605SMin.Xu@Sun.COM Adapter->param_autoneg_cap = 0;
616810605SMin.Xu@Sun.COM Adapter->param_pause_cap = 1;
616910605SMin.Xu@Sun.COM Adapter->param_asym_pause_cap = 1;
617010605SMin.Xu@Sun.COM Adapter->param_1000fdx_cap = 1;
617110605SMin.Xu@Sun.COM Adapter->param_1000hdx_cap = 0;
617210605SMin.Xu@Sun.COM Adapter->param_100t4_cap = 0;
617310605SMin.Xu@Sun.COM Adapter->param_100fdx_cap = 0;
617410605SMin.Xu@Sun.COM Adapter->param_100hdx_cap = 0;
617510605SMin.Xu@Sun.COM Adapter->param_10fdx_cap = 0;
617610605SMin.Xu@Sun.COM Adapter->param_10hdx_cap = 0;
617710605SMin.Xu@Sun.COM
617810605SMin.Xu@Sun.COM Adapter->param_adv_autoneg = 0;
617910605SMin.Xu@Sun.COM Adapter->param_adv_pause = 1;
618010605SMin.Xu@Sun.COM Adapter->param_adv_asym_pause = 1;
618110605SMin.Xu@Sun.COM Adapter->param_adv_1000fdx = 1;
618210605SMin.Xu@Sun.COM Adapter->param_adv_1000hdx = 0;
618310605SMin.Xu@Sun.COM Adapter->param_adv_100t4 = 0;
618410605SMin.Xu@Sun.COM Adapter->param_adv_100fdx = 0;
618510605SMin.Xu@Sun.COM Adapter->param_adv_100hdx = 0;
618610605SMin.Xu@Sun.COM Adapter->param_adv_10fdx = 0;
618710605SMin.Xu@Sun.COM Adapter->param_adv_10hdx = 0;
618810605SMin.Xu@Sun.COM
618910605SMin.Xu@Sun.COM Adapter->param_lp_autoneg = 0;
619010605SMin.Xu@Sun.COM Adapter->param_lp_pause = 0;
619110605SMin.Xu@Sun.COM Adapter->param_lp_asym_pause = 0;
619210605SMin.Xu@Sun.COM Adapter->param_lp_1000fdx = 0;
619310605SMin.Xu@Sun.COM Adapter->param_lp_1000hdx = 0;
619410605SMin.Xu@Sun.COM Adapter->param_lp_100t4 = 0;
619510605SMin.Xu@Sun.COM Adapter->param_lp_100fdx = 0;
619610605SMin.Xu@Sun.COM Adapter->param_lp_100hdx = 0;
619710605SMin.Xu@Sun.COM Adapter->param_lp_10fdx = 0;
619810605SMin.Xu@Sun.COM Adapter->param_lp_10hdx = 0;
619910605SMin.Xu@Sun.COM }
62005082Syy150190 }
62015273Sgl147354
62025273Sgl147354 /*
62035273Sgl147354 * FMA support
62045273Sgl147354 */
62055273Sgl147354
62065273Sgl147354 int
e1000g_check_acc_handle(ddi_acc_handle_t handle)62075273Sgl147354 e1000g_check_acc_handle(ddi_acc_handle_t handle)
62085273Sgl147354 {
62095273Sgl147354 ddi_fm_error_t de;
62105273Sgl147354
62115273Sgl147354 ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION);
62125273Sgl147354 ddi_fm_acc_err_clear(handle, DDI_FME_VERSION);
62135273Sgl147354 return (de.fme_status);
62145273Sgl147354 }
62155273Sgl147354
62165273Sgl147354 int
e1000g_check_dma_handle(ddi_dma_handle_t handle)62175273Sgl147354 e1000g_check_dma_handle(ddi_dma_handle_t handle)
62185273Sgl147354 {
62195273Sgl147354 ddi_fm_error_t de;
62205273Sgl147354
62215273Sgl147354 ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION);
62225273Sgl147354 return (de.fme_status);
62235273Sgl147354 }
62245273Sgl147354
62255273Sgl147354 /*
62265273Sgl147354 * The IO fault service error handling callback function
62275273Sgl147354 */
62287426SChenliang.Xu@Sun.COM /* ARGSUSED2 */
62295273Sgl147354 static int
e1000g_fm_error_cb(dev_info_t * dip,ddi_fm_error_t * err,const void * impl_data)62305273Sgl147354 e1000g_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data)
62315273Sgl147354 {
62325273Sgl147354 /*
62335273Sgl147354 * as the driver can always deal with an error in any dma or
62345273Sgl147354 * access handle, we can just return the fme_status value.
62355273Sgl147354 */
62365273Sgl147354 pci_ereport_post(dip, err, NULL);
62375273Sgl147354 return (err->fme_status);
62385273Sgl147354 }
62395273Sgl147354
62405273Sgl147354 static void
e1000g_fm_init(struct e1000g * Adapter)62415273Sgl147354 e1000g_fm_init(struct e1000g *Adapter)
62425273Sgl147354 {
62435273Sgl147354 ddi_iblock_cookie_t iblk;
624411236SStephen.Hanson@Sun.COM int fma_dma_flag;
62455273Sgl147354
62465273Sgl147354 /* Only register with IO Fault Services if we have some capability */
62475273Sgl147354 if (Adapter->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) {
62485273Sgl147354 e1000g_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC;
62495273Sgl147354 } else {
62505273Sgl147354 e1000g_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC;
62515273Sgl147354 }
62525273Sgl147354
62535273Sgl147354 if (Adapter->fm_capabilities & DDI_FM_DMACHK_CAPABLE) {
62545273Sgl147354 fma_dma_flag = 1;
62555273Sgl147354 } else {
62565273Sgl147354 fma_dma_flag = 0;
62575273Sgl147354 }
62585273Sgl147354
625911236SStephen.Hanson@Sun.COM (void) e1000g_set_fma_flags(fma_dma_flag);
62605273Sgl147354
62615273Sgl147354 if (Adapter->fm_capabilities) {
62625273Sgl147354
62635273Sgl147354 /* Register capabilities with IO Fault Services */
62645273Sgl147354 ddi_fm_init(Adapter->dip, &Adapter->fm_capabilities, &iblk);
62655273Sgl147354
62665273Sgl147354 /*
62675273Sgl147354 * Initialize pci ereport capabilities if ereport capable
62685273Sgl147354 */
62695273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) ||
62705273Sgl147354 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
62715273Sgl147354 pci_ereport_setup(Adapter->dip);
62725273Sgl147354
62735273Sgl147354 /*
62745273Sgl147354 * Register error callback if error callback capable
62755273Sgl147354 */
62765273Sgl147354 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
62775273Sgl147354 ddi_fm_handler_register(Adapter->dip,
62785273Sgl147354 e1000g_fm_error_cb, (void*) Adapter);
62795273Sgl147354 }
62805273Sgl147354 }
62815273Sgl147354
62825273Sgl147354 static void
e1000g_fm_fini(struct e1000g * Adapter)62835273Sgl147354 e1000g_fm_fini(struct e1000g *Adapter)
62845273Sgl147354 {
62855273Sgl147354 /* Only unregister FMA capabilities if we registered some */
62865273Sgl147354 if (Adapter->fm_capabilities) {
62875273Sgl147354
62885273Sgl147354 /*
62895273Sgl147354 * Release any resources allocated by pci_ereport_setup()
62905273Sgl147354 */
62915273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities) ||
62925273Sgl147354 DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
62935273Sgl147354 pci_ereport_teardown(Adapter->dip);
62945273Sgl147354
62955273Sgl147354 /*
62965273Sgl147354 * Un-register error callback if error callback capable
62975273Sgl147354 */
62985273Sgl147354 if (DDI_FM_ERRCB_CAP(Adapter->fm_capabilities))
62995273Sgl147354 ddi_fm_handler_unregister(Adapter->dip);
63005273Sgl147354
63015273Sgl147354 /* Unregister from IO Fault Services */
63028949SChangqing.Li@Sun.COM mutex_enter(&e1000g_rx_detach_lock);
63035273Sgl147354 ddi_fm_fini(Adapter->dip);
63048949SChangqing.Li@Sun.COM if (Adapter->priv_dip != NULL) {
63058949SChangqing.Li@Sun.COM DEVI(Adapter->priv_dip)->devi_fmhdl = NULL;
63068949SChangqing.Li@Sun.COM }
63078949SChangqing.Li@Sun.COM mutex_exit(&e1000g_rx_detach_lock);
63085273Sgl147354 }
63095273Sgl147354 }
63105273Sgl147354
63115273Sgl147354 void
e1000g_fm_ereport(struct e1000g * Adapter,char * detail)63125273Sgl147354 e1000g_fm_ereport(struct e1000g *Adapter, char *detail)
63135273Sgl147354 {
63145273Sgl147354 uint64_t ena;
63155273Sgl147354 char buf[FM_MAX_CLASS];
63165273Sgl147354
63175273Sgl147354 (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
63185273Sgl147354 ena = fm_ena_generate(0, FM_ENA_FMT1);
63195273Sgl147354 if (DDI_FM_EREPORT_CAP(Adapter->fm_capabilities)) {
63205273Sgl147354 ddi_fm_ereport_post(Adapter->dip, buf, ena, DDI_NOSLEEP,
63215273Sgl147354 FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
63225273Sgl147354 }
63235273Sgl147354 }
63246512Ssowmini
63257656SSherry.Moore@Sun.COM /*
63267656SSherry.Moore@Sun.COM * quiesce(9E) entry point.
63277656SSherry.Moore@Sun.COM *
63287656SSherry.Moore@Sun.COM * This function is called when the system is single-threaded at high
63297656SSherry.Moore@Sun.COM * PIL with preemption disabled. Therefore, this function must not be
63307656SSherry.Moore@Sun.COM * blocked.
63317656SSherry.Moore@Sun.COM *
63327656SSherry.Moore@Sun.COM * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure.
63337656SSherry.Moore@Sun.COM * DDI_FAILURE indicates an error condition and should almost never happen.
63347656SSherry.Moore@Sun.COM */
63357656SSherry.Moore@Sun.COM static int
e1000g_quiesce(dev_info_t * devinfo)63367656SSherry.Moore@Sun.COM e1000g_quiesce(dev_info_t *devinfo)
63377656SSherry.Moore@Sun.COM {
63387656SSherry.Moore@Sun.COM struct e1000g *Adapter;
63397656SSherry.Moore@Sun.COM
63407656SSherry.Moore@Sun.COM Adapter = (struct e1000g *)ddi_get_driver_private(devinfo);
63417656SSherry.Moore@Sun.COM
63427656SSherry.Moore@Sun.COM if (Adapter == NULL)
63437656SSherry.Moore@Sun.COM return (DDI_FAILURE);
63447656SSherry.Moore@Sun.COM
63457656SSherry.Moore@Sun.COM e1000g_clear_all_interrupts(Adapter);
63467656SSherry.Moore@Sun.COM
63477656SSherry.Moore@Sun.COM (void) e1000_reset_hw(&Adapter->shared);
63487656SSherry.Moore@Sun.COM
63497656SSherry.Moore@Sun.COM /* Setup our HW Tx Head & Tail descriptor pointers */
63507656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_TDH(0), 0);
63517656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_TDT(0), 0);
63527656SSherry.Moore@Sun.COM
63537656SSherry.Moore@Sun.COM /* Setup our HW Rx Head & Tail descriptor pointers */
63547656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RDH(0), 0);
63557656SSherry.Moore@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RDT(0), 0);
63567656SSherry.Moore@Sun.COM
63577656SSherry.Moore@Sun.COM return (DDI_SUCCESS);
63587656SSherry.Moore@Sun.COM }
63597656SSherry.Moore@Sun.COM
63606512Ssowmini /*
63616512Ssowmini * synchronize the adv* and en* parameters.
63626512Ssowmini *
63636512Ssowmini * See comments in <sys/dld.h> for details of the *_en_*
63646512Ssowmini * parameters. The usage of ndd for setting adv parameters will
63656512Ssowmini * synchronize all the en parameters with the e1000g parameters,
63667607STed.You@Sun.COM * implicitly disabling any settings made via dladm.
63676512Ssowmini */
63686512Ssowmini static void
e1000g_param_sync(struct e1000g * Adapter)63696512Ssowmini e1000g_param_sync(struct e1000g *Adapter)
63706512Ssowmini {
63716512Ssowmini Adapter->param_en_1000fdx = Adapter->param_adv_1000fdx;
63726512Ssowmini Adapter->param_en_1000hdx = Adapter->param_adv_1000hdx;
63736512Ssowmini Adapter->param_en_100fdx = Adapter->param_adv_100fdx;
63746512Ssowmini Adapter->param_en_100hdx = Adapter->param_adv_100hdx;
63756512Ssowmini Adapter->param_en_10fdx = Adapter->param_adv_10fdx;
63766512Ssowmini Adapter->param_en_10hdx = Adapter->param_adv_10hdx;
63776512Ssowmini }
63787607STed.You@Sun.COM
63797607STed.You@Sun.COM /*
63807607STed.You@Sun.COM * e1000g_get_driver_control - tell manageability firmware that the driver
63817607STed.You@Sun.COM * has control.
63827607STed.You@Sun.COM */
63837607STed.You@Sun.COM static void
e1000g_get_driver_control(struct e1000_hw * hw)63847607STed.You@Sun.COM e1000g_get_driver_control(struct e1000_hw *hw)
63857607STed.You@Sun.COM {
63867607STed.You@Sun.COM uint32_t ctrl_ext;
63877607STed.You@Sun.COM uint32_t swsm;
63887607STed.You@Sun.COM
63897607STed.You@Sun.COM /* tell manageability firmware the driver has taken over */
63907607STed.You@Sun.COM switch (hw->mac.type) {
63917607STed.You@Sun.COM case e1000_82573:
63927607STed.You@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM);
63937607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD);
63947607STed.You@Sun.COM break;
63957607STed.You@Sun.COM case e1000_82571:
63967607STed.You@Sun.COM case e1000_82572:
63977607STed.You@Sun.COM case e1000_82574:
63987607STed.You@Sun.COM case e1000_80003es2lan:
63997607STed.You@Sun.COM case e1000_ich8lan:
64007607STed.You@Sun.COM case e1000_ich9lan:
64017607STed.You@Sun.COM case e1000_ich10lan:
640210680SMin.Xu@Sun.COM case e1000_pchlan:
64037607STed.You@Sun.COM ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
64047607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL_EXT,
64057607STed.You@Sun.COM ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
64067607STed.You@Sun.COM break;
64077607STed.You@Sun.COM default:
64087607STed.You@Sun.COM /* no manageability firmware: do nothing */
64097607STed.You@Sun.COM break;
64107607STed.You@Sun.COM }
64117607STed.You@Sun.COM }
64127607STed.You@Sun.COM
64137607STed.You@Sun.COM /*
64147607STed.You@Sun.COM * e1000g_release_driver_control - tell manageability firmware that the driver
64157607STed.You@Sun.COM * has released control.
64167607STed.You@Sun.COM */
64177607STed.You@Sun.COM static void
e1000g_release_driver_control(struct e1000_hw * hw)64187607STed.You@Sun.COM e1000g_release_driver_control(struct e1000_hw *hw)
64197607STed.You@Sun.COM {
64207607STed.You@Sun.COM uint32_t ctrl_ext;
64217607STed.You@Sun.COM uint32_t swsm;
64227607STed.You@Sun.COM
64237607STed.You@Sun.COM /* tell manageability firmware the driver has released control */
64247607STed.You@Sun.COM switch (hw->mac.type) {
64257607STed.You@Sun.COM case e1000_82573:
64267607STed.You@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM);
64277607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
64287607STed.You@Sun.COM break;
64297607STed.You@Sun.COM case e1000_82571:
64307607STed.You@Sun.COM case e1000_82572:
64317607STed.You@Sun.COM case e1000_82574:
64327607STed.You@Sun.COM case e1000_80003es2lan:
64337607STed.You@Sun.COM case e1000_ich8lan:
64347607STed.You@Sun.COM case e1000_ich9lan:
64357607STed.You@Sun.COM case e1000_ich10lan:
643610680SMin.Xu@Sun.COM case e1000_pchlan:
64377607STed.You@Sun.COM ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
64387607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL_EXT,
64397607STed.You@Sun.COM ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
64407607STed.You@Sun.COM break;
64417607STed.You@Sun.COM default:
64427607STed.You@Sun.COM /* no manageability firmware: do nothing */
64437607STed.You@Sun.COM break;
64447607STed.You@Sun.COM }
64457607STed.You@Sun.COM }
64467722SShuguo.Yang@Sun.COM
64477722SShuguo.Yang@Sun.COM /*
64487722SShuguo.Yang@Sun.COM * Restore e1000g promiscuous mode.
64497722SShuguo.Yang@Sun.COM */
64507722SShuguo.Yang@Sun.COM static void
e1000g_restore_promisc(struct e1000g * Adapter)64517722SShuguo.Yang@Sun.COM e1000g_restore_promisc(struct e1000g *Adapter)
64527722SShuguo.Yang@Sun.COM {
64537722SShuguo.Yang@Sun.COM if (Adapter->e1000g_promisc) {
64547722SShuguo.Yang@Sun.COM uint32_t rctl;
64557722SShuguo.Yang@Sun.COM
64567722SShuguo.Yang@Sun.COM rctl = E1000_READ_REG(&Adapter->shared, E1000_RCTL);
64577722SShuguo.Yang@Sun.COM rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM);
64587722SShuguo.Yang@Sun.COM E1000_WRITE_REG(&Adapter->shared, E1000_RCTL, rctl);
64597722SShuguo.Yang@Sun.COM }
64607722SShuguo.Yang@Sun.COM }
6461