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