3c515.c

来自「linux 内核源代码」· C语言 代码 · 共 1,591 行 · 第 1/4 页

C
1,591
字号
/*	Written 1997-1998 by Donald Becker.	This software may be used and distributed according to the terms	of the GNU General Public License, incorporated herein by reference.	This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403	2000/2/2- Added support for kernel-level ISAPnP		by Stephen Frost <sfrost@snowman.net> and Alessandro Zummo	Cleaned up for 2.3.x/softnet by Jeff Garzik and Alan Cox.	2001/11/17 - Added ethtool support (jgarzik)	2002/10/28 - Locking updates for 2.5 (alan@redhat.com)*/#define DRV_NAME		"3c515"#define DRV_VERSION		"0.99t-ac"#define DRV_RELDATE		"28-Oct-2002"static char *version =DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " becker@scyld.com and others\n";#define CORKSCREW 1/* "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 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;/* Enable the automatic media selection code -- usually set. */#define AUTOMEDIA 1/* Allow the use of fragment bus master transfers instead of only   programmed-I/O for Vortex cards.  Full-bus-master transfers are always   enabled by default on Boomerang cards.  If VORTEX_BUS_MASTER is defined,   the feature may be turned on using 'options'. */#define VORTEX_BUS_MASTER/* A few values that may be tweaked. *//* Keep the ring sizes a power of two for efficiency. */#define TX_RING_SIZE	16#define RX_RING_SIZE	16#define PKT_BUF_SZ		1536	/* Size of each temporary Rx buffer. */#include <linux/module.h>#include <linux/isapnp.h>#include <linux/kernel.h>#include <linux/netdevice.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/skbuff.h>#include <linux/etherdevice.h>#include <linux/interrupt.h>#include <linux/timer.h>#include <linux/ethtool.h>#include <linux/bitops.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/dma.h>#define NEW_MULTICAST#include <linux/delay.h>#define MAX_UNITS 8MODULE_AUTHOR("Donald Becker <becker@scyld.com>");MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");MODULE_LICENSE("GPL");MODULE_VERSION(DRV_VERSION);/* "Knobs" for adjusting internal parameters. *//* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */#define DRIVER_DEBUG 1/* Some values here only for performance evaluation and path-coverage   debugging. */static int rx_nocopy, rx_copy, queued_packet;/* Number of times to check to see if the Tx FIFO has space, used in some   limited cases. */#define WAIT_TX_AVAIL 200/* Operational parameter that usually are not changed. */#define TX_TIMEOUT  40		/* Time in jiffies before concluding Tx hung *//* The size here is somewhat misleading: the Corkscrew also uses the ISA   aliased registers at <base>+0x400.   */#define CORKSCREW_TOTAL_SIZE 0x20#ifdef DRIVER_DEBUGstatic int corkscrew_debug = DRIVER_DEBUG;#elsestatic int corkscrew_debug = 1;#endif#define CORKSCREW_ID 10/*				Theory of OperationI. Board CompatibilityThis device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,3Com's ISA bus adapter for Fast Ethernet.  Due to the unique I/O port layout,it's not practical to integrate this driver with the other EtherLink drivers.II. Board-specific settingsThe Corkscrew has an EEPROM for configuration, but no special settings areneeded for Linux.III. Driver operationThe 3c515 series use an interface that's very similar to the 3c900 "Boomerang"PCI cards, with the bus master interface extensively modified to work withthe ISA bus.The card is capable of full-bus-master transfers with separatelists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,DEC Tulip and Intel Speedo3.This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediatereceive buffer.  This scheme allocates full-sized skbuffs as receivebuffers.  The value RX_COPYBREAK is used as the copying breakpoint: it ischosen to trade-off the memory wasted by passing the full-sized skbuff tothe queue layer for all frames vs. the copying cost of copying a frame to acorrectly-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 the netiflayer.  The other thread is the interrupt handler, which is singlethreaded by the hardware and other software.IV. NotesThanks to Terry Murphy of 3Com for providing documentation and a developmentboard.The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Comproject names.  I use these names to eliminate confusion -- 3Com productnumbers and names are very similar and often confused.The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!This driver only supports ethernet frames because of the recent MTU limitof 1.5K, but the changes to support 4.5K are minimal.*//* 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 chips   can handle FDDI length frames (~4500 octets) and now parameters count   32-bit 'Dwords' rather than octets. */enum corkscrew_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,};/* The SetRxFilter command accepts the following classes: */enum RxFilter {	RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8};/* Bits in the general status register. */enum corkscrew_status {	IntLatch = 0x0001, AdapterFailure = 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 Corkscrew 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 {	Wn0IRQ = 0x08,#if defined(CORKSCREW)	Wn0EepromCmd = 0x200A,	/* Corkscrew EEPROM command register. */	Wn0EepromData = 0x200C,	/* Corkscrew EEPROM results register. */#else	Wn0EepromCmd = 10,	/* Window 0: EEPROM command register. */	Wn0EepromData = 12,	/* Window 0: EEPROM results register. */#endif};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,};enum Window3 {			/* Window 3: MAC/config bits. */	Wn3_Config = 0, Wn3_MAC_Ctrl = 6, Wn3_Options = 8,};enum wn3_config {	Ram_size = 7,	Ram_width = 8,	Ram_speed = 0x30,	Rom_size = 0xc0,	Ram_split_shift = 16,	Ram_split = 3 << Ram_split_shift,	Xcvr_shift = 20,	Xcvr = 7 << Xcvr_shift,	Autoselect = 0x1000000,};enum Window4 {	Wn4_NetDiag = 6, Wn4_Media = 10,	/* Window 4: Xcvr/media bits. */};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. */	Media_LnkBeat = 0x0800,};enum Window7 {			/* Window 7: Bus Master control. */	Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,};/* Boomerang-style bus master control registers.  Note ISA aliases! */enum MasterCtrl {	PktStatus = 0x400, DownListPtr = 0x404, FragAddr = 0x408, FragLen =	    0x40c,	TxFreeThreshold = 0x40f, UpPktStatus = 0x410, UpListPtr = 0x418,};/* The Rx and Tx descriptor lists.   Caution Alpha hackers: these types are 32 bits!  Note also the 8 byte   alignment contraint on tx_ring[] and rx_ring[]. */struct boom_rx_desc {	u32 next;	s32 status;	u32 addr;	s32 length;};/* Values for the Rx status entry. */enum rx_desc_status {	RxDComplete = 0x00008000, RxDError = 0x4000,	/* See boomerang_rx() for actual error bits */};struct boom_tx_desc {	u32 next;	s32 status;	u32 addr;	s32 length;};struct corkscrew_private {	const char *product_name;	struct list_head list;	struct net_device *our_dev;	/* The Rx and Tx rings are here to keep them quad-word-aligned. */	struct boom_rx_desc rx_ring[RX_RING_SIZE];	struct boom_tx_desc tx_ring[TX_RING_SIZE];	/* The addresses of transmit- and receive-in-place skbuffs. */	struct sk_buff *rx_skbuff[RX_RING_SIZE];	struct sk_buff *tx_skbuff[TX_RING_SIZE];	unsigned int cur_rx, cur_tx;	/* The next free ring entry */	unsigned int dirty_rx, dirty_tx;/* The ring entries to be free()ed. */	struct net_device_stats stats;	struct sk_buff *tx_skb;	/* Packet being eaten by bus master ctrl.  */	struct timer_list timer;	/* Media selection timer. */	int capabilities	;	/* Adapter capabilities word. */	int options;			/* User-settable misc. driver options. */	int last_rx_packets;		/* For media autoselection. */	unsigned int available_media:8,	/* From Wn3_Options */		media_override:3,	/* Passed-in media type. */		default_media:3,	/* Read from the EEPROM. */		full_duplex:1, autoselect:1, bus_master:1,	/* Vortex can only do a fragment bus-m. */		full_bus_master_tx:1, full_bus_master_rx:1,	/* Boomerang  */		tx_full:1;	spinlock_t lock;	struct device *dev;};/* The action to take with a media selection timer tick.   Note that we deviate from the 3Com order by checking 10base2 before AUI. */enum xcvr_types {	XCVR_10baseT = 0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,	XCVR_100baseFx, XCVR_MII = 6, XCVR_Default = 8,};static struct media_table {	char *name;	unsigned int media_bits:16,	/* Bits to set in Wn4_Media register. */		mask:8,			/* The transceiver-present bit in Wn3_Config. */		next:8;			/* The media type to try next. */	short wait;			/* Time before we check media status. */} media_tbl[] = {	{ "10baseT", Media_10TP, 0x08, XCVR_10base2, (14 * HZ) / 10 },	{ "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1 * HZ) / 10},	{ "undefined", 0, 0x80, XCVR_10baseT, 10000},	{ "10base2", 0, 0x10, XCVR_AUI, (1 * HZ) / 10},	{ "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14 * HZ) / 10},	{ "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14 * HZ) / 10},	{ "MII", 0, 0x40, XCVR_10baseT, 3 * HZ},	{ "undefined", 0, 0x01, XCVR_10baseT, 10000},	{ "Default", 0, 0xFF, XCVR_10baseT, 10000},};#ifdef __ISAPNP__static struct isapnp_device_id corkscrew_isapnp_adapters[] = {	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5051),		(long) "3Com Fast EtherLink ISA" },	{ }	/* terminate list */};MODULE_DEVICE_TABLE(isapnp, corkscrew_isapnp_adapters);static int nopnp;#endif /* __ISAPNP__ */static struct net_device *corkscrew_scan(int unit);static int corkscrew_setup(struct net_device *dev, int ioaddr,			    struct pnp_dev *idev, int card_number);static int corkscrew_open(struct net_device *dev);static void corkscrew_timer(unsigned long arg);static int corkscrew_start_xmit(struct sk_buff *skb,				struct net_device *dev);static int corkscrew_rx(struct net_device *dev);static void corkscrew_timeout(struct net_device *dev);static int boomerang_rx(struct net_device *dev);static irqreturn_t corkscrew_interrupt(int irq, void *dev_id);static int corkscrew_close(struct net_device *dev);static void update_stats(int addr, struct net_device *dev);static struct net_device_stats *corkscrew_get_stats(struct net_device *dev);static void set_rx_mode(struct net_device *dev);static const struct ethtool_ops netdev_ethtool_ops;/*   Unfortunately maximizing the shared code between the integrated and   module version of the driver results in a complicated set of initialization   procedures.   init_module() -- modules /  tc59x_init()  -- built-in		The wrappers for corkscrew_scan()   corkscrew_scan()  		 The common routine that scans for PCI and EISA cards   corkscrew_found_device() Allocate a device structure when we find a card.					Different versions exist for modules and built-in.   corkscrew_probe1()		Fill in the device structure -- this is separated					so that the modules code can put it in dev->init.*//* This driver uses 'options' to pass the media type, full-duplex flag, etc. */

⌨️ 快捷键说明

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