📄 e1000_main.c
字号:
/******************************************************************************* Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The full GNU General Public License is included in this distribution in the file called LICENSE. Contact Information: Linux NICS <linux.nics@intel.com> Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497*******************************************************************************/#include "e1000.h"/* Change Log * 6.3.9 12/16/2005 * o incorporate fix for recycled skbs from IBM LTC * 6.3.7 11/18/2005 * o Honor eeprom setting for enabling/disabling Wake On Lan * 6.3.5 11/17/2005 * o Fix memory leak in rx ring handling for PCI Express adapters * 6.3.4 11/8/05 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree * 6.3.2 9/20/05 * o Render logic that sets/resets DRV_LOAD as inline functions to * avoid code replication. If f/w is AMT then set DRV_LOAD only when * network interface is open. * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs. * o Adjust PBA partioning for Jumbo frames using MTU size and not * rx_buffer_len * 6.3.1 9/19/05 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic (e1000_clean_tx_irq) * o Support for 8086:10B5 device (Quad Port) * 6.2.14 9/15/05 * o In AMT enabled configurations, set/reset DRV_LOAD bit on interface * open/close * 6.2.13 9/14/05 * o Invoke e1000_check_mng_mode only for 8257x controllers since it * accesses the FWSM that is not supported in other controllers * 6.2.12 9/9/05 * o Add support for device id E1000_DEV_ID_82546GB_QUAD_COPPER * o set RCTL:SECRC only for controllers newer than 82543. * o When the n/w interface comes down reset DRV_LOAD bit to notify f/w. * This code was moved from e1000_remove to e1000_close * 6.2.10 9/6/05 * o Fix error in updating RDT in el1000_alloc_rx_buffers[_ps] -- one off. * o Enable fc by default on 82573 controllers (do not read eeprom) * o Fix rx_errors statistic not to include missed_packet_count * o Fix rx_dropped statistic not to include missed_packet_count (Padraig Brady) * 6.2.9 8/30/05 * o Remove call to update statistics from the controller ib e1000_get_stats * 6.2.8 8/30/05 * o Improved algorithm for rx buffer allocation/rdt update * o Flow control watermarks relative to rx PBA size * o Simplified 'Tx Hung' detect logic * 6.2.7 8/17/05 * o Report rx buffer allocation failures and tx timeout counts in stats * 6.2.6 8/16/05 * o Implement workaround for controller erratum -- linear non-tso packet * following a TSO gets written back prematurely * 6.2.5 8/15/05 * o Set netdev->tx_queue_len based on link speed/duplex settings. * o Fix net_stats.rx_fifo_errors <p@draigBrady.com> * o Do not power off PHY if SoL/IDER session is active * 6.2.4 8/10/05 * o Fix loopback test setup/cleanup for 82571/3 controllers * o Fix parsing of outgoing packets (e1000_transfer_dhcp_info) to treat * all packets as raw * o Prevent operations that will cause the PHY to be reset if SoL/IDER * sessions are active and log a message * 6.2.2 7/21/05 * o used fixed size descriptors for all MTU sizes, reduces memory load * 6.1.2 4/13/05 * o Fixed ethtool diagnostics * o Enabled flow control to take default eeprom settings * o Added stats_lock around e1000_read_phy_reg commands to avoid concurrent * calls, one from mii_ioctl and other from within update_stats while * processing MIIREG ioctl. */char e1000_driver_name[] = "e1000";static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";#ifndef CONFIG_E1000_NAPI#define DRIVERNAPI#else#define DRIVERNAPI "-NAPI"#endif#define DRV_VERSION "6.3.9-k4"DRIVERNAPIchar e1000_driver_version[] = DRV_VERSION;static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";/* e1000_pci_tbl - PCI Device ID Table * * Last entry must be all 0s * * Macro expands to... * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} */static struct pci_device_id e1000_pci_tbl[] = { INTEL_E1000_ETHERNET_DEVICE(0x1000), INTEL_E1000_ETHERNET_DEVICE(0x1001), INTEL_E1000_ETHERNET_DEVICE(0x1004), INTEL_E1000_ETHERNET_DEVICE(0x1008), INTEL_E1000_ETHERNET_DEVICE(0x1009), INTEL_E1000_ETHERNET_DEVICE(0x100C), INTEL_E1000_ETHERNET_DEVICE(0x100D), INTEL_E1000_ETHERNET_DEVICE(0x100E), INTEL_E1000_ETHERNET_DEVICE(0x100F), INTEL_E1000_ETHERNET_DEVICE(0x1010), INTEL_E1000_ETHERNET_DEVICE(0x1011), INTEL_E1000_ETHERNET_DEVICE(0x1012), INTEL_E1000_ETHERNET_DEVICE(0x1013), INTEL_E1000_ETHERNET_DEVICE(0x1014), INTEL_E1000_ETHERNET_DEVICE(0x1015), INTEL_E1000_ETHERNET_DEVICE(0x1016), INTEL_E1000_ETHERNET_DEVICE(0x1017), INTEL_E1000_ETHERNET_DEVICE(0x1018), INTEL_E1000_ETHERNET_DEVICE(0x1019), INTEL_E1000_ETHERNET_DEVICE(0x101A), INTEL_E1000_ETHERNET_DEVICE(0x101D), INTEL_E1000_ETHERNET_DEVICE(0x101E), INTEL_E1000_ETHERNET_DEVICE(0x1026), INTEL_E1000_ETHERNET_DEVICE(0x1027), INTEL_E1000_ETHERNET_DEVICE(0x1028), INTEL_E1000_ETHERNET_DEVICE(0x105E), INTEL_E1000_ETHERNET_DEVICE(0x105F), INTEL_E1000_ETHERNET_DEVICE(0x1060), INTEL_E1000_ETHERNET_DEVICE(0x1075), INTEL_E1000_ETHERNET_DEVICE(0x1076), INTEL_E1000_ETHERNET_DEVICE(0x1077), INTEL_E1000_ETHERNET_DEVICE(0x1078), INTEL_E1000_ETHERNET_DEVICE(0x1079), INTEL_E1000_ETHERNET_DEVICE(0x107A), INTEL_E1000_ETHERNET_DEVICE(0x107B), INTEL_E1000_ETHERNET_DEVICE(0x107C), INTEL_E1000_ETHERNET_DEVICE(0x107D), INTEL_E1000_ETHERNET_DEVICE(0x107E), INTEL_E1000_ETHERNET_DEVICE(0x107F), INTEL_E1000_ETHERNET_DEVICE(0x108A), INTEL_E1000_ETHERNET_DEVICE(0x108B), INTEL_E1000_ETHERNET_DEVICE(0x108C), INTEL_E1000_ETHERNET_DEVICE(0x1099), INTEL_E1000_ETHERNET_DEVICE(0x109A), INTEL_E1000_ETHERNET_DEVICE(0x10B5), /* required last entry */ {0,}};MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);int e1000_up(struct e1000_adapter *adapter);void e1000_down(struct e1000_adapter *adapter);void e1000_reset(struct e1000_adapter *adapter);int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);void e1000_free_all_tx_resources(struct e1000_adapter *adapter);void e1000_free_all_rx_resources(struct e1000_adapter *adapter);static int e1000_setup_tx_resources(struct e1000_adapter *adapter, struct e1000_tx_ring *txdr);static int e1000_setup_rx_resources(struct e1000_adapter *adapter, struct e1000_rx_ring *rxdr);static void e1000_free_tx_resources(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring);static void e1000_free_rx_resources(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring);void e1000_update_stats(struct e1000_adapter *adapter);/* Local Function Prototypes */static int e1000_init_module(void);static void e1000_exit_module(void);static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);static void __devexit e1000_remove(struct pci_dev *pdev);static int e1000_alloc_queues(struct e1000_adapter *adapter);#ifdef CONFIG_E1000_MQstatic void e1000_setup_queue_mapping(struct e1000_adapter *adapter);#endifstatic int e1000_sw_init(struct e1000_adapter *adapter);static int e1000_open(struct net_device *netdev);static int e1000_close(struct net_device *netdev);static void e1000_configure_tx(struct e1000_adapter *adapter);static void e1000_configure_rx(struct e1000_adapter *adapter);static void e1000_setup_rctl(struct e1000_adapter *adapter);static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);static void e1000_clean_tx_ring(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring);static void e1000_clean_rx_ring(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring);static void e1000_set_multi(struct net_device *netdev);static void e1000_update_phy_info(unsigned long data);static void e1000_watchdog(unsigned long data);static void e1000_watchdog_task(struct e1000_adapter *adapter);static void e1000_82547_tx_fifo_stall(unsigned long data);static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);static struct net_device_stats * e1000_get_stats(struct net_device *netdev);static int e1000_change_mtu(struct net_device *netdev, int new_mtu);static int e1000_set_mac(struct net_device *netdev, void *p);static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring);#ifdef CONFIG_E1000_NAPIstatic int e1000_clean(struct net_device *poll_dev, int *budget);static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring, int *work_done, int work_to_do);static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring, int *work_done, int work_to_do);#elsestatic boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring);static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring);#endifstatic void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring, int cleaned_count);static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring, int cleaned_count);static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);void e1000_set_ethtool_ops(struct net_device *netdev);static void e1000_enter_82542_rst(struct e1000_adapter *adapter);static void e1000_leave_82542_rst(struct e1000_adapter *adapter);static void e1000_tx_timeout(struct net_device *dev);static void e1000_tx_timeout_task(struct net_device *dev);static void e1000_smartspeed(struct e1000_adapter *adapter);static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb);static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);static void e1000_restore_vlan(struct e1000_adapter *adapter);#ifdef CONFIG_PMstatic int e1000_suspend(struct pci_dev *pdev, pm_message_t state);static int e1000_resume(struct pci_dev *pdev);#endif#ifdef CONFIG_NET_POLL_CONTROLLER/* for netdump / net console */static void e1000_netpoll (struct net_device *netdev);#endif#ifdef CONFIG_E1000_MQ/* for multiple Rx queues */void e1000_rx_schedule(void *data);#endif/* Exported from other modules */extern void e1000_check_options(struct e1000_adapter *adapter);static struct pci_driver e1000_driver = { .name = e1000_driver_name, .id_table = e1000_pci_tbl, .probe = e1000_probe, .remove = __devexit_p(e1000_remove), /* Power Managment Hooks */#ifdef CONFIG_PM .suspend = e1000_suspend, .resume = e1000_resume#endif};MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");MODULE_LICENSE("GPL");MODULE_VERSION(DRV_VERSION);static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;module_param(debug, int, 0);MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");/** * e1000_init_module - Driver Registration Routine * * e1000_init_module is the first routine called when the driver is * loaded. All it does is register with the PCI subsystem. **/static int __inite1000_init_module(void){ int ret; printk(KERN_INFO "%s - version %s\n", e1000_driver_string, e1000_driver_version); printk(KERN_INFO "%s\n", e1000_copyright); ret = pci_module_init(&e1000_driver); return ret;}module_init(e1000_init_module);/** * e1000_exit_module - Driver Exit Cleanup Routine * * e1000_exit_module is called just before the driver is removed * from memory. **/static void __exite1000_exit_module(void){ pci_unregister_driver(&e1000_driver);}module_exit(e1000_exit_module);/** * e1000_irq_disable - Mask off interrupt generation on the NIC * @adapter: board private structure **/static inline voide1000_irq_disable(struct e1000_adapter *adapter){ atomic_inc(&adapter->irq_sem); E1000_WRITE_REG(&adapter->hw, IMC, ~0); E1000_WRITE_FLUSH(&adapter->hw); synchronize_irq(adapter->pdev->irq);}/** * e1000_irq_enable - Enable default interrupt generation settings * @adapter: board private structure **/static inline voide1000_irq_enable(struct e1000_adapter *adapter){ if (likely(atomic_dec_and_test(&adapter->irq_sem))) { E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); E1000_WRITE_FLUSH(&adapter->hw); }}static voide1000_update_mng_vlan(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; uint16_t vid = adapter->hw.mng_cookie.vlan_id; uint16_t old_vid = adapter->mng_vlan_id; if (adapter->vlgrp) { if (!adapter->vlgrp->vlan_devices[vid]) { if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { e1000_vlan_rx_add_vid(netdev, vid); adapter->mng_vlan_id = vid; } else adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && (vid != old_vid) && !adapter->vlgrp->vlan_devices[old_vid]) e1000_vlan_rx_kill_vid(netdev, old_vid); } }}/** * e1000_release_hw_control - release control of the h/w to f/w * @adapter: address of board private structure * * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that the * driver is no longer loaded. For AMT version (only with 82573) i * of the f/w this means that the netowrk i/f is closed. * **/static inline void e1000_release_hw_control(struct e1000_adapter *adapter){ uint32_t ctrl_ext; uint32_t swsm; /* Let firmware taken over control of h/w */ switch (adapter->hw.mac_type) { case e1000_82571: case e1000_82572: ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); break; case e1000_82573: swsm = E1000_READ_REG(&adapter->hw, SWSM); E1000_WRITE_REG(&adapter->hw, SWSM, swsm & ~E1000_SWSM_DRV_LOAD); default: break; }}/** * e1000_get_hw_control - get control of the h/w from f/w * @adapter: address of board private structure * * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that * the driver is loaded. For AMT version (only with 82573) * of the f/w this means that the netowrk i/f is open. * **/static inline void e1000_get_hw_control(struct e1000_adapter *adapter){ uint32_t ctrl_ext; uint32_t swsm; /* Let firmware know the driver has taken over */ switch (adapter->hw.mac_type) { case e1000_82571: case e1000_82572: ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); break; case e1000_82573: swsm = E1000_READ_REG(&adapter->hw, SWSM); E1000_WRITE_REG(&adapter->hw, SWSM, swsm | E1000_SWSM_DRV_LOAD); break; default: break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -