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

📄 3c509.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 3 页
字号:
/* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. *//*	Written 1993-2000 by Donald Becker.	Copyright 1994-2000 by Donald Becker.	Copyright 1993 United States Government as represented by the	Director, National Security Agency.	 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 EtherLinkIII series.	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403	Known limitations:	Because of the way 3c509 ISA detection works it's difficult to predict	a priori which of several ISA-mode cards will be detected first.	This driver does not use predictive interrupt mode, resulting in higher	packet latency but lower overhead.  If interrupts are disabled for an	unusually long time it could also result in missed packets, but in	practice this rarely happens.	FIXES:		Alan Cox:       Removed the 'Unexpected interrupt' bug.		Michael Meskes:	Upgraded to Donald Becker's version 1.07.		Alan Cox:	Increased the eeprom delay. Regardless of 				what the docs say some people definitely				get problems with lower (but in card spec)				delays		v1.10 4/21/97 Fixed module code so that multiple cards may be detected,				other cleanups.  -djb		Andrea Arcangeli:	Upgraded to Donald Becker's version 1.12.		Rick Payne:	Fixed SMP race condition		v1.13 9/8/97 Made 'max_interrupt_work' an insmod-settable variable -djb		v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb		v1.15 1/31/98 Faster recovery for Tx errors. -djb		v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb		v1.18 12Mar2001 Andrew Morton <andrewm@uow.edu.au>			- Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz)			- Reviewed against 1.18 from scyld.com		v1.18a 17Nov2001 Jeff Garzik <jgarzik@mandrakesoft.com>			- ethtool support*/#define DRV_NAME	"3c509"#define DRV_VERSION	"1.18a"#define DRV_RELDATE	"17Nov2001"/* A few values that may be tweaked. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT  (400*HZ/1000)/* Maximum events (Rx packets, etc.) to handle at each interrupt. */static int max_interrupt_work = 10;#include <linux/config.h>#include <linux/module.h>#include <linux/mca.h>#include <linux/isapnp.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/interrupt.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/slab.h>#include <linux/ioport.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/delay.h>	/* for udelay() */#include <linux/spinlock.h>#include <linux/ethtool.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/irq.h>static char versionA[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE "becker@scyld.com\n";static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";#ifdef EL3_DEBUGstatic int el3_debug = EL3_DEBUG;#elsestatic int el3_debug = 2;#endif/* To minimize the size of the driver source I only define operating   constants if they are used several times.  You'll need the manual   anyway if you want to understand driver details. *//* Offsets from base I/O address. */#define EL3_DATA 0x00#define EL3_CMD 0x0e#define EL3_STATUS 0x0e#define	 EEPROM_READ 0x80#define EL3_IO_EXTENT	16#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)/* The top five bits written to EL3_CMD are a command, the lower   11 bits are the parameter, if applicable. */enum c509cmd {	TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,	RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, 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, StatsEnable = 21<<11,	StatsDisable = 22<<11, StopCoax = 23<<11,};enum c509status {	IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,	TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,	IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };/* The SetRxFilter command accepts the following classes: */enum RxFilter {	RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };/* Register window 1 offsets, the window used in normal operation. */#define TX_FIFO		0x00#define RX_FIFO		0x00#define RX_STATUS 	0x08#define TX_STATUS 	0x0B#define TX_FREE		0x0C		/* Remaining free bytes in Tx buffer. */#define WN0_IRQ		0x08		/* Window 0: Set IRQ line in bits 12-15. */#define WN4_MEDIA	0x0A		/* Window 4: Various transcvr/media bits. */#define  MEDIA_TP	0x00C0		/* Enable link beat and jabber for 10baseT. *//* * Must be a power of two (we use a binary and in the * circular queue) */#define SKB_QUEUE_SIZE	64struct el3_private {	struct net_device_stats stats;	struct net_device *next_dev;	spinlock_t lock;	/* skb send-queue */	int head, size;	struct sk_buff *queue[SKB_QUEUE_SIZE];	char mca_slot;};static int id_port __initdata = 0x110;	/* Start with 0x110 to avoid new sound cards.*/static struct net_device *el3_root_dev;static ushort id_read_eeprom(int index);static ushort read_eeprom(int ioaddr, int index);static int el3_open(struct net_device *dev);static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);static void el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void update_stats(struct net_device *dev);static struct net_device_stats *el3_get_stats(struct net_device *dev);static int el3_rx(struct net_device *dev);static int el3_close(struct net_device *dev);static void set_multicast_list(struct net_device *dev);static void el3_tx_timeout (struct net_device *dev);static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);#ifdef CONFIG_MCAstruct el3_mca_adapters_struct {	char* name;	int id;};static struct el3_mca_adapters_struct el3_mca_adapters[] __initdata = {	{ "3Com 3c529 EtherLink III (10base2)", 0x627c },	{ "3Com 3c529 EtherLink III (10baseT)", 0x627d },	{ "3Com 3c529 EtherLink III (test mode)", 0x62db },	{ "3Com 3c529 EtherLink III (TP or coax)", 0x62f6 },	{ "3Com 3c529 EtherLink III (TP)", 0x62f7 },	{ NULL, 0 },};#endif /* CONFIG_MCA */#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)static struct isapnp_device_id el3_isapnp_adapters[] __initdata = {	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5090),		(long) "3Com Etherlink III (TP)" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5091),		(long) "3Com Etherlink III" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5094),		(long) "3Com Etherlink III (combo)" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5095),		(long) "3Com Etherlink III (TPO)" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5098),		(long) "3Com Etherlink III (TPC)" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f7),		(long) "3Com Etherlink III compatible" },	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,		ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f8),		(long) "3Com Etherlink III compatible" },	{ }	/* terminate list */};MODULE_DEVICE_TABLE(isapnp, el3_isapnp_adapters);MODULE_LICENSE("GPL");static u16 el3_isapnp_phys_addr[8][3];#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */static int nopnp;int __init el3_probe(struct net_device *dev){	struct el3_private *lp;	short lrs_state = 0xff, i;	int ioaddr, irq, if_port;	u16 phys_addr[3];	static int current_tag;	int mca_slot = -1;#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)	static int pnp_cards;#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */	if (dev) SET_MODULE_OWNER(dev);	/* First check all slots of the EISA bus.  The next slot address to	   probe is kept in 'eisa_addr' to support multiple probe() calls. */	if (EISA_bus) {		static int eisa_addr = 0x1000;		while (eisa_addr < 0x9000) {			int device_id;			ioaddr = eisa_addr;			eisa_addr += 0x1000;			/* Check the standard EISA ID register for an encoded '3Com'. */			if (inw(ioaddr + 0xC80) != 0x6d50)				continue;			/* Avoid conflict with 3c590, 3c592, 3c597, etc */			device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);			if ((device_id & 0xFF00) == 0x5900) {				continue;			}			/* Change the register set to the configuration window 0. */			outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);			irq = inw(ioaddr + WN0_IRQ) >> 12;			if_port = inw(ioaddr + 6)>>14;			for (i = 0; i < 3; i++)				phys_addr[i] = htons(read_eeprom(ioaddr, i));			/* Restore the "Product ID" to the EEPROM read register. */			read_eeprom(ioaddr, 3);			/* Was the EISA code an add-on hack?  Nahhhhh... */			goto found;		}	}#ifdef CONFIG_MCA	/* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily	 * modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca)	 * to support standard MCA probing.	 *	 * redone for multi-card detection by ZP Gu (zpg@castle.net)	 * now works as a module	 */	if( MCA_bus ) {		int slot, j;		u_char pos4, pos5;		for( j = 0; el3_mca_adapters[j].name != NULL; j ++ ) {			slot = 0;			while( slot != MCA_NOTFOUND ) {				slot = mca_find_unused_adapter(					el3_mca_adapters[j].id, slot );				if( slot == MCA_NOTFOUND ) break;				/* if we get this far, an adapter has been				 * detected and is enabled				 */				pos4 = mca_read_stored_pos( slot, 4 );				pos5 = mca_read_stored_pos( slot, 5 );				ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;				irq = pos5 & 0x0f;				/* probing for a card at a particular IO/IRQ */				if(dev && ((dev->irq >= 1 && dev->irq != irq) ||			   	(dev->base_addr >= 1 && dev->base_addr != ioaddr))) {					slot++;         /* probing next slot */					continue;				}				printk("3c509: found %s at slot %d\n",					el3_mca_adapters[j].name, slot + 1 );				/* claim the slot */				mca_set_adapter_name(slot, el3_mca_adapters[j].name);				mca_set_adapter_procfn(slot, NULL, NULL);				mca_mark_as_used(slot);				if_port = pos4 & 0x03;				if (el3_debug > 2) {					printk("3c529: irq %d  ioaddr 0x%x  ifport %d\n", irq, ioaddr, if_port);				}				EL3WINDOW(0);				for (i = 0; i < 3; i++) {					phys_addr[i] = htons(read_eeprom(ioaddr, i));				}								mca_slot = slot;				goto found;			}		}		/* if we get here, we didn't find an MCA adapter */		return -ENODEV;	}#endif /* CONFIG_MCA */#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)	if (nopnp == 1)		goto no_pnp;	for (i=0; el3_isapnp_adapters[i].vendor != 0; i++) {		struct pci_dev *idev = NULL;		int j;		while ((idev = isapnp_find_dev(NULL,						el3_isapnp_adapters[i].vendor,						el3_isapnp_adapters[i].function,						idev))) {			idev->prepare(idev);			/* Deactivation is needed if the driver was called			   with "nopnp=1" before, does not harm if not. */			idev->deactivate(idev);			idev->activate(idev);			if (!idev->resource[0].start || check_region(idev->resource[0].start, EL3_IO_EXTENT))				continue;			ioaddr = idev->resource[0].start;			if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509 PnP"))				return -EBUSY;			irq = idev->irq_resource[0].start;			if (el3_debug > 3)				printk ("ISAPnP reports %s at i/o 0x%x, irq %d\n",					(char*) el3_isapnp_adapters[i].driver_data, ioaddr, irq);			EL3WINDOW(0);			for (j = 0; j < 3; j++)				el3_isapnp_phys_addr[pnp_cards][j] =					phys_addr[j] =						htons(read_eeprom(ioaddr, j));			if_port = read_eeprom(ioaddr, 8) >> 14;			pnp_cards++;			goto found;		}	}no_pnp:#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */	/* Select an open I/O location at 0x1*0 to do contention select. */	for ( ; id_port < 0x200; id_port += 0x10) {		if (check_region(id_port, 1))			continue;		outb(0x00, id_port);		outb(0xff, id_port);		if (inb(id_port) & 0x01)			break;	}	if (id_port >= 0x200) {		/* Rare -- do we really need a warning? */		printk(" WARNING: No I/O port available for 3c509 activation.\n");		return -ENODEV;	}	/* Next check for all ISA bus boards by sending the ID sequence to the

⌨️ 快捷键说明

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