From 260ac341af2054f3d3cbea3cc49947a6bf8db2b5 Mon Sep 17 00:00:00 2001 From: pdeuskar Date: Thu, 3 Aug 2006 19:05:04 +0000 Subject: Revert back changes to made in rev 1.109 of if_em.c which were unnecessary. This makes it easier for us to get the changes into -current and to -stable quickly. --- sys/dev/em/if_em.c | 1948 ++++++++++++++++++++++++++-------------------------- sys/dev/em/if_em.h | 8 +- 2 files changed, 978 insertions(+), 978 deletions(-) diff --git a/sys/dev/em/if_em.c b/sys/dev/em/if_em.c index c23f932..0ac9d55 100644 --- a/sys/dev/em/if_em.c +++ b/sys/dev/em/if_em.c @@ -197,64 +197,64 @@ static void em_start_locked(struct ifnet *ifp); static int em_ioctl(struct ifnet *, u_long, caddr_t); static void em_watchdog(struct ifnet *); static void em_init(void *); -static void em_init_locked(struct em_softc *); +static void em_init_locked(struct adapter *); static void em_stop(void *); static void em_media_status(struct ifnet *, struct ifmediareq *); static int em_media_change(struct ifnet *); -static void em_identify_hardware(struct em_softc *); -static int em_allocate_pci_resources(struct em_softc *); -static int em_allocate_intr(struct em_softc *); -static void em_free_intr(struct em_softc *); -static void em_free_pci_resources(struct em_softc *); +static void em_identify_hardware(struct adapter *); +static int em_allocate_pci_resources(struct adapter *); +static int em_allocate_intr(struct adapter *); +static void em_free_intr(struct adapter *); +static void em_free_pci_resources(struct adapter *); static void em_local_timer(void *); -static int em_hardware_init(struct em_softc *); -static void em_setup_interface(device_t, struct em_softc *); -static int em_setup_transmit_structures(struct em_softc *); -static void em_initialize_transmit_unit(struct em_softc *); -static int em_setup_receive_structures(struct em_softc *); -static void em_initialize_receive_unit(struct em_softc *); -static void em_enable_intr(struct em_softc *); -static void em_disable_intr(struct em_softc *); -static void em_free_transmit_structures(struct em_softc *); -static void em_free_receive_structures(struct em_softc *); -static void em_update_stats_counters(struct em_softc *); -static void em_txeof(struct em_softc *); -static int em_allocate_receive_structures(struct em_softc *); -static int em_allocate_transmit_structures(struct em_softc *); -static int em_rxeof(struct em_softc *, int); +static int em_hardware_init(struct adapter *); +static void em_setup_interface(device_t, struct adapter *); +static int em_setup_transmit_structures(struct adapter *); +static void em_initialize_transmit_unit(struct adapter *); +static int em_setup_receive_structures(struct adapter *); +static void em_initialize_receive_unit(struct adapter *); +static void em_enable_intr(struct adapter *); +static void em_disable_intr(struct adapter *); +static void em_free_transmit_structures(struct adapter *); +static void em_free_receive_structures(struct adapter *); +static void em_update_stats_counters(struct adapter *); +static void em_txeof(struct adapter *); +static int em_allocate_receive_structures(struct adapter *); +static int em_allocate_transmit_structures(struct adapter *); +static int em_rxeof(struct adapter *, int); #ifndef __NO_STRICT_ALIGNMENT -static int em_fixup_rx(struct em_softc *); +static int em_fixup_rx(struct adapter *); #endif -static void em_receive_checksum(struct em_softc *, struct em_rx_desc *, +static void em_receive_checksum(struct adapter *, struct em_rx_desc *, struct mbuf *); -static void em_transmit_checksum_setup(struct em_softc *, struct mbuf *, +static void em_transmit_checksum_setup(struct adapter *, struct mbuf *, uint32_t *, uint32_t *); -static void em_set_promisc(struct em_softc *); -static void em_disable_promisc(struct em_softc *); -static void em_set_multi(struct em_softc *); -static void em_print_hw_stats(struct em_softc *); -static void em_update_link_status(struct em_softc *); -static int em_get_buf(int i, struct em_softc *, struct mbuf *); -static void em_enable_vlans(struct em_softc *); -static void em_disable_vlans(struct em_softc *); -static int em_encap(struct em_softc *, struct mbuf **); -static void em_smartspeed(struct em_softc *); -static int em_82547_fifo_workaround(struct em_softc *, int); -static void em_82547_update_fifo_head(struct em_softc *, int); -static int em_82547_tx_fifo_reset(struct em_softc *); +static void em_set_promisc(struct adapter *); +static void em_disable_promisc(struct adapter *); +static void em_set_multi(struct adapter *); +static void em_print_hw_stats(struct adapter *); +static void em_update_link_status(struct adapter *); +static int em_get_buf(int i, struct adapter *, struct mbuf *); +static void em_enable_vlans(struct adapter *); +static void em_disable_vlans(struct adapter *); +static int em_encap(struct adapter *, struct mbuf **); +static void em_smartspeed(struct adapter *); +static int em_82547_fifo_workaround(struct adapter *, int); +static void em_82547_update_fifo_head(struct adapter *, int); +static int em_82547_tx_fifo_reset(struct adapter *); static void em_82547_move_tail(void *arg); -static void em_82547_move_tail_locked(struct em_softc *); -static int em_dma_malloc(struct em_softc *, bus_size_t, +static void em_82547_move_tail_locked(struct adapter *); +static int em_dma_malloc(struct adapter *, bus_size_t, struct em_dma_alloc *, int); -static void em_dma_free(struct em_softc *, struct em_dma_alloc *); -static void em_print_debug_info(struct em_softc *); +static void em_dma_free(struct adapter *, struct em_dma_alloc *); +static void em_print_debug_info(struct adapter *); static int em_is_valid_ether_addr(uint8_t *); static int em_sysctl_stats(SYSCTL_HANDLER_ARGS); static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS); static uint32_t em_fill_descriptors (bus_addr_t address, uint32_t length, PDESC_ARRAY desc_array); static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS); -static void em_add_int_delay_sysctl(struct em_softc *, const char *, +static void em_add_int_delay_sysctl(struct adapter *, const char *, const char *, struct em_int_delay_info *, int, int); /* @@ -266,7 +266,7 @@ static poll_handler_t em_poll; static void em_intr(void *); #else static void em_intr_fast(void *); -static void em_add_int_process_limit(struct em_softc *, const char *, +static void em_add_int_process_limit(struct adapter *, const char *, const char *, int *, int); static void em_handle_rxtx(void *context, int pending); static void em_handle_link(void *context, int pending); @@ -288,7 +288,7 @@ static device_method_t em_methods[] = { }; static driver_t em_driver = { - "em", em_methods, sizeof(struct em_softc), + "em", em_methods, sizeof(struct adapter), }; static devclass_t em_devclass; @@ -387,57 +387,57 @@ em_probe(device_t dev) static int em_attach(device_t dev) { - struct em_softc *sc; + struct adapter *adapter; int tsize, rsize; int error = 0; INIT_DEBUGOUT("em_attach: begin"); - sc = device_get_softc(dev); - sc->dev = sc->osdep.dev = dev; - EM_LOCK_INIT(sc, device_get_nameunit(dev)); + adapter = device_get_softc(dev); + adapter->dev = adapter->osdep.dev = dev; + EM_LOCK_INIT(adapter, device_get_nameunit(dev)); /* SYSCTL stuff */ SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), - OID_AUTO, "debug_info", CTLTYPE_INT|CTLFLAG_RW, sc, 0, + OID_AUTO, "debug_info", CTLTYPE_INT|CTLFLAG_RW, adapter, 0, em_sysctl_debug_info, "I", "Debug Information"); SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), - OID_AUTO, "stats", CTLTYPE_INT|CTLFLAG_RW, sc, 0, + OID_AUTO, "stats", CTLTYPE_INT|CTLFLAG_RW, adapter, 0, em_sysctl_stats, "I", "Statistics"); - callout_init(&sc->timer, CALLOUT_MPSAFE); - callout_init(&sc->tx_fifo_timer, CALLOUT_MPSAFE); + callout_init(&adapter->timer, CALLOUT_MPSAFE); + callout_init(&adapter->tx_fifo_timer, CALLOUT_MPSAFE); /* Determine hardware revision */ - em_identify_hardware(sc); + em_identify_hardware(adapter); /* Set up some sysctls for the tunable interrupt delays */ - em_add_int_delay_sysctl(sc, "rx_int_delay", - "receive interrupt delay in usecs", &sc->rx_int_delay, - E1000_REG_OFFSET(&sc->hw, RDTR), em_rx_int_delay_dflt); - em_add_int_delay_sysctl(sc, "tx_int_delay", - "transmit interrupt delay in usecs", &sc->tx_int_delay, - E1000_REG_OFFSET(&sc->hw, TIDV), em_tx_int_delay_dflt); - if (sc->hw.mac_type >= em_82540) { - em_add_int_delay_sysctl(sc, "rx_abs_int_delay", + em_add_int_delay_sysctl(adapter, "rx_int_delay", + "receive interrupt delay in usecs", &adapter->rx_int_delay, + E1000_REG_OFFSET(&adapter->hw, RDTR), em_rx_int_delay_dflt); + em_add_int_delay_sysctl(adapter, "tx_int_delay", + "transmit interrupt delay in usecs", &adapter->tx_int_delay, + E1000_REG_OFFSET(&adapter->hw, TIDV), em_tx_int_delay_dflt); + if (adapter->hw.mac_type >= em_82540) { + em_add_int_delay_sysctl(adapter, "rx_abs_int_delay", "receive interrupt delay limit in usecs", - &sc->rx_abs_int_delay, - E1000_REG_OFFSET(&sc->hw, RADV), + &adapter->rx_abs_int_delay, + E1000_REG_OFFSET(&adapter->hw, RADV), em_rx_abs_int_delay_dflt); - em_add_int_delay_sysctl(sc, "tx_abs_int_delay", + em_add_int_delay_sysctl(adapter, "tx_abs_int_delay", "transmit interrupt delay limit in usecs", - &sc->tx_abs_int_delay, - E1000_REG_OFFSET(&sc->hw, TADV), + &adapter->tx_abs_int_delay, + E1000_REG_OFFSET(&adapter->hw, TADV), em_tx_abs_int_delay_dflt); } #ifndef DEVICE_POLLING /* Sysctls for limiting the amount of work done in the taskqueue */ - em_add_int_process_limit(sc, "rx_processing_limit", - "max number of rx packets to process", &sc->rx_process_limit, + em_add_int_process_limit(adapter, "rx_processing_limit", + "max number of rx packets to process", &adapter->rx_process_limit, em_rx_process_limit); #endif @@ -447,139 +447,139 @@ em_attach(device_t dev) * of EM_DBA_ALIGN. */ if (((em_txd * sizeof(struct em_tx_desc)) % EM_DBA_ALIGN) != 0 || - (sc->hw.mac_type >= em_82544 && em_txd > EM_MAX_TXD) || - (sc->hw.mac_type < em_82544 && em_txd > EM_MAX_TXD_82543) || + (adapter->hw.mac_type >= em_82544 && em_txd > EM_MAX_TXD) || + (adapter->hw.mac_type < em_82544 && em_txd > EM_MAX_TXD_82543) || (em_txd < EM_MIN_TXD)) { device_printf(dev, "Using %d TX descriptors instead of %d!\n", EM_DEFAULT_TXD, em_txd); - sc->num_tx_desc = EM_DEFAULT_TXD; + adapter->num_tx_desc = EM_DEFAULT_TXD; } else - sc->num_tx_desc = em_txd; + adapter->num_tx_desc = em_txd; if (((em_rxd * sizeof(struct em_rx_desc)) % EM_DBA_ALIGN) != 0 || - (sc->hw.mac_type >= em_82544 && em_rxd > EM_MAX_RXD) || - (sc->hw.mac_type < em_82544 && em_rxd > EM_MAX_RXD_82543) || + (adapter->hw.mac_type >= em_82544 && em_rxd > EM_MAX_RXD) || + (adapter->hw.mac_type < em_82544 && em_rxd > EM_MAX_RXD_82543) || (em_rxd < EM_MIN_RXD)) { device_printf(dev, "Using %d RX descriptors instead of %d!\n", EM_DEFAULT_RXD, em_rxd); - sc->num_rx_desc = EM_DEFAULT_RXD; + adapter->num_rx_desc = EM_DEFAULT_RXD; } else - sc->num_rx_desc = em_rxd; + adapter->num_rx_desc = em_rxd; - sc->hw.autoneg = DO_AUTO_NEG; - sc->hw.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT; - sc->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT; - sc->hw.tbi_compatibility_en = TRUE; - sc->rx_buffer_len = EM_RXBUFFER_2048; + adapter->hw.autoneg = DO_AUTO_NEG; + adapter->hw.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT; + adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT; + adapter->hw.tbi_compatibility_en = TRUE; + adapter->rx_buffer_len = EM_RXBUFFER_2048; - sc->hw.phy_init_script = 1; - sc->hw.phy_reset_disable = FALSE; + adapter->hw.phy_init_script = 1; + adapter->hw.phy_reset_disable = FALSE; #ifndef EM_MASTER_SLAVE - sc->hw.master_slave = em_ms_hw_default; + adapter->hw.master_slave = em_ms_hw_default; #else - sc->hw.master_slave = EM_MASTER_SLAVE; + adapter->hw.master_slave = EM_MASTER_SLAVE; #endif /* * Set the max frame size assuming standard ethernet * sized frames. */ - sc->hw.max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN; + adapter->hw.max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN; - sc->hw.min_frame_size = MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN; + adapter->hw.min_frame_size = MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN; /* * This controls when hardware reports transmit completion * status. */ - sc->hw.report_tx_early = 1; - if (em_allocate_pci_resources(sc)) { + adapter->hw.report_tx_early = 1; + if (em_allocate_pci_resources(adapter)) { device_printf(dev, "Allocation of PCI resources failed\n"); error = ENXIO; goto err_pci; } /* Initialize eeprom parameters */ - em_init_eeprom_params(&sc->hw); + em_init_eeprom_params(&adapter->hw); - tsize = roundup2(sc->num_tx_desc * sizeof(struct em_tx_desc), + tsize = roundup2(adapter->num_tx_desc * sizeof(struct em_tx_desc), EM_DBA_ALIGN); /* Allocate Transmit Descriptor ring */ - if (em_dma_malloc(sc, tsize, &sc->txdma, BUS_DMA_NOWAIT)) { + if (em_dma_malloc(adapter, tsize, &adapter->txdma, BUS_DMA_NOWAIT)) { device_printf(dev, "Unable to allocate tx_desc memory\n"); error = ENOMEM; goto err_tx_desc; } - sc->tx_desc_base = (struct em_tx_desc *)sc->txdma.dma_vaddr; + adapter->tx_desc_base = (struct em_tx_desc *)adapter->txdma.dma_vaddr; - rsize = roundup2(sc->num_rx_desc * sizeof(struct em_rx_desc), + rsize = roundup2(adapter->num_rx_desc * sizeof(struct em_rx_desc), EM_DBA_ALIGN); /* Allocate Receive Descriptor ring */ - if (em_dma_malloc(sc, rsize, &sc->rxdma, BUS_DMA_NOWAIT)) { + if (em_dma_malloc(adapter, rsize, &adapter->rxdma, BUS_DMA_NOWAIT)) { device_printf(dev, "Unable to allocate rx_desc memory\n"); error = ENOMEM; goto err_rx_desc; } - sc->rx_desc_base = (struct em_rx_desc *)sc->rxdma.dma_vaddr; + adapter->rx_desc_base = (struct em_rx_desc *)adapter->rxdma.dma_vaddr; /* Initialize the hardware */ - if (em_hardware_init(sc)) { + if (em_hardware_init(adapter)) { device_printf(dev, "Unable to initialize the hardware\n"); error = EIO; goto err_hw_init; } /* Copy the permanent MAC address out of the EEPROM */ - if (em_read_mac_addr(&sc->hw) < 0) { + if (em_read_mac_addr(&adapter->hw) < 0) { device_printf(dev, "EEPROM read error while reading MAC" " address\n"); error = EIO; goto err_hw_init; } - if (!em_is_valid_ether_addr(sc->hw.mac_addr)) { + if (!em_is_valid_ether_addr(adapter->hw.mac_addr)) { device_printf(dev, "Invalid MAC address\n"); error = EIO; goto err_hw_init; } /* Setup OS specific network interface */ - em_setup_interface(dev, sc); + em_setup_interface(dev, adapter); - em_allocate_intr(sc); + em_allocate_intr(adapter); /* Initialize statistics */ - em_clear_hw_cntrs(&sc->hw); - em_update_stats_counters(sc); - sc->hw.get_link_status = 1; - em_update_link_status(sc); + em_clear_hw_cntrs(&adapter->hw); + em_update_stats_counters(adapter); + adapter->hw.get_link_status = 1; + em_update_link_status(adapter); /* Indicate SOL/IDER usage */ - if (em_check_phy_reset_block(&sc->hw)) + if (em_check_phy_reset_block(&adapter->hw)) device_printf(dev, "PHY reset is blocked due to SOL/IDER session.\n"); /* Identify 82544 on PCIX */ - em_get_bus_info(&sc->hw); - if(sc->hw.bus_type == em_bus_type_pcix && sc->hw.mac_type == em_82544) - sc->pcix_82544 = TRUE; + em_get_bus_info(&adapter->hw); + if(adapter->hw.bus_type == em_bus_type_pcix && adapter->hw.mac_type == em_82544) + adapter->pcix_82544 = TRUE; else - sc->pcix_82544 = FALSE; + adapter->pcix_82544 = FALSE; INIT_DEBUGOUT("em_attach: end"); return (0); err_hw_init: - em_dma_free(sc, &sc->rxdma); + em_dma_free(adapter, &adapter->rxdma); err_rx_desc: - em_dma_free(sc, &sc->txdma); + em_dma_free(adapter, &adapter->txdma); err_tx_desc: err_pci: - em_free_intr(sc); - em_free_pci_resources(sc); - EM_LOCK_DESTROY(sc); + em_free_intr(adapter); + em_free_pci_resources(adapter); + EM_LOCK_DESTROY(adapter); return (error); } @@ -597,8 +597,8 @@ err_pci: static int em_detach(device_t dev) { - struct em_softc *sc = device_get_softc(dev); - struct ifnet *ifp = sc->ifp; + struct adapter *adapter = device_get_softc(dev); + struct ifnet *ifp = adapter->ifp; INIT_DEBUGOUT("em_detach: begin"); @@ -607,31 +607,31 @@ em_detach(device_t dev) ether_poll_deregister(ifp); #endif - em_free_intr(sc); - EM_LOCK(sc); - sc->in_detach = 1; - em_stop(sc); - em_phy_hw_reset(&sc->hw); - EM_UNLOCK(sc); - ether_ifdetach(sc->ifp); + em_free_intr(adapter); + EM_LOCK(adapter); + adapter->in_detach = 1; + em_stop(adapter); + em_phy_hw_reset(&adapter->hw); + EM_UNLOCK(adapter); + ether_ifdetach(adapter->ifp); - em_free_pci_resources(sc); + em_free_pci_resources(adapter); bus_generic_detach(dev); if_free(ifp); /* Free Transmit Descriptor ring */ - if (sc->tx_desc_base) { - em_dma_free(sc, &sc->txdma); - sc->tx_desc_base = NULL; + if (adapter->tx_desc_base) { + em_dma_free(adapter, &adapter->txdma); + adapter->tx_desc_base = NULL; } /* Free Receive Descriptor ring */ - if (sc->rx_desc_base) { - em_dma_free(sc, &sc->rxdma); - sc->rx_desc_base = NULL; + if (adapter->rx_desc_base) { + em_dma_free(adapter, &adapter->rxdma); + adapter->rx_desc_base = NULL; } - EM_LOCK_DESTROY(sc); + EM_LOCK_DESTROY(adapter); return (0); } @@ -645,10 +645,10 @@ em_detach(device_t dev) static int em_shutdown(device_t dev) { - struct em_softc *sc = device_get_softc(dev); - EM_LOCK(sc); - em_stop(sc); - EM_UNLOCK(sc); + struct adapter *adapter = device_get_softc(dev); + EM_LOCK(adapter); + em_stop(adapter); + EM_UNLOCK(adapter); return (0); } @@ -658,11 +658,11 @@ em_shutdown(device_t dev) static int em_suspend(device_t dev) { - struct em_softc *sc = device_get_softc(dev); + struct adapter *adapter = device_get_softc(dev); - EM_LOCK(sc); - em_stop(sc); - EM_UNLOCK(sc); + EM_LOCK(adapter); + em_stop(adapter); + EM_UNLOCK(adapter); return bus_generic_suspend(dev); } @@ -670,15 +670,15 @@ em_suspend(device_t dev) static int em_resume(device_t dev) { - struct em_softc *sc = device_get_softc(dev); - struct ifnet *ifp = sc->ifp; + struct adapter *adapter = device_get_softc(dev); + struct ifnet *ifp = adapter->ifp; - EM_LOCK(sc); - em_init_locked(sc); + EM_LOCK(adapter); + em_init_locked(adapter); if ((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING)) em_start_locked(ifp); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); return bus_generic_resume(dev); } @@ -697,15 +697,15 @@ em_resume(device_t dev) static void em_start_locked(struct ifnet *ifp) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; struct mbuf *m_head; - EM_LOCK_ASSERT(sc); + EM_LOCK_ASSERT(adapter); if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) return; - if (!sc->link_active) + if (!adapter->link_active) return; while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) { @@ -717,7 +717,7 @@ em_start_locked(struct ifnet *ifp) * em_encap() can modify our pointer, and or make it NULL on * failure. In that event, we can't requeue. */ - if (em_encap(sc, &m_head)) { + if (em_encap(adapter, &m_head)) { if (m_head == NULL) break; ifp->if_drv_flags |= IFF_DRV_OACTIVE; @@ -736,12 +736,12 @@ em_start_locked(struct ifnet *ifp) static void em_start(struct ifnet *ifp) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; - EM_LOCK(sc); + EM_LOCK(adapter); if (ifp->if_drv_flags & IFF_DRV_RUNNING) em_start_locked(ifp); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } /********************************************************************* @@ -756,12 +756,12 @@ em_start(struct ifnet *ifp) static int em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; struct ifreq *ifr = (struct ifreq *)data; struct ifaddr *ifa = (struct ifaddr *)data; int error = 0; - if (sc->in_detach) + if (adapter->in_detach) return (error); switch (command) { @@ -777,9 +777,9 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) */ ifp->if_flags |= IFF_UP; if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { - EM_LOCK(sc); - em_init_locked(sc); - EM_UNLOCK(sc); + EM_LOCK(adapter); + em_init_locked(adapter); + EM_UNLOCK(adapter); } arp_ifinit(ifp, ifa); } else @@ -792,14 +792,14 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)"); - EM_LOCK(sc); - switch (sc->hw.mac_type) { + EM_LOCK(adapter); + switch (adapter->hw.mac_type) { case em_82573: /* * 82573 only supports jumbo frames * if ASPM is disabled. */ - em_read_eeprom(&sc->hw, EEPROM_INIT_3GIO_3, 1, + em_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, &eeprom_data); if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) { max_frame_size = ETHER_MAX_LEN; @@ -820,59 +820,59 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) } if (ifr->ifr_mtu > max_frame_size - ETHER_HDR_LEN - ETHER_CRC_LEN) { - EM_UNLOCK(sc); + EM_UNLOCK(adapter); error = EINVAL; break; } ifp->if_mtu = ifr->ifr_mtu; - sc->hw.max_frame_size = + adapter->hw.max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; - em_init_locked(sc); - EM_UNLOCK(sc); + em_init_locked(adapter); + EM_UNLOCK(adapter); break; } case SIOCSIFFLAGS: IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)"); - EM_LOCK(sc); + EM_LOCK(adapter); if (ifp->if_flags & IFF_UP) { if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) { - if ((ifp->if_flags ^ sc->if_flags) & + if ((ifp->if_flags ^ adapter->if_flags) & IFF_PROMISC) { - em_disable_promisc(sc); - em_set_promisc(sc); + em_disable_promisc(adapter); + em_set_promisc(adapter); } } else - em_init_locked(sc); + em_init_locked(adapter); } else { if (ifp->if_drv_flags & IFF_DRV_RUNNING) { - em_stop(sc); + em_stop(adapter); } } - sc->if_flags = ifp->if_flags; - EM_UNLOCK(sc); + adapter->if_flags = ifp->if_flags; + EM_UNLOCK(adapter); break; case SIOCADDMULTI: case SIOCDELMULTI: IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI"); if (ifp->if_drv_flags & IFF_DRV_RUNNING) { - EM_LOCK(sc); - em_disable_intr(sc); - em_set_multi(sc); - if (sc->hw.mac_type == em_82542_rev2_0) { - em_initialize_receive_unit(sc); + EM_LOCK(adapter); + em_disable_intr(adapter); + em_set_multi(adapter); + if (adapter->hw.mac_type == em_82542_rev2_0) { + em_initialize_receive_unit(adapter); } #ifdef DEVICE_POLLING if (!(ifp->if_capenable & IFCAP_POLLING)) #endif - em_enable_intr(sc); - EM_UNLOCK(sc); + em_enable_intr(adapter); + EM_UNLOCK(adapter); } break; case SIOCSIFMEDIA: case SIOCGIFMEDIA: IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)"); - error = ifmedia_ioctl(ifp, ifr, &sc->media, command); + error = ifmedia_ioctl(ifp, ifr, &adapter->media, command); break; case SIOCSIFCAP: { @@ -887,17 +887,17 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) error = ether_poll_register(em_poll, ifp); if (error) return (error); - EM_LOCK(sc); - em_disable_intr(sc); + EM_LOCK(adapter); + em_disable_intr(adapter); ifp->if_capenable |= IFCAP_POLLING; - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } else { error = ether_poll_deregister(ifp); /* Enable interrupt even in error case */ - EM_LOCK(sc); - em_enable_intr(sc); + EM_LOCK(adapter); + em_enable_intr(adapter); ifp->if_capenable &= ~IFCAP_POLLING; - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } } #endif @@ -910,7 +910,7 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) reinit = 1; } if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING)) - em_init(sc); + em_init(adapter); VLAN_CAPABILITIES(ifp); break; } @@ -932,26 +932,26 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data) static void em_watchdog(struct ifnet *ifp) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; - EM_LOCK(sc); + EM_LOCK(adapter); /* If we are in this routine because of pause frames, then * don't reset the hardware. */ - if (E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_TXOFF) { + if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_TXOFF) { ifp->if_timer = EM_TX_TIMEOUT; - EM_UNLOCK(sc); + EM_UNLOCK(adapter); return; } - if (em_check_for_link(&sc->hw) == 0) - device_printf(sc->dev, "watchdog timeout -- resetting\n"); + if (em_check_for_link(&adapter->hw) == 0) + device_printf(adapter->dev, "watchdog timeout -- resetting\n"); ifp->if_drv_flags &= ~IFF_DRV_RUNNING; - sc->watchdog_events++; + adapter->watchdog_events++; - em_init_locked(sc); - EM_UNLOCK(sc); + em_init_locked(adapter); + EM_UNLOCK(adapter); } /********************************************************************* @@ -966,17 +966,17 @@ em_watchdog(struct ifnet *ifp) **********************************************************************/ static void -em_init_locked(struct em_softc *sc) +em_init_locked(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; - device_t dev = sc->dev; + struct ifnet *ifp = adapter->ifp; + device_t dev = adapter->dev; uint32_t pba; INIT_DEBUGOUT("em_init: begin"); - EM_LOCK_ASSERT(sc); + EM_LOCK_ASSERT(adapter); - em_stop(sc); + em_stop(adapter); /* * Packet Buffer Allocation (PBA) @@ -989,16 +989,16 @@ em_init_locked(struct em_softc *sc) * Default allocation: PBA=30K for Rx, leaving 10K for Tx. * Note: default does not leave enough room for Jumbo Frame >10k. */ - switch (sc->hw.mac_type) { + switch (adapter->hw.mac_type) { case em_82547: case em_82547_rev_2: /* 82547: Total Packet Buffer is 40K */ - if (sc->hw.max_frame_size > EM_RXBUFFER_8192) + if (adapter->hw.max_frame_size > EM_RXBUFFER_8192) pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */ else pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */ - sc->tx_fifo_head = 0; - sc->tx_head_addr = pba << EM_TX_HEAD_ADDR_SHIFT; - sc->tx_fifo_size = (E1000_PBA_40K - pba) << EM_PBA_BYTES_SHIFT; + adapter->tx_fifo_head = 0; + adapter->tx_head_addr = pba << EM_TX_HEAD_ADDR_SHIFT; + adapter->tx_fifo_size = (E1000_PBA_40K - pba) << EM_PBA_BYTES_SHIFT; break; case em_80003es2lan: /* 80003es2lan: Total Packet Buffer is 48K */ case em_82571: /* 82571: Total Packet Buffer is 48K */ @@ -1014,85 +1014,85 @@ em_init_locked(struct em_softc *sc) break; default: /* Devices before 82547 had a Packet Buffer of 64K. */ - if(sc->hw.max_frame_size > EM_RXBUFFER_8192) + if(adapter->hw.max_frame_size > EM_RXBUFFER_8192) pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */ else pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */ } INIT_DEBUGOUT1("em_init: pba=%dK",pba); - E1000_WRITE_REG(&sc->hw, PBA, pba); + E1000_WRITE_REG(&adapter->hw, PBA, pba); /* Get the latest mac address, User can use a LAA */ - bcopy(IF_LLADDR(sc->ifp), sc->hw.mac_addr, ETHER_ADDR_LEN); + bcopy(IF_LLADDR(adapter->ifp), adapter->hw.mac_addr, ETHER_ADDR_LEN); /* Initialize the hardware */ - if (em_hardware_init(sc)) { + if (em_hardware_init(adapter)) { device_printf(dev, "Unable to initialize the hardware\n"); return; } - em_update_link_status(sc); + em_update_link_status(adapter); if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) - em_enable_vlans(sc); + em_enable_vlans(adapter); /* Prepare transmit descriptors and buffers */ - if (em_setup_transmit_structures(sc)) { + if (em_setup_transmit_structures(adapter)) { device_printf(dev, "Could not setup transmit structures\n"); - em_stop(sc); + em_stop(adapter); return; } - em_initialize_transmit_unit(sc); + em_initialize_transmit_unit(adapter); /* Setup Multicast table */ - em_set_multi(sc); + em_set_multi(adapter); /* Prepare receive descriptors and buffers */ - if (em_setup_receive_structures(sc)) { + if (em_setup_receive_structures(adapter)) { device_printf(dev, "Could not setup receive structures\n"); - em_stop(sc); + em_stop(adapter); return; } - em_initialize_receive_unit(sc); + em_initialize_receive_unit(adapter); /* Don't loose promiscuous settings */ - em_set_promisc(sc); + em_set_promisc(adapter); ifp->if_drv_flags |= IFF_DRV_RUNNING; ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; - if (sc->hw.mac_type >= em_82543) { + if (adapter->hw.mac_type >= em_82543) { if (ifp->if_capenable & IFCAP_TXCSUM) ifp->if_hwassist = EM_CHECKSUM_FEATURES; else ifp->if_hwassist = 0; } - callout_reset(&sc->timer, hz, em_local_timer, sc); - em_clear_hw_cntrs(&sc->hw); + callout_reset(&adapter->timer, hz, em_local_timer, adapter); + em_clear_hw_cntrs(&adapter->hw); #ifdef DEVICE_POLLING /* * Only enable interrupts if we are not polling, make sure * they are off otherwise. */ if (ifp->if_capenable & IFCAP_POLLING) - em_disable_intr(sc); + em_disable_intr(adapter); else #endif /* DEVICE_POLLING */ - em_enable_intr(sc); + em_enable_intr(adapter); /* Don't reset the phy next time init gets called */ - sc->hw.phy_reset_disable = TRUE; + adapter->hw.phy_reset_disable = TRUE; } static void em_init(void *arg) { - struct em_softc *sc = arg; + struct adapter *adapter = arg; - EM_LOCK(sc); - em_init_locked(sc); - EM_UNLOCK(sc); + EM_LOCK(adapter); + em_init_locked(adapter); + EM_UNLOCK(adapter); } @@ -1105,31 +1105,31 @@ em_init(void *arg) static void em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; uint32_t reg_icr; - EM_LOCK(sc); + EM_LOCK(adapter); if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { - EM_UNLOCK(sc); + EM_UNLOCK(adapter); return; } if (cmd == POLL_AND_CHECK_STATUS) { - reg_icr = E1000_READ_REG(&sc->hw, ICR); + reg_icr = E1000_READ_REG(&adapter->hw, ICR); if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { - callout_stop(&sc->timer); - sc->hw.get_link_status = 1; - em_check_for_link(&sc->hw); - em_update_link_status(sc); - callout_reset(&sc->timer, hz, em_local_timer, sc); + callout_stop(&adapter->timer); + adapter->hw.get_link_status = 1; + em_check_for_link(&adapter->hw); + em_update_link_status(adapter); + callout_reset(&adapter->timer, hz, em_local_timer, adapter); } } - em_rxeof(sc, count); - em_txeof(sc); + em_rxeof(adapter, count); + em_txeof(adapter); if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) em_start_locked(ifp); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } /********************************************************************* @@ -1140,22 +1140,22 @@ em_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) static void em_intr(void *arg) { - struct em_softc *sc = arg; + struct adapter *adapter = arg; struct ifnet *ifp; uint32_t reg_icr; - EM_LOCK(sc); + EM_LOCK(adapter); - ifp = sc->ifp; + ifp = adapter->ifp; if (ifp->if_capenable & IFCAP_POLLING) { - EM_UNLOCK(sc); + EM_UNLOCK(adapter); return; } for (;;) { - reg_icr = E1000_READ_REG(&sc->hw, ICR); - if (sc->hw.mac_type >= em_82571 && + reg_icr = E1000_READ_REG(&adapter->hw, ICR); + if (adapter->hw.mac_type >= em_82571 && (reg_icr & E1000_ICR_INT_ASSERTED) == 0) break; else if (reg_icr == 0) @@ -1171,28 +1171,28 @@ em_intr(void *arg) break; if (ifp->if_drv_flags & IFF_DRV_RUNNING) { - em_rxeof(sc, -1); - em_txeof(sc); + em_rxeof(adapter, -1); + em_txeof(adapter); } /* Link status change */ if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { - callout_stop(&sc->timer); - sc->hw.get_link_status = 1; - em_check_for_link(&sc->hw); - em_update_link_status(sc); - callout_reset(&sc->timer, hz, em_local_timer, sc); + callout_stop(&adapter->timer); + adapter->hw.get_link_status = 1; + em_check_for_link(&adapter->hw); + em_update_link_status(adapter); + callout_reset(&adapter->timer, hz, em_local_timer, adapter); } if (reg_icr & E1000_ICR_RXO) - sc->rx_overruns++; + adapter->rx_overruns++; } if (ifp->if_drv_flags & IFF_DRV_RUNNING && !IFQ_DRV_IS_EMPTY(&ifp->if_snd)) em_start_locked(ifp); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } #else /* if not DEVICE_POLLING, then fast interrupt routines only */ @@ -1200,46 +1200,46 @@ em_intr(void *arg) static void em_handle_link(void *context, int pending) { - struct em_softc *sc = context; + struct adapter *adapter = context; struct ifnet *ifp; - ifp = sc->ifp; + ifp = adapter->ifp; - EM_LOCK(sc); + EM_LOCK(adapter); - callout_stop(&sc->timer); - sc->hw.get_link_status = 1; - em_check_for_link(&sc->hw); - em_update_link_status(sc); - callout_reset(&sc->timer, hz, em_local_timer, sc); - EM_UNLOCK(sc); + callout_stop(&adapter->timer); + adapter->hw.get_link_status = 1; + em_check_for_link(&adapter->hw); + em_update_link_status(adapter); + callout_reset(&adapter->timer, hz, em_local_timer, adapter); + EM_UNLOCK(adapter); } static void em_handle_rxtx(void *context, int pending) { - struct em_softc *sc = context; + struct adapter *adapter = context; struct ifnet *ifp; NET_LOCK_GIANT(); - ifp = sc->ifp; + ifp = adapter->ifp; /* * TODO: * It should be possible to run the tx clean loop without the lock. */ if (ifp->if_drv_flags & IFF_DRV_RUNNING) { - if (em_rxeof(sc, sc->rx_process_limit) != 0) - taskqueue_enqueue(sc->tq, &sc->rxtx_task); - EM_LOCK(sc); - em_txeof(sc); + if (em_rxeof(adapter, adapter->rx_process_limit) != 0) + taskqueue_enqueue(adapter->tq, &adapter->rxtx_task); + EM_LOCK(adapter); + em_txeof(adapter); if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) em_start_locked(ifp); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } - em_enable_intr(sc); + em_enable_intr(adapter); NET_UNLOCK_GIANT(); } @@ -1251,13 +1251,13 @@ em_handle_rxtx(void *context, int pending) static void em_intr_fast(void *arg) { - struct em_softc *sc = arg; + struct adapter *adapter = arg; struct ifnet *ifp; uint32_t reg_icr; - ifp = sc->ifp; + ifp = adapter->ifp; - reg_icr = E1000_READ_REG(&sc->hw, ICR); + reg_icr = E1000_READ_REG(&adapter->hw, ICR); /* Hot eject? */ if (reg_icr == 0xffffffff) @@ -1271,7 +1271,7 @@ em_intr_fast(void *arg) * Starting with the 82571 chip, bit 31 should be used to * determine whether the interrupt belongs to us. */ - if (sc->hw.mac_type >= em_82571 && + if (adapter->hw.mac_type >= em_82571 && (reg_icr & E1000_ICR_INT_ASSERTED) == 0) return; @@ -1280,15 +1280,15 @@ em_intr_fast(void *arg) * cheap, just assume that it is needed. This also works around the * MSI message reordering errata on certain systems. */ - em_disable_intr(sc); - taskqueue_enqueue(sc->tq, &sc->rxtx_task); + em_disable_intr(adapter); + taskqueue_enqueue(adapter->tq, &adapter->rxtx_task); /* Link status change */ if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) - taskqueue_enqueue(taskqueue_fast, &sc->link_task); + taskqueue_enqueue(taskqueue_fast, &adapter->link_task); if (reg_icr & E1000_ICR_RXO) - sc->rx_overruns++; + adapter->rx_overruns++; } #endif /* ! DEVICE_POLLING */ @@ -1303,25 +1303,25 @@ em_intr_fast(void *arg) static void em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) { - struct em_softc *sc = ifp->if_softc; + struct adapter *adapter = ifp->if_softc; INIT_DEBUGOUT("em_media_status: begin"); - em_check_for_link(&sc->hw); - em_update_link_status(sc); + em_check_for_link(&adapter->hw); + em_update_link_status(adapter); ifmr->ifm_status = IFM_AVALID; ifmr->ifm_active = IFM_ETHER; - if (!sc->link_active) + if (!adapter->link_active) return; ifmr->ifm_status |= IFM_ACTIVE; - if (sc->hw.media_type == em_media_type_fiber) { + if (adapter->hw.media_type == em_media_type_fiber) { ifmr->ifm_active |= IFM_1000_SX | IFM_FDX; } else { - switch (sc->link_speed) { + switch (adapter->link_speed) { case 10: ifmr->ifm_active |= IFM_10_T; break; @@ -1332,7 +1332,7 @@ em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) ifmr->ifm_active |= IFM_1000_T; break; } - if (sc->link_duplex == FULL_DUPLEX) + if (adapter->link_duplex == FULL_DUPLEX) ifmr->ifm_active |= IFM_FDX; else ifmr->ifm_active |= IFM_HDX; @@ -1350,8 +1350,8 @@ em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) static int em_media_change(struct ifnet *ifp) { - struct em_softc *sc = ifp->if_softc; - struct ifmedia *ifm = &sc->media; + struct adapter *adapter = ifp->if_softc; + struct ifmedia *ifm = &adapter->media; INIT_DEBUGOUT("em_media_change: begin"); @@ -1360,40 +1360,40 @@ em_media_change(struct ifnet *ifp) switch (IFM_SUBTYPE(ifm->ifm_media)) { case IFM_AUTO: - sc->hw.autoneg = DO_AUTO_NEG; - sc->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT; + adapter->hw.autoneg = DO_AUTO_NEG; + adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT; break; case IFM_1000_SX: case IFM_1000_T: - sc->hw.autoneg = DO_AUTO_NEG; - sc->hw.autoneg_advertised = ADVERTISE_1000_FULL; + adapter->hw.autoneg = DO_AUTO_NEG; + adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; break; case IFM_100_TX: - sc->hw.autoneg = FALSE; - sc->hw.autoneg_advertised = 0; + adapter->hw.autoneg = FALSE; + adapter->hw.autoneg_advertised = 0; if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) - sc->hw.forced_speed_duplex = em_100_full; + adapter->hw.forced_speed_duplex = em_100_full; else - sc->hw.forced_speed_duplex = em_100_half; + adapter->hw.forced_speed_duplex = em_100_half; break; case IFM_10_T: - sc->hw.autoneg = FALSE; - sc->hw.autoneg_advertised = 0; + adapter->hw.autoneg = FALSE; + adapter->hw.autoneg_advertised = 0; if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) - sc->hw.forced_speed_duplex = em_10_full; + adapter->hw.forced_speed_duplex = em_10_full; else - sc->hw.forced_speed_duplex = em_10_half; + adapter->hw.forced_speed_duplex = em_10_half; break; default: - device_printf(sc->dev, "Unsupported media type\n"); + device_printf(adapter->dev, "Unsupported media type\n"); } /* As the speed/duplex settings my have changed we need to * reset the PHY. */ - sc->hw.phy_reset_disable = FALSE; + adapter->hw.phy_reset_disable = FALSE; - em_init(sc); + em_init(adapter); return (0); } @@ -1405,9 +1405,9 @@ em_media_change(struct ifnet *ifp) * return 0 on success, positive on failure **********************************************************************/ static int -em_encap(struct em_softc *sc, struct mbuf **m_headp) +em_encap(struct adapter *adapter, struct mbuf **m_headp) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; bus_dma_segment_t segs[EM_MAX_SCATTER]; bus_dmamap_t map; struct em_buffer *tx_buffer, *tx_buffer_last; @@ -1426,10 +1426,10 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) * Force a cleanup if number of TX descriptors * available hits the threshold. */ - if (sc->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) { - em_txeof(sc); - if (sc->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) { - sc->no_tx_desc_avail1++; + if (adapter->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) { + em_txeof(adapter); + if (adapter->num_tx_desc_avail <= EM_TX_CLEANUP_THRESHOLD) { + adapter->no_tx_desc_avail1++; return (ENOBUFS); } } @@ -1443,7 +1443,7 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) * encapsulation in the driver, since it will have come down from the * VLAN layer with a tag instead of a VLAN header. */ - if (mtag != NULL && sc->em_insert_vlan_header) { + if (mtag != NULL && adapter->em_insert_vlan_header) { struct ether_vlan_header *evl; struct ether_header eh; @@ -1476,36 +1476,36 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) /* * Map the packet for DMA. */ - tx_buffer = &sc->tx_buffer_area[sc->next_avail_tx_desc]; + tx_buffer = &adapter->tx_buffer_area[adapter->next_avail_tx_desc]; tx_buffer_last = tx_buffer; map = tx_buffer->map; - error = bus_dmamap_load_mbuf_sg(sc->txtag, map, m_head, segs, &nsegs, + error = bus_dmamap_load_mbuf_sg(adapter->txtag, map, m_head, segs, &nsegs, BUS_DMA_NOWAIT); if (error != 0) { - sc->no_tx_dma_setup++; + adapter->no_tx_dma_setup++; return (error); } KASSERT(nsegs != 0, ("em_encap: empty packet")); - if (nsegs > sc->num_tx_desc_avail) { - sc->no_tx_desc_avail2++; + if (nsegs > adapter->num_tx_desc_avail) { + adapter->no_tx_desc_avail2++; error = ENOBUFS; goto encap_fail; } if (ifp->if_hwassist > 0) - em_transmit_checksum_setup(sc, m_head, &txd_upper, &txd_lower); + em_transmit_checksum_setup(adapter, m_head, &txd_upper, &txd_lower); else txd_upper = txd_lower = 0; - i = sc->next_avail_tx_desc; - if (sc->pcix_82544) { + i = adapter->next_avail_tx_desc; + if (adapter->pcix_82544) { txd_saved = i; txd_used = 0; } for (j = 0; j < nsegs; j++) { /* If adapter is 82544 and on PCIX bus. */ - if(sc->pcix_82544) { + if(adapter->pcix_82544) { DESC_ARRAY desc_array; uint32_t array_elements, counter; @@ -1516,47 +1516,47 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) array_elements = em_fill_descriptors(segs[j].ds_addr, segs[j].ds_len, &desc_array); for (counter = 0; counter < array_elements; counter++) { - if (txd_used == sc->num_tx_desc_avail) { - sc->next_avail_tx_desc = txd_saved; - sc->no_tx_desc_avail2++; + if (txd_used == adapter->num_tx_desc_avail) { + adapter->next_avail_tx_desc = txd_saved; + adapter->no_tx_desc_avail2++; error = ENOBUFS; goto encap_fail; } - tx_buffer = &sc->tx_buffer_area[i]; - current_tx_desc = &sc->tx_desc_base[i]; + tx_buffer = &adapter->tx_buffer_area[i]; + current_tx_desc = &adapter->tx_desc_base[i]; current_tx_desc->buffer_addr = htole64( desc_array.descriptor[counter].address); current_tx_desc->lower.data = htole32( - (sc->txd_cmd | txd_lower | + (adapter->txd_cmd | txd_lower | (uint16_t)desc_array.descriptor[counter].length)); current_tx_desc->upper.data = htole32((txd_upper)); - if (++i == sc->num_tx_desc) + if (++i == adapter->num_tx_desc) i = 0; tx_buffer->m_head = NULL; txd_used++; } } else { - tx_buffer = &sc->tx_buffer_area[i]; - current_tx_desc = &sc->tx_desc_base[i]; + tx_buffer = &adapter->tx_buffer_area[i]; + current_tx_desc = &adapter->tx_desc_base[i]; current_tx_desc->buffer_addr = htole64(segs[j].ds_addr); current_tx_desc->lower.data = htole32( - sc->txd_cmd | txd_lower | segs[j].ds_len); + adapter->txd_cmd | txd_lower | segs[j].ds_len); current_tx_desc->upper.data = htole32(txd_upper); - if (++i == sc->num_tx_desc) + if (++i == adapter->num_tx_desc) i = 0; tx_buffer->m_head = NULL; } } - sc->next_avail_tx_desc = i; - if (sc->pcix_82544) - sc->num_tx_desc_avail -= txd_used; + adapter->next_avail_tx_desc = i; + if (adapter->pcix_82544) + adapter->num_tx_desc_avail -= txd_used; else - sc->num_tx_desc_avail -= nsegs; + adapter->num_tx_desc_avail -= nsegs; if (mtag != NULL) { /* Set the vlan id. */ @@ -1570,7 +1570,7 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) tx_buffer->m_head = m_head; tx_buffer_last->map = tx_buffer->map; tx_buffer->map = map; - bus_dmamap_sync(sc->txtag, map, BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(adapter->txtag, map, BUS_DMASYNC_PREWRITE); /* * Last Descriptor of Packet needs End Of Packet (EOP). @@ -1581,20 +1581,20 @@ em_encap(struct em_softc *sc, struct mbuf **m_headp) * Advance the Transmit Descriptor Tail (Tdt), this tells the E1000 * that this frame is available to transmit. */ - bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map, + bus_dmamap_sync(adapter->txdma.dma_tag, adapter->txdma.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); - if (sc->hw.mac_type == em_82547 && sc->link_duplex == HALF_DUPLEX) - em_82547_move_tail_locked(sc); + if (adapter->hw.mac_type == em_82547 && adapter->link_duplex == HALF_DUPLEX) + em_82547_move_tail_locked(adapter); else { - E1000_WRITE_REG(&sc->hw, TDT, i); - if (sc->hw.mac_type == em_82547) - em_82547_update_fifo_head(sc, m_head->m_pkthdr.len); + E1000_WRITE_REG(&adapter->hw, TDT, i); + if (adapter->hw.mac_type == em_82547) + em_82547_update_fifo_head(adapter, m_head->m_pkthdr.len); } return (0); encap_fail: - bus_dmamap_unload(sc->txtag, map); + bus_dmamap_unload(adapter->txtag, map); return (error); } @@ -1607,7 +1607,7 @@ encap_fail: * **********************************************************************/ static void -em_82547_move_tail_locked(struct em_softc *sc) +em_82547_move_tail_locked(struct adapter *adapter) { uint16_t hw_tdt; uint16_t sw_tdt; @@ -1615,27 +1615,27 @@ em_82547_move_tail_locked(struct em_softc *sc) uint16_t length = 0; boolean_t eop = 0; - EM_LOCK_ASSERT(sc); + EM_LOCK_ASSERT(adapter); - hw_tdt = E1000_READ_REG(&sc->hw, TDT); - sw_tdt = sc->next_avail_tx_desc; + hw_tdt = E1000_READ_REG(&adapter->hw, TDT); + sw_tdt = adapter->next_avail_tx_desc; while (hw_tdt != sw_tdt) { - tx_desc = &sc->tx_desc_base[hw_tdt]; + tx_desc = &adapter->tx_desc_base[hw_tdt]; length += tx_desc->lower.flags.length; eop = tx_desc->lower.data & E1000_TXD_CMD_EOP; - if(++hw_tdt == sc->num_tx_desc) + if(++hw_tdt == adapter->num_tx_desc) hw_tdt = 0; if (eop) { - if (em_82547_fifo_workaround(sc, length)) { - sc->tx_fifo_wrk_cnt++; - callout_reset(&sc->tx_fifo_timer, 1, - em_82547_move_tail, sc); + if (em_82547_fifo_workaround(adapter, length)) { + adapter->tx_fifo_wrk_cnt++; + callout_reset(&adapter->tx_fifo_timer, 1, + em_82547_move_tail, adapter); break; } - E1000_WRITE_REG(&sc->hw, TDT, hw_tdt); - em_82547_update_fifo_head(sc, length); + E1000_WRITE_REG(&adapter->hw, TDT, hw_tdt); + em_82547_update_fifo_head(adapter, length); length = 0; } } @@ -1644,25 +1644,25 @@ em_82547_move_tail_locked(struct em_softc *sc) static void em_82547_move_tail(void *arg) { - struct em_softc *sc = arg; + struct adapter *adapter = arg; - EM_LOCK(sc); - em_82547_move_tail_locked(sc); - EM_UNLOCK(sc); + EM_LOCK(adapter); + em_82547_move_tail_locked(adapter); + EM_UNLOCK(adapter); } static int -em_82547_fifo_workaround(struct em_softc *sc, int len) +em_82547_fifo_workaround(struct adapter *adapter, int len) { int fifo_space, fifo_pkt_len; fifo_pkt_len = roundup2(len + EM_FIFO_HDR, EM_FIFO_HDR); - if (sc->link_duplex == HALF_DUPLEX) { - fifo_space = sc->tx_fifo_size - sc->tx_fifo_head; + if (adapter->link_duplex == HALF_DUPLEX) { + fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; if (fifo_pkt_len >= (EM_82547_PKT_THRESH + fifo_space)) { - if (em_82547_tx_fifo_reset(sc)) + if (em_82547_tx_fifo_reset(adapter)) return (0); else return (1); @@ -1673,44 +1673,44 @@ em_82547_fifo_workaround(struct em_softc *sc, int len) } static void -em_82547_update_fifo_head(struct em_softc *sc, int len) +em_82547_update_fifo_head(struct adapter *adapter, int len) { int fifo_pkt_len = roundup2(len + EM_FIFO_HDR, EM_FIFO_HDR); /* tx_fifo_head is always 16 byte aligned */ - sc->tx_fifo_head += fifo_pkt_len; - if (sc->tx_fifo_head >= sc->tx_fifo_size) { - sc->tx_fifo_head -= sc->tx_fifo_size; + adapter->tx_fifo_head += fifo_pkt_len; + if (adapter->tx_fifo_head >= adapter->tx_fifo_size) { + adapter->tx_fifo_head -= adapter->tx_fifo_size; } } static int -em_82547_tx_fifo_reset(struct em_softc *sc) +em_82547_tx_fifo_reset(struct adapter *adapter) { uint32_t tctl; - if ((E1000_READ_REG(&sc->hw, TDT) == E1000_READ_REG(&sc->hw, TDH)) && - (E1000_READ_REG(&sc->hw, TDFT) == E1000_READ_REG(&sc->hw, TDFH)) && - (E1000_READ_REG(&sc->hw, TDFTS) == E1000_READ_REG(&sc->hw, TDFHS))&& - (E1000_READ_REG(&sc->hw, TDFPC) == 0)) { + if ((E1000_READ_REG(&adapter->hw, TDT) == E1000_READ_REG(&adapter->hw, TDH)) && + (E1000_READ_REG(&adapter->hw, TDFT) == E1000_READ_REG(&adapter->hw, TDFH)) && + (E1000_READ_REG(&adapter->hw, TDFTS) == E1000_READ_REG(&adapter->hw, TDFHS))&& + (E1000_READ_REG(&adapter->hw, TDFPC) == 0)) { /* Disable TX unit */ - tctl = E1000_READ_REG(&sc->hw, TCTL); - E1000_WRITE_REG(&sc->hw, TCTL, tctl & ~E1000_TCTL_EN); + tctl = E1000_READ_REG(&adapter->hw, TCTL); + E1000_WRITE_REG(&adapter->hw, TCTL, tctl & ~E1000_TCTL_EN); /* Reset FIFO pointers */ - E1000_WRITE_REG(&sc->hw, TDFT, sc->tx_head_addr); - E1000_WRITE_REG(&sc->hw, TDFH, sc->tx_head_addr); - E1000_WRITE_REG(&sc->hw, TDFTS, sc->tx_head_addr); - E1000_WRITE_REG(&sc->hw, TDFHS, sc->tx_head_addr); + E1000_WRITE_REG(&adapter->hw, TDFT, adapter->tx_head_addr); + E1000_WRITE_REG(&adapter->hw, TDFH, adapter->tx_head_addr); + E1000_WRITE_REG(&adapter->hw, TDFTS, adapter->tx_head_addr); + E1000_WRITE_REG(&adapter->hw, TDFHS, adapter->tx_head_addr); /* Re-enable TX unit */ - E1000_WRITE_REG(&sc->hw, TCTL, tctl); - E1000_WRITE_FLUSH(&sc->hw); + E1000_WRITE_REG(&adapter->hw, TCTL, tctl); + E1000_WRITE_FLUSH(&adapter->hw); - sc->tx_fifo_head = 0; - sc->tx_fifo_reset_cnt++; + adapter->tx_fifo_head = 0; + adapter->tx_fifo_reset_cnt++; return (TRUE); } @@ -1720,47 +1720,47 @@ em_82547_tx_fifo_reset(struct em_softc *sc) } static void -em_set_promisc(struct em_softc *sc) +em_set_promisc(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; uint32_t reg_rctl; - reg_rctl = E1000_READ_REG(&sc->hw, RCTL); + reg_rctl = E1000_READ_REG(&adapter->hw, RCTL); if (ifp->if_flags & IFF_PROMISC) { reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); /* Disable VLAN stripping in promiscous mode * This enables bridging of vlan tagged frames to occur * and also allows vlan tags to be seen in tcpdump */ if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) - em_disable_vlans(sc); - sc->em_insert_vlan_header = 1; + em_disable_vlans(adapter); + adapter->em_insert_vlan_header = 1; } else if (ifp->if_flags & IFF_ALLMULTI) { reg_rctl |= E1000_RCTL_MPE; reg_rctl &= ~E1000_RCTL_UPE; - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); - sc->em_insert_vlan_header = 0; + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); + adapter->em_insert_vlan_header = 0; } else - sc->em_insert_vlan_header = 0; + adapter->em_insert_vlan_header = 0; } static void -em_disable_promisc(struct em_softc *sc) +em_disable_promisc(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; uint32_t reg_rctl; - reg_rctl = E1000_READ_REG(&sc->hw, RCTL); + reg_rctl = E1000_READ_REG(&adapter->hw, RCTL); reg_rctl &= (~E1000_RCTL_UPE); reg_rctl &= (~E1000_RCTL_MPE); - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) - em_enable_vlans(sc); - sc->em_insert_vlan_header = 0; + em_enable_vlans(adapter); + adapter->em_insert_vlan_header = 0; } @@ -1772,9 +1772,9 @@ em_disable_promisc(struct em_softc *sc) **********************************************************************/ static void -em_set_multi(struct em_softc *sc) +em_set_multi(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; struct ifmultiaddr *ifma; uint32_t reg_rctl = 0; uint8_t mta[MAX_NUM_MULTICAST_ADDRESSES * ETH_LENGTH_OF_ADDRESS]; @@ -1782,12 +1782,12 @@ em_set_multi(struct em_softc *sc) IOCTL_DEBUGOUT("em_set_multi: begin"); - if (sc->hw.mac_type == em_82542_rev2_0) { - reg_rctl = E1000_READ_REG(&sc->hw, RCTL); - if (sc->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) - em_pci_clear_mwi(&sc->hw); + if (adapter->hw.mac_type == em_82542_rev2_0) { + reg_rctl = E1000_READ_REG(&adapter->hw, RCTL); + if (adapter->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) + em_pci_clear_mwi(&adapter->hw); reg_rctl |= E1000_RCTL_RST; - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); msec_delay(5); } @@ -1806,19 +1806,19 @@ em_set_multi(struct em_softc *sc) IF_ADDR_UNLOCK(ifp); if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) { - reg_rctl = E1000_READ_REG(&sc->hw, RCTL); + reg_rctl = E1000_READ_REG(&adapter->hw, RCTL); reg_rctl |= E1000_RCTL_MPE; - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); } else - em_mc_addr_list_update(&sc->hw, mta, mcnt, 0, 1); + em_mc_addr_list_update(&adapter->hw, mta, mcnt, 0, 1); - if (sc->hw.mac_type == em_82542_rev2_0) { - reg_rctl = E1000_READ_REG(&sc->hw, RCTL); + if (adapter->hw.mac_type == em_82542_rev2_0) { + reg_rctl = E1000_READ_REG(&adapter->hw, RCTL); reg_rctl &= ~E1000_RCTL_RST; - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); msec_delay(5); - if (sc->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) - em_pci_set_mwi(&sc->hw); + if (adapter->hw.pci_cmd_word & CMD_MEM_WRT_INVALIDATE) + em_pci_set_mwi(&adapter->hw); } } @@ -1833,60 +1833,60 @@ em_set_multi(struct em_softc *sc) static void em_local_timer(void *arg) { - struct em_softc *sc = arg; - struct ifnet *ifp = sc->ifp; + struct adapter *adapter = arg; + struct ifnet *ifp = adapter->ifp; - EM_LOCK(sc); + EM_LOCK(adapter); - em_check_for_link(&sc->hw); - em_update_link_status(sc); - em_update_stats_counters(sc); + em_check_for_link(&adapter->hw); + em_update_link_status(adapter); + em_update_stats_counters(adapter); if (em_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) - em_print_hw_stats(sc); - em_smartspeed(sc); + em_print_hw_stats(adapter); + em_smartspeed(adapter); - callout_reset(&sc->timer, hz, em_local_timer, sc); + callout_reset(&adapter->timer, hz, em_local_timer, adapter); - EM_UNLOCK(sc); + EM_UNLOCK(adapter); } static void -em_update_link_status(struct em_softc *sc) +em_update_link_status(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; - device_t dev = sc->dev; + struct ifnet *ifp = adapter->ifp; + device_t dev = adapter->dev; - if (E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_LU) { - if (sc->link_active == 0) { - em_get_speed_and_duplex(&sc->hw, &sc->link_speed, - &sc->link_duplex); + if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) { + if (adapter->link_active == 0) { + em_get_speed_and_duplex(&adapter->hw, &adapter->link_speed, + &adapter->link_duplex); /* Check if we may set SPEED_MODE bit on PCI-E */ - if ((sc->link_speed == SPEED_1000) && - ((sc->hw.mac_type == em_82571) || - (sc->hw.mac_type == em_82572))) { + if ((adapter->link_speed == SPEED_1000) && + ((adapter->hw.mac_type == em_82571) || + (adapter->hw.mac_type == em_82572))) { int tarc0; - tarc0 = E1000_READ_REG(&sc->hw, TARC0); + tarc0 = E1000_READ_REG(&adapter->hw, TARC0); tarc0 |= SPEED_MODE_BIT; - E1000_WRITE_REG(&sc->hw, TARC0, tarc0); + E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); } if (bootverbose) device_printf(dev, "Link is up %d Mbps %s\n", - sc->link_speed, - ((sc->link_duplex == FULL_DUPLEX) ? + adapter->link_speed, + ((adapter->link_duplex == FULL_DUPLEX) ? "Full Duplex" : "Half Duplex")); - sc->link_active = 1; - sc->smartspeed = 0; - ifp->if_baudrate = sc->link_speed * 1000000; + adapter->link_active = 1; + adapter->smartspeed = 0; + ifp->if_baudrate = adapter->link_speed * 1000000; if_link_state_change(ifp, LINK_STATE_UP); } } else { - if (sc->link_active == 1) { - ifp->if_baudrate = sc->link_speed = 0; - sc->link_duplex = 0; + if (adapter->link_active == 1) { + ifp->if_baudrate = adapter->link_speed = 0; + adapter->link_duplex = 0; if (bootverbose) device_printf(dev, "Link is Down\n"); - sc->link_active = 0; + adapter->link_active = 0; if_link_state_change(ifp, LINK_STATE_DOWN); } } @@ -1902,19 +1902,19 @@ em_update_link_status(struct em_softc *sc) static void em_stop(void *arg) { - struct em_softc *sc = arg; - struct ifnet *ifp = sc->ifp; + struct adapter *adapter = arg; + struct ifnet *ifp = adapter->ifp; - EM_LOCK_ASSERT(sc); + EM_LOCK_ASSERT(adapter); INIT_DEBUGOUT("em_stop: begin"); - em_disable_intr(sc); - em_reset_hw(&sc->hw); - callout_stop(&sc->timer); - callout_stop(&sc->tx_fifo_timer); - em_free_transmit_structures(sc); - em_free_receive_structures(sc); + em_disable_intr(adapter); + em_reset_hw(&adapter->hw); + callout_stop(&adapter->timer); + callout_stop(&adapter->tx_fifo_timer); + em_free_transmit_structures(adapter); + em_free_receive_structures(adapter); /* Tell the stack that the interface is no longer active */ ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); @@ -1927,61 +1927,61 @@ em_stop(void *arg) * **********************************************************************/ static void -em_identify_hardware(struct em_softc *sc) +em_identify_hardware(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; /* Make sure our PCI config space has the necessary stuff set */ - sc->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); - if ((sc->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) == 0 && - (sc->hw.pci_cmd_word & PCIM_CMD_MEMEN)) { + adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); + if ((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) == 0 && + (adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN)) { device_printf(dev, "Memory Access and/or Bus Master bits " "were not set!\n"); - sc->hw.pci_cmd_word |= + adapter->hw.pci_cmd_word |= (PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN); - pci_write_config(dev, PCIR_COMMAND, sc->hw.pci_cmd_word, 2); + pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2); } /* Save off the information about this board */ - sc->hw.vendor_id = pci_get_vendor(dev); - sc->hw.device_id = pci_get_device(dev); - sc->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1); - sc->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2); - sc->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2); + 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 = pci_read_config(dev, PCIR_SUBVEND_0, 2); + adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2); /* Identify the MAC */ - if (em_set_mac_type(&sc->hw)) + if (em_set_mac_type(&adapter->hw)) device_printf(dev, "Unknown MAC Type\n"); - if(sc->hw.mac_type == em_82541 || sc->hw.mac_type == em_82541_rev_2 || - sc->hw.mac_type == em_82547 || sc->hw.mac_type == em_82547_rev_2) - sc->hw.phy_init_script = TRUE; + if(adapter->hw.mac_type == em_82541 || adapter->hw.mac_type == em_82541_rev_2 || + adapter->hw.mac_type == em_82547 || adapter->hw.mac_type == em_82547_rev_2) + adapter->hw.phy_init_script = TRUE; } static int -em_allocate_pci_resources(struct em_softc *sc) +em_allocate_pci_resources(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; int val, rid; rid = PCIR_BAR(0); - sc->res_memory = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + adapter->res_memory = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (sc->res_memory == NULL) { + if (adapter->res_memory == NULL) { device_printf(dev, "Unable to allocate bus resource: memory\n"); return (ENXIO); } - sc->osdep.mem_bus_space_tag = - rman_get_bustag(sc->res_memory); - sc->osdep.mem_bus_space_handle = rman_get_bushandle(sc->res_memory); - sc->hw.hw_addr = (uint8_t *)&sc->osdep.mem_bus_space_handle; + adapter->osdep.mem_bus_space_tag = + rman_get_bustag(adapter->res_memory); + adapter->osdep.mem_bus_space_handle = rman_get_bushandle(adapter->res_memory); + adapter->hw.hw_addr = (uint8_t *)&adapter->osdep.mem_bus_space_handle; - if (sc->hw.mac_type > em_82543) { + if (adapter->hw.mac_type > em_82543) { /* Figure our where our IO BAR is ? */ for (rid = PCIR_BAR(0); rid < PCIR_CIS;) { val = pci_read_config(dev, rid, 4); if (E1000_BAR_TYPE(val) == E1000_BAR_TYPE_IO) { - sc->io_rid = rid; + adapter->io_rid = rid; break; } rid += 4; @@ -1993,57 +1993,57 @@ em_allocate_pci_resources(struct em_softc *sc) device_printf(dev, "Unable to locate IO BAR\n"); return (ENXIO); } - sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT, - &sc->io_rid, RF_ACTIVE); - if (sc->res_ioport == NULL) { + adapter->res_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT, + &adapter->io_rid, RF_ACTIVE); + if (adapter->res_ioport == NULL) { device_printf(dev, "Unable to allocate bus resource: " "ioport\n"); return (ENXIO); } - sc->hw.io_base = 0; - sc->osdep.io_bus_space_tag = rman_get_bustag(sc->res_ioport); - sc->osdep.io_bus_space_handle = - rman_get_bushandle(sc->res_ioport); + adapter->hw.io_base = 0; + adapter->osdep.io_bus_space_tag = rman_get_bustag(adapter->res_ioport); + adapter->osdep.io_bus_space_handle = + rman_get_bushandle(adapter->res_ioport); } /* For ICH8 we need to find the flash memory. */ - if (sc->hw.mac_type == em_ich8lan) { + if (adapter->hw.mac_type == em_ich8lan) { rid = EM_FLASH; - sc->flash_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + adapter->flash_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - sc->osdep.flash_bus_space_tag = rman_get_bustag(sc->flash_mem); - sc->osdep.flash_bus_space_handle = - rman_get_bushandle(sc->flash_mem); + adapter->osdep.flash_bus_space_tag = rman_get_bustag(adapter->flash_mem); + adapter->osdep.flash_bus_space_handle = + rman_get_bushandle(adapter->flash_mem); } rid = 0x0; - sc->res_interrupt = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + adapter->res_interrupt = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); - if (sc->res_interrupt == NULL) { + if (adapter->res_interrupt == NULL) { device_printf(dev, "Unable to allocate bus resource: " "interrupt\n"); return (ENXIO); } - sc->hw.back = &sc->osdep; + adapter->hw.back = &adapter->osdep; return (0); } int -em_allocate_intr(struct em_softc *sc) +em_allocate_intr(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; int error; /* Manually turn off all interrupts */ - E1000_WRITE_REG(&sc->hw, IMC, 0xffffffff); + E1000_WRITE_REG(&adapter->hw, IMC, 0xffffffff); #ifdef DEVICE_POLLING - if (sc->int_handler_tag == NULL && (error = bus_setup_intr(dev, - sc->res_interrupt, INTR_TYPE_NET | INTR_MPSAFE, em_intr, sc, - &sc->int_handler_tag)) != 0) { + if (adapter->int_handler_tag == NULL && (error = bus_setup_intr(dev, + adapter->res_interrupt, INTR_TYPE_NET | INTR_MPSAFE, em_intr, adapter, + &adapter->int_handler_tag)) != 0) { device_printf(dev, "Failed to register interrupt handler"); return (error); } @@ -2052,63 +2052,63 @@ em_allocate_intr(struct em_softc *sc) * Try allocating a fast interrupt and the associated deferred * processing contexts. */ - TASK_INIT(&sc->rxtx_task, 0, em_handle_rxtx, sc); - TASK_INIT(&sc->link_task, 0, em_handle_link, sc); - sc->tq = taskqueue_create_fast("em_taskq", M_NOWAIT, - taskqueue_thread_enqueue, &sc->tq); - taskqueue_start_threads(&sc->tq, 1, PI_NET, "%s taskq", - device_get_nameunit(sc->dev)); - if ((error = bus_setup_intr(dev, sc->res_interrupt, - INTR_TYPE_NET | INTR_FAST, em_intr_fast, sc, - &sc->int_handler_tag)) != 0) { + TASK_INIT(&adapter->rxtx_task, 0, em_handle_rxtx, adapter); + TASK_INIT(&adapter->link_task, 0, em_handle_link, adapter); + adapter->tq = taskqueue_create_fast("em_taskq", M_NOWAIT, + taskqueue_thread_enqueue, &adapter->tq); + taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s taskq", + device_get_nameunit(adapter->dev)); + if ((error = bus_setup_intr(dev, adapter->res_interrupt, + INTR_TYPE_NET | INTR_FAST, em_intr_fast, adapter, + &adapter->int_handler_tag)) != 0) { device_printf(dev, "Failed to register fast interrupt " "handler: %d\n", error); - taskqueue_free(sc->tq); - sc->tq = NULL; + taskqueue_free(adapter->tq); + adapter->tq = NULL; return (error); } #endif - em_enable_intr(sc); + em_enable_intr(adapter); return (0); } static void -em_free_intr(struct em_softc *sc) +em_free_intr(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; - if (sc->res_interrupt != NULL) { - bus_teardown_intr(dev, sc->res_interrupt, sc->int_handler_tag); - sc->int_handler_tag = NULL; + if (adapter->res_interrupt != NULL) { + bus_teardown_intr(dev, adapter->res_interrupt, adapter->int_handler_tag); + adapter->int_handler_tag = NULL; } - if (sc->tq != NULL) { - taskqueue_drain(sc->tq, &sc->rxtx_task); - taskqueue_drain(taskqueue_fast, &sc->link_task); - taskqueue_free(sc->tq); - sc->tq = NULL; + if (adapter->tq != NULL) { + taskqueue_drain(adapter->tq, &adapter->rxtx_task); + taskqueue_drain(taskqueue_fast, &adapter->link_task); + taskqueue_free(adapter->tq); + adapter->tq = NULL; } } static void -em_free_pci_resources(struct em_softc *sc) +em_free_pci_resources(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; - if (sc->res_interrupt != NULL) - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->res_interrupt); + if (adapter->res_interrupt != NULL) + bus_release_resource(dev, SYS_RES_IRQ, 0, adapter->res_interrupt); - if (sc->res_memory != NULL) + if (adapter->res_memory != NULL) bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), - sc->res_memory); + adapter->res_memory); - if (sc->flash_mem != NULL) + if (adapter->flash_mem != NULL) bus_release_resource(dev, SYS_RES_MEMORY, EM_FLASH, - sc->flash_mem); + adapter->flash_mem); - if (sc->res_ioport != NULL) - bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, - sc->res_ioport); + if (adapter->res_ioport != NULL) + bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid, + adapter->res_ioport); } /********************************************************************* @@ -2120,25 +2120,25 @@ em_free_pci_resources(struct em_softc *sc) * **********************************************************************/ static int -em_hardware_init(struct em_softc *sc) +em_hardware_init(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; uint16_t rx_buffer_size; INIT_DEBUGOUT("em_hardware_init: begin"); /* Issue a global reset */ - em_reset_hw(&sc->hw); + em_reset_hw(&adapter->hw); /* When hardware is reset, fifo_head is also reset */ - sc->tx_fifo_head = 0; + adapter->tx_fifo_head = 0; /* Make sure we have a good EEPROM before we read from it */ - if (em_validate_eeprom_checksum(&sc->hw) < 0) { + if (em_validate_eeprom_checksum(&adapter->hw) < 0) { device_printf(dev, "The EEPROM Checksum Is Not Valid\n"); return (EIO); } - if (em_read_part_num(&sc->hw, &(sc->part_num)) < 0) { + if (em_read_part_num(&adapter->hw, &(adapter->part_num)) < 0) { device_printf(dev, "EEPROM read error while reading part " "number\n"); return (EIO); @@ -2146,13 +2146,13 @@ em_hardware_init(struct em_softc *sc) /* Set up smart power down as default off on newer adapters. */ if (!em_smart_pwr_down && - (sc->hw.mac_type == em_82571 || sc->hw.mac_type == em_82572)) { + (adapter->hw.mac_type == em_82571 || adapter->hw.mac_type == em_82572)) { uint16_t phy_tmp = 0; /* Speed up time to link by disabling smart power down. */ - em_read_phy_reg(&sc->hw, IGP02E1000_PHY_POWER_MGMT, &phy_tmp); + em_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, &phy_tmp); phy_tmp &= ~IGP02E1000_PM_SPD; - em_write_phy_reg(&sc->hw, IGP02E1000_PHY_POWER_MGMT, phy_tmp); + em_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, phy_tmp); } /* @@ -2169,24 +2169,24 @@ em_hardware_init(struct em_softc *sc) * by 1500. * - The pause time is fairly large at 1000 x 512ns = 512 usec. */ - rx_buffer_size = ((E1000_READ_REG(&sc->hw, PBA) & 0xffff) << 10 ); + rx_buffer_size = ((E1000_READ_REG(&adapter->hw, PBA) & 0xffff) << 10 ); - sc->hw.fc_high_water = rx_buffer_size - - roundup2(sc->hw.max_frame_size, 1024); - sc->hw.fc_low_water = sc->hw.fc_high_water - 1500; - if (sc->hw.mac_type == em_80003es2lan) - sc->hw.fc_pause_time = 0xFFFF; + adapter->hw.fc_high_water = rx_buffer_size - + roundup2(adapter->hw.max_frame_size, 1024); + adapter->hw.fc_low_water = adapter->hw.fc_high_water - 1500; + if (adapter->hw.mac_type == em_80003es2lan) + adapter->hw.fc_pause_time = 0xFFFF; else - sc->hw.fc_pause_time = 0x1000; - sc->hw.fc_send_xon = TRUE; - sc->hw.fc = em_fc_full; + adapter->hw.fc_pause_time = 0x1000; + adapter->hw.fc_send_xon = TRUE; + adapter->hw.fc = em_fc_full; - if (em_init_hw(&sc->hw) < 0) { + if (em_init_hw(&adapter->hw) < 0) { device_printf(dev, "Hardware Initialization Failed"); return (EIO); } - em_check_for_link(&sc->hw); + em_check_for_link(&adapter->hw); return (0); } @@ -2197,31 +2197,31 @@ em_hardware_init(struct em_softc *sc) * **********************************************************************/ static void -em_setup_interface(device_t dev, struct em_softc *sc) +em_setup_interface(device_t dev, struct adapter *adapter) { struct ifnet *ifp; INIT_DEBUGOUT("em_setup_interface: begin"); - ifp = sc->ifp = if_alloc(IFT_ETHER); + ifp = adapter->ifp = if_alloc(IFT_ETHER); if (ifp == NULL) panic("%s: can not if_alloc()", device_get_nameunit(dev)); if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_mtu = ETHERMTU; ifp->if_init = em_init; - ifp->if_softc = sc; + ifp->if_softc = adapter; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = em_ioctl; ifp->if_start = em_start; ifp->if_watchdog = em_watchdog; - IFQ_SET_MAXLEN(&ifp->if_snd, sc->num_tx_desc - 1); - ifp->if_snd.ifq_drv_maxlen = sc->num_tx_desc - 1; + IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 1); + ifp->if_snd.ifq_drv_maxlen = adapter->num_tx_desc - 1; IFQ_SET_READY(&ifp->if_snd); - ether_ifattach(ifp, sc->hw.mac_addr); + ether_ifattach(ifp, adapter->hw.mac_addr); ifp->if_capabilities = ifp->if_capenable = 0; - if (sc->hw.mac_type >= em_82543) { + if (adapter->hw.mac_type >= em_82543) { ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM; ifp->if_capenable |= IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM; } @@ -2241,26 +2241,26 @@ em_setup_interface(device_t dev, struct em_softc *sc) * Specify the media types supported by this adapter and register * callbacks to update media and link information */ - ifmedia_init(&sc->media, IFM_IMASK, em_media_change, em_media_status); - if (sc->hw.media_type == em_media_type_fiber) { - ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_SX | IFM_FDX, + ifmedia_init(&adapter->media, IFM_IMASK, em_media_change, em_media_status); + if (adapter->hw.media_type == em_media_type_fiber) { + ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_SX, + ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX, 0, NULL); } else { - ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T | IFM_FDX, + ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T, 0, NULL); + ifmedia_add(&adapter->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX, + ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX | IFM_FDX, + ifmedia_add(&adapter->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_T | IFM_FDX, + ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); - ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_T, 0, NULL); + ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_T, 0, NULL); } - ifmedia_add(&sc->media, IFM_ETHER | IFM_AUTO, 0, NULL); - ifmedia_set(&sc->media, IFM_ETHER | IFM_AUTO); + ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL); + ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO); } @@ -2270,57 +2270,57 @@ em_setup_interface(device_t dev, struct em_softc *sc) * **********************************************************************/ static void -em_smartspeed(struct em_softc *sc) +em_smartspeed(struct adapter *adapter) { uint16_t phy_tmp; - if (sc->link_active || (sc->hw.phy_type != em_phy_igp) || - sc->hw.autoneg == 0 || - (sc->hw.autoneg_advertised & ADVERTISE_1000_FULL) == 0) + if (adapter->link_active || (adapter->hw.phy_type != em_phy_igp) || + adapter->hw.autoneg == 0 || + (adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL) == 0) return; - if (sc->smartspeed == 0) { + if (adapter->smartspeed == 0) { /* If Master/Slave config fault is asserted twice, * we assume back-to-back */ - em_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp); + em_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp); if (!(phy_tmp & SR_1000T_MS_CONFIG_FAULT)) return; - em_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp); + em_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_tmp); if (phy_tmp & SR_1000T_MS_CONFIG_FAULT) { - em_read_phy_reg(&sc->hw, PHY_1000T_CTRL, &phy_tmp); + em_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_tmp); if(phy_tmp & CR_1000T_MS_ENABLE) { phy_tmp &= ~CR_1000T_MS_ENABLE; - em_write_phy_reg(&sc->hw, PHY_1000T_CTRL, + em_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_tmp); - sc->smartspeed++; - if(sc->hw.autoneg && - !em_phy_setup_autoneg(&sc->hw) && - !em_read_phy_reg(&sc->hw, PHY_CTRL, + adapter->smartspeed++; + if(adapter->hw.autoneg && + !em_phy_setup_autoneg(&adapter->hw) && + !em_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_tmp)) { phy_tmp |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); - em_write_phy_reg(&sc->hw, PHY_CTRL, + em_write_phy_reg(&adapter->hw, PHY_CTRL, phy_tmp); } } } return; - } else if(sc->smartspeed == EM_SMARTSPEED_DOWNSHIFT) { + } else if(adapter->smartspeed == EM_SMARTSPEED_DOWNSHIFT) { /* If still no link, perhaps using 2/3 pair cable */ - em_read_phy_reg(&sc->hw, PHY_1000T_CTRL, &phy_tmp); + em_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_tmp); phy_tmp |= CR_1000T_MS_ENABLE; - em_write_phy_reg(&sc->hw, PHY_1000T_CTRL, phy_tmp); - if(sc->hw.autoneg && - !em_phy_setup_autoneg(&sc->hw) && - !em_read_phy_reg(&sc->hw, PHY_CTRL, &phy_tmp)) { + em_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_tmp); + if(adapter->hw.autoneg && + !em_phy_setup_autoneg(&adapter->hw) && + !em_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_tmp)) { phy_tmp |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); - em_write_phy_reg(&sc->hw, PHY_CTRL, phy_tmp); + em_write_phy_reg(&adapter->hw, PHY_CTRL, phy_tmp); } } /* Restart process after EM_SMARTSPEED_MAX iterations */ - if(sc->smartspeed++ == EM_SMARTSPEED_MAX) - sc->smartspeed = 0; + if(adapter->smartspeed++ == EM_SMARTSPEED_MAX) + adapter->smartspeed = 0; } @@ -2336,7 +2336,7 @@ em_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) } static int -em_dma_malloc(struct em_softc *sc, bus_size_t size, struct em_dma_alloc *dma, +em_dma_malloc(struct adapter *adapter, bus_size_t size, struct em_dma_alloc *dma, int mapflags) { int error; @@ -2354,7 +2354,7 @@ em_dma_malloc(struct em_softc *sc, bus_size_t size, struct em_dma_alloc *dma, NULL, /* lockarg */ &dma->dma_tag); if (error) { - device_printf(sc->dev, "%s: bus_dma_tag_create failed: %d\n", + device_printf(adapter->dev, "%s: bus_dma_tag_create failed: %d\n", __func__, error); goto fail_0; } @@ -2362,7 +2362,7 @@ em_dma_malloc(struct em_softc *sc, bus_size_t size, struct em_dma_alloc *dma, error = bus_dmamem_alloc(dma->dma_tag, (void**) &dma->dma_vaddr, BUS_DMA_NOWAIT, &dma->dma_map); if (error) { - device_printf(sc->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n", + device_printf(adapter->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__, (uintmax_t)size, error); goto fail_2; } @@ -2371,7 +2371,7 @@ em_dma_malloc(struct em_softc *sc, bus_size_t size, struct em_dma_alloc *dma, error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size, em_dmamap_cb, &dma->dma_paddr, mapflags | BUS_DMA_NOWAIT); if (error || dma->dma_paddr == 0) { - device_printf(sc->dev, "%s: bus_dmamap_load failed: %d\n", + device_printf(adapter->dev, "%s: bus_dmamap_load failed: %d\n", __func__, error); goto fail_3; } @@ -2391,7 +2391,7 @@ fail_0: } static void -em_dma_free(struct em_softc *sc, struct em_dma_alloc *dma) +em_dma_free(struct adapter *adapter, struct em_dma_alloc *dma) { if (dma->dma_tag == NULL) return; @@ -2414,16 +2414,16 @@ em_dma_free(struct em_softc *sc, struct em_dma_alloc *dma) * **********************************************************************/ static int -em_allocate_transmit_structures(struct em_softc *sc) +em_allocate_transmit_structures(struct adapter *adapter) { - sc->tx_buffer_area = malloc(sizeof(struct em_buffer) * - sc->num_tx_desc, M_DEVBUF, M_NOWAIT); - if (sc->tx_buffer_area == NULL) { - device_printf(sc->dev, "Unable to allocate tx_buffer memory\n"); + adapter->tx_buffer_area = malloc(sizeof(struct em_buffer) * + adapter->num_tx_desc, M_DEVBUF, M_NOWAIT); + if (adapter->tx_buffer_area == NULL) { + device_printf(adapter->dev, "Unable to allocate tx_buffer memory\n"); return (ENOMEM); } - bzero(sc->tx_buffer_area, sizeof(struct em_buffer) * sc->num_tx_desc); + bzero(adapter->tx_buffer_area, sizeof(struct em_buffer) * adapter->num_tx_desc); return (0); } @@ -2434,9 +2434,9 @@ em_allocate_transmit_structures(struct em_softc *sc) * **********************************************************************/ static int -em_setup_transmit_structures(struct em_softc *sc) +em_setup_transmit_structures(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; struct em_buffer *tx_buffer; bus_size_t size; int error, i; @@ -2444,7 +2444,7 @@ em_setup_transmit_structures(struct em_softc *sc) /* * Setup DMA descriptor areas. */ - size = roundup2(sc->hw.max_frame_size, MCLBYTES); + size = roundup2(adapter->hw.max_frame_size, MCLBYTES); if ((error = bus_dma_tag_create(NULL, /* parent */ 1, 0, /* alignment, bounds */ BUS_SPACE_MAXADDR, /* lowaddr */ @@ -2456,18 +2456,18 @@ em_setup_transmit_structures(struct em_softc *sc) 0, /* flags */ NULL, /* lockfunc */ NULL, /* lockarg */ - &sc->txtag)) != 0) { + &adapter->txtag)) != 0) { device_printf(dev, "Unable to allocate TX DMA tag\n"); goto fail; } - if ((error = em_allocate_transmit_structures(sc)) != 0) + if ((error = em_allocate_transmit_structures(adapter)) != 0) goto fail; - bzero(sc->tx_desc_base, (sizeof(struct em_tx_desc)) * sc->num_tx_desc); - tx_buffer = sc->tx_buffer_area; - for (i = 0; i < sc->num_tx_desc; i++) { - error = bus_dmamap_create(sc->txtag, 0, &tx_buffer->map); + bzero(adapter->tx_desc_base, (sizeof(struct em_tx_desc)) * adapter->num_tx_desc); + tx_buffer = adapter->tx_buffer_area; + for (i = 0; i < adapter->num_tx_desc; i++) { + error = bus_dmamap_create(adapter->txtag, 0, &tx_buffer->map); if (error != 0) { device_printf(dev, "Unable to create TX DMA map\n"); goto fail; @@ -2475,21 +2475,21 @@ em_setup_transmit_structures(struct em_softc *sc) tx_buffer++; } - sc->next_avail_tx_desc = 0; - sc->oldest_used_tx_desc = 0; + adapter->next_avail_tx_desc = 0; + adapter->oldest_used_tx_desc = 0; /* Set number of descriptors available */ - sc->num_tx_desc_avail = sc->num_tx_desc; + adapter->num_tx_desc_avail = adapter->num_tx_desc; /* Set checksum context */ - sc->active_checksum_context = OFFLOAD_NONE; - bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map, + adapter->active_checksum_context = OFFLOAD_NONE; + bus_dmamap_sync(adapter->txdma.dma_tag, adapter->txdma.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); return (0); fail: - em_free_transmit_structures(sc); + em_free_transmit_structures(adapter); return (error); } @@ -2499,7 +2499,7 @@ fail: * **********************************************************************/ static void -em_initialize_transmit_unit(struct em_softc *sc) +em_initialize_transmit_unit(struct adapter *adapter) { uint32_t reg_tctl, reg_tarc; uint32_t reg_tipg = 0; @@ -2507,22 +2507,22 @@ em_initialize_transmit_unit(struct em_softc *sc) INIT_DEBUGOUT("em_initialize_transmit_unit: begin"); /* Setup the Base and Length of the Tx Descriptor Ring */ - bus_addr = sc->txdma.dma_paddr; - E1000_WRITE_REG(&sc->hw, TDLEN, - sc->num_tx_desc * sizeof(struct em_tx_desc)); - E1000_WRITE_REG(&sc->hw, TDBAH, (uint32_t)(bus_addr >> 32)); - E1000_WRITE_REG(&sc->hw, TDBAL, (uint32_t)bus_addr); + bus_addr = adapter->txdma.dma_paddr; + E1000_WRITE_REG(&adapter->hw, TDLEN, + adapter->num_tx_desc * sizeof(struct em_tx_desc)); + E1000_WRITE_REG(&adapter->hw, TDBAH, (uint32_t)(bus_addr >> 32)); + E1000_WRITE_REG(&adapter->hw, TDBAL, (uint32_t)bus_addr); /* Setup the HW Tx Head and Tail descriptor pointers */ - E1000_WRITE_REG(&sc->hw, TDT, 0); - E1000_WRITE_REG(&sc->hw, TDH, 0); + E1000_WRITE_REG(&adapter->hw, TDT, 0); + E1000_WRITE_REG(&adapter->hw, TDH, 0); - HW_DEBUGOUT2("Base = %x, Length = %x\n", E1000_READ_REG(&sc->hw, TDBAL), - E1000_READ_REG(&sc->hw, TDLEN)); + HW_DEBUGOUT2("Base = %x, Length = %x\n", E1000_READ_REG(&adapter->hw, TDBAL), + E1000_READ_REG(&adapter->hw, TDLEN)); /* Set the default values for the Tx Inter Packet Gap timer */ - switch (sc->hw.mac_type) { + switch (adapter->hw.mac_type) { case em_82542_rev2_0: case em_82542_rev2_1: reg_tipg = DEFAULT_82542_TIPG_IPGT; @@ -2535,7 +2535,7 @@ em_initialize_transmit_unit(struct em_softc *sc) E1000_TIPG_IPGR2_SHIFT; break; default: - if (sc->hw.media_type == em_media_type_fiber) + if (adapter->hw.media_type == em_media_type_fiber) reg_tipg = DEFAULT_82543_TIPG_IPGT_FIBER; else reg_tipg = DEFAULT_82543_TIPG_IPGT_COPPER; @@ -2543,49 +2543,49 @@ em_initialize_transmit_unit(struct em_softc *sc) reg_tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT; } - E1000_WRITE_REG(&sc->hw, TIPG, reg_tipg); - E1000_WRITE_REG(&sc->hw, TIDV, sc->tx_int_delay.value); - if(sc->hw.mac_type >= em_82540) - E1000_WRITE_REG(&sc->hw, TADV, sc->tx_abs_int_delay.value); + E1000_WRITE_REG(&adapter->hw, TIPG, reg_tipg); + E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay.value); + if(adapter->hw.mac_type >= em_82540) + E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay.value); /* Do adapter specific tweaks before we enable the transmitter. */ - if (sc->hw.mac_type == em_82571 || sc->hw.mac_type == em_82572) { - reg_tarc = E1000_READ_REG(&sc->hw, TARC0); + if (adapter->hw.mac_type == em_82571 || adapter->hw.mac_type == em_82572) { + reg_tarc = E1000_READ_REG(&adapter->hw, TARC0); reg_tarc |= (1 << 25); - E1000_WRITE_REG(&sc->hw, TARC0, reg_tarc); - reg_tarc = E1000_READ_REG(&sc->hw, TARC1); + E1000_WRITE_REG(&adapter->hw, TARC0, reg_tarc); + reg_tarc = E1000_READ_REG(&adapter->hw, TARC1); reg_tarc |= (1 << 25); reg_tarc &= ~(1 << 28); - E1000_WRITE_REG(&sc->hw, TARC1, reg_tarc); - } else if (sc->hw.mac_type == em_80003es2lan) { - reg_tarc = E1000_READ_REG(&sc->hw, TARC0); + E1000_WRITE_REG(&adapter->hw, TARC1, reg_tarc); + } else if (adapter->hw.mac_type == em_80003es2lan) { + reg_tarc = E1000_READ_REG(&adapter->hw, TARC0); reg_tarc |= 1; - if (sc->hw.media_type == em_media_type_internal_serdes) + if (adapter->hw.media_type == em_media_type_internal_serdes) reg_tarc |= (1 << 20); - E1000_WRITE_REG(&sc->hw, TARC0, reg_tarc); - reg_tarc = E1000_READ_REG(&sc->hw, TARC1); + E1000_WRITE_REG(&adapter->hw, TARC0, reg_tarc); + reg_tarc = E1000_READ_REG(&adapter->hw, TARC1); reg_tarc |= 1; - E1000_WRITE_REG(&sc->hw, TARC1, reg_tarc); + E1000_WRITE_REG(&adapter->hw, TARC1, reg_tarc); } /* Program the Transmit Control Register */ reg_tctl = E1000_TCTL_PSP | E1000_TCTL_EN | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); - if (sc->hw.mac_type >= em_82571) + if (adapter->hw.mac_type >= em_82571) reg_tctl |= E1000_TCTL_MULR; - if (sc->link_duplex == 1) { + if (adapter->link_duplex == 1) { reg_tctl |= E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT; } else { reg_tctl |= E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT; } /* This write will effectively turn on the transmit unit. */ - E1000_WRITE_REG(&sc->hw, TCTL, reg_tctl); + E1000_WRITE_REG(&adapter->hw, TCTL, reg_tctl); /* Setup Transmit Descriptor Settings for this adapter */ - sc->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_RS; + adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_RS; - if (sc->tx_int_delay.value > 0) - sc->txd_cmd |= E1000_TXD_CMD_IDE; + if (adapter->tx_int_delay.value > 0) + adapter->txd_cmd |= E1000_TXD_CMD_IDE; } /********************************************************************* @@ -2594,40 +2594,40 @@ em_initialize_transmit_unit(struct em_softc *sc) * **********************************************************************/ static void -em_free_transmit_structures(struct em_softc *sc) +em_free_transmit_structures(struct adapter *adapter) { struct em_buffer *tx_buffer; int i; INIT_DEBUGOUT("free_transmit_structures: begin"); - if (sc->tx_buffer_area != NULL) { - tx_buffer = sc->tx_buffer_area; - for (i = 0; i < sc->num_tx_desc; i++, tx_buffer++) { + if (adapter->tx_buffer_area != NULL) { + tx_buffer = adapter->tx_buffer_area; + for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) { if (tx_buffer->m_head != NULL) { - bus_dmamap_sync(sc->txtag, tx_buffer->map, + bus_dmamap_sync(adapter->txtag, tx_buffer->map, BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->txtag, + bus_dmamap_unload(adapter->txtag, tx_buffer->map); m_freem(tx_buffer->m_head); tx_buffer->m_head = NULL; } else if (tx_buffer->map != NULL) - bus_dmamap_unload(sc->txtag, + bus_dmamap_unload(adapter->txtag, tx_buffer->map); if (tx_buffer->map != NULL) { - bus_dmamap_destroy(sc->txtag, + bus_dmamap_destroy(adapter->txtag, tx_buffer->map); tx_buffer->map = NULL; } } } - if (sc->tx_buffer_area != NULL) { - free(sc->tx_buffer_area, M_DEVBUF); - sc->tx_buffer_area = NULL; + if (adapter->tx_buffer_area != NULL) { + free(adapter->tx_buffer_area, M_DEVBUF); + adapter->tx_buffer_area = NULL; } - if (sc->txtag != NULL) { - bus_dma_tag_destroy(sc->txtag); - sc->txtag = NULL; + if (adapter->txtag != NULL) { + bus_dma_tag_destroy(adapter->txtag); + adapter->txtag = NULL; } } @@ -2639,7 +2639,7 @@ em_free_transmit_structures(struct em_softc *sc) * **********************************************************************/ static void -em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp, +em_transmit_checksum_setup(struct adapter *adapter, struct mbuf *mp, uint32_t *txd_upper, uint32_t *txd_lower) { struct em_context_desc *TXD; @@ -2651,18 +2651,18 @@ em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp, if (mp->m_pkthdr.csum_flags & CSUM_TCP) { *txd_upper = E1000_TXD_POPTS_TXSM << 8; *txd_lower = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; - if (sc->active_checksum_context == OFFLOAD_TCP_IP) + if (adapter->active_checksum_context == OFFLOAD_TCP_IP) return; else - sc->active_checksum_context = OFFLOAD_TCP_IP; + adapter->active_checksum_context = OFFLOAD_TCP_IP; } else if (mp->m_pkthdr.csum_flags & CSUM_UDP) { *txd_upper = E1000_TXD_POPTS_TXSM << 8; *txd_lower = E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; - if (sc->active_checksum_context == OFFLOAD_UDP_IP) + if (adapter->active_checksum_context == OFFLOAD_UDP_IP) return; else - sc->active_checksum_context = OFFLOAD_UDP_IP; + adapter->active_checksum_context = OFFLOAD_UDP_IP; } else { *txd_upper = 0; *txd_lower = 0; @@ -2677,9 +2677,9 @@ em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp, /* If we reach this point, the checksum offload context * needs to be reset. */ - curr_txd = sc->next_avail_tx_desc; - tx_buffer = &sc->tx_buffer_area[curr_txd]; - TXD = (struct em_context_desc *) &sc->tx_desc_base[curr_txd]; + curr_txd = adapter->next_avail_tx_desc; + tx_buffer = &adapter->tx_buffer_area[curr_txd]; + TXD = (struct em_context_desc *) &adapter->tx_desc_base[curr_txd]; TXD->lower_setup.ip_fields.ipcss = ETHER_HDR_LEN; TXD->lower_setup.ip_fields.ipcso = @@ -2691,26 +2691,26 @@ em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp, ETHER_HDR_LEN + sizeof(struct ip); TXD->upper_setup.tcp_fields.tucse = htole16(0); - if (sc->active_checksum_context == OFFLOAD_TCP_IP) { + if (adapter->active_checksum_context == OFFLOAD_TCP_IP) { TXD->upper_setup.tcp_fields.tucso = ETHER_HDR_LEN + sizeof(struct ip) + offsetof(struct tcphdr, th_sum); - } else if (sc->active_checksum_context == OFFLOAD_UDP_IP) { + } else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) { TXD->upper_setup.tcp_fields.tucso = ETHER_HDR_LEN + sizeof(struct ip) + offsetof(struct udphdr, uh_sum); } TXD->tcp_seg_setup.data = htole32(0); - TXD->cmd_and_length = htole32(sc->txd_cmd | E1000_TXD_CMD_DEXT); + TXD->cmd_and_length = htole32(adapter->txd_cmd | E1000_TXD_CMD_DEXT); tx_buffer->m_head = NULL; - if (++curr_txd == sc->num_tx_desc) + if (++curr_txd == adapter->num_tx_desc) curr_txd = 0; - sc->num_tx_desc_avail--; - sc->next_avail_tx_desc = curr_txd; + adapter->num_tx_desc_avail--; + adapter->next_avail_tx_desc = curr_txd; } /********************************************************************** @@ -2721,25 +2721,25 @@ em_transmit_checksum_setup(struct em_softc *sc, struct mbuf *mp, * **********************************************************************/ static void -em_txeof(struct em_softc *sc) +em_txeof(struct adapter *adapter) { int i, num_avail; struct em_buffer *tx_buffer; struct em_tx_desc *tx_desc; - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; - EM_LOCK_ASSERT(sc); + EM_LOCK_ASSERT(adapter); - if (sc->num_tx_desc_avail == sc->num_tx_desc) + if (adapter->num_tx_desc_avail == adapter->num_tx_desc) return; - num_avail = sc->num_tx_desc_avail; - i = sc->oldest_used_tx_desc; + num_avail = adapter->num_tx_desc_avail; + i = adapter->oldest_used_tx_desc; - tx_buffer = &sc->tx_buffer_area[i]; - tx_desc = &sc->tx_desc_base[i]; + tx_buffer = &adapter->tx_buffer_area[i]; + tx_desc = &adapter->tx_desc_base[i]; - bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map, + bus_dmamap_sync(adapter->txdma.dma_tag, adapter->txdma.dma_map, BUS_DMASYNC_POSTREAD); while (tx_desc->upper.fields.status & E1000_TXD_STAT_DD) { @@ -2748,24 +2748,24 @@ em_txeof(struct em_softc *sc) if (tx_buffer->m_head) { ifp->if_opackets++; - bus_dmamap_sync(sc->txtag, tx_buffer->map, + bus_dmamap_sync(adapter->txtag, tx_buffer->map, BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->txtag, tx_buffer->map); + bus_dmamap_unload(adapter->txtag, tx_buffer->map); m_freem(tx_buffer->m_head); tx_buffer->m_head = NULL; } - if (++i == sc->num_tx_desc) + if (++i == adapter->num_tx_desc) i = 0; - tx_buffer = &sc->tx_buffer_area[i]; - tx_desc = &sc->tx_desc_base[i]; + tx_buffer = &adapter->tx_buffer_area[i]; + tx_desc = &adapter->tx_desc_base[i]; } - bus_dmamap_sync(sc->txdma.dma_tag, sc->txdma.dma_map, + bus_dmamap_sync(adapter->txdma.dma_tag, adapter->txdma.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); - sc->oldest_used_tx_desc = i; + adapter->oldest_used_tx_desc = i; /* * If we have enough room, clear IFF_DRV_OACTIVE to tell the stack @@ -2775,12 +2775,12 @@ em_txeof(struct em_softc *sc) */ if (num_avail > EM_TX_CLEANUP_THRESHOLD) { ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; - if (num_avail == sc->num_tx_desc) + if (num_avail == adapter->num_tx_desc) ifp->if_timer = 0; - else if (num_avail != sc->num_tx_desc_avail) + else if (num_avail != adapter->num_tx_desc_avail) ifp->if_timer = EM_TX_TIMEOUT; } - sc->num_tx_desc_avail = num_avail; + adapter->num_tx_desc_avail = num_avail; } /********************************************************************* @@ -2789,9 +2789,9 @@ em_txeof(struct em_softc *sc) * **********************************************************************/ static int -em_get_buf(int i, struct em_softc *sc, struct mbuf *mp) +em_get_buf(int i, struct adapter *adapter, struct mbuf *mp) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; bus_dma_segment_t segs[1]; struct em_buffer *rx_buffer; int error, nsegs; @@ -2799,7 +2799,7 @@ em_get_buf(int i, struct em_softc *sc, struct mbuf *mp) if (mp == NULL) { mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); if (mp == NULL) { - sc->mbuf_cluster_failed++; + adapter->mbuf_cluster_failed++; return (ENOBUFS); } mp->m_len = mp->m_pkthdr.len = MCLBYTES; @@ -2812,13 +2812,13 @@ em_get_buf(int i, struct em_softc *sc, struct mbuf *mp) if (ifp->if_mtu <= ETHERMTU) m_adj(mp, ETHER_ALIGN); - rx_buffer = &sc->rx_buffer_area[i]; + rx_buffer = &adapter->rx_buffer_area[i]; /* * Using memory from the mbuf cluster pool, invoke the * bus_dma machinery to arrange the memory mapping. */ - error = bus_dmamap_load_mbuf_sg(sc->rxtag, rx_buffer->map, + error = bus_dmamap_load_mbuf_sg(adapter->rxtag, rx_buffer->map, mp, segs, &nsegs, 0); if (error != 0) { m_free(mp); @@ -2827,8 +2827,8 @@ em_get_buf(int i, struct em_softc *sc, struct mbuf *mp) /* If nsegs is wrong then the stack is corrupt. */ KASSERT(nsegs == 1, ("Too many segments returned!")); rx_buffer->m_head = mp; - sc->rx_desc_base[i].buffer_addr = htole64(segs[0].ds_addr); - bus_dmamap_sync(sc->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD); + adapter->rx_desc_base[i].buffer_addr = htole64(segs[0].ds_addr); + bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD); return (0); } @@ -2842,20 +2842,20 @@ em_get_buf(int i, struct em_softc *sc, struct mbuf *mp) * **********************************************************************/ static int -em_allocate_receive_structures(struct em_softc *sc) +em_allocate_receive_structures(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; struct em_buffer *rx_buffer; int i, error; - sc->rx_buffer_area = malloc(sizeof(struct em_buffer) * sc->num_rx_desc, + adapter->rx_buffer_area = malloc(sizeof(struct em_buffer) * adapter->num_rx_desc, M_DEVBUF, M_NOWAIT); - if (sc->rx_buffer_area == NULL) { + if (adapter->rx_buffer_area == NULL) { device_printf(dev, "Unable to allocate rx_buffer memory\n"); return (ENOMEM); } - bzero(sc->rx_buffer_area, sizeof(struct em_buffer) * sc->num_rx_desc); + bzero(adapter->rx_buffer_area, sizeof(struct em_buffer) * adapter->num_rx_desc); error = bus_dma_tag_create(NULL, /* parent */ 1, 0, /* alignment, bounds */ @@ -2868,16 +2868,16 @@ em_allocate_receive_structures(struct em_softc *sc) 0, /* flags */ NULL, /* lockfunc */ NULL, /* lockarg */ - &sc->rxtag); + &adapter->rxtag); if (error) { device_printf(dev, "%s: bus_dma_tag_create failed %d\n", __func__, error); goto fail; } - rx_buffer = sc->rx_buffer_area; - for (i = 0; i < sc->num_rx_desc; i++, rx_buffer++) { - error = bus_dmamap_create(sc->rxtag, BUS_DMA_NOWAIT, + rx_buffer = adapter->rx_buffer_area; + for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) { + error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT, &rx_buffer->map); if (error) { device_printf(dev, "%s: bus_dmamap_create failed: %d\n", @@ -2886,18 +2886,18 @@ em_allocate_receive_structures(struct em_softc *sc) } } - for (i = 0; i < sc->num_rx_desc; i++) { - error = em_get_buf(i, sc, NULL); + for (i = 0; i < adapter->num_rx_desc; i++) { + error = em_get_buf(i, adapter, NULL); if (error) goto fail; } - bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map, + bus_dmamap_sync(adapter->rxdma.dma_tag, adapter->rxdma.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); return (0); fail: - em_free_receive_structures(sc); + em_free_receive_structures(adapter); return (error); } @@ -2907,17 +2907,17 @@ fail: * **********************************************************************/ static int -em_setup_receive_structures(struct em_softc *sc) +em_setup_receive_structures(struct adapter *adapter) { int error; - bzero(sc->rx_desc_base, (sizeof(struct em_rx_desc)) * sc->num_rx_desc); + bzero(adapter->rx_desc_base, (sizeof(struct em_rx_desc)) * adapter->num_rx_desc); - if ((error = em_allocate_receive_structures(sc)) != 0) + if ((error = em_allocate_receive_structures(adapter)) != 0) return (error); /* Setup our descriptor pointers */ - sc->next_rx_desc_to_check = 0; + adapter->next_rx_desc_to_check = 0; return (0); } @@ -2928,9 +2928,9 @@ em_setup_receive_structures(struct em_softc *sc) * **********************************************************************/ static void -em_initialize_receive_unit(struct em_softc *sc) +em_initialize_receive_unit(struct adapter *adapter) { - struct ifnet *ifp = sc->ifp; + struct ifnet *ifp = adapter->ifp; uint64_t bus_addr; uint32_t reg_rctl; uint32_t reg_rxcsum; @@ -2941,13 +2941,13 @@ em_initialize_receive_unit(struct em_softc *sc) * Make sure receives are disabled while setting * up the descriptor ring */ - E1000_WRITE_REG(&sc->hw, RCTL, 0); + E1000_WRITE_REG(&adapter->hw, RCTL, 0); /* Set the Receive Delay Timer Register */ - E1000_WRITE_REG(&sc->hw, RDTR, sc->rx_int_delay.value | E1000_RDT_FPDB); + E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay.value | E1000_RDT_FPDB); - if(sc->hw.mac_type >= em_82540) { - E1000_WRITE_REG(&sc->hw, RADV, sc->rx_abs_int_delay.value); + if(adapter->hw.mac_type >= em_82540) { + E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay.value); /* * Set the interrupt throttling rate. Value is calculated @@ -2955,30 +2955,30 @@ em_initialize_receive_unit(struct em_softc *sc) */ #define MAX_INTS_PER_SEC 8000 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256) - E1000_WRITE_REG(&sc->hw, ITR, DEFAULT_ITR); + E1000_WRITE_REG(&adapter->hw, ITR, DEFAULT_ITR); } /* Setup the Base and Length of the Rx Descriptor Ring */ - bus_addr = sc->rxdma.dma_paddr; - E1000_WRITE_REG(&sc->hw, RDLEN, sc->num_rx_desc * + bus_addr = adapter->rxdma.dma_paddr; + E1000_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc * sizeof(struct em_rx_desc)); - E1000_WRITE_REG(&sc->hw, RDBAH, (uint32_t)(bus_addr >> 32)); - E1000_WRITE_REG(&sc->hw, RDBAL, (uint32_t)bus_addr); + E1000_WRITE_REG(&adapter->hw, RDBAH, (uint32_t)(bus_addr >> 32)); + E1000_WRITE_REG(&adapter->hw, RDBAL, (uint32_t)bus_addr); /* Setup the HW Rx Head and Tail Descriptor Pointers */ - E1000_WRITE_REG(&sc->hw, RDT, sc->num_rx_desc - 1); - E1000_WRITE_REG(&sc->hw, RDH, 0); + E1000_WRITE_REG(&adapter->hw, RDT, adapter->num_rx_desc - 1); + E1000_WRITE_REG(&adapter->hw, RDH, 0); /* Setup the Receive Control Register */ reg_rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | - (sc->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); + (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); - if (sc->hw.tbi_compatibility_on == TRUE) + if (adapter->hw.tbi_compatibility_on == TRUE) reg_rctl |= E1000_RCTL_SBP; - switch (sc->rx_buffer_len) { + switch (adapter->rx_buffer_len) { default: case EM_RXBUFFER_2048: reg_rctl |= E1000_RCTL_SZ_2048; @@ -2998,15 +2998,15 @@ em_initialize_receive_unit(struct em_softc *sc) reg_rctl |= E1000_RCTL_LPE; /* Enable 82543 Receive Checksum Offload for TCP and UDP */ - if ((sc->hw.mac_type >= em_82543) && + if ((adapter->hw.mac_type >= em_82543) && (ifp->if_capenable & IFCAP_RXCSUM)) { - reg_rxcsum = E1000_READ_REG(&sc->hw, RXCSUM); + reg_rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM); reg_rxcsum |= (E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL); - E1000_WRITE_REG(&sc->hw, RXCSUM, reg_rxcsum); + E1000_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum); } /* Enable Receives */ - E1000_WRITE_REG(&sc->hw, RCTL, reg_rctl); + E1000_WRITE_REG(&adapter->hw, RCTL, reg_rctl); } /********************************************************************* @@ -3015,40 +3015,40 @@ em_initialize_receive_unit(struct em_softc *sc) * **********************************************************************/ static void -em_free_receive_structures(struct em_softc *sc) +em_free_receive_structures(struct adapter *adapter) { struct em_buffer *rx_buffer; int i; INIT_DEBUGOUT("free_receive_structures: begin"); - if (sc->rx_buffer_area != NULL) { - rx_buffer = sc->rx_buffer_area; - for (i = 0; i < sc->num_rx_desc; i++, rx_buffer++) { + if (adapter->rx_buffer_area != NULL) { + rx_buffer = adapter->rx_buffer_area; + for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) { if (rx_buffer->m_head != NULL) { - bus_dmamap_sync(sc->rxtag, rx_buffer->map, + bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_POSTREAD); - bus_dmamap_unload(sc->rxtag, + bus_dmamap_unload(adapter->rxtag, rx_buffer->map); m_freem(rx_buffer->m_head); rx_buffer->m_head = NULL; } else if (rx_buffer->map != NULL) - bus_dmamap_unload(sc->rxtag, + bus_dmamap_unload(adapter->rxtag, rx_buffer->map); if (rx_buffer->map != NULL) { - bus_dmamap_destroy(sc->rxtag, + bus_dmamap_destroy(adapter->rxtag, rx_buffer->map); rx_buffer->map = NULL; } } } - if (sc->rx_buffer_area != NULL) { - free(sc->rx_buffer_area, M_DEVBUF); - sc->rx_buffer_area = NULL; + if (adapter->rx_buffer_area != NULL) { + free(adapter->rx_buffer_area, M_DEVBUF); + adapter->rx_buffer_area = NULL; } - if (sc->rxtag != NULL) { - bus_dma_tag_destroy(sc->rxtag); - sc->rxtag = NULL; + if (adapter->rxtag != NULL) { + bus_dma_tag_destroy(adapter->rxtag); + adapter->rxtag = NULL; } } @@ -3063,7 +3063,7 @@ em_free_receive_structures(struct em_softc *sc) * *********************************************************************/ static int -em_rxeof(struct em_softc *sc, int count) +em_rxeof(struct adapter *adapter, int count) { struct ifnet *ifp; struct mbuf *mp; @@ -3075,10 +3075,10 @@ em_rxeof(struct em_softc *sc, int count) /* Pointer to the receive descriptor being examined. */ struct em_rx_desc *current_desc; - ifp = sc->ifp; - i = sc->next_rx_desc_to_check; - current_desc = &sc->rx_desc_base[i]; - bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map, + ifp = adapter->ifp; + i = adapter->next_rx_desc_to_check; + current_desc = &adapter->rx_desc_base[i]; + bus_dmamap_sync(adapter->rxdma.dma_tag, adapter->rxdma.dma_map, BUS_DMASYNC_POSTREAD); if (!((current_desc->status) & E1000_RXD_STAT_DD)) @@ -3089,11 +3089,11 @@ em_rxeof(struct em_softc *sc, int count) (ifp->if_drv_flags & IFF_DRV_RUNNING)) { struct mbuf *m = NULL; - mp = sc->rx_buffer_area[i].m_head; - bus_dmamap_sync(sc->rxtag, sc->rx_buffer_area[i].map, + mp = adapter->rx_buffer_area[i].m_head; + bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map, BUS_DMASYNC_POSTREAD); - bus_dmamap_unload(sc->rxtag, - sc->rx_buffer_area[i].map); + bus_dmamap_unload(adapter->rxtag, + adapter->rx_buffer_area[i].map); accept_frame = 1; prev_len_adj = 0; @@ -3115,16 +3115,16 @@ em_rxeof(struct em_softc *sc, int count) uint8_t last_byte; uint32_t pkt_len = desc_len; - if (sc->fmp != NULL) - pkt_len += sc->fmp->m_pkthdr.len; + if (adapter->fmp != NULL) + pkt_len += adapter->fmp->m_pkthdr.len; last_byte = *(mtod(mp, caddr_t) + desc_len - 1); - if (TBI_ACCEPT(&sc->hw, current_desc->status, + if (TBI_ACCEPT(&adapter->hw, current_desc->status, current_desc->errors, pkt_len, last_byte)) { - em_tbi_adjust_stats(&sc->hw, - &sc->stats, pkt_len, - sc->hw.mac_addr); + em_tbi_adjust_stats(&adapter->hw, + &adapter->stats, pkt_len, + adapter->hw.mac_addr); if (len > 0) len--; } else @@ -3132,23 +3132,23 @@ em_rxeof(struct em_softc *sc, int count) } if (accept_frame) { - if (em_get_buf(i, sc, NULL) == ENOBUFS) { - sc->dropped_pkts++; - em_get_buf(i, sc, mp); - if (sc->fmp != NULL) - m_freem(sc->fmp); - sc->fmp = NULL; - sc->lmp = NULL; + if (em_get_buf(i, adapter, NULL) == ENOBUFS) { + adapter->dropped_pkts++; + em_get_buf(i, adapter, mp); + if (adapter->fmp != NULL) + m_freem(adapter->fmp); + adapter->fmp = NULL; + adapter->lmp = NULL; break; } /* Assign correct length to the current fragment */ mp->m_len = len; - if (sc->fmp == NULL) { + if (adapter->fmp == NULL) { mp->m_pkthdr.len = len; - sc->fmp = mp; /* Store the first mbuf */ - sc->lmp = mp; + adapter->fmp = mp; /* Store the first mbuf */ + adapter->lmp = mp; } else { /* Chain mbuf's together */ mp->m_flags &= ~M_PKTHDR; @@ -3158,72 +3158,72 @@ em_rxeof(struct em_softc *sc, int count) * descriptor. */ if (prev_len_adj > 0) { - sc->lmp->m_len -= prev_len_adj; - sc->fmp->m_pkthdr.len -= + adapter->lmp->m_len -= prev_len_adj; + adapter->fmp->m_pkthdr.len -= prev_len_adj; } - sc->lmp->m_next = mp; - sc->lmp = sc->lmp->m_next; - sc->fmp->m_pkthdr.len += len; + adapter->lmp->m_next = mp; + adapter->lmp = adapter->lmp->m_next; + adapter->fmp->m_pkthdr.len += len; } if (eop) { - sc->fmp->m_pkthdr.rcvif = ifp; + adapter->fmp->m_pkthdr.rcvif = ifp; ifp->if_ipackets++; - em_receive_checksum(sc, current_desc, - sc->fmp); + em_receive_checksum(adapter, current_desc, + adapter->fmp); #ifndef __NO_STRICT_ALIGNMENT if (ifp->if_mtu > ETHERMTU && - em_fixup_rx(sc) != 0) + em_fixup_rx(adapter) != 0) goto skip; #endif if (current_desc->status & E1000_RXD_STAT_VP) - VLAN_INPUT_TAG(ifp, sc->fmp, + VLAN_INPUT_TAG(ifp, adapter->fmp, (le16toh(current_desc->special) & E1000_RXD_SPC_VLAN_MASK)); #ifndef __NO_STRICT_ALIGNMENT skip: #endif - m = sc->fmp; - sc->fmp = NULL; - sc->lmp = NULL; + m = adapter->fmp; + adapter->fmp = NULL; + adapter->lmp = NULL; } } else { - sc->dropped_pkts++; - em_get_buf(i, sc, mp); - if (sc->fmp != NULL) - m_freem(sc->fmp); - sc->fmp = NULL; - sc->lmp = NULL; + adapter->dropped_pkts++; + em_get_buf(i, adapter, mp); + if (adapter->fmp != NULL) + m_freem(adapter->fmp); + adapter->fmp = NULL; + adapter->lmp = NULL; } /* Zero out the receive descriptors status. */ current_desc->status = 0; - bus_dmamap_sync(sc->rxdma.dma_tag, sc->rxdma.dma_map, + bus_dmamap_sync(adapter->rxdma.dma_tag, adapter->rxdma.dma_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); /* Advance our pointers to the next descriptor. */ - if (++i == sc->num_rx_desc) + if (++i == adapter->num_rx_desc) i = 0; if (m != NULL) { - sc->next_rx_desc_to_check = i; + adapter->next_rx_desc_to_check = i; #ifdef DEVICE_POLLING - EM_UNLOCK(sc); + EM_UNLOCK(adapter); (*ifp->if_input)(ifp, m); - EM_LOCK(sc); + EM_LOCK(adapter); #else (*ifp->if_input)(ifp, m); #endif - i = sc->next_rx_desc_to_check; + i = adapter->next_rx_desc_to_check; } - current_desc = &sc->rx_desc_base[i]; + current_desc = &adapter->rx_desc_base[i]; } - sc->next_rx_desc_to_check = i; + adapter->next_rx_desc_to_check = i; /* Advance the E1000's Receive Queue #0 "Tail Pointer". */ if (--i < 0) - i = sc->num_rx_desc - 1; - E1000_WRITE_REG(&sc->hw, RDT, i); + i = adapter->num_rx_desc - 1; + E1000_WRITE_REG(&adapter->hw, RDT, i); if (!((current_desc->status) & E1000_RXD_STAT_DD)) return (0); @@ -3246,13 +3246,13 @@ skip: * not used at all on architectures with strict alignment. */ static int -em_fixup_rx(struct em_softc *sc) +em_fixup_rx(struct adapter *adapter) { struct mbuf *m, *n; int error; error = 0; - m = sc->fmp; + m = adapter->fmp; if (m->m_len <= (MCLBYTES - ETHER_HDR_LEN)) { bcopy(m->m_data, m->m_data + ETHER_HDR_LEN, m->m_len); m->m_data += ETHER_HDR_LEN; @@ -3265,11 +3265,11 @@ em_fixup_rx(struct em_softc *sc) n->m_len = ETHER_HDR_LEN; M_MOVE_PKTHDR(n, m); n->m_next = m; - sc->fmp = n; + adapter->fmp = n; } else { - sc->dropped_pkts++; - m_freem(sc->fmp); - sc->fmp = NULL; + adapter->dropped_pkts++; + m_freem(adapter->fmp); + adapter->fmp = NULL; error = ENOMEM; } } @@ -3286,11 +3286,11 @@ em_fixup_rx(struct em_softc *sc) * *********************************************************************/ static void -em_receive_checksum(struct em_softc *sc, struct em_rx_desc *rx_desc, +em_receive_checksum(struct adapter *adapter, struct em_rx_desc *rx_desc, struct mbuf *mp) { /* 82543 or newer only */ - if ((sc->hw.mac_type < em_82543) || + if ((adapter->hw.mac_type < em_82543) || /* Ignore Checksum bit is set */ (rx_desc->status & E1000_RXD_STAT_IXSM)) { mp->m_pkthdr.csum_flags = 0; @@ -3321,35 +3321,35 @@ em_receive_checksum(struct em_softc *sc, struct em_rx_desc *rx_desc, static void -em_enable_vlans(struct em_softc *sc) +em_enable_vlans(struct adapter *adapter) { uint32_t ctrl; - E1000_WRITE_REG(&sc->hw, VET, ETHERTYPE_VLAN); + E1000_WRITE_REG(&adapter->hw, VET, ETHERTYPE_VLAN); - ctrl = E1000_READ_REG(&sc->hw, CTRL); + ctrl = E1000_READ_REG(&adapter->hw, CTRL); ctrl |= E1000_CTRL_VME; - E1000_WRITE_REG(&sc->hw, CTRL, ctrl); + E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); } static void -em_disable_vlans(struct em_softc *sc) +em_disable_vlans(struct adapter *adapter) { uint32_t ctrl; - ctrl = E1000_READ_REG(&sc->hw, CTRL); + ctrl = E1000_READ_REG(&adapter->hw, CTRL); ctrl &= ~E1000_CTRL_VME; - E1000_WRITE_REG(&sc->hw, CTRL, ctrl); + E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); } static void -em_enable_intr(struct em_softc *sc) +em_enable_intr(struct adapter *adapter) { - E1000_WRITE_REG(&sc->hw, IMS, (IMS_ENABLE_MASK)); + E1000_WRITE_REG(&adapter->hw, IMS, (IMS_ENABLE_MASK)); } static void -em_disable_intr(struct em_softc *sc) +em_disable_intr(struct adapter *adapter) { /* * The first version of 82542 had an errata where when link was forced @@ -3360,11 +3360,11 @@ em_disable_intr(struct em_softc *sc) * all the time. */ - if (sc->hw.mac_type == em_82542_rev2_0) - E1000_WRITE_REG(&sc->hw, IMC, + if (adapter->hw.mac_type == em_82542_rev2_0) + E1000_WRITE_REG(&adapter->hw, IMC, (0xffffffff & ~E1000_IMC_RXSEQ)); else - E1000_WRITE_REG(&sc->hw, IMC, + E1000_WRITE_REG(&adapter->hw, IMC, 0xffffffff); } @@ -3464,91 +3464,91 @@ em_fill_descriptors (bus_addr_t address, uint32_t length, * **********************************************************************/ static void -em_update_stats_counters(struct em_softc *sc) +em_update_stats_counters(struct adapter *adapter) { struct ifnet *ifp; - if(sc->hw.media_type == em_media_type_copper || - (E1000_READ_REG(&sc->hw, STATUS) & E1000_STATUS_LU)) { - sc->stats.symerrs += E1000_READ_REG(&sc->hw, SYMERRS); - sc->stats.sec += E1000_READ_REG(&sc->hw, SEC); - } - sc->stats.crcerrs += E1000_READ_REG(&sc->hw, CRCERRS); - sc->stats.mpc += E1000_READ_REG(&sc->hw, MPC); - sc->stats.scc += E1000_READ_REG(&sc->hw, SCC); - sc->stats.ecol += E1000_READ_REG(&sc->hw, ECOL); - - sc->stats.mcc += E1000_READ_REG(&sc->hw, MCC); - sc->stats.latecol += E1000_READ_REG(&sc->hw, LATECOL); - sc->stats.colc += E1000_READ_REG(&sc->hw, COLC); - sc->stats.dc += E1000_READ_REG(&sc->hw, DC); - sc->stats.rlec += E1000_READ_REG(&sc->hw, RLEC); - sc->stats.xonrxc += E1000_READ_REG(&sc->hw, XONRXC); - sc->stats.xontxc += E1000_READ_REG(&sc->hw, XONTXC); - sc->stats.xoffrxc += E1000_READ_REG(&sc->hw, XOFFRXC); - sc->stats.xofftxc += E1000_READ_REG(&sc->hw, XOFFTXC); - sc->stats.fcruc += E1000_READ_REG(&sc->hw, FCRUC); - sc->stats.prc64 += E1000_READ_REG(&sc->hw, PRC64); - sc->stats.prc127 += E1000_READ_REG(&sc->hw, PRC127); - sc->stats.prc255 += E1000_READ_REG(&sc->hw, PRC255); - sc->stats.prc511 += E1000_READ_REG(&sc->hw, PRC511); - sc->stats.prc1023 += E1000_READ_REG(&sc->hw, PRC1023); - sc->stats.prc1522 += E1000_READ_REG(&sc->hw, PRC1522); - sc->stats.gprc += E1000_READ_REG(&sc->hw, GPRC); - sc->stats.bprc += E1000_READ_REG(&sc->hw, BPRC); - sc->stats.mprc += E1000_READ_REG(&sc->hw, MPRC); - sc->stats.gptc += E1000_READ_REG(&sc->hw, GPTC); + if(adapter->hw.media_type == em_media_type_copper || + (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) { + adapter->stats.symerrs += E1000_READ_REG(&adapter->hw, SYMERRS); + adapter->stats.sec += E1000_READ_REG(&adapter->hw, SEC); + } + adapter->stats.crcerrs += E1000_READ_REG(&adapter->hw, CRCERRS); + adapter->stats.mpc += E1000_READ_REG(&adapter->hw, MPC); + adapter->stats.scc += E1000_READ_REG(&adapter->hw, SCC); + adapter->stats.ecol += E1000_READ_REG(&adapter->hw, ECOL); + + adapter->stats.mcc += E1000_READ_REG(&adapter->hw, MCC); + adapter->stats.latecol += E1000_READ_REG(&adapter->hw, LATECOL); + adapter->stats.colc += E1000_READ_REG(&adapter->hw, COLC); + adapter->stats.dc += E1000_READ_REG(&adapter->hw, DC); + adapter->stats.rlec += E1000_READ_REG(&adapter->hw, RLEC); + adapter->stats.xonrxc += E1000_READ_REG(&adapter->hw, XONRXC); + adapter->stats.xontxc += E1000_READ_REG(&adapter->hw, XONTXC); + adapter->stats.xoffrxc += E1000_READ_REG(&adapter->hw, XOFFRXC); + adapter->stats.xofftxc += E1000_READ_REG(&adapter->hw, XOFFTXC); + adapter->stats.fcruc += E1000_READ_REG(&adapter->hw, FCRUC); + adapter->stats.prc64 += E1000_READ_REG(&adapter->hw, PRC64); + adapter->stats.prc127 += E1000_READ_REG(&adapter->hw, PRC127); + adapter->stats.prc255 += E1000_READ_REG(&adapter->hw, PRC255); + adapter->stats.prc511 += E1000_READ_REG(&adapter->hw, PRC511); + adapter->stats.prc1023 += E1000_READ_REG(&adapter->hw, PRC1023); + adapter->stats.prc1522 += E1000_READ_REG(&adapter->hw, PRC1522); + adapter->stats.gprc += E1000_READ_REG(&adapter->hw, GPRC); + adapter->stats.bprc += E1000_READ_REG(&adapter->hw, BPRC); + adapter->stats.mprc += E1000_READ_REG(&adapter->hw, MPRC); + adapter->stats.gptc += E1000_READ_REG(&adapter->hw, GPTC); /* For the 64-bit byte counters the low dword must be read first. */ /* Both registers clear on the read of the high dword */ - sc->stats.gorcl += E1000_READ_REG(&sc->hw, GORCL); - sc->stats.gorch += E1000_READ_REG(&sc->hw, GORCH); - sc->stats.gotcl += E1000_READ_REG(&sc->hw, GOTCL); - sc->stats.gotch += E1000_READ_REG(&sc->hw, GOTCH); - - sc->stats.rnbc += E1000_READ_REG(&sc->hw, RNBC); - sc->stats.ruc += E1000_READ_REG(&sc->hw, RUC); - sc->stats.rfc += E1000_READ_REG(&sc->hw, RFC); - sc->stats.roc += E1000_READ_REG(&sc->hw, ROC); - sc->stats.rjc += E1000_READ_REG(&sc->hw, RJC); - - sc->stats.torl += E1000_READ_REG(&sc->hw, TORL); - sc->stats.torh += E1000_READ_REG(&sc->hw, TORH); - sc->stats.totl += E1000_READ_REG(&sc->hw, TOTL); - sc->stats.toth += E1000_READ_REG(&sc->hw, TOTH); - - sc->stats.tpr += E1000_READ_REG(&sc->hw, TPR); - sc->stats.tpt += E1000_READ_REG(&sc->hw, TPT); - sc->stats.ptc64 += E1000_READ_REG(&sc->hw, PTC64); - sc->stats.ptc127 += E1000_READ_REG(&sc->hw, PTC127); - sc->stats.ptc255 += E1000_READ_REG(&sc->hw, PTC255); - sc->stats.ptc511 += E1000_READ_REG(&sc->hw, PTC511); - sc->stats.ptc1023 += E1000_READ_REG(&sc->hw, PTC1023); - sc->stats.ptc1522 += E1000_READ_REG(&sc->hw, PTC1522); - sc->stats.mptc += E1000_READ_REG(&sc->hw, MPTC); - sc->stats.bptc += E1000_READ_REG(&sc->hw, BPTC); - - if (sc->hw.mac_type >= em_82543) { - sc->stats.algnerrc += E1000_READ_REG(&sc->hw, ALGNERRC); - sc->stats.rxerrc += E1000_READ_REG(&sc->hw, RXERRC); - sc->stats.tncrs += E1000_READ_REG(&sc->hw, TNCRS); - sc->stats.cexterr += E1000_READ_REG(&sc->hw, CEXTERR); - sc->stats.tsctc += E1000_READ_REG(&sc->hw, TSCTC); - sc->stats.tsctfc += E1000_READ_REG(&sc->hw, TSCTFC); - } - ifp = sc->ifp; - - ifp->if_collisions = sc->stats.colc; + adapter->stats.gorcl += E1000_READ_REG(&adapter->hw, GORCL); + adapter->stats.gorch += E1000_READ_REG(&adapter->hw, GORCH); + adapter->stats.gotcl += E1000_READ_REG(&adapter->hw, GOTCL); + adapter->stats.gotch += E1000_READ_REG(&adapter->hw, GOTCH); + + adapter->stats.rnbc += E1000_READ_REG(&adapter->hw, RNBC); + adapter->stats.ruc += E1000_READ_REG(&adapter->hw, RUC); + adapter->stats.rfc += E1000_READ_REG(&adapter->hw, RFC); + adapter->stats.roc += E1000_READ_REG(&adapter->hw, ROC); + adapter->stats.rjc += E1000_READ_REG(&adapter->hw, RJC); + + adapter->stats.torl += E1000_READ_REG(&adapter->hw, TORL); + adapter->stats.torh += E1000_READ_REG(&adapter->hw, TORH); + adapter->stats.totl += E1000_READ_REG(&adapter->hw, TOTL); + adapter->stats.toth += E1000_READ_REG(&adapter->hw, TOTH); + + adapter->stats.tpr += E1000_READ_REG(&adapter->hw, TPR); + adapter->stats.tpt += E1000_READ_REG(&adapter->hw, TPT); + adapter->stats.ptc64 += E1000_READ_REG(&adapter->hw, PTC64); + adapter->stats.ptc127 += E1000_READ_REG(&adapter->hw, PTC127); + adapter->stats.ptc255 += E1000_READ_REG(&adapter->hw, PTC255); + adapter->stats.ptc511 += E1000_READ_REG(&adapter->hw, PTC511); + adapter->stats.ptc1023 += E1000_READ_REG(&adapter->hw, PTC1023); + adapter->stats.ptc1522 += E1000_READ_REG(&adapter->hw, PTC1522); + adapter->stats.mptc += E1000_READ_REG(&adapter->hw, MPTC); + adapter->stats.bptc += E1000_READ_REG(&adapter->hw, BPTC); + + if (adapter->hw.mac_type >= em_82543) { + adapter->stats.algnerrc += E1000_READ_REG(&adapter->hw, ALGNERRC); + adapter->stats.rxerrc += E1000_READ_REG(&adapter->hw, RXERRC); + adapter->stats.tncrs += E1000_READ_REG(&adapter->hw, TNCRS); + adapter->stats.cexterr += E1000_READ_REG(&adapter->hw, CEXTERR); + adapter->stats.tsctc += E1000_READ_REG(&adapter->hw, TSCTC); + adapter->stats.tsctfc += E1000_READ_REG(&adapter->hw, TSCTFC); + } + ifp = adapter->ifp; + + ifp->if_collisions = adapter->stats.colc; /* Rx Errors */ - ifp->if_ierrors = sc->dropped_pkts + sc->stats.rxerrc + - sc->stats.crcerrs + sc->stats.algnerrc + sc->stats.ruc + - sc->stats.roc + sc->stats.mpc + sc->stats.cexterr; + ifp->if_ierrors = adapter->dropped_pkts + adapter->stats.rxerrc + + adapter->stats.crcerrs + adapter->stats.algnerrc + adapter->stats.ruc + + adapter->stats.roc + adapter->stats.mpc + adapter->stats.cexterr; /* Tx Errors */ - ifp->if_oerrors = sc->stats.ecol + sc->stats.latecol + - sc->watchdog_events; + ifp->if_oerrors = adapter->stats.ecol + adapter->stats.latecol + + adapter->watchdog_events; } @@ -3560,91 +3560,91 @@ em_update_stats_counters(struct em_softc *sc) * **********************************************************************/ static void -em_print_debug_info(struct em_softc *sc) +em_print_debug_info(struct adapter *adapter) { - device_t dev = sc->dev; - uint8_t *hw_addr = sc->hw.hw_addr; + device_t dev = adapter->dev; + uint8_t *hw_addr = adapter->hw.hw_addr; device_printf(dev, "Adapter hardware address = %p \n", hw_addr); device_printf(dev, "CTRL = 0x%x RCTL = 0x%x \n", - E1000_READ_REG(&sc->hw, CTRL), - E1000_READ_REG(&sc->hw, RCTL)); + E1000_READ_REG(&adapter->hw, CTRL), + E1000_READ_REG(&adapter->hw, RCTL)); device_printf(dev, "Packet buffer = Tx=%dk Rx=%dk \n", - ((E1000_READ_REG(&sc->hw, PBA) & 0xffff0000) >> 16),\ - (E1000_READ_REG(&sc->hw, PBA) & 0xffff) ); + ((E1000_READ_REG(&adapter->hw, PBA) & 0xffff0000) >> 16),\ + (E1000_READ_REG(&adapter->hw, PBA) & 0xffff) ); device_printf(dev, "Flow control watermarks high = %d low = %d\n", - sc->hw.fc_high_water, - sc->hw.fc_low_water); + adapter->hw.fc_high_water, + adapter->hw.fc_low_water); device_printf(dev, "tx_int_delay = %d, tx_abs_int_delay = %d\n", - E1000_READ_REG(&sc->hw, TIDV), - E1000_READ_REG(&sc->hw, TADV)); + E1000_READ_REG(&adapter->hw, TIDV), + E1000_READ_REG(&adapter->hw, TADV)); device_printf(dev, "rx_int_delay = %d, rx_abs_int_delay = %d\n", - E1000_READ_REG(&sc->hw, RDTR), - E1000_READ_REG(&sc->hw, RADV)); + E1000_READ_REG(&adapter->hw, RDTR), + E1000_READ_REG(&adapter->hw, RADV)); device_printf(dev, "fifo workaround = %lld, fifo_reset_count = %lld\n", - (long long)sc->tx_fifo_wrk_cnt, - (long long)sc->tx_fifo_reset_cnt); + (long long)adapter->tx_fifo_wrk_cnt, + (long long)adapter->tx_fifo_reset_cnt); device_printf(dev, "hw tdh = %d, hw tdt = %d\n", - E1000_READ_REG(&sc->hw, TDH), - E1000_READ_REG(&sc->hw, TDT)); + E1000_READ_REG(&adapter->hw, TDH), + E1000_READ_REG(&adapter->hw, TDT)); device_printf(dev, "Num Tx descriptors avail = %d\n", - sc->num_tx_desc_avail); + adapter->num_tx_desc_avail); device_printf(dev, "Tx Descriptors not avail1 = %ld\n", - sc->no_tx_desc_avail1); + adapter->no_tx_desc_avail1); device_printf(dev, "Tx Descriptors not avail2 = %ld\n", - sc->no_tx_desc_avail2); + adapter->no_tx_desc_avail2); device_printf(dev, "Std mbuf failed = %ld\n", - sc->mbuf_alloc_failed); + adapter->mbuf_alloc_failed); device_printf(dev, "Std mbuf cluster failed = %ld\n", - sc->mbuf_cluster_failed); + adapter->mbuf_cluster_failed); device_printf(dev, "Driver dropped packets = %ld\n", - sc->dropped_pkts); + adapter->dropped_pkts); } static void -em_print_hw_stats(struct em_softc *sc) +em_print_hw_stats(struct adapter *adapter) { - device_t dev = sc->dev; + device_t dev = adapter->dev; device_printf(dev, "Excessive collisions = %lld\n", - (long long)sc->stats.ecol); + (long long)adapter->stats.ecol); device_printf(dev, "Symbol errors = %lld\n", - (long long)sc->stats.symerrs); + (long long)adapter->stats.symerrs); device_printf(dev, "Sequence errors = %lld\n", - (long long)sc->stats.sec); - device_printf(dev, "Defer count = %lld\n", (long long)sc->stats.dc); + (long long)adapter->stats.sec); + device_printf(dev, "Defer count = %lld\n", (long long)adapter->stats.dc); - device_printf(dev, "Missed Packets = %lld\n", (long long)sc->stats.mpc); + device_printf(dev, "Missed Packets = %lld\n", (long long)adapter->stats.mpc); device_printf(dev, "Receive No Buffers = %lld\n", - (long long)sc->stats.rnbc); + (long long)adapter->stats.rnbc); /* RLEC is inaccurate on some hardware, calculate our own. */ device_printf(dev, "Receive Length Errors = %lld\n", - ((long long)sc->stats.roc + (long long)sc->stats.ruc)); + ((long long)adapter->stats.roc + (long long)adapter->stats.ruc)); device_printf(dev, "Receive errors = %lld\n", - (long long)sc->stats.rxerrc); - device_printf(dev, "Crc errors = %lld\n", (long long)sc->stats.crcerrs); + (long long)adapter->stats.rxerrc); + device_printf(dev, "Crc errors = %lld\n", (long long)adapter->stats.crcerrs); device_printf(dev, "Alignment errors = %lld\n", - (long long)sc->stats.algnerrc); + (long long)adapter->stats.algnerrc); device_printf(dev, "Carrier extension errors = %lld\n", - (long long)sc->stats.cexterr); - device_printf(dev, "RX overruns = %ld\n", sc->rx_overruns); - device_printf(dev, "watchdog timeouts = %ld\n", sc->watchdog_events); + (long long)adapter->stats.cexterr); + device_printf(dev, "RX overruns = %ld\n", adapter->rx_overruns); + device_printf(dev, "watchdog timeouts = %ld\n", adapter->watchdog_events); - device_printf(dev, "XON Rcvd = %lld\n", (long long)sc->stats.xonrxc); - device_printf(dev, "XON Xmtd = %lld\n", (long long)sc->stats.xontxc); - device_printf(dev, "XOFF Rcvd = %lld\n", (long long)sc->stats.xoffrxc); - device_printf(dev, "XOFF Xmtd = %lld\n", (long long)sc->stats.xofftxc); + device_printf(dev, "XON Rcvd = %lld\n", (long long)adapter->stats.xonrxc); + device_printf(dev, "XON Xmtd = %lld\n", (long long)adapter->stats.xontxc); + device_printf(dev, "XOFF Rcvd = %lld\n", (long long)adapter->stats.xoffrxc); + device_printf(dev, "XOFF Xmtd = %lld\n", (long long)adapter->stats.xofftxc); device_printf(dev, "Good Packets Rcvd = %lld\n", - (long long)sc->stats.gprc); + (long long)adapter->stats.gprc); device_printf(dev, "Good Packets Xmtd = %lld\n", - (long long)sc->stats.gptc); + (long long)adapter->stats.gptc); } static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS) { - struct em_softc *sc; + struct adapter *adapter; int error; int result; @@ -3655,8 +3655,8 @@ em_sysctl_debug_info(SYSCTL_HANDLER_ARGS) return (error); if (result == 1) { - sc = (struct em_softc *)arg1; - em_print_debug_info(sc); + adapter = (struct adapter *)arg1; + em_print_debug_info(adapter); } return (error); @@ -3666,7 +3666,7 @@ em_sysctl_debug_info(SYSCTL_HANDLER_ARGS) static int em_sysctl_stats(SYSCTL_HANDLER_ARGS) { - struct em_softc *sc; + struct adapter *adapter; int error; int result; @@ -3677,8 +3677,8 @@ em_sysctl_stats(SYSCTL_HANDLER_ARGS) return (error); if (result == 1) { - sc = (struct em_softc *)arg1; - em_print_hw_stats(sc); + adapter = (struct adapter *)arg1; + em_print_hw_stats(adapter); } return (error); @@ -3688,7 +3688,7 @@ static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS) { struct em_int_delay_info *info; - struct em_softc *sc; + struct adapter *adapter; uint32_t regval; int error; int usecs; @@ -3704,10 +3704,10 @@ em_sysctl_int_delay(SYSCTL_HANDLER_ARGS) info->value = usecs; ticks = E1000_USECS_TO_TICKS(usecs); - sc = info->sc; + adapter = info->adapter; - EM_LOCK(sc); - regval = E1000_READ_OFFSET(&sc->hw, info->offset); + EM_LOCK(adapter); + regval = E1000_READ_OFFSET(&adapter->hw, info->offset); regval = (regval & ~0xffff) | (ticks & 0xffff); /* Handle a few special cases. */ switch (info->offset) { @@ -3718,40 +3718,40 @@ em_sysctl_int_delay(SYSCTL_HANDLER_ARGS) case E1000_TIDV: case E1000_82542_TIDV: if (ticks == 0) { - sc->txd_cmd &= ~E1000_TXD_CMD_IDE; + adapter->txd_cmd &= ~E1000_TXD_CMD_IDE; /* Don't write 0 into the TIDV register. */ regval++; } else - sc->txd_cmd |= E1000_TXD_CMD_IDE; + adapter->txd_cmd |= E1000_TXD_CMD_IDE; break; } - E1000_WRITE_OFFSET(&sc->hw, info->offset, regval); - EM_UNLOCK(sc); + E1000_WRITE_OFFSET(&adapter->hw, info->offset, regval); + EM_UNLOCK(adapter); return (0); } static void -em_add_int_delay_sysctl(struct em_softc *sc, const char *name, +em_add_int_delay_sysctl(struct adapter *adapter, const char *name, const char *description, struct em_int_delay_info *info, int offset, int value) { - info->sc = sc; + info->adapter = adapter; info->offset = offset; info->value = value; - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), + SYSCTL_ADD_PROC(device_get_sysctl_ctx(adapter->dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)), OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, info, 0, em_sysctl_int_delay, "I", description); } #ifndef DEVICE_POLLING static void -em_add_int_process_limit(struct em_softc *sc, const char *name, +em_add_int_process_limit(struct adapter *adapter, const char *name, const char *description, int *limit, int value) { *limit = value; - SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), + SYSCTL_ADD_INT(device_get_sysctl_ctx(adapter->dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)), OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description); } #endif diff --git a/sys/dev/em/if_em.h b/sys/dev/em/if_em.h index e8fb6ad..bf2bd7f 100644 --- a/sys/dev/em/if_em.h +++ b/sys/dev/em/if_em.h @@ -146,7 +146,7 @@ POSSIBILITY OF SUCH DAMAGE. * This parameter controls when the driver calls the routine to reclaim * transmit descriptors. */ -#define EM_TX_CLEANUP_THRESHOLD (sc->num_tx_desc / 8) +#define EM_TX_CLEANUP_THRESHOLD (adapter->num_tx_desc / 8) /* * This parameter controls whether or not autonegotation is enabled. @@ -232,9 +232,9 @@ typedef enum _XSUM_CONTEXT_T { OFFLOAD_UDP_IP } XSUM_CONTEXT_T; -struct em_softc sc; /* XXX: ugly forward declaration */ +struct adapter adapter; /* XXX: ugly forward declaration */ struct em_int_delay_info { - struct em_softc *sc; /* XXX: ugly pointer */ + struct adapter *adapter; /* XXX: ugly pointer */ int offset; /* Register offset to read/write */ int value; /* Current value in usecs */ }; @@ -253,7 +253,7 @@ struct em_dma_alloc { }; /* Driver softc. */ -struct em_softc { +struct adapter { struct ifnet *ifp; struct em_hw hw; -- cgit v1.1