📄 e1000_main.c
字号:
/******************************************************************************* Intel PRO/1000 Linux driver Copyright(c) 1999 - 2006 Intel Corporation. This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope 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., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called "COPYING". Contact Information: Linux NICS <linux.nics@intel.com> e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497*******************************************************************************/#include "e1000.h"/* Change Log * 7.0.36 10-Mar-2006 * o fixups for compilation issues on older kernels * 7.0.35 3-Mar-2006 * 7.0.34 * o Major performance fixes by understanding relationship of rx_buffer_len * to window size growth. _ps and legacy receive paths changed * o merge with kernel changes * o legacy receive path went back to single descriptor model for jumbos * 7.0.33 3-Feb-2006 * o Added another fix for the pass false carrier bit * 7.0.32 24-Jan-2006 * o Need to rebuild with noew version number for the pass false carrier * fix in e1000_hw.c * 7.0.30 18-Jan-2006 * o fixup for tso workaround to disable it for pci-x * o fix mem leak on 82542 * o fixes for 10 Mb/s connections and incorrect stats * 7.0.28 01/06/2006 * o hardware workaround to only set "speed mode" bit for 1G link. * 7.0.26 12/23/2005 * o wake on lan support modified for device ID 10B5 * o fix dhcp + vlan issue not making it to the iAMT firmware * 7.0.24 12/9/2005 * o New hardware support for the Gigabit NIC embedded in the south bridge * o Fixes to the recycling logic (skb->tail) 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) */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 "7.2.9"DRIVERNAPIchar e1000_driver_version[] = DRV_VERSION;static char e1000_copyright[] = "Copyright (c) 1999-2006 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(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(0x1049), INTEL_E1000_ETHERNET_DEVICE(0x104A), INTEL_E1000_ETHERNET_DEVICE(0x104B), INTEL_E1000_ETHERNET_DEVICE(0x104C), INTEL_E1000_ETHERNET_DEVICE(0x104D), 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(0x1096), INTEL_E1000_ETHERNET_DEVICE(0x1098), INTEL_E1000_ETHERNET_DEVICE(0x1099), INTEL_E1000_ETHERNET_DEVICE(0x109A), INTEL_E1000_ETHERNET_DEVICE(0x10A4), INTEL_E1000_ETHERNET_DEVICE(0x10B5), INTEL_E1000_ETHERNET_DEVICE(0x10B9), INTEL_E1000_ETHERNET_DEVICE(0x10BA), INTEL_E1000_ETHERNET_DEVICE(0x10BB), /* 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_reinit_locked(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);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);static 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_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);#ifdef SIOCGMIIPHYstatic int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);#endifvoid e1000_set_ethtool_ops(struct net_device *netdev);#ifdef ETHTOOL_OPS_COMPATextern int ethtool_ioctl(struct ifreq *ifr);#endifstatic 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_reset_task(struct net_device *dev);static void e1000_smartspeed(struct e1000_adapter *adapter);static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb);#ifdef NETIF_F_HW_VLAN_TXstatic 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);#endifstatic int e1000_suspend(struct pci_dev *pdev, pm_message_t state);#ifdef CONFIG_PMstatic 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 USE_DRIVER_SHUTDOWN_HANDLERstatic void e1000_shutdown(struct pci_dev *pdev);#elsestatic int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);static struct notifier_block e1000_notifier_reboot = { .notifier_call = e1000_notify_reboot, .next = NULL, .priority = 0};#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 */ .suspend = e1000_suspend,#ifdef CONFIG_PM .resume = e1000_resume,#endif#ifdef USE_DRIVER_SHUTDOWN_HANDLER .shutdown = e1000_shutdown#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);#ifndef USE_DRIVER_SHUTDOWN_HANDLER if (ret >= 0) { register_reboot_notifier(&e1000_notifier_reboot); }#endif 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){#ifndef USE_DRIVER_SHUTDOWN_HANDLER unregister_reboot_notifier(&e1000_notifier_reboot);#endif pci_unregister_driver(&e1000_driver);}module_exit(e1000_exit_module);static int e1000_request_irq(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; int flags, err = 0; flags = IRQF_SHARED;#ifdef CONFIG_PCI_MSI if (adapter->hw.mac_type > e1000_82547_rev_2) { adapter->have_msi = TRUE; if ((err = pci_enable_msi(adapter->pdev))) { DPRINTK(PROBE, ERR, "Unable to allocate MSI interrupt Error: %d\n", err); adapter->have_msi = FALSE; } } if (adapter->have_msi) flags &= ~IRQF_SHARED;#endif if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags, netdev->name, netdev))) DPRINTK(PROBE, ERR, "Unable to allocate interrupt Error: %d\n", err); return err;}static void e1000_free_irq(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; free_irq(adapter->pdev->irq, netdev);#ifdef CONFIG_PCI_MSI if (adapter->have_msi) pci_disable_msi(adapter->pdev);#endif}/** * e1000_irq_disable - Mask off interrupt generation on the NIC * @adapter: board private structure **/static 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 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); }}#ifdef NETIF_F_HW_VLAN_TXstatic 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); } else adapter->mng_vlan_id = vid; }}#endif/** * 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 voide1000_release_hw_control(struct e1000_adapter *adapter){ uint32_t ctrl_ext; uint32_t swsm; uint32_t extcnf; /* Let firmware taken over control of h/w */ switch (adapter->hw.mac_type) { case e1000_82571: case e1000_82572: case e1000_80003es2lan: ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -