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

📄 cs89x0.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for linux. *//*	Written 1996 by Russell Nelson, with reference to skeleton.c	written 1993-1994 by Donald Becker.	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 at nelson@crynwr.com, Crynwr	Software, 11 Grant St., Potsdam, NY 13676  Changelog:  Mike Cruse        : mcruse@cti-ltd.com                    : Changes for Linux 2.0 compatibility.                     : Added dev_id parameter in net_interrupt(),                    : request_irq() and free_irq(). Just NULL for now.  Mike Cruse        : Added MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT macros                    : in net_open() and net_close() so kerneld would know                    : that the module is in use and wouldn't eject the                     : driver prematurely.  Mike Cruse        : Rewrote init_module() and cleanup_module using 8390.c                    : as an example. Disabled autoprobing in init_module(),                    : not a good thing to do to other devices while Linux                    : is running from all accounts.                      Alan Cox          : Removed 1.2 support, added 2.1 extra counters.*/static char *version ="cs89x0.c:v1.02 11/26/96 Russell Nelson <nelson@crynwr.com>\n";/* ======================= configure the driver here ======================= *//* use 0 for production, 1 for verification, >2 for debug */#ifndef NET_DEBUG#define NET_DEBUG 2#endif/* ======================= end of configuration ======================= *//* Always include 'config.h' first in case the user wants to turn on   or override something. */#ifdef MODULE#include <linux/module.h>#include <linux/version.h>#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#endif#define PRINTK(x) printk x/*  Sources:	Crynwr packet driver epktisa.	Crystal Semiconductor data sheets.*/#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 <linux/errno.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include "cs89x0.h"/* First, a few definitions that the brave might change. *//* A zero-terminated list of I/O addresses to be probed. */static unsigned int netcard_portlist[] __initdata =   { 0x300, 0x320, 0x340, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};static unsigned int net_debug = NET_DEBUG;/* The number of low I/O ports used by the ethercard. */#define NETCARD_IO_EXTENT	16/* Information that need to be kept for each board. */struct net_local {	struct net_device_stats stats;	int chip_type;		/* one of: CS8900, CS8920, CS8920M */	char chip_revision;	/* revision letter of the chip ('A'...) */	int send_cmd;		/* the propercommand used to send a packet. */	int auto_neg_cnf;	int adapter_cnf;	int isa_config;	int irq_map;	int rx_mode;	int curr_rx_cfg;        int linectl;        int send_underrun;      /* keep track of how many underruns in a row we get */	struct sk_buff *skb;};/* Index to functions, as function prototypes. */extern int cs89x0_probe(struct device *dev);static int cs89x0_probe1(struct device *dev, int ioaddr);static int net_open(struct device *dev);static int	net_send_packet(struct sk_buff *skb, struct device *dev);static void net_interrupt(int irq, void *dev_id, struct pt_regs *regs);static void set_multicast_list(struct device *dev);static void net_rx(struct device *dev);static int net_close(struct device *dev);static struct net_device_stats *net_get_stats(struct device *dev);static void reset_chip(struct device *dev);static int get_eeprom_data(struct device *dev, int off, int len, int *buffer);static int get_eeprom_cksum(int off, int len, int *buffer);static int set_mac_address(struct device *dev, void *addr);/* Example routines you must write ;->. */#define tx_done(dev) 1/* 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 netcard_drv ={"netcard", cs89x0_probe1, NETCARD_IO_EXTENT, netcard_portlist};#else__initfunc(intcs89x0_probe(struct device *dev)){	int i;	int base_addr = dev ? dev->base_addr : 0;	if (base_addr > 0x1ff)		/* Check a single specified location. */		return cs89x0_probe1(dev, base_addr);	else if (base_addr != 0)	/* Don't probe at all. */		return ENXIO;	for (i = 0; netcard_portlist[i]; i++) {		int ioaddr = netcard_portlist[i];		if (check_region(ioaddr, NETCARD_IO_EXTENT))			continue;		if (cs89x0_probe1(dev, ioaddr) == 0)			return 0;	}	printk("cs89x0: no cs8900 or cs8920 detected.  Be sure to disable PnP with SETUP\n");	return ENODEV;}#endifstatic int inlinereadreg(struct device *dev, int portno){	outw(portno, dev->base_addr + ADD_PORT);	return inw(dev->base_addr + DATA_PORT);}static void inlinewritereg(struct device *dev, int portno, int value){	outw(portno, dev->base_addr + ADD_PORT);	outw(value, dev->base_addr + DATA_PORT);}static int inlinereadword(struct device *dev, int portno){	return inw(dev->base_addr + portno);}static void inlinewriteword(struct device *dev, int portno, int value){	outw(value, dev->base_addr + portno);}__initfunc(static intwait_eeprom_ready(struct device *dev)){	int timeout = jiffies;	/* check to see if the EEPROM is ready, a timeout is used -	   just in case EEPROM is ready when SI_BUSY in the	   PP_SelfST is clear */	while(readreg(dev, PP_SelfST) & SI_BUSY)		if (jiffies - timeout >= 40)			return -1;	return 0;}__initfunc(static intget_eeprom_data(struct device *dev, int off, int len, int *buffer)){	int i;	if (net_debug > 3) printk("EEPROM data from %x for %x:\n",off,len);	for (i = 0; i < len; i++) {		if (wait_eeprom_ready(dev) < 0) return -1;		/* Now send the EEPROM read command and EEPROM location to read */		writereg(dev, PP_EECMD, (off + i) | EEPROM_READ_CMD);		if (wait_eeprom_ready(dev) < 0) return -1;		buffer[i] = readreg(dev, PP_EEData);		if (net_debug > 3) printk("%04x ", buffer[i]);	}	if (net_debug > 3) printk("\n");        return 0;}__initfunc(static intget_eeprom_cksum(int off, int len, int *buffer)){	int i, cksum;	cksum = 0;	for (i = 0; i < len; i++)		cksum += buffer[i];	cksum &= 0xffff;	if (cksum == 0)		return 0;	return -1;}/* 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.  */__initfunc(static int cs89x0_probe1(struct device *dev, int ioaddr)){	struct net_local *lp;	static unsigned version_printed = 0;	int i;	unsigned rev_type = 0;	int eeprom_buff[CHKSUM_LEN];	/* Initialize the device structure. */	if (dev->priv == NULL) {		dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);                memset(dev->priv, 0, sizeof(struct net_local));        }	lp = (struct net_local *)dev->priv;	/* if they give us an odd I/O address, then do ONE write to           the address port, to get it back to address zero, where we           expect to find the EISA signature word. */	if (ioaddr & 1) {		ioaddr &= ~1;		if ((inw(ioaddr + ADD_PORT) & ADD_MASK) != ADD_SIG)			return ENODEV;		outw(PP_ChipID, ioaddr + ADD_PORT);	}	if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG)		return ENODEV;	/* Fill in the 'dev' fields. */	dev->base_addr = ioaddr;	/* get the chip type */	rev_type = readreg(dev, PRODUCT_ID_ADD);	lp->chip_type = rev_type &~ REVISON_BITS;	lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';	/* Check the chip type and revision in order to set the correct send command	CS8920 revision C and CS8900 revision F can use the faster send. */	lp->send_cmd = TX_AFTER_381;	if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')		lp->send_cmd = TX_NOW;	if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')		lp->send_cmd = TX_NOW;	if (net_debug  &&  version_printed++ == 0)		printk(version);	printk("%s: cs89%c0%s rev %c found at %#3lx",	       dev->name,	       lp->chip_type==CS8900?'0':'2',	       lp->chip_type==CS8920M?"M":"",	       lp->chip_revision,	       dev->base_addr);	reset_chip(dev);	/* First check to see if an EEPROM is attached*/	if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)		printk("\ncs89x0: No EEPROM, relying on command line....\n");	else if (get_eeprom_data(dev, START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {		printk("\ncs89x0: EEPROM read failed, relying on command line.\n");        } else if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {                printk("\ncs89x0: EEPROM checksum bad, relyong on command line\n");        } else {                /* get transmission control word  but keep the autonegotiation bits */                if (!lp->auto_neg_cnf) lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];                /* Store adapter configuration */                if (!lp->adapter_cnf) lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];                /* Store ISA configuration */                lp->isa_config = eeprom_buff[ISA_CNF_OFFSET/2];                /* store the initial memory base address */                dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET/2] << 8;                for (i = 0; i < ETH_ALEN/2; i++) {                        dev->dev_addr[i*2] = eeprom_buff[i];                        dev->dev_addr[i*2+1] = eeprom_buff[i] >> 8;                }        }	printk(" media %s%s%s",	       (lp->adapter_cnf & A_CNF_10B_T)?"RJ-45,":"",	       (lp->adapter_cnf & A_CNF_AUI)?"AUI,":"",	       (lp->adapter_cnf & A_CNF_10B_2)?"BNC,":"");	lp->irq_map = 0xffff;	/* If this is a CS8900 then no pnp soft */	if (lp->chip_type != CS8900 &&	    /* Check if the ISA IRQ has been set  */		(i = readreg(dev, PP_CS8920_ISAINT) & 0xff,		 (i != 0 && i < CS8920_NO_INTS))) {		if (!dev->irq)			dev->irq = i;	} else {		i = lp->isa_config & INT_NO_MASK;		if (lp->chip_type == CS8900) {			/* the table that follows is dependent upon how you wired up your cs8900			 * in your system.  The table is the same as the cs8900 engineering demo			 * board.  irq_map also depends on the contents of the table.  Also see			 * write_irq, which is the reverse mapping of the table below. */			switch(i) {			case 0: i = 10; break;			case 1: i = 11; break;			case 2: i = 12; break;			case 3: i =  5; break;			default: printk("\ncs89x0: bug: isa_config is %d\n", i);			}			lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */		} else {			int irq_map_buff[IRQ_MAP_LEN/2];			if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,					    IRQ_MAP_LEN/2,					    irq_map_buff) >= 0) {				if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)					lp->irq_map = (irq_map_buff[0]>>8) | (irq_map_buff[1] << 8);			}		}		if (!dev->irq)			dev->irq = i;	}

⌨️ 快捷键说明

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