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

📄 ewrk3.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*  ewrk3.c: A DIGITAL EtherWORKS 3 ethernet driver for Linux.   Written 1994 by David C. Davies.   Copyright 1994 Digital Equipment Corporation.   This software may be used and distributed according to the terms of   the GNU Public License, incorporated herein by reference.   This driver is written for the Digital Equipment Corporation series   of EtherWORKS ethernet cards:   DE203 Turbo (BNC)   DE204 Turbo (TP)   DE205 Turbo (TP BNC)   The driver has been tested on a relatively busy  network using the DE205   card and benchmarked with 'ttcp': it transferred 16M  of data at 975kB/s   (7.8Mb/s) to a DECstation 5000/200.   The author may be reached at davies@maniac.ultranet.com.   =========================================================================   This driver has been written  substantially  from scratch, although  its   inheritance of style and stack interface from 'depca.c' and in turn from   Donald Becker's 'lance.c' should be obvious.   The  DE203/4/5 boards  all  use a new proprietary   chip in place of the   LANCE chip used in prior cards  (DEPCA, DE100, DE200/1/2, DE210, DE422).   Use the depca.c driver in the standard distribution  for the LANCE based   cards from DIGITAL; this driver will not work with them.   The DE203/4/5 cards have 2  main modes: shared memory  and I/O only. I/O   only makes  all the card accesses through  I/O transactions and  no high   (shared)  memory is used. This  mode provides a >48% performance penalty   and  is deprecated in this  driver,  although allowed to provide initial   setup when hardstrapped.   The shared memory mode comes in 3 flavours: 2kB, 32kB and 64kB. There is   no point in using any mode other than the 2kB  mode - their performances   are virtually identical, although the driver has  been tested in the 2kB   and 32kB modes. I would suggest you uncomment the line:   FORCE_2K_MODE;   to allow the driver to configure the card as a  2kB card at your current   base  address, thus leaving more  room to clutter  your  system box with   other memory hungry boards.   As many ISA  and EISA cards  can be supported  under this driver  as you   wish, limited primarily  by the available IRQ lines,  rather than by the   available I/O addresses  (24 ISA,  16 EISA).   I have  checked different   configurations of  multiple  depca cards and  ewrk3 cards  and have  not   found a problem yet (provided you have at least depca.c v0.38) ...   The board IRQ setting   must be at  an unused  IRQ which is  auto-probed   using  Donald  Becker's autoprobe  routines.   All  these cards   are at   {5,10,11,15}.   No 16MB memory  limitation should exist with this  driver as DMA is  not   used and the common memory area is in low memory on the network card (my   current system has 20MB and I've not had problems yet).   The ability to load  this driver as a  loadable module has been included   and used  extensively during the  driver development (to save those long   reboot sequences). To utilise this ability, you have to do 8 things:   0) have a copy of the loadable modules code installed on your system.   1) copy ewrk3.c from the  /linux/drivers/net directory to your favourite   temporary directory.   2) edit the  source code near  line 1898 to reflect  the I/O address and   IRQ you're using.   3) compile  ewrk3.c, but include -DMODULE in  the command line to ensure   that the correct bits are compiled (see end of source code).   4) if you are wanting to add a new  card, goto 5. Otherwise, recompile a   kernel with the ewrk3 configuration turned off and reboot.   5) insmod ewrk3.o   [Alan Cox: Changed this so you can insmod ewrk3.o irq=x io=y]   6) run the net startup bits for your new eth?? interface manually   (usually /etc/rc.inet[12] at boot time).   7) enjoy!   Note that autoprobing is not allowed in loadable modules - the system is   already up and running and you're messing with interrupts.   To unload a module, turn off the associated interface   'ifconfig eth?? down' then 'rmmod ewrk3'.   Promiscuous   mode has been  turned  off  in this driver,   but  all the   multicast  address bits  have been   turned on. This  improved the  send   performance on a busy network by about 13%.   Ioctl's have now been provided (primarily because  I wanted to grab some   packet size statistics). They  are patterned after 'plipconfig.c' from a   suggestion by Alan Cox.  Using these  ioctls, you can enable promiscuous   mode, add/delete multicast  addresses, change the hardware address,  get   packet size distribution statistics and muck around with the control and   status register. I'll add others if and when the need arises.   TO DO:   ------   Revision History   ----------------   Version   Date        Description   0.1     26-aug-94   Initial writing. ALPHA code release.   0.11    31-aug-94   Fixed: 2k mode memory base calc.,   LeMAC version calc.,   IRQ vector assignments during autoprobe.   0.12    31-aug-94   Tested working on LeMAC2 (DE20[345]-AC) card.   Fixed up MCA hash table algorithm.   0.20     4-sep-94   Added IOCTL functionality.   0.21    14-sep-94   Added I/O mode.   0.21axp 15-sep-94   Special version for ALPHA AXP Linux V1.0.   0.22    16-sep-94   Added more IOCTLs & tidied up.   0.23    21-sep-94   Added transmit cut through.   0.24    31-oct-94   Added uid checks in some ioctls.   0.30     1-nov-94   BETA code release.   0.31     5-dec-94   Added check/allocate region code.   0.32    16-jan-95   Broadcast packet fix.   0.33    10-Feb-95   Fix recognition bug reported by <bkm@star.rl.ac.uk>.   0.40    27-Dec-95   Rationalise MODULE and autoprobe code.   Rewrite for portability & updated.   ALPHA support from <jestabro@amt.tay1.dec.com>   Added verify_area() calls in ewrk3_ioctl() from   suggestion by <heiko@colossus.escape.de>.   Add new multicasting code.   0.41    20-Jan-96   Fix IRQ set up problem reported by   <kenneth@bbs.sas.ntu.ac.sg>.   0.42    22-Apr-96      Fix alloc_device() bug <jari@markkus2.fimr.fi>   0.43    16-Aug-96      Update alloc_device() to conform to de4x5.c   ========================================================================= */static const char *version = "ewrk3.c:v0.43 96/8/16 davies@maniac.ultranet.com\n";#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/ptrace.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/init.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <asm/uaccess.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/time.h>#include <linux/types.h>#include <linux/unistd.h>#include <linux/ctype.h>#include "ewrk3.h"#ifdef EWRK3_DEBUGstatic int ewrk3_debug = EWRK3_DEBUG;#elsestatic int ewrk3_debug = 1;#endif#define EWRK3_NDA 0xffe0	/* No Device Address */#define PROBE_LENGTH    32#define ETH_PROM_SIG    0xAA5500FFUL#ifndef EWRK3_SIGNATURE#define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}#define EWRK3_STRLEN 8#endif#ifndef EWRK3_RAM_BASE_ADDRESSES#define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}#endif/*   ** Sets up the I/O area for the autoprobe. */#define EWRK3_IO_BASE 0x100	/* Start address for probe search */#define EWRK3_IOP_INC 0x20	/* I/O address increment */#define EWRK3_TOTAL_SIZE 0x20	/* required I/O address length */#ifndef MAX_NUM_EWRK3S#define MAX_NUM_EWRK3S 21#endif#ifndef EWRK3_EISA_IO_PORTS#define EWRK3_EISA_IO_PORTS 0x0c00	/* I/O port base address, slot 0 */#endif#ifndef MAX_EISA_SLOTS#define MAX_EISA_SLOTS 16#define EISA_SLOT_INC 0x1000#endif#define CRC_POLYNOMIAL_BE 0x04c11db7UL	/* Ethernet CRC, big endian */#define CRC_POLYNOMIAL_LE 0xedb88320UL	/* Ethernet CRC, little endian */#define QUEUE_PKT_TIMEOUT (1*HZ)	/* Jiffies *//*   ** EtherWORKS 3 shared memory window sizes */#define IO_ONLY         0x00#define SHMEM_2K        0x800#define SHMEM_32K       0x8000#define SHMEM_64K       0x10000/*   ** EtherWORKS 3 IRQ ENABLE/DISABLE */#define ENABLE_IRQs { \  icr |= lp->irq_mask;\  outb(icr, EWRK3_ICR);                     /* Enable the IRQs */\}#define DISABLE_IRQs { \  icr = inb(EWRK3_ICR);\  icr &= ~lp->irq_mask;\  outb(icr, EWRK3_ICR);                     /* Disable the IRQs */\}/*   ** EtherWORKS 3 START/STOP */#define START_EWRK3 { \  csr = inb(EWRK3_CSR);\  csr &= ~(CSR_TXD|CSR_RXD);\  outb(csr, EWRK3_CSR);                     /* Enable the TX and/or RX */\}#define STOP_EWRK3 { \  csr = (CSR_TXD|CSR_RXD);\  outb(csr, EWRK3_CSR);                     /* Disable the TX and/or RX */\}/*   ** The EtherWORKS 3 private structure */#define EWRK3_PKT_STAT_SZ 16#define EWRK3_PKT_BIN_SZ  128	/* Should be >=100 unless you				   increase EWRK3_PKT_STAT_SZ */struct ewrk3_private {	char adapter_name[80];	/* Name exported to /proc/ioports */	u_long shmem_base;	/* Shared memory start address */	u_long shmem_length;	/* Shared memory window length */	struct net_device_stats stats;	/* Public stats */	struct {		u32 bins[EWRK3_PKT_STAT_SZ];	/* Private stats counters */		u32 unicast;		u32 multicast;		u32 broadcast;		u32 excessive_collisions;		u32 tx_underruns;		u32 excessive_underruns;	} pktStats;	u_char irq_mask;	/* Adapter IRQ mask bits */	u_char mPage;		/* Maximum 2kB Page number */	u_char lemac;		/* Chip rev. level */	u_char hard_strapped;	/* Don't allow a full open */	u_char lock;		/* Lock the page register */	u_char txc;		/* Transmit cut through */	u_char *mctbl;		/* Pointer to the multicast table */};/*   ** Force the EtherWORKS 3 card to be in 2kB MODE */#define FORCE_2K_MODE { \  shmem_length = SHMEM_2K;\  outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\}/*   ** Public Functions */static int ewrk3_open(struct device *dev);static int ewrk3_queue_pkt(struct sk_buff *skb, struct device *dev);static void ewrk3_interrupt(int irq, void *dev_id, struct pt_regs *regs);static int ewrk3_close(struct device *dev);static struct net_device_stats *ewrk3_get_stats(struct device *dev);static void set_multicast_list(struct device *dev);static int ewrk3_ioctl(struct device *dev, struct ifreq *rq, int cmd);/*   ** Private functions */static int ewrk3_hw_init(struct device *dev, u_long iobase);static void ewrk3_init(struct device *dev);static int ewrk3_rx(struct device *dev);static int ewrk3_tx(struct device *dev);static void EthwrkSignature(char *name, char *eeprom_image);static int DevicePresent(u_long iobase);static void SetMulticastFilter(struct device *dev);static int EISA_signature(char *name, s32 eisa_id);static int Read_EEPROM(u_long iobase, u_char eaddr);static int Write_EEPROM(short data, u_long iobase, u_char eaddr);static u_char get_hw_addr(struct device *dev, u_char * eeprom_image, char chipType);static void isa_probe(struct device *dev, u_long iobase);static void eisa_probe(struct device *dev, u_long iobase);static struct device *alloc_device(struct device *dev, u_long iobase);static int ewrk3_dev_index(char *s);static struct device *insert_device(struct device *dev, u_long iobase, int (*init) (struct device *));#ifdef MODULEint init_module(void);void cleanup_module(void);static int autoprobed = 1, loading_module = 1;#elsestatic u_char irq[] ={5, 0, 10, 3, 11, 9, 15, 12};static int autoprobed = 0, loading_module = 0;#endif				/* MODULE */static char name[EWRK3_STRLEN + 1];static int num_ewrk3s = 0, num_eth = 0;/*   ** Miscellaneous defines... */#define INIT_EWRK3 {\    outb(EEPROM_INIT, EWRK3_IOPR);\    mdelay(1);\}__initfunc(int ewrk3_probe(struct device *dev)){	int tmp = num_ewrk3s, status = -ENODEV;	u_long iobase = dev->base_addr;	if ((iobase == 0) && loading_module) {		printk("Autoprobing is not supported when loading a module based driver.\n");		status = -EIO;	} else {		/* First probe for the Ethernet */		/* Address PROM pattern */		isa_probe(dev, iobase);		eisa_probe(dev, iobase);		if ((tmp == num_ewrk3s) && (iobase != 0) && loading_module) {			printk("%s: ewrk3_probe() cannot find device at 0x%04lx.\n", dev->name,			       iobase);		}		/*		   ** Walk the device list to check that at least one device		   ** initialised OK		 */		for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);		if (dev->priv)			status = 0;		if (iobase == 0)			autoprobed = 1;	}	return status;}__initfunc(static int	   ewrk3_hw_init(struct device *dev, u_long iobase)){	struct ewrk3_private *lp;	int i, status = 0;	u_long mem_start, shmem_length;	u_char cr, cmr, icr, nicsr, lemac, hard_strapped = 0;	u_char eeprom_image[EEPROM_MAX], chksum, eisa_cr = 0;	/*	   ** Stop the EWRK3. Enable the DBR ROM. Disable interrupts and remote boot.	   ** This also disables the EISA_ENABLE bit in the EISA Control Register.	 */	if (iobase > 0x400)		eisa_cr = inb(EISA_CR);	INIT_EWRK3;	nicsr = inb(EWRK3_CSR);	icr = inb(EWRK3_ICR);	icr &= 0x70;	outb(icr, EWRK3_ICR);	/* Disable all the IRQs */	if (nicsr == (CSR_TXD | CSR_RXD)) {		/* Check that the EEPROM is alive and well and not living on Pluto... */		for (chksum = 0, i = 0; i < EEPROM_MAX; i += 2) {			union {				short val;				char c[2];			} tmp;			tmp.val = (short) Read_EEPROM(iobase, (i >> 1));			eeprom_image[i] = tmp.c[0];			eeprom_image[i + 1] = tmp.c[1];			chksum += eeprom_image[i] + eeprom_image[i + 1];		}		if (chksum != 0) {	/* Bad EEPROM Data! */			printk("%s: Device has a bad on-board EEPROM.\n", dev->name);			status = -ENXIO;		} else {			EthwrkSignature(name, eeprom_image);			if (*name != '\0') {	/* found a EWRK3 device */				dev->base_addr = iobase;				if (iobase > 0x400) {					outb(eisa_cr, EISA_CR);		/* Rewrite the EISA CR */				}				lemac = eeprom_image[EEPROM_CHIPVER];				cmr = inb(EWRK3_CMR);				if (((lemac == LeMAC) && ((cmr & CMR_NO_EEPROM) != CMR_NO_EEPROM)) ||				((lemac == LeMAC2) && !(cmr & CMR_HS))) {					printk("%s: %s at %#4lx", dev->name, name, iobase);					hard_strapped = 1;				} else if ((iobase & 0x0fff) == EWRK3_EISA_IO_PORTS) {					/* EISA slot address */					printk("%s: %s at %#4lx (EISA slot %ld)",					       dev->name, name, iobase, ((iobase >> 12) & 0x0f));				} else {	/* ISA port address */					printk("%s: %s at %#4lx", dev->name, name, iobase);				}				if (!status) {					printk(", h/w address ");					if (lemac != LeMAC2)						DevicePresent(iobase);	/* need after EWRK3_INIT */					status = get_hw_addr(dev, eeprom_image, lemac);					for (i = 0; i < ETH_ALEN - 1; i++) {	/* get the ethernet addr. */						printk("%2.2x:", dev->dev_addr[i]);					}					printk("%2.2x,\n", dev->dev_addr[i]);					if (status) {						printk("      which has an EEPROM CRC error.\n");						status = -ENXIO;					} else {						if (lemac == LeMAC2) {	/* Special LeMAC2 CMR things */							cmr &= ~(CMR_RA | CMR_WB | CMR_LINK | CMR_POLARITY | CMR_0WS);							if (eeprom_image[EEPROM_MISC0] & READ_AHEAD)								cmr |= CMR_RA;							if (eeprom_image[EEPROM_MISC0] & WRITE_BEHIND)								cmr |= CMR_WB;							if (eeprom_image[EEPROM_NETMAN0] & NETMAN_POL)								cmr |= CMR_POLARITY;							if (eeprom_image[EEPROM_NETMAN0] & NETMAN_LINK)								cmr |= CMR_LINK;							if (eeprom_image[EEPROM_MISC0] & _0WS_ENA)								cmr |= CMR_0WS;						}						if (eeprom_image[EEPROM_SETUP] & SETUP_DRAM)							cmr |= CMR_DRAM;						outb(cmr, EWRK3_CMR);						cr = inb(EWRK3_CR);	/* Set up the Control Register */						cr |= eeprom_image[EEPROM_SETUP] & SETUP_APD;						if (cr & SETUP_APD)							cr |= eeprom_image[EEPROM_SETUP] & SETUP_PS;						cr |= eeprom_image[EEPROM_MISC0] & FAST_BUS;						cr |= eeprom_image[EEPROM_MISC0] & ENA_16;						outb(cr, EWRK3_CR);

⌨️ 快捷键说明

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