e1000_main.c
来自「优龙2410linux2.6.8内核源代码」· C语言 代码 · 共 2,331 行 · 第 1/5 页
C
2,331 行
/******************************************************************************* 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"#include <linux/rtnetlink.h>/* Change Log * * 5.2.51 5/14/04 * o set default configuration to 'NAPI disabled'. NAPI enabled driver * causes kernel panic when the interface is shutdown while data is being * transferred. * 5.2.47 5/04/04 * o fixed ethtool -t implementation * 5.2.45 4/29/04 * o fixed ethtool -e implementation * o Support for ethtool ops [Stephen Hemminger (shemminger@osdl.org)] * 5.2.42 4/26/04 * o Added support for the DPRINTK macro for enhanced error logging. Some * parts of the patch were supplied by Jon Mason. * o Move the register_netdevice() donw in the probe routine due to a * loading/unloading test issue. * o Added a long RX byte count the the extra ethtool data members for BER * testing purposes. * 5.2.39 3/12/04 */char e1000_driver_name[] = "e1000";char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";char e1000_driver_version[] = "5.2.52-k4";char e1000_copyright[] = "Copyright (c) 1999-2004 Intel Corporation.";/* e1000_pci_tbl - PCI Device ID Table * * 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, private data (not used) } */static struct pci_device_id e1000_pci_tbl[] = { {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, 0x1010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1011, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1015, 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, 0x1018, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x101D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x101E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1026, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1027, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1075, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1076, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1077, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1078, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x1079, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x107A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0x8086, 0x107B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 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 inline void e1000_irq_disable(struct e1000_adapter *adapter);static inline void e1000_irq_enable(struct e1000_adapter *adapter);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 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_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 *dev);#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 = 3;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);inte1000_up(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; int err; /* 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); 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);}voide1000_reset(struct e1000_adapter *adapter){ uint32_t pba, manc; /* 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); e1000_init_hw(&adapter->hw); /* 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); if(adapter->en_mng_pt) { manc = E1000_READ_REG(&adapter->hw, MANC); manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST); E1000_WRITE_REG(&adapter->hw, MANC, manc); }}/** * 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, DMA_64BIT_MASK))) { pci_using_dac = 1; } else { if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { 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; rtnl_lock(); /* we need to set the name early since the DPRINTK macro needs it set */ if (dev_alloc_name(netdev, netdev->name) < 0) goto err_free_unlock; 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; } } 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; set_ethtool_ops(netdev); netdev->tx_timeout = &e1000_tx_timeout; netdev->watchdog_timeo = 5 * HZ;#ifdef CONFIG_E1000_NAPI netdev->poll = &e1000_clean; netdev->weight = 64;#endif 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;#ifdef CONFIG_NET_POLL_CONTROLLER netdev->poll_controller = e1000_netpoll;#endif netdev->mem_start = mmio_start; netdev->mem_end = mmio_start + mmio_len; netdev->base_addr = adapter->hw.io_base; adapter->bd_number = cards_found; /* setup the private structure */ if((err = e1000_sw_init(adapter))) goto err_sw_init;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?