📄 e1000_main.c
字号:
/******************************************************************************* Copyright(c) 1999 - 2002 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*******************************************************************************/#define __E1000_MAIN__#ifdef IANS#define _IANS_MAIN_MODULE_C_#endif#include "e1000.h"/* Change Log * * 4.3.15 8/9/02 * o Clean up: prepended a shortened version of the license that references * the full license in LICENSE. * o Clean up: copied small packets to small socket buffers for truesize * bug that is exposed with the NFS mount daemon. * o Clean up: added pci reads for pci posting issues. * o Bug fix: added memory barriers for IA64. * o Feature: added locking mechanism for asf functionality. * * 4.3.2 7/5/02 * o Bug fix: perform controller reset using I/O rather than mmio because * some chipsets try to perform a 64-bit write, but the controller ignores * the upper 32-bit write once the reset is intiated by the lower 32-bit * write, causing a master abort. * o Bug fix: fixed jumbo frames sized from 1514 to 2048. * o ASF support: disable ARP when driver is loaded or resumed; enable when * driver is removed or suspended. * o Bug fix: changed default setting for RxIntDelay to 0 for 82542/3/4 * controllers to workaround h/w errata where controller will hang when * RxIntDelay <> 0 under certian network conditions. * o Clean up: removed unused and undocumented user-settable settings for * PHY. * o Bug fix: ethtool GEEPROM was using byte address rather than word * addressing. * o Feature: added support for ethtool SEEPROM. * o Feature: added support for entropy pool. * * 4.2.17 5/30/02 */ char e1000_driver_name[] = "e1000";char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";char e1000_driver_version[] = "4.3.15";char e1000_copyright[] = "Copyright (c) 1999-2002 Intel Corporation.";/* e1000_pci_tbl - PCI Device ID Table * * Private driver_data field (last one) stores an index into e1000_strings * Wildcard entries (PCI_ANY_ID) should come last * Last entry must be all 0s * * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, * Class, Class Mask, String Index } */static struct pci_device_id e1000_pci_tbl[] __devinitdata = { /* Intel(R) PRO/1000 Network Connection */ {0x8086, 0x1000, 0x8086, 0x1000, 0, 0, 0}, {0x8086, 0x1001, 0x8086, 0x1003, 0, 0, 0}, {0x8086, 0x1004, 0x8086, 0x1004, 0, 0, 0}, {0x8086, 0x1008, 0x8086, 0x1107, 0, 0, 0}, {0x8086, 0x1009, 0x8086, 0x1109, 0, 0, 0}, {0x8086, 0x100C, 0x8086, 0x1112, 0, 0, 0}, {0x8086, 0x100E, 0x8086, 0x001E, 0, 0, 0}, /* Compaq Gigabit Ethernet Server Adapter */ {0x8086, 0x1000, 0x0E11, PCI_ANY_ID, 0, 0, 1}, {0x8086, 0x1001, 0x0E11, PCI_ANY_ID, 0, 0, 1}, {0x8086, 0x1004, 0x0E11, PCI_ANY_ID, 0, 0, 1}, /* IBM Mobile, Desktop & Server Adapters */ {0x8086, 0x1000, 0x1014, PCI_ANY_ID, 0, 0, 2}, {0x8086, 0x1001, 0x1014, PCI_ANY_ID, 0, 0, 2}, {0x8086, 0x1004, 0x1014, PCI_ANY_ID, 0, 0, 2}, /* Generic */ {0x8086, 0x1000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x100C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x100D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x100E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x100F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1011, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* required last entry */ {0,}};MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);static char *e1000_strings[] = { "Intel(R) PRO/1000 Network Connection", "Compaq Gigabit Ethernet Server Adapter", "IBM Mobile, Desktop & Server Adapters"};/* Local Function Prototypes */int e1000_up(struct e1000_adapter *adapter);void e1000_down(struct e1000_adapter *adapter);void e1000_reset(struct e1000_adapter *adapter);void e1000_smbus_lock(struct pci_dev *pdev, boolean_t lock);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 e1000_remove(struct pci_dev *pdev);static void e1000_sw_init(struct e1000_adapter *adapter);static int e1000_open(struct net_device *netdev);static int e1000_close(struct net_device *netdev);static int e1000_setup_tx_resources(struct e1000_adapter *adapter);static int e1000_setup_rx_resources(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_tx_ring(struct e1000_adapter *adapter);static void e1000_clean_rx_ring(struct e1000_adapter *adapter);static void e1000_free_tx_resources(struct e1000_adapter *adapter);static void e1000_free_rx_resources(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);void e1000_watchdog_1(struct e1000_adapter *adapter);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 void e1000_update_stats(struct e1000_adapter *adapter);static inline void e1000_irq_disable(struct e1000_adapter *adapter);static inline void e1000_irq_enable(struct e1000_adapter *adapter);static void e1000_intr(int irq, void *data, struct pt_regs *regs);static void e1000_clean_tx_irq(struct e1000_adapter *adapter);static void e1000_clean_rx_irq(struct e1000_adapter *adapter);static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);static int e1000_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 inline void e1000_rx_checksum(struct e1000_adapter *adapter, struct e1000_rx_desc *rx_desc, struct sk_buff *skb);static boolean_t e1000_smbus_arp_enable(struct e1000_adapter *adapter, boolean_t arp_enable);#ifdef HAVE_TX_TIMEOUTstatic void e1000_tx_timeout(struct net_device *dev);#endif#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);#endifstatic 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/* For Click polling */static int e1000_tx_pqueue(struct net_device *dev, struct sk_buff *skb);static int e1000_tx_start(struct net_device *dev);static int e1000_rx_refill(struct net_device *dev, struct sk_buff **);static int e1000_tx_eob(struct net_device *dev);static struct sk_buff *e1000_tx_clean(struct net_device *dev);static struct sk_buff *e1000_rx_poll(struct net_device *dev, int *want);static int e1000_poll_on(struct net_device *dev);static int e1000_poll_off(struct net_device *dev);struct notifier_block e1000_notifier = { notifier_call: e1000_notify_reboot, next: NULL, priority: 0};/* Exported from other modules */extern void e1000_check_options(struct e1000_adapter *adapter);extern void e1000_proc_dev_setup(struct e1000_adapter *adapter);extern void e1000_proc_dev_free(struct e1000_adapter *adapter);extern int e1000_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr);#ifdef IDIAGextern int e1000_diag_ioctl(struct net_device *netdev, struct ifreq *ifr);#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};MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");MODULE_LICENSE("GPL");#ifdef EXPORT_SYMTABEXPORT_SYMBOL(e1000_smbus_lock);#endif/** * 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 " w/ Click polling\n"); printk(KERN_INFO "%s\n", e1000_copyright); ret = pci_module_init(&e1000_driver); if(ret >= 0) register_reboot_notifier(&e1000_notifier); 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); pci_unregister_driver(&e1000_driver);}module_exit(e1000_exit_module);inte1000_up(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; if(request_irq(netdev->irq, &e1000_intr, SA_SHIRQ | SA_SAMPLE_RANDOM, netdev->name, netdev)) return -1; /* hardware has been reset, we need to reload some things */ e1000_set_multi(netdev);#ifdef IANS if((ANS_PRIVATE_DATA_FIELD(adapter)->tag_mode) != IANS_BD_TAGGING_NONE) bd_ans_hw_EnableVLAN(adapter);#endif e1000_configure_tx(adapter); e1000_setup_rctl(adapter); e1000_configure_rx(adapter); e1000_alloc_rx_buffers(adapter); 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(netdev->irq, netdev); 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);}voide1000_reset(struct e1000_adapter *adapter){ /* Repartition Pba for greater than 9k mtu * To take effect CTRL.RST is required. */ if(adapter->rx_buffer_len > E1000_RXBUFFER_8192) E1000_WRITE_REG(&adapter->hw, PBA, E1000_JUMBO_PBA); else E1000_WRITE_REG(&adapter->hw, PBA, E1000_DEFAULT_PBA); adapter->hw.fc = adapter->hw.original_fc; down(&adapter->smbus_lock); e1000_reset_hw(&adapter->hw); up(&adapter->smbus_lock); if(adapter->hw.mac_type >= e1000_82544) E1000_WRITE_REG(&adapter->hw, WUC, 0); e1000_init_hw(&adapter->hw); 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; if((i = pci_enable_device(pdev))) return i; if(!(i = pci_set_dma_mask(pdev, PCI_DMA_64BIT))) { pci_using_dac = 1; } else { if((i = pci_set_dma_mask(pdev, PCI_DMA_32BIT))) { E1000_ERR("No usable DMA configuration, aborting\n"); return i; } pci_using_dac = 0; } if((i = pci_request_regions(pdev, e1000_driver_name))) return i; pci_set_master(pdev); netdev = alloc_etherdev(sizeof(struct e1000_adapter)); if(!netdev) goto err_alloc_etherdev; SET_MODULE_OWNER(netdev); pci_set_drvdata(pdev, netdev); adapter = netdev->priv; adapter->netdev = netdev; adapter->pdev = pdev; adapter->hw.back = adapter; 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) 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; } } netdev->open = &e1000_open; netdev->stop = &e1000_close; netdev->hard_start_xmit = &e1000_xmit_frame; netdev->get_stats = &e1000_get_stats; netdev->set_multicast_list = &e1000_set_multi; netdev->set_mac_address = &e1000_set_mac; netdev->change_mtu = &e1000_change_mtu; netdev->do_ioctl = &e1000_ioctl;#ifdef HAVE_TX_TIMEOUT netdev->tx_timeout = &e1000_tx_timeout; netdev->watchdog_timeo = HZ;#endif#ifdef NETIF_F_HW_VLAN_TX netdev->vlan_rx_register = e1000_vlan_rx_register; netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;#endif /* Click - polling extensions */ netdev->polling = 0; netdev->rx_poll = e1000_rx_poll; netdev->rx_refill = e1000_rx_refill; netdev->tx_queue = e1000_tx_pqueue; netdev->tx_eob = e1000_tx_eob; netdev->tx_start = e1000_tx_start; netdev->tx_clean = e1000_tx_clean; netdev->poll_off = e1000_poll_off; netdev->poll_on = e1000_poll_on; netdev->irq = pdev->irq; netdev->mem_start = mmio_start; netdev->base_addr = adapter->hw.io_base; adapter->bd_number = cards_found; adapter->id_string = e1000_strings[ent->driver_data]; /* setup the private structure */ e1000_sw_init(adapter);#ifdef MAX_SKB_FRAGS if(adapter->hw.mac_type >= e1000_82543) {#ifdef NETIF_F_HW_VLAN_TX netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;#else netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM;#endif } else { netdev->features = NETIF_F_SG; } if(pci_using_dac) netdev->features |= NETIF_F_HIGHDMA;#endif /* make sure the EEPROM is good */ if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) { printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n"); goto err_eeprom; } /* copy the MAC address out of the EEPROM */ e1000_read_mac_addr(&adapter->hw); memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -