📄 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*******************************************************************************/#include "e1000.h"/* Change Log * * 4.4.19 11/27/02 * o Feature: Added user-settable knob for interrupt throttle rate (ITR). * o Cleanup: removed large static array allocations. * o Cleanup: C99 struct initializer format. * o Bug fix: restore VLAN settings when interface is brought up. * o Bug fix: return cleanly in probe if error in detecting MAC type. * o Bug fix: Wake up on magic packet by default only if enabled in eeprom. * o Bug fix: Validate MAC address in set_mac. * o Bug fix: Throw away zero-length Tx skbs. * o Bug fix: Make ethtool EEPROM acceses work on older versions of ethtool. * * 4.4.12 10/15/02 * o Clean up: use members of pci_device rather than direct calls to * pci_read_config_word. * o Bug fix: changed default flow control settings. * o Clean up: ethtool file now has an inclusive list for adapters in the * Wake-On-LAN capabilities instead of an exclusive list. * o Bug fix: miscellaneous WoL bug fixes. * o Added software interrupt for clearing rx ring * o Bug fix: easier to undo "forcing" of 1000/fd using ethtool. * o Now setting netdev->mem_end in e1000_probe. * o Clean up: Moved tx_timeout from interrupt context to process context * using schedule_task. * * 4.3.15 8/9/02 */char e1000_driver_name[] = "e1000";char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";char e1000_driver_version[] = "4.4.19-k1";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}, {0x8086, 0x1016, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1017, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x101E, 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);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 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 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);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 void e1000_tx_timeout(struct net_device *dev);static void e1000_tx_timeout_task(struct net_device *dev);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_notify_netdev(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);#endifstruct notifier_block e1000_notifier_reboot = { .notifier_call = e1000_notify_reboot, .next = NULL, .priority = 0};struct notifier_block e1000_notifier_netdev = { .notifier_call = e1000_notify_netdev, .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);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");/** * 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); register_netdevice_notifier(&e1000_notifier_netdev); } 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); unregister_netdevice_notifier(&e1000_notifier_netdev); 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); e1000_restore_vlan(adapter); 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; e1000_reset_hw(&adapter->hw); 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; uint16_t eeprom_data; 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; netdev->tx_timeout = &e1000_tx_timeout; netdev->watchdog_timeo = HZ; 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; netdev->irq = pdev->irq; netdev->mem_start = mmio_start; netdev->mem_end = mmio_start + mmio_len; netdev->base_addr = adapter->hw.io_base; adapter->bd_number = cards_found; adapter->id_string = e1000_strings[ent->driver_data]; /* setup the private structure */ if(e1000_sw_init(adapter)) goto err_sw_init; if(adapter->hw.mac_type >= e1000_82543) { 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; } if(pci_using_dac) netdev->features |= NETIF_F_HIGHDMA; /* 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); if(!is_valid_ether_addr(netdev->dev_addr)) goto err_eeprom; e1000_read_part_num(&adapter->hw, &(adapter->part_num)); e1000_get_bus_info(&adapter->hw); if((adapter->hw.mac_type == e1000_82544) && (adapter->hw.bus_type == e1000_bus_type_pcix)) adapter->max_data_per_txd = 4096; else adapter->max_data_per_txd = MAX_JUMBO_FRAME_SIZE; init_timer(&adapter->watchdog_timer); adapter->watchdog_timer.function = &e1000_watchdog; adapter->watchdog_timer.data = (unsigned long) adapter; init_timer(&adapter->phy_info_timer); adapter->phy_info_timer.function = &e1000_update_phy_info; adapter->phy_info_timer.data = (unsigned long) adapter;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -