More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / ni52.c
blob67f857fc37aef8ce33779ffba56aee2e1b1cdac0
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 General 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 than 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; /* debug-printk 0: off 1: a few 2: more */
103 static int automatic_resume; /* experimental .. better should be zero */
104 static int rfdadd; /* 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/slab.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) mdelay(32 * x);
164 #define DELAY_16(); { udelay(16); }
165 #define DELAY_18(); { udelay(4); }
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 irqreturn_t 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 static void ni52_timeout(struct net_device *dev);
203 #if 0
204 static void ni52_dump(struct net_device *,void *);
205 #endif
207 /* helper-functions */
208 static int init586(struct net_device *dev);
209 static int check586(struct net_device *dev,char *where,unsigned size);
210 static void alloc586(struct net_device *dev);
211 static void startrecv586(struct net_device *dev);
212 static void *alloc_rfa(struct net_device *dev,void *ptr);
213 static void ni52_rcv_int(struct net_device *dev);
214 static void ni52_xmt_int(struct net_device *dev);
215 static void ni52_rnr_int(struct net_device *dev);
217 struct priv
219 struct net_device_stats stats;
220 unsigned long base;
221 char *memtop;
222 long int lock;
223 int reseted;
224 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
225 volatile struct scp_struct *scp; /* volatile is important */
226 volatile struct iscp_struct *iscp; /* volatile is important */
227 volatile struct scb_struct *scb; /* volatile is important */
228 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
229 #if (NUM_XMIT_BUFFS == 1)
230 volatile struct transmit_cmd_struct *xmit_cmds[2];
231 volatile struct nop_cmd_struct *nop_cmds[2];
232 #else
233 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
234 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
235 #endif
236 volatile int nop_point,num_recv_buffs;
237 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
238 volatile int xmit_count,xmit_last;
241 /**********************************************
242 * close device
244 static int ni52_close(struct net_device *dev)
246 free_irq(dev->irq, dev);
248 ni_reset586(); /* the hard way to stop the receiver */
250 netif_stop_queue(dev);
252 return 0;
255 /**********************************************
256 * open device
258 static int ni52_open(struct net_device *dev)
260 int ret;
262 ni_disint();
263 alloc586(dev);
264 init586(dev);
265 startrecv586(dev);
266 ni_enaint();
268 ret = request_irq(dev->irq, &ni52_interrupt,0,dev->name,dev);
269 if (ret)
271 ni_reset586();
272 return ret;
275 netif_start_queue(dev);
277 return 0; /* most done by init */
280 /**********************************************
281 * Check to see if there's an 82586 out there.
283 static int check586(struct net_device *dev,char *where,unsigned size)
285 struct priv pb;
286 struct priv *p = /* (struct priv *) dev->priv*/ &pb;
287 char *iscp_addrs[2];
288 int i;
290 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
291 p->memtop = isa_bus_to_virt((unsigned long)where) + size;
292 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
293 memset((char *)p->scp,0, sizeof(struct scp_struct));
294 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
295 if(((char *)p->scp)[i])
296 return 0;
297 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
298 if(p->scp->sysbus != SYSBUSVAL)
299 return 0;
301 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
302 iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct);
304 for(i=0;i<2;i++)
306 p->iscp = (struct iscp_struct *) iscp_addrs[i];
307 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
309 p->scp->iscp = make24(p->iscp);
310 p->iscp->busy = 1;
312 ni_reset586();
313 ni_attn586();
314 DELAY(1); /* wait a while... */
316 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
317 return 0;
319 return 1;
322 /******************************************************************
323 * set iscp at the right place, called by ni52_probe1 and open586.
325 static void alloc586(struct net_device *dev)
327 struct priv *p = (struct priv *) dev->priv;
329 ni_reset586();
330 DELAY(1);
332 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
333 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
334 p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct));
336 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
337 memset((char *) p->scp ,0,sizeof(struct scp_struct));
339 p->scp->iscp = make24(p->iscp);
340 p->scp->sysbus = SYSBUSVAL;
341 p->iscp->scb_offset = make16(p->scb);
343 p->iscp->busy = 1;
344 ni_reset586();
345 ni_attn586();
347 DELAY(1);
349 if(p->iscp->busy)
350 printk("%s: Init-Problems (alloc).\n",dev->name);
352 p->reseted = 0;
354 memset((char *)p->scb,0,sizeof(struct scb_struct));
357 /**********************************************
358 * probe the ni5210-card
360 int __init ni52_probe(struct net_device *dev)
362 #ifndef MODULE
363 int *port;
364 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
365 #endif
366 int base_addr = dev->base_addr;
368 SET_MODULE_OWNER(dev);
370 if (base_addr > 0x1ff) /* Check a single specified location. */
371 return ni52_probe1(dev, base_addr);
372 else if (base_addr > 0) /* Don't probe at all. */
373 return -ENXIO;
375 #ifdef MODULE
376 printk("%s: no autoprobing allowed for modules.\n",dev->name);
377 #else
378 for (port = ports; *port; port++) {
379 int ioaddr = *port;
380 dev->base_addr = ioaddr;
381 if (ni52_probe1(dev, ioaddr) == 0)
382 return 0;
385 #ifdef FULL_IO_PROBE
386 for(dev->base_addr=0x200; dev->base_addr<0x400; dev->base_addr+=8)
387 if (ni52_probe1(dev, dev->base_addr) == 0)
388 return 0;
389 #endif
391 #endif
393 dev->base_addr = base_addr;
394 return -ENODEV;
397 static int __init ni52_probe1(struct net_device *dev,int ioaddr)
399 int i, size, retval;
401 if (!request_region(ioaddr, NI52_TOTAL_SIZE, dev->name))
402 return -EBUSY;
404 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
405 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
406 retval = -ENODEV;
407 goto out;
410 for(i=0;i<ETH_ALEN;i++)
411 dev->dev_addr[i] = inb(dev->base_addr+i);
413 if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
414 || dev->dev_addr[2] != NI52_ADDR2) {
415 retval = -ENODEV;
416 goto out;
419 printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);
422 * check (or search) IO-Memory, 8K and 16K
424 #ifdef MODULE
425 size = dev->mem_end - dev->mem_start;
426 if(size != 0x2000 && size != 0x4000) {
427 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size);
428 retval = -ENODEV;
429 goto out;
431 if(!check586(dev,(char *) dev->mem_start,size)) {
432 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
433 retval = -ENODEV;
434 goto out;
436 #else
437 if(dev->mem_start != 0) /* no auto-mem-probe */
439 size = 0x4000; /* check for 16K mem */
440 if(!check586(dev,(char *) dev->mem_start,size)) {
441 size = 0x2000; /* check for 8K mem */
442 if(!check586(dev,(char *) dev->mem_start,size)) {
443 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);
444 retval = -ENODEV;
445 goto out;
449 else
451 static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000,
452 0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 };
453 for(i=0;;i++)
455 if(!memaddrs[i]) {
456 printk("?memprobe, Can't find io-memory!\n");
457 retval = -ENODEV;
458 goto out;
460 dev->mem_start = memaddrs[i];
461 size = 0x2000; /* check for 8K mem */
462 if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */
463 break;
464 size = 0x4000; /* check for 16K mem */
465 if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */
466 break;
469 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
470 #endif
472 dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
473 if(dev->priv == NULL) {
474 printk("%s: Ooops .. can't allocate private driver memory.\n",dev->name);
475 retval = -ENOMEM;
476 goto out;
478 /* warning: we don't free it on errors */
479 memset((char *) dev->priv,0,sizeof(struct priv));
481 ((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size;
482 ((struct priv *) (dev->priv))->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
483 alloc586(dev);
485 /* set number of receive-buffs according to memsize */
486 if(size == 0x2000)
487 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
488 else
489 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
491 printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size);
493 if(dev->irq < 2)
495 unsigned long irq_mask, delay;
497 irq_mask = probe_irq_on();
498 ni_reset586();
499 ni_attn586();
501 delay = jiffies + HZ/50;
502 while (time_before(jiffies, delay)) ;
503 dev->irq = probe_irq_off(irq_mask);
504 if(!dev->irq)
506 printk("?autoirq, Failed to detect IRQ line!\n");
507 kfree(dev->priv);
508 dev->priv = NULL;
509 retval = -EAGAIN;
510 goto out;
512 printk("IRQ %d (autodetected).\n",dev->irq);
514 else {
515 if(dev->irq == 2)
516 dev->irq = 9;
517 printk("IRQ %d (assigned and not checked!).\n",dev->irq);
520 dev->open = ni52_open;
521 dev->stop = ni52_close;
522 dev->get_stats = ni52_get_stats;
523 dev->tx_timeout = ni52_timeout;
524 dev->watchdog_timeo = HZ/20;
525 dev->hard_start_xmit = ni52_send_packet;
526 dev->set_multicast_list = set_multicast_list;
528 dev->if_port = 0;
530 ether_setup(dev);
532 return 0;
533 out:
534 release_region(ioaddr, NI52_TOTAL_SIZE);
535 return retval;
538 /**********************************************
539 * init the chip (ni52-interrupt should be disabled?!)
540 * needs a correct 'allocated' memory
543 static int init586(struct net_device *dev)
545 void *ptr;
546 int i,result=0;
547 struct priv *p = (struct priv *) dev->priv;
548 volatile struct configure_cmd_struct *cfg_cmd;
549 volatile struct iasetup_cmd_struct *ias_cmd;
550 volatile struct tdr_cmd_struct *tdr_cmd;
551 volatile struct mcsetup_cmd_struct *mc_cmd;
552 struct dev_mc_list *dmi=dev->mc_list;
553 int num_addrs=dev->mc_count;
555 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
557 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
558 cfg_cmd->cmd_status = 0;
559 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
560 cfg_cmd->cmd_link = 0xffff;
562 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
563 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */
564 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
565 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
566 cfg_cmd->priority = 0x00;
567 cfg_cmd->ifs = 0x60;
568 cfg_cmd->time_low = 0x00;
569 cfg_cmd->time_high = 0xf2;
570 cfg_cmd->promisc = 0;
571 if(dev->flags & IFF_ALLMULTI) {
572 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
573 if(num_addrs > len) {
574 printk("%s: switching to promisc. mode\n",dev->name);
575 dev->flags|=IFF_PROMISC;
578 if(dev->flags&IFF_PROMISC)
580 cfg_cmd->promisc=1;
581 dev->flags|=IFF_PROMISC;
583 cfg_cmd->carr_coll = 0x00;
585 p->scb->cbl_offset = make16(cfg_cmd);
586 p->scb->cmd_ruc = 0;
588 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
589 ni_attn586();
591 WAIT_4_STAT_COMPL(cfg_cmd);
593 if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
595 printk("%s: configure command failed: %x\n",dev->name,cfg_cmd->cmd_status);
596 return 1;
600 * individual address setup
603 ias_cmd = (struct iasetup_cmd_struct *)ptr;
605 ias_cmd->cmd_status = 0;
606 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
607 ias_cmd->cmd_link = 0xffff;
609 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
611 p->scb->cbl_offset = make16(ias_cmd);
613 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
614 ni_attn586();
616 WAIT_4_STAT_COMPL(ias_cmd);
618 if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
619 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status);
620 return 1;
624 * TDR, wire check .. e.g. no resistor e.t.c
627 tdr_cmd = (struct tdr_cmd_struct *)ptr;
629 tdr_cmd->cmd_status = 0;
630 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
631 tdr_cmd->cmd_link = 0xffff;
632 tdr_cmd->status = 0;
634 p->scb->cbl_offset = make16(tdr_cmd);
635 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
636 ni_attn586();
638 WAIT_4_STAT_COMPL(tdr_cmd);
640 if(!(tdr_cmd->cmd_status & STAT_COMPL))
642 printk("%s: Problems while running the TDR.\n",dev->name);
644 else
646 DELAY_16(); /* wait for result */
647 result = tdr_cmd->status;
649 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
650 ni_attn586(); /* ack the interrupts */
652 if(result & TDR_LNK_OK)
654 else if(result & TDR_XCVR_PRB)
655 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
656 else if(result & TDR_ET_OPN)
657 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
658 else if(result & TDR_ET_SRT)
660 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
661 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
663 else
664 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
668 * Multicast setup
670 if(num_addrs && !(dev->flags & IFF_PROMISC) )
672 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
673 mc_cmd->cmd_status = 0;
674 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
675 mc_cmd->cmd_link = 0xffff;
676 mc_cmd->mc_cnt = num_addrs * 6;
678 for(i=0;i<num_addrs;i++,dmi=dmi->next)
679 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6);
681 p->scb->cbl_offset = make16(mc_cmd);
682 p->scb->cmd_cuc = CUC_START;
683 ni_attn586();
685 WAIT_4_STAT_COMPL(mc_cmd);
687 if( (mc_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
688 printk("%s: Can't apply multicast-address-list.\n",dev->name);
692 * alloc nop/xmit-cmds
694 #if (NUM_XMIT_BUFFS == 1)
695 for(i=0;i<2;i++)
697 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
698 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
699 p->nop_cmds[i]->cmd_status = 0;
700 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
701 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
703 #else
704 for(i=0;i<NUM_XMIT_BUFFS;i++)
706 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
707 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
708 p->nop_cmds[i]->cmd_status = 0;
709 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
710 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
712 #endif
714 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
717 * alloc xmit-buffs / init xmit_cmds
719 for(i=0;i<NUM_XMIT_BUFFS;i++)
721 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
722 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
723 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
724 ptr = (char *) ptr + XMIT_BUFF_SIZE;
725 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
726 ptr = (char *) ptr + sizeof(struct tbd_struct);
727 if((void *)ptr > (void *)p->iscp)
729 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
730 return 1;
732 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
733 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
734 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
735 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
736 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
737 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
738 p->xmit_buffs[i]->next = 0xffff;
739 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
742 p->xmit_count = 0;
743 p->xmit_last = 0;
744 #ifndef NO_NOPCOMMANDS
745 p->nop_point = 0;
746 #endif
749 * 'start transmitter'
751 #ifndef NO_NOPCOMMANDS
752 p->scb->cbl_offset = make16(p->nop_cmds[0]);
753 p->scb->cmd_cuc = CUC_START;
754 ni_attn586();
755 WAIT_4_SCB_CMD();
756 #else
757 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
758 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_SUSPEND | CMD_INT;
759 #endif
762 * ack. interrupts
764 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
765 ni_attn586();
766 DELAY_16();
768 ni_enaint();
770 return 0;
773 /******************************************************
774 * This is a helper routine for ni52_rnr_int() and init586().
775 * It sets up the Receive Frame Area (RFA).
778 static void *alloc_rfa(struct net_device *dev,void *ptr)
780 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
781 volatile struct rbd_struct *rbd;
782 int i;
783 struct priv *p = (struct priv *) dev->priv;
785 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
786 p->rfd_first = rfd;
788 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
789 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
790 rfd[i].rbd_offset = 0xffff;
792 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */
794 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
796 rbd = (struct rbd_struct *) ptr;
797 ptr = (void *) (rbd + p->num_recv_buffs);
799 /* clr descriptors */
800 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
802 for(i=0;i<p->num_recv_buffs;i++)
804 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
805 rbd[i].size = RECV_BUFF_SIZE;
806 rbd[i].buffer = make24(ptr);
807 ptr = (char *) ptr + RECV_BUFF_SIZE;
810 p->rfd_top = p->rfd_first;
811 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
813 p->scb->rfa_offset = make16(p->rfd_first);
814 p->rfd_first->rbd_offset = make16(rbd);
816 return ptr;
820 /**************************************************
821 * Interrupt Handler ...
824 static irqreturn_t ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr)
826 struct net_device *dev = dev_id;
827 unsigned short stat;
828 int cnt=0;
829 struct priv *p;
831 if (!dev) {
832 printk ("ni5210-interrupt: irq %d for unknown device.\n",irq);
833 return IRQ_NONE;
835 p = (struct priv *) dev->priv;
837 if(debuglevel > 1)
838 printk("I");
840 WAIT_4_SCB_CMD(); /* wait for last command */
842 while((stat=p->scb->cus & STAT_MASK))
844 p->scb->cmd_cuc = stat;
845 ni_attn586();
847 if(stat & STAT_FR) /* received a frame */
848 ni52_rcv_int(dev);
850 if(stat & STAT_RNR) /* RU went 'not ready' */
852 printk("(R)");
853 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
855 WAIT_4_SCB_CMD();
856 p->scb->cmd_ruc = RUC_RESUME;
857 ni_attn586();
858 WAIT_4_SCB_CMD_RUC();
860 else
862 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
863 ni52_rnr_int(dev);
867 if(stat & STAT_CX) /* command with I-bit set complete */
868 ni52_xmt_int(dev);
870 #ifndef NO_NOPCOMMANDS
871 if(stat & STAT_CNA) /* CU went 'not ready' */
873 if(netif_running(dev))
874 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
876 #endif
878 if(debuglevel > 1)
879 printk("%d",cnt++);
881 WAIT_4_SCB_CMD(); /* wait for ack. (ni52_xmt_int can be faster than ack!!) */
882 if(p->scb->cmd_cuc) /* timed out? */
884 printk("%s: Acknowledge timed out.\n",dev->name);
885 ni_disint();
886 break;
890 if(debuglevel > 1)
891 printk("i");
892 return IRQ_HANDLED;
895 /*******************************************************
896 * receive-interrupt
899 static void ni52_rcv_int(struct net_device *dev)
901 int status,cnt=0;
902 unsigned short totlen;
903 struct sk_buff *skb;
904 struct rbd_struct *rbd;
905 struct priv *p = (struct priv *) dev->priv;
907 if(debuglevel > 0)
908 printk("R");
910 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
912 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
914 if(status & RFD_OK) /* frame received without error? */
916 if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */
918 totlen &= RBD_MASK; /* length of this frame */
919 rbd->status = 0;
920 skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
921 if(skb != NULL)
923 skb->dev = dev;
924 skb_reserve(skb,2);
925 skb_put(skb,totlen);
926 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0);
927 skb->protocol=eth_type_trans(skb,dev);
928 netif_rx(skb);
929 dev->last_rx = jiffies;
930 p->stats.rx_packets++;
931 p->stats.rx_bytes += totlen;
933 else
934 p->stats.rx_dropped++;
936 else
938 int rstat;
939 /* free all RBD's until RBD_LAST is set */
940 totlen = 0;
941 while(!((rstat=rbd->status) & RBD_LAST))
943 totlen += rstat & RBD_MASK;
944 if(!rstat)
946 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
947 break;
949 rbd->status = 0;
950 rbd = (struct rbd_struct *) make32(rbd->next);
952 totlen += rstat & RBD_MASK;
953 rbd->status = 0;
954 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
955 p->stats.rx_dropped++;
958 else /* frame !(ok), only with 'save-bad-frames' */
960 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
961 p->stats.rx_errors++;
963 p->rfd_top->stat_high = 0;
964 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
965 p->rfd_top->rbd_offset = 0xffff;
966 p->rfd_last->last = 0; /* delete RFD_SUSP */
967 p->rfd_last = p->rfd_top;
968 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
969 p->scb->rfa_offset = make16(p->rfd_top);
971 if(debuglevel > 0)
972 printk("%d",cnt++);
975 if(automatic_resume)
977 WAIT_4_SCB_CMD();
978 p->scb->cmd_ruc = RUC_RESUME;
979 ni_attn586();
980 WAIT_4_SCB_CMD_RUC();
983 #ifdef WAIT_4_BUSY
985 int i;
986 for(i=0;i<1024;i++)
988 if(p->rfd_top->status)
989 break;
990 DELAY_16();
991 if(i == 1023)
992 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
995 #endif
997 #if 0
998 if(!at_least_one)
1000 int i;
1001 volatile struct rfd_struct *rfds=p->rfd_top;
1002 volatile struct rbd_struct *rbds;
1003 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
1004 for(i=0;i< (p->num_recv_buffs+4);i++)
1006 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
1007 printk("%04x:%04x ",rfds->status,rbds->status);
1008 rfds = (struct rfd_struct *) make32(rfds->next);
1010 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
1011 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);
1013 old_at_least = at_least_one;
1014 #endif
1016 if(debuglevel > 0)
1017 printk("r");
1020 /**********************************************************
1021 * handle 'Receiver went not ready'.
1024 static void ni52_rnr_int(struct net_device *dev)
1026 struct priv *p = (struct priv *) dev->priv;
1028 p->stats.rx_errors++;
1030 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1031 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1032 ni_attn586();
1033 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */
1035 alloc_rfa(dev,(char *)p->rfd_first);
1036 /* maybe add a check here, before restarting the RU */
1037 startrecv586(dev); /* restart RU */
1039 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
1043 /**********************************************************
1044 * handle xmit - interrupt
1047 static void ni52_xmt_int(struct net_device *dev)
1049 int status;
1050 struct priv *p = (struct priv *) dev->priv;
1052 if(debuglevel > 0)
1053 printk("X");
1055 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1056 if(!(status & STAT_COMPL))
1057 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
1059 if(status & STAT_OK)
1061 p->stats.tx_packets++;
1062 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1064 else
1066 p->stats.tx_errors++;
1067 if(status & TCMD_LATECOLL) {
1068 printk("%s: late collision detected.\n",dev->name);
1069 p->stats.collisions++;
1071 else if(status & TCMD_NOCARRIER) {
1072 p->stats.tx_carrier_errors++;
1073 printk("%s: no carrier detected.\n",dev->name);
1075 else if(status & TCMD_LOSTCTS)
1076 printk("%s: loss of CTS detected.\n",dev->name);
1077 else if(status & TCMD_UNDERRUN) {
1078 p->stats.tx_fifo_errors++;
1079 printk("%s: DMA underrun detected.\n",dev->name);
1081 else if(status & TCMD_MAXCOLL) {
1082 printk("%s: Max. collisions exceeded.\n",dev->name);
1083 p->stats.collisions += 16;
1087 #if (NUM_XMIT_BUFFS > 1)
1088 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
1089 p->xmit_last = 0;
1090 #endif
1091 netif_wake_queue(dev);
1094 /***********************************************************
1095 * (re)start the receiver
1098 static void startrecv586(struct net_device *dev)
1100 struct priv *p = (struct priv *) dev->priv;
1102 WAIT_4_SCB_CMD();
1103 WAIT_4_SCB_CMD_RUC();
1104 p->scb->rfa_offset = make16(p->rfd_first);
1105 p->scb->cmd_ruc = RUC_START;
1106 ni_attn586(); /* start cmd. */
1107 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */
1110 static void ni52_timeout(struct net_device *dev)
1112 struct priv *p = (struct priv *) dev->priv;
1113 #ifndef NO_NOPCOMMANDS
1114 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
1116 netif_wake_queue(dev);
1117 #ifdef DEBUG
1118 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
1119 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);
1120 #endif
1121 p->scb->cmd_cuc = CUC_ABORT;
1122 ni_attn586();
1123 WAIT_4_SCB_CMD();
1124 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1125 p->scb->cmd_cuc = CUC_START;
1126 ni_attn586();
1127 WAIT_4_SCB_CMD();
1128 dev->trans_start = jiffies;
1129 return 0;
1131 #endif
1133 #ifdef DEBUG
1134 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
1135 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status);
1136 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
1137 #endif
1138 ni52_close(dev);
1139 ni52_open(dev);
1141 dev->trans_start = jiffies;
1144 /******************************************************
1145 * send frame
1148 static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1150 int len,i;
1151 #ifndef NO_NOPCOMMANDS
1152 int next_nop;
1153 #endif
1154 struct priv *p = (struct priv *) dev->priv;
1156 if(skb->len > XMIT_BUFF_SIZE)
1158 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1159 return 0;
1162 netif_stop_queue(dev);
1164 #if(NUM_XMIT_BUFFS > 1)
1165 if(test_and_set_bit(0,(void *) &p->lock)) {
1166 printk("%s: Queue was locked\n",dev->name);
1167 return 1;
1169 else
1170 #endif
1172 memcpy((char *)p->xmit_cbuffs[p->xmit_count],(char *)(skb->data),skb->len);
1173 len = skb->len;
1174 if (len < ETH_ZLEN) {
1175 len = ETH_ZLEN;
1176 memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0, len - skb->len);
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 unsigned long flags;
1244 save_flags(flags);
1245 cli();
1246 if(p->xmit_count != p->xmit_last)
1247 netif_wake_queue(dev);
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 ..
1287 static void set_multicast_list(struct net_device *dev)
1289 netif_stop_queue(dev);
1290 ni_disint();
1291 alloc586(dev);
1292 init586(dev);
1293 startrecv586(dev);
1294 ni_enaint();
1295 netif_wake_queue(dev);
1298 #ifdef MODULE
1299 static struct net_device dev_ni52;
1301 /* set: io,irq,memstart,memend or set it when calling insmod */
1302 static int irq=9;
1303 static int io=0x300;
1304 static long memstart; /* e.g 0xd0000 */
1305 static long memend; /* e.g 0xd4000 */
1307 MODULE_PARM(io, "i");
1308 MODULE_PARM(irq, "i");
1309 MODULE_PARM(memstart, "l");
1310 MODULE_PARM(memend, "l");
1311 MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
1312 MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1313 MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1314 MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1316 int init_module(void)
1318 if(io <= 0x0 || !memend || !memstart || irq < 2) {
1319 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1320 return -ENODEV;
1322 dev_ni52.init = ni52_probe;
1323 dev_ni52.irq = irq;
1324 dev_ni52.base_addr = io;
1325 dev_ni52.mem_end = memend;
1326 dev_ni52.mem_start = memstart;
1327 if (register_netdev(&dev_ni52) != 0)
1328 return -EIO;
1329 return 0;
1332 void cleanup_module(void)
1334 release_region(dev_ni52.base_addr, NI52_TOTAL_SIZE);
1335 unregister_netdev(&dev_ni52);
1336 kfree(dev_ni52.priv);
1337 dev_ni52.priv = NULL;
1339 #endif /* MODULE */
1341 #if 0
1343 * DUMP .. we expect a not running CMD unit and enough space
1345 void ni52_dump(struct net_device *dev,void *ptr)
1347 struct priv *p = (struct priv *) dev->priv;
1348 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1349 int i;
1351 p->scb->cmd_cuc = CUC_ABORT;
1352 ni_attn586();
1353 WAIT_4_SCB_CMD();
1354 WAIT_4_SCB_CMD_RUC();
1356 dump_cmd->cmd_status = 0;
1357 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1358 dump_cmd->dump_offset = make16((dump_cmd + 1));
1359 dump_cmd->cmd_link = 0xffff;
1361 p->scb->cbl_offset = make16(dump_cmd);
1362 p->scb->cmd_cuc = CUC_START;
1363 ni_attn586();
1364 WAIT_4_STAT_COMPL(dump_cmd);
1366 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1367 printk("%s: Can't get dump information.\n",dev->name);
1369 for(i=0;i<170;i++) {
1370 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1371 if(i % 24 == 23)
1372 printk("\n");
1374 printk("\n");
1376 #endif
1377 MODULE_LICENSE("GPL");
1380 * END: linux/drivers/net/ni52.c