📄 3c575_cb.c
字号:
/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. *//* Written 1996-2000 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, copryight 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 3Com "Vortex" and "Boomerang" series ethercards. Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597 and the EtherLink XL 3c900 and 3c905 cards. The original author may be reached as becker@scyld.com, or C/O Scyld Computing Corporation 410 Severn Ave., Suite 210 Annapolis MD 21403 Support information and updates are available at http://www.scyld.com/network/vortex.html*/static const char versionA[] ="3c59x.c:v0.99Q 5/16/2000 Donald Becker, becker@scyld.com\n";static const char versionB[] =" http://www.scyld.com/network/vortex.html\n";/* 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. */#define vortex_debug debug/* This driver uses 'options' to pass the media type, full-duplex flag, etc. See media_tbl[] and the web page for the possible types. There is no limit on card count, MAX_UNITS limits only module options. */#define MAX_UNITS 8static 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};/* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 32;/* Set the copy breakpoint for the copy-only-tiny-frames scheme. Setting to > 1512 effectively disables this feature. */static const int rx_copybreak = 200;/* Allow setting MTU to a larger size, bypassing the normal Ethernet setup. */static const int mtu = 1500;/* Use hardware checksums? */static int use_hw_csums = 1;/* For Cyclone,Tornado cards, polling interval for DownListPtr */static int down_poll_rate = 20;/* Autodetect link polarity reversal? */static int auto_polarity = 1;/* Operational parameters that are set at compile time. *//* Keep the ring sizes a power of two for compile 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/* 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.*/#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/version.h>#ifdef MODULE#ifdef MODVERSIONS#include <linux/modversions.h>#endif#include <linux/module.h>#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#endif#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/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <asm/irq.h>#include <asm/byteorder.h>#include <asm/bitops.h>#include <asm/io.h>/* Kernel compatibility defines, some common to David Hinds' PCMCIA package. This is only in the support-all-kernels source code. */#if (LINUX_VERSION_CODE <= 0x20100)#ifndef __alpha__#define ioremap(a,b) \ (((a)<0x100000) ? (void *)((u_long)(a)) : vremap(a,b))#define iounmap(v) \ do { if ((u_long)(v) > 0x100000) vfree(v); } while (0)#endif#endif#if LINUX_VERSION_CODE < 0x20138#define test_and_set_bit(val, addr) set_bit(val, addr)typedef long spinlock_t;#define SPIN_LOCK_UNLOCKED 0#define spin_lock(lock)#define spin_unlock(lock)#define spin_lock_irqsave(lock, flags) save_flags(flags); cli();#define spin_unlock_irqrestore(lock, flags) restore_flags(flags);#endif#if LINUX_VERSION_CODE < 0x20155#define PCI_SUPPORT_VER1#else#define PCI_SUPPORT_VER2#endif#if LINUX_VERSION_CODE < 0x20159#define dev_free_skb(skb) dev_kfree_skb (skb, FREE_WRITE);#else /* Grrr, incompatible changes should change the name. */#define dev_free_skb(skb) dev_kfree_skb(skb);#endif#if ! defined(CAP_NET_ADMIN)#define capable(CAP_XXX) (suser())#endif#define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))#define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("3Com EtherLink XL (3c590/3c900 series) driver");MODULE_LICENSE("GPL");MODULE_PARM(debug, "i");MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(use_hw_csums, "i");MODULE_PARM(down_poll_rate, "i");/* Operational parameter that usually are not changed. *//* Set iff a MII transceiver on any interface requires mdio preamble. This only set with the original DP83840 on older 3c905 boards, so the extra code size of a per-interface flag is not worthwhile. */static char mii_preamble_required = 0;/* Performance and path-coverage information. */static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;/* Theory of OperationI. Board CompatibilityThis device driver is designed for the 3Com FastEtherLink and FastEtherLinkXL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbsversions of the FastEtherLink cards. The supported product IDs arein the pci_tbl[] list.The related ISA 3c515 is supported with a separate driver, 3c515.c, includedwith the kernel source.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 should be set to assign thePCI INTA signal to an otherwise unused system IRQ line.The EEPROM settings for media type and forced-full-duplex are observed.The EEPROM media type should be left at the default "autoselect" unless using10base2 or AUI connections which cannot be reliably detected.III. Driver operationThe 3c59x series use an interface that's very similar to the previous 3c5x9series. The primary interface is two programmed-I/O FIFOs, with analternate single-contiguous-region bus-master transfer (see next).The 3c900 "Boomerang" series uses a full-bus-master interface with separatelists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,DEC Tulip and Intel Speedo3. The first chip version retains a compatibleprogrammed-I/O interface that has been removed in 'B' and subsequent boardrevisions.One extension that is advertised in a very large font is that the adaptersare capable of being bus masters. On the Vortex chip this capability wasonly for a single contiguous region making it far less useful than the fullbus master capability. There is a significant performance impact of takingan extra interrupt or polling for the completion of each transfer, as wellas difficulty sharing the single transfer engine between the transmit andreceive threads. Using DMA transfers is a win only with large blocks orwith the flawed versions of the Intel Orion motherboard PCI controller.The Boomerang chip's full-bus-master interface is useful, and has thecurrently-unused advantages over other similar chips that queued transmitpackets may be reordered and receive buffer groups are associated with asingle frame.With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.Rather than a fixed intermediate receive buffer, this scheme allocatesfull-sized skbuffs as receive buffers. The value RX_COPYBREAK is used asthe copying breakpoint: it is chosen to trade-off the memory wasted bypassing the full-sized skbuff to the queue layer for all frames vs. thecopying cost of copying a frame to a correctly-sized skbuff.IIIC. SynchronizationThe driver runs as two independent, single-threaded flows of control. Oneis the send-packet routine, which enforces single threaded by the tx queuesystem. The other thread is the interrupt handler, which is singlethreaded by the hardware and other software.IV. NotesThanks to Cameron Spitzer and Terry Murphy of 3Com for providing development3c590, 3c595, and 3c900 boards.The name "Vortex" is the internal 3Com project name for the PCI ASIC, andthe EISA version is called "Demon". According to Terry these names comefrom rides at the local amusement park.The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes.This driver only supports ethernet packets on some kernels because of theskbuff allocation limit of 4K.*//* This table drives the PCI probe routines. It's mostly boilerplate in all of the drivers, and will likely be provided by some future kernel.*/enum pci_flags_bit { PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,};struct pci_id_info { const char *name; u16 vendor_id, device_id, device_id_mask, flags; int drv_flags, io_size; struct net_device *(*probe1)(int pci_bus, int pci_devfn, struct net_device *dev, long ioaddr, int irq, int chip_idx, int fnd_cnt);};/* The Vortex size is twice that of the original EtherLinkIII series: the runtime register window, window 1, is now always mapped in. The Boomerang size is twice as large as the Vortex -- it has additional bus master control registers. */#define VORTEX_SIZE 0x20#define BOOMERANG_SIZE 0x40#define CYCLONE_SIZE 0x80enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8, HAS_PWR_CTRL=0x10, HAS_MII=0x20, HAS_NWAY=0x40, HAS_CB_FNS=0x80, EEPROM_8BIT=0x200, INVERT_LED_PWR=0x400, MII_XCVR_PWR=0x800, HAS_FIFO_BUG=0x1000, };static struct net_device *vortex_probe1(int pci_bus, int pci_devfn, struct net_device *dev, long ioaddr, int irq, int dev_id, int card_idx);static struct pci_id_info pci_tbl[] = { {"3c575 Boomerang CardBus", 0x10B7, 0x5057, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 64, vortex_probe1}, {"3CCFE575BT Cyclone CardBus", 0x10B7, 0x5157, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS| EEPROM_8BIT|INVERT_LED_PWR, 128, vortex_probe1}, {"3CCFE575CT Tornado CardBus", 0x10B7, 0x5257, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS| EEPROM_8BIT|MII_XCVR_PWR, 128, vortex_probe1}, {"3CCFE656 Cyclone CardBus", 0x10B7, 0x6560, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS| EEPROM_8BIT|INVERT_LED_PWR|MII_XCVR_PWR, 128, vortex_probe1}, {"3CCFEM656B Cyclone CardBus", 0x10B7, 0x6562, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS| EEPROM_8BIT|INVERT_LED_PWR|MII_XCVR_PWR, 128, vortex_probe1}, {"3CXFEM656C Tornado CardBus", 0x10B7, 0x6564, 0xffff, PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS| EEPROM_8BIT|MII_XCVR_PWR, 128, vortex_probe1}, {"3c575 series CardBus (unknown version)", 0x10B7, 0x5057, 0xf0ff, PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII| EEPROM_8BIT|INVERT_LED_PWR, 64, vortex_probe1}, {0,}, /* 0 terminated list. */};/* Operational definitions. These are not used by other compilation units and thus are not exported in a ".h" file. First the windows. There are eight register windows, with the command and status registers available in each. */#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)#define EL3_CMD 0x0e#define EL3_STATUS 0x0e/* The top five bits written to EL3_CMD are a command, the lower 11 bits are the parameter, if applicable. Note that 11 parameters bits was fine for ethernet, but the new chip can handle FDDI length frames (~4500 octets) and now parameters count 32-bit 'Dwords' rather than octets. */enum vortex_cmd { TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11, RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, UpStall = 6<<11, UpUnstall = (6<<11)+1, DownStall = (6<<11)+2, DownUnstall = (6<<11)+3, RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11, FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11, SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11, SetTxThreshold = 18<<11, SetTxStart = 19<<11, StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11, StatsDisable = 22<<11, StopCoax = 23<<11, SetTxReclaim = 24<<11, SetFilterBit = 25<<11,};/* The SetRxFilter command accepts the following classes: */enum RxFilter { RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };/* Bits in the general status register. */enum vortex_status { IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004, TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020, IntReq = 0x0040, StatsFull = 0x0080, DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10, DMAInProgress = 1<<11, /* DMA controller is still busy.*/ CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/};/* Register window 1 offsets, the window used in normal operation. On the Vortex this window is always mapped at offsets 0x10-0x1f. */enum Window1 { TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14, RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B, TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */};enum Window0 { Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */ Wn0EepromData = 12, /* Window 0: EEPROM results register. */ IntrStatus=0x0E, /* Valid in all windows. */};enum Win0_EEPROM_bits { EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0, EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */ EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */};/* EEPROM locations. */enum eeprom_offset { PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3, EtherLink3ID=7, IFXcvrIO=8, IRQLine=9, NodeAddr01=10, NodeAddr23=11, NodeAddr45=12, DriverTune=13, Checksum=15};enum Window2 { /* Window 2. */ Wn2_ResetOptions=12,};enum Window3 { /* Window 3: MAC/config bits. */ Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,};union wn3_config { int i; struct w3_config_fields { unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2; int pad8:8; unsigned int ram_split:2, pad18:2, xcvr:4, autoselect:1; int pad24:7; } u;};enum Window4 { /* Window 4: Xcvr/media bits. */ Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,};enum Win4_Media_bits { Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */ Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */ Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -