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