📄 e100_main.c
字号:
/******************************************************************************* 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*******************************************************************************//*********************************************************************** ** INTEL CORPORATION ** ** This software is supplied under the terms of the license included ** above. All use of this driver must be in accordance with the terms ** of that license. ** ** Module Name: e100_main.c ** ** Abstract: Functions for the driver entry points like load, ** unload, open and close. All board specific calls made ** by the network interface section of the driver. ** ** Environment: This file is intended to be specific to the Linux ** operating system. ** ***********************************************************************//* Change Log * * 2.3.38 12/14/03 * o Added netpoll support. * o Added ICH6 device ID support * o Moved to 2.6 APIs: pci_name() and free_netdev(). * o Removed some __devinit from some functions that shouldn't be marked * as such (Anton Blanchard [anton@samba.org]). * * 2.3.33 10/21/03 * o Bug fix (Bugzilla 97908): Loading e100 was causing crash on Itanium2 * with HP chipset * o Bug fix (Bugzilla 101583): e100 can't pass traffic with ipv6 * o Bug fix (Bugzilla 101360): PRO/10+ can't pass traffic * * 2.3.27 08/08/03 */ #undef __NO_VERSION__ #include <linux/config.h>#include <net/checksum.h>#include <linux/tcp.h>#include <linux/udp.h>#include "e100.h"#include "e100_ucode.h"#include "e100_config.h"#include "e100_phy.h"#ifdef E100_IA64_DMA_FIX#if !(defined __ia64__)#undef E100_IA64_DMA_FIX#endif#endifextern void e100_force_speed_duplex_to_phy(struct e100_private *bdp);#ifdef ETHTOOL_GSTATSstatic char e100_gstrings_stats[][ETH_GSTRING_LEN] = { "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", "rx_length_errors", "rx_over_errors", "rx_crc_errors", "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", "tx_heartbeat_errors", "tx_window_errors", /* device-specific stats */ "tx_late_collision_errors", "tx_deferred", "tx_single_collisions", "tx_multi_collisions", "rx_collision_detected_errors", "tx_flow_control_pause", "rx_flow_control_pause", "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets",};#define E100_NET_STATS_LEN 21#define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN#endif /* ETHTOOL_GSTATS */#ifdef SIOCETHTOOLstatic int e100_do_ethtool_ioctl(struct net_device *, struct ifreq *);static void e100_get_speed_duplex_caps(struct e100_private *);static int e100_ethtool_get_settings(struct net_device *, struct ifreq *);static int e100_ethtool_set_settings(struct net_device *, struct ifreq *);#ifdef ETHTOOL_GDRVINFOstatic int e100_ethtool_get_drvinfo(struct net_device *, struct ifreq *);#endif#ifdef ETHTOOL_GEEPROMstatic int e100_ethtool_eeprom(struct net_device *, struct ifreq *);#define E100_EEPROM_MAGIC 0x1234#endif#ifdef ETHTOOL_GLINKstatic int e100_ethtool_glink(struct net_device *, struct ifreq *);#endif#ifdef ETHTOOL_GEEPROM /* GREGS broken in earlier ethtool.h */#ifdef ETHTOOL_GREGSstatic int e100_ethtool_gregs(struct net_device *, struct ifreq *);#endif#endif#ifdef ETHTOOL_NWAY_RSTstatic int e100_ethtool_nway_rst(struct net_device *, struct ifreq *);#endif#ifdef ETHTOOL_GWOLstatic int e100_ethtool_wol(struct net_device *, struct ifreq *);#endif#ifdef CONFIG_PMstatic unsigned char e100_setup_filter(struct e100_private *bdp);static void e100_do_wol(struct pci_dev *pcid, struct e100_private *bdp);#endif#ifdef ETHTOOL_SWOLstatic u16 e100_get_ip_lbytes(struct net_device *dev);#endifextern void e100_config_wol(struct e100_private *bdp);#ifdef ETHTOOL_TESTextern u32 e100_run_diag(struct net_device *dev, u64 *test_info, u32 flags);static int e100_ethtool_test(struct net_device *, struct ifreq *);#endif#ifdef ETHTOOL_GSTRINGSstatic int e100_ethtool_gstrings(struct net_device *, struct ifreq *);static char test_strings[][ETH_GSTRING_LEN] = { "Link test (on/offline)", "Eeprom test (on/offline)", "Self test (offline)", "Mac loopback (offline)", "Phy loopback (offline)", "Cable diagnostic (offline)"};#endif#ifdef ETHTOOL_PHYS_IDstatic int e100_ethtool_led_blink(struct net_device *, struct ifreq *);#endif#endif /*SIOCETHTOOL */#ifdef SIOCGMIIPHYstatic int e100_mii_ioctl(struct net_device *, struct ifreq *, int);#endifstatic unsigned char e100_delayed_exec_non_cu_cmd(struct e100_private *, nxmit_cb_entry_t *);static void e100_free_nontx_list(struct e100_private *);static void e100_non_tx_background(unsigned long);static inline void e100_tx_skb_free(struct e100_private *bdp, tcb_t *tcb);/* Global Data structures and variables */char e100_copyright[] __devinitdata = "Copyright (c) 2004 Intel Corporation";char e100_driver_version[]="2.3.38";const char *e100_full_driver_name = "Intel(R) PRO/100 Network Driver";char e100_short_driver_name[] = "e100";static int e100nics = 0;#ifdef NETIF_F_HW_VLAN_TXstatic void e100_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);static void e100_vlan_rx_add_vid(struct net_device *netdev, u16 vid);static void e100_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);#endif#ifdef CONFIG_NET_POLL_CONTROLLER/* for netdump / net console */static void e100_netpoll (struct net_device *dev);#endif#ifdef CONFIG_PMstatic int e100_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);static int e100_suspend(struct pci_dev *pcid, u32 state);static int e100_resume(struct pci_dev *pcid);static unsigned char e100_asf_enabled(struct e100_private *bdp);struct notifier_block e100_notifier_reboot = { .notifier_call = e100_notify_reboot, .next = NULL, .priority = 0};#endif/*********************************************************************//*! This is a GCC extension to ANSI C. * See the item "Labeled Elements in Initializers" in the section * "Extensions to the C Language Family" of the GCC documentation. *********************************************************************/#define E100_PARAM_INIT { [0 ... E100_MAX_NIC] = -1 }/* All parameters are treated the same, as an integer array of values. * This macro just reduces the need to repeat the same declaration code * over and over (plus this helps to avoid typo bugs). */#define E100_PARAM(X, S) \ static const int X[E100_MAX_NIC + 1] = E100_PARAM_INIT; \ MODULE_PARM(X, "1-" __MODULE_STRING(E100_MAX_NIC) "i"); \ MODULE_PARM_DESC(X, S);/* ====================================================================== */static u8 e100_D101M_checksum(struct e100_private *, struct sk_buff *);static u8 e100_D102_check_checksum(rfd_t *);static int e100_ioctl(struct net_device *, struct ifreq *, int);static int e100_change_mtu(struct net_device *, int);static int e100_xmit_frame(struct sk_buff *, struct net_device *);static unsigned char e100_init(struct e100_private *);static int e100_set_mac(struct net_device *, void *);struct net_device_stats *e100_get_stats(struct net_device *);static irqreturn_t e100intr(int, void *, struct pt_regs *);static void e100_print_brd_conf(struct e100_private *);static void e100_set_multi(struct net_device *);static u8 e100_pci_setup(struct pci_dev *, struct e100_private *);static u8 e100_sw_init(struct e100_private *);static void e100_tco_workaround(struct e100_private *);static unsigned char e100_alloc_space(struct e100_private *);static void e100_dealloc_space(struct e100_private *);static int e100_alloc_tcb_pool(struct e100_private *);static void e100_setup_tcb_pool(tcb_t *, unsigned int, struct e100_private *);static void e100_free_tcb_pool(struct e100_private *);static int e100_alloc_rfd_pool(struct e100_private *);static void e100_free_rfd_pool(struct e100_private *);static void e100_rd_eaddr(struct e100_private *);static void e100_rd_pwa_no(struct e100_private *);extern u16 e100_eeprom_read(struct e100_private *, u16);extern void e100_eeprom_write_block(struct e100_private *, u16, u16 *, u16);extern u16 e100_eeprom_size(struct e100_private *);u16 e100_eeprom_calculate_chksum(struct e100_private *adapter);static unsigned char e100_clr_cntrs(struct e100_private *);static unsigned char e100_load_microcode(struct e100_private *);static unsigned char e100_setup_iaaddr(struct e100_private *, u8 *);static unsigned char e100_update_stats(struct e100_private *bdp);static void e100_start_ru(struct e100_private *);static void e100_dump_stats_cntrs(struct e100_private *);static void e100_check_options(int board, struct e100_private *bdp);static void e100_set_int_option(int *, int, int, int, int, char *);static void e100_set_bool_option(struct e100_private *bdp, int, u32, int, char *);unsigned char e100_wait_exec_cmplx(struct e100_private *, u32, u8, u8);void e100_exec_cmplx(struct e100_private *, u32, u8);/** * e100_get_rx_struct - retrieve cell to hold skb buff from the pool * @bdp: atapter's private data struct * * Returns the new cell to hold sk_buff or %NULL. */static inline struct rx_list_elem *e100_get_rx_struct(struct e100_private *bdp){ struct rx_list_elem *rx_struct = NULL; if (!list_empty(&(bdp->rx_struct_pool))) { rx_struct = list_entry(bdp->rx_struct_pool.next, struct rx_list_elem, list_elem); list_del(&(rx_struct->list_elem)); } return rx_struct;}/** * e100_alloc_skb - allocate an skb for the adapter * @bdp: atapter's private data struct * * Allocates skb with enough room for rfd, and data, and reserve non-data space. * Returns the new cell with sk_buff or %NULL. */static inline struct rx_list_elem *e100_alloc_skb(struct e100_private *bdp){ struct sk_buff *new_skb; u32 skb_size = sizeof (rfd_t); struct rx_list_elem *rx_struct;#ifdef E100_IA64_DMA_FIX new_skb = (struct sk_buff *) __dev_alloc_skb(skb_size, GFP_ATOMIC | GFP_DMA); if (new_skb == NULL) { new_skb = (struct sk_buff *) dev_alloc_skb(skb_size); }#else new_skb = (struct sk_buff *) dev_alloc_skb(skb_size);#endif if (new_skb) { /* The IP data should be DWORD aligned. since the ethernet header is 14 bytes long, we need to reserve 2 extra bytes so that the TCP/IP headers will be DWORD aligned. */ skb_reserve(new_skb, 2); if ((rx_struct = e100_get_rx_struct(bdp)) == NULL) goto err; rx_struct->skb = new_skb; rx_struct->dma_addr = pci_map_single(bdp->pdev, new_skb->data, sizeof (rfd_t), PCI_DMA_FROMDEVICE); if (!rx_struct->dma_addr) goto err; skb_reserve(new_skb, bdp->rfd_size); return rx_struct; } else { return NULL; }err: dev_kfree_skb_irq(new_skb); return NULL;}/** * e100_add_skb_to_end - add an skb to the end of our rfd list * @bdp: atapter's private data struct * @rx_struct: rx_list_elem with the new skb * * Adds a newly allocated skb to the end of our rfd list. */inline voide100_add_skb_to_end(struct e100_private *bdp, struct rx_list_elem *rx_struct){ rfd_t *rfdn; /* The new rfd */ rfd_t *rfd; /* The old rfd */ struct rx_list_elem *rx_struct_last; (rx_struct->skb)->dev = bdp->device; rfdn = RFD_POINTER(rx_struct->skb, bdp); rfdn->rfd_header.cb_status = 0; rfdn->rfd_header.cb_cmd = __constant_cpu_to_le16(RFD_EL_BIT); rfdn->rfd_act_cnt = 0; rfdn->rfd_sz = __constant_cpu_to_le16(RFD_DATA_SIZE); pci_dma_sync_single(bdp->pdev, rx_struct->dma_addr, bdp->rfd_size, PCI_DMA_TODEVICE); if (!list_empty(&(bdp->active_rx_list))) { rx_struct_last = list_entry(bdp->active_rx_list.prev, struct rx_list_elem, list_elem); rfd = RFD_POINTER(rx_struct_last->skb, bdp); pci_dma_sync_single(bdp->pdev, rx_struct_last->dma_addr, 4, PCI_DMA_FROMDEVICE); put_unaligned(cpu_to_le32(rx_struct->dma_addr), ((u32 *) (&(rfd->rfd_header.cb_lnk_ptr)))); pci_dma_sync_single(bdp->pdev, rx_struct_last->dma_addr, 8, PCI_DMA_TODEVICE); rfd->rfd_header.cb_cmd &= __constant_cpu_to_le16((u16) ~RFD_EL_BIT); pci_dma_sync_single(bdp->pdev, rx_struct_last->dma_addr, 4, PCI_DMA_TODEVICE); } list_add_tail(&(rx_struct->list_elem), &(bdp->active_rx_list));}static inline voide100_alloc_skbs(struct e100_private *bdp){ for (; bdp->skb_req > 0; bdp->skb_req--) { struct rx_list_elem *rx_struct; if ((rx_struct = e100_alloc_skb(bdp)) == NULL) return; e100_add_skb_to_end(bdp, rx_struct); }}void e100_tx_srv(struct e100_private *);u32 e100_rx_srv(struct e100_private *);void e100_watchdog(struct net_device *);void e100_refresh_txthld(struct e100_private *);void e100_manage_adaptive_ifs(struct e100_private *);void e100_clear_pools(struct e100_private *);static void e100_clear_structs(struct net_device *);static inline tcb_t *e100_prepare_xmit_buff(struct e100_private *, struct sk_buff *);static void e100_set_multi_exec(struct net_device *dev);MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");MODULE_DESCRIPTION("Intel(R) PRO/100 Network Driver");MODULE_LICENSE("GPL");E100_PARAM(TxDescriptors, "Number of transmit descriptors");E100_PARAM(RxDescriptors, "Number of receive descriptors");E100_PARAM(XsumRX, "Disable or enable Receive Checksum offload");E100_PARAM(e100_speed_duplex, "Speed and Duplex settings");E100_PARAM(ucode, "Disable or enable microcode loading");E100_PARAM(ber, "Value for the BER correction algorithm");E100_PARAM(flow_control, "Disable or enable Ethernet PAUSE frames processing");E100_PARAM(IntDelay, "Value for CPU saver's interrupt delay");E100_PARAM(BundleSmallFr, "Disable or enable interrupt bundling of small frames");E100_PARAM(BundleMax, "Maximum number for CPU saver's packet bundling");E100_PARAM(IFS, "Disable or enable the adaptive IFS algorithm");/** * e100_exec_cmd - issue a comand * @bdp: atapter's private data struct * @scb_cmd_low: the command that is to be issued * * This general routine will issue a command to the e100. */static inline voide100_exec_cmd(struct e100_private *bdp, u8 cmd_low){ writeb(cmd_low, &(bdp->scb->scb_cmd_low)); readw(&(bdp->scb->scb_status)); /* flushes last write, read-safe */}/** * e100_wait_scb - wait for SCB to clear * @bdp: atapter's private data struct * * This routine checks to see if the e100 has accepted a command. * It does so by checking the command field in the SCB, which will * be zeroed by the e100 upon accepting a command. The loop waits * for up to 1 millisecond for command acceptance. * * Returns: * true if the SCB cleared within 1 millisecond. * false if it didn't clear within 1 millisecond */unsigned chare100_wait_scb(struct e100_private *bdp){ int i; /* loop on the scb for a few times */ for (i = 0; i < 100; i++) { if (!readb(&bdp->scb->scb_cmd_low)) return true; cpu_relax(); } /* it didn't work. do it the slow way using udelay()s */ for (i = 0; i < E100_MAX_SCB_WAIT; i++) { if (!readb(&bdp->scb->scb_cmd_low)) return true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -