Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * net-3-driver for the NI5210 card (i82586 Ethernet chip) | |
3 | * | |
4 | * This is an extension to the Linux operating system, and is covered by the | |
5 | * same GNU General Public License that covers that work. | |
6 | * | |
7 | * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later) | |
8 | * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de) | |
9 | * [feel free to mail ....] | |
10 | * | |
11 | * when using as module: (no autoprobing!) | |
1da177e4 LT |
12 | * run with e.g: |
13 | * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000 | |
14 | * | |
15 | * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!. | |
16 | * | |
17 | * If you find a bug, please report me: | |
18 | * The kernel panic output and any kmsg from the ni52 driver | |
19 | * the ni5210-driver-version and the linux-kernel version | |
20 | * how many shared memory (memsize) on the netcard, | |
21 | * bootprom: yes/no, base_addr, mem_start | |
22 | * maybe the ni5210-card revision and the i82586 version | |
23 | * | |
24 | * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340 | |
25 | * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000, | |
26 | * 0xd8000,0xcc000,0xce000,0xda000,0xdc000 | |
27 | * | |
28 | * sources: | |
29 | * skeleton.c from Donald Becker | |
30 | * | |
31 | * I have also done a look in the following sources: (mail me if you need them) | |
32 | * crynwr-packet-driver by Russ Nelson | |
33 | * Garret A. Wollman's (fourth) i82586-driver for BSD | |
a197f693 AC |
34 | * (before getting an i82596 (yes 596 not 586) manual, the existing drivers |
35 | * helped me a lot to understand this tricky chip.) | |
1da177e4 LT |
36 | * |
37 | * Known Problems: | |
38 | * The internal sysbus seems to be slow. So we often lose packets because of | |
39 | * overruns while receiving from a fast remote host. | |
a197f693 AC |
40 | * This can slow down TCP connections. Maybe the newer ni5210 cards are |
41 | * better. My experience is, that if a machine sends with more than about | |
42 | * 500-600K/s the fifo/sysbus overflows. | |
1da177e4 LT |
43 | * |
44 | * IMPORTANT NOTE: | |
45 | * On fast networks, it's a (very) good idea to have 16K shared memory. With | |
a197f693 AC |
46 | * 8K, we can store only 4 receive frames, so it can (easily) happen that a |
47 | * remote machine 'overruns' our system. | |
1da177e4 LT |
48 | * |
49 | * Known i82586/card problems (I'm sure, there are many more!): | |
50 | * Running the NOP-mode, the i82586 sometimes seems to forget to report | |
51 | * every xmit-interrupt until we restart the CU. | |
52 | * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit | |
53 | * in the RBD-Struct which indicates an end of the RBD queue. | |
54 | * Instead, the RU fetches another (randomly selected and | |
55 | * usually used) RBD and begins to fill it. (Maybe, this happens only if | |
56 | * the last buffer from the previous RFD fits exact into the queue and | |
57 | * the next RFD can't fetch an initial RBD. Anyone knows more? ) | |
58 | * | |
59 | * results from ftp performance tests with Linux 1.2.5 | |
60 | * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s) | |
a197f693 AC |
61 | * sending in NOP-mode: peak performance up to 530K/s (but better don't |
62 | * run this mode) | |
1da177e4 LT |
63 | */ |
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 | * | |
a197f693 AC |
96 | * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, |
97 | * too (MH) | |
1da177e4 LT |
98 | * |
99 | * < 30.Sep.93: first versions | |
100 | */ | |
101 | ||
102 | static int debuglevel; /* debug-printk 0: off 1: a few 2: more */ | |
103 | static int automatic_resume; /* experimental .. better should be zero */ | |
104 | static int rfdadd; /* rfdadd=1 may be better for 8K MEM cards */ | |
a197f693 | 105 | static int fifo = 0x8; /* don't change */ |
1da177e4 | 106 | |
1da177e4 LT |
107 | #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 | ||
a197f693 AC |
130 | #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); } | |
1da177e4 | 134 | |
05bd831f | 135 | #define make32(ptr16) ((void __iomem *)(p->memtop + (short) (ptr16))) |
e06ee2bb AV |
136 | #define make24(ptr32) ((char __iomem *)(ptr32)) - p->base |
137 | #define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\ | |
138 | - p->memtop)) | |
1da177e4 LT |
139 | |
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 | ||
146 | sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8; | |
147 | sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT | |
148 | sizeof(rfd) = 24; sizeof(rbd) = 12; | |
149 | sizeof(tbd) = 8; sizeof(transmit_cmd) = 16; | |
150 | sizeof(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 | ||
1da177e4 LT |
163 | |
164 | #define NI52_TOTAL_SIZE 16 | |
165 | #define NI52_ADDR0 0x02 | |
166 | #define NI52_ADDR1 0x07 | |
167 | #define NI52_ADDR2 0x01 | |
168 | ||
a197f693 AC |
169 | static int ni52_probe1(struct net_device *dev, int ioaddr); |
170 | static irqreturn_t ni52_interrupt(int irq, void *dev_id); | |
1da177e4 LT |
171 | static int ni52_open(struct net_device *dev); |
172 | static int ni52_close(struct net_device *dev); | |
a197f693 | 173 | static int ni52_send_packet(struct sk_buff *, struct net_device *); |
1da177e4 LT |
174 | static struct net_device_stats *ni52_get_stats(struct net_device *dev); |
175 | static void set_multicast_list(struct net_device *dev); | |
176 | static void ni52_timeout(struct net_device *dev); | |
1da177e4 LT |
177 | |
178 | /* helper-functions */ | |
179 | static int init586(struct net_device *dev); | |
de597146 | 180 | static int check586(struct net_device *dev, unsigned size); |
1da177e4 LT |
181 | static void alloc586(struct net_device *dev); |
182 | static void startrecv586(struct net_device *dev); | |
2d76c267 | 183 | static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr); |
1da177e4 LT |
184 | static void ni52_rcv_int(struct net_device *dev); |
185 | static void ni52_xmt_int(struct net_device *dev); | |
186 | static void ni52_rnr_int(struct net_device *dev); | |
187 | ||
a197f693 | 188 | struct priv { |
1da177e4 | 189 | struct net_device_stats stats; |
e06ee2bb AV |
190 | char __iomem *base; |
191 | char __iomem *mapped; | |
2d76c267 | 192 | char __iomem *memtop; |
a197f693 AC |
193 | spinlock_t spinlock; |
194 | int reset; | |
2d76c267 AV |
195 | 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]; | |
1da177e4 | 200 | #if (NUM_XMIT_BUFFS == 1) |
2d76c267 AV |
201 | struct transmit_cmd_struct __iomem *xmit_cmds[2]; |
202 | struct nop_cmd_struct __iomem *nop_cmds[2]; | |
1da177e4 | 203 | #else |
2d76c267 AV |
204 | struct transmit_cmd_struct __iomem *xmit_cmds[NUM_XMIT_BUFFS]; |
205 | struct nop_cmd_struct __iomem *nop_cmds[NUM_XMIT_BUFFS]; | |
1da177e4 | 206 | #endif |
a197f693 | 207 | int nop_point, num_recv_buffs; |
2d76c267 | 208 | char __iomem *xmit_cbuffs[NUM_XMIT_BUFFS]; |
a197f693 | 209 | int xmit_count, xmit_last; |
1da177e4 LT |
210 | }; |
211 | ||
a197f693 AC |
212 | /* wait for command with timeout: */ |
213 | static void wait_for_scb_cmd(struct net_device *dev) | |
214 | { | |
4cf1653a | 215 | struct priv *p = netdev_priv(dev); |
a197f693 AC |
216 | 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 | ||
232 | static void wait_for_scb_cmd_ruc(struct net_device *dev) | |
233 | { | |
4cf1653a | 234 | struct priv *p = netdev_priv(dev); |
a197f693 AC |
235 | 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", | |
05bd831f AV |
242 | dev->name, readb(&p->scb->cmd_ruc), |
243 | readb(&p->scb->rus)); | |
a197f693 AC |
244 | if (!p->reset) { |
245 | p->reset = 1; | |
246 | ni_reset586(); | |
247 | } | |
248 | } | |
249 | } | |
250 | } | |
251 | ||
2d76c267 | 252 | static void wait_for_stat_compl(void __iomem *p) |
a197f693 | 253 | { |
2d76c267 | 254 | struct nop_cmd_struct __iomem *addr = p; |
a197f693 AC |
255 | 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 | ||
1da177e4 LT |
263 | /********************************************** |
264 | * close device | |
265 | */ | |
266 | static int ni52_close(struct net_device *dev) | |
267 | { | |
268 | free_irq(dev->irq, dev); | |
1da177e4 | 269 | ni_reset586(); /* the hard way to stop the receiver */ |
1da177e4 | 270 | netif_stop_queue(dev); |
1da177e4 LT |
271 | return 0; |
272 | } | |
273 | ||
274 | /********************************************** | |
275 | * open device | |
276 | */ | |
277 | static 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 | ||
a197f693 AC |
287 | ret = request_irq(dev->irq, &ni52_interrupt, 0, dev->name, dev); |
288 | if (ret) { | |
1da177e4 LT |
289 | ni_reset586(); |
290 | return ret; | |
291 | } | |
1da177e4 | 292 | netif_start_queue(dev); |
1da177e4 LT |
293 | return 0; /* most done by init */ |
294 | } | |
295 | ||
76af5699 AV |
296 | static int check_iscp(struct net_device *dev, void __iomem *addr) |
297 | { | |
298 | struct iscp_struct __iomem *iscp = addr; | |
4cf1653a | 299 | struct priv *p = netdev_priv(dev); |
76af5699 AV |
300 | 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 | ||
1da177e4 LT |
314 | /********************************************** |
315 | * Check to see if there's an 82586 out there. | |
316 | */ | |
de597146 | 317 | static int check586(struct net_device *dev, unsigned size) |
1da177e4 | 318 | { |
4cf1653a | 319 | struct priv *p = netdev_priv(dev); |
1da177e4 LT |
320 | int i; |
321 | ||
176f65f3 AV |
322 | p->mapped = ioremap(dev->mem_start, size); |
323 | if (!p->mapped) | |
324 | return 0; | |
325 | ||
e06ee2bb AV |
326 | p->base = p->mapped + size - 0x01000000; |
327 | p->memtop = p->mapped + size; | |
2d76c267 | 328 | p->scp = (struct scp_struct __iomem *)(p->base + SCP_DEFAULT_ADDRESS); |
7f8cfd56 | 329 | p->scb = (struct scb_struct __iomem *) p->mapped; |
76af5699 | 330 | p->iscp = (struct iscp_struct __iomem *)p->scp - 1; |
2d76c267 | 331 | memset_io(p->scp, 0, sizeof(struct scp_struct)); |
a197f693 AC |
332 | for (i = 0; i < sizeof(struct scp_struct); i++) |
333 | /* memory was writeable? */ | |
2d76c267 | 334 | if (readb((char __iomem *)p->scp + i)) |
176f65f3 | 335 | goto Enodev; |
a197f693 AC |
336 | writeb(SYSBUSVAL, &p->scp->sysbus); /* 1 = 8Bit-Bus, 0 = 16 Bit */ |
337 | if (readb(&p->scp->sysbus) != SYSBUSVAL) | |
176f65f3 | 338 | goto Enodev; |
1da177e4 | 339 | |
76af5699 | 340 | if (!check_iscp(dev, p->mapped)) |
176f65f3 | 341 | goto Enodev; |
76af5699 | 342 | if (!check_iscp(dev, p->iscp)) |
176f65f3 | 343 | goto Enodev; |
1da177e4 | 344 | return 1; |
176f65f3 AV |
345 | Enodev: |
346 | iounmap(p->mapped); | |
347 | return 0; | |
1da177e4 LT |
348 | } |
349 | ||
350 | /****************************************************************** | |
351 | * set iscp at the right place, called by ni52_probe1 and open586. | |
352 | */ | |
353 | static void alloc586(struct net_device *dev) | |
354 | { | |
4cf1653a | 355 | struct priv *p = netdev_priv(dev); |
1da177e4 LT |
356 | |
357 | ni_reset586(); | |
a197f693 AC |
358 | mdelay(32); |
359 | ||
a197f693 AC |
360 | memset_io(p->iscp, 0, sizeof(struct iscp_struct)); |
361 | memset_io(p->scp , 0, sizeof(struct scp_struct)); | |
1da177e4 | 362 | |
a197f693 AC |
363 | writel(make24(p->iscp), &p->scp->iscp); |
364 | writeb(SYSBUSVAL, &p->scp->sysbus); | |
365 | writew(make16(p->scb), &p->iscp->scb_offset); | |
1da177e4 | 366 | |
a197f693 | 367 | writeb(1, &p->iscp->busy); |
1da177e4 LT |
368 | ni_reset586(); |
369 | ni_attn586(); | |
370 | ||
a197f693 | 371 | mdelay(32); |
1da177e4 | 372 | |
a197f693 AC |
373 | if (readb(&p->iscp->busy)) |
374 | printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); | |
1da177e4 | 375 | |
a197f693 | 376 | p->reset = 0; |
1da177e4 | 377 | |
2d76c267 | 378 | memset_io(p->scb, 0, sizeof(struct scb_struct)); |
1da177e4 LT |
379 | } |
380 | ||
381 | /* set: io,irq,memstart,memend or set it when calling insmod */ | |
a197f693 AC |
382 | static int irq = 9; |
383 | static int io = 0x300; | |
1da177e4 LT |
384 | static long memstart; /* e.g 0xd0000 */ |
385 | static long memend; /* e.g 0xd4000 */ | |
386 | ||
387 | /********************************************** | |
388 | * probe the ni5210-card | |
389 | */ | |
390 | struct 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}; | |
176f65f3 | 394 | struct priv *p; |
1da177e4 LT |
395 | int *port; |
396 | int err = 0; | |
397 | ||
398 | if (!dev) | |
399 | return ERR_PTR(-ENOMEM); | |
400 | ||
4cf1653a | 401 | p = netdev_priv(dev); |
176f65f3 | 402 | |
1da177e4 LT |
403 | 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 | ||
1da177e4 LT |
412 | 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; | |
431 | got_it: | |
432 | err = register_netdev(dev); | |
433 | if (err) | |
434 | goto out1; | |
435 | return dev; | |
436 | out1: | |
176f65f3 | 437 | iounmap(p->mapped); |
1da177e4 LT |
438 | release_region(dev->base_addr, NI52_TOTAL_SIZE); |
439 | out: | |
440 | free_netdev(dev); | |
441 | return ERR_PTR(err); | |
442 | } | |
443 | ||
2c7669e3 SH |
444 | static 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 | ||
a197f693 | 456 | static int __init ni52_probe1(struct net_device *dev, int ioaddr) |
1da177e4 LT |
457 | { |
458 | int i, size, retval; | |
4cf1653a | 459 | struct priv *priv = netdev_priv(dev); |
1da177e4 LT |
460 | |
461 | dev->base_addr = ioaddr; | |
462 | dev->irq = irq; | |
463 | dev->mem_start = memstart; | |
464 | dev->mem_end = memend; | |
465 | ||
7f8cfd56 AV |
466 | spin_lock_init(&priv->spinlock); |
467 | ||
1da177e4 LT |
468 | if (!request_region(ioaddr, NI52_TOTAL_SIZE, DRV_NAME)) |
469 | return -EBUSY; | |
470 | ||
a197f693 | 471 | if (!(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) || |
1da177e4 LT |
472 | !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2)) { |
473 | retval = -ENODEV; | |
474 | goto out; | |
475 | } | |
476 | ||
a197f693 | 477 | for (i = 0; i < ETH_ALEN; i++) |
1da177e4 LT |
478 | dev->dev_addr[i] = inb(dev->base_addr+i); |
479 | ||
a197f693 | 480 | if (dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1 |
1da177e4 LT |
481 | || dev->dev_addr[2] != NI52_ADDR2) { |
482 | retval = -ENODEV; | |
483 | goto out; | |
484 | } | |
485 | ||
a197f693 AC |
486 | printk(KERN_INFO "%s: NI5210 found at %#3lx, ", |
487 | dev->name, dev->base_addr); | |
1da177e4 LT |
488 | |
489 | /* | |
490 | * check (or search) IO-Memory, 8K and 16K | |
491 | */ | |
492 | #ifdef MODULE | |
493 | size = dev->mem_end - dev->mem_start; | |
a197f693 AC |
494 | 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); | |
1da177e4 LT |
497 | retval = -ENODEV; |
498 | goto out; | |
499 | } | |
de597146 | 500 | if (!check586(dev, size)) { |
a197f693 | 501 | printk(KERN_ERR "?memcheck, Can't find memory at 0x%lx with size %d!\n", dev->mem_start, size); |
1da177e4 LT |
502 | retval = -ENODEV; |
503 | goto out; | |
504 | } | |
505 | #else | |
a197f693 AC |
506 | if (dev->mem_start != 0) { |
507 | /* no auto-mem-probe */ | |
1da177e4 | 508 | size = 0x4000; /* check for 16K mem */ |
de597146 | 509 | if (!check586(dev, size)) { |
1da177e4 | 510 | size = 0x2000; /* check for 8K mem */ |
de597146 | 511 | if (!check586(dev, size)) { |
a197f693 | 512 | printk(KERN_ERR "?memprobe, Can't find memory at 0x%lx!\n", dev->mem_start); |
1da177e4 LT |
513 | retval = -ENODEV; |
514 | goto out; | |
515 | } | |
516 | } | |
a197f693 AC |
517 | } 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"); | |
1da177e4 LT |
525 | retval = -ENODEV; |
526 | goto out; | |
527 | } | |
528 | dev->mem_start = memaddrs[i]; | |
529 | size = 0x2000; /* check for 8K mem */ | |
de597146 | 530 | if (check586(dev, size)) |
a197f693 | 531 | /* 8K-check */ |
1da177e4 LT |
532 | break; |
533 | size = 0x4000; /* check for 16K mem */ | |
de597146 | 534 | if (check586(dev, size)) |
a197f693 | 535 | /* 16K-check */ |
1da177e4 LT |
536 | break; |
537 | } | |
538 | } | |
a197f693 AC |
539 | /* set mem_end showed by 'ifconfig' */ |
540 | dev->mem_end = dev->mem_start + size; | |
1da177e4 LT |
541 | #endif |
542 | ||
1da177e4 LT |
543 | alloc586(dev); |
544 | ||
545 | /* set number of receive-buffs according to memsize */ | |
a197f693 | 546 | if (size == 0x2000) |
e06ee2bb | 547 | priv->num_recv_buffs = NUM_RECV_BUFFS_8; |
1da177e4 | 548 | else |
e06ee2bb | 549 | priv->num_recv_buffs = NUM_RECV_BUFFS_16; |
1da177e4 | 550 | |
a197f693 AC |
551 | printk(KERN_DEBUG "Memaddr: 0x%lx, Memsize: %d, ", |
552 | dev->mem_start, size); | |
1da177e4 | 553 | |
a197f693 | 554 | if (dev->irq < 2) { |
1da177e4 LT |
555 | 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); | |
a197f693 | 563 | if (!dev->irq) { |
1da177e4 LT |
564 | printk("?autoirq, Failed to detect IRQ line!\n"); |
565 | retval = -EAGAIN; | |
176f65f3 | 566 | iounmap(priv->mapped); |
1da177e4 LT |
567 | goto out; |
568 | } | |
a197f693 AC |
569 | printk("IRQ %d (autodetected).\n", dev->irq); |
570 | } else { | |
571 | if (dev->irq == 2) | |
1da177e4 | 572 | dev->irq = 9; |
a197f693 | 573 | printk("IRQ %d (assigned and not checked!).\n", dev->irq); |
1da177e4 LT |
574 | } |
575 | ||
2c7669e3 | 576 | dev->netdev_ops = &ni52_netdev_ops; |
1da177e4 | 577 | dev->watchdog_timeo = HZ/20; |
1da177e4 LT |
578 | |
579 | return 0; | |
580 | out: | |
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 | ||
590 | static int init586(struct net_device *dev) | |
591 | { | |
2d76c267 | 592 | void __iomem *ptr; |
a197f693 | 593 | int i, result = 0; |
4cf1653a | 594 | struct priv *p = netdev_priv(dev); |
2d76c267 AV |
595 | 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; | |
a197f693 AC |
599 | struct dev_mc_list *dmi = dev->mc_list; |
600 | int num_addrs = dev->mc_count; | |
1da177e4 | 601 | |
2d76c267 | 602 | ptr = p->scb + 1; |
1da177e4 | 603 | |
2d76c267 | 604 | cfg_cmd = ptr; /* configure-command */ |
a197f693 AC |
605 | writew(0, &cfg_cmd->cmd_status); |
606 | writew(CMD_CONFIGURE | CMD_LAST, &cfg_cmd->cmd_cmd); | |
607 | writew(0xFFFF, &cfg_cmd->cmd_link); | |
608 | ||
609 | /* 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); | |
618 | writeb(0x60, &cfg_cmd->ifs);; | |
619 | writeb(0x00, &cfg_cmd->time_low); | |
620 | writeb(0xf2, &cfg_cmd->time_high); | |
621 | writeb(0x00, &cfg_cmd->promisc);; | |
622 | if (dev->flags & IFF_ALLMULTI) { | |
2d76c267 | 623 | int len = ((char __iomem *)p->iscp - (char __iomem *)ptr - 8) / 6; |
a197f693 AC |
624 | if (num_addrs > len) { |
625 | printk(KERN_ERR "%s: switching to promisc. mode\n", | |
626 | dev->name); | |
c16d1185 | 627 | writeb(0x01, &cfg_cmd->promisc); |
1da177e4 LT |
628 | } |
629 | } | |
a197f693 AC |
630 | 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); | |
05bd831f | 634 | writeb(0, &p->scb->cmd_ruc); |
1da177e4 | 635 | |
a197f693 | 636 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
1da177e4 LT |
637 | ni_attn586(); |
638 | ||
a197f693 | 639 | wait_for_stat_compl(cfg_cmd); |
1da177e4 | 640 | |
a197f693 AC |
641 | 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)); | |
1da177e4 LT |
645 | return 1; |
646 | } | |
647 | ||
648 | /* | |
649 | * individual address setup | |
650 | */ | |
651 | ||
2d76c267 | 652 | ias_cmd = ptr; |
1da177e4 | 653 | |
a197f693 AC |
654 | writew(0, &ias_cmd->cmd_status); |
655 | writew(CMD_IASETUP | CMD_LAST, &ias_cmd->cmd_cmd); | |
656 | writew(0xffff, &ias_cmd->cmd_link); | |
1da177e4 | 657 | |
2d76c267 | 658 | memcpy_toio(&ias_cmd->iaddr, (char *)dev->dev_addr, ETH_ALEN); |
1da177e4 | 659 | |
a197f693 | 660 | writew(make16(ias_cmd), &p->scb->cbl_offset); |
1da177e4 | 661 | |
a197f693 | 662 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ |
1da177e4 LT |
663 | ni_attn586(); |
664 | ||
a197f693 | 665 | wait_for_stat_compl(ias_cmd); |
1da177e4 | 666 | |
a197f693 AC |
667 | 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)); | |
1da177e4 LT |
670 | return 1; |
671 | } | |
672 | ||
673 | /* | |
674 | * TDR, wire check .. e.g. no resistor e.t.c | |
675 | */ | |
6aa20a22 | 676 | |
2d76c267 | 677 | tdr_cmd = ptr; |
1da177e4 | 678 | |
a197f693 AC |
679 | 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); | |
1da177e4 | 683 | |
a197f693 AC |
684 | writew(make16(tdr_cmd), &p->scb->cbl_offset); |
685 | writeb(CUC_START, &p->scb->cmd_cuc); /* cmd.-unit start */ | |
1da177e4 LT |
686 | ni_attn586(); |
687 | ||
a197f693 | 688 | wait_for_stat_compl(tdr_cmd); |
1da177e4 | 689 | |
a197f693 AC |
690 | 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); | |
1da177e4 LT |
697 | ni_attn586(); /* ack the interrupts */ |
698 | ||
a197f693 | 699 | if (result & TDR_LNK_OK) |
1da177e4 | 700 | ; |
a197f693 AC |
701 | 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); | |
1da177e4 LT |
715 | } |
716 | ||
717 | /* | |
718 | * Multicast setup | |
719 | */ | |
a197f693 | 720 | if (num_addrs && !(dev->flags & IFF_PROMISC)) { |
2d76c267 | 721 | mc_cmd = ptr; |
a197f693 AC |
722 | 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); | |
1da177e4 | 726 | |
a197f693 | 727 | for (i = 0; i < num_addrs; i++, dmi = dmi->next) |
2d76c267 | 728 | memcpy_toio(mc_cmd->mc_list[i], |
a197f693 | 729 | dmi->dmi_addr, 6); |
1da177e4 | 730 | |
a197f693 AC |
731 | writew(make16(mc_cmd), &p->scb->cbl_offset); |
732 | writeb(CUC_START, &p->scb->cmd_cuc); | |
1da177e4 LT |
733 | ni_attn586(); |
734 | ||
a197f693 | 735 | wait_for_stat_compl(mc_cmd); |
1da177e4 | 736 | |
a197f693 AC |
737 | 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); | |
1da177e4 LT |
740 | } |
741 | ||
742 | /* | |
743 | * alloc nop/xmit-cmds | |
744 | */ | |
745 | #if (NUM_XMIT_BUFFS == 1) | |
a197f693 | 746 | for (i = 0; i < 2; i++) { |
2d76c267 | 747 | p->nop_cmds[i] = ptr; |
a197f693 AC |
748 | 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); | |
2d76c267 | 751 | ptr = ptr + sizeof(struct nop_cmd_struct); |
1da177e4 LT |
752 | } |
753 | #else | |
a197f693 | 754 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
2d76c267 | 755 | p->nop_cmds[i] = ptr; |
a197f693 AC |
756 | 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); | |
2d76c267 | 759 | ptr = ptr + sizeof(struct nop_cmd_struct); |
1da177e4 LT |
760 | } |
761 | #endif | |
762 | ||
2d76c267 | 763 | ptr = alloc_rfa(dev, ptr); /* init receive-frame-area */ |
1da177e4 LT |
764 | |
765 | /* | |
766 | * alloc xmit-buffs / init xmit_cmds | |
767 | */ | |
a197f693 AC |
768 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
769 | /* Transmit cmd/buff 0 */ | |
2d76c267 AV |
770 | 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) { | |
a197f693 AC |
777 | printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", |
778 | dev->name); | |
1da177e4 LT |
779 | return 1; |
780 | } | |
2d76c267 | 781 | memset_io(p->xmit_cmds[i], 0, |
a197f693 | 782 | sizeof(struct transmit_cmd_struct)); |
2d76c267 | 783 | memset_io(p->xmit_buffs[i], 0, |
a197f693 AC |
784 | 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); | |
1da177e4 LT |
792 | } |
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 | |
a197f693 AC |
804 | writew(make16(p->nop_cmds[0]), &p->scb->cbl_offset); |
805 | writeb(CUC_START, &p->scb->cmd_cuc); | |
1da177e4 | 806 | ni_attn586(); |
a197f693 | 807 | wait_for_scb_cmd(dev); |
1da177e4 | 808 | #else |
a197f693 AC |
809 | 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); | |
1da177e4 LT |
811 | #endif |
812 | ||
813 | /* | |
814 | * ack. interrupts | |
815 | */ | |
a197f693 | 816 | writeb(readb(&p->scb->cus) & STAT_MASK, &p->scb->cmd_cuc); |
1da177e4 | 817 | ni_attn586(); |
a197f693 | 818 | udelay(16); |
1da177e4 LT |
819 | |
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 | ||
2d76c267 | 830 | static void __iomem *alloc_rfa(struct net_device *dev, void __iomem *ptr) |
1da177e4 | 831 | { |
2d76c267 AV |
832 | struct rfd_struct __iomem *rfd = ptr; |
833 | struct rbd_struct __iomem *rbd; | |
1da177e4 | 834 | int i; |
4cf1653a | 835 | struct priv *p = netdev_priv(dev); |
1da177e4 | 836 | |
2d76c267 | 837 | memset_io(rfd, 0, |
a197f693 | 838 | sizeof(struct rfd_struct) * (p->num_recv_buffs + rfdadd)); |
1da177e4 LT |
839 | p->rfd_first = rfd; |
840 | ||
a197f693 AC |
841 | 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); | |
1da177e4 | 845 | } |
a197f693 AC |
846 | /* RU suspend */ |
847 | writeb(RFD_SUSP, &rfd[p->num_recv_buffs-1+rfdadd].last); | |
1da177e4 | 848 | |
2d76c267 | 849 | ptr = rfd + (p->num_recv_buffs + rfdadd); |
1da177e4 | 850 | |
2d76c267 AV |
851 | rbd = ptr; |
852 | ptr = rbd + p->num_recv_buffs; | |
1da177e4 LT |
853 | |
854 | /* clr descriptors */ | |
2d76c267 | 855 | memset_io(rbd, 0, sizeof(struct rbd_struct) * (p->num_recv_buffs)); |
1da177e4 | 856 | |
a197f693 AC |
857 | 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); | |
2d76c267 | 861 | ptr = ptr + RECV_BUFF_SIZE; |
1da177e4 | 862 | } |
1da177e4 LT |
863 | p->rfd_top = p->rfd_first; |
864 | p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); | |
865 | ||
a197f693 AC |
866 | writew(make16(p->rfd_first), &p->scb->rfa_offset); |
867 | writew(make16(rbd), &p->rfd_first->rbd_offset); | |
1da177e4 LT |
868 | |
869 | return ptr; | |
870 | } | |
871 | ||
872 | ||
873 | /************************************************** | |
874 | * Interrupt Handler ... | |
875 | */ | |
876 | ||
a197f693 | 877 | static irqreturn_t ni52_interrupt(int irq, void *dev_id) |
1da177e4 LT |
878 | { |
879 | struct net_device *dev = dev_id; | |
a197f693 AC |
880 | unsigned int stat; |
881 | int cnt = 0; | |
1da177e4 LT |
882 | struct priv *p; |
883 | ||
4cf1653a | 884 | p = netdev_priv(dev); |
1da177e4 | 885 | |
a197f693 | 886 | if (debuglevel > 1) |
1da177e4 LT |
887 | printk("I"); |
888 | ||
a197f693 | 889 | spin_lock(&p->spinlock); |
1da177e4 | 890 | |
a197f693 AC |
891 | 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); | |
1da177e4 LT |
895 | ni_attn586(); |
896 | ||
a197f693 | 897 | if (stat & STAT_FR) /* received a frame */ |
1da177e4 LT |
898 | ni52_rcv_int(dev); |
899 | ||
a197f693 | 900 | if (stat & STAT_RNR) { /* RU went 'not ready' */ |
1da177e4 | 901 | printk("(R)"); |
a197f693 AC |
902 | if (readb(&p->scb->rus) & RU_SUSPEND) { |
903 | /* special case: RU_SUSPEND */ | |
904 | wait_for_scb_cmd(dev); | |
05bd831f | 905 | writeb(RUC_RESUME, &p->scb->cmd_ruc); |
1da177e4 | 906 | ni_attn586(); |
a197f693 AC |
907 | 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)); | |
1da177e4 LT |
911 | ni52_rnr_int(dev); |
912 | } | |
913 | } | |
914 | ||
a197f693 AC |
915 | /* Command with I-bit set complete */ |
916 | if (stat & STAT_CX) | |
1da177e4 LT |
917 | ni52_xmt_int(dev); |
918 | ||
919 | #ifndef NO_NOPCOMMANDS | |
a197f693 AC |
920 | 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)); | |
1da177e4 LT |
924 | } |
925 | #endif | |
926 | ||
a197f693 AC |
927 | if (debuglevel > 1) |
928 | printk("%d", cnt++); | |
1da177e4 | 929 | |
a197f693 AC |
930 | /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */ |
931 | wait_for_scb_cmd(dev); | |
05bd831f | 932 | if (readb(&p->scb->cmd_cuc)) { /* timed out? */ |
a197f693 AC |
933 | printk(KERN_ERR "%s: Acknowledge timed out.\n", |
934 | dev->name); | |
1da177e4 LT |
935 | ni_disint(); |
936 | break; | |
937 | } | |
938 | } | |
a197f693 | 939 | spin_unlock(&p->spinlock); |
1da177e4 | 940 | |
a197f693 | 941 | if (debuglevel > 1) |
1da177e4 LT |
942 | printk("i"); |
943 | return IRQ_HANDLED; | |
944 | } | |
945 | ||
946 | /******************************************************* | |
947 | * receive-interrupt | |
948 | */ | |
949 | ||
950 | static void ni52_rcv_int(struct net_device *dev) | |
951 | { | |
a197f693 | 952 | int status, cnt = 0; |
1da177e4 LT |
953 | unsigned short totlen; |
954 | struct sk_buff *skb; | |
2d76c267 | 955 | struct rbd_struct __iomem *rbd; |
4cf1653a | 956 | struct priv *p = netdev_priv(dev); |
1da177e4 | 957 | |
a197f693 | 958 | if (debuglevel > 0) |
1da177e4 LT |
959 | printk("R"); |
960 | ||
a197f693 | 961 | for (; (status = readb(&p->rfd_top->stat_high)) & RFD_COMPL;) { |
05bd831f | 962 | rbd = make32(readw(&p->rfd_top->rbd_offset)); |
a197f693 AC |
963 | 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); | |
05bd831f | 973 | memcpy_fromio(skb->data, p->base + readl(&rbd->buffer), totlen); |
a197f693 AC |
974 | skb->protocol = eth_type_trans(skb, dev); |
975 | netif_rx(skb); | |
a197f693 AC |
976 | p->stats.rx_packets++; |
977 | p->stats.rx_bytes += totlen; | |
978 | } else | |
979 | p->stats.rx_dropped++; | |
980 | } 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; | |
1da177e4 | 989 | } |
a197f693 | 990 | writew(0, &rbd->status); |
05bd831f | 991 | rbd = make32(readw(&rbd->next)); |
1da177e4 | 992 | } |
a197f693 AC |
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++; | |
1da177e4 | 998 | } |
a197f693 AC |
999 | } else {/* frame !(ok), only with 'save-bad-frames' */ |
1000 | printk(KERN_ERR "%s: oops! rfd-error-status: %04x\n", | |
1001 | dev->name, status); | |
1da177e4 LT |
1002 | p->stats.rx_errors++; |
1003 | } | |
a197f693 AC |
1004 | 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 */ | |
1da177e4 | 1008 | p->rfd_last = p->rfd_top; |
05bd831f | 1009 | p->rfd_top = make32(readw(&p->rfd_top->next)); /* step to next RFD */ |
a197f693 | 1010 | writew(make16(p->rfd_top), &p->scb->rfa_offset); |
1da177e4 | 1011 | |
a197f693 AC |
1012 | if (debuglevel > 0) |
1013 | printk("%d", cnt++); | |
1da177e4 LT |
1014 | } |
1015 | ||
a197f693 AC |
1016 | if (automatic_resume) { |
1017 | wait_for_scb_cmd(dev); | |
1018 | writeb(RUC_RESUME, &p->scb->cmd_ruc); | |
1da177e4 | 1019 | ni_attn586(); |
a197f693 | 1020 | wait_for_scb_cmd_ruc(dev); |
1da177e4 LT |
1021 | } |
1022 | ||
1023 | #ifdef WAIT_4_BUSY | |
1024 | { | |
1025 | int i; | |
a197f693 AC |
1026 | for (i = 0; i < 1024; i++) { |
1027 | if (p->rfd_top->status) | |
1da177e4 | 1028 | break; |
a197f693 AC |
1029 | udelay(16); |
1030 | if (i == 1023) | |
1031 | printk(KERN_ERR "%s: RU hasn't fetched next RFD (not busy/complete)\n", dev->name); | |
1da177e4 LT |
1032 | } |
1033 | } | |
1034 | #endif | |
a197f693 | 1035 | if (debuglevel > 0) |
1da177e4 LT |
1036 | printk("r"); |
1037 | } | |
1038 | ||
1039 | /********************************************************** | |
1040 | * handle 'Receiver went not ready'. | |
1041 | */ | |
1042 | ||
1043 | static void ni52_rnr_int(struct net_device *dev) | |
1044 | { | |
4cf1653a | 1045 | struct priv *p = netdev_priv(dev); |
1da177e4 LT |
1046 | |
1047 | p->stats.rx_errors++; | |
1048 | ||
a197f693 AC |
1049 | 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. */ | |
1da177e4 | 1051 | ni_attn586(); |
a197f693 | 1052 | wait_for_scb_cmd_ruc(dev); /* wait for accept cmd. */ |
1da177e4 | 1053 | |
2d76c267 | 1054 | alloc_rfa(dev, p->rfd_first); |
a197f693 | 1055 | /* maybe add a check here, before restarting the RU */ |
1da177e4 LT |
1056 | startrecv586(dev); /* restart RU */ |
1057 | ||
05bd831f AV |
1058 | printk(KERN_ERR "%s: Receive-Unit restarted. Status: %04x\n", |
1059 | dev->name, readb(&p->scb->rus)); | |
1da177e4 LT |
1060 | |
1061 | } | |
1062 | ||
1063 | /********************************************************** | |
1064 | * handle xmit - interrupt | |
1065 | */ | |
1066 | ||
1067 | static void ni52_xmt_int(struct net_device *dev) | |
1068 | { | |
1069 | int status; | |
4cf1653a | 1070 | struct priv *p = netdev_priv(dev); |
1da177e4 | 1071 | |
a197f693 | 1072 | if (debuglevel > 0) |
1da177e4 LT |
1073 | printk("X"); |
1074 | ||
a197f693 AC |
1075 | 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); | |
1da177e4 | 1078 | |
a197f693 | 1079 | if (status & STAT_OK) { |
1da177e4 LT |
1080 | p->stats.tx_packets++; |
1081 | p->stats.collisions += (status & TCMD_MAXCOLLMASK); | |
a197f693 | 1082 | } else { |
1da177e4 | 1083 | p->stats.tx_errors++; |
a197f693 AC |
1084 | if (status & TCMD_LATECOLL) { |
1085 | printk(KERN_ERR "%s: late collision detected.\n", | |
1086 | dev->name); | |
1da177e4 | 1087 | p->stats.collisions++; |
a197f693 | 1088 | } else if (status & TCMD_NOCARRIER) { |
1da177e4 | 1089 | p->stats.tx_carrier_errors++; |
a197f693 AC |
1090 | 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) { | |
1da177e4 | 1096 | p->stats.tx_fifo_errors++; |
a197f693 AC |
1097 | 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); | |
1da177e4 LT |
1102 | p->stats.collisions += 16; |
1103 | } | |
1104 | } | |
1da177e4 | 1105 | #if (NUM_XMIT_BUFFS > 1) |
a197f693 | 1106 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) |
1da177e4 LT |
1107 | p->xmit_last = 0; |
1108 | #endif | |
1109 | netif_wake_queue(dev); | |
1110 | } | |
1111 | ||
1112 | /*********************************************************** | |
1113 | * (re)start the receiver | |
1114 | */ | |
1115 | ||
1116 | static void startrecv586(struct net_device *dev) | |
1117 | { | |
4cf1653a | 1118 | struct priv *p = netdev_priv(dev); |
1da177e4 | 1119 | |
a197f693 AC |
1120 | 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); | |
1da177e4 | 1124 | ni_attn586(); /* start cmd. */ |
a197f693 AC |
1125 | wait_for_scb_cmd_ruc(dev); |
1126 | /* wait for accept cmd. (no timeout!!) */ | |
1da177e4 LT |
1127 | } |
1128 | ||
1129 | static void ni52_timeout(struct net_device *dev) | |
1130 | { | |
4cf1653a | 1131 | struct priv *p = netdev_priv(dev); |
1da177e4 | 1132 | #ifndef NO_NOPCOMMANDS |
a197f693 | 1133 | if (readb(&p->scb->cus) & CU_ACTIVE) { /* COMMAND-UNIT active? */ |
1da177e4 LT |
1134 | netif_wake_queue(dev); |
1135 | #ifdef DEBUG | |
a197f693 AC |
1136 | 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); | |
1da177e4 | 1143 | #endif |
a197f693 | 1144 | writeb(CUC_ABORT, &p->scb->cmd_cuc); |
1da177e4 | 1145 | ni_attn586(); |
a197f693 AC |
1146 | 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); | |
1da177e4 | 1149 | ni_attn586(); |
a197f693 | 1150 | wait_for_scb_cmd(dev); |
1da177e4 LT |
1151 | dev->trans_start = jiffies; |
1152 | return 0; | |
1153 | } | |
1154 | #endif | |
1155 | { | |
1156 | #ifdef DEBUG | |
a197f693 AC |
1157 | 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); | |
1da177e4 LT |
1165 | #endif |
1166 | ni52_close(dev); | |
1167 | ni52_open(dev); | |
1168 | } | |
1169 | dev->trans_start = jiffies; | |
1170 | } | |
1171 | ||
1172 | /****************************************************** | |
1173 | * send frame | |
1174 | */ | |
1175 | ||
1176 | static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev) | |
1177 | { | |
a197f693 | 1178 | int len, i; |
1da177e4 LT |
1179 | #ifndef NO_NOPCOMMANDS |
1180 | int next_nop; | |
1181 | #endif | |
4cf1653a | 1182 | struct priv *p = netdev_priv(dev); |
1da177e4 | 1183 | |
a197f693 AC |
1184 | if (skb->len > XMIT_BUFF_SIZE) { |
1185 | 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); | |
ec634fe3 | 1186 | return NETDEV_TX_OK; |
1da177e4 LT |
1187 | } |
1188 | ||
1189 | netif_stop_queue(dev); | |
1190 | ||
05bd831f | 1191 | memcpy_toio(p->xmit_cbuffs[p->xmit_count], skb->data, skb->len); |
a197f693 AC |
1192 | len = skb->len; |
1193 | if (len < ETH_ZLEN) { | |
1194 | len = ETH_ZLEN; | |
05bd831f | 1195 | memset_io(p->xmit_cbuffs[p->xmit_count]+skb->len, 0, |
a197f693 | 1196 | len - skb->len); |
1da177e4 | 1197 | } |
1da177e4 LT |
1198 | |
1199 | #if (NUM_XMIT_BUFFS == 1) | |
1200 | # ifdef NO_NOPCOMMANDS | |
1201 | ||
1202 | #ifdef DEBUG | |
05bd831f | 1203 | if (readb(&p->scb->cus) & CU_ACTIVE) { |
a197f693 AC |
1204 | printk(KERN_ERR "%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev->name); |
1205 | printk(KERN_ERR "%s: stat: %04x %04x\n", | |
1206 | dev->name, readb(&p->scb->cus), | |
1207 | readw(&p->xmit_cmds[0]->cmd_status)); | |
1208 | } | |
1da177e4 | 1209 | #endif |
05bd831f | 1210 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); |
a197f693 AC |
1211 | for (i = 0; i < 16; i++) { |
1212 | writew(0, &p->xmit_cmds[0]->cmd_status); | |
1213 | wait_for_scb_cmd(dev); | |
1214 | if ((readb(&p->scb->cus) & CU_STATUS) == CU_SUSPEND) | |
1215 | writeb(CUC_RESUME, &p->scb->cmd_cuc); | |
1216 | else { | |
1217 | writew(make16(p->xmit_cmds[0]), &p->scb->cbl_offset); | |
1218 | writeb(CUC_START, &p->scb->cmd_cuc); | |
1da177e4 | 1219 | } |
a197f693 | 1220 | ni_attn586(); |
1da177e4 | 1221 | dev->trans_start = jiffies; |
a197f693 AC |
1222 | if (!i) |
1223 | dev_kfree_skb(skb); | |
1224 | wait_for_scb_cmd(dev); | |
1225 | /* test it, because CU sometimes doesn't start immediately */ | |
1226 | if (readb(&p->scb->cus) & CU_ACTIVE) | |
1227 | break; | |
1228 | if (readw(&p->xmit_cmds[0]->cmd_status)) | |
1229 | break; | |
1230 | if (i == 15) | |
1231 | printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name); | |
1232 | } | |
1233 | # else | |
1234 | next_nop = (p->nop_point + 1) & 0x1; | |
1235 | writew(TBD_LAST | len, &p->xmit_buffs[0]->size); | |
1236 | writew(make16(p->nop_cmds[next_nop]), &p->xmit_cmds[0]->cmd_link); | |
1237 | writew(make16(p->nop_cmds[next_nop]), | |
1238 | &p->nop_cmds[next_nop]->cmd_link); | |
1239 | writew(0, &p->xmit_cmds[0]->cmd_status); | |
1240 | writew(0, &p->nop_cmds[next_nop]->cmd_status); | |
1241 | ||
1242 | writew(make16(p->xmit_cmds[0]), &p->nop_cmds[p->nop_point]->cmd_link); | |
1243 | dev->trans_start = jiffies; | |
1244 | p->nop_point = next_nop; | |
1245 | dev_kfree_skb(skb); | |
1da177e4 LT |
1246 | # endif |
1247 | #else | |
a197f693 AC |
1248 | writew(TBD_LAST | len, &p->xmit_buffs[p->xmit_count]->size); |
1249 | next_nop = p->xmit_count + 1 | |
1250 | if (next_nop == NUM_XMIT_BUFFS) | |
1251 | next_nop = 0; | |
1252 | writew(0, &p->xmit_cmds[p->xmit_count]->cmd_status); | |
1253 | /* linkpointer of xmit-command already points to next nop cmd */ | |
1254 | writew(make16(p->nop_cmds[next_nop]), | |
1255 | &p->nop_cmds[next_nop]->cmd_link); | |
1256 | writew(0, &p->nop_cmds[next_nop]->cmd_status); | |
1257 | writew(make16(p->xmit_cmds[p->xmit_count]), | |
1258 | &p->nop_cmds[p->xmit_count]->cmd_link); | |
1259 | dev->trans_start = jiffies; | |
1260 | p->xmit_count = next_nop; | |
1261 | { | |
1262 | unsigned long flags; | |
1263 | spin_lock_irqsave(&p->spinlock); | |
1264 | if (p->xmit_count != p->xmit_last) | |
1265 | netif_wake_queue(dev); | |
1266 | spin_unlock_irqrestore(&p->spinlock); | |
1da177e4 | 1267 | } |
a197f693 AC |
1268 | dev_kfree_skb(skb); |
1269 | #endif | |
ec634fe3 | 1270 | return NETDEV_TX_OK; |
1da177e4 LT |
1271 | } |
1272 | ||
1273 | /******************************************* | |
1274 | * Someone wanna have the statistics | |
1275 | */ | |
1276 | ||
1277 | static struct net_device_stats *ni52_get_stats(struct net_device *dev) | |
1278 | { | |
4cf1653a | 1279 | struct priv *p = netdev_priv(dev); |
a197f693 AC |
1280 | unsigned short crc, aln, rsc, ovrn; |
1281 | ||
1282 | /* Get error-statistics from the ni82586 */ | |
1283 | crc = readw(&p->scb->crc_errs); | |
1284 | writew(0, &p->scb->crc_errs); | |
1285 | aln = readw(&p->scb->aln_errs); | |
1286 | writew(0, &p->scb->aln_errs); | |
1287 | rsc = readw(&p->scb->rsc_errs); | |
1288 | writew(0, &p->scb->rsc_errs); | |
1289 | ovrn = readw(&p->scb->ovrn_errs); | |
1290 | writew(0, &p->scb->ovrn_errs); | |
1da177e4 LT |
1291 | |
1292 | p->stats.rx_crc_errors += crc; | |
1293 | p->stats.rx_fifo_errors += ovrn; | |
1294 | p->stats.rx_frame_errors += aln; | |
1295 | p->stats.rx_dropped += rsc; | |
1296 | ||
1297 | return &p->stats; | |
1298 | } | |
1299 | ||
1300 | /******************************************************** | |
1301 | * Set MC list .. | |
1302 | */ | |
1303 | ||
1304 | static void set_multicast_list(struct net_device *dev) | |
1305 | { | |
1306 | netif_stop_queue(dev); | |
1307 | ni_disint(); | |
1308 | alloc586(dev); | |
1309 | init586(dev); | |
1310 | startrecv586(dev); | |
1311 | ni_enaint(); | |
1312 | netif_wake_queue(dev); | |
1313 | } | |
1314 | ||
1315 | #ifdef MODULE | |
1316 | static struct net_device *dev_ni52; | |
1317 | ||
1318 | module_param(io, int, 0); | |
1319 | module_param(irq, int, 0); | |
1320 | module_param(memstart, long, 0); | |
1321 | module_param(memend, long, 0); | |
1322 | MODULE_PARM_DESC(io, "NI5210 I/O base address,required"); | |
1323 | MODULE_PARM_DESC(irq, "NI5210 IRQ number,required"); | |
1324 | MODULE_PARM_DESC(memstart, "NI5210 memory base address,required"); | |
1325 | MODULE_PARM_DESC(memend, "NI5210 memory end address,required"); | |
1326 | ||
19a8664d | 1327 | int __init init_module(void) |
1da177e4 | 1328 | { |
a197f693 AC |
1329 | if (io <= 0x0 || !memend || !memstart || irq < 2) { |
1330 | printk(KERN_ERR "ni52: Autoprobing not allowed for modules.\n"); | |
1331 | printk(KERN_ERR "ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); | |
1da177e4 LT |
1332 | return -ENODEV; |
1333 | } | |
1334 | dev_ni52 = ni52_probe(-1); | |
1335 | if (IS_ERR(dev_ni52)) | |
1336 | return PTR_ERR(dev_ni52); | |
1337 | return 0; | |
1338 | } | |
1339 | ||
afc8eb46 | 1340 | void __exit cleanup_module(void) |
1da177e4 | 1341 | { |
4cf1653a | 1342 | struct priv *p = netdev_priv(dev_ni52); |
1da177e4 | 1343 | unregister_netdev(dev_ni52); |
176f65f3 | 1344 | iounmap(p->mapped); |
1da177e4 LT |
1345 | release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE); |
1346 | free_netdev(dev_ni52); | |
1347 | } | |
1348 | #endif /* MODULE */ | |
1349 | ||
1da177e4 | 1350 | MODULE_LICENSE("GPL"); |