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

📄 seeq8005.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 2 页
字号:
/* seeq8005.c: A network driver for linux. *//*	Based on skeleton.c,	Written 1993-94 by Donald Becker.	See the skeleton.c file for further copyright information.	This software may be used and distributed according to the terms	of the GNU Public License, incorporated herein by reference.	The author may be reached as hamish@zot.apana.org.au	This file is a network device driver for the SEEQ 8005 chipset and	the Linux operating system.*/static const char *version =	"seeq8005.c:v1.00 8/07/95 Hamish Coleman (hamish@zot.apana.org.au)\n";/*  Sources:  	SEEQ 8005 databook  	  Version history:  	1.00	Public release. cosmetic changes (no warnings now)  	0.68	Turning per- packet,interrupt debug messages off - testing for release.  	0.67	timing problems/bad buffer reads seem to be fixed now  	0.63	*!@$ protocol=eth_type_trans -- now packets flow  	0.56	Send working  	0.48	Receive working*/#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 <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/errno.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include "seeq8005.h"/* First, a few definitions that the brave might change. *//* A zero-terminated list of I/O addresses to be probed. */static unsigned int seeq8005_portlist[] =   { 0x300, 0x320, 0x340, 0x360, 0};/* use 0 for production, 1 for verification, >2 for debug */#ifndef NET_DEBUG#define NET_DEBUG 1#endifstatic unsigned int net_debug = NET_DEBUG;/* Information that need to be kept for each board. */struct net_local {	struct enet_statistics stats;	unsigned short receive_ptr;		/* What address in packet memory do we expect a recv_pkt_header? */	long open_time;				/* Useless example local info. */};/* The station (ethernet) address prefix, used for IDing the board. */#define SA_ADDR0 0x00#define SA_ADDR1 0x80#define SA_ADDR2 0x4b/* Index to functions, as function prototypes. */extern int seeq8005_probe(struct device *dev);static int seeq8005_probe1(struct device *dev, int ioaddr);static int seeq8005_open(struct device *dev);static int seeq8005_send_packet(struct sk_buff *skb, struct device *dev);static void seeq8005_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void seeq8005_rx(struct device *dev);static int seeq8005_close(struct device *dev);static struct enet_statistics *seeq8005_get_stats(struct device *dev);static void set_multicast_list(struct device *dev);/* Example routines you must write ;->. */#define tx_done(dev)	(inw(SEEQ_STATUS) & SEEQSTAT_TX_ON)extern void hardware_send_packet(struct device *dev, char *buf, int length);extern void seeq8005_init(struct device *dev, int startp);inline void wait_for_buffer(struct device *dev);/* Check for a network adaptor of this type, and return '0' iff 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).   */#ifdef HAVE_DEVLIST/* Support for a alternate probe manager, which will eliminate the   boilerplate below. */struct netdev_entry seeq8005_drv ={"seeq8005", seeq8005_probe1, SEEQ8005_IO_EXTENT, seeq8005_portlist};#elseintseeq8005_probe(struct device *dev){	int i;	int base_addr = dev ? dev->base_addr : 0;	if (base_addr > 0x1ff)		/* Check a single specified location. */		return seeq8005_probe1(dev, base_addr);	else if (base_addr != 0)	/* Don't probe at all. */		return ENXIO;	for (i = 0; seeq8005_portlist[i]; i++) {		int ioaddr = seeq8005_portlist[i];		if (check_region(ioaddr, SEEQ8005_IO_EXTENT))			continue;		if (seeq8005_probe1(dev, ioaddr) == 0)			return 0;	}	return ENODEV;}#endif/* This is the real probe routine.  Linux has a history of friendly device   probes on the ISA bus.  A good device probes avoids doing writes, and   verifies that the correct device exists and functions.  */static int seeq8005_probe1(struct device *dev, int ioaddr){	static unsigned version_printed = 0;	int i,j;	unsigned char SA_prom[32];	int old_cfg1;	int old_cfg2;	int old_stat;	int old_dmaar;	int old_rear;	if (net_debug>1)		printk("seeq8005: probing at 0x%x\n",ioaddr);	old_stat = inw(SEEQ_STATUS);					/* read status register */	if (old_stat == 0xffff)		return ENODEV;						/* assume that 0xffff == no device */	if ( (old_stat & 0x1800) != 0x1800 ) {				/* assume that unused bits are 1, as my manual says */		if (net_debug>1) {			printk("seeq8005: reserved stat bits != 0x1800\n");			printk("          == 0x%04x\n",old_stat);		}	 	return ENODEV;	}	old_rear = inw(SEEQ_REA);	if (old_rear == 0xffff) {		outw(0,SEEQ_REA);		if (inw(SEEQ_REA) == 0xffff) {				/* assume that 0xffff == no device */			return ENODEV;		}	} else if ((old_rear & 0xff00) != 0xff00) {			/* assume that unused bits are 1 */		if (net_debug>1) {			printk("seeq8005: unused rear bits != 0xff00\n");			printk("          == 0x%04x\n",old_rear);		}		return ENODEV;	}		old_cfg2 = inw(SEEQ_CFG2);					/* read CFG2 register */	old_cfg1 = inw(SEEQ_CFG1);	old_dmaar = inw(SEEQ_DMAAR);		if (net_debug>4) {		printk("seeq8005: stat = 0x%04x\n",old_stat);		printk("seeq8005: cfg1 = 0x%04x\n",old_cfg1);		printk("seeq8005: cfg2 = 0x%04x\n",old_cfg2);		printk("seeq8005: raer = 0x%04x\n",old_rear);		printk("seeq8005: dmaar= 0x%04x\n",old_dmaar);	}		outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);	/* setup for reading PROM */	outw( 0, SEEQ_DMAAR);						/* set starting PROM address */	outw( SEEQCFG1_BUFFER_PROM, SEEQ_CFG1);				/* set buffer to look at PROM */			j=0;	for(i=0; i <32; i++) {		j+= SA_prom[i] = inw(SEEQ_BUFFER) & 0xff;	}#if 0	/* untested because I only have the one card */	if ( (j&0xff) != 0 ) {						/* checksum appears to be 8bit = 0 */		if (net_debug>1) {					/* check this before deciding that we have a card */			printk("seeq8005: prom sum error\n");		}		outw( old_stat, SEEQ_STATUS);		outw( old_dmaar, SEEQ_DMAAR);		outw( old_cfg1, SEEQ_CFG1);		return ENODEV;	}#endif	outw( SEEQCFG2_RESET, SEEQ_CFG2);				/* reset the card */	SLOW_DOWN_IO;							/* have to wait 4us after a reset - should be fixed */	SLOW_DOWN_IO;	SLOW_DOWN_IO;	SLOW_DOWN_IO;	outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);		if (net_debug) {		printk("seeq8005: prom sum = 0x%08x\n",j);		for(j=0; j<32; j+=16) {			printk("seeq8005: prom %02x: ",j);			for(i=0;i<16;i++) {				printk("%02x ",SA_prom[j|i]);			}			printk(" ");			for(i=0;i<16;i++) {				if ((SA_prom[j|i]>31)&&(SA_prom[j|i]<127)) {					printk("%c", SA_prom[j|i]);				} else {					printk(" ");				}			}			printk("\n");		}	}#if 0		/* 	 * testing the packet buffer memory doesn't work yet	 * but all other buffer accesses do 	 *			- fixing is not a priority	 */	if (net_debug>1) {					/* test packet buffer memory */		printk("seeq8005: testing packet buffer ... ");		outw( SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);		outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);		outw( 0 , SEEQ_DMAAR);		for(i=0;i<32768;i++) {			outw(0x5a5a, SEEQ_BUFFER);		}		j=jiffies+HZ;		while ( ((inw(SEEQ_STATUS) & SEEQSTAT_FIFO_EMPTY) != SEEQSTAT_FIFO_EMPTY) && jiffies < j )			mb();		outw( 0 , SEEQ_DMAAR);		while ( ((inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && jiffies < j+HZ)			mb();		if ( (inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)			outw( SEEQCMD_WINDOW_INT_ACK | (inw(SEEQ_STATUS)& SEEQCMD_INT_MASK), SEEQ_CMD);		outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);		j=0;		for(i=0;i<32768;i++) {			if (inw(SEEQ_BUFFER) != 0x5a5a)				j++;		}		if (j) {			printk("%i\n",j);		} else {			printk("ok.\n");		}	}#endif	/* Allocate a new 'dev' if needed. */	if (dev == NULL)		dev = init_etherdev(0, sizeof(struct net_local));	if (net_debug  &&  version_printed++ == 0)		printk(version);	printk("%s: %s found at %#3x, ", dev->name, "seeq8005", ioaddr);	/* Fill in the 'dev' fields. */	dev->base_addr = ioaddr;	/* Retrieve and print the ethernet address. */	for (i = 0; i < 6; i++)		printk(" %2.2x", dev->dev_addr[i] = SA_prom[i+6]);	if (dev->irq == 0xff)		;			/* Do nothing: a user-level program will set it. */	else if (dev->irq < 2) {	/* "Auto-IRQ" */		autoirq_setup(0);				outw( SEEQCMD_RX_INT_EN | SEEQCMD_SET_RX_ON | SEEQCMD_SET_RX_OFF, SEEQ_CMD );		dev->irq = autoirq_report(0);				if (net_debug >= 2)			printk(" autoirq is %d\n", dev->irq);	} else if (dev->irq == 2)	  /* Fixup for users that don't know that IRQ 2 is really IRQ 9,	   * or don't know which one to set. 	   */	  dev->irq = 9;#if 0	{		 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", NULL);		 if (irqval) {			 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,					 dev->irq, irqval);			 return EAGAIN;		 }	}#endif	/* Grab the region so we can find another board if autoIRQ fails. */	request_region(ioaddr, SEEQ8005_IO_EXTENT,"seeq8005");	/* Initialize the device structure. */	dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);	if (dev->priv == NULL)		return -ENOMEM;	memset(dev->priv, 0, sizeof(struct net_local));	dev->open		= seeq8005_open;	dev->stop		= seeq8005_close;	dev->hard_start_xmit = seeq8005_send_packet;	dev->get_stats	= seeq8005_get_stats;	dev->set_multicast_list = &set_multicast_list;	/* Fill in the fields of the device structure with ethernet values. */	ether_setup(dev);		dev->flags &= ~IFF_MULTICAST;	return 0;}/* Open/initialize the board.  This is called (in the current kernel)   sometime after booting when the 'ifconfig' program is run.   This routine should set everything up anew at each open, even   registers that "should" only need to be set once at boot, so that   there is non-reboot way to recover if something goes wrong.   */static intseeq8005_open(struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	{		 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", NULL);		 if (irqval) {			 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,					 dev->irq, irqval);			 return EAGAIN;		 }	}	irq2dev_map[dev->irq] = dev;	/* Reset the hardware here.  Don't forget to set the station address. */	seeq8005_init(dev, 1);	lp->open_time = jiffies;	dev->tbusy = 0;	dev->interrupt = 0;	dev->start = 1;	return 0;}static intseeq8005_send_packet(struct sk_buff *skb, struct device *dev){	int ioaddr = dev->base_addr;	if (dev->tbusy) {		/* If we get here, some higher level has decided we are broken.		   There should really be a "kick me" function call instead. */		int tickssofar = jiffies - dev->trans_start;

⌨️ 快捷键说明

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