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