blob: 05c29c2cef2a62327e3932796b1026961914d528 [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!)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * run with e.g:
13 * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
14 *
15 * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
16 *
17 * If you find a bug, please report me:
18 * The kernel panic output and any kmsg from the ni52 driver
19 * the ni5210-driver-version and the linux-kernel version
20 * how many shared memory (memsize) on the netcard,
21 * bootprom: yes/no, base_addr, mem_start
22 * maybe the ni5210-card revision and the i82586 version
23 *
24 * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
25 * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
26 * 0xd8000,0xcc000,0xce000,0xda000,0xdc000
27 *
28 * sources:
29 * skeleton.c from Donald Becker
30 *
31 * I have also done a look in the following sources: (mail me if you need them)
32 * crynwr-packet-driver by Russ Nelson
33 * Garret A. Wollman's (fourth) i82586-driver for BSD
Alan Coxa197f692008-02-08 15:27:38 +000034 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
35 * helped me a lot to understand this tricky chip.)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 *
37 * Known Problems:
38 * The internal sysbus seems to be slow. So we often lose packets because of
39 * overruns while receiving from a fast remote host.
Alan Coxa197f692008-02-08 15:27:38 +000040 * This can slow down TCP connections. Maybe the newer ni5210 cards are
41 * better. My experience is, that if a machine sends with more than about
42 * 500-600K/s the fifo/sysbus overflows.
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 *
44 * IMPORTANT NOTE:
45 * On fast networks, it's a (very) good idea to have 16K shared memory. With
Alan Coxa197f692008-02-08 15:27:38 +000046 * 8K, we can store only 4 receive frames, so it can (easily) happen that a
47 * remote machine 'overruns' our system.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 *
49 * Known i82586/card problems (I'm sure, there are many more!):
50 * Running the NOP-mode, the i82586 sometimes seems to forget to report
51 * every xmit-interrupt until we restart the CU.
52 * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
53 * in the RBD-Struct which indicates an end of the RBD queue.
54 * Instead, the RU fetches another (randomly selected and
55 * usually used) RBD and begins to fill it. (Maybe, this happens only if
56 * the last buffer from the previous RFD fits exact into the queue and
57 * the next RFD can't fetch an initial RBD. Anyone knows more? )
58 *
59 * results from ftp performance tests with Linux 1.2.5
60 * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
Alan Coxa197f692008-02-08 15:27:38 +000061 * sending in NOP-mode: peak performance up to 530K/s (but better don't
62 * run this mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
64
65/*
66 * 29.Sept.96: virt_to_bus changes for new memory scheme
67 * 19.Feb.96: more Mcast changes, module support (MH)
68 *
69 * 18.Nov.95: Mcast changes (AC).
70 *
71 * 23.April.95: fixed(?) receiving problems by configuring a RFD more
72 * than the number of RBD's. Can maybe cause other problems.
73 * 18.April.95: Added MODULE support (MH)
74 * 17.April.95: MC related changes in init586() and set_multicast_list().
75 * removed use of 'jiffies' in init586() (MH)
76 *
77 * 19.Sep.94: Added Multicast support (not tested yet) (MH)
78 *
79 * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
80 * Now, every RFD has exact one RBD. (MH)
81 *
82 * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
83 *
84 * 19.Aug.94: changed request_irq() parameter (MH)
85 *
86 * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
87 *
88 * 19.July.94: lotsa cleanups .. (MH)
89 *
90 * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
91 *
92 * 4.July.94: patches for Linux 1.1.24 (MH)
93 *
94 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
95 *
Alan Coxa197f692008-02-08 15:27:38 +000096 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
97 * too (MH)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 *
99 * < 30.Sep.93: first versions
100 */
101
102static int debuglevel; /* debug-printk 0: off 1: a few 2: more */
103static int automatic_resume; /* experimental .. better should be zero */
104static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */
Alan Coxa197f692008-02-08 15:27:38 +0000105static int fifo = 0x8; /* don't change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#include <linux/module.h>
108#include <linux/kernel.h>
109#include <linux/string.h>
110#include <linux/errno.h>
111#include <linux/ioport.h>
112#include <linux/slab.h>
113#include <linux/interrupt.h>
114#include <linux/delay.h>
115#include <linux/init.h>
116#include <linux/bitops.h>
117#include <asm/io.h>
118
119#include <linux/netdevice.h>
120#include <linux/etherdevice.h>
121#include <linux/skbuff.h>
122
123#include "ni52.h"
124
125#define DRV_NAME "ni52"
126
127#define DEBUG /* debug on */
128#define SYSBUSVAL 1 /* 8 Bit */
129
Alan Coxa197f692008-02-08 15:27:38 +0000130#define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); }
131#define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
132#define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); }
133#define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Al Viro05bd8312008-03-19 09:44:39 +0000135#define make32(ptr16) ((void __iomem *)(p->memtop + (short) (ptr16)))
Al Viroe06ee2b2008-03-19 09:43:59 +0000136#define make24(ptr32) ((char __iomem *)(ptr32)) - p->base
137#define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
138 - p->memtop))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140/******************* how to calculate the buffers *****************************
141
142 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
143 * --------------- in a different (more stable?) mode. Only in this mode it's
144 * possible to configure the driver with 'NO_NOPCOMMANDS'
145
146sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
147sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
148sizeof(rfd) = 24; sizeof(rbd) = 12;
149sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
150sizeof(nop_cmd) = 8;
151
152 * if you don't know the driver, better do not change these values: */
153
154#define RECV_BUFF_SIZE 1524 /* slightly oversized */
155#define XMIT_BUFF_SIZE 1524 /* slightly oversized */
156#define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
157#define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
158#define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
159#define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
160
161/**************************************************************************/
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164#define NI52_TOTAL_SIZE 16
165#define NI52_ADDR0 0x02
166#define NI52_ADDR1 0x07
167#define NI52_ADDR2 0x01
168
Alan Coxa197f692008-02-08 15:27:38 +0000169static int ni52_probe1(struct net_device *dev, int ioaddr);
170static irqreturn_t ni52_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static int ni52_open(struct net_device *dev);
172static int ni52_close(struct net_device *dev);
Stephen Hemminger613573252009-08-31 19:50:58 +0000173static netdev_tx_t ni52_send_packet(struct sk_buff *, struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174static struct net_device_stats *ni52_get_stats(struct net_device *dev);
175static void set_multicast_list(struct net_device *dev);
176static void ni52_timeout(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* helper-functions */
179static int init586(struct net_device *dev);
Al Virode597142008-03-19 09:43:49 +0000180static int check586(struct net_device *dev, unsigned size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181static void alloc586(struct net_device *dev);
182static void startrecv586(struct net_device *dev);
Al Viro2d76c262008-03-19 09:43:29 +0000183static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static void ni52_rcv_int(struct net_device *dev);
185static void ni52_xmt_int(struct net_device *dev);
186static void ni52_rnr_int(struct net_device *dev);
187
Alan Coxa197f692008-02-08 15:27:38 +0000188struct priv {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 struct net_device_stats stats;
Al Viroe06ee2b2008-03-19 09:43:59 +0000190 char __iomem *base;
191 char __iomem *mapped;
Al Viro2d76c262008-03-19 09:43:29 +0000192 char __iomem *memtop;
Alan Coxa197f692008-02-08 15:27:38 +0000193 spinlock_t spinlock;
194 int reset;
Al Viro2d76c262008-03-19 09:43:29 +0000195 struct rfd_struct __iomem *rfd_last, *rfd_top, *rfd_first;
196 struct scp_struct __iomem *scp;
197 struct iscp_struct __iomem *iscp;
198 struct scb_struct __iomem *scb;
199 struct tbd_struct __iomem *xmit_buffs[NUM_XMIT_BUFFS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#if (NUM_XMIT_BUFFS == 1)
Al Viro2d76c262008-03-19 09:43:29 +0000201 struct transmit_cmd_struct __iomem *xmit_cmds[2];
202 struct nop_cmd_struct __iomem *nop_cmds[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#else
Al Viro2d76c262008-03-19 09:43:29 +0000204 struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS];
205 struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#endif
Alan Coxa197f692008-02-08 15:27:38 +0000207 int nop_point, num_recv_buffs;
Al Viro2d76c262008-03-19 09:43:29 +0000208 char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS];
Alan Coxa197f692008-02-08 15:27:38 +0000209 int xmit_count, xmit_last;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210};
211
Alan Coxa197f692008-02-08 15:27:38 +0000212/* wait for command with timeout: */
213static void wait_for_scb_cmd(struct net_device *dev)
214{
Wang Chen4cf16532008-11-12 23:38:14 -0800215 struct priv *p = netdev_priv(dev);
Alan Coxa197f692008-02-08 15:27:38 +0000216 int i;
217 for (i = 0; i < 16384; i++) {
218 if (readb(&p->scb->cmd_cuc) == 0)
219 break;
220 udelay(4);
221 if (i == 16383) {
222 printk(KERN_ERR "%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
223 dev->name, readb(&p->scb->cmd_cuc), readb(&p->scb->cus));
224 if (!p->reset) {
225 p->reset = 1;
226 ni_reset586();
227 }
228 }
229 }
230}
231
232static void wait_for_scb_cmd_ruc(struct net_device *dev)
233{
Wang Chen4cf16532008-11-12 23:38:14 -0800234 struct priv *p = netdev_priv(dev);
Alan Coxa197f692008-02-08 15:27:38 +0000235 int i;
236 for (i = 0; i < 16384; i++) {
237 if (readb(&p->scb->cmd_ruc) == 0)
238 break;
239 udelay(4);
240 if (i == 16383) {
241 printk(KERN_ERR "%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
Al Viro05bd8312008-03-19 09:44:39 +0000242 dev->name, readb(&p->scb->cmd_ruc),
243 readb(&p->scb->rus));
Alan Coxa197f692008-02-08 15:27:38 +0000244 if (!p->reset) {
245 p->reset = 1;
246 ni_reset586();
247 }
248 }
249 }
250}
251
Al Viro2d76c262008-03-19 09:43:29 +0000252static void wait_for_stat_compl(void __iomem *p)
Alan Coxa197f692008-02-08 15:27:38 +0000253{
Al Viro2d76c262008-03-19 09:43:29 +0000254 struct nop_cmd_struct __iomem *addr = p;
Alan Coxa197f692008-02-08 15:27:38 +0000255 int i;
256 for (i = 0; i < 32767; i++) {
257 if (readw(&((addr)->cmd_status)) & STAT_COMPL)
258 break;
259 udelay(32);
260 }
261}
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/**********************************************
264 * close device
265 */
266static int ni52_close(struct net_device *dev)
267{
268 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 ni_reset586(); /* the hard way to stop the receiver */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return 0;
272}
273
274/**********************************************
275 * open device
276 */
277static int ni52_open(struct net_device *dev)
278{
279 int ret;
280
281 ni_disint();
282 alloc586(dev);
283 init586(dev);
284 startrecv586(dev);
285 ni_enaint();
286
Joe Perchesa0607fd2009-11-18 23:29:17 -0800287 ret = request_irq(dev->irq, ni52_interrupt, 0, dev->name, dev);
Alan Coxa197f692008-02-08 15:27:38 +0000288 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ni_reset586();
290 return ret;
291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return 0; /* most done by init */
294}
295
Al Viro76af5692008-03-19 09:44:19 +0000296static int check_iscp(struct net_device *dev, void __iomem *addr)
297{
298 struct iscp_struct __iomem *iscp = addr;
Wang Chen4cf16532008-11-12 23:38:14 -0800299 struct priv *p = netdev_priv(dev);
Al Viro76af5692008-03-19 09:44:19 +0000300 memset_io(iscp, 0, sizeof(struct iscp_struct));
301
302 writel(make24(iscp), &p->scp->iscp);
303 writeb(1, &iscp->busy);
304
305 ni_reset586();
306 ni_attn586();
307 mdelay(32); /* wait a while... */
308 /* i82586 clears 'busy' after successful init */
309 if (readb(&iscp->busy))
310 return 0;
311 return 1;
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/**********************************************
315 * Check to see if there's an 82586 out there.
316 */
Al Virode597142008-03-19 09:43:49 +0000317static int check586(struct net_device *dev, unsigned size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Wang Chen4cf16532008-11-12 23:38:14 -0800319 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 int i;
321
Al Viro176f65f2008-03-19 09:44:29 +0000322 p->mapped = ioremap(dev->mem_start, size);
323 if (!p->mapped)
324 return 0;
325
Al Viroe06ee2b2008-03-19 09:43:59 +0000326 p->base = p->mapped + size - 0x01000000;
327 p->memtop = p->mapped + size;
Al Viro2d76c262008-03-19 09:43:29 +0000328 p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS);
Al Viro7f8cfd52008-03-19 09:44:09 +0000329 p->scb = (struct scb_struct __iomem *) p->mapped;
Al Viro76af5692008-03-19 09:44:19 +0000330 p->iscp = (struct iscp_struct __iomem *)p->scp - 1;
Al Viro2d76c262008-03-19 09:43:29 +0000331 memset_io(p->scp, 0, sizeof(struct scp_struct));
Alan Coxa197f692008-02-08 15:27:38 +0000332 for (i = 0; i < sizeof(struct scp_struct); i++)
333 /* memory was writeable? */
Al Viro2d76c262008-03-19 09:43:29 +0000334 if (readb((char __iomem *)p->scp + i))
Al Viro176f65f2008-03-19 09:44:29 +0000335 goto Enodev;
Alan Coxa197f692008-02-08 15:27:38 +0000336 writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */
337 if (readb(&p->scp->sysbus) != SYSBUSVAL)
Al Viro176f65f2008-03-19 09:44:29 +0000338 goto Enodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Al Viro76af5692008-03-19 09:44:19 +0000340 if (!check_iscp(dev, p->mapped))
Al Viro176f65f2008-03-19 09:44:29 +0000341 goto Enodev;
Al Viro76af5692008-03-19 09:44:19 +0000342 if (!check_iscp(dev, p->iscp))
Al Viro176f65f2008-03-19 09:44:29 +0000343 goto Enodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return 1;
Al Viro176f65f2008-03-19 09:44:29 +0000345Enodev:
346 iounmap(p->mapped);
347 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350/******************************************************************
351 * set iscp at the right place, called by ni52_probe1 and open586.
352 */
353static void alloc586(struct net_device *dev)
354{
Wang Chen4cf16532008-11-12 23:38:14 -0800355 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 ni_reset586();
Alan Coxa197f692008-02-08 15:27:38 +0000358 mdelay(32);
359
Alan Coxa197f692008-02-08 15:27:38 +0000360 memset_io(p->iscp, 0, sizeof(struct iscp_struct));
361 memset_io(p->scp , 0, sizeof(struct scp_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Alan Coxa197f692008-02-08 15:27:38 +0000363 writel(make24(p->iscp), &p->scp->iscp);
364 writeb(SYSBUSVAL, &p->scp->sysbus);
365 writew(make16(p->scb), &p->iscp->scb_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Alan Coxa197f692008-02-08 15:27:38 +0000367 writeb(1, &p->iscp->busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 ni_reset586();
369 ni_attn586();
370
Alan Coxa197f692008-02-08 15:27:38 +0000371 mdelay(32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Alan Coxa197f692008-02-08 15:27:38 +0000373 if (readb(&p->iscp->busy))
374 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Alan Coxa197f692008-02-08 15:27:38 +0000376 p->reset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Al Viro2d76c262008-03-19 09:43:29 +0000378 memset_io(p->scb, 0, sizeof(struct scb_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381/* set: io,irq,memstart,memend or set it when calling insmod */
Alan Coxa197f692008-02-08 15:27:38 +0000382static int irq = 9;
383static int io = 0x300;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384static long memstart; /* e.g 0xd0000 */
385static long memend; /* e.g 0xd4000 */
386
387/**********************************************
388 * probe the ni5210-card
389 */
390struct net_device * __init ni52_probe(int unit)
391{
392 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
393 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
Al Viro176f65f2008-03-19 09:44:29 +0000394 struct priv *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 int *port;
396 int err = 0;
397
398 if (!dev)
399 return ERR_PTR(-ENOMEM);
400
Wang Chen4cf16532008-11-12 23:38:14 -0800401 p = netdev_priv(dev);
Al Viro176f65f2008-03-19 09:44:29 +0000402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (unit >= 0) {
404 sprintf(dev->name, "eth%d", unit);
405 netdev_boot_setup_check(dev);
406 io = dev->base_addr;
407 irq = dev->irq;
408 memstart = dev->mem_start;
409 memend = dev->mem_end;
410 }
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (io > 0x1ff) { /* Check a single specified location. */
413 err = ni52_probe1(dev, io);
414 } else if (io > 0) { /* Don't probe at all. */
415 err = -ENXIO;
416 } else {
417 for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
418 ;
419 if (*port)
420 goto got_it;
421#ifdef FULL_IO_PROBE
422 for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
423 ;
424 if (io < 0x400)
425 goto got_it;
426#endif
427 err = -ENODEV;
428 }
429 if (err)
430 goto out;
431got_it:
432 err = register_netdev(dev);
433 if (err)
434 goto out1;
435 return dev;
436out1:
Al Viro176f65f2008-03-19 09:44:29 +0000437 iounmap(p->mapped);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 release_region(dev->base_addr, NI52_TOTAL_SIZE);
439out:
440 free_netdev(dev);
441 return ERR_PTR(err);
442}
443
Stephen Hemminger2c7669e2009-03-26 15:11:39 +0000444static const struct net_device_ops ni52_netdev_ops = {
445 .ndo_open = ni52_open,
446 .ndo_stop = ni52_close,
447 .ndo_get_stats = ni52_get_stats,
448 .ndo_tx_timeout = ni52_timeout,
449 .ndo_start_xmit = ni52_send_packet,
450 .ndo_set_multicast_list = set_multicast_list,
451 .ndo_change_mtu = eth_change_mtu,
452 .ndo_set_mac_address = eth_mac_addr,
453 .ndo_validate_addr = eth_validate_addr,
454};
455
Alan Coxa197f692008-02-08 15:27:38 +0000456static int __init ni52_probe1(struct net_device *dev, int ioaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
458 int i, size, retval;
Wang Chen4cf16532008-11-12 23:38:14 -0800459 struct priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 dev->base_addr = ioaddr;
462 dev->irq = irq;
463 dev->mem_start = memstart;
464 dev->mem_end = memend;
465
Al Viro7f8cfd52008-03-19 09:44:09 +0000466 spin_lock_init(&priv->spinlock);
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME))
469 return -EBUSY;
470
Alan Coxa197f692008-02-08 15:27:38 +0000471 if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) {
473 retval = -ENODEV;
474 goto out;
475 }
476
Alan Coxa197f692008-02-08 15:27:38 +0000477 for (i = 0; i < ETH_ALEN; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 dev->dev_addr[i] = inb(dev->base_addr+i);
479
Joe Perches8e95a202009-12-03 07:58:21 +0000480 if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 ||
481 dev->dev_addr[2] != NI52_ADDR2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 retval = -ENODEV;
483 goto out;
484 }
485
Alan Coxa197f692008-02-08 15:27:38 +0000486 printk(KERN_INFO "%s: NI5210 found at %#3lx, ",
487 dev->name, dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 /*
490 * check (or search) IO-Memory, 8K and 16K
491 */
492#ifdef MODULE
493 size = dev->mem_end - dev->mem_start;
Alan Coxa197f692008-02-08 15:27:38 +0000494 if (size != 0x2000 && size != 0x4000) {
495 printk("\n");
496 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 -0700497 retval = -ENODEV;
498 goto out;
499 }
Al Virode597142008-03-19 09:43:49 +0000500 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000501 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 -0700502 retval = -ENODEV;
503 goto out;
504 }
505#else
Alan Coxa197f692008-02-08 15:27:38 +0000506 if (dev->mem_start != 0) {
507 /* no auto-mem-probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000509 if (!check586(dev, size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000511 if (!check586(dev, size)) {
Alan Coxa197f692008-02-08 15:27:38 +0000512 printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 retval = -ENODEV;
514 goto out;
515 }
516 }
Alan Coxa197f692008-02-08 15:27:38 +0000517 } else {
518 static const unsigned long memaddrs[] = {
519 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
520 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
521 };
522 for (i = 0;; i++) {
523 if (!memaddrs[i]) {
524 printk(KERN_ERR "?memprobe, Can't find io-memory!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 retval = -ENODEV;
526 goto out;
527 }
528 dev->mem_start = memaddrs[i];
529 size = 0x2000; /* check for 8K mem */
Al Virode597142008-03-19 09:43:49 +0000530 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000531 /* 8K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533 size = 0x4000; /* check for 16K mem */
Al Virode597142008-03-19 09:43:49 +0000534 if (check586(dev, size))
Alan Coxa197f692008-02-08 15:27:38 +0000535 /* 16K-check */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 break;
537 }
538 }
Alan Coxa197f692008-02-08 15:27:38 +0000539 /* set mem_end showed by 'ifconfig' */
540 dev->mem_end = dev->mem_start + size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#endif
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 alloc586(dev);
544
545 /* set number of receive-buffs according to memsize */
Alan Coxa197f692008-02-08 15:27:38 +0000546 if (size == 0x2000)
Al Viroe06ee2b2008-03-19 09:43:59 +0000547 priv->num_recv_buffs = NUM_RECV_BUFFS_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 else
Al Viroe06ee2b2008-03-19 09:43:59 +0000549 priv->num_recv_buffs = NUM_RECV_BUFFS_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Alan Coxa197f692008-02-08 15:27:38 +0000551 printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ",
552 dev->mem_start, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Alan Coxa197f692008-02-08 15:27:38 +0000554 if (dev->irq < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 unsigned long irq_mask;
556
557 irq_mask = probe_irq_on();
558 ni_reset586();
559 ni_attn586();
560
561 mdelay(20);
562 dev->irq = probe_irq_off(irq_mask);
Alan Coxa197f692008-02-08 15:27:38 +0000563 if (!dev->irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 printk("?autoirq, Failed to detect IRQ line!\n");
565 retval = -EAGAIN;
Al Viro176f65f2008-03-19 09:44:29 +0000566 iounmap(priv->mapped);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 goto out;
568 }
Alan Coxa197f692008-02-08 15:27:38 +0000569 printk("IRQ %d (autodetected).\n", dev->irq);
570 } else {
571 if (dev->irq == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 dev->irq = 9;
Alan Coxa197f692008-02-08 15:27:38 +0000573 printk("IRQ %d (assigned and not checked!).\n", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
Stephen Hemminger2c7669e2009-03-26 15:11:39 +0000576 dev->netdev_ops = &ni52_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 dev->watchdog_timeo = HZ/20;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 return 0;
580out:
581 release_region(ioaddr, NI52_TOTAL_SIZE);
582 return retval;
583}
584
585/**********************************************
586 * init the chip (ni52-interrupt should be disabled?!)
587 * needs a correct 'allocated' memory
588 */
589
590static int init586(struct net_device *dev)
591{
Al Viro2d76c262008-03-19 09:43:29 +0000592 void __iomem *ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000593 int i, result = 0;
Wang Chen4cf16532008-11-12 23:38:14 -0800594 struct priv *p = netdev_priv(dev);
Al Viro2d76c262008-03-19 09:43:29 +0000595 struct configure_cmd_struct __iomem *cfg_cmd;
596 struct iasetup_cmd_struct __iomem *ias_cmd;
597 struct tdr_cmd_struct __iomem *tdr_cmd;
598 struct mcsetup_cmd_struct __iomem *mc_cmd;
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000599 struct dev_mc_list *dmi;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000600 int num_addrs = netdev_mc_count(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Al Viro2d76c262008-03-19 09:43:29 +0000602 ptr = p->scb + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Al Viro2d76c262008-03-19 09:43:29 +0000604 cfg_cmd = ptr; /* configure-command */
Alan Coxa197f692008-02-08 15:27:38 +0000605 writew(0, &cfg_cmd->cmd_status);
606 writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd);
607 writew(0xFFFF, &cfg_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Alan Coxa197f692008-02-08 15:27:38 +0000609 /* number of cfg bytes */
610 writeb(0x0a, &cfg_cmd->byte_cnt);
611 /* fifo-limit (8=tx:32/rx:64) */
612 writeb(fifo, &cfg_cmd->fifo);
613 /* hold or discard bad recv frames (bit 7) */
614 writeb(0x40, &cfg_cmd->sav_bf);
615 /* addr_len |!src_insert |pre-len |loopback */
616 writeb(0x2e, &cfg_cmd->adr_len);
617 writeb(0x00, &cfg_cmd->priority);
Joe Perchesa419aef2009-08-18 11:18:35 -0700618 writeb(0x60, &cfg_cmd->ifs);
Alan Coxa197f692008-02-08 15:27:38 +0000619 writeb(0x00, &cfg_cmd->time_low);
620 writeb(0xf2, &cfg_cmd->time_high);
Joe Perchesa419aef2009-08-18 11:18:35 -0700621 writeb(0x00, &cfg_cmd->promisc);
Alan Coxa197f692008-02-08 15:27:38 +0000622 if (dev->flags & IFF_ALLMULTI) {
Al Viro2d76c262008-03-19 09:43:29 +0000623 int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6;
Alan Coxa197f692008-02-08 15:27:38 +0000624 if (num_addrs > len) {
625 printk(KERN_ERR "%s: switching to promisc. mode\n",
626 dev->name);
Wang Chenc16d1182008-07-22 13:13:12 +0800627 writeb(0x01, &cfg_cmd->promisc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629 }
Alan Coxa197f692008-02-08 15:27:38 +0000630 if (dev->flags & IFF_PROMISC)
631 writeb(0x01, &cfg_cmd->promisc);
632 writeb(0x00, &cfg_cmd->carr_coll);
633 writew(make16(cfg_cmd), &p->scb->cbl_offset);
Al Viro05bd8312008-03-19 09:44:39 +0000634 writeb(0, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Alan Coxa197f692008-02-08 15:27:38 +0000636 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 ni_attn586();
638
Alan Coxa197f692008-02-08 15:27:38 +0000639 wait_for_stat_compl(cfg_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Alan Coxa197f692008-02-08 15:27:38 +0000641 if ((readw(&cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
642 (STAT_COMPL|STAT_OK)) {
643 printk(KERN_ERR "%s: configure command failed: %x\n",
644 dev->name, readw(&cfg_cmd->cmd_status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return 1;
646 }
647
648 /*
649 * individual address setup
650 */
651
Al Viro2d76c262008-03-19 09:43:29 +0000652 ias_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Alan Coxa197f692008-02-08 15:27:38 +0000654 writew(0, &ias_cmd->cmd_status);
655 writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd);
656 writew(0xffff, &ias_cmd->cmd_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Al Viro2d76c262008-03-19 09:43:29 +0000658 memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Alan Coxa197f692008-02-08 15:27:38 +0000660 writew(make16(ias_cmd), &p->scb->cbl_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Alan Coxa197f692008-02-08 15:27:38 +0000662 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 ni_attn586();
664
Alan Coxa197f692008-02-08 15:27:38 +0000665 wait_for_stat_compl(ias_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Alan Coxa197f692008-02-08 15:27:38 +0000667 if ((readw(&ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) !=
668 (STAT_OK|STAT_COMPL)) {
669 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 -0700670 return 1;
671 }
672
673 /*
674 * TDR, wire check .. e.g. no resistor e.t.c
675 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400676
Al Viro2d76c262008-03-19 09:43:29 +0000677 tdr_cmd = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Alan Coxa197f692008-02-08 15:27:38 +0000679 writew(0, &tdr_cmd->cmd_status);
680 writew(CMD_TDR | CMD_LAST, &tdr_cmd->cmd_cmd);
681 writew(0xffff, &tdr_cmd->cmd_link);
682 writew(0, &tdr_cmd->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Alan Coxa197f692008-02-08 15:27:38 +0000684 writew(make16(tdr_cmd), &p->scb->cbl_offset);
685 writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 ni_attn586();
687
Alan Coxa197f692008-02-08 15:27:38 +0000688 wait_for_stat_compl(tdr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Alan Coxa197f692008-02-08 15:27:38 +0000690 if (!(readw(&tdr_cmd->cmd_status) & STAT_COMPL))
691 printk(KERN_ERR "%s: Problems while running the TDR.\n",
692 dev->name);
693 else {
694 udelay(16);
695 result = readw(&tdr_cmd->status);
696 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 ni_attn586(); /* ack the interrupts */
698
Alan Coxa197f692008-02-08 15:27:38 +0000699 if (result & TDR_LNK_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 ;
Alan Coxa197f692008-02-08 15:27:38 +0000701 else if (result & TDR_XCVR_PRB)
702 printk(KERN_ERR "%s: TDR: Transceiver problem. Check the cable(s)!\n",
703 dev->name);
704 else if (result & TDR_ET_OPN)
705 printk(KERN_ERR "%s: TDR: No correct termination %d clocks away.\n",
706 dev->name, result & TDR_TIMEMASK);
707 else if (result & TDR_ET_SRT) {
708 /* time == 0 -> strange :-) */
709 if (result & TDR_TIMEMASK)
710 printk(KERN_ERR "%s: TDR: Detected a short circuit %d clocks away.\n",
711 dev->name, result & TDR_TIMEMASK);
712 } else
713 printk(KERN_ERR "%s: TDR: Unknown status %04x\n",
714 dev->name, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 }
716
717 /*
718 * Multicast setup
719 */
Alan Coxa197f692008-02-08 15:27:38 +0000720 if (num_addrs && !(dev->flags & IFF_PROMISC)) {
Al Viro2d76c262008-03-19 09:43:29 +0000721 mc_cmd = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000722 writew(0, &mc_cmd->cmd_status);
723 writew(CMD_MCSETUP | CMD_LAST, &mc_cmd->cmd_cmd);
724 writew(0xffff, &mc_cmd->cmd_link);
725 writew(num_addrs * 6, &mc_cmd->mc_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +0000727 i = 0;
728 netdev_for_each_mc_addr(dmi, dev)
729 memcpy_toio(mc_cmd->mc_list[i++], dmi->dmi_addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Alan Coxa197f692008-02-08 15:27:38 +0000731 writew(make16(mc_cmd), &p->scb->cbl_offset);
732 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 ni_attn586();
734
Alan Coxa197f692008-02-08 15:27:38 +0000735 wait_for_stat_compl(mc_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Alan Coxa197f692008-02-08 15:27:38 +0000737 if ((readw(&mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK))
738 != (STAT_COMPL|STAT_OK))
739 printk(KERN_ERR "%s: Can't apply multicast-address-list.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
742 /*
743 * alloc nop/xmit-cmds
744 */
745#if (NUM_XMIT_BUFFS == 1)
Alan Coxa197f692008-02-08 15:27:38 +0000746 for (i = 0; i < 2; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000747 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000748 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
749 writew(0, &p->nop_cmds[i]->cmd_status);
750 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000751 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753#else
Alan Coxa197f692008-02-08 15:27:38 +0000754 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
Al Viro2d76c262008-03-19 09:43:29 +0000755 p->nop_cmds[i] = ptr;
Alan Coxa197f692008-02-08 15:27:38 +0000756 writew(CMD_NOP, &p->nop_cmds[i]->cmd_cmd);
757 writew(0, &p->nop_cmds[i]->cmd_status);
758 writew(make16(p->nop_cmds[i]), &p->nop_cmds[i]->cmd_link);
Al Viro2d76c262008-03-19 09:43:29 +0000759 ptr = ptr + sizeof(struct nop_cmd_struct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761#endif
762
Al Viro2d76c262008-03-19 09:43:29 +0000763 ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /*
766 * alloc xmit-buffs / init xmit_cmds
767 */
Alan Coxa197f692008-02-08 15:27:38 +0000768 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
769 /* Transmit cmd/buff 0 */
Al Viro2d76c262008-03-19 09:43:29 +0000770 p->xmit_cmds[i] = ptr;
771 ptr = ptr + sizeof(struct transmit_cmd_struct);
772 p->xmit_cbuffs[i] = ptr; /* char-buffs */
773 ptr = ptr + XMIT_BUFF_SIZE;
774 p->xmit_buffs[i] = ptr; /* TBD */
775 ptr = ptr + sizeof(struct tbd_struct);
776 if ((void __iomem *)ptr > (void __iomem *)p->iscp) {
Alan Coxa197f692008-02-08 15:27:38 +0000777 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n",
778 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return 1;
780 }
Al Viro2d76c262008-03-19 09:43:29 +0000781 memset_io(p->xmit_cmds[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000782 sizeof(struct transmit_cmd_struct));
Al Viro2d76c262008-03-19 09:43:29 +0000783 memset_io(p->xmit_buffs[i], 0,
Alan Coxa197f692008-02-08 15:27:38 +0000784 sizeof(struct tbd_struct));
785 writew(make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]),
786 &p->xmit_cmds[i]->cmd_link);
787 writew(STAT_COMPL, &p->xmit_cmds[i]->cmd_status);
788 writew(CMD_XMIT|CMD_INT, &p->xmit_cmds[i]->cmd_cmd);
789 writew(make16(p->xmit_buffs[i]), &p->xmit_cmds[i]->tbd_offset);
790 writew(0xffff, &p->xmit_buffs[i]->next);
791 writel(make24(p->xmit_cbuffs[i]), &p->xmit_buffs[i]->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793
794 p->xmit_count = 0;
795 p->xmit_last = 0;
796#ifndef NO_NOPCOMMANDS
797 p->nop_point = 0;
798#endif
799
800 /*
801 * 'start transmitter'
802 */
803#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000804 writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset);
805 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000807 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808#else
Alan Coxa197f692008-02-08 15:27:38 +0000809 writew(make16(p->xmit_cmds[0]), &p->xmit_cmds[0]->cmd_link);
810 writew(CMD_XMIT | CMD_SUSPEND | CMD_INT, &p->xmit_cmds[0]->cmd_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811#endif
812
813 /*
814 * ack. interrupts
815 */
Alan Coxa197f692008-02-08 15:27:38 +0000816 writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000818 udelay(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 ni_enaint();
821
822 return 0;
823}
824
825/******************************************************
826 * This is a helper routine for ni52_rnr_int() and init586().
827 * It sets up the Receive Frame Area (RFA).
828 */
829
Al Viro2d76c262008-03-19 09:43:29 +0000830static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Al Viro2d76c262008-03-19 09:43:29 +0000832 struct rfd_struct __iomem *rfd = ptr;
833 struct rbd_struct __iomem *rbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800835 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Al Viro2d76c262008-03-19 09:43:29 +0000837 memset_io(rfd, 0,
Alan Coxa197f692008-02-08 15:27:38 +0000838 sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 p->rfd_first = rfd;
840
Alan Coxa197f692008-02-08 15:27:38 +0000841 for (i = 0; i < (p->num_recv_buffs + rfdadd); i++) {
842 writew(make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd)),
843 &rfd[i].next);
844 writew(0xffff, &rfd[i].rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
Alan Coxa197f692008-02-08 15:27:38 +0000846 /* RU suspend */
847 writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Al Viro2d76c262008-03-19 09:43:29 +0000849 ptr = rfd + (p->num_recv_buffs + rfdadd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Al Viro2d76c262008-03-19 09:43:29 +0000851 rbd = ptr;
852 ptr = rbd + p->num_recv_buffs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* clr descriptors */
Al Viro2d76c262008-03-19 09:43:29 +0000855 memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Alan Coxa197f692008-02-08 15:27:38 +0000857 for (i = 0; i < p->num_recv_buffs; i++) {
858 writew(make16(rbd + (i+1) % p->num_recv_buffs), &rbd[i].next);
859 writew(RECV_BUFF_SIZE, &rbd[i].size);
860 writel(make24(ptr), &rbd[i].buffer);
Al Viro2d76c262008-03-19 09:43:29 +0000861 ptr = ptr + RECV_BUFF_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 p->rfd_top = p->rfd_first;
864 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
865
Alan Coxa197f692008-02-08 15:27:38 +0000866 writew(make16(p->rfd_first), &p->scb->rfa_offset);
867 writew(make16(rbd), &p->rfd_first->rbd_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 return ptr;
870}
871
872
873/**************************************************
874 * Interrupt Handler ...
875 */
876
Alan Coxa197f692008-02-08 15:27:38 +0000877static irqreturn_t ni52_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
879 struct net_device *dev = dev_id;
Alan Coxa197f692008-02-08 15:27:38 +0000880 unsigned int stat;
881 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 struct priv *p;
883
Wang Chen4cf16532008-11-12 23:38:14 -0800884 p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Alan Coxa197f692008-02-08 15:27:38 +0000886 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 printk("I");
888
Alan Coxa197f692008-02-08 15:27:38 +0000889 spin_lock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Alan Coxa197f692008-02-08 15:27:38 +0000891 wait_for_scb_cmd(dev); /* wait for last command */
892
893 while ((stat = readb(&p->scb->cus) & STAT_MASK)) {
894 writeb(stat, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 ni_attn586();
896
Alan Coxa197f692008-02-08 15:27:38 +0000897 if (stat & STAT_FR) /* received a frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 ni52_rcv_int(dev);
899
Alan Coxa197f692008-02-08 15:27:38 +0000900 if (stat & STAT_RNR) { /* RU went 'not ready' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 printk("(R)");
Alan Coxa197f692008-02-08 15:27:38 +0000902 if (readb(&p->scb->rus) & RU_SUSPEND) {
903 /* special case: RU_SUSPEND */
904 wait_for_scb_cmd(dev);
Al Viro05bd8312008-03-19 09:44:39 +0000905 writeb(RUC_RESUME, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +0000907 wait_for_scb_cmd_ruc(dev);
908 } else {
909 printk(KERN_ERR "%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
910 dev->name, stat, readb(&p->scb->rus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 ni52_rnr_int(dev);
912 }
913 }
914
Alan Coxa197f692008-02-08 15:27:38 +0000915 /* Command with I-bit set complete */
916 if (stat & STAT_CX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 ni52_xmt_int(dev);
918
919#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +0000920 if (stat & STAT_CNA) { /* CU went 'not ready' */
921 if (netif_running(dev))
922 printk(KERN_ERR "%s: oops! CU has left active state. stat: %04x/%02x.\n",
923 dev->name, stat, readb(&p->scb->cus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925#endif
926
Alan Coxa197f692008-02-08 15:27:38 +0000927 if (debuglevel > 1)
928 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Alan Coxa197f692008-02-08 15:27:38 +0000930 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
931 wait_for_scb_cmd(dev);
Al Viro05bd8312008-03-19 09:44:39 +0000932 if (readb(&p->scb->cmd_cuc)) { /* timed out? */
Alan Coxa197f692008-02-08 15:27:38 +0000933 printk(KERN_ERR "%s: Acknowledge timed out.\n",
934 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 ni_disint();
936 break;
937 }
938 }
Alan Coxa197f692008-02-08 15:27:38 +0000939 spin_unlock(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Alan Coxa197f692008-02-08 15:27:38 +0000941 if (debuglevel > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 printk("i");
943 return IRQ_HANDLED;
944}
945
946/*******************************************************
947 * receive-interrupt
948 */
949
950static void ni52_rcv_int(struct net_device *dev)
951{
Alan Coxa197f692008-02-08 15:27:38 +0000952 int status, cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 unsigned short totlen;
954 struct sk_buff *skb;
Al Viro2d76c262008-03-19 09:43:29 +0000955 struct rbd_struct __iomem *rbd;
Wang Chen4cf16532008-11-12 23:38:14 -0800956 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Alan Coxa197f692008-02-08 15:27:38 +0000958 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 printk("R");
960
Alan Coxa197f692008-02-08 15:27:38 +0000961 for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) {
Al Viro05bd8312008-03-19 09:44:39 +0000962 rbd = make32(readw(&p->rfd_top->rbd_offset));
Alan Coxa197f692008-02-08 15:27:38 +0000963 if (status & RFD_OK) { /* frame received without error? */
964 totlen = readw(&rbd->status);
965 if (totlen & RBD_LAST) {
966 /* the first and the last buffer? */
967 totlen &= RBD_MASK; /* length of this frame */
968 writew(0x00, &rbd->status);
969 skb = (struct sk_buff *)dev_alloc_skb(totlen+2);
970 if (skb != NULL) {
971 skb_reserve(skb, 2);
972 skb_put(skb, totlen);
Al Viro05bd8312008-03-19 09:44:39 +0000973 memcpy_fromio(skb->data, p->base + readl(&rbd->buffer), totlen);
Alan Coxa197f692008-02-08 15:27:38 +0000974 skb->protocol = eth_type_trans(skb, dev);
975 netif_rx(skb);
Alan Coxa197f692008-02-08 15:27:38 +0000976 p->stats.rx_packets++;
977 p->stats.rx_bytes += totlen;
978 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 p->stats.rx_dropped++;
Alan Coxa197f692008-02-08 15:27:38 +0000980 } else {
981 int rstat;
982 /* free all RBD's until RBD_LAST is set */
983 totlen = 0;
984 while (!((rstat = readw(&rbd->status)) & RBD_LAST)) {
985 totlen += rstat & RBD_MASK;
986 if (!rstat) {
987 printk(KERN_ERR "%s: Whoops .. no end mark in RBD list\n", dev->name);
988 break;
989 }
990 writew(0, &rbd->status);
Al Viro05bd8312008-03-19 09:44:39 +0000991 rbd = make32(readw(&rbd->next));
Alan Coxa197f692008-02-08 15:27:38 +0000992 }
993 totlen += rstat & RBD_MASK;
994 writew(0, &rbd->status);
995 printk(KERN_ERR "%s: received oversized frame! length: %d\n",
996 dev->name, totlen);
997 p->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
Alan Coxa197f692008-02-08 15:27:38 +0000999 } else {/* frame !(ok), only with 'save-bad-frames' */
1000 printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n",
1001 dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 p->stats.rx_errors++;
1003 }
Alan Coxa197f692008-02-08 15:27:38 +00001004 writeb(0, &p->rfd_top->stat_high);
1005 writeb(RFD_SUSP, &p->rfd_top->last); /* maybe exchange by RFD_LAST */
1006 writew(0xffff, &p->rfd_top->rbd_offset);
1007 writeb(0, &p->rfd_last->last); /* delete RFD_SUSP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 p->rfd_last = p->rfd_top;
Al Viro05bd8312008-03-19 09:44:39 +00001009 p->rfd_top = make32(readw(&p->rfd_top->next)); /* step to next RFD */
Alan Coxa197f692008-02-08 15:27:38 +00001010 writew(make16(p->rfd_top), &p->scb->rfa_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Alan Coxa197f692008-02-08 15:27:38 +00001012 if (debuglevel > 0)
1013 printk("%d", cnt++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015
Alan Coxa197f692008-02-08 15:27:38 +00001016 if (automatic_resume) {
1017 wait_for_scb_cmd(dev);
1018 writeb(RUC_RESUME, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001020 wait_for_scb_cmd_ruc(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
1022
1023#ifdef WAIT_4_BUSY
1024 {
1025 int i;
Alan Coxa197f692008-02-08 15:27:38 +00001026 for (i = 0; i < 1024; i++) {
1027 if (p->rfd_top->status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 break;
Alan Coxa197f692008-02-08 15:27:38 +00001029 udelay(16);
1030 if (i == 1023)
1031 printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033 }
1034#endif
Alan Coxa197f692008-02-08 15:27:38 +00001035 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 printk("r");
1037}
1038
1039/**********************************************************
1040 * handle 'Receiver went not ready'.
1041 */
1042
1043static void ni52_rnr_int(struct net_device *dev)
1044{
Wang Chen4cf16532008-11-12 23:38:14 -08001045 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 p->stats.rx_errors++;
1048
Alan Coxa197f692008-02-08 15:27:38 +00001049 wait_for_scb_cmd(dev); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1050 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 -07001051 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001052 wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Al Viro2d76c262008-03-19 09:43:29 +00001054 alloc_rfa(dev, p->rfd_first);
Alan Coxa197f692008-02-08 15:27:38 +00001055 /* maybe add a check here, before restarting the RU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 startrecv586(dev); /* restart RU */
1057
Al Viro05bd8312008-03-19 09:44:39 +00001058 printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n",
1059 dev->name, readb(&p->scb->rus));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061}
1062
1063/**********************************************************
1064 * handle xmit - interrupt
1065 */
1066
1067static void ni52_xmt_int(struct net_device *dev)
1068{
1069 int status;
Wang Chen4cf16532008-11-12 23:38:14 -08001070 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Alan Coxa197f692008-02-08 15:27:38 +00001072 if (debuglevel > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 printk("X");
1074
Alan Coxa197f692008-02-08 15:27:38 +00001075 status = readw(&p->xmit_cmds[p->xmit_last]->cmd_status);
1076 if (!(status & STAT_COMPL))
1077 printk(KERN_ERR "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Alan Coxa197f692008-02-08 15:27:38 +00001079 if (status & STAT_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 p->stats.tx_packets++;
1081 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
Alan Coxa197f692008-02-08 15:27:38 +00001082 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 p->stats.tx_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001084 if (status & TCMD_LATECOLL) {
1085 printk(KERN_ERR "%s: late collision detected.\n",
1086 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 p->stats.collisions++;
Alan Coxa197f692008-02-08 15:27:38 +00001088 } else if (status & TCMD_NOCARRIER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 p->stats.tx_carrier_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001090 printk(KERN_ERR "%s: no carrier detected.\n",
1091 dev->name);
1092 } else if (status & TCMD_LOSTCTS)
1093 printk(KERN_ERR "%s: loss of CTS detected.\n",
1094 dev->name);
1095 else if (status & TCMD_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 p->stats.tx_fifo_errors++;
Alan Coxa197f692008-02-08 15:27:38 +00001097 printk(KERN_ERR "%s: DMA underrun detected.\n",
1098 dev->name);
1099 } else if (status & TCMD_MAXCOLL) {
1100 printk(KERN_ERR "%s: Max. collisions exceeded.\n",
1101 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 p->stats.collisions += 16;
1103 }
1104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105#if (NUM_XMIT_BUFFS > 1)
Alan Coxa197f692008-02-08 15:27:38 +00001106 if ((++p->xmit_last) == NUM_XMIT_BUFFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 p->xmit_last = 0;
1108#endif
1109 netif_wake_queue(dev);
1110}
1111
1112/***********************************************************
1113 * (re)start the receiver
1114 */
1115
1116static void startrecv586(struct net_device *dev)
1117{
Wang Chen4cf16532008-11-12 23:38:14 -08001118 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Alan Coxa197f692008-02-08 15:27:38 +00001120 wait_for_scb_cmd(dev);
1121 wait_for_scb_cmd_ruc(dev);
1122 writew(make16(p->rfd_first), &p->scb->rfa_offset);
1123 writeb(RUC_START, &p->scb->cmd_ruc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 ni_attn586(); /* start cmd. */
Alan Coxa197f692008-02-08 15:27:38 +00001125 wait_for_scb_cmd_ruc(dev);
1126 /* wait for accept cmd. (no timeout!!) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
1129static void ni52_timeout(struct net_device *dev)
1130{
Wang Chen4cf16532008-11-12 23:38:14 -08001131 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132#ifndef NO_NOPCOMMANDS
Alan Coxa197f692008-02-08 15:27:38 +00001133 if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 netif_wake_queue(dev);
1135#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001136 printk(KERN_ERR "%s: strange ... timeout with CU active?!?\n",
1137 dev->name);
1138 printk(KERN_ERR "%s: X0: %04x N0: %04x N1: %04x %d\n",
1139 dev->name, (int)p->xmit_cmds[0]->cmd_status,
1140 readw(&p->nop_cmds[0]->cmd_status),
1141 readw(&p->nop_cmds[1]->cmd_status),
1142 p->nop_point);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143#endif
Alan Coxa197f692008-02-08 15:27:38 +00001144 writeb(CUC_ABORT, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001146 wait_for_scb_cmd(dev);
1147 writew(make16(p->nop_cmds[p->nop_point]), &p->scb->cbl_offset);
1148 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 ni_attn586();
Alan Coxa197f692008-02-08 15:27:38 +00001150 wait_for_scb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 dev->trans_start = jiffies;
1152 return 0;
1153 }
1154#endif
1155 {
1156#ifdef DEBUG
Alan Coxa197f692008-02-08 15:27:38 +00001157 printk(KERN_ERR "%s: xmitter timed out, try to restart! stat: %02x\n",
1158 dev->name, readb(&p->scb->cus));
1159 printk(KERN_ERR "%s: command-stats: %04x %04x\n",
1160 dev->name,
1161 readw(&p->xmit_cmds[0]->cmd_status),
1162 readw(&p->xmit_cmds[1]->cmd_status));
1163 printk(KERN_ERR "%s: check, whether you set the right interrupt number!\n",
1164 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165#endif
1166 ni52_close(dev);
1167 ni52_open(dev);
1168 }
1169 dev->trans_start = jiffies;
1170}
1171
1172/******************************************************
1173 * send frame
1174 */
1175
Stephen Hemminger613573252009-08-31 19:50:58 +00001176static netdev_tx_t ni52_send_packet(struct sk_buff *skb,
1177 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
Alan Coxa197f692008-02-08 15:27:38 +00001179 int len, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#ifndef NO_NOPCOMMANDS
1181 int next_nop;
1182#endif
Wang Chen4cf16532008-11-12 23:38:14 -08001183 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Alan Coxa197f692008-02-08 15:27:38 +00001185 if (skb->len > XMIT_BUFF_SIZE) {
1186 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);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001187 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189
1190 netif_stop_queue(dev);
1191
Al Viro05bd8312008-03-19 09:44:39 +00001192 memcpy_toio(p->xmit_cbuffs[p->xmit_count], skb->data, skb->len);
Alan Coxa197f692008-02-08 15:27:38 +00001193 len = skb->len;
1194 if (len < ETH_ZLEN) {
1195 len = ETH_ZLEN;
Al Viro05bd8312008-03-19 09:44:39 +00001196 memset_io(p->xmit_cbuffs[p->xmit_count]+skb->len, 0,
Alan Coxa197f692008-02-08 15:27:38 +00001197 len - skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200#if (NUM_XMIT_BUFFS == 1)
1201# ifdef NO_NOPCOMMANDS
1202
1203#ifdef DEBUG
Al Viro05bd8312008-03-19 09:44:39 +00001204 if (readb(&p->scb->cus) & CU_ACTIVE) {
Alan Coxa197f692008-02-08 15:27:38 +00001205 printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name);
1206 printk(KERN_ERR "%s: stat: %04x %04x\n",
1207 dev->name, readb(&p->scb->cus),
1208 readw(&p->xmit_cmds[0]->cmd_status));
1209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210#endif
Al Viro05bd8312008-03-19 09:44:39 +00001211 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
Alan Coxa197f692008-02-08 15:27:38 +00001212 for (i = 0; i < 16; i++) {
1213 writew(0, &p->xmit_cmds[0]->cmd_status);
1214 wait_for_scb_cmd(dev);
1215 if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND)
1216 writeb(CUC_RESUME, &p->scb->cmd_cuc);
1217 else {
1218 writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset);
1219 writeb(CUC_START, &p->scb->cmd_cuc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
Alan Coxa197f692008-02-08 15:27:38 +00001221 ni_attn586();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 dev->trans_start = jiffies;
Alan Coxa197f692008-02-08 15:27:38 +00001223 if (!i)
1224 dev_kfree_skb(skb);
1225 wait_for_scb_cmd(dev);
1226 /* test it, because CU sometimes doesn't start immediately */
1227 if (readb(&p->scb->cus) & CU_ACTIVE)
1228 break;
1229 if (readw(&p->xmit_cmds[0]->cmd_status))
1230 break;
1231 if (i == 15)
1232 printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1233 }
1234# else
1235 next_nop = (p->nop_point + 1) & 0x1;
1236 writew(TBD_LAST | len, &p->xmit_buffs[0]->size);
1237 writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link);
1238 writew(make16(p->nop_cmds[next_nop]),
1239 &p->nop_cmds[next_nop]->cmd_link);
1240 writew(0, &p->xmit_cmds[0]->cmd_status);
1241 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1242
1243 writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link);
1244 dev->trans_start = jiffies;
1245 p->nop_point = next_nop;
1246 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247# endif
1248#else
Alan Coxa197f692008-02-08 15:27:38 +00001249 writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size);
1250 next_nop = p->xmit_count + 1
1251 if (next_nop == NUM_XMIT_BUFFS)
1252 next_nop = 0;
1253 writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status);
1254 /* linkpointer of xmit-command already points to next nop cmd */
1255 writew(make16(p->nop_cmds[next_nop]),
1256 &p->nop_cmds[next_nop]->cmd_link);
1257 writew(0, &p->nop_cmds[next_nop]->cmd_status);
1258 writew(make16(p->xmit_cmds[p->xmit_count]),
1259 &p->nop_cmds[p->xmit_count]->cmd_link);
1260 dev->trans_start = jiffies;
1261 p->xmit_count = next_nop;
1262 {
1263 unsigned long flags;
1264 spin_lock_irqsave(&p->spinlock);
1265 if (p->xmit_count != p->xmit_last)
1266 netif_wake_queue(dev);
1267 spin_unlock_irqrestore(&p->spinlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 }
Alan Coxa197f692008-02-08 15:27:38 +00001269 dev_kfree_skb(skb);
1270#endif
Patrick McHardyec634fe2009-07-05 19:23:38 -07001271 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
1274/*******************************************
1275 * Someone wanna have the statistics
1276 */
1277
1278static struct net_device_stats *ni52_get_stats(struct net_device *dev)
1279{
Wang Chen4cf16532008-11-12 23:38:14 -08001280 struct priv *p = netdev_priv(dev);
Alan Coxa197f692008-02-08 15:27:38 +00001281 unsigned short crc, aln, rsc, ovrn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
Alan Coxa197f692008-02-08 15:27:38 +00001283 /* Get error-statistics from the ni82586 */
1284 crc = readw(&p->scb->crc_errs);
1285 writew(0, &p->scb->crc_errs);
1286 aln = readw(&p->scb->aln_errs);
1287 writew(0, &p->scb->aln_errs);
1288 rsc = readw(&p->scb->rsc_errs);
1289 writew(0, &p->scb->rsc_errs);
1290 ovrn = readw(&p->scb->ovrn_errs);
1291 writew(0, &p->scb->ovrn_errs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 p->stats.rx_crc_errors += crc;
1294 p->stats.rx_fifo_errors += ovrn;
1295 p->stats.rx_frame_errors += aln;
1296 p->stats.rx_dropped += rsc;
1297
1298 return &p->stats;
1299}
1300
1301/********************************************************
1302 * Set MC list ..
1303 */
1304
1305static void set_multicast_list(struct net_device *dev)
1306{
1307 netif_stop_queue(dev);
1308 ni_disint();
1309 alloc586(dev);
1310 init586(dev);
1311 startrecv586(dev);
1312 ni_enaint();
1313 netif_wake_queue(dev);
1314}
1315
1316#ifdef MODULE
1317static struct net_device *dev_ni52;
1318
1319module_param(io, int, 0);
1320module_param(irq, int, 0);
1321module_param(memstart, long, 0);
1322module_param(memend, long, 0);
1323MODULE_PARM_DESC(io, "NI5210 I/O base address,required");
1324MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1325MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1326MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1327
Andrew Morton19a86642006-08-14 23:00:05 -07001328int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
Alan Coxa197f692008-02-08 15:27:38 +00001330 if (io <= 0x0 || !memend || !memstart || irq < 2) {
1331 printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n");
1332 printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 return -ENODEV;
1334 }
1335 dev_ni52 = ni52_probe(-1);
1336 if (IS_ERR(dev_ni52))
1337 return PTR_ERR(dev_ni52);
1338 return 0;
1339}
1340
Al Viroafc8eb42006-06-14 18:50:53 -04001341void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342{
Wang Chen4cf16532008-11-12 23:38:14 -08001343 struct priv *p = netdev_priv(dev_ni52);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 unregister_netdev(dev_ni52);
Al Viro176f65f2008-03-19 09:44:29 +00001345 iounmap(p->mapped);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
1347 free_netdev(dev_ni52);
1348}
1349#endif /* MODULE */
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351MODULE_LICENSE("GPL");