blob: fa611f6a856374dc38108cce9546237b8dabf76b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Alan Coxa197f692008-02-08 15:27:38 +000036 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
37 * helped me a lot to understand this tricky chip.)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 *
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.
Alan Coxa197f692008-02-08 15:27:38 +000042 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 *
46 * IMPORTANT NOTE:
47 * On fast networks, it's a (very) good idea to have 16K shared memory. With
Alan Coxa197f692008-02-08 15:27:38 +000048 * 8K, we can store only 4 receive frames, so it can (easily) happen that a
49 * remote machine 'overruns' our system.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 *
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)
Alan Coxa197f692008-02-08 15:27:38 +000063 * sending in NOP-mode: peak performance up to 530K/s (but better don't
64 * run this mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
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 *
Alan Coxa197f692008-02-08 15:27:38 +000098 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
99 * too (MH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * < 30.Sep.93: first versions
102 */
103
104static int debuglevel; /* debug-printk 0: off 1: a few 2: more */
105static int automatic_resume; /* experimental .. better should be zero */
106static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */
Alan Coxa197f692008-02-08 15:27:38 +0000107static int fifo = 0x8; /* don't change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#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
Alan Coxa197f692008-02-08 15:27:38 +0000132#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); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Alan Coxa197f692008-02-08 15:27:38 +0000137#define make32(ptr16) (p->memtop + (short) (ptr16))
Al Viroe06ee2b2008-03-19 09:43:59 +0000138#define make24(ptr32) ((char __iomem *)(ptr32)) - p->base
139#define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
140 - p->memtop))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
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
148sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
149sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
150sizeof(rfd) = 24; sizeof(rbd) = 12;
151sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
152sizeof(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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166#define NI52_TOTAL_SIZE 16
167#define NI52_ADDR0 0x02
168#define NI52_ADDR1 0x07
169#define NI52_ADDR2 0x01
170
Alan Coxa197f692008-02-08 15:27:38 +0000171static int ni52_probe1(struct net_device *dev, int ioaddr);
172static irqreturn_t ni52_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static int ni52_open(struct net_device *dev);
174static int ni52_close(struct net_device *dev);
Alan Coxa197f692008-02-08 15:27:38 +0000175static int ni52_send_packet(struct sk_buff *, struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static struct net_device_stats *ni52_get_stats(struct net_device *dev);
177static void set_multicast_list(struct net_device *dev);
178static void ni52_timeout(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180/* helper-functions */
181static int init586(struct net_device *dev);
Al Virode597142008-03-19 09:43:49 +0000182static int check586(struct net_device *dev, unsigned size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static void alloc586(struct net_device *dev);
184static void startrecv586(struct net_device *dev);
Al Viro2d76c262008-03-19 09:43:29 +0000185static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static void ni52_rcv_int(struct net_device *dev);
187static void ni52_xmt_int(struct net_device *dev);
188static void ni52_rnr_int(struct net_device *dev);
189
Alan Coxa197f692008-02-08 15:27:38 +0000190struct priv {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 struct net_device_stats stats;
Al Viroe06ee2b2008-03-19 09:43:59 +0000192 char __iomem *base;
193 char __iomem *mapped;
Al Viro2d76c262008-03-19 09:43:29 +0000194 char __iomem *memtop;
Alan Coxa197f692008-02-08 15:27:38 +0000195 spinlock_t spinlock;
196 int reset;
Al Viro2d76c262008-03-19 09:43:29 +0000197 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];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#if (NUM_XMIT_BUFFS == 1)
Al Viro2d76c262008-03-19 09:43:29 +0000203 struct transmit_cmd_struct __iomem *xmit_cmds[2];
204 struct nop_cmd_struct __iomem *nop_cmds[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#else
Al Viro2d76c262008-03-19 09:43:29 +0000206 struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS];
207 struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#endif
Alan Coxa197f692008-02-08 15:27:38 +0000209 int nop_point, num_recv_buffs;
Al Viro2d76c262008-03-19 09:43:29 +0000210 char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS];
Alan Coxa197f692008-02-08 15:27:38 +0000211 int xmit_count, xmit_last;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212};
213
Alan Coxa197f692008-02-08 15:27:38 +0000214/* wait for command with timeout: */
215static 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
234static 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
Al Viro2d76c262008-03-19 09:43:29 +0000253static void wait_for_stat_compl(void __iomem *p)
Alan Coxa197f692008-02-08 15:27:38 +0000254{
Al Viro2d76c262008-03-19 09:43:29 +0000255 struct nop_cmd_struct __iomem *addr = p;
Alan Coxa197f692008-02-08 15:27:38 +0000256 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/**********************************************
265 * close device
266 */
267static int ni52_close(struct net_device *dev)
268{
269 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 ni_reset586(); /* the hard way to stop the receiver */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return 0;
273}
274
275/**********************************************
276 * open device
277 */
278static 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
Alan Coxa197f692008-02-08 15:27:38 +0000288 ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev);
289 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 ni_reset586();
291 return ret;
292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 return 0; /* most done by init */
295}
296
Al Viro76af5692008-03-19 09:44:19 +0000297static int check_iscp(struct net_device *dev, void __iomem *addr)
298{
299 struct iscp_struct __iomem *iscp = addr;
300 struct priv *p = dev->priv;
301 memset_io(iscp, 0, sizeof(struct iscp_struct));
302
303 writel(make24(iscp), &p->scp->iscp);
304 writeb(1, &iscp->busy);
305
306 ni_reset586();
307 ni_attn586();
308 mdelay(32); /* wait a while... */
309 /* i82586 clears 'busy' after successful init */
310 if (readb(&iscp->busy))
311 return 0;
312 return 1;
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/**********************************************
316 * Check to see if there's an 82586 out there.
317 */
Al Virode597142008-03-19 09:43:49 +0000318static int check586(struct net_device *dev, unsigned size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Al Viro7f8cfd52008-03-19 09:44:09 +0000320 struct priv *p = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 int i;
322
Al Viro76af5692008-03-19 09:44:19 +0000323 p->mapped = (char __iomem *)isa_bus_to_virt(dev->mem_start);
Al Viroe06ee2b2008-03-19 09:43:59 +0000324 p->base = p->mapped + size - 0x01000000;
325 p->memtop = p->mapped + size;
Al Viro2d76c262008-03-19 09:43:29 +0000326 p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
Al Viro7f8cfd52008-03-19 09:44:09 +0000327 p->scb = (struct scb_struct __iomem *) p->mapped;
Al Viro76af5692008-03-19 09:44:19 +0000328 p->iscp = (struct iscp_struct __iomem *)p->scp - 1;
Al Viro2d76c262008-03-19 09:43:29 +0000329 memset_io(p->scp, 0, sizeof(struct scp_struct));
Alan Coxa197f692008-02-08 15:27:38 +0000330 for (i = 0; i < sizeof(struct scp_struct); i++)
331 /* memory was writeable? */
Al Viro2d76c262008-03-19 09:43:29 +0000332 if (readb((char __iomem *)p->scp + i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return 0;
Alan Coxa197f692008-02-08 15:27:38 +0000334 writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
335 if (readb(&p->scp->sysbus) != SYSBUSVAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return 0;
337
Al Viro76af5692008-03-19 09:44:19 +0000338 if (!check_iscp(dev, p->mapped))
339 return 0;
340 if (!check_iscp(dev, p->iscp))
341 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return 1;
343}
344
345/******************************************************************
346 * set iscp at the right place, called by ni52_probe1 and open586.
347 */
348static void alloc586(struct net_device *dev)
349{
350 struct priv *p = (struct priv *) dev->priv;
351
352 ni_reset586();
Alan Coxa197f692008-02-08 15:27:38 +0000353 mdelay(32);
354
Alan Coxa197f692008-02-08 15:27:38 +0000355 memset_io(p->iscp, 0, sizeof(struct iscp_struct));
356 memset_io(p->scp , 0, sizeof(struct scp_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Alan Coxa197f692008-02-08 15:27:38 +0000358 writel(make24(p->iscp), &p->scp->iscp);
359 writeb(SYSBUSVAL, &p->scp->sysbus);
360 writew(make16(p->scb), &p->iscp->scb_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Alan Coxa197f692008-02-08 15:27:38 +0000362 writeb(1, &p->iscp->busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 ni_reset586();
364 ni_attn586();
365
Alan Coxa197f692008-02-08 15:27:38 +0000366 mdelay(32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Alan Coxa197f692008-02-08 15:27:38 +0000368 if (readb(&p->iscp->busy))
369 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Alan Coxa197f692008-02-08 15:27:38 +0000371 p->reset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Al Viro2d76c262008-03-19 09:43:29 +0000373 memset_io(p->scb, 0, sizeof(struct scb_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
376/* set: io,irq,memstart,memend or set it when calling insmod */
Alan Coxa197f692008-02-08 15:27:38 +0000377static int irq = 9;
378static int io = 0x300;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379static long memstart; /* e.g 0xd0000 */
380static long memend; /* e.g 0xd4000 */
381
382/**********************************************
383 * probe the ni5210-card
384 */
385struct net_device * __init ni52_probe(int unit)
386{
387 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
388 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
389 int *port;
390 int err = 0;
391
392 if (!dev)
393 return ERR_PTR(-ENOMEM);
394
395 if (unit >= 0) {
396 sprintf(dev->name, "eth%d", unit);
397 netdev_boot_setup_check(dev);
398 io = dev->base_addr;
399 irq = dev->irq;
400 memstart = dev->mem_start;
401 memend = dev->mem_end;
402 }
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (io > 0x1ff) { /* Check a single specified location. */
405 err = ni52_probe1(dev, io);
406 } else if (io > 0) { /* Don't probe at all. */
407 err = -ENXIO;
408 } else {
409 for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
410 ;
411 if (*port)
412 goto got_it;
413#ifdef FULL_IO_PROBE
414 for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
415 ;
416 if (io < 0x400)
417 goto got_it;
418#endif
419 err = -ENODEV;
420 }
421 if (err)
422 goto out;
423got_it:
424 err = register_netdev(dev);
425 if (err)
426 goto out1;
427 return dev;
428out1:
429 release_region(dev->base_addr, NI52_TOTAL_SIZE);
430out:
431 free_netdev(dev);
432 return ERR_PTR(err);
433}
434
Alan Coxa197f692008-02-08 15:27:38 +0000435static int __init ni52_probe1(struct net_device *dev, int ioaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
437 int i, size, retval;
Al Viroe06ee2b2008-03-19 09:43:59 +0000438 struct priv *priv = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 dev->base_addr = ioaddr;
441 dev->irq = irq;
442 dev->mem_start = memstart;
443 dev->mem_end = memend;
444
Al Viro7f8cfd52008-03-19 09:44:09 +0000445 spin_lock_init(&priv->spinlock);
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
448 return -EBUSY;
449
Alan Coxa197f692008-02-08 15:27:38 +0000450 if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
452 retval = -ENODEV;
453 goto out;
454 }
455
Alan Coxa197f692008-02-08 15:27:38 +0000456 for (i = 0; i < ETH_ALEN; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 dev->dev_addr[i] = inb(dev->base_addr+i);
458
Alan Coxa197f692008-02-08 15:27:38 +0000459 if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 || dev->dev_addr[2] != NI52_ADDR2) {
461 retval = -ENODEV;
462 goto out;
463 }
464
Alan Coxa197f692008-02-08 15:27:38 +0000465 printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
466 dev->name, dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 /*
469 * check (or search) IO-Memory, 8K and 16K
470 */
471#ifdef MODULE
472 size = dev->mem_end - dev->mem_start;
Alan Coxa197f692008-02-08 15:27:38 +0000473 if (size != 0x2000 && size != 0x4000) {
474 printk("\n");
475 printk(KERN_ERR "%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev->name, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 retval = -ENODEV;
477 goto out;
478 }
Al Virode597142008-03-19 09:43:49 +0000479 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000480 printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 retval = -ENODEV;
482 goto out;
483 }
484#else
Alan Coxa197f692008-02-08 15:27:38 +0000485 if (dev->mem_start != 0) {
486 /* no auto-mem-probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000488 if (!check586(dev, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000490 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000491 printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 retval = -ENODEV;
493 goto out;
494 }
495 }
Alan Coxa197f692008-02-08 15:27:38 +0000496 } else {
497 static const unsigned long memaddrs[] = {
498 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
499 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
500 };
501 for (i = 0;; i++) {
502 if (!memaddrs[i]) {
503 printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 retval = -ENODEV;
505 goto out;
506 }
507 dev->mem_start = memaddrs[i];
508 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000509 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000510 /* 8K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 break;
512 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000513 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000514 /* 16K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 break;
516 }
517 }
Alan Coxa197f692008-02-08 15:27:38 +0000518 /* set mem_end showed by 'ifconfig' */
519 dev->mem_end = dev->mem_start + size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#endif
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 alloc586(dev);
523
524 /* set number of receive-buffs according to memsize */
Alan Coxa197f692008-02-08 15:27:38 +0000525 if (size == 0x2000)
Al Viroe06ee2b2008-03-19 09:43:59 +0000526 priv->num_recv_buffs = NUM_RECV_BUFFS_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 else
Al Viroe06ee2b2008-03-19 09:43:59 +0000528 priv->num_recv_buffs = NUM_RECV_BUFFS_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Alan Coxa197f692008-02-08 15:27:38 +0000530 printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
531 dev->mem_start, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Alan Coxa197f692008-02-08 15:27:38 +0000533 if (dev->irq < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 unsigned long irq_mask;
535
536 irq_mask = probe_irq_on();
537 ni_reset586();
538 ni_attn586();
539
540 mdelay(20);
541 dev->irq = probe_irq_off(irq_mask);
Alan Coxa197f692008-02-08 15:27:38 +0000542 if (!dev->irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 printk("?autoirq, Failed to detect IRQ line!\n");
544 retval = -EAGAIN;
545 goto out;
546 }
Alan Coxa197f692008-02-08 15:27:38 +0000547 printk("IRQ %d (autodetected).\n", dev->irq);
548 } else {
549 if (dev->irq == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 dev->irq = 9;
Alan Coxa197f692008-02-08 15:27:38 +0000551 printk("IRQ %d (assigned and not checked!).\n", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553
554 dev->open = ni52_open;
555 dev->stop = ni52_close;
556 dev->get_stats = ni52_get_stats;
557 dev->tx_timeout = ni52_timeout;
558 dev->watchdog_timeo = HZ/20;
559 dev->hard_start_xmit = ni52_send_packet;
560 dev->set_multicast_list = set_multicast_list;
561
562 dev->if_port = 0;
563
564 return 0;
565out:
566 release_region(ioaddr, NI52_TOTAL_SIZE);
567 return retval;
568}
569
570/**********************************************
571 * init the chip (ni52-interrupt should be disabled?!)
572 * needs a correct 'allocated' memory
573 */
574
575static int init586(struct net_device *dev)
576{
Al Viro2d76c262008-03-19 09:43:29 +0000577 void __iomem *ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000578 int i, result = 0;
579 struct priv *p = (struct priv *)dev->priv;
Al Viro2d76c262008-03-19 09:43:29 +0000580 struct configure_cmd_struct __iomem *cfg_cmd;
581 struct iasetup_cmd_struct __iomem *ias_cmd;
582 struct tdr_cmd_struct __iomem *tdr_cmd;
583 struct mcsetup_cmd_struct __iomem *mc_cmd;
Alan Coxa197f692008-02-08 15:27:38 +0000584 struct dev_mc_list *dmi = dev->mc_list;
585 int num_addrs = dev->mc_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Al Viro2d76c262008-03-19 09:43:29 +0000587 ptr = p->scb + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Al Viro2d76c262008-03-19 09:43:29 +0000589 cfg_cmd = ptr; /* configure-command */
Alan Coxa197f692008-02-08 15:27:38 +0000590 writew(0, &cfg_cmd->cmd_status);
591 writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
592 writew(0xFFFF, &cfg_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Alan Coxa197f692008-02-08 15:27:38 +0000594 /* number of cfg bytes */
595 writeb(0x0a, &cfg_cmd->byte_cnt);
596 /* fifo-limit (8=tx:32/rx:64) */
597 writeb(fifo, &cfg_cmd->fifo);
598 /* hold or discard bad recv frames (bit 7) */
599 writeb(0x40, &cfg_cmd->sav_bf);
600 /* addr_len |!src_insert |pre-len |loopback */
601 writeb(0x2e, &cfg_cmd->adr_len);
602 writeb(0x00, &cfg_cmd->priority);
603 writeb(0x60, &cfg_cmd->ifs);;
604 writeb(0x00, &cfg_cmd->time_low);
605 writeb(0xf2, &cfg_cmd->time_high);
606 writeb(0x00, &cfg_cmd->promisc);;
607 if (dev->flags & IFF_ALLMULTI) {
Al Viro2d76c262008-03-19 09:43:29 +0000608 int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
Alan Coxa197f692008-02-08 15:27:38 +0000609 if (num_addrs > len) {
610 printk(KERN_ERR "%s: switching to promisc. mode\n",
611 dev->name);
612 dev->flags |= IFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614 }
Alan Coxa197f692008-02-08 15:27:38 +0000615 if (dev->flags & IFF_PROMISC)
616 writeb(0x01, &cfg_cmd->promisc);
617 writeb(0x00, &cfg_cmd->carr_coll);
618 writew(make16(cfg_cmd), &p->scb->cbl_offset);
619 writew(0, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Alan Coxa197f692008-02-08 15:27:38 +0000621 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 ni_attn586();
623
Alan Coxa197f692008-02-08 15:27:38 +0000624 wait_for_stat_compl(cfg_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Alan Coxa197f692008-02-08 15:27:38 +0000626 if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
627 (STAT_COMPL|STAT_OK)) {
628 printk(KERN_ERR "%s: configure command failed: %x\n",
629 dev->name, readw(&cfg_cmd->cmd_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return 1;
631 }
632
633 /*
634 * individual address setup
635 */
636
Al Viro2d76c262008-03-19 09:43:29 +0000637 ias_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Alan Coxa197f692008-02-08 15:27:38 +0000639 writew(0, &ias_cmd->cmd_status);
640 writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
641 writew(0xffff, &ias_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Al Viro2d76c262008-03-19 09:43:29 +0000643 memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Alan Coxa197f692008-02-08 15:27:38 +0000645 writew(make16(ias_cmd), &p->scb->cbl_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Alan Coxa197f692008-02-08 15:27:38 +0000647 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 ni_attn586();
649
Alan Coxa197f692008-02-08 15:27:38 +0000650 wait_for_stat_compl(ias_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Alan Coxa197f692008-02-08 15:27:38 +0000652 if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
653 (STAT_OK|STAT_COMPL)) {
654 printk(KERN_ERR "%s (ni52): individual address setup command failed: %04x\n", dev->name, readw(&ias_cmd->cmd_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return 1;
656 }
657
658 /*
659 * TDR, wire check .. e.g. no resistor e.t.c
660 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400661
Al Viro2d76c262008-03-19 09:43:29 +0000662 tdr_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Alan Coxa197f692008-02-08 15:27:38 +0000664 writew(0, &tdr_cmd->cmd_status);
665 writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
666 writew(0xffff, &tdr_cmd->cmd_link);
667 writew(0, &tdr_cmd->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Alan Coxa197f692008-02-08 15:27:38 +0000669 writew(make16(tdr_cmd), &p->scb->cbl_offset);
670 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 ni_attn586();
672
Alan Coxa197f692008-02-08 15:27:38 +0000673 wait_for_stat_compl(tdr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Alan Coxa197f692008-02-08 15:27:38 +0000675 if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
676 printk(KERN_ERR "%s: Problems while running the TDR.\n",
677 dev->name);
678 else {
679 udelay(16);
680 result = readw(&tdr_cmd->status);
681 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 ni_attn586(); /* ack the interrupts */
683
Alan Coxa197f692008-02-08 15:27:38 +0000684 if (result & TDR_LNK_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 ;
Alan Coxa197f692008-02-08 15:27:38 +0000686 else if (result & TDR_XCVR_PRB)
687 printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
688 dev->name);
689 else if (result & TDR_ET_OPN)
690 printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
691 dev->name, result & TDR_TIMEMASK);
692 else if (result & TDR_ET_SRT) {
693 /* time == 0 -> strange :-) */
694 if (result & TDR_TIMEMASK)
695 printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
696 dev->name, result & TDR_TIMEMASK);
697 } else
698 printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
699 dev->name, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
702 /*
703 * Multicast setup
704 */
Alan Coxa197f692008-02-08 15:27:38 +0000705 if (num_addrs && !(dev->flags & IFF_PROMISC)) {
Al Viro2d76c262008-03-19 09:43:29 +0000706 mc_cmd = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000707 writew(0, &mc_cmd->cmd_status);
708 writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
709 writew(0xffff, &mc_cmd->cmd_link);
710 writew(num_addrs * 6, &mc_cmd->mc_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Alan Coxa197f692008-02-08 15:27:38 +0000712 for (i = 0; i < num_addrs; i++, dmi = dmi->next)
Al Viro2d76c262008-03-19 09:43:29 +0000713 memcpy_toio(mc_cmd->mc_list[i],
Alan Coxa197f692008-02-08 15:27:38 +0000714 dmi->dmi_addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Alan Coxa197f692008-02-08 15:27:38 +0000716 writew(make16(mc_cmd), &p->scb->cbl_offset);
717 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 ni_attn586();
719
Alan Coxa197f692008-02-08 15:27:38 +0000720 wait_for_stat_compl(mc_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Alan Coxa197f692008-02-08 15:27:38 +0000722 if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
723 != (STAT_COMPL|STAT_OK))
724 printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
727 /*
728 * alloc nop/xmit-cmds
729 */
730#if (NUM_XMIT_BUFFS == 1)
Alan Coxa197f692008-02-08 15:27:38 +0000731 for (i = 0; i < 2; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000732 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000733 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
734 writew(0, &p->nop_cmds[i]->cmd_status);
735 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000736 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
738#else
Alan Coxa197f692008-02-08 15:27:38 +0000739 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000740 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000741 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
742 writew(0, &p->nop_cmds[i]->cmd_status);
743 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000744 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
746#endif
747
Al Viro2d76c262008-03-19 09:43:29 +0000748 ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 /*
751 * alloc xmit-buffs / init xmit_cmds
752 */
Alan Coxa197f692008-02-08 15:27:38 +0000753 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
754 /* Transmit cmd/buff 0 */
Al Viro2d76c262008-03-19 09:43:29 +0000755 p->xmit_cmds[i] = ptr;
756 ptr = ptr + sizeof(struct transmit_cmd_struct);
757 p->xmit_cbuffs[i] = ptr; /* char-buffs */
758 ptr = ptr + XMIT_BUFF_SIZE;
759 p->xmit_buffs[i] = ptr; /* TBD */
760 ptr = ptr + sizeof(struct tbd_struct);
761 if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
Alan Coxa197f692008-02-08 15:27:38 +0000762 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
763 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return 1;
765 }
Al Viro2d76c262008-03-19 09:43:29 +0000766 memset_io(p->xmit_cmds[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000767 sizeof(struct transmit_cmd_struct));
Al Viro2d76c262008-03-19 09:43:29 +0000768 memset_io(p->xmit_buffs[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000769 sizeof(struct tbd_struct));
770 writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
771 &p->xmit_cmds[i]->cmd_link);
772 writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
773 writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
774 writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
775 writew(0xffff, &p->xmit_buffs[i]->next);
776 writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
778
779 p->xmit_count = 0;
780 p->xmit_last = 0;
781#ifndef NO_NOPCOMMANDS
782 p->nop_point = 0;
783#endif
784
785 /*
786 * 'start transmitter'
787 */
788#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000789 writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
790 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000792 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#else
Alan Coxa197f692008-02-08 15:27:38 +0000794 writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
795 writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796#endif
797
798 /*
799 * ack. interrupts
800 */
Alan Coxa197f692008-02-08 15:27:38 +0000801 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000803 udelay(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 ni_enaint();
806
807 return 0;
808}
809
810/******************************************************
811 * This is a helper routine for ni52_rnr_int() and init586().
812 * It sets up the Receive Frame Area (RFA).
813 */
814
Al Viro2d76c262008-03-19 09:43:29 +0000815static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Al Viro2d76c262008-03-19 09:43:29 +0000817 struct rfd_struct __iomem *rfd = ptr;
818 struct rbd_struct __iomem *rbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 int i;
820 struct priv *p = (struct priv *) dev->priv;
821
Al Viro2d76c262008-03-19 09:43:29 +0000822 memset_io(rfd, 0,
Alan Coxa197f692008-02-08 15:27:38 +0000823 sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 p->rfd_first = rfd;
825
Alan Coxa197f692008-02-08 15:27:38 +0000826 for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
827 writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
828 &rfd[i].next);
829 writew(0xffff, &rfd[i].rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
Alan Coxa197f692008-02-08 15:27:38 +0000831 /* RU suspend */
832 writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Al Viro2d76c262008-03-19 09:43:29 +0000834 ptr = rfd + (p->num_recv_buffs + rfdadd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Al Viro2d76c262008-03-19 09:43:29 +0000836 rbd = ptr;
837 ptr = rbd + p->num_recv_buffs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /* clr descriptors */
Al Viro2d76c262008-03-19 09:43:29 +0000840 memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Alan Coxa197f692008-02-08 15:27:38 +0000842 for (i = 0; i < p->num_recv_buffs; i++) {
843 writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
844 writew(RECV_BUFF_SIZE, &rbd[i].size);
845 writel(make24(ptr), &rbd[i].buffer);
Al Viro2d76c262008-03-19 09:43:29 +0000846 ptr = ptr + RECV_BUFF_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 p->rfd_top = p->rfd_first;
849 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
850
Alan Coxa197f692008-02-08 15:27:38 +0000851 writew(make16(p->rfd_first), &p->scb->rfa_offset);
852 writew(make16(rbd), &p->rfd_first->rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 return ptr;
855}
856
857
858/**************************************************
859 * Interrupt Handler ...
860 */
861
Alan Coxa197f692008-02-08 15:27:38 +0000862static irqreturn_t ni52_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
864 struct net_device *dev = dev_id;
Alan Coxa197f692008-02-08 15:27:38 +0000865 unsigned int stat;
866 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 struct priv *p;
868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 p = (struct priv *) dev->priv;
870
Alan Coxa197f692008-02-08 15:27:38 +0000871 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 printk("I");
873
Alan Coxa197f692008-02-08 15:27:38 +0000874 spin_lock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Alan Coxa197f692008-02-08 15:27:38 +0000876 wait_for_scb_cmd(dev); /* wait for last command */
877
878 while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
879 writeb(stat, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 ni_attn586();
881
Alan Coxa197f692008-02-08 15:27:38 +0000882 if (stat & STAT_FR) /* received a frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 ni52_rcv_int(dev);
884
Alan Coxa197f692008-02-08 15:27:38 +0000885 if (stat & STAT_RNR) { /* RU went 'not ready' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 printk("(R)");
Alan Coxa197f692008-02-08 15:27:38 +0000887 if (readb(&p->scb->rus) & RU_SUSPEND) {
888 /* special case: RU_SUSPEND */
889 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 p->scb->cmd_ruc = RUC_RESUME;
891 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000892 wait_for_scb_cmd_ruc(dev);
893 } else {
894 printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
895 dev->name, stat, readb(&p->scb->rus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 ni52_rnr_int(dev);
897 }
898 }
899
Alan Coxa197f692008-02-08 15:27:38 +0000900 /* Command with I-bit set complete */
901 if (stat & STAT_CX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 ni52_xmt_int(dev);
903
904#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000905 if (stat & STAT_CNA) { /* CU went 'not ready' */
906 if (netif_running(dev))
907 printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
908 dev->name, stat, readb(&p->scb->cus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910#endif
911
Alan Coxa197f692008-02-08 15:27:38 +0000912 if (debuglevel > 1)
913 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Alan Coxa197f692008-02-08 15:27:38 +0000915 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
916 wait_for_scb_cmd(dev);
917 if (p->scb->cmd_cuc) { /* timed out? */
918 printk(KERN_ERR "%s: Acknowledge timed out.\n",
919 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 ni_disint();
921 break;
922 }
923 }
Alan Coxa197f692008-02-08 15:27:38 +0000924 spin_unlock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Alan Coxa197f692008-02-08 15:27:38 +0000926 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 printk("i");
928 return IRQ_HANDLED;
929}
930
931/*******************************************************
932 * receive-interrupt
933 */
934
935static void ni52_rcv_int(struct net_device *dev)
936{
Alan Coxa197f692008-02-08 15:27:38 +0000937 int status, cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 unsigned short totlen;
939 struct sk_buff *skb;
Al Viro2d76c262008-03-19 09:43:29 +0000940 struct rbd_struct __iomem *rbd;
Alan Coxa197f692008-02-08 15:27:38 +0000941 struct priv *p = (struct priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Alan Coxa197f692008-02-08 15:27:38 +0000943 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 printk("R");
945
Alan Coxa197f692008-02-08 15:27:38 +0000946 for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
Al Viro2d76c262008-03-19 09:43:29 +0000947 rbd = (struct rbd_struct __iomem *) make32(p->rfd_top->rbd_offset);
Alan Coxa197f692008-02-08 15:27:38 +0000948 if (status & RFD_OK) { /* frame received without error? */
949 totlen = readw(&rbd->status);
950 if (totlen & RBD_LAST) {
951 /* the first and the last buffer? */
952 totlen &= RBD_MASK; /* length of this frame */
953 writew(0x00, &rbd->status);
954 skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
955 if (skb != NULL) {
956 skb_reserve(skb, 2);
957 skb_put(skb, totlen);
Al Viroe06ee2b2008-03-19 09:43:59 +0000958 skb_copy_to_linear_data(skb, p->base + (unsigned long) rbd->buffer, totlen);
Alan Coxa197f692008-02-08 15:27:38 +0000959 skb->protocol = eth_type_trans(skb, dev);
960 netif_rx(skb);
961 dev->last_rx = jiffies;
962 p->stats.rx_packets++;
963 p->stats.rx_bytes += totlen;
964 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 p->stats.rx_dropped++;
Alan Coxa197f692008-02-08 15:27:38 +0000966 } else {
967 int rstat;
968 /* free all RBD's until RBD_LAST is set */
969 totlen = 0;
970 while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
971 totlen += rstat & RBD_MASK;
972 if (!rstat) {
973 printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
974 break;
975 }
976 writew(0, &rbd->status);
Al Viro2d76c262008-03-19 09:43:29 +0000977 rbd = (struct rbd_struct __iomem *) make32(readl(&rbd->next));
Alan Coxa197f692008-02-08 15:27:38 +0000978 }
979 totlen += rstat & RBD_MASK;
980 writew(0, &rbd->status);
981 printk(KERN_ERR "%s: received oversized frame! length: %d\n",
982 dev->name, totlen);
983 p->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 }
Alan Coxa197f692008-02-08 15:27:38 +0000985 } else {/* frame !(ok), only with 'save-bad-frames' */
986 printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
987 dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 p->stats.rx_errors++;
989 }
Alan Coxa197f692008-02-08 15:27:38 +0000990 writeb(0, &p->rfd_top->stat_high);
991 writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
992 writew(0xffff, &p->rfd_top->rbd_offset);
993 writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 p->rfd_last = p->rfd_top;
Al Viro2d76c262008-03-19 09:43:29 +0000995 p->rfd_top = (struct rfd_struct __iomem *) make32(p->rfd_top->next); /* step to next RFD */
Alan Coxa197f692008-02-08 15:27:38 +0000996 writew(make16(p->rfd_top), &p->scb->rfa_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Alan Coxa197f692008-02-08 15:27:38 +0000998 if (debuglevel > 0)
999 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001
Alan Coxa197f692008-02-08 15:27:38 +00001002 if (automatic_resume) {
1003 wait_for_scb_cmd(dev);
1004 writeb(RUC_RESUME, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001006 wait_for_scb_cmd_ruc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008
1009#ifdef WAIT_4_BUSY
1010 {
1011 int i;
Alan Coxa197f692008-02-08 15:27:38 +00001012 for (i = 0; i < 1024; i++) {
1013 if (p->rfd_top->status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 break;
Alan Coxa197f692008-02-08 15:27:38 +00001015 udelay(16);
1016 if (i == 1023)
1017 printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 }
1020#endif
Alan Coxa197f692008-02-08 15:27:38 +00001021 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 printk("r");
1023}
1024
1025/**********************************************************
1026 * handle 'Receiver went not ready'.
1027 */
1028
1029static void ni52_rnr_int(struct net_device *dev)
1030{
1031 struct priv *p = (struct priv *) dev->priv;
1032
1033 p->stats.rx_errors++;
1034
Alan Coxa197f692008-02-08 15:27:38 +00001035 wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1036 writeb(RUC_ABORT, &p->scb->cmd_ruc); /* usually the RU is in the 'no resource'-state .. abort it now. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001038 wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Al Viro2d76c262008-03-19 09:43:29 +00001040 alloc_rfa(dev, p->rfd_first);
Alan Coxa197f692008-02-08 15:27:38 +00001041 /* maybe add a check here, before restarting the RU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 startrecv586(dev); /* restart RU */
1043
Alan Coxa197f692008-02-08 15:27:38 +00001044 printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046}
1047
1048/**********************************************************
1049 * handle xmit - interrupt
1050 */
1051
1052static void ni52_xmt_int(struct net_device *dev)
1053{
1054 int status;
1055 struct priv *p = (struct priv *) dev->priv;
1056
Alan Coxa197f692008-02-08 15:27:38 +00001057 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 printk("X");
1059
Alan Coxa197f692008-02-08 15:27:38 +00001060 status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
1061 if (!(status & STAT_COMPL))
1062 printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Alan Coxa197f692008-02-08 15:27:38 +00001064 if (status & STAT_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 p->stats.tx_packets++;
1066 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
Alan Coxa197f692008-02-08 15:27:38 +00001067 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 p->stats.tx_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001069 if (status & TCMD_LATECOLL) {
1070 printk(KERN_ERR "%s: late collision detected.\n",
1071 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 p->stats.collisions++;
Alan Coxa197f692008-02-08 15:27:38 +00001073 } else if (status & TCMD_NOCARRIER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 p->stats.tx_carrier_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001075 printk(KERN_ERR "%s: no carrier detected.\n",
1076 dev->name);
1077 } else if (status & TCMD_LOSTCTS)
1078 printk(KERN_ERR "%s: loss of CTS detected.\n",
1079 dev->name);
1080 else if (status & TCMD_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 p->stats.tx_fifo_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001082 printk(KERN_ERR "%s: DMA underrun detected.\n",
1083 dev->name);
1084 } else if (status & TCMD_MAXCOLL) {
1085 printk(KERN_ERR "%s: Max. collisions exceeded.\n",
1086 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 p->stats.collisions += 16;
1088 }
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090#if (NUM_XMIT_BUFFS > 1)
Alan Coxa197f692008-02-08 15:27:38 +00001091 if ((++p->xmit_last) == NUM_XMIT_BUFFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 p->xmit_last = 0;
1093#endif
1094 netif_wake_queue(dev);
1095}
1096
1097/***********************************************************
1098 * (re)start the receiver
1099 */
1100
1101static void startrecv586(struct net_device *dev)
1102{
1103 struct priv *p = (struct priv *) dev->priv;
1104
Alan Coxa197f692008-02-08 15:27:38 +00001105 wait_for_scb_cmd(dev);
1106 wait_for_scb_cmd_ruc(dev);
1107 writew(make16(p->rfd_first), &p->scb->rfa_offset);
1108 writeb(RUC_START, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 ni_attn586(); /* start cmd. */
Alan Coxa197f692008-02-08 15:27:38 +00001110 wait_for_scb_cmd_ruc(dev);
1111 /* wait for accept cmd. (no timeout!!) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
1114static void ni52_timeout(struct net_device *dev)
1115{
1116 struct priv *p = (struct priv *) dev->priv;
1117#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +00001118 if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 netif_wake_queue(dev);
1120#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001121 printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
1122 dev->name);
1123 printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
1124 dev->name, (int)p->xmit_cmds[0]->cmd_status,
1125 readw(&p->nop_cmds[0]->cmd_status),
1126 readw(&p->nop_cmds[1]->cmd_status),
1127 p->nop_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128#endif
Alan Coxa197f692008-02-08 15:27:38 +00001129 writeb(CUC_ABORT, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001131 wait_for_scb_cmd(dev);
1132 writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
1133 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001135 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 dev->trans_start = jiffies;
1137 return 0;
1138 }
1139#endif
1140 {
1141#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001142 printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
1143 dev->name, readb(&p->scb->cus));
1144 printk(KERN_ERR "%s: command-stats: %04x %04x\n",
1145 dev->name,
1146 readw(&p->xmit_cmds[0]->cmd_status),
1147 readw(&p->xmit_cmds[1]->cmd_status));
1148 printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
1149 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150#endif
1151 ni52_close(dev);
1152 ni52_open(dev);
1153 }
1154 dev->trans_start = jiffies;
1155}
1156
1157/******************************************************
1158 * send frame
1159 */
1160
1161static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1162{
Alan Coxa197f692008-02-08 15:27:38 +00001163 int len, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164#ifndef NO_NOPCOMMANDS
1165 int next_nop;
1166#endif
1167 struct priv *p = (struct priv *) dev->priv;
1168
Alan Coxa197f692008-02-08 15:27:38 +00001169 if (skb->len > XMIT_BUFF_SIZE) {
1170 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 return 0;
1172 }
1173
1174 netif_stop_queue(dev);
1175
Alan Coxa197f692008-02-08 15:27:38 +00001176 skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count],
1177 skb->len);
1178 len = skb->len;
1179 if (len < ETH_ZLEN) {
1180 len = ETH_ZLEN;
1181 memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
1182 len - skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185#if (NUM_XMIT_BUFFS == 1)
1186# ifdef NO_NOPCOMMANDS
1187
1188#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001189 if (p->scb->cus & CU_ACTIVE) {
1190 printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
1191 printk(KERN_ERR "%s: stat: %04x %04x\n",
1192 dev->name, readb(&p->scb->cus),
1193 readw(&p->xmit_cmds[0]->cmd_status));
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195#endif
Alan Coxa197f692008-02-08 15:27:38 +00001196 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);;
1197 for (i = 0; i < 16; i++) {
1198 writew(0, &p->xmit_cmds[0]->cmd_status);
1199 wait_for_scb_cmd(dev);
1200 if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
1201 writeb(CUC_RESUME, &p->scb->cmd_cuc);
1202 else {
1203 writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
1204 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
Alan Coxa197f692008-02-08 15:27:38 +00001206 ni_attn586();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 dev->trans_start = jiffies;
Alan Coxa197f692008-02-08 15:27:38 +00001208 if (!i)
1209 dev_kfree_skb(skb);
1210 wait_for_scb_cmd(dev);
1211 /* test it, because CU sometimes doesn't start immediately */
1212 if (readb(&p->scb->cus) & CU_ACTIVE)
1213 break;
1214 if (readw(&p->xmit_cmds[0]->cmd_status))
1215 break;
1216 if (i == 15)
1217 printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1218 }
1219# else
1220 next_nop = (p->nop_point + 1) & 0x1;
1221 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
1222 writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
1223 writew(make16(p->nop_cmds[next_nop]),
1224 &p->nop_cmds[next_nop]->cmd_link);
1225 writew(0, &p->xmit_cmds[0]->cmd_status);
1226 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1227
1228 writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
1229 dev->trans_start = jiffies;
1230 p->nop_point = next_nop;
1231 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232# endif
1233#else
Alan Coxa197f692008-02-08 15:27:38 +00001234 writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
1235 next_nop = p->xmit_count + 1
1236 if (next_nop == NUM_XMIT_BUFFS)
1237 next_nop = 0;
1238 writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
1239 /* linkpointer of xmit-command already points to next nop cmd */
1240 writew(make16(p->nop_cmds[next_nop]),
1241 &p->nop_cmds[next_nop]->cmd_link);
1242 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1243 writew(make16(p->xmit_cmds[p->xmit_count]),
1244 &p->nop_cmds[p->xmit_count]->cmd_link);
1245 dev->trans_start = jiffies;
1246 p->xmit_count = next_nop;
1247 {
1248 unsigned long flags;
1249 spin_lock_irqsave(&p->spinlock);
1250 if (p->xmit_count != p->xmit_last)
1251 netif_wake_queue(dev);
1252 spin_unlock_irqrestore(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
Alan Coxa197f692008-02-08 15:27:38 +00001254 dev_kfree_skb(skb);
1255#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 return 0;
1257}
1258
1259/*******************************************
1260 * Someone wanna have the statistics
1261 */
1262
1263static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1264{
1265 struct priv *p = (struct priv *) dev->priv;
Alan Coxa197f692008-02-08 15:27:38 +00001266 unsigned short crc, aln, rsc, ovrn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Alan Coxa197f692008-02-08 15:27:38 +00001268 /* Get error-statistics from the ni82586 */
1269 crc = readw(&p->scb->crc_errs);
1270 writew(0, &p->scb->crc_errs);
1271 aln = readw(&p->scb->aln_errs);
1272 writew(0, &p->scb->aln_errs);
1273 rsc = readw(&p->scb->rsc_errs);
1274 writew(0, &p->scb->rsc_errs);
1275 ovrn = readw(&p->scb->ovrn_errs);
1276 writew(0, &p->scb->ovrn_errs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
1278 p->stats.rx_crc_errors += crc;
1279 p->stats.rx_fifo_errors += ovrn;
1280 p->stats.rx_frame_errors += aln;
1281 p->stats.rx_dropped += rsc;
1282
1283 return &p->stats;
1284}
1285
1286/********************************************************
1287 * Set MC list ..
1288 */
1289
1290static void set_multicast_list(struct net_device *dev)
1291{
1292 netif_stop_queue(dev);
1293 ni_disint();
1294 alloc586(dev);
1295 init586(dev);
1296 startrecv586(dev);
1297 ni_enaint();
1298 netif_wake_queue(dev);
1299}
1300
1301#ifdef MODULE
1302static struct net_device *dev_ni52;
1303
1304module_param(io, int, 0);
1305module_param(irq, int, 0);
1306module_param(memstart, long, 0);
1307module_param(memend, long, 0);
1308MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
1309MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1310MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1311MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1312
Andrew Morton19a86642006-08-14 23:00:05 -07001313int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
Alan Coxa197f692008-02-08 15:27:38 +00001315 if (io <= 0x0 || !memend || !memstart || irq < 2) {
1316 printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
1317 printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 return -ENODEV;
1319 }
1320 dev_ni52 = ni52_probe(-1);
1321 if (IS_ERR(dev_ni52))
1322 return PTR_ERR(dev_ni52);
1323 return 0;
1324}
1325
Al Viroafc8eb42006-06-14 18:50:53 -04001326void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
1328 unregister_netdev(dev_ni52);
1329 release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
1330 free_netdev(dev_ni52);
1331}
1332#endif /* MODULE */
1333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334MODULE_LICENSE("GPL");
1335
1336/*
1337 * END: linux/drivers/net/ni52.c
1338 */