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