]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - drivers/net/ni52.c
[netdrvr] Use dev_printk() when ethernet interface isn't available
[linux-2.6.git] / drivers / net / ni52.c
1 /*
2  * net-3-driver for the NI5210 card (i82586 Ethernet chip)
3  *
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.
6  *
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 ....]
10  *
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
16  *
17  * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
18  *
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
25  *
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
29  *
30  * sources:
31  *   skeleton.c from Donald Becker
32  *
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.)
38  *
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.
45  *
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.
50  *
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? )
60  *
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)
64  */
65
66 /*
67  * 29.Sept.96: virt_to_bus changes for new memory scheme
68  * 19.Feb.96: more Mcast changes, module support (MH)
69  *
70  * 18.Nov.95: Mcast changes (AC).
71  *
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)
77  *
78  * 19.Sep.94: Added Multicast support (not tested yet) (MH)
79  *
80  * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
81  *            Now, every RFD has exact one RBD. (MH)
82  *
83  * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
84  *
85  * 19.Aug.94: changed request_irq() parameter (MH)
86  *
87  * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
88  *
89  * 19.July.94: lotsa cleanups .. (MH)
90  *
91  * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
92  *
93  * 4.July.94: patches for Linux 1.1.24  (MH)
94  *
95  * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
96  *
97  * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, too (MH)
98  *
99  * < 30.Sep.93: first versions
100  */
101
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 */
106
107 /* #define REALLY_SLOW_IO */
108
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 <linux/bitops.h>
119 #include <asm/io.h>
120
121 #include <linux/netdevice.h>
122 #include <linux/etherdevice.h>
123 #include <linux/skbuff.h>
124
125 #include "ni52.h"
126
127 #define DRV_NAME "ni52"
128
129 #define DEBUG       /* debug on */
130 #define SYSBUSVAL 1 /* 8 Bit */
131
132 #define ni_attn586()  {outb(0,dev->base_addr+NI52_ATTENTION);}
133 #define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);}
134 #define ni_disint()   {outb(0,dev->base_addr+NI52_INTDIS);}
135 #define ni_enaint()   {outb(0,dev->base_addr+NI52_INTENA);}
136
137 #define make32(ptr16) (p->memtop + (short) (ptr16) )
138 #define make24(ptr32) ( ((char *) (ptr32)) - p->base)
139 #define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop ))
140
141 /******************* how to calculate the buffers *****************************
142
143   * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
144   * --------------- in a different (more stable?) mode. Only in this mode it's
145   *                 possible to configure the driver with 'NO_NOPCOMMANDS'
146
147 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
148 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
149 sizeof(rfd) = 24; sizeof(rbd) = 12;
150 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
151 sizeof(nop_cmd) = 8;
152
153   * if you don't know the driver, better do not change these values: */
154
155 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
156 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
157 #define NUM_XMIT_BUFFS 1    /* config for both, 8K and 16K shmem */
158 #define NUM_RECV_BUFFS_8  4 /* config for 8K shared mem */
159 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
160 #define NO_NOPCOMMANDS      /* only possible with NUM_XMIT_BUFFS=1 */
161
162 /**************************************************************************/
163
164 /* different DELAYs */
165 #define DELAY(x) mdelay(32 * x);
166 #define DELAY_16(); { udelay(16); }
167 #define DELAY_18(); { udelay(4); }
168
169 /* wait for command with timeout: */
170 #define WAIT_4_SCB_CMD() \
171 { int i; \
172   for(i=0;i<16384;i++) { \
173     if(!p->scb->cmd_cuc) break; \
174     DELAY_18(); \
175     if(i == 16383) { \
176       printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
177        if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
178
179 #define WAIT_4_SCB_CMD_RUC() { int i; \
180   for(i=0;i<16384;i++) { \
181     if(!p->scb->cmd_ruc) break; \
182     DELAY_18(); \
183     if(i == 16383) { \
184       printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
185        if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
186
187 #define WAIT_4_STAT_COMPL(addr) { int i; \
188    for(i=0;i<32767;i++) { \
189      if((addr)->cmd_status & STAT_COMPL) break; \
190      DELAY_16(); DELAY_16(); } }
191
192 #define NI52_TOTAL_SIZE 16
193 #define NI52_ADDR0 0x02
194 #define NI52_ADDR1 0x07
195 #define NI52_ADDR2 0x01
196
197 static int     ni52_probe1(struct net_device *dev,int ioaddr);
198 static irqreturn_t ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr);
199 static int     ni52_open(struct net_device *dev);
200 static int     ni52_close(struct net_device *dev);
201 static int     ni52_send_packet(struct sk_buff *,struct net_device *);
202 static struct  net_device_stats *ni52_get_stats(struct net_device *dev);
203 static void    set_multicast_list(struct net_device *dev);
204 static void    ni52_timeout(struct net_device *dev);
205 #if 0
206 static void    ni52_dump(struct net_device *,void *);
207 #endif
208
209 /* helper-functions */
210 static int     init586(struct net_device *dev);
211 static int     check586(struct net_device *dev,char *where,unsigned size);
212 static void    alloc586(struct net_device *dev);
213 static void    startrecv586(struct net_device *dev);
214 static void   *alloc_rfa(struct net_device *dev,void *ptr);
215 static void    ni52_rcv_int(struct net_device *dev);
216 static void    ni52_xmt_int(struct net_device *dev);
217 static void    ni52_rnr_int(struct net_device *dev);
218
219 struct priv
220 {
221         struct net_device_stats stats;
222         unsigned long base;
223         char *memtop;
224         long int lock;
225         int reseted;
226         volatile struct rfd_struct      *rfd_last,*rfd_top,*rfd_first;
227         volatile struct scp_struct      *scp;   /* volatile is important */
228         volatile struct iscp_struct     *iscp;  /* volatile is important */
229         volatile struct scb_struct      *scb;   /* volatile is important */
230         volatile struct tbd_struct      *xmit_buffs[NUM_XMIT_BUFFS];
231 #if (NUM_XMIT_BUFFS == 1)
232         volatile struct transmit_cmd_struct *xmit_cmds[2];
233         volatile struct nop_cmd_struct *nop_cmds[2];
234 #else
235         volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
236         volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
237 #endif
238         volatile int            nop_point,num_recv_buffs;
239         volatile char           *xmit_cbuffs[NUM_XMIT_BUFFS];
240         volatile int            xmit_count,xmit_last;
241 };
242
243 /**********************************************
244  * close device
245  */
246 static int ni52_close(struct net_device *dev)
247 {
248         free_irq(dev->irq, dev);
249
250         ni_reset586(); /* the hard way to stop the receiver */
251
252         netif_stop_queue(dev);
253
254         return 0;
255 }
256
257 /**********************************************
258  * open device
259  */
260 static int ni52_open(struct net_device *dev)
261 {
262         int ret;
263
264         ni_disint();
265         alloc586(dev);
266         init586(dev);
267         startrecv586(dev);
268         ni_enaint();
269
270         ret = request_irq(dev->irq, &ni52_interrupt,0,dev->name,dev);
271         if (ret)
272         {
273                 ni_reset586();
274                 return ret;
275         }
276
277         netif_start_queue(dev);
278
279         return 0; /* most done by init */
280 }
281
282 /**********************************************
283  * Check to see if there's an 82586 out there.
284  */
285 static int check586(struct net_device *dev,char *where,unsigned size)
286 {
287         struct priv pb;
288         struct priv *p = /* (struct priv *) dev->priv*/ &pb;
289         char *iscp_addrs[2];
290         int i;
291
292         p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
293         p->memtop = isa_bus_to_virt((unsigned long)where) + size;
294         p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
295         memset((char *)p->scp,0, sizeof(struct scp_struct));
296         for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
297                 if(((char *)p->scp)[i])
298                         return 0;
299         p->scp->sysbus = SYSBUSVAL;                             /* 1 = 8Bit-Bus, 0 = 16 Bit */
300         if(p->scp->sysbus != SYSBUSVAL)
301                 return 0;
302
303         iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
304         iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct);
305
306         for(i=0;i<2;i++)
307         {
308                 p->iscp = (struct iscp_struct *) iscp_addrs[i];
309                 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
310
311                 p->scp->iscp = make24(p->iscp);
312                 p->iscp->busy = 1;
313
314                 ni_reset586();
315                 ni_attn586();
316                 DELAY(1);       /* wait a while... */
317
318                 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
319                         return 0;
320         }
321         return 1;
322 }
323
324 /******************************************************************
325  * set iscp at the right place, called by ni52_probe1 and open586.
326  */
327 static void alloc586(struct net_device *dev)
328 {
329         struct priv *p =        (struct priv *) dev->priv;
330
331         ni_reset586();
332         DELAY(1);
333
334         p->scp  = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
335         p->scb  = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
336         p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct));
337
338         memset((char *) p->iscp,0,sizeof(struct iscp_struct));
339         memset((char *) p->scp ,0,sizeof(struct scp_struct));
340
341         p->scp->iscp = make24(p->iscp);
342         p->scp->sysbus = SYSBUSVAL;
343         p->iscp->scb_offset = make16(p->scb);
344
345         p->iscp->busy = 1;
346         ni_reset586();
347         ni_attn586();
348
349         DELAY(1);
350
351         if(p->iscp->busy)
352                 printk("%s: Init-Problems (alloc).\n",dev->name);
353
354         p->reseted = 0;
355
356         memset((char *)p->scb,0,sizeof(struct scb_struct));
357 }
358
359 /* set: io,irq,memstart,memend or set it when calling insmod */
360 static int irq=9;
361 static int io=0x300;
362 static long memstart;   /* e.g 0xd0000 */
363 static long memend;     /* e.g 0xd4000 */
364
365 /**********************************************
366  * probe the ni5210-card
367  */
368 struct net_device * __init ni52_probe(int unit)
369 {
370         struct net_device *dev = alloc_etherdev(sizeof(struct priv));
371         static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
372         int *port;
373         int err = 0;
374
375         if (!dev)
376                 return ERR_PTR(-ENOMEM);
377
378         if (unit >= 0) {
379                 sprintf(dev->name, "eth%d", unit);
380                 netdev_boot_setup_check(dev);
381                 io = dev->base_addr;
382                 irq = dev->irq;
383                 memstart = dev->mem_start;
384                 memend = dev->mem_end;
385         }
386
387         SET_MODULE_OWNER(dev);
388
389         if (io > 0x1ff) {       /* Check a single specified location. */
390                 err = ni52_probe1(dev, io);
391         } else if (io > 0) {            /* Don't probe at all. */
392                 err = -ENXIO;
393         } else {
394                 for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
395                         ;
396                 if (*port)
397                         goto got_it;
398 #ifdef FULL_IO_PROBE
399                 for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
400                         ;
401                 if (io < 0x400)
402                         goto got_it;
403 #endif
404                 err = -ENODEV;
405         }
406         if (err)
407                 goto out;
408 got_it:
409         err = register_netdev(dev);
410         if (err)
411                 goto out1;
412         return dev;
413 out1:
414         release_region(dev->base_addr, NI52_TOTAL_SIZE);
415 out:
416         free_netdev(dev);
417         return ERR_PTR(err);
418 }
419
420 static int __init ni52_probe1(struct net_device *dev,int ioaddr)
421 {
422         int i, size, retval;
423
424         dev->base_addr = ioaddr;
425         dev->irq = irq;
426         dev->mem_start = memstart;
427         dev->mem_end = memend;
428
429         if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
430                 return -EBUSY;
431
432         if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
433             !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
434                 retval = -ENODEV;
435                 goto out;
436         }
437
438         for(i=0;i<ETH_ALEN;i++)
439                 dev->dev_addr[i] = inb(dev->base_addr+i);
440
441         if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
442                  || dev->dev_addr[2] != NI52_ADDR2) {
443                 retval = -ENODEV;
444                 goto out;
445         }
446
447         printk(KERN_INFO "%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);
448
449         /*
450          * check (or search) IO-Memory, 8K and 16K
451          */
452 #ifdef MODULE
453         size = dev->mem_end - dev->mem_start;
454         if(size != 0x2000 && size != 0x4000) {
455                 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size);
456                 retval = -ENODEV;
457                 goto out;
458         }
459         if(!check586(dev,(char *) dev->mem_start,size)) {
460                 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
461                 retval = -ENODEV;
462                 goto out;
463         }
464 #else
465         if(dev->mem_start != 0) /* no auto-mem-probe */
466         {
467                 size = 0x4000; /* check for 16K mem */
468                 if(!check586(dev,(char *) dev->mem_start,size)) {
469                         size = 0x2000; /* check for 8K mem */
470                         if(!check586(dev,(char *) dev->mem_start,size)) {
471                                 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);
472                                 retval = -ENODEV;
473                                 goto out;
474                         }
475                 }
476         }
477         else
478         {
479                 static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000,
480                                         0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 };
481                 for(i=0;;i++)
482                 {
483                         if(!memaddrs[i]) {
484                                 printk("?memprobe, Can't find io-memory!\n");
485                                 retval = -ENODEV;
486                                 goto out;
487                         }
488                         dev->mem_start = memaddrs[i];
489                         size = 0x2000; /* check for 8K mem */
490                         if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */
491                                 break;
492                         size = 0x4000; /* check for 16K mem */
493                         if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */
494                                 break;
495                 }
496         }
497         dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
498 #endif
499
500         memset((char *) dev->priv,0,sizeof(struct priv));
501
502         ((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size;
503         ((struct priv *) (dev->priv))->base =   (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
504         alloc586(dev);
505
506         /* set number of receive-buffs according to memsize */
507         if(size == 0x2000)
508                 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
509         else
510                 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
511
512         printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size);
513
514         if(dev->irq < 2)
515         {
516                 unsigned long irq_mask;
517
518                 irq_mask = probe_irq_on();
519                 ni_reset586();
520                 ni_attn586();
521
522                 mdelay(20);
523                 dev->irq = probe_irq_off(irq_mask);
524                 if(!dev->irq)
525                 {
526                         printk("?autoirq, Failed to detect IRQ line!\n");
527                         retval = -EAGAIN;
528                         goto out;
529                 }
530                 printk("IRQ %d (autodetected).\n",dev->irq);
531         }
532         else    {
533                 if(dev->irq == 2)
534                         dev->irq = 9;
535                 printk("IRQ %d (assigned and not checked!).\n",dev->irq);
536         }
537
538         dev->open               = ni52_open;
539         dev->stop               = ni52_close;
540         dev->get_stats          = ni52_get_stats;
541         dev->tx_timeout         = ni52_timeout;
542         dev->watchdog_timeo     = HZ/20;
543         dev->hard_start_xmit    = ni52_send_packet;
544         dev->set_multicast_list = set_multicast_list;
545
546         dev->if_port            = 0;
547
548         return 0;
549 out:
550         release_region(ioaddr, NI52_TOTAL_SIZE);
551         return retval;
552 }
553
554 /**********************************************
555  * init the chip (ni52-interrupt should be disabled?!)
556  * needs a correct 'allocated' memory
557  */
558
559 static int init586(struct net_device *dev)
560 {
561         void *ptr;
562         int i,result=0;
563         struct priv *p = (struct priv *) dev->priv;
564         volatile struct configure_cmd_struct    *cfg_cmd;
565         volatile struct iasetup_cmd_struct *ias_cmd;
566         volatile struct tdr_cmd_struct *tdr_cmd;
567         volatile struct mcsetup_cmd_struct *mc_cmd;
568         struct dev_mc_list *dmi=dev->mc_list;
569         int num_addrs=dev->mc_count;
570
571         ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
572
573         cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
574         cfg_cmd->cmd_status     = 0;
575         cfg_cmd->cmd_cmd        = CMD_CONFIGURE | CMD_LAST;
576         cfg_cmd->cmd_link       = 0xffff;
577
578         cfg_cmd->byte_cnt       = 0x0a; /* number of cfg bytes */
579         cfg_cmd->fifo           = fifo; /* fifo-limit (8=tx:32/rx:64) */
580         cfg_cmd->sav_bf         = 0x40; /* hold or discard bad recv frames (bit 7) */
581         cfg_cmd->adr_len        = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
582         cfg_cmd->priority       = 0x00;
583         cfg_cmd->ifs            = 0x60;
584         cfg_cmd->time_low       = 0x00;
585         cfg_cmd->time_high      = 0xf2;
586         cfg_cmd->promisc        = 0;
587         if(dev->flags & IFF_ALLMULTI) {
588                 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
589                 if(num_addrs > len)     {
590                         printk("%s: switching to promisc. mode\n",dev->name);
591                         dev->flags|=IFF_PROMISC;
592                 }
593         }
594         if(dev->flags&IFF_PROMISC)
595         {
596                          cfg_cmd->promisc=1;
597                          dev->flags|=IFF_PROMISC;
598         }
599         cfg_cmd->carr_coll      = 0x00;
600
601         p->scb->cbl_offset      = make16(cfg_cmd);
602         p->scb->cmd_ruc         = 0;
603
604         p->scb->cmd_cuc         = CUC_START; /* cmd.-unit start */
605         ni_attn586();
606
607         WAIT_4_STAT_COMPL(cfg_cmd);
608
609         if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
610         {
611                 printk("%s: configure command failed: %x\n",dev->name,cfg_cmd->cmd_status);
612                 return 1;
613         }
614
615         /*
616          * individual address setup
617          */
618
619         ias_cmd = (struct iasetup_cmd_struct *)ptr;
620
621         ias_cmd->cmd_status     = 0;
622         ias_cmd->cmd_cmd        = CMD_IASETUP | CMD_LAST;
623         ias_cmd->cmd_link       = 0xffff;
624
625         memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
626
627         p->scb->cbl_offset = make16(ias_cmd);
628
629         p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
630         ni_attn586();
631
632         WAIT_4_STAT_COMPL(ias_cmd);
633
634         if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
635                 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status);
636                 return 1;
637         }
638
639         /*
640          * TDR, wire check .. e.g. no resistor e.t.c
641          */
642          
643         tdr_cmd = (struct tdr_cmd_struct *)ptr;
644
645         tdr_cmd->cmd_status     = 0;
646         tdr_cmd->cmd_cmd        = CMD_TDR | CMD_LAST;
647         tdr_cmd->cmd_link       = 0xffff;
648         tdr_cmd->status         = 0;
649
650         p->scb->cbl_offset = make16(tdr_cmd);
651         p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
652         ni_attn586();
653
654         WAIT_4_STAT_COMPL(tdr_cmd);
655
656         if(!(tdr_cmd->cmd_status & STAT_COMPL))
657         {
658                 printk("%s: Problems while running the TDR.\n",dev->name);
659         }
660         else
661         {
662                 DELAY_16(); /* wait for result */
663                 result = tdr_cmd->status;
664
665                 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
666                 ni_attn586(); /* ack the interrupts */
667
668                 if(result & TDR_LNK_OK)
669                         ;
670                 else if(result & TDR_XCVR_PRB)
671                         printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
672                 else if(result & TDR_ET_OPN)
673                         printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
674                 else if(result & TDR_ET_SRT)
675                 {
676                         if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
677                                 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
678                 }
679                 else
680                         printk("%s: TDR: Unknown status %04x\n",dev->name,result);
681         }
682
683         /*
684          * Multicast setup
685          */
686         if(num_addrs && !(dev->flags & IFF_PROMISC) )
687         {
688                 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
689                 mc_cmd->cmd_status = 0;
690                 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
691                 mc_cmd->cmd_link = 0xffff;
692                 mc_cmd->mc_cnt = num_addrs * 6;
693
694                 for(i=0;i<num_addrs;i++,dmi=dmi->next)
695                         memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6);
696
697                 p->scb->cbl_offset = make16(mc_cmd);
698                 p->scb->cmd_cuc = CUC_START;
699                 ni_attn586();
700
701                 WAIT_4_STAT_COMPL(mc_cmd);
702
703                 if( (mc_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
704                         printk("%s: Can't apply multicast-address-list.\n",dev->name);
705         }
706
707         /*
708          * alloc nop/xmit-cmds
709          */
710 #if (NUM_XMIT_BUFFS == 1)
711         for(i=0;i<2;i++)
712         {
713                 p->nop_cmds[i]                  = (struct nop_cmd_struct *)ptr;
714                 p->nop_cmds[i]->cmd_cmd         = CMD_NOP;
715                 p->nop_cmds[i]->cmd_status      = 0;
716                 p->nop_cmds[i]->cmd_link        = make16((p->nop_cmds[i]));
717                 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
718         }
719 #else
720         for(i=0;i<NUM_XMIT_BUFFS;i++)
721         {
722                 p->nop_cmds[i]                  = (struct nop_cmd_struct *)ptr;
723                 p->nop_cmds[i]->cmd_cmd         = CMD_NOP;
724                 p->nop_cmds[i]->cmd_status      = 0;
725                 p->nop_cmds[i]->cmd_link        = make16((p->nop_cmds[i]));
726                 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
727         }
728 #endif
729
730         ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
731
732         /*
733          * alloc xmit-buffs / init xmit_cmds
734          */
735         for(i=0;i<NUM_XMIT_BUFFS;i++)
736         {
737                 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
738                 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
739                 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
740                 ptr = (char *) ptr + XMIT_BUFF_SIZE;
741                 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
742                 ptr = (char *) ptr + sizeof(struct tbd_struct);
743                 if((void *)ptr > (void *)p->iscp)
744                 {
745                         printk("%s: not enough shared-mem for your configuration!\n",dev->name);
746                         return 1;
747                 }
748                 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
749                 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
750                 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
751                 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
752                 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
753                 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
754                 p->xmit_buffs[i]->next = 0xffff;
755                 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
756         }
757
758         p->xmit_count = 0;
759         p->xmit_last    = 0;
760 #ifndef NO_NOPCOMMANDS
761         p->nop_point    = 0;
762 #endif
763
764          /*
765                 * 'start transmitter'
766                 */
767 #ifndef NO_NOPCOMMANDS
768         p->scb->cbl_offset = make16(p->nop_cmds[0]);
769         p->scb->cmd_cuc = CUC_START;
770         ni_attn586();
771         WAIT_4_SCB_CMD();
772 #else
773         p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
774         p->xmit_cmds[0]->cmd_cmd        = CMD_XMIT | CMD_SUSPEND | CMD_INT;
775 #endif
776
777         /*
778          * ack. interrupts
779          */
780         p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
781         ni_attn586();
782         DELAY_16();
783
784         ni_enaint();
785
786         return 0;
787 }
788
789 /******************************************************
790  * This is a helper routine for ni52_rnr_int() and init586().
791  * It sets up the Receive Frame Area (RFA).
792  */
793
794 static void *alloc_rfa(struct net_device *dev,void *ptr)
795 {
796         volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
797         volatile struct rbd_struct *rbd;
798         int i;
799         struct priv *p = (struct priv *) dev->priv;
800
801         memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
802         p->rfd_first = rfd;
803
804         for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
805                 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
806                 rfd[i].rbd_offset = 0xffff;
807         }
808         rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP;         /* RU suspend */
809
810         ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
811
812         rbd = (struct rbd_struct *) ptr;
813         ptr = (void *) (rbd + p->num_recv_buffs);
814
815          /* clr descriptors */
816         memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
817
818         for(i=0;i<p->num_recv_buffs;i++)
819         {
820                 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
821                 rbd[i].size = RECV_BUFF_SIZE;
822                 rbd[i].buffer = make24(ptr);
823                 ptr = (char *) ptr + RECV_BUFF_SIZE;
824         }
825
826         p->rfd_top      = p->rfd_first;
827         p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
828
829         p->scb->rfa_offset              = make16(p->rfd_first);
830         p->rfd_first->rbd_offset        = make16(rbd);
831
832         return ptr;
833 }
834
835
836 /**************************************************
837  * Interrupt Handler ...
838  */
839
840 static irqreturn_t ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr)
841 {
842         struct net_device *dev = dev_id;
843         unsigned short stat;
844         int cnt=0;
845         struct priv *p;
846
847         if (!dev) {
848                 printk ("ni5210-interrupt: irq %d for unknown device.\n",irq);
849                 return IRQ_NONE;
850         }
851         p = (struct priv *) dev->priv;
852
853         if(debuglevel > 1)
854                 printk("I");
855
856         WAIT_4_SCB_CMD(); /* wait for last command      */
857
858         while((stat=p->scb->cus & STAT_MASK))
859         {
860                 p->scb->cmd_cuc = stat;
861                 ni_attn586();
862
863                 if(stat & STAT_FR)       /* received a frame */
864                         ni52_rcv_int(dev);
865
866                 if(stat & STAT_RNR) /* RU went 'not ready' */
867                 {
868                         printk("(R)");
869                         if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
870                         {
871                                 WAIT_4_SCB_CMD();
872                                 p->scb->cmd_ruc = RUC_RESUME;
873                                 ni_attn586();
874                                 WAIT_4_SCB_CMD_RUC();
875                         }
876                         else
877                         {
878                                 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
879                                 ni52_rnr_int(dev);
880                         }
881                 }
882
883                 if(stat & STAT_CX)              /* command with I-bit set complete */
884                          ni52_xmt_int(dev);
885
886 #ifndef NO_NOPCOMMANDS
887                 if(stat & STAT_CNA)     /* CU went 'not ready' */
888                 {
889                         if(netif_running(dev))
890                                 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
891                 }
892 #endif
893
894                 if(debuglevel > 1)
895                         printk("%d",cnt++);
896
897                 WAIT_4_SCB_CMD(); /* wait for ack. (ni52_xmt_int can be faster than ack!!) */
898                 if(p->scb->cmd_cuc)      /* timed out? */
899                 {
900                         printk("%s: Acknowledge timed out.\n",dev->name);
901                         ni_disint();
902                         break;
903                 }
904         }
905
906         if(debuglevel > 1)
907                 printk("i");
908         return IRQ_HANDLED;
909 }
910
911 /*******************************************************
912  * receive-interrupt
913  */
914
915 static void ni52_rcv_int(struct net_device *dev)
916 {
917         int status,cnt=0;
918         unsigned short totlen;
919         struct sk_buff *skb;
920         struct rbd_struct *rbd;
921         struct priv *p = (struct priv *) dev->priv;
922
923         if(debuglevel > 0)
924                 printk("R");
925
926         for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
927         {
928                         rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
929
930                         if(status & RFD_OK) /* frame received without error? */
931                         {
932                                 if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */
933                                 {
934                                         totlen &= RBD_MASK; /* length of this frame */
935                                         rbd->status = 0;
936                                         skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
937                                         if(skb != NULL)
938                                         {
939                                                 skb->dev = dev;
940                                                 skb_reserve(skb,2);
941                                                 skb_put(skb,totlen);
942                                                 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0);
943                                                 skb->protocol=eth_type_trans(skb,dev);
944                                                 netif_rx(skb);
945                                                 dev->last_rx = jiffies;
946                                                 p->stats.rx_packets++;
947                                                 p->stats.rx_bytes += totlen;
948                                         }
949                                         else
950                                                 p->stats.rx_dropped++;
951                                 }
952                                 else
953                                 {
954                                         int rstat;
955                                                  /* free all RBD's until RBD_LAST is set */
956                                         totlen = 0;
957                                         while(!((rstat=rbd->status) & RBD_LAST))
958                                         {
959                                                 totlen += rstat & RBD_MASK;
960                                                 if(!rstat)
961                                                 {
962                                                         printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
963                                                         break;
964                                                 }
965                                                 rbd->status = 0;
966                                                 rbd = (struct rbd_struct *) make32(rbd->next);
967                                         }
968                                         totlen += rstat & RBD_MASK;
969                                         rbd->status = 0;
970                                         printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
971                                         p->stats.rx_dropped++;
972                          }
973                 }
974                 else /* frame !(ok), only with 'save-bad-frames' */
975                 {
976                         printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
977                         p->stats.rx_errors++;
978                 }
979                 p->rfd_top->stat_high = 0;
980                 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
981                 p->rfd_top->rbd_offset = 0xffff;
982                 p->rfd_last->last = 0;                          /* delete RFD_SUSP      */
983                 p->rfd_last = p->rfd_top;
984                 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
985                 p->scb->rfa_offset = make16(p->rfd_top);
986
987                 if(debuglevel > 0)
988                         printk("%d",cnt++);
989         }
990
991         if(automatic_resume)
992         {
993                 WAIT_4_SCB_CMD();
994                 p->scb->cmd_ruc = RUC_RESUME;
995                 ni_attn586();
996                 WAIT_4_SCB_CMD_RUC();
997         }
998
999 #ifdef WAIT_4_BUSY
1000         {
1001                 int i;
1002                 for(i=0;i<1024;i++)
1003                 {
1004                         if(p->rfd_top->status)
1005                                 break;
1006                         DELAY_16();
1007                         if(i == 1023)
1008                                 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
1009                 }
1010         }
1011 #endif
1012
1013 #if 0
1014         if(!at_least_one)
1015         {
1016                 int i;
1017                 volatile struct rfd_struct *rfds=p->rfd_top;
1018                 volatile struct rbd_struct *rbds;
1019                 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
1020                 for(i=0;i< (p->num_recv_buffs+4);i++)
1021                 {
1022                         rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
1023                         printk("%04x:%04x ",rfds->status,rbds->status);
1024                         rfds = (struct rfd_struct *) make32(rfds->next);
1025                 }
1026                 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
1027                 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);
1028         }
1029         old_at_least = at_least_one;
1030 #endif
1031
1032         if(debuglevel > 0)
1033                 printk("r");
1034 }
1035
1036 /**********************************************************
1037  * handle 'Receiver went not ready'.
1038  */
1039
1040 static void ni52_rnr_int(struct net_device *dev)
1041 {
1042         struct priv *p = (struct priv *) dev->priv;
1043
1044         p->stats.rx_errors++;
1045
1046         WAIT_4_SCB_CMD();               /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1047         p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1048         ni_attn586();
1049         WAIT_4_SCB_CMD_RUC();           /* wait for accept cmd. */
1050
1051         alloc_rfa(dev,(char *)p->rfd_first);
1052 /* maybe add a check here, before restarting the RU */
1053         startrecv586(dev); /* restart RU */
1054
1055         printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
1056
1057 }
1058
1059 /**********************************************************
1060  * handle xmit - interrupt
1061  */
1062
1063 static void ni52_xmt_int(struct net_device *dev)
1064 {
1065         int status;
1066         struct priv *p = (struct priv *) dev->priv;
1067
1068         if(debuglevel > 0)
1069                 printk("X");
1070
1071         status = p->xmit_cmds[p->xmit_last]->cmd_status;
1072         if(!(status & STAT_COMPL))
1073                 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
1074
1075         if(status & STAT_OK)
1076         {
1077                 p->stats.tx_packets++;
1078                 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1079         }
1080         else
1081         {
1082                 p->stats.tx_errors++;
1083                 if(status & TCMD_LATECOLL) {
1084                         printk("%s: late collision detected.\n",dev->name);
1085                         p->stats.collisions++;
1086                 }
1087                 else if(status & TCMD_NOCARRIER) {
1088                         p->stats.tx_carrier_errors++;
1089                         printk("%s: no carrier detected.\n",dev->name);
1090                 }
1091                 else if(status & TCMD_LOSTCTS)
1092                         printk("%s: loss of CTS detected.\n",dev->name);
1093                 else if(status & TCMD_UNDERRUN) {
1094                         p->stats.tx_fifo_errors++;
1095                         printk("%s: DMA underrun detected.\n",dev->name);
1096                 }
1097                 else if(status & TCMD_MAXCOLL) {
1098                         printk("%s: Max. collisions exceeded.\n",dev->name);
1099                         p->stats.collisions += 16;
1100                 }
1101         }
1102
1103 #if (NUM_XMIT_BUFFS > 1)
1104         if( (++p->xmit_last) == NUM_XMIT_BUFFS)
1105                 p->xmit_last = 0;
1106 #endif
1107         netif_wake_queue(dev);
1108 }
1109
1110 /***********************************************************
1111  * (re)start the receiver
1112  */
1113
1114 static void startrecv586(struct net_device *dev)
1115 {
1116         struct priv *p = (struct priv *) dev->priv;
1117
1118         WAIT_4_SCB_CMD();
1119         WAIT_4_SCB_CMD_RUC();
1120         p->scb->rfa_offset = make16(p->rfd_first);
1121         p->scb->cmd_ruc = RUC_START;
1122         ni_attn586();           /* start cmd. */
1123         WAIT_4_SCB_CMD_RUC();   /* wait for accept cmd. (no timeout!!) */
1124 }
1125
1126 static void ni52_timeout(struct net_device *dev)
1127 {
1128         struct priv *p = (struct priv *) dev->priv;
1129 #ifndef NO_NOPCOMMANDS
1130         if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
1131         {
1132                 netif_wake_queue(dev);
1133 #ifdef DEBUG
1134                 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
1135                 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);
1136 #endif
1137                 p->scb->cmd_cuc = CUC_ABORT;
1138                 ni_attn586();
1139                 WAIT_4_SCB_CMD();
1140                 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1141                 p->scb->cmd_cuc = CUC_START;
1142                 ni_attn586();
1143                 WAIT_4_SCB_CMD();
1144                 dev->trans_start = jiffies;
1145                 return 0;
1146         }
1147 #endif
1148         {
1149 #ifdef DEBUG
1150                 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
1151                 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status);
1152                 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
1153 #endif
1154                 ni52_close(dev);
1155                 ni52_open(dev);
1156         }
1157         dev->trans_start = jiffies;
1158 }
1159
1160 /******************************************************
1161  * send frame
1162  */
1163
1164 static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1165 {
1166         int len,i;
1167 #ifndef NO_NOPCOMMANDS
1168         int next_nop;
1169 #endif
1170         struct priv *p = (struct priv *) dev->priv;
1171
1172         if(skb->len > XMIT_BUFF_SIZE)
1173         {
1174                 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1175                 return 0;
1176         }
1177
1178         netif_stop_queue(dev);
1179
1180 #if(NUM_XMIT_BUFFS > 1)
1181         if(test_and_set_bit(0,(void *) &p->lock)) {
1182                 printk("%s: Queue was locked\n",dev->name);
1183                 return 1;
1184         }
1185         else
1186 #endif
1187         {
1188                 memcpy((char *)p->xmit_cbuffs[p->xmit_count],(char *)(skb->data),skb->len);
1189                 len = skb->len;
1190                 if (len < ETH_ZLEN) {
1191                         len = ETH_ZLEN;
1192                         memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0, len - skb->len);
1193                 }
1194
1195 #if (NUM_XMIT_BUFFS == 1)
1196 #       ifdef NO_NOPCOMMANDS
1197
1198 #ifdef DEBUG
1199                 if(p->scb->cus & CU_ACTIVE)
1200                 {
1201                         printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
1202                         printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,p->xmit_cmds[0]->cmd_status);
1203                 }
1204 #endif
1205
1206                 p->xmit_buffs[0]->size = TBD_LAST | len;
1207                 for(i=0;i<16;i++)
1208                 {
1209                         p->xmit_cmds[0]->cmd_status = 0;
1210                         WAIT_4_SCB_CMD();
1211                         if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
1212                                 p->scb->cmd_cuc = CUC_RESUME;
1213                         else
1214                         {
1215                                 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1216                                 p->scb->cmd_cuc = CUC_START;
1217                         }
1218
1219                         ni_attn586();
1220                         dev->trans_start = jiffies;
1221                         if(!i)
1222                                 dev_kfree_skb(skb);
1223                         WAIT_4_SCB_CMD();
1224                         if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1225                                 break;
1226                         if(p->xmit_cmds[0]->cmd_status)
1227                                 break;
1228                         if(i==15)
1229                                 printk("%s: Can't start transmit-command.\n",dev->name);
1230                 }
1231 #       else
1232                 next_nop = (p->nop_point + 1) & 0x1;
1233                 p->xmit_buffs[0]->size = TBD_LAST | len;
1234
1235                 p->xmit_cmds[0]->cmd_link        = p->nop_cmds[next_nop]->cmd_link
1236                                                                                                                                 = make16((p->nop_cmds[next_nop]));
1237                 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1238
1239                 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1240                 dev->trans_start = jiffies;
1241                 p->nop_point = next_nop;
1242                 dev_kfree_skb(skb);
1243 #       endif
1244 #else
1245                 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1246                 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1247                         next_nop = 0;
1248
1249                 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1250                 /* linkpointer of xmit-command already points to next nop cmd */
1251                 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
1252                 p->nop_cmds[next_nop]->cmd_status = 0;
1253
1254                 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1255                 dev->trans_start = jiffies;
1256                 p->xmit_count = next_nop;
1257
1258                 {
1259                         unsigned long flags;
1260                         save_flags(flags);
1261                         cli();
1262                         if(p->xmit_count != p->xmit_last)
1263                                 netif_wake_queue(dev);
1264                         p->lock = 0;
1265                         restore_flags(flags);
1266                 }
1267                 dev_kfree_skb(skb);
1268 #endif
1269         }
1270         return 0;
1271 }
1272
1273 /*******************************************
1274  * Someone wanna have the statistics
1275  */
1276
1277 static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1278 {
1279         struct priv *p = (struct priv *) dev->priv;
1280         unsigned short crc,aln,rsc,ovrn;
1281
1282         crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1283         p->scb->crc_errs = 0;
1284         aln = p->scb->aln_errs;
1285         p->scb->aln_errs = 0;
1286         rsc = p->scb->rsc_errs;
1287         p->scb->rsc_errs = 0;
1288         ovrn = p->scb->ovrn_errs;
1289         p->scb->ovrn_errs = 0;
1290
1291         p->stats.rx_crc_errors += crc;
1292         p->stats.rx_fifo_errors += ovrn;
1293         p->stats.rx_frame_errors += aln;
1294         p->stats.rx_dropped += rsc;
1295
1296         return &p->stats;
1297 }
1298
1299 /********************************************************
1300  * Set MC list ..
1301  */
1302
1303 static void set_multicast_list(struct net_device *dev)
1304 {
1305         netif_stop_queue(dev);
1306         ni_disint();
1307         alloc586(dev);
1308         init586(dev);
1309         startrecv586(dev);
1310         ni_enaint();
1311         netif_wake_queue(dev);
1312 }
1313
1314 #ifdef MODULE
1315 static struct net_device *dev_ni52;
1316
1317 module_param(io, int, 0);
1318 module_param(irq, int, 0);
1319 module_param(memstart, long, 0);
1320 module_param(memend, long, 0);
1321 MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
1322 MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1323 MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1324 MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1325
1326 int init_module(void)
1327 {
1328         if(io <= 0x0 || !memend || !memstart || irq < 2) {
1329                 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1330                 return -ENODEV;
1331         }
1332         dev_ni52 = ni52_probe(-1);
1333         if (IS_ERR(dev_ni52))
1334                 return PTR_ERR(dev_ni52);
1335         return 0;
1336 }
1337
1338 void cleanup_module(void)
1339 {
1340         unregister_netdev(dev_ni52);
1341         release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
1342         free_netdev(dev_ni52);
1343 }
1344 #endif /* MODULE */
1345
1346 #if 0
1347 /*
1348  * DUMP .. we expect a not running CMD unit and enough space
1349  */
1350 void ni52_dump(struct net_device *dev,void *ptr)
1351 {
1352         struct priv *p = (struct priv *) dev->priv;
1353         struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1354         int i;
1355
1356         p->scb->cmd_cuc = CUC_ABORT;
1357         ni_attn586();
1358         WAIT_4_SCB_CMD();
1359         WAIT_4_SCB_CMD_RUC();
1360
1361         dump_cmd->cmd_status = 0;
1362         dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1363         dump_cmd->dump_offset = make16((dump_cmd + 1));
1364         dump_cmd->cmd_link = 0xffff;
1365
1366         p->scb->cbl_offset = make16(dump_cmd);
1367         p->scb->cmd_cuc = CUC_START;
1368         ni_attn586();
1369         WAIT_4_STAT_COMPL(dump_cmd);
1370
1371         if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1372                                 printk("%s: Can't get dump information.\n",dev->name);
1373
1374         for(i=0;i<170;i++) {
1375                 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1376                 if(i % 24 == 23)
1377                         printk("\n");
1378         }
1379         printk("\n");
1380 }
1381 #endif
1382 MODULE_LICENSE("GPL");
1383
1384 /*
1385  * END: linux/drivers/net/ni52.c
1386  */