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