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

📄 com90xx.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      $Id: com90xx.c,v 1.9 1998/03/21 18:02:51 alan Exp $   Derived from the original arcnet.c,   Written 1994-1996 by Avery Pennarun,   which was in turn derived from skeleton.c by Donald Becker.   **********************   The original copyright of skeleton.c was as follows:   skeleton.c Written 1993 by Donald Becker.   Copyright 1993 United States Government as represented by the   Director, National Security Agency.  This software may only be used   and distributed according to the terms of the GNU Public License as   modified by SRC, incorporated herein by reference.   **********************   For more details, see drivers/net/arcnet.c   ********************** */#include <linux/module.h>#include <linux/version.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/interrupt.h>#include <linux/ptrace.h>#include <linux/ioport.h>#include <linux/in.h>#include <linux/malloc.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/if_arp.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include <linux/if_arcnet.h>#include <linux/arcdevice.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <net/arp.h>/**************************************************************************//* On a fast computer, the buffer copy from memory to the ARCnet card during * a transmit can hog the bus just a little too long.  SLOW_XMIT_COPY * replaces the fast memcpy() with a slower for() loop that seems to solve * my problems with ftape. * * Probably a better solution would be to use memcpy_toio (more portable * anyway) and modify that routine to support REALLY_SLOW_IO-style * defines; ARCnet probably is not the only driver that can screw up an * ftape DMA transfer. * * Turn this on if you have timing-sensitive DMA (ie. a tape drive) and * would like to sacrifice a little bit of network speed to reduce tape * write retries or some related problem. */#undef SLOW_XMIT_COPY/* Define this to speed up the autoprobe by assuming if only one io port and * shmem are left in the list at Stage 5, they must correspond to each * other. * * This is undefined by default because it might not always be true, and the * extra check makes the autoprobe even more careful.  Speed demons can turn * it on - I think it should be fine if you only have one ARCnet card * installed. * * If no ARCnet cards are installed, this delay never happens anyway and thus * the option has no effect. */#undef FAST_PROBE/* Internal function declarations */#ifdef MODULEstatic#endifint arc90xx_probe(struct device *dev);static void arc90xx_rx(struct device *dev, int recbuf);static int arc90xx_found(struct device *dev, int ioaddr, int airq, u_long shmem, int more);static void arc90xx_inthandler(struct device *dev);static int arc90xx_reset(struct device *dev, int reset_delay);static void arc90xx_setmask(struct device *dev, u_char mask);static void arc90xx_command(struct device *dev, u_char command);static u_char arc90xx_status(struct device *dev);static void arc90xx_prepare_tx(struct device *dev, u_char * hdr, int hdrlen,	     char *data, int length, int daddr, int exceptA, int offset);static void arc90xx_openclose(int open);/* Module parameters */#ifdef MODULEstatic int io = 0x0;		/* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */static int irq = 0;		/* or use the insmod io= irq= shmem= options */static int shmem = 0;static char *device;		/* use eg. device="arc1" to change name */MODULE_PARM(io, "i");MODULE_PARM(irq, "i");MODULE_PARM(shmem, "i");MODULE_PARM(device, "s");#else__initfunc(void com90xx_setup(char *str, int *ints));char __initdata com90xx_explicit = 0;extern struct device arcnet_devs[];extern char arcnet_dev_names[][10];extern int arcnet_num_devs;#endif/* Handy defines for ARCnet specific stuff *//* The number of low I/O ports used by the card. */#define ARCNET_TOTAL_SIZE	16/* COM 9026 controller chip --> ARCnet register addresses */#define _INTMASK (ioaddr+0)	/* writable */#define _STATUS  (ioaddr+0)	/* readable */#define _COMMAND (ioaddr+1)	/* writable, returns random vals on read (?) */#define _RESET  (ioaddr+8)	/* software reset (on read) */#define _MEMDATA  (ioaddr+12)	/* Data port for IO-mapped memory */#define _ADDR_HI  (ioaddr+15)	/* Control registers for said */#define _ADDR_LO  (ioaddr+14)#define _CONFIG  (ioaddr+2)	/* Configuration register */#define RDDATAflag      0x00	/* Next access is a read/~write */#define ARCSTATUS	inb(_STATUS)#define ACOMMAND(cmd) 	outb((cmd),_COMMAND)#define AINTMASK(msk)	outb((msk),_INTMASK)#define SETCONF		outb(lp->config,_CONFIG)#define ARCRESET	inb(_RESET)static const char *version ="com90xx.c: v3.00 97/11/09 Avery Pennarun <apenwarr@worldvisions.ca> et al.\n";/**************************************************************************** *                                                                          * * Probe and initialization                                                 * *                                                                          * ****************************************************************************//* Check for an ARCnet network adaptor, and return '0' if one exists. *  If dev->base_addr == 0, probe all likely locations. *  If dev->base_addr == 1, always return failure. *  If dev->base_addr == 2, allocate space for the device and return success *                          (detachable devices only). * * NOTE: the list of possible ports/shmems is static, so it is retained * across calls to arcnet_probe.  So, if more than one ARCnet probe is made, * values that were discarded once will not even be tried again. * * FIXME: grab all devices in one shot and eliminate the big static array. */static int ports[(0x3f0 - 0x200) / 16 + 1] __initdata = {	0};static u_long shmems[(0xFF800 - 0xA0000) / 2048 + 1] __initdata = {	0};__initfunc(int arc90xx_probe(struct device *dev)){	static int init_once = 0;	static int numports = sizeof(ports) / sizeof(ports[0]), numshmems = sizeof(shmems) / sizeof(shmems[0]);	int count, status, delayval, ioaddr, numprint, airq, retval = -ENODEV,	 openparen = 0;	unsigned long airqmask;	int *port;	u_long *shmem;	if (!init_once) {		for (count = 0x200; count <= 0x3f0; count += 16)			ports[(count - 0x200) / 16] = count;		for (count = 0xA0000; count <= 0xFF800; count += 2048)			shmems[(count - 0xA0000) / 2048] = count;		BUGLVL(D_NORMAL) printk(version);		BUGMSG(D_DURING, "space used for probe buffers: %d+%d=%d bytes\n",		       sizeof(ports), sizeof(shmems),		       sizeof(ports) + sizeof(shmems));	}	init_once++;	BUGMSG(D_INIT, "given: base %lXh, IRQ %d, shmem %lXh\n",	       dev->base_addr, dev->irq, dev->mem_start);	if (dev->base_addr > 0x1ff) {	/* Check a single specified port */		ports[0] = dev->base_addr;		numports = 1;	} else if (dev->base_addr > 0)	/* Don't probe at all. */		return -ENXIO;	if (dev->mem_start) {		shmems[0] = dev->mem_start;		numshmems = 1;	}	/* Stage 1: abandon any reserved ports, or ones with status==0xFF	 * (empty), and reset any others by reading the reset port.	 */	BUGMSG(D_INIT, "Stage 1: ");	numprint = 0;	for (port = &ports[0]; port - ports < numports; port++) {		numprint++;		if (numprint > 8) {			BUGMSG2(D_INIT, "\n");			BUGMSG(D_INIT, "Stage 1: ");			numprint = 1;		}		BUGMSG2(D_INIT, "%Xh ", *port);		ioaddr = *port;		if (check_region(*port, ARCNET_TOTAL_SIZE)) {			BUGMSG2(D_INIT_REASONS, "(check_region)\n");			BUGMSG(D_INIT_REASONS, "Stage 1: ");			BUGLVL(D_INIT_REASONS) numprint = 0;			*port = ports[numports - 1];			numports--;			port--;			continue;		}		if (ARCSTATUS == 0xFF) {			BUGMSG2(D_INIT_REASONS, "(empty)\n");			BUGMSG(D_INIT_REASONS, "Stage 1: ");			BUGLVL(D_INIT_REASONS) numprint = 0;			*port = ports[numports - 1];			numports--;			port--;			continue;		}		ARCRESET;	/* begin resetting card */		BUGMSG2(D_INIT_REASONS, "\n");		BUGMSG(D_INIT_REASONS, "Stage 1: ");		BUGLVL(D_INIT_REASONS) numprint = 0;	}	BUGMSG2(D_INIT, "\n");	if (!numports) {		BUGMSG(D_NORMAL, "Stage 1: No ARCnet cards found.\n");		return -ENODEV;	}	/* Stage 2: we have now reset any possible ARCnet cards, so we can't	 * do anything until they finish.  If D_INIT, print the list of	 * cards that are left.	 */	BUGMSG(D_INIT, "Stage 2: ");	numprint = 0;	for (port = &ports[0]; port - ports < numports; port++) {		numprint++;		if (numprint > 8) {			BUGMSG2(D_INIT, "\n");			BUGMSG(D_INIT, "Stage 2: ");			numprint = 1;		}		BUGMSG2(D_INIT, "%Xh ", *port);	}	BUGMSG2(D_INIT, "\n");	JIFFER(RESETtime);	/* Stage 3: abandon any shmem addresses that don't have the signature	 * 0xD1 byte in the right place, or are read-only.	 */	BUGMSG(D_INIT, "Stage 3: ");	numprint = 0;	for (shmem = &shmems[0]; shmem - shmems < numshmems; shmem++) {		u_long ptr;		numprint++;		if (numprint > 8) {			BUGMSG2(D_INIT, "\n");			BUGMSG(D_INIT, "Stage 3: ");			numprint = 1;		}		BUGMSG2(D_INIT, "%lXh ", *shmem);		ptr = (u_long) (*shmem);		if (readb(ptr) != TESTvalue) {			BUGMSG2(D_INIT_REASONS, "(mem=%02Xh, not %02Xh)\n",				readb(ptr), TESTvalue);			BUGMSG(D_INIT_REASONS, "Stage 3: ");			BUGLVL(D_INIT_REASONS) numprint = 0;			*shmem = shmems[numshmems - 1];			numshmems--;			shmem--;			continue;		}		/* By writing 0x42 to the TESTvalue location, we also make		 * sure no "mirror" shmem areas show up - if they occur		 * in another pass through this loop, they will be discarded		 * because *cptr != TESTvalue.		 */		writeb(0x42, ptr);		if (readb(ptr) != 0x42) {			BUGMSG2(D_INIT_REASONS, "(read only)\n");			BUGMSG(D_INIT_REASONS, "Stage 3: ");			*shmem = shmems[numshmems - 1];			numshmems--;			shmem--;			continue;		}		BUGMSG2(D_INIT_REASONS, "\n");		BUGMSG(D_INIT_REASONS, "Stage 3: ");		BUGLVL(D_INIT_REASONS) numprint = 0;	}	BUGMSG2(D_INIT, "\n");	if (!numshmems) {		BUGMSG(D_NORMAL, "Stage 3: No ARCnet cards found.\n");		return -ENODEV;	}	/* Stage 4: something of a dummy, to report the shmems that are	 * still possible after stage 3.	 */	BUGMSG(D_INIT, "Stage 4: ");	numprint = 0;	for (shmem = &shmems[0]; shmem - shmems < numshmems; shmem++) {		numprint++;		if (numprint > 8) {			BUGMSG2(D_INIT, "\n");			BUGMSG(D_INIT, "Stage 4: ");			numprint = 1;		}		BUGMSG2(D_INIT, "%lXh ", *shmem);	}	BUGMSG2(D_INIT, "\n");	/* Stage 5: for any ports that have the correct status, can disable	 * the RESET flag, and (if no irq is given) generate an autoirq,	 * register an ARCnet device.	 *	 * Currently, we can only register one device per probe, so quit	 * after the first one is found.	 */	BUGMSG(D_INIT, "Stage 5: ");	numprint = 0;	for (port = &ports[0]; port - ports < numports; port++) {		numprint++;		if (numprint > 8) {			BUGMSG2(D_INIT, "\n");			BUGMSG(D_INIT, "Stage 5: ");			numprint = 1;		}		BUGMSG2(D_INIT, "%Xh ", *port);		ioaddr = *port;		status = ARCSTATUS;		if ((status & 0x9D)		    != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {			BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status);			BUGMSG(D_INIT_REASONS, "Stage 5: ");			BUGLVL(D_INIT_REASONS) numprint = 0;			*port = ports[numports - 1];			numports--;			port--;			continue;		}		ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);		status = ARCSTATUS;		if (status & RESETflag) {			BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",				status);			BUGMSG(D_INIT_REASONS, "Stage 5: ");			BUGLVL(D_INIT_REASONS) numprint = 0;			*port = ports[numports - 1];			numports--;			port--;

⌨️ 快捷键说明

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