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