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