2 net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)
5 This is an extension to the Linux operating system, and is covered by the
6 same Gnu Public License that covers that work.
8 Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)
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.
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.
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.
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/">
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.
34 The original device probe code was stolen from ps2esdi.c
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.
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?
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.
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
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
65 This driver does support multiple ethernet cards when used as a module
66 (up to MAX_3C523_CARDS, the default being 4)
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
76 update to 1.3.59, incorporated multicast diffs from ni52.c
78 added shared irq support
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>
85 $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 $
89 #include <linux/module.h>
92 #include <linux/kernel.h>
93 #include <linux/sched.h>
94 #include <linux/string.h>
95 #include <linux/errno.h>
96 #include <linux/ioport.h>
97 #include <linux/malloc.h>
98 #include <linux/interrupt.h>
99 #include <linux/delay.h>
100 #include <linux/mca.h>
101 #include <asm/processor.h>
102 #include <asm/bitops.h>
105 #include <linux/netdevice.h>
106 #include <linux/etherdevice.h>
107 #include <linux/skbuff.h>
108 #include <linux/init.h>
112 /*************************************************************************/
113 #define DEBUG /* debug on */
114 #define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
115 #undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */
117 #define make32(ptr16) (p->memtop + (short) (ptr16) )
118 #define make24(ptr32) ((char *) (ptr32) - p->base)
119 #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
121 /*************************************************************************/
123 Tables to which we can map values in the configuration registers.
125 static int irq_table
[] __initdata
= {
129 static int csr_table
[] __initdata
= {
130 0x300, 0x1300, 0x2300, 0x3300
133 static int shm_table
[] __initdata
= {
134 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
137 /******************* how to calculate the buffers *****************************
140 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
141 * --------------- in a different (more stable?) mode. Only in this mode it's
142 * possible to configure the driver with 'NO_NOPCOMMANDS'
144 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
145 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
146 sizeof(rfd) = 24; sizeof(rbd) = 12;
147 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
150 * if you don't know the driver, better do not change this values: */
152 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
153 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
154 #define NUM_XMIT_BUFFS 4 /* config for both, 8K and 16K shmem */
155 #define NUM_RECV_BUFFS_8 1 /* config for 8K shared mem */
156 #define NUM_RECV_BUFFS_16 6 /* config for 16K shared mem */
158 #if (NUM_XMIT_BUFFS == 1)
159 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
162 /**************************************************************************/
164 #define DELAY(x) {int i=jiffies; \
165 if(loops_per_sec == 1) \
166 while(time_after(i+(x), jiffies)); \
168 __delay((loops_per_sec>>5)*x); \
171 /* a much shorter delay: */
172 #define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }
174 /* wait for command with timeout: */
175 #define WAIT_4_SCB_CMD() { int i; \
176 for(i=0;i<1024;i++) { \
177 if(!p->scb->cmd) break; \
180 printk("%s:%d: scb_cmd timed out .. resetting i82586\n",\
181 dev->name,__LINE__); \
182 elmc_id_reset586(); } } }
184 static void elmc_interrupt(int irq
, void *dev_id
, struct pt_regs
*reg_ptr
);
185 static int elmc_open(struct net_device
*dev
);
186 static int elmc_close(struct net_device
*dev
);
187 static int elmc_send_packet(struct sk_buff
*, struct net_device
*);
188 static struct net_device_stats
*elmc_get_stats(struct net_device
*dev
);
189 #ifdef ELMC_MULTICAST
190 static void set_multicast_list(struct net_device
*dev
);
193 /* helper-functions */
194 static int init586(struct net_device
*dev
);
195 static int check586(struct net_device
*dev
, unsigned long where
, unsigned size
);
196 static void alloc586(struct net_device
*dev
);
197 static void startrecv586(struct net_device
*dev
);
198 static void *alloc_rfa(struct net_device
*dev
, void *ptr
);
199 static void elmc_rcv_int(struct net_device
*dev
);
200 static void elmc_xmt_int(struct net_device
*dev
);
201 static void elmc_rnr_int(struct net_device
*dev
);
204 struct net_device_stats stats
;
207 volatile struct rfd_struct
*rfd_last
, *rfd_top
, *rfd_first
;
208 volatile struct scp_struct
*scp
; /* volatile is important */
209 volatile struct iscp_struct
*iscp
; /* volatile is important */
210 volatile struct scb_struct
*scb
; /* volatile is important */
211 volatile struct tbd_struct
*xmit_buffs
[NUM_XMIT_BUFFS
];
212 volatile struct transmit_cmd_struct
*xmit_cmds
[NUM_XMIT_BUFFS
];
213 #if (NUM_XMIT_BUFFS == 1)
214 volatile struct nop_cmd_struct
*nop_cmds
[2];
216 volatile struct nop_cmd_struct
*nop_cmds
[NUM_XMIT_BUFFS
];
218 volatile int nop_point
, num_recv_buffs
;
219 volatile char *xmit_cbuffs
[NUM_XMIT_BUFFS
];
220 volatile int xmit_count
, xmit_last
;
224 #define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
225 #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
227 /* with interrupts disabled - this will clear the interrupt bit in the
228 3c523 control register, and won't put it back. This effectively
229 disables interrupts on the card. */
230 #define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);}
231 #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
233 /*************************************************************************/
235 Do a Channel Attention on the 3c523. This is extremely board dependent.
237 static void elmc_do_attn586(int ioaddr
, int ints
)
239 /* the 3c523 requires a minimum of 500 ns. The delays here might be
240 a little too large, and hence they may cut the performance of the
241 card slightly. If someone who knows a little more about Linux
242 timing would care to play with these, I'd appreciate it. */
244 /* this bit masking stuff is crap. I'd rather have separate
245 registers with strobe triggers for each of these functions. <sigh>
246 Ya take what ya got. */
248 outb(ELMC_CTRL_RST
| 0x3 | ELMC_CTRL_CA
| ints
, ioaddr
+ ELMC_CTRL
);
249 DELAY_16(); /* > 500 ns */
250 outb(ELMC_CTRL_RST
| 0x3 | ints
, ioaddr
+ ELMC_CTRL
);
253 /*************************************************************************/
255 Reset the 82586 on the 3c523. Also very board dependent.
257 static void elmc_do_reset586(int ioaddr
, int ints
)
259 /* toggle the RST bit low then high */
260 outb(0x3 | ELMC_CTRL_LBK
, ioaddr
+ ELMC_CTRL
);
261 DELAY_16(); /* > 500 ns */
262 outb(ELMC_CTRL_RST
| ELMC_CTRL_LBK
| 0x3, ioaddr
+ ELMC_CTRL
);
264 elmc_do_attn586(ioaddr
, ints
);
267 /**********************************************
271 static int elmc_close(struct net_device
*dev
)
273 elmc_id_reset586(); /* the hard way to stop the receiver */
275 free_irq(dev
->irq
, dev
);
287 /**********************************************
291 static int elmc_open(struct net_device
*dev
)
294 elmc_id_attn586(); /* disable interrupts */
296 if (request_irq(dev
->irq
, &elmc_interrupt
, SA_SHIRQ
| SA_SAMPLE_RANDOM
,
299 printk("%s: couldn't get irq %d\n", dev
->name
, dev
->irq
);
315 return 0; /* most done by init */
318 /**********************************************
319 * Check to see if there's an 82586 out there.
322 static int __init
check586(struct net_device
*dev
, unsigned long where
, unsigned size
)
324 struct priv
*p
= (struct priv
*) dev
->priv
;
328 p
->base
= where
+ size
- 0x01000000;
329 p
->memtop
= phys_to_virt(where
) + size
;
330 p
->scp
= (struct scp_struct
*)phys_to_virt(p
->base
+ SCP_DEFAULT_ADDRESS
);
331 memset((char *) p
->scp
, 0, sizeof(struct scp_struct
));
332 p
->scp
->sysbus
= SYSBUSVAL
; /* 1 = 8Bit-Bus, 0 = 16 Bit */
334 iscp_addrs
[0] = phys_to_virt(where
);
335 iscp_addrs
[1] = (char *) p
->scp
- sizeof(struct iscp_struct
);
337 for (i
= 0; i
< 2; i
++) {
338 p
->iscp
= (struct iscp_struct
*) iscp_addrs
[i
];
339 memset((char *) p
->iscp
, 0, sizeof(struct iscp_struct
));
341 p
->scp
->iscp
= make24(p
->iscp
);
346 /* reset586 does an implicit CA */
348 /* apparently, you sometimes have to kick the 82586 twice... */
351 if (p
->iscp
->busy
) { /* i82586 clears 'busy' after successful init */
358 /******************************************************************
359 * set iscp at the right place, called by elmc_probe and open586.
362 void alloc586(struct net_device
*dev
)
364 struct priv
*p
= (struct priv
*) dev
->priv
;
369 p
->scp
= (struct scp_struct
*) phys_to_virt(p
->base
+ SCP_DEFAULT_ADDRESS
);
370 p
->scb
= (struct scb_struct
*) phys_to_virt(dev
->mem_start
);
371 p
->iscp
= (struct iscp_struct
*) ((char *) p
->scp
- sizeof(struct iscp_struct
));
373 memset((char *) p
->iscp
, 0, sizeof(struct iscp_struct
));
374 memset((char *) p
->scp
, 0, sizeof(struct scp_struct
));
376 p
->scp
->iscp
= make24(p
->iscp
);
377 p
->scp
->sysbus
= SYSBUSVAL
;
378 p
->iscp
->scb_offset
= make16(p
->scb
);
387 printk("%s: Init-Problems (alloc).\n", dev
->name
);
389 memset((char *) p
->scb
, 0, sizeof(struct scb_struct
));
392 /*****************************************************************/
394 static int elmc_getinfo(char *buf
, int slot
, void *d
)
397 struct net_device
*dev
= (struct net_device
*) d
;
403 len
+= sprintf(buf
+ len
, "Revision: 0x%x\n",
404 inb(dev
->base_addr
+ ELMC_REVISION
) & 0xf);
405 len
+= sprintf(buf
+ len
, "IRQ: %d\n", dev
->irq
);
406 len
+= sprintf(buf
+ len
, "IO Address: %#lx-%#lx\n", dev
->base_addr
,
407 dev
->base_addr
+ ELMC_IO_EXTENT
);
408 len
+= sprintf(buf
+ len
, "Memory: %#lx-%#lx\n", dev
->mem_start
,
410 len
+= sprintf(buf
+ len
, "Transceiver: %s\n", dev
->if_port
?
411 "External" : "Internal");
412 len
+= sprintf(buf
+ len
, "Device: %s\n", dev
->name
);
413 len
+= sprintf(buf
+ len
, "Hardware Address:");
414 for (i
= 0; i
< 6; i
++) {
415 len
+= sprintf(buf
+ len
, " %02x", dev
->dev_addr
[i
]);
421 } /* elmc_getinfo() */
423 /*****************************************************************/
425 int __init
elmc_probe(struct net_device
*dev
)
428 int base_addr
= dev
? dev
->base_addr
: 0;
429 int irq
= dev
? dev
->irq
: 0;
433 unsigned int size
= 0;
438 /* search through the slots for the 3c523. */
439 slot
= mca_find_adapter(ELMC_MCA_ID
, 0);
441 status
= mca_read_stored_pos(slot
, 2);
443 dev
->irq
=irq_table
[(status
& ELMC_STATUS_IRQ_SELECT
) >> 6];
444 dev
->base_addr
=csr_table
[(status
& ELMC_STATUS_CSR_SELECT
) >> 1];
447 If we're trying to match a specified irq or IO address,
448 we'll reject a match unless it's what we're looking for.
449 Also reject it if the card is already in use.
452 if((irq
&& irq
!= dev
->irq
) || (base_addr
&& base_addr
!= dev
->base_addr
)
453 || check_region(dev
->base_addr
,ELMC_IO_EXTENT
)) {
454 slot
= mca_find_adapter(ELMC_MCA_ID
, slot
+ 1);
457 /* found what we're looking for... */
461 /* we didn't find any 3c523 in the slots we checked for */
462 if (slot
== MCA_NOTFOUND
) {
463 return ((base_addr
|| irq
) ? ENXIO
: ENODEV
);
465 mca_set_adapter_name(slot
, "3Com 3c523 Etherlink/MC");
466 mca_set_adapter_procfn(slot
, (MCA_ProcFn
) elmc_getinfo
, dev
);
468 /* if we get this far, adapter has been found - carry on */
469 printk("%s: 3c523 adapter found in slot %d\n", dev
->name
, slot
+ 1);
471 /* Now we extract configuration info from the card.
472 The 3c523 provides information in two of the POS registers, but
473 the second one is only needed if we want to tell the card what IRQ
474 to use. I suspect that whoever sets the thing up initially would
475 prefer we don't screw with those things.
477 Note that we read the status info when we found the card...
479 See 3c523.h for more details.
482 /* revision is stored in the first 4 bits of the revision register */
483 revision
= inb(dev
->base_addr
+ ELMC_REVISION
) & 0xf;
485 /* according to docs, we read the interrupt and write it back to
486 the IRQ select register, since the POST might not configure the IRQ
490 mca_write_pos(slot
, 3, 0x04);
493 mca_write_pos(slot
, 3, 0x02);
496 mca_write_pos(slot
, 3, 0x08);
499 mca_write_pos(slot
, 3, 0x01);
503 request_region(dev
->base_addr
, ELMC_IO_EXTENT
, "3c523");
505 dev
->priv
= (void *) kmalloc(sizeof(struct priv
), GFP_KERNEL
);
506 if (dev
->priv
== NULL
) {
509 memset((char *) dev
->priv
, 0, sizeof(struct priv
));
511 ((struct priv
*) (dev
->priv
))->slot
= slot
;
513 printk("%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev
->name
, (int) revision
,
516 /* Determine if we're using the on-board transceiver (i.e. coax) or
517 an external one. The information is pretty much useless, but I
518 guess it's worth brownie points. */
519 dev
->if_port
= (status
& ELMC_STATUS_DISABLE_THIN
);
521 /* The 3c523 has a 24K chunk of memory. The first 16K is the
522 shared memory, while the last 8K is for the EtherStart BIOS ROM.
523 Which we don't care much about here. We'll just tell Linux that
524 we're using 16K. MCA won't permit address space conflicts caused
525 by not mapping the other 8K. */
526 dev
->mem_start
= shm_table
[(status
& ELMC_STATUS_MEMORY_SELECT
) >> 3];
528 /* We're using MCA, so it's a given that the information about memory
529 size is correct. The Crynwr drivers do something like this. */
531 elmc_id_reset586(); /* seems like a good idea before checking it... */
533 size
= 0x4000; /* check for 16K mem */
534 if (!check586(dev
, dev
->mem_start
, size
)) {
535 printk("%s: memprobe, Can't find memory at 0x%lx!\n", dev
->name
,
537 release_region(dev
->base_addr
, ELMC_IO_EXTENT
);
540 dev
->mem_end
= dev
->mem_start
+ size
; /* set mem_end showed by 'ifconfig' */
542 ((struct priv
*) (dev
->priv
))->base
= dev
->mem_start
+ size
- 0x01000000;
545 elmc_id_reset586(); /* make sure it doesn't generate spurious ints */
547 /* set number of receive-buffs according to memsize */
548 ((struct priv
*) dev
->priv
)->num_recv_buffs
= NUM_RECV_BUFFS_16
;
550 /* dump all the assorted information */
551 printk("%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev
->name
,
552 dev
->irq
, dev
->if_port
? "ex" : "in",
553 dev
->mem_start
, dev
->mem_end
- 1);
555 /* The hardware address for the 3c523 is stored in the first six
556 bytes of the IO address. */
557 printk("%s: hardware address ", dev
->name
);
558 for (i
= 0; i
< 6; i
++) {
559 dev
->dev_addr
[i
] = inb(dev
->base_addr
+ i
);
560 printk(" %02x", dev
->dev_addr
[i
]);
564 dev
->open
= &elmc_open
;
565 dev
->stop
= &elmc_close
;
566 dev
->get_stats
= &elmc_get_stats
;
567 dev
->hard_start_xmit
= &elmc_send_packet
;
568 #ifdef ELMC_MULTICAST
569 dev
->set_multicast_list
= &set_multicast_list
;
571 dev
->set_multicast_list
= NULL
;
580 /* note that we haven't actually requested the IRQ from the kernel.
581 That gets done in elmc_open(). I'm not sure that's such a good idea,
582 but it works, so I'll go with it. */
584 #ifndef ELMC_MULTICAST
585 dev
->flags
&=~IFF_MULTICAST
; /* Multicast doesn't work */
591 /**********************************************
592 * init the chip (elmc-interrupt should be disabled?!)
593 * needs a correct 'allocated' memory
596 static int init586(struct net_device
*dev
)
601 struct priv
*p
= (struct priv
*) dev
->priv
;
602 volatile struct configure_cmd_struct
*cfg_cmd
;
603 volatile struct iasetup_cmd_struct
*ias_cmd
;
604 volatile struct tdr_cmd_struct
*tdr_cmd
;
605 volatile struct mcsetup_cmd_struct
*mc_cmd
;
606 struct dev_mc_list
*dmi
= dev
->mc_list
;
607 int num_addrs
= dev
->mc_count
;
609 ptr
= (void *) ((char *) p
->scb
+ sizeof(struct scb_struct
));
611 cfg_cmd
= (struct configure_cmd_struct
*) ptr
; /* configure-command */
612 cfg_cmd
->cmd_status
= 0;
613 cfg_cmd
->cmd_cmd
= CMD_CONFIGURE
| CMD_LAST
;
614 cfg_cmd
->cmd_link
= 0xffff;
616 cfg_cmd
->byte_cnt
= 0x0a; /* number of cfg bytes */
617 cfg_cmd
->fifo
= 0x08; /* fifo-limit (8=tx:32/rx:64) */
618 cfg_cmd
->sav_bf
= 0x40; /* hold or discard bad recv frames (bit 7) */
619 cfg_cmd
->adr_len
= 0x2e; /* addr_len |!src_insert |pre-len |loopback */
620 cfg_cmd
->priority
= 0x00;
622 cfg_cmd
->time_low
= 0x00;
623 cfg_cmd
->time_high
= 0xf2;
624 cfg_cmd
->promisc
= 0;
625 if (dev
->flags
& (IFF_ALLMULTI
| IFF_PROMISC
)) {
626 cfg_cmd
->promisc
= 1;
627 dev
->flags
|= IFF_PROMISC
;
629 cfg_cmd
->carr_coll
= 0x00;
631 p
->scb
->cbl_offset
= make16(cfg_cmd
);
633 p
->scb
->cmd
= CUC_START
; /* cmd.-unit start */
636 s
= jiffies
; /* warning: only active with interrupts on !! */
637 while (!(cfg_cmd
->cmd_status
& STAT_COMPL
)) {
638 if (jiffies
- s
> 30*HZ
/100)
642 if ((cfg_cmd
->cmd_status
& (STAT_OK
| STAT_COMPL
)) != (STAT_COMPL
| STAT_OK
)) {
643 printk("%s (elmc): configure command failed: %x\n", dev
->name
, cfg_cmd
->cmd_status
);
647 * individual address setup
649 ias_cmd
= (struct iasetup_cmd_struct
*) ptr
;
651 ias_cmd
->cmd_status
= 0;
652 ias_cmd
->cmd_cmd
= CMD_IASETUP
| CMD_LAST
;
653 ias_cmd
->cmd_link
= 0xffff;
655 memcpy((char *) &ias_cmd
->iaddr
, (char *) dev
->dev_addr
, ETH_ALEN
);
657 p
->scb
->cbl_offset
= make16(ias_cmd
);
659 p
->scb
->cmd
= CUC_START
; /* cmd.-unit start */
663 while (!(ias_cmd
->cmd_status
& STAT_COMPL
)) {
664 if (jiffies
- s
> 30*HZ
/100)
668 if ((ias_cmd
->cmd_status
& (STAT_OK
| STAT_COMPL
)) != (STAT_OK
| STAT_COMPL
)) {
669 printk("%s (elmc): individual address setup command failed: %04x\n", dev
->name
, ias_cmd
->cmd_status
);
673 * TDR, wire check .. e.g. no resistor e.t.c
675 tdr_cmd
= (struct tdr_cmd_struct
*) ptr
;
677 tdr_cmd
->cmd_status
= 0;
678 tdr_cmd
->cmd_cmd
= CMD_TDR
| CMD_LAST
;
679 tdr_cmd
->cmd_link
= 0xffff;
682 p
->scb
->cbl_offset
= make16(tdr_cmd
);
684 p
->scb
->cmd
= CUC_START
; /* cmd.-unit start */
688 while (!(tdr_cmd
->cmd_status
& STAT_COMPL
)) {
689 if (jiffies
- s
> 30*HZ
/100) {
690 printk("%s: %d Problems while running the TDR.\n", dev
->name
, __LINE__
);
697 DELAY(2); /* wait for result */
698 result
= tdr_cmd
->status
;
700 p
->scb
->cmd
= p
->scb
->status
& STAT_MASK
;
701 elmc_id_attn586(); /* ack the interrupts */
703 if (result
& TDR_LNK_OK
) {
705 } else if (result
& TDR_XCVR_PRB
) {
706 printk("%s: TDR: Transceiver problem!\n", dev
->name
);
707 } else if (result
& TDR_ET_OPN
) {
708 printk("%s: TDR: No correct termination %d clocks away.\n", dev
->name
, result
& TDR_TIMEMASK
);
709 } else if (result
& TDR_ET_SRT
) {
710 if (result
& TDR_TIMEMASK
) /* time == 0 -> strange :-) */
711 printk("%s: TDR: Detected a short circuit %d clocks away.\n", dev
->name
, result
& TDR_TIMEMASK
);
713 printk("%s: TDR: Unknown status %04x\n", dev
->name
, result
);
719 p
->scb
->cmd
= p
->scb
->status
& STAT_MASK
;
723 * alloc nop/xmit-cmds
725 #if (NUM_XMIT_BUFFS == 1)
726 for (i
= 0; i
< 2; i
++) {
727 p
->nop_cmds
[i
] = (struct nop_cmd_struct
*) ptr
;
728 p
->nop_cmds
[i
]->cmd_cmd
= CMD_NOP
;
729 p
->nop_cmds
[i
]->cmd_status
= 0;
730 p
->nop_cmds
[i
]->cmd_link
= make16((p
->nop_cmds
[i
]));
731 ptr
= (char *) ptr
+ sizeof(struct nop_cmd_struct
);
733 p
->xmit_cmds
[0] = (struct transmit_cmd_struct
*) ptr
; /* transmit cmd/buff 0 */
734 ptr
= (char *) ptr
+ sizeof(struct transmit_cmd_struct
);
736 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
737 p
->nop_cmds
[i
] = (struct nop_cmd_struct
*) ptr
;
738 p
->nop_cmds
[i
]->cmd_cmd
= CMD_NOP
;
739 p
->nop_cmds
[i
]->cmd_status
= 0;
740 p
->nop_cmds
[i
]->cmd_link
= make16((p
->nop_cmds
[i
]));
741 ptr
= (char *) ptr
+ sizeof(struct nop_cmd_struct
);
742 p
->xmit_cmds
[i
] = (struct transmit_cmd_struct
*) ptr
; /*transmit cmd/buff 0 */
743 ptr
= (char *) ptr
+ sizeof(struct transmit_cmd_struct
);
747 ptr
= alloc_rfa(dev
, (void *) ptr
); /* init receive-frame-area */
754 /* I don't understand this: do we really need memory after the init? */
755 int len
= ((char *) p
->iscp
- (char *) ptr
- 8) / 6;
757 printk("%s: Ooooops, no memory for MC-Setup!\n", dev
->name
);
759 if (len
< num_addrs
) {
761 printk("%s: Sorry, can only apply %d MC-Address(es).\n",
762 dev
->name
, num_addrs
);
764 mc_cmd
= (struct mcsetup_cmd_struct
*) ptr
;
765 mc_cmd
->cmd_status
= 0;
766 mc_cmd
->cmd_cmd
= CMD_MCSETUP
| CMD_LAST
;
767 mc_cmd
->cmd_link
= 0xffff;
768 mc_cmd
->mc_cnt
= num_addrs
* 6;
769 for (i
= 0; i
< num_addrs
; i
++) {
770 memcpy((char *) mc_cmd
->mc_list
[i
], dmi
->dmi_addr
, 6);
773 p
->scb
->cbl_offset
= make16(mc_cmd
);
774 p
->scb
->cmd
= CUC_START
;
777 while (!(mc_cmd
->cmd_status
& STAT_COMPL
)) {
778 if (jiffies
- s
> 30*HZ
/100)
781 if (!(mc_cmd
->cmd_status
& STAT_COMPL
)) {
782 printk("%s: Can't apply multicast-address-list.\n", dev
->name
);
787 * alloc xmit-buffs / init xmit_cmds
789 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
790 p
->xmit_cbuffs
[i
] = (char *) ptr
; /* char-buffs */
791 ptr
= (char *) ptr
+ XMIT_BUFF_SIZE
;
792 p
->xmit_buffs
[i
] = (struct tbd_struct
*) ptr
; /* TBD */
793 ptr
= (char *) ptr
+ sizeof(struct tbd_struct
);
794 if ((void *) ptr
> (void *) p
->iscp
) {
795 printk("%s: not enough shared-mem for your configuration!\n", dev
->name
);
798 memset((char *) (p
->xmit_cmds
[i
]), 0, sizeof(struct transmit_cmd_struct
));
799 memset((char *) (p
->xmit_buffs
[i
]), 0, sizeof(struct tbd_struct
));
800 p
->xmit_cmds
[i
]->cmd_status
= STAT_COMPL
;
801 p
->xmit_cmds
[i
]->cmd_cmd
= CMD_XMIT
| CMD_INT
;
802 p
->xmit_cmds
[i
]->tbd_offset
= make16((p
->xmit_buffs
[i
]));
803 p
->xmit_buffs
[i
]->next
= 0xffff;
804 p
->xmit_buffs
[i
]->buffer
= make24((p
->xmit_cbuffs
[i
]));
809 #ifndef NO_NOPCOMMANDS
814 * 'start transmitter' (nop-loop)
816 #ifndef NO_NOPCOMMANDS
817 p
->scb
->cbl_offset
= make16(p
->nop_cmds
[0]);
818 p
->scb
->cmd
= CUC_START
;
822 p
->xmit_cmds
[0]->cmd_link
= 0xffff;
823 p
->xmit_cmds
[0]->cmd_cmd
= CMD_XMIT
| CMD_LAST
| CMD_INT
;
829 /******************************************************
830 * This is a helper routine for elmc_rnr_int() and init586().
831 * It sets up the Receive Frame Area (RFA).
834 static void *alloc_rfa(struct net_device
*dev
, void *ptr
)
836 volatile struct rfd_struct
*rfd
= (struct rfd_struct
*) ptr
;
837 volatile struct rbd_struct
*rbd
;
839 struct priv
*p
= (struct priv
*) dev
->priv
;
841 memset((char *) rfd
, 0, sizeof(struct rfd_struct
) * p
->num_recv_buffs
);
844 for (i
= 0; i
< p
->num_recv_buffs
; i
++) {
845 rfd
[i
].next
= make16(rfd
+ (i
+ 1) % p
->num_recv_buffs
);
847 rfd
[p
->num_recv_buffs
- 1].last
= RFD_SUSP
; /* RU suspend */
849 ptr
= (void *) (rfd
+ p
->num_recv_buffs
);
851 rbd
= (struct rbd_struct
*) ptr
;
852 ptr
= (void *) (rbd
+ p
->num_recv_buffs
);
854 /* clr descriptors */
855 memset((char *) rbd
, 0, sizeof(struct rbd_struct
) * p
->num_recv_buffs
);
857 for (i
= 0; i
< p
->num_recv_buffs
; i
++) {
858 rbd
[i
].next
= make16((rbd
+ (i
+ 1) % p
->num_recv_buffs
));
859 rbd
[i
].size
= RECV_BUFF_SIZE
;
860 rbd
[i
].buffer
= make24(ptr
);
861 ptr
= (char *) ptr
+ RECV_BUFF_SIZE
;
864 p
->rfd_top
= p
->rfd_first
;
865 p
->rfd_last
= p
->rfd_first
+ p
->num_recv_buffs
- 1;
867 p
->scb
->rfa_offset
= make16(p
->rfd_first
);
868 p
->rfd_first
->rbd_offset
= make16(rbd
);
874 /**************************************************
875 * Interrupt Handler ...
878 static void elmc_interrupt(int irq
, void *dev_id
, struct pt_regs
*reg_ptr
)
880 struct net_device
*dev
= (struct net_device
*) dev_id
;
885 printk("elmc-interrupt: irq %d for unknown device.\n", (int) -(((struct pt_regs
*) reg_ptr
)->orig_eax
+ 2));
887 } else if (!dev
->start
) {
888 /* The 3c523 has this habit of generating interrupts during the
889 reset. I'm not sure if the ni52 has this same problem, but it's
890 really annoying if we haven't finished initializing it. I was
891 hoping all the elmc_id_* commands would disable this, but I
892 might have missed a few. */
894 elmc_id_attn586(); /* ack inter. and disable any more */
896 } else if (!(ELMC_CTRL_INT
& inb(dev
->base_addr
+ ELMC_CTRL
))) {
897 /* wasn't this device */
900 /* reading ELMC_CTRL also clears the INT bit. */
902 p
= (struct priv
*) dev
->priv
;
906 while ((stat
= p
->scb
->status
& STAT_MASK
))
909 elmc_attn586(); /* ack inter. */
911 if (stat
& STAT_CX
) {
912 /* command with I-bit set complete */
915 if (stat
& STAT_FR
) {
916 /* received a frame */
919 #ifndef NO_NOPCOMMANDS
920 if (stat
& STAT_CNA
) {
921 /* CU went 'not ready' */
923 printk("%s: oops! CU has left active state. stat: %04x/%04x.\n", dev
->name
, (int) stat
, (int) p
->scb
->status
);
928 if (stat
& STAT_RNR
) {
929 /* RU went 'not ready' */
931 if (p
->scb
->status
& RU_SUSPEND
) {
932 /* special case: RU_SUSPEND */
935 p
->scb
->cmd
= RUC_RESUME
;
938 printk("%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev
->name
, (int) stat
, (int) p
->scb
->status
);
942 WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
943 if (p
->scb
->cmd
) { /* timed out? */
951 /*******************************************************
955 static void elmc_rcv_int(struct net_device
*dev
)
958 unsigned short totlen
;
960 struct rbd_struct
*rbd
;
961 struct priv
*p
= (struct priv
*) dev
->priv
;
963 for (; (status
= p
->rfd_top
->status
) & STAT_COMPL
;) {
964 rbd
= (struct rbd_struct
*) make32(p
->rfd_top
->rbd_offset
);
966 if (status
& STAT_OK
) { /* frame received without error? */
967 if ((totlen
= rbd
->status
) & RBD_LAST
) { /* the first and the last buffer? */
968 totlen
&= RBD_MASK
; /* length of this frame */
970 skb
= (struct sk_buff
*) dev_alloc_skb(totlen
+ 2);
973 skb_reserve(skb
, 2); /* 16 byte alignment */
974 memcpy(skb_put(skb
, totlen
), (u8
*)phys_to_virt(p
->base
) + (unsigned long) rbd
->buffer
, totlen
);
975 skb
->protocol
= eth_type_trans(skb
, dev
);
977 p
->stats
.rx_packets
++;
978 p
->stats
.rx_bytes
+= totlen
;
980 p
->stats
.rx_dropped
++;
983 printk("%s: received oversized frame.\n", dev
->name
);
984 p
->stats
.rx_dropped
++;
986 } else { /* frame !(ok), only with 'save-bad-frames' */
987 printk("%s: oops! rfd-error-status: %04x\n", dev
->name
, status
);
988 p
->stats
.rx_errors
++;
990 p
->rfd_top
->status
= 0;
991 p
->rfd_top
->last
= RFD_SUSP
;
992 p
->rfd_last
->last
= 0; /* delete RU_SUSP */
993 p
->rfd_last
= p
->rfd_top
;
994 p
->rfd_top
= (struct rfd_struct
*) make32(p
->rfd_top
->next
); /* step to next RFD */
998 /**********************************************************
999 * handle 'Receiver went not ready'.
1002 static void elmc_rnr_int(struct net_device
*dev
)
1004 struct priv
*p
= (struct priv
*) dev
->priv
;
1006 p
->stats
.rx_errors
++;
1008 WAIT_4_SCB_CMD(); /* wait for the last cmd */
1009 p
->scb
->cmd
= RUC_ABORT
; /* usually the RU is in the 'no resource'-state .. abort it now. */
1011 WAIT_4_SCB_CMD(); /* wait for accept cmd. */
1013 alloc_rfa(dev
, (char *) p
->rfd_first
);
1014 startrecv586(dev
); /* restart RU */
1016 printk("%s: Receive-Unit restarted. Status: %04x\n", dev
->name
, p
->scb
->status
);
1020 /**********************************************************
1021 * handle xmit - interrupt
1024 static void elmc_xmt_int(struct net_device
*dev
)
1027 struct priv
*p
= (struct priv
*) dev
->priv
;
1029 status
= p
->xmit_cmds
[p
->xmit_last
]->cmd_status
;
1030 if (!(status
& STAT_COMPL
)) {
1031 printk("%s: strange .. xmit-int without a 'COMPLETE'\n", dev
->name
);
1033 if (status
& STAT_OK
) {
1034 p
->stats
.tx_packets
++;
1035 p
->stats
.collisions
+= (status
& TCMD_MAXCOLLMASK
);
1037 p
->stats
.tx_errors
++;
1038 if (status
& TCMD_LATECOLL
) {
1039 printk("%s: late collision detected.\n", dev
->name
);
1040 p
->stats
.collisions
++;
1041 } else if (status
& TCMD_NOCARRIER
) {
1042 p
->stats
.tx_carrier_errors
++;
1043 printk("%s: no carrier detected.\n", dev
->name
);
1044 } else if (status
& TCMD_LOSTCTS
) {
1045 printk("%s: loss of CTS detected.\n", dev
->name
);
1046 } else if (status
& TCMD_UNDERRUN
) {
1047 p
->stats
.tx_fifo_errors
++;
1048 printk("%s: DMA underrun detected.\n", dev
->name
);
1049 } else if (status
& TCMD_MAXCOLL
) {
1050 printk("%s: Max. collisions exceeded.\n", dev
->name
);
1051 p
->stats
.collisions
+= 16;
1055 #if (NUM_XMIT_BUFFS != 1)
1056 if ((++p
->xmit_last
) == NUM_XMIT_BUFFS
) {
1065 /***********************************************************
1066 * (re)start the receiver
1069 static void startrecv586(struct net_device
*dev
)
1071 struct priv
*p
= (struct priv
*) dev
->priv
;
1073 p
->scb
->rfa_offset
= make16(p
->rfd_first
);
1074 p
->scb
->cmd
= RUC_START
;
1075 elmc_attn586(); /* start cmd. */
1076 WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */
1079 /******************************************************
1083 static int elmc_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1086 #ifndef NO_NOPCOMMANDS
1089 struct priv
*p
= (struct priv
*) dev
->priv
;
1092 int tickssofar
= jiffies
- dev
->trans_start
;
1093 if (tickssofar
< 5) {
1096 /* COMMAND-UNIT active? */
1097 if (p
->scb
->status
& CU_ACTIVE
) {
1100 printk("%s: strange ... timeout with CU active?!?\n", dev
->name
);
1101 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
);
1103 p
->scb
->cmd
= CUC_ABORT
;
1106 p
->scb
->cbl_offset
= make16(p
->nop_cmds
[p
->nop_point
]);
1107 p
->scb
->cmd
= CUC_START
;
1110 dev
->trans_start
= jiffies
;
1114 printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev
->name
, p
->scb
->status
);
1115 printk("%s: command-stats: %04x %04x\n", dev
->name
, p
->xmit_cmds
[0]->cmd_status
, p
->xmit_cmds
[1]->cmd_status
);
1120 dev
->trans_start
= jiffies
;
1123 if (test_and_set_bit(0, (void *) &dev
->tbusy
) != 0) {
1124 printk("%s: Transmitter access conflict.\n", dev
->name
);
1126 memcpy((char *) p
->xmit_cbuffs
[p
->xmit_count
], (char *) (skb
->data
), skb
->len
);
1127 len
= (ETH_ZLEN
< skb
->len
) ? skb
->len
: ETH_ZLEN
;
1129 #if (NUM_XMIT_BUFFS == 1)
1130 #ifdef NO_NOPCOMMANDS
1131 p
->xmit_buffs
[0]->size
= TBD_LAST
| len
;
1132 for (i
= 0; i
< 16; i
++) {
1133 p
->scb
->cbl_offset
= make16(p
->xmit_cmds
[0]);
1134 p
->scb
->cmd
= CUC_START
;
1135 p
->xmit_cmds
[0]->cmd_status
= 0;
1138 dev
->trans_start
= jiffies
;
1143 if ((p
->scb
->status
& CU_ACTIVE
)) { /* test it, because CU sometimes doesn't start immediately */
1146 if (p
->xmit_cmds
[0]->cmd_status
) {
1150 printk("%s: Can't start transmit-command.\n", dev
->name
);
1154 next_nop
= (p
->nop_point
+ 1) & 0x1;
1155 p
->xmit_buffs
[0]->size
= TBD_LAST
| len
;
1157 p
->xmit_cmds
[0]->cmd_link
= p
->nop_cmds
[next_nop
]->cmd_link
1158 = make16((p
->nop_cmds
[next_nop
]));
1159 p
->xmit_cmds
[0]->cmd_status
= p
->nop_cmds
[next_nop
]->cmd_status
= 0;
1161 p
->nop_cmds
[p
->nop_point
]->cmd_link
= make16((p
->xmit_cmds
[0]));
1162 dev
->trans_start
= jiffies
;
1163 p
->nop_point
= next_nop
;
1167 p
->xmit_buffs
[p
->xmit_count
]->size
= TBD_LAST
| len
;
1168 if ((next_nop
= p
->xmit_count
+ 1) == NUM_XMIT_BUFFS
) {
1171 p
->xmit_cmds
[p
->xmit_count
]->cmd_status
= 0;
1172 p
->xmit_cmds
[p
->xmit_count
]->cmd_link
= p
->nop_cmds
[next_nop
]->cmd_link
1173 = make16((p
->nop_cmds
[next_nop
]));
1174 p
->nop_cmds
[next_nop
]->cmd_status
= 0;
1176 p
->nop_cmds
[p
->xmit_count
]->cmd_link
= make16((p
->xmit_cmds
[p
->xmit_count
]));
1177 dev
->trans_start
= jiffies
;
1178 p
->xmit_count
= next_nop
;
1181 if (p
->xmit_count
!= p
->xmit_last
) {
1191 /*******************************************
1192 * Someone wanna have the statistics
1195 static struct net_device_stats
*elmc_get_stats(struct net_device
*dev
)
1197 struct priv
*p
= (struct priv
*) dev
->priv
;
1198 unsigned short crc
, aln
, rsc
, ovrn
;
1200 crc
= p
->scb
->crc_errs
; /* get error-statistic from the ni82586 */
1201 p
->scb
->crc_errs
-= crc
;
1202 aln
= p
->scb
->aln_errs
;
1203 p
->scb
->aln_errs
-= aln
;
1204 rsc
= p
->scb
->rsc_errs
;
1205 p
->scb
->rsc_errs
-= rsc
;
1206 ovrn
= p
->scb
->ovrn_errs
;
1207 p
->scb
->ovrn_errs
-= ovrn
;
1209 p
->stats
.rx_crc_errors
+= crc
;
1210 p
->stats
.rx_fifo_errors
+= ovrn
;
1211 p
->stats
.rx_frame_errors
+= aln
;
1212 p
->stats
.rx_dropped
+= rsc
;
1217 /********************************************************
1221 #ifdef ELMC_MULTICAST
1222 static void set_multicast_list(struct net_device
*dev
)
1225 /* without a running interface, promiscuous doesn't work */
1236 /*************************************************************************/
1240 /* Increase if needed ;) */
1241 #define MAX_3C523_CARDS 4
1242 /* I'm not sure where this magic 9 comes from */
1245 static char devicenames
[NAMELEN
* MAX_3C523_CARDS
] = {0,};
1247 static struct net_device dev_elmc
[MAX_3C523_CARDS
] =
1250 NULL
/*"3c523" */ , 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, NULL
1254 static int irq
[MAX_3C523_CARDS
] = {0,};
1255 static int io
[MAX_3C523_CARDS
] = {0,};
1256 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_3C523_CARDS
) "i");
1257 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_3C523_CARDS
) "i");
1259 int init_module(void)
1261 int this_dev
,found
= 0;
1263 /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */
1264 for(this_dev
=0; this_dev
<MAX_3C523_CARDS
; this_dev
++)
1266 struct net_device
*dev
= &dev_elmc
[this_dev
];
1267 dev
->name
=devicenames
+(NAMELEN
*this_dev
);
1268 dev
->irq
=irq
[this_dev
];
1269 dev
->base_addr
=io
[this_dev
];
1270 dev
->init
=elmc_probe
;
1271 if(register_netdev(dev
)!=0) {
1272 if(io
[this_dev
]==0) break;
1273 printk(KERN_WARNING
"3c523.c: No 3c523 card found at io=%#x\n",io
[this_dev
]);
1278 if(io
[0]==0) printk(KERN_NOTICE
"3c523.c: No 3c523 cards found\n");
1283 void cleanup_module(void)
1286 for(this_dev
=0; this_dev
<MAX_3C523_CARDS
; this_dev
++) {
1288 struct net_device
*dev
= &dev_elmc
[this_dev
];
1290 /* shutdown interrupts on the card */
1292 if (dev
->irq
!= 0) {
1293 /* this should be done by close, but if we failed to
1294 initialize properly something may have gotten hosed. */
1295 free_irq(dev
->irq
, dev
);
1298 if (dev
->base_addr
!= 0) {
1299 release_region(dev
->base_addr
, ELMC_IO_EXTENT
);
1304 unregister_netdev(dev
);
1306 mca_set_adapter_procfn(((struct priv
*) (dev
->priv
))->slot
,
1309 kfree_s(dev
->priv
, sizeof(struct priv
));