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

📄 e1000_main.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************    Copyright(c) 1999 - 2004 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 * 5.3.12	6/7/04 * - kcompat NETIF_MSG for older kernels (2.4.9) <sean.p.mcdermott@intel.com> * - if_mii support and associated kcompat for older kernels * - More errlogging support from Jon Mason <jonmason@us.ibm.com> * - Fix TSO issues on PPC64 machines -- Jon Mason <jonmason@us.ibm.com> * 5.6.5 	11/01/04 * - Enabling NETIF_F_SG without checksum offload is illegal -      John Mason <jdmason@us.ibm.com> * 5.6.3        10/26/04 * - Remove redundant initialization - Jamal Hadi * - Reset buffer_info->dma in tx resource cleanup logic * 5.6.2	10/12/04 * - Sparse cleanup - shemminger@osdl.org * - Fix tx resource cleanup logic */char e1000_driver_name[] = "e1000";char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";#ifndef CONFIG_E1000_NAPI#define DRIVERNAPI#else#define DRIVERNAPI "-NAPI"#endifchar e1000_driver_version[] = "5.6.10.1-k1"DRIVERNAPI;char e1000_copyright[] = "Copyright (c) 1999-2004 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(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(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(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(0x108A),	/* 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_tx_resources(struct e1000_adapter *adapter);int e1000_setup_rx_resources(struct e1000_adapter *adapter);void e1000_free_tx_resources(struct e1000_adapter *adapter);void e1000_free_rx_resources(struct e1000_adapter *adapter);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_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_tx_ring(struct e1000_adapter *adapter);static void e1000_clean_rx_ring(struct e1000_adapter *adapter);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);#ifdef CONFIG_E1000_NAPIstatic int e1000_clean(struct net_device *netdev, int *budget);static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,                                    int *work_done, int work_to_do);#elsestatic boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter);#endifstatic void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);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 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);static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);static int e1000_suspend(struct pci_dev *pdev, uint32_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);#endifstruct notifier_block e1000_notifier_reboot = {	.notifier_call	= e1000_notify_reboot,	.next		= NULL,	.priority	= 0};/* 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");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);	if(ret >= 0) {		register_reboot_notifier(&e1000_notifier_reboot);	}	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){	unregister_reboot_notifier(&e1000_notifier_reboot);	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();}/** * 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);	}}inte1000_up(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	int 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);	e1000_alloc_rx_buffers(adapter);	if((err = request_irq(adapter->pdev->irq, &e1000_intr,		              SA_SHIRQ | SA_SAMPLE_RANDOM,		              netdev->name, netdev)))		return err;	mod_timer(&adapter->watchdog_timer, jiffies);	e1000_irq_enable(adapter);	return 0;}voide1000_down(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	e1000_irq_disable(adapter);	free_irq(adapter->pdev->irq, netdev);	del_timer_sync(&adapter->tx_fifo_stall_timer);	del_timer_sync(&adapter->watchdog_timer);	del_timer_sync(&adapter->phy_info_timer);	adapter->link_speed = 0;	adapter->link_duplex = 0;	netif_carrier_off(netdev);	netif_stop_queue(netdev);	e1000_reset(adapter);	e1000_clean_tx_ring(adapter);	e1000_clean_rx_ring(adapter);	/* If WoL is not enabled	 * Power down the PHY so no link is implied when interface is down */	if(!adapter->wol && adapter->hw.media_type == e1000_media_type_copper) {		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);	}}voide1000_reset(struct e1000_adapter *adapter){	uint32_t pba;	/* Repartition Pba for greater than 9k mtu	 * To take effect CTRL.RST is required.	 */	if(adapter->hw.mac_type < e1000_82547) {		if(adapter->rx_buffer_len > E1000_RXBUFFER_8192)			pba = E1000_PBA_40K;		else			pba = E1000_PBA_48K;	} else {		if(adapter->rx_buffer_len > E1000_RXBUFFER_8192)			pba = E1000_PBA_22K;		else			pba = E1000_PBA_30K;		adapter->tx_fifo_head = 0;		adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;		adapter->tx_fifo_size =			(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;		atomic_set(&adapter->tx_fifo_stall, 0);	}	E1000_WRITE_REG(&adapter->hw, PBA, pba);	/* flow control settings */	adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -				    E1000_FC_HIGH_DIFF;	adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -				   E1000_FC_LOW_DIFF;	adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;	adapter->hw.fc_send_xon = 1;	adapter->hw.fc = adapter->hw.original_fc;	e1000_reset_hw(&adapter->hw);	if(adapter->hw.mac_type >= e1000_82544)		E1000_WRITE_REG(&adapter->hw, WUC, 0);	if(e1000_init_hw(&adapter->hw))		DPRINTK(PROBE, ERR, "Hardware Error\n");	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);	e1000_reset_adaptive(&adapter->hw);	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);}/** * e1000_probe - Device Initialization Routine * @pdev: PCI device information struct * @ent: entry in e1000_pci_tbl * * Returns 0 on success, negative on failure * * e1000_probe initializes an adapter identified by a pci_dev structure. * The OS initialization, configuring of the adapter private structure, * and a hardware reset occur. **/static int __devinite1000_probe(struct pci_dev *pdev,            const struct pci_device_id *ent){	struct net_device *netdev;	struct e1000_adapter *adapter;	static int cards_found = 0;	unsigned long mmio_start;	int mmio_len;	int pci_using_dac;	int i;	int err;	uint16_t eeprom_data;	if((err = pci_enable_device(pdev)))		return err;	if(!(err = pci_set_dma_mask(pdev, PCI_DMA_64BIT))) {		pci_using_dac = 1;	} else {		if((err = pci_set_dma_mask(pdev, PCI_DMA_32BIT))) {			E1000_ERR("No usable DMA configuration, aborting\n");			return err;		}		pci_using_dac = 0;	}	if((err = pci_request_regions(pdev, e1000_driver_name)))		return err;	pci_set_master(pdev);	netdev = alloc_etherdev(sizeof(struct e1000_adapter));	if(!netdev) {		err = -ENOMEM;		goto err_alloc_etherdev;	}	SET_MODULE_OWNER(netdev);	SET_NETDEV_DEV(netdev, &pdev->dev);	pci_set_drvdata(pdev, netdev);	adapter = netdev->priv;	adapter->netdev = netdev;	adapter->pdev = pdev;	adapter->hw.back = adapter;	adapter->msg_enable = (1 << debug) - 1;	mmio_start = pci_resource_start(pdev, BAR_0);	mmio_len = pci_resource_len(pdev, BAR_0);	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);	if(!adapter->hw.hw_addr) {		err = -EIO;		goto err_ioremap;	}	for(i = BAR_1; i <= BAR_5; i++) {		if(pci_resource_len(pdev, i) == 0)			continue;		if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {			adapter->hw.io_base = pci_resource_start(pdev, i);			break;		}	}

⌨️ 快捷键说明

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