ab@2201: /******************************************************************************* ab@2201: ab@2201: Intel PRO/1000 Linux driver ab@2201: Copyright(c) 1999 - 2006 Intel Corporation. ab@2201: ab@2201: This program is free software; you can redistribute it and/or modify it ab@2201: under the terms and conditions of the GNU General Public License, ab@2201: version 2, as published by the Free Software Foundation. ab@2201: ab@2201: This program is distributed in the hope it will be useful, but WITHOUT ab@2201: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ab@2201: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for ab@2201: more details. ab@2201: ab@2201: You should have received a copy of the GNU General Public License along with ab@2201: this program; if not, write to the Free Software Foundation, Inc., ab@2201: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. ab@2201: ab@2201: The full GNU General Public License is included in this distribution in ab@2201: the file called "COPYING". ab@2201: ab@2201: Contact Information: ab@2201: Linux NICS ab@2201: e1000-devel Mailing List ab@2201: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 ab@2201: ab@2201: *******************************************************************************/ ab@2201: ab@2201: #include "e1000.h" ab@2201: #include ab@2201: ab@2201: char e1000_driver_name[] = "e1000"; ab@2201: static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; ab@2201: #define DRV_VERSION "7.3.21-k5-NAPI" ab@2201: const char e1000_driver_version[] = DRV_VERSION; ab@2201: static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; ab@2201: ab@2201: /* e1000_pci_tbl - PCI Device ID Table ab@2201: * ab@2201: * Last entry must be all 0s ab@2201: * ab@2201: * Macro expands to... ab@2201: * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} ab@2201: */ ab@2201: static struct pci_device_id e1000_pci_tbl[] = { ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1000), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1001), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1004), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1008), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1009), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x100C), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x100D), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x100E), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x100F), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1010), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1011), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1012), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1013), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1014), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1015), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1016), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1017), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1018), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1019), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x101A), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x101D), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x101E), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1026), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1027), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1028), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1075), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1076), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1077), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1078), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1079), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x107A), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x107B), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x107C), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x108A), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x1099), ab@2201: INTEL_E1000_ETHERNET_DEVICE(0x10B5), ab@2201: /* required last entry */ ab@2201: {0,} ab@2201: }; ab@2201: ab@2201: MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); ab@2201: ab@2201: int e1000_up(struct e1000_adapter *adapter); ab@2201: void e1000_down(struct e1000_adapter *adapter); ab@2201: void e1000_reinit_locked(struct e1000_adapter *adapter); ab@2201: void e1000_reset(struct e1000_adapter *adapter); ab@2201: int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx); ab@2201: int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); ab@2201: int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); ab@2201: void e1000_free_all_tx_resources(struct e1000_adapter *adapter); ab@2201: void e1000_free_all_rx_resources(struct e1000_adapter *adapter); ab@2201: static int e1000_setup_tx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *txdr); ab@2201: static int e1000_setup_rx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rxdr); ab@2201: static void e1000_free_tx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring); ab@2201: static void e1000_free_rx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring); ab@2201: void e1000_update_stats(struct e1000_adapter *adapter); ab@2201: ab@2201: static int e1000_init_module(void); ab@2201: static void e1000_exit_module(void); ab@2201: static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); ab@2201: static void __devexit e1000_remove(struct pci_dev *pdev); ab@2201: static int e1000_alloc_queues(struct e1000_adapter *adapter); ab@2201: static int e1000_sw_init(struct e1000_adapter *adapter); ab@2201: static int e1000_open(struct net_device *netdev); ab@2201: static int e1000_close(struct net_device *netdev); ab@2201: static void e1000_configure_tx(struct e1000_adapter *adapter); ab@2201: static void e1000_configure_rx(struct e1000_adapter *adapter); ab@2201: static void e1000_setup_rctl(struct e1000_adapter *adapter); ab@2201: static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); ab@2201: static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); ab@2201: static void e1000_clean_tx_ring(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring); ab@2201: static void e1000_clean_rx_ring(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring); ab@2201: static void e1000_set_rx_mode(struct net_device *netdev); ab@2201: static void e1000_update_phy_info(unsigned long data); ab@2201: static void e1000_watchdog(unsigned long data); ab@2201: static void e1000_82547_tx_fifo_stall(unsigned long data); ab@2201: static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, ab@2201: struct net_device *netdev); ab@2201: static struct net_device_stats * e1000_get_stats(struct net_device *netdev); ab@2201: static int e1000_change_mtu(struct net_device *netdev, int new_mtu); ab@2201: static int e1000_set_mac(struct net_device *netdev, void *p); ab@2201: static irqreturn_t e1000_intr(int irq, void *data); ab@2201: static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring); ab@2201: static int e1000_clean(struct napi_struct *napi, int budget); ab@2201: static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int *work_done, int work_to_do); ab@2201: static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int *work_done, int work_to_do); ab@2201: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int cleaned_count); ab@2201: static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int cleaned_count); ab@2201: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); ab@2201: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, ab@2201: int cmd); ab@2201: static void e1000_enter_82542_rst(struct e1000_adapter *adapter); ab@2201: static void e1000_leave_82542_rst(struct e1000_adapter *adapter); ab@2201: static void e1000_tx_timeout(struct net_device *dev); ab@2201: static void e1000_reset_task(struct work_struct *work); ab@2201: static void e1000_smartspeed(struct e1000_adapter *adapter); ab@2201: static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, ab@2201: struct sk_buff *skb); ab@2201: ab@2201: static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); ab@2201: static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); ab@2201: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); ab@2201: static void e1000_restore_vlan(struct e1000_adapter *adapter); ab@2201: ab@2201: #ifdef CONFIG_PM ab@2201: static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); ab@2201: static int e1000_resume(struct pci_dev *pdev); ab@2201: #endif ab@2201: static void e1000_shutdown(struct pci_dev *pdev); ab@2201: ab@2201: #ifdef CONFIG_NET_POLL_CONTROLLER ab@2201: /* for netdump / net console */ ab@2201: static void e1000_netpoll (struct net_device *netdev); ab@2201: #endif ab@2201: ab@2201: #define COPYBREAK_DEFAULT 256 ab@2201: static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; ab@2201: module_param(copybreak, uint, 0644); ab@2201: MODULE_PARM_DESC(copybreak, ab@2201: "Maximum size of packet that is copied to a new buffer on receive"); ab@2201: ab@2201: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, ab@2201: pci_channel_state_t state); ab@2201: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); ab@2201: static void e1000_io_resume(struct pci_dev *pdev); ab@2201: ab@2201: static struct pci_error_handlers e1000_err_handler = { ab@2201: .error_detected = e1000_io_error_detected, ab@2201: .slot_reset = e1000_io_slot_reset, ab@2201: .resume = e1000_io_resume, ab@2201: }; ab@2201: ab@2201: static struct pci_driver e1000_driver = { ab@2201: .name = e1000_driver_name, ab@2201: .id_table = e1000_pci_tbl, ab@2201: .probe = e1000_probe, ab@2201: .remove = __devexit_p(e1000_remove), ab@2201: #ifdef CONFIG_PM ab@2201: /* Power Managment Hooks */ ab@2201: .suspend = e1000_suspend, ab@2201: .resume = e1000_resume, ab@2201: #endif ab@2201: .shutdown = e1000_shutdown, ab@2201: .err_handler = &e1000_err_handler ab@2201: }; ab@2201: ab@2201: MODULE_AUTHOR("Intel Corporation, "); ab@2201: MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); ab@2201: MODULE_LICENSE("GPL"); ab@2201: MODULE_VERSION(DRV_VERSION); ab@2201: ab@2201: static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; ab@2201: module_param(debug, int, 0); ab@2201: MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); ab@2201: ab@2201: /** ab@2201: * e1000_init_module - Driver Registration Routine ab@2201: * ab@2201: * e1000_init_module is the first routine called when the driver is ab@2201: * loaded. All it does is register with the PCI subsystem. ab@2201: **/ ab@2201: ab@2201: static int __init e1000_init_module(void) ab@2201: { ab@2201: int ret; ab@2201: printk(KERN_INFO "%s - version %s\n", ab@2201: e1000_driver_string, e1000_driver_version); ab@2201: ab@2201: printk(KERN_INFO "%s\n", e1000_copyright); ab@2201: ab@2201: ret = pci_register_driver(&e1000_driver); ab@2201: if (copybreak != COPYBREAK_DEFAULT) { ab@2201: if (copybreak == 0) ab@2201: printk(KERN_INFO "e1000: copybreak disabled\n"); ab@2201: else ab@2201: printk(KERN_INFO "e1000: copybreak enabled for " ab@2201: "packets <= %u bytes\n", copybreak); ab@2201: } ab@2201: return ret; ab@2201: } ab@2201: ab@2201: module_init(e1000_init_module); ab@2201: ab@2201: /** ab@2201: * e1000_exit_module - Driver Exit Cleanup Routine ab@2201: * ab@2201: * e1000_exit_module is called just before the driver is removed ab@2201: * from memory. ab@2201: **/ ab@2201: ab@2201: static void __exit e1000_exit_module(void) ab@2201: { ab@2201: pci_unregister_driver(&e1000_driver); ab@2201: } ab@2201: ab@2201: module_exit(e1000_exit_module); ab@2201: ab@2201: static int e1000_request_irq(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: irq_handler_t handler = e1000_intr; ab@2201: int irq_flags = IRQF_SHARED; ab@2201: int err; ab@2201: ab@2201: err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, ab@2201: netdev); ab@2201: if (err) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate interrupt Error: %d\n", err); ab@2201: } ab@2201: ab@2201: return err; ab@2201: } ab@2201: ab@2201: static void e1000_free_irq(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: ab@2201: free_irq(adapter->pdev->irq, netdev); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_irq_disable - Mask off interrupt generation on the NIC ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: ab@2201: static void e1000_irq_disable(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: ew32(IMC, ~0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: synchronize_irq(adapter->pdev->irq); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_irq_enable - Enable default interrupt generation settings ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: ab@2201: static void e1000_irq_enable(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: ew32(IMS, IMS_ENABLE_MASK); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: ab@2201: static void e1000_update_mng_vlan(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: u16 vid = hw->mng_cookie.vlan_id; ab@2201: u16 old_vid = adapter->mng_vlan_id; ab@2201: if (adapter->vlgrp) { ab@2201: if (!vlan_group_get_device(adapter->vlgrp, vid)) { ab@2201: if (hw->mng_cookie.status & ab@2201: E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { ab@2201: e1000_vlan_rx_add_vid(netdev, vid); ab@2201: adapter->mng_vlan_id = vid; ab@2201: } else ab@2201: adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; ab@2201: ab@2201: if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && ab@2201: (vid != old_vid) && ab@2201: !vlan_group_get_device(adapter->vlgrp, old_vid)) ab@2201: e1000_vlan_rx_kill_vid(netdev, old_vid); ab@2201: } else ab@2201: adapter->mng_vlan_id = vid; ab@2201: } ab@2201: } ab@2201: ab@2201: static void e1000_init_manageability(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: if (adapter->en_mng_pt) { ab@2201: u32 manc = er32(MANC); ab@2201: ab@2201: /* disable hardware interception of ARP */ ab@2201: manc &= ~(E1000_MANC_ARP_EN); ab@2201: ab@2201: ew32(MANC, manc); ab@2201: } ab@2201: } ab@2201: ab@2201: static void e1000_release_manageability(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: if (adapter->en_mng_pt) { ab@2201: u32 manc = er32(MANC); ab@2201: ab@2201: /* re-enable hardware interception of ARP */ ab@2201: manc |= E1000_MANC_ARP_EN; ab@2201: ab@2201: ew32(MANC, manc); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_configure - configure the hardware for RX and TX ab@2201: * @adapter = private board structure ab@2201: **/ ab@2201: static void e1000_configure(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: int i; ab@2201: ab@2201: e1000_set_rx_mode(netdev); ab@2201: ab@2201: e1000_restore_vlan(adapter); ab@2201: e1000_init_manageability(adapter); ab@2201: ab@2201: e1000_configure_tx(adapter); ab@2201: e1000_setup_rctl(adapter); ab@2201: e1000_configure_rx(adapter); ab@2201: /* call E1000_DESC_UNUSED which always leaves ab@2201: * at least 1 descriptor unused to make sure ab@2201: * next_to_use != next_to_clean */ ab@2201: for (i = 0; i < adapter->num_rx_queues; i++) { ab@2201: struct e1000_rx_ring *ring = &adapter->rx_ring[i]; ab@2201: adapter->alloc_rx_buf(adapter, ring, ab@2201: E1000_DESC_UNUSED(ring)); ab@2201: } ab@2201: ab@2201: adapter->tx_queue_len = netdev->tx_queue_len; ab@2201: } ab@2201: ab@2201: int e1000_up(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: /* hardware has been reset, we need to reload some things */ ab@2201: e1000_configure(adapter); ab@2201: ab@2201: clear_bit(__E1000_DOWN, &adapter->flags); ab@2201: ab@2201: napi_enable(&adapter->napi); ab@2201: ab@2201: e1000_irq_enable(adapter); ab@2201: ab@2201: netif_wake_queue(adapter->netdev); ab@2201: ab@2201: /* fire a link change interrupt to start the watchdog */ ab@2201: ew32(ICS, E1000_ICS_LSC); ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_power_up_phy - restore link in case the phy was powered down ab@2201: * @adapter: address of board private structure ab@2201: * ab@2201: * The phy may be powered down to save power and turn off link when the ab@2201: * driver is unloaded and wake on lan is not enabled (among others) ab@2201: * *** this routine MUST be followed by a call to e1000_reset *** ab@2201: * ab@2201: **/ ab@2201: ab@2201: void e1000_power_up_phy(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u16 mii_reg = 0; ab@2201: ab@2201: /* Just clear the power down bit to wake the phy back up */ ab@2201: if (hw->media_type == e1000_media_type_copper) { ab@2201: /* according to the manual, the phy will retain its ab@2201: * settings across a power-down/up cycle */ ab@2201: e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); ab@2201: mii_reg &= ~MII_CR_POWER_DOWN; ab@2201: e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); ab@2201: } ab@2201: } ab@2201: ab@2201: static void e1000_power_down_phy(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: /* Power down the PHY so no link is implied when interface is down * ab@2201: * The PHY cannot be powered down if any of the following is true * ab@2201: * (a) WoL is enabled ab@2201: * (b) AMT is active ab@2201: * (c) SoL/IDER session is active */ ab@2201: if (!adapter->wol && hw->mac_type >= e1000_82540 && ab@2201: hw->media_type == e1000_media_type_copper) { ab@2201: u16 mii_reg = 0; ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82540: ab@2201: case e1000_82545: ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547: ab@2201: case e1000_82547_rev_2: ab@2201: if (er32(MANC) & E1000_MANC_SMBUS_EN) ab@2201: goto out; ab@2201: break; ab@2201: default: ab@2201: goto out; ab@2201: } ab@2201: e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); ab@2201: mii_reg |= MII_CR_POWER_DOWN; ab@2201: e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); ab@2201: mdelay(1); ab@2201: } ab@2201: out: ab@2201: return; ab@2201: } ab@2201: ab@2201: void e1000_down(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: u32 rctl, tctl; ab@2201: ab@2201: /* signal that we're down so the interrupt handler does not ab@2201: * reschedule our watchdog timer */ ab@2201: set_bit(__E1000_DOWN, &adapter->flags); ab@2201: ab@2201: /* disable receives in the hardware */ ab@2201: rctl = er32(RCTL); ab@2201: ew32(RCTL, rctl & ~E1000_RCTL_EN); ab@2201: /* flush and sleep below */ ab@2201: ab@2201: netif_tx_disable(netdev); ab@2201: ab@2201: /* disable transmits in the hardware */ ab@2201: tctl = er32(TCTL); ab@2201: tctl &= ~E1000_TCTL_EN; ab@2201: ew32(TCTL, tctl); ab@2201: /* flush both disables and wait for them to finish */ ab@2201: E1000_WRITE_FLUSH(); ab@2201: msleep(10); ab@2201: ab@2201: napi_disable(&adapter->napi); ab@2201: ab@2201: e1000_irq_disable(adapter); ab@2201: ab@2201: del_timer_sync(&adapter->tx_fifo_stall_timer); ab@2201: del_timer_sync(&adapter->watchdog_timer); ab@2201: del_timer_sync(&adapter->phy_info_timer); ab@2201: ab@2201: netdev->tx_queue_len = adapter->tx_queue_len; ab@2201: adapter->link_speed = 0; ab@2201: adapter->link_duplex = 0; ab@2201: netif_carrier_off(netdev); ab@2201: ab@2201: e1000_reset(adapter); ab@2201: e1000_clean_all_tx_rings(adapter); ab@2201: e1000_clean_all_rx_rings(adapter); ab@2201: } ab@2201: ab@2201: void e1000_reinit_locked(struct e1000_adapter *adapter) ab@2201: { ab@2201: WARN_ON(in_interrupt()); ab@2201: while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) ab@2201: msleep(1); ab@2201: e1000_down(adapter); ab@2201: e1000_up(adapter); ab@2201: clear_bit(__E1000_RESETTING, &adapter->flags); ab@2201: } ab@2201: ab@2201: void e1000_reset(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 pba = 0, tx_space, min_tx_space, min_rx_space; ab@2201: bool legacy_pba_adjust = false; ab@2201: u16 hwm; ab@2201: ab@2201: /* Repartition Pba for greater than 9k mtu ab@2201: * To take effect CTRL.RST is required. ab@2201: */ ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: case e1000_82544: ab@2201: case e1000_82540: ab@2201: case e1000_82541: ab@2201: case e1000_82541_rev_2: ab@2201: legacy_pba_adjust = true; ab@2201: pba = E1000_PBA_48K; ab@2201: break; ab@2201: case e1000_82545: ab@2201: case e1000_82545_rev_3: ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: pba = E1000_PBA_48K; ab@2201: break; ab@2201: case e1000_82547: ab@2201: case e1000_82547_rev_2: ab@2201: legacy_pba_adjust = true; ab@2201: pba = E1000_PBA_30K; ab@2201: break; ab@2201: case e1000_undefined: ab@2201: case e1000_num_macs: ab@2201: break; ab@2201: } ab@2201: ab@2201: if (legacy_pba_adjust) { ab@2201: if (hw->max_frame_size > E1000_RXBUFFER_8192) ab@2201: pba -= 8; /* allocate more FIFO for Tx */ ab@2201: ab@2201: if (hw->mac_type == e1000_82547) { ab@2201: adapter->tx_fifo_head = 0; ab@2201: adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; ab@2201: adapter->tx_fifo_size = ab@2201: (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; ab@2201: atomic_set(&adapter->tx_fifo_stall, 0); ab@2201: } ab@2201: } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { ab@2201: /* adjust PBA for jumbo frames */ ab@2201: ew32(PBA, pba); ab@2201: ab@2201: /* To maintain wire speed transmits, the Tx FIFO should be ab@2201: * large enough to accommodate two full transmit packets, ab@2201: * rounded up to the next 1KB and expressed in KB. Likewise, ab@2201: * the Rx FIFO should be large enough to accommodate at least ab@2201: * one full receive packet and is similarly rounded up and ab@2201: * expressed in KB. */ ab@2201: pba = er32(PBA); ab@2201: /* upper 16 bits has Tx packet buffer allocation size in KB */ ab@2201: tx_space = pba >> 16; ab@2201: /* lower 16 bits has Rx packet buffer allocation size in KB */ ab@2201: pba &= 0xffff; ab@2201: /* ab@2201: * the tx fifo also stores 16 bytes of information about the tx ab@2201: * but don't include ethernet FCS because hardware appends it ab@2201: */ ab@2201: min_tx_space = (hw->max_frame_size + ab@2201: sizeof(struct e1000_tx_desc) - ab@2201: ETH_FCS_LEN) * 2; ab@2201: min_tx_space = ALIGN(min_tx_space, 1024); ab@2201: min_tx_space >>= 10; ab@2201: /* software strips receive CRC, so leave room for it */ ab@2201: min_rx_space = hw->max_frame_size; ab@2201: min_rx_space = ALIGN(min_rx_space, 1024); ab@2201: min_rx_space >>= 10; ab@2201: ab@2201: /* If current Tx allocation is less than the min Tx FIFO size, ab@2201: * and the min Tx FIFO size is less than the current Rx FIFO ab@2201: * allocation, take space away from current Rx allocation */ ab@2201: if (tx_space < min_tx_space && ab@2201: ((min_tx_space - tx_space) < pba)) { ab@2201: pba = pba - (min_tx_space - tx_space); ab@2201: ab@2201: /* PCI/PCIx hardware has PBA alignment constraints */ ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82545 ... e1000_82546_rev_3: ab@2201: pba &= ~(E1000_PBA_8K - 1); ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: /* if short on rx space, rx wins and must trump tx ab@2201: * adjustment or use Early Receive if available */ ab@2201: if (pba < min_rx_space) ab@2201: pba = min_rx_space; ab@2201: } ab@2201: } ab@2201: ab@2201: ew32(PBA, pba); ab@2201: ab@2201: /* ab@2201: * flow control settings: ab@2201: * The high water mark must be low enough to fit one full frame ab@2201: * (or the size used for early receive) above it in the Rx FIFO. ab@2201: * Set it to the lower of: ab@2201: * - 90% of the Rx FIFO size, and ab@2201: * - the full Rx FIFO size minus the early receive size (for parts ab@2201: * with ERT support assuming ERT set to E1000_ERT_2048), or ab@2201: * - the full Rx FIFO size minus one full frame ab@2201: */ ab@2201: hwm = min(((pba << 10) * 9 / 10), ab@2201: ((pba << 10) - hw->max_frame_size)); ab@2201: ab@2201: hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */ ab@2201: hw->fc_low_water = hw->fc_high_water - 8; ab@2201: hw->fc_pause_time = E1000_FC_PAUSE_TIME; ab@2201: hw->fc_send_xon = 1; ab@2201: hw->fc = hw->original_fc; ab@2201: ab@2201: /* Allow time for pending master requests to run */ ab@2201: e1000_reset_hw(hw); ab@2201: if (hw->mac_type >= e1000_82544) ab@2201: ew32(WUC, 0); ab@2201: ab@2201: if (e1000_init_hw(hw)) ab@2201: DPRINTK(PROBE, ERR, "Hardware Error\n"); ab@2201: e1000_update_mng_vlan(adapter); ab@2201: ab@2201: /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ ab@2201: if (hw->mac_type >= e1000_82544 && ab@2201: hw->autoneg == 1 && ab@2201: hw->autoneg_advertised == ADVERTISE_1000_FULL) { ab@2201: u32 ctrl = er32(CTRL); ab@2201: /* clear phy power management bit if we are in gig only mode, ab@2201: * which if enabled will attempt negotiation to 100Mb, which ab@2201: * can cause a loss of link at power off or driver unload */ ab@2201: ctrl &= ~E1000_CTRL_SWDPIN3; ab@2201: ew32(CTRL, ctrl); ab@2201: } ab@2201: ab@2201: /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ ab@2201: ew32(VET, ETHERNET_IEEE_VLAN_TYPE); ab@2201: ab@2201: e1000_reset_adaptive(hw); ab@2201: e1000_phy_get_info(hw, &adapter->phy_info); ab@2201: ab@2201: e1000_release_manageability(adapter); ab@2201: } ab@2201: ab@2201: /** ab@2201: * Dump the eeprom for users having checksum issues ab@2201: **/ ab@2201: static void e1000_dump_eeprom(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct ethtool_eeprom eeprom; ab@2201: const struct ethtool_ops *ops = netdev->ethtool_ops; ab@2201: u8 *data; ab@2201: int i; ab@2201: u16 csum_old, csum_new = 0; ab@2201: ab@2201: eeprom.len = ops->get_eeprom_len(netdev); ab@2201: eeprom.offset = 0; ab@2201: ab@2201: data = kmalloc(eeprom.len, GFP_KERNEL); ab@2201: if (!data) { ab@2201: printk(KERN_ERR "Unable to allocate memory to dump EEPROM" ab@2201: " data\n"); ab@2201: return; ab@2201: } ab@2201: ab@2201: ops->get_eeprom(netdev, &eeprom, data); ab@2201: ab@2201: csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + ab@2201: (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); ab@2201: for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) ab@2201: csum_new += data[i] + (data[i + 1] << 8); ab@2201: csum_new = EEPROM_SUM - csum_new; ab@2201: ab@2201: printk(KERN_ERR "/*********************/\n"); ab@2201: printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); ab@2201: printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); ab@2201: ab@2201: printk(KERN_ERR "Offset Values\n"); ab@2201: printk(KERN_ERR "======== ======\n"); ab@2201: print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); ab@2201: ab@2201: printk(KERN_ERR "Include this output when contacting your support " ab@2201: "provider.\n"); ab@2201: printk(KERN_ERR "This is not a software error! Something bad " ab@2201: "happened to your hardware or\n"); ab@2201: printk(KERN_ERR "EEPROM image. Ignoring this " ab@2201: "problem could result in further problems,\n"); ab@2201: printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); ab@2201: printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " ab@2201: "which is invalid\n"); ab@2201: printk(KERN_ERR "and requires you to set the proper MAC " ab@2201: "address manually before continuing\n"); ab@2201: printk(KERN_ERR "to enable this network device.\n"); ab@2201: printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " ab@2201: "to your hardware vendor\n"); ab@2201: printk(KERN_ERR "or Intel Customer Support.\n"); ab@2201: printk(KERN_ERR "/*********************/\n"); ab@2201: ab@2201: kfree(data); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_is_need_ioport - determine if an adapter needs ioport resources or not ab@2201: * @pdev: PCI device information struct ab@2201: * ab@2201: * Return true if an adapter needs ioport resources ab@2201: **/ ab@2201: static int e1000_is_need_ioport(struct pci_dev *pdev) ab@2201: { ab@2201: switch (pdev->device) { ab@2201: case E1000_DEV_ID_82540EM: ab@2201: case E1000_DEV_ID_82540EM_LOM: ab@2201: case E1000_DEV_ID_82540EP: ab@2201: case E1000_DEV_ID_82540EP_LOM: ab@2201: case E1000_DEV_ID_82540EP_LP: ab@2201: case E1000_DEV_ID_82541EI: ab@2201: case E1000_DEV_ID_82541EI_MOBILE: ab@2201: case E1000_DEV_ID_82541ER: ab@2201: case E1000_DEV_ID_82541ER_LOM: ab@2201: case E1000_DEV_ID_82541GI: ab@2201: case E1000_DEV_ID_82541GI_LF: ab@2201: case E1000_DEV_ID_82541GI_MOBILE: ab@2201: case E1000_DEV_ID_82544EI_COPPER: ab@2201: case E1000_DEV_ID_82544EI_FIBER: ab@2201: case E1000_DEV_ID_82544GC_COPPER: ab@2201: case E1000_DEV_ID_82544GC_LOM: ab@2201: case E1000_DEV_ID_82545EM_COPPER: ab@2201: case E1000_DEV_ID_82545EM_FIBER: ab@2201: case E1000_DEV_ID_82546EB_COPPER: ab@2201: case E1000_DEV_ID_82546EB_FIBER: ab@2201: case E1000_DEV_ID_82546EB_QUAD_COPPER: ab@2201: return true; ab@2201: default: ab@2201: return false; ab@2201: } ab@2201: } ab@2201: ab@2201: static const struct net_device_ops e1000_netdev_ops = { ab@2201: .ndo_open = e1000_open, ab@2201: .ndo_stop = e1000_close, ab@2201: .ndo_start_xmit = e1000_xmit_frame, ab@2201: .ndo_get_stats = e1000_get_stats, ab@2201: .ndo_set_rx_mode = e1000_set_rx_mode, ab@2201: .ndo_set_mac_address = e1000_set_mac, ab@2201: .ndo_tx_timeout = e1000_tx_timeout, ab@2201: .ndo_change_mtu = e1000_change_mtu, ab@2201: .ndo_do_ioctl = e1000_ioctl, ab@2201: .ndo_validate_addr = eth_validate_addr, ab@2201: ab@2201: .ndo_vlan_rx_register = e1000_vlan_rx_register, ab@2201: .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, ab@2201: .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, ab@2201: #ifdef CONFIG_NET_POLL_CONTROLLER ab@2201: .ndo_poll_controller = e1000_netpoll, ab@2201: #endif ab@2201: }; ab@2201: ab@2201: /** ab@2201: * e1000_probe - Device Initialization Routine ab@2201: * @pdev: PCI device information struct ab@2201: * @ent: entry in e1000_pci_tbl ab@2201: * ab@2201: * Returns 0 on success, negative on failure ab@2201: * ab@2201: * e1000_probe initializes an adapter identified by a pci_dev structure. ab@2201: * The OS initialization, configuring of the adapter private structure, ab@2201: * and a hardware reset occur. ab@2201: **/ ab@2201: static int __devinit e1000_probe(struct pci_dev *pdev, ab@2201: const struct pci_device_id *ent) ab@2201: { ab@2201: struct net_device *netdev; ab@2201: struct e1000_adapter *adapter; ab@2201: struct e1000_hw *hw; ab@2201: ab@2201: static int cards_found = 0; ab@2201: static int global_quad_port_a = 0; /* global ksp3 port a indication */ ab@2201: int i, err, pci_using_dac; ab@2201: u16 eeprom_data = 0; ab@2201: u16 eeprom_apme_mask = E1000_EEPROM_APME; ab@2201: int bars, need_ioport; ab@2201: ab@2201: /* do not allocate ioport bars when not needed */ ab@2201: need_ioport = e1000_is_need_ioport(pdev); ab@2201: if (need_ioport) { ab@2201: bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); ab@2201: err = pci_enable_device(pdev); ab@2201: } else { ab@2201: bars = pci_select_bars(pdev, IORESOURCE_MEM); ab@2201: err = pci_enable_device_mem(pdev); ab@2201: } ab@2201: if (err) ab@2201: return err; ab@2201: ab@2201: if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && ab@2201: !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { ab@2201: pci_using_dac = 1; ab@2201: } else { ab@2201: err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); ab@2201: if (err) { ab@2201: err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); ab@2201: if (err) { ab@2201: E1000_ERR("No usable DMA configuration, " ab@2201: "aborting\n"); ab@2201: goto err_dma; ab@2201: } ab@2201: } ab@2201: pci_using_dac = 0; ab@2201: } ab@2201: ab@2201: err = pci_request_selected_regions(pdev, bars, e1000_driver_name); ab@2201: if (err) ab@2201: goto err_pci_reg; ab@2201: ab@2201: pci_set_master(pdev); ab@2201: ab@2201: err = -ENOMEM; ab@2201: netdev = alloc_etherdev(sizeof(struct e1000_adapter)); ab@2201: if (!netdev) ab@2201: goto err_alloc_etherdev; ab@2201: ab@2201: SET_NETDEV_DEV(netdev, &pdev->dev); ab@2201: ab@2201: pci_set_drvdata(pdev, netdev); ab@2201: adapter = netdev_priv(netdev); ab@2201: adapter->netdev = netdev; ab@2201: adapter->pdev = pdev; ab@2201: adapter->msg_enable = (1 << debug) - 1; ab@2201: adapter->bars = bars; ab@2201: adapter->need_ioport = need_ioport; ab@2201: ab@2201: hw = &adapter->hw; ab@2201: hw->back = adapter; ab@2201: ab@2201: err = -EIO; ab@2201: hw->hw_addr = pci_ioremap_bar(pdev, BAR_0); ab@2201: if (!hw->hw_addr) ab@2201: goto err_ioremap; ab@2201: ab@2201: if (adapter->need_ioport) { ab@2201: for (i = BAR_1; i <= BAR_5; i++) { ab@2201: if (pci_resource_len(pdev, i) == 0) ab@2201: continue; ab@2201: if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { ab@2201: hw->io_base = pci_resource_start(pdev, i); ab@2201: break; ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: netdev->netdev_ops = &e1000_netdev_ops; ab@2201: e1000_set_ethtool_ops(netdev); ab@2201: netdev->watchdog_timeo = 5 * HZ; ab@2201: netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); ab@2201: ab@2201: strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); ab@2201: ab@2201: adapter->bd_number = cards_found; ab@2201: ab@2201: /* setup the private structure */ ab@2201: ab@2201: err = e1000_sw_init(adapter); ab@2201: if (err) ab@2201: goto err_sw_init; ab@2201: ab@2201: err = -EIO; ab@2201: ab@2201: if (hw->mac_type >= e1000_82543) { ab@2201: netdev->features = NETIF_F_SG | ab@2201: NETIF_F_HW_CSUM | ab@2201: NETIF_F_HW_VLAN_TX | ab@2201: NETIF_F_HW_VLAN_RX | ab@2201: NETIF_F_HW_VLAN_FILTER; ab@2201: } ab@2201: ab@2201: if ((hw->mac_type >= e1000_82544) && ab@2201: (hw->mac_type != e1000_82547)) ab@2201: netdev->features |= NETIF_F_TSO; ab@2201: ab@2201: if (pci_using_dac) ab@2201: netdev->features |= NETIF_F_HIGHDMA; ab@2201: ab@2201: netdev->vlan_features |= NETIF_F_TSO; ab@2201: netdev->vlan_features |= NETIF_F_HW_CSUM; ab@2201: netdev->vlan_features |= NETIF_F_SG; ab@2201: ab@2201: adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw); ab@2201: ab@2201: /* initialize eeprom parameters */ ab@2201: if (e1000_init_eeprom_params(hw)) { ab@2201: E1000_ERR("EEPROM initialization failed\n"); ab@2201: goto err_eeprom; ab@2201: } ab@2201: ab@2201: /* before reading the EEPROM, reset the controller to ab@2201: * put the device in a known good starting state */ ab@2201: ab@2201: e1000_reset_hw(hw); ab@2201: ab@2201: /* make sure the EEPROM is good */ ab@2201: if (e1000_validate_eeprom_checksum(hw) < 0) { ab@2201: DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); ab@2201: e1000_dump_eeprom(adapter); ab@2201: /* ab@2201: * set MAC address to all zeroes to invalidate and temporary ab@2201: * disable this device for the user. This blocks regular ab@2201: * traffic while still permitting ethtool ioctls from reaching ab@2201: * the hardware as well as allowing the user to run the ab@2201: * interface after manually setting a hw addr using ab@2201: * `ip set address` ab@2201: */ ab@2201: memset(hw->mac_addr, 0, netdev->addr_len); ab@2201: } else { ab@2201: /* copy the MAC address out of the EEPROM */ ab@2201: if (e1000_read_mac_addr(hw)) ab@2201: DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); ab@2201: } ab@2201: /* don't block initalization here due to bad MAC address */ ab@2201: memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len); ab@2201: memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len); ab@2201: ab@2201: if (!is_valid_ether_addr(netdev->perm_addr)) ab@2201: DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); ab@2201: ab@2201: e1000_get_bus_info(hw); ab@2201: ab@2201: init_timer(&adapter->tx_fifo_stall_timer); ab@2201: adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; ab@2201: adapter->tx_fifo_stall_timer.data = (unsigned long)adapter; ab@2201: ab@2201: init_timer(&adapter->watchdog_timer); ab@2201: adapter->watchdog_timer.function = &e1000_watchdog; ab@2201: adapter->watchdog_timer.data = (unsigned long) adapter; ab@2201: ab@2201: init_timer(&adapter->phy_info_timer); ab@2201: adapter->phy_info_timer.function = &e1000_update_phy_info; ab@2201: adapter->phy_info_timer.data = (unsigned long)adapter; ab@2201: ab@2201: INIT_WORK(&adapter->reset_task, e1000_reset_task); ab@2201: ab@2201: e1000_check_options(adapter); ab@2201: ab@2201: /* Initial Wake on LAN setting ab@2201: * If APM wake is enabled in the EEPROM, ab@2201: * enable the ACPI Magic Packet filter ab@2201: */ ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: case e1000_82543: ab@2201: break; ab@2201: case e1000_82544: ab@2201: e1000_read_eeprom(hw, ab@2201: EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); ab@2201: eeprom_apme_mask = E1000_EEPROM_82544_APM; ab@2201: break; ab@2201: case e1000_82546: ab@2201: case e1000_82546_rev_3: ab@2201: if (er32(STATUS) & E1000_STATUS_FUNC_1){ ab@2201: e1000_read_eeprom(hw, ab@2201: EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); ab@2201: break; ab@2201: } ab@2201: /* Fall Through */ ab@2201: default: ab@2201: e1000_read_eeprom(hw, ab@2201: EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); ab@2201: break; ab@2201: } ab@2201: if (eeprom_data & eeprom_apme_mask) ab@2201: adapter->eeprom_wol |= E1000_WUFC_MAG; ab@2201: ab@2201: /* now that we have the eeprom settings, apply the special cases ab@2201: * where the eeprom may be wrong or the board simply won't support ab@2201: * wake on lan on a particular port */ ab@2201: switch (pdev->device) { ab@2201: case E1000_DEV_ID_82546GB_PCIE: ab@2201: adapter->eeprom_wol = 0; ab@2201: break; ab@2201: case E1000_DEV_ID_82546EB_FIBER: ab@2201: case E1000_DEV_ID_82546GB_FIBER: ab@2201: /* Wake events only supported on port A for dual fiber ab@2201: * regardless of eeprom setting */ ab@2201: if (er32(STATUS) & E1000_STATUS_FUNC_1) ab@2201: adapter->eeprom_wol = 0; ab@2201: break; ab@2201: case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: ab@2201: /* if quad port adapter, disable WoL on all but port A */ ab@2201: if (global_quad_port_a != 0) ab@2201: adapter->eeprom_wol = 0; ab@2201: else ab@2201: adapter->quad_port_a = 1; ab@2201: /* Reset for multiple quad port adapters */ ab@2201: if (++global_quad_port_a == 4) ab@2201: global_quad_port_a = 0; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* initialize the wol settings based on the eeprom settings */ ab@2201: adapter->wol = adapter->eeprom_wol; ab@2201: device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); ab@2201: ab@2201: /* print bus type/speed/width info */ ab@2201: DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", ab@2201: ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""), ab@2201: ((hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : ab@2201: (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : ab@2201: (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : ab@2201: (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), ab@2201: ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : "32-bit")); ab@2201: ab@2201: printk("%pM\n", netdev->dev_addr); ab@2201: ab@2201: /* reset the hardware with the new settings */ ab@2201: e1000_reset(adapter); ab@2201: ab@2201: strcpy(netdev->name, "eth%d"); ab@2201: err = register_netdev(netdev); ab@2201: if (err) ab@2201: goto err_register; ab@2201: ab@2201: /* carrier off reporting is important to ethtool even BEFORE open */ ab@2201: netif_carrier_off(netdev); ab@2201: ab@2201: DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); ab@2201: ab@2201: cards_found++; ab@2201: return 0; ab@2201: ab@2201: err_register: ab@2201: err_eeprom: ab@2201: e1000_phy_hw_reset(hw); ab@2201: ab@2201: if (hw->flash_address) ab@2201: iounmap(hw->flash_address); ab@2201: kfree(adapter->tx_ring); ab@2201: kfree(adapter->rx_ring); ab@2201: err_sw_init: ab@2201: iounmap(hw->hw_addr); ab@2201: err_ioremap: ab@2201: free_netdev(netdev); ab@2201: err_alloc_etherdev: ab@2201: pci_release_selected_regions(pdev, bars); ab@2201: err_pci_reg: ab@2201: err_dma: ab@2201: pci_disable_device(pdev); ab@2201: return err; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_remove - Device Removal Routine ab@2201: * @pdev: PCI device information struct ab@2201: * ab@2201: * e1000_remove is called by the PCI subsystem to alert the driver ab@2201: * that it should release a PCI device. The could be caused by a ab@2201: * Hot-Plug event, or because the driver is going to be removed from ab@2201: * memory. ab@2201: **/ ab@2201: ab@2201: static void __devexit e1000_remove(struct pci_dev *pdev) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: set_bit(__E1000_DOWN, &adapter->flags); ab@2201: del_timer_sync(&adapter->tx_fifo_stall_timer); ab@2201: del_timer_sync(&adapter->watchdog_timer); ab@2201: del_timer_sync(&adapter->phy_info_timer); ab@2201: ab@2201: cancel_work_sync(&adapter->reset_task); ab@2201: ab@2201: e1000_release_manageability(adapter); ab@2201: ab@2201: unregister_netdev(netdev); ab@2201: ab@2201: e1000_phy_hw_reset(hw); ab@2201: ab@2201: kfree(adapter->tx_ring); ab@2201: kfree(adapter->rx_ring); ab@2201: ab@2201: iounmap(hw->hw_addr); ab@2201: if (hw->flash_address) ab@2201: iounmap(hw->flash_address); ab@2201: pci_release_selected_regions(pdev, adapter->bars); ab@2201: ab@2201: free_netdev(netdev); ab@2201: ab@2201: pci_disable_device(pdev); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_sw_init - Initialize general software structures (struct e1000_adapter) ab@2201: * @adapter: board private structure to initialize ab@2201: * ab@2201: * e1000_sw_init initializes the Adapter private data structure. ab@2201: * Fields are initialized based on PCI device information and ab@2201: * OS network device settings (MTU size). ab@2201: **/ ab@2201: ab@2201: static int __devinit e1000_sw_init(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: ab@2201: /* PCI config space info */ ab@2201: ab@2201: hw->vendor_id = pdev->vendor; ab@2201: hw->device_id = pdev->device; ab@2201: hw->subsystem_vendor_id = pdev->subsystem_vendor; ab@2201: hw->subsystem_id = pdev->subsystem_device; ab@2201: hw->revision_id = pdev->revision; ab@2201: ab@2201: pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); ab@2201: ab@2201: adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; ab@2201: hw->max_frame_size = netdev->mtu + ab@2201: ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; ab@2201: hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; ab@2201: ab@2201: /* identify the MAC */ ab@2201: ab@2201: if (e1000_set_mac_type(hw)) { ab@2201: DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); ab@2201: return -EIO; ab@2201: } ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: default: ab@2201: break; ab@2201: case e1000_82541: ab@2201: case e1000_82547: ab@2201: case e1000_82541_rev_2: ab@2201: case e1000_82547_rev_2: ab@2201: hw->phy_init_script = 1; ab@2201: break; ab@2201: } ab@2201: ab@2201: e1000_set_media_type(hw); ab@2201: ab@2201: hw->wait_autoneg_complete = false; ab@2201: hw->tbi_compatibility_en = true; ab@2201: hw->adaptive_ifs = true; ab@2201: ab@2201: /* Copper options */ ab@2201: ab@2201: if (hw->media_type == e1000_media_type_copper) { ab@2201: hw->mdix = AUTO_ALL_MODES; ab@2201: hw->disable_polarity_correction = false; ab@2201: hw->master_slave = E1000_MASTER_SLAVE; ab@2201: } ab@2201: ab@2201: adapter->num_tx_queues = 1; ab@2201: adapter->num_rx_queues = 1; ab@2201: ab@2201: if (e1000_alloc_queues(adapter)) { ab@2201: DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); ab@2201: return -ENOMEM; ab@2201: } ab@2201: ab@2201: /* Explicitly disable IRQ since the NIC can be in any state. */ ab@2201: e1000_irq_disable(adapter); ab@2201: ab@2201: spin_lock_init(&adapter->stats_lock); ab@2201: ab@2201: set_bit(__E1000_DOWN, &adapter->flags); ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_alloc_queues - Allocate memory for all rings ab@2201: * @adapter: board private structure to initialize ab@2201: * ab@2201: * We allocate one ring per queue at run-time since we don't know the ab@2201: * number of queues at compile-time. ab@2201: **/ ab@2201: ab@2201: static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) ab@2201: { ab@2201: adapter->tx_ring = kcalloc(adapter->num_tx_queues, ab@2201: sizeof(struct e1000_tx_ring), GFP_KERNEL); ab@2201: if (!adapter->tx_ring) ab@2201: return -ENOMEM; ab@2201: ab@2201: adapter->rx_ring = kcalloc(adapter->num_rx_queues, ab@2201: sizeof(struct e1000_rx_ring), GFP_KERNEL); ab@2201: if (!adapter->rx_ring) { ab@2201: kfree(adapter->tx_ring); ab@2201: return -ENOMEM; ab@2201: } ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_open - Called when a network interface is made active ab@2201: * @netdev: network interface device structure ab@2201: * ab@2201: * Returns 0 on success, negative value on failure ab@2201: * ab@2201: * The open entry point is called when a network interface is made ab@2201: * active by the system (IFF_UP). At this point all resources needed ab@2201: * for transmit and receive operations are allocated, the interrupt ab@2201: * handler is registered with the OS, the watchdog timer is started, ab@2201: * and the stack is notified that the interface is ready. ab@2201: **/ ab@2201: ab@2201: static int e1000_open(struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: int err; ab@2201: ab@2201: /* disallow open during test */ ab@2201: if (test_bit(__E1000_TESTING, &adapter->flags)) ab@2201: return -EBUSY; ab@2201: ab@2201: netif_carrier_off(netdev); ab@2201: ab@2201: /* allocate transmit descriptors */ ab@2201: err = e1000_setup_all_tx_resources(adapter); ab@2201: if (err) ab@2201: goto err_setup_tx; ab@2201: ab@2201: /* allocate receive descriptors */ ab@2201: err = e1000_setup_all_rx_resources(adapter); ab@2201: if (err) ab@2201: goto err_setup_rx; ab@2201: ab@2201: e1000_power_up_phy(adapter); ab@2201: ab@2201: adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; ab@2201: if ((hw->mng_cookie.status & ab@2201: E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { ab@2201: e1000_update_mng_vlan(adapter); ab@2201: } ab@2201: ab@2201: /* before we allocate an interrupt, we must be ready to handle it. ab@2201: * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt ab@2201: * as soon as we call pci_request_irq, so we have to setup our ab@2201: * clean_rx handler before we do so. */ ab@2201: e1000_configure(adapter); ab@2201: ab@2201: err = e1000_request_irq(adapter); ab@2201: if (err) ab@2201: goto err_req_irq; ab@2201: ab@2201: /* From here on the code is the same as e1000_up() */ ab@2201: clear_bit(__E1000_DOWN, &adapter->flags); ab@2201: ab@2201: napi_enable(&adapter->napi); ab@2201: ab@2201: e1000_irq_enable(adapter); ab@2201: ab@2201: netif_start_queue(netdev); ab@2201: ab@2201: /* fire a link status change interrupt to start the watchdog */ ab@2201: ew32(ICS, E1000_ICS_LSC); ab@2201: ab@2201: return E1000_SUCCESS; ab@2201: ab@2201: err_req_irq: ab@2201: e1000_power_down_phy(adapter); ab@2201: e1000_free_all_rx_resources(adapter); ab@2201: err_setup_rx: ab@2201: e1000_free_all_tx_resources(adapter); ab@2201: err_setup_tx: ab@2201: e1000_reset(adapter); ab@2201: ab@2201: return err; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_close - Disables a network interface ab@2201: * @netdev: network interface device structure ab@2201: * ab@2201: * Returns 0, this is not allowed to fail ab@2201: * ab@2201: * The close entry point is called when an interface is de-activated ab@2201: * by the OS. The hardware is still under the drivers control, but ab@2201: * needs to be disabled. A global MAC reset is issued to stop the ab@2201: * hardware, and all transmit and receive resources are freed. ab@2201: **/ ab@2201: ab@2201: static int e1000_close(struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); ab@2201: e1000_down(adapter); ab@2201: e1000_power_down_phy(adapter); ab@2201: e1000_free_irq(adapter); ab@2201: ab@2201: e1000_free_all_tx_resources(adapter); ab@2201: e1000_free_all_rx_resources(adapter); ab@2201: ab@2201: /* kill manageability vlan ID if supported, but not if a vlan with ab@2201: * the same ID is registered on the host OS (let 8021q kill it) */ ab@2201: if ((hw->mng_cookie.status & ab@2201: E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && ab@2201: !(adapter->vlgrp && ab@2201: vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { ab@2201: e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); ab@2201: } ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary ab@2201: * @adapter: address of board private structure ab@2201: * @start: address of beginning of memory ab@2201: * @len: length of memory ab@2201: **/ ab@2201: static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start, ab@2201: unsigned long len) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: unsigned long begin = (unsigned long)start; ab@2201: unsigned long end = begin + len; ab@2201: ab@2201: /* First rev 82545 and 82546 need to not allow any memory ab@2201: * write location to cross 64k boundary due to errata 23 */ ab@2201: if (hw->mac_type == e1000_82545 || ab@2201: hw->mac_type == e1000_82546) { ab@2201: return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; ab@2201: } ab@2201: ab@2201: return true; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_tx_resources - allocate Tx resources (Descriptors) ab@2201: * @adapter: board private structure ab@2201: * @txdr: tx descriptor ring (for a specific queue) to setup ab@2201: * ab@2201: * Return 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: static int e1000_setup_tx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *txdr) ab@2201: { ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: int size; ab@2201: ab@2201: size = sizeof(struct e1000_buffer) * txdr->count; ab@2201: txdr->buffer_info = vmalloc(size); ab@2201: if (!txdr->buffer_info) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate memory for the transmit descriptor ring\n"); ab@2201: return -ENOMEM; ab@2201: } ab@2201: memset(txdr->buffer_info, 0, size); ab@2201: ab@2201: /* round up to nearest 4K */ ab@2201: ab@2201: txdr->size = txdr->count * sizeof(struct e1000_tx_desc); ab@2201: txdr->size = ALIGN(txdr->size, 4096); ab@2201: ab@2201: txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); ab@2201: if (!txdr->desc) { ab@2201: setup_tx_desc_die: ab@2201: vfree(txdr->buffer_info); ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate memory for the transmit descriptor ring\n"); ab@2201: return -ENOMEM; ab@2201: } ab@2201: ab@2201: /* Fix for errata 23, can't cross 64kB boundary */ ab@2201: if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { ab@2201: void *olddesc = txdr->desc; ab@2201: dma_addr_t olddma = txdr->dma; ab@2201: DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " ab@2201: "at %p\n", txdr->size, txdr->desc); ab@2201: /* Try again, without freeing the previous */ ab@2201: txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); ab@2201: /* Failed allocation, critical failure */ ab@2201: if (!txdr->desc) { ab@2201: pci_free_consistent(pdev, txdr->size, olddesc, olddma); ab@2201: goto setup_tx_desc_die; ab@2201: } ab@2201: ab@2201: if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { ab@2201: /* give up */ ab@2201: pci_free_consistent(pdev, txdr->size, txdr->desc, ab@2201: txdr->dma); ab@2201: pci_free_consistent(pdev, txdr->size, olddesc, olddma); ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate aligned memory " ab@2201: "for the transmit descriptor ring\n"); ab@2201: vfree(txdr->buffer_info); ab@2201: return -ENOMEM; ab@2201: } else { ab@2201: /* Free old allocation, new allocation was successful */ ab@2201: pci_free_consistent(pdev, txdr->size, olddesc, olddma); ab@2201: } ab@2201: } ab@2201: memset(txdr->desc, 0, txdr->size); ab@2201: ab@2201: txdr->next_to_use = 0; ab@2201: txdr->next_to_clean = 0; ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_all_tx_resources - wrapper to allocate Tx resources ab@2201: * (Descriptors) for all queues ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Return 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: int e1000_setup_all_tx_resources(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i, err = 0; ab@2201: ab@2201: for (i = 0; i < adapter->num_tx_queues; i++) { ab@2201: err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); ab@2201: if (err) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Allocation for Tx Queue %u failed\n", i); ab@2201: for (i-- ; i >= 0; i--) ab@2201: e1000_free_tx_resources(adapter, ab@2201: &adapter->tx_ring[i]); ab@2201: break; ab@2201: } ab@2201: } ab@2201: ab@2201: return err; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_configure_tx - Configure 8254x Transmit Unit after Reset ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Configure the Tx unit of the MAC after a reset. ab@2201: **/ ab@2201: ab@2201: static void e1000_configure_tx(struct e1000_adapter *adapter) ab@2201: { ab@2201: u64 tdba; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 tdlen, tctl, tipg; ab@2201: u32 ipgr1, ipgr2; ab@2201: ab@2201: /* Setup the HW Tx Head and Tail descriptor pointers */ ab@2201: ab@2201: switch (adapter->num_tx_queues) { ab@2201: case 1: ab@2201: default: ab@2201: tdba = adapter->tx_ring[0].dma; ab@2201: tdlen = adapter->tx_ring[0].count * ab@2201: sizeof(struct e1000_tx_desc); ab@2201: ew32(TDLEN, tdlen); ab@2201: ew32(TDBAH, (tdba >> 32)); ab@2201: ew32(TDBAL, (tdba & 0x00000000ffffffffULL)); ab@2201: ew32(TDT, 0); ab@2201: ew32(TDH, 0); ab@2201: adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); ab@2201: adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT); ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Set the default values for the Tx Inter Packet Gap timer */ ab@2201: if ((hw->media_type == e1000_media_type_fiber || ab@2201: hw->media_type == e1000_media_type_internal_serdes)) ab@2201: tipg = DEFAULT_82543_TIPG_IPGT_FIBER; ab@2201: else ab@2201: tipg = DEFAULT_82543_TIPG_IPGT_COPPER; ab@2201: ab@2201: switch (hw->mac_type) { ab@2201: case e1000_82542_rev2_0: ab@2201: case e1000_82542_rev2_1: ab@2201: tipg = DEFAULT_82542_TIPG_IPGT; ab@2201: ipgr1 = DEFAULT_82542_TIPG_IPGR1; ab@2201: ipgr2 = DEFAULT_82542_TIPG_IPGR2; ab@2201: break; ab@2201: default: ab@2201: ipgr1 = DEFAULT_82543_TIPG_IPGR1; ab@2201: ipgr2 = DEFAULT_82543_TIPG_IPGR2; ab@2201: break; ab@2201: } ab@2201: tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; ab@2201: tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; ab@2201: ew32(TIPG, tipg); ab@2201: ab@2201: /* Set the Tx Interrupt Delay register */ ab@2201: ab@2201: ew32(TIDV, adapter->tx_int_delay); ab@2201: if (hw->mac_type >= e1000_82540) ab@2201: ew32(TADV, adapter->tx_abs_int_delay); ab@2201: ab@2201: /* Program the Transmit Control Register */ ab@2201: ab@2201: tctl = er32(TCTL); ab@2201: tctl &= ~E1000_TCTL_CT; ab@2201: tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | ab@2201: (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); ab@2201: ab@2201: e1000_config_collision_dist(hw); ab@2201: ab@2201: /* Setup Transmit Descriptor Settings for eop descriptor */ ab@2201: adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; ab@2201: ab@2201: /* only set IDE if we are delaying interrupts using the timers */ ab@2201: if (adapter->tx_int_delay) ab@2201: adapter->txd_cmd |= E1000_TXD_CMD_IDE; ab@2201: ab@2201: if (hw->mac_type < e1000_82543) ab@2201: adapter->txd_cmd |= E1000_TXD_CMD_RPS; ab@2201: else ab@2201: adapter->txd_cmd |= E1000_TXD_CMD_RS; ab@2201: ab@2201: /* Cache if we're 82544 running in PCI-X because we'll ab@2201: * need this to apply a workaround later in the send path. */ ab@2201: if (hw->mac_type == e1000_82544 && ab@2201: hw->bus_type == e1000_bus_type_pcix) ab@2201: adapter->pcix_82544 = 1; ab@2201: ab@2201: ew32(TCTL, tctl); ab@2201: ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_rx_resources - allocate Rx resources (Descriptors) ab@2201: * @adapter: board private structure ab@2201: * @rxdr: rx descriptor ring (for a specific queue) to setup ab@2201: * ab@2201: * Returns 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: static int e1000_setup_rx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rxdr) ab@2201: { ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: int size, desc_len; ab@2201: ab@2201: size = sizeof(struct e1000_buffer) * rxdr->count; ab@2201: rxdr->buffer_info = vmalloc(size); ab@2201: if (!rxdr->buffer_info) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate memory for the receive descriptor ring\n"); ab@2201: return -ENOMEM; ab@2201: } ab@2201: memset(rxdr->buffer_info, 0, size); ab@2201: ab@2201: desc_len = sizeof(struct e1000_rx_desc); ab@2201: ab@2201: /* Round up to nearest 4K */ ab@2201: ab@2201: rxdr->size = rxdr->count * desc_len; ab@2201: rxdr->size = ALIGN(rxdr->size, 4096); ab@2201: ab@2201: rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); ab@2201: ab@2201: if (!rxdr->desc) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate memory for the receive descriptor ring\n"); ab@2201: setup_rx_desc_die: ab@2201: vfree(rxdr->buffer_info); ab@2201: return -ENOMEM; ab@2201: } ab@2201: ab@2201: /* Fix for errata 23, can't cross 64kB boundary */ ab@2201: if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { ab@2201: void *olddesc = rxdr->desc; ab@2201: dma_addr_t olddma = rxdr->dma; ab@2201: DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " ab@2201: "at %p\n", rxdr->size, rxdr->desc); ab@2201: /* Try again, without freeing the previous */ ab@2201: rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); ab@2201: /* Failed allocation, critical failure */ ab@2201: if (!rxdr->desc) { ab@2201: pci_free_consistent(pdev, rxdr->size, olddesc, olddma); ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate memory " ab@2201: "for the receive descriptor ring\n"); ab@2201: goto setup_rx_desc_die; ab@2201: } ab@2201: ab@2201: if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { ab@2201: /* give up */ ab@2201: pci_free_consistent(pdev, rxdr->size, rxdr->desc, ab@2201: rxdr->dma); ab@2201: pci_free_consistent(pdev, rxdr->size, olddesc, olddma); ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Unable to allocate aligned memory " ab@2201: "for the receive descriptor ring\n"); ab@2201: goto setup_rx_desc_die; ab@2201: } else { ab@2201: /* Free old allocation, new allocation was successful */ ab@2201: pci_free_consistent(pdev, rxdr->size, olddesc, olddma); ab@2201: } ab@2201: } ab@2201: memset(rxdr->desc, 0, rxdr->size); ab@2201: ab@2201: rxdr->next_to_clean = 0; ab@2201: rxdr->next_to_use = 0; ab@2201: rxdr->rx_skb_top = NULL; ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_all_rx_resources - wrapper to allocate Rx resources ab@2201: * (Descriptors) for all queues ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Return 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: int e1000_setup_all_rx_resources(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i, err = 0; ab@2201: ab@2201: for (i = 0; i < adapter->num_rx_queues; i++) { ab@2201: err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); ab@2201: if (err) { ab@2201: DPRINTK(PROBE, ERR, ab@2201: "Allocation for Rx Queue %u failed\n", i); ab@2201: for (i-- ; i >= 0; i--) ab@2201: e1000_free_rx_resources(adapter, ab@2201: &adapter->rx_ring[i]); ab@2201: break; ab@2201: } ab@2201: } ab@2201: ab@2201: return err; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_setup_rctl - configure the receive control registers ab@2201: * @adapter: Board private structure ab@2201: **/ ab@2201: static void e1000_setup_rctl(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 rctl; ab@2201: ab@2201: rctl = er32(RCTL); ab@2201: ab@2201: rctl &= ~(3 << E1000_RCTL_MO_SHIFT); ab@2201: ab@2201: rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | ab@2201: E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | ab@2201: (hw->mc_filter_type << E1000_RCTL_MO_SHIFT); ab@2201: ab@2201: if (hw->tbi_compatibility_on == 1) ab@2201: rctl |= E1000_RCTL_SBP; ab@2201: else ab@2201: rctl &= ~E1000_RCTL_SBP; ab@2201: ab@2201: if (adapter->netdev->mtu <= ETH_DATA_LEN) ab@2201: rctl &= ~E1000_RCTL_LPE; ab@2201: else ab@2201: rctl |= E1000_RCTL_LPE; ab@2201: ab@2201: /* Setup buffer sizes */ ab@2201: rctl &= ~E1000_RCTL_SZ_4096; ab@2201: rctl |= E1000_RCTL_BSEX; ab@2201: switch (adapter->rx_buffer_len) { ab@2201: case E1000_RXBUFFER_2048: ab@2201: default: ab@2201: rctl |= E1000_RCTL_SZ_2048; ab@2201: rctl &= ~E1000_RCTL_BSEX; ab@2201: break; ab@2201: case E1000_RXBUFFER_4096: ab@2201: rctl |= E1000_RCTL_SZ_4096; ab@2201: break; ab@2201: case E1000_RXBUFFER_8192: ab@2201: rctl |= E1000_RCTL_SZ_8192; ab@2201: break; ab@2201: case E1000_RXBUFFER_16384: ab@2201: rctl |= E1000_RCTL_SZ_16384; ab@2201: break; ab@2201: } ab@2201: ab@2201: ew32(RCTL, rctl); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_configure_rx - Configure 8254x Receive Unit after Reset ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Configure the Rx unit of the MAC after a reset. ab@2201: **/ ab@2201: ab@2201: static void e1000_configure_rx(struct e1000_adapter *adapter) ab@2201: { ab@2201: u64 rdba; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 rdlen, rctl, rxcsum; ab@2201: ab@2201: if (adapter->netdev->mtu > ETH_DATA_LEN) { ab@2201: rdlen = adapter->rx_ring[0].count * ab@2201: sizeof(struct e1000_rx_desc); ab@2201: adapter->clean_rx = e1000_clean_jumbo_rx_irq; ab@2201: adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; ab@2201: } else { ab@2201: rdlen = adapter->rx_ring[0].count * ab@2201: sizeof(struct e1000_rx_desc); ab@2201: adapter->clean_rx = e1000_clean_rx_irq; ab@2201: adapter->alloc_rx_buf = e1000_alloc_rx_buffers; ab@2201: } ab@2201: ab@2201: /* disable receives while setting up the descriptors */ ab@2201: rctl = er32(RCTL); ab@2201: ew32(RCTL, rctl & ~E1000_RCTL_EN); ab@2201: ab@2201: /* set the Receive Delay Timer Register */ ab@2201: ew32(RDTR, adapter->rx_int_delay); ab@2201: ab@2201: if (hw->mac_type >= e1000_82540) { ab@2201: ew32(RADV, adapter->rx_abs_int_delay); ab@2201: if (adapter->itr_setting != 0) ab@2201: ew32(ITR, 1000000000 / (adapter->itr * 256)); ab@2201: } ab@2201: ab@2201: /* Setup the HW Rx Head and Tail Descriptor Pointers and ab@2201: * the Base and Length of the Rx Descriptor Ring */ ab@2201: switch (adapter->num_rx_queues) { ab@2201: case 1: ab@2201: default: ab@2201: rdba = adapter->rx_ring[0].dma; ab@2201: ew32(RDLEN, rdlen); ab@2201: ew32(RDBAH, (rdba >> 32)); ab@2201: ew32(RDBAL, (rdba & 0x00000000ffffffffULL)); ab@2201: ew32(RDT, 0); ab@2201: ew32(RDH, 0); ab@2201: adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); ab@2201: adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT); ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Enable 82543 Receive Checksum Offload for TCP and UDP */ ab@2201: if (hw->mac_type >= e1000_82543) { ab@2201: rxcsum = er32(RXCSUM); ab@2201: if (adapter->rx_csum) ab@2201: rxcsum |= E1000_RXCSUM_TUOFL; ab@2201: else ab@2201: /* don't need to clear IPPCSE as it defaults to 0 */ ab@2201: rxcsum &= ~E1000_RXCSUM_TUOFL; ab@2201: ew32(RXCSUM, rxcsum); ab@2201: } ab@2201: ab@2201: /* Enable Receives */ ab@2201: ew32(RCTL, rctl); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_free_tx_resources - Free Tx Resources per Queue ab@2201: * @adapter: board private structure ab@2201: * @tx_ring: Tx descriptor ring for a specific queue ab@2201: * ab@2201: * Free all transmit software resources ab@2201: **/ ab@2201: ab@2201: static void e1000_free_tx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring) ab@2201: { ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: ab@2201: e1000_clean_tx_ring(adapter, tx_ring); ab@2201: ab@2201: vfree(tx_ring->buffer_info); ab@2201: tx_ring->buffer_info = NULL; ab@2201: ab@2201: pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); ab@2201: ab@2201: tx_ring->desc = NULL; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_free_all_tx_resources - Free Tx Resources for All Queues ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Free all transmit software resources ab@2201: **/ ab@2201: ab@2201: void e1000_free_all_tx_resources(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i; ab@2201: ab@2201: for (i = 0; i < adapter->num_tx_queues; i++) ab@2201: e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); ab@2201: } ab@2201: ab@2201: static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, ab@2201: struct e1000_buffer *buffer_info) ab@2201: { ab@2201: if (buffer_info->dma) { ab@2201: if (buffer_info->mapped_as_page) ab@2201: pci_unmap_page(adapter->pdev, buffer_info->dma, ab@2201: buffer_info->length, PCI_DMA_TODEVICE); ab@2201: else ab@2201: pci_unmap_single(adapter->pdev, buffer_info->dma, ab@2201: buffer_info->length, ab@2201: PCI_DMA_TODEVICE); ab@2201: buffer_info->dma = 0; ab@2201: } ab@2201: if (buffer_info->skb) { ab@2201: dev_kfree_skb_any(buffer_info->skb); ab@2201: buffer_info->skb = NULL; ab@2201: } ab@2201: buffer_info->time_stamp = 0; ab@2201: /* buffer_info must be completely set up in the transmit path */ ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_tx_ring - Free Tx Buffers ab@2201: * @adapter: board private structure ab@2201: * @tx_ring: ring to be cleaned ab@2201: **/ ab@2201: ab@2201: static void e1000_clean_tx_ring(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct e1000_buffer *buffer_info; ab@2201: unsigned long size; ab@2201: unsigned int i; ab@2201: ab@2201: /* Free all the Tx ring sk_buffs */ ab@2201: ab@2201: for (i = 0; i < tx_ring->count; i++) { ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: e1000_unmap_and_free_tx_resource(adapter, buffer_info); ab@2201: } ab@2201: ab@2201: size = sizeof(struct e1000_buffer) * tx_ring->count; ab@2201: memset(tx_ring->buffer_info, 0, size); ab@2201: ab@2201: /* Zero out the descriptor ring */ ab@2201: ab@2201: memset(tx_ring->desc, 0, tx_ring->size); ab@2201: ab@2201: tx_ring->next_to_use = 0; ab@2201: tx_ring->next_to_clean = 0; ab@2201: tx_ring->last_tx_tso = 0; ab@2201: ab@2201: writel(0, hw->hw_addr + tx_ring->tdh); ab@2201: writel(0, hw->hw_addr + tx_ring->tdt); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_all_tx_rings - Free Tx Buffers for all queues ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: ab@2201: static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i; ab@2201: ab@2201: for (i = 0; i < adapter->num_tx_queues; i++) ab@2201: e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_free_rx_resources - Free Rx Resources ab@2201: * @adapter: board private structure ab@2201: * @rx_ring: ring to clean the resources from ab@2201: * ab@2201: * Free all receive software resources ab@2201: **/ ab@2201: ab@2201: static void e1000_free_rx_resources(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring) ab@2201: { ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: ab@2201: e1000_clean_rx_ring(adapter, rx_ring); ab@2201: ab@2201: vfree(rx_ring->buffer_info); ab@2201: rx_ring->buffer_info = NULL; ab@2201: ab@2201: pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); ab@2201: ab@2201: rx_ring->desc = NULL; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_free_all_rx_resources - Free Rx Resources for All Queues ab@2201: * @adapter: board private structure ab@2201: * ab@2201: * Free all receive software resources ab@2201: **/ ab@2201: ab@2201: void e1000_free_all_rx_resources(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i; ab@2201: ab@2201: for (i = 0; i < adapter->num_rx_queues; i++) ab@2201: e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_rx_ring - Free Rx Buffers per Queue ab@2201: * @adapter: board private structure ab@2201: * @rx_ring: ring to free buffers from ab@2201: **/ ab@2201: ab@2201: static void e1000_clean_rx_ring(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct e1000_buffer *buffer_info; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: unsigned long size; ab@2201: unsigned int i; ab@2201: ab@2201: /* Free all the Rx ring sk_buffs */ ab@2201: for (i = 0; i < rx_ring->count; i++) { ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: if (buffer_info->dma && ab@2201: adapter->clean_rx == e1000_clean_rx_irq) { ab@2201: pci_unmap_single(pdev, buffer_info->dma, ab@2201: buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: } else if (buffer_info->dma && ab@2201: adapter->clean_rx == e1000_clean_jumbo_rx_irq) { ab@2201: pci_unmap_page(pdev, buffer_info->dma, ab@2201: buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: } ab@2201: ab@2201: buffer_info->dma = 0; ab@2201: if (buffer_info->page) { ab@2201: put_page(buffer_info->page); ab@2201: buffer_info->page = NULL; ab@2201: } ab@2201: if (buffer_info->skb) { ab@2201: dev_kfree_skb(buffer_info->skb); ab@2201: buffer_info->skb = NULL; ab@2201: } ab@2201: } ab@2201: ab@2201: /* there also may be some cached data from a chained receive */ ab@2201: if (rx_ring->rx_skb_top) { ab@2201: dev_kfree_skb(rx_ring->rx_skb_top); ab@2201: rx_ring->rx_skb_top = NULL; ab@2201: } ab@2201: ab@2201: size = sizeof(struct e1000_buffer) * rx_ring->count; ab@2201: memset(rx_ring->buffer_info, 0, size); ab@2201: ab@2201: /* Zero out the descriptor ring */ ab@2201: memset(rx_ring->desc, 0, rx_ring->size); ab@2201: ab@2201: rx_ring->next_to_clean = 0; ab@2201: rx_ring->next_to_use = 0; ab@2201: ab@2201: writel(0, hw->hw_addr + rx_ring->rdh); ab@2201: writel(0, hw->hw_addr + rx_ring->rdt); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_all_rx_rings - Free Rx Buffers for all queues ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: ab@2201: static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter) ab@2201: { ab@2201: int i; ab@2201: ab@2201: for (i = 0; i < adapter->num_rx_queues; i++) ab@2201: e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); ab@2201: } ab@2201: ab@2201: /* The 82542 2.0 (revision 2) needs to have the receive unit in reset ab@2201: * and memory write and invalidate disabled for certain operations ab@2201: */ ab@2201: static void e1000_enter_82542_rst(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: u32 rctl; ab@2201: ab@2201: e1000_pci_clear_mwi(hw); ab@2201: ab@2201: rctl = er32(RCTL); ab@2201: rctl |= E1000_RCTL_RST; ab@2201: ew32(RCTL, rctl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: mdelay(5); ab@2201: ab@2201: if (netif_running(netdev)) ab@2201: e1000_clean_all_rx_rings(adapter); ab@2201: } ab@2201: ab@2201: static void e1000_leave_82542_rst(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: u32 rctl; ab@2201: ab@2201: rctl = er32(RCTL); ab@2201: rctl &= ~E1000_RCTL_RST; ab@2201: ew32(RCTL, rctl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: mdelay(5); ab@2201: ab@2201: if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) ab@2201: e1000_pci_set_mwi(hw); ab@2201: ab@2201: if (netif_running(netdev)) { ab@2201: /* No need to loop, because 82542 supports only 1 queue */ ab@2201: struct e1000_rx_ring *ring = &adapter->rx_ring[0]; ab@2201: e1000_configure_rx(adapter); ab@2201: adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_mac - Change the Ethernet Address of the NIC ab@2201: * @netdev: network interface device structure ab@2201: * @p: pointer to an address structure ab@2201: * ab@2201: * Returns 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: static int e1000_set_mac(struct net_device *netdev, void *p) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct sockaddr *addr = p; ab@2201: ab@2201: if (!is_valid_ether_addr(addr->sa_data)) ab@2201: return -EADDRNOTAVAIL; ab@2201: ab@2201: /* 82542 2.0 needs to be in reset to write receive address registers */ ab@2201: ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: e1000_enter_82542_rst(adapter); ab@2201: ab@2201: memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); ab@2201: memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len); ab@2201: ab@2201: e1000_rar_set(hw, hw->mac_addr, 0); ab@2201: ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: e1000_leave_82542_rst(adapter); ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set ab@2201: * @netdev: network interface device structure ab@2201: * ab@2201: * The set_rx_mode entry point is called whenever the unicast or multicast ab@2201: * address lists or the network interface flags are updated. This routine is ab@2201: * responsible for configuring the hardware for proper unicast, multicast, ab@2201: * promiscuous mode, and all-multi behavior. ab@2201: **/ ab@2201: ab@2201: static void e1000_set_rx_mode(struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct netdev_hw_addr *ha; ab@2201: bool use_uc = false; ab@2201: struct dev_addr_list *mc_ptr; ab@2201: u32 rctl; ab@2201: u32 hash_value; ab@2201: int i, rar_entries = E1000_RAR_ENTRIES; ab@2201: int mta_reg_count = E1000_NUM_MTA_REGISTERS; ab@2201: u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC); ab@2201: ab@2201: if (!mcarray) { ab@2201: DPRINTK(PROBE, ERR, "memory allocation failed\n"); ab@2201: return; ab@2201: } ab@2201: ab@2201: /* Check for Promiscuous and All Multicast modes */ ab@2201: ab@2201: rctl = er32(RCTL); ab@2201: ab@2201: if (netdev->flags & IFF_PROMISC) { ab@2201: rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); ab@2201: rctl &= ~E1000_RCTL_VFE; ab@2201: } else { ab@2201: if (netdev->flags & IFF_ALLMULTI) ab@2201: rctl |= E1000_RCTL_MPE; ab@2201: else ab@2201: rctl &= ~E1000_RCTL_MPE; ab@2201: /* Enable VLAN filter if there is a VLAN */ ab@2201: if (adapter->vlgrp) ab@2201: rctl |= E1000_RCTL_VFE; ab@2201: } ab@2201: ab@2201: if (netdev->uc.count > rar_entries - 1) { ab@2201: rctl |= E1000_RCTL_UPE; ab@2201: } else if (!(netdev->flags & IFF_PROMISC)) { ab@2201: rctl &= ~E1000_RCTL_UPE; ab@2201: use_uc = true; ab@2201: } ab@2201: ab@2201: ew32(RCTL, rctl); ab@2201: ab@2201: /* 82542 2.0 needs to be in reset to write receive address registers */ ab@2201: ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: e1000_enter_82542_rst(adapter); ab@2201: ab@2201: /* load the first 14 addresses into the exact filters 1-14. Unicast ab@2201: * addresses take precedence to avoid disabling unicast filtering ab@2201: * when possible. ab@2201: * ab@2201: * RAR 0 is used for the station MAC adddress ab@2201: * if there are not 14 addresses, go ahead and clear the filters ab@2201: */ ab@2201: i = 1; ab@2201: if (use_uc) ab@2201: list_for_each_entry(ha, &netdev->uc.list, list) { ab@2201: if (i == rar_entries) ab@2201: break; ab@2201: e1000_rar_set(hw, ha->addr, i++); ab@2201: } ab@2201: ab@2201: WARN_ON(i == rar_entries); ab@2201: ab@2201: mc_ptr = netdev->mc_list; ab@2201: ab@2201: for (; i < rar_entries; i++) { ab@2201: if (mc_ptr) { ab@2201: e1000_rar_set(hw, mc_ptr->da_addr, i); ab@2201: mc_ptr = mc_ptr->next; ab@2201: } else { ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: } ab@2201: } ab@2201: ab@2201: /* load any remaining addresses into the hash table */ ab@2201: ab@2201: for (; mc_ptr; mc_ptr = mc_ptr->next) { ab@2201: u32 hash_reg, hash_bit, mta; ab@2201: hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); ab@2201: hash_reg = (hash_value >> 5) & 0x7F; ab@2201: hash_bit = hash_value & 0x1F; ab@2201: mta = (1 << hash_bit); ab@2201: mcarray[hash_reg] |= mta; ab@2201: } ab@2201: ab@2201: /* write the hash table completely, write from bottom to avoid ab@2201: * both stupid write combining chipsets, and flushing each write */ ab@2201: for (i = mta_reg_count - 1; i >= 0 ; i--) { ab@2201: /* ab@2201: * If we are on an 82544 has an errata where writing odd ab@2201: * offsets overwrites the previous even offset, but writing ab@2201: * backwards over the range solves the issue by always ab@2201: * writing the odd offset first ab@2201: */ ab@2201: E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]); ab@2201: } ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: if (hw->mac_type == e1000_82542_rev2_0) ab@2201: e1000_leave_82542_rst(adapter); ab@2201: ab@2201: kfree(mcarray); ab@2201: } ab@2201: ab@2201: /* Need to wait a few seconds after link up to get diagnostic information from ab@2201: * the phy */ ab@2201: ab@2201: static void e1000_update_phy_info(unsigned long data) ab@2201: { ab@2201: struct e1000_adapter *adapter = (struct e1000_adapter *)data; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: e1000_phy_get_info(hw, &adapter->phy_info); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_82547_tx_fifo_stall - Timer Call-back ab@2201: * @data: pointer to adapter cast into an unsigned long ab@2201: **/ ab@2201: ab@2201: static void e1000_82547_tx_fifo_stall(unsigned long data) ab@2201: { ab@2201: struct e1000_adapter *adapter = (struct e1000_adapter *)data; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: u32 tctl; ab@2201: ab@2201: if (atomic_read(&adapter->tx_fifo_stall)) { ab@2201: if ((er32(TDT) == er32(TDH)) && ab@2201: (er32(TDFT) == er32(TDFH)) && ab@2201: (er32(TDFTS) == er32(TDFHS))) { ab@2201: tctl = er32(TCTL); ab@2201: ew32(TCTL, tctl & ~E1000_TCTL_EN); ab@2201: ew32(TDFT, adapter->tx_head_addr); ab@2201: ew32(TDFH, adapter->tx_head_addr); ab@2201: ew32(TDFTS, adapter->tx_head_addr); ab@2201: ew32(TDFHS, adapter->tx_head_addr); ab@2201: ew32(TCTL, tctl); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: adapter->tx_fifo_head = 0; ab@2201: atomic_set(&adapter->tx_fifo_stall, 0); ab@2201: netif_wake_queue(netdev); ab@2201: } else if (!test_bit(__E1000_DOWN, &adapter->flags)) { ab@2201: mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: static bool e1000_has_link(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: bool link_active = false; ab@2201: ab@2201: /* get_link_status is set on LSC (link status) interrupt or ab@2201: * rx sequence error interrupt. get_link_status will stay ab@2201: * false until the e1000_check_for_link establishes link ab@2201: * for copper adapters ONLY ab@2201: */ ab@2201: switch (hw->media_type) { ab@2201: case e1000_media_type_copper: ab@2201: if (hw->get_link_status) { ab@2201: e1000_check_for_link(hw); ab@2201: link_active = !hw->get_link_status; ab@2201: } else { ab@2201: link_active = true; ab@2201: } ab@2201: break; ab@2201: case e1000_media_type_fiber: ab@2201: e1000_check_for_link(hw); ab@2201: link_active = !!(er32(STATUS) & E1000_STATUS_LU); ab@2201: break; ab@2201: case e1000_media_type_internal_serdes: ab@2201: e1000_check_for_link(hw); ab@2201: link_active = hw->serdes_has_link; ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: return link_active; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_watchdog - Timer Call-back ab@2201: * @data: pointer to adapter cast into an unsigned long ab@2201: **/ ab@2201: static void e1000_watchdog(unsigned long data) ab@2201: { ab@2201: struct e1000_adapter *adapter = (struct e1000_adapter *)data; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct e1000_tx_ring *txdr = adapter->tx_ring; ab@2201: u32 link, tctl; ab@2201: ab@2201: link = e1000_has_link(adapter); ab@2201: if ((netif_carrier_ok(netdev)) && link) ab@2201: goto link_up; ab@2201: ab@2201: if (link) { ab@2201: if (!netif_carrier_ok(netdev)) { ab@2201: u32 ctrl; ab@2201: bool txb2b = true; ab@2201: /* update snapshot of PHY registers on LSC */ ab@2201: e1000_get_speed_and_duplex(hw, ab@2201: &adapter->link_speed, ab@2201: &adapter->link_duplex); ab@2201: ab@2201: ctrl = er32(CTRL); ab@2201: printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, " ab@2201: "Flow Control: %s\n", ab@2201: netdev->name, ab@2201: adapter->link_speed, ab@2201: adapter->link_duplex == FULL_DUPLEX ? ab@2201: "Full Duplex" : "Half Duplex", ab@2201: ((ctrl & E1000_CTRL_TFCE) && (ctrl & ab@2201: E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & ab@2201: E1000_CTRL_RFCE) ? "RX" : ((ctrl & ab@2201: E1000_CTRL_TFCE) ? "TX" : "None" ))); ab@2201: ab@2201: /* tweak tx_queue_len according to speed/duplex ab@2201: * and adjust the timeout factor */ ab@2201: netdev->tx_queue_len = adapter->tx_queue_len; ab@2201: adapter->tx_timeout_factor = 1; ab@2201: switch (adapter->link_speed) { ab@2201: case SPEED_10: ab@2201: txb2b = false; ab@2201: netdev->tx_queue_len = 10; ab@2201: adapter->tx_timeout_factor = 16; ab@2201: break; ab@2201: case SPEED_100: ab@2201: txb2b = false; ab@2201: netdev->tx_queue_len = 100; ab@2201: /* maybe add some timeout factor ? */ ab@2201: break; ab@2201: } ab@2201: ab@2201: /* enable transmits in the hardware */ ab@2201: tctl = er32(TCTL); ab@2201: tctl |= E1000_TCTL_EN; ab@2201: ew32(TCTL, tctl); ab@2201: ab@2201: netif_carrier_on(netdev); ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: mod_timer(&adapter->phy_info_timer, ab@2201: round_jiffies(jiffies + 2 * HZ)); ab@2201: adapter->smartspeed = 0; ab@2201: } ab@2201: } else { ab@2201: if (netif_carrier_ok(netdev)) { ab@2201: adapter->link_speed = 0; ab@2201: adapter->link_duplex = 0; ab@2201: printk(KERN_INFO "e1000: %s NIC Link is Down\n", ab@2201: netdev->name); ab@2201: netif_carrier_off(netdev); ab@2201: ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: mod_timer(&adapter->phy_info_timer, ab@2201: round_jiffies(jiffies + 2 * HZ)); ab@2201: } ab@2201: ab@2201: e1000_smartspeed(adapter); ab@2201: } ab@2201: ab@2201: link_up: ab@2201: e1000_update_stats(adapter); ab@2201: ab@2201: hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; ab@2201: adapter->tpt_old = adapter->stats.tpt; ab@2201: hw->collision_delta = adapter->stats.colc - adapter->colc_old; ab@2201: adapter->colc_old = adapter->stats.colc; ab@2201: ab@2201: adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; ab@2201: adapter->gorcl_old = adapter->stats.gorcl; ab@2201: adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; ab@2201: adapter->gotcl_old = adapter->stats.gotcl; ab@2201: ab@2201: e1000_update_adaptive(hw); ab@2201: ab@2201: if (!netif_carrier_ok(netdev)) { ab@2201: if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { ab@2201: /* We've lost link, so the controller stops DMA, ab@2201: * but we've got queued Tx work that's never going ab@2201: * to get done, so reset controller to flush Tx. ab@2201: * (Do the reset outside of interrupt context). */ ab@2201: adapter->tx_timeout_count++; ab@2201: schedule_work(&adapter->reset_task); ab@2201: /* return immediately since reset is imminent */ ab@2201: return; ab@2201: } ab@2201: } ab@2201: ab@2201: /* Cause software interrupt to ensure rx ring is cleaned */ ab@2201: ew32(ICS, E1000_ICS_RXDMT0); ab@2201: ab@2201: /* Force detection of hung controller every watchdog period */ ab@2201: adapter->detect_tx_hung = true; ab@2201: ab@2201: /* Reset the timer */ ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: mod_timer(&adapter->watchdog_timer, ab@2201: round_jiffies(jiffies + 2 * HZ)); ab@2201: } ab@2201: ab@2201: enum latency_range { ab@2201: lowest_latency = 0, ab@2201: low_latency = 1, ab@2201: bulk_latency = 2, ab@2201: latency_invalid = 255 ab@2201: }; ab@2201: ab@2201: /** ab@2201: * e1000_update_itr - update the dynamic ITR value based on statistics ab@2201: * @adapter: pointer to adapter ab@2201: * @itr_setting: current adapter->itr ab@2201: * @packets: the number of packets during this measurement interval ab@2201: * @bytes: the number of bytes during this measurement interval ab@2201: * ab@2201: * Stores a new ITR value based on packets and byte ab@2201: * counts during the last interrupt. The advantage of per interrupt ab@2201: * computation is faster updates and more accurate ITR for the current ab@2201: * traffic pattern. Constants in this function were computed ab@2201: * based on theoretical maximum wire speed and thresholds were set based ab@2201: * on testing data as well as attempting to minimize response time ab@2201: * while increasing bulk throughput. ab@2201: * this functionality is controlled by the InterruptThrottleRate module ab@2201: * parameter (see e1000_param.c) ab@2201: **/ ab@2201: static unsigned int e1000_update_itr(struct e1000_adapter *adapter, ab@2201: u16 itr_setting, int packets, int bytes) ab@2201: { ab@2201: unsigned int retval = itr_setting; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: if (unlikely(hw->mac_type < e1000_82540)) ab@2201: goto update_itr_done; ab@2201: ab@2201: if (packets == 0) ab@2201: goto update_itr_done; ab@2201: ab@2201: switch (itr_setting) { ab@2201: case lowest_latency: ab@2201: /* jumbo frames get bulk treatment*/ ab@2201: if (bytes/packets > 8000) ab@2201: retval = bulk_latency; ab@2201: else if ((packets < 5) && (bytes > 512)) ab@2201: retval = low_latency; ab@2201: break; ab@2201: case low_latency: /* 50 usec aka 20000 ints/s */ ab@2201: if (bytes > 10000) { ab@2201: /* jumbo frames need bulk latency setting */ ab@2201: if (bytes/packets > 8000) ab@2201: retval = bulk_latency; ab@2201: else if ((packets < 10) || ((bytes/packets) > 1200)) ab@2201: retval = bulk_latency; ab@2201: else if ((packets > 35)) ab@2201: retval = lowest_latency; ab@2201: } else if (bytes/packets > 2000) ab@2201: retval = bulk_latency; ab@2201: else if (packets <= 2 && bytes < 512) ab@2201: retval = lowest_latency; ab@2201: break; ab@2201: case bulk_latency: /* 250 usec aka 4000 ints/s */ ab@2201: if (bytes > 25000) { ab@2201: if (packets > 35) ab@2201: retval = low_latency; ab@2201: } else if (bytes < 6000) { ab@2201: retval = low_latency; ab@2201: } ab@2201: break; ab@2201: } ab@2201: ab@2201: update_itr_done: ab@2201: return retval; ab@2201: } ab@2201: ab@2201: static void e1000_set_itr(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u16 current_itr; ab@2201: u32 new_itr = adapter->itr; ab@2201: ab@2201: if (unlikely(hw->mac_type < e1000_82540)) ab@2201: return; ab@2201: ab@2201: /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ ab@2201: if (unlikely(adapter->link_speed != SPEED_1000)) { ab@2201: current_itr = 0; ab@2201: new_itr = 4000; ab@2201: goto set_itr_now; ab@2201: } ab@2201: ab@2201: adapter->tx_itr = e1000_update_itr(adapter, ab@2201: adapter->tx_itr, ab@2201: adapter->total_tx_packets, ab@2201: adapter->total_tx_bytes); ab@2201: /* conservative mode (itr 3) eliminates the lowest_latency setting */ ab@2201: if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) ab@2201: adapter->tx_itr = low_latency; ab@2201: ab@2201: adapter->rx_itr = e1000_update_itr(adapter, ab@2201: adapter->rx_itr, ab@2201: adapter->total_rx_packets, ab@2201: adapter->total_rx_bytes); ab@2201: /* conservative mode (itr 3) eliminates the lowest_latency setting */ ab@2201: if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) ab@2201: adapter->rx_itr = low_latency; ab@2201: ab@2201: current_itr = max(adapter->rx_itr, adapter->tx_itr); ab@2201: ab@2201: switch (current_itr) { ab@2201: /* counts and packets in update_itr are dependent on these numbers */ ab@2201: case lowest_latency: ab@2201: new_itr = 70000; ab@2201: break; ab@2201: case low_latency: ab@2201: new_itr = 20000; /* aka hwitr = ~200 */ ab@2201: break; ab@2201: case bulk_latency: ab@2201: new_itr = 4000; ab@2201: break; ab@2201: default: ab@2201: break; ab@2201: } ab@2201: ab@2201: set_itr_now: ab@2201: if (new_itr != adapter->itr) { ab@2201: /* this attempts to bias the interrupt rate towards Bulk ab@2201: * by adding intermediate steps when interrupt rate is ab@2201: * increasing */ ab@2201: new_itr = new_itr > adapter->itr ? ab@2201: min(adapter->itr + (new_itr >> 2), new_itr) : ab@2201: new_itr; ab@2201: adapter->itr = new_itr; ab@2201: ew32(ITR, 1000000000 / (new_itr * 256)); ab@2201: } ab@2201: ab@2201: return; ab@2201: } ab@2201: ab@2201: #define E1000_TX_FLAGS_CSUM 0x00000001 ab@2201: #define E1000_TX_FLAGS_VLAN 0x00000002 ab@2201: #define E1000_TX_FLAGS_TSO 0x00000004 ab@2201: #define E1000_TX_FLAGS_IPV4 0x00000008 ab@2201: #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 ab@2201: #define E1000_TX_FLAGS_VLAN_SHIFT 16 ab@2201: ab@2201: static int e1000_tso(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring, struct sk_buff *skb) ab@2201: { ab@2201: struct e1000_context_desc *context_desc; ab@2201: struct e1000_buffer *buffer_info; ab@2201: unsigned int i; ab@2201: u32 cmd_length = 0; ab@2201: u16 ipcse = 0, tucse, mss; ab@2201: u8 ipcss, ipcso, tucss, tucso, hdr_len; ab@2201: int err; ab@2201: ab@2201: if (skb_is_gso(skb)) { ab@2201: if (skb_header_cloned(skb)) { ab@2201: err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); ab@2201: if (err) ab@2201: return err; ab@2201: } ab@2201: ab@2201: hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); ab@2201: mss = skb_shinfo(skb)->gso_size; ab@2201: if (skb->protocol == htons(ETH_P_IP)) { ab@2201: struct iphdr *iph = ip_hdr(skb); ab@2201: iph->tot_len = 0; ab@2201: iph->check = 0; ab@2201: tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, ab@2201: iph->daddr, 0, ab@2201: IPPROTO_TCP, ab@2201: 0); ab@2201: cmd_length = E1000_TXD_CMD_IP; ab@2201: ipcse = skb_transport_offset(skb) - 1; ab@2201: } else if (skb->protocol == htons(ETH_P_IPV6)) { ab@2201: ipv6_hdr(skb)->payload_len = 0; ab@2201: tcp_hdr(skb)->check = ab@2201: ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, ab@2201: &ipv6_hdr(skb)->daddr, ab@2201: 0, IPPROTO_TCP, 0); ab@2201: ipcse = 0; ab@2201: } ab@2201: ipcss = skb_network_offset(skb); ab@2201: ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; ab@2201: tucss = skb_transport_offset(skb); ab@2201: tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; ab@2201: tucse = 0; ab@2201: ab@2201: cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | ab@2201: E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); ab@2201: ab@2201: i = tx_ring->next_to_use; ab@2201: context_desc = E1000_CONTEXT_DESC(*tx_ring, i); ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: ab@2201: context_desc->lower_setup.ip_fields.ipcss = ipcss; ab@2201: context_desc->lower_setup.ip_fields.ipcso = ipcso; ab@2201: context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); ab@2201: context_desc->upper_setup.tcp_fields.tucss = tucss; ab@2201: context_desc->upper_setup.tcp_fields.tucso = tucso; ab@2201: context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); ab@2201: context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); ab@2201: context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; ab@2201: context_desc->cmd_and_length = cpu_to_le32(cmd_length); ab@2201: ab@2201: buffer_info->time_stamp = jiffies; ab@2201: buffer_info->next_to_watch = i; ab@2201: ab@2201: if (++i == tx_ring->count) i = 0; ab@2201: tx_ring->next_to_use = i; ab@2201: ab@2201: return true; ab@2201: } ab@2201: return false; ab@2201: } ab@2201: ab@2201: static bool e1000_tx_csum(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring, struct sk_buff *skb) ab@2201: { ab@2201: struct e1000_context_desc *context_desc; ab@2201: struct e1000_buffer *buffer_info; ab@2201: unsigned int i; ab@2201: u8 css; ab@2201: u32 cmd_len = E1000_TXD_CMD_DEXT; ab@2201: ab@2201: if (skb->ip_summed != CHECKSUM_PARTIAL) ab@2201: return false; ab@2201: ab@2201: switch (skb->protocol) { ab@2201: case cpu_to_be16(ETH_P_IP): ab@2201: if (ip_hdr(skb)->protocol == IPPROTO_TCP) ab@2201: cmd_len |= E1000_TXD_CMD_TCP; ab@2201: break; ab@2201: case cpu_to_be16(ETH_P_IPV6): ab@2201: /* XXX not handling all IPV6 headers */ ab@2201: if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) ab@2201: cmd_len |= E1000_TXD_CMD_TCP; ab@2201: break; ab@2201: default: ab@2201: if (unlikely(net_ratelimit())) ab@2201: DPRINTK(DRV, WARNING, ab@2201: "checksum_partial proto=%x!\n", skb->protocol); ab@2201: break; ab@2201: } ab@2201: ab@2201: css = skb_transport_offset(skb); ab@2201: ab@2201: i = tx_ring->next_to_use; ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: context_desc = E1000_CONTEXT_DESC(*tx_ring, i); ab@2201: ab@2201: context_desc->lower_setup.ip_config = 0; ab@2201: context_desc->upper_setup.tcp_fields.tucss = css; ab@2201: context_desc->upper_setup.tcp_fields.tucso = ab@2201: css + skb->csum_offset; ab@2201: context_desc->upper_setup.tcp_fields.tucse = 0; ab@2201: context_desc->tcp_seg_setup.data = 0; ab@2201: context_desc->cmd_and_length = cpu_to_le32(cmd_len); ab@2201: ab@2201: buffer_info->time_stamp = jiffies; ab@2201: buffer_info->next_to_watch = i; ab@2201: ab@2201: if (unlikely(++i == tx_ring->count)) i = 0; ab@2201: tx_ring->next_to_use = i; ab@2201: ab@2201: return true; ab@2201: } ab@2201: ab@2201: #define E1000_MAX_TXD_PWR 12 ab@2201: #define E1000_MAX_DATA_PER_TXD (1<hw; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: struct e1000_buffer *buffer_info; ab@2201: unsigned int len = skb_headlen(skb); ab@2201: unsigned int offset = 0, size, count = 0, i; ab@2201: unsigned int f; ab@2201: ab@2201: i = tx_ring->next_to_use; ab@2201: ab@2201: while (len) { ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: size = min(len, max_per_txd); ab@2201: /* Workaround for Controller erratum -- ab@2201: * descriptor for non-tso packet in a linear SKB that follows a ab@2201: * tso gets written back prematurely before the data is fully ab@2201: * DMA'd to the controller */ ab@2201: if (!skb->data_len && tx_ring->last_tx_tso && ab@2201: !skb_is_gso(skb)) { ab@2201: tx_ring->last_tx_tso = 0; ab@2201: size -= 4; ab@2201: } ab@2201: ab@2201: /* Workaround for premature desc write-backs ab@2201: * in TSO mode. Append 4-byte sentinel desc */ ab@2201: if (unlikely(mss && !nr_frags && size == len && size > 8)) ab@2201: size -= 4; ab@2201: /* work-around for errata 10 and it applies ab@2201: * to all controllers in PCI-X mode ab@2201: * The fix is to make sure that the first descriptor of a ab@2201: * packet is smaller than 2048 - 16 - 16 (or 2016) bytes ab@2201: */ ab@2201: if (unlikely((hw->bus_type == e1000_bus_type_pcix) && ab@2201: (size > 2015) && count == 0)) ab@2201: size = 2015; ab@2201: ab@2201: /* Workaround for potential 82544 hang in PCI-X. Avoid ab@2201: * terminating buffers within evenly-aligned dwords. */ ab@2201: if (unlikely(adapter->pcix_82544 && ab@2201: !((unsigned long)(skb->data + offset + size - 1) & 4) && ab@2201: size > 4)) ab@2201: size -= 4; ab@2201: ab@2201: buffer_info->length = size; ab@2201: /* set time_stamp *before* dma to help avoid a possible race */ ab@2201: buffer_info->time_stamp = jiffies; ab@2201: buffer_info->mapped_as_page = false; ab@2201: buffer_info->dma = pci_map_single(pdev, skb->data + offset, ab@2201: size, PCI_DMA_TODEVICE); ab@2201: if (pci_dma_mapping_error(pdev, buffer_info->dma)) ab@2201: goto dma_error; ab@2201: buffer_info->next_to_watch = i; ab@2201: ab@2201: len -= size; ab@2201: offset += size; ab@2201: count++; ab@2201: if (len) { ab@2201: i++; ab@2201: if (unlikely(i == tx_ring->count)) ab@2201: i = 0; ab@2201: } ab@2201: } ab@2201: ab@2201: for (f = 0; f < nr_frags; f++) { ab@2201: struct skb_frag_struct *frag; ab@2201: ab@2201: frag = &skb_shinfo(skb)->frags[f]; ab@2201: len = frag->size; ab@2201: offset = frag->page_offset; ab@2201: ab@2201: while (len) { ab@2201: i++; ab@2201: if (unlikely(i == tx_ring->count)) ab@2201: i = 0; ab@2201: ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: size = min(len, max_per_txd); ab@2201: /* Workaround for premature desc write-backs ab@2201: * in TSO mode. Append 4-byte sentinel desc */ ab@2201: if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) ab@2201: size -= 4; ab@2201: /* Workaround for potential 82544 hang in PCI-X. ab@2201: * Avoid terminating buffers within evenly-aligned ab@2201: * dwords. */ ab@2201: if (unlikely(adapter->pcix_82544 && ab@2201: !((unsigned long)(page_to_phys(frag->page) + offset ab@2201: + size - 1) & 4) && ab@2201: size > 4)) ab@2201: size -= 4; ab@2201: ab@2201: buffer_info->length = size; ab@2201: buffer_info->time_stamp = jiffies; ab@2201: buffer_info->mapped_as_page = true; ab@2201: buffer_info->dma = pci_map_page(pdev, frag->page, ab@2201: offset, size, ab@2201: PCI_DMA_TODEVICE); ab@2201: if (pci_dma_mapping_error(pdev, buffer_info->dma)) ab@2201: goto dma_error; ab@2201: buffer_info->next_to_watch = i; ab@2201: ab@2201: len -= size; ab@2201: offset += size; ab@2201: count++; ab@2201: } ab@2201: } ab@2201: ab@2201: tx_ring->buffer_info[i].skb = skb; ab@2201: tx_ring->buffer_info[first].next_to_watch = i; ab@2201: ab@2201: return count; ab@2201: ab@2201: dma_error: ab@2201: dev_err(&pdev->dev, "TX DMA map failed\n"); ab@2201: buffer_info->dma = 0; ab@2201: if (count) ab@2201: count--; ab@2201: ab@2201: while (count--) { ab@2201: if (i==0) ab@2201: i += tx_ring->count; ab@2201: i--; ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: e1000_unmap_and_free_tx_resource(adapter, buffer_info); ab@2201: } ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: static void e1000_tx_queue(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring, int tx_flags, ab@2201: int count) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct e1000_tx_desc *tx_desc = NULL; ab@2201: struct e1000_buffer *buffer_info; ab@2201: u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; ab@2201: unsigned int i; ab@2201: ab@2201: if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { ab@2201: txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | ab@2201: E1000_TXD_CMD_TSE; ab@2201: txd_upper |= E1000_TXD_POPTS_TXSM << 8; ab@2201: ab@2201: if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) ab@2201: txd_upper |= E1000_TXD_POPTS_IXSM << 8; ab@2201: } ab@2201: ab@2201: if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { ab@2201: txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; ab@2201: txd_upper |= E1000_TXD_POPTS_TXSM << 8; ab@2201: } ab@2201: ab@2201: if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { ab@2201: txd_lower |= E1000_TXD_CMD_VLE; ab@2201: txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); ab@2201: } ab@2201: ab@2201: i = tx_ring->next_to_use; ab@2201: ab@2201: while (count--) { ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: tx_desc = E1000_TX_DESC(*tx_ring, i); ab@2201: tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); ab@2201: tx_desc->lower.data = ab@2201: cpu_to_le32(txd_lower | buffer_info->length); ab@2201: tx_desc->upper.data = cpu_to_le32(txd_upper); ab@2201: if (unlikely(++i == tx_ring->count)) i = 0; ab@2201: } ab@2201: ab@2201: tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); ab@2201: ab@2201: /* Force memory writes to complete before letting h/w ab@2201: * know there are new descriptors to fetch. (Only ab@2201: * applicable for weak-ordered memory model archs, ab@2201: * such as IA-64). */ ab@2201: wmb(); ab@2201: ab@2201: tx_ring->next_to_use = i; ab@2201: writel(i, hw->hw_addr + tx_ring->tdt); ab@2201: /* we need this if more than one processor can write to our tail ab@2201: * at a time, it syncronizes IO on IA64/Altix systems */ ab@2201: mmiowb(); ab@2201: } ab@2201: ab@2201: /** ab@2201: * 82547 workaround to avoid controller hang in half-duplex environment. ab@2201: * The workaround is to avoid queuing a large packet that would span ab@2201: * the internal Tx FIFO ring boundary by notifying the stack to resend ab@2201: * the packet at a later time. This gives the Tx FIFO an opportunity to ab@2201: * flush all packets. When that occurs, we reset the Tx FIFO pointers ab@2201: * to the beginning of the Tx FIFO. ab@2201: **/ ab@2201: ab@2201: #define E1000_FIFO_HDR 0x10 ab@2201: #define E1000_82547_PAD_LEN 0x3E0 ab@2201: ab@2201: static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, ab@2201: struct sk_buff *skb) ab@2201: { ab@2201: u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; ab@2201: u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; ab@2201: ab@2201: skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); ab@2201: ab@2201: if (adapter->link_duplex != HALF_DUPLEX) ab@2201: goto no_fifo_stall_required; ab@2201: ab@2201: if (atomic_read(&adapter->tx_fifo_stall)) ab@2201: return 1; ab@2201: ab@2201: if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { ab@2201: atomic_set(&adapter->tx_fifo_stall, 1); ab@2201: return 1; ab@2201: } ab@2201: ab@2201: no_fifo_stall_required: ab@2201: adapter->tx_fifo_head += skb_fifo_len; ab@2201: if (adapter->tx_fifo_head >= adapter->tx_fifo_size) ab@2201: adapter->tx_fifo_head -= adapter->tx_fifo_size; ab@2201: return 0; ab@2201: } ab@2201: ab@2201: static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_tx_ring *tx_ring = adapter->tx_ring; ab@2201: ab@2201: netif_stop_queue(netdev); ab@2201: /* Herbert's original patch had: ab@2201: * smp_mb__after_netif_stop_queue(); ab@2201: * but since that doesn't exist yet, just open code it. */ ab@2201: smp_mb(); ab@2201: ab@2201: /* We need to check again in a case another CPU has just ab@2201: * made room available. */ ab@2201: if (likely(E1000_DESC_UNUSED(tx_ring) < size)) ab@2201: return -EBUSY; ab@2201: ab@2201: /* A reprieve! */ ab@2201: netif_start_queue(netdev); ab@2201: ++adapter->restart_queue; ab@2201: return 0; ab@2201: } ab@2201: ab@2201: static int e1000_maybe_stop_tx(struct net_device *netdev, ab@2201: struct e1000_tx_ring *tx_ring, int size) ab@2201: { ab@2201: if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) ab@2201: return 0; ab@2201: return __e1000_maybe_stop_tx(netdev, size); ab@2201: } ab@2201: ab@2201: #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) ab@2201: static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, ab@2201: struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct e1000_tx_ring *tx_ring; ab@2201: unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; ab@2201: unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; ab@2201: unsigned int tx_flags = 0; ab@2201: unsigned int len = skb->len - skb->data_len; ab@2201: unsigned int nr_frags; ab@2201: unsigned int mss; ab@2201: int count = 0; ab@2201: int tso; ab@2201: unsigned int f; ab@2201: ab@2201: /* This goes back to the question of how to logically map a tx queue ab@2201: * to a flow. Right now, performance is impacted slightly negatively ab@2201: * if using multiple tx queues. If the stack breaks away from a ab@2201: * single qdisc implementation, we can look at this again. */ ab@2201: tx_ring = adapter->tx_ring; ab@2201: ab@2201: if (unlikely(skb->len <= 0)) { ab@2201: dev_kfree_skb_any(skb); ab@2201: return NETDEV_TX_OK; ab@2201: } ab@2201: ab@2201: mss = skb_shinfo(skb)->gso_size; ab@2201: /* The controller does a simple calculation to ab@2201: * make sure there is enough room in the FIFO before ab@2201: * initiating the DMA for each buffer. The calc is: ab@2201: * 4 = ceil(buffer len/mss). To make sure we don't ab@2201: * overrun the FIFO, adjust the max buffer len if mss ab@2201: * drops. */ ab@2201: if (mss) { ab@2201: u8 hdr_len; ab@2201: max_per_txd = min(mss << 2, max_per_txd); ab@2201: max_txd_pwr = fls(max_per_txd) - 1; ab@2201: ab@2201: hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); ab@2201: if (skb->data_len && hdr_len == len) { ab@2201: switch (hw->mac_type) { ab@2201: unsigned int pull_size; ab@2201: case e1000_82544: ab@2201: /* Make sure we have room to chop off 4 bytes, ab@2201: * and that the end alignment will work out to ab@2201: * this hardware's requirements ab@2201: * NOTE: this is a TSO only workaround ab@2201: * if end byte alignment not correct move us ab@2201: * into the next dword */ ab@2201: if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) ab@2201: break; ab@2201: /* fall through */ ab@2201: pull_size = min((unsigned int)4, skb->data_len); ab@2201: if (!__pskb_pull_tail(skb, pull_size)) { ab@2201: DPRINTK(DRV, ERR, ab@2201: "__pskb_pull_tail failed.\n"); ab@2201: dev_kfree_skb_any(skb); ab@2201: return NETDEV_TX_OK; ab@2201: } ab@2201: len = skb->len - skb->data_len; ab@2201: break; ab@2201: default: ab@2201: /* do nothing */ ab@2201: break; ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: /* reserve a descriptor for the offload context */ ab@2201: if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) ab@2201: count++; ab@2201: count++; ab@2201: ab@2201: /* Controller Erratum workaround */ ab@2201: if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb)) ab@2201: count++; ab@2201: ab@2201: count += TXD_USE_COUNT(len, max_txd_pwr); ab@2201: ab@2201: if (adapter->pcix_82544) ab@2201: count++; ab@2201: ab@2201: /* work-around for errata 10 and it applies to all controllers ab@2201: * in PCI-X mode, so add one more descriptor to the count ab@2201: */ ab@2201: if (unlikely((hw->bus_type == e1000_bus_type_pcix) && ab@2201: (len > 2015))) ab@2201: count++; ab@2201: ab@2201: nr_frags = skb_shinfo(skb)->nr_frags; ab@2201: for (f = 0; f < nr_frags; f++) ab@2201: count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, ab@2201: max_txd_pwr); ab@2201: if (adapter->pcix_82544) ab@2201: count += nr_frags; ab@2201: ab@2201: /* need: count + 2 desc gap to keep tail from touching ab@2201: * head, otherwise try next time */ ab@2201: if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) ab@2201: return NETDEV_TX_BUSY; ab@2201: ab@2201: if (unlikely(hw->mac_type == e1000_82547)) { ab@2201: if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { ab@2201: netif_stop_queue(netdev); ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: mod_timer(&adapter->tx_fifo_stall_timer, ab@2201: jiffies + 1); ab@2201: return NETDEV_TX_BUSY; ab@2201: } ab@2201: } ab@2201: ab@2201: if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { ab@2201: tx_flags |= E1000_TX_FLAGS_VLAN; ab@2201: tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); ab@2201: } ab@2201: ab@2201: first = tx_ring->next_to_use; ab@2201: ab@2201: tso = e1000_tso(adapter, tx_ring, skb); ab@2201: if (tso < 0) { ab@2201: dev_kfree_skb_any(skb); ab@2201: return NETDEV_TX_OK; ab@2201: } ab@2201: ab@2201: if (likely(tso)) { ab@2201: if (likely(hw->mac_type != e1000_82544)) ab@2201: tx_ring->last_tx_tso = 1; ab@2201: tx_flags |= E1000_TX_FLAGS_TSO; ab@2201: } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) ab@2201: tx_flags |= E1000_TX_FLAGS_CSUM; ab@2201: ab@2201: if (likely(skb->protocol == htons(ETH_P_IP))) ab@2201: tx_flags |= E1000_TX_FLAGS_IPV4; ab@2201: ab@2201: count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd, ab@2201: nr_frags, mss); ab@2201: ab@2201: if (count) { ab@2201: e1000_tx_queue(adapter, tx_ring, tx_flags, count); ab@2201: /* Make sure there is space in the ring for the next send. */ ab@2201: e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); ab@2201: ab@2201: } else { ab@2201: dev_kfree_skb_any(skb); ab@2201: tx_ring->buffer_info[first].time_stamp = 0; ab@2201: tx_ring->next_to_use = first; ab@2201: } ab@2201: ab@2201: return NETDEV_TX_OK; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_tx_timeout - Respond to a Tx Hang ab@2201: * @netdev: network interface device structure ab@2201: **/ ab@2201: ab@2201: static void e1000_tx_timeout(struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: ab@2201: /* Do the reset outside of interrupt context */ ab@2201: adapter->tx_timeout_count++; ab@2201: schedule_work(&adapter->reset_task); ab@2201: } ab@2201: ab@2201: static void e1000_reset_task(struct work_struct *work) ab@2201: { ab@2201: struct e1000_adapter *adapter = ab@2201: container_of(work, struct e1000_adapter, reset_task); ab@2201: ab@2201: e1000_reinit_locked(adapter); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_get_stats - Get System Network Statistics ab@2201: * @netdev: network interface device structure ab@2201: * ab@2201: * Returns the address of the device statistics structure. ab@2201: * The statistics are actually updated from the timer callback. ab@2201: **/ ab@2201: ab@2201: static struct net_device_stats *e1000_get_stats(struct net_device *netdev) ab@2201: { ab@2201: /* only return the current stats */ ab@2201: return &netdev->stats; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_change_mtu - Change the Maximum Transfer Unit ab@2201: * @netdev: network interface device structure ab@2201: * @new_mtu: new value for maximum frame size ab@2201: * ab@2201: * Returns 0 on success, negative on failure ab@2201: **/ ab@2201: ab@2201: static int e1000_change_mtu(struct net_device *netdev, int new_mtu) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; ab@2201: ab@2201: if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || ab@2201: (max_frame > MAX_JUMBO_FRAME_SIZE)) { ab@2201: DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); ab@2201: return -EINVAL; ab@2201: } ab@2201: ab@2201: /* Adapter-specific max frame size limits. */ ab@2201: switch (hw->mac_type) { ab@2201: case e1000_undefined ... e1000_82542_rev2_1: ab@2201: if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) { ab@2201: DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); ab@2201: return -EINVAL; ab@2201: } ab@2201: break; ab@2201: default: ab@2201: /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ ab@2201: break; ab@2201: } ab@2201: ab@2201: while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) ab@2201: msleep(1); ab@2201: /* e1000_down has a dependency on max_frame_size */ ab@2201: hw->max_frame_size = max_frame; ab@2201: if (netif_running(netdev)) ab@2201: e1000_down(adapter); ab@2201: ab@2201: /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN ab@2201: * means we reserve 2 more, this pushes us to allocate from the next ab@2201: * larger slab size. ab@2201: * i.e. RXBUFFER_2048 --> size-4096 slab ab@2201: * however with the new *_jumbo_rx* routines, jumbo receives will use ab@2201: * fragmented skbs */ ab@2201: ab@2201: if (max_frame <= E1000_RXBUFFER_2048) ab@2201: adapter->rx_buffer_len = E1000_RXBUFFER_2048; ab@2201: else ab@2201: #if (PAGE_SIZE >= E1000_RXBUFFER_16384) ab@2201: adapter->rx_buffer_len = E1000_RXBUFFER_16384; ab@2201: #elif (PAGE_SIZE >= E1000_RXBUFFER_4096) ab@2201: adapter->rx_buffer_len = PAGE_SIZE; ab@2201: #endif ab@2201: ab@2201: /* adjust allocation if LPE protects us, and we aren't using SBP */ ab@2201: if (!hw->tbi_compatibility_on && ab@2201: ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) || ab@2201: (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) ab@2201: adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; ab@2201: ab@2201: printk(KERN_INFO "e1000: %s changing MTU from %d to %d\n", ab@2201: netdev->name, netdev->mtu, new_mtu); ab@2201: netdev->mtu = new_mtu; ab@2201: ab@2201: if (netif_running(netdev)) ab@2201: e1000_up(adapter); ab@2201: else ab@2201: e1000_reset(adapter); ab@2201: ab@2201: clear_bit(__E1000_RESETTING, &adapter->flags); ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_update_stats - Update the board statistics counters ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: ab@2201: void e1000_update_stats(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: unsigned long flags; ab@2201: u16 phy_tmp; ab@2201: ab@2201: #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF ab@2201: ab@2201: /* ab@2201: * Prevent stats update while adapter is being reset, or if the pci ab@2201: * connection is down. ab@2201: */ ab@2201: if (adapter->link_speed == 0) ab@2201: return; ab@2201: if (pci_channel_offline(pdev)) ab@2201: return; ab@2201: ab@2201: spin_lock_irqsave(&adapter->stats_lock, flags); ab@2201: ab@2201: /* these counters are modified from e1000_tbi_adjust_stats, ab@2201: * called from the interrupt context, so they must only ab@2201: * be written while holding adapter->stats_lock ab@2201: */ ab@2201: ab@2201: adapter->stats.crcerrs += er32(CRCERRS); ab@2201: adapter->stats.gprc += er32(GPRC); ab@2201: adapter->stats.gorcl += er32(GORCL); ab@2201: adapter->stats.gorch += er32(GORCH); ab@2201: adapter->stats.bprc += er32(BPRC); ab@2201: adapter->stats.mprc += er32(MPRC); ab@2201: adapter->stats.roc += er32(ROC); ab@2201: ab@2201: adapter->stats.prc64 += er32(PRC64); ab@2201: adapter->stats.prc127 += er32(PRC127); ab@2201: adapter->stats.prc255 += er32(PRC255); ab@2201: adapter->stats.prc511 += er32(PRC511); ab@2201: adapter->stats.prc1023 += er32(PRC1023); ab@2201: adapter->stats.prc1522 += er32(PRC1522); ab@2201: ab@2201: adapter->stats.symerrs += er32(SYMERRS); ab@2201: adapter->stats.mpc += er32(MPC); ab@2201: adapter->stats.scc += er32(SCC); ab@2201: adapter->stats.ecol += er32(ECOL); ab@2201: adapter->stats.mcc += er32(MCC); ab@2201: adapter->stats.latecol += er32(LATECOL); ab@2201: adapter->stats.dc += er32(DC); ab@2201: adapter->stats.sec += er32(SEC); ab@2201: adapter->stats.rlec += er32(RLEC); ab@2201: adapter->stats.xonrxc += er32(XONRXC); ab@2201: adapter->stats.xontxc += er32(XONTXC); ab@2201: adapter->stats.xoffrxc += er32(XOFFRXC); ab@2201: adapter->stats.xofftxc += er32(XOFFTXC); ab@2201: adapter->stats.fcruc += er32(FCRUC); ab@2201: adapter->stats.gptc += er32(GPTC); ab@2201: adapter->stats.gotcl += er32(GOTCL); ab@2201: adapter->stats.gotch += er32(GOTCH); ab@2201: adapter->stats.rnbc += er32(RNBC); ab@2201: adapter->stats.ruc += er32(RUC); ab@2201: adapter->stats.rfc += er32(RFC); ab@2201: adapter->stats.rjc += er32(RJC); ab@2201: adapter->stats.torl += er32(TORL); ab@2201: adapter->stats.torh += er32(TORH); ab@2201: adapter->stats.totl += er32(TOTL); ab@2201: adapter->stats.toth += er32(TOTH); ab@2201: adapter->stats.tpr += er32(TPR); ab@2201: ab@2201: adapter->stats.ptc64 += er32(PTC64); ab@2201: adapter->stats.ptc127 += er32(PTC127); ab@2201: adapter->stats.ptc255 += er32(PTC255); ab@2201: adapter->stats.ptc511 += er32(PTC511); ab@2201: adapter->stats.ptc1023 += er32(PTC1023); ab@2201: adapter->stats.ptc1522 += er32(PTC1522); ab@2201: ab@2201: adapter->stats.mptc += er32(MPTC); ab@2201: adapter->stats.bptc += er32(BPTC); ab@2201: ab@2201: /* used for adaptive IFS */ ab@2201: ab@2201: hw->tx_packet_delta = er32(TPT); ab@2201: adapter->stats.tpt += hw->tx_packet_delta; ab@2201: hw->collision_delta = er32(COLC); ab@2201: adapter->stats.colc += hw->collision_delta; ab@2201: ab@2201: if (hw->mac_type >= e1000_82543) { ab@2201: adapter->stats.algnerrc += er32(ALGNERRC); ab@2201: adapter->stats.rxerrc += er32(RXERRC); ab@2201: adapter->stats.tncrs += er32(TNCRS); ab@2201: adapter->stats.cexterr += er32(CEXTERR); ab@2201: adapter->stats.tsctc += er32(TSCTC); ab@2201: adapter->stats.tsctfc += er32(TSCTFC); ab@2201: } ab@2201: ab@2201: /* Fill out the OS statistics structure */ ab@2201: netdev->stats.multicast = adapter->stats.mprc; ab@2201: netdev->stats.collisions = adapter->stats.colc; ab@2201: ab@2201: /* Rx Errors */ ab@2201: ab@2201: /* RLEC on some newer hardware can be incorrect so build ab@2201: * our own version based on RUC and ROC */ ab@2201: netdev->stats.rx_errors = adapter->stats.rxerrc + ab@2201: adapter->stats.crcerrs + adapter->stats.algnerrc + ab@2201: adapter->stats.ruc + adapter->stats.roc + ab@2201: adapter->stats.cexterr; ab@2201: adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; ab@2201: netdev->stats.rx_length_errors = adapter->stats.rlerrc; ab@2201: netdev->stats.rx_crc_errors = adapter->stats.crcerrs; ab@2201: netdev->stats.rx_frame_errors = adapter->stats.algnerrc; ab@2201: netdev->stats.rx_missed_errors = adapter->stats.mpc; ab@2201: ab@2201: /* Tx Errors */ ab@2201: adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; ab@2201: netdev->stats.tx_errors = adapter->stats.txerrc; ab@2201: netdev->stats.tx_aborted_errors = adapter->stats.ecol; ab@2201: netdev->stats.tx_window_errors = adapter->stats.latecol; ab@2201: netdev->stats.tx_carrier_errors = adapter->stats.tncrs; ab@2201: if (hw->bad_tx_carr_stats_fd && ab@2201: adapter->link_duplex == FULL_DUPLEX) { ab@2201: netdev->stats.tx_carrier_errors = 0; ab@2201: adapter->stats.tncrs = 0; ab@2201: } ab@2201: ab@2201: /* Tx Dropped needs to be maintained elsewhere */ ab@2201: ab@2201: /* Phy Stats */ ab@2201: if (hw->media_type == e1000_media_type_copper) { ab@2201: if ((adapter->link_speed == SPEED_1000) && ab@2201: (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { ab@2201: phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; ab@2201: adapter->phy_stats.idle_errors += phy_tmp; ab@2201: } ab@2201: ab@2201: if ((hw->mac_type <= e1000_82546) && ab@2201: (hw->phy_type == e1000_phy_m88) && ab@2201: !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) ab@2201: adapter->phy_stats.receive_errors += phy_tmp; ab@2201: } ab@2201: ab@2201: /* Management Stats */ ab@2201: if (hw->has_smbus) { ab@2201: adapter->stats.mgptc += er32(MGTPTC); ab@2201: adapter->stats.mgprc += er32(MGTPRC); ab@2201: adapter->stats.mgpdc += er32(MGTPDC); ab@2201: } ab@2201: ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, flags); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_intr - Interrupt Handler ab@2201: * @irq: interrupt number ab@2201: * @data: pointer to a network interface device structure ab@2201: **/ ab@2201: ab@2201: static irqreturn_t e1000_intr(int irq, void *data) ab@2201: { ab@2201: struct net_device *netdev = data; ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 icr = er32(ICR); ab@2201: ab@2201: if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags))) ab@2201: return IRQ_NONE; /* Not our interrupt */ ab@2201: ab@2201: if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { ab@2201: hw->get_link_status = 1; ab@2201: /* guard against interrupt when we're going down */ ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: mod_timer(&adapter->watchdog_timer, jiffies + 1); ab@2201: } ab@2201: ab@2201: /* disable interrupts, without the synchronize_irq bit */ ab@2201: ew32(IMC, ~0); ab@2201: E1000_WRITE_FLUSH(); ab@2201: ab@2201: if (likely(napi_schedule_prep(&adapter->napi))) { ab@2201: adapter->total_tx_bytes = 0; ab@2201: adapter->total_tx_packets = 0; ab@2201: adapter->total_rx_bytes = 0; ab@2201: adapter->total_rx_packets = 0; ab@2201: __napi_schedule(&adapter->napi); ab@2201: } else { ab@2201: /* this really should not happen! if it does it is basically a ab@2201: * bug, but not a hard error, so enable ints and continue */ ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_enable(adapter); ab@2201: } ab@2201: ab@2201: return IRQ_HANDLED; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean - NAPI Rx polling callback ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: static int e1000_clean(struct napi_struct *napi, int budget) ab@2201: { ab@2201: struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); ab@2201: int tx_clean_complete = 0, work_done = 0; ab@2201: ab@2201: tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]); ab@2201: ab@2201: adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget); ab@2201: ab@2201: if (!tx_clean_complete) ab@2201: work_done = budget; ab@2201: ab@2201: /* If budget not fully consumed, exit the polling mode */ ab@2201: if (work_done < budget) { ab@2201: if (likely(adapter->itr_setting & 3)) ab@2201: e1000_set_itr(adapter); ab@2201: napi_complete(napi); ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_enable(adapter); ab@2201: } ab@2201: ab@2201: return work_done; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_tx_irq - Reclaim resources after transmit completes ab@2201: * @adapter: board private structure ab@2201: **/ ab@2201: static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_tx_ring *tx_ring) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct e1000_tx_desc *tx_desc, *eop_desc; ab@2201: struct e1000_buffer *buffer_info; ab@2201: unsigned int i, eop; ab@2201: unsigned int count = 0; ab@2201: unsigned int total_tx_bytes=0, total_tx_packets=0; ab@2201: ab@2201: i = tx_ring->next_to_clean; ab@2201: eop = tx_ring->buffer_info[i].next_to_watch; ab@2201: eop_desc = E1000_TX_DESC(*tx_ring, eop); ab@2201: ab@2201: while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && ab@2201: (count < tx_ring->count)) { ab@2201: bool cleaned = false; ab@2201: for ( ; !cleaned; count++) { ab@2201: tx_desc = E1000_TX_DESC(*tx_ring, i); ab@2201: buffer_info = &tx_ring->buffer_info[i]; ab@2201: cleaned = (i == eop); ab@2201: ab@2201: if (cleaned) { ab@2201: struct sk_buff *skb = buffer_info->skb; ab@2201: unsigned int segs, bytecount; ab@2201: segs = skb_shinfo(skb)->gso_segs ?: 1; ab@2201: /* multiply data chunks by size of headers */ ab@2201: bytecount = ((segs - 1) * skb_headlen(skb)) + ab@2201: skb->len; ab@2201: total_tx_packets += segs; ab@2201: total_tx_bytes += bytecount; ab@2201: } ab@2201: e1000_unmap_and_free_tx_resource(adapter, buffer_info); ab@2201: tx_desc->upper.data = 0; ab@2201: ab@2201: if (unlikely(++i == tx_ring->count)) i = 0; ab@2201: } ab@2201: ab@2201: eop = tx_ring->buffer_info[i].next_to_watch; ab@2201: eop_desc = E1000_TX_DESC(*tx_ring, eop); ab@2201: } ab@2201: ab@2201: tx_ring->next_to_clean = i; ab@2201: ab@2201: #define TX_WAKE_THRESHOLD 32 ab@2201: if (unlikely(count && netif_carrier_ok(netdev) && ab@2201: E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { ab@2201: /* Make sure that anybody stopping the queue after this ab@2201: * sees the new next_to_clean. ab@2201: */ ab@2201: smp_mb(); ab@2201: ab@2201: if (netif_queue_stopped(netdev) && ab@2201: !(test_bit(__E1000_DOWN, &adapter->flags))) { ab@2201: netif_wake_queue(netdev); ab@2201: ++adapter->restart_queue; ab@2201: } ab@2201: } ab@2201: ab@2201: if (adapter->detect_tx_hung) { ab@2201: /* Detect a transmit hang in hardware, this serializes the ab@2201: * check with the clearing of time_stamp and movement of i */ ab@2201: adapter->detect_tx_hung = false; ab@2201: if (tx_ring->buffer_info[eop].time_stamp && ab@2201: time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + ab@2201: (adapter->tx_timeout_factor * HZ)) && ab@2201: !(er32(STATUS) & E1000_STATUS_TXOFF)) { ab@2201: ab@2201: /* detected Tx unit hang */ ab@2201: DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" ab@2201: " Tx Queue <%lu>\n" ab@2201: " TDH <%x>\n" ab@2201: " TDT <%x>\n" ab@2201: " next_to_use <%x>\n" ab@2201: " next_to_clean <%x>\n" ab@2201: "buffer_info[next_to_clean]\n" ab@2201: " time_stamp <%lx>\n" ab@2201: " next_to_watch <%x>\n" ab@2201: " jiffies <%lx>\n" ab@2201: " next_to_watch.status <%x>\n", ab@2201: (unsigned long)((tx_ring - adapter->tx_ring) / ab@2201: sizeof(struct e1000_tx_ring)), ab@2201: readl(hw->hw_addr + tx_ring->tdh), ab@2201: readl(hw->hw_addr + tx_ring->tdt), ab@2201: tx_ring->next_to_use, ab@2201: tx_ring->next_to_clean, ab@2201: tx_ring->buffer_info[eop].time_stamp, ab@2201: eop, ab@2201: jiffies, ab@2201: eop_desc->upper.fields.status); ab@2201: netif_stop_queue(netdev); ab@2201: } ab@2201: } ab@2201: adapter->total_tx_bytes += total_tx_bytes; ab@2201: adapter->total_tx_packets += total_tx_packets; ab@2201: netdev->stats.tx_bytes += total_tx_bytes; ab@2201: netdev->stats.tx_packets += total_tx_packets; ab@2201: return (count < tx_ring->count); ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_rx_checksum - Receive Checksum Offload for 82543 ab@2201: * @adapter: board private structure ab@2201: * @status_err: receive descriptor status and error fields ab@2201: * @csum: receive descriptor csum field ab@2201: * @sk_buff: socket buffer with received data ab@2201: **/ ab@2201: ab@2201: static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, ab@2201: u32 csum, struct sk_buff *skb) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u16 status = (u16)status_err; ab@2201: u8 errors = (u8)(status_err >> 24); ab@2201: skb->ip_summed = CHECKSUM_NONE; ab@2201: ab@2201: /* 82543 or newer only */ ab@2201: if (unlikely(hw->mac_type < e1000_82543)) return; ab@2201: /* Ignore Checksum bit is set */ ab@2201: if (unlikely(status & E1000_RXD_STAT_IXSM)) return; ab@2201: /* TCP/UDP checksum error bit is set */ ab@2201: if (unlikely(errors & E1000_RXD_ERR_TCPE)) { ab@2201: /* let the stack verify checksum errors */ ab@2201: adapter->hw_csum_err++; ab@2201: return; ab@2201: } ab@2201: /* TCP/UDP Checksum has not been calculated */ ab@2201: if (!(status & E1000_RXD_STAT_TCPCS)) ab@2201: return; ab@2201: ab@2201: /* It must be a TCP or UDP packet with a valid checksum */ ab@2201: if (likely(status & E1000_RXD_STAT_TCPCS)) { ab@2201: /* TCP checksum is good */ ab@2201: skb->ip_summed = CHECKSUM_UNNECESSARY; ab@2201: } ab@2201: adapter->hw_csum_good++; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_consume_page - helper function ab@2201: **/ ab@2201: static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, ab@2201: u16 length) ab@2201: { ab@2201: bi->page = NULL; ab@2201: skb->len += length; ab@2201: skb->data_len += length; ab@2201: skb->truesize += length; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_receive_skb - helper function to handle rx indications ab@2201: * @adapter: board private structure ab@2201: * @status: descriptor status field as written by hardware ab@2201: * @vlan: descriptor vlan field as written by hardware (no le/be conversion) ab@2201: * @skb: pointer to sk_buff to be indicated to stack ab@2201: */ ab@2201: static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status, ab@2201: __le16 vlan, struct sk_buff *skb) ab@2201: { ab@2201: if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) { ab@2201: vlan_hwaccel_receive_skb(skb, adapter->vlgrp, ab@2201: le16_to_cpu(vlan) & ab@2201: E1000_RXD_SPC_VLAN_MASK); ab@2201: } else { ab@2201: netif_receive_skb(skb); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy ab@2201: * @adapter: board private structure ab@2201: * @rx_ring: ring to clean ab@2201: * @work_done: amount of napi work completed this call ab@2201: * @work_to_do: max amount of work allowed for this call to do ab@2201: * ab@2201: * the return value indicates whether actual cleaning was done, there ab@2201: * is no guarantee that everything was cleaned ab@2201: */ ab@2201: static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int *work_done, int work_to_do) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: struct e1000_rx_desc *rx_desc, *next_rxd; ab@2201: struct e1000_buffer *buffer_info, *next_buffer; ab@2201: unsigned long irq_flags; ab@2201: u32 length; ab@2201: unsigned int i; ab@2201: int cleaned_count = 0; ab@2201: bool cleaned = false; ab@2201: unsigned int total_rx_bytes=0, total_rx_packets=0; ab@2201: ab@2201: i = rx_ring->next_to_clean; ab@2201: rx_desc = E1000_RX_DESC(*rx_ring, i); ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: ab@2201: while (rx_desc->status & E1000_RXD_STAT_DD) { ab@2201: struct sk_buff *skb; ab@2201: u8 status; ab@2201: ab@2201: if (*work_done >= work_to_do) ab@2201: break; ab@2201: (*work_done)++; ab@2201: ab@2201: status = rx_desc->status; ab@2201: skb = buffer_info->skb; ab@2201: buffer_info->skb = NULL; ab@2201: ab@2201: if (++i == rx_ring->count) i = 0; ab@2201: next_rxd = E1000_RX_DESC(*rx_ring, i); ab@2201: prefetch(next_rxd); ab@2201: ab@2201: next_buffer = &rx_ring->buffer_info[i]; ab@2201: ab@2201: cleaned = true; ab@2201: cleaned_count++; ab@2201: pci_unmap_page(pdev, buffer_info->dma, buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: buffer_info->dma = 0; ab@2201: ab@2201: length = le16_to_cpu(rx_desc->length); ab@2201: ab@2201: /* errors is only valid for DD + EOP descriptors */ ab@2201: if (unlikely((status & E1000_RXD_STAT_EOP) && ab@2201: (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { ab@2201: u8 last_byte = *(skb->data + length - 1); ab@2201: if (TBI_ACCEPT(hw, status, rx_desc->errors, length, ab@2201: last_byte)) { ab@2201: spin_lock_irqsave(&adapter->stats_lock, ab@2201: irq_flags); ab@2201: e1000_tbi_adjust_stats(hw, &adapter->stats, ab@2201: length, skb->data); ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, ab@2201: irq_flags); ab@2201: length--; ab@2201: } else { ab@2201: /* recycle both page and skb */ ab@2201: buffer_info->skb = skb; ab@2201: /* an error means any chain goes out the window ab@2201: * too */ ab@2201: if (rx_ring->rx_skb_top) ab@2201: dev_kfree_skb(rx_ring->rx_skb_top); ab@2201: rx_ring->rx_skb_top = NULL; ab@2201: goto next_desc; ab@2201: } ab@2201: } ab@2201: ab@2201: #define rxtop rx_ring->rx_skb_top ab@2201: if (!(status & E1000_RXD_STAT_EOP)) { ab@2201: /* this descriptor is only the beginning (or middle) */ ab@2201: if (!rxtop) { ab@2201: /* this is the beginning of a chain */ ab@2201: rxtop = skb; ab@2201: skb_fill_page_desc(rxtop, 0, buffer_info->page, ab@2201: 0, length); ab@2201: } else { ab@2201: /* this is the middle of a chain */ ab@2201: skb_fill_page_desc(rxtop, ab@2201: skb_shinfo(rxtop)->nr_frags, ab@2201: buffer_info->page, 0, length); ab@2201: /* re-use the skb, only consumed the page */ ab@2201: buffer_info->skb = skb; ab@2201: } ab@2201: e1000_consume_page(buffer_info, rxtop, length); ab@2201: goto next_desc; ab@2201: } else { ab@2201: if (rxtop) { ab@2201: /* end of the chain */ ab@2201: skb_fill_page_desc(rxtop, ab@2201: skb_shinfo(rxtop)->nr_frags, ab@2201: buffer_info->page, 0, length); ab@2201: /* re-use the current skb, we only consumed the ab@2201: * page */ ab@2201: buffer_info->skb = skb; ab@2201: skb = rxtop; ab@2201: rxtop = NULL; ab@2201: e1000_consume_page(buffer_info, skb, length); ab@2201: } else { ab@2201: /* no chain, got EOP, this buf is the packet ab@2201: * copybreak to save the put_page/alloc_page */ ab@2201: if (length <= copybreak && ab@2201: skb_tailroom(skb) >= length) { ab@2201: u8 *vaddr; ab@2201: vaddr = kmap_atomic(buffer_info->page, ab@2201: KM_SKB_DATA_SOFTIRQ); ab@2201: memcpy(skb_tail_pointer(skb), vaddr, length); ab@2201: kunmap_atomic(vaddr, ab@2201: KM_SKB_DATA_SOFTIRQ); ab@2201: /* re-use the page, so don't erase ab@2201: * buffer_info->page */ ab@2201: skb_put(skb, length); ab@2201: } else { ab@2201: skb_fill_page_desc(skb, 0, ab@2201: buffer_info->page, 0, ab@2201: length); ab@2201: e1000_consume_page(buffer_info, skb, ab@2201: length); ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: /* Receive Checksum Offload XXX recompute due to CRC strip? */ ab@2201: e1000_rx_checksum(adapter, ab@2201: (u32)(status) | ab@2201: ((u32)(rx_desc->errors) << 24), ab@2201: le16_to_cpu(rx_desc->csum), skb); ab@2201: ab@2201: pskb_trim(skb, skb->len - 4); ab@2201: ab@2201: /* probably a little skewed due to removing CRC */ ab@2201: total_rx_bytes += skb->len; ab@2201: total_rx_packets++; ab@2201: ab@2201: /* eth type trans needs skb->data to point to something */ ab@2201: if (!pskb_may_pull(skb, ETH_HLEN)) { ab@2201: DPRINTK(DRV, ERR, "pskb_may_pull failed.\n"); ab@2201: dev_kfree_skb(skb); ab@2201: goto next_desc; ab@2201: } ab@2201: ab@2201: skb->protocol = eth_type_trans(skb, netdev); ab@2201: ab@2201: e1000_receive_skb(adapter, status, rx_desc->special, skb); ab@2201: ab@2201: next_desc: ab@2201: rx_desc->status = 0; ab@2201: ab@2201: /* return some buffers to hardware, one at a time is too slow */ ab@2201: if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { ab@2201: adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); ab@2201: cleaned_count = 0; ab@2201: } ab@2201: ab@2201: /* use prefetched values */ ab@2201: rx_desc = next_rxd; ab@2201: buffer_info = next_buffer; ab@2201: } ab@2201: rx_ring->next_to_clean = i; ab@2201: ab@2201: cleaned_count = E1000_DESC_UNUSED(rx_ring); ab@2201: if (cleaned_count) ab@2201: adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); ab@2201: ab@2201: adapter->total_rx_packets += total_rx_packets; ab@2201: adapter->total_rx_bytes += total_rx_bytes; ab@2201: netdev->stats.rx_bytes += total_rx_bytes; ab@2201: netdev->stats.rx_packets += total_rx_packets; ab@2201: return cleaned; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_clean_rx_irq - Send received data up the network stack; legacy ab@2201: * @adapter: board private structure ab@2201: * @rx_ring: ring to clean ab@2201: * @work_done: amount of napi work completed this call ab@2201: * @work_to_do: max amount of work allowed for this call to do ab@2201: */ ab@2201: static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int *work_done, int work_to_do) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: struct e1000_rx_desc *rx_desc, *next_rxd; ab@2201: struct e1000_buffer *buffer_info, *next_buffer; ab@2201: unsigned long flags; ab@2201: u32 length; ab@2201: unsigned int i; ab@2201: int cleaned_count = 0; ab@2201: bool cleaned = false; ab@2201: unsigned int total_rx_bytes=0, total_rx_packets=0; ab@2201: ab@2201: i = rx_ring->next_to_clean; ab@2201: rx_desc = E1000_RX_DESC(*rx_ring, i); ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: ab@2201: while (rx_desc->status & E1000_RXD_STAT_DD) { ab@2201: struct sk_buff *skb; ab@2201: u8 status; ab@2201: ab@2201: if (*work_done >= work_to_do) ab@2201: break; ab@2201: (*work_done)++; ab@2201: ab@2201: status = rx_desc->status; ab@2201: skb = buffer_info->skb; ab@2201: buffer_info->skb = NULL; ab@2201: ab@2201: prefetch(skb->data - NET_IP_ALIGN); ab@2201: ab@2201: if (++i == rx_ring->count) i = 0; ab@2201: next_rxd = E1000_RX_DESC(*rx_ring, i); ab@2201: prefetch(next_rxd); ab@2201: ab@2201: next_buffer = &rx_ring->buffer_info[i]; ab@2201: ab@2201: cleaned = true; ab@2201: cleaned_count++; ab@2201: pci_unmap_single(pdev, buffer_info->dma, buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: buffer_info->dma = 0; ab@2201: ab@2201: length = le16_to_cpu(rx_desc->length); ab@2201: /* !EOP means multiple descriptors were used to store a single ab@2201: * packet, if thats the case we need to toss it. In fact, we ab@2201: * to toss every packet with the EOP bit clear and the next ab@2201: * frame that _does_ have the EOP bit set, as it is by ab@2201: * definition only a frame fragment ab@2201: */ ab@2201: if (unlikely(!(status & E1000_RXD_STAT_EOP))) ab@2201: adapter->discarding = true; ab@2201: ab@2201: if (adapter->discarding) { ab@2201: /* All receives must fit into a single buffer */ ab@2201: E1000_DBG("%s: Receive packet consumed multiple" ab@2201: " buffers\n", netdev->name); ab@2201: /* recycle */ ab@2201: buffer_info->skb = skb; ab@2201: if (status & E1000_RXD_STAT_EOP) ab@2201: adapter->discarding = false; ab@2201: goto next_desc; ab@2201: } ab@2201: ab@2201: if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { ab@2201: u8 last_byte = *(skb->data + length - 1); ab@2201: if (TBI_ACCEPT(hw, status, rx_desc->errors, length, ab@2201: last_byte)) { ab@2201: spin_lock_irqsave(&adapter->stats_lock, flags); ab@2201: e1000_tbi_adjust_stats(hw, &adapter->stats, ab@2201: length, skb->data); ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, ab@2201: flags); ab@2201: length--; ab@2201: } else { ab@2201: /* recycle */ ab@2201: buffer_info->skb = skb; ab@2201: goto next_desc; ab@2201: } ab@2201: } ab@2201: ab@2201: /* adjust length to remove Ethernet CRC, this must be ab@2201: * done after the TBI_ACCEPT workaround above */ ab@2201: length -= 4; ab@2201: ab@2201: /* probably a little skewed due to removing CRC */ ab@2201: total_rx_bytes += length; ab@2201: total_rx_packets++; ab@2201: ab@2201: /* code added for copybreak, this should improve ab@2201: * performance for small packets with large amounts ab@2201: * of reassembly being done in the stack */ ab@2201: if (length < copybreak) { ab@2201: struct sk_buff *new_skb = ab@2201: netdev_alloc_skb_ip_align(netdev, length); ab@2201: if (new_skb) { ab@2201: skb_copy_to_linear_data_offset(new_skb, ab@2201: -NET_IP_ALIGN, ab@2201: (skb->data - ab@2201: NET_IP_ALIGN), ab@2201: (length + ab@2201: NET_IP_ALIGN)); ab@2201: /* save the skb in buffer_info as good */ ab@2201: buffer_info->skb = skb; ab@2201: skb = new_skb; ab@2201: } ab@2201: /* else just continue with the old one */ ab@2201: } ab@2201: /* end copybreak code */ ab@2201: skb_put(skb, length); ab@2201: ab@2201: /* Receive Checksum Offload */ ab@2201: e1000_rx_checksum(adapter, ab@2201: (u32)(status) | ab@2201: ((u32)(rx_desc->errors) << 24), ab@2201: le16_to_cpu(rx_desc->csum), skb); ab@2201: ab@2201: skb->protocol = eth_type_trans(skb, netdev); ab@2201: ab@2201: e1000_receive_skb(adapter, status, rx_desc->special, skb); ab@2201: ab@2201: next_desc: ab@2201: rx_desc->status = 0; ab@2201: ab@2201: /* return some buffers to hardware, one at a time is too slow */ ab@2201: if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { ab@2201: adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); ab@2201: cleaned_count = 0; ab@2201: } ab@2201: ab@2201: /* use prefetched values */ ab@2201: rx_desc = next_rxd; ab@2201: buffer_info = next_buffer; ab@2201: } ab@2201: rx_ring->next_to_clean = i; ab@2201: ab@2201: cleaned_count = E1000_DESC_UNUSED(rx_ring); ab@2201: if (cleaned_count) ab@2201: adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); ab@2201: ab@2201: adapter->total_rx_packets += total_rx_packets; ab@2201: adapter->total_rx_bytes += total_rx_bytes; ab@2201: netdev->stats.rx_bytes += total_rx_bytes; ab@2201: netdev->stats.rx_packets += total_rx_packets; ab@2201: return cleaned; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers ab@2201: * @adapter: address of board private structure ab@2201: * @rx_ring: pointer to receive ring structure ab@2201: * @cleaned_count: number of buffers to allocate this pass ab@2201: **/ ab@2201: ab@2201: static void ab@2201: e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, int cleaned_count) ab@2201: { ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: struct e1000_rx_desc *rx_desc; ab@2201: struct e1000_buffer *buffer_info; ab@2201: struct sk_buff *skb; ab@2201: unsigned int i; ab@2201: unsigned int bufsz = 256 - 16 /*for skb_reserve */ ; ab@2201: ab@2201: i = rx_ring->next_to_use; ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: ab@2201: while (cleaned_count--) { ab@2201: skb = buffer_info->skb; ab@2201: if (skb) { ab@2201: skb_trim(skb, 0); ab@2201: goto check_page; ab@2201: } ab@2201: ab@2201: skb = netdev_alloc_skb_ip_align(netdev, bufsz); ab@2201: if (unlikely(!skb)) { ab@2201: /* Better luck next round */ ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Fix for errata 23, can't cross 64kB boundary */ ab@2201: if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { ab@2201: struct sk_buff *oldskb = skb; ab@2201: DPRINTK(PROBE, ERR, "skb align check failed: %u bytes " ab@2201: "at %p\n", bufsz, skb->data); ab@2201: /* Try again, without freeing the previous */ ab@2201: skb = netdev_alloc_skb_ip_align(netdev, bufsz); ab@2201: /* Failed allocation, critical failure */ ab@2201: if (!skb) { ab@2201: dev_kfree_skb(oldskb); ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; ab@2201: } ab@2201: ab@2201: if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { ab@2201: /* give up */ ab@2201: dev_kfree_skb(skb); ab@2201: dev_kfree_skb(oldskb); ab@2201: break; /* while (cleaned_count--) */ ab@2201: } ab@2201: ab@2201: /* Use new allocation */ ab@2201: dev_kfree_skb(oldskb); ab@2201: } ab@2201: buffer_info->skb = skb; ab@2201: buffer_info->length = adapter->rx_buffer_len; ab@2201: check_page: ab@2201: /* allocate a new page if necessary */ ab@2201: if (!buffer_info->page) { ab@2201: buffer_info->page = alloc_page(GFP_ATOMIC); ab@2201: if (unlikely(!buffer_info->page)) { ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; ab@2201: } ab@2201: } ab@2201: ab@2201: if (!buffer_info->dma) { ab@2201: buffer_info->dma = pci_map_page(pdev, ab@2201: buffer_info->page, 0, ab@2201: buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: if (pci_dma_mapping_error(pdev, buffer_info->dma)) { ab@2201: put_page(buffer_info->page); ab@2201: dev_kfree_skb(skb); ab@2201: buffer_info->page = NULL; ab@2201: buffer_info->skb = NULL; ab@2201: buffer_info->dma = 0; ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; /* while !buffer_info->skb */ ab@2201: } ab@2201: } ab@2201: ab@2201: rx_desc = E1000_RX_DESC(*rx_ring, i); ab@2201: rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); ab@2201: ab@2201: if (unlikely(++i == rx_ring->count)) ab@2201: i = 0; ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: } ab@2201: ab@2201: if (likely(rx_ring->next_to_use != i)) { ab@2201: rx_ring->next_to_use = i; ab@2201: if (unlikely(i-- == 0)) ab@2201: i = (rx_ring->count - 1); ab@2201: ab@2201: /* Force memory writes to complete before letting h/w ab@2201: * know there are new descriptors to fetch. (Only ab@2201: * applicable for weak-ordered memory model archs, ab@2201: * such as IA-64). */ ab@2201: wmb(); ab@2201: writel(i, adapter->hw.hw_addr + rx_ring->rdt); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended ab@2201: * @adapter: address of board private structure ab@2201: **/ ab@2201: ab@2201: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, ab@2201: struct e1000_rx_ring *rx_ring, ab@2201: int cleaned_count) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct net_device *netdev = adapter->netdev; ab@2201: struct pci_dev *pdev = adapter->pdev; ab@2201: struct e1000_rx_desc *rx_desc; ab@2201: struct e1000_buffer *buffer_info; ab@2201: struct sk_buff *skb; ab@2201: unsigned int i; ab@2201: unsigned int bufsz = adapter->rx_buffer_len; ab@2201: ab@2201: i = rx_ring->next_to_use; ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: ab@2201: while (cleaned_count--) { ab@2201: skb = buffer_info->skb; ab@2201: if (skb) { ab@2201: skb_trim(skb, 0); ab@2201: goto map_skb; ab@2201: } ab@2201: ab@2201: skb = netdev_alloc_skb_ip_align(netdev, bufsz); ab@2201: if (unlikely(!skb)) { ab@2201: /* Better luck next round */ ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; ab@2201: } ab@2201: ab@2201: /* Fix for errata 23, can't cross 64kB boundary */ ab@2201: if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { ab@2201: struct sk_buff *oldskb = skb; ab@2201: DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " ab@2201: "at %p\n", bufsz, skb->data); ab@2201: /* Try again, without freeing the previous */ ab@2201: skb = netdev_alloc_skb_ip_align(netdev, bufsz); ab@2201: /* Failed allocation, critical failure */ ab@2201: if (!skb) { ab@2201: dev_kfree_skb(oldskb); ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; ab@2201: } ab@2201: ab@2201: if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { ab@2201: /* give up */ ab@2201: dev_kfree_skb(skb); ab@2201: dev_kfree_skb(oldskb); ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; /* while !buffer_info->skb */ ab@2201: } ab@2201: ab@2201: /* Use new allocation */ ab@2201: dev_kfree_skb(oldskb); ab@2201: } ab@2201: buffer_info->skb = skb; ab@2201: buffer_info->length = adapter->rx_buffer_len; ab@2201: map_skb: ab@2201: buffer_info->dma = pci_map_single(pdev, ab@2201: skb->data, ab@2201: buffer_info->length, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: if (pci_dma_mapping_error(pdev, buffer_info->dma)) { ab@2201: dev_kfree_skb(skb); ab@2201: buffer_info->skb = NULL; ab@2201: buffer_info->dma = 0; ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; /* while !buffer_info->skb */ ab@2201: } ab@2201: ab@2201: /* ab@2201: * XXX if it was allocated cleanly it will never map to a ab@2201: * boundary crossing ab@2201: */ ab@2201: ab@2201: /* Fix for errata 23, can't cross 64kB boundary */ ab@2201: if (!e1000_check_64k_bound(adapter, ab@2201: (void *)(unsigned long)buffer_info->dma, ab@2201: adapter->rx_buffer_len)) { ab@2201: DPRINTK(RX_ERR, ERR, ab@2201: "dma align check failed: %u bytes at %p\n", ab@2201: adapter->rx_buffer_len, ab@2201: (void *)(unsigned long)buffer_info->dma); ab@2201: dev_kfree_skb(skb); ab@2201: buffer_info->skb = NULL; ab@2201: ab@2201: pci_unmap_single(pdev, buffer_info->dma, ab@2201: adapter->rx_buffer_len, ab@2201: PCI_DMA_FROMDEVICE); ab@2201: buffer_info->dma = 0; ab@2201: ab@2201: adapter->alloc_rx_buff_failed++; ab@2201: break; /* while !buffer_info->skb */ ab@2201: } ab@2201: rx_desc = E1000_RX_DESC(*rx_ring, i); ab@2201: rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); ab@2201: ab@2201: if (unlikely(++i == rx_ring->count)) ab@2201: i = 0; ab@2201: buffer_info = &rx_ring->buffer_info[i]; ab@2201: } ab@2201: ab@2201: if (likely(rx_ring->next_to_use != i)) { ab@2201: rx_ring->next_to_use = i; ab@2201: if (unlikely(i-- == 0)) ab@2201: i = (rx_ring->count - 1); ab@2201: ab@2201: /* Force memory writes to complete before letting h/w ab@2201: * know there are new descriptors to fetch. (Only ab@2201: * applicable for weak-ordered memory model archs, ab@2201: * such as IA-64). */ ab@2201: wmb(); ab@2201: writel(i, hw->hw_addr + rx_ring->rdt); ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. ab@2201: * @adapter: ab@2201: **/ ab@2201: ab@2201: static void e1000_smartspeed(struct e1000_adapter *adapter) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u16 phy_status; ab@2201: u16 phy_ctrl; ab@2201: ab@2201: if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg || ab@2201: !(hw->autoneg_advertised & ADVERTISE_1000_FULL)) ab@2201: return; ab@2201: ab@2201: if (adapter->smartspeed == 0) { ab@2201: /* If Master/Slave config fault is asserted twice, ab@2201: * we assume back-to-back */ ab@2201: e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); ab@2201: if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; ab@2201: e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); ab@2201: if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; ab@2201: e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); ab@2201: if (phy_ctrl & CR_1000T_MS_ENABLE) { ab@2201: phy_ctrl &= ~CR_1000T_MS_ENABLE; ab@2201: e1000_write_phy_reg(hw, PHY_1000T_CTRL, ab@2201: phy_ctrl); ab@2201: adapter->smartspeed++; ab@2201: if (!e1000_phy_setup_autoneg(hw) && ab@2201: !e1000_read_phy_reg(hw, PHY_CTRL, ab@2201: &phy_ctrl)) { ab@2201: phy_ctrl |= (MII_CR_AUTO_NEG_EN | ab@2201: MII_CR_RESTART_AUTO_NEG); ab@2201: e1000_write_phy_reg(hw, PHY_CTRL, ab@2201: phy_ctrl); ab@2201: } ab@2201: } ab@2201: return; ab@2201: } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { ab@2201: /* If still no link, perhaps using 2/3 pair cable */ ab@2201: e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); ab@2201: phy_ctrl |= CR_1000T_MS_ENABLE; ab@2201: e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); ab@2201: if (!e1000_phy_setup_autoneg(hw) && ab@2201: !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) { ab@2201: phy_ctrl |= (MII_CR_AUTO_NEG_EN | ab@2201: MII_CR_RESTART_AUTO_NEG); ab@2201: e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl); ab@2201: } ab@2201: } ab@2201: /* Restart process after E1000_SMARTSPEED_MAX iterations */ ab@2201: if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) ab@2201: adapter->smartspeed = 0; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_ioctl - ab@2201: * @netdev: ab@2201: * @ifreq: ab@2201: * @cmd: ab@2201: **/ ab@2201: ab@2201: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) ab@2201: { ab@2201: switch (cmd) { ab@2201: case SIOCGMIIPHY: ab@2201: case SIOCGMIIREG: ab@2201: case SIOCSMIIREG: ab@2201: return e1000_mii_ioctl(netdev, ifr, cmd); ab@2201: default: ab@2201: return -EOPNOTSUPP; ab@2201: } ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_mii_ioctl - ab@2201: * @netdev: ab@2201: * @ifreq: ab@2201: * @cmd: ab@2201: **/ ab@2201: ab@2201: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, ab@2201: int cmd) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: struct mii_ioctl_data *data = if_mii(ifr); ab@2201: int retval; ab@2201: u16 mii_reg; ab@2201: u16 spddplx; ab@2201: unsigned long flags; ab@2201: ab@2201: if (hw->media_type != e1000_media_type_copper) ab@2201: return -EOPNOTSUPP; ab@2201: ab@2201: switch (cmd) { ab@2201: case SIOCGMIIPHY: ab@2201: data->phy_id = hw->phy_addr; ab@2201: break; ab@2201: case SIOCGMIIREG: ab@2201: spin_lock_irqsave(&adapter->stats_lock, flags); ab@2201: if (e1000_read_phy_reg(hw, data->reg_num & 0x1F, ab@2201: &data->val_out)) { ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, flags); ab@2201: return -EIO; ab@2201: } ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, flags); ab@2201: break; ab@2201: case SIOCSMIIREG: ab@2201: if (data->reg_num & ~(0x1F)) ab@2201: return -EFAULT; ab@2201: mii_reg = data->val_in; ab@2201: spin_lock_irqsave(&adapter->stats_lock, flags); ab@2201: if (e1000_write_phy_reg(hw, data->reg_num, ab@2201: mii_reg)) { ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, flags); ab@2201: return -EIO; ab@2201: } ab@2201: spin_unlock_irqrestore(&adapter->stats_lock, flags); ab@2201: if (hw->media_type == e1000_media_type_copper) { ab@2201: switch (data->reg_num) { ab@2201: case PHY_CTRL: ab@2201: if (mii_reg & MII_CR_POWER_DOWN) ab@2201: break; ab@2201: if (mii_reg & MII_CR_AUTO_NEG_EN) { ab@2201: hw->autoneg = 1; ab@2201: hw->autoneg_advertised = 0x2F; ab@2201: } else { ab@2201: if (mii_reg & 0x40) ab@2201: spddplx = SPEED_1000; ab@2201: else if (mii_reg & 0x2000) ab@2201: spddplx = SPEED_100; ab@2201: else ab@2201: spddplx = SPEED_10; ab@2201: spddplx += (mii_reg & 0x100) ab@2201: ? DUPLEX_FULL : ab@2201: DUPLEX_HALF; ab@2201: retval = e1000_set_spd_dplx(adapter, ab@2201: spddplx); ab@2201: if (retval) ab@2201: return retval; ab@2201: } ab@2201: if (netif_running(adapter->netdev)) ab@2201: e1000_reinit_locked(adapter); ab@2201: else ab@2201: e1000_reset(adapter); ab@2201: break; ab@2201: case M88E1000_PHY_SPEC_CTRL: ab@2201: case M88E1000_EXT_PHY_SPEC_CTRL: ab@2201: if (e1000_phy_reset(hw)) ab@2201: return -EIO; ab@2201: break; ab@2201: } ab@2201: } else { ab@2201: switch (data->reg_num) { ab@2201: case PHY_CTRL: ab@2201: if (mii_reg & MII_CR_POWER_DOWN) ab@2201: break; ab@2201: if (netif_running(adapter->netdev)) ab@2201: e1000_reinit_locked(adapter); ab@2201: else ab@2201: e1000_reset(adapter); ab@2201: break; ab@2201: } ab@2201: } ab@2201: break; ab@2201: default: ab@2201: return -EOPNOTSUPP; ab@2201: } ab@2201: return E1000_SUCCESS; ab@2201: } ab@2201: ab@2201: void e1000_pci_set_mwi(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_adapter *adapter = hw->back; ab@2201: int ret_val = pci_set_mwi(adapter->pdev); ab@2201: ab@2201: if (ret_val) ab@2201: DPRINTK(PROBE, ERR, "Error in setting MWI\n"); ab@2201: } ab@2201: ab@2201: void e1000_pci_clear_mwi(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_adapter *adapter = hw->back; ab@2201: ab@2201: pci_clear_mwi(adapter->pdev); ab@2201: } ab@2201: ab@2201: int e1000_pcix_get_mmrbc(struct e1000_hw *hw) ab@2201: { ab@2201: struct e1000_adapter *adapter = hw->back; ab@2201: return pcix_get_mmrbc(adapter->pdev); ab@2201: } ab@2201: ab@2201: void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) ab@2201: { ab@2201: struct e1000_adapter *adapter = hw->back; ab@2201: pcix_set_mmrbc(adapter->pdev, mmrbc); ab@2201: } ab@2201: ab@2201: void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value) ab@2201: { ab@2201: outl(value, port); ab@2201: } ab@2201: ab@2201: static void e1000_vlan_rx_register(struct net_device *netdev, ab@2201: struct vlan_group *grp) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 ctrl, rctl; ab@2201: ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_disable(adapter); ab@2201: adapter->vlgrp = grp; ab@2201: ab@2201: if (grp) { ab@2201: /* enable VLAN tag insert/strip */ ab@2201: ctrl = er32(CTRL); ab@2201: ctrl |= E1000_CTRL_VME; ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: /* enable VLAN receive filtering */ ab@2201: rctl = er32(RCTL); ab@2201: rctl &= ~E1000_RCTL_CFIEN; ab@2201: if (!(netdev->flags & IFF_PROMISC)) ab@2201: rctl |= E1000_RCTL_VFE; ab@2201: ew32(RCTL, rctl); ab@2201: e1000_update_mng_vlan(adapter); ab@2201: } else { ab@2201: /* disable VLAN tag insert/strip */ ab@2201: ctrl = er32(CTRL); ab@2201: ctrl &= ~E1000_CTRL_VME; ab@2201: ew32(CTRL, ctrl); ab@2201: ab@2201: /* disable VLAN receive filtering */ ab@2201: rctl = er32(RCTL); ab@2201: rctl &= ~E1000_RCTL_VFE; ab@2201: ew32(RCTL, rctl); ab@2201: ab@2201: if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { ab@2201: e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); ab@2201: adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; ab@2201: } ab@2201: } ab@2201: ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_enable(adapter); ab@2201: } ab@2201: ab@2201: static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 vfta, index; ab@2201: ab@2201: if ((hw->mng_cookie.status & ab@2201: E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && ab@2201: (vid == adapter->mng_vlan_id)) ab@2201: return; ab@2201: /* add VID to filter table */ ab@2201: index = (vid >> 5) & 0x7F; ab@2201: vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); ab@2201: vfta |= (1 << (vid & 0x1F)); ab@2201: e1000_write_vfta(hw, index, vfta); ab@2201: } ab@2201: ab@2201: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 vfta, index; ab@2201: ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_disable(adapter); ab@2201: vlan_group_set_device(adapter->vlgrp, vid, NULL); ab@2201: if (!test_bit(__E1000_DOWN, &adapter->flags)) ab@2201: e1000_irq_enable(adapter); ab@2201: ab@2201: /* remove VID from filter table */ ab@2201: index = (vid >> 5) & 0x7F; ab@2201: vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); ab@2201: vfta &= ~(1 << (vid & 0x1F)); ab@2201: e1000_write_vfta(hw, index, vfta); ab@2201: } ab@2201: ab@2201: static void e1000_restore_vlan(struct e1000_adapter *adapter) ab@2201: { ab@2201: e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); ab@2201: ab@2201: if (adapter->vlgrp) { ab@2201: u16 vid; ab@2201: for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { ab@2201: if (!vlan_group_get_device(adapter->vlgrp, vid)) ab@2201: continue; ab@2201: e1000_vlan_rx_add_vid(adapter->netdev, vid); ab@2201: } ab@2201: } ab@2201: } ab@2201: ab@2201: int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) ab@2201: { ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: ab@2201: hw->autoneg = 0; ab@2201: ab@2201: /* Fiber NICs only allow 1000 gbps Full duplex */ ab@2201: if ((hw->media_type == e1000_media_type_fiber) && ab@2201: spddplx != (SPEED_1000 + DUPLEX_FULL)) { ab@2201: DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); ab@2201: return -EINVAL; ab@2201: } ab@2201: ab@2201: switch (spddplx) { ab@2201: case SPEED_10 + DUPLEX_HALF: ab@2201: hw->forced_speed_duplex = e1000_10_half; ab@2201: break; ab@2201: case SPEED_10 + DUPLEX_FULL: ab@2201: hw->forced_speed_duplex = e1000_10_full; ab@2201: break; ab@2201: case SPEED_100 + DUPLEX_HALF: ab@2201: hw->forced_speed_duplex = e1000_100_half; ab@2201: break; ab@2201: case SPEED_100 + DUPLEX_FULL: ab@2201: hw->forced_speed_duplex = e1000_100_full; ab@2201: break; ab@2201: case SPEED_1000 + DUPLEX_FULL: ab@2201: hw->autoneg = 1; ab@2201: hw->autoneg_advertised = ADVERTISE_1000_FULL; ab@2201: break; ab@2201: case SPEED_1000 + DUPLEX_HALF: /* not supported */ ab@2201: default: ab@2201: DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); ab@2201: return -EINVAL; ab@2201: } ab@2201: return 0; ab@2201: } ab@2201: ab@2201: static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 ctrl, ctrl_ext, rctl, status; ab@2201: u32 wufc = adapter->wol; ab@2201: #ifdef CONFIG_PM ab@2201: int retval = 0; ab@2201: #endif ab@2201: ab@2201: netif_device_detach(netdev); ab@2201: ab@2201: if (netif_running(netdev)) { ab@2201: WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); ab@2201: e1000_down(adapter); ab@2201: } ab@2201: ab@2201: #ifdef CONFIG_PM ab@2201: retval = pci_save_state(pdev); ab@2201: if (retval) ab@2201: return retval; ab@2201: #endif ab@2201: ab@2201: status = er32(STATUS); ab@2201: if (status & E1000_STATUS_LU) ab@2201: wufc &= ~E1000_WUFC_LNKC; ab@2201: ab@2201: if (wufc) { ab@2201: e1000_setup_rctl(adapter); ab@2201: e1000_set_rx_mode(netdev); ab@2201: ab@2201: /* turn on all-multi mode if wake on multicast is enabled */ ab@2201: if (wufc & E1000_WUFC_MC) { ab@2201: rctl = er32(RCTL); ab@2201: rctl |= E1000_RCTL_MPE; ab@2201: ew32(RCTL, rctl); ab@2201: } ab@2201: ab@2201: if (hw->mac_type >= e1000_82540) { ab@2201: ctrl = er32(CTRL); ab@2201: /* advertise wake from D3Cold */ ab@2201: #define E1000_CTRL_ADVD3WUC 0x00100000 ab@2201: /* phy power management enable */ ab@2201: #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 ab@2201: ctrl |= E1000_CTRL_ADVD3WUC | ab@2201: E1000_CTRL_EN_PHY_PWR_MGMT; ab@2201: ew32(CTRL, ctrl); ab@2201: } ab@2201: ab@2201: if (hw->media_type == e1000_media_type_fiber || ab@2201: hw->media_type == e1000_media_type_internal_serdes) { ab@2201: /* keep the laser running in D3 */ ab@2201: ctrl_ext = er32(CTRL_EXT); ab@2201: ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; ab@2201: ew32(CTRL_EXT, ctrl_ext); ab@2201: } ab@2201: ab@2201: ew32(WUC, E1000_WUC_PME_EN); ab@2201: ew32(WUFC, wufc); ab@2201: } else { ab@2201: ew32(WUC, 0); ab@2201: ew32(WUFC, 0); ab@2201: } ab@2201: ab@2201: e1000_release_manageability(adapter); ab@2201: ab@2201: *enable_wake = !!wufc; ab@2201: ab@2201: /* make sure adapter isn't asleep if manageability is enabled */ ab@2201: if (adapter->en_mng_pt) ab@2201: *enable_wake = true; ab@2201: ab@2201: if (netif_running(netdev)) ab@2201: e1000_free_irq(adapter); ab@2201: ab@2201: pci_disable_device(pdev); ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: #ifdef CONFIG_PM ab@2201: static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) ab@2201: { ab@2201: int retval; ab@2201: bool wake; ab@2201: ab@2201: retval = __e1000_shutdown(pdev, &wake); ab@2201: if (retval) ab@2201: return retval; ab@2201: ab@2201: if (wake) { ab@2201: pci_prepare_to_sleep(pdev); ab@2201: } else { ab@2201: pci_wake_from_d3(pdev, false); ab@2201: pci_set_power_state(pdev, PCI_D3hot); ab@2201: } ab@2201: ab@2201: return 0; ab@2201: } ab@2201: ab@2201: static int e1000_resume(struct pci_dev *pdev) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: u32 err; ab@2201: ab@2201: pci_set_power_state(pdev, PCI_D0); ab@2201: pci_restore_state(pdev); ab@2201: ab@2201: if (adapter->need_ioport) ab@2201: err = pci_enable_device(pdev); ab@2201: else ab@2201: err = pci_enable_device_mem(pdev); ab@2201: if (err) { ab@2201: printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); ab@2201: return err; ab@2201: } ab@2201: pci_set_master(pdev); ab@2201: ab@2201: pci_enable_wake(pdev, PCI_D3hot, 0); ab@2201: pci_enable_wake(pdev, PCI_D3cold, 0); ab@2201: ab@2201: if (netif_running(netdev)) { ab@2201: err = e1000_request_irq(adapter); ab@2201: if (err) ab@2201: return err; ab@2201: } ab@2201: ab@2201: e1000_power_up_phy(adapter); ab@2201: e1000_reset(adapter); ab@2201: ew32(WUS, ~0); ab@2201: ab@2201: e1000_init_manageability(adapter); ab@2201: ab@2201: if (netif_running(netdev)) ab@2201: e1000_up(adapter); ab@2201: ab@2201: netif_device_attach(netdev); ab@2201: ab@2201: return 0; ab@2201: } ab@2201: #endif ab@2201: ab@2201: static void e1000_shutdown(struct pci_dev *pdev) ab@2201: { ab@2201: bool wake; ab@2201: ab@2201: __e1000_shutdown(pdev, &wake); ab@2201: ab@2201: if (system_state == SYSTEM_POWER_OFF) { ab@2201: pci_wake_from_d3(pdev, wake); ab@2201: pci_set_power_state(pdev, PCI_D3hot); ab@2201: } ab@2201: } ab@2201: ab@2201: #ifdef CONFIG_NET_POLL_CONTROLLER ab@2201: /* ab@2201: * Polling 'interrupt' - used by things like netconsole to send skbs ab@2201: * without having to re-enable interrupts. It's not called while ab@2201: * the interrupt routine is executing. ab@2201: */ ab@2201: static void e1000_netpoll(struct net_device *netdev) ab@2201: { ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: ab@2201: disable_irq(adapter->pdev->irq); ab@2201: e1000_intr(adapter->pdev->irq, netdev); ab@2201: enable_irq(adapter->pdev->irq); ab@2201: } ab@2201: #endif ab@2201: ab@2201: /** ab@2201: * e1000_io_error_detected - called when PCI error is detected ab@2201: * @pdev: Pointer to PCI device ab@2201: * @state: The current pci connection state ab@2201: * ab@2201: * This function is called after a PCI bus error affecting ab@2201: * this device has been detected. ab@2201: */ ab@2201: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, ab@2201: pci_channel_state_t state) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: ab@2201: netif_device_detach(netdev); ab@2201: ab@2201: if (state == pci_channel_io_perm_failure) ab@2201: return PCI_ERS_RESULT_DISCONNECT; ab@2201: ab@2201: if (netif_running(netdev)) ab@2201: e1000_down(adapter); ab@2201: pci_disable_device(pdev); ab@2201: ab@2201: /* Request a slot slot reset. */ ab@2201: return PCI_ERS_RESULT_NEED_RESET; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_io_slot_reset - called after the pci bus has been reset. ab@2201: * @pdev: Pointer to PCI device ab@2201: * ab@2201: * Restart the card from scratch, as if from a cold-boot. Implementation ab@2201: * resembles the first-half of the e1000_resume routine. ab@2201: */ ab@2201: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: struct e1000_hw *hw = &adapter->hw; ab@2201: int err; ab@2201: ab@2201: if (adapter->need_ioport) ab@2201: err = pci_enable_device(pdev); ab@2201: else ab@2201: err = pci_enable_device_mem(pdev); ab@2201: if (err) { ab@2201: printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); ab@2201: return PCI_ERS_RESULT_DISCONNECT; ab@2201: } ab@2201: pci_set_master(pdev); ab@2201: ab@2201: pci_enable_wake(pdev, PCI_D3hot, 0); ab@2201: pci_enable_wake(pdev, PCI_D3cold, 0); ab@2201: ab@2201: e1000_reset(adapter); ab@2201: ew32(WUS, ~0); ab@2201: ab@2201: return PCI_ERS_RESULT_RECOVERED; ab@2201: } ab@2201: ab@2201: /** ab@2201: * e1000_io_resume - called when traffic can start flowing again. ab@2201: * @pdev: Pointer to PCI device ab@2201: * ab@2201: * This callback is called when the error recovery driver tells us that ab@2201: * its OK to resume normal operation. Implementation resembles the ab@2201: * second-half of the e1000_resume routine. ab@2201: */ ab@2201: static void e1000_io_resume(struct pci_dev *pdev) ab@2201: { ab@2201: struct net_device *netdev = pci_get_drvdata(pdev); ab@2201: struct e1000_adapter *adapter = netdev_priv(netdev); ab@2201: ab@2201: e1000_init_manageability(adapter); ab@2201: ab@2201: if (netif_running(netdev)) { ab@2201: if (e1000_up(adapter)) { ab@2201: printk("e1000: can't bring device back up after reset\n"); ab@2201: return; ab@2201: } ab@2201: } ab@2201: ab@2201: netif_device_attach(netdev); ab@2201: } ab@2201: ab@2201: /* e1000_main.c */