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

📄 e1000_main.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************    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.0.58       4/20/05 *   o Accepted ethtool cleanup patch from Stephen Hemminger  * 6.0.44+	2/15/05 *   o applied Anton's patch to resolve tx hang in hardware *   o Applied Andrew Mortons patch - e1000 stops working after resume */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.1.16-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(0x109A),	/* 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);static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,                                      struct e1000_rx_ring *rx_ring);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);		}	}}	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);	for (i = 0; i < adapter->num_queues; i++)		adapter->alloc_rx_buf(adapter, &adapter->rx_ring[i]);#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,		    "Unable to allocate interrupt Error: %d\n", err);		return err;	}	mod_timer(&adapter->watchdog_timer, jiffies);#ifdef CONFIG_E1000_NAPI	netif_poll_enable(netdev);#endif	e1000_irq_enable(adapter);	return 0;}voide1000_down(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	e1000_irq_disable(adapter);#ifdef CONFIG_E1000_MQ	while (atomic_read(&adapter->rx_sched_call_data.count) != 0);#endif	free_irq(adapter->pdev->irq, netdev);#ifdef CONFIG_PCI_MSI	if(adapter->hw.mac_type > e1000_82547_rev_2 &&	   adapter->have_msi == TRUE)		pci_disable_msi(adapter->pdev);#endif	del_timer_sync(&adapter->tx_fifo_stall_timer);	del_timer_sync(&adapter->watchdog_timer);	del_timer_sync(&adapter->phy_info_timer);#ifdef CONFIG_E1000_NAPI	netif_poll_disable(netdev);#endif	adapter->link_speed = 0;	adapter->link_duplex = 0;	netif_carrier_off(netdev);	netif_stop_queue(netdev);	e1000_reset(adapter);	e1000_clean_all_tx_rings(adapter);	e1000_clean_all_rx_rings(adapter);	/* If WoL is not enabled and management mode is not IAMT	 * Power down the PHY so no link is implied when interface is down */	if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&	   adapter->hw.media_type == e1000_media_type_copper &&	   !e1000_check_mng_mode(&adapter->hw) &&	   !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {		uint16_t mii_reg;		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);		mii_reg |= MII_CR_POWER_DOWN;		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);		mdelay(1);	}}voide1000_reset(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	uint32_t pba, manc;	uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;	uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;	/* Repartition Pba for greater than 9k mtu	 * To take effect CTRL.RST is required.	 */	switch (adapter->hw.mac_type) {	case e1000_82547:	case e1000_82547_rev_2:		pba = E1000_PBA_30K;		break;	case e1000_82571:	case e1000_82572:		pba = E1000_PBA_38K;		break;	case e1000_82573:		pba = E1000_PBA_12K;		break;	default:		pba = E1000_PBA_48K;		break;	}	if((adapter->hw.mac_type != e1000_82573) &&	   (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {		pba -= 8; /* allocate more FIFO for Tx */		/* send an XOFF when there is enough space in the		 * Rx FIFO to hold one extra full size Rx packet 		*/		fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE + 					ETHERNET_FCS_SIZE + 1;		fc_low_water_mark = fc_high_water_mark + 8;	}

⌨️ 快捷键说明

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