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

📄 3c523.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)   This is an extension to the Linux operating system, and is covered by the   same Gnu Public License that covers that work.   Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)   This is basically Michael Hipp's ni52 driver, with a new probing   algorithm and some minor changes to the 82586 CA and reset routines.   Thanks a lot Michael for a really clean i82586 implementation!  Unless   otherwise documented in ni52.c, any bugs are mine.   Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in   any way.  The ni52 is a lot easier to modify.   sources:   ni52.c   Crynwr packet driver collection was a great reference for my first   attempt at this sucker.  The 3c507 driver also helped, until I noticed   that ni52.c was a lot nicer.   EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference   Manual, courtesy of 3Com CardFacts, documents the 3c523-specific   stuff.  Information on CardFacts is found in the Ethernet HOWTO.   Also see <a href="http://www.3com.com/">   Microprocessor Communications Support Chips, T.J. Byers, ISBN   0-444-01224-9, has a section on the i82586.  It tells you just enough   to know that you really don't want to learn how to program the chip.   The original device probe code was stolen from ps2esdi.c   Known Problems:   Since most of the code was stolen from ni52.c, you'll run across the   same bugs in the 0.62 version of ni52.c, plus maybe a few because of   the 3c523 idiosynchacies.  The 3c523 has 16K of RAM though, so there   shouldn't be the overrun problem that the 8K ni52 has.   This driver is for a 16K adapter.  It should work fine on the 64K   adapters, but it will only use one of the 4 banks of RAM.  Modifying   this for the 64K version would require a lot of heinous bank   switching, which I'm sure not interested in doing.  If you try to   implement a bank switching version, you'll basically have to remember   what bank is enabled and do a switch everytime you access a memory   location that's not current.  You'll also have to remap pointers on   the driver side, because it only knows about 16K of the memory.   Anyone desperate or masochistic enough to try?   It seems to be stable now when multiple transmit buffers are used.  I   can't see any performance difference, but then I'm working on a 386SX.   Multicast doesn't work.  It doesn't even pretend to work.  Don't use   it.  Don't compile your kernel with multicast support.  I don't know   why.   Features:   This driver is useable as a loadable module.  If you try to specify an   IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will   search the MCA slots until it finds a 3c523 with the specified   parameters.   This driver should support multiple ethernet cards, but I can't test   that.  If someone would I'd greatly appreciate it.   This has been tested with both BNC and TP versions, internal and   external transceivers.  Haven't tested with the 64K version (that I   know of).   History:   Jan 1st, 1996   first public release   Feb 4th, 1996   update to 1.3.59, incorporated multicast diffs from ni52.c   Feb 15th, 1996   added shared irq support   $Header: /fsys2/home/chrisb/linux-1.3.59-MCA/drivers/net/RCS/3c523.c,v 1.1 1996/02/05 01:53:46 chrisb Exp chrisb $ */#ifdef MODULE#include <linux/module.h>#endif#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/mca.h>#include <asm/processor.h>#include <asm/bitops.h>#include <asm/io.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/init.h>#include "3c523.h"/*************************************************************************/#define DEBUG			/* debug on */#define SYSBUSVAL 0		/* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */#define make32(ptr16) (p->memtop + (short) (ptr16) )#define make24(ptr32) ((char *) (ptr32) - p->base)#define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))/*************************************************************************//*   Tables to which we can map values in the configuration registers. */static int irq_table[] __initdata = {	12, 7, 3, 9};static int csr_table[] __initdata = {	0x300, 0x1300, 0x2300, 0x3300};static int shm_table[] __initdata = {	0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000};/******************* how to calculate the buffers *****************************  * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works  * --------------- in a different (more stable?) mode. Only in this mode it's  *                 possible to configure the driver with 'NO_NOPCOMMANDS'sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INITsizeof(rfd) = 24; sizeof(rbd) = 12;sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;sizeof(nop_cmd) = 8;  * if you don't know the driver, better do not change this values: */#define RECV_BUFF_SIZE 1524	/* slightly oversized */#define XMIT_BUFF_SIZE 1524	/* slightly oversized */#define NUM_XMIT_BUFFS 4	/* config for both, 8K and 16K shmem */#define NUM_RECV_BUFFS_8  1	/* config for 8K shared mem */#define NUM_RECV_BUFFS_16 6	/* config for 16K shared mem */#if (NUM_XMIT_BUFFS == 1)#define NO_NOPCOMMANDS		/* only possible with NUM_XMIT_BUFFS=1 */#endif/**************************************************************************/#define DELAY(x) {int i=jiffies; \                  if(loops_per_sec == 1) \                     while(time_after(i+(x), jiffies)); \                  else \                     __delay((loops_per_sec>>5)*x); \                 }/* a much shorter delay: */#define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }/* wait for command with timeout: */#define WAIT_4_SCB_CMD() { int i; \  for(i=0;i<1024;i++) { \    if(!p->scb->cmd) break; \    DELAY_16(); \    if(i == 1023) { \      printk("%s:%d: scb_cmd timed out .. resetting i82586\n",\      	dev->name,__LINE__); \      elmc_id_reset586(); } } }static void elmc_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr);static int elmc_open(struct device *dev);static int elmc_close(struct device *dev);static int elmc_send_packet(struct sk_buff *, struct device *);static struct net_device_stats *elmc_get_stats(struct device *dev);static void set_multicast_list(struct device *dev);/* helper-functions */static int init586(struct device *dev);static int check586(struct device *dev, unsigned long where, unsigned size);static void alloc586(struct device *dev);static void startrecv586(struct device *dev);static void *alloc_rfa(struct device *dev, void *ptr);static void elmc_rcv_int(struct device *dev);static void elmc_xmt_int(struct device *dev);static void elmc_rnr_int(struct device *dev);struct priv {	struct net_device_stats stats;	unsigned long base;	char *memtop;	volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;	volatile struct scp_struct *scp;	/* volatile is important */	volatile struct iscp_struct *iscp;	/* volatile is important */	volatile struct scb_struct *scb;	/* volatile is important */	volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];	volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];#if (NUM_XMIT_BUFFS == 1)	volatile struct nop_cmd_struct *nop_cmds[2];#else	volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];#endif	volatile int nop_point, num_recv_buffs;	volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];	volatile int xmit_count, xmit_last;	volatile int slot;};#define elmc_attn586()  {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}#define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}/* with interrupts disabled - this will clear the interrupt bit in the   3c523 control register, and won't put it back.  This effectively   disables interrupts on the card. */#define elmc_id_attn586()  {elmc_do_attn586(dev->base_addr,0);}#define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}/*************************************************************************//*   Do a Channel Attention on the 3c523.  This is extremely board dependent. */static void elmc_do_attn586(int ioaddr, int ints){	/* the 3c523 requires a minimum of 500 ns.  The delays here might be	   a little too large, and hence they may cut the performance of the	   card slightly.  If someone who knows a little more about Linux	   timing would care to play with these, I'd appreciate it. */	/* this bit masking stuff is crap.  I'd rather have separate	   registers with strobe triggers for each of these functions.  <sigh>	   Ya take what ya got. */	outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);	DELAY_16();		/* > 500 ns */	outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);}/*************************************************************************//*   Reset the 82586 on the 3c523.  Also very board dependent. */static void elmc_do_reset586(int ioaddr, int ints){	/* toggle the RST bit low then high */	outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);	DELAY_16();		/* > 500 ns */	outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);	elmc_do_attn586(ioaddr, ints);}/********************************************** * close device */static int elmc_close(struct device *dev){	elmc_id_reset586();	/* the hard way to stop the receiver */	free_irq(dev->irq, dev);	dev->start = 0;	dev->tbusy = 0;#ifdef MODULE	MOD_DEC_USE_COUNT;#endif	return 0;}/********************************************** * open device */static int elmc_open(struct device *dev){	elmc_id_attn586();	/* disable interrupts */	if (request_irq(dev->irq, &elmc_interrupt, SA_SHIRQ | SA_SAMPLE_RANDOM,			"3c523", dev)	    ) {		printk("%s: couldn't get irq %d\n", dev->name, dev->irq);		elmc_id_reset586();		return -EAGAIN;	}	alloc586(dev);	init586(dev);	startrecv586(dev);	dev->interrupt = 0;	dev->tbusy = 0;	dev->start = 1;#ifdef MODULE	MOD_INC_USE_COUNT;#endif	return 0;		/* most done by init */}/********************************************** * Check to see if there's an 82586 out there. */__initfunc(static int check586(struct device *dev, unsigned long where, unsigned size)){	struct priv *p = (struct priv *) dev->priv;	char *iscp_addrs[2];	int i = 0;	p->base = where + size - 0x01000000;	p->memtop = phys_to_virt(where) + size;	p->scp = (struct scp_struct *)phys_to_virt(p->base + SCP_DEFAULT_ADDRESS);	memset((char *) p->scp, 0, sizeof(struct scp_struct));	p->scp->sysbus = SYSBUSVAL;	/* 1 = 8Bit-Bus, 0 = 16 Bit */	iscp_addrs[0] = phys_to_virt(where);	iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);	for (i = 0; i < 2; i++) {		p->iscp = (struct iscp_struct *) iscp_addrs[i];		memset((char *) p->iscp, 0, sizeof(struct iscp_struct));		p->scp->iscp = make24(p->iscp);		p->iscp->busy = 1;		elmc_id_reset586();		/* reset586 does an implicit CA */		/* apparently, you sometimes have to kick the 82586 twice... */		elmc_id_attn586();		if (p->iscp->busy) {	/* i82586 clears 'busy' after successful init */			return 0;		}	}	return 1;}/****************************************************************** * set iscp at the right place, called by elmc_probe and open586. */void alloc586(struct device *dev){	struct priv *p = (struct priv *) dev->priv;	elmc_id_reset586();	DELAY(2);	p->scp = (struct scp_struct *) phys_to_virt(p->base + SCP_DEFAULT_ADDRESS);	p->scb = (struct scb_struct *) phys_to_virt(dev->mem_start);	p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));	memset((char *) p->iscp, 0, sizeof(struct iscp_struct));	memset((char *) p->scp, 0, sizeof(struct scp_struct));	p->scp->iscp = make24(p->iscp);	p->scp->sysbus = SYSBUSVAL;	p->iscp->scb_offset = make16(p->scb);	p->iscp->busy = 1;	elmc_id_reset586();	elmc_id_attn586();	DELAY(2);	if (p->iscp->busy) {		printk("%s: Init-Problems (alloc).\n", dev->name);	}	memset((char *) p->scb, 0, sizeof(struct scb_struct));}/*****************************************************************/static int elmc_getinfo(char *buf, int slot, void *d){	int len = 0;	struct device *dev = (struct device *) d;	int i;	if (dev == NULL)		return len;	len += sprintf(buf + len, "Revision: 0x%x\n",		       inb(dev->base_addr + ELMC_REVISION) & 0xf);	len += sprintf(buf + len, "IRQ: %d\n", dev->irq);	len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,		       dev->base_addr + ELMC_IO_EXTENT);	len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,		       dev->mem_end - 1);	len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?		       "External" : "Internal");	len += sprintf(buf + len, "Device: %s\n", dev->name);	len += sprintf(buf + len, "Hardware Address:");	for (i = 0; i < 6; i++) {		len += sprintf(buf + len, " %02x", dev->dev_addr[i]);	}	buf[len++] = '\n';	buf[len] = 0;	return len;}				/* elmc_getinfo() *//*****************************************************************/__initfunc(int elmc_probe(struct device *dev)){	static int slot = 0;	int base_addr = dev ? dev->base_addr : 0;	int irq = dev ? dev->irq : 0;	u_char status = 0;	u_char revision = 0;	int i = 0;	unsigned int size = 0;	if (MCA_bus == 0) {		return ENODEV;

⌨️ 快捷键说明

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