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

📄 3c515.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/* 3c515.c: A 3Com ISA EtherLink XL "Corkscrew" ethernet driver for linux. *//*	Written 1997-1998 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 ISA EtherLink XL "Corkscrew" 3c515 ethercard.	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 = "3c515.c:v0.99 4/7/98 becker@cesdis.gsfc.nasa.gov\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 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;/* 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/version.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/ptrace.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/timer.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#define NEW_MULTICAST#include <linux/delay.h>/* Kernel version compatibility functions. */#define RUN_AT(x) (jiffies + (x))#define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)#define FREE_IRQ(irqnum, dev) free_irq(irqnum, dev)#define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)#define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)#if (LINUX_VERSION_CODE < 0x20123)#define test_and_set_bit(val, addr) set_bit(val, addr)#elif defined(MODULE)MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");MODULE_DESCRIPTION("3Com 3c515 Corkscrew 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");#endif/* "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 = 0, rx_copy = 0, queued_packet = 0;/* 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 HAVE_DEVLISTstruct netdev_entry tc515_drv ={"3c515", tc515_probe, CORKSCREW_TOTAL_SIZE, NULL};#endif#ifdef DRIVER_DEBUGint vortex_debug = DRIVER_DEBUG;#elseint vortex_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 thedev->tbusy flag.  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 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,};/* 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, 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,};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:3, pad21:1, autoselect:1;		int pad24:7;	} u;};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 vortex_private {	char devname[8];			/* "ethN" string, also for kernel debug. */	const char *product_name;	struct device *next_module;	/* 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 enet_statistics 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;};/* 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},};static int vortex_scan(struct device *dev);static struct device *vortex_found_device(struct device *dev, int ioaddr,										  int irq, int product_index,										  int options);static int vortex_probe1(struct device *dev);static int vortex_open(struct device *dev);static void vortex_timer(unsigned long arg);static int vortex_start_xmit(struct sk_buff *skb, struct device *dev);static int vortex_rx(struct device *dev);static int boomerang_rx(struct device *dev);static void vortex_interrupt IRQ(int irq, void *dev_id, struct pt_regs *regs);static int vortex_close(struct device *dev);static void update_stats(int addr, struct device *dev);static struct enet_statistics *vortex_get_stats(struct device *dev);static void set_rx_mode(struct device *dev);/* Unlike the other PCI cards the 59x cards don't need a large contiguous   memory region, so making the driver a loadable module is feasible.   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 vortex_scan()   vortex_scan()  		 The common routine that scans for PCI and EISA cards   vortex_found_device() Allocate a device structure when we find a card.					Different versions exist for modules and built-in.

⌨️ 快捷键说明

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