⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e1000_main.c

📁 linux系统的网卡驱动包
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************  Intel PRO/1000 Linux driver  Copyright(c) 1999 - 2008 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 <linux/module.h>#include <linux/types.h>#include <linux/init.h>#include <linux/vmalloc.h>#include <linux/pagemap.h>#include <linux/netdevice.h>#include <linux/tcp.h>#include <linux/ipv6.h>#ifdef NETIF_F_TSO#include <net/checksum.h>#ifdef NETIF_F_TSO6#include <net/ip6_checksum.h>#endif#endif#ifdef SIOCGMIIPHY#include <linux/mii.h>#endif#ifdef SIOCETHTOOL#include <linux/ethtool.h>#endif#ifdef NETIF_F_HW_VLAN_TX#include <linux/if_vlan.h>#endif#ifdef CONFIG_E1000_MQ#include <linux/cpu.h>#include <linux/smp.h>#endif#include "e1000.h"char e1000_driver_name[] = "e1000";static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";#ifdef CONFIG_E1000_NAPI#define DRV_NAPI "-NAPI"#else#define DRV_NAPI#endif#define DRV_DEBUG#define DRV_HW_PERF#define DRV_VERSION "7.6.15.4" DRV_NAPI DRV_DEBUG DRV_HW_PERFconst char e1000_driver_version[] = DRV_VERSION;static const char e1000_copyright[] = "Copyright (c) 1999-2008 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(E1000_DEV_ID_82542),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82543GC_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82543GC_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82544EI_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82544EI_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82544GC_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82544GC_LOM),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82540EM),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82545EM_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546EB_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82545EM_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546EB_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541EI),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541ER_LOM),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82540EM_LOM),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82540EP_LOM),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82540EP),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541EI_MOBILE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82547EI),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82547EI_MOBILE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546EB_QUAD_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82540EP_LP),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82545GM_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82545GM_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82545GM_SERDES),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IGP_M_AMT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IGP_AMT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IGP_C),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IFE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IGP_M),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_SERDES),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82547GI),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541GI),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541GI_MOBILE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541ER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_SERDES),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82541GI_LF),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82572EI_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82572EI_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82572EI_SERDES),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_PCIE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82573E),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82573E_IAMT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_80003ES2LAN_COPPER_DPT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_80003ES2LAN_SERDES_DPT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_QUAD_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82573L),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_QUAD_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_QUAD_FIBER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_SERDES_DUAL),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_SERDES_QUAD),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82572EI),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_80003ES2LAN_COPPER_SPT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_80003ES2LAN_SERDES_SPT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571EB_QUAD_COPPER_LP),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_82571PT_QUAD_COPPER),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IFE_GT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH8_IFE_G),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH9_IGP_AMT),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH9_IGP_C),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH9_IFE),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH9_IFE_G),	INTEL_E1000_ETHERNET_DEVICE(E1000_DEV_ID_ICH9_IFE_GT),	/* required last entry */	{0,}};MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);static int e1000_setup_tx_resources(struct e1000_adapter *adapter,                                    struct e1000_tx_ring *tx_ring);static int e1000_setup_rx_resources(struct e1000_adapter *adapter,                                    struct e1000_rx_ring *rx_ring);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);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(struct e1000_adapter *adapter);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 work_struct *work);static void e1000_82547_tx_fifo_stall(unsigned long data);static int e1000_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev,                                 struct e1000_tx_ring *tx_ring);static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);#ifdef CONFIG_E1000_MQstatic int e1000_subqueue_xmit_frame(struct sk_buff *skb,                                     struct net_device *netdev, int queue);#endifstatic void e1000_phy_read_status(struct e1000_adapter *adapter);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);static irqreturn_t e1000_intr_msi(int irq, void *data);static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,                                    struct e1000_tx_ring *tx_ring);#ifdef CONFIG_E1000_NAPIstatic int e1000_poll(struct napi_struct *napi, int budget);static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,                                    struct e1000_rx_ring *rx_ring,                                    int *work_done, int work_to_do);static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,                                       struct e1000_rx_ring *rx_ring,                                       int *work_done, int work_to_do);static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,                                          struct e1000_rx_ring *rx_ring,                                          int *work_done, int work_to_do);static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,                                         struct e1000_rx_ring *rx_ring,                                         int cleaned_count);#elsestatic bool e1000_clean_rx_irq(struct e1000_adapter *adapter,                                    struct e1000_rx_ring *rx_ring);static bool 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);#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 work_struct *work);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, u16 vid);static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 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#ifndef USE_REBOOT_NOTIFIERstatic 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#ifdef CONFIG_NET_POLL_CONTROLLER/* for netdump / net console */static void e1000_netpoll (struct net_device *netdev);#endif#define COPYBREAK_DEFAULT 256static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;module_param(copybreak, uint, 0644);MODULE_PARM_DESC(copybreak,	"Maximum size of packet that is copied to a new buffer on receive");#ifdef HAVE_PCI_ERSstatic pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,                     pci_channel_state_t state);static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);static void e1000_io_resume(struct pci_dev *pdev);static struct pci_error_handlers e1000_err_handler = {	.error_detected = e1000_io_error_detected,	.slot_reset = e1000_io_slot_reset,	.resume = e1000_io_resume,};#endifstatic struct pci_driver e1000_driver = {	.name     = e1000_driver_name,	.id_table = e1000_pci_tbl,	.probe    = e1000_probe,	.remove   = __devexit_p(e1000_remove),#ifdef CONFIG_PM	/* Power Management Hooks */	.suspend  = e1000_suspend,	.resume   = e1000_resume,#endif#ifndef USE_REBOOT_NOTIFIER	.shutdown = e1000_shutdown,#endif#ifdef HAVE_PCI_ERS	.err_handler = &e1000_err_handler#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 __init e1000_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_register_driver(&e1000_driver);#ifdef USE_REBOOT_NOTIFIER	if (ret >= 0) {		register_reboot_notifier(&e1000_notifier_reboot);	}#endif	if (copybreak != COPYBREAK_DEFAULT) {		if (copybreak == 0)			printk(KERN_INFO "e1000: copybreak disabled\n");		else			printk(KERN_INFO "e1000: copybreak enabled for "			       "packets <= %u bytes\n", copybreak);	}	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 __exit e1000_exit_module(void){#ifdef USE_REBOOT_NOTIFIER	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 irq_flags, err = 0;	irq_flags = IRQF_SHARED;	if (adapter->flags & E1000_FLAG_HAS_MSI) {		err = pci_enable_msi(adapter->pdev);		if (!err)			adapter->flags |= E1000_FLAG_MSI_ENABLED;	}	if (adapter->flags & E1000_FLAG_MSI_ENABLED) {		irq_flags &= ~IRQF_SHARED;		err = request_irq(adapter->pdev->irq, &e1000_intr_msi,		                  irq_flags, netdev->name, netdev);		if (!err) {			return err;		} else {			irq_flags |= IRQF_SHARED;			adapter->flags &= ~E1000_FLAG_MSI_ENABLED;			pci_disable_msi(adapter->pdev);		}	}	err = request_irq(adapter->pdev->irq, &e1000_intr, irq_flags,	                  netdev->name, netdev);	if (err)		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);	if (adapter->flags & E1000_FLAG_MSI_ENABLED) {		pci_disable_msi(adapter->pdev);		adapter->flags &= ~E1000_FLAG_MSI_ENABLED;	}}/** * e1000_irq_disable - Mask off interrupt generation on the NIC * @adapter: board private structure

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -