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