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

📄 ni52.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  * 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.80 (96/02/19) for Linux 1.3.66 (or later) * Copyrights (c) 1994,1995,1996 by M.Hipp (Michael.Hipp@student.uni-tuebingen.de) *    [feel free to mail ....] * * when using as module: (no autoprobing!) *   compile with: gcc -D__KERNEL__ -DMODULE -O2 -c ni52.c *   run with e.g: insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000 * * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!. *  * If you find a bug, please report me: *   The kernel panic output and any kmsg from the ni52 driver *   the ni5210-driver-version and the linux-kernel version  *   how many shared memory (memsize) on the netcard,  *   bootprom: yes/no, base_addr, mem_start *   maybe the ni5210-card revision and the i82586 version * * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340 *                mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000, *                           0xd8000,0xcc000,0xce000,0xda000,0xdc000 * * sources: *   skeleton.c from Donald Becker * * I have also done a look in the following sources: (mail me if you need them) *   crynwr-packet-driver by Russ Nelson *   Garret A. Wollman's (fourth) i82586-driver for BSD *   (before getting an i82596 (yes 596 not 586) manual, the existing drivers helped *    me a lot to understand this tricky chip.) * * Known Problems: *   The internal sysbus seems to be slow. So we often lose packets because of *   overruns while receiving from a fast remote host.  *   This can slow down TCP connections. Maybe the newer ni5210 cards are better. *   my experience is, that if a machine sends with more then about 500-600K/s *   the fifo/sysbus overflows. *  * IMPORTANT NOTE: *   On fast networks, it's a (very) good idea to have 16K shared memory. With *   8K, we can store only 4 receive frames, so it can (easily) happen that a remote  *   machine 'overruns' our system. * * Known i82586/card problems (I'm sure, there are many more!): *   Running the NOP-mode, the i82586 sometimes seems to forget to report *   every xmit-interrupt until we restart the CU. *   Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit  *   in the RBD-Struct which indicates an end of the RBD queue.  *   Instead, the RU fetches another (randomly selected and  *   usually used) RBD and begins to fill it. (Maybe, this happens only if  *   the last buffer from the previous RFD fits exact into the queue and *   the next RFD can't fetch an initial RBD. Anyone knows more? ) * * results from ftp performance tests with Linux 1.2.5  *   send and receive about 350-400 KByte/s (peak up to 460 kbytes/s) *   sending in NOP-mode: peak performance up to 530K/s (but better don't run this mode) *//* * 19.Feb.96: more Mcast changes, module support (MH) * * 18.Nov.95: Mcast changes (AC). * * 23.April.95: fixed(?) receiving problems by configuring a RFD more *              than the number of RBD's. Can maybe cause other problems.  * 18.April.95: Added MODULE support (MH) * 17.April.95: MC related changes in init586() and set_multicast_list(). *              removed use of 'jiffies' in init586() (MH) * * 19.Sep.94: Added Multicast support (not tested yet) (MH) *  * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.  *            Now, every RFD has exact one RBD. (MH) * * 14.Sep.94: added promiscuous mode, a few cleanups (MH) * * 19.Aug.94: changed request_irq() parameter (MH) *  * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH) * * 19.July.94: lotsa cleanups .. (MH) * * 17.July.94: some patches ... verified to run with 1.1.29 (MH) * * 4.July.94: patches for Linux 1.1.24  (MH) * * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH) * * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, too (MH) * * < 30.Sep.93: first versions  */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/malloc.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <asm/bitops.h>#include <asm/io.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include "ni52.h"#define DEBUG       /* debug on */#define SYSBUSVAL 1 /* 8 Bit */#define ni_attn586()  {outb(0,dev->base_addr+NI52_ATTENTION);}#define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);}#define ni_disint()   {outb(0,dev->base_addr+NI52_INTDIS);}#define ni_enaint()   {outb(0,dev->base_addr+NI52_INTENA);}#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 ))/******************* 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 1524 /* slightly oversized */#define XMIT_BUFF_SIZE 1524 /* slightly oversized */#define NUM_XMIT_BUFFS 1    /* config for both, 8K and 16K shmem */#define NUM_RECV_BUFFS_8  4 /* config for 8K shared mem */#define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */#define NO_NOPCOMMANDS      /* only possible with NUM_XMIT_BUFFS=1 *//**************************************************************************//* different DELAYs */#define DELAY(x) __delay((loops_per_sec>>5)*(x)); #define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }#define DELAY_18(); { __delay( (loops_per_sec>>18)+1 ); }/* 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; ni_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; ni_reset586(); } } } }#define WAIT_4_STAT_COMPL(addr) { int i; \   for(i=0;i<32767;i++) { \     if((addr)->cmd_status & STAT_COMPL) break; \     DELAY_16(); DELAY_16(); } }#define NI52_TOTAL_SIZE 16#define NI52_ADDR0 0x02#define NI52_ADDR1 0x07#define NI52_ADDR2 0x01static int     ni52_probe1(struct device *dev,int ioaddr);static void    ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr);static int     ni52_open(struct device *dev);static int     ni52_close(struct device *dev);static int     ni52_send_packet(struct sk_buff *,struct device *);static struct  enet_statistics *ni52_get_stats(struct device *dev);static void    set_multicast_list(struct device *dev);#if 0static void    ni52_dump(struct device *,void *);#endif/* helper-functions */static int     init586(struct device *dev);static int     check586(struct device *dev,char *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    ni52_rcv_int(struct device *dev);static void    ni52_xmt_int(struct device *dev);static void    ni52_rnr_int(struct device *dev);struct priv{  struct enet_statistics stats;  unsigned long base;  char *memtop;  int lock,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 ni52_close(struct device *dev){  free_irq(dev->irq, NULL);  irq2dev_map[dev->irq] = NULL;  ni_reset586(); /* the hard way to stop the receiver */  dev->start = 0;  dev->tbusy = 0;  MOD_DEC_USE_COUNT;  return 0;}/********************************************** * open device  */static int ni52_open(struct device *dev){  ni_disint();  alloc586(dev);  init586(dev);    startrecv586(dev);  ni_enaint();  if(request_irq(dev->irq, &ni52_interrupt,0,"ni5210",NULL))   {    ni_reset586();    return -EAGAIN;  }    irq2dev_map[dev->irq] = dev;  dev->interrupt = 0;  dev->tbusy = 0;  dev->start = 1;  MOD_INC_USE_COUNT;  return 0; /* most done by init */}/********************************************** * Check to see if there's an 82586 out there.  */static int check586(struct device *dev,char *where,unsigned size){  struct priv pb;  struct priv *p = /* (struct priv *) dev->priv*/ &pb;  char *iscp_addrs[2];  int i;  p->base = (unsigned long) where + size - 0x01000000;  p->memtop = where + size;  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_addrs[0] = 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;    ni_reset586();    ni_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 ni52_probe1 and open586.  */void alloc586(struct device *dev){  struct priv *p =  (struct priv *) dev->priv;   ni_reset586();  DELAY(1);  p->scp  = (struct scp_struct *)  (p->base + SCP_DEFAULT_ADDRESS);  p->scb  = (struct scb_struct *)  (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;  ni_reset586();  ni_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));}/********************************************** * probe the ni5210-card */int ni52_probe(struct device *dev){#ifndef MODULE  int *port;  static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};#endif  int base_addr = dev->base_addr;  if (base_addr > 0x1ff)		/* Check a single specified location. */    if( (inb(base_addr+NI52_MAGIC1) == NI52_MAGICVAL1) &&        (inb(base_addr+NI52_MAGIC2) == NI52_MAGICVAL2))      return ni52_probe1(dev, base_addr);  else if (base_addr > 0)		/* Don't probe at all. */    return ENXIO;#ifdef MODULE  printk("%s: no autoprobing allowed for modules.\n",dev->name);#else  for (port = ports; *port; port++) {    int ioaddr = *port;    if (check_region(ioaddr, NI52_TOTAL_SIZE))      continue;    if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||         !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))      continue;    dev->base_addr = ioaddr;    if (ni52_probe1(dev, ioaddr) == 0)      return 0;  }#ifdef FULL_IO_PROBE  for(dev->base_addr=0x200;dev->base_addr<0x400;dev->base_addr+=8)  {    int ioaddr = dev->base_addr;    if (check_region(ioaddr, NI52_TOTAL_SIZE))      continue;    if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||         !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))      continue;    if (ni52_probe1(dev, ioaddr) == 0)      return 0;      }#endif#endif  dev->base_addr = base_addr;  return ENODEV;}static int ni52_probe1(struct device *dev,int ioaddr){  int i,size;  for(i=0;i<ETH_ALEN;i++)    dev->dev_addr[i] = inb(dev->base_addr+i);  if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1     || dev->dev_addr[2] != NI52_ADDR2)    return ENODEV;  printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);  request_region(ioaddr,NI52_TOTAL_SIZE,"ni5210");  /*    * check (or search) IO-Memory, 8K and 16K   */#ifdef MODULE  size = dev->mem_end - dev->mem_start;  if(size != 0x2000 && size != 0x4000)  {    printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size);    return ENODEV;  }  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);    return ENODEV;  }#else  if(dev->mem_start != 0) /* no auto-mem-probe */  {    size = 0x4000; /* check for 16K mem */    if(!check586(dev,(char *) dev->mem_start,size)) {      size = 0x2000; /* check for 8K mem */      if(!check586(dev,(char *) dev->mem_start,size)) {        printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);        return ENODEV;      }    }  }  else    {   static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000,                              0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 };   for(i=0;;i++)    {      if(!memaddrs[i]) {        printk("?memprobe, Can't find io-memory!\n");        return ENODEV;      }      dev->mem_start = memaddrs[i];      size = 0x2000; /* check for 8K mem */      if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */

⌨️ 快捷键说明

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