Index: sys/dev/e1000/if_em.c =================================================================== --- sys/dev/e1000/if_em.c +++ sys/dev/e1000/if_em.c @@ -774,9 +774,9 @@ em_if_attach_pre(if_ctx_t ctx) { struct adapter *adapter; + struct e1000_hw *hw; if_softc_ctx_t scctx; device_t dev; - struct e1000_hw *hw; int error = 0; INIT_DEBUGOUT("em_if_attach_pre: begin"); @@ -828,7 +828,7 @@ device_printf(dev, "attach_pre capping queues at %d\n", scctx->isc_ntxqsets_max); - if (hw.mac.type >= igb_mac_min) { + if (hw->mac.type >= igb_mac_min) { scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] * sizeof(union e1000_adv_tx_desc), EM_DBA_ALIGN); scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] * sizeof(union e1000_adv_rx_desc), EM_DBA_ALIGN); scctx->isc_txd_size[0] = sizeof(union e1000_adv_tx_desc); @@ -840,7 +840,7 @@ scctx->isc_capabilities = scctx->isc_capenable = IGB_CAPS; scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP | CSUM_TSO | CSUM_IP6_TCP | CSUM_IP6_UDP; - if (hw.mac.type != e1000_82575) + if (hw->mac.type != e1000_82575) scctx->isc_tx_csum_flags |= CSUM_SCTP | CSUM_IP6_SCTP; /* ** Some new devices, as with ixgbe, now may @@ -848,7 +848,7 @@ ** track of which is used. */ scctx->isc_msix_bar = pci_msix_table_bar(dev); - } else if (hw.mac.type >= em_mac_min) { + } else if (hw->mac.type >= em_mac_min) { scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0]* sizeof(struct e1000_tx_desc), EM_DBA_ALIGN); scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] * sizeof(union e1000_rx_desc_extended), EM_DBA_ALIGN); scctx->isc_txd_size[0] = sizeof(struct e1000_tx_desc); @@ -880,7 +880,7 @@ * We support MSI-X with 82574 only, but indicate to iflib(4) * that it shall give MSI at least a try with other devices. */ - if (hw.mac.type == e1000_82574) { + if (hw->mac.type == e1000_82574) { scctx->isc_msix_bar = pci_msix_table_bar(dev);; } else { scctx->isc_msix_bar = -1; @@ -894,7 +894,7 @@ scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP; scctx->isc_txrx = &lem_txrx; scctx->isc_capabilities = scctx->isc_capenable = LEM_CAPS; - if (hw.mac.type < e1000_82543) + if (hw->mac.type < e1000_82543) scctx->isc_capenable &= ~(IFCAP_HWCSUM|IFCAP_VLAN_HWCSUM); /* INTx only */ scctx->isc_msix_bar = 0; @@ -987,7 +987,7 @@ hw->phy.autoneg_wait_to_complete = FALSE; hw->phy.autoneg_advertised = AUTONEG_ADV_DEFAULT; - if (hw.mac.type < em_mac_min) { + if (hw->mac.type < em_mac_min) { e1000_init_script_state_82541(hw, TRUE); e1000_set_tbi_compatibility_82543(hw, TRUE); } @@ -1002,7 +1002,7 @@ * Set the frame limits assuming * standard ethernet sized frames. */ - scctx->isc_max_frame_size = hw.mac.max_frame_size = + scctx->isc_max_frame_size = hw->mac.max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHERNET_FCS_SIZE; /* @@ -1203,11 +1203,12 @@ { int max_frame_size; struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if_softc_ctx_t scctx = iflib_get_softc_ctx(ctx); IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)"); - switch (adapter->hw.mac.type) { + switch (hw->mac.type) { case e1000_82571: case e1000_82572: case e1000_ich9lan: @@ -1231,7 +1232,7 @@ max_frame_size = ETHER_MAX_LEN; break; default: - if (adapter->hw.mac.type >= igb_mac_min) + if (hw->mac.type >= igb_mac_min) max_frame_size = 9234; else /* lem */ max_frame_size = MAX_JUMBO_FRAME_SIZE; @@ -1240,7 +1241,7 @@ return (EINVAL); } - scctx->isc_max_frame_size = adapter->hw.mac.max_frame_size = + scctx->isc_max_frame_size = hw->mac.max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; return (0); } @@ -1258,6 +1259,7 @@ em_if_init(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if_softc_ctx_t scctx = adapter->shared; struct ifnet *ifp = iflib_get_ifp(ctx); struct em_tx_queue *tx_que; @@ -1266,11 +1268,11 @@ INIT_DEBUGOUT("em_if_init: begin"); /* Get the latest mac address, User can use a LAA */ - bcopy(if_getlladdr(ifp), adapter->hw.mac.addr, + bcopy(if_getlladdr(ifp), hw->mac.addr, ETHER_ADDR_LEN); /* Put the address into the Receive Address Array */ - e1000_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); + e1000_rar_set(hw, hw->mac.addr, 0); /* * With the 82571 adapter, RAR[0] may be overwritten @@ -1278,9 +1280,9 @@ * in RAR[14] for that eventuality, this assures * the interface continues to function. */ - if (adapter->hw.mac.type == e1000_82571) { - e1000_set_laa_state_82571(&adapter->hw, TRUE); - e1000_rar_set(&adapter->hw, adapter->hw.mac.addr, + if (hw->mac.type == e1000_82571) { + e1000_set_laa_state_82571(hw, TRUE); + e1000_rar_set(hw, hw->mac.addr, E1000_RAR_ENTRIES - 1); } @@ -1303,11 +1305,11 @@ } /* Setup VLAN support, basic and offload if available */ - E1000_WRITE_REG(&adapter->hw, E1000_VET, ETHERTYPE_VLAN); + E1000_WRITE_REG(hw, E1000_VET, ETHERTYPE_VLAN); /* Clear bad data from Rx FIFOs */ - if (adapter->hw.mac.type >= igb_mac_min) - e1000_rx_fifo_flush_82575(&adapter->hw); + if (hw->mac.type >= igb_mac_min) + e1000_rx_fifo_flush_82575(hw); /* Configure for OS presence */ em_init_manageability(adapter); @@ -1328,47 +1330,47 @@ em_setup_vlan_hw_support(adapter); else { u32 ctrl; - ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL); + ctrl = E1000_READ_REG(hw, E1000_CTRL); ctrl |= E1000_CTRL_VME; - E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl); + E1000_WRITE_REG(hw, E1000_CTRL, ctrl); } } else { u32 ctrl; - ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL); + ctrl = E1000_READ_REG(hw, E1000_CTRL); ctrl &= ~E1000_CTRL_VME; - E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl); + E1000_WRITE_REG(hw, E1000_CTRL, ctrl); } /* Don't lose promiscuous settings */ em_if_set_promisc(ctx, if_getflags(ifp)); - e1000_clear_hw_cntrs_base_generic(&adapter->hw); + e1000_clear_hw_cntrs_base_generic(hw); /* MSI-X configuration for 82574 */ - if (adapter->hw.mac.type == e1000_82574) { - int tmp = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); + if (hw->mac.type == e1000_82574) { + int tmp = E1000_READ_REG(hw, E1000_CTRL_EXT); tmp |= E1000_CTRL_EXT_PBA_CLR; - E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, tmp); + E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmp); /* Set the IVAR - interrupt vector routing. */ - E1000_WRITE_REG(&adapter->hw, E1000_IVAR, adapter->ivars); + E1000_WRITE_REG(hw, E1000_IVAR, adapter->ivars); } else if (adapter->intr_type == IFLIB_INTR_MSIX) /* Set up queue routing */ igb_configure_queues(adapter); /* this clears any pending interrupts */ - E1000_READ_REG(&adapter->hw, E1000_ICR); - E1000_WRITE_REG(&adapter->hw, E1000_ICS, E1000_ICS_LSC); + E1000_READ_REG(hw, E1000_ICR); + E1000_WRITE_REG(hw, E1000_ICS, E1000_ICS_LSC); /* AMT based hardware can now take control from firmware */ if (adapter->has_manage && adapter->has_amt) em_get_hw_control(adapter); /* Set Energy Efficient Ethernet */ - if (adapter->hw.mac.type >= igb_mac_min && - adapter->hw.phy.media_type == e1000_media_type_copper) { - if (adapter->hw.mac.type == e1000_i354) - e1000_set_eee_i354(&adapter->hw, TRUE, TRUE); + if (hw->mac.type >= igb_mac_min && + hw->phy.media_type == e1000_media_type_copper) { + if (hw->mac.type == e1000_i354) + e1000_set_eee_i354(hw, TRUE, TRUE); else - e1000_set_eee_i350(&adapter->hw, TRUE, TRUE); + e1000_set_eee_i350(hw, TRUE, TRUE); } } @@ -1484,35 +1486,36 @@ em_msix_link(void *arg) { struct adapter *adapter = arg; + struct e1000_hw *hw = &adapter->hw; u32 reg_icr; ++adapter->link_irq; - MPASS(adapter->hw.back != NULL); - reg_icr = E1000_READ_REG(&adapter->hw, E1000_ICR); + MPASS(hw->back != NULL); + reg_icr = E1000_READ_REG(hw, E1000_ICR); if (reg_icr & E1000_ICR_RXO) adapter->rx_overruns++; if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { em_handle_link(adapter->ctx); - } else if (adapter->hw.mac.type == e1000_82574) { + } else if (hw->mac.type == e1000_82574) { /* Only re-arm 82574 if em_if_update_admin_status() won't. */ - E1000_WRITE_REG(&adapter->hw, E1000_IMS, EM_MSIX_LINK | + E1000_WRITE_REG(hw, E1000_IMS, EM_MSIX_LINK | E1000_IMS_LSC); } - if (adapter->hw.mac.type == e1000_82574) { + if (hw->mac.type == e1000_82574) { /* * Because we must read the ICR for this interrupt it may * clear other causes using autoclear, for this reason we * simply create a soft interrupt for all these vectors. */ if (reg_icr) - E1000_WRITE_REG(&adapter->hw, E1000_ICS, adapter->ims); + E1000_WRITE_REG(hw, E1000_ICS, adapter->ims); } else { /* Re-arm unconditionally */ - E1000_WRITE_REG(&adapter->hw, E1000_IMS, E1000_IMS_LSC); - E1000_WRITE_REG(&adapter->hw, E1000_EIMS, adapter->link_mask); + E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_LSC); + E1000_WRITE_REG(hw, E1000_EIMS, adapter->link_mask); } return (FILTER_HANDLED); @@ -1540,6 +1543,7 @@ em_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; u_char fiber_type = IFM_1000_SX; INIT_DEBUGOUT("em_if_media_status: begin"); @@ -1555,9 +1559,9 @@ ifmr->ifm_status |= IFM_ACTIVE; - if ((adapter->hw.phy.media_type == e1000_media_type_fiber) || - (adapter->hw.phy.media_type == e1000_media_type_internal_serdes)) { - if (adapter->hw.mac.type == e1000_82545) + if ((hw->phy.media_type == e1000_media_type_fiber) || + (hw->phy.media_type == e1000_media_type_internal_serdes)) { + if (hw->mac.type == e1000_82545) fiber_type = IFM_1000_LX; ifmr->ifm_active |= fiber_type | IFM_FDX; } else { @@ -1591,6 +1595,7 @@ em_if_media_change(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; struct ifmedia *ifm = iflib_get_media(ctx); INIT_DEBUGOUT("em_if_media_change: begin"); @@ -1600,30 +1605,30 @@ switch (IFM_SUBTYPE(ifm->ifm_media)) { case IFM_AUTO: - adapter->hw.mac.autoneg = DO_AUTO_NEG; - adapter->hw.phy.autoneg_advertised = AUTONEG_ADV_DEFAULT; + hw->mac.autoneg = DO_AUTO_NEG; + hw->phy.autoneg_advertised = AUTONEG_ADV_DEFAULT; break; case IFM_1000_LX: case IFM_1000_SX: case IFM_1000_T: - adapter->hw.mac.autoneg = DO_AUTO_NEG; - adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; + hw->mac.autoneg = DO_AUTO_NEG; + hw->phy.autoneg_advertised = ADVERTISE_1000_FULL; break; case IFM_100_TX: - adapter->hw.mac.autoneg = FALSE; - adapter->hw.phy.autoneg_advertised = 0; + hw->mac.autoneg = FALSE; + hw->phy.autoneg_advertised = 0; if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) - adapter->hw.mac.forced_speed_duplex = ADVERTISE_100_FULL; + hw->mac.forced_speed_duplex = ADVERTISE_100_FULL; else - adapter->hw.mac.forced_speed_duplex = ADVERTISE_100_HALF; + hw->mac.forced_speed_duplex = ADVERTISE_100_HALF; break; case IFM_10_T: - adapter->hw.mac.autoneg = FALSE; - adapter->hw.phy.autoneg_advertised = 0; + hw->mac.autoneg = FALSE; + hw->phy.autoneg_advertised = 0; if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) - adapter->hw.mac.forced_speed_duplex = ADVERTISE_10_FULL; + hw->mac.forced_speed_duplex = ADVERTISE_10_FULL; else - adapter->hw.mac.forced_speed_duplex = ADVERTISE_10_HALF; + hw->mac.forced_speed_duplex = ADVERTISE_10_HALF; break; default: device_printf(adapter->dev, "Unsupported media type\n"); @@ -1638,22 +1643,23 @@ em_if_set_promisc(if_ctx_t ctx, int flags) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; u32 reg_rctl; em_disable_promisc(ctx); - reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); + reg_rctl = E1000_READ_REG(hw, E1000_RCTL); if (flags & IFF_PROMISC) { reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); /* Turn this on if you want to see bad packets */ if (em_debug_sbp) reg_rctl |= E1000_RCTL_SBP; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl); + E1000_WRITE_REG(hw, E1000_RCTL, reg_rctl); } else if (flags & IFF_ALLMULTI) { reg_rctl |= E1000_RCTL_MPE; reg_rctl &= ~E1000_RCTL_UPE; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl); + E1000_WRITE_REG(hw, E1000_RCTL, reg_rctl); } return (0); } @@ -1704,6 +1710,7 @@ em_if_multi_set(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; struct ifnet *ifp = iflib_get_ifp(ctx); u32 reg_rctl = 0; u8 *mta; /* Multicast array memory */ @@ -1714,33 +1721,33 @@ mta = adapter->mta; bzero(mta, sizeof(u8) * ETHER_ADDR_LEN * MAX_NUM_MULTICAST_ADDRESSES); - if (adapter->hw.mac.type == e1000_82542 && - adapter->hw.revision_id == E1000_REVISION_2) { - reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); - if (adapter->hw.bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) - e1000_pci_clear_mwi(&adapter->hw); + if (hw->mac.type == e1000_82542 && + hw->revision_id == E1000_REVISION_2) { + reg_rctl = E1000_READ_REG(hw, E1000_RCTL); + if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) + e1000_pci_clear_mwi(hw); reg_rctl |= E1000_RCTL_RST; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl); + E1000_WRITE_REG(hw, E1000_RCTL, reg_rctl); msec_delay(5); } mcnt = if_foreach_llmaddr(ifp, em_copy_maddr, mta); if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) { - reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); + reg_rctl = E1000_READ_REG(hw, E1000_RCTL); reg_rctl |= E1000_RCTL_MPE; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl); + E1000_WRITE_REG(hw, E1000_RCTL, reg_rctl); } else - e1000_update_mc_addr_list(&adapter->hw, mta, mcnt); + e1000_update_mc_addr_list(hw, mta, mcnt); - if (adapter->hw.mac.type == e1000_82542 && - adapter->hw.revision_id == E1000_REVISION_2) { - reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); + if (hw->mac.type == e1000_82542 && + hw->revision_id == E1000_REVISION_2) { + reg_rctl = E1000_READ_REG(hw, E1000_RCTL); reg_rctl &= ~E1000_RCTL_RST; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl); + E1000_WRITE_REG(hw, E1000_RCTL, reg_rctl); msec_delay(5); - if (adapter->hw.bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) - e1000_pci_set_mwi(&adapter->hw); + if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) + e1000_pci_set_mwi(hw); } } @@ -1793,7 +1800,7 @@ break; case e1000_media_type_internal_serdes: e1000_check_for_link(hw); - link_check = hw.mac.serdes_has_link; + link_check = hw->mac.serdes_has_link; break; /* VF device is type_unknown */ case e1000_media_type_unknown: @@ -1841,7 +1848,7 @@ msec_delay(I210_LINK_DELAY); /* Reset if the media type changed. */ if (hw->dev_spec._82575.media_changed && - hw.mac.type >= igb_mac_min) { + hw->mac.type >= igb_mac_min) { hw->dev_spec._82575.media_changed = false; adapter->flags |= IGB_MEDIA_RESET; em_reset(ctx); @@ -1889,15 +1896,16 @@ em_if_stop(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; INIT_DEBUGOUT("em_if_stop: begin"); - e1000_reset_hw(&adapter->hw); - if (adapter->hw.mac.type >= e1000_82544) - E1000_WRITE_REG(&adapter->hw, E1000_WUFC, 0); + e1000_reset_hw(hw); + if (hw->mac.type >= e1000_82544) + E1000_WRITE_REG(hw, E1000_WUFC, 0); - e1000_led_off(&adapter->hw); - e1000_cleanup_led(&adapter->hw); + e1000_led_off(hw); + e1000_cleanup_led(hw); } /********************************************************************* @@ -1910,21 +1918,22 @@ { device_t dev = iflib_get_dev(ctx); struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; /* Make sure our PCI config space has the necessary stuff set */ - adapter->hw.bus.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); + hw->bus.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); /* Save off the information about this board */ - adapter->hw.vendor_id = pci_get_vendor(dev); - adapter->hw.device_id = pci_get_device(dev); - adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1); - adapter->hw.subsystem_vendor_id = + hw->vendor_id = pci_get_vendor(dev); + hw->device_id = pci_get_device(dev); + hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); + hw->subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2); - adapter->hw.subsystem_device_id = + hw->subsystem_device_id = pci_read_config(dev, PCIR_SUBDEV_0, 2); /* Do Shared Code Init and Setup */ - if (e1000_set_mac_type(&adapter->hw)) { + if (e1000_set_mac_type(hw)) { device_printf(dev, "Setup init failure\n"); return; } @@ -1934,6 +1943,7 @@ em_allocate_pci_resources(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; device_t dev = iflib_get_dev(ctx); int rid, val; @@ -1947,11 +1957,11 @@ adapter->osdep.mem_bus_space_tag = rman_get_bustag(adapter->memory); adapter->osdep.mem_bus_space_handle = rman_get_bushandle(adapter->memory); - adapter->hw.hw_addr = (u8 *)&adapter->osdep.mem_bus_space_handle; + hw->hw_addr = (u8 *)&adapter->osdep.mem_bus_space_handle; /* Only older adapters use IO mapping */ - if (adapter->hw.mac.type < em_mac_min && - adapter->hw.mac.type > e1000_82543) { + if (hw->mac.type < em_mac_min && + hw->mac.type > e1000_82543) { /* Figure our where our IO BAR is ? */ for (rid = PCIR_BAR(0); rid < PCIR_CIS;) { val = pci_read_config(dev, rid, 4); @@ -1974,14 +1984,14 @@ "ioport\n"); return (ENXIO); } - adapter->hw.io_base = 0; + hw->io_base = 0; adapter->osdep.io_bus_space_tag = rman_get_bustag(adapter->ioport); adapter->osdep.io_bus_space_handle = rman_get_bushandle(adapter->ioport); } - adapter->hw.back = &adapter->osdep; + hw->back = &adapter->osdep; return (0); } @@ -1995,6 +2005,7 @@ em_if_msix_intr_assign(if_ctx_t ctx, int msix) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; struct em_rx_queue *rx_que = adapter->rx_queues; struct em_tx_queue *tx_que = adapter->tx_queues; int error, rid, i, vector = 0, rx_vectors; @@ -2019,11 +2030,11 @@ * are for RX0 and RX1, note this has * NOTHING to do with the MSI-X vector */ - if (adapter->hw.mac.type == e1000_82574) { + if (hw->mac.type == e1000_82574) { rx_que->eims = 1 << (20 + i); adapter->ims |= rx_que->eims; adapter->ivars |= (8 | rx_que->msix) << (i * 4); - } else if (adapter->hw.mac.type == e1000_82575) + } else if (hw->mac.type == e1000_82575) rx_que->eims = E1000_EICR_TX_QUEUE0 << vector; else rx_que->eims = 1 << vector; @@ -2046,11 +2057,11 @@ * are for TX0 and TX1, note this has * NOTHING to do with the MSI-X vector */ - if (adapter->hw.mac.type == e1000_82574) { + if (hw->mac.type == e1000_82574) { tx_que->eims = 1 << (22 + i); adapter->ims |= tx_que->eims; adapter->ivars |= (8 | tx_que->msix) << (8 + (i * 4)); - } else if (adapter->hw.mac.type == e1000_82575) { + } else if (hw->mac.type == e1000_82575) { tx_que->eims = E1000_EICR_TX_QUEUE0 << i; } else { tx_que->eims = 1 << i; @@ -2066,7 +2077,7 @@ goto fail; } adapter->linkvec = rx_vectors; - if (adapter->hw.mac.type < igb_mac_min) { + if (hw->mac.type < igb_mac_min) { adapter->ivars |= (8 | rx_vectors) << 16; adapter->ivars |= 0x80000000; } @@ -2088,13 +2099,13 @@ u32 tmp, ivar = 0, newitr = 0; /* First turn on RSS capability */ - if (hw.mac.type != e1000_82575) + if (hw->mac.type != e1000_82575) E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE | E1000_GPIE_EIAME | E1000_GPIE_PBA | E1000_GPIE_NSICR); /* Turn on MSI-X */ - switch (hw.mac.type) { + switch (hw->mac.type) { case e1000_82580: case e1000_i350: case e1000_i354: @@ -2276,35 +2287,35 @@ static void lem_smartspeed(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; u16 phy_tmp; - if (adapter->link_active || (adapter->hw.phy.type != e1000_phy_igp) || - adapter->hw.mac.autoneg == 0 || - (adapter->hw.phy.autoneg_advertised & ADVERTISE_1000_FULL) == 0) + if (adapter->link_active || (hw->phy.type != e1000_phy_igp) || + hw->mac.autoneg == 0 || + (hw->phy.autoneg_advertised & ADVERTISE_1000_FULL) == 0) return; if (adapter->smartspeed == 0) { /* If Master/Slave config fault is asserted twice, * we assume back-to-back */ - e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp); + e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp); if (!(phy_tmp & SR_1000T_MS_CONFIG_FAULT)) return; - e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp); + e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp); if (phy_tmp & SR_1000T_MS_CONFIG_FAULT) { - e1000_read_phy_reg(&adapter->hw, - PHY_1000T_CTRL, &phy_tmp); + e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_tmp); if(phy_tmp & CR_1000T_MS_ENABLE) { phy_tmp &= ~CR_1000T_MS_ENABLE; - e1000_write_phy_reg(&adapter->hw, + e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_tmp); adapter->smartspeed++; - if(adapter->hw.mac.autoneg && - !e1000_copper_link_autoneg(&adapter->hw) && - !e1000_read_phy_reg(&adapter->hw, + if(hw->mac.autoneg && + !e1000_copper_link_autoneg(hw) && + !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_tmp)) { phy_tmp |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); - e1000_write_phy_reg(&adapter->hw, + e1000_write_phy_reg(hw, PHY_CONTROL, phy_tmp); } } @@ -2312,15 +2323,15 @@ return; } else if(adapter->smartspeed == EM_SMARTSPEED_DOWNSHIFT) { /* If still no link, perhaps using 2/3 pair cable */ - e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_tmp); + e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_tmp); phy_tmp |= CR_1000T_MS_ENABLE; - e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_tmp); - if(adapter->hw.mac.autoneg && - !e1000_copper_link_autoneg(&adapter->hw) && - !e1000_read_phy_reg(&adapter->hw, PHY_CONTROL, &phy_tmp)) { + e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_tmp); + if(hw->mac.autoneg && + !e1000_copper_link_autoneg(hw) && + !e1000_read_phy_reg(hw, PHY_CONTROL, &phy_tmp)) { phy_tmp |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); - e1000_write_phy_reg(&adapter->hw, PHY_CONTROL, phy_tmp); + e1000_write_phy_reg(hw, PHY_CONTROL, phy_tmp); } } /* Restart process after EM_SMARTSPEED_MAX iterations */ @@ -2448,8 +2459,8 @@ { device_t dev = iflib_get_dev(ctx); struct adapter *adapter = iflib_get_softc(ctx); - struct ifnet *ifp = iflib_get_ifp(ctx); struct e1000_hw *hw = &adapter->hw; + struct ifnet *ifp = iflib_get_ifp(ctx); u16 rx_buffer_size; u32 pba; @@ -2493,7 +2504,7 @@ case e1000_ich9lan: case e1000_ich10lan: /* Boost Receive side for jumbo frames */ - if (hw.mac.max_frame_size > 4096) + if (hw->mac.max_frame_size > 4096) pba = E1000_PBA_14K; else pba = E1000_PBA_10K; @@ -2525,7 +2536,7 @@ pba = E1000_PBA_34K; break; default: - if (hw.mac.max_frame_size > 8192) + if (hw->mac.max_frame_size > 8192) pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */ else pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */ @@ -2537,11 +2548,11 @@ pba = E1000_READ_REG(hw, E1000_PBA); tx_space = pba >> 16; pba &= 0xffff; - min_tx = (hw.mac.max_frame_size + + min_tx = (hw->mac.max_frame_size + sizeof(struct e1000_tx_desc) - ETHERNET_FCS_SIZE) * 2; min_tx = roundup2(min_tx, 1024); min_tx >>= 10; - min_rx = hw.mac.max_frame_size; + min_rx = hw->mac.max_frame_size; min_rx = roundup2(min_rx, 1024); min_rx >>= 10; if (tx_space < min_tx && @@ -2578,7 +2589,7 @@ */ rx_buffer_size = (pba & 0xffff) << 10; hw->fc.high_water = rx_buffer_size - - roundup2(hw.mac.max_frame_size, 1024); + roundup2(hw->mac.max_frame_size, 1024); hw->fc.low_water = hw->fc.high_water - 1500; if (adapter->fc) /* locally set flow control value? */ @@ -2653,7 +2664,7 @@ /* Issue a global reset */ e1000_reset_hw(hw); - if (hw.mac.type >= igb_mac_min) { + if (hw->mac.type >= igb_mac_min) { E1000_WRITE_REG(hw, E1000_WUC, 0); } else { E1000_WRITE_REG(hw, E1000_WUFC, 0); @@ -2669,7 +2680,7 @@ device_printf(dev, "Hardware Initialization Failed\n"); return; } - if (hw.mac.type >= igb_mac_min) + if (hw->mac.type >= igb_mac_min) igb_init_dmac(adapter, pba); E1000_WRITE_REG(hw, E1000_VET, ETHERTYPE_VLAN); @@ -2686,9 +2697,9 @@ static void em_initialize_rss_mapping(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; uint8_t rss_key[4 * RSSKEYLEN]; uint32_t reta = 0; - struct e1000_hw *hw = &adapter->hw; int i; /* @@ -2734,7 +2745,7 @@ u32 rss_key[10], mrqc, shift = 0; /* XXX? */ - if (hw.mac.type == e1000_82575) + if (hw->mac.type == e1000_82575) shift = 6; /* @@ -2829,6 +2840,7 @@ { struct ifnet *ifp = iflib_get_ifp(ctx); struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if_softc_ctx_t scctx = adapter->shared; INIT_DEBUGOUT("em_setup_interface: begin"); @@ -2843,11 +2855,11 @@ * Specify the media types supported by this adapter and register * callbacks to update media and link information */ - if (hw.phy.media_type == e1000_media_type_fiber || - hw.phy.media_type == e1000_media_type_internal_serdes) { + if (hw->phy.media_type == e1000_media_type_fiber || + hw->phy.media_type == e1000_media_type_internal_serdes) { u_char fiber_type = IFM_1000_SX; /* default type */ - if (hw.mac.type == e1000_82545) + if (hw->mac.type == e1000_82545) fiber_type = IFM_1000_LX; ifmedia_add(adapter->media, IFM_ETHER | fiber_type | IFM_FDX, 0, NULL); ifmedia_add(adapter->media, IFM_ETHER | fiber_type, 0, NULL); @@ -2856,7 +2868,7 @@ ifmedia_add(adapter->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL); ifmedia_add(adapter->media, IFM_ETHER | IFM_100_TX, 0, NULL); ifmedia_add(adapter->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL); - if (hw.phy.type != e1000_phy_ife) { + if (hw->phy.type != e1000_phy_ife) { ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_T, 0, NULL); } @@ -2998,10 +3010,10 @@ em_initialize_transmit_unit(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if_softc_ctx_t scctx = adapter->shared; struct em_tx_queue *que; struct tx_ring *txr; - struct e1000_hw *hw = &adapter->hw; u32 tctl, txdctl = 0, tarc, tipg = 0; INIT_DEBUGOUT("em_initialize_transmit_unit: begin"); @@ -3046,7 +3058,7 @@ } /* Set the default values for the Tx Inter Packet Gap timer */ - switch (hw.mac.type) { + switch (hw->mac.type) { case e1000_80003es2lan: tipg = DEFAULT_82543_TIPG_IPGR1; tipg |= DEFAULT_80003ES2LAN_TIPG_IPGR2 << @@ -3058,8 +3070,8 @@ tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT; break; default: - if (hw.phy.media_type == e1000_media_type_fiber || - hw.phy.media_type == e1000_media_type_internal_serdes) + if (hw->phy.media_type == e1000_media_type_fiber || + hw->phy.media_type == e1000_media_type_internal_serdes) tipg = DEFAULT_82543_TIPG_IPGT_FIBER; else tipg = DEFAULT_82543_TIPG_IPGT_COPPER; @@ -3070,15 +3082,15 @@ E1000_WRITE_REG(hw, E1000_TIPG, tipg); E1000_WRITE_REG(hw, E1000_TIDV, adapter->tx_int_delay.value); - if(hw.mac.type >= e1000_82540) + if(hw->mac.type >= e1000_82540) E1000_WRITE_REG(hw, E1000_TADV, adapter->tx_abs_int_delay.value); - if (hw.mac.type == e1000_82571 || hw.mac.type == e1000_82572) { + if (hw->mac.type == e1000_82571 || hw->mac.type == e1000_82572) { tarc = E1000_READ_REG(hw, E1000_TARC(0)); tarc |= TARC_SPEED_MODE_BIT; E1000_WRITE_REG(hw, E1000_TARC(0), tarc); - } else if (hw.mac.type == e1000_80003es2lan) { + } else if (hw->mac.type == e1000_80003es2lan) { /* errata: program both queues to unweighted RR */ tarc = E1000_READ_REG(hw, E1000_TARC(0)); tarc |= 1; @@ -3086,7 +3098,7 @@ tarc = E1000_READ_REG(hw, E1000_TARC(1)); tarc |= 1; E1000_WRITE_REG(hw, E1000_TARC(1), tarc); - } else if (hw.mac.type == e1000_82574) { + } else if (hw->mac.type == e1000_82574) { tarc = E1000_READ_REG(hw, E1000_TARC(0)); tarc |= TARC_ERRATA_BIT; if ( adapter->tx_num_queues > 1) { @@ -3106,7 +3118,7 @@ tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT)); - if (hw.mac.type >= e1000_82571) + if (hw->mac.type >= e1000_82571) tctl |= E1000_TCTL_MULR; /* This write will effectively turn on the transmit unit. */ @@ -3136,9 +3148,9 @@ em_initialize_receive_unit(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if_softc_ctx_t scctx = adapter->shared; struct ifnet *ifp = iflib_get_ifp(ctx); - struct e1000_hw *hw = &adapter->hw; struct em_rx_queue *que; int i; u32 rctl, rxcsum, rfctl; @@ -3173,7 +3185,7 @@ if (!em_disable_crc_stripping) rctl |= E1000_RCTL_SECRC; - if (hw.mac.type >= e1000_82540) { + if (hw->mac.type >= e1000_82540) { E1000_WRITE_REG(hw, E1000_RADV, adapter->rx_abs_int_delay.value); @@ -3203,9 +3215,9 @@ rxcsum = E1000_READ_REG(hw, E1000_RXCSUM); if (if_getcapenable(ifp) & IFCAP_RXCSUM && - hw.mac.type >= e1000_82543) { + hw->mac.type >= e1000_82543) { if (adapter->tx_num_queues > 1) { - if (hw.mac.type >= igb_mac_min) { + if (hw->mac.type >= igb_mac_min) { rxcsum |= E1000_RXCSUM_PCSD; if (hw->mac.type != e1000_82575) rxcsum |= E1000_RXCSUM_CRCOFL; @@ -3214,11 +3226,11 @@ E1000_RXCSUM_IPOFL | E1000_RXCSUM_PCSD; } else { - if (hw.mac.type >= igb_mac_min) + if (hw->mac.type >= igb_mac_min) rxcsum |= E1000_RXCSUM_IPPCSE; else rxcsum |= E1000_RXCSUM_TUOFL | E1000_RXCSUM_IPOFL; - if (hw.mac.type > e1000_82575) + if (hw->mac.type > e1000_82575) rxcsum |= E1000_RXCSUM_CRCOFL; } } else @@ -3227,7 +3239,7 @@ E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum); if (adapter->rx_num_queues > 1) { - if (hw.mac.type >= igb_mac_min) + if (hw->mac.type >= igb_mac_min) igb_initialize_rss_mapping(adapter); else em_initialize_rss_mapping(adapter); @@ -3267,11 +3279,11 @@ * Only write to RXDCTL(1) if there is a need for different * settings. */ - if ((hw.mac.type == e1000_ich9lan || hw.mac.type == e1000_pch2lan || - hw.mac.type == e1000_ich10lan) && (if_getmtu(ifp) > ETHERMTU)) { + if ((hw->mac.type == e1000_ich9lan || hw->mac.type == e1000_pch2lan || + hw->mac.type == e1000_ich10lan) && (if_getmtu(ifp) > ETHERMTU)) { u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(0)); E1000_WRITE_REG(hw, E1000_RXDCTL(0), rxdctl | 3); - } else if (hw.mac.type == e1000_82574) { + } else if (hw->mac.type == e1000_82574) { for (int i = 0; i < adapter->rx_num_queues; i++) { u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i)); rxdctl |= 0x20; /* PTHRESH */ @@ -3280,7 +3292,7 @@ rxdctl |= 1 << 24; /* Switch to granularity */ E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl); } - } else if (hw.mac.type >= igb_mac_min) { + } else if (hw->mac.type >= igb_mac_min) { u32 psize, srrctl = 0; if (if_getmtu(ifp) > ETHERMTU) { @@ -3342,7 +3354,7 @@ rxdctl |= IGB_RX_WTHRESH << 16; E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl); } - } else if (hw.mac.type >= e1000_pch2lan) { + } else if (hw->mac.type >= e1000_pch2lan) { if (if_getmtu(ifp) > ETHERMTU) e1000_lv_jumbo_workaround_ich8lan(hw, TRUE); else @@ -3352,7 +3364,7 @@ /* Make sure VLAN Filters are off */ rctl &= ~E1000_RCTL_VFE; - if (hw.mac.type < igb_mac_min) { + if (hw->mac.type < igb_mac_min) { if (adapter->rx_mbuf_sz == MCLBYTES) rctl |= E1000_RCTL_SZ_2048; else if (adapter->rx_mbuf_sz == MJUMPAGESIZE) @@ -3494,11 +3506,13 @@ static void em_init_manageability(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; + /* A shared code workaround */ #define E1000_82542_MANC2H E1000_MANC2H if (adapter->has_manage) { - int manc2h = E1000_READ_REG(&adapter->hw, E1000_MANC2H); - int manc = E1000_READ_REG(&adapter->hw, E1000_MANC); + int manc2h = E1000_READ_REG(hw, E1000_MANC2H); + int manc = E1000_READ_REG(hw, E1000_MANC); /* disable hardware interception of ARP */ manc &= ~(E1000_MANC_ARP_EN); @@ -3509,8 +3523,8 @@ #define E1000_MNG2HOST_PORT_664 (1 << 6) manc2h |= E1000_MNG2HOST_PORT_623; manc2h |= E1000_MNG2HOST_PORT_664; - E1000_WRITE_REG(&adapter->hw, E1000_MANC2H, manc2h); - E1000_WRITE_REG(&adapter->hw, E1000_MANC, manc); + E1000_WRITE_REG(hw, E1000_MANC2H, manc2h); + E1000_WRITE_REG(hw, E1000_MANC, manc); } } @@ -3541,20 +3555,21 @@ static void em_get_hw_control(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; u32 ctrl_ext, swsm; if (adapter->vf_ifp) return; - if (adapter->hw.mac.type == e1000_82573) { - swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM); - E1000_WRITE_REG(&adapter->hw, E1000_SWSM, + if (hw->mac.type == e1000_82573) { + swsm = E1000_READ_REG(hw, E1000_SWSM); + E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD); return; } /* else */ - ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); - E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, + ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); + E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); } @@ -3567,20 +3582,21 @@ static void em_release_hw_control(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; u32 ctrl_ext, swsm; if (!adapter->has_manage) return; - if (adapter->hw.mac.type == e1000_82573) { - swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM); - E1000_WRITE_REG(&adapter->hw, E1000_SWSM, + if (hw->mac.type == e1000_82573) { + swsm = E1000_READ_REG(hw, E1000_SWSM); + E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD); return; } /* else */ - ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); - E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, + ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); + E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); return; } @@ -3606,29 +3622,29 @@ em_get_wakeup(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; device_t dev = iflib_get_dev(ctx); u16 eeprom_data = 0, device_id, apme_mask; - adapter->has_manage = e1000_enable_mng_pass_thru(&adapter->hw); + adapter->has_manage = e1000_enable_mng_pass_thru(hw); apme_mask = EM_EEPROM_APME; - switch (adapter->hw.mac.type) { + switch (hw->mac.type) { case e1000_82542: case e1000_82543: break; case e1000_82544: - e1000_read_nvm(&adapter->hw, - NVM_INIT_CONTROL2_REG, 1, &eeprom_data); + e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &eeprom_data); apme_mask = EM_82544_APME; break; case e1000_82546: case e1000_82546_rev_3: - if (adapter->hw.bus.func == 1) { - e1000_read_nvm(&adapter->hw, + if (hw->bus.func == 1) { + e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); break; } else - e1000_read_nvm(&adapter->hw, + e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); break; case e1000_82573: @@ -3638,12 +3654,12 @@ case e1000_82571: case e1000_82572: case e1000_80003es2lan: - if (adapter->hw.bus.func == 1) { - e1000_read_nvm(&adapter->hw, + if (hw->bus.func == 1) { + e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); break; } else - e1000_read_nvm(&adapter->hw, + e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); break; case e1000_ich8lan: @@ -3664,11 +3680,10 @@ case e1000_vfadapt_i350: apme_mask = E1000_WUC_APME; adapter->has_amt = TRUE; - eeprom_data = E1000_READ_REG(&adapter->hw, E1000_WUC); + eeprom_data = E1000_READ_REG(hw, E1000_WUC); break; default: - e1000_read_nvm(&adapter->hw, - NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); + e1000_read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); break; } if (eeprom_data & apme_mask) @@ -3687,7 +3702,7 @@ case E1000_DEV_ID_82546GB_FIBER: /* Wake events only supported on port A for dual fiber * regardless of eeprom setting */ - if (E1000_READ_REG(&adapter->hw, E1000_STATUS) & + if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1) adapter->wol = 0; break; @@ -3702,7 +3717,7 @@ case E1000_DEV_ID_82571EB_FIBER: /* Wake events only supported on port A for dual fiber * regardless of eeprom setting */ - if (E1000_READ_REG(&adapter->hw, E1000_STATUS) & + if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FUNC_1) adapter->wol = 0; break; @@ -3728,6 +3743,7 @@ em_enable_wakeup(if_ctx_t ctx) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; device_t dev = iflib_get_dev(ctx); if_t ifp = iflib_get_ifp(ctx); int error = 0; @@ -3750,45 +3766,45 @@ if ((if_getcapenable(ifp) & IFCAP_WOL_MCAST) == 0) adapter->wol &= ~E1000_WUFC_MC; else { - rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); + rctl = E1000_READ_REG(hw, E1000_RCTL); rctl |= E1000_RCTL_MPE; - E1000_WRITE_REG(&adapter->hw, E1000_RCTL, rctl); + E1000_WRITE_REG(hw, E1000_RCTL, rctl); } if (!(adapter->wol & (E1000_WUFC_EX | E1000_WUFC_MAG | E1000_WUFC_MC))) goto pme; /* Advertise the wakeup capability */ - ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL); + ctrl = E1000_READ_REG(hw, E1000_CTRL); ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3); - E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl); + E1000_WRITE_REG(hw, E1000_CTRL, ctrl); /* Keep the laser running on Fiber adapters */ - if (adapter->hw.phy.media_type == e1000_media_type_fiber || - adapter->hw.phy.media_type == e1000_media_type_internal_serdes) { - ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); + if (hw->phy.media_type == e1000_media_type_fiber || + hw->phy.media_type == e1000_media_type_internal_serdes) { + ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; - E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext); + E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); } - if ((adapter->hw.mac.type == e1000_ich8lan) || - (adapter->hw.mac.type == e1000_pchlan) || - (adapter->hw.mac.type == e1000_ich9lan) || - (adapter->hw.mac.type == e1000_ich10lan)) - e1000_suspend_workarounds_ich8lan(&adapter->hw); + if ((hw->mac.type == e1000_ich8lan) || + (hw->mac.type == e1000_pchlan) || + (hw->mac.type == e1000_ich9lan) || + (hw->mac.type == e1000_ich10lan)) + e1000_suspend_workarounds_ich8lan(hw); - if ( adapter->hw.mac.type >= e1000_pchlan) { + if (hw->mac.type >= e1000_pchlan) { error = em_enable_phy_wakeup(adapter); if (error) goto pme; } else { /* Enable wakeup by the MAC */ - E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN); - E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol); + E1000_WRITE_REG(hw, E1000_WUC, E1000_WUC_PME_EN); + E1000_WRITE_REG(hw, E1000_WUFC, adapter->wol); } - if (adapter->hw.phy.type == e1000_phy_igp_3) - e1000_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); + if (hw->phy.type == e1000_phy_igp_3) + e1000_igp3_phy_powerdown_workaround_ich8lan(hw); pme: status = pci_read_config(dev, pmc + PCIR_POWER_STATUS, 2); @@ -3815,7 +3831,7 @@ e1000_copy_rx_addrs_to_phy_ich8lan(hw); /* copy MAC MTA to PHY MTA */ - for (int i = 0; i < hw.mac.mta_reg_count; i++) { + for (int i = 0; i < hw->mac.mta_reg_count; i++) { mreg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); e1000_write_phy_reg(hw, BM_MTA(i), (u16)(mreg & 0xFFFF)); e1000_write_phy_reg(hw, BM_MTA(i) + 1, @@ -3878,13 +3894,14 @@ em_if_led_func(if_ctx_t ctx, int onoff) { struct adapter *adapter = iflib_get_softc(ctx); + struct e1000_hw *hw = &adapter->hw; if (onoff) { - e1000_setup_led(&adapter->hw); - e1000_led_on(&adapter->hw); + e1000_setup_led(hw); + e1000_led_on(hw); } else { - e1000_led_off(&adapter->hw); - e1000_cleanup_led(&adapter->hw); + e1000_led_off(hw); + e1000_cleanup_led(hw); } } @@ -3927,98 +3944,99 @@ static void em_update_stats_counters(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; u64 prev_xoffrxc = adapter->stats.xoffrxc; - if(adapter->hw.phy.media_type == e1000_media_type_copper || - (E1000_READ_REG(&adapter->hw, E1000_STATUS) & E1000_STATUS_LU)) { - adapter->stats.symerrs += E1000_READ_REG(&adapter->hw, E1000_SYMERRS); - adapter->stats.sec += E1000_READ_REG(&adapter->hw, E1000_SEC); + if(hw->phy.media_type == e1000_media_type_copper || + (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) { + adapter->stats.symerrs += E1000_READ_REG(hw, E1000_SYMERRS); + adapter->stats.sec += E1000_READ_REG(hw, E1000_SEC); } - adapter->stats.crcerrs += E1000_READ_REG(&adapter->hw, E1000_CRCERRS); - adapter->stats.mpc += E1000_READ_REG(&adapter->hw, E1000_MPC); - adapter->stats.scc += E1000_READ_REG(&adapter->hw, E1000_SCC); - adapter->stats.ecol += E1000_READ_REG(&adapter->hw, E1000_ECOL); - - adapter->stats.mcc += E1000_READ_REG(&adapter->hw, E1000_MCC); - adapter->stats.latecol += E1000_READ_REG(&adapter->hw, E1000_LATECOL); - adapter->stats.colc += E1000_READ_REG(&adapter->hw, E1000_COLC); - adapter->stats.dc += E1000_READ_REG(&adapter->hw, E1000_DC); - adapter->stats.rlec += E1000_READ_REG(&adapter->hw, E1000_RLEC); - adapter->stats.xonrxc += E1000_READ_REG(&adapter->hw, E1000_XONRXC); - adapter->stats.xontxc += E1000_READ_REG(&adapter->hw, E1000_XONTXC); - adapter->stats.xoffrxc += E1000_READ_REG(&adapter->hw, E1000_XOFFRXC); + adapter->stats.crcerrs += E1000_READ_REG(hw, E1000_CRCERRS); + adapter->stats.mpc += E1000_READ_REG(hw, E1000_MPC); + adapter->stats.scc += E1000_READ_REG(hw, E1000_SCC); + adapter->stats.ecol += E1000_READ_REG(hw, E1000_ECOL); + + adapter->stats.mcc += E1000_READ_REG(hw, E1000_MCC); + adapter->stats.latecol += E1000_READ_REG(hw, E1000_LATECOL); + adapter->stats.colc += E1000_READ_REG(hw, E1000_COLC); + adapter->stats.dc += E1000_READ_REG(hw, E1000_DC); + adapter->stats.rlec += E1000_READ_REG(hw, E1000_RLEC); + adapter->stats.xonrxc += E1000_READ_REG(hw, E1000_XONRXC); + adapter->stats.xontxc += E1000_READ_REG(hw, E1000_XONTXC); + adapter->stats.xoffrxc += E1000_READ_REG(hw, E1000_XOFFRXC); /* ** For watchdog management we need to know if we have been ** paused during the last interval, so capture that here. */ if (adapter->stats.xoffrxc != prev_xoffrxc) adapter->shared->isc_pause_frames = 1; - adapter->stats.xofftxc += E1000_READ_REG(&adapter->hw, E1000_XOFFTXC); - adapter->stats.fcruc += E1000_READ_REG(&adapter->hw, E1000_FCRUC); - adapter->stats.prc64 += E1000_READ_REG(&adapter->hw, E1000_PRC64); - adapter->stats.prc127 += E1000_READ_REG(&adapter->hw, E1000_PRC127); - adapter->stats.prc255 += E1000_READ_REG(&adapter->hw, E1000_PRC255); - adapter->stats.prc511 += E1000_READ_REG(&adapter->hw, E1000_PRC511); - adapter->stats.prc1023 += E1000_READ_REG(&adapter->hw, E1000_PRC1023); - adapter->stats.prc1522 += E1000_READ_REG(&adapter->hw, E1000_PRC1522); - adapter->stats.gprc += E1000_READ_REG(&adapter->hw, E1000_GPRC); - adapter->stats.bprc += E1000_READ_REG(&adapter->hw, E1000_BPRC); - adapter->stats.mprc += E1000_READ_REG(&adapter->hw, E1000_MPRC); - adapter->stats.gptc += E1000_READ_REG(&adapter->hw, E1000_GPTC); + adapter->stats.xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC); + adapter->stats.fcruc += E1000_READ_REG(hw, E1000_FCRUC); + adapter->stats.prc64 += E1000_READ_REG(hw, E1000_PRC64); + adapter->stats.prc127 += E1000_READ_REG(hw, E1000_PRC127); + adapter->stats.prc255 += E1000_READ_REG(hw, E1000_PRC255); + adapter->stats.prc511 += E1000_READ_REG(hw, E1000_PRC511); + adapter->stats.prc1023 += E1000_READ_REG(hw, E1000_PRC1023); + adapter->stats.prc1522 += E1000_READ_REG(hw, E1000_PRC1522); + adapter->stats.gprc += E1000_READ_REG(hw, E1000_GPRC); + adapter->stats.bprc += E1000_READ_REG(hw, E1000_BPRC); + adapter->stats.mprc += E1000_READ_REG(hw, E1000_MPRC); + adapter->stats.gptc += E1000_READ_REG(hw, E1000_GPTC); /* For the 64-bit byte counters the low dword must be read first. */ /* Both registers clear on the read of the high dword */ - adapter->stats.gorc += E1000_READ_REG(&adapter->hw, E1000_GORCL) + - ((u64)E1000_READ_REG(&adapter->hw, E1000_GORCH) << 32); - adapter->stats.gotc += E1000_READ_REG(&adapter->hw, E1000_GOTCL) + - ((u64)E1000_READ_REG(&adapter->hw, E1000_GOTCH) << 32); - - adapter->stats.rnbc += E1000_READ_REG(&adapter->hw, E1000_RNBC); - adapter->stats.ruc += E1000_READ_REG(&adapter->hw, E1000_RUC); - adapter->stats.rfc += E1000_READ_REG(&adapter->hw, E1000_RFC); - adapter->stats.roc += E1000_READ_REG(&adapter->hw, E1000_ROC); - adapter->stats.rjc += E1000_READ_REG(&adapter->hw, E1000_RJC); - - adapter->stats.tor += E1000_READ_REG(&adapter->hw, E1000_TORH); - adapter->stats.tot += E1000_READ_REG(&adapter->hw, E1000_TOTH); - - adapter->stats.tpr += E1000_READ_REG(&adapter->hw, E1000_TPR); - adapter->stats.tpt += E1000_READ_REG(&adapter->hw, E1000_TPT); - adapter->stats.ptc64 += E1000_READ_REG(&adapter->hw, E1000_PTC64); - adapter->stats.ptc127 += E1000_READ_REG(&adapter->hw, E1000_PTC127); - adapter->stats.ptc255 += E1000_READ_REG(&adapter->hw, E1000_PTC255); - adapter->stats.ptc511 += E1000_READ_REG(&adapter->hw, E1000_PTC511); - adapter->stats.ptc1023 += E1000_READ_REG(&adapter->hw, E1000_PTC1023); - adapter->stats.ptc1522 += E1000_READ_REG(&adapter->hw, E1000_PTC1522); - adapter->stats.mptc += E1000_READ_REG(&adapter->hw, E1000_MPTC); - adapter->stats.bptc += E1000_READ_REG(&adapter->hw, E1000_BPTC); + adapter->stats.gorc += E1000_READ_REG(hw, E1000_GORCL) + + ((u64)E1000_READ_REG(hw, E1000_GORCH) << 32); + adapter->stats.gotc += E1000_READ_REG(hw, E1000_GOTCL) + + ((u64)E1000_READ_REG(hw, E1000_GOTCH) << 32); + + adapter->stats.rnbc += E1000_READ_REG(hw, E1000_RNBC); + adapter->stats.ruc += E1000_READ_REG(hw, E1000_RUC); + adapter->stats.rfc += E1000_READ_REG(hw, E1000_RFC); + adapter->stats.roc += E1000_READ_REG(hw, E1000_ROC); + adapter->stats.rjc += E1000_READ_REG(hw, E1000_RJC); + + adapter->stats.tor += E1000_READ_REG(hw, E1000_TORH); + adapter->stats.tot += E1000_READ_REG(hw, E1000_TOTH); + + adapter->stats.tpr += E1000_READ_REG(hw, E1000_TPR); + adapter->stats.tpt += E1000_READ_REG(hw, E1000_TPT); + adapter->stats.ptc64 += E1000_READ_REG(hw, E1000_PTC64); + adapter->stats.ptc127 += E1000_READ_REG(hw, E1000_PTC127); + adapter->stats.ptc255 += E1000_READ_REG(hw, E1000_PTC255); + adapter->stats.ptc511 += E1000_READ_REG(hw, E1000_PTC511); + adapter->stats.ptc1023 += E1000_READ_REG(hw, E1000_PTC1023); + adapter->stats.ptc1522 += E1000_READ_REG(hw, E1000_PTC1522); + adapter->stats.mptc += E1000_READ_REG(hw, E1000_MPTC); + adapter->stats.bptc += E1000_READ_REG(hw, E1000_BPTC); /* Interrupt Counts */ - adapter->stats.iac += E1000_READ_REG(&adapter->hw, E1000_IAC); - adapter->stats.icrxptc += E1000_READ_REG(&adapter->hw, E1000_ICRXPTC); - adapter->stats.icrxatc += E1000_READ_REG(&adapter->hw, E1000_ICRXATC); - adapter->stats.ictxptc += E1000_READ_REG(&adapter->hw, E1000_ICTXPTC); - adapter->stats.ictxatc += E1000_READ_REG(&adapter->hw, E1000_ICTXATC); - adapter->stats.ictxqec += E1000_READ_REG(&adapter->hw, E1000_ICTXQEC); - adapter->stats.ictxqmtc += E1000_READ_REG(&adapter->hw, E1000_ICTXQMTC); - adapter->stats.icrxdmtc += E1000_READ_REG(&adapter->hw, E1000_ICRXDMTC); - adapter->stats.icrxoc += E1000_READ_REG(&adapter->hw, E1000_ICRXOC); - - if (adapter->hw.mac.type >= e1000_82543) { + adapter->stats.iac += E1000_READ_REG(hw, E1000_IAC); + adapter->stats.icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC); + adapter->stats.icrxatc += E1000_READ_REG(hw, E1000_ICRXATC); + adapter->stats.ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC); + adapter->stats.ictxatc += E1000_READ_REG(hw, E1000_ICTXATC); + adapter->stats.ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC); + adapter->stats.ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC); + adapter->stats.icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC); + adapter->stats.icrxoc += E1000_READ_REG(hw, E1000_ICRXOC); + + if (hw->mac.type >= e1000_82543) { adapter->stats.algnerrc += - E1000_READ_REG(&adapter->hw, E1000_ALGNERRC); + E1000_READ_REG(hw, E1000_ALGNERRC); adapter->stats.rxerrc += - E1000_READ_REG(&adapter->hw, E1000_RXERRC); + E1000_READ_REG(hw, E1000_RXERRC); adapter->stats.tncrs += - E1000_READ_REG(&adapter->hw, E1000_TNCRS); + E1000_READ_REG(hw, E1000_TNCRS); adapter->stats.cexterr += - E1000_READ_REG(&adapter->hw, E1000_CEXTERR); + E1000_READ_REG(hw, E1000_CEXTERR); adapter->stats.tsctc += - E1000_READ_REG(&adapter->hw, E1000_TSCTC); + E1000_READ_REG(hw, E1000_TSCTC); adapter->stats.tsctfc += - E1000_READ_REG(&adapter->hw, E1000_TSCTFC); + E1000_READ_REG(hw, E1000_TSCTFC); } } @@ -4477,6 +4495,7 @@ int error; static int input = 3; /* default is full */ struct adapter *adapter = (struct adapter *) arg1; + struct e1000_hw *hw = &adapter->hw; error = sysctl_handle_int(oidp, &input, 0, req); @@ -4491,7 +4510,7 @@ case e1000_fc_tx_pause: case e1000_fc_full: case e1000_fc_none: - adapter->hw.fc.requested_mode = input; + hw->fc.requested_mode = input; adapter->fc = input; break; default: @@ -4499,8 +4518,8 @@ return (error); } - adapter->hw.fc.current_mode = adapter->hw.fc.requested_mode; - e1000_force_mac_fc(&adapter->hw); + hw->fc.current_mode = hw->fc.requested_mode; + e1000_force_mac_fc(hw); return (error); } @@ -4576,6 +4595,7 @@ static void em_print_debug_info(struct adapter *adapter) { + struct e1000_hw *hw = &adapter->hw; device_t dev = iflib_get_dev(adapter->ctx); struct ifnet *ifp = iflib_get_ifp(adapter->ctx); struct tx_ring *txr = &adapter->tx_queues->txr; @@ -4594,15 +4614,15 @@ for (int i = 0; i < adapter->tx_num_queues; i++, txr++) { device_printf(dev, "TX Queue %d ------\n", i); device_printf(dev, "hw tdh = %d, hw tdt = %d\n", - E1000_READ_REG(&adapter->hw, E1000_TDH(i)), - E1000_READ_REG(&adapter->hw, E1000_TDT(i))); + E1000_READ_REG(hw, E1000_TDH(i)), + E1000_READ_REG(hw, E1000_TDT(i))); } for (int j=0; j < adapter->rx_num_queues; j++, rxr++) { device_printf(dev, "RX Queue %d ------\n", j); device_printf(dev, "hw rdh = %d, hw rdt = %d\n", - E1000_READ_REG(&adapter->hw, E1000_RDH(j)), - E1000_READ_REG(&adapter->hw, E1000_RDT(j))); + E1000_READ_REG(hw, E1000_RDH(j)), + E1000_READ_REG(hw, E1000_RDT(j))); } }