blob: 3b1c4af615b6043418fa4e3e5ab7607a66d5078e [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
297/**********************************************
298 * Check to see if there's an 82586 out there.
299 */
Al Virode597142008-03-19 09:43:49 +0000300static int check586(struct net_device *dev, unsigned size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Al Virode597142008-03-19 09:43:49 +0000302 unsigned long where = dev->mem_start;
Al Viro7f8cfd52008-03-19 09:44:09 +0000303 struct priv *p = dev->priv;
Al Viro2d76c262008-03-19 09:43:29 +0000304 char __iomem *iscp_addrs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 int i;
306
Al Viroe06ee2b2008-03-19 09:43:59 +0000307 p->mapped = (char __iomem *)isa_bus_to_virt(where);
308 p->base = p->mapped + size - 0x01000000;
309 p->memtop = p->mapped + size;
Al Viro2d76c262008-03-19 09:43:29 +0000310 p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
Al Viro7f8cfd52008-03-19 09:44:09 +0000311 p->scb = (struct scb_struct __iomem *) p->mapped;
Al Viro2d76c262008-03-19 09:43:29 +0000312 memset_io(p->scp, 0, sizeof(struct scp_struct));
Alan Coxa197f692008-02-08 15:27:38 +0000313 for (i = 0; i < sizeof(struct scp_struct); i++)
314 /* memory was writeable? */
Al Viro2d76c262008-03-19 09:43:29 +0000315 if (readb((char __iomem *)p->scp + i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return 0;
Alan Coxa197f692008-02-08 15:27:38 +0000317 writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
318 if (readb(&p->scp->sysbus) != SYSBUSVAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320
Al Viroe06ee2b2008-03-19 09:43:59 +0000321 iscp_addrs[0] = p->mapped;
Al Viro2d76c262008-03-19 09:43:29 +0000322 iscp_addrs[1] = (char __iomem *)p->scp - sizeof(struct iscp_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Alan Coxa197f692008-02-08 15:27:38 +0000324 for (i = 0; i < 2; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000325 p->iscp = (struct iscp_struct __iomem *) iscp_addrs[i];
326 memset_io(p->iscp, 0, sizeof(struct iscp_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alan Coxa197f692008-02-08 15:27:38 +0000328 writel(make24(p->iscp), &p->scp->iscp);
329 writeb(1, &p->iscp->busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 ni_reset586();
332 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000333 mdelay(32); /* wait a while... */
334 /* i82586 clears 'busy' after successful init */
335 if (readb(&p->iscp->busy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return 0;
337 }
Al Viro7f8cfd52008-03-19 09:44:09 +0000338
339 p->iscp = (struct iscp_struct __iomem *)
340 ((char __iomem *)p->scp - sizeof(struct iscp_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return 1;
342}
343
344/******************************************************************
345 * set iscp at the right place, called by ni52_probe1 and open586.
346 */
347static void alloc586(struct net_device *dev)
348{
349 struct priv *p = (struct priv *) dev->priv;
350
351 ni_reset586();
Alan Coxa197f692008-02-08 15:27:38 +0000352 mdelay(32);
353
Alan Coxa197f692008-02-08 15:27:38 +0000354 memset_io(p->iscp, 0, sizeof(struct iscp_struct));
355 memset_io(p->scp , 0, sizeof(struct scp_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Alan Coxa197f692008-02-08 15:27:38 +0000357 writel(make24(p->iscp), &p->scp->iscp);
358 writeb(SYSBUSVAL, &p->scp->sysbus);
359 writew(make16(p->scb), &p->iscp->scb_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Alan Coxa197f692008-02-08 15:27:38 +0000361 writeb(1, &p->iscp->busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 ni_reset586();
363 ni_attn586();
364
Alan Coxa197f692008-02-08 15:27:38 +0000365 mdelay(32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Alan Coxa197f692008-02-08 15:27:38 +0000367 if (readb(&p->iscp->busy))
368 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Alan Coxa197f692008-02-08 15:27:38 +0000370 p->reset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Al Viro2d76c262008-03-19 09:43:29 +0000372 memset_io(p->scb, 0, sizeof(struct scb_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375/* set: io,irq,memstart,memend or set it when calling insmod */
Alan Coxa197f692008-02-08 15:27:38 +0000376static int irq = 9;
377static int io = 0x300;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378static long memstart; /* e.g 0xd0000 */
379static long memend; /* e.g 0xd4000 */
380
381/**********************************************
382 * probe the ni5210-card
383 */
384struct net_device * __init ni52_probe(int unit)
385{
386 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
387 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
388 int *port;
389 int err = 0;
390
391 if (!dev)
392 return ERR_PTR(-ENOMEM);
393
394 if (unit >= 0) {
395 sprintf(dev->name, "eth%d", unit);
396 netdev_boot_setup_check(dev);
397 io = dev->base_addr;
398 irq = dev->irq;
399 memstart = dev->mem_start;
400 memend = dev->mem_end;
401 }
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (io > 0x1ff) { /* Check a single specified location. */
404 err = ni52_probe1(dev, io);
405 } else if (io > 0) { /* Don't probe at all. */
406 err = -ENXIO;
407 } else {
408 for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
409 ;
410 if (*port)
411 goto got_it;
412#ifdef FULL_IO_PROBE
413 for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
414 ;
415 if (io < 0x400)
416 goto got_it;
417#endif
418 err = -ENODEV;
419 }
420 if (err)
421 goto out;
422got_it:
423 err = register_netdev(dev);
424 if (err)
425 goto out1;
426 return dev;
427out1:
428 release_region(dev->base_addr, NI52_TOTAL_SIZE);
429out:
430 free_netdev(dev);
431 return ERR_PTR(err);
432}
433
Alan Coxa197f692008-02-08 15:27:38 +0000434static int __init ni52_probe1(struct net_device *dev, int ioaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
436 int i, size, retval;
Al Viroe06ee2b2008-03-19 09:43:59 +0000437 struct priv *priv = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 dev->base_addr = ioaddr;
440 dev->irq = irq;
441 dev->mem_start = memstart;
442 dev->mem_end = memend;
443
Al Viro7f8cfd52008-03-19 09:44:09 +0000444 spin_lock_init(&priv->spinlock);
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
447 return -EBUSY;
448
Alan Coxa197f692008-02-08 15:27:38 +0000449 if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
451 retval = -ENODEV;
452 goto out;
453 }
454
Alan Coxa197f692008-02-08 15:27:38 +0000455 for (i = 0; i < ETH_ALEN; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 dev->dev_addr[i] = inb(dev->base_addr+i);
457
Alan Coxa197f692008-02-08 15:27:38 +0000458 if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 || dev->dev_addr[2] != NI52_ADDR2) {
460 retval = -ENODEV;
461 goto out;
462 }
463
Alan Coxa197f692008-02-08 15:27:38 +0000464 printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
465 dev->name, dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 /*
468 * check (or search) IO-Memory, 8K and 16K
469 */
470#ifdef MODULE
471 size = dev->mem_end - dev->mem_start;
Alan Coxa197f692008-02-08 15:27:38 +0000472 if (size != 0x2000 && size != 0x4000) {
473 printk("\n");
474 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 -0700475 retval = -ENODEV;
476 goto out;
477 }
Al Virode597142008-03-19 09:43:49 +0000478 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000479 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 -0700480 retval = -ENODEV;
481 goto out;
482 }
483#else
Alan Coxa197f692008-02-08 15:27:38 +0000484 if (dev->mem_start != 0) {
485 /* no auto-mem-probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000487 if (!check586(dev, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000489 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000490 printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 retval = -ENODEV;
492 goto out;
493 }
494 }
Alan Coxa197f692008-02-08 15:27:38 +0000495 } else {
496 static const unsigned long memaddrs[] = {
497 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
498 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
499 };
500 for (i = 0;; i++) {
501 if (!memaddrs[i]) {
502 printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 retval = -ENODEV;
504 goto out;
505 }
506 dev->mem_start = memaddrs[i];
507 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000508 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000509 /* 8K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 break;
511 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000512 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000513 /* 16K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
515 }
516 }
Alan Coxa197f692008-02-08 15:27:38 +0000517 /* set mem_end showed by 'ifconfig' */
518 dev->mem_end = dev->mem_start + size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#endif
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 alloc586(dev);
522
523 /* set number of receive-buffs according to memsize */
Alan Coxa197f692008-02-08 15:27:38 +0000524 if (size == 0x2000)
Al Viroe06ee2b2008-03-19 09:43:59 +0000525 priv->num_recv_buffs = NUM_RECV_BUFFS_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 else
Al Viroe06ee2b2008-03-19 09:43:59 +0000527 priv->num_recv_buffs = NUM_RECV_BUFFS_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Alan Coxa197f692008-02-08 15:27:38 +0000529 printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
530 dev->mem_start, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Alan Coxa197f692008-02-08 15:27:38 +0000532 if (dev->irq < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned long irq_mask;
534
535 irq_mask = probe_irq_on();
536 ni_reset586();
537 ni_attn586();
538
539 mdelay(20);
540 dev->irq = probe_irq_off(irq_mask);
Alan Coxa197f692008-02-08 15:27:38 +0000541 if (!dev->irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 printk("?autoirq, Failed to detect IRQ line!\n");
543 retval = -EAGAIN;
544 goto out;
545 }
Alan Coxa197f692008-02-08 15:27:38 +0000546 printk("IRQ %d (autodetected).\n", dev->irq);
547 } else {
548 if (dev->irq == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 dev->irq = 9;
Alan Coxa197f692008-02-08 15:27:38 +0000550 printk("IRQ %d (assigned and not checked!).\n", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
553 dev->open = ni52_open;
554 dev->stop = ni52_close;
555 dev->get_stats = ni52_get_stats;
556 dev->tx_timeout = ni52_timeout;
557 dev->watchdog_timeo = HZ/20;
558 dev->hard_start_xmit = ni52_send_packet;
559 dev->set_multicast_list = set_multicast_list;
560
561 dev->if_port = 0;
562
563 return 0;
564out:
565 release_region(ioaddr, NI52_TOTAL_SIZE);
566 return retval;
567}
568
569/**********************************************
570 * init the chip (ni52-interrupt should be disabled?!)
571 * needs a correct 'allocated' memory
572 */
573
574static int init586(struct net_device *dev)
575{
Al Viro2d76c262008-03-19 09:43:29 +0000576 void __iomem *ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000577 int i, result = 0;
578 struct priv *p = (struct priv *)dev->priv;
Al Viro2d76c262008-03-19 09:43:29 +0000579 struct configure_cmd_struct __iomem *cfg_cmd;
580 struct iasetup_cmd_struct __iomem *ias_cmd;
581 struct tdr_cmd_struct __iomem *tdr_cmd;
582 struct mcsetup_cmd_struct __iomem *mc_cmd;
Alan Coxa197f692008-02-08 15:27:38 +0000583 struct dev_mc_list *dmi = dev->mc_list;
584 int num_addrs = dev->mc_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Al Viro2d76c262008-03-19 09:43:29 +0000586 ptr = p->scb + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Al Viro2d76c262008-03-19 09:43:29 +0000588 cfg_cmd = ptr; /* configure-command */
Alan Coxa197f692008-02-08 15:27:38 +0000589 writew(0, &cfg_cmd->cmd_status);
590 writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
591 writew(0xFFFF, &cfg_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Alan Coxa197f692008-02-08 15:27:38 +0000593 /* number of cfg bytes */
594 writeb(0x0a, &cfg_cmd->byte_cnt);
595 /* fifo-limit (8=tx:32/rx:64) */
596 writeb(fifo, &cfg_cmd->fifo);
597 /* hold or discard bad recv frames (bit 7) */
598 writeb(0x40, &cfg_cmd->sav_bf);
599 /* addr_len |!src_insert |pre-len |loopback */
600 writeb(0x2e, &cfg_cmd->adr_len);
601 writeb(0x00, &cfg_cmd->priority);
602 writeb(0x60, &cfg_cmd->ifs);;
603 writeb(0x00, &cfg_cmd->time_low);
604 writeb(0xf2, &cfg_cmd->time_high);
605 writeb(0x00, &cfg_cmd->promisc);;
606 if (dev->flags & IFF_ALLMULTI) {
Al Viro2d76c262008-03-19 09:43:29 +0000607 int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
Alan Coxa197f692008-02-08 15:27:38 +0000608 if (num_addrs > len) {
609 printk(KERN_ERR "%s: switching to promisc. mode\n",
610 dev->name);
611 dev->flags |= IFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 }
613 }
Alan Coxa197f692008-02-08 15:27:38 +0000614 if (dev->flags & IFF_PROMISC)
615 writeb(0x01, &cfg_cmd->promisc);
616 writeb(0x00, &cfg_cmd->carr_coll);
617 writew(make16(cfg_cmd), &p->scb->cbl_offset);
618 writew(0, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Alan Coxa197f692008-02-08 15:27:38 +0000620 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 ni_attn586();
622
Alan Coxa197f692008-02-08 15:27:38 +0000623 wait_for_stat_compl(cfg_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Alan Coxa197f692008-02-08 15:27:38 +0000625 if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
626 (STAT_COMPL|STAT_OK)) {
627 printk(KERN_ERR "%s: configure command failed: %x\n",
628 dev->name, readw(&cfg_cmd->cmd_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return 1;
630 }
631
632 /*
633 * individual address setup
634 */
635
Al Viro2d76c262008-03-19 09:43:29 +0000636 ias_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Alan Coxa197f692008-02-08 15:27:38 +0000638 writew(0, &ias_cmd->cmd_status);
639 writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
640 writew(0xffff, &ias_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Al Viro2d76c262008-03-19 09:43:29 +0000642 memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Alan Coxa197f692008-02-08 15:27:38 +0000644 writew(make16(ias_cmd), &p->scb->cbl_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alan Coxa197f692008-02-08 15:27:38 +0000646 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 ni_attn586();
648
Alan Coxa197f692008-02-08 15:27:38 +0000649 wait_for_stat_compl(ias_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Alan Coxa197f692008-02-08 15:27:38 +0000651 if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
652 (STAT_OK|STAT_COMPL)) {
653 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 -0700654 return 1;
655 }
656
657 /*
658 * TDR, wire check .. e.g. no resistor e.t.c
659 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400660
Al Viro2d76c262008-03-19 09:43:29 +0000661 tdr_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Alan Coxa197f692008-02-08 15:27:38 +0000663 writew(0, &tdr_cmd->cmd_status);
664 writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
665 writew(0xffff, &tdr_cmd->cmd_link);
666 writew(0, &tdr_cmd->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Alan Coxa197f692008-02-08 15:27:38 +0000668 writew(make16(tdr_cmd), &p->scb->cbl_offset);
669 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 ni_attn586();
671
Alan Coxa197f692008-02-08 15:27:38 +0000672 wait_for_stat_compl(tdr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Alan Coxa197f692008-02-08 15:27:38 +0000674 if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
675 printk(KERN_ERR "%s: Problems while running the TDR.\n",
676 dev->name);
677 else {
678 udelay(16);
679 result = readw(&tdr_cmd->status);
680 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 ni_attn586(); /* ack the interrupts */
682
Alan Coxa197f692008-02-08 15:27:38 +0000683 if (result & TDR_LNK_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 ;
Alan Coxa197f692008-02-08 15:27:38 +0000685 else if (result & TDR_XCVR_PRB)
686 printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
687 dev->name);
688 else if (result & TDR_ET_OPN)
689 printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
690 dev->name, result & TDR_TIMEMASK);
691 else if (result & TDR_ET_SRT) {
692 /* time == 0 -> strange :-) */
693 if (result & TDR_TIMEMASK)
694 printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
695 dev->name, result & TDR_TIMEMASK);
696 } else
697 printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
698 dev->name, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 /*
702 * Multicast setup
703 */
Alan Coxa197f692008-02-08 15:27:38 +0000704 if (num_addrs && !(dev->flags & IFF_PROMISC)) {
Al Viro2d76c262008-03-19 09:43:29 +0000705 mc_cmd = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000706 writew(0, &mc_cmd->cmd_status);
707 writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
708 writew(0xffff, &mc_cmd->cmd_link);
709 writew(num_addrs * 6, &mc_cmd->mc_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Alan Coxa197f692008-02-08 15:27:38 +0000711 for (i = 0; i < num_addrs; i++, dmi = dmi->next)
Al Viro2d76c262008-03-19 09:43:29 +0000712 memcpy_toio(mc_cmd->mc_list[i],
Alan Coxa197f692008-02-08 15:27:38 +0000713 dmi->dmi_addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Alan Coxa197f692008-02-08 15:27:38 +0000715 writew(make16(mc_cmd), &p->scb->cbl_offset);
716 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 ni_attn586();
718
Alan Coxa197f692008-02-08 15:27:38 +0000719 wait_for_stat_compl(mc_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Alan Coxa197f692008-02-08 15:27:38 +0000721 if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
722 != (STAT_COMPL|STAT_OK))
723 printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 }
725
726 /*
727 * alloc nop/xmit-cmds
728 */
729#if (NUM_XMIT_BUFFS == 1)
Alan Coxa197f692008-02-08 15:27:38 +0000730 for (i = 0; i < 2; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000731 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000732 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
733 writew(0, &p->nop_cmds[i]->cmd_status);
734 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000735 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737#else
Alan Coxa197f692008-02-08 15:27:38 +0000738 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000739 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000740 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
741 writew(0, &p->nop_cmds[i]->cmd_status);
742 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000743 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745#endif
746
Al Viro2d76c262008-03-19 09:43:29 +0000747 ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 /*
750 * alloc xmit-buffs / init xmit_cmds
751 */
Alan Coxa197f692008-02-08 15:27:38 +0000752 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
753 /* Transmit cmd/buff 0 */
Al Viro2d76c262008-03-19 09:43:29 +0000754 p->xmit_cmds[i] = ptr;
755 ptr = ptr + sizeof(struct transmit_cmd_struct);
756 p->xmit_cbuffs[i] = ptr; /* char-buffs */
757 ptr = ptr + XMIT_BUFF_SIZE;
758 p->xmit_buffs[i] = ptr; /* TBD */
759 ptr = ptr + sizeof(struct tbd_struct);
760 if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
Alan Coxa197f692008-02-08 15:27:38 +0000761 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
762 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return 1;
764 }
Al Viro2d76c262008-03-19 09:43:29 +0000765 memset_io(p->xmit_cmds[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000766 sizeof(struct transmit_cmd_struct));
Al Viro2d76c262008-03-19 09:43:29 +0000767 memset_io(p->xmit_buffs[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000768 sizeof(struct tbd_struct));
769 writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
770 &p->xmit_cmds[i]->cmd_link);
771 writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
772 writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
773 writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
774 writew(0xffff, &p->xmit_buffs[i]->next);
775 writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777
778 p->xmit_count = 0;
779 p->xmit_last = 0;
780#ifndef NO_NOPCOMMANDS
781 p->nop_point = 0;
782#endif
783
784 /*
785 * 'start transmitter'
786 */
787#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000788 writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
789 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000791 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792#else
Alan Coxa197f692008-02-08 15:27:38 +0000793 writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
794 writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795#endif
796
797 /*
798 * ack. interrupts
799 */
Alan Coxa197f692008-02-08 15:27:38 +0000800 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000802 udelay(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 ni_enaint();
805
806 return 0;
807}
808
809/******************************************************
810 * This is a helper routine for ni52_rnr_int() and init586().
811 * It sets up the Receive Frame Area (RFA).
812 */
813
Al Viro2d76c262008-03-19 09:43:29 +0000814static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Al Viro2d76c262008-03-19 09:43:29 +0000816 struct rfd_struct __iomem *rfd = ptr;
817 struct rbd_struct __iomem *rbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 int i;
819 struct priv *p = (struct priv *) dev->priv;
820
Al Viro2d76c262008-03-19 09:43:29 +0000821 memset_io(rfd, 0,
Alan Coxa197f692008-02-08 15:27:38 +0000822 sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 p->rfd_first = rfd;
824
Alan Coxa197f692008-02-08 15:27:38 +0000825 for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
826 writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
827 &rfd[i].next);
828 writew(0xffff, &rfd[i].rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 }
Alan Coxa197f692008-02-08 15:27:38 +0000830 /* RU suspend */
831 writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Al Viro2d76c262008-03-19 09:43:29 +0000833 ptr = rfd + (p->num_recv_buffs + rfdadd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Al Viro2d76c262008-03-19 09:43:29 +0000835 rbd = ptr;
836 ptr = rbd + p->num_recv_buffs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 /* clr descriptors */
Al Viro2d76c262008-03-19 09:43:29 +0000839 memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Alan Coxa197f692008-02-08 15:27:38 +0000841 for (i = 0; i < p->num_recv_buffs; i++) {
842 writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
843 writew(RECV_BUFF_SIZE, &rbd[i].size);
844 writel(make24(ptr), &rbd[i].buffer);
Al Viro2d76c262008-03-19 09:43:29 +0000845 ptr = ptr + RECV_BUFF_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 p->rfd_top = p->rfd_first;
848 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
849
Alan Coxa197f692008-02-08 15:27:38 +0000850 writew(make16(p->rfd_first), &p->scb->rfa_offset);
851 writew(make16(rbd), &p->rfd_first->rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 return ptr;
854}
855
856
857/**************************************************
858 * Interrupt Handler ...
859 */
860
Alan Coxa197f692008-02-08 15:27:38 +0000861static irqreturn_t ni52_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
863 struct net_device *dev = dev_id;
Alan Coxa197f692008-02-08 15:27:38 +0000864 unsigned int stat;
865 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 struct priv *p;
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 p = (struct priv *) dev->priv;
869
Alan Coxa197f692008-02-08 15:27:38 +0000870 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 printk("I");
872
Alan Coxa197f692008-02-08 15:27:38 +0000873 spin_lock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Alan Coxa197f692008-02-08 15:27:38 +0000875 wait_for_scb_cmd(dev); /* wait for last command */
876
877 while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
878 writeb(stat, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 ni_attn586();
880
Alan Coxa197f692008-02-08 15:27:38 +0000881 if (stat & STAT_FR) /* received a frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 ni52_rcv_int(dev);
883
Alan Coxa197f692008-02-08 15:27:38 +0000884 if (stat & STAT_RNR) { /* RU went 'not ready' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 printk("(R)");
Alan Coxa197f692008-02-08 15:27:38 +0000886 if (readb(&p->scb->rus) & RU_SUSPEND) {
887 /* special case: RU_SUSPEND */
888 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 p->scb->cmd_ruc = RUC_RESUME;
890 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000891 wait_for_scb_cmd_ruc(dev);
892 } else {
893 printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
894 dev->name, stat, readb(&p->scb->rus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 ni52_rnr_int(dev);
896 }
897 }
898
Alan Coxa197f692008-02-08 15:27:38 +0000899 /* Command with I-bit set complete */
900 if (stat & STAT_CX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 ni52_xmt_int(dev);
902
903#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000904 if (stat & STAT_CNA) { /* CU went 'not ready' */
905 if (netif_running(dev))
906 printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
907 dev->name, stat, readb(&p->scb->cus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
909#endif
910
Alan Coxa197f692008-02-08 15:27:38 +0000911 if (debuglevel > 1)
912 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Alan Coxa197f692008-02-08 15:27:38 +0000914 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
915 wait_for_scb_cmd(dev);
916 if (p->scb->cmd_cuc) { /* timed out? */
917 printk(KERN_ERR "%s: Acknowledge timed out.\n",
918 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 ni_disint();
920 break;
921 }
922 }
Alan Coxa197f692008-02-08 15:27:38 +0000923 spin_unlock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Alan Coxa197f692008-02-08 15:27:38 +0000925 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 printk("i");
927 return IRQ_HANDLED;
928}
929
930/*******************************************************
931 * receive-interrupt
932 */
933
934static void ni52_rcv_int(struct net_device *dev)
935{
Alan Coxa197f692008-02-08 15:27:38 +0000936 int status, cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 unsigned short totlen;
938 struct sk_buff *skb;
Al Viro2d76c262008-03-19 09:43:29 +0000939 struct rbd_struct __iomem *rbd;
Alan Coxa197f692008-02-08 15:27:38 +0000940 struct priv *p = (struct priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Alan Coxa197f692008-02-08 15:27:38 +0000942 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 printk("R");
944
Alan Coxa197f692008-02-08 15:27:38 +0000945 for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
Al Viro2d76c262008-03-19 09:43:29 +0000946 rbd = (struct rbd_struct __iomem *) make32(p->rfd_top->rbd_offset);
Alan Coxa197f692008-02-08 15:27:38 +0000947 if (status & RFD_OK) { /* frame received without error? */
948 totlen = readw(&rbd->status);
949 if (totlen & RBD_LAST) {
950 /* the first and the last buffer? */
951 totlen &= RBD_MASK; /* length of this frame */
952 writew(0x00, &rbd->status);
953 skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
954 if (skb != NULL) {
955 skb_reserve(skb, 2);
956 skb_put(skb, totlen);
Al Viroe06ee2b2008-03-19 09:43:59 +0000957 skb_copy_to_linear_data(skb, p->base + (unsigned long) rbd->buffer, totlen);
Alan Coxa197f692008-02-08 15:27:38 +0000958 skb->protocol = eth_type_trans(skb, dev);
959 netif_rx(skb);
960 dev->last_rx = jiffies;
961 p->stats.rx_packets++;
962 p->stats.rx_bytes += totlen;
963 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 p->stats.rx_dropped++;
Alan Coxa197f692008-02-08 15:27:38 +0000965 } else {
966 int rstat;
967 /* free all RBD's until RBD_LAST is set */
968 totlen = 0;
969 while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
970 totlen += rstat & RBD_MASK;
971 if (!rstat) {
972 printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
973 break;
974 }
975 writew(0, &rbd->status);
Al Viro2d76c262008-03-19 09:43:29 +0000976 rbd = (struct rbd_struct __iomem *) make32(readl(&rbd->next));
Alan Coxa197f692008-02-08 15:27:38 +0000977 }
978 totlen += rstat & RBD_MASK;
979 writew(0, &rbd->status);
980 printk(KERN_ERR "%s: received oversized frame! length: %d\n",
981 dev->name, totlen);
982 p->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
Alan Coxa197f692008-02-08 15:27:38 +0000984 } else {/* frame !(ok), only with 'save-bad-frames' */
985 printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
986 dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 p->stats.rx_errors++;
988 }
Alan Coxa197f692008-02-08 15:27:38 +0000989 writeb(0, &p->rfd_top->stat_high);
990 writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
991 writew(0xffff, &p->rfd_top->rbd_offset);
992 writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 p->rfd_last = p->rfd_top;
Al Viro2d76c262008-03-19 09:43:29 +0000994 p->rfd_top = (struct rfd_struct __iomem *) make32(p->rfd_top->next); /* step to next RFD */
Alan Coxa197f692008-02-08 15:27:38 +0000995 writew(make16(p->rfd_top), &p->scb->rfa_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Alan Coxa197f692008-02-08 15:27:38 +0000997 if (debuglevel > 0)
998 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000
Alan Coxa197f692008-02-08 15:27:38 +00001001 if (automatic_resume) {
1002 wait_for_scb_cmd(dev);
1003 writeb(RUC_RESUME, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001005 wait_for_scb_cmd_ruc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007
1008#ifdef WAIT_4_BUSY
1009 {
1010 int i;
Alan Coxa197f692008-02-08 15:27:38 +00001011 for (i = 0; i < 1024; i++) {
1012 if (p->rfd_top->status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 break;
Alan Coxa197f692008-02-08 15:27:38 +00001014 udelay(16);
1015 if (i == 1023)
1016 printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018 }
1019#endif
Alan Coxa197f692008-02-08 15:27:38 +00001020 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 printk("r");
1022}
1023
1024/**********************************************************
1025 * handle 'Receiver went not ready'.
1026 */
1027
1028static void ni52_rnr_int(struct net_device *dev)
1029{
1030 struct priv *p = (struct priv *) dev->priv;
1031
1032 p->stats.rx_errors++;
1033
Alan Coxa197f692008-02-08 15:27:38 +00001034 wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1035 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 -07001036 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001037 wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Al Viro2d76c262008-03-19 09:43:29 +00001039 alloc_rfa(dev, p->rfd_first);
Alan Coxa197f692008-02-08 15:27:38 +00001040 /* maybe add a check here, before restarting the RU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 startrecv586(dev); /* restart RU */
1042
Alan Coxa197f692008-02-08 15:27:38 +00001043 printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->rus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045}
1046
1047/**********************************************************
1048 * handle xmit - interrupt
1049 */
1050
1051static void ni52_xmt_int(struct net_device *dev)
1052{
1053 int status;
1054 struct priv *p = (struct priv *) dev->priv;
1055
Alan Coxa197f692008-02-08 15:27:38 +00001056 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 printk("X");
1058
Alan Coxa197f692008-02-08 15:27:38 +00001059 status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
1060 if (!(status & STAT_COMPL))
1061 printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Alan Coxa197f692008-02-08 15:27:38 +00001063 if (status & STAT_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 p->stats.tx_packets++;
1065 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
Alan Coxa197f692008-02-08 15:27:38 +00001066 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 p->stats.tx_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001068 if (status & TCMD_LATECOLL) {
1069 printk(KERN_ERR "%s: late collision detected.\n",
1070 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 p->stats.collisions++;
Alan Coxa197f692008-02-08 15:27:38 +00001072 } else if (status & TCMD_NOCARRIER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 p->stats.tx_carrier_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001074 printk(KERN_ERR "%s: no carrier detected.\n",
1075 dev->name);
1076 } else if (status & TCMD_LOSTCTS)
1077 printk(KERN_ERR "%s: loss of CTS detected.\n",
1078 dev->name);
1079 else if (status & TCMD_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 p->stats.tx_fifo_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001081 printk(KERN_ERR "%s: DMA underrun detected.\n",
1082 dev->name);
1083 } else if (status & TCMD_MAXCOLL) {
1084 printk(KERN_ERR "%s: Max. collisions exceeded.\n",
1085 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 p->stats.collisions += 16;
1087 }
1088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089#if (NUM_XMIT_BUFFS > 1)
Alan Coxa197f692008-02-08 15:27:38 +00001090 if ((++p->xmit_last) == NUM_XMIT_BUFFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 p->xmit_last = 0;
1092#endif
1093 netif_wake_queue(dev);
1094}
1095
1096/***********************************************************
1097 * (re)start the receiver
1098 */
1099
1100static void startrecv586(struct net_device *dev)
1101{
1102 struct priv *p = (struct priv *) dev->priv;
1103
Alan Coxa197f692008-02-08 15:27:38 +00001104 wait_for_scb_cmd(dev);
1105 wait_for_scb_cmd_ruc(dev);
1106 writew(make16(p->rfd_first), &p->scb->rfa_offset);
1107 writeb(RUC_START, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 ni_attn586(); /* start cmd. */
Alan Coxa197f692008-02-08 15:27:38 +00001109 wait_for_scb_cmd_ruc(dev);
1110 /* wait for accept cmd. (no timeout!!) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
1113static void ni52_timeout(struct net_device *dev)
1114{
1115 struct priv *p = (struct priv *) dev->priv;
1116#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +00001117 if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 netif_wake_queue(dev);
1119#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001120 printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
1121 dev->name);
1122 printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
1123 dev->name, (int)p->xmit_cmds[0]->cmd_status,
1124 readw(&p->nop_cmds[0]->cmd_status),
1125 readw(&p->nop_cmds[1]->cmd_status),
1126 p->nop_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127#endif
Alan Coxa197f692008-02-08 15:27:38 +00001128 writeb(CUC_ABORT, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001130 wait_for_scb_cmd(dev);
1131 writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
1132 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001134 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 dev->trans_start = jiffies;
1136 return 0;
1137 }
1138#endif
1139 {
1140#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001141 printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
1142 dev->name, readb(&p->scb->cus));
1143 printk(KERN_ERR "%s: command-stats: %04x %04x\n",
1144 dev->name,
1145 readw(&p->xmit_cmds[0]->cmd_status),
1146 readw(&p->xmit_cmds[1]->cmd_status));
1147 printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
1148 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149#endif
1150 ni52_close(dev);
1151 ni52_open(dev);
1152 }
1153 dev->trans_start = jiffies;
1154}
1155
1156/******************************************************
1157 * send frame
1158 */
1159
1160static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1161{
Alan Coxa197f692008-02-08 15:27:38 +00001162 int len, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#ifndef NO_NOPCOMMANDS
1164 int next_nop;
1165#endif
1166 struct priv *p = (struct priv *) dev->priv;
1167
Alan Coxa197f692008-02-08 15:27:38 +00001168 if (skb->len > XMIT_BUFF_SIZE) {
1169 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 -07001170 return 0;
1171 }
1172
1173 netif_stop_queue(dev);
1174
Alan Coxa197f692008-02-08 15:27:38 +00001175 skb_copy_from_linear_data(skb, (char *)p->xmit_cbuffs[p->xmit_count],
1176 skb->len);
1177 len = skb->len;
1178 if (len < ETH_ZLEN) {
1179 len = ETH_ZLEN;
1180 memset((char *)p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
1181 len - skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184#if (NUM_XMIT_BUFFS == 1)
1185# ifdef NO_NOPCOMMANDS
1186
1187#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001188 if (p->scb->cus & CU_ACTIVE) {
1189 printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
1190 printk(KERN_ERR "%s: stat: %04x %04x\n",
1191 dev->name, readb(&p->scb->cus),
1192 readw(&p->xmit_cmds[0]->cmd_status));
1193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194#endif
Alan Coxa197f692008-02-08 15:27:38 +00001195 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);;
1196 for (i = 0; i < 16; i++) {
1197 writew(0, &p->xmit_cmds[0]->cmd_status);
1198 wait_for_scb_cmd(dev);
1199 if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
1200 writeb(CUC_RESUME, &p->scb->cmd_cuc);
1201 else {
1202 writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
1203 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 }
Alan Coxa197f692008-02-08 15:27:38 +00001205 ni_attn586();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 dev->trans_start = jiffies;
Alan Coxa197f692008-02-08 15:27:38 +00001207 if (!i)
1208 dev_kfree_skb(skb);
1209 wait_for_scb_cmd(dev);
1210 /* test it, because CU sometimes doesn't start immediately */
1211 if (readb(&p->scb->cus) & CU_ACTIVE)
1212 break;
1213 if (readw(&p->xmit_cmds[0]->cmd_status))
1214 break;
1215 if (i == 15)
1216 printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1217 }
1218# else
1219 next_nop = (p->nop_point + 1) & 0x1;
1220 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
1221 writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
1222 writew(make16(p->nop_cmds[next_nop]),
1223 &p->nop_cmds[next_nop]->cmd_link);
1224 writew(0, &p->xmit_cmds[0]->cmd_status);
1225 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1226
1227 writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
1228 dev->trans_start = jiffies;
1229 p->nop_point = next_nop;
1230 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231# endif
1232#else
Alan Coxa197f692008-02-08 15:27:38 +00001233 writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
1234 next_nop = p->xmit_count + 1
1235 if (next_nop == NUM_XMIT_BUFFS)
1236 next_nop = 0;
1237 writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
1238 /* linkpointer of xmit-command already points to next nop cmd */
1239 writew(make16(p->nop_cmds[next_nop]),
1240 &p->nop_cmds[next_nop]->cmd_link);
1241 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1242 writew(make16(p->xmit_cmds[p->xmit_count]),
1243 &p->nop_cmds[p->xmit_count]->cmd_link);
1244 dev->trans_start = jiffies;
1245 p->xmit_count = next_nop;
1246 {
1247 unsigned long flags;
1248 spin_lock_irqsave(&p->spinlock);
1249 if (p->xmit_count != p->xmit_last)
1250 netif_wake_queue(dev);
1251 spin_unlock_irqrestore(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 }
Alan Coxa197f692008-02-08 15:27:38 +00001253 dev_kfree_skb(skb);
1254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 return 0;
1256}
1257
1258/*******************************************
1259 * Someone wanna have the statistics
1260 */
1261
1262static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1263{
1264 struct priv *p = (struct priv *) dev->priv;
Alan Coxa197f692008-02-08 15:27:38 +00001265 unsigned short crc, aln, rsc, ovrn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Alan Coxa197f692008-02-08 15:27:38 +00001267 /* Get error-statistics from the ni82586 */
1268 crc = readw(&p->scb->crc_errs);
1269 writew(0, &p->scb->crc_errs);
1270 aln = readw(&p->scb->aln_errs);
1271 writew(0, &p->scb->aln_errs);
1272 rsc = readw(&p->scb->rsc_errs);
1273 writew(0, &p->scb->rsc_errs);
1274 ovrn = readw(&p->scb->ovrn_errs);
1275 writew(0, &p->scb->ovrn_errs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 p->stats.rx_crc_errors += crc;
1278 p->stats.rx_fifo_errors += ovrn;
1279 p->stats.rx_frame_errors += aln;
1280 p->stats.rx_dropped += rsc;
1281
1282 return &p->stats;
1283}
1284
1285/********************************************************
1286 * Set MC list ..
1287 */
1288
1289static void set_multicast_list(struct net_device *dev)
1290{
1291 netif_stop_queue(dev);
1292 ni_disint();
1293 alloc586(dev);
1294 init586(dev);
1295 startrecv586(dev);
1296 ni_enaint();
1297 netif_wake_queue(dev);
1298}
1299
1300#ifdef MODULE
1301static struct net_device *dev_ni52;
1302
1303module_param(io, int, 0);
1304module_param(irq, int, 0);
1305module_param(memstart, long, 0);
1306module_param(memend, long, 0);
1307MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
1308MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1309MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1310MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1311
Andrew Morton19a86642006-08-14 23:00:05 -07001312int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Alan Coxa197f692008-02-08 15:27:38 +00001314 if (io <= 0x0 || !memend || !memstart || irq < 2) {
1315 printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
1316 printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 return -ENODEV;
1318 }
1319 dev_ni52 = ni52_probe(-1);
1320 if (IS_ERR(dev_ni52))
1321 return PTR_ERR(dev_ni52);
1322 return 0;
1323}
1324
Al Viroafc8eb42006-06-14 18:50:53 -04001325void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
1327 unregister_netdev(dev_ni52);
1328 release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
1329 free_netdev(dev_ni52);
1330}
1331#endif /* MODULE */
1332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333MODULE_LICENSE("GPL");
1334
1335/*
1336 * END: linux/drivers/net/ni52.c
1337 */