sun3_82586.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,212 行 · 第 1/3 页
C
1,212 行
/* * Sun3 i82586 Ethernet driver * * Cloned from ni52.c for the Sun3 by Sam Creasey (sammy@sammy.net) * * Original copyright follows: * -------------------------- * * net-3-driver for the NI5210 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. * * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later) * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de) * -------------------------- * * Consult ni52.c for further notes from the original driver. * * This incarnation currently supports the OBIO version of the i82586 chip * used in certain sun3 models. It should be fairly doable to expand this * to support VME if I should every acquire such a board. * */static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */static int automatic_resume = 0; /* experimental .. better should be zero */static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */static int fifo=0x8; /* don't change *//* #define REALLY_SLOW_IO */#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/init.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/idprom.h>#include <asm/machines.h>#include <asm/sun3mmu.h>#include <asm/dvma.h>#include <asm/byteorder.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include "sun3_82586.h"#define DRV_NAME "sun3_82586"#define DEBUG /* debug on */#define SYSBUSVAL 0 /* 16 Bit */#define SUN3_82586_TOTAL_SIZE PAGE_SIZE#define sun3_attn586() {*(volatile unsigned char *)(dev->base_addr) |= IEOB_ATTEN; *(volatile unsigned char *)(dev->base_addr) &= ~IEOB_ATTEN;}#define sun3_reset586() {*(volatile unsigned char *)(dev->base_addr) = 0; udelay(100); *(volatile unsigned char *)(dev->base_addr) = IEOB_NORSET;}#define sun3_disint() {*(volatile unsigned char *)(dev->base_addr) &= ~IEOB_IENAB;}#define sun3_enaint() {*(volatile unsigned char *)(dev->base_addr) |= IEOB_IENAB;}#define sun3_active() {*(volatile unsigned char *)(dev->base_addr) |= (IEOB_IENAB|IEOB_ONAIR|IEOB_NORSET);}#define make32(ptr16) (p->memtop + (swab16((unsigned short) (ptr16))) )#define make24(ptr32) (char *)swab32(( ((unsigned long) (ptr32)) - p->base))#define make16(ptr32) (swab16((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop )))/******************* 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 these values: */#define RECV_BUFF_SIZE 1536 /* slightly oversized */#define XMIT_BUFF_SIZE 1536 /* slightly oversized */#define NUM_XMIT_BUFFS 1 /* config for 32K shmem */#define NUM_RECV_BUFFS_8 4 /* config for 32K shared mem */#define NUM_RECV_BUFFS_16 9 /* config for 32K shared mem */#define NUM_RECV_BUFFS_32 16 /* config for 32K shared mem */#define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 *//**************************************************************************//* different DELAYs */#define DELAY(x) mdelay(32 * x);#define DELAY_16(); { udelay(16); }#define DELAY_18(); { udelay(4); }/* wait for command with timeout: */#define WAIT_4_SCB_CMD() \{ int i; \ for(i=0;i<16384;i++) { \ if(!p->scb->cmd_cuc) break; \ DELAY_18(); \ if(i == 16383) { \ printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \ if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }#define WAIT_4_SCB_CMD_RUC() { int i; \ for(i=0;i<16384;i++) { \ if(!p->scb->cmd_ruc) break; \ DELAY_18(); \ if(i == 16383) { \ printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \ if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }#define WAIT_4_STAT_COMPL(addr) { int i; \ for(i=0;i<32767;i++) { \ if(swab16((addr)->cmd_status) & STAT_COMPL) break; \ DELAY_16(); DELAY_16(); } }static int sun3_82586_probe1(struct net_device *dev,int ioaddr);static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr);static int sun3_82586_open(struct net_device *dev);static int sun3_82586_close(struct net_device *dev);static int sun3_82586_send_packet(struct sk_buff *,struct net_device *);static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev);static void set_multicast_list(struct net_device *dev);static void sun3_82586_timeout(struct net_device *dev);#if 0static void sun3_82586_dump(struct net_device *,void *);#endif/* helper-functions */static int init586(struct net_device *dev);static int check586(struct net_device *dev,char *where,unsigned size);static void alloc586(struct net_device *dev);static void startrecv586(struct net_device *dev);static void *alloc_rfa(struct net_device *dev,void *ptr);static void sun3_82586_rcv_int(struct net_device *dev);static void sun3_82586_xmt_int(struct net_device *dev);static void sun3_82586_rnr_int(struct net_device *dev);struct priv{ struct net_device_stats stats; unsigned long base; char *memtop; long int lock; int reseted; 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;};/********************************************** * close device */static int sun3_82586_close(struct net_device *dev){ free_irq(dev->irq, dev); sun3_reset586(); /* the hard way to stop the receiver */ netif_stop_queue(dev); return 0;}/********************************************** * open device */static int sun3_82586_open(struct net_device *dev){ int ret; sun3_disint(); alloc586(dev); init586(dev); startrecv586(dev); sun3_enaint(); ret = request_irq(dev->irq, &sun3_82586_interrupt,0,dev->name,dev); if (ret) { sun3_reset586(); return ret; } netif_start_queue(dev); return 0; /* most done by init */}/********************************************** * Check to see if there's an 82586 out there. */static int check586(struct net_device *dev,char *where,unsigned size){ struct priv pb; struct priv *p = /* (struct priv *) dev->priv*/ &pb; char *iscp_addr; int i; p->base = (unsigned long) dvma_btov(0); p->memtop = (char *)dvma_btov((unsigned long)where); p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); memset((char *)p->scp,0, sizeof(struct scp_struct)); for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */ if(((char *)p->scp)[i]) return 0; p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */ if(p->scp->sysbus != SYSBUSVAL) return 0; iscp_addr = (char *)dvma_btov((unsigned long)where); p->iscp = (struct iscp_struct *) iscp_addr; memset((char *)p->iscp,0, sizeof(struct iscp_struct)); p->scp->iscp = make24(p->iscp); p->iscp->busy = 1; sun3_reset586(); sun3_attn586(); DELAY(1); /* wait a while... */ if(p->iscp->busy) /* i82586 clears 'busy' after successful init */ return 0; return 1;}/****************************************************************** * set iscp at the right place, called by sun3_82586_probe1 and open586. */static void alloc586(struct net_device *dev){ struct priv *p = (struct priv *) dev->priv; sun3_reset586(); DELAY(1); p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); p->iscp = (struct iscp_struct *) dvma_btov(dev->mem_start); p->scb = (struct scb_struct *) ((char *)p->iscp + 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->scb_base = make24(dvma_btov(dev->mem_start)); p->iscp->busy = 1; sun3_reset586(); sun3_attn586(); DELAY(1); if(p->iscp->busy) printk("%s: Init-Problems (alloc).\n",dev->name); p->reseted = 0; memset((char *)p->scb,0,sizeof(struct scb_struct));}struct net_device * __init sun3_82586_probe(int unit){ struct net_device *dev; unsigned long ioaddr; static int found = 0; int err = -ENOMEM; /* check that this machine has an onboard 82586 */ switch(idprom->id_machtype) { case SM_SUN3|SM_3_160: case SM_SUN3|SM_3_260: /* these machines have 82586 */ break; default: return ERR_PTR(-ENODEV); } if (found) return ERR_PTR(-ENODEV); ioaddr = (unsigned long)ioremap(IE_OBIO, SUN3_82586_TOTAL_SIZE); if (!ioaddr) return ERR_PTR(-ENOMEM); found = 1; dev = alloc_etherdev(sizeof(struct priv)); if (!dev) goto out; if (unit >= 0) { sprintf(dev->name, "eth%d", unit); netdev_boot_setup_check(dev); } SET_MODULE_OWNER(dev); dev->irq = IE_IRQ; dev->base_addr = ioaddr; err = sun3_82586_probe1(dev, ioaddr); if (err) goto out1; err = register_netdev(dev); if (err) goto out2; return dev;out2: release_region(ioaddr, SUN3_82586_TOTAL_SIZE);out1: free_netdev(dev);out: iounmap((void *)ioaddr); return ERR_PTR(err);}static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr){ int i, size, retval; if (!request_region(ioaddr, SUN3_82586_TOTAL_SIZE, DRV_NAME)) return -EBUSY; /* copy in the ethernet address from the prom */ for(i = 0; i < 6 ; i++) dev->dev_addr[i] = idprom->id_ethaddr[i]; printk("%s: SUN3 Intel 82586 found at %lx, ",dev->name,dev->base_addr); /* * check (or search) IO-Memory, 32K */ size = 0x8000; dev->mem_start = (unsigned long)dvma_malloc_align(0x8000, 0x1000); dev->mem_end = dev->mem_start + size; if(size != 0x2000 && size != 0x4000 && size != 0x8000) { printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 or 0x8000 bytes.\n",dev->name,size); retval = -ENODEV; goto out; } if(!check586(dev,(char *) dev->mem_start,size)) { printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size); retval = -ENODEV; goto out; } ((struct priv *) (dev->priv))->memtop = (char *)dvma_btov(dev->mem_start); ((struct priv *) (dev->priv))->base = (unsigned long) dvma_btov(0); alloc586(dev); /* set number of receive-buffs according to memsize */ if(size == 0x2000) ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8; else if(size == 0x4000) ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16; else ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_32; printk("Memaddr: 0x%lx, Memsize: %d, IRQ %d\n",dev->mem_start,size, dev->irq); dev->open = sun3_82586_open; dev->stop = sun3_82586_close; dev->get_stats = sun3_82586_get_stats; dev->tx_timeout = sun3_82586_timeout; dev->watchdog_timeo = HZ/20; dev->hard_start_xmit = sun3_82586_send_packet; dev->set_multicast_list = set_multicast_list; dev->if_port = 0; return 0;out: release_region(ioaddr, SUN3_82586_TOTAL_SIZE); return retval;}static int init586(struct net_device *dev){ void *ptr; int i,result=0; struct priv *p = (struct priv *) dev->priv; volatile struct configure_cmd_struct *cfg_cmd;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?