blob: ff41e1ff56031876862db4a387c45a0dedb5d0b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)
3
4
5 This is an extension to the Linux operating system, and is covered by the
6 same GNU General Public License that covers that work.
7
8 Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)
9
10 This is basically Michael Hipp's ni52 driver, with a new probing
11 algorithm and some minor changes to the 82586 CA and reset routines.
12 Thanks a lot Michael for a really clean i82586 implementation! Unless
13 otherwise documented in ni52.c, any bugs are mine.
14
15 Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in
16 any way. The ni52 is a lot easier to modify.
17
18 sources:
19 ni52.c
20
21 Crynwr packet driver collection was a great reference for my first
22 attempt at this sucker. The 3c507 driver also helped, until I noticed
23 that ni52.c was a lot nicer.
24
25 EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference
26 Manual, courtesy of 3Com CardFacts, documents the 3c523-specific
27 stuff. Information on CardFacts is found in the Ethernet HOWTO.
28 Also see <a href="http://www.3com.com/">
29
30 Microprocessor Communications Support Chips, T.J. Byers, ISBN
31 0-444-01224-9, has a section on the i82586. It tells you just enough
32 to know that you really don't want to learn how to program the chip.
33
34 The original device probe code was stolen from ps2esdi.c
35
36 Known Problems:
37 Since most of the code was stolen from ni52.c, you'll run across the
38 same bugs in the 0.62 version of ni52.c, plus maybe a few because of
39 the 3c523 idiosynchacies. The 3c523 has 16K of RAM though, so there
40 shouldn't be the overrun problem that the 8K ni52 has.
41
42 This driver is for a 16K adapter. It should work fine on the 64K
43 adapters, but it will only use one of the 4 banks of RAM. Modifying
44 this for the 64K version would require a lot of heinous bank
45 switching, which I'm sure not interested in doing. If you try to
46 implement a bank switching version, you'll basically have to remember
47 what bank is enabled and do a switch everytime you access a memory
48 location that's not current. You'll also have to remap pointers on
49 the driver side, because it only knows about 16K of the memory.
50 Anyone desperate or masochistic enough to try?
51
52 It seems to be stable now when multiple transmit buffers are used. I
53 can't see any performance difference, but then I'm working on a 386SX.
54
55 Multicast doesn't work. It doesn't even pretend to work. Don't use
56 it. Don't compile your kernel with multicast support. I don't know
57 why.
58
59 Features:
60 This driver is useable as a loadable module. If you try to specify an
61 IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will
62 search the MCA slots until it finds a 3c523 with the specified
63 parameters.
64
65 This driver does support multiple ethernet cards when used as a module
66 (up to MAX_3C523_CARDS, the default being 4)
67
68 This has been tested with both BNC and TP versions, internal and
69 external transceivers. Haven't tested with the 64K version (that I
70 know of).
71
72 History:
73 Jan 1st, 1996
74 first public release
75 Feb 4th, 1996
76 update to 1.3.59, incorporated multicast diffs from ni52.c
77 Feb 15th, 1996
78 added shared irq support
79 Apr 1999
80 added support for multiple cards when used as a module
81 added option to disable multicast as is causes problems
82 Ganesh Sittampalam <ganesh.sittampalam@magdalen.oxford.ac.uk>
83 Stuart Adamson <stuart.adamson@compsoc.net>
84 Nov 2001
85 added support for ethtool (jgarzik)
Jeff Garzik6aa20a22006-09-13 13:24:59 -040086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 $Header: /fsys2/home/chrisb/linux-1.3.59-MCA/drivers/net/RCS/3c523.c,v 1.1 1996/02/05 01:53:46 chrisb Exp chrisb $
88 */
89
90#define DRV_NAME "3c523"
91#define DRV_VERSION "17-Nov-2001"
92
93#include <linux/init.h>
94#include <linux/netdevice.h>
95#include <linux/etherdevice.h>
96#include <linux/module.h>
97#include <linux/kernel.h>
98#include <linux/string.h>
99#include <linux/errno.h>
100#include <linux/ioport.h>
101#include <linux/skbuff.h>
102#include <linux/slab.h>
103#include <linux/interrupt.h>
104#include <linux/delay.h>
105#include <linux/mca-legacy.h>
106#include <linux/ethtool.h>
107#include <linux/bitops.h>
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800108#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110#include <asm/uaccess.h>
111#include <asm/processor.h>
112#include <asm/io.h>
113
114#include "3c523.h"
115
116/*************************************************************************/
117#define DEBUG /* debug on */
118#define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
119#undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */
120
121#define make32(ptr16) (p->memtop + (short) (ptr16) )
122#define make24(ptr32) ((char *) (ptr32) - p->base)
123#define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
124
125/*************************************************************************/
126/*
127 Tables to which we can map values in the configuration registers.
128 */
129static int irq_table[] __initdata = {
130 12, 7, 3, 9
131};
132
133static int csr_table[] __initdata = {
134 0x300, 0x1300, 0x2300, 0x3300
135};
136
137static int shm_table[] __initdata = {
138 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
139};
140
141/******************* how to calculate the buffers *****************************
142
143
144 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
145 * --------------- in a different (more stable?) mode. Only in this mode it's
146 * possible to configure the driver with 'NO_NOPCOMMANDS'
147
148sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
149sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
150sizeof(rfd) = 24; sizeof(rbd) = 12;
151sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
152sizeof(nop_cmd) = 8;
153
154 * if you don't know the driver, better do not change this values: */
155
156#define RECV_BUFF_SIZE 1524 /* slightly oversized */
157#define XMIT_BUFF_SIZE 1524 /* slightly oversized */
158#define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
159#define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
160#define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
161
162#if (NUM_XMIT_BUFFS == 1)
163#define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
164#endif
165
166/**************************************************************************/
167
168#define DELAY(x) { mdelay(32 * x); }
169
170/* a much shorter delay: */
171#define DELAY_16(); { udelay(16) ; }
172
173/* wait for command with timeout: */
174#define WAIT_4_SCB_CMD() { int i; \
175 for(i=0;i<1024;i++) { \
176 if(!p->scb->cmd) break; \
177 DELAY_16(); \
178 if(i == 1023) { \
179 printk(KERN_WARNING "%s:%d: scb_cmd timed out .. resetting i82586\n",\
180 dev->name,__LINE__); \
181 elmc_id_reset586(); } } }
182
David Howells7d12e782006-10-05 14:55:46 +0100183static irqreturn_t elmc_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static int elmc_open(struct net_device *dev);
185static int elmc_close(struct net_device *dev);
186static int elmc_send_packet(struct sk_buff *, struct net_device *);
187static struct net_device_stats *elmc_get_stats(struct net_device *dev);
188static void elmc_timeout(struct net_device *dev);
189#ifdef ELMC_MULTICAST
190static void set_multicast_list(struct net_device *dev);
191#endif
Jeff Garzik7282d492006-09-13 14:30:00 -0400192static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/* helper-functions */
195static int init586(struct net_device *dev);
196static int check586(struct net_device *dev, unsigned long where, unsigned size);
197static void alloc586(struct net_device *dev);
198static void startrecv586(struct net_device *dev);
199static void *alloc_rfa(struct net_device *dev, void *ptr);
200static void elmc_rcv_int(struct net_device *dev);
201static void elmc_xmt_int(struct net_device *dev);
202static void elmc_rnr_int(struct net_device *dev);
203
204struct priv {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 unsigned long base;
206 char *memtop;
207 unsigned long mapped_start; /* Start of ioremap */
208 volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
209 volatile struct scp_struct *scp; /* volatile is important */
210 volatile struct iscp_struct *iscp; /* volatile is important */
211 volatile struct scb_struct *scb; /* volatile is important */
212 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
213#if (NUM_XMIT_BUFFS == 1)
214 volatile struct transmit_cmd_struct *xmit_cmds[2];
215 volatile struct nop_cmd_struct *nop_cmds[2];
216#else
217 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
218 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
219#endif
220 volatile int nop_point, num_recv_buffs;
221 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
222 volatile int xmit_count, xmit_last;
223 volatile int slot;
224};
225
226#define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
227#define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
228
229/* with interrupts disabled - this will clear the interrupt bit in the
230 3c523 control register, and won't put it back. This effectively
231 disables interrupts on the card. */
232#define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);}
233#define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
234
235/*************************************************************************/
236/*
237 Do a Channel Attention on the 3c523. This is extremely board dependent.
238 */
239static void elmc_do_attn586(int ioaddr, int ints)
240{
241 /* the 3c523 requires a minimum of 500 ns. The delays here might be
242 a little too large, and hence they may cut the performance of the
243 card slightly. If someone who knows a little more about Linux
244 timing would care to play with these, I'd appreciate it. */
245
246 /* this bit masking stuff is crap. I'd rather have separate
247 registers with strobe triggers for each of these functions. <sigh>
248 Ya take what ya got. */
249
250 outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);
251 DELAY_16(); /* > 500 ns */
252 outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);
253}
254
255/*************************************************************************/
256/*
257 Reset the 82586 on the 3c523. Also very board dependent.
258 */
259static void elmc_do_reset586(int ioaddr, int ints)
260{
261 /* toggle the RST bit low then high */
262 outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);
263 DELAY_16(); /* > 500 ns */
264 outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);
265
266 elmc_do_attn586(ioaddr, ints);
267}
268
269/**********************************************
270 * close device
271 */
272
273static int elmc_close(struct net_device *dev)
274{
275 netif_stop_queue(dev);
276 elmc_id_reset586(); /* the hard way to stop the receiver */
277 free_irq(dev->irq, dev);
278 return 0;
279}
280
281/**********************************************
282 * open device
283 */
284
285static int elmc_open(struct net_device *dev)
286{
287 int ret;
288
289 elmc_id_attn586(); /* disable interrupts */
290
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700291 ret = request_irq(dev->irq, &elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 dev->name, dev);
293 if (ret) {
294 printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq);
295 elmc_id_reset586();
296 return ret;
297 }
298 alloc586(dev);
299 init586(dev);
300 startrecv586(dev);
301 netif_start_queue(dev);
302 return 0; /* most done by init */
303}
304
305/**********************************************
306 * Check to see if there's an 82586 out there.
307 */
308
309static int __init check586(struct net_device *dev, unsigned long where, unsigned size)
310{
Wang Chen454d7c92008-11-12 23:37:49 -0800311 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 char *iscp_addrs[2];
313 int i = 0;
314
315 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
316 p->memtop = isa_bus_to_virt((unsigned long)where) + size;
317 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
318 memset((char *) p->scp, 0, sizeof(struct scp_struct));
319 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
320
321 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
322 iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
323
324 for (i = 0; i < 2; i++) {
325 p->iscp = (struct iscp_struct *) iscp_addrs[i];
326 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
327
328 p->scp->iscp = make24(p->iscp);
329 p->iscp->busy = 1;
330
331 elmc_id_reset586();
332
333 /* reset586 does an implicit CA */
334
335 /* apparently, you sometimes have to kick the 82586 twice... */
336 elmc_id_attn586();
337 DELAY(1);
338
339 if (p->iscp->busy) { /* i82586 clears 'busy' after successful init */
340 return 0;
341 }
342 }
343 return 1;
344}
345
346/******************************************************************
347 * set iscp at the right place, called by elmc_probe and open586.
348 */
349
Hannes Ederdac499f2008-12-25 23:56:45 -0800350static void alloc586(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Wang Chen454d7c92008-11-12 23:37:49 -0800352 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 elmc_id_reset586();
355 DELAY(2);
356
357 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
358 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
359 p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));
360
361 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
362 memset((char *) p->scp, 0, sizeof(struct scp_struct));
363
364 p->scp->iscp = make24(p->iscp);
365 p->scp->sysbus = SYSBUSVAL;
366 p->iscp->scb_offset = make16(p->scb);
367
368 p->iscp->busy = 1;
369 elmc_id_reset586();
370 elmc_id_attn586();
371
372 DELAY(2);
373
374 if (p->iscp->busy) {
375 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
376 }
377 memset((char *) p->scb, 0, sizeof(struct scb_struct));
378}
379
380/*****************************************************************/
381
382static int elmc_getinfo(char *buf, int slot, void *d)
383{
384 int len = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700385 struct net_device *dev = d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 if (dev == NULL)
388 return len;
389
390 len += sprintf(buf + len, "Revision: 0x%x\n",
391 inb(dev->base_addr + ELMC_REVISION) & 0xf);
392 len += sprintf(buf + len, "IRQ: %d\n", dev->irq);
393 len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,
394 dev->base_addr + ELMC_IO_EXTENT);
395 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
396 dev->mem_end - 1);
397 len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?
398 "External" : "Internal");
399 len += sprintf(buf + len, "Device: %s\n", dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700400 len += sprintf(buf + len, "Hardware Address: %pM\n",
401 dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 return len;
404} /* elmc_getinfo() */
405
406/*****************************************************************/
407
408static int __init do_elmc_probe(struct net_device *dev)
409{
410 static int slot;
411 int base_addr = dev->base_addr;
412 int irq = dev->irq;
413 u_char status = 0;
414 u_char revision = 0;
415 int i = 0;
416 unsigned int size = 0;
417 int retval;
Wang Chen454d7c92008-11-12 23:37:49 -0800418 struct priv *pr = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (MCA_bus == 0) {
421 return -ENODEV;
422 }
423 /* search through the slots for the 3c523. */
424 slot = mca_find_adapter(ELMC_MCA_ID, 0);
425 while (slot != -1) {
426 status = mca_read_stored_pos(slot, 2);
427
428 dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6];
429 dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /*
432 If we're trying to match a specified irq or IO address,
433 we'll reject a match unless it's what we're looking for.
434 Also reject it if the card is already in use.
435 */
436
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400437 if ((irq && irq != dev->irq) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 (base_addr && base_addr != dev->base_addr)) {
439 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
440 continue;
441 }
442 if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) {
443 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
444 continue;
445 }
446
447 /* found what we're looking for... */
448 break;
449 }
450
451 /* we didn't find any 3c523 in the slots we checked for */
452 if (slot == MCA_NOTFOUND)
453 return ((base_addr || irq) ? -ENXIO : -ENODEV);
454
455 mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC");
456 mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev);
457
458 /* if we get this far, adapter has been found - carry on */
459 printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1);
460
461 /* Now we extract configuration info from the card.
462 The 3c523 provides information in two of the POS registers, but
463 the second one is only needed if we want to tell the card what IRQ
464 to use. I suspect that whoever sets the thing up initially would
465 prefer we don't screw with those things.
466
467 Note that we read the status info when we found the card...
468
469 See 3c523.h for more details.
470 */
471
472 /* revision is stored in the first 4 bits of the revision register */
473 revision = inb(dev->base_addr + ELMC_REVISION) & 0xf;
474
475 /* according to docs, we read the interrupt and write it back to
476 the IRQ select register, since the POST might not configure the IRQ
477 properly. */
478 switch (dev->irq) {
479 case 3:
480 mca_write_pos(slot, 3, 0x04);
481 break;
482 case 7:
483 mca_write_pos(slot, 3, 0x02);
484 break;
485 case 9:
486 mca_write_pos(slot, 3, 0x08);
487 break;
488 case 12:
489 mca_write_pos(slot, 3, 0x01);
490 break;
491 }
492
493 memset(pr, 0, sizeof(struct priv));
494 pr->slot = slot;
495
496 printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision,
497 dev->base_addr);
498
499 /* Determine if we're using the on-board transceiver (i.e. coax) or
500 an external one. The information is pretty much useless, but I
501 guess it's worth brownie points. */
502 dev->if_port = (status & ELMC_STATUS_DISABLE_THIN);
503
504 /* The 3c523 has a 24K chunk of memory. The first 16K is the
505 shared memory, while the last 8K is for the EtherStart BIOS ROM.
506 Which we don't care much about here. We'll just tell Linux that
507 we're using 16K. MCA won't permit address space conflicts caused
508 by not mapping the other 8K. */
509 dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3];
510
511 /* We're using MCA, so it's a given that the information about memory
512 size is correct. The Crynwr drivers do something like this. */
513
514 elmc_id_reset586(); /* seems like a good idea before checking it... */
515
516 size = 0x4000; /* check for 16K mem */
517 if (!check586(dev, dev->mem_start, size)) {
518 printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name,
519 dev->mem_start);
520 retval = -ENODEV;
521 goto err_out;
522 }
523 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
524
525 pr->memtop = isa_bus_to_virt(dev->mem_start) + size;
526 pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
527 alloc586(dev);
528
529 elmc_id_reset586(); /* make sure it doesn't generate spurious ints */
530
531 /* set number of receive-buffs according to memsize */
532 pr->num_recv_buffs = NUM_RECV_BUFFS_16;
533
534 /* dump all the assorted information */
535 printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name,
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400536 dev->irq, dev->if_port ? "ex" : "in",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 dev->mem_start, dev->mem_end - 1);
538
539 /* The hardware address for the 3c523 is stored in the first six
540 bytes of the IO address. */
Joe Perches0795af52007-10-03 17:59:30 -0700541 for (i = 0; i < 6; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 dev->dev_addr[i] = inb(dev->base_addr + i);
Joe Perches0795af52007-10-03 17:59:30 -0700543
Johannes Berge1749612008-10-27 15:59:26 -0700544 printk(KERN_INFO "%s: hardware address %pM\n",
545 dev->name, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 dev->open = &elmc_open;
548 dev->stop = &elmc_close;
549 dev->get_stats = &elmc_get_stats;
550 dev->hard_start_xmit = &elmc_send_packet;
551 dev->tx_timeout = &elmc_timeout;
552 dev->watchdog_timeo = HZ;
553#ifdef ELMC_MULTICAST
554 dev->set_multicast_list = &set_multicast_list;
555#else
556 dev->set_multicast_list = NULL;
557#endif
558 dev->ethtool_ops = &netdev_ethtool_ops;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 /* note that we haven't actually requested the IRQ from the kernel.
561 That gets done in elmc_open(). I'm not sure that's such a good idea,
562 but it works, so I'll go with it. */
563
564#ifndef ELMC_MULTICAST
565 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
566#endif
567
b1fc5502005-05-12 20:11:55 -0400568 retval = register_netdev(dev);
569 if (retval)
570 goto err_out;
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return 0;
573err_out:
574 mca_set_adapter_procfn(slot, NULL, NULL);
575 release_region(dev->base_addr, ELMC_IO_EXTENT);
576 return retval;
577}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400578
Ingo Molnar46a84942008-11-25 17:02:20 -0800579#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580static void cleanup_card(struct net_device *dev)
581{
Wang Chen454d7c92008-11-12 23:37:49 -0800582 mca_set_adapter_procfn(((struct priv *)netdev_priv(dev))->slot,
583 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 release_region(dev->base_addr, ELMC_IO_EXTENT);
585}
Ingo Molnar46a84942008-11-25 17:02:20 -0800586#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587struct net_device * __init elmc_probe(int unit)
588{
589 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
590 int err;
591
592 if (!dev)
593 return ERR_PTR(-ENOMEM);
594
595 sprintf(dev->name, "eth%d", unit);
596 netdev_boot_setup_check(dev);
597
598 err = do_elmc_probe(dev);
599 if (err)
600 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602out:
603 free_netdev(dev);
604 return ERR_PTR(err);
605}
606#endif
607
608/**********************************************
609 * init the chip (elmc-interrupt should be disabled?!)
610 * needs a correct 'allocated' memory
611 */
612
613static int init586(struct net_device *dev)
614{
615 void *ptr;
616 unsigned long s;
617 int i, result = 0;
Wang Chen454d7c92008-11-12 23:37:49 -0800618 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 volatile struct configure_cmd_struct *cfg_cmd;
620 volatile struct iasetup_cmd_struct *ias_cmd;
621 volatile struct tdr_cmd_struct *tdr_cmd;
622 volatile struct mcsetup_cmd_struct *mc_cmd;
623 struct dev_mc_list *dmi = dev->mc_list;
624 int num_addrs = dev->mc_count;
625
626 ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct));
627
628 cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */
629 cfg_cmd->cmd_status = 0;
630 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
631 cfg_cmd->cmd_link = 0xffff;
632
633 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
634 cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */
635 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
636 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
637 cfg_cmd->priority = 0x00;
638 cfg_cmd->ifs = 0x60;
639 cfg_cmd->time_low = 0x00;
640 cfg_cmd->time_high = 0xf2;
641 cfg_cmd->promisc = 0;
Wang Chenc16d1182008-07-22 13:13:12 +0800642 if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 cfg_cmd->promisc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 cfg_cmd->carr_coll = 0x00;
645
646 p->scb->cbl_offset = make16(cfg_cmd);
647
648 p->scb->cmd = CUC_START; /* cmd.-unit start */
649 elmc_id_attn586();
650
651 s = jiffies; /* warning: only active with interrupts on !! */
652 while (!(cfg_cmd->cmd_status & STAT_COMPL)) {
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800653 if (time_after(jiffies, s + 30*HZ/100))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 break;
655 }
656
657 if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) {
658 printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status);
659 return 1;
660 }
661 /*
662 * individual address setup
663 */
664 ias_cmd = (struct iasetup_cmd_struct *) ptr;
665
666 ias_cmd->cmd_status = 0;
667 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
668 ias_cmd->cmd_link = 0xffff;
669
670 memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN);
671
672 p->scb->cbl_offset = make16(ias_cmd);
673
674 p->scb->cmd = CUC_START; /* cmd.-unit start */
675 elmc_id_attn586();
676
677 s = jiffies;
678 while (!(ias_cmd->cmd_status & STAT_COMPL)) {
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800679 if (time_after(jiffies, s + 30*HZ/100))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 break;
681 }
682
683 if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) {
684 printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status);
685 return 1;
686 }
687 /*
688 * TDR, wire check .. e.g. no resistor e.t.c
689 */
690 tdr_cmd = (struct tdr_cmd_struct *) ptr;
691
692 tdr_cmd->cmd_status = 0;
693 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
694 tdr_cmd->cmd_link = 0xffff;
695 tdr_cmd->status = 0;
696
697 p->scb->cbl_offset = make16(tdr_cmd);
698
699 p->scb->cmd = CUC_START; /* cmd.-unit start */
700 elmc_attn586();
701
702 s = jiffies;
703 while (!(tdr_cmd->cmd_status & STAT_COMPL)) {
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800704 if (time_after(jiffies, s + 30*HZ/100)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__);
706 result = 1;
707 break;
708 }
709 }
710
711 if (!result) {
712 DELAY(2); /* wait for result */
713 result = tdr_cmd->status;
714
715 p->scb->cmd = p->scb->status & STAT_MASK;
716 elmc_id_attn586(); /* ack the interrupts */
717
718 if (result & TDR_LNK_OK) {
719 /* empty */
720 } else if (result & TDR_XCVR_PRB) {
721 printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name);
722 } else if (result & TDR_ET_OPN) {
723 printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
724 } else if (result & TDR_ET_SRT) {
725 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
726 printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
727 } else {
728 printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result);
729 }
730 }
731 /*
732 * ack interrupts
733 */
734 p->scb->cmd = p->scb->status & STAT_MASK;
735 elmc_id_attn586();
736
737 /*
738 * alloc nop/xmit-cmds
739 */
740#if (NUM_XMIT_BUFFS == 1)
741 for (i = 0; i < 2; i++) {
742 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
743 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
744 p->nop_cmds[i]->cmd_status = 0;
745 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
746 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
747 }
748 p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */
749 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
750#else
751 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
752 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
753 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
754 p->nop_cmds[i]->cmd_status = 0;
755 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
756 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
757 p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */
758 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
759 }
760#endif
761
762 ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */
763
764 /*
765 * Multicast setup
766 */
767
768 if (dev->mc_count) {
769 /* I don't understand this: do we really need memory after the init? */
770 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
771 if (len <= 0) {
772 printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name);
773 } else {
774 if (len < num_addrs) {
775 num_addrs = len;
776 printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n",
777 dev->name, num_addrs);
778 }
779 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
780 mc_cmd->cmd_status = 0;
781 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
782 mc_cmd->cmd_link = 0xffff;
783 mc_cmd->mc_cnt = num_addrs * 6;
784 for (i = 0; i < num_addrs; i++) {
785 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6);
786 dmi = dmi->next;
787 }
788 p->scb->cbl_offset = make16(mc_cmd);
789 p->scb->cmd = CUC_START;
790 elmc_id_attn586();
791 s = jiffies;
792 while (!(mc_cmd->cmd_status & STAT_COMPL)) {
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800793 if (time_after(jiffies, s + 30*HZ/100))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 break;
795 }
796 if (!(mc_cmd->cmd_status & STAT_COMPL)) {
797 printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name);
798 }
799 }
800 }
801 /*
802 * alloc xmit-buffs / init xmit_cmds
803 */
804 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
805 p->xmit_cbuffs[i] = (char *) ptr; /* char-buffs */
806 ptr = (char *) ptr + XMIT_BUFF_SIZE;
807 p->xmit_buffs[i] = (struct tbd_struct *) ptr; /* TBD */
808 ptr = (char *) ptr + sizeof(struct tbd_struct);
809 if ((void *) ptr > (void *) p->iscp) {
810 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name);
811 return 1;
812 }
813 memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct));
814 memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct));
815 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
816 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
817 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
818 p->xmit_buffs[i]->next = 0xffff;
819 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
820 }
821
822 p->xmit_count = 0;
823 p->xmit_last = 0;
824#ifndef NO_NOPCOMMANDS
825 p->nop_point = 0;
826#endif
827
828 /*
829 * 'start transmitter' (nop-loop)
830 */
831#ifndef NO_NOPCOMMANDS
832 p->scb->cbl_offset = make16(p->nop_cmds[0]);
833 p->scb->cmd = CUC_START;
834 elmc_id_attn586();
835 WAIT_4_SCB_CMD();
836#else
837 p->xmit_cmds[0]->cmd_link = 0xffff;
838 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;
839#endif
840
841 return 0;
842}
843
844/******************************************************
845 * This is a helper routine for elmc_rnr_int() and init586().
846 * It sets up the Receive Frame Area (RFA).
847 */
848
849static void *alloc_rfa(struct net_device *dev, void *ptr)
850{
851 volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr;
852 volatile struct rbd_struct *rbd;
853 int i;
Wang Chen454d7c92008-11-12 23:37:49 -0800854 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs);
857 p->rfd_first = rfd;
858
859 for (i = 0; i < p->num_recv_buffs; i++) {
860 rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs);
861 }
862 rfd[p->num_recv_buffs - 1].last = RFD_SUSP; /* RU suspend */
863
864 ptr = (void *) (rfd + p->num_recv_buffs);
865
866 rbd = (struct rbd_struct *) ptr;
867 ptr = (void *) (rbd + p->num_recv_buffs);
868
869 /* clr descriptors */
870 memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs);
871
872 for (i = 0; i < p->num_recv_buffs; i++) {
873 rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs));
874 rbd[i].size = RECV_BUFF_SIZE;
875 rbd[i].buffer = make24(ptr);
876 ptr = (char *) ptr + RECV_BUFF_SIZE;
877 }
878
879 p->rfd_top = p->rfd_first;
880 p->rfd_last = p->rfd_first + p->num_recv_buffs - 1;
881
882 p->scb->rfa_offset = make16(p->rfd_first);
883 p->rfd_first->rbd_offset = make16(rbd);
884
885 return ptr;
886}
887
888
889/**************************************************
890 * Interrupt Handler ...
891 */
892
893static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100894elmc_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
Jeff Garzikc31f28e2006-10-06 14:56:04 -0400896 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 unsigned short stat;
898 struct priv *p;
899
Jeff Garzikc31f28e2006-10-06 14:56:04 -0400900 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 /* The 3c523 has this habit of generating interrupts during the
902 reset. I'm not sure if the ni52 has this same problem, but it's
903 really annoying if we haven't finished initializing it. I was
904 hoping all the elmc_id_* commands would disable this, but I
905 might have missed a few. */
906
907 elmc_id_attn586(); /* ack inter. and disable any more */
908 return IRQ_HANDLED;
909 } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) {
910 /* wasn't this device */
911 return IRQ_NONE;
912 }
913 /* reading ELMC_CTRL also clears the INT bit. */
914
Wang Chen454d7c92008-11-12 23:37:49 -0800915 p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400917 while ((stat = p->scb->status & STAT_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 {
919 p->scb->cmd = stat;
920 elmc_attn586(); /* ack inter. */
921
922 if (stat & STAT_CX) {
923 /* command with I-bit set complete */
924 elmc_xmt_int(dev);
925 }
926 if (stat & STAT_FR) {
927 /* received a frame */
928 elmc_rcv_int(dev);
929 }
930#ifndef NO_NOPCOMMANDS
931 if (stat & STAT_CNA) {
932 /* CU went 'not ready' */
933 if (netif_running(dev)) {
934 printk(KERN_WARNING "%s: oops! CU has left active state. stat: %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
935 }
936 }
937#endif
938
939 if (stat & STAT_RNR) {
940 /* RU went 'not ready' */
941
942 if (p->scb->status & RU_SUSPEND) {
943 /* special case: RU_SUSPEND */
944
945 WAIT_4_SCB_CMD();
946 p->scb->cmd = RUC_RESUME;
947 elmc_attn586();
948 } else {
949 printk(KERN_WARNING "%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
950 elmc_rnr_int(dev);
951 }
952 }
953 WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
954 if (p->scb->cmd) { /* timed out? */
955 break;
956 }
957 }
958 return IRQ_HANDLED;
959}
960
961/*******************************************************
962 * receive-interrupt
963 */
964
965static void elmc_rcv_int(struct net_device *dev)
966{
967 int status;
968 unsigned short totlen;
969 struct sk_buff *skb;
970 struct rbd_struct *rbd;
Wang Chen454d7c92008-11-12 23:37:49 -0800971 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 for (; (status = p->rfd_top->status) & STAT_COMPL;) {
974 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
975
976 if (status & STAT_OK) { /* frame received without error? */
977 if ((totlen = rbd->status) & RBD_LAST) { /* the first and the last buffer? */
978 totlen &= RBD_MASK; /* length of this frame */
979 rbd->status = 0;
980 skb = (struct sk_buff *) dev_alloc_skb(totlen + 2);
981 if (skb != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 skb_reserve(skb, 2); /* 16 byte alignment */
983 skb_put(skb,totlen);
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700984 skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 skb->protocol = eth_type_trans(skb, dev);
986 netif_rx(skb);
Paulius Zaleckasaa509112008-04-29 11:58:42 +0300987 dev->stats.rx_packets++;
988 dev->stats.rx_bytes += totlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 } else {
Paulius Zaleckasaa509112008-04-29 11:58:42 +0300990 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992 } else {
993 printk(KERN_WARNING "%s: received oversized frame.\n", dev->name);
Paulius Zaleckasaa509112008-04-29 11:58:42 +0300994 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 }
996 } else { /* frame !(ok), only with 'save-bad-frames' */
997 printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status);
Paulius Zaleckasaa509112008-04-29 11:58:42 +0300998 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000 p->rfd_top->status = 0;
1001 p->rfd_top->last = RFD_SUSP;
1002 p->rfd_last->last = 0; /* delete RU_SUSP */
1003 p->rfd_last = p->rfd_top;
1004 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
1005 }
1006}
1007
1008/**********************************************************
1009 * handle 'Receiver went not ready'.
1010 */
1011
1012static void elmc_rnr_int(struct net_device *dev)
1013{
Wang Chen454d7c92008-11-12 23:37:49 -08001014 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001016 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 WAIT_4_SCB_CMD(); /* wait for the last cmd */
1019 p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1020 elmc_attn586();
1021 WAIT_4_SCB_CMD(); /* wait for accept cmd. */
1022
1023 alloc_rfa(dev, (char *) p->rfd_first);
1024 startrecv586(dev); /* restart RU */
1025
1026 printk(KERN_WARNING "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status);
1027
1028}
1029
1030/**********************************************************
1031 * handle xmit - interrupt
1032 */
1033
1034static void elmc_xmt_int(struct net_device *dev)
1035{
1036 int status;
Wang Chen454d7c92008-11-12 23:37:49 -08001037 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1040 if (!(status & STAT_COMPL)) {
1041 printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1042 }
1043 if (status & STAT_OK) {
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001044 dev->stats.tx_packets++;
1045 dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 } else {
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001047 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (status & TCMD_LATECOLL) {
1049 printk(KERN_WARNING "%s: late collision detected.\n", dev->name);
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001050 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 } else if (status & TCMD_NOCARRIER) {
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001052 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 printk(KERN_WARNING "%s: no carrier detected.\n", dev->name);
1054 } else if (status & TCMD_LOSTCTS) {
1055 printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name);
1056 } else if (status & TCMD_UNDERRUN) {
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001057 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name);
1059 } else if (status & TCMD_MAXCOLL) {
1060 printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name);
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001061 dev->stats.collisions += 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063 }
1064
1065#if (NUM_XMIT_BUFFS != 1)
1066 if ((++p->xmit_last) == NUM_XMIT_BUFFS) {
1067 p->xmit_last = 0;
1068 }
1069#endif
1070
1071 netif_wake_queue(dev);
1072}
1073
1074/***********************************************************
1075 * (re)start the receiver
1076 */
1077
1078static void startrecv586(struct net_device *dev)
1079{
Wang Chen454d7c92008-11-12 23:37:49 -08001080 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 p->scb->rfa_offset = make16(p->rfd_first);
1083 p->scb->cmd = RUC_START;
1084 elmc_attn586(); /* start cmd. */
1085 WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */
1086}
1087
1088/******************************************************
1089 * timeout
1090 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092static void elmc_timeout(struct net_device *dev)
1093{
Wang Chen454d7c92008-11-12 23:37:49 -08001094 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 /* COMMAND-UNIT active? */
1096 if (p->scb->status & CU_ACTIVE) {
1097#ifdef DEBUG
1098 printk("%s: strange ... timeout with CU active?!?\n", dev->name);
1099 printk("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, (int) p->xmit_cmds[0]->cmd_status, (int) p->nop_cmds[0]->cmd_status, (int) p->nop_cmds[1]->cmd_status, (int) p->nop_point);
1100#endif
1101 p->scb->cmd = CUC_ABORT;
1102 elmc_attn586();
1103 WAIT_4_SCB_CMD();
1104 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1105 p->scb->cmd = CUC_START;
1106 elmc_attn586();
1107 WAIT_4_SCB_CMD();
1108 netif_wake_queue(dev);
1109 } else {
1110#ifdef DEBUG
1111 printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev->name, p->scb->status);
1112 printk("%s: command-stats: %04x %04x\n", dev->name, p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status);
1113#endif
1114 elmc_close(dev);
1115 elmc_open(dev);
1116 }
1117}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119/******************************************************
1120 * send frame
1121 */
1122
1123static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
1124{
1125 int len;
1126 int i;
1127#ifndef NO_NOPCOMMANDS
1128 int next_nop;
1129#endif
Wang Chen454d7c92008-11-12 23:37:49 -08001130 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 netif_stop_queue(dev);
1133
1134 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (len != skb->len)
1137 memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN);
David S. Miller3dbad802007-03-29 19:16:03 -07001138 skb_copy_from_linear_data(skb, (char *) p->xmit_cbuffs[p->xmit_count], skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140#if (NUM_XMIT_BUFFS == 1)
1141#ifdef NO_NOPCOMMANDS
1142 p->xmit_buffs[0]->size = TBD_LAST | len;
1143 for (i = 0; i < 16; i++) {
1144 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1145 p->scb->cmd = CUC_START;
1146 p->xmit_cmds[0]->cmd_status = 0;
1147 elmc_attn586();
1148 dev->trans_start = jiffies;
1149 if (!i) {
1150 dev_kfree_skb(skb);
1151 }
1152 WAIT_4_SCB_CMD();
1153 if ((p->scb->status & CU_ACTIVE)) { /* test it, because CU sometimes doesn't start immediately */
1154 break;
1155 }
1156 if (p->xmit_cmds[0]->cmd_status) {
1157 break;
1158 }
1159 if (i == 15) {
1160 printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1161 }
1162 }
1163#else
1164 next_nop = (p->nop_point + 1) & 0x1;
1165 p->xmit_buffs[0]->size = TBD_LAST | len;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1168 = make16((p->nop_cmds[next_nop]));
1169 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1170
1171 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1172 dev->trans_start = jiffies;
1173 p->nop_point = next_nop;
1174 dev_kfree_skb(skb);
1175#endif
1176#else
1177 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1178 if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) {
1179 next_nop = 0;
1180 }
1181 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1182 p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1183 = make16((p->nop_cmds[next_nop]));
1184 p->nop_cmds[next_nop]->cmd_status = 0;
1185 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1186 dev->trans_start = jiffies;
1187 p->xmit_count = next_nop;
1188 if (p->xmit_count != p->xmit_last)
1189 netif_wake_queue(dev);
1190 dev_kfree_skb(skb);
1191#endif
1192 return 0;
1193}
1194
1195/*******************************************
1196 * Someone wanna have the statistics
1197 */
1198
1199static struct net_device_stats *elmc_get_stats(struct net_device *dev)
1200{
Wang Chen454d7c92008-11-12 23:37:49 -08001201 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 unsigned short crc, aln, rsc, ovrn;
1203
1204 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1205 p->scb->crc_errs -= crc;
1206 aln = p->scb->aln_errs;
1207 p->scb->aln_errs -= aln;
1208 rsc = p->scb->rsc_errs;
1209 p->scb->rsc_errs -= rsc;
1210 ovrn = p->scb->ovrn_errs;
1211 p->scb->ovrn_errs -= ovrn;
1212
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001213 dev->stats.rx_crc_errors += crc;
1214 dev->stats.rx_fifo_errors += ovrn;
1215 dev->stats.rx_frame_errors += aln;
1216 dev->stats.rx_dropped += rsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Paulius Zaleckasaa509112008-04-29 11:58:42 +03001218 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
1221/********************************************************
1222 * Set MC list ..
1223 */
1224
1225#ifdef ELMC_MULTICAST
1226static void set_multicast_list(struct net_device *dev)
1227{
1228 if (!dev->start) {
1229 /* without a running interface, promiscuous doesn't work */
1230 return;
1231 }
1232 dev->start = 0;
1233 alloc586(dev);
1234 init586(dev);
1235 startrecv586(dev);
1236 dev->start = 1;
1237}
1238#endif
1239
1240static void netdev_get_drvinfo(struct net_device *dev,
1241 struct ethtool_drvinfo *info)
1242{
1243 strcpy(info->driver, DRV_NAME);
1244 strcpy(info->version, DRV_VERSION);
1245 sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr);
1246}
1247
Jeff Garzik7282d492006-09-13 14:30:00 -04001248static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 .get_drvinfo = netdev_get_drvinfo,
1250};
1251
1252#ifdef MODULE
1253
1254/* Increase if needed ;) */
1255#define MAX_3C523_CARDS 4
1256
1257static struct net_device *dev_elmc[MAX_3C523_CARDS];
1258static int irq[MAX_3C523_CARDS];
1259static int io[MAX_3C523_CARDS];
1260module_param_array(irq, int, NULL, 0);
1261module_param_array(io, int, NULL, 0);
1262MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1263MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
Randy Dunlap7b240172005-06-13 12:31:53 -07001264MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Randy Dunlap96e672c2006-06-10 13:33:48 -07001266int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
1268 int this_dev,found = 0;
1269
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001270 /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1272 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
1273 if (!dev)
1274 break;
1275 dev->irq=irq[this_dev];
1276 dev->base_addr=io[this_dev];
1277 if (do_elmc_probe(dev) == 0) {
b1fc5502005-05-12 20:11:55 -04001278 dev_elmc[this_dev] = dev;
1279 found++;
1280 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 }
1282 free_netdev(dev);
1283 if (io[this_dev]==0)
1284 break;
1285 printk(KERN_WARNING "3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]);
1286 }
1287
1288 if(found==0) {
1289 if(io[0]==0) printk(KERN_NOTICE "3c523.c: No 3c523 cards found\n");
1290 return -ENXIO;
1291 } else return 0;
1292}
1293
Al Viroafc8eb42006-06-14 18:50:53 -04001294void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
1296 int this_dev;
1297 for (this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1298 struct net_device *dev = dev_elmc[this_dev];
1299 if (dev) {
1300 unregister_netdev(dev);
1301 cleanup_card(dev);
1302 free_netdev(dev);
1303 }
1304 }
1305}
1306
1307#endif /* MODULE */