Import 2.3.18pre1
[davej-history.git] / drivers / net / ni52.c
blob7efc0dca6301681bf9ea4aa944e469aa89a24c50
1 /*
2 * net-3-driver for the NI5210 card (i82586 Ethernet chip)
4 * This is an extension to the Linux operating system, and is covered by the
5 * same Gnu Public License that covers that work.
7 * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
8 * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
9 * [feel free to mail ....]
11 * when using as module: (no autoprobing!)
12 * compile with:
13 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c
14 * run with e.g:
15 * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
17 * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
19 * If you find a bug, please report me:
20 * The kernel panic output and any kmsg from the ni52 driver
21 * the ni5210-driver-version and the linux-kernel version
22 * how many shared memory (memsize) on the netcard,
23 * bootprom: yes/no, base_addr, mem_start
24 * maybe the ni5210-card revision and the i82586 version
26 * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
27 * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
28 * 0xd8000,0xcc000,0xce000,0xda000,0xdc000
30 * sources:
31 * skeleton.c from Donald Becker
33 * I have also done a look in the following sources: (mail me if you need them)
34 * crynwr-packet-driver by Russ Nelson
35 * Garret A. Wollman's (fourth) i82586-driver for BSD
36 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers helped
37 * me a lot to understand this tricky chip.)
39 * Known Problems:
40 * The internal sysbus seems to be slow. So we often lose packets because of
41 * overruns while receiving from a fast remote host.
42 * This can slow down TCP connections. Maybe the newer ni5210 cards are better.
43 * my experience is, that if a machine sends with more then about 500-600K/s
44 * the fifo/sysbus overflows.
46 * IMPORTANT NOTE:
47 * On fast networks, it's a (very) good idea to have 16K shared memory. With
48 * 8K, we can store only 4 receive frames, so it can (easily) happen that a remote
49 * machine 'overruns' our system.
51 * Known i82586/card problems (I'm sure, there are many more!):
52 * Running the NOP-mode, the i82586 sometimes seems to forget to report
53 * every xmit-interrupt until we restart the CU.
54 * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
55 * in the RBD-Struct which indicates an end of the RBD queue.
56 * Instead, the RU fetches another (randomly selected and
57 * usually used) RBD and begins to fill it. (Maybe, this happens only if
58 * the last buffer from the previous RFD fits exact into the queue and
59 * the next RFD can't fetch an initial RBD. Anyone knows more? )
61 * results from ftp performance tests with Linux 1.2.5
62 * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
63 * sending in NOP-mode: peak performance up to 530K/s (but better don't run this mode)
67 * 29.Sept.96: virt_to_bus changes for new memory scheme
68 * 19.Feb.96: more Mcast changes, module support (MH)
70 * 18.Nov.95: Mcast changes (AC).
72 * 23.April.95: fixed(?) receiving problems by configuring a RFD more
73 * than the number of RBD's. Can maybe cause other problems.
74 * 18.April.95: Added MODULE support (MH)
75 * 17.April.95: MC related changes in init586() and set_multicast_list().
76 * removed use of 'jiffies' in init586() (MH)
78 * 19.Sep.94: Added Multicast support (not tested yet) (MH)
80 * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
81 * Now, every RFD has exact one RBD. (MH)
83 * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
85 * 19.Aug.94: changed request_irq() parameter (MH)
87 * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
89 * 19.July.94: lotsa cleanups .. (MH)
91 * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
93 * 4.July.94: patches for Linux 1.1.24 (MH)
95 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
97 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, too (MH)
99 * < 30.Sep.93: first versions
102 static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */
103 static int automatic_resume = 0; /* experimental .. better should be zero */
104 static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */
105 static int fifo=0x8; /* don't change */
107 /* #define REALLY_SLOW_IO */
109 #include <linux/module.h>
110 #include <linux/kernel.h>
111 #include <linux/string.h>
112 #include <linux/errno.h>
113 #include <linux/ioport.h>
114 #include <linux/malloc.h>
115 #include <linux/interrupt.h>
116 #include <linux/delay.h>
117 #include <linux/init.h>
118 #include <asm/bitops.h>
119 #include <asm/io.h>
121 #include <linux/netdevice.h>
122 #include <linux/etherdevice.h>
123 #include <linux/skbuff.h>
125 #include "ni52.h"
127 #define DEBUG /* debug on */
128 #define SYSBUSVAL 1 /* 8 Bit */
130 #define ni_attn586() {outb(0,dev->base_addr+NI52_ATTENTION);}
131 #define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);}
132 #define ni_disint() {outb(0,dev->base_addr+NI52_INTDIS);}
133 #define ni_enaint() {outb(0,dev->base_addr+NI52_INTENA);}
135 #define make32(ptr16) (p->memtop + (short) (ptr16) )
136 #define make24(ptr32) ( ((char *) (ptr32)) - p->base)
137 #define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop ))
139 /******************* how to calculate the buffers *****************************
141 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
142 * --------------- in a different (more stable?) mode. Only in this mode it's
143 * possible to configure the driver with 'NO_NOPCOMMANDS'
145 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
146 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
147 sizeof(rfd) = 24; sizeof(rbd) = 12;
148 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
149 sizeof(nop_cmd) = 8;
151 * if you don't know the driver, better do not change these values: */
153 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
154 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
155 #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
156 #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
157 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
158 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
160 /**************************************************************************/
162 /* different DELAYs */
163 #define DELAY(x) __delay((loops_per_sec>>5)*(x));
164 #define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }
165 #define DELAY_18(); { __delay( (loops_per_sec>>18)+1 ); }
167 /* wait for command with timeout: */
168 #define WAIT_4_SCB_CMD() \
169 { int i; \
170 for(i=0;i<16384;i++) { \
171 if(!p->scb->cmd_cuc) break; \
172 DELAY_18(); \
173 if(i == 16383) { \
174 printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
175 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
177 #define WAIT_4_SCB_CMD_RUC() { int i; \
178 for(i=0;i<16384;i++) { \
179 if(!p->scb->cmd_ruc) break; \
180 DELAY_18(); \
181 if(i == 16383) { \
182 printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
183 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
185 #define WAIT_4_STAT_COMPL(addr) { int i; \
186 for(i=0;i<32767;i++) { \
187 if((addr)->cmd_status & STAT_COMPL) break; \
188 DELAY_16(); DELAY_16(); } }
190 #define NI52_TOTAL_SIZE 16
191 #define NI52_ADDR0 0x02
192 #define NI52_ADDR1 0x07
193 #define NI52_ADDR2 0x01
195 static int ni52_probe1(struct net_device *dev,int ioaddr);
196 static void ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr);
197 static int ni52_open(struct net_device *dev);
198 static int ni52_close(struct net_device *dev);
199 static int ni52_send_packet(struct sk_buff *,struct net_device *);
200 static struct net_device_stats *ni52_get_stats(struct net_device *dev);
201 static void set_multicast_list(struct net_device *dev);
202 #if 0
203 static void ni52_dump(struct net_device *,void *);
204 #endif
206 /* helper-functions */
207 static int init586(struct net_device *dev);
208 static int check586(struct net_device *dev,char *where,unsigned size);
209 static void alloc586(struct net_device *dev);
210 static void startrecv586(struct net_device *dev);
211 static void *alloc_rfa(struct net_device *dev,void *ptr);
212 static void ni52_rcv_int(struct net_device *dev);
213 static void ni52_xmt_int(struct net_device *dev);
214 static void ni52_rnr_int(struct net_device *dev);
216 struct priv
218 struct net_device_stats stats;
219 unsigned long base;
220 char *memtop;
221 int lock,reseted;
222 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
223 volatile struct scp_struct *scp; /* volatile is important */
224 volatile struct iscp_struct *iscp; /* volatile is important */
225 volatile struct scb_struct *scb; /* volatile is important */
226 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
227 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
228 #if (NUM_XMIT_BUFFS == 1)
229 volatile struct nop_cmd_struct *nop_cmds[2];
230 #else
231 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
232 #endif
233 volatile int nop_point,num_recv_buffs;
234 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
235 volatile int xmit_count,xmit_last;
238 /**********************************************
239 * close device
241 static int ni52_close(struct net_device *dev)
243 free_irq(dev->irq, dev);
245 ni_reset586(); /* the hard way to stop the receiver */
247 dev->start = 0;
248 dev->tbusy = 0;
250 MOD_DEC_USE_COUNT;
252 return 0;
255 /**********************************************
256 * open device
258 static int ni52_open(struct net_device *dev)
260 ni_disint();
261 alloc586(dev);
262 init586(dev);
263 startrecv586(dev);
264 ni_enaint();
266 if(request_irq(dev->irq, &ni52_interrupt,0,"ni5210",dev))
268 ni_reset586();
269 return -EAGAIN;
272 dev->interrupt = 0;
273 dev->tbusy = 0;
274 dev->start = 1;
276 MOD_INC_USE_COUNT;
278 return 0; /* most done by init */
281 /**********************************************
282 * Check to see if there's an 82586 out there.
284 static int check586(struct net_device *dev,char *where,unsigned size)
286 struct priv pb;
287 struct priv *p = /* (struct priv *) dev->priv*/ &pb;
288 char *iscp_addrs[2];
289 int i;
291 p->base = (unsigned long) bus_to_virt((unsigned long)where) + size - 0x01000000;
292 p->memtop = bus_to_virt((unsigned long)where) + size;
293 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
294 memset((char *)p->scp,0, sizeof(struct scp_struct));
295 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
296 if(((char *)p->scp)[i])
297 return 0;
298 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
299 if(p->scp->sysbus != SYSBUSVAL)
300 return 0;
302 iscp_addrs[0] = bus_to_virt((unsigned long)where);
303 iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct);
305 for(i=0;i<2;i++)
307 p->iscp = (struct iscp_struct *) iscp_addrs[i];
308 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
310 p->scp->iscp = make24(p->iscp);
311 p->iscp->busy = 1;
313 ni_reset586();
314 ni_attn586();
315 DELAY(1); /* wait a while... */
317 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
318 return 0;
320 return 1;
323 /******************************************************************
324 * set iscp at the right place, called by ni52_probe1 and open586.
326 void alloc586(struct net_device *dev)
328 struct priv *p = (struct priv *) dev->priv;
330 ni_reset586();
331 DELAY(1);
333 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
334 p->scb = (struct scb_struct *) bus_to_virt(dev->mem_start);
335 p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct));
337 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
338 memset((char *) p->scp ,0,sizeof(struct scp_struct));
340 p->scp->iscp = make24(p->iscp);
341 p->scp->sysbus = SYSBUSVAL;
342 p->iscp->scb_offset = make16(p->scb);
344 p->iscp->busy = 1;
345 ni_reset586();
346 ni_attn586();
348 DELAY(1);
350 if(p->iscp->busy)
351 printk("%s: Init-Problems (alloc).\n",dev->name);
353 p->reseted = 0;
355 memset((char *)p->scb,0,sizeof(struct scb_struct));
358 /**********************************************
359 * probe the ni5210-card
361 int __init ni52_probe(struct net_device *dev)
363 #ifndef MODULE
364 int *port;
365 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
366 #endif
367 int base_addr = dev->base_addr;
369 if (base_addr > 0x1ff) { /* Check a single specified location. */
370 if( (inb(base_addr+NI52_MAGIC1) == NI52_MAGICVAL1) &&
371 (inb(base_addr+NI52_MAGIC2) == NI52_MAGICVAL2))
372 return ni52_probe1(dev, base_addr);
373 } else if (base_addr > 0) /* Don't probe at all. */
374 return ENXIO;
376 #ifdef MODULE
377 printk("%s: no autoprobing allowed for modules.\n",dev->name);
378 #else
379 for (port = ports; *port; port++) {
380 int ioaddr = *port;
381 if (check_region(ioaddr, NI52_TOTAL_SIZE))
382 continue;
383 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
384 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))
385 continue;
387 dev->base_addr = ioaddr;
388 if (ni52_probe1(dev, ioaddr) == 0)
389 return 0;
392 #ifdef FULL_IO_PROBE
393 for(dev->base_addr=0x200;dev->base_addr<0x400;dev->base_addr+=8)
395 int ioaddr = dev->base_addr;
396 if (check_region(ioaddr, NI52_TOTAL_SIZE))
397 continue;
398 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
399 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))
400 continue;
401 if (ni52_probe1(dev, ioaddr) == 0)
402 return 0;
404 #endif
406 #endif
408 dev->base_addr = base_addr;
409 return ENODEV;
412 static int __init ni52_probe1(struct net_device *dev,int ioaddr)
414 int i,size;
416 for(i=0;i<ETH_ALEN;i++)
417 dev->dev_addr[i] = inb(dev->base_addr+i);
419 if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
420 || dev->dev_addr[2] != NI52_ADDR2)
421 return ENODEV;
423 printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);
425 request_region(ioaddr,NI52_TOTAL_SIZE,"ni5210");
428 * check (or search) IO-Memory, 8K and 16K
430 #ifdef MODULE
431 size = dev->mem_end - dev->mem_start;
432 if(size != 0x2000 && size != 0x4000)
434 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size);
435 return ENODEV;
437 if(!check586(dev,(char *) dev->mem_start,size))
439 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
440 return ENODEV;
442 #else
443 if(dev->mem_start != 0) /* no auto-mem-probe */
445 size = 0x4000; /* check for 16K mem */
446 if(!check586(dev,(char *) dev->mem_start,size)) {
447 size = 0x2000; /* check for 8K mem */
448 if(!check586(dev,(char *) dev->mem_start,size)) {
449 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);
450 return ENODEV;
454 else
456 static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000,
457 0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 };
458 for(i=0;;i++)
460 if(!memaddrs[i]) {
461 printk("?memprobe, Can't find io-memory!\n");
462 return ENODEV;
464 dev->mem_start = memaddrs[i];
465 size = 0x2000; /* check for 8K mem */
466 if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */
467 break;
468 size = 0x4000; /* check for 16K mem */
469 if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */
470 break;
473 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
474 #endif
476 dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
477 if(dev->priv == NULL)
479 printk("%s: Ooops .. can't allocate private driver memory.\n",dev->name);
480 return -ENOMEM;
482 /* warning: we don't free it on errors */
483 memset((char *) dev->priv,0,sizeof(struct priv));
485 ((struct priv *) (dev->priv))->memtop = bus_to_virt(dev->mem_start) + size;
486 ((struct priv *) (dev->priv))->base = (unsigned long) bus_to_virt(dev->mem_start) + size - 0x01000000;
487 alloc586(dev);
489 /* set number of receive-buffs according to memsize */
490 if(size == 0x2000)
491 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
492 else
493 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
495 printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size);
497 if(dev->irq < 2)
499 autoirq_setup(0);
500 ni_reset586();
501 ni_attn586();
502 if(!(dev->irq = autoirq_report(2)))
504 printk("?autoirq, Failed to detect IRQ line!\n");
505 return 1;
507 printk("IRQ %d (autodetected).\n",dev->irq);
509 else {
510 if(dev->irq == 2)
511 dev->irq = 9;
512 printk("IRQ %d (assigned and not checked!).\n",dev->irq);
515 dev->open = &ni52_open;
516 dev->stop = &ni52_close;
517 dev->get_stats = &ni52_get_stats;
518 dev->hard_start_xmit = &ni52_send_packet;
519 dev->set_multicast_list = &set_multicast_list;
521 dev->if_port = 0;
523 ether_setup(dev);
525 dev->tbusy = 0;
526 dev->interrupt = 0;
527 dev->start = 0;
529 return 0;
532 /**********************************************
533 * init the chip (ni52-interrupt should be disabled?!)
534 * needs a correct 'allocated' memory
537 static int init586(struct net_device *dev)
539 void *ptr;
540 int i,result=0;
541 struct priv *p = (struct priv *) dev->priv;
542 volatile struct configure_cmd_struct *cfg_cmd;
543 volatile struct iasetup_cmd_struct *ias_cmd;
544 volatile struct tdr_cmd_struct *tdr_cmd;
545 volatile struct mcsetup_cmd_struct *mc_cmd;
546 struct dev_mc_list *dmi=dev->mc_list;
547 int num_addrs=dev->mc_count;
549 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
551 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
552 cfg_cmd->cmd_status = 0;
553 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
554 cfg_cmd->cmd_link = 0xffff;
556 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
557 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */
558 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
559 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
560 cfg_cmd->priority = 0x00;
561 cfg_cmd->ifs = 0x60;
562 cfg_cmd->time_low = 0x00;
563 cfg_cmd->time_high = 0xf2;
564 cfg_cmd->promisc = 0;
565 if(dev->flags & IFF_ALLMULTI) {
566 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
567 if(num_addrs > len) {
568 printk("%s: switching to promisc. mode\n",dev->name);
569 dev->flags|=IFF_PROMISC;
572 if(dev->flags&IFF_PROMISC)
574 cfg_cmd->promisc=1;
575 dev->flags|=IFF_PROMISC;
577 cfg_cmd->carr_coll = 0x00;
579 p->scb->cbl_offset = make16(cfg_cmd);
580 p->scb->cmd_ruc = 0;
582 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
583 ni_attn586();
585 WAIT_4_STAT_COMPL(cfg_cmd);
587 if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
589 printk("%s: configure command failed: %x\n",dev->name,cfg_cmd->cmd_status);
590 return 1;
594 * individual address setup
597 ias_cmd = (struct iasetup_cmd_struct *)ptr;
599 ias_cmd->cmd_status = 0;
600 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
601 ias_cmd->cmd_link = 0xffff;
603 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
605 p->scb->cbl_offset = make16(ias_cmd);
607 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
608 ni_attn586();
610 WAIT_4_STAT_COMPL(ias_cmd);
612 if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
613 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status);
614 return 1;
618 * TDR, wire check .. e.g. no resistor e.t.c
621 tdr_cmd = (struct tdr_cmd_struct *)ptr;
623 tdr_cmd->cmd_status = 0;
624 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
625 tdr_cmd->cmd_link = 0xffff;
626 tdr_cmd->status = 0;
628 p->scb->cbl_offset = make16(tdr_cmd);
629 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
630 ni_attn586();
632 WAIT_4_STAT_COMPL(tdr_cmd);
634 if(!(tdr_cmd->cmd_status & STAT_COMPL))
636 printk("%s: Problems while running the TDR.\n",dev->name);
638 else
640 DELAY_16(); /* wait for result */
641 result = tdr_cmd->status;
643 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
644 ni_attn586(); /* ack the interrupts */
646 if(result & TDR_LNK_OK)
648 else if(result & TDR_XCVR_PRB)
649 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
650 else if(result & TDR_ET_OPN)
651 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
652 else if(result & TDR_ET_SRT)
654 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
655 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
657 else
658 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
662 * Multicast setup
664 if(num_addrs && !(dev->flags & IFF_PROMISC) )
666 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
667 mc_cmd->cmd_status = 0;
668 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
669 mc_cmd->cmd_link = 0xffff;
670 mc_cmd->mc_cnt = num_addrs * 6;
672 for(i=0;i<num_addrs;i++,dmi=dmi->next)
673 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6);
675 p->scb->cbl_offset = make16(mc_cmd);
676 p->scb->cmd_cuc = CUC_START;
677 ni_attn586();
679 WAIT_4_STAT_COMPL(mc_cmd);
681 if( (mc_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
682 printk("%s: Can't apply multicast-address-list.\n",dev->name);
686 * alloc nop/xmit-cmds
688 #if (NUM_XMIT_BUFFS == 1)
689 for(i=0;i<2;i++)
691 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
692 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
693 p->nop_cmds[i]->cmd_status = 0;
694 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
695 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
697 #else
698 for(i=0;i<NUM_XMIT_BUFFS;i++)
700 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
701 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
702 p->nop_cmds[i]->cmd_status = 0;
703 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
704 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
706 #endif
708 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
711 * alloc xmit-buffs / init xmit_cmds
713 for(i=0;i<NUM_XMIT_BUFFS;i++)
715 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
716 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
717 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
718 ptr = (char *) ptr + XMIT_BUFF_SIZE;
719 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
720 ptr = (char *) ptr + sizeof(struct tbd_struct);
721 if((void *)ptr > (void *)p->iscp)
723 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
724 return 1;
726 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
727 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
728 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
729 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
730 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
731 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
732 p->xmit_buffs[i]->next = 0xffff;
733 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
736 p->xmit_count = 0;
737 p->xmit_last = 0;
738 #ifndef NO_NOPCOMMANDS
739 p->nop_point = 0;
740 #endif
743 * 'start transmitter'
745 #ifndef NO_NOPCOMMANDS
746 p->scb->cbl_offset = make16(p->nop_cmds[0]);
747 p->scb->cmd_cuc = CUC_START;
748 ni_attn586();
749 WAIT_4_SCB_CMD();
750 #else
751 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
752 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_SUSPEND | CMD_INT;
753 #endif
756 * ack. interrupts
758 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
759 ni_attn586();
760 DELAY_16();
762 ni_enaint();
764 return 0;
767 /******************************************************
768 * This is a helper routine for ni52_rnr_int() and init586().
769 * It sets up the Receive Frame Area (RFA).
772 static void *alloc_rfa(struct net_device *dev,void *ptr)
774 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
775 volatile struct rbd_struct *rbd;
776 int i;
777 struct priv *p = (struct priv *) dev->priv;
779 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
780 p->rfd_first = rfd;
782 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
783 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
784 rfd[i].rbd_offset = 0xffff;
786 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */
788 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
790 rbd = (struct rbd_struct *) ptr;
791 ptr = (void *) (rbd + p->num_recv_buffs);
793 /* clr descriptors */
794 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
796 for(i=0;i<p->num_recv_buffs;i++)
798 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
799 rbd[i].size = RECV_BUFF_SIZE;
800 rbd[i].buffer = make24(ptr);
801 ptr = (char *) ptr + RECV_BUFF_SIZE;
804 p->rfd_top = p->rfd_first;
805 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
807 p->scb->rfa_offset = make16(p->rfd_first);
808 p->rfd_first->rbd_offset = make16(rbd);
810 return ptr;
814 /**************************************************
815 * Interrupt Handler ...
818 static void ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr)
820 struct net_device *dev = dev_id;
821 unsigned short stat;
822 int cnt=0;
823 struct priv *p;
825 if (!dev) {
826 printk ("ni5210-interrupt: irq %d for unknown device.\n",irq);
827 return;
829 p = (struct priv *) dev->priv;
831 if(debuglevel > 1)
832 printk("I");
834 dev->interrupt = 1;
836 WAIT_4_SCB_CMD(); /* wait for last command */
838 while((stat=p->scb->cus & STAT_MASK))
840 p->scb->cmd_cuc = stat;
841 ni_attn586();
843 if(stat & STAT_FR) /* received a frame */
844 ni52_rcv_int(dev);
846 if(stat & STAT_RNR) /* RU went 'not ready' */
848 printk("(R)");
849 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
851 WAIT_4_SCB_CMD();
852 p->scb->cmd_ruc = RUC_RESUME;
853 ni_attn586();
854 WAIT_4_SCB_CMD_RUC();
856 else
858 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
859 ni52_rnr_int(dev);
863 if(stat & STAT_CX) /* command with I-bit set complete */
864 ni52_xmt_int(dev);
866 #ifndef NO_NOPCOMMANDS
867 if(stat & STAT_CNA) /* CU went 'not ready' */
869 if(dev->start)
870 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
872 #endif
874 if(debuglevel > 1)
875 printk("%d",cnt++);
877 WAIT_4_SCB_CMD(); /* wait for ack. (ni52_xmt_int can be faster than ack!!) */
878 if(p->scb->cmd_cuc) /* timed out? */
880 printk("%s: Acknowledge timed out.\n",dev->name);
881 ni_disint();
882 break;
886 if(debuglevel > 1)
887 printk("i");
889 dev->interrupt = 0;
892 /*******************************************************
893 * receive-interrupt
896 static void ni52_rcv_int(struct net_device *dev)
898 int status,cnt=0;
899 unsigned short totlen;
900 struct sk_buff *skb;
901 struct rbd_struct *rbd;
902 struct priv *p = (struct priv *) dev->priv;
904 if(debuglevel > 0)
905 printk("R");
907 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
909 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
911 if(status & RFD_OK) /* frame received without error? */
913 if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */
915 totlen &= RBD_MASK; /* length of this frame */
916 rbd->status = 0;
917 skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
918 if(skb != NULL)
920 skb->dev = dev;
921 skb_reserve(skb,2);
922 skb_put(skb,totlen);
923 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0);
924 skb->protocol=eth_type_trans(skb,dev);
925 netif_rx(skb);
926 p->stats.rx_packets++;
928 else
929 p->stats.rx_dropped++;
931 else
933 int rstat;
934 /* free all RBD's until RBD_LAST is set */
935 totlen = 0;
936 while(!((rstat=rbd->status) & RBD_LAST))
938 totlen += rstat & RBD_MASK;
939 if(!rstat)
941 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
942 break;
944 rbd->status = 0;
945 rbd = (struct rbd_struct *) make32(rbd->next);
947 totlen += rstat & RBD_MASK;
948 rbd->status = 0;
949 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
950 p->stats.rx_dropped++;
953 else /* frame !(ok), only with 'save-bad-frames' */
955 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
956 p->stats.rx_errors++;
958 p->rfd_top->stat_high = 0;
959 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
960 p->rfd_top->rbd_offset = 0xffff;
961 p->rfd_last->last = 0; /* delete RFD_SUSP */
962 p->rfd_last = p->rfd_top;
963 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
964 p->scb->rfa_offset = make16(p->rfd_top);
966 if(debuglevel > 0)
967 printk("%d",cnt++);
970 if(automatic_resume)
972 WAIT_4_SCB_CMD();
973 p->scb->cmd_ruc = RUC_RESUME;
974 ni_attn586();
975 WAIT_4_SCB_CMD_RUC();
978 #ifdef WAIT_4_BUSY
980 int i;
981 for(i=0;i<1024;i++)
983 if(p->rfd_top->status)
984 break;
985 DELAY_16();
986 if(i == 1023)
987 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
990 #endif
992 #if 0
993 if(!at_least_one)
995 int i;
996 volatile struct rfd_struct *rfds=p->rfd_top;
997 volatile struct rbd_struct *rbds;
998 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
999 for(i=0;i< (p->num_recv_buffs+4);i++)
1001 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
1002 printk("%04x:%04x ",rfds->status,rbds->status);
1003 rfds = (struct rfd_struct *) make32(rfds->next);
1005 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
1006 printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus);
1008 old_at_least = at_least_one;
1009 #endif
1011 if(debuglevel > 0)
1012 printk("r");
1015 /**********************************************************
1016 * handle 'Receiver went not ready'.
1019 static void ni52_rnr_int(struct net_device *dev)
1021 struct priv *p = (struct priv *) dev->priv;
1023 p->stats.rx_errors++;
1025 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1026 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1027 ni_attn586();
1028 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */
1030 alloc_rfa(dev,(char *)p->rfd_first);
1031 /* maybe add a check here, before restarting the RU */
1032 startrecv586(dev); /* restart RU */
1034 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
1038 /**********************************************************
1039 * handle xmit - interrupt
1042 static void ni52_xmt_int(struct net_device *dev)
1044 int status;
1045 struct priv *p = (struct priv *) dev->priv;
1047 if(debuglevel > 0)
1048 printk("X");
1050 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1051 if(!(status & STAT_COMPL))
1052 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
1054 if(status & STAT_OK)
1056 p->stats.tx_packets++;
1057 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1059 else
1061 p->stats.tx_errors++;
1062 if(status & TCMD_LATECOLL) {
1063 printk("%s: late collision detected.\n",dev->name);
1064 p->stats.collisions++;
1066 else if(status & TCMD_NOCARRIER) {
1067 p->stats.tx_carrier_errors++;
1068 printk("%s: no carrier detected.\n",dev->name);
1070 else if(status & TCMD_LOSTCTS)
1071 printk("%s: loss of CTS detected.\n",dev->name);
1072 else if(status & TCMD_UNDERRUN) {
1073 p->stats.tx_fifo_errors++;
1074 printk("%s: DMA underrun detected.\n",dev->name);
1076 else if(status & TCMD_MAXCOLL) {
1077 printk("%s: Max. collisions exceeded.\n",dev->name);
1078 p->stats.collisions += 16;
1082 #if (NUM_XMIT_BUFFS > 1)
1083 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
1084 p->xmit_last = 0;
1085 #endif
1087 dev->tbusy = 0;
1088 mark_bh(NET_BH);
1091 /***********************************************************
1092 * (re)start the receiver
1095 static void startrecv586(struct net_device *dev)
1097 struct priv *p = (struct priv *) dev->priv;
1099 WAIT_4_SCB_CMD();
1100 WAIT_4_SCB_CMD_RUC();
1101 p->scb->rfa_offset = make16(p->rfd_first);
1102 p->scb->cmd_ruc = RUC_START;
1103 ni_attn586(); /* start cmd. */
1104 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */
1107 /******************************************************
1108 * send frame
1111 static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1113 int len,i;
1114 #ifndef NO_NOPCOMMANDS
1115 int next_nop;
1116 #endif
1117 struct priv *p = (struct priv *) dev->priv;
1119 if(dev->tbusy)
1121 int tickssofar = jiffies - dev->trans_start;
1122 if (tickssofar < 5)
1123 return 1;
1125 #ifndef NO_NOPCOMMANDS
1126 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
1128 dev->tbusy = 0;
1129 #ifdef DEBUG
1130 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
1131 printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)p->xmit_cmds[0]->cmd_status,(int)p->nop_cmds[0]->cmd_status,(int)p->nop_cmds[1]->cmd_status,(int)p->nop_point);
1132 #endif
1133 p->scb->cmd_cuc = CUC_ABORT;
1134 ni_attn586();
1135 WAIT_4_SCB_CMD();
1136 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1137 p->scb->cmd_cuc = CUC_START;
1138 ni_attn586();
1139 WAIT_4_SCB_CMD();
1140 dev->trans_start = jiffies;
1141 return 0;
1143 else
1144 #endif
1146 #ifdef DEBUG
1147 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
1148 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status);
1149 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
1150 #endif
1151 ni52_close(dev);
1152 ni52_open(dev);
1154 dev->trans_start = jiffies;
1155 return 0;
1158 if(skb->len > XMIT_BUFF_SIZE)
1160 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1161 return 0;
1164 if (test_and_set_bit(0, (void*)&dev->tbusy)) {
1165 printk("%s: Transmitter access conflict.\n", dev->name);
1166 return 1;
1168 #if(NUM_XMIT_BUFFS > 1)
1169 else if(test_and_set_bit(0,(void *) &p->lock)) {
1170 printk("%s: Queue was locked\n",dev->name);
1171 return 1;
1173 #endif
1174 else
1176 memcpy((char *)p->xmit_cbuffs[p->xmit_count],(char *)(skb->data),skb->len);
1177 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
1179 #if (NUM_XMIT_BUFFS == 1)
1180 # ifdef NO_NOPCOMMANDS
1182 #ifdef DEBUG
1183 if(p->scb->cus & CU_ACTIVE)
1185 printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
1186 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,p->xmit_cmds[0]->cmd_status);
1188 #endif
1190 p->xmit_buffs[0]->size = TBD_LAST | len;
1191 for(i=0;i<16;i++)
1193 p->xmit_cmds[0]->cmd_status = 0;
1194 WAIT_4_SCB_CMD();
1195 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
1196 p->scb->cmd_cuc = CUC_RESUME;
1197 else
1199 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1200 p->scb->cmd_cuc = CUC_START;
1203 ni_attn586();
1204 dev->trans_start = jiffies;
1205 if(!i)
1206 dev_kfree_skb(skb);
1207 WAIT_4_SCB_CMD();
1208 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1209 break;
1210 if(p->xmit_cmds[0]->cmd_status)
1211 break;
1212 if(i==15)
1213 printk("%s: Can't start transmit-command.\n",dev->name);
1215 # else
1216 next_nop = (p->nop_point + 1) & 0x1;
1217 p->xmit_buffs[0]->size = TBD_LAST | len;
1219 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1220 = make16((p->nop_cmds[next_nop]));
1221 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1223 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1224 dev->trans_start = jiffies;
1225 p->nop_point = next_nop;
1226 dev_kfree_skb(skb);
1227 # endif
1228 #else
1229 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1230 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1231 next_nop = 0;
1233 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1234 /* linkpointer of xmit-command already points to next nop cmd */
1235 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
1236 p->nop_cmds[next_nop]->cmd_status = 0;
1238 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1239 dev->trans_start = jiffies;
1240 p->xmit_count = next_nop;
1243 long flags;
1244 save_flags(flags);
1245 cli();
1246 if(p->xmit_count != p->xmit_last)
1247 dev->tbusy = 0;
1248 p->lock = 0;
1249 restore_flags(flags);
1251 dev_kfree_skb(skb);
1252 #endif
1254 return 0;
1257 /*******************************************
1258 * Someone wanna have the statistics
1261 static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1263 struct priv *p = (struct priv *) dev->priv;
1264 unsigned short crc,aln,rsc,ovrn;
1266 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1267 p->scb->crc_errs = 0;
1268 aln = p->scb->aln_errs;
1269 p->scb->aln_errs = 0;
1270 rsc = p->scb->rsc_errs;
1271 p->scb->rsc_errs = 0;
1272 ovrn = p->scb->ovrn_errs;
1273 p->scb->ovrn_errs = 0;
1275 p->stats.rx_crc_errors += crc;
1276 p->stats.rx_fifo_errors += ovrn;
1277 p->stats.rx_frame_errors += aln;
1278 p->stats.rx_dropped += rsc;
1280 return &p->stats;
1283 /********************************************************
1284 * Set MC list ..
1286 static void set_multicast_list(struct net_device *dev)
1288 if(!dev->start)
1290 printk("%s: Can't apply promiscuous/multicastmode to a not running interface.\n",dev->name);
1291 return;
1294 dev->start = 0;
1296 ni_disint();
1297 alloc586(dev);
1298 init586(dev);
1299 startrecv586(dev);
1300 ni_enaint();
1302 dev->start = 1;
1305 #ifdef MODULE
1306 static char devicename[9] = { 0, };
1307 static struct net_device dev_ni52 = {
1308 devicename, /* "ni5210": device name inserted by net_init.c */
1309 0, 0, 0, 0,
1310 0x300, 9, /* I/O address, IRQ */
1311 0, 0, 0, NULL, ni52_probe };
1313 /* set: io,irq,memstart,memend or set it when calling insmod */
1314 int irq=9;
1315 int io=0x300;
1316 long memstart=0; /* e.g 0xd0000 */
1317 long memend=0; /* e.g 0xd4000 */
1319 MODULE_PARM(io, "i");
1320 MODULE_PARM(irq, "i");
1321 MODULE_PARM(memstart, "l");
1322 MODULE_PARM(memend, "l");
1324 int init_module(void)
1326 if(io <= 0x0 || !memend || !memstart || irq < 2) {
1327 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1328 return -ENODEV;
1330 dev_ni52.irq = irq;
1331 dev_ni52.base_addr = io;
1332 dev_ni52.mem_end = memend;
1333 dev_ni52.mem_start = memstart;
1334 if (register_netdev(&dev_ni52) != 0)
1335 return -EIO;
1336 return 0;
1339 void cleanup_module(void)
1341 release_region(dev_ni52.base_addr, NI52_TOTAL_SIZE);
1342 unregister_netdev(&dev_ni52);
1343 kfree(dev_ni52.priv);
1344 dev_ni52.priv = NULL;
1346 #endif /* MODULE */
1348 #if 0
1350 * DUMP .. we expect a not running CMD unit and enough space
1352 void ni52_dump(struct net_device *dev,void *ptr)
1354 struct priv *p = (struct priv *) dev->priv;
1355 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1356 int i;
1358 p->scb->cmd_cuc = CUC_ABORT;
1359 ni_attn586();
1360 WAIT_4_SCB_CMD();
1361 WAIT_4_SCB_CMD_RUC();
1363 dump_cmd->cmd_status = 0;
1364 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1365 dump_cmd->dump_offset = make16((dump_cmd + 1));
1366 dump_cmd->cmd_link = 0xffff;
1368 p->scb->cbl_offset = make16(dump_cmd);
1369 p->scb->cmd_cuc = CUC_START;
1370 ni_attn586();
1371 WAIT_4_STAT_COMPL(dump_cmd);
1373 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1374 printk("%s: Can't get dump information.\n",dev->name);
1376 for(i=0;i<170;i++) {
1377 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1378 if(i % 24 == 23)
1379 printk("\n");
1381 printk("\n");
1383 #endif
1386 * END: linux/drivers/net/ni52.c