e1000_main.c

来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 2,280 行 · 第 1/5 页

C
2,280
字号
/*******************************************************************************    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 * 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.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) */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.0.33-k2"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(0x1096),	INTEL_E1000_ETHERNET_DEVICE(0x1098),	INTEL_E1000_ETHERNET_DEVICE(0x1099),	INTEL_E1000_ETHERNET_DEVICE(0x109A),	INTEL_E1000_ETHERNET_DEVICE(0x10B5),	INTEL_E1000_ETHERNET_DEVICE(0x10B9),	/* 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 *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);/* 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);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_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);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_reset_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);#endifstatic void e1000_shutdown(struct pci_dev *pdev);#ifdef CONFIG_NET_POLL_CONTROLLER/* for netdump / net console */static void e1000_netpoll (struct net_device *netdev);#endifstatic 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	.shutdown = e1000_shutdown};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);		} else			adapter->mng_vlan_id = 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;	}}inte1000_up(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	int i, err;	/* hardware has been reset, we need to reload some things */	/* Reset the PHY if it was previously powered down */	if (adapter->hw.media_type == e1000_media_type_copper) {		uint16_t mii_reg;		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);		if (mii_reg & MII_CR_POWER_DOWN)			e1000_phy_reset(&adapter->hw);	}	e1000_set_multi(netdev);	e1000_restore_vlan(adapter);	e1000_configure_tx(adapter);	e1000_setup_rctl(adapter);	e1000_configure_rx(adapter);	/* call E1000_DESC_UNUSED which always leaves	 * at least 1 descriptor unused to make sure	 * next_to_use != next_to_clean */	for (i = 0; i < adapter->num_rx_queues; i++) {		struct e1000_rx_ring *ring = &adapter->rx_ring[i];		adapter->alloc_rx_buf(adapter, ring,		                      E1000_DESC_UNUSED(ring));	}#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;		}	}#endif	if ((err = request_irq(adapter->pdev->irq, &e1000_intr,		              SA_SHIRQ | SA_SAMPLE_RANDOM,		              netdev->name, netdev))) {		DPRINTK(PROBE, ERR,

⌨️ 快捷键说明

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