⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3c59x.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 5 页
字号:
/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. *//*	Written 1996-1999 by Donald Becker.	This software may be used and distributed according to the terms	of the GNU Public License, incorporated herein by reference.	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 author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O	Center of Excellence in Space Data and Information Sciences	   Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771*/static char *version ="3c59x.c:v0.99L 5/28/99 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/vortex.html\n";/* "Knobs" that adjust features and parameters. *//* 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;/* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 20;/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */#define vortex_debug debug#ifdef VORTEX_DEBUGstatic int vortex_debug = VORTEX_DEBUG;#elsestatic int vortex_debug = 1;#endif/* Some values here only for performance evaluation and path-coverage   debugging. */static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;/* A few values that may be tweaked. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT  (2*HZ)/* Keep the ring sizes a power of two for efficiency. */#define TX_RING_SIZE	16#define RX_RING_SIZE	32#define PKT_BUF_SZ		1536			/* Size of each temporary Rx buffer.*/#ifndef __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/sched.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#if LINUX_VERSION_CODE < 0x20155#include <linux/bios32.h>#endif#include <asm/irq.h>			/* For NR_IRQS only. */#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. */#define RUN_AT(x) (jiffies + (x))#include <linux/delay.h>#if (LINUX_VERSION_CODE >= 0x20100)char kernel_version[] = UTS_RELEASE;#else#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 <= 0x20139#define	net_device_stats enet_statistics#define NETSTATS_VER2#endif#if LINUX_VERSION_CODE < 0x20138#define test_and_set_bit(val, addr) set_bit(val, addr)#define le32_to_cpu(val) (val)#define cpu_to_le32(val) (val)#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#if defined(MODULE) && LINUX_VERSION_CODE > 0x20115MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");MODULE_DESCRIPTION("3Com 3c590/3c900 series Vortex/Boomerang driver");MODULE_PARM(debug, "i");MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");MODULE_PARM(rx_copybreak, "i");MODULE_PARM(max_interrupt_work, "i");MODULE_PARM(compaq_ioaddr, "i");MODULE_PARM(compaq_irq, "i");MODULE_PARM(compaq_device_id, "i");#endif/* Operational parameter that usually are not changed. *//* 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_TOTAL_SIZE 0x20#define BOOMERANG_TOTAL_SIZE 0x40/* 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;/*				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 are  3c590, 3c592, 3c595, 3c597, 3c900, 3c905The related ISA 3c515 is supported with a separate driver, 3c515.c, includedwith the kernel source or available from    cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.htmlII. 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 use by thedev->tbusy flag.  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 because of the skbuff allocationlimit 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 device *(*probe1)(int pci_bus, int pci_devfn, struct device *dev,							 long ioaddr, int irq, int chip_idx, int fnd_cnt);};enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4,	   HAS_PWR_CTRL=0x10, HAS_MII=0x20, HAS_NWAY=0x40, HAS_CB_FNS=0x80, };static struct device *vortex_probe1(int pci_bus, int pci_devfn,									struct device *dev, long ioaddr,									int irq, int dev_id, int card_idx);static struct pci_id_info pci_tbl[] = {	{"3c590 Vortex 10Mbps",			0x10B7, 0x5900, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},	{"3c595 Vortex 100baseTx",		0x10B7, 0x5950, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},	{"3c595 Vortex 100baseT4",		0x10B7, 0x5951, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},	{"3c595 Vortex 100base-MII",	0x10B7, 0x5952, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},	{"3Com Vortex",					0x10B7, 0x5900, 0xff00,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},	{"3c900 Boomerang 10baseT",		0x10B7, 0x9000, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},	{"3c900 Boomerang 10Mbps Combo", 0x10B7, 0x9001, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},	{"3c900 Cyclone 10Mbps Combo", 0x10B7, 0x9005, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c900B-FL Cyclone 10base-FL",	0x10B7, 0x900A, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c905 Boomerang 100baseTx",	0x10B7, 0x9050, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},	{"3c905 Boomerang 100baseT4",	0x10B7, 0x9051, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},	{"3c905B Cyclone 100baseTx",	0x10B7, 0x9055, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},	{"3c905B Cyclone 10/100/BNC",	0x10B7, 0x9058, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},	{"3c905B-FX Cyclone 100baseFx",	0x10B7, 0x905A, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c905C Tornado",	0x10B7, 0x9200, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c980 Cyclone",	0x10B7, 0x9800, 0xfff0,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3cSOHO100-TX Hurricane",	0x10B7, 0x7646, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c555 Laptop Hurricane",	0x10B7, 0x5055, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},	{"3c575 Boomerang CardBus",		0x10B7, 0x5057, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},	{"3CCFE575 Cyclone CardBus",	0x10B7, 0x5157, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,	 128, vortex_probe1},	{"3CCFE656 Cyclone CardBus",	0x10B7, 0x6560, 0xffff,	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,	 128, vortex_probe1},	{"3c575 series CardBus (unknown version)", 0x10B7, 0x5057, 0xf0ff,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},	{"3Com Boomerang (unknown version)",	0x10B7, 0x9000, 0xff00,	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 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, 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;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -