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