📄 epic100.c
字号:
/* epic100.c: A SMC 83c170 EPIC/100 Fast Ethernet driver for Linux. *//* Written/copyright 1997-2001 by Donald Becker. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on or derived from this code fall under the GPL and must retain the authorship, copyright and license notice. This file is not a complete program and may only be used when the entire operating system is licensed under the GPL. This driver is for the SMC83c170/175 "EPIC" series, as used on the SMC EtherPower II 9432 PCI adapter, and several CardBus cards. The author may be reached as becker@scyld.com, or C/O Scyld Computing Corporation 410 Severn Ave., Suite 210 Annapolis MD 21403 Information and updates available at http://www.scyld.com/network/epic100.html --------------------------------------------------------------------- Linux kernel-specific changes: LK1.1.2 (jgarzik): * Merge becker version 1.09 (4/08/2000) LK1.1.3: * Major bugfix to 1.09 driver (Francis Romieu) LK1.1.4 (jgarzik): * Merge becker test version 1.09 (5/29/2000) LK1.1.5: * Fix locking (jgarzik) * Limit 83c175 probe to ethernet-class PCI devices (rgooch) LK1.1.6: * Merge becker version 1.11 * Move pci_enable_device before any PCI BAR len checks LK1.1.7: * { fill me in } LK1.1.8: * ethtool driver info support (jgarzik) LK1.1.9: * ethtool media get/set support (jgarzik) LK1.1.10: * revert MII transceiver init change (jgarzik) LK1.1.11: * implement ETHTOOL_[GS]SET, _NWAY_RST, _[GS]MSGLVL, _GLINK (jgarzik) * replace some MII-related magic numbers with constants LK1.1.12: * fix power-up sequence*/#define DRV_NAME "epic100"#define DRV_VERSION "1.11+LK1.1.12"#define DRV_RELDATE "Jan 18, 2002"/* The user-configurable values. These may be modified when a driver module is loaded.*/static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. *//* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 32;/* Used to pass the full-duplex flag, etc. */#define MAX_UNITS 8 /* More are supported, limit only on options */static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};/* Set the copy breakpoint for the copy-only-tiny-frames scheme. Setting to > 1518 effectively disables this feature. */static int rx_copybreak;/* Operational parameters that are set at compile time. *//* Keep the ring sizes a power of two for operational efficiency. The compiler will convert <unsigned>'%'<2^N> into a bit mask. Making the Tx ring too large decreases the effectiveness of channel bonding and packet priority. There are no ill effects from too-large receive rings. */#define TX_RING_SIZE 16#define TX_QUEUE_LEN 10 /* Limit ring entries actually used. */#define RX_RING_SIZE 32#define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct epic_tx_desc)#define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct epic_rx_desc)/* Operational parameters that usually are not changed. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT (2*HZ)#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*//* Bytes transferred to chip before transmission starts. *//* Initial threshold, increased on underflow, rounded down to 4 byte units. */#define TX_FIFO_THRESH 256#define RX_FIFO_THRESH 1 /* 0-3, 0==32, 64,96, or 3==128 bytes */#if !defined(__OPTIMIZE__)#warning You must compile this file with the correct options!#warning See the last lines of the source file.#error You must compile this driver with "-O".#endif#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include <linux/spinlock.h>#include <linux/ethtool.h>#include <linux/mii.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/uaccess.h>/* These identify the driver base version and may not be removed. */static char version[] __devinitdata =DRV_NAME ".c:v1.11 1/7/2001 Written by Donald Becker <becker@scyld.com>\n";static char version2[] __devinitdata =" http://www.scyld.com/network/epic100.html\n";static char version3[] __devinitdata =" (unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("SMC 83c170 EPIC series Ethernet driver");MODULE_LICENSE("GPL");MODULE_PARM(debug, "i");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM_DESC(debug, "EPIC/100 debug level (0-5)");MODULE_PARM_DESC(max_interrupt_work, "EPIC/100 maximum events handled per interrupt");MODULE_PARM_DESC(options, "EPIC/100: Bits 0-3: media type, bit 4: full duplex");MODULE_PARM_DESC(rx_copybreak, "EPIC/100 copy breakpoint for copy-only-tiny-frames");MODULE_PARM_DESC(full_duplex, "EPIC/100 full duplex setting(s) (1)");/* Theory of OperationI. Board CompatibilityThis device driver is designed for the SMC "EPIC/100", the SMCsingle-chip Ethernet controllers for PCI. This chip is used onthe SMC EtherPower II boards.II. Board-specific settingsPCI bus devices are configured by the system at boot time, so no jumpersneed to be set on the board. The system BIOS will assign thePCI INTA signal to a (preferably otherwise unused) system IRQ line.Note: Kernel versions earlier than 1.3.73 do not support shared PCIinterrupt lines.III. Driver operationIIIa. Ring buffersIVb. Referenceshttp://www.smsc.com/main/datasheets/83c171.pdfhttp://www.smsc.com/main/datasheets/83c175.pdfhttp://scyld.com/expert/NWay.htmlhttp://www.national.com/pf/DP/DP83840A.htmlIVc. Errata*/enum pci_id_flags_bits { /* Set PCI command register bits before calling probe1(). */ PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, /* Read and map the single following PCI BAR. */ PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4, PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,};enum chip_capability_flags { MII_PWRDWN=1, TYPE2_INTR=2, NO_MII=4 };#define EPIC_TOTAL_SIZE 0x100#define USE_IO_OPS 1#ifdef USE_IO_OPS#define EPIC_IOTYPE PCI_USES_MASTER|PCI_USES_IO|PCI_ADDR0#else#define EPIC_IOTYPE PCI_USES_MASTER|PCI_USES_MEM|PCI_ADDR1#endiftypedef enum { SMSC_83C170_0, SMSC_83C170, SMSC_83C175,} chip_t;struct epic_chip_info { const char *name; enum pci_id_flags_bits pci_flags; int io_size; /* Needed for I/O region check or ioremap(). */ int drv_flags; /* Driver use, intended as capability flags. */};/* indexed by chip_t */static struct epic_chip_info pci_id_tbl[] = { { "SMSC EPIC/100 83c170", EPIC_IOTYPE, EPIC_TOTAL_SIZE, TYPE2_INTR | NO_MII | MII_PWRDWN }, { "SMSC EPIC/100 83c170", EPIC_IOTYPE, EPIC_TOTAL_SIZE, TYPE2_INTR }, { "SMSC EPIC/C 83c175", EPIC_IOTYPE, EPIC_TOTAL_SIZE, TYPE2_INTR | MII_PWRDWN },};static struct pci_device_id epic_pci_tbl[] __devinitdata = { { 0x10B8, 0x0005, 0x1092, 0x0AB4, 0, 0, SMSC_83C170_0 }, { 0x10B8, 0x0005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMSC_83C170 }, { 0x10B8, 0x0006, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, SMSC_83C175 }, { 0,}};MODULE_DEVICE_TABLE (pci, epic_pci_tbl); #ifndef USE_IO_OPS#undef inb#undef inw#undef inl#undef outb#undef outw#undef outl#define inb readb#define inw readw#define inl readl#define outb writeb#define outw writew#define outl writel#endif/* Offsets to registers, using the (ugh) SMC names. */enum epic_registers { COMMAND=0, INTSTAT=4, INTMASK=8, GENCTL=0x0C, NVCTL=0x10, EECTL=0x14, PCIBurstCnt=0x18, TEST1=0x1C, CRCCNT=0x20, ALICNT=0x24, MPCNT=0x28, /* Rx error counters. */ MIICtrl=0x30, MIIData=0x34, MIICfg=0x38, LAN0=64, /* MAC address. */ MC0=80, /* Multicast filter table. */ RxCtrl=96, TxCtrl=112, TxSTAT=0x74, PRxCDAR=0x84, RxSTAT=0xA4, EarlyRx=0xB0, PTxCDAR=0xC4, TxThresh=0xDC,};/* Interrupt register bits, using my own meaningful names. */enum IntrStatus { TxIdle=0x40000, RxIdle=0x20000, IntrSummary=0x010000, PCIBusErr170=0x7000, PCIBusErr175=0x1000, PhyEvent175=0x8000, RxStarted=0x0800, RxEarlyWarn=0x0400, CntFull=0x0200, TxUnderrun=0x0100, TxEmpty=0x0080, TxDone=0x0020, RxError=0x0010, RxOverflow=0x0008, RxFull=0x0004, RxHeader=0x0002, RxDone=0x0001,};enum CommandBits { StopRx=1, StartRx=2, TxQueued=4, RxQueued=8, StopTxDMA=0x20, StopRxDMA=0x40, RestartTx=0x80,};static u16 media2miictl[16] = { 0, 0x0C00, 0x0C00, 0x2000, 0x0100, 0x2100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };/* The EPIC100 Rx and Tx buffer descriptors. */struct epic_tx_desc { u32 txstatus; u32 bufaddr; u32 buflength; u32 next;};struct epic_rx_desc { u32 rxstatus; u32 bufaddr; u32 buflength; u32 next;};enum desc_status_bits { DescOwn=0x8000,};#define PRIV_ALIGN 15 /* Required alignment mask */struct epic_private { struct epic_rx_desc *rx_ring; struct epic_tx_desc *tx_ring; /* The saved address of a sent-in-place packet/buffer, for skfree(). */ struct sk_buff* tx_skbuff[TX_RING_SIZE]; /* The addresses of receive-in-place skbuffs. */ struct sk_buff* rx_skbuff[RX_RING_SIZE]; dma_addr_t tx_ring_dma; dma_addr_t rx_ring_dma; /* Ring pointers. */ spinlock_t lock; /* Group with Tx control cache line. */ unsigned int cur_tx, dirty_tx; unsigned int cur_rx, dirty_rx; unsigned int rx_buf_sz; /* Based on MTU+slack. */ struct pci_dev *pci_dev; /* PCI bus location. */ int chip_id, chip_flags; struct net_device_stats stats; struct timer_list timer; /* Media selection timer. */ int tx_threshold; unsigned char mc_filter[8]; signed char phys[4]; /* MII device addresses. */ u16 advertising; /* NWay media advertisement */ int mii_phy_cnt; struct mii_if_info mii; unsigned int tx_full:1; /* The Tx queue is full. */ unsigned int default_port:4; /* Last dev->if_port value. */};static int epic_open(struct net_device *dev);static int read_eeprom(long ioaddr, int location);static int mdio_read(struct net_device *dev, int phy_id, int location);static void mdio_write(struct net_device *dev, int phy_id, int loc, int val);static void epic_restart(struct net_device *dev);static void epic_timer(unsigned long data);static void epic_tx_timeout(struct net_device *dev);static void epic_init_ring(struct net_device *dev);static int epic_start_xmit(struct sk_buff *skb, struct net_device *dev);static int epic_rx(struct net_device *dev);static void epic_interrupt(int irq, void *dev_instance, struct pt_regs *regs);static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static int epic_close(struct net_device *dev);static struct net_device_stats *epic_get_stats(struct net_device *dev);static void set_rx_mode(struct net_device *dev);static int __devinit epic_init_one (struct pci_dev *pdev, const struct pci_device_id *ent){ static int card_idx = -1; long ioaddr; int chip_idx = (int) ent->driver_data; int irq; struct net_device *dev; struct epic_private *ep; int i, option = 0, duplex = 0; void *ring_space; dma_addr_t ring_dma;/* when built into the kernel, we only print version if device is found */#ifndef MODULE static int printed_version; if (!printed_version++) printk (KERN_INFO "%s" KERN_INFO "%s" KERN_INFO "%s", version, version2, version3);#endif card_idx++; i = pci_enable_device(pdev); if (i) return i; irq = pdev->irq; if (pci_resource_len(pdev, 0) < pci_id_tbl[chip_idx].io_size) { printk (KERN_ERR "card %d: no PCI region space\n", card_idx); return -ENODEV; } pci_set_master(pdev);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -