16621Sbt150084 /* 26621Sbt150084 * CDDL HEADER START 36621Sbt150084 * 49353SSamuel.Tu@Sun.COM * Copyright(c) 2007-2009 Intel Corporation. All rights reserved. 56621Sbt150084 * The contents of this file are subject to the terms of the 66621Sbt150084 * Common Development and Distribution License (the "License"). 76621Sbt150084 * You may not use this file except in compliance with the License. 86621Sbt150084 * 97656SSherry.Moore@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107656SSherry.Moore@Sun.COM * or http://www.opensolaris.org/os/licensing. 116621Sbt150084 * See the License for the specific language governing permissions 126621Sbt150084 * and limitations under the License. 136621Sbt150084 * 147656SSherry.Moore@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 157656SSherry.Moore@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 166621Sbt150084 * If applicable, add the following below this CDDL HEADER, with the 176621Sbt150084 * fields enclosed by brackets "[]" replaced with your own identifying 186621Sbt150084 * information: Portions Copyright [yyyy] [name of copyright owner] 196621Sbt150084 * 206621Sbt150084 * CDDL HEADER END 216621Sbt150084 */ 226621Sbt150084 236621Sbt150084 /* 248490SPaul.Guo@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 257656SSherry.Moore@Sun.COM * Use is subject to license terms. 267656SSherry.Moore@Sun.COM */ 277656SSherry.Moore@Sun.COM 286621Sbt150084 #include "ixgbe_sw.h" 296621Sbt150084 30*10998SChenlu.Chen@Sun.COM static char ident[] = "Intel 10Gb Ethernet"; 31*10998SChenlu.Chen@Sun.COM static char ixgbe_version[] = "ixgbe 1.1.1"; 326621Sbt150084 336621Sbt150084 /* 346621Sbt150084 * Local function protoypes 356621Sbt150084 */ 366621Sbt150084 static int ixgbe_register_mac(ixgbe_t *); 376621Sbt150084 static int ixgbe_identify_hardware(ixgbe_t *); 386621Sbt150084 static int ixgbe_regs_map(ixgbe_t *); 396621Sbt150084 static void ixgbe_init_properties(ixgbe_t *); 406621Sbt150084 static int ixgbe_init_driver_settings(ixgbe_t *); 416621Sbt150084 static void ixgbe_init_locks(ixgbe_t *); 426621Sbt150084 static void ixgbe_destroy_locks(ixgbe_t *); 436621Sbt150084 static int ixgbe_init(ixgbe_t *); 446621Sbt150084 static int ixgbe_chip_start(ixgbe_t *); 456621Sbt150084 static void ixgbe_chip_stop(ixgbe_t *); 466621Sbt150084 static int ixgbe_reset(ixgbe_t *); 476621Sbt150084 static void ixgbe_tx_clean(ixgbe_t *); 486621Sbt150084 static boolean_t ixgbe_tx_drain(ixgbe_t *); 496621Sbt150084 static boolean_t ixgbe_rx_drain(ixgbe_t *); 506621Sbt150084 static int ixgbe_alloc_rings(ixgbe_t *); 516621Sbt150084 static void ixgbe_free_rings(ixgbe_t *); 5210376SChenlu.Chen@Sun.COM static int ixgbe_alloc_rx_data(ixgbe_t *); 5310376SChenlu.Chen@Sun.COM static void ixgbe_free_rx_data(ixgbe_t *); 546621Sbt150084 static void ixgbe_setup_rings(ixgbe_t *); 556621Sbt150084 static void ixgbe_setup_rx(ixgbe_t *); 566621Sbt150084 static void ixgbe_setup_tx(ixgbe_t *); 576621Sbt150084 static void ixgbe_setup_rx_ring(ixgbe_rx_ring_t *); 586621Sbt150084 static void ixgbe_setup_tx_ring(ixgbe_tx_ring_t *); 596621Sbt150084 static void ixgbe_setup_rss(ixgbe_t *); 606621Sbt150084 static void ixgbe_init_unicst(ixgbe_t *); 618275SEric Cheng static int ixgbe_unicst_set(ixgbe_t *, const uint8_t *, int); 628275SEric Cheng static int ixgbe_unicst_find(ixgbe_t *, const uint8_t *); 636621Sbt150084 static void ixgbe_setup_multicst(ixgbe_t *); 646621Sbt150084 static void ixgbe_get_hw_state(ixgbe_t *); 656621Sbt150084 static void ixgbe_get_conf(ixgbe_t *); 6610376SChenlu.Chen@Sun.COM static void ixgbe_init_params(ixgbe_t *); 676621Sbt150084 static int ixgbe_get_prop(ixgbe_t *, char *, int, int, int); 688490SPaul.Guo@Sun.COM static void ixgbe_driver_link_check(void *); 699353SSamuel.Tu@Sun.COM static void ixgbe_sfp_check(void *); 706621Sbt150084 static void ixgbe_local_timer(void *); 716621Sbt150084 static void ixgbe_arm_watchdog_timer(ixgbe_t *); 726621Sbt150084 static void ixgbe_restart_watchdog_timer(ixgbe_t *); 736621Sbt150084 static void ixgbe_disable_adapter_interrupts(ixgbe_t *); 746621Sbt150084 static void ixgbe_enable_adapter_interrupts(ixgbe_t *); 756621Sbt150084 static boolean_t is_valid_mac_addr(uint8_t *); 766621Sbt150084 static boolean_t ixgbe_stall_check(ixgbe_t *); 776621Sbt150084 static boolean_t ixgbe_set_loopback_mode(ixgbe_t *, uint32_t); 786621Sbt150084 static void ixgbe_set_internal_mac_loopback(ixgbe_t *); 796621Sbt150084 static boolean_t ixgbe_find_mac_address(ixgbe_t *); 806621Sbt150084 static int ixgbe_alloc_intrs(ixgbe_t *); 816621Sbt150084 static int ixgbe_alloc_intr_handles(ixgbe_t *, int); 826621Sbt150084 static int ixgbe_add_intr_handlers(ixgbe_t *); 836621Sbt150084 static void ixgbe_map_rxring_to_vector(ixgbe_t *, int, int); 846621Sbt150084 static void ixgbe_map_txring_to_vector(ixgbe_t *, int, int); 859353SSamuel.Tu@Sun.COM static void ixgbe_setup_ivar(ixgbe_t *, uint16_t, uint8_t, int8_t); 869353SSamuel.Tu@Sun.COM static void ixgbe_enable_ivar(ixgbe_t *, uint16_t, int8_t); 879353SSamuel.Tu@Sun.COM static void ixgbe_disable_ivar(ixgbe_t *, uint16_t, int8_t); 889353SSamuel.Tu@Sun.COM static int ixgbe_map_intrs_to_vectors(ixgbe_t *); 896621Sbt150084 static void ixgbe_setup_adapter_vector(ixgbe_t *); 906621Sbt150084 static void ixgbe_rem_intr_handlers(ixgbe_t *); 916621Sbt150084 static void ixgbe_rem_intrs(ixgbe_t *); 926621Sbt150084 static int ixgbe_enable_intrs(ixgbe_t *); 936621Sbt150084 static int ixgbe_disable_intrs(ixgbe_t *); 946621Sbt150084 static uint_t ixgbe_intr_legacy(void *, void *); 956621Sbt150084 static uint_t ixgbe_intr_msi(void *, void *); 969353SSamuel.Tu@Sun.COM static uint_t ixgbe_intr_msix(void *, void *); 976621Sbt150084 static void ixgbe_intr_rx_work(ixgbe_rx_ring_t *); 986621Sbt150084 static void ixgbe_intr_tx_work(ixgbe_tx_ring_t *); 998490SPaul.Guo@Sun.COM static void ixgbe_intr_other_work(ixgbe_t *, uint32_t); 1006621Sbt150084 static void ixgbe_get_driver_control(struct ixgbe_hw *); 1018275SEric Cheng static int ixgbe_addmac(void *, const uint8_t *); 1028275SEric Cheng static int ixgbe_remmac(void *, const uint8_t *); 1036621Sbt150084 static void ixgbe_release_driver_control(struct ixgbe_hw *); 1046621Sbt150084 1056621Sbt150084 static int ixgbe_attach(dev_info_t *, ddi_attach_cmd_t); 1066621Sbt150084 static int ixgbe_detach(dev_info_t *, ddi_detach_cmd_t); 1076621Sbt150084 static int ixgbe_resume(dev_info_t *); 1086621Sbt150084 static int ixgbe_suspend(dev_info_t *); 1096621Sbt150084 static void ixgbe_unconfigure(dev_info_t *, ixgbe_t *); 1106621Sbt150084 static uint8_t *ixgbe_mc_table_itr(struct ixgbe_hw *, uint8_t **, uint32_t *); 1116621Sbt150084 1126621Sbt150084 static int ixgbe_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, 1136621Sbt150084 const void *impl_data); 1146621Sbt150084 static void ixgbe_fm_init(ixgbe_t *); 1156621Sbt150084 static void ixgbe_fm_fini(ixgbe_t *); 1166621Sbt150084 11710376SChenlu.Chen@Sun.COM mac_priv_prop_t ixgbe_priv_props[] = { 11810376SChenlu.Chen@Sun.COM {"_tx_copy_thresh", MAC_PROP_PERM_RW}, 11910376SChenlu.Chen@Sun.COM {"_tx_recycle_thresh", MAC_PROP_PERM_RW}, 12010376SChenlu.Chen@Sun.COM {"_tx_overload_thresh", MAC_PROP_PERM_RW}, 12110376SChenlu.Chen@Sun.COM {"_tx_resched_thresh", MAC_PROP_PERM_RW}, 12210376SChenlu.Chen@Sun.COM {"_rx_copy_thresh", MAC_PROP_PERM_RW}, 12310376SChenlu.Chen@Sun.COM {"_rx_limit_per_intr", MAC_PROP_PERM_RW}, 12410376SChenlu.Chen@Sun.COM {"_intr_throttling", MAC_PROP_PERM_RW}, 12510376SChenlu.Chen@Sun.COM {"_adv_pause_cap", MAC_PROP_PERM_READ}, 12610376SChenlu.Chen@Sun.COM {"_adv_asym_pause_cap", MAC_PROP_PERM_READ} 12710376SChenlu.Chen@Sun.COM }; 12810376SChenlu.Chen@Sun.COM 12910376SChenlu.Chen@Sun.COM #define IXGBE_MAX_PRIV_PROPS \ 13010376SChenlu.Chen@Sun.COM (sizeof (ixgbe_priv_props) / sizeof (mac_priv_prop_t)) 13110376SChenlu.Chen@Sun.COM 1326621Sbt150084 static struct cb_ops ixgbe_cb_ops = { 1336621Sbt150084 nulldev, /* cb_open */ 1346621Sbt150084 nulldev, /* cb_close */ 1356621Sbt150084 nodev, /* cb_strategy */ 1366621Sbt150084 nodev, /* cb_print */ 1376621Sbt150084 nodev, /* cb_dump */ 1386621Sbt150084 nodev, /* cb_read */ 1396621Sbt150084 nodev, /* cb_write */ 1406621Sbt150084 nodev, /* cb_ioctl */ 1416621Sbt150084 nodev, /* cb_devmap */ 1426621Sbt150084 nodev, /* cb_mmap */ 1436621Sbt150084 nodev, /* cb_segmap */ 1446621Sbt150084 nochpoll, /* cb_chpoll */ 1456621Sbt150084 ddi_prop_op, /* cb_prop_op */ 1466621Sbt150084 NULL, /* cb_stream */ 1476621Sbt150084 D_MP | D_HOTPLUG, /* cb_flag */ 1486621Sbt150084 CB_REV, /* cb_rev */ 1496621Sbt150084 nodev, /* cb_aread */ 1506621Sbt150084 nodev /* cb_awrite */ 1516621Sbt150084 }; 1526621Sbt150084 1536621Sbt150084 static struct dev_ops ixgbe_dev_ops = { 1546621Sbt150084 DEVO_REV, /* devo_rev */ 1556621Sbt150084 0, /* devo_refcnt */ 1566621Sbt150084 NULL, /* devo_getinfo */ 1576621Sbt150084 nulldev, /* devo_identify */ 1586621Sbt150084 nulldev, /* devo_probe */ 1596621Sbt150084 ixgbe_attach, /* devo_attach */ 1606621Sbt150084 ixgbe_detach, /* devo_detach */ 1616621Sbt150084 nodev, /* devo_reset */ 1626621Sbt150084 &ixgbe_cb_ops, /* devo_cb_ops */ 1636621Sbt150084 NULL, /* devo_bus_ops */ 1647656SSherry.Moore@Sun.COM ddi_power, /* devo_power */ 1657656SSherry.Moore@Sun.COM ddi_quiesce_not_supported, /* devo_quiesce */ 1666621Sbt150084 }; 1676621Sbt150084 1686621Sbt150084 static struct modldrv ixgbe_modldrv = { 1696621Sbt150084 &mod_driverops, /* Type of module. This one is a driver */ 1706621Sbt150084 ident, /* Discription string */ 1716621Sbt150084 &ixgbe_dev_ops /* driver ops */ 1726621Sbt150084 }; 1736621Sbt150084 1746621Sbt150084 static struct modlinkage ixgbe_modlinkage = { 1756621Sbt150084 MODREV_1, &ixgbe_modldrv, NULL 1766621Sbt150084 }; 1776621Sbt150084 1786621Sbt150084 /* 1796621Sbt150084 * Access attributes for register mapping 1806621Sbt150084 */ 1816621Sbt150084 ddi_device_acc_attr_t ixgbe_regs_acc_attr = { 1826621Sbt150084 DDI_DEVICE_ATTR_V0, 1836621Sbt150084 DDI_STRUCTURE_LE_ACC, 1846621Sbt150084 DDI_STRICTORDER_ACC, 1856621Sbt150084 DDI_FLAGERR_ACC 1866621Sbt150084 }; 1876621Sbt150084 1886621Sbt150084 /* 1896621Sbt150084 * Loopback property 1906621Sbt150084 */ 1916621Sbt150084 static lb_property_t lb_normal = { 1926621Sbt150084 normal, "normal", IXGBE_LB_NONE 1936621Sbt150084 }; 1946621Sbt150084 1956621Sbt150084 static lb_property_t lb_mac = { 1966621Sbt150084 internal, "MAC", IXGBE_LB_INTERNAL_MAC 1976621Sbt150084 }; 1986621Sbt150084 19910376SChenlu.Chen@Sun.COM #define IXGBE_M_CALLBACK_FLAGS \ 20010376SChenlu.Chen@Sun.COM (MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 2016621Sbt150084 2026621Sbt150084 static mac_callbacks_t ixgbe_m_callbacks = { 2036621Sbt150084 IXGBE_M_CALLBACK_FLAGS, 2046621Sbt150084 ixgbe_m_stat, 2056621Sbt150084 ixgbe_m_start, 2066621Sbt150084 ixgbe_m_stop, 2076621Sbt150084 ixgbe_m_promisc, 2086621Sbt150084 ixgbe_m_multicst, 2098275SEric Cheng NULL, 2106621Sbt150084 NULL, 2116621Sbt150084 ixgbe_m_ioctl, 21210376SChenlu.Chen@Sun.COM ixgbe_m_getcapab, 21310376SChenlu.Chen@Sun.COM NULL, 21410376SChenlu.Chen@Sun.COM NULL, 21510376SChenlu.Chen@Sun.COM ixgbe_m_setprop, 21610376SChenlu.Chen@Sun.COM ixgbe_m_getprop 2176621Sbt150084 }; 2186621Sbt150084 2196621Sbt150084 /* 2208490SPaul.Guo@Sun.COM * Initialize capabilities of each supported adapter type 2218490SPaul.Guo@Sun.COM */ 2228490SPaul.Guo@Sun.COM static adapter_info_t ixgbe_82598eb_cap = { 2238490SPaul.Guo@Sun.COM 64, /* maximum number of rx queues */ 2248490SPaul.Guo@Sun.COM 1, /* minimum number of rx queues */ 2258490SPaul.Guo@Sun.COM 8, /* default number of rx queues */ 2268490SPaul.Guo@Sun.COM 32, /* maximum number of tx queues */ 2278490SPaul.Guo@Sun.COM 1, /* minimum number of tx queues */ 2288490SPaul.Guo@Sun.COM 8, /* default number of tx queues */ 22910376SChenlu.Chen@Sun.COM 0xFFFF, /* maximum interrupt throttle rate */ 23010376SChenlu.Chen@Sun.COM 0, /* minimum interrupt throttle rate */ 23110376SChenlu.Chen@Sun.COM 200, /* default interrupt throttle rate */ 2328490SPaul.Guo@Sun.COM 18, /* maximum total msix vectors */ 2338490SPaul.Guo@Sun.COM 16, /* maximum number of ring vectors */ 2348490SPaul.Guo@Sun.COM 2, /* maximum number of other vectors */ 2358490SPaul.Guo@Sun.COM IXGBE_EICR_LSC, /* "other" interrupt types handled */ 2368490SPaul.Guo@Sun.COM (IXGBE_FLAG_DCA_CAPABLE /* capability flags */ 2378490SPaul.Guo@Sun.COM | IXGBE_FLAG_RSS_CAPABLE 2388490SPaul.Guo@Sun.COM | IXGBE_FLAG_VMDQ_CAPABLE) 2398490SPaul.Guo@Sun.COM }; 2408490SPaul.Guo@Sun.COM 2419353SSamuel.Tu@Sun.COM static adapter_info_t ixgbe_82599eb_cap = { 2429353SSamuel.Tu@Sun.COM 128, /* maximum number of rx queues */ 2439353SSamuel.Tu@Sun.COM 1, /* minimum number of rx queues */ 2449353SSamuel.Tu@Sun.COM 8, /* default number of rx queues */ 2459353SSamuel.Tu@Sun.COM 128, /* maximum number of tx queues */ 2469353SSamuel.Tu@Sun.COM 1, /* minimum number of tx queues */ 2479353SSamuel.Tu@Sun.COM 8, /* default number of tx queues */ 24810376SChenlu.Chen@Sun.COM 0xFF8, /* maximum interrupt throttle rate */ 24910376SChenlu.Chen@Sun.COM 0, /* minimum interrupt throttle rate */ 25010376SChenlu.Chen@Sun.COM 200, /* default interrupt throttle rate */ 2519353SSamuel.Tu@Sun.COM 64, /* maximum total msix vectors */ 2529353SSamuel.Tu@Sun.COM 16, /* maximum number of ring vectors */ 2539353SSamuel.Tu@Sun.COM 2, /* maximum number of other vectors */ 2549353SSamuel.Tu@Sun.COM IXGBE_EICR_LSC, /* "other" interrupt types handled */ 2559353SSamuel.Tu@Sun.COM (IXGBE_FLAG_DCA_CAPABLE /* capability flags */ 2569353SSamuel.Tu@Sun.COM | IXGBE_FLAG_RSS_CAPABLE 2579353SSamuel.Tu@Sun.COM | IXGBE_FLAG_VMDQ_CAPABLE) 2589353SSamuel.Tu@Sun.COM }; 2599353SSamuel.Tu@Sun.COM 2608490SPaul.Guo@Sun.COM /* 2616621Sbt150084 * Module Initialization Functions. 2626621Sbt150084 */ 2636621Sbt150084 2646621Sbt150084 int 2656621Sbt150084 _init(void) 2666621Sbt150084 { 2676621Sbt150084 int status; 2686621Sbt150084 2696621Sbt150084 mac_init_ops(&ixgbe_dev_ops, MODULE_NAME); 2706621Sbt150084 2716621Sbt150084 status = mod_install(&ixgbe_modlinkage); 2726621Sbt150084 2736621Sbt150084 if (status != DDI_SUCCESS) { 2746621Sbt150084 mac_fini_ops(&ixgbe_dev_ops); 2756621Sbt150084 } 2766621Sbt150084 2776621Sbt150084 return (status); 2786621Sbt150084 } 2796621Sbt150084 2806621Sbt150084 int 2816621Sbt150084 _fini(void) 2826621Sbt150084 { 2836621Sbt150084 int status; 2846621Sbt150084 2856621Sbt150084 status = mod_remove(&ixgbe_modlinkage); 2866621Sbt150084 2876621Sbt150084 if (status == DDI_SUCCESS) { 2886621Sbt150084 mac_fini_ops(&ixgbe_dev_ops); 2896621Sbt150084 } 2906621Sbt150084 2916621Sbt150084 return (status); 2926621Sbt150084 } 2936621Sbt150084 2946621Sbt150084 int 2956621Sbt150084 _info(struct modinfo *modinfop) 2966621Sbt150084 { 2976621Sbt150084 int status; 2986621Sbt150084 2996621Sbt150084 status = mod_info(&ixgbe_modlinkage, modinfop); 3006621Sbt150084 3016621Sbt150084 return (status); 3026621Sbt150084 } 3036621Sbt150084 3046621Sbt150084 /* 3056621Sbt150084 * ixgbe_attach - Driver attach. 3066621Sbt150084 * 3076621Sbt150084 * This function is the device specific initialization entry 3086621Sbt150084 * point. This entry point is required and must be written. 3096621Sbt150084 * The DDI_ATTACH command must be provided in the attach entry 3106621Sbt150084 * point. When attach() is called with cmd set to DDI_ATTACH, 3116621Sbt150084 * all normal kernel services (such as kmem_alloc(9F)) are 3126621Sbt150084 * available for use by the driver. 3136621Sbt150084 * 3146621Sbt150084 * The attach() function will be called once for each instance 3156621Sbt150084 * of the device on the system with cmd set to DDI_ATTACH. 3166621Sbt150084 * Until attach() succeeds, the only driver entry points which 3176621Sbt150084 * may be called are open(9E) and getinfo(9E). 3186621Sbt150084 */ 3196621Sbt150084 static int 3206621Sbt150084 ixgbe_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) 3216621Sbt150084 { 3226621Sbt150084 ixgbe_t *ixgbe; 3236621Sbt150084 struct ixgbe_osdep *osdep; 3246621Sbt150084 struct ixgbe_hw *hw; 3256621Sbt150084 int instance; 3268490SPaul.Guo@Sun.COM char taskqname[32]; 3276621Sbt150084 3286621Sbt150084 /* 3296621Sbt150084 * Check the command and perform corresponding operations 3306621Sbt150084 */ 3316621Sbt150084 switch (cmd) { 3326621Sbt150084 default: 3336621Sbt150084 return (DDI_FAILURE); 3346621Sbt150084 3356621Sbt150084 case DDI_RESUME: 3366621Sbt150084 return (ixgbe_resume(devinfo)); 3376621Sbt150084 3386621Sbt150084 case DDI_ATTACH: 3396621Sbt150084 break; 3406621Sbt150084 } 3416621Sbt150084 3426621Sbt150084 /* Get the device instance */ 3436621Sbt150084 instance = ddi_get_instance(devinfo); 3446621Sbt150084 3456621Sbt150084 /* Allocate memory for the instance data structure */ 3466621Sbt150084 ixgbe = kmem_zalloc(sizeof (ixgbe_t), KM_SLEEP); 3476621Sbt150084 3486621Sbt150084 ixgbe->dip = devinfo; 3496621Sbt150084 ixgbe->instance = instance; 3506621Sbt150084 3516621Sbt150084 hw = &ixgbe->hw; 3526621Sbt150084 osdep = &ixgbe->osdep; 3536621Sbt150084 hw->back = osdep; 3546621Sbt150084 osdep->ixgbe = ixgbe; 3556621Sbt150084 3566621Sbt150084 /* Attach the instance pointer to the dev_info data structure */ 3576621Sbt150084 ddi_set_driver_private(devinfo, ixgbe); 3586621Sbt150084 3596621Sbt150084 /* 3606621Sbt150084 * Initialize for fma support 3616621Sbt150084 */ 3627167Sgg161487 ixgbe->fm_capabilities = ixgbe_get_prop(ixgbe, PROP_FM_CAPABLE, 3636621Sbt150084 0, 0x0f, DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE | 3646621Sbt150084 DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE); 3656621Sbt150084 ixgbe_fm_init(ixgbe); 3666621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_FM_INIT; 3676621Sbt150084 3686621Sbt150084 /* 3696621Sbt150084 * Map PCI config space registers 3706621Sbt150084 */ 3716621Sbt150084 if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) { 3726621Sbt150084 ixgbe_error(ixgbe, "Failed to map PCI configurations"); 3736621Sbt150084 goto attach_fail; 3746621Sbt150084 } 3756621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG; 3766621Sbt150084 3776621Sbt150084 /* 3786621Sbt150084 * Identify the chipset family 3796621Sbt150084 */ 3806621Sbt150084 if (ixgbe_identify_hardware(ixgbe) != IXGBE_SUCCESS) { 3816621Sbt150084 ixgbe_error(ixgbe, "Failed to identify hardware"); 3826621Sbt150084 goto attach_fail; 3836621Sbt150084 } 3846621Sbt150084 3856621Sbt150084 /* 3866621Sbt150084 * Map device registers 3876621Sbt150084 */ 3886621Sbt150084 if (ixgbe_regs_map(ixgbe) != IXGBE_SUCCESS) { 3896621Sbt150084 ixgbe_error(ixgbe, "Failed to map device registers"); 3906621Sbt150084 goto attach_fail; 3916621Sbt150084 } 3926621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_REGS_MAP; 3936621Sbt150084 3946621Sbt150084 /* 3956621Sbt150084 * Initialize driver parameters 3966621Sbt150084 */ 3976621Sbt150084 ixgbe_init_properties(ixgbe); 3986621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_PROPS; 3996621Sbt150084 4006621Sbt150084 /* 4016621Sbt150084 * Allocate interrupts 4026621Sbt150084 */ 4036621Sbt150084 if (ixgbe_alloc_intrs(ixgbe) != IXGBE_SUCCESS) { 4046621Sbt150084 ixgbe_error(ixgbe, "Failed to allocate interrupts"); 4056621Sbt150084 goto attach_fail; 4066621Sbt150084 } 4076621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_ALLOC_INTR; 4086621Sbt150084 4096621Sbt150084 /* 4106621Sbt150084 * Allocate rx/tx rings based on the ring numbers. 4116621Sbt150084 * The actual numbers of rx/tx rings are decided by the number of 4126621Sbt150084 * allocated interrupt vectors, so we should allocate the rings after 4136621Sbt150084 * interrupts are allocated. 4146621Sbt150084 */ 4156621Sbt150084 if (ixgbe_alloc_rings(ixgbe) != IXGBE_SUCCESS) { 4166621Sbt150084 ixgbe_error(ixgbe, "Failed to allocate rx and tx rings"); 4176621Sbt150084 goto attach_fail; 4186621Sbt150084 } 4196621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_ALLOC_RINGS; 4206621Sbt150084 4216621Sbt150084 /* 4226621Sbt150084 * Map rings to interrupt vectors 4236621Sbt150084 */ 4249353SSamuel.Tu@Sun.COM if (ixgbe_map_intrs_to_vectors(ixgbe) != IXGBE_SUCCESS) { 4259353SSamuel.Tu@Sun.COM ixgbe_error(ixgbe, "Failed to map interrupts to vectors"); 4266621Sbt150084 goto attach_fail; 4276621Sbt150084 } 4286621Sbt150084 4296621Sbt150084 /* 4306621Sbt150084 * Add interrupt handlers 4316621Sbt150084 */ 4326621Sbt150084 if (ixgbe_add_intr_handlers(ixgbe) != IXGBE_SUCCESS) { 4336621Sbt150084 ixgbe_error(ixgbe, "Failed to add interrupt handlers"); 4346621Sbt150084 goto attach_fail; 4356621Sbt150084 } 4366621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_ADD_INTR; 4376621Sbt150084 4386621Sbt150084 /* 4398490SPaul.Guo@Sun.COM * Create a taskq for link-status-change 4408490SPaul.Guo@Sun.COM */ 4418490SPaul.Guo@Sun.COM (void) sprintf(taskqname, "ixgbe%d_taskq", instance); 4428490SPaul.Guo@Sun.COM if ((ixgbe->lsc_taskq = ddi_taskq_create(devinfo, taskqname, 4438490SPaul.Guo@Sun.COM 1, TASKQ_DEFAULTPRI, 0)) == NULL) { 4448490SPaul.Guo@Sun.COM ixgbe_error(ixgbe, "taskq_create failed"); 4458490SPaul.Guo@Sun.COM goto attach_fail; 4468490SPaul.Guo@Sun.COM } 4478490SPaul.Guo@Sun.COM ixgbe->attach_progress |= ATTACH_PROGRESS_LSC_TASKQ; 4488490SPaul.Guo@Sun.COM 4498490SPaul.Guo@Sun.COM /* 4506621Sbt150084 * Initialize driver parameters 4516621Sbt150084 */ 4526621Sbt150084 if (ixgbe_init_driver_settings(ixgbe) != IXGBE_SUCCESS) { 4536621Sbt150084 ixgbe_error(ixgbe, "Failed to initialize driver settings"); 4546621Sbt150084 goto attach_fail; 4556621Sbt150084 } 4566621Sbt150084 4576621Sbt150084 /* 4586621Sbt150084 * Initialize mutexes for this device. 4596621Sbt150084 * Do this before enabling the interrupt handler and 4606621Sbt150084 * register the softint to avoid the condition where 4616621Sbt150084 * interrupt handler can try using uninitialized mutex. 4626621Sbt150084 */ 4636621Sbt150084 ixgbe_init_locks(ixgbe); 4646621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_LOCKS; 4656621Sbt150084 4666621Sbt150084 /* 4676621Sbt150084 * Initialize chipset hardware 4686621Sbt150084 */ 4696621Sbt150084 if (ixgbe_init(ixgbe) != IXGBE_SUCCESS) { 4706621Sbt150084 ixgbe_error(ixgbe, "Failed to initialize adapter"); 4716621Sbt150084 goto attach_fail; 4726621Sbt150084 } 4736621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_INIT; 4746621Sbt150084 4756621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.cfg_handle) != DDI_FM_OK) { 4766621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST); 4776621Sbt150084 goto attach_fail; 4786621Sbt150084 } 4796621Sbt150084 4806621Sbt150084 /* 4816621Sbt150084 * Initialize statistics 4826621Sbt150084 */ 4836621Sbt150084 if (ixgbe_init_stats(ixgbe) != IXGBE_SUCCESS) { 4846621Sbt150084 ixgbe_error(ixgbe, "Failed to initialize statistics"); 4856621Sbt150084 goto attach_fail; 4866621Sbt150084 } 4876621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_STATS; 4886621Sbt150084 4896621Sbt150084 /* 4906621Sbt150084 * Register the driver to the MAC 4916621Sbt150084 */ 4926621Sbt150084 if (ixgbe_register_mac(ixgbe) != IXGBE_SUCCESS) { 4936621Sbt150084 ixgbe_error(ixgbe, "Failed to register MAC"); 4946621Sbt150084 goto attach_fail; 4956621Sbt150084 } 4968490SPaul.Guo@Sun.COM mac_link_update(ixgbe->mac_hdl, LINK_STATE_UNKNOWN); 4976621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_MAC; 4986621Sbt150084 4996621Sbt150084 /* 5006621Sbt150084 * Now that mutex locks are initialized, and the chip is also 5016621Sbt150084 * initialized, enable interrupts. 5026621Sbt150084 */ 5036621Sbt150084 if (ixgbe_enable_intrs(ixgbe) != IXGBE_SUCCESS) { 5046621Sbt150084 ixgbe_error(ixgbe, "Failed to enable DDI interrupts"); 5056621Sbt150084 goto attach_fail; 5066621Sbt150084 } 5076621Sbt150084 ixgbe->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR; 5086621Sbt150084 509*10998SChenlu.Chen@Sun.COM ixgbe_log(ixgbe, "%s", ixgbe_version); 5106621Sbt150084 ixgbe->ixgbe_state |= IXGBE_INITIALIZED; 5116621Sbt150084 5126621Sbt150084 return (DDI_SUCCESS); 5136621Sbt150084 5146621Sbt150084 attach_fail: 5156621Sbt150084 ixgbe_unconfigure(devinfo, ixgbe); 5166621Sbt150084 return (DDI_FAILURE); 5176621Sbt150084 } 5186621Sbt150084 5196621Sbt150084 /* 5206621Sbt150084 * ixgbe_detach - Driver detach. 5216621Sbt150084 * 5226621Sbt150084 * The detach() function is the complement of the attach routine. 5236621Sbt150084 * If cmd is set to DDI_DETACH, detach() is used to remove the 5246621Sbt150084 * state associated with a given instance of a device node 5256621Sbt150084 * prior to the removal of that instance from the system. 5266621Sbt150084 * 5276621Sbt150084 * The detach() function will be called once for each instance 5286621Sbt150084 * of the device for which there has been a successful attach() 5296621Sbt150084 * once there are no longer any opens on the device. 5306621Sbt150084 * 5316621Sbt150084 * Interrupts routine are disabled, All memory allocated by this 5326621Sbt150084 * driver are freed. 5336621Sbt150084 */ 5346621Sbt150084 static int 5356621Sbt150084 ixgbe_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd) 5366621Sbt150084 { 5376621Sbt150084 ixgbe_t *ixgbe; 5386621Sbt150084 5396621Sbt150084 /* 5406621Sbt150084 * Check detach command 5416621Sbt150084 */ 5426621Sbt150084 switch (cmd) { 5436621Sbt150084 default: 5446621Sbt150084 return (DDI_FAILURE); 5456621Sbt150084 5466621Sbt150084 case DDI_SUSPEND: 5476621Sbt150084 return (ixgbe_suspend(devinfo)); 5486621Sbt150084 5496621Sbt150084 case DDI_DETACH: 5506621Sbt150084 break; 5516621Sbt150084 } 5526621Sbt150084 5536621Sbt150084 5546621Sbt150084 /* 5556621Sbt150084 * Get the pointer to the driver private data structure 5566621Sbt150084 */ 5576621Sbt150084 ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo); 5586621Sbt150084 if (ixgbe == NULL) 5596621Sbt150084 return (DDI_FAILURE); 5606621Sbt150084 5616621Sbt150084 /* 5626621Sbt150084 * Unregister MAC. If failed, we have to fail the detach 5636621Sbt150084 */ 5646621Sbt150084 if (mac_unregister(ixgbe->mac_hdl) != 0) { 5656621Sbt150084 ixgbe_error(ixgbe, "Failed to unregister MAC"); 5666621Sbt150084 return (DDI_FAILURE); 5676621Sbt150084 } 5686621Sbt150084 ixgbe->attach_progress &= ~ATTACH_PROGRESS_MAC; 5696621Sbt150084 5706621Sbt150084 /* 5716621Sbt150084 * If the device is still running, it needs to be stopped first. 5726621Sbt150084 * This check is necessary because under some specific circumstances, 5736621Sbt150084 * the detach routine can be called without stopping the interface 5746621Sbt150084 * first. 5756621Sbt150084 */ 5766621Sbt150084 mutex_enter(&ixgbe->gen_lock); 5776621Sbt150084 if (ixgbe->ixgbe_state & IXGBE_STARTED) { 5786621Sbt150084 ixgbe->ixgbe_state &= ~IXGBE_STARTED; 57910376SChenlu.Chen@Sun.COM ixgbe_stop(ixgbe, B_TRUE); 5806621Sbt150084 mutex_exit(&ixgbe->gen_lock); 5816621Sbt150084 /* Disable and stop the watchdog timer */ 5826621Sbt150084 ixgbe_disable_watchdog_timer(ixgbe); 5836621Sbt150084 } else 5846621Sbt150084 mutex_exit(&ixgbe->gen_lock); 5856621Sbt150084 5866621Sbt150084 /* 5876621Sbt150084 * Check if there are still rx buffers held by the upper layer. 5886621Sbt150084 * If so, fail the detach. 5896621Sbt150084 */ 5906621Sbt150084 if (!ixgbe_rx_drain(ixgbe)) 5916621Sbt150084 return (DDI_FAILURE); 5926621Sbt150084 5936621Sbt150084 /* 5946621Sbt150084 * Do the remaining unconfigure routines 5956621Sbt150084 */ 5966621Sbt150084 ixgbe_unconfigure(devinfo, ixgbe); 5976621Sbt150084 5986621Sbt150084 return (DDI_SUCCESS); 5996621Sbt150084 } 6006621Sbt150084 6016621Sbt150084 static void 6026621Sbt150084 ixgbe_unconfigure(dev_info_t *devinfo, ixgbe_t *ixgbe) 6036621Sbt150084 { 6046621Sbt150084 /* 6056621Sbt150084 * Disable interrupt 6066621Sbt150084 */ 6076621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) { 6086621Sbt150084 (void) ixgbe_disable_intrs(ixgbe); 6096621Sbt150084 } 6106621Sbt150084 6116621Sbt150084 /* 6126621Sbt150084 * Unregister MAC 6136621Sbt150084 */ 6146621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_MAC) { 6156621Sbt150084 (void) mac_unregister(ixgbe->mac_hdl); 6166621Sbt150084 } 6176621Sbt150084 6186621Sbt150084 /* 6196621Sbt150084 * Free statistics 6206621Sbt150084 */ 6216621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_STATS) { 6226621Sbt150084 kstat_delete((kstat_t *)ixgbe->ixgbe_ks); 6236621Sbt150084 } 6246621Sbt150084 6256621Sbt150084 /* 6266621Sbt150084 * Remove interrupt handlers 6276621Sbt150084 */ 6286621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_ADD_INTR) { 6296621Sbt150084 ixgbe_rem_intr_handlers(ixgbe); 6306621Sbt150084 } 6316621Sbt150084 6326621Sbt150084 /* 6338490SPaul.Guo@Sun.COM * Remove taskq for link-status-change 6348490SPaul.Guo@Sun.COM */ 6358490SPaul.Guo@Sun.COM if (ixgbe->attach_progress & ATTACH_PROGRESS_LSC_TASKQ) { 6368490SPaul.Guo@Sun.COM ddi_taskq_destroy(ixgbe->lsc_taskq); 6378490SPaul.Guo@Sun.COM } 6388490SPaul.Guo@Sun.COM 6398490SPaul.Guo@Sun.COM /* 6406621Sbt150084 * Remove interrupts 6416621Sbt150084 */ 6426621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_ALLOC_INTR) { 6436621Sbt150084 ixgbe_rem_intrs(ixgbe); 6446621Sbt150084 } 6456621Sbt150084 6466621Sbt150084 /* 6476621Sbt150084 * Remove driver properties 6486621Sbt150084 */ 6496621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_PROPS) { 6506621Sbt150084 (void) ddi_prop_remove_all(devinfo); 6516621Sbt150084 } 6526621Sbt150084 6536621Sbt150084 /* 6546621Sbt150084 * Stop the chipset 6556621Sbt150084 */ 6566621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_INIT) { 6576621Sbt150084 mutex_enter(&ixgbe->gen_lock); 6586621Sbt150084 ixgbe_chip_stop(ixgbe); 6596621Sbt150084 mutex_exit(&ixgbe->gen_lock); 6606621Sbt150084 } 6616621Sbt150084 6626621Sbt150084 /* 6636621Sbt150084 * Free register handle 6646621Sbt150084 */ 6656621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_REGS_MAP) { 6666621Sbt150084 if (ixgbe->osdep.reg_handle != NULL) 6676621Sbt150084 ddi_regs_map_free(&ixgbe->osdep.reg_handle); 6686621Sbt150084 } 6696621Sbt150084 6706621Sbt150084 /* 6716621Sbt150084 * Free PCI config handle 6726621Sbt150084 */ 6736621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) { 6746621Sbt150084 if (ixgbe->osdep.cfg_handle != NULL) 6756621Sbt150084 pci_config_teardown(&ixgbe->osdep.cfg_handle); 6766621Sbt150084 } 6776621Sbt150084 6786621Sbt150084 /* 6796621Sbt150084 * Free locks 6806621Sbt150084 */ 6816621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_LOCKS) { 6826621Sbt150084 ixgbe_destroy_locks(ixgbe); 6836621Sbt150084 } 6846621Sbt150084 6856621Sbt150084 /* 6866621Sbt150084 * Free the rx/tx rings 6876621Sbt150084 */ 6886621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_ALLOC_RINGS) { 6896621Sbt150084 ixgbe_free_rings(ixgbe); 6906621Sbt150084 } 6916621Sbt150084 6926621Sbt150084 /* 6936621Sbt150084 * Unregister FMA capabilities 6946621Sbt150084 */ 6956621Sbt150084 if (ixgbe->attach_progress & ATTACH_PROGRESS_FM_INIT) { 6966621Sbt150084 ixgbe_fm_fini(ixgbe); 6976621Sbt150084 } 6986621Sbt150084 6996621Sbt150084 /* 7006621Sbt150084 * Free the driver data structure 7016621Sbt150084 */ 7026621Sbt150084 kmem_free(ixgbe, sizeof (ixgbe_t)); 7036621Sbt150084 7046621Sbt150084 ddi_set_driver_private(devinfo, NULL); 7056621Sbt150084 } 7066621Sbt150084 7076621Sbt150084 /* 7086621Sbt150084 * ixgbe_register_mac - Register the driver and its function pointers with 7096621Sbt150084 * the GLD interface. 7106621Sbt150084 */ 7116621Sbt150084 static int 7126621Sbt150084 ixgbe_register_mac(ixgbe_t *ixgbe) 7136621Sbt150084 { 7146621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 7156621Sbt150084 mac_register_t *mac; 7166621Sbt150084 int status; 7176621Sbt150084 7186621Sbt150084 if ((mac = mac_alloc(MAC_VERSION)) == NULL) 7196621Sbt150084 return (IXGBE_FAILURE); 7206621Sbt150084 7216621Sbt150084 mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 7226621Sbt150084 mac->m_driver = ixgbe; 7236621Sbt150084 mac->m_dip = ixgbe->dip; 7246621Sbt150084 mac->m_src_addr = hw->mac.addr; 7256621Sbt150084 mac->m_callbacks = &ixgbe_m_callbacks; 7266621Sbt150084 mac->m_min_sdu = 0; 7276621Sbt150084 mac->m_max_sdu = ixgbe->default_mtu; 7286621Sbt150084 mac->m_margin = VLAN_TAGSZ; 72910376SChenlu.Chen@Sun.COM mac->m_priv_props = ixgbe_priv_props; 73010376SChenlu.Chen@Sun.COM mac->m_priv_prop_count = IXGBE_MAX_PRIV_PROPS; 7318275SEric Cheng mac->m_v12n = MAC_VIRT_LEVEL1; 7326621Sbt150084 7336621Sbt150084 status = mac_register(mac, &ixgbe->mac_hdl); 7346621Sbt150084 7356621Sbt150084 mac_free(mac); 7366621Sbt150084 7376621Sbt150084 return ((status == 0) ? IXGBE_SUCCESS : IXGBE_FAILURE); 7386621Sbt150084 } 7396621Sbt150084 7406621Sbt150084 /* 7416621Sbt150084 * ixgbe_identify_hardware - Identify the type of the chipset. 7426621Sbt150084 */ 7436621Sbt150084 static int 7446621Sbt150084 ixgbe_identify_hardware(ixgbe_t *ixgbe) 7456621Sbt150084 { 7466621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 7476621Sbt150084 struct ixgbe_osdep *osdep = &ixgbe->osdep; 7486621Sbt150084 7496621Sbt150084 /* 7506621Sbt150084 * Get the device id 7516621Sbt150084 */ 7526621Sbt150084 hw->vendor_id = 7536621Sbt150084 pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID); 7546621Sbt150084 hw->device_id = 7556621Sbt150084 pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID); 7566621Sbt150084 hw->revision_id = 7576621Sbt150084 pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID); 7586621Sbt150084 hw->subsystem_device_id = 7596621Sbt150084 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID); 7606621Sbt150084 hw->subsystem_vendor_id = 7616621Sbt150084 pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID); 7626621Sbt150084 7638490SPaul.Guo@Sun.COM /* 7648490SPaul.Guo@Sun.COM * Set the mac type of the adapter based on the device id 7658490SPaul.Guo@Sun.COM */ 7668490SPaul.Guo@Sun.COM if (ixgbe_set_mac_type(hw) != IXGBE_SUCCESS) { 7678490SPaul.Guo@Sun.COM return (IXGBE_FAILURE); 7688490SPaul.Guo@Sun.COM } 7698490SPaul.Guo@Sun.COM 7708490SPaul.Guo@Sun.COM /* 7718490SPaul.Guo@Sun.COM * Install adapter capabilities 7728490SPaul.Guo@Sun.COM */ 7738490SPaul.Guo@Sun.COM switch (hw->mac.type) { 7748490SPaul.Guo@Sun.COM case ixgbe_mac_82598EB: 7759353SSamuel.Tu@Sun.COM ixgbe_log(ixgbe, "identify 82598 adapter\n"); 7768490SPaul.Guo@Sun.COM ixgbe->capab = &ixgbe_82598eb_cap; 7778490SPaul.Guo@Sun.COM 7788490SPaul.Guo@Sun.COM if (ixgbe_get_media_type(hw) == ixgbe_media_type_copper) { 7798490SPaul.Guo@Sun.COM ixgbe->capab->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; 7808490SPaul.Guo@Sun.COM ixgbe->capab->other_intr |= IXGBE_EICR_GPI_SDP1; 7818490SPaul.Guo@Sun.COM } 7829353SSamuel.Tu@Sun.COM ixgbe->capab->other_intr |= IXGBE_EICR_LSC; 7839353SSamuel.Tu@Sun.COM 7849353SSamuel.Tu@Sun.COM break; 7859353SSamuel.Tu@Sun.COM case ixgbe_mac_82599EB: 7869353SSamuel.Tu@Sun.COM ixgbe_log(ixgbe, "identify 82599 adapter\n"); 7879353SSamuel.Tu@Sun.COM ixgbe->capab = &ixgbe_82599eb_cap; 7889353SSamuel.Tu@Sun.COM 7899353SSamuel.Tu@Sun.COM ixgbe->capab->other_intr = (IXGBE_EICR_GPI_SDP1 | 7909353SSamuel.Tu@Sun.COM IXGBE_EICR_GPI_SDP2 | IXGBE_EICR_LSC); 7918490SPaul.Guo@Sun.COM 7928490SPaul.Guo@Sun.COM break; 7938490SPaul.Guo@Sun.COM default: 7948490SPaul.Guo@Sun.COM ixgbe_log(ixgbe, 7958490SPaul.Guo@Sun.COM "adapter not supported in ixgbe_identify_hardware(): %d\n", 7968490SPaul.Guo@Sun.COM hw->mac.type); 7978490SPaul.Guo@Sun.COM return (IXGBE_FAILURE); 7988490SPaul.Guo@Sun.COM } 7998490SPaul.Guo@Sun.COM 8006621Sbt150084 return (IXGBE_SUCCESS); 8016621Sbt150084 } 8026621Sbt150084 8036621Sbt150084 /* 8046621Sbt150084 * ixgbe_regs_map - Map the device registers. 8056621Sbt150084 * 8066621Sbt150084 */ 8076621Sbt150084 static int 8086621Sbt150084 ixgbe_regs_map(ixgbe_t *ixgbe) 8096621Sbt150084 { 8106621Sbt150084 dev_info_t *devinfo = ixgbe->dip; 8116621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 8126621Sbt150084 struct ixgbe_osdep *osdep = &ixgbe->osdep; 8136621Sbt150084 off_t mem_size; 8146621Sbt150084 8156621Sbt150084 /* 8166621Sbt150084 * First get the size of device registers to be mapped. 8176621Sbt150084 */ 8189353SSamuel.Tu@Sun.COM if (ddi_dev_regsize(devinfo, IXGBE_ADAPTER_REGSET, &mem_size) 8199353SSamuel.Tu@Sun.COM != DDI_SUCCESS) { 8206621Sbt150084 return (IXGBE_FAILURE); 8216621Sbt150084 } 8226621Sbt150084 8236621Sbt150084 /* 8246621Sbt150084 * Call ddi_regs_map_setup() to map registers 8256621Sbt150084 */ 8269353SSamuel.Tu@Sun.COM if ((ddi_regs_map_setup(devinfo, IXGBE_ADAPTER_REGSET, 8276621Sbt150084 (caddr_t *)&hw->hw_addr, 0, 8286621Sbt150084 mem_size, &ixgbe_regs_acc_attr, 8296621Sbt150084 &osdep->reg_handle)) != DDI_SUCCESS) { 8306621Sbt150084 return (IXGBE_FAILURE); 8316621Sbt150084 } 8326621Sbt150084 8336621Sbt150084 return (IXGBE_SUCCESS); 8346621Sbt150084 } 8356621Sbt150084 8366621Sbt150084 /* 8376621Sbt150084 * ixgbe_init_properties - Initialize driver properties. 8386621Sbt150084 */ 8396621Sbt150084 static void 8406621Sbt150084 ixgbe_init_properties(ixgbe_t *ixgbe) 8416621Sbt150084 { 8426621Sbt150084 /* 8436621Sbt150084 * Get conf file properties, including link settings 8446621Sbt150084 * jumbo frames, ring number, descriptor number, etc. 8456621Sbt150084 */ 8466621Sbt150084 ixgbe_get_conf(ixgbe); 84710376SChenlu.Chen@Sun.COM 84810376SChenlu.Chen@Sun.COM ixgbe_init_params(ixgbe); 8496621Sbt150084 } 8506621Sbt150084 8516621Sbt150084 /* 8526621Sbt150084 * ixgbe_init_driver_settings - Initialize driver settings. 8536621Sbt150084 * 8546621Sbt150084 * The settings include hardware function pointers, bus information, 8556621Sbt150084 * rx/tx rings settings, link state, and any other parameters that 8566621Sbt150084 * need to be setup during driver initialization. 8576621Sbt150084 */ 8586621Sbt150084 static int 8596621Sbt150084 ixgbe_init_driver_settings(ixgbe_t *ixgbe) 8606621Sbt150084 { 8616621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 8628275SEric Cheng dev_info_t *devinfo = ixgbe->dip; 8636621Sbt150084 ixgbe_rx_ring_t *rx_ring; 8646621Sbt150084 ixgbe_tx_ring_t *tx_ring; 8656621Sbt150084 uint32_t rx_size; 8666621Sbt150084 uint32_t tx_size; 8676621Sbt150084 int i; 8686621Sbt150084 8696621Sbt150084 /* 8706621Sbt150084 * Initialize chipset specific hardware function pointers 8716621Sbt150084 */ 8726621Sbt150084 if (ixgbe_init_shared_code(hw) != IXGBE_SUCCESS) { 8736621Sbt150084 return (IXGBE_FAILURE); 8746621Sbt150084 } 8756621Sbt150084 8766621Sbt150084 /* 8778275SEric Cheng * Get the system page size 8788275SEric Cheng */ 8798275SEric Cheng ixgbe->sys_page_size = ddi_ptob(devinfo, (ulong_t)1); 8808275SEric Cheng 8818275SEric Cheng /* 8826621Sbt150084 * Set rx buffer size 8836621Sbt150084 * 8846621Sbt150084 * The IP header alignment room is counted in the calculation. 8856621Sbt150084 * The rx buffer size is in unit of 1K that is required by the 8866621Sbt150084 * chipset hardware. 8876621Sbt150084 */ 8886621Sbt150084 rx_size = ixgbe->max_frame_size + IPHDR_ALIGN_ROOM; 8896621Sbt150084 ixgbe->rx_buf_size = ((rx_size >> 10) + 8906621Sbt150084 ((rx_size & (((uint32_t)1 << 10) - 1)) > 0 ? 1 : 0)) << 10; 8916621Sbt150084 8926621Sbt150084 /* 8936621Sbt150084 * Set tx buffer size 8946621Sbt150084 */ 8956621Sbt150084 tx_size = ixgbe->max_frame_size; 8966621Sbt150084 ixgbe->tx_buf_size = ((tx_size >> 10) + 8976621Sbt150084 ((tx_size & (((uint32_t)1 << 10) - 1)) > 0 ? 1 : 0)) << 10; 8986621Sbt150084 8996621Sbt150084 /* 9006621Sbt150084 * Initialize rx/tx rings parameters 9016621Sbt150084 */ 9026621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) { 9036621Sbt150084 rx_ring = &ixgbe->rx_rings[i]; 9046621Sbt150084 rx_ring->index = i; 9056621Sbt150084 rx_ring->ixgbe = ixgbe; 9066621Sbt150084 } 9076621Sbt150084 9086621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 9096621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 9106621Sbt150084 tx_ring->index = i; 9116621Sbt150084 tx_ring->ixgbe = ixgbe; 9126621Sbt150084 if (ixgbe->tx_head_wb_enable) 9136621Sbt150084 tx_ring->tx_recycle = ixgbe_tx_recycle_head_wb; 9146621Sbt150084 else 9156621Sbt150084 tx_ring->tx_recycle = ixgbe_tx_recycle_legacy; 9166621Sbt150084 9176621Sbt150084 tx_ring->ring_size = ixgbe->tx_ring_size; 9186621Sbt150084 tx_ring->free_list_size = ixgbe->tx_ring_size + 9196621Sbt150084 (ixgbe->tx_ring_size >> 1); 9206621Sbt150084 } 9216621Sbt150084 9226621Sbt150084 /* 9236621Sbt150084 * Initialize values of interrupt throttling rate 9246621Sbt150084 */ 9259353SSamuel.Tu@Sun.COM for (i = 1; i < MAX_INTR_VECTOR; i++) 9266621Sbt150084 ixgbe->intr_throttling[i] = ixgbe->intr_throttling[0]; 9276621Sbt150084 9286621Sbt150084 /* 9296621Sbt150084 * The initial link state should be "unknown" 9306621Sbt150084 */ 9316621Sbt150084 ixgbe->link_state = LINK_STATE_UNKNOWN; 9329353SSamuel.Tu@Sun.COM 9336621Sbt150084 return (IXGBE_SUCCESS); 9346621Sbt150084 } 9356621Sbt150084 9366621Sbt150084 /* 9376621Sbt150084 * ixgbe_init_locks - Initialize locks. 9386621Sbt150084 */ 9396621Sbt150084 static void 9406621Sbt150084 ixgbe_init_locks(ixgbe_t *ixgbe) 9416621Sbt150084 { 9426621Sbt150084 ixgbe_rx_ring_t *rx_ring; 9436621Sbt150084 ixgbe_tx_ring_t *tx_ring; 9446621Sbt150084 int i; 9456621Sbt150084 9466621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) { 9476621Sbt150084 rx_ring = &ixgbe->rx_rings[i]; 9486621Sbt150084 mutex_init(&rx_ring->rx_lock, NULL, 9496621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9506621Sbt150084 } 9516621Sbt150084 9526621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 9536621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 9546621Sbt150084 mutex_init(&tx_ring->tx_lock, NULL, 9556621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9566621Sbt150084 mutex_init(&tx_ring->recycle_lock, NULL, 9576621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9586621Sbt150084 mutex_init(&tx_ring->tcb_head_lock, NULL, 9596621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9606621Sbt150084 mutex_init(&tx_ring->tcb_tail_lock, NULL, 9616621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9626621Sbt150084 } 9636621Sbt150084 9646621Sbt150084 mutex_init(&ixgbe->gen_lock, NULL, 9656621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9666621Sbt150084 9676621Sbt150084 mutex_init(&ixgbe->watchdog_lock, NULL, 9686621Sbt150084 MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri)); 9696621Sbt150084 } 9706621Sbt150084 9716621Sbt150084 /* 9726621Sbt150084 * ixgbe_destroy_locks - Destroy locks. 9736621Sbt150084 */ 9746621Sbt150084 static void 9756621Sbt150084 ixgbe_destroy_locks(ixgbe_t *ixgbe) 9766621Sbt150084 { 9776621Sbt150084 ixgbe_rx_ring_t *rx_ring; 9786621Sbt150084 ixgbe_tx_ring_t *tx_ring; 9796621Sbt150084 int i; 9806621Sbt150084 9816621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) { 9826621Sbt150084 rx_ring = &ixgbe->rx_rings[i]; 9836621Sbt150084 mutex_destroy(&rx_ring->rx_lock); 9846621Sbt150084 } 9856621Sbt150084 9866621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 9876621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 9886621Sbt150084 mutex_destroy(&tx_ring->tx_lock); 9896621Sbt150084 mutex_destroy(&tx_ring->recycle_lock); 9906621Sbt150084 mutex_destroy(&tx_ring->tcb_head_lock); 9916621Sbt150084 mutex_destroy(&tx_ring->tcb_tail_lock); 9926621Sbt150084 } 9936621Sbt150084 9946621Sbt150084 mutex_destroy(&ixgbe->gen_lock); 9956621Sbt150084 mutex_destroy(&ixgbe->watchdog_lock); 9966621Sbt150084 } 9976621Sbt150084 9986621Sbt150084 static int 9996621Sbt150084 ixgbe_resume(dev_info_t *devinfo) 10006621Sbt150084 { 10016621Sbt150084 ixgbe_t *ixgbe; 10026621Sbt150084 10036621Sbt150084 ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo); 10046621Sbt150084 if (ixgbe == NULL) 10056621Sbt150084 return (DDI_FAILURE); 10066621Sbt150084 10076621Sbt150084 mutex_enter(&ixgbe->gen_lock); 10086621Sbt150084 10096621Sbt150084 if (ixgbe->ixgbe_state & IXGBE_STARTED) { 101010376SChenlu.Chen@Sun.COM if (ixgbe_start(ixgbe, B_FALSE) != IXGBE_SUCCESS) { 10116621Sbt150084 mutex_exit(&ixgbe->gen_lock); 10126621Sbt150084 return (DDI_FAILURE); 10136621Sbt150084 } 10146621Sbt150084 10156621Sbt150084 /* 10166621Sbt150084 * Enable and start the watchdog timer 10176621Sbt150084 */ 10186621Sbt150084 ixgbe_enable_watchdog_timer(ixgbe); 10196621Sbt150084 } 10206621Sbt150084 10216621Sbt150084 ixgbe->ixgbe_state &= ~IXGBE_SUSPENDED; 10226621Sbt150084 10236621Sbt150084 mutex_exit(&ixgbe->gen_lock); 10246621Sbt150084 10256621Sbt150084 return (DDI_SUCCESS); 10266621Sbt150084 } 10276621Sbt150084 10286621Sbt150084 static int 10296621Sbt150084 ixgbe_suspend(dev_info_t *devinfo) 10306621Sbt150084 { 10316621Sbt150084 ixgbe_t *ixgbe; 10326621Sbt150084 10336621Sbt150084 ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo); 10346621Sbt150084 if (ixgbe == NULL) 10356621Sbt150084 return (DDI_FAILURE); 10366621Sbt150084 10376621Sbt150084 mutex_enter(&ixgbe->gen_lock); 10386621Sbt150084 10396621Sbt150084 ixgbe->ixgbe_state |= IXGBE_SUSPENDED; 104010376SChenlu.Chen@Sun.COM if (!(ixgbe->ixgbe_state & IXGBE_STARTED)) { 104110376SChenlu.Chen@Sun.COM mutex_exit(&ixgbe->gen_lock); 104210376SChenlu.Chen@Sun.COM return (DDI_SUCCESS); 104310376SChenlu.Chen@Sun.COM } 104410376SChenlu.Chen@Sun.COM ixgbe_stop(ixgbe, B_FALSE); 10456621Sbt150084 10466621Sbt150084 mutex_exit(&ixgbe->gen_lock); 10476621Sbt150084 10486621Sbt150084 /* 10496621Sbt150084 * Disable and stop the watchdog timer 10506621Sbt150084 */ 10516621Sbt150084 ixgbe_disable_watchdog_timer(ixgbe); 10526621Sbt150084 10536621Sbt150084 return (DDI_SUCCESS); 10546621Sbt150084 } 10556621Sbt150084 10566621Sbt150084 /* 10576621Sbt150084 * ixgbe_init - Initialize the device. 10586621Sbt150084 */ 10596621Sbt150084 static int 10606621Sbt150084 ixgbe_init(ixgbe_t *ixgbe) 10616621Sbt150084 { 10626621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 10636621Sbt150084 10646621Sbt150084 mutex_enter(&ixgbe->gen_lock); 10656621Sbt150084 10666621Sbt150084 /* 10676621Sbt150084 * Reset chipset to put the hardware in a known state 10686621Sbt150084 * before we try to do anything with the eeprom. 10696621Sbt150084 */ 10706621Sbt150084 if (ixgbe_reset_hw(hw) != IXGBE_SUCCESS) { 10716621Sbt150084 ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE); 10726621Sbt150084 goto init_fail; 10736621Sbt150084 } 10746621Sbt150084 10756621Sbt150084 /* 10766621Sbt150084 * Need to init eeprom before validating the checksum. 10776621Sbt150084 */ 10786621Sbt150084 if (ixgbe_init_eeprom_params(hw) < 0) { 10796621Sbt150084 ixgbe_error(ixgbe, 10806621Sbt150084 "Unable to intitialize the eeprom interface."); 10816621Sbt150084 ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE); 10826621Sbt150084 goto init_fail; 10836621Sbt150084 } 10846621Sbt150084 10856621Sbt150084 /* 10866621Sbt150084 * NVM validation 10876621Sbt150084 */ 10886621Sbt150084 if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) { 10896621Sbt150084 /* 10906621Sbt150084 * Some PCI-E parts fail the first check due to 10916621Sbt150084 * the link being in sleep state. Call it again, 10926621Sbt150084 * if it fails a second time it's a real issue. 10936621Sbt150084 */ 10946621Sbt150084 if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) { 10956621Sbt150084 ixgbe_error(ixgbe, 10966621Sbt150084 "Invalid NVM checksum. Please contact " 10976621Sbt150084 "the vendor to update the NVM."); 10986621Sbt150084 ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE); 10996621Sbt150084 goto init_fail; 11006621Sbt150084 } 11016621Sbt150084 } 11026621Sbt150084 11036621Sbt150084 /* 11046621Sbt150084 * Setup default flow control thresholds - enable/disable 11056621Sbt150084 * & flow control type is controlled by ixgbe.conf 11066621Sbt150084 */ 11076621Sbt150084 hw->fc.high_water = DEFAULT_FCRTH; 11086621Sbt150084 hw->fc.low_water = DEFAULT_FCRTL; 11096621Sbt150084 hw->fc.pause_time = DEFAULT_FCPAUSE; 11106621Sbt150084 hw->fc.send_xon = B_TRUE; 11116621Sbt150084 11126621Sbt150084 /* 11136621Sbt150084 * Initialize link settings 11146621Sbt150084 */ 11156621Sbt150084 (void) ixgbe_driver_setup_link(ixgbe, B_FALSE); 11166621Sbt150084 11176621Sbt150084 /* 11186621Sbt150084 * Initialize the chipset hardware 11196621Sbt150084 */ 11206621Sbt150084 if (ixgbe_chip_start(ixgbe) != IXGBE_SUCCESS) { 11216621Sbt150084 ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE); 11226621Sbt150084 goto init_fail; 11236621Sbt150084 } 11246621Sbt150084 11256621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.cfg_handle) != DDI_FM_OK) { 11266621Sbt150084 goto init_fail; 11276621Sbt150084 } 11286621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 11296621Sbt150084 goto init_fail; 11306621Sbt150084 } 11316621Sbt150084 11326621Sbt150084 mutex_exit(&ixgbe->gen_lock); 11336621Sbt150084 return (IXGBE_SUCCESS); 11346621Sbt150084 11356621Sbt150084 init_fail: 11366621Sbt150084 /* 11376621Sbt150084 * Reset PHY 11386621Sbt150084 */ 11396621Sbt150084 (void) ixgbe_reset_phy(hw); 11406621Sbt150084 11416621Sbt150084 mutex_exit(&ixgbe->gen_lock); 11426621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST); 11436621Sbt150084 return (IXGBE_FAILURE); 11446621Sbt150084 } 11456621Sbt150084 11466621Sbt150084 /* 11476621Sbt150084 * ixgbe_chip_start - Initialize and start the chipset hardware. 11486621Sbt150084 */ 11496621Sbt150084 static int 11506621Sbt150084 ixgbe_chip_start(ixgbe_t *ixgbe) 11516621Sbt150084 { 11526621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 115310305SPaul.Guo@Sun.COM int ret_val, i; 11546621Sbt150084 11556621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 11566621Sbt150084 11576621Sbt150084 /* 11586621Sbt150084 * Get the mac address 11596621Sbt150084 * This function should handle SPARC case correctly. 11606621Sbt150084 */ 11616621Sbt150084 if (!ixgbe_find_mac_address(ixgbe)) { 11626621Sbt150084 ixgbe_error(ixgbe, "Failed to get the mac address"); 11636621Sbt150084 return (IXGBE_FAILURE); 11646621Sbt150084 } 11656621Sbt150084 11666621Sbt150084 /* 11676621Sbt150084 * Validate the mac address 11686621Sbt150084 */ 11696621Sbt150084 (void) ixgbe_init_rx_addrs(hw); 11706621Sbt150084 if (!is_valid_mac_addr(hw->mac.addr)) { 11716621Sbt150084 ixgbe_error(ixgbe, "Invalid mac address"); 11726621Sbt150084 return (IXGBE_FAILURE); 11736621Sbt150084 } 11746621Sbt150084 11756621Sbt150084 /* 11766621Sbt150084 * Configure/Initialize hardware 11776621Sbt150084 */ 117810305SPaul.Guo@Sun.COM ret_val = ixgbe_init_hw(hw); 117910305SPaul.Guo@Sun.COM if (ret_val != IXGBE_SUCCESS) { 118010305SPaul.Guo@Sun.COM if (ret_val == IXGBE_ERR_EEPROM_VERSION) { 118110305SPaul.Guo@Sun.COM ixgbe_error(ixgbe, 118210305SPaul.Guo@Sun.COM "This 82599 device is pre-release and contains" 118310305SPaul.Guo@Sun.COM " outdated firmware, please contact your hardware" 118410305SPaul.Guo@Sun.COM " vendor for a replacement."); 118510305SPaul.Guo@Sun.COM } else { 118610305SPaul.Guo@Sun.COM ixgbe_error(ixgbe, "Failed to initialize hardware"); 118710305SPaul.Guo@Sun.COM return (IXGBE_FAILURE); 118810305SPaul.Guo@Sun.COM } 11896621Sbt150084 } 11906621Sbt150084 11916621Sbt150084 /* 11926621Sbt150084 * Setup adapter interrupt vectors 11936621Sbt150084 */ 11946621Sbt150084 ixgbe_setup_adapter_vector(ixgbe); 11956621Sbt150084 11966621Sbt150084 /* 11976621Sbt150084 * Initialize unicast addresses. 11986621Sbt150084 */ 11996621Sbt150084 ixgbe_init_unicst(ixgbe); 12006621Sbt150084 12016621Sbt150084 /* 12026621Sbt150084 * Setup and initialize the mctable structures. 12036621Sbt150084 */ 12046621Sbt150084 ixgbe_setup_multicst(ixgbe); 12056621Sbt150084 12066621Sbt150084 /* 12076621Sbt150084 * Set interrupt throttling rate 12086621Sbt150084 */ 12099353SSamuel.Tu@Sun.COM for (i = 0; i < ixgbe->intr_cnt; i++) { 12106621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EITR(i), ixgbe->intr_throttling[i]); 12119353SSamuel.Tu@Sun.COM } 12126621Sbt150084 12136621Sbt150084 /* 12146621Sbt150084 * Save the state of the phy 12156621Sbt150084 */ 12166621Sbt150084 ixgbe_get_hw_state(ixgbe); 12176621Sbt150084 12186621Sbt150084 /* 12196621Sbt150084 * Make sure driver has control 12206621Sbt150084 */ 12216621Sbt150084 ixgbe_get_driver_control(hw); 12226621Sbt150084 12236621Sbt150084 return (IXGBE_SUCCESS); 12246621Sbt150084 } 12256621Sbt150084 12266621Sbt150084 /* 12276621Sbt150084 * ixgbe_chip_stop - Stop the chipset hardware 12286621Sbt150084 */ 12296621Sbt150084 static void 12306621Sbt150084 ixgbe_chip_stop(ixgbe_t *ixgbe) 12316621Sbt150084 { 12326621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 12336621Sbt150084 12346621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 12356621Sbt150084 12366621Sbt150084 /* 12376621Sbt150084 * Tell firmware driver is no longer in control 12386621Sbt150084 */ 12396621Sbt150084 ixgbe_release_driver_control(hw); 12406621Sbt150084 12416621Sbt150084 /* 12426621Sbt150084 * Reset the chipset 12436621Sbt150084 */ 12446621Sbt150084 (void) ixgbe_reset_hw(hw); 12456621Sbt150084 12466621Sbt150084 /* 12476621Sbt150084 * Reset PHY 12486621Sbt150084 */ 12496621Sbt150084 (void) ixgbe_reset_phy(hw); 12506621Sbt150084 } 12516621Sbt150084 12526621Sbt150084 /* 12536621Sbt150084 * ixgbe_reset - Reset the chipset and re-start the driver. 12546621Sbt150084 * 12556621Sbt150084 * It involves stopping and re-starting the chipset, 12566621Sbt150084 * and re-configuring the rx/tx rings. 12576621Sbt150084 */ 12586621Sbt150084 static int 12596621Sbt150084 ixgbe_reset(ixgbe_t *ixgbe) 12606621Sbt150084 { 126110376SChenlu.Chen@Sun.COM /* 126210376SChenlu.Chen@Sun.COM * Disable and stop the watchdog timer 126310376SChenlu.Chen@Sun.COM */ 126410376SChenlu.Chen@Sun.COM ixgbe_disable_watchdog_timer(ixgbe); 12656621Sbt150084 12666621Sbt150084 mutex_enter(&ixgbe->gen_lock); 12676621Sbt150084 12686621Sbt150084 ASSERT(ixgbe->ixgbe_state & IXGBE_STARTED); 12696621Sbt150084 ixgbe->ixgbe_state &= ~IXGBE_STARTED; 12706621Sbt150084 127110376SChenlu.Chen@Sun.COM ixgbe_stop(ixgbe, B_FALSE); 127210376SChenlu.Chen@Sun.COM 127310376SChenlu.Chen@Sun.COM if (ixgbe_start(ixgbe, B_FALSE) != IXGBE_SUCCESS) { 127410376SChenlu.Chen@Sun.COM mutex_exit(&ixgbe->gen_lock); 127510376SChenlu.Chen@Sun.COM return (IXGBE_FAILURE); 12766621Sbt150084 } 12776621Sbt150084 12786621Sbt150084 ixgbe->ixgbe_state |= IXGBE_STARTED; 12796621Sbt150084 mutex_exit(&ixgbe->gen_lock); 12806621Sbt150084 128110376SChenlu.Chen@Sun.COM /* 128210376SChenlu.Chen@Sun.COM * Enable and start the watchdog timer 128310376SChenlu.Chen@Sun.COM */ 128410376SChenlu.Chen@Sun.COM ixgbe_enable_watchdog_timer(ixgbe); 128510376SChenlu.Chen@Sun.COM 12866621Sbt150084 return (IXGBE_SUCCESS); 12876621Sbt150084 } 12886621Sbt150084 12896621Sbt150084 /* 12906621Sbt150084 * ixgbe_tx_clean - Clean the pending transmit packets and DMA resources. 12916621Sbt150084 */ 12926621Sbt150084 static void 12936621Sbt150084 ixgbe_tx_clean(ixgbe_t *ixgbe) 12946621Sbt150084 { 12956621Sbt150084 ixgbe_tx_ring_t *tx_ring; 12966621Sbt150084 tx_control_block_t *tcb; 12976621Sbt150084 link_list_t pending_list; 12986621Sbt150084 uint32_t desc_num; 12996621Sbt150084 int i, j; 13006621Sbt150084 13016621Sbt150084 LINK_LIST_INIT(&pending_list); 13026621Sbt150084 13036621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 13046621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 13056621Sbt150084 13066621Sbt150084 mutex_enter(&tx_ring->recycle_lock); 13076621Sbt150084 13086621Sbt150084 /* 13096621Sbt150084 * Clean the pending tx data - the pending packets in the 13106621Sbt150084 * work_list that have no chances to be transmitted again. 13116621Sbt150084 * 13126621Sbt150084 * We must ensure the chipset is stopped or the link is down 13136621Sbt150084 * before cleaning the transmit packets. 13146621Sbt150084 */ 13156621Sbt150084 desc_num = 0; 13166621Sbt150084 for (j = 0; j < tx_ring->ring_size; j++) { 13176621Sbt150084 tcb = tx_ring->work_list[j]; 13186621Sbt150084 if (tcb != NULL) { 13196621Sbt150084 desc_num += tcb->desc_num; 13206621Sbt150084 13216621Sbt150084 tx_ring->work_list[j] = NULL; 13226621Sbt150084 13236621Sbt150084 ixgbe_free_tcb(tcb); 13246621Sbt150084 13256621Sbt150084 LIST_PUSH_TAIL(&pending_list, &tcb->link); 13266621Sbt150084 } 13276621Sbt150084 } 13286621Sbt150084 13296621Sbt150084 if (desc_num > 0) { 13306621Sbt150084 atomic_add_32(&tx_ring->tbd_free, desc_num); 13316621Sbt150084 ASSERT(tx_ring->tbd_free == tx_ring->ring_size); 13326621Sbt150084 13336621Sbt150084 /* 13346621Sbt150084 * Reset the head and tail pointers of the tbd ring; 13356621Sbt150084 * Reset the writeback head if it's enable. 13366621Sbt150084 */ 13376621Sbt150084 tx_ring->tbd_head = 0; 13386621Sbt150084 tx_ring->tbd_tail = 0; 13396621Sbt150084 if (ixgbe->tx_head_wb_enable) 13406621Sbt150084 *tx_ring->tbd_head_wb = 0; 13416621Sbt150084 13426621Sbt150084 IXGBE_WRITE_REG(&ixgbe->hw, 13436621Sbt150084 IXGBE_TDH(tx_ring->index), 0); 13446621Sbt150084 IXGBE_WRITE_REG(&ixgbe->hw, 13456621Sbt150084 IXGBE_TDT(tx_ring->index), 0); 13466621Sbt150084 } 13476621Sbt150084 13486621Sbt150084 mutex_exit(&tx_ring->recycle_lock); 13496621Sbt150084 13506621Sbt150084 /* 13516621Sbt150084 * Add the tx control blocks in the pending list to 13526621Sbt150084 * the free list. 13536621Sbt150084 */ 13546621Sbt150084 ixgbe_put_free_list(tx_ring, &pending_list); 13556621Sbt150084 } 13566621Sbt150084 } 13576621Sbt150084 13586621Sbt150084 /* 13596621Sbt150084 * ixgbe_tx_drain - Drain the tx rings to allow pending packets to be 13606621Sbt150084 * transmitted. 13616621Sbt150084 */ 13626621Sbt150084 static boolean_t 13636621Sbt150084 ixgbe_tx_drain(ixgbe_t *ixgbe) 13646621Sbt150084 { 13656621Sbt150084 ixgbe_tx_ring_t *tx_ring; 13666621Sbt150084 boolean_t done; 13676621Sbt150084 int i, j; 13686621Sbt150084 13696621Sbt150084 /* 13706621Sbt150084 * Wait for a specific time to allow pending tx packets 13716621Sbt150084 * to be transmitted. 13726621Sbt150084 * 13736621Sbt150084 * Check the counter tbd_free to see if transmission is done. 13746621Sbt150084 * No lock protection is needed here. 13756621Sbt150084 * 13766621Sbt150084 * Return B_TRUE if all pending packets have been transmitted; 13776621Sbt150084 * Otherwise return B_FALSE; 13786621Sbt150084 */ 13796621Sbt150084 for (i = 0; i < TX_DRAIN_TIME; i++) { 13806621Sbt150084 13816621Sbt150084 done = B_TRUE; 13826621Sbt150084 for (j = 0; j < ixgbe->num_tx_rings; j++) { 13836621Sbt150084 tx_ring = &ixgbe->tx_rings[j]; 13846621Sbt150084 done = done && 13856621Sbt150084 (tx_ring->tbd_free == tx_ring->ring_size); 13866621Sbt150084 } 13876621Sbt150084 13886621Sbt150084 if (done) 13896621Sbt150084 break; 13906621Sbt150084 13916621Sbt150084 msec_delay(1); 13926621Sbt150084 } 13936621Sbt150084 13946621Sbt150084 return (done); 13956621Sbt150084 } 13966621Sbt150084 13976621Sbt150084 /* 13986621Sbt150084 * ixgbe_rx_drain - Wait for all rx buffers to be released by upper layer. 13996621Sbt150084 */ 14006621Sbt150084 static boolean_t 14016621Sbt150084 ixgbe_rx_drain(ixgbe_t *ixgbe) 14026621Sbt150084 { 140310376SChenlu.Chen@Sun.COM boolean_t done = B_TRUE; 140410376SChenlu.Chen@Sun.COM int i; 14056621Sbt150084 14066621Sbt150084 /* 14076621Sbt150084 * Polling the rx free list to check if those rx buffers held by 14086621Sbt150084 * the upper layer are released. 14096621Sbt150084 * 14106621Sbt150084 * Check the counter rcb_free to see if all pending buffers are 14116621Sbt150084 * released. No lock protection is needed here. 14126621Sbt150084 * 14136621Sbt150084 * Return B_TRUE if all pending buffers have been released; 14146621Sbt150084 * Otherwise return B_FALSE; 14156621Sbt150084 */ 14166621Sbt150084 for (i = 0; i < RX_DRAIN_TIME; i++) { 141710376SChenlu.Chen@Sun.COM done = (ixgbe->rcb_pending == 0); 14186621Sbt150084 14196621Sbt150084 if (done) 14206621Sbt150084 break; 14216621Sbt150084 14226621Sbt150084 msec_delay(1); 14236621Sbt150084 } 14246621Sbt150084 14256621Sbt150084 return (done); 14266621Sbt150084 } 14276621Sbt150084 14286621Sbt150084 /* 14296621Sbt150084 * ixgbe_start - Start the driver/chipset. 14306621Sbt150084 */ 14316621Sbt150084 int 143210376SChenlu.Chen@Sun.COM ixgbe_start(ixgbe_t *ixgbe, boolean_t alloc_buffer) 14336621Sbt150084 { 14346621Sbt150084 int i; 14356621Sbt150084 14366621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 14376621Sbt150084 143810376SChenlu.Chen@Sun.COM if (alloc_buffer) { 143910376SChenlu.Chen@Sun.COM if (ixgbe_alloc_rx_data(ixgbe) != IXGBE_SUCCESS) { 144010376SChenlu.Chen@Sun.COM ixgbe_error(ixgbe, 144110376SChenlu.Chen@Sun.COM "Failed to allocate software receive rings"); 144210376SChenlu.Chen@Sun.COM return (IXGBE_FAILURE); 144310376SChenlu.Chen@Sun.COM } 144410376SChenlu.Chen@Sun.COM 144510376SChenlu.Chen@Sun.COM /* Allocate buffers for all the rx/tx rings */ 144610376SChenlu.Chen@Sun.COM if (ixgbe_alloc_dma(ixgbe) != IXGBE_SUCCESS) { 144710376SChenlu.Chen@Sun.COM ixgbe_error(ixgbe, "Failed to allocate DMA resource"); 144810376SChenlu.Chen@Sun.COM return (IXGBE_FAILURE); 144910376SChenlu.Chen@Sun.COM } 145010376SChenlu.Chen@Sun.COM 145110376SChenlu.Chen@Sun.COM ixgbe->tx_ring_init = B_TRUE; 145210376SChenlu.Chen@Sun.COM } else { 145310376SChenlu.Chen@Sun.COM ixgbe->tx_ring_init = B_FALSE; 145410376SChenlu.Chen@Sun.COM } 145510376SChenlu.Chen@Sun.COM 14566621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) 14576621Sbt150084 mutex_enter(&ixgbe->rx_rings[i].rx_lock); 14586621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) 14596621Sbt150084 mutex_enter(&ixgbe->tx_rings[i].tx_lock); 14606621Sbt150084 14616621Sbt150084 /* 14626621Sbt150084 * Start the chipset hardware 14636621Sbt150084 */ 14646621Sbt150084 if (ixgbe_chip_start(ixgbe) != IXGBE_SUCCESS) { 14656621Sbt150084 ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE); 14666621Sbt150084 goto start_failure; 14676621Sbt150084 } 14686621Sbt150084 14696621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 14706621Sbt150084 goto start_failure; 14716621Sbt150084 } 14726621Sbt150084 14736621Sbt150084 /* 14746621Sbt150084 * Setup the rx/tx rings 14756621Sbt150084 */ 14766621Sbt150084 ixgbe_setup_rings(ixgbe); 14776621Sbt150084 14786621Sbt150084 /* 14796621Sbt150084 * Enable adapter interrupts 14806621Sbt150084 * The interrupts must be enabled after the driver state is START 14816621Sbt150084 */ 14826621Sbt150084 ixgbe_enable_adapter_interrupts(ixgbe); 14836621Sbt150084 14846621Sbt150084 for (i = ixgbe->num_tx_rings - 1; i >= 0; i--) 14856621Sbt150084 mutex_exit(&ixgbe->tx_rings[i].tx_lock); 14866621Sbt150084 for (i = ixgbe->num_rx_rings - 1; i >= 0; i--) 14876621Sbt150084 mutex_exit(&ixgbe->rx_rings[i].rx_lock); 14886621Sbt150084 14896621Sbt150084 return (IXGBE_SUCCESS); 14906621Sbt150084 14916621Sbt150084 start_failure: 14926621Sbt150084 for (i = ixgbe->num_tx_rings - 1; i >= 0; i--) 14936621Sbt150084 mutex_exit(&ixgbe->tx_rings[i].tx_lock); 14946621Sbt150084 for (i = ixgbe->num_rx_rings - 1; i >= 0; i--) 14956621Sbt150084 mutex_exit(&ixgbe->rx_rings[i].rx_lock); 14966621Sbt150084 14976621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST); 14986621Sbt150084 14996621Sbt150084 return (IXGBE_FAILURE); 15006621Sbt150084 } 15016621Sbt150084 15026621Sbt150084 /* 15036621Sbt150084 * ixgbe_stop - Stop the driver/chipset. 15046621Sbt150084 */ 15056621Sbt150084 void 150610376SChenlu.Chen@Sun.COM ixgbe_stop(ixgbe_t *ixgbe, boolean_t free_buffer) 15076621Sbt150084 { 15086621Sbt150084 int i; 15096621Sbt150084 15106621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 15116621Sbt150084 15126621Sbt150084 /* 15136621Sbt150084 * Disable the adapter interrupts 15146621Sbt150084 */ 15156621Sbt150084 ixgbe_disable_adapter_interrupts(ixgbe); 15166621Sbt150084 15176621Sbt150084 /* 15186621Sbt150084 * Drain the pending tx packets 15196621Sbt150084 */ 15206621Sbt150084 (void) ixgbe_tx_drain(ixgbe); 15216621Sbt150084 15226621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) 15236621Sbt150084 mutex_enter(&ixgbe->rx_rings[i].rx_lock); 15246621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) 15256621Sbt150084 mutex_enter(&ixgbe->tx_rings[i].tx_lock); 15266621Sbt150084 15276621Sbt150084 /* 15286621Sbt150084 * Stop the chipset hardware 15296621Sbt150084 */ 15306621Sbt150084 ixgbe_chip_stop(ixgbe); 15316621Sbt150084 15326621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 15336621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST); 15346621Sbt150084 } 15356621Sbt150084 15366621Sbt150084 /* 15376621Sbt150084 * Clean the pending tx data/resources 15386621Sbt150084 */ 15396621Sbt150084 ixgbe_tx_clean(ixgbe); 15406621Sbt150084 15416621Sbt150084 for (i = ixgbe->num_tx_rings - 1; i >= 0; i--) 15426621Sbt150084 mutex_exit(&ixgbe->tx_rings[i].tx_lock); 15436621Sbt150084 for (i = ixgbe->num_rx_rings - 1; i >= 0; i--) 15446621Sbt150084 mutex_exit(&ixgbe->rx_rings[i].rx_lock); 154510376SChenlu.Chen@Sun.COM 154610376SChenlu.Chen@Sun.COM if (ixgbe->link_state == LINK_STATE_UP) { 154710376SChenlu.Chen@Sun.COM ixgbe->link_state = LINK_STATE_UNKNOWN; 154810376SChenlu.Chen@Sun.COM mac_link_update(ixgbe->mac_hdl, ixgbe->link_state); 154910376SChenlu.Chen@Sun.COM } 155010376SChenlu.Chen@Sun.COM 155110376SChenlu.Chen@Sun.COM if (free_buffer) { 155210376SChenlu.Chen@Sun.COM /* 155310376SChenlu.Chen@Sun.COM * Release the DMA/memory resources of rx/tx rings 155410376SChenlu.Chen@Sun.COM */ 155510376SChenlu.Chen@Sun.COM ixgbe_free_dma(ixgbe); 155610376SChenlu.Chen@Sun.COM ixgbe_free_rx_data(ixgbe); 155710376SChenlu.Chen@Sun.COM } 15586621Sbt150084 } 15596621Sbt150084 15606621Sbt150084 /* 15616621Sbt150084 * ixgbe_alloc_rings - Allocate memory space for rx/tx rings. 15626621Sbt150084 */ 15636621Sbt150084 static int 15646621Sbt150084 ixgbe_alloc_rings(ixgbe_t *ixgbe) 15656621Sbt150084 { 15666621Sbt150084 /* 15676621Sbt150084 * Allocate memory space for rx rings 15686621Sbt150084 */ 15696621Sbt150084 ixgbe->rx_rings = kmem_zalloc( 15706621Sbt150084 sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings, 15716621Sbt150084 KM_NOSLEEP); 15726621Sbt150084 15736621Sbt150084 if (ixgbe->rx_rings == NULL) { 15746621Sbt150084 return (IXGBE_FAILURE); 15756621Sbt150084 } 15766621Sbt150084 15776621Sbt150084 /* 15786621Sbt150084 * Allocate memory space for tx rings 15796621Sbt150084 */ 15806621Sbt150084 ixgbe->tx_rings = kmem_zalloc( 15816621Sbt150084 sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings, 15826621Sbt150084 KM_NOSLEEP); 15836621Sbt150084 15846621Sbt150084 if (ixgbe->tx_rings == NULL) { 15856621Sbt150084 kmem_free(ixgbe->rx_rings, 15866621Sbt150084 sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings); 15876621Sbt150084 ixgbe->rx_rings = NULL; 15886621Sbt150084 return (IXGBE_FAILURE); 15896621Sbt150084 } 15906621Sbt150084 15918275SEric Cheng /* 15928275SEric Cheng * Allocate memory space for rx ring groups 15938275SEric Cheng */ 15948275SEric Cheng ixgbe->rx_groups = kmem_zalloc( 15958275SEric Cheng sizeof (ixgbe_rx_group_t) * ixgbe->num_rx_groups, 15968275SEric Cheng KM_NOSLEEP); 15978275SEric Cheng 15988275SEric Cheng if (ixgbe->rx_groups == NULL) { 15998275SEric Cheng kmem_free(ixgbe->rx_rings, 16008275SEric Cheng sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings); 16018275SEric Cheng kmem_free(ixgbe->tx_rings, 16028275SEric Cheng sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings); 16038275SEric Cheng ixgbe->rx_rings = NULL; 16048275SEric Cheng ixgbe->tx_rings = NULL; 16058275SEric Cheng return (IXGBE_FAILURE); 16068275SEric Cheng } 16078275SEric Cheng 16086621Sbt150084 return (IXGBE_SUCCESS); 16096621Sbt150084 } 16106621Sbt150084 16116621Sbt150084 /* 16126621Sbt150084 * ixgbe_free_rings - Free the memory space of rx/tx rings. 16136621Sbt150084 */ 16146621Sbt150084 static void 16156621Sbt150084 ixgbe_free_rings(ixgbe_t *ixgbe) 16166621Sbt150084 { 16176621Sbt150084 if (ixgbe->rx_rings != NULL) { 16186621Sbt150084 kmem_free(ixgbe->rx_rings, 16196621Sbt150084 sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings); 16206621Sbt150084 ixgbe->rx_rings = NULL; 16216621Sbt150084 } 16226621Sbt150084 16236621Sbt150084 if (ixgbe->tx_rings != NULL) { 16246621Sbt150084 kmem_free(ixgbe->tx_rings, 16256621Sbt150084 sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings); 16266621Sbt150084 ixgbe->tx_rings = NULL; 16276621Sbt150084 } 16288275SEric Cheng 16298275SEric Cheng if (ixgbe->rx_groups != NULL) { 16308275SEric Cheng kmem_free(ixgbe->rx_groups, 16318275SEric Cheng sizeof (ixgbe_rx_group_t) * ixgbe->num_rx_groups); 16328275SEric Cheng ixgbe->rx_groups = NULL; 16338275SEric Cheng } 16346621Sbt150084 } 16356621Sbt150084 163610376SChenlu.Chen@Sun.COM static int 163710376SChenlu.Chen@Sun.COM ixgbe_alloc_rx_data(ixgbe_t *ixgbe) 163810376SChenlu.Chen@Sun.COM { 163910376SChenlu.Chen@Sun.COM ixgbe_rx_ring_t *rx_ring; 164010376SChenlu.Chen@Sun.COM int i; 164110376SChenlu.Chen@Sun.COM 164210376SChenlu.Chen@Sun.COM for (i = 0; i < ixgbe->num_rx_rings; i++) { 164310376SChenlu.Chen@Sun.COM rx_ring = &ixgbe->rx_rings[i]; 164410376SChenlu.Chen@Sun.COM if (ixgbe_alloc_rx_ring_data(rx_ring) != IXGBE_SUCCESS) 164510376SChenlu.Chen@Sun.COM goto alloc_rx_rings_failure; 164610376SChenlu.Chen@Sun.COM } 164710376SChenlu.Chen@Sun.COM return (IXGBE_SUCCESS); 164810376SChenlu.Chen@Sun.COM 164910376SChenlu.Chen@Sun.COM alloc_rx_rings_failure: 165010376SChenlu.Chen@Sun.COM ixgbe_free_rx_data(ixgbe); 165110376SChenlu.Chen@Sun.COM return (IXGBE_FAILURE); 165210376SChenlu.Chen@Sun.COM } 165310376SChenlu.Chen@Sun.COM 165410376SChenlu.Chen@Sun.COM static void 165510376SChenlu.Chen@Sun.COM ixgbe_free_rx_data(ixgbe_t *ixgbe) 165610376SChenlu.Chen@Sun.COM { 165710376SChenlu.Chen@Sun.COM ixgbe_rx_ring_t *rx_ring; 165810376SChenlu.Chen@Sun.COM ixgbe_rx_data_t *rx_data; 165910376SChenlu.Chen@Sun.COM int i; 166010376SChenlu.Chen@Sun.COM 166110376SChenlu.Chen@Sun.COM for (i = 0; i < ixgbe->num_rx_rings; i++) { 166210376SChenlu.Chen@Sun.COM rx_ring = &ixgbe->rx_rings[i]; 166310376SChenlu.Chen@Sun.COM 166410376SChenlu.Chen@Sun.COM mutex_enter(&ixgbe->rx_pending_lock); 166510376SChenlu.Chen@Sun.COM rx_data = rx_ring->rx_data; 166610376SChenlu.Chen@Sun.COM 166710376SChenlu.Chen@Sun.COM if (rx_data != NULL) { 166810376SChenlu.Chen@Sun.COM rx_data->flag |= IXGBE_RX_STOPPED; 166910376SChenlu.Chen@Sun.COM 167010376SChenlu.Chen@Sun.COM if (rx_data->rcb_pending == 0) { 167110376SChenlu.Chen@Sun.COM ixgbe_free_rx_ring_data(rx_data); 167210376SChenlu.Chen@Sun.COM rx_ring->rx_data = NULL; 167310376SChenlu.Chen@Sun.COM } 167410376SChenlu.Chen@Sun.COM } 167510376SChenlu.Chen@Sun.COM 167610376SChenlu.Chen@Sun.COM mutex_exit(&ixgbe->rx_pending_lock); 167710376SChenlu.Chen@Sun.COM } 167810376SChenlu.Chen@Sun.COM } 167910376SChenlu.Chen@Sun.COM 16806621Sbt150084 /* 16816621Sbt150084 * ixgbe_setup_rings - Setup rx/tx rings. 16826621Sbt150084 */ 16836621Sbt150084 static void 16846621Sbt150084 ixgbe_setup_rings(ixgbe_t *ixgbe) 16856621Sbt150084 { 16866621Sbt150084 /* 16876621Sbt150084 * Setup the rx/tx rings, including the following: 16886621Sbt150084 * 16896621Sbt150084 * 1. Setup the descriptor ring and the control block buffers; 16906621Sbt150084 * 2. Initialize necessary registers for receive/transmit; 16916621Sbt150084 * 3. Initialize software pointers/parameters for receive/transmit; 16926621Sbt150084 */ 16936621Sbt150084 ixgbe_setup_rx(ixgbe); 16946621Sbt150084 16956621Sbt150084 ixgbe_setup_tx(ixgbe); 16966621Sbt150084 } 16976621Sbt150084 16986621Sbt150084 static void 16996621Sbt150084 ixgbe_setup_rx_ring(ixgbe_rx_ring_t *rx_ring) 17006621Sbt150084 { 17016621Sbt150084 ixgbe_t *ixgbe = rx_ring->ixgbe; 170210376SChenlu.Chen@Sun.COM ixgbe_rx_data_t *rx_data = rx_ring->rx_data; 17036621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 17046621Sbt150084 rx_control_block_t *rcb; 17056621Sbt150084 union ixgbe_adv_rx_desc *rbd; 17066621Sbt150084 uint32_t size; 17076621Sbt150084 uint32_t buf_low; 17086621Sbt150084 uint32_t buf_high; 17096621Sbt150084 uint32_t reg_val; 17106621Sbt150084 int i; 17116621Sbt150084 17126621Sbt150084 ASSERT(mutex_owned(&rx_ring->rx_lock)); 17136621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 17146621Sbt150084 17156621Sbt150084 for (i = 0; i < ixgbe->rx_ring_size; i++) { 171610376SChenlu.Chen@Sun.COM rcb = rx_data->work_list[i]; 171710376SChenlu.Chen@Sun.COM rbd = &rx_data->rbd_ring[i]; 17186621Sbt150084 17196621Sbt150084 rbd->read.pkt_addr = rcb->rx_buf.dma_address; 17206621Sbt150084 rbd->read.hdr_addr = NULL; 17216621Sbt150084 } 17226621Sbt150084 17236621Sbt150084 /* 17246621Sbt150084 * Initialize the length register 17256621Sbt150084 */ 172610376SChenlu.Chen@Sun.COM size = rx_data->ring_size * sizeof (union ixgbe_adv_rx_desc); 17276621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(rx_ring->index), size); 17286621Sbt150084 17296621Sbt150084 /* 17306621Sbt150084 * Initialize the base address registers 17316621Sbt150084 */ 173210376SChenlu.Chen@Sun.COM buf_low = (uint32_t)rx_data->rbd_area.dma_address; 173310376SChenlu.Chen@Sun.COM buf_high = (uint32_t)(rx_data->rbd_area.dma_address >> 32); 17346621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(rx_ring->index), buf_high); 17356621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(rx_ring->index), buf_low); 17366621Sbt150084 17376621Sbt150084 /* 17386621Sbt150084 * Setup head & tail pointers 17396621Sbt150084 */ 174010376SChenlu.Chen@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->index), rx_data->ring_size - 1); 17416621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RDH(rx_ring->index), 0); 17426621Sbt150084 174310376SChenlu.Chen@Sun.COM rx_data->rbd_next = 0; 17446621Sbt150084 17456621Sbt150084 /* 17466621Sbt150084 * Setup the Receive Descriptor Control Register (RXDCTL) 17476621Sbt150084 * PTHRESH=32 descriptors (half the internal cache) 17486621Sbt150084 * HTHRESH=0 descriptors (to minimize latency on fetch) 17496621Sbt150084 * WTHRESH defaults to 1 (writeback each descriptor) 17506621Sbt150084 */ 17516621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rx_ring->index)); 17526621Sbt150084 reg_val |= IXGBE_RXDCTL_ENABLE; /* enable queue */ 17539353SSamuel.Tu@Sun.COM 17549353SSamuel.Tu@Sun.COM /* Not a valid value for 82599 */ 17559353SSamuel.Tu@Sun.COM if (hw->mac.type < ixgbe_mac_82599EB) { 17569353SSamuel.Tu@Sun.COM reg_val |= 0x0020; /* pthresh */ 17579353SSamuel.Tu@Sun.COM } 17586621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rx_ring->index), reg_val); 17596621Sbt150084 17609353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 17619353SSamuel.Tu@Sun.COM reg_val = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); 17629353SSamuel.Tu@Sun.COM reg_val |= (IXGBE_RDRXCTL_CRCSTRIP | IXGBE_RDRXCTL_AGGDIS); 17639353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg_val); 17649353SSamuel.Tu@Sun.COM } 17659353SSamuel.Tu@Sun.COM 17666621Sbt150084 /* 17676621Sbt150084 * Setup the Split and Replication Receive Control Register. 17686621Sbt150084 * Set the rx buffer size and the advanced descriptor type. 17696621Sbt150084 */ 17706621Sbt150084 reg_val = (ixgbe->rx_buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) | 17716621Sbt150084 IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; 17729353SSamuel.Tu@Sun.COM reg_val |= IXGBE_SRRCTL_DROP_EN; 17736621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rx_ring->index), reg_val); 17746621Sbt150084 } 17756621Sbt150084 17766621Sbt150084 static void 17776621Sbt150084 ixgbe_setup_rx(ixgbe_t *ixgbe) 17786621Sbt150084 { 17796621Sbt150084 ixgbe_rx_ring_t *rx_ring; 17806621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 17818275SEric Cheng ixgbe_rx_group_t *rx_group; 17826621Sbt150084 uint32_t reg_val; 17838275SEric Cheng uint32_t ring_mapping; 17846621Sbt150084 int i; 17856621Sbt150084 17869353SSamuel.Tu@Sun.COM /* PSRTYPE must be configured for 82599 */ 17879353SSamuel.Tu@Sun.COM reg_val = IXGBE_PSRTYPE_TCPHDR | IXGBE_PSRTYPE_UDPHDR | 17889353SSamuel.Tu@Sun.COM IXGBE_PSRTYPE_IPV4HDR | IXGBE_PSRTYPE_IPV6HDR; 17899353SSamuel.Tu@Sun.COM #define IXGBE_PSRTYPE_L2_PKT 0x00001000 17909353SSamuel.Tu@Sun.COM reg_val |= IXGBE_PSRTYPE_L2_PKT; 17919353SSamuel.Tu@Sun.COM reg_val |= 0xE0000000; 17929353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), reg_val); 17939353SSamuel.Tu@Sun.COM 17946621Sbt150084 /* 17956621Sbt150084 * Set filter control in FCTRL to accept broadcast packets and do 17966621Sbt150084 * not pass pause frames to host. Flow control settings are already 17976621Sbt150084 * in this register, so preserve them. 17986621Sbt150084 */ 17996621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_FCTRL); 18006621Sbt150084 reg_val |= IXGBE_FCTRL_BAM; /* broadcast accept mode */ 18016621Sbt150084 reg_val |= IXGBE_FCTRL_DPF; /* discard pause frames */ 18026621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_val); 18036621Sbt150084 18046621Sbt150084 /* 18056621Sbt150084 * Enable the receive unit. This must be done after filter 18066621Sbt150084 * control is set in FCTRL. 18076621Sbt150084 */ 18086621Sbt150084 reg_val = (IXGBE_RXCTRL_RXEN /* Enable Receive Unit */ 18096621Sbt150084 | IXGBE_RXCTRL_DMBYPS); /* descriptor monitor bypass */ 18106621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val); 18116621Sbt150084 18126621Sbt150084 /* 18136621Sbt150084 * ixgbe_setup_rx_ring must be called after configuring RXCTRL 18146621Sbt150084 */ 18156621Sbt150084 for (i = 0; i < ixgbe->num_rx_rings; i++) { 18166621Sbt150084 rx_ring = &ixgbe->rx_rings[i]; 18176621Sbt150084 ixgbe_setup_rx_ring(rx_ring); 18186621Sbt150084 } 18196621Sbt150084 18206621Sbt150084 /* 18218275SEric Cheng * Setup rx groups. 18228275SEric Cheng */ 18238275SEric Cheng for (i = 0; i < ixgbe->num_rx_groups; i++) { 18248275SEric Cheng rx_group = &ixgbe->rx_groups[i]; 18258275SEric Cheng rx_group->index = i; 18268275SEric Cheng rx_group->ixgbe = ixgbe; 18278275SEric Cheng } 18288275SEric Cheng 18298275SEric Cheng /* 18308275SEric Cheng * Setup the per-ring statistics mapping. 18318275SEric Cheng */ 18328275SEric Cheng ring_mapping = 0; 18338275SEric Cheng for (i = 0; i < ixgbe->num_rx_rings; i++) { 18348275SEric Cheng ring_mapping |= (i & 0xF) << (8 * (i & 0x3)); 18358275SEric Cheng if ((i & 0x3) == 0x3) { 18368275SEric Cheng IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i >> 2), ring_mapping); 18378275SEric Cheng ring_mapping = 0; 18388275SEric Cheng } 18398275SEric Cheng } 18408275SEric Cheng if ((i & 0x3) != 0x3) 18418275SEric Cheng IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i >> 2), ring_mapping); 18428275SEric Cheng 18438275SEric Cheng /* 18449353SSamuel.Tu@Sun.COM * The Max Frame Size in MHADD/MAXFRS will be internally increased 18459353SSamuel.Tu@Sun.COM * by four bytes if the packet has a VLAN field, so includes MTU, 18469353SSamuel.Tu@Sun.COM * ethernet header and frame check sequence. 18479353SSamuel.Tu@Sun.COM * Register is MAXFRS in 82599. 18486621Sbt150084 */ 18496621Sbt150084 reg_val = (ixgbe->default_mtu + sizeof (struct ether_header) 18506621Sbt150084 + ETHERFCSL) << IXGBE_MHADD_MFS_SHIFT; 18516621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MHADD, reg_val); 18526621Sbt150084 18536621Sbt150084 /* 18546621Sbt150084 * Setup Jumbo Frame enable bit 18556621Sbt150084 */ 18566621Sbt150084 if (ixgbe->default_mtu > ETHERMTU) { 18576621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_HLREG0); 18586621Sbt150084 reg_val |= IXGBE_HLREG0_JUMBOEN; 18596621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_val); 18606621Sbt150084 } 18616621Sbt150084 18626621Sbt150084 /* 18636621Sbt150084 * Hardware checksum settings 18646621Sbt150084 */ 18656621Sbt150084 if (ixgbe->rx_hcksum_enable) { 18666621Sbt150084 reg_val = IXGBE_RXCSUM_IPPCSE; /* IP checksum */ 18676621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, reg_val); 18686621Sbt150084 } 18696621Sbt150084 18706621Sbt150084 /* 18716621Sbt150084 * Setup RSS for multiple receive queues 18726621Sbt150084 */ 18736621Sbt150084 if (ixgbe->num_rx_rings > 1) 18746621Sbt150084 ixgbe_setup_rss(ixgbe); 18756621Sbt150084 } 18766621Sbt150084 18776621Sbt150084 static void 18786621Sbt150084 ixgbe_setup_tx_ring(ixgbe_tx_ring_t *tx_ring) 18796621Sbt150084 { 18806621Sbt150084 ixgbe_t *ixgbe = tx_ring->ixgbe; 18816621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 18826621Sbt150084 uint32_t size; 18836621Sbt150084 uint32_t buf_low; 18846621Sbt150084 uint32_t buf_high; 18856621Sbt150084 uint32_t reg_val; 18866621Sbt150084 18876621Sbt150084 ASSERT(mutex_owned(&tx_ring->tx_lock)); 18886621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 18896621Sbt150084 18906621Sbt150084 /* 18916621Sbt150084 * Initialize the length register 18926621Sbt150084 */ 18936621Sbt150084 size = tx_ring->ring_size * sizeof (union ixgbe_adv_tx_desc); 18946621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(tx_ring->index), size); 18956621Sbt150084 18966621Sbt150084 /* 18976621Sbt150084 * Initialize the base address registers 18986621Sbt150084 */ 18996621Sbt150084 buf_low = (uint32_t)tx_ring->tbd_area.dma_address; 19006621Sbt150084 buf_high = (uint32_t)(tx_ring->tbd_area.dma_address >> 32); 19016621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(tx_ring->index), buf_low); 19026621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(tx_ring->index), buf_high); 19036621Sbt150084 19046621Sbt150084 /* 19056621Sbt150084 * Setup head & tail pointers 19066621Sbt150084 */ 19076621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDH(tx_ring->index), 0); 19086621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDT(tx_ring->index), 0); 19096621Sbt150084 19106621Sbt150084 /* 19116621Sbt150084 * Setup head write-back 19126621Sbt150084 */ 19136621Sbt150084 if (ixgbe->tx_head_wb_enable) { 19146621Sbt150084 /* 19156621Sbt150084 * The memory of the head write-back is allocated using 19166621Sbt150084 * the extra tbd beyond the tail of the tbd ring. 19176621Sbt150084 */ 19186621Sbt150084 tx_ring->tbd_head_wb = (uint32_t *) 19196621Sbt150084 ((uintptr_t)tx_ring->tbd_area.address + size); 19206621Sbt150084 *tx_ring->tbd_head_wb = 0; 19216621Sbt150084 19226621Sbt150084 buf_low = (uint32_t) 19236621Sbt150084 (tx_ring->tbd_area.dma_address + size); 19246621Sbt150084 buf_high = (uint32_t) 19256621Sbt150084 ((tx_ring->tbd_area.dma_address + size) >> 32); 19266621Sbt150084 19276621Sbt150084 /* Set the head write-back enable bit */ 19286621Sbt150084 buf_low |= IXGBE_TDWBAL_HEAD_WB_ENABLE; 19296621Sbt150084 19306621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(tx_ring->index), buf_low); 19316621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(tx_ring->index), buf_high); 19326621Sbt150084 19336621Sbt150084 /* 19346621Sbt150084 * Turn off relaxed ordering for head write back or it will 19356621Sbt150084 * cause problems with the tx recycling 19366621Sbt150084 */ 19376621Sbt150084 reg_val = IXGBE_READ_REG(hw, 19386621Sbt150084 IXGBE_DCA_TXCTRL(tx_ring->index)); 19396621Sbt150084 reg_val &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; 19406621Sbt150084 IXGBE_WRITE_REG(hw, 19416621Sbt150084 IXGBE_DCA_TXCTRL(tx_ring->index), reg_val); 19426621Sbt150084 } else { 19436621Sbt150084 tx_ring->tbd_head_wb = NULL; 19446621Sbt150084 } 19456621Sbt150084 19466621Sbt150084 tx_ring->tbd_head = 0; 19476621Sbt150084 tx_ring->tbd_tail = 0; 19486621Sbt150084 tx_ring->tbd_free = tx_ring->ring_size; 19496621Sbt150084 195010376SChenlu.Chen@Sun.COM if (ixgbe->tx_ring_init == B_TRUE) { 19516621Sbt150084 tx_ring->tcb_head = 0; 19526621Sbt150084 tx_ring->tcb_tail = 0; 19536621Sbt150084 tx_ring->tcb_free = tx_ring->free_list_size; 19546621Sbt150084 } 19556621Sbt150084 19566621Sbt150084 /* 19577245Sgg161487 * Initialize the s/w context structure 19586621Sbt150084 */ 19597245Sgg161487 bzero(&tx_ring->tx_context, sizeof (ixgbe_tx_context_t)); 19606621Sbt150084 } 19616621Sbt150084 19626621Sbt150084 static void 19636621Sbt150084 ixgbe_setup_tx(ixgbe_t *ixgbe) 19646621Sbt150084 { 19657167Sgg161487 struct ixgbe_hw *hw = &ixgbe->hw; 19666621Sbt150084 ixgbe_tx_ring_t *tx_ring; 19677167Sgg161487 uint32_t reg_val; 19688275SEric Cheng uint32_t ring_mapping; 19696621Sbt150084 int i; 19706621Sbt150084 19716621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 19726621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 19736621Sbt150084 ixgbe_setup_tx_ring(tx_ring); 19746621Sbt150084 } 19757167Sgg161487 19767167Sgg161487 /* 19778275SEric Cheng * Setup the per-ring statistics mapping. 19788275SEric Cheng */ 19798275SEric Cheng ring_mapping = 0; 19808275SEric Cheng for (i = 0; i < ixgbe->num_tx_rings; i++) { 19818275SEric Cheng ring_mapping |= (i & 0xF) << (8 * (i & 0x3)); 19828275SEric Cheng if ((i & 0x3) == 0x3) { 19839353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 19849353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_TQSM(i >> 2), 19859353SSamuel.Tu@Sun.COM ring_mapping); 19869353SSamuel.Tu@Sun.COM } else { 19879353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i >> 2), 19889353SSamuel.Tu@Sun.COM ring_mapping); 19899353SSamuel.Tu@Sun.COM } 19908275SEric Cheng ring_mapping = 0; 19918275SEric Cheng } 19928275SEric Cheng } 19938275SEric Cheng if ((i & 0x3) != 0x3) 19949353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 19959353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_TQSM(i >> 2), ring_mapping); 19969353SSamuel.Tu@Sun.COM } else { 19979353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i >> 2), ring_mapping); 19989353SSamuel.Tu@Sun.COM } 19998275SEric Cheng 20008275SEric Cheng /* 20017167Sgg161487 * Enable CRC appending and TX padding (for short tx frames) 20027167Sgg161487 */ 20037167Sgg161487 reg_val = IXGBE_READ_REG(hw, IXGBE_HLREG0); 20047167Sgg161487 reg_val |= IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN; 20057167Sgg161487 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_val); 20069353SSamuel.Tu@Sun.COM 20079353SSamuel.Tu@Sun.COM /* 20089353SSamuel.Tu@Sun.COM * enable DMA for 82599 parts 20099353SSamuel.Tu@Sun.COM */ 20109353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 20119353SSamuel.Tu@Sun.COM /* DMATXCTL.TE must be set after all Tx config is complete */ 20129353SSamuel.Tu@Sun.COM reg_val = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); 20139353SSamuel.Tu@Sun.COM reg_val |= IXGBE_DMATXCTL_TE; 20149353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_val); 20159353SSamuel.Tu@Sun.COM } 20169353SSamuel.Tu@Sun.COM 20179353SSamuel.Tu@Sun.COM /* 20189353SSamuel.Tu@Sun.COM * Enabling tx queues .. 20199353SSamuel.Tu@Sun.COM * For 82599 must be done after DMATXCTL.TE is set 20209353SSamuel.Tu@Sun.COM */ 20219353SSamuel.Tu@Sun.COM for (i = 0; i < ixgbe->num_tx_rings; i++) { 20229353SSamuel.Tu@Sun.COM tx_ring = &ixgbe->tx_rings[i]; 20239353SSamuel.Tu@Sun.COM reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(tx_ring->index)); 20249353SSamuel.Tu@Sun.COM reg_val |= IXGBE_TXDCTL_ENABLE; 20259353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->index), reg_val); 20269353SSamuel.Tu@Sun.COM } 20276621Sbt150084 } 20286621Sbt150084 20296621Sbt150084 /* 20306621Sbt150084 * ixgbe_setup_rss - Setup receive-side scaling feature. 20316621Sbt150084 */ 20326621Sbt150084 static void 20336621Sbt150084 ixgbe_setup_rss(ixgbe_t *ixgbe) 20346621Sbt150084 { 20356621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 20367167Sgg161487 uint32_t i, mrqc, rxcsum; 20376621Sbt150084 uint32_t random; 20386621Sbt150084 uint32_t reta; 20396621Sbt150084 20406621Sbt150084 /* 20416621Sbt150084 * Fill out redirection table 20426621Sbt150084 */ 20436621Sbt150084 reta = 0; 20446621Sbt150084 for (i = 0; i < 128; i++) { 20457167Sgg161487 reta = (reta << 8) | (i % ixgbe->num_rx_rings); 20467167Sgg161487 if ((i & 3) == 3) 20476621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); 20486621Sbt150084 } 20496621Sbt150084 20506621Sbt150084 /* 20516621Sbt150084 * Fill out hash function seeds with a random constant 20526621Sbt150084 */ 20536621Sbt150084 for (i = 0; i < 10; i++) { 20546621Sbt150084 (void) random_get_pseudo_bytes((uint8_t *)&random, 20556621Sbt150084 sizeof (uint32_t)); 20566621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random); 20576621Sbt150084 } 20586621Sbt150084 20596621Sbt150084 /* 20607167Sgg161487 * Enable RSS & perform hash on these packet types 20616621Sbt150084 */ 20626621Sbt150084 mrqc = IXGBE_MRQC_RSSEN | 20636621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV4 | 20646621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV4_TCP | 20656621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV4_UDP | 20666621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP | 20676621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6_EX | 20686621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6 | 20696621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6_TCP | 20706621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6_UDP | 20716621Sbt150084 IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP; 20726621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); 20736621Sbt150084 20746621Sbt150084 /* 20756621Sbt150084 * Disable Packet Checksum to enable RSS for multiple receive queues. 20766621Sbt150084 * It is an adapter hardware limitation that Packet Checksum is 20776621Sbt150084 * mutually exclusive with RSS. 20786621Sbt150084 */ 20796621Sbt150084 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); 20806621Sbt150084 rxcsum |= IXGBE_RXCSUM_PCSD; 20816621Sbt150084 rxcsum &= ~IXGBE_RXCSUM_IPPCSE; 20826621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); 20836621Sbt150084 } 20846621Sbt150084 20856621Sbt150084 /* 20866621Sbt150084 * ixgbe_init_unicst - Initialize the unicast addresses. 20876621Sbt150084 */ 20886621Sbt150084 static void 20896621Sbt150084 ixgbe_init_unicst(ixgbe_t *ixgbe) 20906621Sbt150084 { 20916621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 20928275SEric Cheng uint8_t *mac_addr; 20936621Sbt150084 int slot; 20946621Sbt150084 /* 20956621Sbt150084 * Here we should consider two situations: 20966621Sbt150084 * 20978275SEric Cheng * 1. Chipset is initialized at the first time, 20988275SEric Cheng * Clear all the multiple unicast addresses. 20996621Sbt150084 * 21006621Sbt150084 * 2. Chipset is reset 21016621Sbt150084 * Recover the multiple unicast addresses from the 21026621Sbt150084 * software data structure to the RAR registers. 21036621Sbt150084 */ 21046621Sbt150084 if (!ixgbe->unicst_init) { 21056621Sbt150084 /* 21066621Sbt150084 * Initialize the multiple unicast addresses 21076621Sbt150084 */ 21086621Sbt150084 ixgbe->unicst_total = MAX_NUM_UNICAST_ADDRESSES; 21098275SEric Cheng ixgbe->unicst_avail = ixgbe->unicst_total; 21108275SEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) { 21118275SEric Cheng mac_addr = ixgbe->unicst_addr[slot].mac.addr; 21128275SEric Cheng bzero(mac_addr, ETHERADDRL); 21138275SEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr, NULL, NULL); 21146621Sbt150084 ixgbe->unicst_addr[slot].mac.set = 0; 21158275SEric Cheng } 21166621Sbt150084 ixgbe->unicst_init = B_TRUE; 21176621Sbt150084 } else { 21186621Sbt150084 /* Re-configure the RAR registers */ 21198275SEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) { 21208275SEric Cheng mac_addr = ixgbe->unicst_addr[slot].mac.addr; 21218275SEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 1) { 21228275SEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr, 21238275SEric Cheng NULL, IXGBE_RAH_AV); 21248275SEric Cheng } else { 21258275SEric Cheng bzero(mac_addr, ETHERADDRL); 21268275SEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr, 21278275SEric Cheng NULL, NULL); 21288275SEric Cheng } 21298275SEric Cheng } 21306621Sbt150084 } 21316621Sbt150084 } 21328275SEric Cheng 21336621Sbt150084 /* 21346621Sbt150084 * ixgbe_unicst_set - Set the unicast address to the specified slot. 21356621Sbt150084 */ 21366621Sbt150084 int 21376621Sbt150084 ixgbe_unicst_set(ixgbe_t *ixgbe, const uint8_t *mac_addr, 21388275SEric Cheng int slot) 21396621Sbt150084 { 21406621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 21416621Sbt150084 21426621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 21436621Sbt150084 21446621Sbt150084 /* 21456621Sbt150084 * Save the unicast address in the software data structure 21466621Sbt150084 */ 21476621Sbt150084 bcopy(mac_addr, ixgbe->unicst_addr[slot].mac.addr, ETHERADDRL); 21486621Sbt150084 21496621Sbt150084 /* 21506621Sbt150084 * Set the unicast address to the RAR register 21516621Sbt150084 */ 21528275SEric Cheng (void) ixgbe_set_rar(hw, slot, (uint8_t *)mac_addr, NULL, IXGBE_RAH_AV); 21536621Sbt150084 21546621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 21556621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED); 21566621Sbt150084 return (EIO); 21576621Sbt150084 } 21586621Sbt150084 21596621Sbt150084 return (0); 21606621Sbt150084 } 21616621Sbt150084 21626621Sbt150084 /* 21638275SEric Cheng * ixgbe_unicst_find - Find the slot for the specified unicast address 21648275SEric Cheng */ 21658275SEric Cheng int 21668275SEric Cheng ixgbe_unicst_find(ixgbe_t *ixgbe, const uint8_t *mac_addr) 21678275SEric Cheng { 21688275SEric Cheng int slot; 21698275SEric Cheng 21708275SEric Cheng ASSERT(mutex_owned(&ixgbe->gen_lock)); 21718275SEric Cheng 21728275SEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) { 21738275SEric Cheng if (bcmp(ixgbe->unicst_addr[slot].mac.addr, 21748275SEric Cheng mac_addr, ETHERADDRL) == 0) 21758275SEric Cheng return (slot); 21768275SEric Cheng } 21778275SEric Cheng 21788275SEric Cheng return (-1); 21798275SEric Cheng } 21808275SEric Cheng 21818275SEric Cheng /* 21826621Sbt150084 * ixgbe_multicst_add - Add a multicst address. 21836621Sbt150084 */ 21846621Sbt150084 int 21856621Sbt150084 ixgbe_multicst_add(ixgbe_t *ixgbe, const uint8_t *multiaddr) 21866621Sbt150084 { 21876621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 21886621Sbt150084 21896621Sbt150084 if ((multiaddr[0] & 01) == 0) { 21906621Sbt150084 return (EINVAL); 21916621Sbt150084 } 21926621Sbt150084 21936621Sbt150084 if (ixgbe->mcast_count >= MAX_NUM_MULTICAST_ADDRESSES) { 21946621Sbt150084 return (ENOENT); 21956621Sbt150084 } 21966621Sbt150084 21976621Sbt150084 bcopy(multiaddr, 21986621Sbt150084 &ixgbe->mcast_table[ixgbe->mcast_count], ETHERADDRL); 21996621Sbt150084 ixgbe->mcast_count++; 22006621Sbt150084 22016621Sbt150084 /* 22026621Sbt150084 * Update the multicast table in the hardware 22036621Sbt150084 */ 22046621Sbt150084 ixgbe_setup_multicst(ixgbe); 22056621Sbt150084 22066621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 22076621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED); 22086621Sbt150084 return (EIO); 22096621Sbt150084 } 22106621Sbt150084 22116621Sbt150084 return (0); 22126621Sbt150084 } 22136621Sbt150084 22146621Sbt150084 /* 22156621Sbt150084 * ixgbe_multicst_remove - Remove a multicst address. 22166621Sbt150084 */ 22176621Sbt150084 int 22186621Sbt150084 ixgbe_multicst_remove(ixgbe_t *ixgbe, const uint8_t *multiaddr) 22196621Sbt150084 { 22206621Sbt150084 int i; 22216621Sbt150084 22226621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 22236621Sbt150084 22246621Sbt150084 for (i = 0; i < ixgbe->mcast_count; i++) { 22256621Sbt150084 if (bcmp(multiaddr, &ixgbe->mcast_table[i], 22266621Sbt150084 ETHERADDRL) == 0) { 22276621Sbt150084 for (i++; i < ixgbe->mcast_count; i++) { 22286621Sbt150084 ixgbe->mcast_table[i - 1] = 22296621Sbt150084 ixgbe->mcast_table[i]; 22306621Sbt150084 } 22316621Sbt150084 ixgbe->mcast_count--; 22326621Sbt150084 break; 22336621Sbt150084 } 22346621Sbt150084 } 22356621Sbt150084 22366621Sbt150084 /* 22376621Sbt150084 * Update the multicast table in the hardware 22386621Sbt150084 */ 22396621Sbt150084 ixgbe_setup_multicst(ixgbe); 22406621Sbt150084 22416621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 22426621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED); 22436621Sbt150084 return (EIO); 22446621Sbt150084 } 22456621Sbt150084 22466621Sbt150084 return (0); 22476621Sbt150084 } 22486621Sbt150084 22496621Sbt150084 /* 22506621Sbt150084 * ixgbe_setup_multicast - Setup multicast data structures. 22516621Sbt150084 * 22526621Sbt150084 * This routine initializes all of the multicast related structures 22536621Sbt150084 * and save them in the hardware registers. 22546621Sbt150084 */ 22556621Sbt150084 static void 22566621Sbt150084 ixgbe_setup_multicst(ixgbe_t *ixgbe) 22576621Sbt150084 { 22586621Sbt150084 uint8_t *mc_addr_list; 22596621Sbt150084 uint32_t mc_addr_count; 22606621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 22616621Sbt150084 22626621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 22636621Sbt150084 22646621Sbt150084 ASSERT(ixgbe->mcast_count <= MAX_NUM_MULTICAST_ADDRESSES); 22656621Sbt150084 22666621Sbt150084 mc_addr_list = (uint8_t *)ixgbe->mcast_table; 22676621Sbt150084 mc_addr_count = ixgbe->mcast_count; 22686621Sbt150084 22696621Sbt150084 /* 22706621Sbt150084 * Update the multicast addresses to the MTA registers 22716621Sbt150084 */ 22726621Sbt150084 (void) ixgbe_update_mc_addr_list(hw, mc_addr_list, mc_addr_count, 22736621Sbt150084 ixgbe_mc_table_itr); 22746621Sbt150084 } 22756621Sbt150084 22766621Sbt150084 /* 22776621Sbt150084 * ixgbe_get_conf - Get driver configurations set in driver.conf. 22786621Sbt150084 * 22796621Sbt150084 * This routine gets user-configured values out of the configuration 22806621Sbt150084 * file ixgbe.conf. 22816621Sbt150084 * 22826621Sbt150084 * For each configurable value, there is a minimum, a maximum, and a 22836621Sbt150084 * default. 22846621Sbt150084 * If user does not configure a value, use the default. 22856621Sbt150084 * If user configures below the minimum, use the minumum. 22866621Sbt150084 * If user configures above the maximum, use the maxumum. 22876621Sbt150084 */ 22886621Sbt150084 static void 22896621Sbt150084 ixgbe_get_conf(ixgbe_t *ixgbe) 22906621Sbt150084 { 22916621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 22926621Sbt150084 uint32_t flow_control; 22936621Sbt150084 22946621Sbt150084 /* 22956621Sbt150084 * ixgbe driver supports the following user configurations: 22966621Sbt150084 * 22976621Sbt150084 * Jumbo frame configuration: 22986621Sbt150084 * default_mtu 22996621Sbt150084 * 23006621Sbt150084 * Ethernet flow control configuration: 23016621Sbt150084 * flow_control 23026621Sbt150084 * 23036621Sbt150084 * Multiple rings configurations: 23046621Sbt150084 * tx_queue_number 23056621Sbt150084 * tx_ring_size 23066621Sbt150084 * rx_queue_number 23076621Sbt150084 * rx_ring_size 23086621Sbt150084 * 23096621Sbt150084 * Call ixgbe_get_prop() to get the value for a specific 23106621Sbt150084 * configuration parameter. 23116621Sbt150084 */ 23126621Sbt150084 23136621Sbt150084 /* 23146621Sbt150084 * Jumbo frame configuration - max_frame_size controls host buffer 23156621Sbt150084 * allocation, so includes MTU, ethernet header, vlan tag and 23166621Sbt150084 * frame check sequence. 23176621Sbt150084 */ 23186621Sbt150084 ixgbe->default_mtu = ixgbe_get_prop(ixgbe, PROP_DEFAULT_MTU, 23196621Sbt150084 MIN_MTU, MAX_MTU, DEFAULT_MTU); 23206621Sbt150084 23216621Sbt150084 ixgbe->max_frame_size = ixgbe->default_mtu + 23226621Sbt150084 sizeof (struct ether_vlan_header) + ETHERFCSL; 23236621Sbt150084 23246621Sbt150084 /* 23256621Sbt150084 * Ethernet flow control configuration 23266621Sbt150084 */ 23276621Sbt150084 flow_control = ixgbe_get_prop(ixgbe, PROP_FLOW_CONTROL, 23288275SEric Cheng ixgbe_fc_none, 3, ixgbe_fc_none); 23296621Sbt150084 if (flow_control == 3) 23306621Sbt150084 flow_control = ixgbe_fc_default; 23316621Sbt150084 23329353SSamuel.Tu@Sun.COM /* 23339353SSamuel.Tu@Sun.COM * fc.requested mode is what the user requests. After autoneg, 23349353SSamuel.Tu@Sun.COM * fc.current_mode will be the flow_control mode that was negotiated. 23359353SSamuel.Tu@Sun.COM */ 23369353SSamuel.Tu@Sun.COM hw->fc.requested_mode = flow_control; 23376621Sbt150084 23386621Sbt150084 /* 23396621Sbt150084 * Multiple rings configurations 23406621Sbt150084 */ 23416621Sbt150084 ixgbe->num_tx_rings = ixgbe_get_prop(ixgbe, PROP_TX_QUEUE_NUM, 23428490SPaul.Guo@Sun.COM ixgbe->capab->min_tx_que_num, 23438490SPaul.Guo@Sun.COM ixgbe->capab->max_tx_que_num, 23448490SPaul.Guo@Sun.COM ixgbe->capab->def_tx_que_num); 23456621Sbt150084 ixgbe->tx_ring_size = ixgbe_get_prop(ixgbe, PROP_TX_RING_SIZE, 23466621Sbt150084 MIN_TX_RING_SIZE, MAX_TX_RING_SIZE, DEFAULT_TX_RING_SIZE); 23476621Sbt150084 23486621Sbt150084 ixgbe->num_rx_rings = ixgbe_get_prop(ixgbe, PROP_RX_QUEUE_NUM, 23498490SPaul.Guo@Sun.COM ixgbe->capab->min_rx_que_num, 23508490SPaul.Guo@Sun.COM ixgbe->capab->max_rx_que_num, 23518490SPaul.Guo@Sun.COM ixgbe->capab->def_rx_que_num); 23526621Sbt150084 ixgbe->rx_ring_size = ixgbe_get_prop(ixgbe, PROP_RX_RING_SIZE, 23536621Sbt150084 MIN_RX_RING_SIZE, MAX_RX_RING_SIZE, DEFAULT_RX_RING_SIZE); 23546621Sbt150084 23556621Sbt150084 /* 23568275SEric Cheng * Multiple groups configuration 23578275SEric Cheng */ 23588275SEric Cheng ixgbe->num_rx_groups = ixgbe_get_prop(ixgbe, PROP_RX_GROUP_NUM, 23598275SEric Cheng MIN_RX_GROUP_NUM, MAX_RX_GROUP_NUM, DEFAULT_RX_GROUP_NUM); 23608275SEric Cheng 23618275SEric Cheng ixgbe->mr_enable = ixgbe_get_prop(ixgbe, PROP_MR_ENABLE, 23628275SEric Cheng 0, 1, DEFAULT_MR_ENABLE); 23638275SEric Cheng 23648275SEric Cheng if (ixgbe->mr_enable == B_FALSE) { 23658275SEric Cheng ixgbe->num_tx_rings = 1; 23668275SEric Cheng ixgbe->num_rx_rings = 1; 23678275SEric Cheng ixgbe->num_rx_groups = 1; 23688275SEric Cheng } 23698275SEric Cheng 23708275SEric Cheng /* 23716621Sbt150084 * Tunable used to force an interrupt type. The only use is 23726621Sbt150084 * for testing of the lesser interrupt types. 23736621Sbt150084 * 0 = don't force interrupt type 23748275SEric Cheng * 1 = force interrupt type MSI-X 23756621Sbt150084 * 2 = force interrupt type MSI 23766621Sbt150084 * 3 = force interrupt type Legacy 23776621Sbt150084 */ 23786621Sbt150084 ixgbe->intr_force = ixgbe_get_prop(ixgbe, PROP_INTR_FORCE, 23796621Sbt150084 IXGBE_INTR_NONE, IXGBE_INTR_LEGACY, IXGBE_INTR_NONE); 23806621Sbt150084 23816621Sbt150084 ixgbe->tx_hcksum_enable = ixgbe_get_prop(ixgbe, PROP_TX_HCKSUM_ENABLE, 23827167Sgg161487 0, 1, DEFAULT_TX_HCKSUM_ENABLE); 23836621Sbt150084 ixgbe->rx_hcksum_enable = ixgbe_get_prop(ixgbe, PROP_RX_HCKSUM_ENABLE, 23847167Sgg161487 0, 1, DEFAULT_RX_HCKSUM_ENABLE); 23856621Sbt150084 ixgbe->lso_enable = ixgbe_get_prop(ixgbe, PROP_LSO_ENABLE, 23867167Sgg161487 0, 1, DEFAULT_LSO_ENABLE); 23876621Sbt150084 ixgbe->tx_head_wb_enable = ixgbe_get_prop(ixgbe, PROP_TX_HEAD_WB_ENABLE, 23887167Sgg161487 0, 1, DEFAULT_TX_HEAD_WB_ENABLE); 23897167Sgg161487 23909353SSamuel.Tu@Sun.COM /* Head Write Back not recommended for 82599 */ 23919353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 23929353SSamuel.Tu@Sun.COM ixgbe->tx_head_wb_enable = B_FALSE; 23939353SSamuel.Tu@Sun.COM } 23949353SSamuel.Tu@Sun.COM 23957167Sgg161487 /* 23967167Sgg161487 * ixgbe LSO needs the tx h/w checksum support. 23977167Sgg161487 * LSO will be disabled if tx h/w checksum is not 23987167Sgg161487 * enabled. 23997167Sgg161487 */ 24007167Sgg161487 if (ixgbe->tx_hcksum_enable == B_FALSE) { 24017167Sgg161487 ixgbe->lso_enable = B_FALSE; 24027167Sgg161487 } 24036621Sbt150084 24046621Sbt150084 ixgbe->tx_copy_thresh = ixgbe_get_prop(ixgbe, PROP_TX_COPY_THRESHOLD, 24056621Sbt150084 MIN_TX_COPY_THRESHOLD, MAX_TX_COPY_THRESHOLD, 24066621Sbt150084 DEFAULT_TX_COPY_THRESHOLD); 24076621Sbt150084 ixgbe->tx_recycle_thresh = ixgbe_get_prop(ixgbe, 24086621Sbt150084 PROP_TX_RECYCLE_THRESHOLD, MIN_TX_RECYCLE_THRESHOLD, 24096621Sbt150084 MAX_TX_RECYCLE_THRESHOLD, DEFAULT_TX_RECYCLE_THRESHOLD); 24106621Sbt150084 ixgbe->tx_overload_thresh = ixgbe_get_prop(ixgbe, 24116621Sbt150084 PROP_TX_OVERLOAD_THRESHOLD, MIN_TX_OVERLOAD_THRESHOLD, 24126621Sbt150084 MAX_TX_OVERLOAD_THRESHOLD, DEFAULT_TX_OVERLOAD_THRESHOLD); 24136621Sbt150084 ixgbe->tx_resched_thresh = ixgbe_get_prop(ixgbe, 24146621Sbt150084 PROP_TX_RESCHED_THRESHOLD, MIN_TX_RESCHED_THRESHOLD, 24156621Sbt150084 MAX_TX_RESCHED_THRESHOLD, DEFAULT_TX_RESCHED_THRESHOLD); 24166621Sbt150084 24176621Sbt150084 ixgbe->rx_copy_thresh = ixgbe_get_prop(ixgbe, PROP_RX_COPY_THRESHOLD, 24186621Sbt150084 MIN_RX_COPY_THRESHOLD, MAX_RX_COPY_THRESHOLD, 24196621Sbt150084 DEFAULT_RX_COPY_THRESHOLD); 24206621Sbt150084 ixgbe->rx_limit_per_intr = ixgbe_get_prop(ixgbe, PROP_RX_LIMIT_PER_INTR, 24216621Sbt150084 MIN_RX_LIMIT_PER_INTR, MAX_RX_LIMIT_PER_INTR, 24226621Sbt150084 DEFAULT_RX_LIMIT_PER_INTR); 24236621Sbt150084 242410376SChenlu.Chen@Sun.COM ixgbe->intr_throttling[0] = ixgbe_get_prop(ixgbe, PROP_INTR_THROTTLING, 242510376SChenlu.Chen@Sun.COM ixgbe->capab->min_intr_throttle, 242610376SChenlu.Chen@Sun.COM ixgbe->capab->max_intr_throttle, 242710376SChenlu.Chen@Sun.COM ixgbe->capab->def_intr_throttle); 24289353SSamuel.Tu@Sun.COM /* 242910376SChenlu.Chen@Sun.COM * 82599 requires the interupt throttling rate is 243010376SChenlu.Chen@Sun.COM * a multiple of 8. This is enforced by the register 243110376SChenlu.Chen@Sun.COM * definiton. 24329353SSamuel.Tu@Sun.COM */ 243310376SChenlu.Chen@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) 243410376SChenlu.Chen@Sun.COM ixgbe->intr_throttling[0] = ixgbe->intr_throttling[0] & 0xFF8; 243510376SChenlu.Chen@Sun.COM } 243610376SChenlu.Chen@Sun.COM 243710376SChenlu.Chen@Sun.COM static void 243810376SChenlu.Chen@Sun.COM ixgbe_init_params(ixgbe_t *ixgbe) 243910376SChenlu.Chen@Sun.COM { 244010376SChenlu.Chen@Sun.COM ixgbe->param_en_10000fdx_cap = 1; 244110376SChenlu.Chen@Sun.COM ixgbe->param_en_1000fdx_cap = 1; 244210376SChenlu.Chen@Sun.COM ixgbe->param_en_100fdx_cap = 1; 244310376SChenlu.Chen@Sun.COM ixgbe->param_adv_10000fdx_cap = 1; 244410376SChenlu.Chen@Sun.COM ixgbe->param_adv_1000fdx_cap = 1; 244510376SChenlu.Chen@Sun.COM ixgbe->param_adv_100fdx_cap = 1; 244610376SChenlu.Chen@Sun.COM 244710376SChenlu.Chen@Sun.COM ixgbe->param_pause_cap = 1; 244810376SChenlu.Chen@Sun.COM ixgbe->param_asym_pause_cap = 1; 244910376SChenlu.Chen@Sun.COM ixgbe->param_rem_fault = 0; 245010376SChenlu.Chen@Sun.COM 245110376SChenlu.Chen@Sun.COM ixgbe->param_adv_autoneg_cap = 1; 245210376SChenlu.Chen@Sun.COM ixgbe->param_adv_pause_cap = 1; 245310376SChenlu.Chen@Sun.COM ixgbe->param_adv_asym_pause_cap = 1; 245410376SChenlu.Chen@Sun.COM ixgbe->param_adv_rem_fault = 0; 245510376SChenlu.Chen@Sun.COM 245610376SChenlu.Chen@Sun.COM ixgbe->param_lp_10000fdx_cap = 0; 245710376SChenlu.Chen@Sun.COM ixgbe->param_lp_1000fdx_cap = 0; 245810376SChenlu.Chen@Sun.COM ixgbe->param_lp_100fdx_cap = 0; 245910376SChenlu.Chen@Sun.COM ixgbe->param_lp_autoneg_cap = 0; 246010376SChenlu.Chen@Sun.COM ixgbe->param_lp_pause_cap = 0; 246110376SChenlu.Chen@Sun.COM ixgbe->param_lp_asym_pause_cap = 0; 246210376SChenlu.Chen@Sun.COM ixgbe->param_lp_rem_fault = 0; 24636621Sbt150084 } 24646621Sbt150084 24656621Sbt150084 /* 24666621Sbt150084 * ixgbe_get_prop - Get a property value out of the configuration file 24676621Sbt150084 * ixgbe.conf. 24686621Sbt150084 * 24696621Sbt150084 * Caller provides the name of the property, a default value, a minimum 24706621Sbt150084 * value, and a maximum value. 24716621Sbt150084 * 24726621Sbt150084 * Return configured value of the property, with default, minimum and 24736621Sbt150084 * maximum properly applied. 24746621Sbt150084 */ 24756621Sbt150084 static int 24766621Sbt150084 ixgbe_get_prop(ixgbe_t *ixgbe, 24776621Sbt150084 char *propname, /* name of the property */ 24786621Sbt150084 int minval, /* minimum acceptable value */ 24796621Sbt150084 int maxval, /* maximim acceptable value */ 24806621Sbt150084 int defval) /* default value */ 24816621Sbt150084 { 24826621Sbt150084 int value; 24836621Sbt150084 24846621Sbt150084 /* 24856621Sbt150084 * Call ddi_prop_get_int() to read the conf settings 24866621Sbt150084 */ 24876621Sbt150084 value = ddi_prop_get_int(DDI_DEV_T_ANY, ixgbe->dip, 24886621Sbt150084 DDI_PROP_DONTPASS, propname, defval); 24896621Sbt150084 if (value > maxval) 24906621Sbt150084 value = maxval; 24916621Sbt150084 24926621Sbt150084 if (value < minval) 24936621Sbt150084 value = minval; 24946621Sbt150084 24956621Sbt150084 return (value); 24966621Sbt150084 } 24976621Sbt150084 24986621Sbt150084 /* 24996621Sbt150084 * ixgbe_driver_setup_link - Using the link properties to setup the link. 25006621Sbt150084 */ 25016621Sbt150084 int 25026621Sbt150084 ixgbe_driver_setup_link(ixgbe_t *ixgbe, boolean_t setup_hw) 25036621Sbt150084 { 2504*10998SChenlu.Chen@Sun.COM u32 autoneg_advertised = 0; 2505*10998SChenlu.Chen@Sun.COM 2506*10998SChenlu.Chen@Sun.COM /* 2507*10998SChenlu.Chen@Sun.COM * No half duplex support with 10Gb parts 2508*10998SChenlu.Chen@Sun.COM */ 2509*10998SChenlu.Chen@Sun.COM if (ixgbe->param_adv_10000fdx_cap == 1) 2510*10998SChenlu.Chen@Sun.COM autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; 2511*10998SChenlu.Chen@Sun.COM 2512*10998SChenlu.Chen@Sun.COM if (ixgbe->param_adv_1000fdx_cap == 1) 2513*10998SChenlu.Chen@Sun.COM autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; 2514*10998SChenlu.Chen@Sun.COM 2515*10998SChenlu.Chen@Sun.COM if (ixgbe->param_adv_100fdx_cap == 1) 2516*10998SChenlu.Chen@Sun.COM autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL; 2517*10998SChenlu.Chen@Sun.COM 2518*10998SChenlu.Chen@Sun.COM if (ixgbe->param_adv_autoneg_cap == 1 && autoneg_advertised == 0) { 2519*10998SChenlu.Chen@Sun.COM ixgbe_notice(ixgbe, "Invalid link settings. Setup link " 2520*10998SChenlu.Chen@Sun.COM "to autonegotiation with full link capabilities."); 2521*10998SChenlu.Chen@Sun.COM 2522*10998SChenlu.Chen@Sun.COM autoneg_advertised = IXGBE_LINK_SPEED_10GB_FULL | 2523*10998SChenlu.Chen@Sun.COM IXGBE_LINK_SPEED_1GB_FULL | 2524*10998SChenlu.Chen@Sun.COM IXGBE_LINK_SPEED_100_FULL; 25256621Sbt150084 } 25266621Sbt150084 25276621Sbt150084 if (setup_hw) { 2528*10998SChenlu.Chen@Sun.COM if (ixgbe_setup_link(&ixgbe->hw, autoneg_advertised, 2529*10998SChenlu.Chen@Sun.COM ixgbe->param_adv_autoneg_cap, B_TRUE) != IXGBE_SUCCESS) { 25309353SSamuel.Tu@Sun.COM ixgbe_notice(ixgbe, "Setup link failed on this " 25319353SSamuel.Tu@Sun.COM "device."); 25326621Sbt150084 return (IXGBE_FAILURE); 25339353SSamuel.Tu@Sun.COM } 25346621Sbt150084 } 25356621Sbt150084 25366621Sbt150084 return (IXGBE_SUCCESS); 25376621Sbt150084 } 25386621Sbt150084 25396621Sbt150084 /* 25408490SPaul.Guo@Sun.COM * ixgbe_driver_link_check - Link status processing done in taskq. 25416621Sbt150084 */ 25428490SPaul.Guo@Sun.COM static void 25438490SPaul.Guo@Sun.COM ixgbe_driver_link_check(void *arg) 25446621Sbt150084 { 25458490SPaul.Guo@Sun.COM ixgbe_t *ixgbe = (ixgbe_t *)arg; 25466621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 25476621Sbt150084 ixgbe_link_speed speed = IXGBE_LINK_SPEED_UNKNOWN; 25486621Sbt150084 boolean_t link_up = B_FALSE; 25496621Sbt150084 boolean_t link_changed = B_FALSE; 25506621Sbt150084 25518490SPaul.Guo@Sun.COM mutex_enter(&ixgbe->gen_lock); 25528490SPaul.Guo@Sun.COM 25538490SPaul.Guo@Sun.COM /* check for link, wait the full time */ 25548490SPaul.Guo@Sun.COM (void) ixgbe_check_link(hw, &speed, &link_up, true); 25556621Sbt150084 if (link_up) { 25569353SSamuel.Tu@Sun.COM /* Link is up, enable flow control settings */ 25579353SSamuel.Tu@Sun.COM (void) ixgbe_fc_enable(hw, 0); 25589353SSamuel.Tu@Sun.COM 25596621Sbt150084 /* 25606621Sbt150084 * The Link is up, check whether it was marked as down earlier 25616621Sbt150084 */ 25626621Sbt150084 if (ixgbe->link_state != LINK_STATE_UP) { 25636621Sbt150084 switch (speed) { 25649353SSamuel.Tu@Sun.COM case IXGBE_LINK_SPEED_10GB_FULL: 25659353SSamuel.Tu@Sun.COM ixgbe->link_speed = SPEED_10GB; 25669353SSamuel.Tu@Sun.COM break; 25679353SSamuel.Tu@Sun.COM case IXGBE_LINK_SPEED_1GB_FULL: 25689353SSamuel.Tu@Sun.COM ixgbe->link_speed = SPEED_1GB; 25699353SSamuel.Tu@Sun.COM break; 25709353SSamuel.Tu@Sun.COM case IXGBE_LINK_SPEED_100_FULL: 25719353SSamuel.Tu@Sun.COM ixgbe->link_speed = SPEED_100; 25726621Sbt150084 } 25736621Sbt150084 ixgbe->link_duplex = LINK_DUPLEX_FULL; 25746621Sbt150084 ixgbe->link_state = LINK_STATE_UP; 25756621Sbt150084 ixgbe->link_down_timeout = 0; 25766621Sbt150084 link_changed = B_TRUE; 25776621Sbt150084 } 25786621Sbt150084 } else { 25796621Sbt150084 if (ixgbe->link_state != LINK_STATE_DOWN) { 25806621Sbt150084 ixgbe->link_speed = 0; 25816621Sbt150084 ixgbe->link_duplex = 0; 25826621Sbt150084 ixgbe->link_state = LINK_STATE_DOWN; 25836621Sbt150084 link_changed = B_TRUE; 25846621Sbt150084 } 25856621Sbt150084 25866621Sbt150084 if (ixgbe->ixgbe_state & IXGBE_STARTED) { 25876621Sbt150084 if (ixgbe->link_down_timeout < MAX_LINK_DOWN_TIMEOUT) { 25886621Sbt150084 ixgbe->link_down_timeout++; 25896621Sbt150084 } else if (ixgbe->link_down_timeout == 25906621Sbt150084 MAX_LINK_DOWN_TIMEOUT) { 25916621Sbt150084 ixgbe_tx_clean(ixgbe); 25926621Sbt150084 ixgbe->link_down_timeout++; 25936621Sbt150084 } 25946621Sbt150084 } 25956621Sbt150084 } 25966621Sbt150084 25978490SPaul.Guo@Sun.COM /* 25988490SPaul.Guo@Sun.COM * this is only reached after a link-status-change interrupt 25998490SPaul.Guo@Sun.COM * so always get new phy state 26008490SPaul.Guo@Sun.COM */ 26018490SPaul.Guo@Sun.COM ixgbe_get_hw_state(ixgbe); 26028490SPaul.Guo@Sun.COM 26038490SPaul.Guo@Sun.COM /* re-enable the interrupt, which was automasked */ 26048490SPaul.Guo@Sun.COM ixgbe->eims |= IXGBE_EICR_LSC; 26058490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims); 26068490SPaul.Guo@Sun.COM 26078490SPaul.Guo@Sun.COM mutex_exit(&ixgbe->gen_lock); 26088490SPaul.Guo@Sun.COM 26098490SPaul.Guo@Sun.COM /* outside the gen_lock */ 26108490SPaul.Guo@Sun.COM if (link_changed) { 26118490SPaul.Guo@Sun.COM mac_link_update(ixgbe->mac_hdl, ixgbe->link_state); 26128490SPaul.Guo@Sun.COM } 26136621Sbt150084 } 26146621Sbt150084 26156621Sbt150084 /* 26169353SSamuel.Tu@Sun.COM * ixgbe_sfp_check - sfp module processing done in taskq only for 82599. 26179353SSamuel.Tu@Sun.COM */ 26189353SSamuel.Tu@Sun.COM static void 26199353SSamuel.Tu@Sun.COM ixgbe_sfp_check(void *arg) 26209353SSamuel.Tu@Sun.COM { 26219353SSamuel.Tu@Sun.COM ixgbe_t *ixgbe = (ixgbe_t *)arg; 26229353SSamuel.Tu@Sun.COM uint32_t eicr = ixgbe->eicr; 26239353SSamuel.Tu@Sun.COM struct ixgbe_hw *hw = &ixgbe->hw; 26249353SSamuel.Tu@Sun.COM 26259353SSamuel.Tu@Sun.COM if (eicr & IXGBE_EICR_GPI_SDP1) { 26269353SSamuel.Tu@Sun.COM /* clear the interrupt */ 26279353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); 26289353SSamuel.Tu@Sun.COM 26299353SSamuel.Tu@Sun.COM /* if link up, do multispeed fiber setup */ 2630*10998SChenlu.Chen@Sun.COM (void) ixgbe_setup_link(hw, IXGBE_LINK_SPEED_82599_AUTONEG, 2631*10998SChenlu.Chen@Sun.COM B_TRUE, B_TRUE); 26329353SSamuel.Tu@Sun.COM ixgbe_driver_link_check(ixgbe); 26339353SSamuel.Tu@Sun.COM } else if (eicr & IXGBE_EICR_GPI_SDP2) { 26349353SSamuel.Tu@Sun.COM /* clear the interrupt */ 26359353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); 26369353SSamuel.Tu@Sun.COM 26379353SSamuel.Tu@Sun.COM /* if link up, do sfp module setup */ 26389353SSamuel.Tu@Sun.COM (void) hw->mac.ops.setup_sfp(hw); 26399353SSamuel.Tu@Sun.COM 26409353SSamuel.Tu@Sun.COM /* do multispeed fiber setup */ 2641*10998SChenlu.Chen@Sun.COM (void) ixgbe_setup_link(hw, IXGBE_LINK_SPEED_82599_AUTONEG, 2642*10998SChenlu.Chen@Sun.COM B_TRUE, B_TRUE); 26439353SSamuel.Tu@Sun.COM ixgbe_driver_link_check(ixgbe); 26449353SSamuel.Tu@Sun.COM } 26459353SSamuel.Tu@Sun.COM } 26469353SSamuel.Tu@Sun.COM 26479353SSamuel.Tu@Sun.COM /* 26486621Sbt150084 * ixgbe_local_timer - Driver watchdog function. 26496621Sbt150084 * 26506621Sbt150084 * This function will handle the transmit stall check, link status check and 26516621Sbt150084 * other routines. 26526621Sbt150084 */ 26536621Sbt150084 static void 26546621Sbt150084 ixgbe_local_timer(void *arg) 26556621Sbt150084 { 26566621Sbt150084 ixgbe_t *ixgbe = (ixgbe_t *)arg; 26576621Sbt150084 26586621Sbt150084 if (ixgbe_stall_check(ixgbe)) { 26599353SSamuel.Tu@Sun.COM ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED); 26606621Sbt150084 ixgbe->reset_count++; 26616621Sbt150084 if (ixgbe_reset(ixgbe) == IXGBE_SUCCESS) 26626621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_RESTORED); 26636621Sbt150084 } 26646621Sbt150084 26656621Sbt150084 ixgbe_restart_watchdog_timer(ixgbe); 26666621Sbt150084 } 26676621Sbt150084 26686621Sbt150084 /* 26696621Sbt150084 * ixgbe_stall_check - Check for transmit stall. 26706621Sbt150084 * 26716621Sbt150084 * This function checks if the adapter is stalled (in transmit). 26726621Sbt150084 * 26736621Sbt150084 * It is called each time the watchdog timeout is invoked. 26746621Sbt150084 * If the transmit descriptor reclaim continuously fails, 26756621Sbt150084 * the watchdog value will increment by 1. If the watchdog 26766621Sbt150084 * value exceeds the threshold, the ixgbe is assumed to 26776621Sbt150084 * have stalled and need to be reset. 26786621Sbt150084 */ 26796621Sbt150084 static boolean_t 26806621Sbt150084 ixgbe_stall_check(ixgbe_t *ixgbe) 26816621Sbt150084 { 26826621Sbt150084 ixgbe_tx_ring_t *tx_ring; 26836621Sbt150084 boolean_t result; 26846621Sbt150084 int i; 26856621Sbt150084 26866621Sbt150084 if (ixgbe->link_state != LINK_STATE_UP) 26876621Sbt150084 return (B_FALSE); 26886621Sbt150084 26896621Sbt150084 /* 26906621Sbt150084 * If any tx ring is stalled, we'll reset the chipset 26916621Sbt150084 */ 26926621Sbt150084 result = B_FALSE; 26936621Sbt150084 for (i = 0; i < ixgbe->num_tx_rings; i++) { 26946621Sbt150084 tx_ring = &ixgbe->tx_rings[i]; 269510376SChenlu.Chen@Sun.COM if (tx_ring->tbd_free <= ixgbe->tx_recycle_thresh) { 269610305SPaul.Guo@Sun.COM tx_ring->tx_recycle(tx_ring); 269710305SPaul.Guo@Sun.COM } 26986621Sbt150084 26996621Sbt150084 if (tx_ring->recycle_fail > 0) 27006621Sbt150084 tx_ring->stall_watchdog++; 27016621Sbt150084 else 27026621Sbt150084 tx_ring->stall_watchdog = 0; 27036621Sbt150084 27046621Sbt150084 if (tx_ring->stall_watchdog >= STALL_WATCHDOG_TIMEOUT) { 27056621Sbt150084 result = B_TRUE; 27066621Sbt150084 break; 27076621Sbt150084 } 27086621Sbt150084 } 27096621Sbt150084 27106621Sbt150084 if (result) { 27116621Sbt150084 tx_ring->stall_watchdog = 0; 27126621Sbt150084 tx_ring->recycle_fail = 0; 27136621Sbt150084 } 27146621Sbt150084 27156621Sbt150084 return (result); 27166621Sbt150084 } 27176621Sbt150084 27186621Sbt150084 27196621Sbt150084 /* 27206621Sbt150084 * is_valid_mac_addr - Check if the mac address is valid. 27216621Sbt150084 */ 27226621Sbt150084 static boolean_t 27236621Sbt150084 is_valid_mac_addr(uint8_t *mac_addr) 27246621Sbt150084 { 27256621Sbt150084 const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 }; 27266621Sbt150084 const uint8_t addr_test2[6] = 27276621Sbt150084 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 27286621Sbt150084 27296621Sbt150084 if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) || 27306621Sbt150084 !(bcmp(addr_test2, mac_addr, ETHERADDRL))) 27316621Sbt150084 return (B_FALSE); 27326621Sbt150084 27336621Sbt150084 return (B_TRUE); 27346621Sbt150084 } 27356621Sbt150084 27366621Sbt150084 static boolean_t 27376621Sbt150084 ixgbe_find_mac_address(ixgbe_t *ixgbe) 27386621Sbt150084 { 27396621Sbt150084 #ifdef __sparc 27406621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 27416621Sbt150084 uchar_t *bytes; 27426621Sbt150084 struct ether_addr sysaddr; 27436621Sbt150084 uint_t nelts; 27446621Sbt150084 int err; 27456621Sbt150084 boolean_t found = B_FALSE; 27466621Sbt150084 27476621Sbt150084 /* 27486621Sbt150084 * The "vendor's factory-set address" may already have 27496621Sbt150084 * been extracted from the chip, but if the property 27506621Sbt150084 * "local-mac-address" is set we use that instead. 27516621Sbt150084 * 27526621Sbt150084 * We check whether it looks like an array of 6 27536621Sbt150084 * bytes (which it should, if OBP set it). If we can't 27546621Sbt150084 * make sense of it this way, we'll ignore it. 27556621Sbt150084 */ 27566621Sbt150084 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip, 27576621Sbt150084 DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts); 27586621Sbt150084 if (err == DDI_PROP_SUCCESS) { 27596621Sbt150084 if (nelts == ETHERADDRL) { 27606621Sbt150084 while (nelts--) 27616621Sbt150084 hw->mac.addr[nelts] = bytes[nelts]; 27626621Sbt150084 found = B_TRUE; 27636621Sbt150084 } 27646621Sbt150084 ddi_prop_free(bytes); 27656621Sbt150084 } 27666621Sbt150084 27676621Sbt150084 /* 27686621Sbt150084 * Look up the OBP property "local-mac-address?". If the user has set 27696621Sbt150084 * 'local-mac-address? = false', use "the system address" instead. 27706621Sbt150084 */ 27716621Sbt150084 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip, 0, 27726621Sbt150084 "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) { 27736621Sbt150084 if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) { 27746621Sbt150084 if (localetheraddr(NULL, &sysaddr) != 0) { 27756621Sbt150084 bcopy(&sysaddr, hw->mac.addr, ETHERADDRL); 27766621Sbt150084 found = B_TRUE; 27776621Sbt150084 } 27786621Sbt150084 } 27796621Sbt150084 ddi_prop_free(bytes); 27806621Sbt150084 } 27816621Sbt150084 27826621Sbt150084 /* 27836621Sbt150084 * Finally(!), if there's a valid "mac-address" property (created 27846621Sbt150084 * if we netbooted from this interface), we must use this instead 27856621Sbt150084 * of any of the above to ensure that the NFS/install server doesn't 27866621Sbt150084 * get confused by the address changing as Solaris takes over! 27876621Sbt150084 */ 27886621Sbt150084 err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip, 27896621Sbt150084 DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts); 27906621Sbt150084 if (err == DDI_PROP_SUCCESS) { 27916621Sbt150084 if (nelts == ETHERADDRL) { 27926621Sbt150084 while (nelts--) 27936621Sbt150084 hw->mac.addr[nelts] = bytes[nelts]; 27946621Sbt150084 found = B_TRUE; 27956621Sbt150084 } 27966621Sbt150084 ddi_prop_free(bytes); 27976621Sbt150084 } 27986621Sbt150084 27996621Sbt150084 if (found) { 28006621Sbt150084 bcopy(hw->mac.addr, hw->mac.perm_addr, ETHERADDRL); 28016621Sbt150084 return (B_TRUE); 28026621Sbt150084 } 28036621Sbt150084 #else 28046621Sbt150084 _NOTE(ARGUNUSED(ixgbe)); 28056621Sbt150084 #endif 28066621Sbt150084 28076621Sbt150084 return (B_TRUE); 28086621Sbt150084 } 28096621Sbt150084 28106621Sbt150084 #pragma inline(ixgbe_arm_watchdog_timer) 28116621Sbt150084 static void 28126621Sbt150084 ixgbe_arm_watchdog_timer(ixgbe_t *ixgbe) 28136621Sbt150084 { 28146621Sbt150084 /* 28156621Sbt150084 * Fire a watchdog timer 28166621Sbt150084 */ 28176621Sbt150084 ixgbe->watchdog_tid = 28186621Sbt150084 timeout(ixgbe_local_timer, 28196621Sbt150084 (void *)ixgbe, 1 * drv_usectohz(1000000)); 28206621Sbt150084 28216621Sbt150084 } 28226621Sbt150084 28236621Sbt150084 /* 28246621Sbt150084 * ixgbe_enable_watchdog_timer - Enable and start the driver watchdog timer. 28256621Sbt150084 */ 28266621Sbt150084 void 28276621Sbt150084 ixgbe_enable_watchdog_timer(ixgbe_t *ixgbe) 28286621Sbt150084 { 28296621Sbt150084 mutex_enter(&ixgbe->watchdog_lock); 28306621Sbt150084 28316621Sbt150084 if (!ixgbe->watchdog_enable) { 28326621Sbt150084 ixgbe->watchdog_enable = B_TRUE; 28336621Sbt150084 ixgbe->watchdog_start = B_TRUE; 28346621Sbt150084 ixgbe_arm_watchdog_timer(ixgbe); 28356621Sbt150084 } 28366621Sbt150084 28376621Sbt150084 mutex_exit(&ixgbe->watchdog_lock); 28386621Sbt150084 } 28396621Sbt150084 28406621Sbt150084 /* 28416621Sbt150084 * ixgbe_disable_watchdog_timer - Disable and stop the driver watchdog timer. 28426621Sbt150084 */ 28436621Sbt150084 void 28446621Sbt150084 ixgbe_disable_watchdog_timer(ixgbe_t *ixgbe) 28456621Sbt150084 { 28466621Sbt150084 timeout_id_t tid; 28476621Sbt150084 28486621Sbt150084 mutex_enter(&ixgbe->watchdog_lock); 28496621Sbt150084 28506621Sbt150084 ixgbe->watchdog_enable = B_FALSE; 28516621Sbt150084 ixgbe->watchdog_start = B_FALSE; 28526621Sbt150084 tid = ixgbe->watchdog_tid; 28536621Sbt150084 ixgbe->watchdog_tid = 0; 28546621Sbt150084 28556621Sbt150084 mutex_exit(&ixgbe->watchdog_lock); 28566621Sbt150084 28576621Sbt150084 if (tid != 0) 28586621Sbt150084 (void) untimeout(tid); 28596621Sbt150084 } 28606621Sbt150084 28616621Sbt150084 /* 28626621Sbt150084 * ixgbe_start_watchdog_timer - Start the driver watchdog timer. 28636621Sbt150084 */ 28648490SPaul.Guo@Sun.COM void 28656621Sbt150084 ixgbe_start_watchdog_timer(ixgbe_t *ixgbe) 28666621Sbt150084 { 28676621Sbt150084 mutex_enter(&ixgbe->watchdog_lock); 28686621Sbt150084 28696621Sbt150084 if (ixgbe->watchdog_enable) { 28706621Sbt150084 if (!ixgbe->watchdog_start) { 28716621Sbt150084 ixgbe->watchdog_start = B_TRUE; 28726621Sbt150084 ixgbe_arm_watchdog_timer(ixgbe); 28736621Sbt150084 } 28746621Sbt150084 } 28756621Sbt150084 28766621Sbt150084 mutex_exit(&ixgbe->watchdog_lock); 28776621Sbt150084 } 28786621Sbt150084 28796621Sbt150084 /* 28806621Sbt150084 * ixgbe_restart_watchdog_timer - Restart the driver watchdog timer. 28816621Sbt150084 */ 28826621Sbt150084 static void 28836621Sbt150084 ixgbe_restart_watchdog_timer(ixgbe_t *ixgbe) 28846621Sbt150084 { 28856621Sbt150084 mutex_enter(&ixgbe->watchdog_lock); 28866621Sbt150084 28876621Sbt150084 if (ixgbe->watchdog_start) 28886621Sbt150084 ixgbe_arm_watchdog_timer(ixgbe); 28896621Sbt150084 28906621Sbt150084 mutex_exit(&ixgbe->watchdog_lock); 28916621Sbt150084 } 28926621Sbt150084 28936621Sbt150084 /* 28946621Sbt150084 * ixgbe_stop_watchdog_timer - Stop the driver watchdog timer. 28956621Sbt150084 */ 28968490SPaul.Guo@Sun.COM void 28976621Sbt150084 ixgbe_stop_watchdog_timer(ixgbe_t *ixgbe) 28986621Sbt150084 { 28996621Sbt150084 timeout_id_t tid; 29006621Sbt150084 29016621Sbt150084 mutex_enter(&ixgbe->watchdog_lock); 29026621Sbt150084 29036621Sbt150084 ixgbe->watchdog_start = B_FALSE; 29046621Sbt150084 tid = ixgbe->watchdog_tid; 29056621Sbt150084 ixgbe->watchdog_tid = 0; 29066621Sbt150084 29076621Sbt150084 mutex_exit(&ixgbe->watchdog_lock); 29086621Sbt150084 29096621Sbt150084 if (tid != 0) 29106621Sbt150084 (void) untimeout(tid); 29116621Sbt150084 } 29126621Sbt150084 29136621Sbt150084 /* 29146621Sbt150084 * ixgbe_disable_adapter_interrupts - Disable all adapter interrupts. 29156621Sbt150084 */ 29166621Sbt150084 static void 29176621Sbt150084 ixgbe_disable_adapter_interrupts(ixgbe_t *ixgbe) 29186621Sbt150084 { 29196621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 29206621Sbt150084 29216621Sbt150084 /* 29226621Sbt150084 * mask all interrupts off 29236621Sbt150084 */ 29246621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xffffffff); 29256621Sbt150084 29266621Sbt150084 /* 29276621Sbt150084 * for MSI-X, also disable autoclear 29286621Sbt150084 */ 29296621Sbt150084 if (ixgbe->intr_type == DDI_INTR_TYPE_MSIX) { 29306621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EIAC, 0x0); 29316621Sbt150084 } 29326621Sbt150084 29336621Sbt150084 IXGBE_WRITE_FLUSH(hw); 29346621Sbt150084 } 29356621Sbt150084 29366621Sbt150084 /* 29376621Sbt150084 * ixgbe_enable_adapter_interrupts - Enable all hardware interrupts. 29386621Sbt150084 */ 29396621Sbt150084 static void 29406621Sbt150084 ixgbe_enable_adapter_interrupts(ixgbe_t *ixgbe) 29416621Sbt150084 { 29426621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 29438490SPaul.Guo@Sun.COM uint32_t eiac, eiam; 29448490SPaul.Guo@Sun.COM uint32_t gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); 29458490SPaul.Guo@Sun.COM 29468490SPaul.Guo@Sun.COM /* interrupt types to enable */ 29478490SPaul.Guo@Sun.COM ixgbe->eims = IXGBE_EIMS_ENABLE_MASK; /* shared code default */ 29488490SPaul.Guo@Sun.COM ixgbe->eims &= ~IXGBE_EIMS_TCP_TIMER; /* minus tcp timer */ 29498490SPaul.Guo@Sun.COM ixgbe->eims |= ixgbe->capab->other_intr; /* "other" interrupt types */ 29508490SPaul.Guo@Sun.COM 29518490SPaul.Guo@Sun.COM /* enable automask on "other" causes that this adapter can generate */ 29528490SPaul.Guo@Sun.COM eiam = ixgbe->capab->other_intr; 29536621Sbt150084 29546621Sbt150084 /* 29556621Sbt150084 * msi-x mode 29566621Sbt150084 */ 29576621Sbt150084 if (ixgbe->intr_type == DDI_INTR_TYPE_MSIX) { 29586621Sbt150084 /* enable autoclear but not on bits 29:20 */ 29598490SPaul.Guo@Sun.COM eiac = (ixgbe->eims & ~IXGBE_OTHER_INTR); 29606621Sbt150084 29616621Sbt150084 /* general purpose interrupt enable */ 29628490SPaul.Guo@Sun.COM gpie |= (IXGBE_GPIE_MSIX_MODE 29638490SPaul.Guo@Sun.COM | IXGBE_GPIE_PBA_SUPPORT 29648490SPaul.Guo@Sun.COM | IXGBE_GPIE_OCD 29658490SPaul.Guo@Sun.COM | IXGBE_GPIE_EIAME); 29666621Sbt150084 /* 29676621Sbt150084 * non-msi-x mode 29686621Sbt150084 */ 29696621Sbt150084 } else { 29706621Sbt150084 29716621Sbt150084 /* disable autoclear, leave gpie at default */ 29726621Sbt150084 eiac = 0; 29738490SPaul.Guo@Sun.COM 29749353SSamuel.Tu@Sun.COM /* 29759353SSamuel.Tu@Sun.COM * General purpose interrupt enable. 29769353SSamuel.Tu@Sun.COM * For 82599, extended interrupt automask enable 29779353SSamuel.Tu@Sun.COM * only in MSI or MSI-X mode 29789353SSamuel.Tu@Sun.COM */ 29799353SSamuel.Tu@Sun.COM if ((hw->mac.type < ixgbe_mac_82599EB) || 29809353SSamuel.Tu@Sun.COM (ixgbe->intr_type == DDI_INTR_TYPE_MSI)) { 29819353SSamuel.Tu@Sun.COM gpie |= IXGBE_GPIE_EIAME; 29829353SSamuel.Tu@Sun.COM } 29839353SSamuel.Tu@Sun.COM } 29849353SSamuel.Tu@Sun.COM /* Enable specific interrupts for 82599 */ 29859353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 29869353SSamuel.Tu@Sun.COM gpie |= IXGBE_SDP2_GPIEN; /* pluggable optics intr */ 29879353SSamuel.Tu@Sun.COM gpie |= IXGBE_SDP1_GPIEN; /* LSC interrupt */ 29886621Sbt150084 } 29896621Sbt150084 29908490SPaul.Guo@Sun.COM /* write to interrupt control registers */ 29918490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims); 29926621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EIAC, eiac); 29938490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIAM, eiam); 29946621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); 29956621Sbt150084 IXGBE_WRITE_FLUSH(hw); 29966621Sbt150084 } 29976621Sbt150084 29986621Sbt150084 /* 29996621Sbt150084 * ixgbe_loopback_ioctl - Loopback support. 30006621Sbt150084 */ 30016621Sbt150084 enum ioc_reply 30026621Sbt150084 ixgbe_loopback_ioctl(ixgbe_t *ixgbe, struct iocblk *iocp, mblk_t *mp) 30036621Sbt150084 { 30046621Sbt150084 lb_info_sz_t *lbsp; 30056621Sbt150084 lb_property_t *lbpp; 30066621Sbt150084 uint32_t *lbmp; 30076621Sbt150084 uint32_t size; 30086621Sbt150084 uint32_t value; 30096621Sbt150084 30106621Sbt150084 if (mp->b_cont == NULL) 30116621Sbt150084 return (IOC_INVAL); 30126621Sbt150084 30136621Sbt150084 switch (iocp->ioc_cmd) { 30146621Sbt150084 default: 30156621Sbt150084 return (IOC_INVAL); 30166621Sbt150084 30176621Sbt150084 case LB_GET_INFO_SIZE: 30186621Sbt150084 size = sizeof (lb_info_sz_t); 30196621Sbt150084 if (iocp->ioc_count != size) 30206621Sbt150084 return (IOC_INVAL); 30216621Sbt150084 30226621Sbt150084 value = sizeof (lb_normal); 30236621Sbt150084 value += sizeof (lb_mac); 30246621Sbt150084 30256621Sbt150084 lbsp = (lb_info_sz_t *)(uintptr_t)mp->b_cont->b_rptr; 30266621Sbt150084 *lbsp = value; 30276621Sbt150084 break; 30286621Sbt150084 30296621Sbt150084 case LB_GET_INFO: 30306621Sbt150084 value = sizeof (lb_normal); 30316621Sbt150084 value += sizeof (lb_mac); 30326621Sbt150084 30336621Sbt150084 size = value; 30346621Sbt150084 if (iocp->ioc_count != size) 30356621Sbt150084 return (IOC_INVAL); 30366621Sbt150084 30376621Sbt150084 value = 0; 30386621Sbt150084 lbpp = (lb_property_t *)(uintptr_t)mp->b_cont->b_rptr; 30396621Sbt150084 30406621Sbt150084 lbpp[value++] = lb_normal; 30416621Sbt150084 lbpp[value++] = lb_mac; 30426621Sbt150084 break; 30436621Sbt150084 30446621Sbt150084 case LB_GET_MODE: 30456621Sbt150084 size = sizeof (uint32_t); 30466621Sbt150084 if (iocp->ioc_count != size) 30476621Sbt150084 return (IOC_INVAL); 30486621Sbt150084 30496621Sbt150084 lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 30506621Sbt150084 *lbmp = ixgbe->loopback_mode; 30516621Sbt150084 break; 30526621Sbt150084 30536621Sbt150084 case LB_SET_MODE: 30546621Sbt150084 size = 0; 30556621Sbt150084 if (iocp->ioc_count != sizeof (uint32_t)) 30566621Sbt150084 return (IOC_INVAL); 30576621Sbt150084 30586621Sbt150084 lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr; 30596621Sbt150084 if (!ixgbe_set_loopback_mode(ixgbe, *lbmp)) 30606621Sbt150084 return (IOC_INVAL); 30616621Sbt150084 break; 30626621Sbt150084 } 30636621Sbt150084 30646621Sbt150084 iocp->ioc_count = size; 30656621Sbt150084 iocp->ioc_error = 0; 30666621Sbt150084 30676621Sbt150084 if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) { 30686621Sbt150084 ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED); 30696621Sbt150084 return (IOC_INVAL); 30706621Sbt150084 } 30716621Sbt150084 30726621Sbt150084 return (IOC_REPLY); 30736621Sbt150084 } 30746621Sbt150084 30756621Sbt150084 /* 30766621Sbt150084 * ixgbe_set_loopback_mode - Setup loopback based on the loopback mode. 30776621Sbt150084 */ 30786621Sbt150084 static boolean_t 30796621Sbt150084 ixgbe_set_loopback_mode(ixgbe_t *ixgbe, uint32_t mode) 30806621Sbt150084 { 30816621Sbt150084 if (mode == ixgbe->loopback_mode) 30826621Sbt150084 return (B_TRUE); 30836621Sbt150084 30846621Sbt150084 ixgbe->loopback_mode = mode; 30856621Sbt150084 30866621Sbt150084 if (mode == IXGBE_LB_NONE) { 30876621Sbt150084 /* 30886621Sbt150084 * Reset the chip 30896621Sbt150084 */ 30906621Sbt150084 (void) ixgbe_reset(ixgbe); 30916621Sbt150084 return (B_TRUE); 30926621Sbt150084 } 30936621Sbt150084 30946621Sbt150084 mutex_enter(&ixgbe->gen_lock); 30956621Sbt150084 30966621Sbt150084 switch (mode) { 30976621Sbt150084 default: 30986621Sbt150084 mutex_exit(&ixgbe->gen_lock); 30996621Sbt150084 return (B_FALSE); 31006621Sbt150084 31016621Sbt150084 case IXGBE_LB_INTERNAL_MAC: 31026621Sbt150084 ixgbe_set_internal_mac_loopback(ixgbe); 31036621Sbt150084 break; 31046621Sbt150084 } 31056621Sbt150084 31066621Sbt150084 mutex_exit(&ixgbe->gen_lock); 31076621Sbt150084 31086621Sbt150084 return (B_TRUE); 31096621Sbt150084 } 31106621Sbt150084 31116621Sbt150084 /* 31126621Sbt150084 * ixgbe_set_internal_mac_loopback - Set the internal MAC loopback mode. 31136621Sbt150084 */ 31146621Sbt150084 static void 31156621Sbt150084 ixgbe_set_internal_mac_loopback(ixgbe_t *ixgbe) 31166621Sbt150084 { 31176621Sbt150084 struct ixgbe_hw *hw; 31186621Sbt150084 uint32_t reg; 31196621Sbt150084 uint8_t atlas; 31206621Sbt150084 31216621Sbt150084 hw = &ixgbe->hw; 31226621Sbt150084 31236621Sbt150084 /* 31246621Sbt150084 * Setup MAC loopback 31256621Sbt150084 */ 31266621Sbt150084 reg = IXGBE_READ_REG(&ixgbe->hw, IXGBE_HLREG0); 31276621Sbt150084 reg |= IXGBE_HLREG0_LPBK; 31286621Sbt150084 IXGBE_WRITE_REG(&ixgbe->hw, IXGBE_HLREG0, reg); 31296621Sbt150084 31306621Sbt150084 reg = IXGBE_READ_REG(&ixgbe->hw, IXGBE_AUTOC); 31316621Sbt150084 reg &= ~IXGBE_AUTOC_LMS_MASK; 31326621Sbt150084 IXGBE_WRITE_REG(&ixgbe->hw, IXGBE_AUTOC, reg); 31336621Sbt150084 31346621Sbt150084 /* 31356621Sbt150084 * Disable Atlas Tx lanes to keep packets in loopback and not on wire 31366621Sbt150084 */ 31376621Sbt150084 if (hw->mac.type == ixgbe_mac_82598EB) { 31386621Sbt150084 (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_LPBK, 31396621Sbt150084 &atlas); 31406621Sbt150084 atlas |= IXGBE_ATLAS_PDN_TX_REG_EN; 31416621Sbt150084 (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_LPBK, 31426621Sbt150084 atlas); 31436621Sbt150084 31446621Sbt150084 (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_10G, 31456621Sbt150084 &atlas); 31466621Sbt150084 atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL; 31476621Sbt150084 (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_10G, 31486621Sbt150084 atlas); 31496621Sbt150084 31506621Sbt150084 (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_1G, 31516621Sbt150084 &atlas); 31526621Sbt150084 atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL; 31536621Sbt150084 (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_1G, 31546621Sbt150084 atlas); 31556621Sbt150084 31566621Sbt150084 (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_AN, 31576621Sbt150084 &atlas); 31586621Sbt150084 atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL; 31596621Sbt150084 (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_AN, 31606621Sbt150084 atlas); 31616621Sbt150084 } 31626621Sbt150084 } 31636621Sbt150084 31646621Sbt150084 #pragma inline(ixgbe_intr_rx_work) 31656621Sbt150084 /* 31666621Sbt150084 * ixgbe_intr_rx_work - RX processing of ISR. 31676621Sbt150084 */ 31686621Sbt150084 static void 31696621Sbt150084 ixgbe_intr_rx_work(ixgbe_rx_ring_t *rx_ring) 31706621Sbt150084 { 31716621Sbt150084 mblk_t *mp; 31726621Sbt150084 31736621Sbt150084 mutex_enter(&rx_ring->rx_lock); 31746621Sbt150084 31758275SEric Cheng mp = ixgbe_ring_rx(rx_ring, IXGBE_POLL_NULL); 31766621Sbt150084 mutex_exit(&rx_ring->rx_lock); 31776621Sbt150084 31786621Sbt150084 if (mp != NULL) 31798275SEric Cheng mac_rx_ring(rx_ring->ixgbe->mac_hdl, rx_ring->ring_handle, mp, 31808275SEric Cheng rx_ring->ring_gen_num); 31816621Sbt150084 } 31826621Sbt150084 31836621Sbt150084 #pragma inline(ixgbe_intr_tx_work) 31846621Sbt150084 /* 31856621Sbt150084 * ixgbe_intr_tx_work - TX processing of ISR. 31866621Sbt150084 */ 31876621Sbt150084 static void 31886621Sbt150084 ixgbe_intr_tx_work(ixgbe_tx_ring_t *tx_ring) 31896621Sbt150084 { 319010376SChenlu.Chen@Sun.COM ixgbe_t *ixgbe = tx_ring->ixgbe; 319110376SChenlu.Chen@Sun.COM 31926621Sbt150084 /* 31936621Sbt150084 * Recycle the tx descriptors 31946621Sbt150084 */ 31956621Sbt150084 tx_ring->tx_recycle(tx_ring); 31966621Sbt150084 31976621Sbt150084 /* 31986621Sbt150084 * Schedule the re-transmit 31996621Sbt150084 */ 32006621Sbt150084 if (tx_ring->reschedule && 320110376SChenlu.Chen@Sun.COM (tx_ring->tbd_free >= ixgbe->tx_resched_thresh)) { 32026621Sbt150084 tx_ring->reschedule = B_FALSE; 32038275SEric Cheng mac_tx_ring_update(tx_ring->ixgbe->mac_hdl, 32048275SEric Cheng tx_ring->ring_handle); 32056621Sbt150084 IXGBE_DEBUG_STAT(tx_ring->stat_reschedule); 32066621Sbt150084 } 32076621Sbt150084 } 32086621Sbt150084 32096621Sbt150084 #pragma inline(ixgbe_intr_other_work) 32106621Sbt150084 /* 32118490SPaul.Guo@Sun.COM * ixgbe_intr_other_work - Process interrupt types other than tx/rx 32126621Sbt150084 */ 32136621Sbt150084 static void 32148490SPaul.Guo@Sun.COM ixgbe_intr_other_work(ixgbe_t *ixgbe, uint32_t eicr) 32156621Sbt150084 { 32169353SSamuel.Tu@Sun.COM struct ixgbe_hw *hw = &ixgbe->hw; 32178490SPaul.Guo@Sun.COM /* 32188490SPaul.Guo@Sun.COM * dispatch taskq to handle link status change 32198490SPaul.Guo@Sun.COM */ 32208490SPaul.Guo@Sun.COM if (eicr & IXGBE_EICR_LSC) { 32218490SPaul.Guo@Sun.COM if ((ddi_taskq_dispatch(ixgbe->lsc_taskq, 32228490SPaul.Guo@Sun.COM ixgbe_driver_link_check, (void *)ixgbe, DDI_NOSLEEP)) 32238490SPaul.Guo@Sun.COM != DDI_SUCCESS) { 32248490SPaul.Guo@Sun.COM ixgbe_log(ixgbe, "Fail to dispatch taskq"); 32258490SPaul.Guo@Sun.COM } 32268490SPaul.Guo@Sun.COM } 32276621Sbt150084 32286621Sbt150084 /* 32298490SPaul.Guo@Sun.COM * check for fan failure on adapters with fans 32306621Sbt150084 */ 32318490SPaul.Guo@Sun.COM if ((ixgbe->capab->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && 32328490SPaul.Guo@Sun.COM (eicr & IXGBE_EICR_GPI_SDP1)) { 32339353SSamuel.Tu@Sun.COM if (hw->mac.type < ixgbe_mac_82599EB) { 32349353SSamuel.Tu@Sun.COM ixgbe_log(ixgbe, 32359353SSamuel.Tu@Sun.COM "Fan has stopped, replace the adapter\n"); 32369353SSamuel.Tu@Sun.COM 32379353SSamuel.Tu@Sun.COM /* re-enable the interrupt, which was automasked */ 32389353SSamuel.Tu@Sun.COM ixgbe->eims |= IXGBE_EICR_GPI_SDP1; 32399353SSamuel.Tu@Sun.COM } 32409353SSamuel.Tu@Sun.COM } 32419353SSamuel.Tu@Sun.COM 32429353SSamuel.Tu@Sun.COM /* 32439353SSamuel.Tu@Sun.COM * Do SFP check for 82599 32449353SSamuel.Tu@Sun.COM */ 32459353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 32469353SSamuel.Tu@Sun.COM if ((ddi_taskq_dispatch(ixgbe->lsc_taskq, 32479353SSamuel.Tu@Sun.COM ixgbe_sfp_check, (void *)ixgbe, 32489353SSamuel.Tu@Sun.COM DDI_NOSLEEP)) != DDI_SUCCESS) { 324910305SPaul.Guo@Sun.COM ixgbe_log(ixgbe, "No memory available to dispatch " 325010305SPaul.Guo@Sun.COM "taskq for SFP check"); 32519353SSamuel.Tu@Sun.COM } 32528490SPaul.Guo@Sun.COM } 32536621Sbt150084 } 32546621Sbt150084 32556621Sbt150084 /* 32566621Sbt150084 * ixgbe_intr_legacy - Interrupt handler for legacy interrupts. 32576621Sbt150084 */ 32586621Sbt150084 static uint_t 32596621Sbt150084 ixgbe_intr_legacy(void *arg1, void *arg2) 32606621Sbt150084 { 32616621Sbt150084 ixgbe_t *ixgbe = (ixgbe_t *)arg1; 32626621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 32636621Sbt150084 ixgbe_tx_ring_t *tx_ring; 32648275SEric Cheng ixgbe_rx_ring_t *rx_ring; 32656621Sbt150084 uint32_t eicr; 32666621Sbt150084 mblk_t *mp; 32676621Sbt150084 boolean_t tx_reschedule; 32686621Sbt150084 uint_t result; 32696621Sbt150084 32708490SPaul.Guo@Sun.COM _NOTE(ARGUNUSED(arg2)); 32716621Sbt150084 32726621Sbt150084 mutex_enter(&ixgbe->gen_lock); 32736621Sbt150084 if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) { 32746621Sbt150084 mutex_exit(&ixgbe->gen_lock); 32756621Sbt150084 return (DDI_INTR_UNCLAIMED); 32766621Sbt150084 } 32776621Sbt150084 32786621Sbt150084 mp = NULL; 32796621Sbt150084 tx_reschedule = B_FALSE; 32806621Sbt150084 32816621Sbt150084 /* 32826621Sbt150084 * Any bit set in eicr: claim this interrupt 32836621Sbt150084 */ 32846621Sbt150084 eicr = IXGBE_READ_REG(hw, IXGBE_EICR); 32856621Sbt150084 if (eicr) { 32866621Sbt150084 /* 32876621Sbt150084 * For legacy interrupt, we have only one interrupt, 32886621Sbt150084 * so we have only one rx ring and one tx ring enabled. 32896621Sbt150084 */ 32906621Sbt150084 ASSERT(ixgbe->num_rx_rings == 1); 32916621Sbt150084 ASSERT(ixgbe->num_tx_rings == 1); 32926621Sbt150084 32936621Sbt150084 /* 32948275SEric Cheng * For legacy interrupt, rx rings[0] will use RTxQ[0]. 32956621Sbt150084 */ 32968275SEric Cheng if (eicr & 0x1) { 32979353SSamuel.Tu@Sun.COM ixgbe->eimc |= IXGBE_EICR_RTX_QUEUE; 32989353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMC, ixgbe->eimc); 32999353SSamuel.Tu@Sun.COM ixgbe->eims |= IXGBE_EICR_RTX_QUEUE; 33006621Sbt150084 /* 33016621Sbt150084 * Clean the rx descriptors 33026621Sbt150084 */ 33038275SEric Cheng rx_ring = &ixgbe->rx_rings[0]; 33048275SEric Cheng mp = ixgbe_ring_rx(rx_ring, IXGBE_POLL_NULL); 33058275SEric Cheng } 33068275SEric Cheng 33078275SEric Cheng /* 33088275SEric Cheng * For legacy interrupt, tx rings[0] will use RTxQ[1]. 33098275SEric Cheng */ 33108275SEric Cheng if (eicr & 0x2) { 33116621Sbt150084 /* 33126621Sbt150084 * Recycle the tx descriptors 33136621Sbt150084 */ 33146621Sbt150084 tx_ring = &ixgbe->tx_rings[0]; 33156621Sbt150084 tx_ring->tx_recycle(tx_ring); 33166621Sbt150084 33176621Sbt150084 /* 33186621Sbt150084 * Schedule the re-transmit 33196621Sbt150084 */ 33206621Sbt150084 tx_reschedule = (tx_ring->reschedule && 332110376SChenlu.Chen@Sun.COM (tx_ring->tbd_free >= ixgbe->tx_resched_thresh)); 33226621Sbt150084 } 33236621Sbt150084 33248490SPaul.Guo@Sun.COM /* any interrupt type other than tx/rx */ 33258490SPaul.Guo@Sun.COM if (eicr & ixgbe->capab->other_intr) { 33269353SSamuel.Tu@Sun.COM if (hw->mac.type < ixgbe_mac_82599EB) { 33279353SSamuel.Tu@Sun.COM ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR); 33289353SSamuel.Tu@Sun.COM } 33299353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 33309353SSamuel.Tu@Sun.COM ixgbe->eimc = IXGBE_82599_OTHER_INTR; 33319353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMC, ixgbe->eimc); 33329353SSamuel.Tu@Sun.COM } 33339353SSamuel.Tu@Sun.COM ixgbe_intr_other_work(ixgbe, eicr); 33348490SPaul.Guo@Sun.COM ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR); 33356621Sbt150084 } 33366621Sbt150084 33378490SPaul.Guo@Sun.COM mutex_exit(&ixgbe->gen_lock); 33388490SPaul.Guo@Sun.COM 33396621Sbt150084 result = DDI_INTR_CLAIMED; 33406621Sbt150084 } else { 33418490SPaul.Guo@Sun.COM mutex_exit(&ixgbe->gen_lock); 33428490SPaul.Guo@Sun.COM 33436621Sbt150084 /* 33446621Sbt150084 * No interrupt cause bits set: don't claim this interrupt. 33456621Sbt150084 */ 33466621Sbt150084 result = DDI_INTR_UNCLAIMED; 33476621Sbt150084 } 33486621Sbt150084 33498490SPaul.Guo@Sun.COM /* re-enable the interrupts which were automasked */ 33508490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims); 33516621Sbt150084 33526621Sbt150084 /* 33536621Sbt150084 * Do the following work outside of the gen_lock 33546621Sbt150084 */ 33559353SSamuel.Tu@Sun.COM if (mp != NULL) { 33568275SEric Cheng mac_rx_ring(rx_ring->ixgbe->mac_hdl, rx_ring->ring_handle, mp, 33578275SEric Cheng rx_ring->ring_gen_num); 33589353SSamuel.Tu@Sun.COM } 33596621Sbt150084 33606621Sbt150084 if (tx_reschedule) { 33616621Sbt150084 tx_ring->reschedule = B_FALSE; 33628275SEric Cheng mac_tx_ring_update(ixgbe->mac_hdl, tx_ring->ring_handle); 33636621Sbt150084 IXGBE_DEBUG_STAT(tx_ring->stat_reschedule); 33646621Sbt150084 } 33656621Sbt150084 33666621Sbt150084 return (result); 33676621Sbt150084 } 33686621Sbt150084 33696621Sbt150084 /* 33706621Sbt150084 * ixgbe_intr_msi - Interrupt handler for MSI. 33716621Sbt150084 */ 33726621Sbt150084 static uint_t 33736621Sbt150084 ixgbe_intr_msi(void *arg1, void *arg2) 33746621Sbt150084 { 33756621Sbt150084 ixgbe_t *ixgbe = (ixgbe_t *)arg1; 33766621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 33776621Sbt150084 uint32_t eicr; 33786621Sbt150084 33798490SPaul.Guo@Sun.COM _NOTE(ARGUNUSED(arg2)); 33808490SPaul.Guo@Sun.COM 33816621Sbt150084 eicr = IXGBE_READ_REG(hw, IXGBE_EICR); 33826621Sbt150084 33836621Sbt150084 /* 33846621Sbt150084 * For MSI interrupt, we have only one vector, 33856621Sbt150084 * so we have only one rx ring and one tx ring enabled. 33866621Sbt150084 */ 33876621Sbt150084 ASSERT(ixgbe->num_rx_rings == 1); 33886621Sbt150084 ASSERT(ixgbe->num_tx_rings == 1); 33896621Sbt150084 33906621Sbt150084 /* 33918275SEric Cheng * For MSI interrupt, rx rings[0] will use RTxQ[0]. 33926621Sbt150084 */ 33938275SEric Cheng if (eicr & 0x1) { 33946621Sbt150084 ixgbe_intr_rx_work(&ixgbe->rx_rings[0]); 33958275SEric Cheng } 33968275SEric Cheng 33978275SEric Cheng /* 33988275SEric Cheng * For MSI interrupt, tx rings[0] will use RTxQ[1]. 33998275SEric Cheng */ 34008275SEric Cheng if (eicr & 0x2) { 34016621Sbt150084 ixgbe_intr_tx_work(&ixgbe->tx_rings[0]); 34026621Sbt150084 } 34036621Sbt150084 34048490SPaul.Guo@Sun.COM /* any interrupt type other than tx/rx */ 34058490SPaul.Guo@Sun.COM if (eicr & ixgbe->capab->other_intr) { 34068490SPaul.Guo@Sun.COM mutex_enter(&ixgbe->gen_lock); 34079353SSamuel.Tu@Sun.COM if (hw->mac.type < ixgbe_mac_82599EB) { 34089353SSamuel.Tu@Sun.COM ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR); 34099353SSamuel.Tu@Sun.COM } 34109353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 34119353SSamuel.Tu@Sun.COM ixgbe->eimc = IXGBE_82599_OTHER_INTR; 34129353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMC, ixgbe->eimc); 34139353SSamuel.Tu@Sun.COM } 34149353SSamuel.Tu@Sun.COM ixgbe_intr_other_work(ixgbe, eicr); 34158490SPaul.Guo@Sun.COM ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR); 34168490SPaul.Guo@Sun.COM mutex_exit(&ixgbe->gen_lock); 34176621Sbt150084 } 34186621Sbt150084 34198490SPaul.Guo@Sun.COM /* re-enable the interrupts which were automasked */ 34208490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims); 34218490SPaul.Guo@Sun.COM 34226621Sbt150084 return (DDI_INTR_CLAIMED); 34236621Sbt150084 } 34246621Sbt150084 34256621Sbt150084 /* 34269353SSamuel.Tu@Sun.COM * ixgbe_intr_msix - Interrupt handler for MSI-X. 34276621Sbt150084 */ 34286621Sbt150084 static uint_t 34299353SSamuel.Tu@Sun.COM ixgbe_intr_msix(void *arg1, void *arg2) 34306621Sbt150084 { 34319353SSamuel.Tu@Sun.COM ixgbe_intr_vector_t *vect = (ixgbe_intr_vector_t *)arg1; 34328275SEric Cheng ixgbe_t *ixgbe = vect->ixgbe; 34339353SSamuel.Tu@Sun.COM struct ixgbe_hw *hw = &ixgbe->hw; 34349353SSamuel.Tu@Sun.COM uint32_t eicr; 34358275SEric Cheng int r_idx = 0; 34366621Sbt150084 34378490SPaul.Guo@Sun.COM _NOTE(ARGUNUSED(arg2)); 34388490SPaul.Guo@Sun.COM 34396621Sbt150084 /* 34408275SEric Cheng * Clean each rx ring that has its bit set in the map 34416621Sbt150084 */ 34426621Sbt150084 r_idx = bt_getlowbit(vect->rx_map, 0, (ixgbe->num_rx_rings - 1)); 34436621Sbt150084 while (r_idx >= 0) { 34446621Sbt150084 ixgbe_intr_rx_work(&ixgbe->rx_rings[r_idx]); 34456621Sbt150084 r_idx = bt_getlowbit(vect->rx_map, (r_idx + 1), 34466621Sbt150084 (ixgbe->num_rx_rings - 1)); 34476621Sbt150084 } 34486621Sbt150084 34498275SEric Cheng /* 34508275SEric Cheng * Clean each tx ring that has its bit set in the map 34518275SEric Cheng */ 34528275SEric Cheng r_idx = bt_getlowbit(vect->tx_map, 0, (ixgbe->num_tx_rings - 1)); 34538275SEric Cheng while (r_idx >= 0) { 34548275SEric Cheng ixgbe_intr_tx_work(&ixgbe->tx_rings[r_idx]); 34558275SEric Cheng r_idx = bt_getlowbit(vect->tx_map, (r_idx + 1), 34568275SEric Cheng (ixgbe->num_tx_rings - 1)); 34578275SEric Cheng } 34588275SEric Cheng 34596621Sbt150084 34606621Sbt150084 /* 34619353SSamuel.Tu@Sun.COM * Clean other interrupt (link change) that has its bit set in the map 34626621Sbt150084 */ 34639353SSamuel.Tu@Sun.COM if (BT_TEST(vect->other_map, 0) == 1) { 34649353SSamuel.Tu@Sun.COM eicr = IXGBE_READ_REG(hw, IXGBE_EICR); 34659353SSamuel.Tu@Sun.COM 34669353SSamuel.Tu@Sun.COM /* 34679353SSamuel.Tu@Sun.COM * Need check cause bits and only other causes will 34689353SSamuel.Tu@Sun.COM * be processed 34699353SSamuel.Tu@Sun.COM */ 34709353SSamuel.Tu@Sun.COM /* any interrupt type other than tx/rx */ 34719353SSamuel.Tu@Sun.COM if (eicr & ixgbe->capab->other_intr) { 34729353SSamuel.Tu@Sun.COM if (hw->mac.type < ixgbe_mac_82599EB) { 34739353SSamuel.Tu@Sun.COM mutex_enter(&ixgbe->gen_lock); 34749353SSamuel.Tu@Sun.COM ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR); 34759353SSamuel.Tu@Sun.COM ixgbe_intr_other_work(ixgbe, eicr); 34769353SSamuel.Tu@Sun.COM mutex_exit(&ixgbe->gen_lock); 34779353SSamuel.Tu@Sun.COM } else { 34789353SSamuel.Tu@Sun.COM if (hw->mac.type == ixgbe_mac_82599EB) { 34799353SSamuel.Tu@Sun.COM mutex_enter(&ixgbe->gen_lock); 34809353SSamuel.Tu@Sun.COM ixgbe->eims |= IXGBE_EICR_RTX_QUEUE; 34819353SSamuel.Tu@Sun.COM ixgbe_intr_other_work(ixgbe, eicr); 34829353SSamuel.Tu@Sun.COM mutex_exit(&ixgbe->gen_lock); 34839353SSamuel.Tu@Sun.COM } 34849353SSamuel.Tu@Sun.COM } 34859353SSamuel.Tu@Sun.COM } 34869353SSamuel.Tu@Sun.COM 34879353SSamuel.Tu@Sun.COM /* re-enable the interrupts which were automasked */ 34889353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims); 34896621Sbt150084 } 34906621Sbt150084 34916621Sbt150084 return (DDI_INTR_CLAIMED); 34926621Sbt150084 } 34936621Sbt150084 34946621Sbt150084 /* 34956621Sbt150084 * ixgbe_alloc_intrs - Allocate interrupts for the driver. 34966621Sbt150084 * 34976621Sbt150084 * Normal sequence is to try MSI-X; if not sucessful, try MSI; 34986621Sbt150084 * if not successful, try Legacy. 34996621Sbt150084 * ixgbe->intr_force can be used to force sequence to start with 35006621Sbt150084 * any of the 3 types. 35016621Sbt150084 * If MSI-X is not used, number of tx/rx rings is forced to 1. 35026621Sbt150084 */ 35036621Sbt150084 static int 35046621Sbt150084 ixgbe_alloc_intrs(ixgbe_t *ixgbe) 35056621Sbt150084 { 35066621Sbt150084 dev_info_t *devinfo; 35076621Sbt150084 int intr_types; 35086621Sbt150084 int rc; 35096621Sbt150084 35106621Sbt150084 devinfo = ixgbe->dip; 35116621Sbt150084 35126621Sbt150084 /* 35136621Sbt150084 * Get supported interrupt types 35146621Sbt150084 */ 35156621Sbt150084 rc = ddi_intr_get_supported_types(devinfo, &intr_types); 35166621Sbt150084 35176621Sbt150084 if (rc != DDI_SUCCESS) { 35186621Sbt150084 ixgbe_log(ixgbe, 35196621Sbt150084 "Get supported interrupt types failed: %d", rc); 35206621Sbt150084 return (IXGBE_FAILURE); 35216621Sbt150084 } 35226621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, "Supported interrupt types: %x", intr_types); 35236621Sbt150084 35246621Sbt150084 ixgbe->intr_type = 0; 35256621Sbt150084 35266621Sbt150084 /* 35276621Sbt150084 * Install MSI-X interrupts 35286621Sbt150084 */ 35296621Sbt150084 if ((intr_types & DDI_INTR_TYPE_MSIX) && 35306621Sbt150084 (ixgbe->intr_force <= IXGBE_INTR_MSIX)) { 35316621Sbt150084 rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_MSIX); 35326621Sbt150084 if (rc == IXGBE_SUCCESS) 35336621Sbt150084 return (IXGBE_SUCCESS); 35346621Sbt150084 35356621Sbt150084 ixgbe_log(ixgbe, 35366621Sbt150084 "Allocate MSI-X failed, trying MSI interrupts..."); 35376621Sbt150084 } 35386621Sbt150084 35396621Sbt150084 /* 35408275SEric Cheng * MSI-X not used, force rings and groups to 1 35416621Sbt150084 */ 35426621Sbt150084 ixgbe->num_rx_rings = 1; 35438275SEric Cheng ixgbe->num_rx_groups = 1; 35446621Sbt150084 ixgbe->num_tx_rings = 1; 35456621Sbt150084 ixgbe_log(ixgbe, 35468275SEric Cheng "MSI-X not used, force rings and groups number to 1"); 35476621Sbt150084 35486621Sbt150084 /* 35496621Sbt150084 * Install MSI interrupts 35506621Sbt150084 */ 35516621Sbt150084 if ((intr_types & DDI_INTR_TYPE_MSI) && 35526621Sbt150084 (ixgbe->intr_force <= IXGBE_INTR_MSI)) { 35536621Sbt150084 rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_MSI); 35546621Sbt150084 if (rc == IXGBE_SUCCESS) 35556621Sbt150084 return (IXGBE_SUCCESS); 35566621Sbt150084 35576621Sbt150084 ixgbe_log(ixgbe, 35586621Sbt150084 "Allocate MSI failed, trying Legacy interrupts..."); 35596621Sbt150084 } 35606621Sbt150084 35616621Sbt150084 /* 35626621Sbt150084 * Install legacy interrupts 35636621Sbt150084 */ 35646621Sbt150084 if (intr_types & DDI_INTR_TYPE_FIXED) { 35656621Sbt150084 rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_FIXED); 35666621Sbt150084 if (rc == IXGBE_SUCCESS) 35676621Sbt150084 return (IXGBE_SUCCESS); 35686621Sbt150084 35696621Sbt150084 ixgbe_log(ixgbe, 35706621Sbt150084 "Allocate Legacy interrupts failed"); 35716621Sbt150084 } 35726621Sbt150084 35736621Sbt150084 /* 35746621Sbt150084 * If none of the 3 types succeeded, return failure 35756621Sbt150084 */ 35766621Sbt150084 return (IXGBE_FAILURE); 35776621Sbt150084 } 35786621Sbt150084 35796621Sbt150084 /* 35806621Sbt150084 * ixgbe_alloc_intr_handles - Allocate interrupt handles. 35816621Sbt150084 * 35826621Sbt150084 * For legacy and MSI, only 1 handle is needed. For MSI-X, 35836621Sbt150084 * if fewer than 2 handles are available, return failure. 35848275SEric Cheng * Upon success, this maps the vectors to rx and tx rings for 35858275SEric Cheng * interrupts. 35866621Sbt150084 */ 35876621Sbt150084 static int 35886621Sbt150084 ixgbe_alloc_intr_handles(ixgbe_t *ixgbe, int intr_type) 35896621Sbt150084 { 35906621Sbt150084 dev_info_t *devinfo; 35916621Sbt150084 int request, count, avail, actual; 35928275SEric Cheng int minimum; 35936621Sbt150084 int rc; 35946621Sbt150084 35956621Sbt150084 devinfo = ixgbe->dip; 35966621Sbt150084 35976621Sbt150084 switch (intr_type) { 35986621Sbt150084 case DDI_INTR_TYPE_FIXED: 35996621Sbt150084 request = 1; /* Request 1 legacy interrupt handle */ 36006621Sbt150084 minimum = 1; 36016621Sbt150084 IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: legacy"); 36026621Sbt150084 break; 36036621Sbt150084 36046621Sbt150084 case DDI_INTR_TYPE_MSI: 36056621Sbt150084 request = 1; /* Request 1 MSI interrupt handle */ 36066621Sbt150084 minimum = 1; 36076621Sbt150084 IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: MSI"); 36086621Sbt150084 break; 36096621Sbt150084 36106621Sbt150084 case DDI_INTR_TYPE_MSIX: 36116621Sbt150084 /* 36126621Sbt150084 * Best number of vectors for the adapter is 36139353SSamuel.Tu@Sun.COM * # rx rings + # tx rings. 36146621Sbt150084 */ 36159353SSamuel.Tu@Sun.COM request = ixgbe->num_rx_rings + ixgbe->num_tx_rings; 36169353SSamuel.Tu@Sun.COM if (request > ixgbe->capab->max_ring_vect) 36179353SSamuel.Tu@Sun.COM request = ixgbe->capab->max_ring_vect; 36186621Sbt150084 minimum = 2; 36196621Sbt150084 IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: MSI-X"); 36206621Sbt150084 break; 36216621Sbt150084 36226621Sbt150084 default: 36236621Sbt150084 ixgbe_log(ixgbe, 36246621Sbt150084 "invalid call to ixgbe_alloc_intr_handles(): %d\n", 36256621Sbt150084 intr_type); 36266621Sbt150084 return (IXGBE_FAILURE); 36276621Sbt150084 } 36286621Sbt150084 IXGBE_DEBUGLOG_2(ixgbe, "interrupt handles requested: %d minimum: %d", 36296621Sbt150084 request, minimum); 36306621Sbt150084 36316621Sbt150084 /* 36326621Sbt150084 * Get number of supported interrupts 36336621Sbt150084 */ 36346621Sbt150084 rc = ddi_intr_get_nintrs(devinfo, intr_type, &count); 36356621Sbt150084 if ((rc != DDI_SUCCESS) || (count < minimum)) { 36366621Sbt150084 ixgbe_log(ixgbe, 36376621Sbt150084 "Get interrupt number failed. Return: %d, count: %d", 36386621Sbt150084 rc, count); 36396621Sbt150084 return (IXGBE_FAILURE); 36406621Sbt150084 } 36416621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, "interrupts supported: %d", count); 36426621Sbt150084 36436621Sbt150084 /* 36446621Sbt150084 * Get number of available interrupts 36456621Sbt150084 */ 36466621Sbt150084 rc = ddi_intr_get_navail(devinfo, intr_type, &avail); 36476621Sbt150084 if ((rc != DDI_SUCCESS) || (avail < minimum)) { 36486621Sbt150084 ixgbe_log(ixgbe, 36496621Sbt150084 "Get interrupt available number failed. " 36506621Sbt150084 "Return: %d, available: %d", rc, avail); 36516621Sbt150084 return (IXGBE_FAILURE); 36526621Sbt150084 } 36536621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, "interrupts available: %d", avail); 36546621Sbt150084 36556621Sbt150084 if (avail < request) { 36566621Sbt150084 ixgbe_log(ixgbe, "Request %d handles, %d available", 36576621Sbt150084 request, avail); 36586621Sbt150084 request = avail; 36596621Sbt150084 } 36606621Sbt150084 36616621Sbt150084 actual = 0; 36626621Sbt150084 ixgbe->intr_cnt = 0; 36636621Sbt150084 36646621Sbt150084 /* 36656621Sbt150084 * Allocate an array of interrupt handles 36666621Sbt150084 */ 36676621Sbt150084 ixgbe->intr_size = request * sizeof (ddi_intr_handle_t); 36686621Sbt150084 ixgbe->htable = kmem_alloc(ixgbe->intr_size, KM_SLEEP); 36696621Sbt150084 36706621Sbt150084 rc = ddi_intr_alloc(devinfo, ixgbe->htable, intr_type, 0, 36716621Sbt150084 request, &actual, DDI_INTR_ALLOC_NORMAL); 36726621Sbt150084 if (rc != DDI_SUCCESS) { 36736621Sbt150084 ixgbe_log(ixgbe, "Allocate interrupts failed. " 36746621Sbt150084 "return: %d, request: %d, actual: %d", 36756621Sbt150084 rc, request, actual); 36766621Sbt150084 goto alloc_handle_fail; 36776621Sbt150084 } 36786621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, "interrupts actually allocated: %d", actual); 36796621Sbt150084 36806621Sbt150084 ixgbe->intr_cnt = actual; 36816621Sbt150084 36826621Sbt150084 /* 36838275SEric Cheng * Now we know the actual number of vectors. Here we map the vector 36848275SEric Cheng * to other, rx rings and tx ring. 36856621Sbt150084 */ 36866621Sbt150084 if (actual < minimum) { 36876621Sbt150084 ixgbe_log(ixgbe, "Insufficient interrupt handles available: %d", 36886621Sbt150084 actual); 36896621Sbt150084 goto alloc_handle_fail; 36906621Sbt150084 } 36916621Sbt150084 36926621Sbt150084 /* 36936621Sbt150084 * Get priority for first vector, assume remaining are all the same 36946621Sbt150084 */ 36956621Sbt150084 rc = ddi_intr_get_pri(ixgbe->htable[0], &ixgbe->intr_pri); 36966621Sbt150084 if (rc != DDI_SUCCESS) { 36976621Sbt150084 ixgbe_log(ixgbe, 36986621Sbt150084 "Get interrupt priority failed: %d", rc); 36996621Sbt150084 goto alloc_handle_fail; 37006621Sbt150084 } 37016621Sbt150084 37026621Sbt150084 rc = ddi_intr_get_cap(ixgbe->htable[0], &ixgbe->intr_cap); 37036621Sbt150084 if (rc != DDI_SUCCESS) { 37046621Sbt150084 ixgbe_log(ixgbe, 37056621Sbt150084 "Get interrupt cap failed: %d", rc); 37066621Sbt150084 goto alloc_handle_fail; 37076621Sbt150084 } 37086621Sbt150084 37096621Sbt150084 ixgbe->intr_type = intr_type; 37106621Sbt150084 37116621Sbt150084 return (IXGBE_SUCCESS); 37126621Sbt150084 37136621Sbt150084 alloc_handle_fail: 37146621Sbt150084 ixgbe_rem_intrs(ixgbe); 37156621Sbt150084 37166621Sbt150084 return (IXGBE_FAILURE); 37176621Sbt150084 } 37186621Sbt150084 37196621Sbt150084 /* 37206621Sbt150084 * ixgbe_add_intr_handlers - Add interrupt handlers based on the interrupt type. 37216621Sbt150084 * 37226621Sbt150084 * Before adding the interrupt handlers, the interrupt vectors have 37236621Sbt150084 * been allocated, and the rx/tx rings have also been allocated. 37246621Sbt150084 */ 37256621Sbt150084 static int 37266621Sbt150084 ixgbe_add_intr_handlers(ixgbe_t *ixgbe) 37276621Sbt150084 { 37288275SEric Cheng int vector = 0; 37296621Sbt150084 int rc; 37306621Sbt150084 37316621Sbt150084 switch (ixgbe->intr_type) { 37326621Sbt150084 case DDI_INTR_TYPE_MSIX: 37336621Sbt150084 /* 37349353SSamuel.Tu@Sun.COM * Add interrupt handler for all vectors 37356621Sbt150084 */ 37369353SSamuel.Tu@Sun.COM for (vector = 0; vector < ixgbe->intr_cnt; vector++) { 37376621Sbt150084 /* 37386621Sbt150084 * install pointer to vect_map[vector] 37396621Sbt150084 */ 37406621Sbt150084 rc = ddi_intr_add_handler(ixgbe->htable[vector], 37419353SSamuel.Tu@Sun.COM (ddi_intr_handler_t *)ixgbe_intr_msix, 37426621Sbt150084 (void *)&ixgbe->vect_map[vector], NULL); 37436621Sbt150084 37446621Sbt150084 if (rc != DDI_SUCCESS) { 37456621Sbt150084 ixgbe_log(ixgbe, 37466621Sbt150084 "Add rx interrupt handler failed. " 37478275SEric Cheng "return: %d, vector: %d", rc, vector); 37486621Sbt150084 for (vector--; vector >= 0; vector--) { 37496621Sbt150084 (void) ddi_intr_remove_handler( 37506621Sbt150084 ixgbe->htable[vector]); 37516621Sbt150084 } 37526621Sbt150084 return (IXGBE_FAILURE); 37536621Sbt150084 } 37546621Sbt150084 } 37558275SEric Cheng 37566621Sbt150084 break; 37576621Sbt150084 37586621Sbt150084 case DDI_INTR_TYPE_MSI: 37596621Sbt150084 /* 37606621Sbt150084 * Add interrupt handlers for the only vector 37616621Sbt150084 */ 37626621Sbt150084 rc = ddi_intr_add_handler(ixgbe->htable[vector], 37636621Sbt150084 (ddi_intr_handler_t *)ixgbe_intr_msi, 37646621Sbt150084 (void *)ixgbe, NULL); 37656621Sbt150084 37666621Sbt150084 if (rc != DDI_SUCCESS) { 37676621Sbt150084 ixgbe_log(ixgbe, 37686621Sbt150084 "Add MSI interrupt handler failed: %d", rc); 37696621Sbt150084 return (IXGBE_FAILURE); 37706621Sbt150084 } 37716621Sbt150084 37726621Sbt150084 break; 37736621Sbt150084 37746621Sbt150084 case DDI_INTR_TYPE_FIXED: 37756621Sbt150084 /* 37766621Sbt150084 * Add interrupt handlers for the only vector 37776621Sbt150084 */ 37786621Sbt150084 rc = ddi_intr_add_handler(ixgbe->htable[vector], 37796621Sbt150084 (ddi_intr_handler_t *)ixgbe_intr_legacy, 37806621Sbt150084 (void *)ixgbe, NULL); 37816621Sbt150084 37826621Sbt150084 if (rc != DDI_SUCCESS) { 37836621Sbt150084 ixgbe_log(ixgbe, 37846621Sbt150084 "Add legacy interrupt handler failed: %d", rc); 37856621Sbt150084 return (IXGBE_FAILURE); 37866621Sbt150084 } 37876621Sbt150084 37886621Sbt150084 break; 37896621Sbt150084 37906621Sbt150084 default: 37916621Sbt150084 return (IXGBE_FAILURE); 37926621Sbt150084 } 37936621Sbt150084 37946621Sbt150084 return (IXGBE_SUCCESS); 37956621Sbt150084 } 37966621Sbt150084 37976621Sbt150084 #pragma inline(ixgbe_map_rxring_to_vector) 37986621Sbt150084 /* 37996621Sbt150084 * ixgbe_map_rxring_to_vector - Map given rx ring to given interrupt vector. 38006621Sbt150084 */ 38016621Sbt150084 static void 38026621Sbt150084 ixgbe_map_rxring_to_vector(ixgbe_t *ixgbe, int r_idx, int v_idx) 38036621Sbt150084 { 38046621Sbt150084 /* 38056621Sbt150084 * Set bit in map 38066621Sbt150084 */ 38076621Sbt150084 BT_SET(ixgbe->vect_map[v_idx].rx_map, r_idx); 38086621Sbt150084 38096621Sbt150084 /* 38106621Sbt150084 * Count bits set 38116621Sbt150084 */ 38126621Sbt150084 ixgbe->vect_map[v_idx].rxr_cnt++; 38136621Sbt150084 38146621Sbt150084 /* 38156621Sbt150084 * Remember bit position 38166621Sbt150084 */ 38178275SEric Cheng ixgbe->rx_rings[r_idx].intr_vector = v_idx; 38186621Sbt150084 ixgbe->rx_rings[r_idx].vect_bit = 1 << v_idx; 38196621Sbt150084 } 38206621Sbt150084 38216621Sbt150084 #pragma inline(ixgbe_map_txring_to_vector) 38226621Sbt150084 /* 38236621Sbt150084 * ixgbe_map_txring_to_vector - Map given tx ring to given interrupt vector. 38246621Sbt150084 */ 38256621Sbt150084 static void 38266621Sbt150084 ixgbe_map_txring_to_vector(ixgbe_t *ixgbe, int t_idx, int v_idx) 38276621Sbt150084 { 38286621Sbt150084 /* 38296621Sbt150084 * Set bit in map 38306621Sbt150084 */ 38316621Sbt150084 BT_SET(ixgbe->vect_map[v_idx].tx_map, t_idx); 38326621Sbt150084 38336621Sbt150084 /* 38346621Sbt150084 * Count bits set 38356621Sbt150084 */ 38366621Sbt150084 ixgbe->vect_map[v_idx].txr_cnt++; 38376621Sbt150084 38386621Sbt150084 /* 38396621Sbt150084 * Remember bit position 38406621Sbt150084 */ 38418275SEric Cheng ixgbe->tx_rings[t_idx].intr_vector = v_idx; 38426621Sbt150084 ixgbe->tx_rings[t_idx].vect_bit = 1 << v_idx; 38436621Sbt150084 } 38446621Sbt150084 38456621Sbt150084 /* 38468275SEric Cheng * ixgbe_setup_ivar - Set the given entry in the given interrupt vector 38476621Sbt150084 * allocation register (IVAR). 38489353SSamuel.Tu@Sun.COM * cause: 38499353SSamuel.Tu@Sun.COM * -1 : other cause 38509353SSamuel.Tu@Sun.COM * 0 : rx 38519353SSamuel.Tu@Sun.COM * 1 : tx 38526621Sbt150084 */ 38536621Sbt150084 static void 38549353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry, uint8_t msix_vector, 38559353SSamuel.Tu@Sun.COM int8_t cause) 38566621Sbt150084 { 38576621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 38586621Sbt150084 u32 ivar, index; 38596621Sbt150084 38609353SSamuel.Tu@Sun.COM switch (hw->mac.type) { 38619353SSamuel.Tu@Sun.COM case ixgbe_mac_82598EB: 38629353SSamuel.Tu@Sun.COM msix_vector |= IXGBE_IVAR_ALLOC_VAL; 38639353SSamuel.Tu@Sun.COM if (cause == -1) { 38649353SSamuel.Tu@Sun.COM cause = 0; 38659353SSamuel.Tu@Sun.COM } 38669353SSamuel.Tu@Sun.COM index = (((cause * 64) + intr_alloc_entry) >> 2) & 0x1F; 38679353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); 38689353SSamuel.Tu@Sun.COM ivar &= ~(0xFF << (8 * (intr_alloc_entry & 0x3))); 38699353SSamuel.Tu@Sun.COM ivar |= (msix_vector << (8 * (intr_alloc_entry & 0x3))); 38709353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); 38719353SSamuel.Tu@Sun.COM break; 38729353SSamuel.Tu@Sun.COM case ixgbe_mac_82599EB: 38739353SSamuel.Tu@Sun.COM if (cause == -1) { 38749353SSamuel.Tu@Sun.COM /* other causes */ 38759353SSamuel.Tu@Sun.COM msix_vector |= IXGBE_IVAR_ALLOC_VAL; 38769353SSamuel.Tu@Sun.COM index = (intr_alloc_entry & 1) * 8; 38779353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC); 38789353SSamuel.Tu@Sun.COM ivar &= ~(0xFF << index); 38799353SSamuel.Tu@Sun.COM ivar |= (msix_vector << index); 38809353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar); 38819353SSamuel.Tu@Sun.COM } else { 38829353SSamuel.Tu@Sun.COM /* tx or rx causes */ 38839353SSamuel.Tu@Sun.COM msix_vector |= IXGBE_IVAR_ALLOC_VAL; 38849353SSamuel.Tu@Sun.COM index = ((16 * (intr_alloc_entry & 1)) + (8 * cause)); 38859353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, 38869353SSamuel.Tu@Sun.COM IXGBE_IVAR(intr_alloc_entry >> 1)); 38879353SSamuel.Tu@Sun.COM ivar &= ~(0xFF << index); 38889353SSamuel.Tu@Sun.COM ivar |= (msix_vector << index); 38899353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(intr_alloc_entry >> 1), 38909353SSamuel.Tu@Sun.COM ivar); 38919353SSamuel.Tu@Sun.COM } 38929353SSamuel.Tu@Sun.COM break; 38939353SSamuel.Tu@Sun.COM default: 38949353SSamuel.Tu@Sun.COM break; 38959353SSamuel.Tu@Sun.COM } 38968275SEric Cheng } 38978275SEric Cheng 38988275SEric Cheng /* 38998275SEric Cheng * ixgbe_enable_ivar - Enable the given entry by setting the VAL bit of 39008275SEric Cheng * given interrupt vector allocation register (IVAR). 39019353SSamuel.Tu@Sun.COM * cause: 39029353SSamuel.Tu@Sun.COM * -1 : other cause 39039353SSamuel.Tu@Sun.COM * 0 : rx 39049353SSamuel.Tu@Sun.COM * 1 : tx 39058275SEric Cheng */ 39068275SEric Cheng static void 39079353SSamuel.Tu@Sun.COM ixgbe_enable_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry, int8_t cause) 39088275SEric Cheng { 39098275SEric Cheng struct ixgbe_hw *hw = &ixgbe->hw; 39108275SEric Cheng u32 ivar, index; 39118275SEric Cheng 39129353SSamuel.Tu@Sun.COM switch (hw->mac.type) { 39139353SSamuel.Tu@Sun.COM case ixgbe_mac_82598EB: 39149353SSamuel.Tu@Sun.COM if (cause == -1) { 39159353SSamuel.Tu@Sun.COM cause = 0; 39169353SSamuel.Tu@Sun.COM } 39179353SSamuel.Tu@Sun.COM index = (((cause * 64) + intr_alloc_entry) >> 2) & 0x1F; 39189353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); 39199353SSamuel.Tu@Sun.COM ivar |= (IXGBE_IVAR_ALLOC_VAL << (8 * 39209353SSamuel.Tu@Sun.COM (intr_alloc_entry & 0x3))); 39219353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); 39229353SSamuel.Tu@Sun.COM break; 39239353SSamuel.Tu@Sun.COM case ixgbe_mac_82599EB: 39249353SSamuel.Tu@Sun.COM if (cause == -1) { 39259353SSamuel.Tu@Sun.COM /* other causes */ 39269353SSamuel.Tu@Sun.COM index = (intr_alloc_entry & 1) * 8; 39279353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC); 39289353SSamuel.Tu@Sun.COM ivar |= (IXGBE_IVAR_ALLOC_VAL << index); 39299353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar); 39309353SSamuel.Tu@Sun.COM } else { 39319353SSamuel.Tu@Sun.COM /* tx or rx causes */ 39329353SSamuel.Tu@Sun.COM index = ((16 * (intr_alloc_entry & 1)) + (8 * cause)); 39339353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, 39349353SSamuel.Tu@Sun.COM IXGBE_IVAR(intr_alloc_entry >> 1)); 39359353SSamuel.Tu@Sun.COM ivar |= (IXGBE_IVAR_ALLOC_VAL << index); 39369353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(intr_alloc_entry >> 1), 39379353SSamuel.Tu@Sun.COM ivar); 39389353SSamuel.Tu@Sun.COM } 39399353SSamuel.Tu@Sun.COM break; 39409353SSamuel.Tu@Sun.COM default: 39419353SSamuel.Tu@Sun.COM break; 39429353SSamuel.Tu@Sun.COM } 39438275SEric Cheng } 39448275SEric Cheng 39458275SEric Cheng /* 39469353SSamuel.Tu@Sun.COM * ixgbe_disable_ivar - Disble the given entry by clearing the VAL bit of 39478275SEric Cheng * given interrupt vector allocation register (IVAR). 39489353SSamuel.Tu@Sun.COM * cause: 39499353SSamuel.Tu@Sun.COM * -1 : other cause 39509353SSamuel.Tu@Sun.COM * 0 : rx 39519353SSamuel.Tu@Sun.COM * 1 : tx 39528275SEric Cheng */ 39538275SEric Cheng static void 39549353SSamuel.Tu@Sun.COM ixgbe_disable_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry, int8_t cause) 39558275SEric Cheng { 39568275SEric Cheng struct ixgbe_hw *hw = &ixgbe->hw; 39578275SEric Cheng u32 ivar, index; 39588275SEric Cheng 39599353SSamuel.Tu@Sun.COM switch (hw->mac.type) { 39609353SSamuel.Tu@Sun.COM case ixgbe_mac_82598EB: 39619353SSamuel.Tu@Sun.COM if (cause == -1) { 39629353SSamuel.Tu@Sun.COM cause = 0; 39639353SSamuel.Tu@Sun.COM } 39649353SSamuel.Tu@Sun.COM index = (((cause * 64) + intr_alloc_entry) >> 2) & 0x1F; 39659353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); 39669353SSamuel.Tu@Sun.COM ivar &= ~(IXGBE_IVAR_ALLOC_VAL<< (8 * 39679353SSamuel.Tu@Sun.COM (intr_alloc_entry & 0x3))); 39689353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); 39699353SSamuel.Tu@Sun.COM break; 39709353SSamuel.Tu@Sun.COM case ixgbe_mac_82599EB: 39719353SSamuel.Tu@Sun.COM if (cause == -1) { 39729353SSamuel.Tu@Sun.COM /* other causes */ 39739353SSamuel.Tu@Sun.COM index = (intr_alloc_entry & 1) * 8; 39749353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC); 39759353SSamuel.Tu@Sun.COM ivar &= ~(IXGBE_IVAR_ALLOC_VAL << index); 39769353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar); 39779353SSamuel.Tu@Sun.COM } else { 39789353SSamuel.Tu@Sun.COM /* tx or rx causes */ 39799353SSamuel.Tu@Sun.COM index = ((16 * (intr_alloc_entry & 1)) + (8 * cause)); 39809353SSamuel.Tu@Sun.COM ivar = IXGBE_READ_REG(hw, 39819353SSamuel.Tu@Sun.COM IXGBE_IVAR(intr_alloc_entry >> 1)); 39829353SSamuel.Tu@Sun.COM ivar &= ~(IXGBE_IVAR_ALLOC_VAL << index); 39839353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(intr_alloc_entry >> 1), 39849353SSamuel.Tu@Sun.COM ivar); 39859353SSamuel.Tu@Sun.COM } 39869353SSamuel.Tu@Sun.COM break; 39879353SSamuel.Tu@Sun.COM default: 39889353SSamuel.Tu@Sun.COM break; 39899353SSamuel.Tu@Sun.COM } 39906621Sbt150084 } 39916621Sbt150084 39926621Sbt150084 /* 39939353SSamuel.Tu@Sun.COM * ixgbe_map_intrs_to_vectors - Map different interrupts to MSI-X vectors. 39946621Sbt150084 * 39959353SSamuel.Tu@Sun.COM * For MSI-X, here will map rx interrupt, tx interrupt and other interrupt 39969353SSamuel.Tu@Sun.COM * to vector[0 - (intr_cnt -1)]. 39976621Sbt150084 */ 39986621Sbt150084 static int 39999353SSamuel.Tu@Sun.COM ixgbe_map_intrs_to_vectors(ixgbe_t *ixgbe) 40006621Sbt150084 { 40016621Sbt150084 int i, vector = 0; 40026621Sbt150084 40036621Sbt150084 /* initialize vector map */ 40046621Sbt150084 bzero(&ixgbe->vect_map, sizeof (ixgbe->vect_map)); 40059353SSamuel.Tu@Sun.COM for (i = 0; i < ixgbe->intr_cnt; i++) { 40069353SSamuel.Tu@Sun.COM ixgbe->vect_map[i].ixgbe = ixgbe; 40079353SSamuel.Tu@Sun.COM } 40086621Sbt150084 40096621Sbt150084 /* 40108275SEric Cheng * non-MSI-X case is very simple: rx rings[0] on RTxQ[0], 40118275SEric Cheng * tx rings[0] on RTxQ[1]. 40126621Sbt150084 */ 40136621Sbt150084 if (ixgbe->intr_type != DDI_INTR_TYPE_MSIX) { 40146621Sbt150084 ixgbe_map_rxring_to_vector(ixgbe, 0, 0); 40158275SEric Cheng ixgbe_map_txring_to_vector(ixgbe, 0, 1); 40166621Sbt150084 return (IXGBE_SUCCESS); 40176621Sbt150084 } 40186621Sbt150084 40196621Sbt150084 /* 40209353SSamuel.Tu@Sun.COM * Interrupts/vectors mapping for MSI-X 40216621Sbt150084 */ 40226621Sbt150084 40236621Sbt150084 /* 40249353SSamuel.Tu@Sun.COM * Map other interrupt to vector 0, 40259353SSamuel.Tu@Sun.COM * Set bit in map and count the bits set. 40269353SSamuel.Tu@Sun.COM */ 40279353SSamuel.Tu@Sun.COM BT_SET(ixgbe->vect_map[vector].other_map, 0); 40289353SSamuel.Tu@Sun.COM ixgbe->vect_map[vector].other_cnt++; 40299353SSamuel.Tu@Sun.COM vector++; 40309353SSamuel.Tu@Sun.COM 40319353SSamuel.Tu@Sun.COM /* 40329353SSamuel.Tu@Sun.COM * Map rx ring interrupts to vectors 40336621Sbt150084 */ 40348275SEric Cheng for (i = 0; i < ixgbe->num_rx_rings; i++) { 40358275SEric Cheng ixgbe_map_rxring_to_vector(ixgbe, i, vector); 40369353SSamuel.Tu@Sun.COM vector = (vector +1) % ixgbe->intr_cnt; 40378275SEric Cheng } 40386621Sbt150084 40396621Sbt150084 /* 40409353SSamuel.Tu@Sun.COM * Map tx ring interrupts to vectors 40416621Sbt150084 */ 40428275SEric Cheng for (i = 0; i < ixgbe->num_tx_rings; i++) { 40438275SEric Cheng ixgbe_map_txring_to_vector(ixgbe, i, vector); 40449353SSamuel.Tu@Sun.COM vector = (vector +1) % ixgbe->intr_cnt; 40456621Sbt150084 } 40466621Sbt150084 40476621Sbt150084 return (IXGBE_SUCCESS); 40486621Sbt150084 } 40496621Sbt150084 40506621Sbt150084 /* 40516621Sbt150084 * ixgbe_setup_adapter_vector - Setup the adapter interrupt vector(s). 40526621Sbt150084 * 40538275SEric Cheng * This relies on ring/vector mapping already set up in the 40546621Sbt150084 * vect_map[] structures 40556621Sbt150084 */ 40566621Sbt150084 static void 40576621Sbt150084 ixgbe_setup_adapter_vector(ixgbe_t *ixgbe) 40586621Sbt150084 { 40596621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 40609353SSamuel.Tu@Sun.COM ixgbe_intr_vector_t *vect; /* vector bitmap */ 40618275SEric Cheng int r_idx; /* ring index */ 40628275SEric Cheng int v_idx; /* vector index */ 40636621Sbt150084 40646621Sbt150084 /* 40656621Sbt150084 * Clear any previous entries 40666621Sbt150084 */ 40679353SSamuel.Tu@Sun.COM switch (hw->mac.type) { 40689353SSamuel.Tu@Sun.COM case ixgbe_mac_82598EB: 40699353SSamuel.Tu@Sun.COM for (v_idx = 0; v_idx < 25; v_idx++) 40709353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(v_idx), 0); 40719353SSamuel.Tu@Sun.COM 40729353SSamuel.Tu@Sun.COM break; 40739353SSamuel.Tu@Sun.COM case ixgbe_mac_82599EB: 40749353SSamuel.Tu@Sun.COM for (v_idx = 0; v_idx < 64; v_idx++) 40759353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR(v_idx), 0); 40769353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, 0); 40779353SSamuel.Tu@Sun.COM 40789353SSamuel.Tu@Sun.COM break; 40799353SSamuel.Tu@Sun.COM default: 40809353SSamuel.Tu@Sun.COM break; 40819353SSamuel.Tu@Sun.COM } 40826621Sbt150084 40836621Sbt150084 /* 40848275SEric Cheng * For non MSI-X interrupt, rx rings[0] will use RTxQ[0], and 40858275SEric Cheng * tx rings[0] will use RTxQ[1]. 40866621Sbt150084 */ 40878275SEric Cheng if (ixgbe->intr_type != DDI_INTR_TYPE_MSIX) { 40889353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe, 0, 0, 0); 40899353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe, 0, 1, 1); 40908275SEric Cheng return; 40918275SEric Cheng } 40928275SEric Cheng 40938275SEric Cheng /* 40949353SSamuel.Tu@Sun.COM * For MSI-X interrupt, "Other" is always on vector[0]. 40958275SEric Cheng */ 40969353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_OTHER_CAUSES_INDEX, 0, -1); 40976621Sbt150084 40986621Sbt150084 /* 40996621Sbt150084 * For each interrupt vector, populate the IVAR table 41006621Sbt150084 */ 41016621Sbt150084 for (v_idx = 0; v_idx < ixgbe->intr_cnt; v_idx++) { 41026621Sbt150084 vect = &ixgbe->vect_map[v_idx]; 41036621Sbt150084 41046621Sbt150084 /* 41056621Sbt150084 * For each rx ring bit set 41066621Sbt150084 */ 41076621Sbt150084 r_idx = bt_getlowbit(vect->rx_map, 0, 41086621Sbt150084 (ixgbe->num_rx_rings - 1)); 41096621Sbt150084 41106621Sbt150084 while (r_idx >= 0) { 41119353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe, r_idx, v_idx, 0); 41126621Sbt150084 r_idx = bt_getlowbit(vect->rx_map, (r_idx + 1), 41136621Sbt150084 (ixgbe->num_rx_rings - 1)); 41146621Sbt150084 } 41156621Sbt150084 41166621Sbt150084 /* 41176621Sbt150084 * For each tx ring bit set 41186621Sbt150084 */ 41196621Sbt150084 r_idx = bt_getlowbit(vect->tx_map, 0, 41206621Sbt150084 (ixgbe->num_tx_rings - 1)); 41216621Sbt150084 41226621Sbt150084 while (r_idx >= 0) { 41239353SSamuel.Tu@Sun.COM ixgbe_setup_ivar(ixgbe, r_idx, v_idx, 1); 41246621Sbt150084 r_idx = bt_getlowbit(vect->tx_map, (r_idx + 1), 41256621Sbt150084 (ixgbe->num_tx_rings - 1)); 41266621Sbt150084 } 41276621Sbt150084 } 41286621Sbt150084 } 41296621Sbt150084 41306621Sbt150084 /* 41316621Sbt150084 * ixgbe_rem_intr_handlers - Remove the interrupt handlers. 41326621Sbt150084 */ 41336621Sbt150084 static void 41346621Sbt150084 ixgbe_rem_intr_handlers(ixgbe_t *ixgbe) 41356621Sbt150084 { 41366621Sbt150084 int i; 41376621Sbt150084 int rc; 41386621Sbt150084 41396621Sbt150084 for (i = 0; i < ixgbe->intr_cnt; i++) { 41406621Sbt150084 rc = ddi_intr_remove_handler(ixgbe->htable[i]); 41416621Sbt150084 if (rc != DDI_SUCCESS) { 41426621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, 41436621Sbt150084 "Remove intr handler failed: %d", rc); 41446621Sbt150084 } 41456621Sbt150084 } 41466621Sbt150084 } 41476621Sbt150084 41486621Sbt150084 /* 41496621Sbt150084 * ixgbe_rem_intrs - Remove the allocated interrupts. 41506621Sbt150084 */ 41516621Sbt150084 static void 41526621Sbt150084 ixgbe_rem_intrs(ixgbe_t *ixgbe) 41536621Sbt150084 { 41546621Sbt150084 int i; 41556621Sbt150084 int rc; 41566621Sbt150084 41576621Sbt150084 for (i = 0; i < ixgbe->intr_cnt; i++) { 41586621Sbt150084 rc = ddi_intr_free(ixgbe->htable[i]); 41596621Sbt150084 if (rc != DDI_SUCCESS) { 41606621Sbt150084 IXGBE_DEBUGLOG_1(ixgbe, 41616621Sbt150084 "Free intr failed: %d", rc); 41626621Sbt150084 } 41636621Sbt150084 } 41646621Sbt150084 41656621Sbt150084 kmem_free(ixgbe->htable, ixgbe->intr_size); 41666621Sbt150084 ixgbe->htable = NULL; 41676621Sbt150084 } 41686621Sbt150084 41696621Sbt150084 /* 41706621Sbt150084 * ixgbe_enable_intrs - Enable all the ddi interrupts. 41716621Sbt150084 */ 41726621Sbt150084 static int 41736621Sbt150084 ixgbe_enable_intrs(ixgbe_t *ixgbe) 41746621Sbt150084 { 41756621Sbt150084 int i; 41766621Sbt150084 int rc; 41776621Sbt150084 41786621Sbt150084 /* 41796621Sbt150084 * Enable interrupts 41806621Sbt150084 */ 41816621Sbt150084 if (ixgbe->intr_cap & DDI_INTR_FLAG_BLOCK) { 41826621Sbt150084 /* 41836621Sbt150084 * Call ddi_intr_block_enable() for MSI 41846621Sbt150084 */ 41856621Sbt150084 rc = ddi_intr_block_enable(ixgbe->htable, ixgbe->intr_cnt); 41866621Sbt150084 if (rc != DDI_SUCCESS) { 41876621Sbt150084 ixgbe_log(ixgbe, 41886621Sbt150084 "Enable block intr failed: %d", rc); 41896621Sbt150084 return (IXGBE_FAILURE); 41906621Sbt150084 } 41916621Sbt150084 } else { 41926621Sbt150084 /* 41936621Sbt150084 * Call ddi_intr_enable() for Legacy/MSI non block enable 41946621Sbt150084 */ 41956621Sbt150084 for (i = 0; i < ixgbe->intr_cnt; i++) { 41966621Sbt150084 rc = ddi_intr_enable(ixgbe->htable[i]); 41976621Sbt150084 if (rc != DDI_SUCCESS) { 41986621Sbt150084 ixgbe_log(ixgbe, 41996621Sbt150084 "Enable intr failed: %d", rc); 42006621Sbt150084 return (IXGBE_FAILURE); 42016621Sbt150084 } 42026621Sbt150084 } 42036621Sbt150084 } 42046621Sbt150084 42056621Sbt150084 return (IXGBE_SUCCESS); 42066621Sbt150084 } 42076621Sbt150084 42086621Sbt150084 /* 42096621Sbt150084 * ixgbe_disable_intrs - Disable all the interrupts. 42106621Sbt150084 */ 42116621Sbt150084 static int 42126621Sbt150084 ixgbe_disable_intrs(ixgbe_t *ixgbe) 42136621Sbt150084 { 42146621Sbt150084 int i; 42156621Sbt150084 int rc; 42166621Sbt150084 42176621Sbt150084 /* 42186621Sbt150084 * Disable all interrupts 42196621Sbt150084 */ 42206621Sbt150084 if (ixgbe->intr_cap & DDI_INTR_FLAG_BLOCK) { 42216621Sbt150084 rc = ddi_intr_block_disable(ixgbe->htable, ixgbe->intr_cnt); 42226621Sbt150084 if (rc != DDI_SUCCESS) { 42236621Sbt150084 ixgbe_log(ixgbe, 42246621Sbt150084 "Disable block intr failed: %d", rc); 42256621Sbt150084 return (IXGBE_FAILURE); 42266621Sbt150084 } 42276621Sbt150084 } else { 42286621Sbt150084 for (i = 0; i < ixgbe->intr_cnt; i++) { 42296621Sbt150084 rc = ddi_intr_disable(ixgbe->htable[i]); 42306621Sbt150084 if (rc != DDI_SUCCESS) { 42316621Sbt150084 ixgbe_log(ixgbe, 42326621Sbt150084 "Disable intr failed: %d", rc); 42336621Sbt150084 return (IXGBE_FAILURE); 42346621Sbt150084 } 42356621Sbt150084 } 42366621Sbt150084 } 42376621Sbt150084 42386621Sbt150084 return (IXGBE_SUCCESS); 42396621Sbt150084 } 42406621Sbt150084 42416621Sbt150084 /* 42426621Sbt150084 * ixgbe_get_hw_state - Get and save parameters related to adapter hardware. 42436621Sbt150084 */ 42446621Sbt150084 static void 42456621Sbt150084 ixgbe_get_hw_state(ixgbe_t *ixgbe) 42466621Sbt150084 { 42476621Sbt150084 struct ixgbe_hw *hw = &ixgbe->hw; 42488490SPaul.Guo@Sun.COM ixgbe_link_speed speed = IXGBE_LINK_SPEED_UNKNOWN; 42498490SPaul.Guo@Sun.COM boolean_t link_up = B_FALSE; 42506621Sbt150084 uint32_t pcs1g_anlp = 0; 42516621Sbt150084 uint32_t pcs1g_ana = 0; 42526621Sbt150084 42536621Sbt150084 ASSERT(mutex_owned(&ixgbe->gen_lock)); 42546621Sbt150084 ixgbe->param_lp_1000fdx_cap = 0; 42556621Sbt150084 ixgbe->param_lp_100fdx_cap = 0; 42566621Sbt150084 42578490SPaul.Guo@Sun.COM /* check for link, don't wait */ 42588490SPaul.Guo@Sun.COM (void) ixgbe_check_link(hw, &speed, &link_up, false); 42598490SPaul.Guo@Sun.COM if (link_up) { 42606621Sbt150084 pcs1g_anlp = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); 42616621Sbt150084 pcs1g_ana = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); 42626621Sbt150084 42636621Sbt150084 ixgbe->param_lp_1000fdx_cap = 42646621Sbt150084 (pcs1g_anlp & IXGBE_PCS1GANLP_LPFD) ? 1 : 0; 42656621Sbt150084 ixgbe->param_lp_100fdx_cap = 42666621Sbt150084 (pcs1g_anlp & IXGBE_PCS1GANLP_LPFD) ? 1 : 0; 42676621Sbt150084 } 42686621Sbt150084 426910376SChenlu.Chen@Sun.COM ixgbe->param_adv_1000fdx_cap = 427010376SChenlu.Chen@Sun.COM (pcs1g_ana & IXGBE_PCS1GANA_FDC) ? 1 : 0; 427110376SChenlu.Chen@Sun.COM ixgbe->param_adv_100fdx_cap = (pcs1g_ana & IXGBE_PCS1GANA_FDC) ? 1 : 0; 42726621Sbt150084 } 42736621Sbt150084 42746621Sbt150084 /* 42756621Sbt150084 * ixgbe_get_driver_control - Notify that driver is in control of device. 42766621Sbt150084 */ 42776621Sbt150084 static void 42786621Sbt150084 ixgbe_get_driver_control(struct ixgbe_hw *hw) 42796621Sbt150084 { 42806621Sbt150084 uint32_t ctrl_ext; 42816621Sbt150084 42826621Sbt150084 /* 42836621Sbt150084 * Notify firmware that driver is in control of device 42846621Sbt150084 */ 42856621Sbt150084 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 42866621Sbt150084 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD; 42876621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 42886621Sbt150084 } 42896621Sbt150084 42906621Sbt150084 /* 42916621Sbt150084 * ixgbe_release_driver_control - Notify that driver is no longer in control 42926621Sbt150084 * of device. 42936621Sbt150084 */ 42946621Sbt150084 static void 42956621Sbt150084 ixgbe_release_driver_control(struct ixgbe_hw *hw) 42966621Sbt150084 { 42976621Sbt150084 uint32_t ctrl_ext; 42986621Sbt150084 42996621Sbt150084 /* 43006621Sbt150084 * Notify firmware that driver is no longer in control of device 43016621Sbt150084 */ 43026621Sbt150084 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 43036621Sbt150084 ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD; 43046621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 43056621Sbt150084 } 43066621Sbt150084 43076621Sbt150084 /* 43086621Sbt150084 * ixgbe_atomic_reserve - Atomic decrease operation. 43096621Sbt150084 */ 43106621Sbt150084 int 43116621Sbt150084 ixgbe_atomic_reserve(uint32_t *count_p, uint32_t n) 43126621Sbt150084 { 43136621Sbt150084 uint32_t oldval; 43146621Sbt150084 uint32_t newval; 43156621Sbt150084 43166621Sbt150084 /* 43176621Sbt150084 * ATOMICALLY 43186621Sbt150084 */ 43196621Sbt150084 do { 43206621Sbt150084 oldval = *count_p; 43216621Sbt150084 if (oldval < n) 43226621Sbt150084 return (-1); 43236621Sbt150084 newval = oldval - n; 43246621Sbt150084 } while (atomic_cas_32(count_p, oldval, newval) != oldval); 43256621Sbt150084 43266621Sbt150084 return (newval); 43276621Sbt150084 } 43286621Sbt150084 43296621Sbt150084 /* 43306621Sbt150084 * ixgbe_mc_table_itr - Traverse the entries in the multicast table. 43316621Sbt150084 */ 43326621Sbt150084 static uint8_t * 43336621Sbt150084 ixgbe_mc_table_itr(struct ixgbe_hw *hw, uint8_t **upd_ptr, uint32_t *vmdq) 43346621Sbt150084 { 43358490SPaul.Guo@Sun.COM uint8_t *addr = *upd_ptr; 43368490SPaul.Guo@Sun.COM uint8_t *new_ptr; 43378490SPaul.Guo@Sun.COM 43386621Sbt150084 _NOTE(ARGUNUSED(hw)); 43396621Sbt150084 _NOTE(ARGUNUSED(vmdq)); 43406621Sbt150084 43416621Sbt150084 new_ptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS; 43426621Sbt150084 *upd_ptr = new_ptr; 43436621Sbt150084 return (addr); 43446621Sbt150084 } 43456621Sbt150084 43466621Sbt150084 /* 43476621Sbt150084 * FMA support 43486621Sbt150084 */ 43496621Sbt150084 int 43506621Sbt150084 ixgbe_check_acc_handle(ddi_acc_handle_t handle) 43516621Sbt150084 { 43526621Sbt150084 ddi_fm_error_t de; 43536621Sbt150084 43546621Sbt150084 ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION); 43556621Sbt150084 ddi_fm_acc_err_clear(handle, DDI_FME_VERSION); 43566621Sbt150084 return (de.fme_status); 43576621Sbt150084 } 43586621Sbt150084 43596621Sbt150084 int 43606621Sbt150084 ixgbe_check_dma_handle(ddi_dma_handle_t handle) 43616621Sbt150084 { 43626621Sbt150084 ddi_fm_error_t de; 43636621Sbt150084 43646621Sbt150084 ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION); 43656621Sbt150084 return (de.fme_status); 43666621Sbt150084 } 43676621Sbt150084 43686621Sbt150084 /* 43696621Sbt150084 * ixgbe_fm_error_cb - The IO fault service error handling callback function. 43706621Sbt150084 */ 43716621Sbt150084 static int 43726621Sbt150084 ixgbe_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data) 43736621Sbt150084 { 43746621Sbt150084 _NOTE(ARGUNUSED(impl_data)); 43756621Sbt150084 /* 43766621Sbt150084 * as the driver can always deal with an error in any dma or 43776621Sbt150084 * access handle, we can just return the fme_status value. 43786621Sbt150084 */ 43796621Sbt150084 pci_ereport_post(dip, err, NULL); 43806621Sbt150084 return (err->fme_status); 43816621Sbt150084 } 43826621Sbt150084 43836621Sbt150084 static void 43846621Sbt150084 ixgbe_fm_init(ixgbe_t *ixgbe) 43856621Sbt150084 { 43866621Sbt150084 ddi_iblock_cookie_t iblk; 43876621Sbt150084 int fma_acc_flag, fma_dma_flag; 43886621Sbt150084 43896621Sbt150084 /* 43906621Sbt150084 * Only register with IO Fault Services if we have some capability 43916621Sbt150084 */ 43926621Sbt150084 if (ixgbe->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) { 43936621Sbt150084 ixgbe_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC; 43946621Sbt150084 fma_acc_flag = 1; 43956621Sbt150084 } else { 43966621Sbt150084 ixgbe_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC; 43976621Sbt150084 fma_acc_flag = 0; 43986621Sbt150084 } 43996621Sbt150084 44006621Sbt150084 if (ixgbe->fm_capabilities & DDI_FM_DMACHK_CAPABLE) { 44016621Sbt150084 fma_dma_flag = 1; 44026621Sbt150084 } else { 44036621Sbt150084 fma_dma_flag = 0; 44046621Sbt150084 } 44056621Sbt150084 44066621Sbt150084 ixgbe_set_fma_flags(fma_acc_flag, fma_dma_flag); 44076621Sbt150084 44086621Sbt150084 if (ixgbe->fm_capabilities) { 44096621Sbt150084 44106621Sbt150084 /* 44116621Sbt150084 * Register capabilities with IO Fault Services 44126621Sbt150084 */ 44136621Sbt150084 ddi_fm_init(ixgbe->dip, &ixgbe->fm_capabilities, &iblk); 44146621Sbt150084 44156621Sbt150084 /* 44166621Sbt150084 * Initialize pci ereport capabilities if ereport capable 44176621Sbt150084 */ 44186621Sbt150084 if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities) || 44196621Sbt150084 DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities)) 44206621Sbt150084 pci_ereport_setup(ixgbe->dip); 44216621Sbt150084 44226621Sbt150084 /* 44236621Sbt150084 * Register error callback if error callback capable 44246621Sbt150084 */ 44256621Sbt150084 if (DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities)) 44266621Sbt150084 ddi_fm_handler_register(ixgbe->dip, 44276621Sbt150084 ixgbe_fm_error_cb, (void*) ixgbe); 44286621Sbt150084 } 44296621Sbt150084 } 44306621Sbt150084 44316621Sbt150084 static void 44326621Sbt150084 ixgbe_fm_fini(ixgbe_t *ixgbe) 44336621Sbt150084 { 44346621Sbt150084 /* 44356621Sbt150084 * Only unregister FMA capabilities if they are registered 44366621Sbt150084 */ 44376621Sbt150084 if (ixgbe->fm_capabilities) { 44386621Sbt150084 44396621Sbt150084 /* 44406621Sbt150084 * Release any resources allocated by pci_ereport_setup() 44416621Sbt150084 */ 44426621Sbt150084 if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities) || 44436621Sbt150084 DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities)) 44446621Sbt150084 pci_ereport_teardown(ixgbe->dip); 44456621Sbt150084 44466621Sbt150084 /* 44476621Sbt150084 * Un-register error callback if error callback capable 44486621Sbt150084 */ 44496621Sbt150084 if (DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities)) 44506621Sbt150084 ddi_fm_handler_unregister(ixgbe->dip); 44516621Sbt150084 44526621Sbt150084 /* 44536621Sbt150084 * Unregister from IO Fault Service 44546621Sbt150084 */ 44556621Sbt150084 ddi_fm_fini(ixgbe->dip); 44566621Sbt150084 } 44576621Sbt150084 } 44586621Sbt150084 44596621Sbt150084 void 44606621Sbt150084 ixgbe_fm_ereport(ixgbe_t *ixgbe, char *detail) 44616621Sbt150084 { 44626621Sbt150084 uint64_t ena; 44636621Sbt150084 char buf[FM_MAX_CLASS]; 44646621Sbt150084 44656621Sbt150084 (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail); 44666621Sbt150084 ena = fm_ena_generate(0, FM_ENA_FMT1); 44676621Sbt150084 if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities)) { 44686621Sbt150084 ddi_fm_ereport_post(ixgbe->dip, buf, ena, DDI_NOSLEEP, 44696621Sbt150084 FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL); 44706621Sbt150084 } 44716621Sbt150084 } 44728275SEric Cheng 44738275SEric Cheng static int 44748275SEric Cheng ixgbe_ring_start(mac_ring_driver_t rh, uint64_t mr_gen_num) 44758275SEric Cheng { 44768275SEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)rh; 44778275SEric Cheng 44788275SEric Cheng mutex_enter(&rx_ring->rx_lock); 44798275SEric Cheng rx_ring->ring_gen_num = mr_gen_num; 44808275SEric Cheng mutex_exit(&rx_ring->rx_lock); 44818275SEric Cheng return (0); 44828275SEric Cheng } 44838275SEric Cheng 44848275SEric Cheng /* 44858275SEric Cheng * Callback funtion for MAC layer to register all rings. 44868275SEric Cheng */ 44878275SEric Cheng /* ARGSUSED */ 44888275SEric Cheng void 44898275SEric Cheng ixgbe_fill_ring(void *arg, mac_ring_type_t rtype, const int rg_index, 44908275SEric Cheng const int ring_index, mac_ring_info_t *infop, mac_ring_handle_t rh) 44918275SEric Cheng { 44928275SEric Cheng ixgbe_t *ixgbe = (ixgbe_t *)arg; 44938275SEric Cheng mac_intr_t *mintr = &infop->mri_intr; 44948275SEric Cheng 44958275SEric Cheng switch (rtype) { 44968275SEric Cheng case MAC_RING_TYPE_RX: { 44978275SEric Cheng ASSERT(rg_index == 0); 44988275SEric Cheng ASSERT(ring_index < ixgbe->num_rx_rings); 44998275SEric Cheng 45008275SEric Cheng ixgbe_rx_ring_t *rx_ring = &ixgbe->rx_rings[ring_index]; 45018275SEric Cheng rx_ring->ring_handle = rh; 45028275SEric Cheng 45038275SEric Cheng infop->mri_driver = (mac_ring_driver_t)rx_ring; 45048275SEric Cheng infop->mri_start = ixgbe_ring_start; 45058275SEric Cheng infop->mri_stop = NULL; 45068275SEric Cheng infop->mri_poll = ixgbe_ring_rx_poll; 45078275SEric Cheng 45088275SEric Cheng mintr->mi_handle = (mac_intr_handle_t)rx_ring; 45098275SEric Cheng mintr->mi_enable = ixgbe_rx_ring_intr_enable; 45108275SEric Cheng mintr->mi_disable = ixgbe_rx_ring_intr_disable; 45118275SEric Cheng 45128275SEric Cheng break; 45138275SEric Cheng } 45148275SEric Cheng case MAC_RING_TYPE_TX: { 45158275SEric Cheng ASSERT(rg_index == -1); 45168275SEric Cheng ASSERT(ring_index < ixgbe->num_tx_rings); 45178275SEric Cheng 45188275SEric Cheng ixgbe_tx_ring_t *tx_ring = &ixgbe->tx_rings[ring_index]; 45198275SEric Cheng tx_ring->ring_handle = rh; 45208275SEric Cheng 45218275SEric Cheng infop->mri_driver = (mac_ring_driver_t)tx_ring; 45228275SEric Cheng infop->mri_start = NULL; 45238275SEric Cheng infop->mri_stop = NULL; 45248275SEric Cheng infop->mri_tx = ixgbe_ring_tx; 45258275SEric Cheng 45268275SEric Cheng break; 45278275SEric Cheng } 45288275SEric Cheng default: 45298275SEric Cheng break; 45308275SEric Cheng } 45318275SEric Cheng } 45328275SEric Cheng 45338275SEric Cheng /* 45348275SEric Cheng * Callback funtion for MAC layer to register all groups. 45358275SEric Cheng */ 45368275SEric Cheng void 45378275SEric Cheng ixgbe_fill_group(void *arg, mac_ring_type_t rtype, const int index, 45388275SEric Cheng mac_group_info_t *infop, mac_group_handle_t gh) 45398275SEric Cheng { 45408275SEric Cheng ixgbe_t *ixgbe = (ixgbe_t *)arg; 45418275SEric Cheng 45428275SEric Cheng switch (rtype) { 45438275SEric Cheng case MAC_RING_TYPE_RX: { 45448275SEric Cheng ixgbe_rx_group_t *rx_group; 45458275SEric Cheng 45468275SEric Cheng rx_group = &ixgbe->rx_groups[index]; 45478275SEric Cheng rx_group->group_handle = gh; 45488275SEric Cheng 45498275SEric Cheng infop->mgi_driver = (mac_group_driver_t)rx_group; 45508275SEric Cheng infop->mgi_start = NULL; 45518275SEric Cheng infop->mgi_stop = NULL; 45528275SEric Cheng infop->mgi_addmac = ixgbe_addmac; 45538275SEric Cheng infop->mgi_remmac = ixgbe_remmac; 45548275SEric Cheng infop->mgi_count = (ixgbe->num_rx_rings / ixgbe->num_rx_groups); 45558275SEric Cheng 45568275SEric Cheng break; 45578275SEric Cheng } 45588275SEric Cheng case MAC_RING_TYPE_TX: 45598275SEric Cheng break; 45608275SEric Cheng default: 45618275SEric Cheng break; 45628275SEric Cheng } 45638275SEric Cheng } 45648275SEric Cheng 45658275SEric Cheng /* 45668275SEric Cheng * Enable interrupt on the specificed rx ring. 45678275SEric Cheng */ 45688275SEric Cheng int 45698275SEric Cheng ixgbe_rx_ring_intr_enable(mac_intr_handle_t intrh) 45708275SEric Cheng { 45718275SEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)intrh; 45728275SEric Cheng ixgbe_t *ixgbe = rx_ring->ixgbe; 45738275SEric Cheng int r_idx = rx_ring->index; 45748275SEric Cheng int v_idx = rx_ring->intr_vector; 45758275SEric Cheng 45768275SEric Cheng mutex_enter(&ixgbe->gen_lock); 45778275SEric Cheng ASSERT(BT_TEST(ixgbe->vect_map[v_idx].rx_map, r_idx) == 0); 45788275SEric Cheng 45798275SEric Cheng /* 45808275SEric Cheng * To enable interrupt by setting the VAL bit of given interrupt 45818275SEric Cheng * vector allocation register (IVAR). 45828275SEric Cheng */ 45839353SSamuel.Tu@Sun.COM ixgbe_enable_ivar(ixgbe, r_idx, 0); 45848275SEric Cheng 45858275SEric Cheng BT_SET(ixgbe->vect_map[v_idx].rx_map, r_idx); 458610305SPaul.Guo@Sun.COM 458710305SPaul.Guo@Sun.COM /* 458810305SPaul.Guo@Sun.COM * To trigger a Rx interrupt to on this ring 458910305SPaul.Guo@Sun.COM */ 459010305SPaul.Guo@Sun.COM IXGBE_WRITE_REG(&ixgbe->hw, IXGBE_EICS, (1 << v_idx)); 459110305SPaul.Guo@Sun.COM IXGBE_WRITE_FLUSH(&ixgbe->hw); 459210305SPaul.Guo@Sun.COM 45938275SEric Cheng mutex_exit(&ixgbe->gen_lock); 45948275SEric Cheng 45958275SEric Cheng return (0); 45968275SEric Cheng } 45978275SEric Cheng 45988275SEric Cheng /* 45998275SEric Cheng * Disable interrupt on the specificed rx ring. 46008275SEric Cheng */ 46018275SEric Cheng int 46028275SEric Cheng ixgbe_rx_ring_intr_disable(mac_intr_handle_t intrh) 46038275SEric Cheng { 46048275SEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)intrh; 46058275SEric Cheng ixgbe_t *ixgbe = rx_ring->ixgbe; 46068275SEric Cheng int r_idx = rx_ring->index; 46078275SEric Cheng int v_idx = rx_ring->intr_vector; 46088275SEric Cheng 46098275SEric Cheng mutex_enter(&ixgbe->gen_lock); 46108275SEric Cheng ASSERT(BT_TEST(ixgbe->vect_map[v_idx].rx_map, r_idx) == 1); 46118275SEric Cheng 46128275SEric Cheng /* 46138275SEric Cheng * To disable interrupt by clearing the VAL bit of given interrupt 46148275SEric Cheng * vector allocation register (IVAR). 46158275SEric Cheng */ 46169353SSamuel.Tu@Sun.COM ixgbe_disable_ivar(ixgbe, r_idx, 0); 46178275SEric Cheng 46188275SEric Cheng BT_CLEAR(ixgbe->vect_map[v_idx].rx_map, r_idx); 46198275SEric Cheng 46208275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46218275SEric Cheng 46228275SEric Cheng return (0); 46238275SEric Cheng } 46248275SEric Cheng 46258275SEric Cheng /* 46268275SEric Cheng * Add a mac address. 46278275SEric Cheng */ 46288275SEric Cheng static int 46298275SEric Cheng ixgbe_addmac(void *arg, const uint8_t *mac_addr) 46308275SEric Cheng { 46318275SEric Cheng ixgbe_rx_group_t *rx_group = (ixgbe_rx_group_t *)arg; 46328275SEric Cheng ixgbe_t *ixgbe = rx_group->ixgbe; 46338275SEric Cheng int slot; 46348275SEric Cheng int err; 46358275SEric Cheng 46368275SEric Cheng mutex_enter(&ixgbe->gen_lock); 46378275SEric Cheng 46388275SEric Cheng if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) { 46398275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46408275SEric Cheng return (ECANCELED); 46418275SEric Cheng } 46428275SEric Cheng 46438275SEric Cheng if (ixgbe->unicst_avail == 0) { 46448275SEric Cheng /* no slots available */ 46458275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46468275SEric Cheng return (ENOSPC); 46478275SEric Cheng } 46488275SEric Cheng 46498275SEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) { 46508275SEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 0) 46518275SEric Cheng break; 46528275SEric Cheng } 46538275SEric Cheng 46548275SEric Cheng ASSERT((slot >= 0) && (slot < ixgbe->unicst_total)); 46558275SEric Cheng 46568275SEric Cheng if ((err = ixgbe_unicst_set(ixgbe, mac_addr, slot)) == 0) { 46578275SEric Cheng ixgbe->unicst_addr[slot].mac.set = 1; 46588275SEric Cheng ixgbe->unicst_avail--; 46598275SEric Cheng } 46608275SEric Cheng 46618275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46628275SEric Cheng 46638275SEric Cheng return (err); 46648275SEric Cheng } 46658275SEric Cheng 46668275SEric Cheng /* 46678275SEric Cheng * Remove a mac address. 46688275SEric Cheng */ 46698275SEric Cheng static int 46708275SEric Cheng ixgbe_remmac(void *arg, const uint8_t *mac_addr) 46718275SEric Cheng { 46728275SEric Cheng ixgbe_rx_group_t *rx_group = (ixgbe_rx_group_t *)arg; 46738275SEric Cheng ixgbe_t *ixgbe = rx_group->ixgbe; 46748275SEric Cheng int slot; 46758275SEric Cheng int err; 46768275SEric Cheng 46778275SEric Cheng mutex_enter(&ixgbe->gen_lock); 46788275SEric Cheng 46798275SEric Cheng if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) { 46808275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46818275SEric Cheng return (ECANCELED); 46828275SEric Cheng } 46838275SEric Cheng 46848275SEric Cheng slot = ixgbe_unicst_find(ixgbe, mac_addr); 46858275SEric Cheng if (slot == -1) { 46868275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46878275SEric Cheng return (EINVAL); 46888275SEric Cheng } 46898275SEric Cheng 46908275SEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 0) { 46918275SEric Cheng mutex_exit(&ixgbe->gen_lock); 46928275SEric Cheng return (EINVAL); 46938275SEric Cheng } 46948275SEric Cheng 46958275SEric Cheng bzero(ixgbe->unicst_addr[slot].mac.addr, ETHERADDRL); 46968275SEric Cheng if ((err = ixgbe_unicst_set(ixgbe, 46978275SEric Cheng ixgbe->unicst_addr[slot].mac.addr, slot)) == 0) { 46988275SEric Cheng ixgbe->unicst_addr[slot].mac.set = 0; 46998275SEric Cheng ixgbe->unicst_avail++; 47008275SEric Cheng } 47018275SEric Cheng 47028275SEric Cheng mutex_exit(&ixgbe->gen_lock); 47038275SEric Cheng 47048275SEric Cheng return (err); 47058275SEric Cheng } 4706